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

pkt-line.c
run-command.c
run-command.h
index 08a1427c0d4f6743182b235ec9d9c710c3c99b5b..62fdb37079fa31698846044448b5cfb398e45528 100644 (file)
@@ -1,5 +1,6 @@
 #include "cache.h"
 #include "pkt-line.h"
+#include "run-command.h"
 
 char packet_buffer[LARGE_PACKET_MAX];
 static const char *packet_trace_prefix = "git";
@@ -11,6 +12,11 @@ void packet_trace_identity(const char *prog)
        packet_trace_prefix = xstrdup(prog);
 }
 
+static const char *get_trace_prefix(void)
+{
+       return in_async() ? "sideband" : packet_trace_prefix;
+}
+
 static int packet_trace_pack(const char *buf, unsigned int len, int sideband)
 {
        if (!sideband) {
@@ -57,7 +63,7 @@ static void packet_trace(const char *buf, unsigned int len, int write)
        strbuf_init(&out, len+32);
 
        strbuf_addf(&out, "packet: %12s%c ",
-                   packet_trace_prefix, write ? '>' : '<');
+                   get_trace_prefix(), write ? '>' : '<');
 
        /* XXX we should really handle printable utf8 */
        for (i = 0; i < len; i++) {
index 3277cf797ed41e5834b3b94fa8d2e9e9d5b4a317..c8029f239405e463bba5b033a7321faf16ca6c0d 100644 (file)
@@ -595,7 +595,7 @@ static NORETURN void die_async(const char *err, va_list params)
 {
        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 +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 +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 +725,7 @@ 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));
        }
 
index 5b4425a3cbe1aea2bae40c4e060e45ee2d7a29a5..629fab7ae0b2af5c0ada5977a11f862de4cdd273 100644 (file)
@@ -118,5 +118,6 @@ struct async {
 
 int start_async(struct async *async);
 int finish_async(struct async *async);
+int in_async(void);
 
 #endif