Junio C Hamano <gitster@xxxxxxxxx> writes: > I think it is just the matter of moving "if (startup-info)..." logic > outside the "is the :$path lacking an explicit stage number" block and > having it after that if/else, no? Like this, perhaps? -- >8 -- Subject: get_sha1: teach ":$n:<path>" the same relative path logic Earlier we taught the object name parser ":<path>" syntax that uses a path 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 use relative path the same way. Signed-off-by: Junio C Hamano <gitster@xxxxxxxxx> --- sha1_name.c | 14 ++++++++------ t/t1506-rev-parse-diagnosis.sh | 24 ++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/sha1_name.c b/sha1_name.c index f918faf..2074056 100644 --- a/sha1_name.c +++ b/sha1_name.c @@ -1091,17 +1091,19 @@ int get_sha1_with_context_1(const char *name, unsigned char *sha1, return get_sha1_oneline(name + 2, sha1); if (namelen < 3 || name[2] != ':' || - name[1] < '0' || '3' < name[1]) { + name[1] < '0' || '3' < name[1]) cp = name + 1; - new_path = resolve_relative_path(cp); - if (new_path) - cp = new_path; - } else { stage = name[1] - '0'; cp = name + 3; } - namelen = strlen(cp); + new_path = resolve_relative_path(cp); + if (!new_path) { + namelen = namelen - (cp - name); + } else { + cp = new_path; + namelen = strlen(cp); + } strncpy(oc->path, cp, sizeof(oc->path)); diff --git a/t/t1506-rev-parse-diagnosis.sh b/t/t1506-rev-parse-diagnosis.sh index 1866470..9f8adb1 100755 --- a/t/t1506-rev-parse-diagnosis.sh +++ b/t/t1506-rev-parse-diagnosis.sh @@ -34,6 +34,8 @@ test_expect_success 'correct file objects' ' test_expect_success 'correct relative file objects (0)' ' git rev-parse :file.txt >expected && git rev-parse :./file.txt >result && + test_cmp expected result && + git rev-parse :0:./file.txt >result && test_cmp expected result ' @@ -68,6 +70,28 @@ test_expect_success 'correct relative file objects (4)' ' ) ' +test_expect_success 'correct relative file objects (5)' ' + git rev-parse :subdir/file.txt >expected && + ( + cd subdir && + git rev-parse :./file.txt >result && + test_cmp ../expected result && + git rev-parse :0:./file.txt >result && + test_cmp ../expected result + ) +' + +test_expect_success 'correct relative file objects (6)' ' + git rev-parse :file.txt >expected && + ( + cd subdir && + git rev-parse :../file.txt >result && + test_cmp ../expected result && + git rev-parse :0:../file.txt >result && + test_cmp ../expected result + ) +' + test_expect_success 'incorrect revision id' ' test_must_fail git rev-parse foobar:file.txt 2>error && grep "Invalid object name '"'"'foobar'"'"'." error && -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html