Skip to content

Commit 88bad58

Browse files
committed
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
2 parents db9789a + fd89433 commit 88bad58

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

pkt-line.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "cache.h"
22
#include "pkt-line.h"
3+
#include "run-command.h"
34

45
char packet_buffer[LARGE_PACKET_MAX];
56
static const char *packet_trace_prefix = "git";
@@ -11,6 +12,11 @@ void packet_trace_identity(const char *prog)
1112
packet_trace_prefix = xstrdup(prog);
1213
}
1314

15+
static const char *get_trace_prefix(void)
16+
{
17+
return in_async() ? "sideband" : packet_trace_prefix;
18+
}
19+
1420
static int packet_trace_pack(const char *buf, unsigned int len, int sideband)
1521
{
1622
if (!sideband) {
@@ -57,7 +63,7 @@ static void packet_trace(const char *buf, unsigned int len, int write)
5763
strbuf_init(&out, len+32);
5864

5965
strbuf_addf(&out, "packet: %12s%c ",
60-
packet_trace_prefix, write ? '>' : '<');
66+
get_trace_prefix(), write ? '>' : '<');
6167

6268
/* XXX we should really handle printable utf8 */
6369
for (i = 0; i < len; i++) {

run-command.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,7 @@ static NORETURN void die_async(const char *err, va_list params)
595595
{
596596
vreportf("fatal: ", err, params);
597597

598-
if (!pthread_equal(main_thread, pthread_self())) {
598+
if (in_async()) {
599599
struct async *async = pthread_getspecific(async_key);
600600
if (async->proc_in >= 0)
601601
close(async->proc_in);
@@ -614,6 +614,13 @@ static int async_die_is_recursing(void)
614614
return ret != NULL;
615615
}
616616

617+
int in_async(void)
618+
{
619+
if (!main_thread_set)
620+
return 0; /* no asyncs started yet */
621+
return !pthread_equal(main_thread, pthread_self());
622+
}
623+
617624
#else
618625

619626
static struct {
@@ -653,6 +660,12 @@ int git_atexit(void (*handler)(void))
653660
}
654661
#define atexit git_atexit
655662

663+
static int process_is_async;
664+
int in_async(void)
665+
{
666+
return process_is_async;
667+
}
668+
656669
#endif
657670

658671
int start_async(struct async *async)
@@ -712,6 +725,7 @@ int start_async(struct async *async)
712725
if (need_out)
713726
close(fdout[0]);
714727
git_atexit_clear();
728+
process_is_async = 1;
715729
exit(!!async->proc(proc_in, proc_out, async->data));
716730
}
717731

run-command.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,5 +118,6 @@ struct async {
118118

119119
int start_async(struct async *async);
120120
int finish_async(struct async *async);
121+
int in_async(void);
121122

122123
#endif

0 commit comments

Comments
 (0)