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

Re: [PATCH v3 1/3] tree-walk: be more specific about corrupt tree errors

From
Jeff King <peff@peff.net>
Date
Sep 27, 2016, 18:59 UTC
Message-ID
<20160927185925.hkqlq63oeafldnrz@sigill.intra.peff.net>
In-Reply-To
<1474989806-5002-1-git-send-email-dturner@twosigma.com>
On Tue, Sep 27, 2016 at 11:23:24AM -0400, David Turner wrote:
> +test_expect_success 'malformed mode in tree' '
> +	hex_sha1=$(echo foo | git hash-object --stdin -w) &&
> +	bin_sha1=$(echo $hex_sha1 | perl -ne "printf \"\\\\%03o\", ord for /../g") &&

Sorry, the perl snippet I posted earlier was totally braindead. It gives you the octal for the raw bytes, but we really just want to convert the hex to octal (we could also print the raw bytes from the hex, but I didn't want to take chances on shells that can't handle NULs in environment variables).

I also find it helps to define a helper function outside of the test block to avoid quoting hell. So something like:

  hex2oct () {
	perl -ne 'printf "\\%03o", hex for /../g'
  }
  test_expect_success ... '
	bin_sha1=$(echo $hex_sha1 | hex2oct)
  '
-Peff
Previous: Junio C Hamano
Message 7 of 7 in “tree-walk: be more specific about corrupt tree errors”
  1. 1/3 tree-walk: be more specific about corrupt tree errorsDavid Turner, Sep 27, 2016
  2. 2/3 fsck: handle bad trees like other errorsDavid Turner, Sep 27, 2016
  3. Jeff KingSep 27, 2016
  4. 3/3 add David Turner's Two Sigma addressDavid Turner, Sep 27, 2016
  5. Junio C HamanoSep 27, 2016
  6. Junio C HamanoSep 27, 2016
  7. Jeff KingSep 27, 2016

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.