straighten the list of objects to deltify
Not all objects are subject to deltification, so avoid carrying those along, and provide the real count to progress display. Signed-off-by: Nicolas Pitre <nico@cam.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Nicolas Pitre committed
Sep 6, 2007 at 02:13 UTC
75d3985319f2eb40008e9fe6454880ecc620a0de
1 file changed
+42
-35
builtin-pack-objects.c
+42
-35
@@ -1313,12 +1313,6 @@ static int try_delta(struct unpacked *trg, struct unpacked *src,
1313
if (trg_entry->type != src_entry->type)
1314
return -1;
1315
1316
- /* We do not compute delta to *create* objects we are not
1317
- * going to pack.
1318
- */
1319
- if (trg_entry->preferred_base)
1320
- return -1;
1321
-
1316
/*
1317
* We do not bother to try a delta that we discarded
1318
* on an earlier try, but only when reusing delta data.
@@ -1443,43 +1437,24 @@ static void free_unpacked(struct unpacked *n)
1437
n->depth = 0;
1438
}
1439
1446
-static void find_deltas(struct object_entry **list, int window, int depth)
1440
+static void find_deltas(struct object_entry **list, unsigned list_size,
1441
+ unsigned nr_deltas, int window, int depth)
1442
{
1448
- uint32_t i = nr_objects, idx = 0, count = 0, processed = 0;
1443
+ uint32_t i = list_size, idx = 0, count = 0, processed = 0;
1444
unsigned int array_size = window * sizeof(struct unpacked);
1445
struct unpacked *array;
1446
int max_depth;
1447
1453
- if (!nr_objects)
1454
- return;
1448
array = xmalloc(array_size);
1449
memset(array, 0, array_size);
1450
if (progress)
1458
- start_progress(&progress_state, "Deltifying %u objects...", "", nr_result);
1451
+ start_progress(&progress_state, "Deltifying %u objects...", "", nr_deltas);
1452
1453
do {
1454
struct object_entry *entry = list[--i];
1455
struct unpacked *n = array + idx;
1456
int j, best_base = -1;
1457
1465
- if (!entry->preferred_base)
1466
- processed++;
1467
-
1468
- if (progress)
1469
- display_progress(&progress_state, processed);
1470
-
1471
- if (entry->delta)
1472
- /* This happens if we decided to reuse existing
1473
- * delta from a pack. "!no_reuse_delta &&" is implied.
1474
- */
1475
- continue;
1476
-
1477
- if (entry->size < 50)
1478
- continue;
1479
-
1480
- if (entry->no_try_delta)
1481
- continue;
1482
-
1458
free_unpacked(n);
1459
n->entry = entry;
1460
@@ -1491,6 +1466,15 @@ static void find_deltas(struct object_entry **list, int window, int depth)
1466
count--;
1467
}
1468
1469
+ /* We do not compute delta to *create* objects we are not
1470
+ * going to pack.
1471
+ */
1472
+ if (entry->preferred_base)
1473
+ goto next;
1474
+
1475
+ if (progress)
1476
+ display_progress(&progress_state, ++processed);
1477
+
1478
/*
1479
* If the current object is at pack edge, take the depth the
1480
* objects that depend on the current object into account
@@ -1565,18 +1549,41 @@ static void find_deltas(struct object_entry **list, int window, int depth)
1549
static void prepare_pack(int window, int depth)
1550
{
1551
struct object_entry **delta_list;
1568
- uint32_t i;
1552
+ uint32_t i, n, nr_deltas;
1553
1554
get_object_details();
1555
1572
- if (!window || !depth)
1556
+ if (!nr_objects || !window || !depth)
1557
return;
1558
1559
delta_list = xmalloc(nr_objects * sizeof(*delta_list));
1576
- for (i = 0; i < nr_objects; i++)
1577
- delta_list[i] = objects + i;
1578
- qsort(delta_list, nr_objects, sizeof(*delta_list), type_size_sort);
1579
- find_deltas(delta_list, window+1, depth);
1560
+ nr_deltas = n = 0;
1561
+
1562
+ for (i = 0; i < nr_objects; i++) {
1563
+ struct object_entry *entry = objects + i;
1564
+
1565
+ if (entry->delta)
1566
+ /* This happens if we decided to reuse existing
1567
+ * delta from a pack. "!no_reuse_delta &&" is implied.
1568
+ */
1569
+ continue;
1570
+
1571
+ if (entry->size < 50)
1572
+ continue;
1573
+
1574
+ if (entry->no_try_delta)
1575
+ continue;
1576
+
1577
+ if (!entry->preferred_base)
1578
+ nr_deltas++;
1579
+
1580
+ delta_list[n++] = entry;
1581
+ }
1582
+
1583
+ if (nr_deltas) {
1584
+ qsort(delta_list, n, sizeof(*delta_list), type_size_sort);
1585
+ find_deltas(delta_list, n, nr_deltas, window+1, depth);
1586
+ }
1587
free(delta_list);
1588
}
1589