Add git-pack-intersect
Subsystems (2)
cover Add git-pack-intersect
This patch series adds git-pack-intersect. It finds redundant packs by calculating the union of all objects present in .git/objects/pack and then computing the smallest set of packs which contain all the objects in this union.
It is quite fast, if I may say so myself. On my AMD3200+ it manages to minimize a linux-2.6 repository with 9 pack files totaling 430MB in ~0.7 seconds. The remaining packfiles total 102MB, which is a nice reduction.
git-fsck-objects reports no errors after pruning, but the algorithm is not proven correct so backups might be in order before this gets more testing.
/Lukas
Dear diary, on Wed, Nov 09, 2005 at 02:20:59AM CET, I got a letter where Lukas Sandström <[email protected]> said that...
Quoted 4 lines
This patch series adds git-pack-intersect. It finds redundant packs by calculating the union of all objects present in .git/objects/pack and then computing the smallest set of packs which contain all the objects in this union.
Sounds nice, except the name - it does something else than what the name says, so perhaps something like 'git-pack-redundant' would be more appropriate.
Signature · 4 lines
Petr "Pasky" Baudis Stuff: http://pasky.or.cz/ VI has two modes: the one in which it beeps and the one in which it doesn't.
Quoted 9 lines · Petr Baudis
Dear diary, on Wed, Nov 09, 2005 at 02:20:59AM CET, I got a letter where Lukas Sandström <[email protected]> said that...
Quoted 4 lines
This patch series adds git-pack-intersect. It finds redundant packs by calculating the union of all objects present in .git/objects/pack and then computing the smallest set of packs which contain all the objects in this union.
Quoted 4 lines
Sounds nice, except the name - it does something else than what the name says, so perhaps something like 'git-pack-redundant' would be more appropriate.
It would be better if it was in git-prune or a default action for git-repack. I can't imagine a scenario where keeping redundant packfiles is useful.
Signature · 3 lines
Andreas Ericsson [email protected] OP5 AB www.op5.se Tel: +46 8-230225 Fax: +46 8-230231
Quoted 4 lines · Andreas Ericsson
It would be better if it was in git-prune or a default action for git-repack. I can't imagine a scenario where keeping redundant packfiles is useful.
Perhaps if git-daemon ever does caching of packfiles, removing the smaller packfiles might not be optimal.
Integrating it with git-prune sounds like a good idea though, I'll look in to it.
/Lukas
Quoted 2 lines · Lukas Sandstr.ANvm
Perhaps if git-daemon ever does caching of packfiles, removing the smaller packfiles might not be optimal.
Ah, that reminds me of something.
I did not advertise it too much, but you can put a prepackaged packs in $GIT_DIR/pack-cache/ and it is used when upload-pack notices it is creating that exact pack.
This is useless for ordinary repository, but can be useful for historical repositories whose heads/tags never change (e.g. the Linux kernel repository resurrected from bkcvs). There you could:
$ git repack -a -d $ ln $GIT_DIR/objects/pack/pack-* $GIT_DIR/pack-cache/.
and a clone request would feed the pack, without regenerating the pack data from scratch. upload-pack still reads, sorts and computes SHA1 hash of the list of objects to find the pack name, but that is a fairly quick operation, compared to the rest of the pack generation process.
PATCH 1/1 Rename git-pack-intersect to git-pack-redundant
In reply to Petr BaudisQuoted 9 lines · Petr Baudis
Dear diary, on Wed, Nov 09, 2005 at 02:20:59AM CET, I got a letter where Lukas Sandström <[email protected]> said that...
Quoted 4 lines
This patch series adds git-pack-intersect. It finds redundant packs by calculating the union of all objects present in .git/objects/pack and then computing the smallest set of packs which contain all the objects in this union.
Quoted 4 lines
Sounds nice, except the name - it does something else than what the name says, so perhaps something like 'git-pack-redundant' would be more appropriate.
Yes, it would. git-pack-intersect is a working name from before I knew what the program would actually do. In the beginning it just computed the intersection of two pack-files...
/Lukas Sandström
-- >8 -- cut here -- >8 --
Subject: [PATCH] Rename git-pack-intersect to git-pack-redundant
This patch renames git-pack-intersect to git-pack-redundant as suggested by Petr Baudis. The new name reflects what the program does, rather than how it does it.
Also fix a small argument parsing bug.
---
.gitignore | 2 +-
Documentation/git-pack-redundant.txt | 6 +++---
Makefile | 2 +-
git-repack.sh | 4 ++--
pack-redundant.c | 10 ++++++----
5 files changed, 13 insertions(+), 11 deletions(-)
rename Documentation/{git-pack-intersect.txt => git-pack-redundant.txt} (86%)
rename pack-intersect.c => pack-redundant.c (98%)applies-to: 85a2ca124a0579c98df5e6d9158a7ee358aeefef 4db829aa0d1811ccf3505aca232045d7970aec5d
.gitignore +1 -1
@@ -60,7 +60,7 @@ git-mktag git-name-rev git-mv git-octopus -git-pack-intersect +git-pack-redundant git-pack-objects git-parse-remote git-patch-id
Documentation/git-pack-redundant.txt renamed from Documentation/git-pack-intersect.txt +3 -3
@@ -1,14 +1,14 @@ -git-pack-intersect(1) +git-pack-redundant(1) ===================== NAME ---- -git-pack-intersect - Program used to find redundant pack files. +git-pack-redundant - Program used to find redundant pack files. SYNOPSIS -------- -'git-pack-intersect [ -v ] < -a | .pack filename ... >' +'git-pack-redundant [ -v ] < -a | .pack filename ... >' DESCRIPTION -----------
Makefile +1 -1
@@ -122,7 +122,7 @@ PROGRAMS = \ git-unpack-objects$X git-update-index$X git-update-server-info$X \ git-upload-pack$X git-verify-pack$X git-write-tree$X \ git-update-ref$X git-symbolic-ref$X git-check-ref-format$X \ - git-name-rev$X git-pack-intersect$X $(SIMPLE_PROGRAMS) + git-name-rev$X git-pack-redundant$X $(SIMPLE_PROGRAMS) # Backward compatibility -- to be removed after 1.0 PROGRAMS += git-ssh-pull$X git-ssh-push$X
git-repack.sh +2 -2
@@ -45,7 +45,7 @@ if [ -z "$name" ]; then if test "$remove_redandant" = t ; then echo "Removing redundant packs." sync - redundant=$(git-pack-intersect -a) + redundant=$(git-pack-redundant -a) if test "$redundant" != "" ; then echo $redundant | xargs rm fi
@@ -63,7 +63,7 @@ exit if test "$remove_redandant" = t then sync - redundant=$(git-pack-intersect -a) + redundant=$(git-pack-redundant -a) if test "$redundant" != "" ; then echo $redundant | xargs rm fi
pack-redundant.c renamed from pack-intersect.c +6 -4
@@ -8,8 +8,8 @@#include "cache.h" -static const char pack_intersect_usage[] = -"git-pack-intersect [ -v ] < -a | <.pack filename> ...>" ; +static const char pack_redundant_usage[] = +"git-pack-redundant [ -v ] < -a | <.pack filename> ...>" ;int all =0 , verbose =0 ;
@@ -522,8 +522,10 @@ int main(int argc, char **argv)for (i =1 ; i < argc; i++) {const char *arg = argv[i]; -if (!strcmp (arg,"--" )) +if (!strcmp (arg,"--" )) { + i++;break ; + }if (!strcmp (arg,"-a" )) { all =1 ;continue ;
@@ -533,7 +535,7 @@ int main(int argc, char **argv)continue ; }if (*arg =='-' ) -usage (pack_intersect_usage); +usage (pack_redundant_usage);else break ; }
---
0.99.9.GIT
PATCH 1/4 Add git-pack-intersect
In reply to Lukas SandströmAdd git-pack-intersect
This patch adds the program git-pack-intersect. It is used to find redundant packs in git repositories.
---
Makefile | 2 pack-intersect.c | 577 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ sha1_file.c | 3 3 files changed, 581 insertions(+), 1 deletions(-) create mode 100644 pack-intersect.c
applies-to: bb7dd65e1d945edbe0137a761ebc388c7394067a cb2f9b435d8101fd29454b77fb5047b7edf847dc
Makefile +1 -1
@@ -122,7 +122,7 @@ PROGRAMS = \ git-unpack-objects$X git-update-index$X git-update-server-info$X \ git-upload-pack$X git-verify-pack$X git-write-tree$X \ git-update-ref$X git-symbolic-ref$X git-check-ref-format$X \ - git-name-rev$X $(SIMPLE_PROGRAMS) + git-name-rev$X git-pack-intersect$X $(SIMPLE_PROGRAMS) # Backward compatibility -- to be removed after 1.0 PROGRAMS += git-ssh-pull$X git-ssh-push$X
pack-intersect.c new file +577 -0
577 lines not on this page · raw message
sha1_file.c +3 -0
@@ -424,6 +424,7 @@ struct packed_git *add_packed_git(char *struct packed_git *p;unsigned long idx_size;void *idx_map; +char sha1[20 ];if (check_packed_git_idx (path, &idx_size, &idx_map))return NULL ;
@@ -447,6 +448,8 @@ struct packed_git *add_packed_git(char * p->pack_last_used =0 ; p->pack_use_cnt =0 ; p->pack_local = local; +if (!get_sha1_hex (path + path_len -40 -4 , sha1)) +memcpy (p->sha1, sha1,20 );return p; }
---
0.99.9.GIT
PATCH 2/4 Add documentation for git-pack-intersect
In reply to Lukas SandströmAdd documentation for git-pack-intersect
---
Documentation/git-pack-intersect.txt | 47 ++++++++++++++++++++++++++++++++++ 1 files changed, 47 insertions(+), 0 deletions(-) create mode 100644 Documentation/git-pack-intersect.txt
applies-to: 2746df1385345537edc41746b191c67ee98eea20 a1b6ab6c15c3b782478a524a7fd7791ba92960e6
Documentation/git-pack-intersect.txt new file +47 -0
@@ -0,0 +1,47 @@ +git-pack-intersect(1) +===================== + +NAME +---- +git-pack-intersect - Program used to find redundant pack files. + + +SYNOPSIS +-------- +'git-pack-intersect [ -v ] < -a | .pack filename ... >' + +DESCRIPTION +----------- +This program computes which packs in your repository +are redundant. The output is suitable for piping to +'xargs rm' if you are in the root of the repository. + +OPTIONS +------- + +-v:: + Verbose. Outputs some statistics to stderr. + Has a small performance penalty. + +-a:: + All. Processes all the local packs. Any filenames on + the commandline are ignored. + +Author +------ +Written by Lukas Sandström <[email protected]> + +Documentation +-------------- +Documentation by Lukas Sandström <[email protected]> + +See-Also +-------- +gitlink:git-pack-objects[1] +gitlink:git-repack[1] +gitlink:git-prune-packed[1] + +GIT +--- +Part of the gitlink:git[7] suite +
---
0.99.9.GIT
PATCH 3/4 Add git-pack-intersect to .gitignore
In reply to Lukas SandströmAdd git-pack-intersect to .gitignore
---
.gitignore | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
applies-to: f4f7accfd9ee93f528c85bae514334fbc7a70be7 7b8da40e79aa09b43ba4590c6bf8169ed85e4871
.gitignore +1 -0
@@ -60,6 +60,7 @@ git-mktag git-name-rev git-mv git-octopus +git-pack-intersect git-pack-objects git-parse-remote git-patch-id
---
0.99.9.GIT
PATCH 4/4 Make git-repack use git-pack-intersect
In reply to Lukas SandströmMake git-repack use git-pack-intersect.
---
git-repack.sh | 30 ++++++++++++------------------ 1 files changed, 12 insertions(+), 18 deletions(-)
applies-to: 73e05dab832dd7320a5128fbf97e693f23ffb949 2cbd6ade19a768eca47f6f7313f6831226ee58b7
git-repack.sh +12 -18
@@ -32,10 +32,6 @@ case ",$all_into_one," in rev_list= rev_parse='--all' pack_objects= - # This part is a stop-gap until we have proper pack redundancy - # checker. - existing=`cd "$PACKDIR" && \ - find . -type f \( -name '*.pack' -o -name '*.idx' \) -print` ;; esac if [ "$local" ]; then
@@ -46,6 +42,14 @@ name=$(git-rev-list --objects $rev_list exit 1 if [ -z "$name" ]; then echo Nothing new to pack. + if test "$remove_redandant" = t ; then + echo "Removing redundant packs." + sync + redundant=$(git-pack-intersect -a) + if test "$redundant" != "" ; then + echo $redundant | xargs rm + fi + fi exit 0 fi echo "Pack pack-$name created."
@@ -58,20 +62,10 @@ exit if test "$remove_redandant" = t then - # We know $existing are all redandant only when - # all-into-one is used. - if test "$all_into_one" != '' && test "$existing" != '' - then - sync - ( cd "$PACKDIR" && - for e in $existing - do - case "$e" in - ./pack-$name.pack | ./pack-$name.idx) ;; - *) rm -f $e ;; - esac - done - ) + sync + redundant=$(git-pack-intersect -a) + if test "$redundant" != "" ; then + echo $redundant | xargs rm fi fi
---
0.99.9.GIT