From: Junio C Hamano Date: Mon, 5 Oct 2015 19:30:09 +0000 (-0700) Subject: Merge branch 'jk/async-pkt-line' X-Git-Tag: v2.7.0-rc0~145 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/88bad58d3860a8e0cf6499951e24311d15bc63f0?ds=inline;hp=-c Merge branch 'jk/async-pkt-line' 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 --- 88bad58d3860a8e0cf6499951e24311d15bc63f0 diff --combined run-command.c index 3277cf797e,6131a44bdd..c8029f2394 --- a/run-command.c +++ b/run-command.c @@@ -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) @@@ -211,6 -212,17 +211,6 @@@ */ 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) @@@ -712,6 -738,7 +725,7 @@@ 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 5b4425a3cb,4aaac7ce0f..629fab7ae0 --- a/run-command.h +++ b/run-command.h @@@ -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