]> git.ipfire.org Git - thirdparty/git.git/blame - builtin/pack-redundant.c
Sync with 2.16.6
[thirdparty/git.git] / builtin / pack-redundant.c
CommitLineData
c283ab21
LS
1/*
2*
3* Copyright 2005, Lukas Sandstrom <lukass@etek.chalmers.se>
4*
5* This file is licensed under the GPL v2.
6*
7*/
8
c2e86add 9#include "builtin.h"
4f39cd82 10#include "packfile.h"
c283ab21 11
6d016c9c
LS
12#define BLKSIZE 512
13
9bc0f32c 14static const char pack_redundant_usage[] =
9c9b4f2f 15"git pack-redundant [--verbose] [--alt-odb] (--all | <filename.pack>...)";
c283ab21 16
96f1e58f 17static int load_all_packs, verbose, alt_odb;
c283ab21
LS
18
19struct llist_item {
20 struct llist_item *next;
42873078 21 const unsigned char *sha1;
c283ab21 22};
bd22c904 23static struct llist {
c283ab21
LS
24 struct llist_item *front;
25 struct llist_item *back;
26 size_t size;
1c3039e8 27} *all_objects; /* all objects which must be present in local packfiles */
c283ab21 28
bd22c904 29static struct pack_list {
c283ab21
LS
30 struct pack_list *next;
31 struct packed_git *pack;
32 struct llist *unique_objects;
33 struct llist *all_objects;
1c3039e8 34} *local_packs = NULL, *altodb_packs = NULL;
c283ab21
LS
35
36struct pll {
37 struct pll *next;
38 struct pack_list *pl;
39};
40
96f1e58f 41static struct llist_item *free_nodes;
60435f68 42
6d016c9c
LS
43static inline void llist_item_put(struct llist_item *item)
44{
45 item->next = free_nodes;
46 free_nodes = item;
47}
48
962554c6 49static inline struct llist_item *llist_item_get(void)
60435f68 50{
b2e4bafb 51 struct llist_item *new_item;
60435f68 52 if ( free_nodes ) {
b2e4bafb 53 new_item = free_nodes;
60435f68 54 free_nodes = free_nodes->next;
6d016c9c
LS
55 } else {
56 int i = 1;
b2e4bafb 57 ALLOC_ARRAY(new_item, BLKSIZE);
eeefa7c9 58 for (; i < BLKSIZE; i++)
b2e4bafb 59 llist_item_put(&new_item[i]);
6d016c9c 60 }
b2e4bafb 61 return new_item;
60435f68
AR
62}
63
60435f68 64static void llist_free(struct llist *list)
c283ab21 65{
eeefa7c9 66 while ((list->back = list->front)) {
c283ab21 67 list->front = list->front->next;
60435f68 68 llist_item_put(list->back);
c283ab21
LS
69 }
70 free(list);
71}
72
bd22c904 73static inline void llist_init(struct llist **list)
c283ab21
LS
74{
75 *list = xmalloc(sizeof(struct llist));
76 (*list)->front = (*list)->back = NULL;
77 (*list)->size = 0;
78}
79
bd22c904 80static struct llist * llist_copy(struct llist *list)
c283ab21
LS
81{
82 struct llist *ret;
b2e4bafb 83 struct llist_item *new_item, *old_item, *prev;
a6080a0a 84
c283ab21
LS
85 llist_init(&ret);
86
87 if ((ret->size = list->size) == 0)
88 return ret;
89
b2e4bafb
BW
90 new_item = ret->front = llist_item_get();
91 new_item->sha1 = list->front->sha1;
c283ab21 92
b2e4bafb
BW
93 old_item = list->front->next;
94 while (old_item) {
95 prev = new_item;
96 new_item = llist_item_get();
97 prev->next = new_item;
98 new_item->sha1 = old_item->sha1;
99 old_item = old_item->next;
c283ab21 100 }
b2e4bafb
BW
101 new_item->next = NULL;
102 ret->back = new_item;
a6080a0a 103
c283ab21
LS
104 return ret;
105}
106
42873078
NP
107static inline struct llist_item *llist_insert(struct llist *list,
108 struct llist_item *after,
109 const unsigned char *sha1)
c283ab21 110{
b2e4bafb
BW
111 struct llist_item *new_item = llist_item_get();
112 new_item->sha1 = sha1;
113 new_item->next = NULL;
c283ab21
LS
114
115 if (after != NULL) {
b2e4bafb
BW
116 new_item->next = after->next;
117 after->next = new_item;
c283ab21 118 if (after == list->back)
b2e4bafb 119 list->back = new_item;
c283ab21
LS
120 } else {/* insert in front */
121 if (list->size == 0)
b2e4bafb 122 list->back = new_item;
c283ab21 123 else
b2e4bafb
BW
124 new_item->next = list->front;
125 list->front = new_item;
c283ab21
LS
126 }
127 list->size++;
b2e4bafb 128 return new_item;
c283ab21
LS
129}
130
42873078
NP
131static inline struct llist_item *llist_insert_back(struct llist *list,
132 const unsigned char *sha1)
c283ab21
LS
133{
134 return llist_insert(list, list->back, sha1);
135}
136
42873078
NP
137static inline struct llist_item *llist_insert_sorted_unique(struct llist *list,
138 const unsigned char *sha1, struct llist_item *hint)
c283ab21
LS
139{
140 struct llist_item *prev = NULL, *l;
141
142 l = (hint == NULL) ? list->front : hint;
143 while (l) {
a89fccd2 144 int cmp = hashcmp(l->sha1, sha1);
c283ab21
LS
145 if (cmp > 0) { /* we insert before this entry */
146 return llist_insert(list, prev, sha1);
147 }
eeefa7c9 148 if (!cmp) { /* already exists */
c283ab21
LS
149 return l;
150 }
151 prev = l;
152 l = l->next;
153 }
154 /* insert at the end */
155 return llist_insert_back(list, sha1);
156}
157
c283ab21 158/* returns a pointer to an item in front of sha1 */
b99a394c 159static inline struct llist_item * llist_sorted_remove(struct llist *list, const unsigned char *sha1, struct llist_item *hint)
c283ab21
LS
160{
161 struct llist_item *prev, *l;
162
163redo_from_start:
164 l = (hint == NULL) ? list->front : hint;
165 prev = NULL;
166 while (l) {
a89fccd2 167 int cmp = hashcmp(l->sha1, sha1);
c283ab21
LS
168 if (cmp > 0) /* not in list, since sorted */
169 return prev;
eeefa7c9 170 if (!cmp) { /* found */
c283ab21
LS
171 if (prev == NULL) {
172 if (hint != NULL && hint != list->front) {
173 /* we don't know the previous element */
174 hint = NULL;
175 goto redo_from_start;
176 }
177 list->front = l->next;
178 } else
179 prev->next = l->next;
180 if (l == list->back)
181 list->back = prev;
60435f68 182 llist_item_put(l);
c283ab21
LS
183 list->size--;
184 return prev;
185 }
186 prev = l;
187 l = l->next;
188 }
189 return prev;
190}
191
1a41e743 192/* computes A\B */
bd22c904 193static void llist_sorted_difference_inplace(struct llist *A,
1a41e743
LS
194 struct llist *B)
195{
196 struct llist_item *hint, *b;
197
198 hint = NULL;
199 b = B->front;
200
201 while (b) {
202 hint = llist_sorted_remove(A, b->sha1, hint);
203 b = b->next;
204 }
205}
206
bd22c904 207static inline struct pack_list * pack_list_insert(struct pack_list **pl,
c283ab21
LS
208 struct pack_list *entry)
209{
210 struct pack_list *p = xmalloc(sizeof(struct pack_list));
211 memcpy(p, entry, sizeof(struct pack_list));
212 p->next = *pl;
213 *pl = p;
214 return p;
215}
216
bd22c904 217static inline size_t pack_list_size(struct pack_list *pl)
1c3039e8
LS
218{
219 size_t ret = 0;
eeefa7c9 220 while (pl) {
1c3039e8
LS
221 ret++;
222 pl = pl->next;
223 }
224 return ret;
225}
226
d1ab1577
AR
227static struct pack_list * pack_list_difference(const struct pack_list *A,
228 const struct pack_list *B)
c283ab21 229{
d1ab1577
AR
230 struct pack_list *ret;
231 const struct pack_list *pl;
c283ab21
LS
232
233 if (A == NULL)
234 return NULL;
235
236 pl = B;
237 while (pl != NULL) {
238 if (A->pack == pl->pack)
239 return pack_list_difference(A->next, B);
240 pl = pl->next;
241 }
242 ret = xmalloc(sizeof(struct pack_list));
243 memcpy(ret, A, sizeof(struct pack_list));
244 ret->next = pack_list_difference(A->next, B);
245 return ret;
246}
247
bd22c904 248static void cmp_two_packs(struct pack_list *p1, struct pack_list *p2)
c283ab21 249{
8c681e07 250 unsigned long p1_off = 0, p2_off = 0, p1_step, p2_step;
42873078 251 const unsigned char *p1_base, *p2_base;
c283ab21 252 struct llist_item *p1_hint = NULL, *p2_hint = NULL;
1d7f171c 253
42873078
NP
254 p1_base = p1->pack->index_data;
255 p2_base = p2->pack->index_data;
8c681e07
NP
256 p1_base += 256 * 4 + ((p1->pack->index_version < 2) ? 4 : 8);
257 p2_base += 256 * 4 + ((p2->pack->index_version < 2) ? 4 : 8);
258 p1_step = (p1->pack->index_version < 2) ? 24 : 20;
259 p2_step = (p2->pack->index_version < 2) ? 24 : 20;
c283ab21 260
8c681e07
NP
261 while (p1_off < p1->pack->num_objects * p1_step &&
262 p2_off < p2->pack->num_objects * p2_step)
c283ab21 263 {
a89fccd2 264 int cmp = hashcmp(p1_base + p1_off, p2_base + p2_off);
c283ab21
LS
265 /* cmp ~ p1 - p2 */
266 if (cmp == 0) {
267 p1_hint = llist_sorted_remove(p1->unique_objects,
268 p1_base + p1_off, p1_hint);
269 p2_hint = llist_sorted_remove(p2->unique_objects,
270 p1_base + p1_off, p2_hint);
8c681e07
NP
271 p1_off += p1_step;
272 p2_off += p2_step;
c283ab21
LS
273 continue;
274 }
275 if (cmp < 0) { /* p1 has the object, p2 doesn't */
8c681e07 276 p1_off += p1_step;
c283ab21 277 } else { /* p2 has the object, p1 doesn't */
8c681e07 278 p2_off += p2_step;
c283ab21
LS
279 }
280 }
281}
282
962554c6 283static void pll_free(struct pll *l)
751a71e2 284{
6d016c9c
LS
285 struct pll *old;
286 struct pack_list *opl;
287
288 while (l) {
289 old = l;
290 while (l->pl) {
291 opl = l->pl;
292 l->pl = opl->next;
293 free(opl);
751a71e2 294 }
6d016c9c
LS
295 l = l->next;
296 free(old);
751a71e2 297 }
751a71e2
LS
298}
299
c283ab21
LS
300/* all the permutations have to be free()d at the same time,
301 * since they refer to each other
302 */
6d016c9c 303static struct pll * get_permutations(struct pack_list *list, int n)
c283ab21 304{
bdd478d6 305 struct pll *subset, *ret = NULL, *new_pll = NULL;
6d016c9c
LS
306
307 if (list == NULL || pack_list_size(list) < n || n == 0)
c283ab21
LS
308 return NULL;
309
6d016c9c
LS
310 if (n == 1) {
311 while (list) {
bdd478d6 312 new_pll = xmalloc(sizeof(*new_pll));
6d016c9c
LS
313 new_pll->pl = NULL;
314 pack_list_insert(&new_pll->pl, list);
315 new_pll->next = ret;
316 ret = new_pll;
317 list = list->next;
318 }
319 return ret;
c283ab21
LS
320 }
321
6d016c9c
LS
322 while (list->next) {
323 subset = get_permutations(list->next, n - 1);
324 while (subset) {
bdd478d6 325 new_pll = xmalloc(sizeof(*new_pll));
6d016c9c
LS
326 new_pll->pl = subset->pl;
327 pack_list_insert(&new_pll->pl, list);
328 new_pll->next = ret;
329 ret = new_pll;
330 subset = subset->next;
751a71e2 331 }
6d016c9c 332 list = list->next;
c283ab21 333 }
6d016c9c 334 return ret;
c283ab21
LS
335}
336
bd22c904 337static int is_superset(struct pack_list *pl, struct llist *list)
c283ab21 338{
1c3039e8 339 struct llist *diff;
c283ab21
LS
340
341 diff = llist_copy(list);
342
343 while (pl) {
d1ab1577 344 llist_sorted_difference_inplace(diff, pl->all_objects);
c283ab21
LS
345 if (diff->size == 0) { /* we're done */
346 llist_free(diff);
347 return 1;
348 }
349 pl = pl->next;
350 }
351 llist_free(diff);
352 return 0;
353}
354
bd22c904 355static size_t sizeof_union(struct packed_git *p1, struct packed_git *p2)
c283ab21
LS
356{
357 size_t ret = 0;
8c681e07 358 unsigned long p1_off = 0, p2_off = 0, p1_step, p2_step;
42873078 359 const unsigned char *p1_base, *p2_base;
c283ab21 360
42873078
NP
361 p1_base = p1->index_data;
362 p2_base = p2->index_data;
8c681e07
NP
363 p1_base += 256 * 4 + ((p1->index_version < 2) ? 4 : 8);
364 p2_base += 256 * 4 + ((p2->index_version < 2) ? 4 : 8);
365 p1_step = (p1->index_version < 2) ? 24 : 20;
366 p2_step = (p2->index_version < 2) ? 24 : 20;
c283ab21 367
8c681e07
NP
368 while (p1_off < p1->num_objects * p1_step &&
369 p2_off < p2->num_objects * p2_step)
c283ab21 370 {
a89fccd2 371 int cmp = hashcmp(p1_base + p1_off, p2_base + p2_off);
c283ab21
LS
372 /* cmp ~ p1 - p2 */
373 if (cmp == 0) {
374 ret++;
8c681e07
NP
375 p1_off += p1_step;
376 p2_off += p2_step;
c283ab21
LS
377 continue;
378 }
379 if (cmp < 0) { /* p1 has the object, p2 doesn't */
8c681e07 380 p1_off += p1_step;
c283ab21 381 } else { /* p2 has the object, p1 doesn't */
8c681e07 382 p2_off += p2_step;
c283ab21
LS
383 }
384 }
385 return ret;
386}
387
388/* another O(n^2) function ... */
bd22c904 389static size_t get_pack_redundancy(struct pack_list *pl)
c283ab21
LS
390{
391 struct pack_list *subset;
bd22c904 392 size_t ret = 0;
1c3039e8
LS
393
394 if (pl == NULL)
395 return 0;
396
c283ab21 397 while ((subset = pl->next)) {
eeefa7c9 398 while (subset) {
c283ab21
LS
399 ret += sizeof_union(pl->pack, subset->pack);
400 subset = subset->next;
401 }
402 pl = pl->next;
403 }
404 return ret;
405}
406
c4001d92 407static inline off_t pack_set_bytecount(struct pack_list *pl)
c283ab21 408{
c4001d92 409 off_t ret = 0;
c283ab21
LS
410 while (pl) {
411 ret += pl->pack->pack_size;
412 ret += pl->pack->index_size;
413 pl = pl->next;
414 }
415 return ret;
416}
417
bd22c904 418static void minimize(struct pack_list **min)
c283ab21
LS
419{
420 struct pack_list *pl, *unique = NULL,
421 *non_unique = NULL, *min_perm = NULL;
422 struct pll *perm, *perm_all, *perm_ok = NULL, *new_perm;
1c3039e8 423 struct llist *missing;
c4001d92 424 off_t min_perm_size = 0, perm_size;
6d016c9c 425 int n;
c283ab21 426
1c3039e8 427 pl = local_packs;
c283ab21 428 while (pl) {
eeefa7c9 429 if (pl->unique_objects->size)
c283ab21
LS
430 pack_list_insert(&unique, pl);
431 else
432 pack_list_insert(&non_unique, pl);
433 pl = pl->next;
434 }
435 /* find out which objects are missing from the set of unique packs */
436 missing = llist_copy(all_objects);
437 pl = unique;
438 while (pl) {
6d016c9c 439 llist_sorted_difference_inplace(missing, pl->all_objects);
c283ab21
LS
440 pl = pl->next;
441 }
442
1c3039e8 443 /* return if there are no objects missing from the unique set */
c283ab21
LS
444 if (missing->size == 0) {
445 *min = unique;
077a34e0 446 free(missing);
c283ab21
LS
447 return;
448 }
449
450 /* find the permutations which contain all missing objects */
6d016c9c
LS
451 for (n = 1; n <= pack_list_size(non_unique) && !perm_ok; n++) {
452 perm_all = perm = get_permutations(non_unique, n);
453 while (perm) {
454 if (is_superset(perm->pl, missing)) {
455 new_perm = xmalloc(sizeof(struct pll));
456 memcpy(new_perm, perm, sizeof(struct pll));
457 new_perm->next = perm_ok;
458 perm_ok = new_perm;
459 }
460 perm = perm->next;
c283ab21 461 }
6d016c9c
LS
462 if (perm_ok)
463 break;
464 pll_free(perm_all);
c283ab21 465 }
c283ab21 466 if (perm_ok == NULL)
d7530708 467 die("Internal error: No complete sets found!");
c283ab21
LS
468
469 /* find the permutation with the smallest size */
470 perm = perm_ok;
471 while (perm) {
472 perm_size = pack_set_bytecount(perm->pl);
c4001d92 473 if (!min_perm_size || min_perm_size > perm_size) {
c283ab21
LS
474 min_perm_size = perm_size;
475 min_perm = perm->pl;
476 }
477 perm = perm->next;
478 }
479 *min = min_perm;
480 /* add the unique packs to the list */
481 pl = unique;
eeefa7c9 482 while (pl) {
c283ab21
LS
483 pack_list_insert(min, pl);
484 pl = pl->next;
485 }
486}
487
bd22c904 488static void load_all_objects(void)
c283ab21 489{
1c3039e8 490 struct pack_list *pl = local_packs;
c283ab21 491 struct llist_item *hint, *l;
c283ab21
LS
492
493 llist_init(&all_objects);
494
495 while (pl) {
c283ab21
LS
496 hint = NULL;
497 l = pl->all_objects->front;
498 while (l) {
499 hint = llist_insert_sorted_unique(all_objects,
500 l->sha1, hint);
501 l = l->next;
502 }
503 pl = pl->next;
504 }
1c3039e8
LS
505 /* remove objects present in remote packs */
506 pl = altodb_packs;
507 while (pl) {
508 llist_sorted_difference_inplace(all_objects, pl->all_objects);
509 pl = pl->next;
510 }
c283ab21
LS
511}
512
513/* this scales like O(n^2) */
bd22c904 514static void cmp_local_packs(void)
c283ab21 515{
1c3039e8 516 struct pack_list *subset, *pl = local_packs;
c283ab21 517
1c3039e8 518 while ((subset = pl)) {
eeefa7c9 519 while ((subset = subset->next))
1c3039e8
LS
520 cmp_two_packs(pl, subset);
521 pl = pl->next;
522 }
06a45c8c 523}
1c3039e8 524
bd22c904 525static void scan_alt_odb_packs(void)
06a45c8c
LS
526{
527 struct pack_list *local, *alt;
528
529 alt = altodb_packs;
530 while (alt) {
531 local = local_packs;
532 while (local) {
533 llist_sorted_difference_inplace(local->unique_objects,
534 alt->all_objects);
535 local = local->next;
1c3039e8 536 }
6d016c9c 537 llist_sorted_difference_inplace(all_objects, alt->all_objects);
06a45c8c 538 alt = alt->next;
c283ab21
LS
539 }
540}
541
bd22c904 542static struct pack_list * add_pack(struct packed_git *p)
c283ab21
LS
543{
544 struct pack_list l;
8c681e07 545 unsigned long off = 0, step;
42873078 546 const unsigned char *base;
c283ab21 547
06a45c8c
LS
548 if (!p->pack_local && !(alt_odb || verbose))
549 return NULL;
550
c283ab21
LS
551 l.pack = p;
552 llist_init(&l.all_objects);
553
eaa86770 554 if (open_pack_index(p))
d079837e
SP
555 return NULL;
556
42873078 557 base = p->index_data;
8c681e07
NP
558 base += 256 * 4 + ((p->index_version < 2) ? 4 : 8);
559 step = (p->index_version < 2) ? 24 : 20;
560 while (off < p->num_objects * step) {
c283ab21 561 llist_insert_back(l.all_objects, base + off);
8c681e07 562 off += step;
c283ab21
LS
563 }
564 /* this list will be pruned in cmp_two_packs later */
565 l.unique_objects = llist_copy(l.all_objects);
1c3039e8
LS
566 if (p->pack_local)
567 return pack_list_insert(&local_packs, &l);
568 else
06a45c8c 569 return pack_list_insert(&altodb_packs, &l);
c283ab21
LS
570}
571
377d0276 572static struct pack_list * add_pack_file(const char *filename)
c283ab21
LS
573{
574 struct packed_git *p = packed_git;
575
576 if (strlen(filename) < 40)
d7530708 577 die("Bad pack filename: %s", filename);
c283ab21
LS
578
579 while (p) {
580 if (strstr(p->pack_name, filename))
c283ab21
LS
581 return add_pack(p);
582 p = p->next;
583 }
d7530708 584 die("Filename %s not found in packed_git", filename);
c283ab21
LS
585}
586
bd22c904 587static void load_all(void)
c283ab21
LS
588{
589 struct packed_git *p = packed_git;
590
591 while (p) {
1c3039e8 592 add_pack(p);
c283ab21
LS
593 p = p->next;
594 }
595}
596
377d0276 597int cmd_pack_redundant(int argc, const char **argv, const char *prefix)
c283ab21
LS
598{
599 int i;
600 struct pack_list *min, *red, *pl;
bb931cf9 601 struct llist *ignore;
b99a394c
JH
602 unsigned char *sha1;
603 char buf[42]; /* 40 byte sha1 + \n + \0 */
c283ab21 604
99caeed0
JN
605 if (argc == 2 && !strcmp(argv[1], "-h"))
606 usage(pack_redundant_usage);
607
c283ab21
LS
608 for (i = 1; i < argc; i++) {
609 const char *arg = argv[i];
eeefa7c9 610 if (!strcmp(arg, "--")) {
9bc0f32c 611 i++;
c283ab21 612 break;
9bc0f32c 613 }
eeefa7c9 614 if (!strcmp(arg, "--all")) {
1c3039e8 615 load_all_packs = 1;
c283ab21
LS
616 continue;
617 }
eeefa7c9 618 if (!strcmp(arg, "--verbose")) {
c283ab21
LS
619 verbose = 1;
620 continue;
621 }
eeefa7c9 622 if (!strcmp(arg, "--alt-odb")) {
1c3039e8
LS
623 alt_odb = 1;
624 continue;
625 }
eeefa7c9 626 if (*arg == '-')
9bc0f32c 627 usage(pack_redundant_usage);
c283ab21
LS
628 else
629 break;
630 }
631
632 prepare_packed_git();
633
1c3039e8 634 if (load_all_packs)
c283ab21
LS
635 load_all();
636 else
637 while (*(argv + i) != NULL)
638 add_pack_file(*(argv + i++));
639
1c3039e8 640 if (local_packs == NULL)
d7530708 641 die("Zero packs found!");
c283ab21 642
c283ab21
LS
643 load_all_objects();
644
06a45c8c
LS
645 cmp_local_packs();
646 if (alt_odb)
647 scan_alt_odb_packs();
648
bb931cf9
LS
649 /* ignore objects given on stdin */
650 llist_init(&ignore);
651 if (!isatty(0)) {
652 while (fgets(buf, sizeof(buf), stdin)) {
653 sha1 = xmalloc(20);
654 if (get_sha1_hex(buf, sha1))
655 die("Bad sha1 on stdin: %s", buf);
656 llist_insert_sorted_unique(ignore, sha1, NULL);
657 }
658 }
659 llist_sorted_difference_inplace(all_objects, ignore);
660 pl = local_packs;
661 while (pl) {
662 llist_sorted_difference_inplace(pl->unique_objects, ignore);
663 pl = pl->next;
664 }
665
c283ab21 666 minimize(&min);
06a45c8c 667
c283ab21 668 if (verbose) {
abacbe41
KR
669 fprintf(stderr, "There are %lu packs available in alt-odbs.\n",
670 (unsigned long)pack_list_size(altodb_packs));
c283ab21
LS
671 fprintf(stderr, "The smallest (bytewise) set of packs is:\n");
672 pl = min;
673 while (pl) {
674 fprintf(stderr, "\t%s\n", pl->pack->pack_name);
675 pl = pl->next;
676 }
abacbe41
KR
677 fprintf(stderr, "containing %lu duplicate objects "
678 "with a total size of %lukb.\n",
679 (unsigned long)get_pack_redundancy(min),
680 (unsigned long)pack_set_bytecount(min)/1024);
681 fprintf(stderr, "A total of %lu unique objects were considered.\n",
682 (unsigned long)all_objects->size);
c283ab21
LS
683 fprintf(stderr, "Redundant packs (with indexes):\n");
684 }
1c3039e8 685 pl = red = pack_list_difference(local_packs, min);
c283ab21
LS
686 while (pl) {
687 printf("%s\n%s\n",
1c3039e8
LS
688 sha1_pack_index_name(pl->pack->sha1),
689 pl->pack->pack_name);
c283ab21
LS
690 pl = pl->next;
691 }
bb931cf9 692 if (verbose)
b99a394c
JH
693 fprintf(stderr, "%luMB of redundant packs in total.\n",
694 (unsigned long)pack_set_bytecount(red)/(1024*1024));
c283ab21
LS
695
696 return 0;
697}