@matheusbsbs / matheus-bagliano / commits / 71b03b42c6
Fork 0

Don't crash during repack of a reflog with pruned commits.

If the user has been using reflog for a long time (e.g. since its introduction) then it is very likely that an existing branch's reflog may still mention commits which have long since been pruned out of the repository. Rather than aborting with a very useless error message during git-repack, pack as many valid commits as we can get from the reflog and let the user know that the branch's reflog contains already pruned commits. A future 'git reflog expire' (or whatever it finally winds up being called) can then be performed to expunge those reflog entries. Signed-off-by: Shawn O. Pearce <spearce@spearce.org> Signed-off-by: Junio C Hamano <junkio@cox.net>

Shawn O. Pearce committed Dec 21, 2006 at 19:49 UTC 71b03b42c637d884295b48d4f5d830a5f5f3578b
1 file changed +20 -10
revision.c
+20 -10
@@ -466,6 +466,7 @@ static void limit_list(struct rev_info *revs)
466
467 struct all_refs_cb {
468 int all_flags;
469 + int warned_bad_reflog;
470 struct rev_info *all_revs;
471 const char *name_for_errormsg;
472 };
@@ -487,25 +488,34 @@ static void handle_all(struct rev_info *revs, unsigned flags)
488 for_each_ref(handle_one_ref, &cb);
489 }
490
490 -static int handle_one_reflog_ent(unsigned char *osha1, unsigned char *nsha1, char *detail, void *cb_data)
491 +static void handle_one_reflog_commit(unsigned char *sha1, void *cb_data)
492 {
493 struct all_refs_cb *cb = cb_data;
493 - struct object *object;
494 -
495 - if (!is_null_sha1(osha1)) {
496 - object = get_reference(cb->all_revs, cb->name_for_errormsg,
497 - osha1, cb->all_flags);
498 - add_pending_object(cb->all_revs, object, "");
494 + if (!is_null_sha1(sha1)) {
495 + struct object *o = parse_object(sha1);
496 + if (o) {
497 + o->flags |= cb->all_flags;
498 + add_pending_object(cb->all_revs, o, "");
499 + }
500 + else if (!cb->warned_bad_reflog) {
501 + warn("reflog of '%s' references pruned commits",
502 + cb->name_for_errormsg);
503 + cb->warned_bad_reflog = 1;
504 + }
505 }
500 - object = get_reference(cb->all_revs, cb->name_for_errormsg,
501 - nsha1, cb->all_flags);
502 - add_pending_object(cb->all_revs, object, "");
506 +}
507 +
508 +static int handle_one_reflog_ent(unsigned char *osha1, unsigned char *nsha1, char *detail, void *cb_data)
509 +{
510 + handle_one_reflog_commit(osha1, cb_data);
511 + handle_one_reflog_commit(nsha1, cb_data);
512 return 0;
513 }
514
515 static int handle_one_reflog(const char *path, const unsigned char *sha1, int flag, void *cb_data)
516 {
517 struct all_refs_cb *cb = cb_data;
518 + cb->warned_bad_reflog = 0;
519 cb->name_for_errormsg = path;
520 for_each_reflog_ent(path, handle_one_reflog_ent, cb_data);
521 return 0;