git archive cleanup
authorTimo Savola <tsavola@movial.fi>
Sun, 6 Apr 2008 06:56:36 +0000 (09:56 +0300)
committerTimo Savola <tsavola@movial.fi>
Sun, 6 Apr 2008 06:57:12 +0000 (09:57 +0300)
matrix/git.py
matrix/matrix.py

index ec02a13..c3e8fb3 100644 (file)
@@ -172,23 +172,34 @@ def ls_tree(name, treeish, name_only=False, recursive=False):
 def ls_files(name, options):
        return call_output(['ls-files'] + options, workdir=name)
 
-
-def archive(name, arch_name,prefix=None,branch='HEAD'):
-       cmd = ['archive','--format=tar']
+def archive(name, arch_name, prefix=None, treeish='HEAD'):
+       cmd = ['archive', '--format=tar']
        if prefix:
-               cmd.append('--prefix=%s'%prefix)
+               cmd.append('--prefix=%s' % prefix)
+       cmd.append(treeish)
 
-       inp,out = os.pipe()
-       call_output(cmd+[branch],workdir=name,fd=out,wait=False)
+       inp, out = os.pipe()
+       call_output(cmd, workdir=name, fd=out, wait=False)
        os.close(out)
-       infile=os.fdopen(inp)
-       outfile=bz2.BZ2File(arch_name,'w')
-       data=infile.read(1024*50)
-       while data:
-               outfile.write(data)
-               data=infile.read(1024*50)
-       infile.close()
-       outfile.close()
+
+       infile = os.fdopen(inp)
+       outfile = bz2.BZ2File(arch_name, 'w')
+       done = False
+
+       try:
+               while True:
+                       data = infile.read(1024 * 50)
+                       if not data:
+                               break
+                       outfile.write(data)
+
+               done = True
+       finally:
+               infile.close()
+               outfile.close()
+
+               if not done:
+                       os.remove(arch_name)
 
 def describe(name,branch='HEAD'):
        cmd={'args':['describe',branch],'workdir':name}
index a737508..9098cb2 100644 (file)
@@ -489,7 +489,7 @@ def package_component_sources(c, location):
 
        git.archive(c.repo.path, path,
                    prefix=os.path.basename(c.name) + '/',
-                   branch=c.get_active_tag())
+                   treeish=c.get_active_tag())
 
 def build_rootfs(clean=True, rootfs_only=False, jffs2_only=False, devrootfs_only=False):
        parse_config('rootfs')