Protect commits recorded in reflog from pruning.
This teaches fsck-objects and prune to protect objects referred to by reflog entries. Signed-off-by: Junio C Hamano <junkio@cox.net>
Junio C Hamano committed
Dec 18, 2006 at 01:36 UTC
55dd55263b6d27aa8daa77bd69f5ea990b66c7a1
2 files changed
+38
builtin-prune.c
+16
@@ -181,12 +181,28 @@ static void walk_commit_list(struct rev_info *revs)
181
}
182
}
183
184
+static int add_one_reflog_ent(unsigned char *osha1, unsigned char *nsha1, char *datail, void *cb_data)
185
+{
186
+ struct object *object;
187
+
188
+ object = parse_object(osha1);
189
+ if (object)
190
+ add_pending_object(&revs, object, "");
191
+ object = parse_object(nsha1);
192
+ if (object)
193
+ add_pending_object(&revs, object, "");
194
+ return 0;
195
+}
196
+
197
static int add_one_ref(const char *path, const unsigned char *sha1, int flag, void *cb_data)
198
{
199
struct object *object = parse_object(sha1);
200
if (!object)
201
die("bad object ref: %s:%s", path, sha1_to_hex(sha1));
202
add_pending_object(&revs, object, "");
203
+
204
+ for_each_reflog_ent(path, add_one_reflog_ent, NULL);
205
+
206
return 0;
207
}
208
fsck-objects.c
+22
@@ -399,6 +399,25 @@ static void fsck_dir(int i, char *path)
399
400
static int default_refs;
401
402
+static int fsck_handle_reflog_ent(unsigned char *osha1, unsigned char *nsha1, char *datail, void *cb_data)
403
+{
404
+ struct object *obj;
405
+
406
+ if (!is_null_sha1(osha1)) {
407
+ obj = lookup_object(osha1);
408
+ if (obj) {
409
+ obj->used = 1;
410
+ mark_reachable(obj, REACHABLE);
411
+ }
412
+ }
413
+ obj = lookup_object(nsha1);
414
+ if (obj) {
415
+ obj->used = 1;
416
+ mark_reachable(obj, REACHABLE);
417
+ }
418
+ return 0;
419
+}
420
+
421
static int fsck_handle_ref(const char *refname, const unsigned char *sha1, int flag, void *cb_data)
422
{
423
struct object *obj;
@@ -416,6 +435,9 @@ static int fsck_handle_ref(const char *refname, const unsigned char *sha1, int f
435
default_refs++;
436
obj->used = 1;
437
mark_reachable(obj, REACHABLE);
438
+
439
+ for_each_reflog_ent(refname, fsck_handle_reflog_ent, NULL);
440
+
441
return 0;
442
}
443