summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorConley Owens <cco3@android.com>2013-12-18 17:44:58 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2013-12-18 17:44:59 +0000
commitf045d49a71b64b854589c8821d8bf220c6ed9fd3 (patch)
treeb4facc31b41327b5478b12e9213b4f4179ebb171
parent53d6a7b8955e9377cc0a12206be357e7936621b1 (diff)
parent335f5ef4ad25a85c69fe6d8c848c5d1d447e22c8 (diff)
downloadgit-repo-f045d49a71b64b854589c8821d8bf220c6ed9fd3.tar.gz
Merge "Add --archive option to init to sync using git archive"
-rw-r--r--manifest_xml.py4
-rw-r--r--project.py63
-rwxr-xr-xrepo4
-rw-r--r--subcmds/init.py21
-rw-r--r--subcmds/sync.py11
5 files changed, 98 insertions, 5 deletions
diff --git a/manifest_xml.py b/manifest_xml.py
index 457d5ab0..785976bc 100644
--- a/manifest_xml.py
+++ b/manifest_xml.py
@@ -329,6 +329,10 @@ class XmlManifest(object):
329 def IsMirror(self): 329 def IsMirror(self):
330 return self.manifestProject.config.GetBoolean('repo.mirror') 330 return self.manifestProject.config.GetBoolean('repo.mirror')
331 331
332 @property
333 def IsArchive(self):
334 return self.manifestProject.config.GetBoolean('repo.archive')
335
332 def _Unload(self): 336 def _Unload(self):
333 self._loaded = False 337 self._loaded = False
334 self._projects = {} 338 self._projects = {}
diff --git a/project.py b/project.py
index b01a52ba..0d491119 100644
--- a/project.py
+++ b/project.py
@@ -23,6 +23,7 @@ import shutil
23import stat 23import stat
24import subprocess 24import subprocess
25import sys 25import sys
26import tarfile
26import tempfile 27import tempfile
27import time 28import time
28 29
@@ -982,15 +983,62 @@ class Project(object):
982 983
983## Sync ## 984## Sync ##
984 985
986 def _ExtractArchive(self, tarpath, path=None):
987 """Extract the given tar on its current location
988
989 Args:
990 - tarpath: The path to the actual tar file
991
992 """
993 try:
994 with tarfile.open(tarpath, 'r') as tar:
995 tar.extractall(path=path)
996 return True
997 except (IOError, tarfile.TarError) as e:
998 print("error: Cannot extract archive %s: "
999 "%s" % (tarpath, str(e)), file=sys.stderr)
1000 return False
1001
985 def Sync_NetworkHalf(self, 1002 def Sync_NetworkHalf(self,
986 quiet=False, 1003 quiet=False,
987 is_new=None, 1004 is_new=None,
988 current_branch_only=False, 1005 current_branch_only=False,
989 clone_bundle=True, 1006 clone_bundle=True,
990 no_tags=False): 1007 no_tags=False,
1008 archive=False):
991 """Perform only the network IO portion of the sync process. 1009 """Perform only the network IO portion of the sync process.
992 Local working directory/branch state is not affected. 1010 Local working directory/branch state is not affected.
993 """ 1011 """
1012 if archive and not isinstance(self, MetaProject):
1013 if self.remote.url.startswith(('http://', 'https://')):
1014 print("error: %s: Cannot fetch archives from http/https "
1015 "remotes." % self.name, file=sys.stderr)
1016 return False
1017
1018 name = self.relpath.replace('\\', '/')
1019 name = name.replace('/', '_')
1020 tarpath = '%s.tar' % name
1021 topdir = self.manifest.topdir
1022
1023 try:
1024 self._FetchArchive(tarpath, cwd=topdir)
1025 except GitError as e:
1026 print('error: %s' % str(e), file=sys.stderr)
1027 return False
1028
1029 # From now on, we only need absolute tarpath
1030 tarpath = os.path.join(topdir, tarpath)
1031
1032 if not self._ExtractArchive(tarpath, path=topdir):
1033 return False
1034 try:
1035 os.remove(tarpath)
1036 except OSError as e:
1037 print("warn: Cannot remove archive %s: "
1038 "%s" % (tarpath, str(e)), file=sys.stderr)
1039 self._CopyFiles()
1040 return True
1041
994 if is_new is None: 1042 if is_new is None:
995 is_new = not self.Exists 1043 is_new = not self.Exists
996 if is_new: 1044 if is_new:
@@ -1573,6 +1621,19 @@ class Project(object):
1573 1621
1574## Direct Git Commands ## 1622## Direct Git Commands ##
1575 1623
1624 def _FetchArchive(self, tarpath, cwd=None):
1625 cmd = ['archive', '-v', '-o', tarpath]
1626 cmd.append('--remote=%s' % self.remote.url)
1627 cmd.append('--prefix=%s/' % self.relpath)
1628 cmd.append(self.revisionExpr)
1629
1630 command = GitCommand(self, cmd, cwd=cwd,
1631 capture_stdout=True,
1632 capture_stderr=True)
1633
1634 if command.Wait() != 0:
1635 raise GitError('git archive %s: %s' % (self.name, command.stderr))
1636
1576 def _RemoteFetch(self, name=None, 1637 def _RemoteFetch(self, name=None,
1577 current_branch_only=False, 1638 current_branch_only=False,
1578 initial=False, 1639 initial=False,
diff --git a/repo b/repo
index 277bbc6e..d81cdd60 100755
--- a/repo
+++ b/repo
@@ -180,6 +180,10 @@ group.add_option('--reference',
180group.add_option('--depth', type='int', default=None, 180group.add_option('--depth', type='int', default=None,
181 dest='depth', 181 dest='depth',
182 help='create a shallow clone with given depth; see git clone') 182 help='create a shallow clone with given depth; see git clone')
183group.add_option('--archive',
184 dest='archive', action='store_true',
185 help='checkout an archive instead of a git repository for '
186 'each project. See git archive.')
183group.add_option('-g', '--groups', 187group.add_option('-g', '--groups',
184 dest='groups', default='default', 188 dest='groups', default='default',
185 help='restrict manifest projects to ones with specified ' 189 help='restrict manifest projects to ones with specified '
diff --git a/subcmds/init.py b/subcmds/init.py
index a44fb7a9..b1fcb69c 100644
--- a/subcmds/init.py
+++ b/subcmds/init.py
@@ -99,6 +99,10 @@ to update the working directory files.
99 g.add_option('--depth', type='int', default=None, 99 g.add_option('--depth', type='int', default=None,
100 dest='depth', 100 dest='depth',
101 help='create a shallow clone with given depth; see git clone') 101 help='create a shallow clone with given depth; see git clone')
102 g.add_option('--archive',
103 dest='archive', action='store_true',
104 help='checkout an archive instead of a git repository for '
105 'each project. See git archive.')
102 g.add_option('-g', '--groups', 106 g.add_option('-g', '--groups',
103 dest='groups', default='default', 107 dest='groups', default='default',
104 help='restrict manifest projects to ones with specified ' 108 help='restrict manifest projects to ones with specified '
@@ -198,6 +202,16 @@ to update the working directory files.
198 if opt.reference: 202 if opt.reference:
199 m.config.SetString('repo.reference', opt.reference) 203 m.config.SetString('repo.reference', opt.reference)
200 204
205 if opt.archive:
206 if is_new:
207 m.config.SetString('repo.archive', 'true')
208 else:
209 print('fatal: --archive is only supported when initializing a new '
210 'workspace.', file=sys.stderr)
211 print('Either delete the .repo folder in this workspace, or initialize '
212 'in another location.', file=sys.stderr)
213 sys.exit(1)
214
201 if opt.mirror: 215 if opt.mirror:
202 if is_new: 216 if is_new:
203 m.config.SetString('repo.mirror', 'true') 217 m.config.SetString('repo.mirror', 'true')
@@ -366,6 +380,13 @@ to update the working directory files.
366 if opt.reference: 380 if opt.reference:
367 opt.reference = os.path.expanduser(opt.reference) 381 opt.reference = os.path.expanduser(opt.reference)
368 382
383 # Check this here, else manifest will be tagged "not new" and init won't be
384 # possible anymore without removing the .repo/manifests directory.
385 if opt.archive and opt.mirror:
386 print('fatal: --mirror and --archive cannot be used together.',
387 file=sys.stderr)
388 sys.exit(1)
389
369 self._SyncManifest(opt) 390 self._SyncManifest(opt)
370 self._LinkManifest(opt.manifest_name) 391 self._LinkManifest(opt.manifest_name)
371 392
diff --git a/subcmds/sync.py b/subcmds/sync.py
index d8aec59b..0279ff60 100644
--- a/subcmds/sync.py
+++ b/subcmds/sync.py
@@ -253,7 +253,7 @@ later is required to fix a server side protocol bug.
253 quiet=opt.quiet, 253 quiet=opt.quiet,
254 current_branch_only=opt.current_branch_only, 254 current_branch_only=opt.current_branch_only,
255 clone_bundle=not opt.no_clone_bundle, 255 clone_bundle=not opt.no_clone_bundle,
256 no_tags=opt.no_tags) 256 no_tags=opt.no_tags, archive=self.manifest.IsArchive)
257 self._fetch_times.Set(project, time.time() - start) 257 self._fetch_times.Set(project, time.time() - start)
258 258
259 # Lock around all the rest of the code, since printing, updating a set 259 # Lock around all the rest of the code, since printing, updating a set
@@ -294,7 +294,8 @@ later is required to fix a server side protocol bug.
294 quiet=opt.quiet, 294 quiet=opt.quiet,
295 current_branch_only=opt.current_branch_only, 295 current_branch_only=opt.current_branch_only,
296 clone_bundle=not opt.no_clone_bundle, 296 clone_bundle=not opt.no_clone_bundle,
297 no_tags=opt.no_tags): 297 no_tags=opt.no_tags,
298 archive=self.manifest.IsArchive):
298 fetched.add(project.gitdir) 299 fetched.add(project.gitdir)
299 else: 300 else:
300 print('error: Cannot fetch %s' % project.name, file=sys.stderr) 301 print('error: Cannot fetch %s' % project.name, file=sys.stderr)
@@ -338,7 +339,9 @@ later is required to fix a server side protocol bug.
338 pm.end() 339 pm.end()
339 self._fetch_times.Save() 340 self._fetch_times.Save()
340 341
341 self._GCProjects(projects) 342 if not self.manifest.IsArchive:
343 self._GCProjects(projects)
344
342 return fetched 345 return fetched
343 346
344 def _GCProjects(self, projects): 347 def _GCProjects(self, projects):
@@ -641,7 +644,7 @@ later is required to fix a server side protocol bug.
641 previously_missing_set = missing_set 644 previously_missing_set = missing_set
642 fetched.update(self._Fetch(missing, opt)) 645 fetched.update(self._Fetch(missing, opt))
643 646
644 if self.manifest.IsMirror: 647 if self.manifest.IsMirror or self.manifest.IsArchive:
645 # bail out now, we have no working tree 648 # bail out now, we have no working tree
646 return 649 return
647 650