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"
31 #include "pluginmacros.h"
35 extern GeanyData
*geany_data
;
38 static const gchar
*HG_CMD_DIFF_FILE
[] = { "hg", "diff", FILENAME
, NULL
};
39 static const gchar
*HG_CMD_DIFF_DIR
[] = { "hg", "diff", DIRNAME
, NULL
};
40 static const gchar
*HG_CMD_REVERT_FILE
[] = { "hg", "revert", BASE_FILENAME
, NULL
};
41 static const gchar
*HG_CMD_STATUS
[] = { "hg", "status", NULL
};
42 static const gchar
*HG_CMD_ADD
[] = { "hg", "add", BASE_FILENAME
, NULL
};
43 static const gchar
*HG_CMD_REMOVE
[] = { "hg", "remove", BASE_FILENAME
, NULL
};
44 static const gchar
*HG_CMD_LOG_FILE
[] = { "hg", "log", BASE_FILENAME
, NULL
};
45 static const gchar
*HG_CMD_LOG_DIR
[] = { "hg", "log", 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", BASE_FILENAME
, NULL
};
48 static const gchar
*HG_CMD_SHOW
[] = { "hg", "cat", BASE_FILENAME
, NULL
};
50 static void *HG_COMMANDS
[] = { HG_CMD_DIFF_FILE
,
64 in_vc_hg(const gchar
* filename
)
67 gchar
*argv
[] = { "hg", "status", "-mac", NULL
, NULL
};
73 if (!find_dir(filename
, ".hg", TRUE
))
76 if (g_file_test(filename
, G_FILE_TEST_IS_DIR
))
79 dir
= g_path_get_dirname(filename
);
80 base_name
= g_path_get_basename(filename
);
83 exit_code
= execute_custom_command((const gchar
**) argv
, NULL
, &std_output
, NULL
,
98 get_commit_files_hg(const gchar
* dir
)
109 gint pstatus
= FIRST_CHAR
;
112 gchar
*base_dir
= find_subdir_path(dir
, ".hg");
113 const gchar
*start
= NULL
;
118 const char *argv
[] = { "hg", "status", NULL
};
120 g_return_val_if_fail(base_dir
, NULL
);
122 execute_custom_command(argv
, NULL
, &txt
, NULL
, base_dir
, NULL
, NULL
);
136 else if (pstatus
== FIRST_CHAR
)
139 status
= FILE_STATUS_ADDED
;
141 status
= FILE_STATUS_DELETED
;
143 status
= FILE_STATUS_MODIFIED
;
145 status
= FILE_STATUS_UNKNOWN
;
146 pstatus
= SKIP_SPACE
;
148 else if (pstatus
== SKIP_SPACE
)
150 if (*p
== ' ' || *p
== '\t')
159 else if (pstatus
== FILE_NAME
)
163 if (status
!= FILE_STATUS_UNKNOWN
)
165 base_name
= g_malloc0(p
- start
+ 1);
166 memcpy(base_name
, start
, p
- start
);
167 filename
= g_build_filename(base_dir
, base_name
, NULL
);
169 item
= g_new(CommitItem
, 1);
170 item
->status
= status
;
171 item
->path
= filename
;
172 ret
= g_slist_append(ret
, item
);
174 pstatus
= FIRST_CHAR
;
184 VC_RECORD VC_HG
= { HG_COMMANDS
, NO_ENV
, "hg", in_vc_hg
, get_commit_files_hg
};