summaryrefslogtreecommitdiff
path: root/refs
diff options
context:
space:
mode:
authorMichael Haggerty <mhagger@alum.mit.edu>2017-05-22 16:17:48 +0200
committerJunio C Hamano <gitster@pobox.com>2017-05-23 14:29:55 +0900
commit531cc4a56da1eff87cb57d90012197eb6d721edd (patch)
tree6bb6caa35ec9c613d258b1d501185d4572e19b44 /refs
parent8556f8d61330ec677dc48b0ef39e2017d6927708 (diff)
downloadgit-531cc4a56da1eff87cb57d90012197eb6d721edd.tar.gz
should_pack_ref(): new function, extracted from `files_pack_refs()`
Extract a function for deciding whether a reference should be packed. It is a self-contained bit of logic, so splitting it out improves readability. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'refs')
-rw-r--r--refs/files-backend.c42
1 files changed, 28 insertions, 14 deletions
diff --git a/refs/files-backend.c b/refs/files-backend.c
index 8d0ce739a6..29514392b0 100644
--- a/refs/files-backend.c
+++ b/refs/files-backend.c
@@ -1455,6 +1455,32 @@ static void prune_refs(struct files_ref_store *refs, struct ref_to_prune *r)
}
}
+/*
+ * Return true if the specified reference should be packed.
+ */
+static int should_pack_ref(const char *refname,
+ const struct object_id *oid, unsigned int ref_flags,
+ unsigned int pack_flags)
+{
+ /* Do not pack per-worktree refs: */
+ if (ref_type(refname) != REF_TYPE_NORMAL)
+ 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;
+
+ /* Do not pack broken refs: */
+ if (!ref_resolves_to_object(refname, oid, ref_flags))
+ return 0;
+
+ return 1;
+}
+
static int files_pack_refs(struct ref_store *ref_store, unsigned int flags)
{
struct files_ref_store *refs =
@@ -1476,21 +1502,9 @@ static int files_pack_refs(struct ref_store *ref_store, unsigned int flags)
* pruned, also add it to refs_to_prune.
*/
struct ref_entry *packed_entry;
- int is_tag_ref = starts_with(iter->refname, "refs/tags/");
-
- /* Do not pack per-worktree refs: */
- if (ref_type(iter->refname) != REF_TYPE_NORMAL)
- continue;
-
- /* ALWAYS pack tags */
- if (!(flags & PACK_REFS_ALL) && !is_tag_ref)
- continue;
-
- /* Do not pack symbolic or broken refs: */
- if (iter->flags & REF_ISSYMREF)
- continue;
- if (!ref_resolves_to_object(iter->refname, iter->oid, iter->flags))
+ if (!should_pack_ref(iter->refname, iter->oid, iter->flags,
+ flags))
continue;
/*