Skip to content

Commit 6a22d52

Browse files
derrickstoleegitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e9ab2ed commit 6a22d52

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

builtin/pack-objects.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include "packfile.h"
3232
#include "object-store.h"
3333
#include "dir.h"
34+
#include "midx.h"
3435

3536
#define IN_PACK(obj) oe_in_pack(&to_pack, obj)
3637
#define SIZE(obj) oe_size(&to_pack, obj)
@@ -1040,6 +1041,7 @@ static int want_object_in_pack(const struct object_id *oid,
10401041
{
10411042
int want;
10421043
struct list_head *pos;
1044+
struct multi_pack_index *m;
10431045

10441046
if (!exclude && local && has_loose_object_nonlocal(oid))
10451047
return 0;
@@ -1054,6 +1056,32 @@ static int want_object_in_pack(const struct object_id *oid,
10541056
if (want != -1)
10551057
return want;
10561058
}
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+
10571085
list_for_each(pos, get_packed_git_mru(the_repository)) {
10581086
struct packed_git *p = list_entry(pos, struct packed_git, mru);
10591087
off_t offset;

t/t5319-multi-pack-index.sh

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,13 @@ test_expect_success 'multi-pack-index and alternates' '
176176
compare_results_with_midx "with alternate (local midx)"
177177

178178
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/*
180186
'
181187

182188
compare_results_with_midx "with alternate (remote midx)"

0 commit comments

Comments
 (0)