pack-objects: consider packs in multi-pack-index

When running 'git pack-objects --local', we want to avoid packing objects that are in an alternate. Currently, we check for these objects using the packed_git_mru list, which excludes the pack-files covered by a multi-pack-index. Add a new iteration over the multi-pack-indexes to find these copies and mark them as unwanted. Signed-off-by: Derrick Stolee <dstolee@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Derrick Stolee committed Aug 20, 2018 at 16:52 UTC 6a22d521260f86dff8fe6f23ab329cebb62ba4f0
2 files changed +35 -1
builtin/pack-objects.c
+28
@@ -31,6 +31,7 @@
31 #include "packfile.h"
32 #include "object-store.h"
33 #include "dir.h"
34 +#include "midx.h"
35
36 #define IN_PACK(obj) oe_in_pack(&to_pack, obj)
37 #define SIZE(obj) oe_size(&to_pack, obj)
@@ -1040,6 +1041,7 @@ static int want_object_in_pack(const struct object_id *oid,
1041 {
1042 int want;
1043 struct list_head *pos;
1044 + struct multi_pack_index *m;
1045
1046 if (!exclude && local && has_loose_object_nonlocal(oid))
1047 return 0;
@@ -1054,6 +1056,32 @@ static int want_object_in_pack(const struct object_id *oid,
1056 if (want != -1)
1057 return want;
1058 }
1059 +
1060 + for (m = get_multi_pack_index(the_repository); m; m = m->next) {
1061 + struct pack_entry e;
1062 + if (fill_midx_entry(oid, &e, m)) {
1063 + struct packed_git *p = e.p;
1064 + off_t offset;
1065 +
1066 + if (p == *found_pack)
1067 + offset = *found_offset;
1068 + else
1069 + offset = find_pack_entry_one(oid->hash, p);
1070 +
1071 + if (offset) {
1072 + if (!*found_pack) {
1073 + if (!is_pack_valid(p))
1074 + continue;
1075 + *found_offset = offset;
1076 + *found_pack = p;
1077 + }
1078 + want = want_found_object(exclude, p);
1079 + if (want != -1)
1080 + return want;
1081 + }
1082 + }
1083 + }
1084 +
1085 list_for_each(pos, get_packed_git_mru(the_repository)) {
1086 struct packed_git *p = list_entry(pos, struct packed_git, mru);
1087 off_t offset;
t/t5319-multi-pack-index.sh
+7 -1
@@ -176,7 +176,13 @@ test_expect_success 'multi-pack-index and alternates' '
176 compare_results_with_midx "with alternate (local midx)"
177
178 test_expect_success 'multi-pack-index in an alternate' '
179 - mv .git/objects/pack/* alt.git/objects/pack
179 + mv .git/objects/pack/* alt.git/objects/pack &&
180 + test_commit add_local_objects &&
181 + git repack --local &&
182 + git multi-pack-index write &&
183 + midx_read_expect 1 3 4 $objdir &&
184 + git reset --hard HEAD~1 &&
185 + rm -f .git/objects/pack/*
186 '
187
188 compare_results_with_midx "with alternate (remote midx)"