diff options
author | James Murty <james@murty.co> | 2014-05-31 21:27:49 +0100 |
---|---|---|
committer | James Murty <james@murty.co> | 2014-05-31 21:27:49 +0100 |
commit | 9b67909e57b2e7a5b1a1f169ac49d920ce900ed7 (patch) | |
tree | 002a9d2c83abc720e89df393d17d33c12af3a3f5 | |
parent | 697b834d6be85196d6ecd29708f8265628a015de (diff) | |
parent | a95c86dbfe0a08d74a4b409d3cd2352f28cdd227 (diff) | |
download | git-fat-9b67909e57b2e7a5b1a1f169ac49d920ce900ed7.tar.gz |
Merge branch 'upstream' into improve_referenced_objects_performance
-rwxr-xr-x | git-fat | 32 | ||||
-rwxr-xr-x | test-retroactive.sh | 9 | ||||
-rwxr-xr-x | test.sh | 24 |
3 files changed, 60 insertions, 5 deletions
@@ -135,6 +135,13 @@ class GitFat(object): self.magiclens = [magiclen(enc) for enc in [self.encode_v1, self.encode_v2]] # All prior versions def setup(self): mkdir_p(self.objdir) + def is_init_done(self): + return gitconfig_get('filter.fat.clean') or gitconfig_get('filter.fat.smudge') + def assert_init_done(self): + if not self.is_init_done(): + sys.stderr.write('fatal: git-fat is not yet configured in this repository.\n') + sys.stderr.write('Run "git fat init" to configure.\n') + sys.exit(1) def get_rsync(self): cfgpath = os.path.join(self.gitroot,'.gitfat') remote = gitconfig_get('rsync.remote', file=cfgpath) @@ -388,6 +395,7 @@ class GitFat(object): sys.exit(p.returncode) def checkout(self, show_orphans=False): 'Update any stale files in the present working tree' + self.assert_init_done() for digest, fname in self.orphan_files(): objpath = os.path.join(self.objdir, digest) if os.access(objpath, os.R_OK): @@ -450,9 +458,27 @@ class GitFat(object): fname = os.path.join(self.objdir, obj) print('%10d %s' % (os.stat(fname).st_size, obj)) os.remove(fname) + + def cmd_verify(self): + """Print details of git-fat objects with incorrect data hash""" + corrupted_objects = [] + for obj in self.catalog_objects(): + fname = os.path.join(self.objdir, obj) + h = hashlib.new('sha1') + for block in readblocks(open(fname)): + h.update(block) + data_hash = h.hexdigest() + if obj != data_hash: + corrupted_objects.append((obj, data_hash)) + if corrupted_objects: + print('Corrupted objects: %d' % len(corrupted_objects)) + for obj, data_hash in corrupted_objects: + print('%s data hash is %s' % (obj, data_hash)) + sys.exit(1) + def cmd_init(self): self.setup() - if gitconfig_get('filter.fat.clean') or gitconfig_get('filter.fat.smudge'): + if self.is_init_done(): print('Git fat already configured, check configuration in .git/config') else: gitconfig_set('filter.fat.clean', 'git-fat filter-clean') @@ -575,6 +601,8 @@ if __name__ == '__main__': fat.cmd_pull(sys.argv[2:]) elif cmd == 'gc': fat.cmd_gc() + elif cmd == 'verify': + fat.cmd_verify() elif cmd == 'checkout': fat.cmd_checkout(sys.argv[2:]) elif cmd == 'find': @@ -582,4 +610,4 @@ if __name__ == '__main__': elif cmd == 'index-filter': fat.cmd_index_filter(sys.argv[2:]) else: - print('Usage: git fat [init|status|push|pull|gc|checkout|find|index-filter]', file=sys.stderr) + print('Usage: git fat [init|status|push|pull|gc|verify|checkout|find|index-filter]', file=sys.stderr) diff --git a/test-retroactive.sh b/test-retroactive.sh index dd02367..51a38ec 100755 --- a/test-retroactive.sh +++ b/test-retroactive.sh @@ -1,8 +1,11 @@ #!/bin/sh -ex +fullpath() { echo "`pwd`/$1"; } + git init retro cd retro cp /usr/share/dict/words words.big +chmod u+w words.big git add words.big git commit -m'Add big file without using git-fat' sort words.big > sorted.big @@ -25,7 +28,7 @@ git commit -am'Import big files into git-fat' git log --stat git fat find 10000 | awk '{print $1}' > fat-files -git filter-branch --index-filter "git fat index-filter $(realpath fat-files) --manage-gitattributes" --tag-name-filter cat -- --all +git filter-branch --index-filter "git fat index-filter $(fullpath fat-files) --manage-gitattributes" --tag-name-filter cat -- --all git log --stat git checkout HEAD^ @@ -37,14 +40,14 @@ ls -al git checkout master cat > .gitfat <<EOF [rsync] -remote = $(realpath ../retro-store) +remote = $(fullpath ../retro-store) EOF git add .gitfat git commit -m'Add .gitfat for local push' git fat push cd .. -git clone file:///$(realpath retro) retro-clone +git clone file:///$(fullpath retro) retro-clone cd retro-clone git fat init git fat pull @@ -2,6 +2,9 @@ # Any copyright is dedicated to the Public Domain. # http://creativecommons.org/publicdomain/zero/1.0/ +# Clear out repos and fat store from prior test runs +rm -fR fat-test fat-test2 /tmp/fat-store + git init fat-test cd fat-test git fat init @@ -29,6 +32,19 @@ git fat push cd .. git clone fat-test fat-test2 cd fat-test2 +# checkout and pull should fail in repo not yet init'ed for git-fat +git fat checkout && true +if [ $? -eq 0 ] +then + echo 'ERROR: "git fat checkout" in uninitialised repo should fail' + exit 1 +fi +git fat pull -- 'a.fa*' && true +if [ $? -eq 0 ] +then + echo 'ERROR: "git fat pull" in uninitialised repo should fail' + exit 1 +fi git fat init git fat pull -- 'a.fa*' cat a.fat @@ -38,3 +54,11 @@ git commit -m'add d with normal content' rm d git fat pull +# Check verify command finds corrupt object +mv .git/fat/objects/6ecec2e21d3033e7ba53e2db63f69dbd3a011fa8 \ + .git/fat/objects/6ecec2e21d3033e7ba53e2db63f69dbd3a011fa8.bak +echo "Not the right data" > .git/fat/objects/6ecec2e21d3033e7ba53e2db63f69dbd3a011fa8 +git fat verify && true +if [ $? -eq 0 ]; then echo "Verify did not detect invalid object"; exit 1; fi +mv .git/fat/objects/6ecec2e21d3033e7ba53e2db63f69dbd3a011fa8.bak \ + .git/fat/objects/6ecec2e21d3033e7ba53e2db63f69dbd3a011fa8 |