Make git-pack-redundant consider alt-odbs
This patch changes git-pack-redundant so that packfiles in alternate object directories also are considered when deciding which objects are redundant. This functionality is controlled by the flag '--alt-odb'. Also convert the other flags to the long form, and update docs and git-repack accordingly. Signed-off-by: Lukas Sandström <lukass@etek.chalmers.se> Signed-off-by: Junio C Hamano <junkio@cox.net>
Lukas_Sandström committed
Nov 11, 2005 at 01:25 UTC
1c3039e8f1eb01766cff976793c8f439095967f6
3 files changed
+106
-62
Documentation/git-pack-redundant.txt
+10
-7
@@ -8,7 +8,7 @@ git-pack-redundant - Program used to find redundant pack files.
8
9
SYNOPSIS
10
--------
11
-'git-pack-redundant [ -v ] < -a | .pack filename ... >'
11
+'git-pack-redundant [ --verbose ] [ --alt-odb ] < --all | .pack filename ... >'
12
13
DESCRIPTION
14
-----------
@@ -19,13 +19,16 @@ are redundant. The output is suitable for piping to
19
OPTIONS
20
-------
21
22
--v::
23
- Verbose. Outputs some statistics to stderr.
24
- Has a small performance penalty.
22
26
--a::
27
- All. Processes all the local packs. Any filenames on
28
- the commandline are ignored.
23
+--all::
24
+ Processes all packs. Any filenames on the commandline are ignored.
25
+
26
+--alt-odb::
27
+ Don't require objects present in packs from alternate object
28
+ directories to be present in local packs.
29
+
30
+--verbose::
31
+ Outputs some statistics to stderr. Has a small performance penalty.
32
33
Author
34
------
git-repack.sh
+2
-2
@@ -45,7 +45,7 @@ if [ -z "$name" ]; then
45
if test "$remove_redandant" = t ; then
46
echo "Removing redundant packs."
47
sync
48
- redundant=$(git-pack-redundant -a)
48
+ redundant=$(git-pack-redundant --all)
49
if test "$redundant" != "" ; then
50
echo $redundant | xargs rm
51
fi
@@ -63,7 +63,7 @@ exit
63
if test "$remove_redandant" = t
64
then
65
sync
66
- redundant=$(git-pack-redundant -a)
66
+ redundant=$(git-pack-redundant --all)
67
if test "$redundant" != "" ; then
68
echo $redundant | xargs rm
69
fi
pack-redundant.c
+94
-53
@@ -9,9 +9,9 @@
9
#include "cache.h"
10
11
static const char pack_redundant_usage[] =
12
-"git-pack-redundant [ -v ] < -a | <.pack filename> ...>";
12
+"git-pack-redundant [ --verbose ] [ --alt-odb ] < --all | <.pack filename> ...>";
13
14
-int all = 0, verbose = 0;
14
+int load_all_packs = 0, verbose = 0, alt_odb = 0;
15
16
struct llist_item {
17
struct llist_item *next;
@@ -21,14 +21,14 @@ struct llist {
21
struct llist_item *front;
22
struct llist_item *back;
23
size_t size;
24
-} *all_objects;
24
+} *all_objects; /* all objects which must be present in local packfiles */
25
26
struct pack_list {
27
struct pack_list *next;
28
struct packed_git *pack;
29
struct llist *unique_objects;
30
struct llist *all_objects;
31
-} *pack_list;
31
+} *local_packs = NULL, *altodb_packs = NULL;
32
33
struct pll {
34
struct pll *next;
@@ -128,32 +128,35 @@ inline struct llist_item * llist_insert_sorted_unique(struct llist *list,
128
}
129
130
/* computes A\B */
131
-struct llist * llist_sorted_difference(struct llist_item *A,
132
- struct llist_item *B)
131
+void llist_sorted_difference_inplace(struct llist *A,
132
+ struct llist *B)
133
{
134
- struct llist *ret;
135
- llist_init(&ret);
134
+ struct llist_item *prev, *a, *b, *x;
135
137
- while (A != NULL && B != NULL) {
138
- int cmp = memcmp(A->sha1, B->sha1, 20);
136
+ prev = a = A->front;
137
+ b = B->front;
138
+
139
+ while (a != NULL && b != NULL) {
140
+ int cmp = memcmp(a->sha1, b->sha1, 20);
141
if (!cmp) {
140
- A = A->next;
141
- B = B->next;
142
- continue;
143
- }
144
- if(cmp > 0) { /* we'll never find this B */
145
- B = B->next;
146
- continue;
147
- }
148
- /* A has the object, B doesn't */
149
- llist_insert_back(ret, A->sha1);
150
- A = A->next;
151
- }
152
- while (A != NULL) {
153
- llist_insert_back(ret, A->sha1);
154
- A = A->next;
142
+ x = a;
143
+ if (a == A->front)
144
+ A->front = a->next;
145
+ a = prev->next = a->next;
146
+
147
+ if (a == NULL) /* end of list */
148
+ A->back = prev;
149
+ A->size--;
150
+ free(x);
151
+ b = b->next;
152
+ } else
153
+ if (cmp > 0)
154
+ b = b->next;
155
+ else {
156
+ prev = a;
157
+ a = a->next;
158
+ }
159
}
156
- return ret;
160
}
161
162
/* returns a pointer to an item in front of sha1 */
@@ -201,6 +204,16 @@ inline struct pack_list * pack_list_insert(struct pack_list **pl,
204
return p;
205
}
206
207
+inline size_t pack_list_size(struct pack_list *pl)
208
+{
209
+ size_t ret = 0;
210
+ while(pl) {
211
+ ret++;
212
+ pl = pl->next;
213
+ }
214
+ return ret;
215
+}
216
+
217
struct pack_list * pack_list_difference(struct pack_list *A,
218
struct pack_list *B)
219
{
@@ -294,15 +307,13 @@ struct pll * get_all_permutations(struct pack_list *list)
307
308
int is_superset(struct pack_list *pl, struct llist *list)
309
{
297
- struct llist *diff, *old;
310
+ struct llist *diff;
311
312
diff = llist_copy(list);
313
314
while (pl) {
302
- old = diff;
303
- diff = llist_sorted_difference(diff->front,
304
- pl->all_objects->front);
305
- llist_free(old);
315
+ llist_sorted_difference_inplace(diff,
316
+ pl->all_objects);
317
if (diff->size == 0) { /* we're done */
318
llist_free(diff);
319
return 1;
@@ -347,6 +358,10 @@ size_t sizeof_union(struct packed_git *p1, struct packed_git *p2)
358
size_t get_pack_redundancy(struct pack_list *pl)
359
{
360
struct pack_list *subset;
361
+
362
+ if (pl == NULL)
363
+ return 0;
364
+
365
size_t ret = 0;
366
while ((subset = pl->next)) {
367
while(subset) {
@@ -374,10 +389,10 @@ void minimize(struct pack_list **min)
389
struct pack_list *pl, *unique = NULL,
390
*non_unique = NULL, *min_perm = NULL;
391
struct pll *perm, *perm_all, *perm_ok = NULL, *new_perm;
377
- struct llist *missing, *old;
392
+ struct llist *missing;
393
size_t min_perm_size = (size_t)-1, perm_size;
394
380
- pl = pack_list;
395
+ pl = local_packs;
396
while (pl) {
397
if(pl->unique_objects->size)
398
pack_list_insert(&unique, pl);
@@ -389,13 +404,12 @@ void minimize(struct pack_list **min)
404
missing = llist_copy(all_objects);
405
pl = unique;
406
while (pl) {
392
- old = missing;
393
- missing = llist_sorted_difference(missing->front,
394
- pl->all_objects->front);
395
- llist_free(old);
407
+ llist_sorted_difference_inplace(missing,
408
+ pl->all_objects);
409
pl = pl->next;
410
}
411
412
+ /* return if there are no objects missing from the unique set */
413
if (missing->size == 0) {
414
*min = unique;
415
return;
@@ -437,7 +451,7 @@ void minimize(struct pack_list **min)
451
452
void load_all_objects()
453
{
440
- struct pack_list *pl = pack_list;
454
+ struct pack_list *pl = local_packs;
455
struct llist_item *hint, *l;
456
int i;
457
@@ -454,17 +468,34 @@ void load_all_objects()
468
}
469
pl = pl->next;
470
}
471
+ /* remove objects present in remote packs */
472
+ pl = altodb_packs;
473
+ while (pl) {
474
+ llist_sorted_difference_inplace(all_objects, pl->all_objects);
475
+ pl = pl->next;
476
+ }
477
}
478
479
/* this scales like O(n^2) */
480
void cmp_packs()
481
{
462
- struct pack_list *subset, *curr = pack_list;
482
+ struct pack_list *subset, *pl = local_packs;
483
464
- while ((subset = curr)) {
484
+ while ((subset = pl)) {
485
while((subset = subset->next))
466
- cmp_two_packs(curr, subset);
467
- curr = curr->next;
486
+ cmp_two_packs(pl, subset);
487
+ pl = pl->next;
488
+ }
489
+
490
+ pl = altodb_packs;
491
+ while (pl) {
492
+ subset = local_packs;
493
+ while (subset) {
494
+ llist_sorted_difference_inplace(subset->unique_objects,
495
+ pl->all_objects);
496
+ subset = subset->next;
497
+ }
498
+ pl = pl->next;
499
}
500
}
501
@@ -485,7 +516,10 @@ struct pack_list * add_pack(struct packed_git *p)
516
}
517
/* this list will be pruned in cmp_two_packs later */
518
l.unique_objects = llist_copy(l.all_objects);
488
- return pack_list_insert(&pack_list, &l);
519
+ if (p->pack_local)
520
+ return pack_list_insert(&local_packs, &l);
521
+ else
522
+ return alt_odb ? pack_list_insert(&altodb_packs, &l) : NULL;
523
}
524
525
struct pack_list * add_pack_file(char *filename)
@@ -497,7 +531,6 @@ struct pack_list * add_pack_file(char *filename)
531
532
while (p) {
533
if (strstr(p->pack_name, filename))
500
- /* this will silently ignore packs in alt-odb */
534
return add_pack(p);
535
p = p->next;
536
}
@@ -509,8 +542,7 @@ void load_all()
542
struct packed_git *p = packed_git;
543
544
while (p) {
512
- if (p->pack_local) /* ignore alt-odb for now */
513
- add_pack(p);
545
+ add_pack(p);
546
p = p->next;
547
}
548
}
@@ -526,14 +558,18 @@ int main(int argc, char **argv)
558
i++;
559
break;
560
}
529
- if(!strcmp(arg, "-a")) {
530
- all = 1;
561
+ if(!strcmp(arg, "--all")) {
562
+ load_all_packs = 1;
563
continue;
564
}
533
- if(!strcmp(arg, "-v")) {
565
+ if(!strcmp(arg, "--verbose")) {
566
verbose = 1;
567
continue;
568
}
569
+ if(!strcmp(arg, "--alt-odb")) {
570
+ alt_odb = 1;
571
+ continue;
572
+ }
573
if(*arg == '-')
574
usage(pack_redundant_usage);
575
else
@@ -542,13 +578,13 @@ int main(int argc, char **argv)
578
579
prepare_packed_git();
580
545
- if(all)
581
+ if (load_all_packs)
582
load_all();
583
else
584
while (*(argv + i) != NULL)
585
add_pack_file(*(argv + i++));
586
551
- if (pack_list == NULL)
587
+ if (local_packs == NULL)
588
die("Zero packs found!\n");
589
590
cmp_packs();
@@ -557,6 +593,8 @@ int main(int argc, char **argv)
593
594
minimize(&min);
595
if (verbose) {
596
+ fprintf(stderr, "There are %ld packs available in alt-odbs.\n",
597
+ pack_list_size(altodb_packs));
598
fprintf(stderr, "The smallest (bytewise) set of packs is:\n");
599
pl = min;
600
while (pl) {
@@ -566,12 +604,15 @@ int main(int argc, char **argv)
604
fprintf(stderr, "containing %ld duplicate objects "
605
"with a total size of %ldkb.\n",
606
get_pack_redundancy(min), pack_set_bytecount(min)/1024);
607
+ fprintf(stderr, "A total of %ld unique objects were considered.\n",
608
+ all_objects->size);
609
fprintf(stderr, "Redundant packs (with indexes):\n");
610
}
571
- pl = red = pack_list_difference(pack_list, min);
611
+ pl = red = pack_list_difference(local_packs, min);
612
while (pl) {
613
printf("%s\n%s\n",
574
- sha1_pack_index_name(pl->pack->sha1), pl->pack->pack_name);
614
+ sha1_pack_index_name(pl->pack->sha1),
615
+ pl->pack->pack_name);
616
pl = pl->next;
617
}
618