git-reflog: add option --rewrite to update reflog entries while expiring
Certain sanity checks on the reflog assume that each entry will contain a reference to the previous entry. i.e. that the "old" sha1 field of a reflog entry will be equal to the "new" sha1 field of the previous entry. When reflog entries are deleted, this assumption may not hold. This patch adds a new option to git-reflog which causes the subcommands "expire" and "delete" to rewrite the "old" sha1 field of each reflog entry so that it points to the previous reflog entry. Signed-off-by: Brandon Casey <casey@nrlssc.navy.mil> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
3c386aa338
commit
2b81fab288
@ -15,7 +15,7 @@
|
|||||||
static const char reflog_expire_usage[] =
|
static const char reflog_expire_usage[] =
|
||||||
"git-reflog (show|expire) [--verbose] [--dry-run] [--stale-fix] [--expire=<time>] [--expire-unreachable=<time>] [--all] <refs>...";
|
"git-reflog (show|expire) [--verbose] [--dry-run] [--stale-fix] [--expire=<time>] [--expire-unreachable=<time>] [--all] <refs>...";
|
||||||
static const char reflog_delete_usage[] =
|
static const char reflog_delete_usage[] =
|
||||||
"git-reflog delete [--verbose] [--dry-run] <refs>...";
|
"git-reflog delete [--verbose] [--dry-run] [--rewrite] <refs>...";
|
||||||
|
|
||||||
static unsigned long default_reflog_expire;
|
static unsigned long default_reflog_expire;
|
||||||
static unsigned long default_reflog_expire_unreachable;
|
static unsigned long default_reflog_expire_unreachable;
|
||||||
@ -24,6 +24,7 @@ struct cmd_reflog_expire_cb {
|
|||||||
struct rev_info revs;
|
struct rev_info revs;
|
||||||
int dry_run;
|
int dry_run;
|
||||||
int stalefix;
|
int stalefix;
|
||||||
|
int rewrite;
|
||||||
int verbose;
|
int verbose;
|
||||||
unsigned long expire_total;
|
unsigned long expire_total;
|
||||||
unsigned long expire_unreachable;
|
unsigned long expire_unreachable;
|
||||||
@ -35,6 +36,7 @@ struct expire_reflog_cb {
|
|||||||
const char *ref;
|
const char *ref;
|
||||||
struct commit *ref_commit;
|
struct commit *ref_commit;
|
||||||
struct cmd_reflog_expire_cb *cmd;
|
struct cmd_reflog_expire_cb *cmd;
|
||||||
|
unsigned char last_kept_sha1[20];
|
||||||
};
|
};
|
||||||
|
|
||||||
struct collected_reflog {
|
struct collected_reflog {
|
||||||
@ -216,6 +218,9 @@ static int expire_reflog_ent(unsigned char *osha1, unsigned char *nsha1,
|
|||||||
if (timestamp < cb->cmd->expire_total)
|
if (timestamp < cb->cmd->expire_total)
|
||||||
goto prune;
|
goto prune;
|
||||||
|
|
||||||
|
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)))
|
||||||
@ -243,6 +248,7 @@ static int expire_reflog_ent(unsigned char *osha1, unsigned char *nsha1,
|
|||||||
sha1_to_hex(osha1), sha1_to_hex(nsha1),
|
sha1_to_hex(osha1), sha1_to_hex(nsha1),
|
||||||
email, timestamp, sign, zone,
|
email, timestamp, sign, zone,
|
||||||
message);
|
message);
|
||||||
|
hashcpy(cb->last_kept_sha1, nsha1);
|
||||||
}
|
}
|
||||||
if (cb->cmd->verbose)
|
if (cb->cmd->verbose)
|
||||||
printf("keep %s", message);
|
printf("keep %s", message);
|
||||||
@ -364,6 +370,8 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix)
|
|||||||
cb.expire_unreachable = approxidate(arg + 21);
|
cb.expire_unreachable = approxidate(arg + 21);
|
||||||
else if (!strcmp(arg, "--stale-fix"))
|
else if (!strcmp(arg, "--stale-fix"))
|
||||||
cb.stalefix = 1;
|
cb.stalefix = 1;
|
||||||
|
else if (!strcmp(arg, "--rewrite"))
|
||||||
|
cb.rewrite = 1;
|
||||||
else if (!strcmp(arg, "--all"))
|
else if (!strcmp(arg, "--all"))
|
||||||
do_all = 1;
|
do_all = 1;
|
||||||
else if (!strcmp(arg, "--verbose"))
|
else if (!strcmp(arg, "--verbose"))
|
||||||
@ -433,6 +441,8 @@ static int cmd_reflog_delete(int argc, const char **argv, const char *prefix)
|
|||||||
const char *arg = argv[i];
|
const char *arg = argv[i];
|
||||||
if (!strcmp(arg, "--dry-run") || !strcmp(arg, "-n"))
|
if (!strcmp(arg, "--dry-run") || !strcmp(arg, "-n"))
|
||||||
cb.dry_run = 1;
|
cb.dry_run = 1;
|
||||||
|
else if (!strcmp(arg, "--rewrite"))
|
||||||
|
cb.rewrite = 1;
|
||||||
else if (!strcmp(arg, "--verbose"))
|
else if (!strcmp(arg, "--verbose"))
|
||||||
cb.verbose = 1;
|
cb.verbose = 1;
|
||||||
else if (!strcmp(arg, "--")) {
|
else if (!strcmp(arg, "--")) {
|
||||||
|
Loading…
Reference in New Issue
Block a user