Skip to content

Commit 07815e2

Browse files
avargitster
authored andcommitted
reflog expire: refactor & use "tip_commit" only for UE_NORMAL
Add an intermediate variable for "tip_commit" in reflog_expiry_prepare(), and only add it to the struct if we're handling the UE_NORMAL case. The code behaves the same way as before, but this makes the control flow clearer, and the shorter name allows us to fold a 4-line i/else into a one-line ternary instead. Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 20d6b68 commit 07815e2

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

builtin/reflog.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -354,16 +354,14 @@ static void reflog_expiry_prepare(const char *refname,
354354
{
355355
struct expire_reflog_policy_cb *cb = cb_data;
356356
struct commit_list *elem;
357+
struct commit *commit = NULL;
357358

358359
if (!cb->cmd.expire_unreachable || is_head(refname)) {
359360
cb->unreachable_expire_kind = UE_HEAD;
360361
} else {
361-
cb->tip_commit = lookup_commit_reference_gently(the_repository,
362-
oid, 1);
363-
if (!cb->tip_commit)
364-
cb->unreachable_expire_kind = UE_ALWAYS;
365-
else
366-
cb->unreachable_expire_kind = UE_NORMAL;
362+
commit = lookup_commit_reference_gently(the_repository,
363+
oid, 1);
364+
cb->unreachable_expire_kind = commit ? UE_NORMAL : UE_ALWAYS;
367365
}
368366

369367
if (cb->cmd.expire_unreachable <= cb->cmd.expire_total)
@@ -378,7 +376,9 @@ static void reflog_expiry_prepare(const char *refname,
378376
commit_list_insert(elem->item, &cb->mark_list);
379377
break;
380378
case UE_NORMAL:
381-
commit_list_insert(cb->tip_commit, &cb->mark_list);
379+
commit_list_insert(commit, &cb->mark_list);
380+
/* For reflog_expiry_cleanup() below */
381+
cb->tip_commit = commit;
382382
}
383383
cb->mark_limit = cb->cmd.expire_total;
384384
mark_reachable(cb);

0 commit comments

Comments
 (0)