31
31
# Import from the Standard Library
32
32
from string import hexdigits
33
33
import sys , tarfile
34
- import os .path
35
34
from time import time
36
35
if sys .version_info [0 ] < 3 :
37
36
from cStringIO import StringIO
@@ -567,15 +566,14 @@ def favor_to_enum(favor):
567
566
#
568
567
# Utility for writing a tree into an archive
569
568
#
570
- def write_archive (self , treeish , archive , timestamp = None , root_path = None ):
569
+ def write_archive (self , treeish , archive , timestamp = None , prefix = '' ):
571
570
"""Write treeish into an archive
572
571
573
572
If no timestamp is provided and 'treeish' is a commit, its committer
574
573
timestamp will be used. Otherwise the current time will be used.
575
574
576
- If no root_path is provided, the archive will be created so that
577
- extracting it will create files under root_path, instead of the current
578
- directory (equivalent to "tar -C root_path ..." while extracting).
575
+ All path names in the archive are added to 'prefix', which defaults to
576
+ an empty string.
579
577
580
578
Arguments:
581
579
@@ -585,8 +583,8 @@ def write_archive(self, treeish, archive, timestamp=None, root_path=None):
585
583
An archive from the 'tarfile' module
586
584
timestamp
587
585
Timestamp to use for the files in the archive.
588
- root_path
589
- The path under which all the files will appear in the archive.
586
+ prefix
587
+ Extra prefix to add to the path names in the archive.
590
588
591
589
Example::
592
590
@@ -615,17 +613,14 @@ def write_archive(self, treeish, archive, timestamp=None, root_path=None):
615
613
if not timestamp :
616
614
timestamp = int (time ())
617
615
618
- if root_path is None :
619
- root_path = '.'
620
-
621
616
tree = treeish .peel (Tree )
622
617
623
618
index = Index ()
624
619
index .read_tree (tree )
625
620
626
621
for entry in index :
627
622
content = self [entry .id ].read_raw ()
628
- info = tarfile .TarInfo (os . path . join ( root_path , entry .path ) )
623
+ info = tarfile .TarInfo (prefix + entry .path )
629
624
info .size = len (content )
630
625
info .mtime = timestamp
631
626
info .uname = info .gname = 'root' # just because git does this
0 commit comments