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

[PATCH v2 0/11] fast-export: allow seeding the anonymized mapping

From
Jeff King <peff@peff.net>
Date
Jun 25, 2020, 19:48 UTC
Message-ID
<20200625194802.GA4028913@coredump.intra.peff.net>
In-Reply-To
<20200623152436.GA50925@coredump.intra.peff.net>

Here's a re-roll of the "--seed-anonymize" feature, incorporating changes from Eric's review.

Here's a summary of the changes. Patches 1-8 are unchanged:
  [01/11]: t9351: derive anonymized tree checks from original repo
  [02/11]: fast-export: use xmemdupz() for anonymizing oids
  [03/11]: fast-export: store anonymized oids as hex strings
  [04/11]: fast-export: tighten anonymize_mem() interface to handle only strings
  [05/11]: fast-export: stop storing lengths in anonymized hashmaps
  [06/11]: fast-export: use a flex array to store anonymized entries
  [07/11]: fast-export: move global "idents" anonymize hashmap into function
  [08/11]: fast-export: add a "data" callback parameter to anonymize_str()
  [09/11]: fast-export: allow seeding the anonymized mapping
    - the option is now called "--anonymize-map", and the word "seed"
      isn't used in any user-facing documentation
    - incorporated Eric's documentation suggestions
    - --anonymize-map without --anonymize now triggers an error
  [10/11]: fast-export: anonymize "master" refname
    - minor adjustments to handle change of option name
  [11/11]: fast-export: use local array to store anonymized oid
    - new in this iteration; this address the gcc-4 warning that Gábor
      mentioned. I prepared it on top since I think we'd eventually want
      to revert it once we decide that compiler is too old (and I'd be
      perfectly fine to declare that it's so now, and just never apply
      it at all).
Full range diff is below.
 1:  65dca0c684 =  1:  dd2668d7fe t9351: derive anonymized tree checks from original repo
 2:  bc79b92850 =  2:  46a07c62e1 fast-export: use xmemdupz() for anonymizing oids
 3:  f5b34b3730 =  3:  a7be6c4703 fast-export: store anonymized oids as hex strings
 4:  5982a5c764 =  4:  712e481e4e fast-export: tighten anonymize_mem() interface to handle only strings
 5:  d6b7a75a13 =  5:  1ad28f560a fast-export: stop storing lengths in anonymized hashmaps
 6:  f897a949b1 =  6:  b6456c0c7b fast-export: use a flex array to store anonymized entries
 7:  e5465fb8d8 =  7:  81d478c12b fast-export: move global "idents" anonymize hashmap into function
 8:  8dd74b95b7 =  8:  0d34f57a94 fast-export: add a "data" callback parameter to anonymize_str()
 9:  c7aec82ba5 !  9:  64e3afe46f fast-export: allow seeding the anonymized mapping
    @@ Commit message
         does work, but it's a bit awkward to use (you have to manually dig the
         items you care about out of the mapping).
     
    +    Helped-by: Eric Sunshine <sunshine@sunshineco.com>
         Signed-off-by: Jeff King <peff@peff.net>
     
      ## Documentation/git-fast-export.txt ##
     @@ Documentation/git-fast-export.txt: by keeping the marks the same across runs.
      	the shape of the history and stored tree.  See the section on
      	`ANONYMIZING` below.
      
    -+--seed-anonymized=<from>[:<to>]::
    ++--anonymize-map=<from>[:<to>]::
     +	Convert token `<from>` to `<to>` in the anonymized output. If
     +	`<to>` is omitted, map `<from>` to itself (i.e., do not
     +	anonymize it). See the section on `ANONYMIZING` below.
    @@ Documentation/git-fast-export.txt: collapse "User 0", "User 1", etc into "User X
     +paths, which becomes challenging after refnames and paths have been
     +anonymized. You can ask for a particular token to be left as-is or
     +mapped to a new value. For example, if you have a bug which reproduces
    -+with `git rev-list mybranch -- foo.c`, you can run:
    ++with `git rev-list sensitive -- secret.c`, you can run:
     +
     +---------------------------------------------------
     +$ git fast-export --anonymize --all \
    -+      --seed-anonymized=foo.c:secret.c \
    -+      --seed-anonymized=mybranch \
    ++      --anonymize-map=sensitive:foo \
    ++      --anonymize-map=secret.c:bar.c \
     +      >stream
     +---------------------------------------------------
     +
    -+After importing the stream, you can then run `git rev-list mybranch --
    -+secret.c` in the anonymized repository.
    ++After importing the stream, you can then run `git rev-list foo -- bar.c`
    ++in the anonymized repository.
     +
     +Note that paths and refnames are split into tokens at slash boundaries.
    -+The command above would anonymize `subdir/foo.c` as something like
    -+`path123/secret.c`.
    ++The command above would anonymize `subdir/secret.c` as something like
    ++`path123/bar.c`; you could then search for `bar.c` in the anonymized
    ++repository to determine the final pathname.
    ++
    ++To make referencing the final pathname simpler, you can map each path
    ++component; so if you also anonymize `subdir` to `publicdir`, then the
    ++final pathname would be `publicdir/bar.c`.
      
      LIMITATIONS
      -----------
    @@ builtin/fast-export.c: static void handle_deletes(void)
     +	return xstrdup(data);
     +}
     +
    -+static int parse_opt_seed_anonymized(const struct option *opt,
    -+				     const char *arg, int unset)
    ++static int parse_opt_anonymize_map(const struct option *opt,
    ++				   const char *arg, int unset)
     +{
     +	struct hashmap *map = opt->value;
     +	const char *delim, *value;
    @@ builtin/fast-export.c: static void handle_deletes(void)
     +	}
     +
     +	if (!keylen || !*value)
    -+		return error(_("--seed-anonymized token cannot be empty"));
    ++		return error(_("--anonymize-map token cannot be empty"));
     +
     +	anonymize_str(map, anonymize_seed, arg, keylen, (void *)value);
     +
    @@ builtin/fast-export.c: int cmd_fast_export(int argc, const char **argv, const ch
      		OPT_STRING_LIST(0, "refspec", &refspecs_list, N_("refspec"),
      			     N_("Apply refspec to exported refs")),
      		OPT_BOOL(0, "anonymize", &anonymize, N_("anonymize output")),
    -+		OPT_CALLBACK_F(0, "seed-anonymized", &anonymized_seeds, N_("from:to"),
    ++		OPT_CALLBACK_F(0, "anonymize-map", &anonymized_seeds, N_("from:to"),
     +			       N_("convert <from> to <to> in anonymized output"),
    -+			       PARSE_OPT_NONEG, parse_opt_seed_anonymized),
    ++			       PARSE_OPT_NONEG, parse_opt_anonymize_map),
      		OPT_BOOL(0, "reference-excluded-parents",
      			 &reference_excluded_commits, N_("Reference parents which are not in fast-export stream by object id")),
      		OPT_BOOL(0, "show-original-ids", &show_original_ids,
    +@@ builtin/fast-export.c: int cmd_fast_export(int argc, const char **argv, const char *prefix)
    + 	if (argc > 1)
    + 		usage_with_options (fast_export_usage, options);
    + 
    ++	if (anonymized_seeds.cmpfn && !anonymize)
    ++		die(_("--anonymize-map without --anonymize does not make sense"));
    ++
    + 	if (refspecs_list.nr) {
    + 		int i;
    + 
     
      ## t/t9351-fast-export-anonymize.sh ##
     @@ t/t9351-fast-export-anonymize.sh: test_description='basic tests for fast-export --anonymize'
    @@ t/t9351-fast-export-anonymize.sh: test_expect_success 'setup simple repo' '
      test_expect_success 'export anonymized stream' '
     -	git fast-export --anonymize --all >stream
     +	git fast-export --anonymize --all \
    -+		--seed-anonymized=retain-me \
    -+		--seed-anonymized=xyzzy:custom-name \
    ++		--anonymize-map=retain-me \
    ++		--anonymize-map=xyzzy:custom-name \
     +		>stream
      '
      
10:  59737b97de ! 10:  103f5bcd65 fast-export: anonymize "master" refname
    @@ Commit message
     
         Note that we have to adjust the test a bit, since it relied on using the
         name "master" in the anonymized repos. We could just use
    -    --seed-anonymized=master to keep the same output, but then we wouldn't
    +    --anonymize-map=master to keep the same output, but then we wouldn't
         know if it works because of our hard-coded master or because of the
    -    seeding.
    +    explicit map.
     
         So let's flip the test a bit, and confirm that we anonymize "master",
         but keep "other" in the output.
    @@ builtin/fast-export.c: static const char *anonymize_refname(const char *refname)
      ## t/t9351-fast-export-anonymize.sh ##
     @@ t/t9351-fast-export-anonymize.sh: test_expect_success 'export anonymized stream' '
      	git fast-export --anonymize --all \
    - 		--seed-anonymized=retain-me \
    - 		--seed-anonymized=xyzzy:custom-name \
    -+		--seed-anonymized=other \
    + 		--anonymize-map=retain-me \
    + 		--anonymize-map=xyzzy:custom-name \
    ++		--anonymize-map=other \
      		>stream
      '
      
 -:  ---------- > 11:  f2640407c5 fast-export: use local array to store anonymized oid
Previous: Jeff KingNext: Jeff King
Message 52 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.