Merge remote-tracking branch 'gandalf/archive_enh'
Conflicts: pygit2/repository.py
This commit is contained in:
@@ -566,12 +566,15 @@ 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):
|
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.
|
||||||
|
|
||||||
|
All path names in the archive are added to 'prefix', which defaults to
|
||||||
|
an empty string.
|
||||||
|
|
||||||
Arguments:
|
Arguments:
|
||||||
|
|
||||||
treeish
|
treeish
|
||||||
@@ -580,6 +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.
|
||||||
|
prefix
|
||||||
|
Extra prefix to add to the path names in the archive.
|
||||||
|
|
||||||
Example::
|
Example::
|
||||||
|
|
||||||
@@ -615,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(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
|
||||||
@@ -623,8 +628,10 @@ class Repository(_Repository):
|
|||||||
info.type = archive.SYMTYPE
|
info.type = archive.SYMTYPE
|
||||||
info.linkname = content
|
info.linkname = content
|
||||||
info.mode = 0o777 # symlinks get placeholder
|
info.mode = 0o777 # symlinks get placeholder
|
||||||
|
info.size = 0
|
||||||
archive.addfile(info, StringIO(content))
|
archive.addfile(info)
|
||||||
|
else:
|
||||||
|
archive.addfile(info, StringIO(content))
|
||||||
|
|
||||||
#
|
#
|
||||||
# Ahead-behind, which mostly lives on its own namespace
|
# Ahead-behind, which mostly lives on its own namespace
|
||||||
|
|||||||
Reference in New Issue
Block a user