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

[PATCH v2 2/4] fast-export: anonymize "master" refname

From
Jeff King <peff@peff.net>
Date
Jun 22, 2020, 21:48 UTC
Message-ID
<20200622214802.GB3303964@coredump.intra.peff.net>
In-Reply-To
<20200622214745.GA3302779@coredump.intra.peff.net>

Running "fast-export --anonymize" will leave "refs/heads/master" untouched in the output, for two reasons:

  - it helped to have some known reference point between the original
    and anonymized repository
  - since it's historically the default branch name, it doesn't leak any
    information

Now that we can ask fast-export to dump the anonymized ref mapping, we have a much better tool for the first one (because it works for _any_ ref, not just master).

For the second, the notion of "default branch name" is likely to become configurable soon, at which point the name _does_ leak information. Let's drop this special case in preparation.

Note that we have to adjust the test a bit, since it relied on using the name "master" in the anonymized repos. But this gives us a good opportunity to further test the new dumping feature.

Signed-off-by: Jeff King <peff@peff.net>
---
 builtin/fast-export.c            |  7 -------
 t/t9351-fast-export-anonymize.sh | 15 +++++----------
 2 files changed, 5 insertions(+), 17 deletions(-)
diff --git a/builtin/fast-export.c b/builtin/fast-export.c
index 844726d45a..faaab6c7e9 100644
--- a/builtin/fast-export.c
+++ b/builtin/fast-export.c
@@ -538,13 +538,6 @@ static const char *anonymize_refname(const char *refname)
 	const char *full_refname = refname;
 	int i;
 
-	/*
-	 * We also leave "master" as a special case, since it does not reveal
-	 * anything interesting.
-	 */
-	if (!strcmp(refname, "refs/heads/master"))
-		return refname;
-
 	strbuf_reset(&anon);
 	for (i = 0; i < ARRAY_SIZE(prefixes); i++) {
 		if (skip_prefix(refname, prefixes[i], &refname)) {
diff --git a/t/t9351-fast-export-anonymize.sh b/t/t9351-fast-export-anonymize.sh
index 75cbc7b329..c726306c4d 100755
--- a/t/t9351-fast-export-anonymize.sh
+++ b/t/t9351-fast-export-anonymize.sh
@@ -26,11 +26,8 @@ test_expect_success 'stream omits path names' '
 	! grep xyzzy stream
 '
 
-test_expect_success 'stream allows master as refname' '
-	grep master stream
-'
-
-test_expect_success 'stream omits other refnames' '
+test_expect_success 'stream omits refnames' '
+	! grep master stream &&
 	! grep other stream &&
 	! grep mytag stream
 '
@@ -53,9 +50,6 @@ test_expect_success 'refname mapping can be dumped' '
 	# so just check that we have the right number and
 	# that a sample line looks sane.
 	expected_count=$(git for-each-ref | wc -l) &&
-	# Note that master is not anonymized, and so not included
-	# in the mapping.
-	expected_count=$((expected_count - 1)) &&
 	test_line_count = $expected_count refs.out &&
 	grep "^refs/heads/other refs/heads/" refs.out
 '
@@ -71,15 +65,16 @@ test_expect_success 'import stream to new repository' '
 test_expect_success 'result has two branches' '
 	git for-each-ref --format="%(refname)" refs/heads >branches &&
 	test_line_count = 2 branches &&
-	other_branch=$(grep -v refs/heads/master branches)
+	main_branch=$(sed -ne "s,refs/heads/master ,,p" ../refs.out) &&
+	other_branch=$(sed -ne "s,refs/heads/other ,,p" ../refs.out)
 '
 
 test_expect_success 'repo has original shape and timestamps' '
 	shape () {
 		git log --format="%m %ct" --left-right --boundary "$@"
 	} &&
 	(cd .. && shape master...other) >expect &&
-	shape master...$other_branch >actual &&
+	shape $main_branch...$other_branch >actual &&
 	test_cmp expect actual
 '
 
-- 
2.27.0.517.gbc32778fa3
Previous: Jeff KingNext: Jeff King
Message 20 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.