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 if command == 'update' and options.transitive and not options.revision: |
| 348 _, revision = gclient_utils.SplitUrlRevision(self.parsed_url) |
| 349 if not revision: |
| 350 options.revision = revision_overrides.get(self.parent.name) |
| 351 if options.verbose and options.revision: |
| 352 print("Using parent's revision date: %s" % options.revision) |
| 353 # If the parent has a revision override, then it must have been |
| 354 # converted to date format. |
| 355 assert (not options.revision or |
| 356 gclient_utils.IsDateRevision(options.revision)) |
| 357 |
| 358 def maybeConvertToDateRevision(options): |
| 359 """If we are performing an update and --transitive is set, convert the |
| 360 revision to a date-revision (if necessary). Instead of having |
| 361 -r 101 replace the revision with the time stamp of 101 (e.g. |
| 362 "{2011-18-04}"). |
| 363 This way dependencies are upgraded to the revision they had at the |
| 364 check-in of revision 101.""" |
| 365 if (command == 'update' and |
| 366 options.transitive and |
| 367 options.revision and |
| 368 not gclient_utils.IsDateRevision(options.revision)): |
| 369 revision_date = scm.GetRevisionDate(options.revision) |
| 370 revision = gclient_utils.MakeDateRevision(revision_date) |
| 371 if options.verbose: |
| 372 print("Updating revision override from %s to %s." % |
| 373 (options.revision, revision)) |
| 374 revision_overrides[self.name] = revision |
| 375 |
342 assert self._file_list == [] | 376 assert self._file_list == [] |
343 if not self.should_process: | 377 if not self.should_process: |
344 return | 378 return |
345 # When running runhooks, there's no need to consult the SCM. | 379 # When running runhooks, there's no need to consult the SCM. |
346 # All known hooks are expected to run unconditionally regardless of working | 380 # All known hooks are expected to run unconditionally regardless of working |
347 # copy state, so skip the SCM status check. | 381 # copy state, so skip the SCM status check. |
348 run_scm = command not in ('runhooks', None) | 382 run_scm = command not in ('runhooks', None) |
349 self.parsed_url = self.LateOverride(self.url) | 383 self.parsed_url = self.LateOverride(self.url) |
350 if run_scm and self.parsed_url: | 384 if run_scm and self.parsed_url: |
351 if isinstance(self.parsed_url, self.FileImpl): | 385 if isinstance(self.parsed_url, self.FileImpl): |
352 # Special support for single-file checkout. | 386 # Special support for single-file checkout. |
353 if not command in (None, 'cleanup', 'diff', 'pack', 'status'): | 387 if not command in (None, 'cleanup', 'diff', 'pack', 'status'): |
354 options.revision = self.parsed_url.GetRevision() | 388 options.revision = self.parsed_url.GetRevision() |
355 scm = gclient_scm.SVNWrapper(self.parsed_url.GetPath(), | 389 scm = gclient_scm.SVNWrapper(self.parsed_url.GetPath(), |
356 self.root_dir(), | 390 self.root_dir(), |
357 self.name) | 391 self.name) |
358 scm.RunCommand('updatesingle', options, | 392 scm.RunCommand('updatesingle', options, |
359 args + [self.parsed_url.GetFilename()], | 393 args + [self.parsed_url.GetFilename()], |
360 self._file_list) | 394 self._file_list) |
361 else: | 395 else: |
362 # Create a shallow copy to mutate revision. | 396 # Create a shallow copy to mutate revision. |
363 options = copy.copy(options) | 397 options = copy.copy(options) |
364 options.revision = revision_overrides.get(self.name) | 398 options.revision = revision_overrides.get(self.name) |
| 399 maybeGetParentRevision(options) |
365 scm = gclient_scm.CreateSCM(self.parsed_url, self.root_dir(), self.name) | 400 scm = gclient_scm.CreateSCM(self.parsed_url, self.root_dir(), self.name) |
366 scm.RunCommand(command, options, args, self._file_list) | 401 scm.RunCommand(command, options, args, self._file_list) |
| 402 maybeConvertToDateRevision(options) |
367 self._file_list = [os.path.join(self.name, f.strip()) | 403 self._file_list = [os.path.join(self.name, f.strip()) |
368 for f in self._file_list] | 404 for f in self._file_list] |
369 self.processed = True | 405 self.processed = True |
370 if self.recursion_limit() > 0: | 406 if self.recursion_limit() > 0: |
371 # Then we can parse the DEPS file. | 407 # Then we can parse the DEPS file. |
372 self.ParseDepsFile() | 408 self.ParseDepsFile() |
373 # Adjust the implicit dependency requirement; e.g. if a DEPS file contains | 409 # 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 | 410 # 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 | 411 # src/foo. Yes, it's O(n^2)... It's important to do that before |
376 # enqueueing them. | 412 # enqueueing them. |
(...skipping 659 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1036 parser.add_option('-n', '--nohooks', action='store_true', | 1072 parser.add_option('-n', '--nohooks', action='store_true', |
1037 help='don\'t run hooks after the update is complete') | 1073 help='don\'t run hooks after the update is complete') |
1038 parser.add_option('-r', '--revision', action='append', | 1074 parser.add_option('-r', '--revision', action='append', |
1039 dest='revisions', metavar='REV', default=[], | 1075 dest='revisions', metavar='REV', default=[], |
1040 help='Enforces revision/hash for the solutions with the ' | 1076 help='Enforces revision/hash for the solutions with the ' |
1041 'format src@rev. The src@ part is optional and can be ' | 1077 'format src@rev. The src@ part is optional and can be ' |
1042 'skipped. -r can be used multiple times when .gclient ' | 1078 'skipped. -r can be used multiple times when .gclient ' |
1043 'has multiple solutions configured and will work even ' | 1079 'has multiple solutions configured and will work even ' |
1044 'if the src@ part is skipped. Note that specifying ' | 1080 'if the src@ part is skipped. Note that specifying ' |
1045 '--revision means your safesync_url gets ignored.') | 1081 '--revision means your safesync_url gets ignored.') |
| 1082 parser.add_option('-t', '--transitive', action='store_true', |
| 1083 help='When a revision is specified (in the DEPS file or ' |
| 1084 'with the command-line flag), transitively update ' |
| 1085 'the dependencies to the date of the given revision. ' |
| 1086 'Only supported for SVN repositories.') |
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 |