git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 5/6] refs: stop resolving ref corresponding to reflogs

From
Junio C Hamano <gitster@pobox.com>
Date
Feb 20, 2024, 00:14 UTC
Message-ID
<xmqqjzn0yote.fsf@gitster.g>
In-Reply-To
<a7459b9483660d1a44df500aaee85ad38146eb02.1708353264.git.ps@pks.im>
Patrick Steinhardt <ps@pks.im> writes:
Show 5 quoted lines
> Refactor the code to call `check_refname_format()` directly instead of
> trying to resolve the ref. This is significantly more efficient given
> that we don't have to hit the object database anymore to list reflogs.
> And second, it ensures that we end up showing reflogs of broken refs,
> which will help to make the reflog more useful.

And the user would notice corrupt ones among those reflogs listed when using "rev-list -g" on the reflog anyway? Which sounds like a sensible thing to do.

Show 5 quoted lines
> Note that this really only impacts the case where the corresponding ref
> is corrupt. Reflogs for nonexistent refs would have been returned to the
> caller beforehand already as we did not pass `RESOLVE_REF_READING` to
> the function, and thus `refs_resolve_ref_unsafe()` would have returned
> successfully in that case.

What do "Reflogs for nonexistent refs" really mean? With the files backend, if "git branch -d main" that removed the "main" branch somehow forgot to remove the ".git/logs/refs/heads/main" file, the reflog entries in such a file is for nonexistent ref. Is that what you meant? As a tool to help diagnosing and correcting minor repo breakages, finding such a leftover file that should not exist is a good idea, I would think.

Would we see missing reflog for a ref that exists in the iteration? I guess we shouldn't, as the reflog iterator that recursively enumerates files under "$GIT_DIR/logs/" would not see such a missing reflog by definition.

Show 12 quoted lines
> diff --git a/refs/files-backend.c b/refs/files-backend.c
> index 2b3c99b00d..741148087d 100644
> --- a/refs/files-backend.c
> +++ b/refs/files-backend.c
> @@ -2130,17 +2130,9 @@ static int files_reflog_iterator_advance(struct ref_iterator *ref_iterator)
>  	while ((ok = dir_iterator_advance(diter)) == ITER_OK) {
>  		if (!S_ISREG(diter->st.st_mode))
>  			continue;
> -		if (diter->basename[0] == '.')
> +		if (check_refname_format(diter->basename,
> +					 REFNAME_ALLOW_ONELEVEL))
>  			continue;
A tangent.

I've never liked the code arrangement in the check_refname_format() that assumes that each level can be separately checked with exactly the same logic, and the only thing ALLOW_ONELEVEL does is to include pseudorefs and HEAD; this makes such assumption even more ingrained. I am not sure what to think about it, but let's keep reading.

> -		if (ends_with(diter->basename, ".lock"))
> -			continue;
This can safely go, as it is rejected by check_refname_format().
Show 6 quoted lines
> -		if (!refs_resolve_ref_unsafe(iter->ref_store,
> -					     diter->relative_path, 0,
> -					     NULL, NULL)) {
> -			error("bad ref for %s", diter->path.buf);
> -			continue;
> -		}

This is the focus of this step in the series. We did not abort the iteration before, but now we no longer issue any error message.

Show 17 quoted lines
>  		iter->base.refname = diter->relative_path;
>  		return ITER_OK;
> diff --git a/refs/reftable-backend.c b/refs/reftable-backend.c
> index 889bb1f1ba..efbbf23c72 100644
> --- a/refs/reftable-backend.c
> +++ b/refs/reftable-backend.c
> @@ -1659,11 +1659,9 @@ static int reftable_reflog_iterator_advance(struct ref_iterator *ref_iterator)
>  		if (iter->last_name && !strcmp(iter->log.refname, iter->last_name))
>  			continue;
>  
> -		if (!refs_resolve_ref_unsafe(&iter->refs->base, iter->log.refname,
> -					     0, NULL, NULL)) {
> -			error(_("bad ref for %s"), iter->log.refname);
> +		if (check_refname_format(iter->log.refname,
> +					 REFNAME_ALLOW_ONELEVEL))
>  			continue;
> -		}
This side is much more straight-forward.  Looking good.
>  
>  		free(iter->last_name);
>  		iter->last_name = xstrdup(iter->log.refname);
Previous: Patrick SteinhardtNext: Patrick Steinhardt
Message 13 of 39 in “reflog: introduce subcommand to list reflogs”
  1. 0/6 reflog: introduce subcommand to list reflogsPatrick Steinhardt, Feb 19, 2024
  2. 1/6 dir-iterator: pass name to `prepare_next_entry_data()` directlyPatrick Steinhardt, Feb 19, 2024
  3. 2/6 dir-iterator: support iteration in sorted orderPatrick Steinhardt, Feb 19, 2024
  4. Junio C HamanoFeb 19, 2024
  5. Patrick SteinhardtFeb 20, 2024
  6. 3/6 refs/files: sort reflogs returned by the reflog iteratorPatrick Steinhardt, Feb 19, 2024
  7. Junio C HamanoFeb 20, 2024
  8. Patrick SteinhardtFeb 20, 2024
  9. 4/6 refs: drop unused params from the reflog iterator callbackPatrick Steinhardt, Feb 19, 2024
  10. Junio C HamanoFeb 20, 2024
  11. Patrick SteinhardtFeb 20, 2024
  12. 5/6 refs: stop resolving ref corresponding to reflogsPatrick Steinhardt, Feb 19, 2024
  13. Junio C HamanoFeb 20, 2024
  14. Patrick SteinhardtFeb 20, 2024
  15. 6/6 builtin/reflog: introduce subcommand to list reflogsPatrick Steinhardt, Feb 19, 2024
  16. Junio C HamanoFeb 20, 2024
  17. Patrick SteinhardtFeb 20, 2024
  18. 0/7 reflog: introduce subcommand to list reflogsPatrick Steinhardt, Feb 20, 2024
  19. 1/7 dir-iterator: pass name to `prepare_next_entry_data()` directlyPatrick Steinhardt, Feb 20, 2024
  20. 2/7 dir-iterator: support iteration in sorted orderPatrick Steinhardt, Feb 20, 2024
  21. 3/7 refs/files: sort reflogs returned by the reflog iteratorPatrick Steinhardt, Feb 20, 2024
  22. 4/7 refs: always treat iterators as orderedPatrick Steinhardt, Feb 20, 2024
  23. 5/7 refs: drop unused params from the reflog iterator callbackPatrick Steinhardt, Feb 20, 2024
  24. 6/7 refs: stop resolving ref corresponding to reflogsPatrick Steinhardt, Feb 20, 2024
  25. 7/7 builtin/reflog: introduce subcommand to list reflogsPatrick Steinhardt, Feb 20, 2024
  26. 7/7 builtin/reflog: introduce subcommand to list reflogsTeng Long, Apr 24, 2024
  27. Patrick SteinhardtApr 24, 2024
  28. Junio C HamanoApr 24, 2024
  29. Junio C HamanoFeb 20, 2024
  30. Patrick SteinhardtFeb 21, 2024
  31. 0/8 reflog: introduce subcommand to list reflogsPatrick Steinhardt, Feb 21, 2024
  32. 1/8 dir-iterator: pass name to `prepare_next_entry_data()` directlyPatrick Steinhardt, Feb 21, 2024
  33. 2/8 dir-iterator: support iteration in sorted orderPatrick Steinhardt, Feb 21, 2024
  34. 3/8 refs/files: sort reflogs returned by the reflog iteratorPatrick Steinhardt, Feb 21, 2024
  35. 4/8 refs/files: sort merged worktree and common reflogsPatrick Steinhardt, Feb 21, 2024
  36. 5/8 refs: always treat iterators as orderedPatrick Steinhardt, Feb 21, 2024
  37. 6/8 refs: drop unused params from the reflog iterator callbackPatrick Steinhardt, Feb 21, 2024
  38. 7/8 refs: stop resolving ref corresponding to reflogsPatrick Steinhardt, Feb 21, 2024
  39. 8/8 builtin/reflog: introduce subcommand to list reflogsPatrick Steinhardt, Feb 21, 2024

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.