git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 7/8] add packet tracing debug code

From
Jonathan Nieder <jrnieder@gmail.com>
Date
Feb 24, 2011, 21:44 UTC
Message-ID
<20110224214412.GG17412@elie>
In-Reply-To
<20110224143019.GG15477@sigill.intra.peff.net>
Jeff King wrote:
> This shows a trace of all packets coming in or out of a given
> program. This can help with debugging object negotiation or
> other protocol issues.
Sounds handy.
> Packet tracing can be enabled with GIT_TRACE_PACKET=<foo>,
> where <foo> takes the same arguments as GIT_TRACE.
[...]
Show 7 quoted lines
> --- a/builtin/clone.c
> +++ b/builtin/clone.c
> @@ -383,6 +383,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
>  
>  	junk_pid = getpid();
>  
> +	packet_trace_identity("clone");

My first thought on reading this was "identity operation" (= pass-through), which left me a little confused.

Maybe "packet_trace_set_identity" (or ...set_prefix) would be a little clearer?

> +++ b/pkt-line.c
> @@ -1,6 +1,51 @@
[...]
Show 6 quoted lines
> +	if ((len >= 4 && !prefixcmp(buf, "PACK")) ||
> +	    (len >= 5 && !prefixcmp(buf+1, "PACK"))) {
> +		strbuf_addstr(&out, "PACK ...");
> +		unsetenv(trace_key);
> +	}
> +	else {
Style: should be cuddled, I think.
> +		/* XXX we should really handle printable utf8 */
> +		for (i = 0; i < len; i++) {

Maybe using is_utf8, extended to take a length argument? (Assuming it's okay if non-ASCII is escaped in packets containing non-utf8 parts.)

[...]
Show 6 quoted lines
> @@ -39,11 +84,13 @@ ssize_t safe_write(int fd, const void *buf, ssize_t n)
>   */
>  void packet_flush(int fd)
>  {
> +	packet_trace("0000", 4, 1);
>  	safe_write(fd, "0000", 4);
... I wonder if it would make sense to do
 static void packet_writebuf(int fd, const char *buf, size_t buflen)
 {
	packet_trace(buf, buflen, 1);
	safe_write(fd, buf, buflen);
 }

Nah, that would include the size noise for even nonempty packets, which your implementation conveniently omits.

Thanks, looks useful.
Previous: Jeff KingNext: Jeff King
Message 25 of 32 in “refactor trace code”
  1. 0/8 refactor trace codeJeff King, Feb 24, 2011
  2. 1/8 compat: provide a fallback va_copy definitionJeff King, Feb 24, 2011
  3. Erik Faye-LundFeb 24, 2011
  4. compat: fall back on __va_copy if availableJonathan Nieder, Mar 8, 2011
  5. Junio C HamanoMar 8, 2011
  6. Jonathan NiederMar 8, 2011
  7. Jonathan NiederFeb 24, 2011
  8. 2/8 strbuf: add strbuf_addvJeff King, Feb 24, 2011
  9. Christian CouderFeb 24, 2011
  10. Jeff KingFeb 24, 2011
  11. Jonathan NiederFeb 24, 2011
  12. 3/8 trace: add trace_vprintfJeff King, Feb 24, 2011
  13. Jonathan NiederFeb 24, 2011
  14. 4/8 trace: refactor to support multiple env variablesJeff King, Feb 24, 2011
  15. Junio C HamanoFeb 24, 2011
  16. Jeff KingFeb 24, 2011
  17. Junio C HamanoFeb 24, 2011
  18. Jeff KingFeb 24, 2011
  19. Junio C HamanoFeb 24, 2011
  20. Jonathan NiederFeb 24, 2011
  21. 5/8 trace: factor out "do we want to trace" logicJeff King, Feb 24, 2011
  22. Christian CouderFeb 24, 2011
  23. 6/8 trace: add trace_strbufJeff King, Feb 24, 2011
  24. 7/8 add packet tracing debug codeJeff King, Feb 24, 2011
  25. Jonathan NiederFeb 24, 2011
  26. 8/8 trace: give repo_setup trace its own keyJeff King, Feb 24, 2011
  27. Andreas EricssonFeb 24, 2011
  28. Jeff KingFeb 24, 2011
  29. Christian CouderFeb 24, 2011
  30. Jonathan NiederFeb 24, 2011
  31. Nguyen Thai Ngoc DuyFeb 25, 2011
  32. Junio C HamanoFeb 26, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.