[Xfce4-commits] <thunar-vcs-plugin:master> Reduced the number of functions for in git stash

Peter de Ridder noreply at xfce.org
Sun Feb 27 20:38:11 CET 2011


Updating branch refs/heads/master
         to f18b89b5bbfa042d121f1e787e7c46532ef81072 (commit)
       from faed686f60fdd32f9ca540c94b75122bfa9b1dc9 (commit)

commit f18b89b5bbfa042d121f1e787e7c46532ef81072
Author: Peter de Ridder <peter at xfce.org>
Date:   Sun Feb 27 15:26:42 2011 +0100

    Reduced the number of functions for in git stash

 tvp-git-helper/tgh-stash.c |  159 ++++++--------------------------------------
 1 files changed, 20 insertions(+), 139 deletions(-)

diff --git a/tvp-git-helper/tgh-stash.c b/tvp-git-helper/tgh-stash.c
index 42ce18c..20404fa 100644
--- a/tvp-git-helper/tgh-stash.c
+++ b/tvp-git-helper/tgh-stash.c
@@ -55,9 +55,6 @@ static void child_exit (GPid pid, gint status, gpointer user_data)
   g_free (args);
 }
 
-static gchar *argv_list[] = {"git", "--no-pager", "stash", "list", NULL};
-static gchar *argv_clear[] = {"git", "--no-pager", "stash", "clear", NULL};
-
 static gboolean stash_list_spawn (TghStashDialog *dialog, GPid *pid)
 {
   GError *error = NULL;
@@ -65,7 +62,9 @@ static gboolean stash_list_spawn (TghStashDialog *dialog, GPid *pid)
   GIOChannel *chan_out, *chan_err;
   TghOutputParser *parser;
 
-  if(!g_spawn_async_with_pipes(NULL, argv_list, NULL, G_SPAWN_DO_NOT_REAP_CHILD | G_SPAWN_SEARCH_PATH, NULL, NULL, pid, NULL, &fd_out, &fd_err, &error))
+  static const gchar *argv[] = {"git", "--no-pager", "stash", "list", NULL};
+
+  if(!g_spawn_async_with_pipes(NULL, (gchar**)argv, NULL, G_SPAWN_DO_NOT_REAP_CHILD | G_SPAWN_SEARCH_PATH, NULL, NULL, pid, NULL, &fd_out, &fd_err, &error))
   {
     return FALSE;
   }
@@ -88,19 +87,19 @@ static gboolean stash_show_spawn (TghStashDialog *dialog, const gchar *name, GPi
   gint fd_out, fd_err;
   GIOChannel *chan_out, *chan_err;
   TghOutputParser *parser;
-  gchar **argv;
+  const gchar **argv;
 
-  argv = g_new (gchar*, 7);
+  argv = g_new (const gchar*, 7);
 
   argv[0] = "git";
   argv[1] = "--no-pager";
   argv[2] = "stash";
   argv[3] = "show";
   argv[4] = "--numstat";
-  argv[5] = (gchar*)name;
+  argv[5] = name;
   argv[6] = NULL;
 
-  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))
+  if (!g_spawn_async_with_pipes (NULL, (gchar**)argv, NULL, G_SPAWN_DO_NOT_REAP_CHILD | G_SPAWN_SEARCH_PATH, NULL, NULL, pid, NULL, &fd_out, &fd_err, &error))
   {
     g_free (argv);
     return FALSE;
@@ -119,146 +118,26 @@ static gboolean stash_show_spawn (TghStashDialog *dialog, const gchar *name, GPi
   return TRUE;
 }
 
-static gboolean stash_save_spawn (TghStashDialog *dialog, const gchar *name, GPid *pid)
+static gboolean stash_action_spawn (TghStashDialog *dialog, const gchar *action, const gchar *name, GPid *pid)
 {
   GError *error = NULL;
   gint fd_err;
   GIOChannel *chan_err;
   TghOutputParser *parser;
-  gchar **argv;
+  const gchar **argv;
   struct exit_args *args;
 
-  argv = g_new (gchar*, 7);
+  argv = g_new (const gchar*, 7);
 
   argv[0] = "git";
   argv[1] = "--no-pager";
   argv[2] = "stash";
-  argv[3] = "save";
+  argv[3] = action;
   argv[4] = "-q";
-  argv[5] = (gchar*)name;
+  argv[5] = name;
   argv[6] = NULL;
 
-  if (!g_spawn_async_with_pipes (NULL, argv, NULL, G_SPAWN_DO_NOT_REAP_CHILD | G_SPAWN_SEARCH_PATH, NULL, NULL, pid, NULL, NULL, &fd_err, &error))
-  {
-    g_free (argv);
-    return FALSE;
-  }
-  g_free (argv);
-
-  parser = tgh_error_parser_new (GTK_WIDGET (dialog));
-
-  args = g_new (struct exit_args, 1);
-  args->parser = parser;
-  args->dialog = dialog;
-
-  g_child_watch_add(*pid, (GChildWatchFunc)child_exit, args);
-
-  chan_err = g_io_channel_unix_new (fd_err);
-  g_io_add_watch (chan_err, G_IO_IN|G_IO_HUP, (GIOFunc)tgh_parse_output_func, parser);
-
-  return TRUE;
-}
-
-static gboolean stash_apply_spawn (TghStashDialog *dialog, const gchar *name, GPid *pid)
-{
-  GError *error = NULL;
-  gint fd_err;
-  GIOChannel *chan_err;
-  TghOutputParser *parser;
-  gchar **argv;
-  struct exit_args *args;
-
-  argv = g_new (gchar*, 7);
-
-  argv[0] = "git";
-  argv[1] = "--no-pager";
-  argv[2] = "stash";
-  argv[3] = "apply";
-  argv[4] = "-q";
-  argv[5] = (gchar*)name;
-  argv[6] = NULL;
-
-  if (!g_spawn_async_with_pipes (NULL, argv, NULL, G_SPAWN_DO_NOT_REAP_CHILD | G_SPAWN_SEARCH_PATH, NULL, NULL, pid, NULL, NULL, &fd_err, &error))
-  {
-    g_free (argv);
-    return FALSE;
-  }
-  g_free (argv);
-
-  parser = tgh_error_parser_new (GTK_WIDGET (dialog));
-
-  args = g_new (struct exit_args, 1);
-  args->parser = parser;
-  args->dialog = dialog;
-
-  g_child_watch_add(*pid, (GChildWatchFunc)child_exit, args);
-
-  chan_err = g_io_channel_unix_new (fd_err);
-  g_io_add_watch (chan_err, G_IO_IN|G_IO_HUP, (GIOFunc)tgh_parse_output_func, parser);
-
-  return TRUE;
-}
-
-static gboolean stash_pop_spawn (TghStashDialog *dialog, const gchar *name, GPid *pid)
-{
-  GError *error = NULL;
-  gint fd_err;
-  GIOChannel *chan_err;
-  TghOutputParser *parser;
-  gchar **argv;
-  struct exit_args *args;
-
-  argv = g_new (gchar*, 7);
-
-  argv[0] = "git";
-  argv[1] = "--no-pager";
-  argv[2] = "stash";
-  argv[3] = "pop";
-  argv[4] = "-q";
-  argv[5] = (gchar*)name;
-  argv[6] = NULL;
-
-  if (!g_spawn_async_with_pipes (NULL, argv, NULL, G_SPAWN_DO_NOT_REAP_CHILD | G_SPAWN_SEARCH_PATH, NULL, NULL, pid, NULL, NULL, &fd_err, &error))
-  {
-    g_free (argv);
-    return FALSE;
-  }
-  g_free (argv);
-
-  parser = tgh_error_parser_new (GTK_WIDGET (dialog));
-
-  args = g_new (struct exit_args, 1);
-  args->parser = parser;
-  args->dialog = dialog;
-
-  g_child_watch_add(*pid, (GChildWatchFunc)child_exit, args);
-
-  chan_err = g_io_channel_unix_new (fd_err);
-  g_io_add_watch (chan_err, G_IO_IN|G_IO_HUP, (GIOFunc)tgh_parse_output_func, parser);
-
-  return TRUE;
-}
-
-static gboolean stash_drop_spawn (TghStashDialog *dialog, const gchar *name, GPid *pid)
-{
-  GError *error = NULL;
-  gint fd_err;
-  GIOChannel *chan_err;
-  TghOutputParser *parser;
-  gchar **argv;
-  struct exit_args *args;
-
-  argv = g_new (gchar*, 7);
-
-  argv[0] = "git";
-  argv[1] = "--no-pager";
-  argv[2] = "stash";
-  argv[3] = "drop";
-  argv[4] = "-q";
-  argv[5] = (gchar*)name;
-  argv[6] = NULL;
-
-  if (!g_spawn_async_with_pipes (NULL, argv, NULL, G_SPAWN_DO_NOT_REAP_CHILD | G_SPAWN_SEARCH_PATH, NULL, NULL, pid, NULL, NULL, &fd_err, &error))
+  if (!g_spawn_async_with_pipes (NULL, (gchar**)argv, NULL, G_SPAWN_DO_NOT_REAP_CHILD | G_SPAWN_SEARCH_PATH, NULL, NULL, pid, NULL, NULL, &fd_err, &error))
   {
     g_free (argv);
     return FALSE;
@@ -287,7 +166,9 @@ static gboolean stash_clear_spawn (TghStashDialog *dialog, GPid *pid)
   TghOutputParser *parser;
   struct exit_args *args;
 
-  if (!g_spawn_async_with_pipes (NULL, argv_clear, NULL, G_SPAWN_DO_NOT_REAP_CHILD | G_SPAWN_SEARCH_PATH, NULL, NULL, pid, NULL, NULL, &fd_err, &error))
+  static const gchar *argv[] = {"git", "--no-pager", "stash", "clear", NULL};
+
+  if (!g_spawn_async_with_pipes (NULL, (gchar**)argv, NULL, G_SPAWN_DO_NOT_REAP_CHILD | G_SPAWN_SEARCH_PATH, NULL, NULL, pid, NULL, NULL, &fd_err, &error))
     return FALSE;
 
   parser = tgh_error_parser_new (GTK_WIDGET (dialog));
@@ -316,7 +197,7 @@ static void show_stash (TghStashDialog *dialog, const gchar *name, gpointer user
 static void save_stash (TghStashDialog *dialog, const gchar *name, gpointer user_data)
 {
   GPid pid;
-  if (stash_save_spawn(dialog, name, &pid))
+  if (stash_action_spawn(dialog, "save", name, &pid))
     tgh_replace_child(TRUE, pid);
   else
     tgh_stash_dialog_done(dialog);
@@ -325,7 +206,7 @@ static void save_stash (TghStashDialog *dialog, const gchar *name, gpointer user
 static void apply_stash (TghStashDialog *dialog, const gchar *name, gpointer user_data)
 {
   GPid pid;
-  if (stash_apply_spawn(dialog, name, &pid))
+  if (stash_action_spawn(dialog, "apply", name, &pid))
     tgh_replace_child(TRUE, pid);
   else
     tgh_stash_dialog_done(dialog);
@@ -334,7 +215,7 @@ static void apply_stash (TghStashDialog *dialog, const gchar *name, gpointer use
 static void pop_stash (TghStashDialog *dialog, const gchar *name, gpointer user_data)
 {
   GPid pid;
-  if (stash_pop_spawn(dialog, name, &pid))
+  if (stash_action_spawn(dialog, "pop", name, &pid))
     tgh_replace_child(TRUE, pid);
   else
     tgh_stash_dialog_done(dialog);
@@ -343,7 +224,7 @@ static void pop_stash (TghStashDialog *dialog, const gchar *name, gpointer user_
 static void drop_stash (TghStashDialog *dialog, const gchar *name, gpointer user_data)
 {
   GPid pid;
-  if (stash_drop_spawn(dialog, name, &pid))
+  if (stash_action_spawn(dialog, "drop", name, &pid))
     tgh_replace_child(TRUE, pid);
   else
     tgh_stash_dialog_done(dialog);



More information about the Xfce4-commits mailing list