~ubuntu-branches/ubuntu/trusty/thunar-vcs-plugin/trusty

« back to all changes in this revision

Viewing changes to tvp-svn-helper/tsh-commit.c

  • Committer: Bazaar Package Importer
  • Author(s): Yves-Alexis Perez
  • Date: 2011-08-08 22:57:33 UTC
  • Revision ID: james.westby@ubuntu.com-20110808225733-mh2lhudn627hcmxu
Tags: upstream-0.1.4
ImportĀ upstreamĀ versionĀ 0.1.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*-
 
2
 * Copyright (C) 2007-2011  Peter de Ridder <peter@xfce.org>
 
3
 *
 
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.
 
8
 *
 
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.
 
13
 *
 
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
 
17
 */
 
18
 
 
19
#ifdef HAVE_CONFIG_H
 
20
#include <config.h>
 
21
#endif
 
22
 
 
23
#ifdef HAVE_STDLIB_H
 
24
#include <stdlib.h>
 
25
#endif
 
26
 
 
27
#include <glib.h>
 
28
#include <gtk/gtk.h>
 
29
 
 
30
#include <libxfce4util/libxfce4util.h>
 
31
 
 
32
#include <subversion-1/svn_client.h>
 
33
#include <subversion-1/svn_pools.h>
 
34
 
 
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"
 
40
 
 
41
#include "tsh-commit.h"
 
42
 
 
43
struct thread_args {
 
44
        svn_client_ctx_t *ctx;
 
45
        apr_pool_t *pool;
 
46
        TshNotifyDialog *dialog;
 
47
  GSList *files;
 
48
};
 
49
 
 
50
static gpointer commit_thread (gpointer user_data)
 
51
{
 
52
  struct thread_args *args = user_data;
 
53
  gboolean result = TRUE;
 
54
  svn_error_t *err;
 
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;
 
61
  GSList *iter;
 
62
  GSList *delete = NULL;
 
63
  //GSList *reverse_start = NULL, *reverse_end = NULL;
 
64
  gint delete_size = 0;
 
65
  gint size = 0;
 
66
  gint size_indirect = 0;
 
67
  gboolean recursive = TRUE;
 
68
  gchar *error_str;
 
69
  gchar *message;
 
70
  gchar buffer[256];
 
71
 
 
72
  g_free (args);
 
73
 
 
74
  subpool = svn_pool_create (pool);
 
75
 
 
76
  for (iter = files; result && iter; iter = g_slist_next (iter))
 
77
  {
 
78
    TshFileInfo *info;
 
79
    size_indirect++;
 
80
 
 
81
    info = iter->data;
 
82
 
 
83
    if (!(info->flags & TSH_FILE_INFO_INDIRECT))
 
84
    {
 
85
      if (!(info->flags & TSH_FILE_INFO_RECURSIVE))
 
86
        recursive = FALSE;
 
87
      size++;
 
88
      switch (info->status)
 
89
      {
 
90
        case TSH_FILE_STATUS_MISSING:
 
91
          delete_size++;
 
92
          delete = g_slist_prepend (delete, info);
 
93
          break;
 
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)))
 
96
          {
 
97
            error_str = tsh_strerror(err);
 
98
            gdk_threads_enter();
 
99
            tsh_notify_dialog_add(dialog, _("Failed"), error_str, NULL);
 
100
            gdk_threads_leave();
 
101
            g_free(error_str);
 
102
 
 
103
            svn_error_clear(err);
 
104
            result = FALSE;//FIXME: needed ??
 
105
          }
 
106
          break;
 
107
        default:
 
108
          break;
 
109
      }
 
110
    }
 
111
  }
 
112
 
 
113
  if (result && delete_size)
 
114
  {
 
115
    paths = apr_array_make (subpool, delete_size, sizeof (const char *));
 
116
 
 
117
    for (iter = delete; iter; iter = g_slist_next (iter))
 
118
    {
 
119
      TshFileInfo *info = iter->data;
 
120
      APR_ARRAY_PUSH (paths, const char *) = info->path;
 
121
    }
 
122
 
 
123
    if ((err = svn_client_delete3(NULL, paths, FALSE, FALSE, NULL, ctx, subpool)))
 
124
    {
 
125
      svn_pool_destroy (subpool);
 
126
 
 
127
      error_str = tsh_strerror(err);
 
128
      gdk_threads_enter();
 
129
      tsh_notify_dialog_add(dialog, _("Failed"), error_str, NULL);
 
130
      gdk_threads_leave();
 
131
      g_free(error_str);
 
132
 
 
133
      svn_error_clear(err);
 
134
      result = FALSE;//FIXME: needed ??
 
135
    }
 
136
  }
 
137
 
 
138
  g_slist_free (delete);
 
139
 
 
140
  svn_pool_destroy (subpool);
 
141
 
 
142
  /* check if an error occurred in add commands */
 
143
  if (result)//FIXME: needed ??
 
144
  {
 
145
    subpool = svn_pool_create (pool);
 
146
 
 
147
    if(recursive && size)
 
148
    {
 
149
      paths = apr_array_make (subpool, size, sizeof (const char *));
 
150
 
 
151
      for (iter = files; iter; iter = g_slist_next (iter))
 
152
      {
 
153
        TshFileInfo *info = iter->data;
 
154
        if (!(info->flags & TSH_FILE_INFO_INDIRECT))
 
155
        {
 
156
          APR_ARRAY_PUSH (paths, const char *) = info->path;
 
157
        }
 
158
      }
 
159
    }
 
160
    else if(size_indirect)
 
161
    {
 
162
      /* Set recursive to false if it wasn't already, FIXME: needed?? */
 
163
      recursive = FALSE;
 
164
 
 
165
      paths = apr_array_make (subpool, size_indirect, sizeof (const char *));
 
166
 
 
167
      for (iter = files; iter; iter = g_slist_next (iter))
 
168
      {
 
169
        TshFileInfo *info = iter->data;
 
170
        APR_ARRAY_PUSH (paths, const char *) = info->path;
 
171
      }
 
172
    }
 
173
    else
 
174
    {
 
175
      paths = apr_array_make (subpool, 1, sizeof (const char *));
 
176
 
 
177
      APR_ARRAY_PUSH (paths, const char *) = ""; // current directory
 
178
    }
 
179
 
 
180
    if ((err = svn_client_commit4(&commit_info, paths, recursive?svn_depth_infinity:svn_depth_empty, FALSE, FALSE, NULL, NULL, ctx, subpool)))
 
181
    {
 
182
      svn_pool_destroy (subpool);
 
183
 
 
184
      error_str = tsh_strerror(err);
 
185
      gdk_threads_enter();
 
186
      tsh_notify_dialog_add(dialog, _("Failed"), error_str, NULL);
 
187
      tsh_notify_dialog_done (dialog);
 
188
      gdk_threads_leave();
 
189
      g_free(error_str);
 
190
 
 
191
      svn_error_clear(err);
 
192
      tsh_reset_cancel();
 
193
      return GINT_TO_POINTER (FALSE);
 
194
    }
 
195
 
 
196
    if(SVN_IS_VALID_REVNUM(commit_info->revision))
 
197
    {
 
198
      g_snprintf(buffer, 256, _("At revision: %ld"), commit_info->revision);
 
199
      message = buffer;
 
200
    }
 
201
    else
 
202
    {
 
203
      message = _("Nothing to do");
 
204
    }
 
205
 
 
206
    svn_pool_destroy (subpool);
 
207
  }
 
208
 
 
209
  gdk_threads_enter();
 
210
  if (result)
 
211
    tsh_notify_dialog_add(dialog, _("Completed"), message, NULL);
 
212
  tsh_notify_dialog_done (dialog);
 
213
  gdk_threads_leave();
 
214
 
 
215
  tsh_reset_cancel();
 
216
  return GINT_TO_POINTER (result);
 
217
}
 
218
 
 
219
GThread *tsh_commit (gchar **files, svn_client_ctx_t *ctx, apr_pool_t *pool)
 
220
{
 
221
        GtkWidget *dialog;
 
222
        struct thread_args *args;
 
223
  GSList *file_list;
 
224
 
 
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)
 
227
  {
 
228
    gtk_widget_destroy (dialog);
 
229
    return NULL;
 
230
  }
 
231
  g_strfreev (files);
 
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);
 
234
 
 
235
  if(!file_list)
 
236
    return NULL;
 
237
 
 
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);
 
241
 
 
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);
 
244
 
 
245
        ctx->notify_func2 = tsh_notify_func2;
 
246
        ctx->notify_baton2 = dialog;
 
247
 
 
248
        args = g_malloc (sizeof (struct thread_args));
 
249
        args->ctx = ctx;
 
250
        args->pool = pool;
 
251
        args->dialog = TSH_NOTIFY_DIALOG (dialog);
 
252
        args->files = file_list;
 
253
 
 
254
        return g_thread_create (commit_thread, args, TRUE, NULL);
 
255
}
 
256