should_pack_ref(): new function, extracted from `files_pack_refs()`
authorMichael Haggerty <mhagger@alum.mit.edu>
Mon, 22 May 2017 14:17:48 +0000 (16:17 +0200)
committerJunio C Hamano <gitster@pobox.com>
Tue, 23 May 2017 05:29:55 +0000 (14:29 +0900)
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>
refs/files-backend.c
index 8d0ce739a602b69df5ea2bc77ecd6b8c9a6ec4e3..29514392b014abeac8ca3e9858f5cb39e4f77102 100644 (file)
@@ -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;
 
                /*