Skip to content

Commit 59c50a9

Browse files
pks-tgitster
authored andcommitted
refs: stop resolving ref corresponding to reflogs
The reflog iterator tries to resolve the corresponding ref for every reflog that it is about to yield. Historically, this was done due to multiple reasons: - It ensures that the refname is safe because we end up calling `check_refname_format()`. Also, non-conformant refnames are skipped altogether. - The iterator used to yield the resolved object ID as well as its flags to the callback. This info was never used though, and the corresponding parameters were dropped in the preceding commit. - When a ref is corrupt then the reflog is not emitted at all. We're about to introduce a new `git reflog list` subcommand that will print all reflogs that the refdb knows about. Skipping over reflogs whose refs are corrupted would be quite counterproductive in this case as the user would have no way to learn about reflogs which may still exist in their repository to help and rescue such a corrupted ref. Thus, the only remaining reason for why we'd want to resolve the ref is to verify its refname. 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. 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. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 31f8983 commit 59c50a9

File tree

2 files changed

+4
-14
lines changed

2 files changed

+4
-14
lines changed

refs/files-backend.c

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2129,17 +2129,9 @@ static int files_reflog_iterator_advance(struct ref_iterator *ref_iterator)
21292129
while ((ok = dir_iterator_advance(diter)) == ITER_OK) {
21302130
if (!S_ISREG(diter->st.st_mode))
21312131
continue;
2132-
if (diter->basename[0] == '.')
2132+
if (check_refname_format(diter->basename,
2133+
REFNAME_ALLOW_ONELEVEL))
21332134
continue;
2134-
if (ends_with(diter->basename, ".lock"))
2135-
continue;
2136-
2137-
if (!refs_resolve_ref_unsafe(iter->ref_store,
2138-
diter->relative_path, 0,
2139-
NULL, NULL)) {
2140-
error("bad ref for %s", diter->path.buf);
2141-
continue;
2142-
}
21432135

21442136
iter->base.refname = diter->relative_path;
21452137
return ITER_OK;

refs/reftable-backend.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1616,11 +1616,9 @@ static int reftable_reflog_iterator_advance(struct ref_iterator *ref_iterator)
16161616
if (iter->last_name && !strcmp(iter->log.refname, iter->last_name))
16171617
continue;
16181618

1619-
if (!refs_resolve_ref_unsafe(&iter->refs->base, iter->log.refname,
1620-
0, NULL, NULL)) {
1621-
error(_("bad ref for %s"), iter->log.refname);
1619+
if (check_refname_format(iter->log.refname,
1620+
REFNAME_ALLOW_ONELEVEL))
16221621
continue;
1623-
}
16241622

16251623
free(iter->last_name);
16261624
iter->last_name = xstrdup(iter->log.refname);

0 commit comments

Comments
 (0)