Merge branch 'jk/async-pkt-line'
authorJunio C Hamano <gitster@pobox.com>
Mon, 5 Oct 2015 19:30:09 +0000 (12:30 -0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 5 Oct 2015 19:30:09 +0000 (12:30 -0700)
The debugging infrastructure for pkt-line based communication has
been improved to mark the side-band communication specifically.

* jk/async-pkt-line:
pkt-line: show packets in async processes as "sideband"
run-command: provide in_async query function

1  2 
run-command.c
run-command.h
diff --combined run-command.c
index 3277cf797ed41e5834b3b94fa8d2e9e9d5b4a317,6131a44bddabd44e7cceeca59f223b43622b5f0e..c8029f239405e463bba5b033a7321faf16ca6c0d
@@@ -200,6 -200,7 +200,6 @@@ static int execv_shell_cmd(const char *
  #endif
  
  #ifndef GIT_WINDOWS_NATIVE
 -static int child_err = 2;
  static int child_notifier = -1;
  
  static void notify_parent(void)
         */
        xwrite(child_notifier, "", 1);
  }
 -
 -static NORETURN void die_child(const char *err, va_list params)
 -{
 -      vwritef(child_err, "fatal: ", err, params);
 -      exit(128);
 -}
 -
 -static void error_child(const char *err, va_list params)
 -{
 -      vwritef(child_err, "error: ", err, params);
 -}
  #endif
  
  static inline void set_cloexec(int fd)
@@@ -350,10 -362,11 +350,10 @@@ fail_pipe
                 * in subsequent call paths use the parent's stderr.
                 */
                if (cmd->no_stderr || need_err) {
 -                      child_err = dup(2);
 +                      int child_err = dup(2);
                        set_cloexec(child_err);
 +                      set_error_handle(fdopen(child_err, "w"));
                }
 -              set_die_routine(die_child);
 -              set_error_routine(error_child);
  
                close(notify_pipe[0]);
                set_cloexec(notify_pipe[1]);
@@@ -595,7 -608,7 +595,7 @@@ static NORETURN void die_async(const ch
  {
        vreportf("fatal: ", err, params);
  
-       if (!pthread_equal(main_thread, pthread_self())) {
+       if (in_async()) {
                struct async *async = pthread_getspecific(async_key);
                if (async->proc_in >= 0)
                        close(async->proc_in);
@@@ -614,6 -627,13 +614,13 @@@ static int async_die_is_recursing(void
        return ret != NULL;
  }
  
+ int in_async(void)
+ {
+       if (!main_thread_set)
+               return 0; /* no asyncs started yet */
+       return !pthread_equal(main_thread, pthread_self());
+ }
  #else
  
  static struct {
@@@ -653,6 -673,12 +660,12 @@@ int git_atexit(void (*handler)(void)
  }
  #define atexit git_atexit
  
+ static int process_is_async;
+ int in_async(void)
+ {
+       return process_is_async;
+ }
  #endif
  
  int start_async(struct async *async)
                if (need_out)
                        close(fdout[0]);
                git_atexit_clear();
+               process_is_async = 1;
                exit(!!async->proc(proc_in, proc_out, async->data));
        }
  
@@@ -784,13 -811,11 +798,13 @@@ int finish_async(struct async *async
  
  const char *find_hook(const char *name)
  {
 -      const char *path = git_path("hooks/%s", name);
 -      if (access(path, X_OK) < 0)
 -              path = NULL;
 +      static struct strbuf path = STRBUF_INIT;
  
 -      return path;
 +      strbuf_reset(&path);
 +      strbuf_git_path(&path, "hooks/%s", name);
 +      if (access(path.buf, X_OK) < 0)
 +              return NULL;
 +      return path.buf;
  }
  
  int run_hook_ve(const char *const *env, const char *name, va_list args)
diff --combined run-command.h
index 5b4425a3cbe1aea2bae40c4e060e45ee2d7a29a5,4aaac7ce0f3a4639aa28845adc9419dbee544746..629fab7ae0b2af5c0ada5977a11f862de4cdd273
@@@ -52,11 -52,6 +52,11 @@@ int start_command(struct child_process 
  int finish_command(struct child_process *);
  int run_command(struct child_process *);
  
 +/*
 + * Returns the path to the hook file, or NULL if the hook is missing
 + * or disabled. Note that this points to static storage that will be
 + * overwritten by further calls to find_hook and run_hook_*.
 + */
  extern const char *find_hook(const char *name);
  LAST_ARG_MUST_BE_NULL
  extern int run_hook_le(const char *const *env, const char *name, ...);
@@@ -118,5 -113,6 +118,6 @@@ struct async 
  
  int start_async(struct async *async);
  int finish_async(struct async *async);
+ int in_async(void);
  
  #endif