Skip to content

Commit 60cc3c4

Browse files
mhaggergitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f3b661f commit 60cc3c4

File tree

1 file changed

+42
-28
lines changed

1 file changed

+42
-28
lines changed

builtin/reflog.c

Lines changed: 42 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -288,51 +288,65 @@ static int unreachable(struct expire_reflog_cb *cb, struct commit *commit, unsig
288288
return !(commit->object.flags & REACHABLE);
289289
}
290290

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)
294297
{
295298
struct expire_reflog_cb *cb = cb_data;
296299
struct commit *old, *new;
297300

298301
if (timestamp < cb->cmd->expire_total)
299-
goto prune;
300-
301-
if (cb->cmd->rewrite)
302-
osha1 = cb->last_kept_sha1;
302+
return 1;
303303

304304
old = new = NULL;
305305
if (cb->cmd->stalefix &&
306306
(!keep_entry(&old, osha1) || !keep_entry(&new, nsha1)))
307-
goto prune;
307+
return 1;
308308

309309
if (timestamp < cb->cmd->expire_unreachable) {
310310
if (cb->unreachable_expire_kind == UE_ALWAYS)
311-
goto prune;
311+
return 1;
312312
if (unreachable(cb, old, osha1) || unreachable(cb, new, nsha1))
313-
goto prune;
313+
return 1;
314314
}
315315

316316
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+
330319
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+
}
336350
return 0;
337351
}
338352

0 commit comments

Comments
 (0)