@@ -456,48 +456,27 @@ def clone(self, path, **kwargs):
456456 self .git .clone (self .path , path , ** kwargs )
457457 return Repo (path )
458458
459- def archive_tar (self , treeish = 'master' , prefix = None ):
460- """
461- Archive the given treeish
462-
463- ``treeish``
464- is the treeish name/id (default 'master')
465-
466- ``prefix``
467- is the optional prefix to prepend to each filename in the archive
468-
469- Examples::
470-
471- >>> repo.archive_tar
472- <String containing tar archive>
473-
474- >>> repo.archive_tar('a87ff14')
475- <String containing tar archive for commit a87ff14>
476459
477- >>> repo.archive_tar('master', 'myproject/')
478- <String containing tar bytes archive, whose files are prefixed with 'myproject/'>
479-
480- Returns
481- str (containing bytes of tar archive)
460+ def archive (self , ostream , treeish = None , prefix = None , ** kwargs ):
482461 """
483- options = {}
484- if prefix :
485- options ['prefix' ] = prefix
486- return self .git .archive (treeish , ** options )
487-
488- def archive_tar_gz (self , treeish = 'master' , prefix = None ):
489- """
490- Archive and gzip the given treeish
462+ Archive the tree at the given revision.
463+ ``ostream``
464+ file compatible stream object to which the archive will be written
491465
492466 ``treeish``
493- is the treeish name/id (default 'master')
467+ is the treeish name/id, defaults to active branch
494468
495469 ``prefix``
496470 is the optional prefix to prepend to each filename in the archive
471+
472+ ``kwargs``
473+ Additional arguments passed to git-archive
474+ NOTE: Use the 'format' argument to define the kind of format. Use
475+ specialized ostreams to write any format supported by python
497476
498477 Examples::
499478
500- >>> repo.archive_tar_gz
479+ >>> repo.archive(open("archive"
501480 <String containing tar.gz archive>
502481
503482 >>> repo.archive_tar_gz('a87ff14')
@@ -506,18 +485,22 @@ def archive_tar_gz(self, treeish='master', prefix=None):
506485 >>> repo.archive_tar_gz('master', 'myproject/')
507486 <String containing tar.gz archive and prefixed with 'myproject/'>
508487
509- Returns
510- str (containing the bytes of tar.gz archive)
488+ Raise
489+ GitCommandError in case something went wrong
490+
511491 """
512- kwargs = {}
513- if prefix :
492+ if treeish is None :
493+ treeish = self .active_branch
494+ if prefix and 'prefix' not in kwargs :
514495 kwargs ['prefix' ] = prefix
515- resultstr = self .git .archive (treeish , ** kwargs )
516- sio = StringIO .StringIO ()
517- gf = gzip .GzipFile (fileobj = sio , mode = 'wb' )
518- gf .write (resultstr )
519- gf .close ()
520- return sio .getvalue ()
496+ kwargs ['as_process' ] = True
497+ kwargs ['output_stream' ] = ostream
498+
499+ proc = self .git .archive (treeish , ** kwargs )
500+ status = proc .wait ()
501+ if status != 0 :
502+ raise GitCommandError ( "git-archive" , status , proc .stderr .read () )
503+
521504
522505
523506 def __repr__ (self ):
0 commit comments