Skip to content

Commit 531cc4a

Browse files
mhaggergitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8556f8d commit 531cc4a

File tree

1 file changed

+28
-14
lines changed

1 file changed

+28
-14
lines changed

refs/files-backend.c

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1455,6 +1455,32 @@ static void prune_refs(struct files_ref_store *refs, struct ref_to_prune *r)
14551455
}
14561456
}
14571457

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+
14581484
static int files_pack_refs(struct ref_store *ref_store, unsigned int flags)
14591485
{
14601486
struct files_ref_store *refs =
@@ -1476,21 +1502,9 @@ static int files_pack_refs(struct ref_store *ref_store, unsigned int flags)
14761502
* pruned, also add it to refs_to_prune.
14771503
*/
14781504
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;
14921505

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))
14941508
continue;
14951509

14961510
/*

0 commit comments

Comments
 (0)