diff options
author | Junio C Hamano <gitster@pobox.com> | 2023-06-13 19:29:45 (GMT) |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2023-06-13 19:29:45 (GMT) |
commit | cbc882ea388143bd6bbed139f97f67589777be60 (patch) | |
tree | 31f750427a978f17391c2be83e836d28b25fdee0 /refs/files-backend.c | |
parent | ebd07c9f7e5d56fbe9d5816db95ecf137ed447ea (diff) | |
parent | 4fe42f326e10a547dc65dfe9e5ceaeeee02b98db (diff) | |
download | git-cbc882ea388143bd6bbed139f97f67589777be60.zip git-cbc882ea388143bd6bbed139f97f67589777be60.tar.gz git-cbc882ea388143bd6bbed139f97f67589777be60.tar.bz2 |
Merge branch 'jc/pack-ref-exclude-include'
"git pack-refs" learns "--include" and "--exclude" to tweak the ref
hierarchy to be packed using pattern matching.
* jc/pack-ref-exclude-include:
pack-refs: teach pack-refs --include option
pack-refs: teach --exclude option to exclude refs from being packed
docs: clarify git-pack-refs --all will pack all refs
Diffstat (limited to 'refs/files-backend.c')
-rw-r--r-- | refs/files-backend.c | 27 |
1 files changed, 17 insertions, 10 deletions
diff --git a/refs/files-backend.c b/refs/files-backend.c index bca7b85..9a8333c 100644 --- a/refs/files-backend.c +++ b/refs/files-backend.c @@ -21,6 +21,8 @@ #include "../worktree.h" #include "../wrapper.h" #include "../write-or-die.h" +#include "../revision.h" +#include <wildmatch.h> /* * This backend uses the following flags in `ref_update::flags` for @@ -1175,17 +1177,15 @@ static void prune_refs(struct files_ref_store *refs, struct ref_to_prune **refs_ */ static int should_pack_ref(const char *refname, const struct object_id *oid, unsigned int ref_flags, - unsigned int pack_flags) + struct pack_refs_opts *opts) { + struct string_list_item *item; + /* Do not pack per-worktree refs: */ if (parse_worktree_ref(refname, NULL, NULL, NULL) != REF_WORKTREE_SHARED) return 0; - /* Do not pack non-tags unless PACK_REFS_ALL is set: */ - if (!(pack_flags & PACK_REFS_ALL) && !starts_with(refname, "refs/tags/")) - return 0; - /* Do not pack symbolic refs: */ if (ref_flags & REF_ISSYMREF) return 0; @@ -1194,10 +1194,18 @@ static int should_pack_ref(const char *refname, if (!ref_resolves_to_object(refname, the_repository, oid, ref_flags)) return 0; - return 1; + if (ref_excluded(opts->exclusions, refname)) + return 0; + + for_each_string_list_item(item, opts->includes) + if (!wildmatch(item->string, refname, 0)) + return 1; + + return 0; } -static int files_pack_refs(struct ref_store *ref_store, unsigned int flags) +static int files_pack_refs(struct ref_store *ref_store, + struct pack_refs_opts *opts) { struct files_ref_store *refs = files_downcast(ref_store, REF_STORE_WRITE | REF_STORE_ODB, @@ -1222,8 +1230,7 @@ static int files_pack_refs(struct ref_store *ref_store, unsigned int flags) * in the packed ref cache. If the reference should be * pruned, also add it to refs_to_prune. */ - if (!should_pack_ref(iter->refname, iter->oid, iter->flags, - flags)) + if (!should_pack_ref(iter->refname, iter->oid, iter->flags, opts)) continue; /* @@ -1237,7 +1244,7 @@ static int files_pack_refs(struct ref_store *ref_store, unsigned int flags) iter->refname, err.buf); /* Schedule the loose reference for pruning if requested. */ - if ((flags & PACK_REFS_PRUNE)) { + if ((opts->flags & PACK_REFS_PRUNE)) { struct ref_to_prune *n; FLEX_ALLOC_STR(n, name, iter->refname); oidcpy(&n->oid, iter->oid); |