Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 """Meta checkout manager supporting both Subversion and GIT. | 6 """Meta checkout manager supporting both Subversion and GIT. |
| 7 | 7 |
| 8 Files | 8 Files |
| 9 .gclient : Current client configuration, written by 'config' command. | 9 .gclient : Current client configuration, written by 'config' command. |
| 10 Format is a Python script defining 'solutions', a list whose | 10 Format is a Python script defining 'solutions', a list whose |
| (...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 332 (name, tree[name].hierarchy(), self.hierarchy())) | 332 (name, tree[name].hierarchy(), self.hierarchy())) |
| 333 self.dependencies.append(Dependency(self, name, url, None, None, None, | 333 self.dependencies.append(Dependency(self, name, url, None, None, None, |
| 334 None, should_process)) | 334 None, should_process)) |
| 335 logging.debug('Loaded: %s' % str(self)) | 335 logging.debug('Loaded: %s' % str(self)) |
| 336 | 336 |
| 337 # Arguments number differs from overridden method | 337 # Arguments number differs from overridden method |
| 338 # pylint: disable=W0221 | 338 # pylint: disable=W0221 |
| 339 def run(self, revision_overrides, command, args, work_queue, options): | 339 def run(self, revision_overrides, command, args, work_queue, options): |
| 340 """Runs 'command' before parsing the DEPS in case it's a initial checkout | 340 """Runs 'command' before parsing the DEPS in case it's a initial checkout |
| 341 or a revert.""" | 341 or a revert.""" |
| 342 | |
| 343 def maybeGetParentRevision(options): | |
| 344 """If we are performing an update and --transitive is set, set the | |
| 345 revision to the parent's revision. If we have an explicit revision | |
| 346 do nothing.""" | |
| 347 _, revision = gclient_utils.SplitUrlRevision(self.parsed_url) | |
| 348 if (command == 'update' and | |
| 349 options.transitive and | |
| 350 revision is None and | |
|
M-A Ruel
2011/04/21 23:54:58
style nit: I think you can just do "and revision a
Florian Loitsch
2011/04/26 12:53:06
Done.
| |
| 351 options.revision is None): | |
| 352 options.revision = revision_overrides.get(self.parent.name) | |
| 353 if options.verbose and options.revision is not None: | |
| 354 print("Using parent's revision date: %s" % options.revision) | |
| 355 # If the parent has a revision override, then it must have been | |
| 356 # converted to date format. | |
| 357 assert (options.revision is None or | |
| 358 gclient_utils.IsDateRevision(options.revision)) | |
| 359 | |
| 360 def maybeConvertToDateRevision(options): | |
| 361 """If we are performing an update and --transitive is set, convert the | |
| 362 revision to a date-revision (if necessary). Instead of having | |
| 363 -r 101 replace the revision with the date of 101 (e.g. "{2011-18-04}"). | |
|
M-A Ruel
2011/04/21 23:54:58
s/date/time stamp/
Florian Loitsch
2011/04/26 12:53:06
Done.
| |
| 364 This way dependencies are upgraded to the revision they had at the | |
| 365 check-in of revision 101.""" | |
| 366 if (command == 'update' and | |
| 367 options.transitive and | |
| 368 options.revision is not None and | |
| 369 not gclient_utils.IsDateRevision(options.revision)): | |
| 370 revision_date = scm.GetRevisionDate(options.revision) | |
| 371 revision = gclient_utils.MakeDateRevision(revision_date) | |
| 372 if options.verbose: | |
| 373 print("Updating revision override from %s to %s." % | |
| 374 (options.revision, revision)) | |
| 375 revision_overrides[self.name] = revision | |
| 376 | |
| 342 assert self._file_list == [] | 377 assert self._file_list == [] |
| 343 if not self.should_process: | 378 if not self.should_process: |
| 344 return | 379 return |
| 345 # When running runhooks, there's no need to consult the SCM. | 380 # When running runhooks, there's no need to consult the SCM. |
| 346 # All known hooks are expected to run unconditionally regardless of working | 381 # All known hooks are expected to run unconditionally regardless of working |
| 347 # copy state, so skip the SCM status check. | 382 # copy state, so skip the SCM status check. |
| 348 run_scm = command not in ('runhooks', None) | 383 run_scm = command not in ('runhooks', None) |
| 349 self.parsed_url = self.LateOverride(self.url) | 384 self.parsed_url = self.LateOverride(self.url) |
| 350 if run_scm and self.parsed_url: | 385 if run_scm and self.parsed_url: |
| 351 if isinstance(self.parsed_url, self.FileImpl): | 386 if isinstance(self.parsed_url, self.FileImpl): |
| 352 # Special support for single-file checkout. | 387 # Special support for single-file checkout. |
| 353 if not command in (None, 'cleanup', 'diff', 'pack', 'status'): | 388 if not command in (None, 'cleanup', 'diff', 'pack', 'status'): |
| 354 options.revision = self.parsed_url.GetRevision() | 389 options.revision = self.parsed_url.GetRevision() |
| 355 scm = gclient_scm.SVNWrapper(self.parsed_url.GetPath(), | 390 scm = gclient_scm.SVNWrapper(self.parsed_url.GetPath(), |
| 356 self.root_dir(), | 391 self.root_dir(), |
| 357 self.name) | 392 self.name) |
| 358 scm.RunCommand('updatesingle', options, | 393 scm.RunCommand('updatesingle', options, |
| 359 args + [self.parsed_url.GetFilename()], | 394 args + [self.parsed_url.GetFilename()], |
| 360 self._file_list) | 395 self._file_list) |
| 361 else: | 396 else: |
| 362 # Create a shallow copy to mutate revision. | 397 # Create a shallow copy to mutate revision. |
| 363 options = copy.copy(options) | 398 options = copy.copy(options) |
| 364 options.revision = revision_overrides.get(self.name) | 399 options.revision = revision_overrides.get(self.name) |
| 400 maybeGetParentRevision(options) | |
| 365 scm = gclient_scm.CreateSCM(self.parsed_url, self.root_dir(), self.name) | 401 scm = gclient_scm.CreateSCM(self.parsed_url, self.root_dir(), self.name) |
| 366 scm.RunCommand(command, options, args, self._file_list) | 402 scm.RunCommand(command, options, args, self._file_list) |
| 403 maybeConvertToDateRevision(options) | |
| 367 self._file_list = [os.path.join(self.name, f.strip()) | 404 self._file_list = [os.path.join(self.name, f.strip()) |
| 368 for f in self._file_list] | 405 for f in self._file_list] |
| 369 self.processed = True | 406 self.processed = True |
| 370 if self.recursion_limit() > 0: | 407 if self.recursion_limit() > 0: |
| 371 # Then we can parse the DEPS file. | 408 # Then we can parse the DEPS file. |
| 372 self.ParseDepsFile() | 409 self.ParseDepsFile() |
| 373 # Adjust the implicit dependency requirement; e.g. if a DEPS file contains | 410 # Adjust the implicit dependency requirement; e.g. if a DEPS file contains |
| 374 # both src/foo and src/foo/bar, src/foo/bar is implicitly dependent of | 411 # both src/foo and src/foo/bar, src/foo/bar is implicitly dependent of |
| 375 # src/foo. Yes, it's O(n^2)... It's important to do that before | 412 # src/foo. Yes, it's O(n^2)... It's important to do that before |
| 376 # enqueueing them. | 413 # enqueueing them. |
| (...skipping 659 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1036 parser.add_option('-n', '--nohooks', action='store_true', | 1073 parser.add_option('-n', '--nohooks', action='store_true', |
| 1037 help='don\'t run hooks after the update is complete') | 1074 help='don\'t run hooks after the update is complete') |
| 1038 parser.add_option('-r', '--revision', action='append', | 1075 parser.add_option('-r', '--revision', action='append', |
| 1039 dest='revisions', metavar='REV', default=[], | 1076 dest='revisions', metavar='REV', default=[], |
| 1040 help='Enforces revision/hash for the solutions with the ' | 1077 help='Enforces revision/hash for the solutions with the ' |
| 1041 'format src@rev. The src@ part is optional and can be ' | 1078 'format src@rev. The src@ part is optional and can be ' |
| 1042 'skipped. -r can be used multiple times when .gclient ' | 1079 'skipped. -r can be used multiple times when .gclient ' |
| 1043 'has multiple solutions configured and will work even ' | 1080 'has multiple solutions configured and will work even ' |
| 1044 'if the src@ part is skipped. Note that specifying ' | 1081 'if the src@ part is skipped. Note that specifying ' |
| 1045 '--revision means your safesync_url gets ignored.') | 1082 '--revision means your safesync_url gets ignored.') |
| 1083 parser.add_option('-t', '--transitive', action='store_true', | |
| 1084 help='When a revision is specified (in the DEPS file or ' | |
| 1085 'with the command-line flag), transitively update ' | |
| 1086 'the dependencies to the date of the given revision.') | |
| 1046 parser.add_option('-H', '--head', action='store_true', | 1087 parser.add_option('-H', '--head', action='store_true', |
| 1047 help='skips any safesync_urls specified in ' | 1088 help='skips any safesync_urls specified in ' |
| 1048 'configured solutions and sync to head instead') | 1089 'configured solutions and sync to head instead') |
| 1049 parser.add_option('-D', '--delete_unversioned_trees', action='store_true', | 1090 parser.add_option('-D', '--delete_unversioned_trees', action='store_true', |
| 1050 help='delete any dependency that have been removed from ' | 1091 help='delete any dependency that have been removed from ' |
| 1051 'last sync as long as there is no local modification. ' | 1092 'last sync as long as there is no local modification. ' |
| 1052 'Coupled with --force, it will remove them even with ' | 1093 'Coupled with --force, it will remove them even with ' |
| 1053 'local modifications') | 1094 'local modifications') |
| 1054 parser.add_option('-R', '--reset', action='store_true', | 1095 parser.add_option('-R', '--reset', action='store_true', |
| 1055 help='resets any local changes before updating (git only)') | 1096 help='resets any local changes before updating (git only)') |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1265 except (gclient_utils.Error, subprocess2.CalledProcessError), e: | 1306 except (gclient_utils.Error, subprocess2.CalledProcessError), e: |
| 1266 print >> sys.stderr, 'Error: %s' % str(e) | 1307 print >> sys.stderr, 'Error: %s' % str(e) |
| 1267 return 1 | 1308 return 1 |
| 1268 | 1309 |
| 1269 | 1310 |
| 1270 if '__main__' == __name__: | 1311 if '__main__' == __name__: |
| 1271 fix_encoding.fix_encoding() | 1312 fix_encoding.fix_encoding() |
| 1272 sys.exit(Main(sys.argv[1:])) | 1313 sys.exit(Main(sys.argv[1:])) |
| 1273 | 1314 |
| 1274 # vim: ts=2:sw=2:tw=80:et: | 1315 # vim: ts=2:sw=2:tw=80:et: |
| OLD | NEW |