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

Re: [PATCH 1/3] fast-export: allow dumping the refname mapping

From
Jeff King <peff@peff.net>
Date
Jun 19, 2020, 16:01 UTC
Message-ID
<20200619160129.GA1843858@coredump.intra.peff.net>
In-Reply-To
<CAPig+cRNem-S5LGX=v=1Tid64sXWBxNyWH4ffgLgF0o1yN=mtw@mail.gmail.com>
On Fri, Jun 19, 2020 at 11:51:06AM -0400, Eric Sunshine wrote:
Show 17 quoted lines
> > +static void maybe_dump_anon(FILE *out, struct seen_set *seen,
> > +                           const char *orig, const char *anon)
> > +{
> > +       if (!out)
> > +               return;
> > +       if (!check_and_mark_seen(seen, orig))
> > +               fprintf(out, "%s %s\n", orig, anon);
> > +}
> 
> Nit: For a function which has only a single caller in this patch and
> one more caller added in 3/3, I wonder if the, um, convenience of this
> function short-circuiting as the very first thing it does outweighs
> the loss of clarity of having the callers make the check themselves.
> That is, have the caller do this instead:
> 
>     if (anonymized_refnames_handle)
>         dump_anon(anonymized_refnames_handle, ...);

<shrug> The names were long enough that I thought it was more clear not to repeat myself. I actually wrote originally:

  if (anonymized_refnames_handle &&
      check_and_mark_seen(&seen, full_refname))
          fprintf(anonymized_refnames_handle, "%s %s\n",
	          full_refname, anon.buf));

but I wasn't sure if it was better not to duplicate the output format. OTOH, we _could_ be using quote_path() for the path dumping, in which case the formats would start to differ.

Show 5 quoted lines
> > @@ -1213,6 +1249,9 @@ int cmd_fast_export(int argc, const char **argv, const char *prefix)
> > +       if (anonymized_refnames_file)
> > +               anonymized_refnames_handle = xfopen(anonymized_refnames_file, "w");
> 
> For completeness, do you want to close this file at some point?

My thought was to just let it auto-close at exit() time, since it's effectively process-length.

Show 25 quoted lines
> > diff --git a/t/t9351-fast-export-anonymize.sh b/t/t9351-fast-export-anonymize.sh
> > @@ -46,6 +46,18 @@ test_expect_success 'stream omits tag message' '
> > +test_expect_success 'refname mapping can be dumped' '
> > +       git fast-export --anonymize --all \
> > +               --dump-anonymized-refnames=refs.out >/dev/null &&
> > +       # we make no guarantees of the exact anonymized names,
> > +       # so just check that we have the right number and
> > +       # that a sample line looks sane.
> > +       # Note that master is not anonymized, and so not included
> > +       # in the mapping.
> > +       test_line_count = 6 refs.out &&
> 
> This hard-coded "6" seems rather fragile, causing the test to break if
> other refs are ever added or removed. Perhaps just count the refs
> dynamically?
> 
>     git show-ref >refs &&
>     nrefs=$(wc -l refs) &&
>     # Note that master is not anonymized, and so not included
>     # in the mapping.
>     nrefs=$((nrefs - 1))
>     test_line_count = $nrefs refs.out &&
> 
> and then drop the 'nrefs=$((nrefs - 1))' line and associated comment
> in patch 2/3 which removes the "master" special case.

That's exactly what I wrote originally, but it failed on macos due to extra spaces in the "wc" output. There are other tests nearby that also count the refs (e.g., exactly 2 branches), so I didn't think it was worth trying to deal with the portability issue.

-Peff
Previous: Eric SunshineNext: Eric Sunshine
Message 4 of 64 in “fast-export: allow dumping anonymization mappings”
  1. 0/3 fast-export: allow dumping anonymization mappingsJeff King, Jun 19, 2020
  2. 1/3 fast-export: allow dumping the refname mappingJeff King, Jun 19, 2020
  3. Eric SunshineJun 19, 2020
  4. Jeff KingJun 19, 2020
  5. Eric SunshineJun 19, 2020
  6. Jeff KingJun 19, 2020
  7. Eric SunshineJun 19, 2020
  8. Jeff KingJun 22, 2020
  9. Junio C HamanoJun 19, 2020
  10. Jeff KingJun 22, 2020
  11. 2/3 fast-export: anonymize "master" refnameJeff King, Jun 19, 2020
  12. 3/3 fast-export: allow dumping the path mappingJeff King, Jun 19, 2020
  13. Eric SunshineJun 19, 2020
  14. Junio C HamanoJun 19, 2020
  15. Jeff KingJun 22, 2020
  16. Johannes SchindelinJun 19, 2020
  17. Junio C HamanoJun 22, 2020
  18. 0/4 fast-export: allow dumping anonymization mappingsJeff King, Jun 22, 2020
  19. 1/4 fast-export: allow dumping the refname mappingJeff King, Jun 22, 2020
  20. 2/4 fast-export: anonymize "master" refnameJeff King, Jun 22, 2020
  21. 3/4 fast-export: refactor path printing to not rely on stdoutJeff King, Jun 22, 2020
  22. 4/4 fast-export: allow dumping the path mappingJeff King, Jun 22, 2020
  23. 0/10 fast-export: allow seeding the anonymized mappingJeff King, Jun 23, 2020
  24. 01/10 t9351: derive anonymized tree checks from original repoJeff King, Jun 23, 2020
  25. 02/10 fast-export: use xmemdupz() for anonymizing oidsJeff King, Jun 23, 2020
  26. 03/10 fast-export: store anonymized oids as hex stringsJeff King, Jun 23, 2020
  27. SZEDER GáborJun 24, 2020
  28. Jeff KingJun 24, 2020
  29. Jeff KingJun 25, 2020
  30. SZEDER GáborJun 25, 2020
  31. Jeff KingJun 25, 2020
  32. Johannes SchindelinJun 29, 2020
  33. Jeff KingJun 30, 2020
  34. 04/10 fast-export: tighten anonymize_mem() interface to handle only stringsJeff King, Jun 23, 2020
  35. 05/10 fast-export: stop storing lengths in anonymized hashmapsJeff King, Jun 23, 2020
  36. 06/10 fast-export: use a flex array to store anonymized entriesJeff King, Jun 23, 2020
  37. 07/10 fast-export: move global "idents" anonymize hashmap into functionJeff King, Jun 23, 2020
  38. 08/10 fast-export: add a "data" callback parameter to anonymize_str()Jeff King, Jun 23, 2020
  39. Junio C HamanoJun 24, 2020
  40. 09/10 fast-export: allow seeding the anonymized mappingJeff King, Jun 23, 2020
  41. Eric SunshineJun 23, 2020
  42. Jeff KingJun 23, 2020
  43. Eric SunshineJun 23, 2020
  44. Jeff KingJun 24, 2020
  45. Eric SunshineJun 23, 2020
  46. Jeff KingJun 23, 2020
  47. Eric SunshineJun 23, 2020
  48. Jeff KingJun 24, 2020
  49. 10/10 fast-export: anonymize "master" refnameJeff King, Jun 23, 2020
  50. Junio C HamanoJun 23, 2020
  51. Jeff KingJun 23, 2020
  52. 0/11 fast-export: allow seeding the anonymized mappingJeff King, Jun 25, 2020
  53. 01/11 t9351: derive anonymized tree checks from original repoJeff King, Jun 25, 2020
  54. 02/11 fast-export: use xmemdupz() for anonymizing oidsJeff King, Jun 25, 2020
  55. 03/11 fast-export: store anonymized oids as hex stringsJeff King, Jun 25, 2020
  56. 05/11 fast-export: stop storing lengths in anonymized hashmapsJeff King, Jun 25, 2020
  57. 06/11 fast-export: use a flex array to store anonymized entriesJeff King, Jun 25, 2020
  58. 04/11 fast-export: tighten anonymize_mem() interface to handle only stringsJeff King, Jun 25, 2020
  59. 07/11 fast-export: move global "idents" anonymize hashmap into functionJeff King, Jun 25, 2020
  60. 08/11 fast-export: add a "data" callback parameter to anonymize_str()Jeff King, Jun 25, 2020
  61. 09/11 fast-export: allow seeding the anonymized mappingJeff King, Jun 25, 2020
  62. 11/11 fast-export: use local array to store anonymized oidJeff King, Jun 25, 2020
  63. 10/11 fast-export: anonymize "master" refnameJeff King, Jun 25, 2020
  64. Junio C HamanoJun 25, 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.