summaryrefslogtreecommitdiffstats
path: root/subcmds/start.py
diff options
context:
space:
mode:
Diffstat (limited to 'subcmds/start.py')
-rw-r--r--subcmds/start.py68
1 files changed, 43 insertions, 25 deletions
diff --git a/subcmds/start.py b/subcmds/start.py
index 6ec0b2ce..2addaf2e 100644
--- a/subcmds/start.py
+++ b/subcmds/start.py
@@ -1,5 +1,3 @@
1# -*- coding:utf-8 -*-
2#
3# Copyright (C) 2008 The Android Open Source Project 1# Copyright (C) 2008 The Android Open Source Project
4# 2#
5# Licensed under the Apache License, Version 2.0 (the "License"); 3# Licensed under the Apache License, Version 2.0 (the "License");
@@ -14,19 +12,20 @@
14# See the License for the specific language governing permissions and 12# See the License for the specific language governing permissions and
15# limitations under the License. 13# limitations under the License.
16 14
17from __future__ import print_function 15import functools
18import os 16import os
19import sys 17import sys
20 18
21from command import Command 19from command import Command, DEFAULT_LOCAL_JOBS
22from git_config import IsImmutable 20from git_config import IsImmutable
23from git_command import git 21from git_command import git
24import gitc_utils 22import gitc_utils
25from progress import Progress 23from progress import Progress
26from project import SyncBuffer 24from project import SyncBuffer
27 25
26
28class Start(Command): 27class Start(Command):
29 common = True 28 COMMON = True
30 helpSummary = "Start a new branch for development" 29 helpSummary = "Start a new branch for development"
31 helpUsage = """ 30 helpUsage = """
32%prog <newbranchname> [--all | <project>...] 31%prog <newbranchname> [--all | <project>...]
@@ -35,6 +34,7 @@ class Start(Command):
35'%prog' begins a new branch of development, starting from the 34'%prog' begins a new branch of development, starting from the
36revision specified in the manifest. 35revision specified in the manifest.
37""" 36"""
37 PARALLEL_JOBS = DEFAULT_LOCAL_JOBS
38 38
39 def _Options(self, p): 39 def _Options(self, p):
40 p.add_option('--all', 40 p.add_option('--all',
@@ -42,7 +42,8 @@ revision specified in the manifest.
42 help='begin branch in all projects') 42 help='begin branch in all projects')
43 p.add_option('-r', '--rev', '--revision', dest='revision', 43 p.add_option('-r', '--rev', '--revision', dest='revision',
44 help='point branch at this revision instead of upstream') 44 help='point branch at this revision instead of upstream')
45 p.add_option('--head', dest='revision', action='store_const', const='HEAD', 45 p.add_option('--head', '--HEAD',
46 dest='revision', action='store_const', const='HEAD',
46 help='abbreviation for --rev HEAD') 47 help='abbreviation for --rev HEAD')
47 48
48 def ValidateOptions(self, opt, args): 49 def ValidateOptions(self, opt, args):
@@ -53,6 +54,26 @@ revision specified in the manifest.
53 if not git.check_ref_format('heads/%s' % nb): 54 if not git.check_ref_format('heads/%s' % nb):
54 self.OptionParser.error("'%s' is not a valid name" % nb) 55 self.OptionParser.error("'%s' is not a valid name" % nb)
55 56
57 def _ExecuteOne(self, revision, nb, project):
58 """Start one project."""
59 # If the current revision is immutable, such as a SHA1, a tag or
60 # a change, then we can't push back to it. Substitute with
61 # dest_branch, if defined; or with manifest default revision instead.
62 branch_merge = ''
63 if IsImmutable(project.revisionExpr):
64 if project.dest_branch:
65 branch_merge = project.dest_branch
66 else:
67 branch_merge = self.manifest.default.revisionExpr
68
69 try:
70 ret = project.StartBranch(
71 nb, branch_merge=branch_merge, revision=revision)
72 except Exception as e:
73 print('error: unable to checkout %s: %s' % (project.name, e), file=sys.stderr)
74 ret = False
75 return (ret, project)
76
56 def Execute(self, opt, args): 77 def Execute(self, opt, args):
57 nb = args[0] 78 nb = args[0]
58 err = [] 79 err = []
@@ -60,7 +81,7 @@ revision specified in the manifest.
60 if not opt.all: 81 if not opt.all:
61 projects = args[1:] 82 projects = args[1:]
62 if len(projects) < 1: 83 if len(projects) < 1:
63 projects = ['.',] # start it in the local project by default 84 projects = ['.'] # start it in the local project by default
64 85
65 all_projects = self.GetProjects(projects, 86 all_projects = self.GetProjects(projects,
66 missing_ok=bool(self.gitc_manifest)) 87 missing_ok=bool(self.gitc_manifest))
@@ -84,11 +105,8 @@ revision specified in the manifest.
84 if not os.path.exists(os.getcwd()): 105 if not os.path.exists(os.getcwd()):
85 os.chdir(self.manifest.topdir) 106 os.chdir(self.manifest.topdir)
86 107
87 pm = Progress('Starting %s' % nb, len(all_projects)) 108 pm = Progress('Syncing %s' % nb, len(all_projects), quiet=opt.quiet)
88 for project in all_projects: 109 for project in all_projects:
89 pm.update()
90
91 if self.gitc_manifest:
92 gitc_project = self.gitc_manifest.paths[project.relpath] 110 gitc_project = self.gitc_manifest.paths[project.relpath]
93 # Sync projects that have not been opened. 111 # Sync projects that have not been opened.
94 if not gitc_project.already_synced: 112 if not gitc_project.already_synced:
@@ -101,21 +119,21 @@ revision specified in the manifest.
101 sync_buf = SyncBuffer(self.manifest.manifestProject.config) 119 sync_buf = SyncBuffer(self.manifest.manifestProject.config)
102 project.Sync_LocalHalf(sync_buf) 120 project.Sync_LocalHalf(sync_buf)
103 project.revisionId = gitc_project.old_revision 121 project.revisionId = gitc_project.old_revision
122 pm.update()
123 pm.end()
104 124
105 # If the current revision is immutable, such as a SHA1, a tag or 125 def _ProcessResults(_pool, pm, results):
106 # a change, then we can't push back to it. Substitute with 126 for (result, project) in results:
107 # dest_branch, if defined; or with manifest default revision instead. 127 if not result:
108 branch_merge = '' 128 err.append(project)
109 if IsImmutable(project.revisionExpr): 129 pm.update()
110 if project.dest_branch:
111 branch_merge = project.dest_branch
112 else:
113 branch_merge = self.manifest.default.revisionExpr
114 130
115 if not project.StartBranch( 131 self.ExecuteInParallel(
116 nb, branch_merge=branch_merge, revision=opt.revision): 132 opt.jobs,
117 err.append(project) 133 functools.partial(self._ExecuteOne, opt.revision, nb),
118 pm.end() 134 all_projects,
135 callback=_ProcessResults,
136 output=Progress('Starting %s' % (nb,), len(all_projects), quiet=opt.quiet))
119 137
120 if err: 138 if err:
121 for p in err: 139 for p in err: