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>
This commit is contained in:
parent
f3b661f766
commit
60cc3c4072
@ -288,7 +288,10 @@ static int unreachable(struct expire_reflog_cb *cb, struct commit *commit, unsig
|
|||||||
return !(commit->object.flags & REACHABLE);
|
return !(commit->object.flags & REACHABLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int expire_reflog_ent(unsigned char *osha1, unsigned char *nsha1,
|
/*
|
||||||
|
* Return true iff the specified reflog entry should be expired.
|
||||||
|
*/
|
||||||
|
static int should_expire_reflog_ent(unsigned char *osha1, unsigned char *nsha1,
|
||||||
const char *email, unsigned long timestamp, int tz,
|
const char *email, unsigned long timestamp, int tz,
|
||||||
const char *message, void *cb_data)
|
const char *message, void *cb_data)
|
||||||
{
|
{
|
||||||
@ -296,26 +299,42 @@ static int expire_reflog_ent(unsigned char *osha1, unsigned char *nsha1,
|
|||||||
struct commit *old, *new;
|
struct commit *old, *new;
|
||||||
|
|
||||||
if (timestamp < cb->cmd->expire_total)
|
if (timestamp < cb->cmd->expire_total)
|
||||||
goto prune;
|
return 1;
|
||||||
|
|
||||||
if (cb->cmd->rewrite)
|
|
||||||
osha1 = cb->last_kept_sha1;
|
|
||||||
|
|
||||||
old = new = NULL;
|
old = new = NULL;
|
||||||
if (cb->cmd->stalefix &&
|
if (cb->cmd->stalefix &&
|
||||||
(!keep_entry(&old, osha1) || !keep_entry(&new, nsha1)))
|
(!keep_entry(&old, osha1) || !keep_entry(&new, nsha1)))
|
||||||
goto prune;
|
return 1;
|
||||||
|
|
||||||
if (timestamp < cb->cmd->expire_unreachable) {
|
if (timestamp < cb->cmd->expire_unreachable) {
|
||||||
if (cb->unreachable_expire_kind == UE_ALWAYS)
|
if (cb->unreachable_expire_kind == UE_ALWAYS)
|
||||||
goto prune;
|
return 1;
|
||||||
if (unreachable(cb, old, osha1) || unreachable(cb, new, nsha1))
|
if (unreachable(cb, old, osha1) || unreachable(cb, new, nsha1))
|
||||||
goto prune;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cb->cmd->recno && --(cb->cmd->recno) == 0)
|
if (cb->cmd->recno && --(cb->cmd->recno) == 0)
|
||||||
goto prune;
|
return 1;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int expire_reflog_ent(unsigned char *osha1, unsigned char *nsha1,
|
||||||
|
const char *email, unsigned long timestamp, int tz,
|
||||||
|
const char *message, void *cb_data)
|
||||||
|
{
|
||||||
|
struct expire_reflog_cb *cb = cb_data;
|
||||||
|
|
||||||
|
if (cb->cmd->rewrite)
|
||||||
|
osha1 = cb->last_kept_sha1;
|
||||||
|
|
||||||
|
if (should_expire_reflog_ent(osha1, nsha1, email, timestamp, tz,
|
||||||
|
message, cb_data)) {
|
||||||
|
if (!cb->newlog)
|
||||||
|
printf("would prune %s", message);
|
||||||
|
else if (cb->cmd->verbose)
|
||||||
|
printf("prune %s", message);
|
||||||
|
} else {
|
||||||
if (cb->newlog) {
|
if (cb->newlog) {
|
||||||
char sign = (tz < 0) ? '-' : '+';
|
char sign = (tz < 0) ? '-' : '+';
|
||||||
int zone = (tz < 0) ? (-tz) : tz;
|
int zone = (tz < 0) ? (-tz) : tz;
|
||||||
@ -327,12 +346,7 @@ static int expire_reflog_ent(unsigned char *osha1, unsigned char *nsha1,
|
|||||||
}
|
}
|
||||||
if (cb->cmd->verbose)
|
if (cb->cmd->verbose)
|
||||||
printf("keep %s", message);
|
printf("keep %s", message);
|
||||||
return 0;
|
}
|
||||||
prune:
|
|
||||||
if (!cb->newlog)
|
|
||||||
printf("would prune %s", message);
|
|
||||||
else if (cb->cmd->verbose)
|
|
||||||
printf("prune %s", message);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user