Skip to content

Commit 1308dfe

Browse files
committed
object-name: fix resolution of object names containing curly braces
Given a branch name of 'foo{bar', commands like git cat-file -p foo{bar:README.md should succeed (assuming that branch had a README.md file, of course). However, the change in cce91a2 (Change 'master@noon' syntax to 'master@{noon}'., 2006-05-19) presumed that curly braces would always come after an '@' and be paired, causing 'foo{bar:README.md' to entirely miss the ':' and assume there's no object being referenced. In short, git would report: fatal: Not a valid object name foo{bar:README.md Change the parsing to only make the assumption of paired curly braces immediately after a '@' character appears. Add tests for both this and 'foo@@{...}' cases, which an initial version of this patch broke. Reported-by: Gabriel Amaral <[email protected]> Helped-by: Michael Haggerty <[email protected]> Signed-off-by: Elijah Newren <[email protected]>
1 parent 92999a4 commit 1308dfe

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

object-name.c

+5-3
Original file line numberDiff line numberDiff line change
@@ -2087,12 +2087,14 @@ static enum get_oid_result get_oid_with_context_1(struct repository *repo,
20872087
return -1;
20882088
}
20892089
for (cp = name, bracket_depth = 0; *cp; cp++) {
2090-
if (*cp == '{')
2090+
if (*cp == '@' && *(cp+1) == '{') {
2091+
cp++;
20912092
bracket_depth++;
2092-
else if (bracket_depth && *cp == '}')
2093+
} else if (bracket_depth && *cp == '}') {
20932094
bracket_depth--;
2094-
else if (!bracket_depth && *cp == ':')
2095+
} else if (!bracket_depth && *cp == ':') {
20952096
break;
2097+
}
20962098
}
20972099
if (*cp == ':') {
20982100
struct object_id tree_oid;

t/t1006-cat-file.sh

+17
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,23 @@ test_expect_success FUNNYNAMES '--batch-check, -Z with newline in input' '
603603
test_cmp expect actual
604604
'
605605

606+
test_expect_success 'setup with curly braches in input' '
607+
git branch "foo{bar" &&
608+
git branch "foo@"
609+
'
610+
611+
test_expect_success 'object reference with curly brace' '
612+
git cat-file -p "foo{bar:hello" >actual &&
613+
git cat-file -p master:hello >expect &&
614+
test_cmp expect actual
615+
'
616+
617+
test_expect_success 'object reference with at-sign' '
618+
git cat-file -p "foo@@{0}:hello" >actual &&
619+
git cat-file -p master:hello >expect &&
620+
test_cmp expect actual
621+
'
622+
606623
test_expect_success 'setup blobs which are likely to delta' '
607624
test-tool genrandom foo 10240 >foo &&
608625
{ cat foo && echo plus; } >foo-plus &&

0 commit comments

Comments
 (0)