Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 48 additions & 20 deletions delta-islands.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "pack.h"
#include "tree-walk.h"
#include "diff.h"
#include "prio-queue.h"
#include "progress.h"
#include "refs.h"
#include "khash.h"
Expand Down Expand Up @@ -158,7 +159,12 @@ static struct island_bitmap *create_or_get_island_marks(struct object *obj)
return kh_value(island_marks, pos);
}

static void set_island_marks(struct object *obj, struct island_bitmap *marks)
/*
* Given an object and a set of marks, update the island marks on that object
* to be the union of the existing marks and these new marks. Returns 1 if
* the mark set changes in this process.
*/
static int set_island_marks(struct object *obj, struct island_bitmap *marks)
{
struct island_bitmap *b;
khiter_t pos;
Expand All @@ -172,19 +178,23 @@ static void set_island_marks(struct object *obj, struct island_bitmap *marks)
*/
marks->refcount++;
kh_value(island_marks, pos) = marks;
return;
return 1;
}

b = kh_value(island_marks, pos);
if (island_bitmap_is_subset(marks, b))
return 0;

/*
* We do have it. Make sure we split any copy-on-write before
* updating.
*/
b = kh_value(island_marks, pos);
if (b->refcount > 1) {
b->refcount--;
b = kh_value(island_marks, pos) = island_bitmap_new(b);
}
island_bitmap_or(b, marks);
return 1;
}

static void mark_remote_island_1(struct repository *r,
Expand Down Expand Up @@ -226,9 +236,10 @@ static void mark_remote_island_1(struct repository *r,
struct tree_islands_todo {
struct object_entry *entry;
unsigned int depth;
unsigned queued:1;
};

static int tree_depth_compare(const void *a, const void *b)
static int tree_depth_compare(const void *a, const void *b, void *data UNUSED)
{
const struct tree_islands_todo *todo_a = a;
const struct tree_islands_todo *todo_b = b;
Expand All @@ -242,40 +253,44 @@ void resolve_tree_islands(struct repository *r,
{
struct progress *progress_state = NULL;
struct tree_islands_todo *todo;
int nr = 0;
int i;
struct tree_islands_todo *current;
struct prio_queue queue = { .compare = tree_depth_compare };
uint64_t processed = 0;
uint32_t i;

if (!island_marks)
return;

/*
* We process only trees, as commits and tags have already been handled
* (and passed their marks on to root trees, as well. We must make sure
* to process them in descending tree-depth order so that marks
* propagate down the tree properly, even if a sub-tree is found in
* multiple parent trees.
* (and passed their marks on to root trees, as well). Prefer shallower
* trees, but the first-seen depth can place a shared tree before
* another parent. Requeue trees whose marks change after processing.
*/
ALLOC_ARRAY(todo, to_pack->nr_objects);
for (i = 0; i < to_pack->nr_objects; i++) {
if (oe_type(&to_pack->objects[i]) == OBJ_TREE) {
todo[nr].entry = &to_pack->objects[i];
todo[nr].depth = oe_tree_depth(to_pack, &to_pack->objects[i]);
nr++;
todo[i].entry = &to_pack->objects[i];
todo[i].depth = oe_tree_depth(to_pack, &to_pack->objects[i]);
todo[i].queued = 1;
prio_queue_put(&queue, &todo[i]);
}
}
QSORT(todo, nr, tree_depth_compare);

if (progress)
progress_state = start_progress(r, _("Propagating island marks"), nr);
progress_state = start_progress(r, _("Propagating island marks"), 0);

for (i = 0; i < nr; i++) {
struct object_entry *ent = todo[i].entry;
while ((current = prio_queue_get(&queue))) {
struct object_entry *ent = current->entry;
struct island_bitmap *root_marks;
struct tree *tree;
struct tree_desc desc;
struct name_entry entry;
khiter_t pos;

current->queued = 0;
display_progress(progress_state, ++processed);

pos = kh_get_oid_map(island_marks, ent->idx.oid);
if (pos >= kh_end(island_marks))
continue;
Expand All @@ -289,6 +304,8 @@ void resolve_tree_islands(struct repository *r,
init_tree_desc(&desc, &tree->object.oid, tree->buffer, tree->size);
while (tree_entry(&desc, &entry)) {
struct object *obj;
struct object_entry *child;
struct tree_islands_todo *child_todo;

if (S_ISGITLINK(entry.mode))
continue;
Expand All @@ -297,15 +314,26 @@ void resolve_tree_islands(struct repository *r,
if (!obj)
continue;

set_island_marks(obj, root_marks);
if (!set_island_marks(obj, root_marks) ||
!S_ISDIR(entry.mode))
continue;

child = packlist_find(to_pack, &entry.oid);
if (!child || oe_type(child) != OBJ_TREE)
continue;

child_todo = &todo[child - to_pack->objects];
if (!child_todo->queued) {
child_todo->queued = 1;
prio_queue_put(&queue, child_todo);
}
}

free_tree_buffer(tree);

display_progress(progress_state, i+1);
}

stop_progress(&progress_state);
clear_prio_queue(&queue);
free(todo);
}

Expand Down
91 changes: 91 additions & 0 deletions t/t5320-delta-islands.sh
Original file line number Diff line number Diff line change
Expand Up @@ -170,4 +170,95 @@ test_expect_success 'unmatched island core is not fatal' '
git -c "pack.islandcore=one" repack -adfi
'

for order in deep-newer shallow-newer
do
test_expect_success "setup shared subtree ($order)" '
git init "shared-subtree-$order" &&
(
cd "shared-subtree-$order" &&
shared=$({ test-tool genrandom seed 10240 && echo 1; } |
git hash-object -w --stdin) &&
private=$({ test-tool genrandom seed 10240 && echo 12; } |
git hash-object -w --stdin) &&
nested=$({ test-tool genrandom nested 10240 && echo 1; } |
git hash-object -w --stdin) &&
private_nested=$({ test-tool genrandom nested 10240 && echo 12; } |
git hash-object -w --stdin) &&
leaf=$(printf "100644 blob %s\tfile\n" "$nested" |
git mktree) &&
subtree=$(printf "040000 tree %s\tchild\n100644 blob %s\tfile\n" \
"$leaf" "$shared" | git mktree) &&
root_one=$({
printf "040000 tree %s\ta\n" "$subtree" &&
printf "100644 blob %s\tprivate\n" "$private" &&
printf "100644 blob %s\tprivate-nested\n" "$private_nested"
} | git mktree) &&
inner=$(printf "040000 tree %s\tc\n" "$subtree" |
git mktree) &&
middle=$(printf "040000 tree %s\tb\n" "$inner" |
git mktree) &&
root_two=$(printf "040000 tree %s\tz\n" "$middle" |
git mktree) &&
test_tick &&
one=$(echo one | git commit-tree "$root_one") &&
test_tick &&
two=$(echo two | git commit-tree "$root_two") &&
if test "$order" = shallow-newer
then
test_tick &&
one=$(echo one | git commit-tree "$root_one")
fi &&
git update-ref refs/heads/one "$one" &&
git update-ref refs/heads/two "$two"
)
'

for traversal in --no-path-walk --path-walk
do
for bitmap in --no-write-bitmap-index --write-bitmap-index
do
test_expect_success "islands respect shared subtree ($order, $traversal, $bitmap)" '
(
cd "shared-subtree-$order" &&
shared=$(git rev-parse one:a/file) &&
nested=$(git rev-parse one:a/child/file) &&
: >trace &&
GIT_TRACE2_EVENT="$(pwd)/trace" \
git -c "pack.island=refs/heads/(.*)" \
repack -adfi "$bitmap" "$traversal" 2>err &&
test_grep ! "failed to pack objects via path-walk" err &&
if test "$traversal" = --path-walk
then
test_region pack-objects path-walk trace
fi &&
is_delta_base "$shared" "$ZERO_OID" &&
is_delta_base "$nested" "$ZERO_OID"
)
'
done

test_expect_success "island core orders shared subtree ($order, $traversal)" '
(
cd "shared-subtree-$order" &&
shared=$(git rev-parse one:a/file) &&
private=$(git rev-parse one:private) &&
: >trace &&
GIT_TRACE2_EVENT="$(pwd)/trace" \
git -c "pack.island=refs/heads/(.*)" \
-c pack.islandCore=two repack -adfi "$traversal" 2>err &&
test_grep ! "failed to pack objects via path-walk" err &&
if test "$traversal" = --path-walk
then
test_region pack-objects path-walk trace
fi &&
printf "%s\n" "$shared" "$private" >expect &&
git verify-pack -v .git/objects/pack/*.pack >pack &&
cut -d" " -f1 pack |
grep -E "^($shared|$private)$" >actual &&
test_cmp expect actual
)
'
done
done

test_done
Loading