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>
Michael Haggerty committed
May 22, 2017 at 16:17 UTC
531cc4a56da1eff87cb57d90012197eb6d721edd
1 file changed
+28
-14
refs/files-backend.c
+28
-14
@@ -1455,6 +1455,32 @@ static void prune_refs(struct files_ref_store *refs, struct ref_to_prune *r)
1455
}
1456
}
1457
1458
+/*
1459
+ * Return true if the specified reference should be packed.
1460
+ */
1461
+static int should_pack_ref(const char *refname,
1462
+ const struct object_id *oid, unsigned int ref_flags,
1463
+ unsigned int pack_flags)
1464
+{
1465
+ /* Do not pack per-worktree refs: */
1466
+ if (ref_type(refname) != REF_TYPE_NORMAL)
1467
+ return 0;
1468
+
1469
+ /* Do not pack non-tags unless PACK_REFS_ALL is set: */
1470
+ if (!(pack_flags & PACK_REFS_ALL) && !starts_with(refname, "refs/tags/"))
1471
+ return 0;
1472
+
1473
+ /* Do not pack symbolic refs: */
1474
+ if (ref_flags & REF_ISSYMREF)
1475
+ return 0;
1476
+
1477
+ /* Do not pack broken refs: */
1478
+ if (!ref_resolves_to_object(refname, oid, ref_flags))
1479
+ return 0;
1480
+
1481
+ return 1;
1482
+}
1483
+
1484
static int files_pack_refs(struct ref_store *ref_store, unsigned int flags)
1485
{
1486
struct files_ref_store *refs =
@@ -1476,21 +1502,9 @@ static int files_pack_refs(struct ref_store *ref_store, unsigned int flags)
1502
* pruned, also add it to refs_to_prune.
1503
*/
1504
struct ref_entry *packed_entry;
1479
- int is_tag_ref = starts_with(iter->refname, "refs/tags/");
1480
-
1481
- /* Do not pack per-worktree refs: */
1482
- if (ref_type(iter->refname) != REF_TYPE_NORMAL)
1483
- continue;
1484
-
1485
- /* ALWAYS pack tags */
1486
- if (!(flags & PACK_REFS_ALL) && !is_tag_ref)
1487
- continue;
1488
-
1489
- /* Do not pack symbolic or broken refs: */
1490
- if (iter->flags & REF_ISSYMREF)
1491
- continue;
1505
1493
- if (!ref_resolves_to_object(iter->refname, iter->oid, iter->flags))
1506
+ if (!should_pack_ref(iter->refname, iter->oid, iter->flags,
1507
+ flags))
1508
continue;
1509
1510
/*