Skip to content

Commit 6304929

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

File tree

3 files changed

+52
-9
lines changed

3 files changed

+52
-9
lines changed

builtin-pack-objects.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ static const char pack_usage[] = "\
1717
git-pack-objects [{ -q | --progress | --all-progress }] \n\
1818
[--local] [--incremental] [--window=N] [--depth=N] \n\
1919
[--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\
2121
[<ref-list | <object-list]";
2222

2323
struct object_entry {
@@ -1575,6 +1575,7 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
15751575
}
15761576
if (!strcmp("--unpacked", arg) ||
15771577
!strncmp("--unpacked=", arg, 11) ||
1578+
!strcmp("--reflog", arg) ||
15781579
!strcmp("--all", arg)) {
15791580
use_internal_rev_list = 1;
15801581
if (ARRAY_SIZE(rp_av) - 1 <= rp_ac)

git-repack.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ case ",$all_into_one," in
6262
esac
6363

6464
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") ||
6666
exit 1
6767
if [ -z "$name" ]; then
6868
echo Nothing new to pack.

revision.c

Lines changed: 49 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -464,21 +464,59 @@ static void limit_list(struct rev_info *revs)
464464
revs->commits = newlist;
465465
}
466466

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+
};
469472

470473
static int handle_one_ref(const char *path, const unsigned char *sha1, int flag, void *cb_data)
471474
{
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, "");
474479
return 0;
475480
}
476481

477482
static void handle_all(struct rev_info *revs, unsigned flags)
478483
{
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);
482520
}
483521

484522
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
805843
handle_all(revs, flags);
806844
continue;
807845
}
846+
if (!strcmp(arg, "--reflog")) {
847+
handle_reflog(revs, flags);
848+
continue;
849+
}
808850
if (!strcmp(arg, "--not")) {
809851
flags ^= UNINTERESTING;
810852
continue;

0 commit comments

Comments
 (0)