X-Git-Url: https://git.octo.it/?a=blobdiff_plain;ds=sidebyside;f=pack-objects.c;h=4145f2530501dd80c6ec8a26465bd45f2e258f17;hb=8e4402592574d630cdb5ab4f55a1b7131802ff72;hp=d6a3463604bf3e61d8cf8b7d55947c229def8f07;hpb=fe041ad68d02d3c117c68f9bd3d37cd80208f31d;p=git.git diff --git a/pack-objects.c b/pack-objects.c index d6a34636..4145f253 100644 --- a/pack-objects.c +++ b/pack-objects.c @@ -1,9 +1,13 @@ #include "cache.h" #include "object.h" +#include "blob.h" +#include "commit.h" +#include "tag.h" +#include "tree.h" #include "delta.h" #include "pack.h" #include "csum-file.h" -#include "diff.h" +#include "tree-walk.h" #include #include @@ -32,9 +36,6 @@ struct object_entry { * be used as the base objectto delta huge * objects against. */ - int based_on_preferred; /* current delta candidate is a preferred - * one, or delta against a preferred one. - */ }; /* @@ -204,7 +205,7 @@ 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(otherbuf, othersize, - buf, size, &delta_size, 0, NULL); + buf, size, &delta_size, 0); if (!delta_buf || delta_size != entry->delta_size) die("delta size changed"); free(buf); @@ -606,7 +607,7 @@ static void add_pbase_tree(struct tree_desc *tree, struct name_path *up) if (!add_object_entry(sha1, hash, 1)) continue; - if (!strcmp(type, "tree")) { + if (!strcmp(type, tree_type)) { struct tree_desc sub; void *elem; struct name_path me; @@ -629,7 +630,7 @@ static void add_preferred_base(unsigned char *sha1) struct tree_desc tree; void *elem; - elem = read_object_with_reference(sha1, "tree", &tree.size, NULL); + elem = read_object_with_reference(sha1, tree_type, &tree.size, NULL); tree.buf = elem; if (!tree.buf) return; @@ -687,13 +688,13 @@ static void check_object(struct object_entry *entry) die("unable to get type of object %s", sha1_to_hex(entry->sha1)); - if (!strcmp(type, "commit")) { + if (!strcmp(type, commit_type)) { entry->type = OBJ_COMMIT; - } else if (!strcmp(type, "tree")) { + } else if (!strcmp(type, tree_type)) { entry->type = OBJ_TREE; - } else if (!strcmp(type, "blob")) { + } else if (!strcmp(type, blob_type)) { entry->type = OBJ_BLOB; - } else if (!strcmp(type, "tag")) { + } else if (!strcmp(type, tag_type)) { entry->type = OBJ_TAG; } else die("unable to pack object %s of type %s", @@ -810,7 +811,6 @@ static int type_size_sort(const struct object_entry *a, const struct object_entr struct unpacked { struct object_entry *entry; void *data; - void **delta_index; }; /* @@ -825,8 +825,6 @@ static int try_delta(struct unpacked *cur, struct unpacked *old, unsigned max_de { struct object_entry *cur_entry = cur->entry; struct object_entry *old_entry = old->entry; - int old_preferred = (old_entry->preferred_base || - old_entry->based_on_preferred); unsigned long size, oldsize, delta_size, sizediff; long max_size; void *delta_buf; @@ -868,38 +866,17 @@ static int try_delta(struct unpacked *cur, struct unpacked *old, unsigned max_de * delete). */ max_size = size / 2 - 20; - if (cur_entry->delta) { - if (cur_entry->based_on_preferred) { - if (old_preferred) - max_size = cur_entry->delta_size-1; - else - /* trying with non-preferred one when we - * already have a delta based on preferred - * one is pointless. - */ - return -1; - } - else if (!old_preferred) - max_size = cur_entry->delta_size-1; - else - /* otherwise... even if delta with a - * preferred one produces a bigger result than - * what we currently have, which is based on a - * non-preferred one, it is OK. - */ - ; - } + if (cur_entry->delta) + max_size = cur_entry->delta_size-1; if (sizediff >= max_size) return -1; delta_buf = diff_delta(old->data, oldsize, - cur->data, size, &delta_size, - max_size, old->delta_index); + cur->data, size, &delta_size, max_size); if (!delta_buf) return 0; cur_entry->delta = old_entry; cur_entry->delta_size = delta_size; cur_entry->depth = old_entry->depth + 1; - cur_entry->based_on_preferred = old_preferred; free(delta_buf); return 0; } @@ -950,7 +927,6 @@ static void find_deltas(struct object_entry **list, int window, int depth) */ continue; - free(n->delta_index); free(n->data); n->entry = entry; n->data = read_sha1_file(entry->sha1, type, &size); @@ -969,6 +945,15 @@ static void find_deltas(struct object_entry **list, int window, int depth) if (try_delta(n, m, depth) < 0) break; } +#if 0 + /* if we made n a delta, and if n is already at max + * depth, leaving it in the window is pointless. we + * should evict it first. + * ... in theory only; somehow this makes things worse. + */ + if (entry->delta && depth <= entry->depth) + continue; +#endif idx++; if (idx >= window) idx = 0; @@ -977,10 +962,8 @@ static void find_deltas(struct object_entry **list, int window, int depth) if (progress) fputc('\n', stderr); - for (i = 0; i < window; ++i) { - free(array[i].delta_index); + for (i = 0; i < window; ++i) free(array[i].data); - } free(array); }