summaryrefslogtreecommitdiff
path: root/builtin/reflog.c
diff options
context:
space:
mode:
authorÆvar Arnfjörð Bjarmason <avarab@gmail.com>2021-12-22 05:06:43 +0100
committerJunio C Hamano <gitster@pobox.com>2021-12-22 16:24:13 -0800
commit20d6b6868c1446d548094a0a8aa4393a9c58447c (patch)
tree0c8ce80b86f59a3814282d81851ca7218132091d /builtin/reflog.c
parentf2919bae9836d552a399b67f4f7d26d30128b6d5 (diff)
downloadgit-20d6b6868c1446d548094a0a8aa4393a9c58447c.tar.gz
reflog expire: use "switch" over enum values
Change code added in 03cb91b18cc (reflog --expire-unreachable: special case entries in "HEAD" reflog, 2010-04-09) to use a "switch" statement with an exhaustive list of "case" statements instead of doing numeric comparisons against the enum labels. Now we won't assume that "x != UE_ALWAYS" means "(x == UE_HEAD || x || UE_NORMAL)". That assumption is true now, but we'd introduce subtle bugs here if that were to change, now the compiler will notice and error out on such errors. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/reflog.c')
-rw-r--r--builtin/reflog.c57
1 files changed, 33 insertions, 24 deletions
diff --git a/builtin/reflog.c b/builtin/reflog.c
index 27851c6efb..8d05660e64 100644
--- a/builtin/reflog.c
+++ b/builtin/reflog.c
@@ -303,10 +303,15 @@ static int should_expire_reflog_ent(struct object_id *ooid, struct object_id *no
return 1;
if (timestamp < cb->cmd.expire_unreachable) {
- if (cb->unreachable_expire_kind == UE_ALWAYS)
- return 1;
- if (unreachable(cb, old_commit, ooid) || unreachable(cb, new_commit, noid))
+ switch (cb->unreachable_expire_kind) {
+ case UE_ALWAYS:
return 1;
+ case UE_NORMAL:
+ case UE_HEAD:
+ if (unreachable(cb, old_commit, ooid) || unreachable(cb, new_commit, noid))
+ return 1;
+ break;
+ }
}
if (cb->cmd.recno && --(cb->cmd.recno) == 0)
@@ -348,6 +353,7 @@ static void reflog_expiry_prepare(const char *refname,
void *cb_data)
{
struct expire_reflog_policy_cb *cb = cb_data;
+ struct commit_list *elem;
if (!cb->cmd.expire_unreachable || is_head(refname)) {
cb->unreachable_expire_kind = UE_HEAD;
@@ -363,34 +369,37 @@ static void reflog_expiry_prepare(const char *refname,
if (cb->cmd.expire_unreachable <= cb->cmd.expire_total)
cb->unreachable_expire_kind = UE_ALWAYS;
- if (cb->unreachable_expire_kind != UE_ALWAYS) {
- if (cb->unreachable_expire_kind == UE_HEAD) {
- struct commit_list *elem;
-
- for_each_ref(push_tip_to_list, &cb->tips);
- for (elem = cb->tips; elem; elem = elem->next)
- commit_list_insert(elem->item, &cb->mark_list);
- } else {
- commit_list_insert(cb->tip_commit, &cb->mark_list);
- }
- cb->mark_limit = cb->cmd.expire_total;
- mark_reachable(cb);
+ switch (cb->unreachable_expire_kind) {
+ case UE_ALWAYS:
+ return;
+ case UE_HEAD:
+ for_each_ref(push_tip_to_list, &cb->tips);
+ for (elem = cb->tips; elem; elem = elem->next)
+ commit_list_insert(elem->item, &cb->mark_list);
+ break;
+ case UE_NORMAL:
+ commit_list_insert(cb->tip_commit, &cb->mark_list);
}
+ cb->mark_limit = cb->cmd.expire_total;
+ mark_reachable(cb);
}
static void reflog_expiry_cleanup(void *cb_data)
{
struct expire_reflog_policy_cb *cb = cb_data;
+ struct commit_list *elem;
- if (cb->unreachable_expire_kind != UE_ALWAYS) {
- if (cb->unreachable_expire_kind == UE_HEAD) {
- struct commit_list *elem;
- for (elem = cb->tips; elem; elem = elem->next)
- clear_commit_marks(elem->item, REACHABLE);
- free_commit_list(cb->tips);
- } else {
- clear_commit_marks(cb->tip_commit, REACHABLE);
- }
+ switch (cb->unreachable_expire_kind) {
+ case UE_ALWAYS:
+ return;
+ case UE_HEAD:
+ for (elem = cb->tips; elem; elem = elem->next)
+ clear_commit_marks(elem->item, REACHABLE);
+ free_commit_list(cb->tips);
+ break;
+ case UE_NORMAL:
+ clear_commit_marks(cb->tip_commit, REACHABLE);
+ break;
}
}