Subject: [PATCH 0/4] keep track of unresolved value of symbolic-ref in ref iterators

From: "John Cai via GitGitGadget" <[email-masked]>
Date: Thu, 06 Jun 2024 17:26:36 +0000

For reftable development, it's useful to be able to print out the direct
value of a symbolic reference before resolution. This is currently possible
with git-for-each-ref, but since the iterators do not keep track of the
value of the symbolic ref, a separate call needs to be made each time making
it inefficient.

Address this inefficiency by keeping track of the value of the symbolic
reference in the ref iterator. This patch series also ends with a commit to
use this value in the iterator through callbacks in ref-filter.c.

This series started with [1] but I decided to send a separate patch series
since it is substantially different.

Benchmarking shows that with these changes, we experience a significant
speedup in git-for-each-ref(1):

$ hyperfine --warmup 5 "git for-each-ref --format='%(refname) %(objectname)
%(symref)'" "~/Projects/git/git for-each-ref --format='%(refname)
%(objectname) %(symref)'"

Benchmark 1: git for-each-ref --format='%(refname) %(objectname) %(symref)'
Time (mean ± σ): 210.0 ms ± 9.1 ms [User: 5.8 ms, System: 11.8 ms] Range
(min … max): 203.4 ms … 228.8 ms 12 runs

Benchmark 2: ~/Projects/git/git for-each-ref --format='%(refname)
%(objectname) %(symref)' Time (mean ± σ): 7.4 ms ± 0.7 ms [User: 2.6 ms,
System: 3.9 ms] Range (min … max): 5.9 ms … 11.7 ms 273 runs

Summary ~/Projects/git/git for-each-ref --format='%(refname) %(objectname)
%(symref)' ran 28.47 ± 2.86 times faster than git for-each-ref
--format='%(refname) %(objectname) %(symref)'

 1. https://lore.kernel.org/git/[email-masked]/

John Cai (4):
  refs: add referent parameter to refs_resolve_ref_unsafe
  refs: keep track of unresolved reference value in iterators
  refs: add referent to each_ref_fn
  ref-filter: populate symref from iterator

 add-interactive.c           |  6 +++---
 bisect.c                    |  3 ++-
 blame.c                     |  4 ++--
 builtin/bisect.c            |  6 ++++--
 builtin/blame.c             |  2 +-
 builtin/branch.c            |  2 +-
 builtin/checkout.c          |  2 +-
 builtin/describe.c          |  2 +-
 builtin/fetch.c             |  3 ++-
 builtin/fsck.c              |  6 +++---
 builtin/gc.c                |  1 +
 builtin/log.c               |  1 +
 builtin/name-rev.c          |  2 +-
 builtin/pack-objects.c      |  5 +++--
 builtin/rebase.c            |  6 +++---
 builtin/receive-pack.c      |  4 ++--
 builtin/remote.c            |  6 ++++--
 builtin/repack.c            |  1 +
 builtin/replace.c           |  1 +
 builtin/rev-parse.c         |  4 ++--
 builtin/show-branch.c       |  8 ++++----
 builtin/show-ref.c          |  3 ++-
 builtin/stash.c             |  2 +-
 builtin/submodule--helper.c |  5 +++--
 builtin/symbolic-ref.c      |  2 +-
 builtin/worktree.c          |  1 +
 commit-graph.c              |  1 +
 config.c                    |  2 +-
 delta-islands.c             |  2 +-
 fetch-pack.c                |  2 ++
 help.c                      |  2 +-
 http-backend.c              |  5 +++--
 log-tree.c                  |  4 ++--
 ls-refs.c                   |  7 ++++---
 midx-write.c                |  2 +-
 negotiator/default.c        |  2 +-
 negotiator/skipping.c       |  2 +-
 notes.c                     |  2 +-
 object-name.c               |  2 +-
 reachable.c                 |  2 +-
 ref-filter.c                | 11 ++++++-----
 reflog.c                    |  1 +
 refs.c                      | 32 ++++++++++++++++++--------------
 refs.h                      |  3 ++-
 refs/files-backend.c        | 24 ++++++++++++++----------
 refs/iterator.c             |  5 ++++-
 refs/ref-cache.c            |  6 ++++++
 refs/ref-cache.h            |  2 ++
 refs/refs-internal.h        |  1 +
 refs/reftable-backend.c     |  6 +++---
 remote.c                    | 10 +++++-----
 replace-object.c            |  1 +
 revision.c                  |  4 ++--
 sequencer.c                 |  9 +++++----
 server-info.c               |  2 +-
 shallow.c                   |  2 ++
 submodule.c                 |  2 ++
 t/helper/test-ref-store.c   |  4 ++--
 transport-helper.c          |  1 +
 transport.c                 |  2 +-
 upload-pack.c               | 10 +++++-----
 walker.c                    |  1 +
 worktree.c                  |  6 ++++--
 63 files changed, 161 insertions(+), 109 deletions(-)

base-commit: 7b0defb3915eaa0bd118f0996e8c00b4eb2dc1ca
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-1712%2Fjohn-cai%2Fjc%2Fsymbolic-ref-in-iterator-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-1712/john-cai/jc/symbolic-ref-in-iterator-v1
Pull-Request: https://github.com/git/git/pull/1712
-- 
gitgitgadget