From: "Martin Ågren" <martin.agren@gmail.com>
To: git@vger.kernel.org
Cc: Jeff King <peff@peff.net>, Taylor Blau <me@ttaylorr.com>
Subject: [PATCH v1] load_ref_decorations(): fix decoration with tags
Date: Tue, 13 Jul 2021 00:41:52 +0200 [thread overview]
Message-ID: <20210712224152.2698500-1-martin.agren@gmail.com> (raw)
Commit 88473c8bae ("load_ref_decorations(): avoid parsing non-tag
objects", 2021-06-22) introduced a shortcut to `add_ref_decoration()`:
Rather than calling `parse_object()` directly, call `oid_object_info()`
and then either return early or go on to call `lookup_object_by_type()`
using the type just discovered. As detailed in the commit message, this
provides a significant time saving.
Unfortunately, it also changes the behavior. As an example, on git.git,
git log --oneline --decorate origin/master | grep '(.*tag:.*)'
returns zero hits after 88473c8bae. Before it, we have around 800 hits.
What happens is, all annotated tags are lost from the decoration.
Let's do a partial revert of 88473c8bae: Keep doing that early
`oid_object_info()`, but after that, go on with the full
`parse_object()`. This restores the pre-88473c8bae behavior. We clearly
have lacking test coverage here, so make sure to add a test. Without
this fix to log-tree.c, the git-log invocation in this new test does
pick up the lightweight tags involved, but misses out on the annotated
tag.
Signed-off-by: Martin Ågren <martin.agren@gmail.com>
---
Cc-ing Peff, the author of 88473c8bae, and Taylor, who made a comment
regarding the peeling of tags [1], which might be related.
I'm genuinely unconvinced that my proposed fix is the best possible one.
Or maybe trying a more surgical fix around annotated tags misses a
whole bunch of *other* special cases and we really should go for the
full `parse_object()` to cover all possibilities.
In my brief testing (time git log -1 --decorate on git.git), the time
savings from 88473c8bae seem to be gone. So maybe this should be a full
revert, rather than a partial one. (Plus the test.) Let's hope that
won't be necessary.
Also, I'm not sure whether the test really needs to worry about the
order of the decorations suddenly changing -- maybe it's supposed to be
stable.
[1] https://lore.kernel.org/git/YNKgkGkPiMgNubNE@nand.local/
log-tree.c | 6 ++----
t/t4202-log.sh | 14 ++++++++++++++
2 files changed, 16 insertions(+), 4 deletions(-)
diff --git a/log-tree.c b/log-tree.c
index 4f69ed176d..0b638d2e3c 100644
--- a/log-tree.c
+++ b/log-tree.c
@@ -134,7 +134,6 @@ static int add_ref_decoration(const char *refname, const struct object_id *oid,
int flags, void *cb_data)
{
struct object *obj;
- enum object_type objtype;
enum decoration_type deco_type = DECORATION_NONE;
struct decoration_filter *filter = (struct decoration_filter *)cb_data;
@@ -156,10 +155,9 @@ static int add_ref_decoration(const char *refname, const struct object_id *oid,
return 0;
}
- objtype = oid_object_info(the_repository, oid, NULL);
- if (objtype < 0)
+ if (oid_object_info(the_repository, oid, NULL) < 0)
return 0;
- obj = lookup_object_by_type(the_repository, oid, objtype);
+ obj = parse_object(the_repository, oid);
if (starts_with(refname, "refs/heads/"))
deco_type = DECORATION_REF_LOCAL;
diff --git a/t/t4202-log.sh b/t/t4202-log.sh
index 350cfa3593..3aa5451913 100755
--- a/t/t4202-log.sh
+++ b/t/t4202-log.sh
@@ -1905,6 +1905,20 @@ test_expect_success '--exclude-promisor-objects does not BUG-crash' '
test_must_fail git log --exclude-promisor-objects source-a
'
+test_expect_success 'log --decorate includes, e.g., all kinds of tags' '
+ git log --oneline --decorate >log &&
+ test_line_count = 2 log &&
+ grep "^1ac6c77 (tag: one) one$" log &&
+ grep HEAD log | sed -e "s/^.*(\(.*\)).*$/\1/" -e "s/, /\n/g" |
+ sort >actual &&
+ cat >expect <<-\EOF &&
+ HEAD -> source-b
+ tag: source-tag
+ tag: three
+ EOF
+ test_cmp expect actual
+'
+
test_expect_success 'log --end-of-options' '
git update-ref refs/heads/--source HEAD &&
git log --end-of-options --source >actual &&
--
2.32.0.402.g57bb445576
next reply other threads:[~2021-07-12 22:42 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-12 22:41 Martin Ågren [this message]
2021-07-13 0:06 ` [PATCH v1] load_ref_decorations(): fix decoration with tags Jeff King
2021-07-13 7:40 ` [PATCH v2] " Martin Ågren
2021-07-13 7:52 ` Jeff King
2021-07-13 8:47 ` Martin Ågren
2021-07-13 21:17 ` Junio C Hamano
2021-07-13 21:27 ` Jeff King
2021-07-13 21:40 ` Junio C Hamano
2021-07-13 21:52 ` Martin Ågren
2021-07-13 22:22 ` Jeff King
2021-07-14 8:13 ` Martin Ågren
2021-07-14 16:31 ` [PATCH v3] " Jeff King
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=20210712224152.2698500-1-martin.agren@gmail.com \
--to=martin.agren@gmail.com \
--cc=git@vger.kernel.org \
--cc=me@ttaylorr.com \
--cc=peff@peff.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
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;
as well as URLs for NNTP newsgroup(s).