Skip to content

Commit 486dfb1

Browse files
committedJan 21, 2013
Naming consistency, factor filter_clean to be callable from Python
1 parent f575923 commit 486dfb1

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed
 

‎git-fat

+16-13
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,7 @@ class GitFat(object):
129129
'''
130130
digest, bytes = self.decode(body, noraise=True)
131131
return digest
132-
def cmd_clean(self):
133-
'''
134-
The clean filter runs when a file is added to the index. It gets the "smudged" (tree)
135-
version of the file on stdin and produces the "clean" (repository) version on stdout.
136-
'''
137-
self.setup()
132+
def filter_clean(self, instream, outstreamclean):
138133
h = hashlib.new('sha1')
139134
bytes = 0
140135
fd, tmpname = tempfile.mkstemp(dir=self.objdir)
@@ -143,13 +138,13 @@ class GitFat(object):
143138
cached = False # changes to True when file is cached
144139
with os.fdopen(fd, 'w') as cache:
145140
outstream = cache
146-
blockiter = readblocks(sys.stdin)
141+
blockiter = readblocks(instream)
147142
firstblock = True
148-
for block in readblocks(sys.stdin):
143+
for block in readblocks(instream):
149144
if firstblock:
150145
if len(block) == self.magiclen and self.decode_clean(block[0:self.magiclen]):
151146
ishanging = True # Working tree version is verbatim from repository (not smudged)
152-
outstream = sys.stdout
147+
outstream = outstreamclean
153148
firstblock = False
154149
h.update(block)
155150
bytes += len(block)
@@ -165,12 +160,20 @@ class GitFat(object):
165160
os.rename(tmpname, objfile)
166161
self.verbose('git-fat filter-clean: caching to %s' % objfile)
167162
cached = True
168-
sys.stdout.write(self.encode(digest, bytes))
163+
outstreamclean.write(self.encode(digest, bytes))
169164
finally:
170165
if not cached:
171166
os.remove(tmpname)
172167

173-
def cmd_smudge(self):
168+
def cmd_filter_clean(self):
169+
'''
170+
The clean filter runs when a file is added to the index. It gets the "smudged" (tree)
171+
version of the file on stdin and produces the "clean" (repository) version on stdout.
172+
'''
173+
self.setup()
174+
self.filter_clean(sys.stdin, sys.stdout)
175+
176+
def cmd_filter_smudge(self):
174177
self.setup()
175178
result, bytes = self.decode_stream(sys.stdin)
176179
if isinstance(result, str): # We got a digest
@@ -309,9 +312,9 @@ if __name__ == '__main__':
309312
fat = GitFat()
310313
cmd = sys.argv[1] if len(sys.argv) > 1 else ''
311314
if cmd == 'filter-clean':
312-
fat.cmd_clean()
315+
fat.cmd_filter_clean()
313316
elif cmd == 'filter-smudge':
314-
fat.cmd_smudge()
317+
fat.cmd_filter_smudge()
315318
elif cmd == 'init':
316319
fat.cmd_init()
317320
elif cmd == 'status':

0 commit comments

Comments
 (0)