summaryrefslogtreecommitdiff
path: root/git-fat
diff options
context:
space:
mode:
authorJed Brown <jed@59A2.org>2013-01-21 00:25:29 -0600
committerJed Brown <jed@59A2.org>2013-01-21 00:25:29 -0600
commit486dfb16c1b3e6859ee62b43d1a1e51d38c24b08 (patch)
treede7c1556abe342c6b6dfcd69f628da5b317b3644 /git-fat
parentf5759238e10c64889187214401b24cf028f9d3a6 (diff)
downloadgit-fat-486dfb16c1b3e6859ee62b43d1a1e51d38c24b08.tar.gz
Naming consistency, factor filter_clean to be callable from Python
Diffstat (limited to 'git-fat')
-rwxr-xr-xgit-fat29
1 files changed, 16 insertions, 13 deletions
diff --git a/git-fat b/git-fat
index c1f8ed6..66cc3a8 100755
--- a/git-fat
+++ b/git-fat
@@ -129,12 +129,7 @@ class GitFat(object):
'''
digest, bytes = self.decode(body, noraise=True)
return digest
- def cmd_clean(self):
- '''
- The clean filter runs when a file is added to the index. It gets the "smudged" (tree)
- version of the file on stdin and produces the "clean" (repository) version on stdout.
- '''
- self.setup()
+ def filter_clean(self, instream, outstreamclean):
h = hashlib.new('sha1')
bytes = 0
fd, tmpname = tempfile.mkstemp(dir=self.objdir)
@@ -143,13 +138,13 @@ class GitFat(object):
cached = False # changes to True when file is cached
with os.fdopen(fd, 'w') as cache:
outstream = cache
- blockiter = readblocks(sys.stdin)
+ blockiter = readblocks(instream)
firstblock = True
- for block in readblocks(sys.stdin):
+ for block in readblocks(instream):
if firstblock:
if len(block) == self.magiclen and self.decode_clean(block[0:self.magiclen]):
ishanging = True # Working tree version is verbatim from repository (not smudged)
- outstream = sys.stdout
+ outstream = outstreamclean
firstblock = False
h.update(block)
bytes += len(block)
@@ -165,12 +160,20 @@ class GitFat(object):
os.rename(tmpname, objfile)
self.verbose('git-fat filter-clean: caching to %s' % objfile)
cached = True
- sys.stdout.write(self.encode(digest, bytes))
+ outstreamclean.write(self.encode(digest, bytes))
finally:
if not cached:
os.remove(tmpname)
- def cmd_smudge(self):
+ def cmd_filter_clean(self):
+ '''
+ The clean filter runs when a file is added to the index. It gets the "smudged" (tree)
+ version of the file on stdin and produces the "clean" (repository) version on stdout.
+ '''
+ self.setup()
+ self.filter_clean(sys.stdin, sys.stdout)
+
+ def cmd_filter_smudge(self):
self.setup()
result, bytes = self.decode_stream(sys.stdin)
if isinstance(result, str): # We got a digest
@@ -309,9 +312,9 @@ if __name__ == '__main__':
fat = GitFat()
cmd = sys.argv[1] if len(sys.argv) > 1 else ''
if cmd == 'filter-clean':
- fat.cmd_clean()
+ fat.cmd_filter_clean()
elif cmd == 'filter-smudge':
- fat.cmd_smudge()
+ fat.cmd_filter_smudge()
elif cmd == 'init':
fat.cmd_init()
elif cmd == 'status':