use delta index data when finding best delta matches
This patch allows for computing the delta index for each base object only once and reuse it when trying to find the best delta match. This should set the mark and pave the way for possibly better delta generator algorithms. Signed-off-by: Nicolas Pitre <nico@cam.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
Nicolas Pitre committed
Apr 26, 2006 at 23:58 UTC
f6c7081aa97aa67baa06390a1ef36088c33bf010
1 file changed
+41
-37
pack-objects.c
+41
-37
@@ -994,6 +994,7 @@ static int type_size_sort(const struct object_entry *a, const struct object_entr
994
struct unpacked {
995
struct object_entry *entry;
996
void *data;
997
+ struct delta_index *index;
998
};
999
1000
/*
@@ -1004,64 +1005,56 @@ struct unpacked {
1005
* more importantly, the bigger file is likely the more recent
1006
* one.
1007
*/
1007
-static int try_delta(struct unpacked *cur, struct unpacked *old, unsigned max_depth)
1008
+static int try_delta(struct unpacked *trg, struct unpacked *src,
1009
+ struct delta_index *src_index, unsigned max_depth)
1010
{
1009
- struct object_entry *cur_entry = cur->entry;
1010
- struct object_entry *old_entry = old->entry;
1011
- unsigned long size, oldsize, delta_size, sizediff;
1012
- long max_size;
1011
+ struct object_entry *trg_entry = trg->entry;
1012
+ struct object_entry *src_entry = src->entry;
1013
+ unsigned long size, src_size, delta_size, sizediff, max_size;
1014
void *delta_buf;
1015
1016
/* Don't bother doing diffs between different types */
1016
- if (cur_entry->type != old_entry->type)
1017
+ if (trg_entry->type != src_entry->type)
1018
return -1;
1019
1020
/* We do not compute delta to *create* objects we are not
1021
* going to pack.
1022
*/
1022
- if (cur_entry->preferred_base)
1023
+ if (trg_entry->preferred_base)
1024
return -1;
1025
1025
- /* If the current object is at pack edge, take the depth the
1026
+ /*
1027
+ * If the current object is at pack edge, take the depth the
1028
* objects that depend on the current object into account --
1029
* otherwise they would become too deep.
1030
*/
1029
- if (cur_entry->delta_child) {
1030
- if (max_depth <= cur_entry->delta_limit)
1031
+ if (trg_entry->delta_child) {
1032
+ if (max_depth <= trg_entry->delta_limit)
1033
return 0;
1032
- max_depth -= cur_entry->delta_limit;
1034
+ max_depth -= trg_entry->delta_limit;
1035
}
1034
-
1035
- size = cur_entry->size;
1036
- oldsize = old_entry->size;
1037
- sizediff = oldsize > size ? oldsize - size : size - oldsize;
1038
-
1039
- if (size < 50)
1040
- return -1;
1041
- if (old_entry->depth >= max_depth)
1036
+ if (src_entry->depth >= max_depth)
1037
return 0;
1038
1044
- /*
1045
- * NOTE!
1046
- *
1047
- * We always delta from the bigger to the smaller, since that's
1048
- * more space-efficient (deletes don't have to say _what_ they
1049
- * delete).
1050
- */
1039
+ /* Now some size filtering euristics. */
1040
+ size = trg_entry->size;
1041
max_size = size / 2 - 20;
1052
- if (cur_entry->delta)
1053
- max_size = cur_entry->delta_size-1;
1042
+ if (trg_entry->delta)
1043
+ max_size = trg_entry->delta_size-1;
1044
+ src_size = src_entry->size;
1045
+ sizediff = src_size < size ? size - src_size : 0;
1046
if (sizediff >= max_size)
1047
return 0;
1056
- delta_buf = diff_delta(old->data, oldsize,
1057
- cur->data, size, &delta_size, max_size);
1048
+
1049
+ delta_buf = create_delta(src_index, trg->data, size, &delta_size, max_size);
1050
if (!delta_buf)
1051
return 0;
1060
- cur_entry->delta = old_entry;
1061
- cur_entry->delta_size = delta_size;
1062
- cur_entry->depth = old_entry->depth + 1;
1052
+
1053
+ trg_entry->delta = src_entry;
1054
+ trg_entry->delta_size = delta_size;
1055
+ trg_entry->depth = src_entry->depth + 1;
1056
free(delta_buf);
1064
- return 0;
1057
+ return 1;
1058
}
1059
1060
static void progress_interval(int signum)
@@ -1109,11 +1102,19 @@ static void find_deltas(struct object_entry **list, int window, int depth)
1102
*/
1103
continue;
1104
1105
+ if (entry->size < 50)
1106
+ continue;
1107
+ if (n->index)
1108
+ free_delta_index(n->index);
1109
free(n->data);
1110
n->entry = entry;
1111
n->data = read_sha1_file(entry->sha1, type, &size);
1112
if (size != entry->size)
1116
- die("object %s inconsistent object length (%lu vs %lu)", sha1_to_hex(entry->sha1), size, entry->size);
1113
+ die("object %s inconsistent object length (%lu vs %lu)",
1114
+ sha1_to_hex(entry->sha1), size, entry->size);
1115
+ n->index = create_delta_index(n->data, size);
1116
+ if (!n->index)
1117
+ die("out of memory");
1118
1119
j = window;
1120
while (--j > 0) {
@@ -1124,7 +1125,7 @@ static void find_deltas(struct object_entry **list, int window, int depth)
1125
m = array + other_idx;
1126
if (!m->entry)
1127
break;
1127
- if (try_delta(n, m, depth) < 0)
1128
+ if (try_delta(n, m, m->index, depth) < 0)
1129
break;
1130
}
1131
#if 0
@@ -1144,8 +1145,11 @@ static void find_deltas(struct object_entry **list, int window, int depth)
1145
if (progress)
1146
fputc('\n', stderr);
1147
1147
- for (i = 0; i < window; ++i)
1148
+ for (i = 0; i < window; ++i) {
1149
+ if (array[i].index)
1150
+ free_delta_index(array[i].index);
1151
free(array[i].data);
1152
+ }
1153
free(array);
1154
}
1155