@matheusbsbs / matheus-bagliano / commits / 898b14cedc
Fork 0

pack-objects: rework check_delta_limit usage

Objects that have delta "children" from pack data reuse must consider the depth of their deepest child when they try to deltify themselves for those children not to become too deep. However, in the context of a "thin" pack, the delta children depth was skipped entirely on the presumption that the pack was always going to be exploded on the receiving end, hence the delta length wasn't an issue. Now that we keep received packs as is and reuse pack data when repacking, those packs do contain delta chains that are longer than expected. Worse, those delta chain may even grow longer when the pack is further repacked into another thin pack for a subsequent transmission. So this patch restores strict delta length even for thin packs, and it moves check_delta_limit() usage directly in the delta loop where it is needed. This way the delta_limit can be removed from struct object_entry as well. Oh and the initial value was wrong too. The progress_interval() function was moved to a more logical location in the process. Signed-off-by: Nicolas Pitre <nico@cam.org> Signed-off-by: Junio C Hamano <junkio@cox.net>

Nicolas Pitre committed Apr 16, 2007 at 12:29 UTC 898b14cedc353de95945fcc56e14f463c3066bf0
1 file changed +32 -44
builtin-pack-objects.c
+32 -44
@@ -27,7 +27,6 @@ struct object_entry {
27 * nonzero if already written.
28 */
29 unsigned int depth; /* delta depth */
30 - unsigned int delta_limit; /* base adjustment for in-pack delta */
30 unsigned int hash; /* name hint hash */
31 enum object_type type;
32 enum object_type in_pack_type; /* could be delta */
@@ -1172,19 +1171,6 @@ static void check_object(struct object_entry *entry)
1171 sha1_to_hex(entry->sha1));
1172 }
1173
1175 -static unsigned int check_delta_limit(struct object_entry *me, unsigned int n)
1176 -{
1177 - struct object_entry *child = me->delta_child;
1178 - unsigned int m = n;
1179 - while (child) {
1180 - unsigned int c = check_delta_limit(child, n + 1);
1181 - if (m < c)
1182 - m = c;
1183 - child = child->delta_sibling;
1184 - }
1185 - return m;
1186 -}
1187 -
1174 static void get_object_details(void)
1175 {
1176 uint32_t i;
@@ -1193,23 +1179,6 @@ static void get_object_details(void)
1179 prepare_pack_ix();
1180 for (i = 0, entry = objects; i < nr_objects; i++, entry++)
1181 check_object(entry);
1196 -
1197 - if (nr_objects == nr_result) {
1198 - /*
1199 - * Depth of objects that depend on the entry -- this
1200 - * is subtracted from depth-max to break too deep
1201 - * delta chain because of delta data reusing.
1202 - * However, we loosen this restriction when we know we
1203 - * are creating a thin pack -- it will have to be
1204 - * expanded on the other end anyway, so do not
1205 - * artificially cut the delta chain and let it go as
1206 - * deep as it wants.
1207 - */
1208 - for (i = 0, entry = objects; i < nr_objects; i++, entry++)
1209 - if (!entry->delta && entry->delta_child)
1210 - entry->delta_limit =
1211 - check_delta_limit(entry, 1);
1212 - }
1182 }
1183
1184 typedef int (*entry_sort_t)(const struct object_entry *, const struct object_entry *);
@@ -1322,16 +1291,7 @@ static int try_delta(struct unpacked *trg, struct unpacked *src,
1291 trg_entry->in_pack_type != OBJ_OFS_DELTA)
1292 return 0;
1293
1325 - /*
1326 - * If the current object is at pack edge, take the depth the
1327 - * objects that depend on the current object into account --
1328 - * otherwise they would become too deep.
1329 - */
1330 - if (trg_entry->delta_child) {
1331 - if (max_depth <= trg_entry->delta_limit)
1332 - return 0;
1333 - max_depth -= trg_entry->delta_limit;
1334 - }
1294 + /* Let's not bust the allowed depth. */
1295 if (src_entry->depth >= max_depth)
1296 return 0;
1297
@@ -1378,9 +1338,17 @@ static int try_delta(struct unpacked *trg, struct unpacked *src,
1338 return 1;
1339 }
1340
1381 -static void progress_interval(int signum)
1341 +static unsigned int check_delta_limit(struct object_entry *me, unsigned int n)
1342 {
1383 - progress_update = 1;
1343 + struct object_entry *child = me->delta_child;
1344 + unsigned int m = n;
1345 + while (child) {
1346 + unsigned int c = check_delta_limit(child, n + 1);
1347 + if (m < c)
1348 + m = c;
1349 + child = child->delta_sibling;
1350 + }
1351 + return m;
1352 }
1353
1354 static void find_deltas(struct object_entry **list, int window, int depth)
@@ -1389,6 +1357,7 @@ static void find_deltas(struct object_entry **list, int window, int depth)
1357 unsigned int array_size = window * sizeof(struct unpacked);
1358 struct unpacked *array;
1359 unsigned last_percent = 999;
1360 + int max_depth;
1361
1362 if (!nr_objects)
1363 return;
@@ -1429,6 +1398,18 @@ static void find_deltas(struct object_entry **list, int window, int depth)
1398 n->data = NULL;
1399 n->entry = entry;
1400
1401 + /*
1402 + * If the current object is at pack edge, take the depth the
1403 + * objects that depend on the current object into account
1404 + * otherwise they would become too deep.
1405 + */
1406 + max_depth = depth;
1407 + if (entry->delta_child) {
1408 + max_depth -= check_delta_limit(entry, 0);
1409 + if (max_depth <= 0)
1410 + goto next;
1411 + }
1412 +
1413 j = window;
1414 while (--j > 0) {
1415 uint32_t other_idx = idx + j;
@@ -1438,9 +1419,10 @@ static void find_deltas(struct object_entry **list, int window, int depth)
1419 m = array + other_idx;
1420 if (!m->entry)
1421 break;
1441 - if (try_delta(n, m, depth) < 0)
1422 + if (try_delta(n, m, max_depth) < 0)
1423 break;
1424 }
1425 +
1426 /* if we made n a delta, and if n is already at max
1427 * depth, leaving it in the window is pointless. we
1428 * should evict it first.
@@ -1448,6 +1430,7 @@ static void find_deltas(struct object_entry **list, int window, int depth)
1430 if (entry->delta && depth <= entry->depth)
1431 continue;
1432
1433 + next:
1434 idx++;
1435 if (idx >= window)
1436 idx = 0;
@@ -1525,6 +1508,11 @@ static int reuse_cached_pack(unsigned char *sha1)
1508 return 1;
1509 }
1510
1511 +static void progress_interval(int signum)
1512 +{
1513 + progress_update = 1;
1514 +}
1515 +
1516 static void setup_progress_signal(void)
1517 {
1518 struct sigaction sa;