Use "prefix" instead of "root_path" in write_archive

This commit is contained in:
Alok Singhal
2015-01-30 10:15:08 -08:00
parent 3ee1c798b2
commit f5a5dfc18a

View File

@@ -31,7 +31,6 @@ from __future__ import absolute_import
# Import from the Standard Library # Import from the Standard Library
from string import hexdigits from string import hexdigits
import sys, tarfile import sys, tarfile
import os.path
from time import time from time import time
if sys.version_info[0] < 3: if sys.version_info[0] < 3:
from cStringIO import StringIO from cStringIO import StringIO
@@ -567,15 +566,14 @@ class Repository(_Repository):
# #
# Utility for writing a tree into an archive # Utility for writing a tree into an archive
# #
def write_archive(self, treeish, archive, timestamp=None, root_path=None): def write_archive(self, treeish, archive, timestamp=None, prefix=''):
"""Write treeish into an archive """Write treeish into an archive
If no timestamp is provided and 'treeish' is a commit, its committer If no timestamp is provided and 'treeish' is a commit, its committer
timestamp will be used. Otherwise the current time will be used. timestamp will be used. Otherwise the current time will be used.
If no root_path is provided, the archive will be created so that All path names in the archive are added to 'prefix', which defaults to
extracting it will create files under root_path, instead of the current an empty string.
directory (equivalent to "tar -C root_path ..." while extracting).
Arguments: Arguments:
@@ -585,8 +583,8 @@ class Repository(_Repository):
An archive from the 'tarfile' module An archive from the 'tarfile' module
timestamp timestamp
Timestamp to use for the files in the archive. Timestamp to use for the files in the archive.
root_path prefix
The path under which all the files will appear in the archive. Extra prefix to add to the path names in the archive.
Example:: Example::
@@ -615,9 +613,6 @@ class Repository(_Repository):
if not timestamp: if not timestamp:
timestamp = int(time()) timestamp = int(time())
if root_path is None:
root_path = '.'
tree = treeish.peel(Tree) tree = treeish.peel(Tree)
index = Index() index = Index()
@@ -625,7 +620,7 @@ class Repository(_Repository):
for entry in index: for entry in index:
content = self[entry.id].read_raw() content = self[entry.id].read_raw()
info = tarfile.TarInfo(os.path.join(root_path, entry.path)) info = tarfile.TarInfo(prefix + entry.path)
info.size = len(content) info.size = len(content)
info.mtime = timestamp info.mtime = timestamp
info.uname = info.gname = 'root' # just because git does this info.uname = info.gname = 'root' # just because git does this