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 *HG_CMD_DIFF_FILE[] = { "hg", "diff", ABS_FILENAME, NULL };
38
static const gchar *HG_CMD_DIFF_DIR[] = { "hg", "diff", ABS_DIRNAME, NULL };
39
static const gchar *HG_CMD_REVERT_FILE[] = { "hg", "revert", BASENAME, NULL };
40
static const gchar *HG_CMD_REVERT_DIR[] = { "hg", "revert", BASE_DIRNAME, NULL };
41
static const gchar *HG_CMD_STATUS[] = { "hg", "status", NULL };
42
static const gchar *HG_CMD_ADD[] = { "hg", "add", BASENAME, NULL };
43
static const gchar *HG_CMD_REMOVE[] = { "hg", "remove", BASENAME, NULL };
44
static const gchar *HG_CMD_LOG_FILE[] = { "hg", "log", BASENAME, NULL };
45
static const gchar *HG_CMD_LOG_DIR[] = { "hg", "log", ABS_DIRNAME, NULL };
46
static const gchar *HG_CMD_COMMIT[] = { "hg", "commit", "-m", MESSAGE, FILE_LIST, NULL };
47
static const gchar *HG_CMD_BLAME[] = { "hg", "annotate", BASENAME, NULL };
48
static const gchar *HG_CMD_SHOW[] = { "hg", "cat", BASENAME, NULL };
49
static const gchar *HG_CMD_UPDATE[] = { "hg", "pull", CMD_SEPARATOR, "hg", "update", NULL };
51
static const VC_COMMAND commands[] = {
53
.startdir = VC_COMMAND_STARTDIR_FILE,
54
.command = HG_CMD_DIFF_FILE,
58
.startdir = VC_COMMAND_STARTDIR_FILE,
59
.command = HG_CMD_DIFF_DIR,
63
.startdir = VC_COMMAND_STARTDIR_FILE,
64
.command = HG_CMD_REVERT_FILE,
68
.startdir = VC_COMMAND_STARTDIR_BASE,
69
.command = HG_CMD_REVERT_DIR,
73
.startdir = VC_COMMAND_STARTDIR_FILE,
74
.command = HG_CMD_STATUS,
78
.startdir = VC_COMMAND_STARTDIR_FILE,
79
.command = HG_CMD_ADD,
83
.startdir = VC_COMMAND_STARTDIR_FILE,
84
.command = HG_CMD_REMOVE,
88
.startdir = VC_COMMAND_STARTDIR_FILE,
89
.command = HG_CMD_LOG_FILE,
93
.startdir = VC_COMMAND_STARTDIR_FILE,
94
.command = HG_CMD_LOG_DIR,
98
.startdir = VC_COMMAND_STARTDIR_FILE,
99
.command = HG_CMD_COMMIT,
103
.startdir = VC_COMMAND_STARTDIR_FILE,
104
.command = HG_CMD_BLAME,
108
.startdir = VC_COMMAND_STARTDIR_FILE,
109
.command = HG_CMD_SHOW,
113
.startdir = VC_COMMAND_STARTDIR_BASE,
114
.command = HG_CMD_UPDATE,
120
get_base_dir(const gchar * path)
122
return find_subdir_path(path, ".hg");
126
in_vc_hg(const gchar * filename)
129
gchar *argv[] = { "hg", "status", "-mac", NULL, NULL };
132
gboolean ret = FALSE;
135
if (!find_dir(filename, ".hg", TRUE))
138
if (g_file_test(filename, G_FILE_TEST_IS_DIR))
141
dir = g_path_get_dirname(filename);
142
base_name = g_path_get_basename(filename);
145
exit_code = execute_custom_command(dir, (const gchar **) argv, NULL, &std_output, NULL,
160
get_commit_files_hg(const gchar * dir)
171
gint pstatus = FIRST_CHAR;
174
gchar *base_dir = find_subdir_path(dir, ".hg");
175
const gchar *start = NULL;
180
const char *argv[] = { "hg", "status", NULL };
182
g_return_val_if_fail(base_dir, NULL);
184
execute_custom_command(base_dir, argv, NULL, &txt, NULL, base_dir, NULL, NULL);
198
else if (pstatus == FIRST_CHAR)
201
status = FILE_STATUS_ADDED;
203
status = FILE_STATUS_DELETED;
205
status = FILE_STATUS_MODIFIED;
207
status = FILE_STATUS_UNKNOWN;
208
pstatus = SKIP_SPACE;
210
else if (pstatus == SKIP_SPACE)
212
if (*p == ' ' || *p == '\t')
221
else if (pstatus == FILE_NAME)
225
if (status != FILE_STATUS_UNKNOWN)
227
base_name = g_malloc0(p - start + 1);
228
memcpy(base_name, start, p - start);
229
filename = g_build_filename(base_dir, base_name, NULL);
231
item = g_new(CommitItem, 1);
232
item->status = status;
233
item->path = filename;
234
ret = g_slist_append(ret, item);
236
pstatus = FIRST_CHAR;
247
.commands = commands,
249
.get_base_dir = get_base_dir,
251
.get_commit_files = get_commit_files_hg,