Extract function should_expire_reflog_ent()
Extract from expire_reflog_ent() a function that is solely responsible for deciding whether a reflog entry should be expired. By separating this "business logic" from the mechanics of actually expiring entries, we are working towards the goal of encapsulating reflog expiry within the refs API, with policy decided by a callback function passed to it by its caller. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Michael Haggerty committed
Dec 12, 2014 at 09:56 UTC
60cc3c4072259609aefbdbc762d1f72bcbd97783
1 file changed
+42
-28
builtin/reflog.c
+42
-28
@@ -288,51 +288,65 @@ static int unreachable(struct expire_reflog_cb *cb, struct commit *commit, unsig
288
return !(commit->object.flags & REACHABLE);
289
}
290
291
-static int expire_reflog_ent(unsigned char *osha1, unsigned char *nsha1,
292
- const char *email, unsigned long timestamp, int tz,
293
- const char *message, void *cb_data)
291
+/*
292
+ * Return true iff the specified reflog entry should be expired.
293
+ */
294
+static int should_expire_reflog_ent(unsigned char *osha1, unsigned char *nsha1,
295
+ const char *email, unsigned long timestamp, int tz,
296
+ const char *message, void *cb_data)
297
{
298
struct expire_reflog_cb *cb = cb_data;
299
struct commit *old, *new;
300
301
if (timestamp < cb->cmd->expire_total)
299
- goto prune;
300
-
301
- if (cb->cmd->rewrite)
302
- osha1 = cb->last_kept_sha1;
302
+ return 1;
303
304
old = new = NULL;
305
if (cb->cmd->stalefix &&
306
(!keep_entry(&old, osha1) || !keep_entry(&new, nsha1)))
307
- goto prune;
307
+ return 1;
308
309
if (timestamp < cb->cmd->expire_unreachable) {
310
if (cb->unreachable_expire_kind == UE_ALWAYS)
311
- goto prune;
311
+ return 1;
312
if (unreachable(cb, old, osha1) || unreachable(cb, new, nsha1))
313
- goto prune;
313
+ return 1;
314
}
315
316
if (cb->cmd->recno && --(cb->cmd->recno) == 0)
317
- goto prune;
318
-
319
- if (cb->newlog) {
320
- char sign = (tz < 0) ? '-' : '+';
321
- int zone = (tz < 0) ? (-tz) : tz;
322
- fprintf(cb->newlog, "%s %s %s %lu %c%04d\t%s",
323
- sha1_to_hex(osha1), sha1_to_hex(nsha1),
324
- email, timestamp, sign, zone,
325
- message);
326
- hashcpy(cb->last_kept_sha1, nsha1);
327
- }
328
- if (cb->cmd->verbose)
329
- printf("keep %s", message);
317
+ return 1;
318
+
319
return 0;
331
- prune:
332
- if (!cb->newlog)
333
- printf("would prune %s", message);
334
- else if (cb->cmd->verbose)
335
- printf("prune %s", message);
320
+}
321
+
322
+static int expire_reflog_ent(unsigned char *osha1, unsigned char *nsha1,
323
+ const char *email, unsigned long timestamp, int tz,
324
+ const char *message, void *cb_data)
325
+{
326
+ struct expire_reflog_cb *cb = cb_data;
327
+
328
+ if (cb->cmd->rewrite)
329
+ osha1 = cb->last_kept_sha1;
330
+
331
+ if (should_expire_reflog_ent(osha1, nsha1, email, timestamp, tz,
332
+ message, cb_data)) {
333
+ if (!cb->newlog)
334
+ printf("would prune %s", message);
335
+ else if (cb->cmd->verbose)
336
+ printf("prune %s", message);
337
+ } else {
338
+ if (cb->newlog) {
339
+ char sign = (tz < 0) ? '-' : '+';
340
+ int zone = (tz < 0) ? (-tz) : tz;
341
+ fprintf(cb->newlog, "%s %s %s %lu %c%04d\t%s",
342
+ sha1_to_hex(osha1), sha1_to_hex(nsha1),
343
+ email, timestamp, sign, zone,
344
+ message);
345
+ hashcpy(cb->last_kept_sha1, nsha1);
346
+ }
347
+ if (cb->cmd->verbose)
348
+ printf("keep %s", message);
349
+ }
350
return 0;
351
}
352