Download raw body.
tog log: make ^L stick to current branch
On Sat, Dec 05, 2020 at 09:26:56PM +0100, Christian Weisgerber wrote:
> Stefan Sperling:
>
> > got up -b main
> > tog log -c mybranch
> > -> tog now displays commits starting at 'mybranch'
> > ^L
> > -> tog now displays commits starting at 'main' instead of 'mybranch'
>
> Here's another variant of this problem which your diff also fixes:
>
> cd repo.git
> tog log -c mybranch
> -> tog now displays commits starting at 'mybranch'
> ^L
> -> tog now displays commits starting at 'main' instead of 'mybranch'
>
> > This patch fixes the problem. If a reference is passed to the -c option,
> > remember this reference instead of the work tree's current branch.
>
> Yes. But now this happens:
>
> tog log -c 0.44
> ^L
> tog: bad object data
Wonderful! You have triggered a bug in got_repo_object_match_tag().
This function does not work correctly if its input is an absolute reference
name such as "refs/tags/0.44". It only works for input like "0.44".
Here's my proposed fix:
diff 5a8b5076742038c09dece0c1e59ecddf8cd7a41a /home/stsp/src/got
blob - e604a6980724929b924f7abf1a893dcaafca0590
file + lib/repository.c
--- lib/repository.c
+++ lib/repository.c
@@ -1502,6 +1502,7 @@ got_repo_object_match_tag(struct got_tag_object **tag,
struct got_reflist_head refs;
struct got_reflist_entry *re;
struct got_object_id *tag_id;
+ int name_is_absolute = (strncmp(name, "refs/", 5) == 0);
SIMPLEQ_INIT(&refs);
*tag = NULL;
@@ -1515,7 +1516,8 @@ got_repo_object_match_tag(struct got_tag_object **tag,
refname = got_ref_get_name(re->ref);
if (got_ref_is_symbolic(re->ref))
continue;
- refname += strlen("refs/tags/");
+ if (!name_is_absolute)
+ refname += strlen("refs/tags/");
if (strcmp(refname, name) != 0)
continue;
err = got_ref_resolve(&tag_id, repo, re->ref);
tog log: make ^L stick to current branch