diff options
author | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-06-25 19:30:20 -0700 |
---|---|---|
committer | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-06-25 19:30:20 -0700 |
commit | 75c42d8cc3b42e4b82946848b8ba902b4bbcc38d (patch) | |
tree | f123aa0c4a72ab09eef8cd420d9bcf5391343666 /pack-objects.c | |
parent | 78817c15de0dfb408d1e35a2f692f54dc51e80a3 (diff) | |
download | git-75c42d8cc3b42e4b82946848b8ba902b4bbcc38d.tar.gz git-75c42d8cc3b42e4b82946848b8ba902b4bbcc38d.tar.xz |
Add a "max_size" parameter to diff_delta()
Anything that generates a delta to see if two objects are close usually
isn't interested in the delta ends up being bigger than some specified
size, and this allows us to stop delta generation early when that
happens.
Diffstat (limited to 'pack-objects.c')
-rw-r--r-- | pack-objects.c | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/pack-objects.c b/pack-objects.c index dfa9d44a1..d9328a98d 100644 --- a/pack-objects.c +++ b/pack-objects.c @@ -83,8 +83,8 @@ static void *delta_against(void *buf, unsigned long size, struct object_entry *e if (!otherbuf) die("unable to read %s", sha1_to_hex(entry->delta->sha1)); - delta_buf = diff_delta(buf, size, otherbuf, othersize, &delta_size); - if (delta_size != entry->delta_size) + delta_buf = diff_delta(buf, size, otherbuf, othersize, &delta_size, ~0UL); + if (!delta_buf || delta_size != entry->delta_size) die("delta size changed"); free(buf); free(otherbuf); @@ -292,6 +292,7 @@ static int try_delta(struct unpacked *cur, struct unpacked *old) struct object_entry *cur_entry = cur->entry; struct object_entry *old_entry = old->entry; unsigned long size, oldsize, delta_size; + long max_size; void *delta_buf; /* Don't bother doing diffs between different types */ @@ -300,6 +301,8 @@ static int try_delta(struct unpacked *cur, struct unpacked *old) /* Size is guaranteed to be larger than or equal to oldsize */ size = cur_entry->size; + if (size < 50) + return -1; oldsize = old_entry->size; if (size - oldsize > oldsize / 4) return -1; @@ -311,15 +314,14 @@ static int try_delta(struct unpacked *cur, struct unpacked *old) * more space-efficient (deletes don't have to say _what_ they * delete). */ - delta_buf = diff_delta(cur->data, size, old->data, oldsize, &delta_size); + max_size = size / 2 - 20; + if (cur_entry->delta) + max_size = cur_entry->delta_size-1; + delta_buf = diff_delta(cur->data, size, old->data, oldsize, &delta_size, max_size); if (!delta_buf) - die("unable to create delta"); - if (delta_size + 20 < size / 2) { - if (!cur_entry->delta || cur_entry->delta_size > delta_size) { - cur_entry->delta = old_entry; - cur_entry->delta_size = delta_size; - } - } + return 0; + cur_entry->delta = old_entry; + cur_entry->delta_size = delta_size; free(delta_buf); return 0; } |