2
* Copyright (C) 2007-2011 Peter de Ridder <peter@xfce.org>
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation; either version 2 of the License, or
7
* (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30
#include <libxfce4util/libxfce4util.h>
32
#include <subversion-1/svn_client.h>
33
#include <subversion-1/svn_pools.h>
35
#include "tsh-common.h"
36
#include "tsh-dialog-common.h"
37
#include "tsh-file-selection-dialog.h"
38
#include "tsh-notify-dialog.h"
39
#include "tsh-log-message-dialog.h"
41
#include "tsh-commit.h"
44
svn_client_ctx_t *ctx;
46
TshNotifyDialog *dialog;
50
static gpointer commit_thread (gpointer user_data)
52
struct thread_args *args = user_data;
53
gboolean result = TRUE;
55
svn_commit_info_t *commit_info;
56
apr_array_header_t *paths;
57
svn_client_ctx_t *ctx = args->ctx;
58
apr_pool_t *subpool, *pool = args->pool;
59
TshNotifyDialog *dialog = args->dialog;
60
GSList *files = args->files;
62
GSList *delete = NULL;
63
//GSList *reverse_start = NULL, *reverse_end = NULL;
66
gint size_indirect = 0;
67
gboolean recursive = TRUE;
74
subpool = svn_pool_create (pool);
76
for (iter = files; result && iter; iter = g_slist_next (iter))
83
if (!(info->flags & TSH_FILE_INFO_INDIRECT))
85
if (!(info->flags & TSH_FILE_INFO_RECURSIVE))
90
case TSH_FILE_STATUS_MISSING:
92
delete = g_slist_prepend (delete, info);
94
case TSH_FILE_STATUS_UNVERSIONED:
95
if ((err = svn_client_add4(info->path, (info->flags&TSH_FILE_INFO_RECURSIVE)?svn_depth_infinity:svn_depth_empty, FALSE, FALSE, FALSE, ctx, subpool)))
97
error_str = tsh_strerror(err);
99
tsh_notify_dialog_add(dialog, _("Failed"), error_str, NULL);
103
svn_error_clear(err);
104
result = FALSE;//FIXME: needed ??
113
if (result && delete_size)
115
paths = apr_array_make (subpool, delete_size, sizeof (const char *));
117
for (iter = delete; iter; iter = g_slist_next (iter))
119
TshFileInfo *info = iter->data;
120
APR_ARRAY_PUSH (paths, const char *) = info->path;
123
if ((err = svn_client_delete3(NULL, paths, FALSE, FALSE, NULL, ctx, subpool)))
125
svn_pool_destroy (subpool);
127
error_str = tsh_strerror(err);
129
tsh_notify_dialog_add(dialog, _("Failed"), error_str, NULL);
133
svn_error_clear(err);
134
result = FALSE;//FIXME: needed ??
138
g_slist_free (delete);
140
svn_pool_destroy (subpool);
142
/* check if an error occurred in add commands */
143
if (result)//FIXME: needed ??
145
subpool = svn_pool_create (pool);
147
if(recursive && size)
149
paths = apr_array_make (subpool, size, sizeof (const char *));
151
for (iter = files; iter; iter = g_slist_next (iter))
153
TshFileInfo *info = iter->data;
154
if (!(info->flags & TSH_FILE_INFO_INDIRECT))
156
APR_ARRAY_PUSH (paths, const char *) = info->path;
160
else if(size_indirect)
162
/* Set recursive to false if it wasn't already, FIXME: needed?? */
165
paths = apr_array_make (subpool, size_indirect, sizeof (const char *));
167
for (iter = files; iter; iter = g_slist_next (iter))
169
TshFileInfo *info = iter->data;
170
APR_ARRAY_PUSH (paths, const char *) = info->path;
175
paths = apr_array_make (subpool, 1, sizeof (const char *));
177
APR_ARRAY_PUSH (paths, const char *) = ""; // current directory
180
if ((err = svn_client_commit4(&commit_info, paths, recursive?svn_depth_infinity:svn_depth_empty, FALSE, FALSE, NULL, NULL, ctx, subpool)))
182
svn_pool_destroy (subpool);
184
error_str = tsh_strerror(err);
186
tsh_notify_dialog_add(dialog, _("Failed"), error_str, NULL);
187
tsh_notify_dialog_done (dialog);
191
svn_error_clear(err);
193
return GINT_TO_POINTER (FALSE);
196
if(SVN_IS_VALID_REVNUM(commit_info->revision))
198
g_snprintf(buffer, 256, _("At revision: %ld"), commit_info->revision);
203
message = _("Nothing to do");
206
svn_pool_destroy (subpool);
211
tsh_notify_dialog_add(dialog, _("Completed"), message, NULL);
212
tsh_notify_dialog_done (dialog);
216
return GINT_TO_POINTER (result);
219
GThread *tsh_commit (gchar **files, svn_client_ctx_t *ctx, apr_pool_t *pool)
222
struct thread_args *args;
225
dialog = tsh_file_selection_dialog_new (_("Commit"), NULL, 0, files, TSH_FILE_SELECTION_FLAG_RECURSIVE|TSH_FILE_SELECTION_FLAG_MODIFIED|TSH_FILE_SELECTION_FLAG_UNVERSIONED, ctx, pool);
226
if(gtk_dialog_run (GTK_DIALOG (dialog)) != GTK_RESPONSE_OK)
228
gtk_widget_destroy (dialog);
232
file_list = tsh_file_selection_dialog_get_file_info_by_status (TSH_FILE_SELECTION_DIALOG (dialog), TSH_FILE_STATUS_INVALID, TRUE);
233
gtk_widget_destroy (dialog);
238
dialog = tsh_notify_dialog_new (_("Commit"), NULL, 0);
239
g_signal_connect(dialog, "cancel-clicked", tsh_cancel, NULL);
240
tsh_dialog_start (GTK_DIALOG (dialog), TRUE);
242
ctx->log_msg_func2 = tsh_log_msg_func2;
243
ctx->log_msg_baton2 = tsh_log_message_dialog_new (_("Commit Message"), GTK_WINDOW (dialog), GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT);
245
ctx->notify_func2 = tsh_notify_func2;
246
ctx->notify_baton2 = dialog;
248
args = g_malloc (sizeof (struct thread_args));
251
args->dialog = TSH_NOTIFY_DIALOG (dialog);
252
args->files = file_list;
254
return g_thread_create (commit_thread, args, TRUE, NULL);