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

Re: [PATCH v3 31/39] bundle: add new version for use with SHA-256

From
Eric Sunshine <sunshine@sunshineco.com>
Date
Jul 23, 2020, 05:31 UTC
Message-ID
<CAPig+cRWptYRJUpT71jW6_O9UZ1RK=FCbZj-+OkR_5kGqSWScg@mail.gmail.com>
In-Reply-To
<20200723010943.2329634-32-sandals@crustytoothpaste.net>

On Wed, Jul 22, 2020 at 9:10 PM brian m. carlson <sandals@crustytoothpaste.net> wrote:

Show 16 quoted lines
> [...]
> Since we cannot extend the v2 format in a backward-compatible way, let's
> add a v3 format, which is identical, except for the addition of
> capabilities, which are prefixed by an at sign.  We add "object-format"
> as the only capability and reject unknown capabilities, since we do not
> have a network connection and therefore cannot negotiate with the other
> side.
> [...]
> Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
> ---
> diff --git a/Documentation/technical/bundle-format.txt b/Documentation/technical/bundle-format.txt
> @@ -7,6 +7,8 @@ The Git bundle format is a format that represents both refs and Git objects.
>  == Semantics
>
> -A Git bundle consists of three parts.
> +A Git bundle consists of four parts.

Rather than having to worry about updating this each time the format changes, perhaps just say:

    A Git bundle consists of several parts.
Show 14 quoted lines
> diff --git a/t/t5510-fetch.sh b/t/t5510-fetch.sh
> @@ -281,15 +281,16 @@ test_expect_success 'create bundle 1' '
>  test_expect_success 'header of bundle looks right' '
>         head -n 4 "$D"/bundle1 &&
> -       head -n 1 "$D"/bundle1 | grep "^#" &&
> -       head -n 2 "$D"/bundle1 | grep "^-$OID_REGEX " &&
> -       head -n 3 "$D"/bundle1 | grep "^$OID_REGEX " &&
> -       head -n 4 "$D"/bundle1 | grep "^$"
> +       sed -n -e 1p "$D"/bundle1 | grep "^#" &&
> +       sed -n -e 2p "$D"/bundle1 | grep "^@object-format=" &&
> +       sed -n -e 3p "$D"/bundle1 | grep "^-$OID_REGEX " &&
> +       sed -n -e 4p "$D"/bundle1 | grep "^$OID_REGEX " &&
> +       sed -n -e 5p "$D"/bundle1 | grep "^$"
>  '
I wonder if it would be simpler and cleaner to do something like this instead:
    cat >expect <<\-EOF &&
    # v3 git bundle
    @object-format=sha256
    -[OID] message
    [OID] refs/head/master
    EOF
    head -n 5 "$D"/bundle1 | sanitize_oid >actual &&
    test_cmp expect actual

where sanitize_oid() is a function which converts a hex OID into the literal string "[OID]" (or whatever). I believe I've seen you employ such sanitization functions already in these series in cases when you want to verify that an OID is present in some output but don't care about the actual value.

Or perhaps this approach is overkill?

Reading further in this patch, I see that you actually do employ this technique in a new test you add to t5607, though you don't bother with OID sanitation in that test.

Show 11 quoted lines
> diff --git a/t/t5607-clone-bundle.sh b/t/t5607-clone-bundle.sh
> @@ -94,4 +98,29 @@ test_expect_success 'fetch SHA-1 from bundle' '
> +test_expect_success 'git bundle v3 has expected contents' '
> +       git branch side HEAD &&
> +       git bundle create --version=3 bundle HEAD^..side &&
> +       head -n2 bundle >actual &&
> +       cat >expect <<-EOF &&
> +       # v3 git bundle
> +       @object-format=$(test_oid algo)
> +       EOF
> +       test_cmp actual expect &&
I think you want to swap the 'actual' and 'expect' arguments.
Show 10 quoted lines
> +       git bundle verify bundle
> +'
> +
> +test_expect_success 'git bundle v3 rejects unknown extensions' '
> +       head -n2 bundle >new &&
> +       echo "@unknown=silly" >>new &&
> +       sed "1,2d" bundle >>new &&
> +       test_must_fail git bundle verify new 2>output &&
> +       test_i18ngrep "unknown capability .unknown=silly." output
> +'

I worry about passing binary bundle data through 'sed' like this. Historically, some 'sed' implementations would drop the last part of a file if it didn't end with a newline. Even today, not all 'sed' implementations necessarily pass the binary data through unmolested. For instance, on Mac OS, 'sed' adds a newline at the end of the file if the binary bundle blob didn't end with a newline. Perhaps a more reliable approach would be to use Perl to read the entire bundle in as a blob, use s/// to munge the @object-format= line into the @unknown= line, and write it out.

Previous: brian m. carlsonNext: Eric Sunshine
Message 16 of 52 in “SHA-256, part 3/3”
  1. 00/39 SHA-256, part 3/3brian m. carlson, Jul 23, 2020
  2. 02/39 t1001: use $ZERO_OIDbrian m. carlson, Jul 23, 2020
  3. 03/39 t3305: make hash agnosticbrian m. carlson, Jul 23, 2020
  4. 14/39 t7400: make hash size independentbrian m. carlson, Jul 23, 2020
  5. 05/39 t6100: make hash size independentbrian m. carlson, Jul 23, 2020
  6. 19/39 t8003: make hash size independentbrian m. carlson, Jul 23, 2020
  7. 18/39 t8002: make hash size independentbrian m. carlson, Jul 23, 2020
  8. 22/39 t9300: use $ZERO_OID instead of hard-coded object IDbrian m. carlson, Jul 23, 2020
  9. 23/39 t9301: make hash size independentbrian m. carlson, Jul 23, 2020
  10. 26/39 t9700: make hash size independentbrian m. carlson, Jul 23, 2020
  11. 25/39 t9500: ensure that algorithm info is preserved in configbrian m. carlson, Jul 23, 2020
  12. 24/39 t9350: make hash size independentbrian m. carlson, Jul 23, 2020
  13. 30/39 builtin/verify-pack: implement an --object-format optionbrian m. carlson, Jul 23, 2020
  14. Eric SunshineJul 23, 2020
  15. 31/39 bundle: add new version for use with SHA-256brian m. carlson, Jul 23, 2020
  16. Eric SunshineJul 23, 2020
  17. Eric SunshineJul 23, 2020
  18. brian m. carlsonJul 24, 2020
  19. 38/39 docs: add documentation for extensions.objectFormatbrian m. carlson, Jul 23, 2020
  20. 37/39 ci: run tests with SHA-256brian m. carlson, Jul 23, 2020
  21. 32/39 setup: add support for reading extensions.objectformatbrian m. carlson, Jul 23, 2020
  22. Junio C HamanoJul 23, 2020
  23. brian m. carlsonJul 23, 2020
  24. Junio C HamanoJul 23, 2020
  25. brian m. carlsonJul 25, 2020
  26. 33/39 Enable SHA-256 support by defaultbrian m. carlson, Jul 23, 2020
  27. 39/39 t: remove test_oid_init in testsbrian m. carlson, Jul 23, 2020
  28. 20/39 t8011: make hash size independentbrian m. carlson, Jul 23, 2020
  29. 29/39 http-fetch: set up git directory before parsing pack hashesbrian m. carlson, Jul 23, 2020
  30. 08/39 t6500: specify test values for SHA-256brian m. carlson, Jul 23, 2020
  31. 13/39 t7102: abstract away SHA-1-specific constantsbrian m. carlson, Jul 23, 2020
  32. 11/39 t7063: make hash size independentbrian m. carlson, Jul 23, 2020
  33. 04/39 t3404: prepare 'short SHA-1 collision' tests for SHA-256brian m. carlson, Jul 23, 2020
  34. 06/39 t6101: make hash size independentbrian m. carlson, Jul 23, 2020
  35. 09/39 t6501: avoid hard-coded objectsbrian m. carlson, Jul 23, 2020
  36. 01/39 t: make test-bloom initialize repositorybrian m. carlson, Jul 23, 2020
  37. 12/39 t7201: abstract away SHA-1-specific constantsbrian m. carlson, Jul 23, 2020
  38. 17/39 t7508: use $ZERO_OID instead of hard-coded constantbrian m. carlson, Jul 23, 2020
  39. 10/39 t7003: compute appropriate length constantbrian m. carlson, Jul 23, 2020
  40. 07/39 t6301: make hash size independentbrian m. carlson, Jul 23, 2020
  41. 21/39 t9300: abstract away SHA-1-specific constantsbrian m. carlson, Jul 23, 2020
  42. 16/39 t7506: avoid checking for SHA-1-specific constantsbrian m. carlson, Jul 23, 2020
  43. 15/39 t7405: make hash size independentbrian m. carlson, Jul 23, 2020
  44. 34/39 t: add test_oid option to select hash algorithmbrian m. carlson, Jul 23, 2020
  45. Eric SunshineJul 23, 2020
  46. brian m. carlsonJul 23, 2020
  47. Eric SunshineJul 23, 2020
  48. Junio C HamanoJul 24, 2020
  49. 35/39 t: allow testing different hash algorithms via environmentbrian m. carlson, Jul 23, 2020
  50. 36/39 t: make SHA1 prerequisite depend on default hashbrian m. carlson, Jul 23, 2020
  51. 27/39 t5308: make test work with SHA-256brian m. carlson, Jul 23, 2020
  52. 28/39 t0410: mark test with SHA1 prerequisitebrian m. carlson, Jul 23, 2020

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.