summaryrefslogtreecommitdiff
path: root/refs/files-backend.c
diff options
context:
space:
mode:
authorJohn Cai <johncai86@gmail.com>2023-05-12 21:34:41 (GMT)
committerJunio C Hamano <gitster@pobox.com>2023-05-12 21:54:14 (GMT)
commit826ae79fca263bc2b70c54fddacb1603c5ebb9c6 (patch)
treef0a65557626ded284ed05b538dc0f886c067eb82 /refs/files-backend.c
parent283174b214c4c5416772dcacbc6389dd192969a0 (diff)
downloadgit-826ae79fca263bc2b70c54fddacb1603c5ebb9c6.zip
git-826ae79fca263bc2b70c54fddacb1603c5ebb9c6.tar.gz
git-826ae79fca263bc2b70c54fddacb1603c5ebb9c6.tar.bz2
pack-refs: teach --exclude option to exclude refs from being packed
At GitLab, we have a system that creates ephemeral internal refs that don't live long before getting deleted. Having an option to exclude certain refs from a packed-refs file allows these internal references to be deleted much more efficiently. Add an --exclude option to the pack-refs builtin, and use the ref exclusions API to exclude certain refs from being packed into the final packed-refs file Signed-off-by: John Cai <johncai86@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'refs/files-backend.c')
-rw-r--r--refs/files-backend.c16
1 files changed, 10 insertions, 6 deletions
diff --git a/refs/files-backend.c b/refs/files-backend.c
index d0581ee..8620e01 100644
--- a/refs/files-backend.c
+++ b/refs/files-backend.c
@@ -19,6 +19,7 @@
#include "../worktree.h"
#include "../wrapper.h"
#include "../write-or-die.h"
+#include "../revision.h"
/*
* This backend uses the following flags in `ref_update::flags` for
@@ -1173,15 +1174,18 @@ 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)
{
/* Do not pack per-worktree refs: */
if (parse_worktree_ref(refname, NULL, NULL, NULL) !=
REF_WORKTREE_SHARED)
return 0;
+ if (ref_excluded(opts->exclusions, refname))
+ return 0;
+
/* Do not pack non-tags unless PACK_REFS_ALL is set: */
- if (!(pack_flags & PACK_REFS_ALL) && !starts_with(refname, "refs/tags/"))
+ if (!(opts->flags & PACK_REFS_ALL) && !starts_with(refname, "refs/tags/"))
return 0;
/* Do not pack symbolic refs: */
@@ -1195,7 +1199,8 @@ static int should_pack_ref(const char *refname,
return 1;
}
-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,
@@ -1220,8 +1225,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;
/*
@@ -1235,7 +1239,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);