Updated Spanish translation
[anjuta-git-plugin.git] / plugins / cvs-plugin / cvs-interface.c
blob7107a6558c0d7c5a916a3d556939e73909205ac7
1 /*
2 * cvs-interface.c (c) 2005 Johannes Schmid
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Library General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 #include <libanjuta/anjuta-debug.h>
21 #include <libgnomevfs/gnome-vfs.h>
22 #include "cvs-execute.h"
23 #include "cvs-callbacks.h"
24 #include "cvs-interface.h"
25 #include "plugin.h"
26 #include "libgen.h"
28 static gchar* create_cvs_command_with_cvsroot(AnjutaPreferences* prefs,
29 const gchar* action,
30 const gchar* command_options,
31 const gchar* command_arguments,
32 const gchar* cvsroot)
34 gchar* cvs;
35 gchar* global_options = NULL;
36 gboolean ignorerc;
37 gint compression;
38 gchar* command;
39 /* command global_options cvsroot action command_options command_arguments */
40 gchar* CVS_FORMAT = "%s %s %s %s %s %s";
42 g_return_val_if_fail (prefs != NULL, NULL);
43 g_return_val_if_fail (action != NULL, NULL);
44 g_return_val_if_fail (command_options != NULL, NULL);
45 g_return_val_if_fail (command_arguments != NULL, NULL);
47 cvs = anjuta_preferences_get(prefs, "cvs.path");
48 compression = anjuta_preferences_get_int(prefs, "cvs.compression");
49 ignorerc = anjuta_preferences_get_int(prefs, "cvs.ignorerc");
50 if (compression && ignorerc)
51 global_options = g_strdup_printf("-f -z%d", compression);
52 else if (compression)
53 global_options = g_strdup_printf("-z%d", compression);
54 else if (ignorerc)
55 global_options = g_strdup("-f");
56 else
57 global_options = g_strdup("");
58 if (cvsroot == NULL)
60 cvsroot = "";
62 command = g_strdup_printf(CVS_FORMAT, cvs, global_options, cvsroot, action,
63 command_options, command_arguments);
64 g_free (cvs);
65 g_free (global_options);
67 return command;
70 inline static gchar* create_cvs_command(AnjutaPreferences* prefs,
71 const gchar* action,
72 const gchar* command_options,
73 const gchar* command_arguments)
75 return create_cvs_command_with_cvsroot(prefs, action, command_options,
76 command_arguments, NULL);
79 static void add_option(gboolean value, GString* options, const gchar* argument)
81 if (value)
83 g_string_append(options, " ");
84 g_string_append(options, argument);
88 static gboolean is_directory(const gchar* filename)
90 GnomeVFSFileInfo info;
91 GnomeVFSResult result;
93 result = gnome_vfs_get_file_info(filename, &info, GNOME_VFS_FILE_INFO_DEFAULT);
94 if (result == GNOME_VFS_OK)
96 if (info.type == GNOME_VFS_FILE_TYPE_DIRECTORY)
97 return TRUE;
98 else
99 return FALSE;
101 else
102 return FALSE;
105 void anjuta_cvs_add (AnjutaPlugin *obj, const gchar* filename,
106 gboolean binary, GError **err)
108 gchar* command;
109 CVSPlugin* plugin = ANJUTA_PLUGIN_CVS (obj);
110 GString* options = g_string_new("");
111 gchar* file = g_strdup(filename);
113 add_option(binary, options, "-kb");
116 command = create_cvs_command(
117 anjuta_shell_get_preferences (ANJUTA_PLUGIN(plugin)->shell,
118 NULL), "add", options->str, basename(file));
120 cvs_execute(plugin, command, dirname(file));
121 g_free(command);
122 g_free(file);
123 g_string_free(options, TRUE);
126 void anjuta_cvs_commit (AnjutaPlugin *obj, const gchar* filename, const gchar* log,
127 const gchar* rev, gboolean recurse, GError **err)
129 GString* options = g_string_new("");
130 CVSPlugin* plugin = ANJUTA_PLUGIN_CVS (obj);
131 gchar* command;
133 if (strlen(log))
134 g_string_printf(options, "-m '%s'", log);
135 else
136 g_string_printf(options, "-m 'no log message'");
138 if (strlen(rev))
140 g_string_append_printf(options, " -r %s", rev);
142 add_option(!recurse, options, "-l");
144 if (!is_directory(filename))
146 gchar* file = g_strdup(filename);
147 command = create_cvs_command(anjuta_shell_get_preferences (ANJUTA_PLUGIN(plugin)->shell,
148 NULL), "commit", options->str, basename(file));
149 cvs_execute(plugin, command, dirname(file));
150 g_free(file);
152 else
154 gchar* dir = g_strdup(filename);
155 command = create_cvs_command(anjuta_shell_get_preferences (ANJUTA_PLUGIN(plugin)->shell,
156 NULL), "commit", options->str, "");
157 cvs_execute(plugin, command, dir);
158 g_free(dir);
160 g_free(command);
161 g_string_free(options, TRUE);
164 void anjuta_cvs_diff (AnjutaPlugin *obj, const gchar* filename, const gchar* rev,
165 gboolean recurse, gboolean patch_style, gboolean unified, GError **err)
167 GString* options = g_string_new("");
168 CVSPlugin* plugin = ANJUTA_PLUGIN_CVS (obj);
169 gchar* command;
171 if (strlen(rev))
173 g_string_append_printf(options, " -r %s", rev);
175 add_option(!recurse, options, "-l");
176 add_option(unified, options, "-u");
178 if (!is_directory(filename))
180 gchar* file = g_strdup(filename);
181 command = create_cvs_command(anjuta_shell_get_preferences (ANJUTA_PLUGIN(plugin)->shell,
182 NULL), "diff", options->str, basename(file));
183 cvs_execute_diff(plugin, command, dirname(file));
185 else
187 gchar* dir = g_strdup(filename);
188 command = create_cvs_command(anjuta_shell_get_preferences (ANJUTA_PLUGIN(plugin)->shell,
189 NULL), "diff", options->str, "");
190 cvs_execute_diff(plugin, command, dir);
191 g_free(dir);
193 g_free(command);
194 g_string_free(options, TRUE);
197 void anjuta_cvs_log (AnjutaPlugin *obj, const gchar* filename, gboolean recurse, gboolean verbose, GError **err)
199 GString* options = g_string_new("");
200 CVSPlugin* plugin = ANJUTA_PLUGIN_CVS (obj);
201 gchar* command;
203 add_option(!recurse, options, "-l");
204 add_option(!verbose, options, "-h");
206 if (!is_directory(filename))
208 gchar* file = g_strdup(filename);
209 command = create_cvs_command(anjuta_shell_get_preferences (ANJUTA_PLUGIN(plugin)->shell,
210 NULL), "log", options->str, basename(file));
211 cvs_execute_log(plugin, command, dirname(file));
212 g_free(file);
214 else
216 gchar* dir = g_strdup(filename);
217 command = create_cvs_command(anjuta_shell_get_preferences (ANJUTA_PLUGIN(plugin)->shell,
218 NULL), "log", options->str, "");
219 cvs_execute_log(plugin, command, dir);
220 g_free(dir);
222 g_free(command);
223 g_string_free(options, TRUE);
226 void anjuta_cvs_remove (AnjutaPlugin *obj, const gchar* filename, GError **err)
228 gchar* command;
229 CVSPlugin* plugin = ANJUTA_PLUGIN_CVS (obj);
230 GString* options = g_string_new("");
231 gchar* file = g_strdup(filename);
233 command = create_cvs_command(
234 anjuta_shell_get_preferences (ANJUTA_PLUGIN(plugin)->shell,
235 NULL), "remove", options->str, basename(file));
237 cvs_execute(plugin, command, dirname(file));
238 g_free(file);
239 g_free(command);
240 g_string_free(options, TRUE);
243 void anjuta_cvs_status (AnjutaPlugin *obj, const gchar* filename, gboolean recurse, gboolean verbose, GError **err)
245 gchar* command;
246 CVSPlugin* plugin = ANJUTA_PLUGIN_CVS (obj);
247 GString* options = g_string_new("");
249 add_option(!recurse, options, "-l");
250 add_option(verbose, options, "-v");
252 if (!is_directory(filename))
254 gchar* file = g_strdup(filename);
255 command = create_cvs_command(anjuta_shell_get_preferences (ANJUTA_PLUGIN(plugin)->shell,
256 NULL), "status", options->str, basename(file));
257 cvs_execute_status(plugin, command, dirname(file));
258 g_free(file);
260 else
262 gchar* dir = g_strdup(filename);
263 command = create_cvs_command(anjuta_shell_get_preferences (ANJUTA_PLUGIN(plugin)->shell,
264 NULL), "status", options->str, "");
265 cvs_execute_status(plugin, command, dir);
266 g_free(dir);
268 g_free(command);
269 g_string_free(options, TRUE);
272 void anjuta_cvs_update (AnjutaPlugin *obj, const gchar* filename, gboolean recurse,
273 gboolean prune, gboolean create, gboolean reset_sticky, const gchar* revision, GError **err)
275 GString* options = g_string_new("");
276 CVSPlugin* plugin = ANJUTA_PLUGIN_CVS (obj);
277 gchar* command;
279 add_option(!recurse, options, "-l");
280 add_option(prune, options, "-P");
281 add_option(create, options, "-d");
282 if (strlen(revision))
284 g_string_append_printf(options, " -r %s", revision);
286 else
288 add_option(reset_sticky, options, "-A");
291 if (!is_directory(filename))
293 gchar* file = g_strdup(filename);
294 command = create_cvs_command(anjuta_shell_get_preferences (ANJUTA_PLUGIN(plugin)->shell,
295 NULL), "update", options->str, basename(file));
296 cvs_execute(plugin, command, dirname(file));
297 g_free(file);
299 else
301 gchar* dir = g_strdup(filename);
302 command = create_cvs_command(anjuta_shell_get_preferences (ANJUTA_PLUGIN(plugin)->shell,
303 NULL), "update", options->str, "");
304 cvs_execute(plugin, command, dir);
306 g_free(command);
307 g_string_free(options, TRUE);
310 void anjuta_cvs_import (AnjutaPlugin *obj, const gchar* dir, const gchar* cvsroot,
311 const gchar* module, const gchar* vendor, const gchar* release,
312 const gchar* log, gint server_type, const gchar* username, const
313 gchar* password, GError** error)
315 gchar* cvs_command;
316 gchar* root;
317 GString* options = g_string_new("");
318 CVSPlugin* plugin = ANJUTA_PLUGIN_CVS (obj);
320 switch (server_type)
322 case SERVER_LOCAL:
324 root = g_strdup_printf("-d %s", cvsroot);
325 break;
327 case SERVER_EXTERN:
329 root = g_strdup_printf("-d:ext:%s@%s", username, cvsroot);
330 break;
332 case SERVER_PASSWORD:
334 root = g_strdup_printf("-d:pserver:%s:%s@%s",
335 username, password, cvsroot);
336 break;
338 default:
340 DEBUG_PRINT("Invalid cvs server type!");
341 g_string_free (options, TRUE);
342 return;
345 g_string_printf(options, "-m '%s'", log);
346 g_string_append_printf(options, " %s %s %s", module, vendor, release);
348 cvs_command = create_cvs_command_with_cvsroot(
349 anjuta_shell_get_preferences (ANJUTA_PLUGIN(plugin)->shell, NULL),
350 "import", options->str, "", root);
351 cvs_execute(plugin, cvs_command, dir);
353 g_string_free(options, TRUE);
354 g_free(cvs_command);