Teach git-repack to preserve objects referred to by reflog entries.
This adds a new option --reflog to pack-objects and revision machinery; do not bother documenting it for now, since this is only useful for local repacking. When the option is passed, objects reachable from reflog entries are marked as interesting while computing the set of objects to pack. Signed-off-by: Junio C Hamano <junkio@cox.net>
Junio C Hamano committed
Dec 18, 2006 at 17:25 UTC
63049292e083faf80e033eba4fa43efdbac3acad
3 files changed
+52
-9
builtin-pack-objects.c
+2
-1
@@ -17,7 +17,7 @@ static const char pack_usage[] = "\
17
git-pack-objects [{ -q | --progress | --all-progress }] \n\
18
[--local] [--incremental] [--window=N] [--depth=N] \n\
19
[--no-reuse-delta] [--delta-base-offset] [--non-empty] \n\
20
- [--revs [--unpacked | --all]*] [--stdout | base-name] \n\
20
+ [--revs [--unpacked | --all]*] [--reflog] [--stdout | base-name] \n\
21
[<ref-list | <object-list]";
22
23
struct object_entry {
@@ -1575,6 +1575,7 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
1575
}
1576
if (!strcmp("--unpacked", arg) ||
1577
!strncmp("--unpacked=", arg, 11) ||
1578
+ !strcmp("--reflog", arg) ||
1579
!strcmp("--all", arg)) {
1580
use_internal_rev_list = 1;
1581
if (ARRAY_SIZE(rp_av) - 1 <= rp_ac)
git-repack.sh
+1
-1
@@ -62,7 +62,7 @@ case ",$all_into_one," in
62
esac
63
64
args="$args $local $quiet $no_reuse_delta$extra"
65
-name=$(git-pack-objects --non-empty --all $args </dev/null "$PACKTMP") ||
65
+name=$(git-pack-objects --non-empty --all --reflog $args </dev/null "$PACKTMP") ||
66
exit 1
67
if [ -z "$name" ]; then
68
echo Nothing new to pack.
revision.c
+49
-7
@@ -464,21 +464,59 @@ static void limit_list(struct rev_info *revs)
464
revs->commits = newlist;
465
}
466
467
-static int all_flags;
468
-static struct rev_info *all_revs;
467
+struct all_refs_cb {
468
+ int all_flags;
469
+ struct rev_info *all_revs;
470
+ const char *name_for_errormsg;
471
+};
472
473
static int handle_one_ref(const char *path, const unsigned char *sha1, int flag, void *cb_data)
474
{
472
- struct object *object = get_reference(all_revs, path, sha1, all_flags);
473
- add_pending_object(all_revs, object, "");
475
+ struct all_refs_cb *cb = cb_data;
476
+ struct object *object = get_reference(cb->all_revs, path, sha1,
477
+ cb->all_flags);
478
+ add_pending_object(cb->all_revs, object, "");
479
return 0;
480
}
481
482
static void handle_all(struct rev_info *revs, unsigned flags)
483
{
479
- all_revs = revs;
480
- all_flags = flags;
481
- for_each_ref(handle_one_ref, NULL);
484
+ struct all_refs_cb cb;
485
+ cb.all_revs = revs;
486
+ cb.all_flags = flags;
487
+ for_each_ref(handle_one_ref, &cb);
488
+}
489
+
490
+static int handle_one_reflog_ent(unsigned char *osha1, unsigned char *nsha1, char *detail, void *cb_data)
491
+{
492
+ 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, "");
499
+ }
500
+ object = get_reference(cb->all_revs, cb->name_for_errormsg,
501
+ nsha1, cb->all_flags);
502
+ add_pending_object(cb->all_revs, object, "");
503
+ return 0;
504
+}
505
+
506
+static int handle_one_reflog(const char *path, const unsigned char *sha1, int flag, void *cb_data)
507
+{
508
+ struct all_refs_cb *cb = cb_data;
509
+ cb->name_for_errormsg = path;
510
+ for_each_reflog_ent(path, handle_one_reflog_ent, cb_data);
511
+ return 0;
512
+}
513
+
514
+static void handle_reflog(struct rev_info *revs, unsigned flags)
515
+{
516
+ struct all_refs_cb cb;
517
+ cb.all_revs = revs;
518
+ cb.all_flags = flags;
519
+ for_each_ref(handle_one_reflog, &cb);
520
}
521
522
static int add_parents_only(struct rev_info *revs, const char *arg, int flags)
@@ -805,6 +843,10 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, const ch
843
handle_all(revs, flags);
844
continue;
845
}
846
+ if (!strcmp(arg, "--reflog")) {
847
+ handle_reflog(revs, flags);
848
+ continue;
849
+ }
850
if (!strcmp(arg, "--not")) {
851
flags ^= UNINTERESTING;
852
continue;