summaryrefslogtreecommitdiff
path: root/revision.c
diff options
context:
space:
mode:
authorShawn O. Pearce <spearce@spearce.org>2006-12-22 00:49:06 (GMT)
committerJunio C Hamano <junkio@cox.net>2006-12-22 07:01:57 (GMT)
commit71b03b42c637d884295b48d4f5d830a5f5f3578b (patch)
tree1568f576e074e03407cf47304b1b8f4031378151 /revision.c
parent90cee090a0d7f950130d50df123551e43843e679 (diff)
downloadgit-71b03b42c637d884295b48d4f5d830a5f5f3578b.zip
git-71b03b42c637d884295b48d4f5d830a5f5f3578b.tar.gz
git-71b03b42c637d884295b48d4f5d830a5f5f3578b.tar.bz2
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>
Diffstat (limited to 'revision.c')
-rw-r--r--revision.c30
1 files changed, 20 insertions, 10 deletions
diff --git a/revision.c b/revision.c
index bda9d4d..4f6de2d 100644
--- a/revision.c
+++ b/revision.c
@@ -466,6 +466,7 @@ static void limit_list(struct rev_info *revs)
struct all_refs_cb {
int all_flags;
+ int warned_bad_reflog;
struct rev_info *all_revs;
const char *name_for_errormsg;
};
@@ -487,25 +488,34 @@ static void handle_all(struct rev_info *revs, unsigned flags)
for_each_ref(handle_one_ref, &cb);
}
-static int handle_one_reflog_ent(unsigned char *osha1, unsigned char *nsha1, char *detail, void *cb_data)
+static void handle_one_reflog_commit(unsigned char *sha1, void *cb_data)
{
struct all_refs_cb *cb = cb_data;
- struct object *object;
-
- if (!is_null_sha1(osha1)) {
- object = get_reference(cb->all_revs, cb->name_for_errormsg,
- osha1, cb->all_flags);
- add_pending_object(cb->all_revs, object, "");
+ if (!is_null_sha1(sha1)) {
+ struct object *o = parse_object(sha1);
+ if (o) {
+ o->flags |= cb->all_flags;
+ add_pending_object(cb->all_revs, o, "");
+ }
+ else if (!cb->warned_bad_reflog) {
+ warn("reflog of '%s' references pruned commits",
+ cb->name_for_errormsg);
+ cb->warned_bad_reflog = 1;
+ }
}
- object = get_reference(cb->all_revs, cb->name_for_errormsg,
- nsha1, cb->all_flags);
- add_pending_object(cb->all_revs, object, "");
+}
+
+static int handle_one_reflog_ent(unsigned char *osha1, unsigned char *nsha1, char *detail, void *cb_data)
+{
+ handle_one_reflog_commit(osha1, cb_data);
+ handle_one_reflog_commit(nsha1, cb_data);
return 0;
}
static int handle_one_reflog(const char *path, const unsigned char *sha1, int flag, void *cb_data)
{
struct all_refs_cb *cb = cb_data;
+ cb->warned_bad_reflog = 0;
cb->name_for_errormsg = path;
for_each_reflog_ent(path, handle_one_reflog_ent, cb_data);
return 0;