Skip to content

Commit 55dd552

Browse files
author
Junio C Hamano
committed
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>
1 parent 2ff8166 commit 55dd552

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

builtin-prune.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,12 +181,28 @@ static void walk_commit_list(struct rev_info *revs)
181181
}
182182
}
183183

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+
184197
static int add_one_ref(const char *path, const unsigned char *sha1, int flag, void *cb_data)
185198
{
186199
struct object *object = parse_object(sha1);
187200
if (!object)
188201
die("bad object ref: %s:%s", path, sha1_to_hex(sha1));
189202
add_pending_object(&revs, object, "");
203+
204+
for_each_reflog_ent(path, add_one_reflog_ent, NULL);
205+
190206
return 0;
191207
}
192208

fsck-objects.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,25 @@ static void fsck_dir(int i, char *path)
399399

400400
static int default_refs;
401401

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+
402421
static int fsck_handle_ref(const char *refname, const unsigned char *sha1, int flag, void *cb_data)
403422
{
404423
struct object *obj;
@@ -416,6 +435,9 @@ static int fsck_handle_ref(const char *refname, const unsigned char *sha1, int f
416435
default_refs++;
417436
obj->used = 1;
418437
mark_reachable(obj, REACHABLE);
438+
439+
for_each_reflog_ent(refname, fsck_handle_reflog_ent, NULL);
440+
419441
return 0;
420442
}
421443

0 commit comments

Comments
 (0)