@matheusbsbs / matheus-bagliano / commits / 3d6e0f745e
Fork 0

get_sha1: teach ":$n:<path>" the same relative path logic

We taught the object name parser to take ":./<path>", ":../<path>", etc. and understand them to be relative to the current working directory. Given that ":<path>" is just a short-hand for ":0:<path>" (i.e. "take stage #0 of that path"), we should allow ":$n:<path>" to interpret them the same way. Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Dec 9, 2010 at 13:38 UTC 3d6e0f745e5b958387c9116ff5ba6247b990e6e7
2 files changed +32 -6
sha1_name.c
+8 -6
@@ -1091,17 +1091,19 @@ int get_sha1_with_context_1(const char *name, unsigned char *sha1,
1091 return get_sha1_oneline(name + 2, sha1);
1092 if (namelen < 3 ||
1093 name[2] != ':' ||
1094 - name[1] < '0' || '3' < name[1]) {
1094 + name[1] < '0' || '3' < name[1])
1095 cp = name + 1;
1096 - new_path = resolve_relative_path(cp);
1097 - if (new_path)
1098 - cp = new_path;
1099 - }
1096 else {
1097 stage = name[1] - '0';
1098 cp = name + 3;
1099 }
1104 - namelen = strlen(cp);
1100 + new_path = resolve_relative_path(cp);
1101 + if (!new_path) {
1102 + namelen = namelen - (cp - name);
1103 + } else {
1104 + cp = new_path;
1105 + namelen = strlen(cp);
1106 + }
1107
1108 strncpy(oc->path, cp,
1109 sizeof(oc->path));
t/t1506-rev-parse-diagnosis.sh
+24
@@ -34,6 +34,8 @@ test_expect_success 'correct file objects' '
34 test_expect_success 'correct relative file objects (0)' '
35 git rev-parse :file.txt >expected &&
36 git rev-parse :./file.txt >result &&
37 + test_cmp expected result &&
38 + git rev-parse :0:./file.txt >result &&
39 test_cmp expected result
40 '
41
@@ -68,6 +70,28 @@ test_expect_success 'correct relative file objects (4)' '
70 )
71 '
72
73 +test_expect_success 'correct relative file objects (5)' '
74 + git rev-parse :subdir/file.txt >expected &&
75 + (
76 + cd subdir &&
77 + git rev-parse :./file.txt >result &&
78 + test_cmp ../expected result &&
79 + git rev-parse :0:./file.txt >result &&
80 + test_cmp ../expected result
81 + )
82 +'
83 +
84 +test_expect_success 'correct relative file objects (6)' '
85 + git rev-parse :file.txt >expected &&
86 + (
87 + cd subdir &&
88 + git rev-parse :../file.txt >result &&
89 + test_cmp ../expected result &&
90 + git rev-parse :0:../file.txt >result &&
91 + test_cmp ../expected result
92 + )
93 +'
94 +
95 test_expect_success 'incorrect revision id' '
96 test_must_fail git rev-parse foobar:file.txt 2>error &&
97 grep "Invalid object name '"'"'foobar'"'"'." error &&