diff options
Diffstat (limited to 'subcmds')
| -rw-r--r-- | subcmds/help.py | 1 | ||||
| -rw-r--r-- | subcmds/init.py | 76 | ||||
| -rw-r--r-- | subcmds/manifest.py | 81 | ||||
| -rw-r--r-- | subcmds/rebase.py | 2 | ||||
| -rw-r--r-- | subcmds/sync.py | 23 |
5 files changed, 140 insertions, 43 deletions
diff --git a/subcmds/help.py b/subcmds/help.py index 90b817db..e2f3074c 100644 --- a/subcmds/help.py +++ b/subcmds/help.py | |||
| @@ -165,6 +165,7 @@ See 'repo help --all' for a complete list of recognized commands. | |||
| 165 | print >>sys.stderr, "repo: '%s' is not a repo command." % name | 165 | print >>sys.stderr, "repo: '%s' is not a repo command." % name |
| 166 | sys.exit(1) | 166 | sys.exit(1) |
| 167 | 167 | ||
| 168 | cmd.repodir = self.repodir | ||
| 168 | self._PrintCommandHelp(cmd) | 169 | self._PrintCommandHelp(cmd) |
| 169 | 170 | ||
| 170 | else: | 171 | else: |
diff --git a/subcmds/init.py b/subcmds/init.py index 17edfa05..2ca4e163 100644 --- a/subcmds/init.py +++ b/subcmds/init.py | |||
| @@ -21,6 +21,9 @@ from command import InteractiveCommand, MirrorSafeCommand | |||
| 21 | from error import ManifestParseError | 21 | from error import ManifestParseError |
| 22 | from project import SyncBuffer | 22 | from project import SyncBuffer |
| 23 | from git_command import git_require, MIN_GIT_VERSION | 23 | from git_command import git_require, MIN_GIT_VERSION |
| 24 | from manifest_submodule import SubmoduleManifest | ||
| 25 | from manifest_xml import XmlManifest | ||
| 26 | from subcmds.sync import _ReloadManifest | ||
| 24 | 27 | ||
| 25 | class Init(InteractiveCommand, MirrorSafeCommand): | 28 | class Init(InteractiveCommand, MirrorSafeCommand): |
| 26 | common = True | 29 | common = True |
| @@ -72,9 +75,15 @@ to update the working directory files. | |||
| 72 | g.add_option('-b', '--manifest-branch', | 75 | g.add_option('-b', '--manifest-branch', |
| 73 | dest='manifest_branch', | 76 | dest='manifest_branch', |
| 74 | help='manifest branch or revision', metavar='REVISION') | 77 | help='manifest branch or revision', metavar='REVISION') |
| 75 | g.add_option('-m', '--manifest-name', | 78 | g.add_option('-o', '--origin', |
| 76 | dest='manifest_name', default='default.xml', | 79 | dest='manifest_origin', |
| 77 | help='initial manifest file', metavar='NAME.xml') | 80 | help="use REMOTE instead of 'origin' to track upstream", |
| 81 | metavar='REMOTE') | ||
| 82 | if isinstance(self.manifest, XmlManifest) \ | ||
| 83 | or not self.manifest.manifestProject.Exists: | ||
| 84 | g.add_option('-m', '--manifest-name', | ||
| 85 | dest='manifest_name', default='default.xml', | ||
| 86 | help='initial manifest file', metavar='NAME.xml') | ||
| 78 | g.add_option('--mirror', | 87 | g.add_option('--mirror', |
| 79 | dest='mirror', action='store_true', | 88 | dest='mirror', action='store_true', |
| 80 | help='mirror the forrest') | 89 | help='mirror the forrest') |
| @@ -94,30 +103,42 @@ to update the working directory files. | |||
| 94 | dest='no_repo_verify', action='store_true', | 103 | dest='no_repo_verify', action='store_true', |
| 95 | help='do not verify repo source code') | 104 | help='do not verify repo source code') |
| 96 | 105 | ||
| 97 | def _SyncManifest(self, opt): | 106 | def _ApplyOptions(self, opt, is_new): |
| 98 | m = self.manifest.manifestProject | 107 | m = self.manifest.manifestProject |
| 99 | is_new = not m.Exists | ||
| 100 | 108 | ||
| 101 | if is_new: | 109 | if is_new: |
| 102 | if not opt.manifest_url: | 110 | if opt.manifest_origin: |
| 103 | print >>sys.stderr, 'fatal: manifest url (-u) is required.' | 111 | m.remote.name = opt.manifest_origin |
| 104 | sys.exit(1) | ||
| 105 | |||
| 106 | if not opt.quiet: | ||
| 107 | print >>sys.stderr, 'Getting manifest ...' | ||
| 108 | print >>sys.stderr, ' from %s' % opt.manifest_url | ||
| 109 | m._InitGitDir() | ||
| 110 | 112 | ||
| 111 | if opt.manifest_branch: | 113 | if opt.manifest_branch: |
| 112 | m.revisionExpr = opt.manifest_branch | 114 | m.revisionExpr = opt.manifest_branch |
| 113 | else: | 115 | else: |
| 114 | m.revisionExpr = 'refs/heads/master' | 116 | m.revisionExpr = 'refs/heads/master' |
| 115 | else: | 117 | else: |
| 118 | if opt.manifest_origin: | ||
| 119 | print >>sys.stderr, 'fatal: cannot change origin name' | ||
| 120 | sys.exit(1) | ||
| 121 | |||
| 116 | if opt.manifest_branch: | 122 | if opt.manifest_branch: |
| 117 | m.revisionExpr = opt.manifest_branch | 123 | m.revisionExpr = opt.manifest_branch |
| 118 | else: | 124 | else: |
| 119 | m.PreSync() | 125 | m.PreSync() |
| 120 | 126 | ||
| 127 | def _SyncManifest(self, opt): | ||
| 128 | m = self.manifest.manifestProject | ||
| 129 | is_new = not m.Exists | ||
| 130 | |||
| 131 | if is_new: | ||
| 132 | if not opt.manifest_url: | ||
| 133 | print >>sys.stderr, 'fatal: manifest url (-u) is required.' | ||
| 134 | sys.exit(1) | ||
| 135 | |||
| 136 | if not opt.quiet: | ||
| 137 | print >>sys.stderr, 'Getting manifest ...' | ||
| 138 | print >>sys.stderr, ' from %s' % opt.manifest_url | ||
| 139 | m._InitGitDir() | ||
| 140 | |||
| 141 | self._ApplyOptions(opt, is_new) | ||
| 121 | if opt.manifest_url: | 142 | if opt.manifest_url: |
| 122 | r = m.GetRemote(m.remote.name) | 143 | r = m.GetRemote(m.remote.name) |
| 123 | r.url = opt.manifest_url | 144 | r.url = opt.manifest_url |
| @@ -130,6 +151,7 @@ to update the working directory files. | |||
| 130 | if opt.mirror: | 151 | if opt.mirror: |
| 131 | if is_new: | 152 | if is_new: |
| 132 | m.config.SetString('repo.mirror', 'true') | 153 | m.config.SetString('repo.mirror', 'true') |
| 154 | m.config.ClearCache() | ||
| 133 | else: | 155 | else: |
| 134 | print >>sys.stderr, 'fatal: --mirror not supported on existing client' | 156 | print >>sys.stderr, 'fatal: --mirror not supported on existing client' |
| 135 | sys.exit(1) | 157 | sys.exit(1) |
| @@ -139,14 +161,33 @@ to update the working directory files. | |||
| 139 | print >>sys.stderr, 'fatal: cannot obtain manifest %s' % r.url | 161 | print >>sys.stderr, 'fatal: cannot obtain manifest %s' % r.url |
| 140 | sys.exit(1) | 162 | sys.exit(1) |
| 141 | 163 | ||
| 164 | if is_new and SubmoduleManifest.IsBare(m): | ||
| 165 | new = self.GetManifest(reparse=True, type=SubmoduleManifest) | ||
| 166 | if m.gitdir != new.manifestProject.gitdir: | ||
| 167 | os.rename(m.gitdir, new.manifestProject.gitdir) | ||
| 168 | new = self.GetManifest(reparse=True, type=SubmoduleManifest) | ||
| 169 | m = new.manifestProject | ||
| 170 | self._ApplyOptions(opt, is_new) | ||
| 171 | |||
| 172 | if not is_new: | ||
| 173 | # Force the manifest to load if it exists, the old graph | ||
| 174 | # may be needed inside of _ReloadManifest(). | ||
| 175 | # | ||
| 176 | self.manifest.projects | ||
| 177 | |||
| 142 | syncbuf = SyncBuffer(m.config) | 178 | syncbuf = SyncBuffer(m.config) |
| 143 | m.Sync_LocalHalf(syncbuf) | 179 | m.Sync_LocalHalf(syncbuf) |
| 144 | syncbuf.Finish() | 180 | syncbuf.Finish() |
| 145 | 181 | ||
| 146 | if is_new or m.CurrentBranch is None: | 182 | if isinstance(self.manifest, XmlManifest): |
| 147 | if not m.StartBranch('default'): | 183 | self._LinkManifest(opt.manifest_name) |
| 148 | print >>sys.stderr, 'fatal: cannot create default in manifest' | 184 | _ReloadManifest(self) |
| 149 | sys.exit(1) | 185 | |
| 186 | self._ApplyOptions(opt, is_new) | ||
| 187 | |||
| 188 | if not self.manifest.InitBranch(): | ||
| 189 | print >>sys.stderr, 'fatal: cannot create branch in manifest' | ||
| 190 | sys.exit(1) | ||
| 150 | 191 | ||
| 151 | def _LinkManifest(self, name): | 192 | def _LinkManifest(self, name): |
| 152 | if not name: | 193 | if not name: |
| @@ -229,7 +270,6 @@ to update the working directory files. | |||
| 229 | def Execute(self, opt, args): | 270 | def Execute(self, opt, args): |
| 230 | git_require(MIN_GIT_VERSION, fail=True) | 271 | git_require(MIN_GIT_VERSION, fail=True) |
| 231 | self._SyncManifest(opt) | 272 | self._SyncManifest(opt) |
| 232 | self._LinkManifest(opt.manifest_name) | ||
| 233 | 273 | ||
| 234 | if os.isatty(0) and os.isatty(1) and not self.manifest.IsMirror: | 274 | if os.isatty(0) and os.isatty(1) and not self.manifest.IsMirror: |
| 235 | self._ConfigureUser() | 275 | self._ConfigureUser() |
diff --git a/subcmds/manifest.py b/subcmds/manifest.py index 4374a9d0..dcd3df17 100644 --- a/subcmds/manifest.py +++ b/subcmds/manifest.py | |||
| @@ -17,14 +17,25 @@ import os | |||
| 17 | import sys | 17 | import sys |
| 18 | 18 | ||
| 19 | from command import PagedCommand | 19 | from command import PagedCommand |
| 20 | from manifest_submodule import SubmoduleManifest | ||
| 21 | from manifest_xml import XmlManifest | ||
| 22 | |||
| 23 | def _doc(name): | ||
| 24 | r = os.path.dirname(__file__) | ||
| 25 | r = os.path.dirname(r) | ||
| 26 | fd = open(os.path.join(r, 'docs', name)) | ||
| 27 | try: | ||
| 28 | return fd.read() | ||
| 29 | finally: | ||
| 30 | fd.close() | ||
| 20 | 31 | ||
| 21 | class Manifest(PagedCommand): | 32 | class Manifest(PagedCommand): |
| 22 | common = False | 33 | common = False |
| 23 | helpSummary = "Manifest inspection utility" | 34 | helpSummary = "Manifest inspection utility" |
| 24 | helpUsage = """ | 35 | helpUsage = """ |
| 25 | %prog [-o {-|NAME.xml} [-r]] | 36 | %prog [options] |
| 26 | """ | 37 | """ |
| 27 | _helpDescription = """ | 38 | _xmlHelp = """ |
| 28 | 39 | ||
| 29 | With the -o option, exports the current manifest for inspection. | 40 | With the -o option, exports the current manifest for inspection. |
| 30 | The manifest and (if present) local_manifest.xml are combined | 41 | The manifest and (if present) local_manifest.xml are combined |
| @@ -35,23 +46,30 @@ in a Git repository for use during future 'repo init' invocations. | |||
| 35 | 46 | ||
| 36 | @property | 47 | @property |
| 37 | def helpDescription(self): | 48 | def helpDescription(self): |
| 38 | help = self._helpDescription + '\n' | 49 | help = '' |
| 39 | r = os.path.dirname(__file__) | 50 | if isinstance(self.manifest, XmlManifest): |
| 40 | r = os.path.dirname(r) | 51 | help += self._xmlHelp + '\n' + _doc('manifest_xml.txt') |
| 41 | fd = open(os.path.join(r, 'docs', 'manifest-format.txt')) | 52 | if isinstance(self.manifest, SubmoduleManifest): |
| 42 | for line in fd: | 53 | help += _doc('manifest_submodule.txt') |
| 43 | help += line | ||
| 44 | fd.close() | ||
| 45 | return help | 54 | return help |
| 46 | 55 | ||
| 47 | def _Options(self, p): | 56 | def _Options(self, p): |
| 48 | p.add_option('-r', '--revision-as-HEAD', | 57 | if isinstance(self.manifest, XmlManifest): |
| 49 | dest='peg_rev', action='store_true', | 58 | p.add_option('--upgrade', |
| 50 | help='Save revisions as current HEAD') | 59 | dest='upgrade', action='store_true', |
| 51 | p.add_option('-o', '--output-file', | 60 | help='Upgrade XML manifest to submodule') |
| 52 | dest='output_file', | 61 | p.add_option('-r', '--revision-as-HEAD', |
| 53 | help='File to save the manifest to', | 62 | dest='peg_rev', action='store_true', |
| 54 | metavar='-|NAME.xml') | 63 | help='Save revisions as current HEAD') |
| 64 | p.add_option('-o', '--output-file', | ||
| 65 | dest='output_file', | ||
| 66 | help='File to save the manifest to', | ||
| 67 | metavar='-|NAME.xml') | ||
| 68 | |||
| 69 | def WantPager(self, opt): | ||
| 70 | if isinstance(self.manifest, XmlManifest) and opt.upgrade: | ||
| 71 | return False | ||
| 72 | return True | ||
| 55 | 73 | ||
| 56 | def _Output(self, opt): | 74 | def _Output(self, opt): |
| 57 | if opt.output_file == '-': | 75 | if opt.output_file == '-': |
| @@ -64,13 +82,38 @@ in a Git repository for use during future 'repo init' invocations. | |||
| 64 | if opt.output_file != '-': | 82 | if opt.output_file != '-': |
| 65 | print >>sys.stderr, 'Saved manifest to %s' % opt.output_file | 83 | print >>sys.stderr, 'Saved manifest to %s' % opt.output_file |
| 66 | 84 | ||
| 85 | def _Upgrade(self): | ||
| 86 | old = self.manifest | ||
| 87 | |||
| 88 | if isinstance(old, SubmoduleManifest): | ||
| 89 | print >>sys.stderr, 'error: already upgraded' | ||
| 90 | sys.exit(1) | ||
| 91 | |||
| 92 | old._Load() | ||
| 93 | for p in old.projects.values(): | ||
| 94 | if not os.path.exists(p.gitdir) \ | ||
| 95 | or not os.path.exists(p.worktree): | ||
| 96 | print >>sys.stderr, 'fatal: project "%s" missing' % p.relpath | ||
| 97 | sys.exit(1) | ||
| 98 | |||
| 99 | new = SubmoduleManifest(old.repodir) | ||
| 100 | new.FromXml_Local_1(old, checkout=False) | ||
| 101 | new.FromXml_Definition(old) | ||
| 102 | new.FromXml_Local_2(old) | ||
| 103 | print >>sys.stderr, 'upgraded manifest; commit result manually' | ||
| 104 | |||
| 67 | def Execute(self, opt, args): | 105 | def Execute(self, opt, args): |
| 68 | if args: | 106 | if args: |
| 69 | self.Usage() | 107 | self.Usage() |
| 70 | 108 | ||
| 71 | if opt.output_file is not None: | 109 | if isinstance(self.manifest, XmlManifest): |
| 72 | self._Output(opt) | 110 | if opt.upgrade: |
| 73 | return | 111 | self._Upgrade() |
| 112 | return | ||
| 113 | |||
| 114 | if opt.output_file is not None: | ||
| 115 | self._Output(opt) | ||
| 116 | return | ||
| 74 | 117 | ||
| 75 | print >>sys.stderr, 'error: no operation to perform' | 118 | print >>sys.stderr, 'error: no operation to perform' |
| 76 | print >>sys.stderr, 'error: see repo help manifest' | 119 | print >>sys.stderr, 'error: see repo help manifest' |
diff --git a/subcmds/rebase.py b/subcmds/rebase.py index 7c8e9389..e341296d 100644 --- a/subcmds/rebase.py +++ b/subcmds/rebase.py | |||
| @@ -17,7 +17,7 @@ import sys | |||
| 17 | 17 | ||
| 18 | from command import Command | 18 | from command import Command |
| 19 | from git_command import GitCommand | 19 | from git_command import GitCommand |
| 20 | from git_refs import GitRefs, HEAD, R_HEADS, R_TAGS, R_PUB, R_M | 20 | from git_refs import GitRefs, HEAD, R_HEADS, R_TAGS, R_PUB |
| 21 | from error import GitError | 21 | from error import GitError |
| 22 | 22 | ||
| 23 | class Rebase(Command): | 23 | class Rebase(Command): |
diff --git a/subcmds/sync.py b/subcmds/sync.py index 36ef16db..16f1d189 100644 --- a/subcmds/sync.py +++ b/subcmds/sync.py | |||
| @@ -336,7 +336,14 @@ uncommitted changes are present' % project.relpath | |||
| 336 | # bail out now; the rest touches the working tree | 336 | # bail out now; the rest touches the working tree |
| 337 | return | 337 | return |
| 338 | 338 | ||
| 339 | self.manifest._Unload() | 339 | if mp.HasChanges: |
| 340 | syncbuf = SyncBuffer(mp.config) | ||
| 341 | mp.Sync_LocalHalf(syncbuf) | ||
| 342 | if not syncbuf.Finish(): | ||
| 343 | sys.exit(1) | ||
| 344 | _ReloadManifest(self) | ||
| 345 | mp = self.manifest.manifestProject | ||
| 346 | |||
| 340 | all = self.GetProjects(args, missing_ok=True) | 347 | all = self.GetProjects(args, missing_ok=True) |
| 341 | missing = [] | 348 | missing = [] |
| 342 | for project in all: | 349 | for project in all: |
| @@ -363,10 +370,16 @@ uncommitted changes are present' % project.relpath | |||
| 363 | if not syncbuf.Finish(): | 370 | if not syncbuf.Finish(): |
| 364 | sys.exit(1) | 371 | sys.exit(1) |
| 365 | 372 | ||
| 366 | # If there's a notice that's supposed to print at the end of the sync, print | 373 | def _ReloadManifest(cmd): |
| 367 | # it now... | 374 | old = cmd.manifest |
| 368 | if self.manifest.notice: | 375 | new = cmd.GetManifest(reparse=True) |
| 369 | print self.manifest.notice | 376 | |
| 377 | if old.__class__ != new.__class__: | ||
| 378 | print >>sys.stderr, 'NOTICE: manifest format has changed ***' | ||
| 379 | new.Upgrade_Local(old) | ||
| 380 | else: | ||
| 381 | if new.notice: | ||
| 382 | print new.notice | ||
| 370 | 383 | ||
| 371 | def _PostRepoUpgrade(manifest): | 384 | def _PostRepoUpgrade(manifest): |
| 372 | for project in manifest.projects.values(): | 385 | for project in manifest.projects.values(): |
