Skip to content

Commit

Permalink
Merge branch 'jc/pack'
Browse files Browse the repository at this point in the history
* jc/pack:
  Keep last used delta base in the delta window
  • Loading branch information
Junio C Hamano committed Sep 15, 2007
2 parents eb6d54f + 7763987 commit 357c5e0
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions builtin-pack-objects.c
Original file line number Diff line number Diff line change
Expand Up @@ -1460,7 +1460,7 @@ static void find_deltas(struct object_entry **list, int window, int depth)
do {
struct object_entry *entry = list[--i];
struct unpacked *n = array + idx;
int j;
int j, best_base = -1;

if (!entry->preferred_base)
processed++;
Expand Down Expand Up @@ -1505,15 +1505,19 @@ static void find_deltas(struct object_entry **list, int window, int depth)

j = window;
while (--j > 0) {
int ret;
uint32_t other_idx = idx + j;
struct unpacked *m;
if (other_idx >= window)
other_idx -= window;
m = array + other_idx;
if (!m->entry)
break;
if (try_delta(n, m, max_depth) < 0)
ret = try_delta(n, m, max_depth);
if (ret < 0)
break;
else if (ret > 0)
best_base = other_idx;
}

/* if we made n a delta, and if n is already at max
Expand All @@ -1523,6 +1527,23 @@ static void find_deltas(struct object_entry **list, int window, int depth)
if (entry->delta && depth <= n->depth)
continue;

/*
* Move the best delta base up in the window, after the
* currently deltified object, to keep it longer. It will
* be the first base object to be attempted next.
*/
if (entry->delta) {
struct unpacked swap = array[best_base];
int dist = (window + idx - best_base) % window;
int dst = best_base;
while (dist--) {
int src = (dst + 1) % window;
array[dst] = array[src];
dst = src;
}
array[dst] = swap;
}

next:
idx++;
if (count + 1 < window)
Expand Down

0 comments on commit 357c5e0

Please sign in to comment.