[gitg/wip/sindhus/interactive-rebase] Spawn git and capture stout



commit fcb8c79adc537a42f9775820dff08a52d88e8204
Author: Sindhu S <sindhus live in>
Date:   Wed Sep 11 19:59:56 2013 +0530

    Spawn git and capture stout

 gitg/gitg-rebase-controller.vala |   60 +++++++++++++++++++++++++++++++++++++-
 gitg/gitg-window.vala            |    2 +-
 2 files changed, 60 insertions(+), 2 deletions(-)
---
diff --git a/gitg/gitg-rebase-controller.vala b/gitg/gitg-rebase-controller.vala
index 3cbd20f..c13c00e 100644
--- a/gitg/gitg-rebase-controller.vala
+++ b/gitg/gitg-rebase-controller.vala
@@ -24,7 +24,28 @@ namespace Gitg
                public RebaseController()
                {}
 
-               public void start_rebase()
+               private static bool process_line (IOChannel channel, IOCondition condition, string 
stream_name) {
+                       if (condition == IOCondition.HUP) {
+                               stdout.printf ("%s: The fd has been closed.\n", stream_name);
+                               return false;
+                       }
+
+                       try {
+                               string line;
+                               channel.read_line (out line, null, null);
+                               stdout.printf ("%s: %s", stream_name, line);
+                       } catch (IOChannelError e) {
+                               stdout.printf ("%s: IOChannelError: %s\n", stream_name, e.message);
+                               return false;
+                       } catch (ConvertError e) {
+                               stdout.printf ("%s: ConvertError: %s\n", stream_name, e.message);
+                               return false;
+                       }
+
+                       return true;
+               }
+
+               public void start_rebase(Gtk.Window parent, Gitg.Repository repository)
                {
                        string gitg_path = "";
                        string git_path = "";
@@ -33,6 +54,43 @@ namespace Gitg
                        git_path = Environment.find_program_in_path("git");
                        stdout.printf("gitg path: %s\n", gitg_path);
                        stdout.printf("git path: %s\n", git_path);
+
+                       File? workdir = repository.get_workdir();
+                       string repo_path = workdir.get_path();
+
+                       string[] spawn_args = {"/usr/bin/git", "rebase", "-i", "HEAD~5"};
+                       string[] spawn_env = Environ.get ();
+                       Environ.set_variable(spawn_env, "GIT_SEQUENCE_EDITOR", "jhbuild run gitg --rebase");
+                       Environ.set_variable(spawn_env, "GIT_EDITOR", "jhbuild run gitg 
--rebase-commit-editor");
+                       Pid child_pid;
+
+                       int standard_input;
+                       int standard_output;
+                       int standard_error;
+
+                       Process.spawn_async_with_pipes (repo_path,
+                               spawn_args,
+                               spawn_env,
+                               SpawnFlags.SEARCH_PATH,
+                               null,
+                               out child_pid,
+                               out standard_input,
+                               out standard_output,
+                               out standard_error
+                       );
+
+// stdout:
+               IOChannel output = new IOChannel.unix_new (standard_output);
+               output.add_watch (IOCondition.IN | IOCondition.HUP, (channel, condition) => {
+                       return process_line (channel, condition, "stdout");
+               });
+
+               // stderr:
+               IOChannel error = new IOChannel.unix_new (standard_error);
+               error.add_watch (IOCondition.IN | IOCondition.HUP, (channel, condition) => {
+                       return process_line (channel, condition, "stderr");
+               });
+
                }
        }
 }
\ No newline at end of file
diff --git a/gitg/gitg-window.vala b/gitg/gitg-window.vala
index c5efbe3..445025c 100644
--- a/gitg/gitg-window.vala
+++ b/gitg/gitg-window.vala
@@ -382,7 +382,7 @@ public class Window : Gtk.ApplicationWindow, GitgExt.Application, Initable
        private void on_interactive_rebase_activated()
        {
                var rebase_controller = new RebaseController();
-               rebase_controller.start_rebase();
+               rebase_controller.start_rebase(this, d_repository);
        }
 
        private void on_current_activity_changed(Object obj, ParamSpec pspec)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]