From: Michael Haggerty <mhagger@alum.mit.edu>
To: Junio C Hamano <gitster@pobox.com>
Cc: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>,
"Stefan Beller" <sbeller@google.com>, "Jeff King" <peff@peff.net>,
"Ævar Arnfjörð Bjarmason" <avarab@gmail.com>,
"David Turner" <novalis@novalis.org>,
"Brandon Williams" <bmwill@google.com>,
"Johannes Sixt" <j6t@kdbg.org>,
git@vger.kernel.org, "Michael Haggerty" <mhagger@alum.mit.edu>
Subject: [PATCH v2 18/25] should_pack_ref(): new function, extracted from `files_pack_refs()`
Date: Mon, 22 May 2017 16:17:48 +0200 [thread overview]
Message-ID: <b7786f0cc9664fe86580f4296b4916f450b068d0.1495460199.git.mhagger@alum.mit.edu> (raw)
In-Reply-To: <cover.1495460199.git.mhagger@alum.mit.edu>
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>
---
refs/files-backend.c | 42 ++++++++++++++++++++++++++++--------------
1 file 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;
/*
--
2.11.0
next prev parent reply other threads:[~2017-05-22 14:19 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-05-22 14:17 [PATCH v2 00/25] Prepare to separate out a packed_ref_store Michael Haggerty
2017-05-22 14:17 ` [PATCH v2 01/25] t3600: clean up permissions test properly Michael Haggerty
2017-05-22 14:17 ` [PATCH v2 02/25] refs.h: clarify docstring for the ref_transaction_update()-related fns Michael Haggerty
2017-05-22 14:17 ` [PATCH v2 03/25] ref_iterator_begin_fn(): fix docstring Michael Haggerty
2017-05-22 14:17 ` [PATCH v2 04/25] files-backend: use `die("BUG: ...")`, not `die("internal error: ...")` Michael Haggerty
2017-05-22 14:17 ` [PATCH v2 05/25] prefix_ref_iterator: don't trim too much Michael Haggerty
2017-05-22 14:17 ` [PATCH v2 06/25] refs_ref_iterator_begin(): don't check prefixes redundantly Michael Haggerty
2017-05-22 14:17 ` [PATCH v2 07/25] refs: use `size_t` indexes when iterating over ref transaction updates Michael Haggerty
2017-05-22 14:17 ` [PATCH v2 08/25] ref_store: take a `msg` parameter when deleting references Michael Haggerty
2017-05-22 14:17 ` [PATCH v2 09/25] lockfile: add a new method, is_lock_file_locked() Michael Haggerty
2017-05-22 14:17 ` [PATCH v2 10/25] files-backend: move `lock` member to `files_ref_store` Michael Haggerty
2017-05-22 14:17 ` [PATCH v2 11/25] files_ref_store: put the packed files lock directly in this struct Michael Haggerty
2017-05-22 14:17 ` [PATCH v2 12/25] files_transaction_cleanup(): new helper function Michael Haggerty
2017-05-22 14:17 ` [PATCH v2 13/25] ref_transaction_commit(): check for valid `transaction->state` Michael Haggerty
2017-05-22 14:17 ` [PATCH v2 14/25] ref_transaction_prepare(): new optional step for reference updates Michael Haggerty
2017-05-22 14:17 ` [PATCH v2 15/25] ref_update_reject_duplicates(): expose function to whole refs module Michael Haggerty
2017-05-22 14:17 ` [PATCH v2 16/25] ref_update_reject_duplicates(): use `size_t` rather than `int` Michael Haggerty
2017-05-22 14:17 ` [PATCH v2 17/25] ref_update_reject_duplicates(): add a sanity check Michael Haggerty
2017-05-22 14:17 ` Michael Haggerty [this message]
2017-05-22 14:17 ` [PATCH v2 19/25] get_packed_ref_cache(): assume "packed-refs" won't change while locked Michael Haggerty
2017-05-22 14:17 ` [PATCH v2 20/25] read_packed_refs(): do more of the work of reading packed refs Michael Haggerty
2017-05-22 14:17 ` [PATCH v2 21/25] read_packed_refs(): report unexpected fopen() failures Michael Haggerty
2017-05-22 14:17 ` [PATCH v2 22/25] refs_ref_iterator_begin(): handle `GIT_REF_PARANOIA` Michael Haggerty
2017-05-22 14:17 ` [PATCH v2 23/25] create_ref_entry(): remove `check_name` option Michael Haggerty
2017-05-22 14:17 ` [PATCH v2 24/25] ref-filter: limit traversal to prefix Michael Haggerty
2017-05-22 14:17 ` [PATCH v2 25/25] cache_ref_iterator_begin(): avoid priming unneeded directories Michael Haggerty
2017-05-23 19:45 ` Jeff King
2017-05-24 7:17 ` Michael Haggerty
2017-05-24 7:21 ` Junio C Hamano
2017-05-22 21:51 ` [PATCH v2 00/25] Prepare to separate out a packed_ref_store Stefan Beller
2017-05-24 2:45 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=b7786f0cc9664fe86580f4296b4916f450b068d0.1495460199.git.mhagger@alum.mit.edu \
--to=mhagger@alum.mit.edu \
--cc=avarab@gmail.com \
--cc=bmwill@google.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=j6t@kdbg.org \
--cc=novalis@novalis.org \
--cc=pclouds@gmail.com \
--cc=peff@peff.net \
--cc=sbeller@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).