2
* Copyright 2007 Frank Lanitz <frank(at)frank(dot)uvena(dot)de>
3
* Copyright 2007 Enrico Trƶger <enrico.troeger@uvena.de>
4
* Copyright 2007 Nick Treleaven <nick.treleaven@btinternet.com>
5
* Copyright 2007 Yura Siamashka <yurand2@gmail.com>
7
* This program is free software; you can redistribute it and/or modify
8
* it under the terms of the GNU General Public License as published by
9
* the Free Software Foundation; either version 2 of the License, or
10
* (at your option) any later version.
12
* This program is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
17
* You should have received a copy of the GNU General Public License
18
* along with this program; if not, write to the Free Software
19
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26
#include "plugindata.h"
28
#include "filetypes.h"
30
#include "geanyfunctions.h"
34
extern GeanyData *geany_data;
37
static const gchar *BZR_CMD_DIFF_FILE[] = { "bzr", "diff", BASENAME, NULL };
38
static const gchar *BZR_CMD_DIFF_DIR[] = { "bzr", "diff", ABS_DIRNAME, NULL };
39
static const gchar *BZR_CMD_REVERT_FILE[] = { "bzr", "revert", BASENAME, NULL };
40
static const gchar *BZR_CMD_REVERT_DIR[] = { "bzr", "revert", BASE_DIRNAME, NULL };
41
static const gchar *BZR_CMD_STATUS[] = { "bzr", "status", NULL };
42
static const gchar *BZR_CMD_ADD[] = { "bzr", "add", BASENAME, NULL };
43
static const gchar *BZR_CMD_REMOVE[] = { "bzr", "remove", BASENAME, NULL };
44
static const gchar *BZR_CMD_LOG_FILE[] = { "bzr", "log", BASENAME, NULL };
45
static const gchar *BZR_CMD_LOG_DIR[] = { "bzr", "log", ABS_DIRNAME, NULL };
46
static const gchar *BZR_CMD_COMMIT[] = { "bzr", "commit", "-m", MESSAGE, FILE_LIST, NULL };
47
static const gchar *BZR_CMD_BLAME[] = { "bzr", "blame", "--all", "--long", BASENAME, NULL };
48
static const gchar *BZR_CMD_SHOW[] = { "bzr", "cat", BASENAME, NULL };
49
static const gchar *BZR_CMD_UPDATE[] = { "bzr", "pull", NULL };
51
static const VC_COMMAND commands[] = {
53
.startdir = VC_COMMAND_STARTDIR_FILE,
54
.command = BZR_CMD_DIFF_FILE,
58
.startdir = VC_COMMAND_STARTDIR_FILE,
59
.command = BZR_CMD_DIFF_DIR,
63
.startdir = VC_COMMAND_STARTDIR_FILE,
64
.command = BZR_CMD_REVERT_FILE,
68
.startdir = VC_COMMAND_STARTDIR_BASE,
69
.command = BZR_CMD_REVERT_DIR,
73
.startdir = VC_COMMAND_STARTDIR_FILE,
74
.command = BZR_CMD_STATUS,
78
.startdir = VC_COMMAND_STARTDIR_FILE,
79
.command = BZR_CMD_ADD,
83
.startdir = VC_COMMAND_STARTDIR_FILE,
84
.command = BZR_CMD_REMOVE,
88
.startdir = VC_COMMAND_STARTDIR_FILE,
89
.command = BZR_CMD_LOG_FILE,
93
.startdir = VC_COMMAND_STARTDIR_FILE,
94
.command = BZR_CMD_LOG_DIR,
98
.startdir = VC_COMMAND_STARTDIR_FILE,
99
.command = BZR_CMD_COMMIT,
103
.startdir = VC_COMMAND_STARTDIR_FILE,
104
.command = BZR_CMD_BLAME,
108
.startdir = VC_COMMAND_STARTDIR_FILE,
109
.command = BZR_CMD_SHOW,
113
.startdir = VC_COMMAND_STARTDIR_BASE,
114
.command = BZR_CMD_UPDATE,
121
get_base_dir(const gchar * path)
123
return find_subdir_path(path, ".bzr");
127
in_vc_bzr(const gchar * filename)
130
gchar *argv[] = { "bzr", "log", NULL, NULL };
133
gboolean ret = FALSE;
136
if (!find_dir(filename, ".bzr", TRUE))
139
if (g_file_test(filename, G_FILE_TEST_IS_DIR))
142
dir = g_path_get_dirname(filename);
143
base_name = g_path_get_basename(filename);
146
exit_code = execute_custom_command(dir, (const gchar **) argv, NULL, &std_output, NULL,
147
filename, NULL, NULL);
161
/* parse "bzr status --short" output, see "bzr help status-flags" for details */
163
get_commit_files_bzr(const gchar * dir)
176
gint pstatus = FIRST_CHAR;
179
gchar *base_dir = find_subdir_path(dir, ".bzr");
180
const gchar *start = NULL;
185
const char *argv[] = { "bzr", "status", "--short", NULL };
187
g_return_val_if_fail(base_dir, NULL);
189
execute_custom_command(base_dir, argv, NULL, &txt, NULL, base_dir, NULL, NULL);
203
else if (pstatus == FIRST_CHAR)
206
status = FILE_STATUS_ADDED;
208
status = FILE_STATUS_DELETED;
210
//else if (*p == 'R')
212
status = FILE_STATUS_UNKNOWN;
214
//else if (*p == 'C')
216
//else if (*p == 'P')
217
pstatus = SECOND_CHAR;
219
else if (pstatus == SECOND_CHAR)
222
status = FILE_STATUS_ADDED;
224
status = FILE_STATUS_DELETED;
226
//else if (*p == 'K')
228
status = FILE_STATUS_MODIFIED;
229
pstatus = THIRD_CHAR;
231
else if (pstatus == THIRD_CHAR)
233
// execute bit change
235
pstatus = SKIP_SPACE;
237
else if (pstatus == SKIP_SPACE)
239
if (*p == ' ' || *p == '\t')
248
else if (pstatus == FILE_NAME)
252
if (status != FILE_STATUS_UNKNOWN)
254
base_name = g_malloc0(p - start + 1);
255
memcpy(base_name, start, p - start);
256
filename = g_build_filename(base_dir, base_name, NULL);
258
item = g_new(CommitItem, 1);
259
item->status = status;
260
item->path = filename;
261
ret = g_slist_append(ret, item);
263
pstatus = FIRST_CHAR;
274
.commands = commands,
276
.get_base_dir = get_base_dir,
278
.get_commit_files = get_commit_files_bzr,