diff options
| author | Karthik Nayak <karthik.188@gmail.com> | 2024-02-23 11:01:12 +0100 |
|---|---|---|
| committer | Junio C Hamano <gitster@pobox.com> | 2024-02-23 10:36:28 -0800 |
| commit | 33d15b54358d8ec7fc0bd70062ddd1116402c8fe (patch) | |
| tree | 8d5c2bcc53bb8018a27b96dbc8729b132d0dd20d /refs | |
| parent | 810f7a1aace85ed9ffc454db6726c818c86685f0 (diff) | |
| download | git-33d15b54358d8ec7fc0bd70062ddd1116402c8fe.tar.xz | |
for-each-ref: add new option to include root refs
The git-for-each-ref(1) command doesn't provide a way to print root refs
i.e pseudorefs and HEAD with the regular "refs/" prefixed refs.
This commit adds a new option "--include-root-refs" to
git-for-each-ref(1). When used this would also print pseudorefs and HEAD
for the current worktree.
Signed-off-by: Karthik Nayak <karthik.188@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'refs')
| -rw-r--r-- | refs/reftable-backend.c | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/refs/reftable-backend.c b/refs/reftable-backend.c index a14f2ad7f4..c23a516ac2 100644 --- a/refs/reftable-backend.c +++ b/refs/reftable-backend.c @@ -364,12 +364,15 @@ static int reftable_ref_iterator_advance(struct ref_iterator *ref_iterator) break; /* - * The files backend only lists references contained in - * "refs/". We emulate the same behaviour here and thus skip - * all references that don't start with this prefix. + * The files backend only lists references contained in "refs/" unless + * the root refs are to be included. We emulate the same behaviour here. */ - if (!starts_with(iter->ref.refname, "refs/")) + if (!starts_with(iter->ref.refname, "refs/") && + !(iter->flags & DO_FOR_EACH_INCLUDE_ROOT_REFS && + (is_pseudoref(&iter->refs->base, iter->ref.refname) || + is_headref(&iter->refs->base, iter->ref.refname)))) { continue; + } if (iter->prefix && strncmp(iter->prefix, iter->ref.refname, strlen(iter->prefix))) { |
