Skip to content

Commit f5a5dfc

Browse files
committed
Use "prefix" instead of "root_path" in write_archive
1 parent 3ee1c79 commit f5a5dfc

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

pygit2/repository.py

+6-11
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
# Import from the Standard Library
3232
from string import hexdigits
3333
import sys, tarfile
34-
import os.path
3534
from time import time
3635
if sys.version_info[0] < 3:
3736
from cStringIO import StringIO
@@ -567,15 +566,14 @@ def favor_to_enum(favor):
567566
#
568567
# Utility for writing a tree into an archive
569568
#
570-
def write_archive(self, treeish, archive, timestamp=None, root_path=None):
569+
def write_archive(self, treeish, archive, timestamp=None, prefix=''):
571570
"""Write treeish into an archive
572571
573572
If no timestamp is provided and 'treeish' is a commit, its committer
574573
timestamp will be used. Otherwise the current time will be used.
575574
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.
579577
580578
Arguments:
581579
@@ -585,8 +583,8 @@ def write_archive(self, treeish, archive, timestamp=None, root_path=None):
585583
An archive from the 'tarfile' module
586584
timestamp
587585
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.
590588
591589
Example::
592590
@@ -615,17 +613,14 @@ def write_archive(self, treeish, archive, timestamp=None, root_path=None):
615613
if not timestamp:
616614
timestamp = int(time())
617615

618-
if root_path is None:
619-
root_path = '.'
620-
621616
tree = treeish.peel(Tree)
622617

623618
index = Index()
624619
index.read_tree(tree)
625620

626621
for entry in index:
627622
content = self[entry.id].read_raw()
628-
info = tarfile.TarInfo(os.path.join(root_path, entry.path))
623+
info = tarfile.TarInfo(prefix + entry.path)
629624
info.size = len(content)
630625
info.mtime = timestamp
631626
info.uname = info.gname = 'root' # just because git does this

0 commit comments

Comments
 (0)