@matheusbsbs / matheus-bagliano / commits / 9ffb15d52a
Fork 0

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 <torvalds@linux-foundation.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Linus Torvalds committed Mar 31, 2009 at 09:45 UTC 9ffb15d52a33444652c136681c0b720547c43cbe
1 file changed +26 -6
builtin-reflog.c
+26 -6
@@ -209,6 +209,31 @@ static int keep_entry(struct commit **it, unsigned char *sha1)
209 return 1;
210 }
211
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 +
237 static int expire_reflog_ent(unsigned char *osha1, unsigned char *nsha1,
238 const char *email, unsigned long timestamp, int tz,
239 const char *message, void *cb_data)
@@ -230,12 +255,7 @@ static int expire_reflog_ent(unsigned char *osha1, unsigned char *nsha1,
255 if (timestamp < cb->cmd->expire_unreachable) {
256 if (!cb->ref_commit)
257 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))
259 goto prune;
260 }
261