[Xfce4-commits] <thunar-vcs-plugin:thunarx-2> * tvp-git-helper/tgh-{add, reset}.c: Made chdir work correct. * tvp-git-helper/tgh-file-selection-dialog.[ch]: Don't use input files for git call since this gives the wrong results.

Peter de Ridder noreply at xfce.org
Sun Nov 29 19:04:20 CET 2009


Updating branch refs/heads/thunarx-2
         to 93e8e9f94d7e43f9cb927fd0a6e25ae69c662b9e (commit)
       from 5782267e5a5790db8521f9a671cd514b693fe582 (commit)

commit 93e8e9f94d7e43f9cb927fd0a6e25ae69c662b9e
Author: Peter de Ridder <peter at xfce.org>
Date:   Wed Oct 14 23:03:49 2009 +0200

    * tvp-git-helper/tgh-{add,reset}.c: Made chdir work correct.
    * tvp-git-helper/tgh-file-selection-dialog.[ch]: Don't use input files
      for git call since this gives the wrong results.

 tvp-git-helper/tgh-add.c                   |   14 +++++++++++++-
 tvp-git-helper/tgh-file-selection-dialog.c |   24 +++++-------------------
 tvp-git-helper/tgh-file-selection-dialog.h |    1 -
 tvp-git-helper/tgh-reset.c                 |   14 +++++++++++++-
 4 files changed, 31 insertions(+), 22 deletions(-)

diff --git a/tvp-git-helper/tgh-add.c b/tvp-git-helper/tgh-add.c
index dda5190..4b57046 100644
--- a/tvp-git-helper/tgh-add.c
+++ b/tvp-git-helper/tgh-add.c
@@ -112,7 +112,19 @@ gboolean tgh_add (gchar **files, GPid *pid)
 {
   GtkWidget *dialog;
 
-  dialog = tgh_file_selection_dialog_new (_("Add"), NULL, 0, files, TGH_FILE_SELECTION_FLAG_MODIFIED|TGH_FILE_SELECTION_FLAG_UNTRACKED);
+  if (files)
+    if (chdir(files[0]))
+    {
+      gchar *dirname = g_dirname (files[0]);
+      if (chdir(dirname))
+      {
+        g_free (dirname);
+        return FALSE;
+      }
+      g_free (dirname);
+    }
+
+  dialog = tgh_file_selection_dialog_new (_("Add"), NULL, 0, TGH_FILE_SELECTION_FLAG_MODIFIED|TGH_FILE_SELECTION_FLAG_UNTRACKED);
   if(gtk_dialog_run (GTK_DIALOG (dialog)) != GTK_RESPONSE_OK)
   {
     gtk_widget_destroy (dialog);
diff --git a/tvp-git-helper/tgh-file-selection-dialog.c b/tvp-git-helper/tgh-file-selection-dialog.c
index 0a954e5..387708c 100644
--- a/tvp-git-helper/tgh-file-selection-dialog.c
+++ b/tvp-git-helper/tgh-file-selection-dialog.c
@@ -54,6 +54,8 @@ struct _TghFileSelectionDialogClass
 
 G_DEFINE_TYPE (TghFileSelectionDialog, tgh_file_selection_dialog, GTK_TYPE_DIALOG)
 
+static gchar *argv[] = {"git", "status", NULL};
+
 static void
 tgh_file_selection_dialog_class_init (TghFileSelectionDialogClass *klass)
 {
@@ -141,11 +143,8 @@ static TghOutputParser* status_parser_new (GtkWidget *dialog)
 }
 
 GtkWidget*
-tgh_file_selection_dialog_new (const gchar *title, GtkWindow *parent, GtkDialogFlags flags, gchar **files, TghFileSelectionFlags selection_flags)
+tgh_file_selection_dialog_new (const gchar *title, GtkWindow *parent, GtkDialogFlags flags, TghFileSelectionFlags selection_flags)
 {
-  gsize length;
-  gint i;
-  gchar **argv;
   GPid pid;
   gint fd_out, fd_err;
   GError *error = NULL;
@@ -171,21 +170,6 @@ tgh_file_selection_dialog_new (const gchar *title, GtkWindow *parent, GtkDialogF
 
   dialog->flags = selection_flags;
 
-  length = 3;
-  if(files)
-    length += g_strv_length(files);
-
-  argv = g_new(gchar*, length);
-
-  argv[0] = "git";
-  argv[1] = "status";
-  argv[length-1] = NULL;
-
-  i = 2;
-  if(files)
-    while(*files)
-      argv[i++] = *files++;
-
   if(!g_spawn_async_with_pipes(NULL, argv, NULL, G_SPAWN_DO_NOT_REAP_CHILD | G_SPAWN_SEARCH_PATH, NULL, NULL, &pid, NULL, &fd_out, &fd_err, &error))
   {
     return FALSE;
@@ -295,6 +279,8 @@ status_parser_func(StatusParser *parser, gchar *line)
           break;
       }
 
+      g_debug ("%s, %d", line, add);
+
       if (add)
       {
         GtkTreeModel *model;
diff --git a/tvp-git-helper/tgh-file-selection-dialog.h b/tvp-git-helper/tgh-file-selection-dialog.h
index cb2ec9d..98b7b98 100644
--- a/tvp-git-helper/tgh-file-selection-dialog.h
+++ b/tvp-git-helper/tgh-file-selection-dialog.h
@@ -45,7 +45,6 @@ GType      tgh_file_selection_dialog_get_type   (void) G_GNUC_CONST G_GNUC_INTER
 GtkWidget* tgh_file_selection_dialog_new        (const gchar *title,
                                                  GtkWindow *parent,
                                                  GtkDialogFlags flags,
-                                                 gchar **files,
                                                  TghFileSelectionFlags selection_flags) G_GNUC_MALLOC G_GNUC_INTERNAL;
 
 gchar**    tgh_file_selection_dialog_get_files  (TghFileSelectionDialog *dialog);
diff --git a/tvp-git-helper/tgh-reset.c b/tvp-git-helper/tgh-reset.c
index 8b0bdc7..6daa82f 100644
--- a/tvp-git-helper/tgh-reset.c
+++ b/tvp-git-helper/tgh-reset.c
@@ -124,7 +124,19 @@ gboolean tgh_reset (gchar **files, GPid *pid)
 {
   GtkWidget *dialog;
 
-  dialog = tgh_file_selection_dialog_new (_("Reset"), NULL, 0, files, TGH_FILE_SELECTION_FLAG_ADDED);
+  if (files)
+    if (chdir(files[0]))
+    {
+      gchar *dirname = g_dirname (files[0]);
+      if (chdir(dirname))
+      {
+        g_free (dirname);
+        return FALSE;
+      }
+      g_free (dirname);
+    }
+
+  dialog = tgh_file_selection_dialog_new (_("Reset"), NULL, 0, TGH_FILE_SELECTION_FLAG_ADDED);
   if(gtk_dialog_run (GTK_DIALOG (dialog)) != GTK_RESPONSE_OK)
   {
     gtk_widget_destroy (dialog);



More information about the Xfce4-commits mailing list