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

[PATCH 02/24] t9300 (fast-import): avoid hard-coded object names

From
Jonathan Nieder <jrnieder@gmail.com>
Date
Sep 24, 2010, 07:05 UTC
Message-ID
<20100924070510.GC4666@burratino>
In-Reply-To
<20100924065900.GA4666@burratino>

compare_diff_raw already ensures most (though not all) of the tests do not rely on any particular hash function, but still the attentive reader might be comforted by some less opaque object descriptions.

Tested with
	sed -i s/compare_diff_raw/test_cmp/g t9300-fast-import.sh &&
	sh t9300-fast-import.sh -v -i
Cc: Shawn O. Pearce <spearce@spearce.org>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
 t/t9300-fast-import.sh |   91 ++++++++++++++++++++++++++++++++---------------
 1 files changed, 62 insertions(+), 29 deletions(-)
diff --git a/t/t9300-fast-import.sh b/t/t9300-fast-import.sh
index 1eef926..ed37a4e 100755
--- a/t/t9300-fast-import.sh
+++ b/t/t9300-fast-import.sh
@@ -7,6 +7,8 @@ test_description='test git fast-import utility'
 . ./test-lib.sh
 . "$TEST_DIRECTORY"/diff-lib.sh ;# test-lib chdir's into trash
 
+zeroes=0000000000000000000000000000000000000000
+
 file2_data='file2
 second line of EOF'
 
@@ -31,6 +33,14 @@ verify_packs () {
 	done
 }
 
+test_expect_success 'setup' '
+	file2_id=$(echo "$file2_data" | git hash-object --stdin) &&
+	file3_id=$(echo "$file3_data" | git hash-object --stdin) &&
+	file4_id=$(printf "%s" "$file4_data" | git hash-object --stdin) &&
+	file5_id=$(echo "$file5_data" | git hash-object --stdin) &&
+	file6_id=$(echo "$file6_data" | git hash-object --stdin)
+'
+
 ###
 ### series A
 ###
@@ -165,7 +175,7 @@ test_expect_success \
 	'A: verify pack' \
 	'verify_packs'
 cat >expect <<EOF
-:000000 100755 0000000000000000000000000000000000000000 7123f7f44e39be127c5eb701e5968176ee9d78b1 A	copy-of-file2
+:000000 100755 $zeroes $file2_id A	copy-of-file2
 EOF
 git diff-tree -M -r master verify--import-marks >actual
 test_expect_success \
@@ -345,9 +355,9 @@ test_expect_success \
 	 test_cmp expect actual'
 
 cat >expect <<EOF
-:000000 100755 0000000000000000000000000000000000000000 f1fb5da718392694d0076d677d6d0e364c79b0bc A	file2/newf
-:100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 R100	file2	file2/oldf
-:100644 000000 0d92e9f3374ae2947c23aa477cbc68ce598135f1 0000000000000000000000000000000000000000 D	file3
+:000000 100755 $zeroes $newf A	file2/newf
+:100644 100644 $file2_id $file2_id R100	file2	file2/oldf
+:100644 000000 $file3_id $zeroes D	file3
 EOF
 git diff-tree -M -r master branch >actual
 test_expect_success \
@@ -387,8 +397,8 @@ test_expect_success \
 	'verify_packs'
 
 cat >expect <<EOF
-:000000 100755 0000000000000000000000000000000000000000 35a59026a33beac1569b1c7f66f3090ce9c09afc A	newdir/exec.sh
-:000000 100644 0000000000000000000000000000000000000000 046d0371e9220107917db0d0e030628de8a1de9b A	newdir/interesting
+:000000 100755 $zeroes $file6_id A	newdir/exec.sh
+:000000 100644 $zeroes $file5_id A	newdir/interesting
 EOF
 git diff-tree -M -r branch^ branch >actual
 test_expect_success \
@@ -557,11 +567,11 @@ test_expect_success \
 	'verify_packs'
 
 cat >expect <<EOF
-:100755 000000 f1fb5da718392694d0076d677d6d0e364c79b0bc 0000000000000000000000000000000000000000 D	file2/newf
-:100644 000000 7123f7f44e39be127c5eb701e5968176ee9d78b1 0000000000000000000000000000000000000000 D	file2/oldf
-:100755 000000 85df50785d62d3b05ab03d9cbf7e4a0b49449730 0000000000000000000000000000000000000000 D	file4
-:100644 100644 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 R100	newdir/interesting	h/e/l/lo
-:100755 000000 e74b7d465e52746be2b4bae983670711e6e66657 0000000000000000000000000000000000000000 D	newdir/exec.sh
+:100755 000000 $newf $zeroes D	file2/newf
+:100644 000000 $oldf $zeroes D	file2/oldf
+:100755 000000 $file4_id $zeroes D	file4
+:100644 100644 $file5_id $file5_id R100	newdir/interesting	h/e/l/lo
+:100755 000000 $file6_id $zeroes D	newdir/exec.sh
 EOF
 git diff-tree -M -r H^ H >actual
 test_expect_success \
@@ -698,16 +708,39 @@ M 644 :2 b/other
 M 644 :2 ba
 INPUT_END
 
+test_expect_success 'setup: object names for expected diff' '
+	some_data=$(
+		echo some data |
+		git hash-object -w --stdin
+	) &&
+	other_data=$(
+		echo other data |
+		git hash-object -w --stdin
+	) &&
+	some_tree=$(
+		rm -f tmp_index &&
+		echo "100644 blob $some_data	other" |
+		GIT_INDEX_FILE=tmp_index git update-index --index-info &&
+		GIT_INDEX_FILE=tmp_index git write-tree
+	) &&
+	other_tree=$(
+		rm -f tmp_index &&
+		echo "100644 blob $other_data	other" |
+		GIT_INDEX_FILE=tmp_index git update-index --index-info &&
+		GIT_INDEX_FILE=tmp_index git write-tree
+	)
+'
+
 cat >expect <<EXPECT_END
-:100644 100644 4268632... 55d3a52... M	b.
-:040000 040000 0ae5cac... 443c768... M	b
-:100644 100644 4268632... 55d3a52... M	ba
+:100644 100644 $some_data $other_data M	b.
+:040000 040000 $some_tree $other_tree M	b
+:100644 100644 $some_data $other_data M	ba
 EXPECT_END
 
 test_expect_success \
     'L: verify internal tree sorting' \
 	'git fast-import <input &&
-	 git diff-tree --abbrev --raw L^ L >output &&
+	 git diff-tree L^ L >output &&
 	 test_cmp expect output'
 
 ###
@@ -728,7 +761,7 @@ R file2/newf file2/n.e.w.f
 INPUT_END
 
 cat >expect <<EOF
-:100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc R100	file2/newf	file2/n.e.w.f
+:100755 100755 $newf $newf R100	file2/newf	file2/n.e.w.f
 EOF
 test_expect_success \
 	'M: rename file in same subdirectory' \
@@ -749,7 +782,7 @@ R file2/newf i/am/new/to/you
 INPUT_END
 
 cat >expect <<EOF
-:100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc R100	file2/newf	i/am/new/to/you
+:100755 100755 $newf $newf R100	file2/newf	i/am/new/to/you
 EOF
 test_expect_success \
 	'M: rename file to new subdirectory' \
@@ -770,7 +803,7 @@ R i other/sub
 INPUT_END
 
 cat >expect <<EOF
-:100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc R100	i/am/new/to/you	other/sub/am/new/to/you
+:100755 100755 $newf $newf R100	i/am/new/to/you	other/sub/am/new/to/you
 EOF
 test_expect_success \
 	'M: rename subdirectory to new subdirectory' \
@@ -796,7 +829,7 @@ C file2/newf file2/n.e.w.f
 INPUT_END
 
 cat >expect <<EOF
-:100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100	file2/newf	file2/n.e.w.f
+:100755 100755 $newf $newf C100	file2/newf	file2/n.e.w.f
 EOF
 test_expect_success \
 	'N: copy file in same subdirectory' \
@@ -828,9 +861,9 @@ EOF
 INPUT_END
 
 cat >expect <<EOF
-:100644 100644 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 C100	newdir/interesting	file3/file5
-:100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100	file2/newf	file3/newf
-:100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 C100	file2/oldf	file3/oldf
+:100644 100644 $file5_id $file5_id C100	newdir/interesting	file3/file5
+:100755 100755 $newf $newf C100	file2/newf	file3/newf
+:100644 100644 $oldf $oldf C100	file2/oldf	file3/oldf
 EOF
 test_expect_success \
 	'N: copy then modify subdirectory' \
@@ -863,9 +896,9 @@ test_expect_success \
 
 test_expect_success \
 	'N: copy directory by id' \
-	'cat >expect <<-\EOF &&
-	:100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100	file2/newf	file3/newf
-	:100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 C100	file2/oldf	file3/oldf
+	'cat >expect <<-EOF &&
+	:100755 100755 $newf $newf C100	file2/newf	file3/newf
+	:100644 100644 $oldf $oldf C100	file2/oldf	file3/oldf
 	EOF
 	 subdir=$(git rev-parse refs/heads/branch^0:file2) &&
 	 cat >input <<-INPUT_END &&
@@ -884,10 +917,10 @@ test_expect_success \
 
 test_expect_success \
 	'N: modify copied tree' \
-	'cat >expect <<-\EOF &&
-	:100644 100644 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 C100	newdir/interesting	file3/file5
-	:100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100	file2/newf	file3/newf
-	:100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 C100	file2/oldf	file3/oldf
+	'cat >expect <<-EOF &&
+	:100644 100644 $file5_id $file5_id C100	newdir/interesting	file3/file5
+	:100755 100755 $newf $newf C100	file2/newf	file3/newf
+	:100644 100644 $oldf $oldf C100	file2/oldf	file3/oldf
 	EOF
 	 subdir=$(git rev-parse refs/heads/branch^0:file2) &&
 	 cat >input <<-INPUT_END &&
-- 
1.7.2.3
Previous: Jonathan NiederNext: Jonathan Nieder
Message 19 of 75 in “Teach fast-import to import subtrees named by tree id”
  1. Teach fast-import to import subtrees named by tree idJonathan Nieder, Jul 1, 2010
  2. Teach fast-import to print the id of each imported commitJonathan Nieder, Jul 1, 2010
  3. Sverre RabbelierJul 2, 2010
  4. Jonathan NiederJul 2, 2010
  5. Sverre RabbelierJul 2, 2010
  6. Jonathan NiederJul 2, 2010
  7. Sverre RabbelierJul 2, 2010
  8. Jonathan NiederJul 2, 2010
  9. Sverre RabbelierJul 2, 2010
  10. Sam VilainJul 4, 2010
  11. Jonathan NiederJul 4, 2010
  12. Sam VilainJul 4, 2010
  13. Jonathan NiederJul 4, 2010
  14. Ramkumar RamachandraAug 17, 2010
  15. 0/3 fast-import: give importers access to the object storeJonathan Nieder, Sep 5, 2010
  16. 1/3 t9300 (fast-import): style tweaksJonathan Nieder, Sep 5, 2010
  17. 00/24 Re: [PATCH 1/3] t9300 (fast-import): style tweaksJonathan Nieder, Sep 24, 2010
  18. 01/24 t9300 (fast-import): avoid exiting early on failureJonathan Nieder, Sep 24, 2010
  19. 02/24 t9300 (fast-import): avoid hard-coded object namesJonathan Nieder, Sep 24, 2010
  20. 03/24 t9300 (fast-import): guard "export large marks" test setupJonathan Nieder, Sep 24, 2010
  21. Ramkumar RamachandraSep 24, 2010
  22. Raja R HarinathSep 24, 2010
  23. Ramkumar RamachandraSep 24, 2010
  24. Raja R HarinathSep 24, 2010
  25. 04/24 t9300 (fast-import): check exit status from upstream of pipesJonathan Nieder, Sep 24, 2010
  26. 05/24 t9300 (fast-import): check exit status from command substitutionsJonathan Nieder, Sep 24, 2010
  27. 06/24 t9300 (fast-import): use test_cmp in place of test $(foo) = $(bar)Jonathan Nieder, Sep 24, 2010
  28. 07/24 t9300 (fast-import): use tabs to indentJonathan Nieder, Sep 24, 2010
  29. Ramkumar RamachandraSep 24, 2010
  30. Jonathan NiederSep 24, 2010
  31. 08/24 t9300 (fast-import), series A: re-indentJonathan Nieder, Sep 24, 2010
  32. Sverre RabbelierSep 24, 2010
  33. Jonathan NiederSep 24, 2010
  34. 09/24 t9300 (fast-import), series B: re-indentJonathan Nieder, Sep 24, 2010
  35. 10/24 t9300 (fast-import), series C: re-indentJonathan Nieder, Sep 24, 2010
  36. 11/24 t9300 (fast-import), series D: re-indentJonathan Nieder, Sep 24, 2010
  37. 12/24 t9300 (fast-import), series E: re-indentJonathan Nieder, Sep 24, 2010
  38. 13/24 t9300 (fast-import), series F: re-indentJonathan Nieder, Sep 24, 2010
  39. 14/24 t9300 (fast-import), series H: re-indentJonathan Nieder, Sep 24, 2010
  40. 15/24 t9300 (fast-import), series I: re-indentJonathan Nieder, Sep 24, 2010
  41. 16/24 t9300 (fast-import), series J: re-indentJonathan Nieder, Sep 24, 2010
  42. 17/24 t9300 (fast-import), series K: re-indentJonathan Nieder, Sep 24, 2010
  43. 18/24 t9300 (fast-import), series L: re-indentJonathan Nieder, Sep 24, 2010
  44. 19/24 t9300 (fast-import), series M: re-indentJonathan Nieder, Sep 24, 2010
  45. 20/24 t9300 (fast-import), series N: re-indentJonathan Nieder, Sep 24, 2010
  46. 21/24 t9300 (fast-import), series O: re-indentJonathan Nieder, Sep 24, 2010
  47. 22/24 t9300 (fast-import), series P: re-indentJonathan Nieder, Sep 24, 2010
  48. 23/24 t9300 (fast-import), series Q: re-indentJonathan Nieder, Sep 24, 2010
  49. 24/24 t9300 (fast-import), series R: re-indentJonathan Nieder, Sep 24, 2010
  50. svn-fe statusJonathan Nieder, Sep 25, 2010
  51. Sverre RabbelierSep 25, 2010
  52. Jonathan NiederSep 27, 2010
  53. Sverre RabbelierSep 27, 2010
  54. 2/3 Teach fast-import to print the id of each imported commitJonathan Nieder, Sep 5, 2010
  55. 3/3 fast-import: Let importers retrieve the objects being writtenJonathan Nieder, Sep 5, 2010
  56. Ramkumar RamachandraSep 5, 2010
  57. Sverre RabbelierSep 5, 2010
  58. Ramkumar RamachandraSep 5, 2010
  59. Sverre RabbelierSep 5, 2010
  60. Jonathan NiederSep 5, 2010
  61. 4/3 fast-import: typofixJonathan Nieder, Sep 8, 2010
  62. 5/3 fast-import: allow cat command with empty pathJonathan Nieder, Sep 8, 2010
  63. 6/3 fast-import: Allow cat requests at arbitrary points in streamJonathan Nieder, Sep 8, 2010
  64. Sverre RabbelierSep 8, 2010
  65. Jonathan NiederSep 8, 2010
  66. Ramkumar RamachandraSep 8, 2010
  67. Sam VilainSep 16, 2010
  68. Sverre RabbelierSep 17, 2010
  69. Jonathan NiederSep 24, 2010
  70. Sverre RabbelierSep 24, 2010
  71. Jonathan NiederSep 25, 2010
  72. Sverre RabbelierSep 25, 2010
  73. Sverre RabbelierJul 2, 2010
  74. Jonathan NiederJul 2, 2010
  75. Ramkumar RamachandraJul 2, 2010

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.