Skip to content

Commit 9ffb15d

Browse files
torvaldsgitster
authored andcommitted
Clean up reflog unreachability pruning decision
This clarifies the pruning rules for unreachable commits by having a separate helpder function for the unreachability decision. It's preparation for actual bigger changes to come to speed up the decision when the reachability calculations become a bottleneck. Signed-off-by: Linus Torvalds <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3bd1bb3 commit 9ffb15d

File tree

1 file changed

+26
-6
lines changed

1 file changed

+26
-6
lines changed

builtin-reflog.c

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,31 @@ static int keep_entry(struct commit **it, unsigned char *sha1)
209209
return 1;
210210
}
211211

212+
static int unreachable(struct expire_reflog_cb *cb, struct commit *commit, unsigned char *sha1)
213+
{
214+
/*
215+
* We may or may not have the commit yet - if not, look it
216+
* up using the supplied sha1.
217+
*/
218+
if (!commit) {
219+
if (is_null_sha1(sha1))
220+
return 0;
221+
222+
commit = lookup_commit_reference_gently(sha1, 1);
223+
224+
/* Not a commit -- keep it */
225+
if (!commit)
226+
return 0;
227+
}
228+
229+
/* Reachable from the current ref? Don't prune. */
230+
if (in_merge_bases(commit, &cb->ref_commit, 1))
231+
return 0;
232+
233+
/* We can't reach it - prune it. */
234+
return 1;
235+
}
236+
212237
static int expire_reflog_ent(unsigned char *osha1, unsigned char *nsha1,
213238
const char *email, unsigned long timestamp, int tz,
214239
const char *message, void *cb_data)
@@ -230,12 +255,7 @@ static int expire_reflog_ent(unsigned char *osha1, unsigned char *nsha1,
230255
if (timestamp < cb->cmd->expire_unreachable) {
231256
if (!cb->ref_commit)
232257
goto prune;
233-
if (!old && !is_null_sha1(osha1))
234-
old = lookup_commit_reference_gently(osha1, 1);
235-
if (!new && !is_null_sha1(nsha1))
236-
new = lookup_commit_reference_gently(nsha1, 1);
237-
if ((old && !in_merge_bases(old, &cb->ref_commit, 1)) ||
238-
(new && !in_merge_bases(new, &cb->ref_commit, 1)))
258+
if (unreachable(cb, old, osha1) || unreachable(cb, new, nsha1))
239259
goto prune;
240260
}
241261

0 commit comments

Comments
 (0)