From: "Elijah Newren via GitGitGadget" <gitgitgadget@gmail•com>
To: git@vger•kernel.org
Cc: Patrick Steinhardt <ps@pks•im>, Elijah Newren <newren@gmail•com>,
Elijah Newren <newren@gmail•com>,
Elijah Newren <newren@gmail•com>
Subject: [PATCH v3 1/2] object-name: fix resolution of object names containing curly braces
Date: Mon, 13 Jan 2025 17:13:36 +0000 [thread overview]
Message-ID: <b21b8fc555414789d835f454a0dce3bf685fdb4c.1736788417.git.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.1844.v3.git.1736788417.gitgitgadget@gmail.com>
From: Elijah Newren <newren@gmail•com>
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 cce91a2caef9 (Change 'master@noon' syntax to
'master@{noon}'., 2006-05-19) presumed that curly braces would always
come after an '@' or '^' and be paired, causing e.g. '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 either a '@' or '^' character appears.
Add tests for this, as well as for a few other test cases that initial
versions of this patch broke:
* 'foo@@{...}'
* 'foo^{/${SEARCH_TEXT_WITH_COLON}}:${PATH}'
Note that we'd prefer duplicating the special logic for "@^" characters
here, because if get_oid_basic() or interpret_nth_prior_checkout() or
get_oid_basic() or similar gain extra methods of using curly braces,
then the logic in get_oid_with_context_1() would need to be updated as
well. But it's not clear how to refactor all of these to have a simple
common callpoint with the specialized logic.
Reported-by: Gabriel Amaral <gabriel-amaral@github•com>
Helped-by: Michael Haggerty <mhagger@github•com>
Signed-off-by: Elijah Newren <newren@gmail•com>
---
object-name.c | 8 +++++---
t/t1006-cat-file.sh | 31 ++++++++++++++++++++++++++++++-
2 files changed, 35 insertions(+), 4 deletions(-)
diff --git a/object-name.c b/object-name.c
index a563635a8cb..8e80841acd3 100644
--- a/object-name.c
+++ b/object-name.c
@@ -2051,12 +2051,14 @@ static enum get_oid_result get_oid_with_context_1(struct repository *repo,
return -1;
}
for (cp = name, bracket_depth = 0; *cp; cp++) {
- if (*cp == '{')
+ if (strchr("@^", *cp) && cp[1] == '{') {
+ cp++;
bracket_depth++;
- else if (bracket_depth && *cp == '}')
+ } else if (bracket_depth && *cp == '}') {
bracket_depth--;
- else if (!bracket_depth && *cp == ':')
+ } else if (!bracket_depth && *cp == ':') {
break;
+ }
}
if (*cp == ':') {
struct object_id tree_oid;
diff --git a/t/t1006-cat-file.sh b/t/t1006-cat-file.sh
index ff9bf213aa2..398865d6ebe 100755
--- a/t/t1006-cat-file.sh
+++ b/t/t1006-cat-file.sh
@@ -240,7 +240,8 @@ test_expect_success "setup" '
git config extensions.objectformat $test_hash_algo &&
git config extensions.compatobjectformat $test_compat_hash_algo &&
echo_without_newline "$hello_content" > hello &&
- git update-index --add hello
+ git update-index --add hello &&
+ git commit -m "add hello file"
'
run_blob_tests () {
@@ -602,6 +603,34 @@ test_expect_success FUNNYNAMES '--batch-check, -Z with newline in input' '
test_cmp expect actual
'
+test_expect_success 'setup with curly braches in input' '
+ git branch "foo{bar" HEAD &&
+ git branch "foo@" HEAD
+'
+
+test_expect_success 'object reference with curly brace' '
+ git cat-file -p "foo{bar:hello" >actual &&
+ git cat-file -p HEAD:hello >expect &&
+ test_cmp expect actual
+'
+
+test_expect_success 'object reference with at-sign' '
+ git cat-file -p "foo@@{0}:hello" >actual &&
+ git cat-file -p HEAD:hello >expect &&
+ test_cmp expect actual
+'
+
+test_expect_success 'setup with commit with colon' '
+ git commit-tree -m "testing: just a bunch of junk" HEAD^{tree} >out &&
+ git branch other $(cat out)
+'
+
+test_expect_success 'object reference via commit text search' '
+ git cat-file -p "other^{/testing:}:hello" >actual &&
+ git cat-file -p HEAD:hello >expect &&
+ test_cmp expect actual
+'
+
test_expect_success 'setup blobs which are likely to delta' '
test-tool genrandom foo 10240 >foo &&
{ cat foo && echo plus; } >foo-plus &&
--
gitgitgadget
next prev parent reply other threads:[~2025-01-13 17:13 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-01 2:53 [PATCH] object-name: fix resolution of object names containing curly braces Elijah Newren via GitGitGadget
2025-01-01 17:00 ` Junio C Hamano
2025-01-03 23:34 ` Elijah Newren
2025-01-04 2:52 ` Junio C Hamano
2025-01-03 8:16 ` Patrick Steinhardt
2025-01-03 15:46 ` Junio C Hamano
2025-01-03 23:43 ` Elijah Newren
2025-01-04 0:17 ` [PATCH v2 0/2] " Elijah Newren via GitGitGadget
2025-01-04 0:17 ` [PATCH v2 1/2] " Elijah Newren via GitGitGadget
2025-01-04 17:26 ` Junio C Hamano
2025-01-04 18:54 ` Elijah Newren
2025-01-05 16:14 ` Junio C Hamano
2025-01-04 0:17 ` [PATCH v2 2/2] object-name: be more strict in parsing describe-like output Elijah Newren via GitGitGadget
2025-01-04 14:35 ` [PATCH v2 0/2] object-name: fix resolution of object names containing curly braces Junio C Hamano
2025-01-04 15:55 ` Elijah Newren
2025-01-04 17:51 ` Junio C Hamano
2025-01-04 18:55 ` Elijah Newren
2025-01-06 17:29 ` Junio C Hamano
2025-01-06 19:26 ` Elijah Newren
2025-01-06 20:38 ` Junio C Hamano
2025-01-13 17:13 ` [PATCH v3 0/2] object-name: fix a pair of object name resolution issues Elijah Newren via GitGitGadget
2025-01-13 17:13 ` Elijah Newren via GitGitGadget [this message]
2025-01-13 17:13 ` [PATCH v3 2/2] object-name: be more strict in parsing describe-like output Elijah Newren via GitGitGadget
2025-01-13 18:15 ` [PATCH v3 0/2] object-name: fix a pair of object name resolution issues Junio C Hamano
2025-01-13 19:26 ` Elijah Newren
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=b21b8fc555414789d835f454a0dce3bf685fdb4c.1736788417.git.gitgitgadget@gmail.com \
--to=gitgitgadget@gmail$(echo .)com \
--cc=git@vger$(echo .)kernel.org \
--cc=newren@gmail$(echo .)com \
--cc=ps@pks$(echo .)im \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox