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.
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"
28 static gchar
* create_cvs_command_with_cvsroot(AnjutaPreferences
* prefs
,
30 const gchar
* command_options
,
31 const gchar
* command_arguments
,
35 gchar
* global_options
= NULL
;
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
);
53 global_options
= g_strdup_printf("-z%d", compression
);
55 global_options
= g_strdup("-f");
57 global_options
= g_strdup("");
62 command
= g_strdup_printf(CVS_FORMAT
, cvs
, global_options
, cvsroot
, action
,
63 command_options
, command_arguments
);
65 g_free (global_options
);
70 inline static gchar
* create_cvs_command(AnjutaPreferences
* prefs
,
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
)
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
)
105 void anjuta_cvs_add (AnjutaPlugin
*obj
, const gchar
* filename
,
106 gboolean binary
, GError
**err
)
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
));
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
);
134 g_string_printf(options
, "-m '%s'", log
);
136 g_string_printf(options
, "-m 'no log message'");
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
));
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
);
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
);
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
));
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
);
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
);
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
));
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
);
223 g_string_free(options
, TRUE
);
226 void anjuta_cvs_remove (AnjutaPlugin
*obj
, const gchar
* filename
, GError
**err
)
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
));
240 g_string_free(options
, TRUE
);
243 void anjuta_cvs_status (AnjutaPlugin
*obj
, const gchar
* filename
, gboolean recurse
, gboolean verbose
, GError
**err
)
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
));
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
);
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
);
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
);
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
));
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
);
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
)
317 GString
* options
= g_string_new("");
318 CVSPlugin
* plugin
= ANJUTA_PLUGIN_CVS (obj
);
324 root
= g_strdup_printf("-d %s", cvsroot
);
329 root
= g_strdup_printf("-d:ext:%s@%s", username
, cvsroot
);
332 case SERVER_PASSWORD
:
334 root
= g_strdup_printf("-d:pserver:%s:%s@%s",
335 username
, password
, cvsroot
);
340 DEBUG_PRINT("Invalid cvs server type!");
341 g_string_free (options
, TRUE
);
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
);