diff options
author | Junio C Hamano <gitster@pobox.com> | 2024-03-05 18:44:44 +0100 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2024-03-05 18:44:44 +0100 |
commit | d037212d973351ced4a3f0bb0705575bee4f8566 (patch) | |
tree | 34c0fc73c87850a10df780c5c6a4ecc446be7b6b /ref-filter.c | |
parent | Merge branch 'pb/ort-make-submodule-conflict-message-an-advice' (diff) | |
parent | for-each-ref: add new option to include root refs (diff) | |
download | git-d037212d973351ced4a3f0bb0705575bee4f8566.tar.xz git-d037212d973351ced4a3f0bb0705575bee4f8566.zip |
Merge branch 'kn/for-all-refs'
"git for-each-ref" learned "--include-root-refs" option to show
even the stuff outside the 'refs/' hierarchy.
* kn/for-all-refs:
for-each-ref: add new option to include root refs
ref-filter: rename 'FILTER_REFS_ALL' to 'FILTER_REFS_REGULAR'
refs: introduce `refs_for_each_include_root_refs()`
refs: extract out `loose_fill_ref_dir_regular_file()`
refs: introduce `is_pseudoref()` and `is_headref()`
Diffstat (limited to 'ref-filter.c')
-rw-r--r-- | ref-filter.c | 30 |
1 files changed, 27 insertions, 3 deletions
diff --git a/ref-filter.c b/ref-filter.c index be14b56e32..0ec29f7385 100644 --- a/ref-filter.c +++ b/ref-filter.c @@ -2628,6 +2628,12 @@ static int for_each_fullref_in_pattern(struct ref_filter *filter, each_ref_fn cb, void *cb_data) { + if (filter->kind == FILTER_REFS_KIND_MASK) { + /* In this case, we want to print all refs including root refs. */ + return refs_for_each_include_root_refs(get_main_ref_store(the_repository), + cb, cb_data); + } + if (!filter->match_as_path) { /* * in this case, the patterns are applied after @@ -2750,6 +2756,9 @@ static int ref_kind_from_refname(const char *refname) return ref_kind[i].kind; } + if (is_pseudoref(get_main_ref_store(the_repository), refname)) + return FILTER_REFS_PSEUDOREFS; + return FILTER_REFS_OTHERS; } @@ -2781,7 +2790,16 @@ static struct ref_array_item *apply_ref_filter(const char *refname, const struct /* Obtain the current ref kind from filter_ref_kind() and ignore unwanted refs. */ kind = filter_ref_kind(filter, refname); - if (!(kind & filter->kind)) + + /* + * Generally HEAD refs are printed with special description denoting a rebase, + * detached state and so forth. This is useful when only printing the HEAD ref + * But when it is being printed along with other pseudorefs, it makes sense to + * keep the formatting consistent. So we mask the type to act like a pseudoref. + */ + if (filter->kind == FILTER_REFS_KIND_MASK && kind == FILTER_REFS_DETACHED_HEAD) + kind = FILTER_REFS_PSEUDOREFS; + else if (!(kind & filter->kind)) return NULL; if (!filter_pattern_match(filter, refname)) @@ -3047,9 +3065,15 @@ static int do_filter_refs(struct ref_filter *filter, unsigned int type, each_ref ret = for_each_fullref_in("refs/remotes/", fn, cb_data); else if (filter->kind == FILTER_REFS_TAGS) ret = for_each_fullref_in("refs/tags/", fn, cb_data); - else if (filter->kind & FILTER_REFS_ALL) + else if (filter->kind & FILTER_REFS_REGULAR) ret = for_each_fullref_in_pattern(filter, fn, cb_data); - if (!ret && (filter->kind & FILTER_REFS_DETACHED_HEAD)) + + /* + * When printing all ref types, HEAD is already included, + * so we don't want to print HEAD again. + */ + if (!ret && (filter->kind != FILTER_REFS_KIND_MASK) && + (filter->kind & FILTER_REFS_DETACHED_HEAD)) head_ref(fn, cb_data); } |