##// END OF EJS Templates
subrepo: archive git subrepos
Eric Eisner -
r13027:7f2ecb64 default
parent child Browse files
Show More
@@ -6,7 +6,7 b''
6 # GNU General Public License version 2 or any later version.
6 # GNU General Public License version 2 or any later version.
7
7
8 import errno, os, re, xml.dom.minidom, shutil, urlparse, posixpath
8 import errno, os, re, xml.dom.minidom, shutil, urlparse, posixpath
9 import stat, subprocess
9 import stat, subprocess, tarfile
10 from i18n import _
10 from i18n import _
11 import config, util, node, error, cmdutil
11 import config, util, node, error, cmdutil
12 hg = None
12 hg = None
@@ -613,15 +613,15 b' class gitsubrepo(object):'
613 self._path = ctx._repo.wjoin(path)
613 self._path = ctx._repo.wjoin(path)
614 self._ui = ctx._repo.ui
614 self._ui = ctx._repo.ui
615
615
616 def _gitcommand(self, commands):
616 def _gitcommand(self, commands, stream=False):
617 return self._gitdir(commands)[0]
617 return self._gitdir(commands, stream=stream)[0]
618
618
619 def _gitdir(self, commands):
619 def _gitdir(self, commands, stream=False):
620 commands = ['--no-pager', '--git-dir=%s/.git' % self._path,
620 commands = ['--no-pager', '--git-dir=%s/.git' % self._path,
621 '--work-tree=%s' % self._path] + commands
621 '--work-tree=%s' % self._path] + commands
622 return self._gitnodir(commands)
622 return self._gitnodir(commands, stream=stream)
623
623
624 def _gitnodir(self, commands):
624 def _gitnodir(self, commands, stream=False):
625 """Calls the git command
625 """Calls the git command
626
626
627 The methods tries to call the git command. versions previor to 1.6.0
627 The methods tries to call the git command. versions previor to 1.6.0
@@ -633,8 +633,11 b' class gitsubrepo(object):'
633
633
634 # print git's stderr, which is mostly progress and useful info
634 # print git's stderr, which is mostly progress and useful info
635 p = subprocess.Popen(cmd, shell=True, bufsize=-1,
635 p = subprocess.Popen(cmd, shell=True, bufsize=-1,
636 close_fds=(os.name == 'posix'),
636 close_fds=util.closefds,
637 stdout=subprocess.PIPE)
637 stdout=subprocess.PIPE)
638 if stream:
639 return p.stdout, None
640
638 retdata = p.stdout.read()
641 retdata = p.stdout.read()
639 # wait for the child to exit to avoid race condition.
642 # wait for the child to exit to avoid race condition.
640 p.wait()
643 p.wait()
@@ -795,6 +798,20 b' class gitsubrepo(object):'
795 else:
798 else:
796 os.remove(path)
799 os.remove(path)
797
800
801 def archive(self, archiver, prefix):
802 source, revision = self._state
803 self._fetch(source, revision)
804
805 # Parse git's native archive command.
806 # This should be much faster than manually traversing the trees
807 # and objects with many subprocess calls.
808 tarstream = self._gitcommand(['archive', revision], stream=True)
809 tar = tarfile.open(fileobj=tarstream, mode='r|')
810 for info in tar:
811 archiver.addfile(os.path.join(prefix, self._relpath, info.name),
812 info.mode, info.issym(),
813 tar.extractfile(info).read())
814
798 types = {
815 types = {
799 'hg': hgsubrepo,
816 'hg': hgsubrepo,
800 'svn': svnsubrepo,
817 'svn': svnsubrepo,
@@ -193,3 +193,17 b' update to a revision without the subrepo'
193 ..
193 ..
194 .git
194 .git
195 g
195 g
196
197 archive subrepos
198
199 $ cd ../t
200 $ hg archive --subrepos -r tip ../archive
201 pulling subrepo s
202 $ cd ../archive
203 $ cat s/f
204 f
205 $ cat s/g
206 g
207 gg
208 ggg
209
General Comments 0
You need to be logged in to leave comments. Login now