def Execute(self, opt, args): self.out = _Coloring(self.client.globalConfig) self.printText = self.out.nofmt_printer('text') if opt.color: self.printProject = self.out.nofmt_printer('project', attr='bold') self.printAdded = self.out.nofmt_printer('green', fg='green', attr='bold') self.printRemoved = self.out.nofmt_printer('red', fg='red', attr='bold') self.printRevision = self.out.nofmt_printer('revision', fg='yellow') else: self.printProject = self.printAdded = self.printRemoved = self.printRevision = self.printText manifest1 = RepoClient(self.manifest.repodir) manifest1.Override(args[0], load_local_manifests=False) if len(args) == 1: manifest2 = self.manifest else: manifest2 = RepoClient(self.manifest.repodir) manifest2.Override(args[1], load_local_manifests=False) diff = manifest1.projectsDiff(manifest2) if opt.raw: self._printRawDiff(diff, pretty_format=opt.pretty_format) else: self._printDiff(diff, color=opt.color, pretty_format=opt.pretty_format)
def _Run(self, name, gopts, argv): """Execute the requested subcommand.""" result = 0 if gopts.trace: SetTrace() if gopts.show_version: if name == 'help': name = 'version' else: print('fatal: invalid usage of --version', file=sys.stderr) return 1 SetDefaultColoring(gopts.color) try: cmd = self.commands[name]() except KeyError: print("repo: '%s' is not a repo command. See 'repo help'." % name, file=sys.stderr) return 1 git_trace2_event_log = EventLog() cmd.repodir = self.repodir cmd.client = RepoClient(cmd.repodir) cmd.manifest = cmd.client.manifest cmd.gitc_manifest = None gitc_client_name = gitc_utils.parse_clientdir(os.getcwd()) if gitc_client_name: cmd.gitc_manifest = GitcClient(cmd.repodir, gitc_client_name) cmd.client.isGitcClient = True Editor.globalConfig = cmd.client.globalConfig if not isinstance(cmd, MirrorSafeCommand) and cmd.manifest.IsMirror: print("fatal: '%s' requires a working directory" % name, file=sys.stderr) return 1 if isinstance(cmd, GitcAvailableCommand ) and not gitc_utils.get_gitc_manifest_dir(): print("fatal: '%s' requires GITC to be available" % name, file=sys.stderr) return 1 if isinstance(cmd, GitcClientCommand) and not gitc_client_name: print("fatal: '%s' requires a GITC client" % name, file=sys.stderr) return 1 try: copts, cargs = cmd.OptionParser.parse_args(argv) copts = cmd.ReadEnvironmentOptions(copts) except NoManifestException as e: print('error: in `%s`: %s' % (' '.join([name] + argv), str(e)), file=sys.stderr) print('error: manifest missing or unreadable -- please run init', file=sys.stderr) return 1 if gopts.pager is not False and not isinstance(cmd, InteractiveCommand): config = cmd.client.globalConfig if gopts.pager: use_pager = True else: use_pager = config.GetBoolean('pager.%s' % name) if use_pager is None: use_pager = cmd.WantPager(copts) if use_pager: RunPager(config) start = time.time() cmd_event = cmd.event_log.Add(name, event_log.TASK_COMMAND, start) cmd.event_log.SetParent(cmd_event) git_trace2_event_log.StartEvent() try: cmd.ValidateOptions(copts, cargs) result = cmd.Execute(copts, cargs) except (DownloadError, ManifestInvalidRevisionError, NoManifestException) as e: print('error: in `%s`: %s' % (' '.join([name] + argv), str(e)), file=sys.stderr) if isinstance(e, NoManifestException): print( 'error: manifest missing or unreadable -- please run init', file=sys.stderr) result = 1 except NoSuchProjectError as e: if e.name: print('error: project %s not found' % e.name, file=sys.stderr) else: print('error: no project in current directory', file=sys.stderr) result = 1 except InvalidProjectGroupsError as e: if e.name: print('error: project group must be enabled for project %s' % e.name, file=sys.stderr) else: print( 'error: project group must be enabled for the project in the current directory', file=sys.stderr) result = 1 except SystemExit as e: if e.code: result = e.code raise finally: finish = time.time() elapsed = finish - start hours, remainder = divmod(elapsed, 3600) minutes, seconds = divmod(remainder, 60) if gopts.time: if hours == 0: print('real\t%dm%.3fs' % (minutes, seconds), file=sys.stderr) else: print('real\t%dh%dm%.3fs' % (hours, minutes, seconds), file=sys.stderr) cmd.event_log.FinishEvent(cmd_event, finish, result is None or result == 0) git_trace2_event_log.ExitEvent(result) if gopts.event_log: cmd.event_log.Write( os.path.abspath(os.path.expanduser(gopts.event_log))) git_trace2_event_log.Write(gopts.git_trace2_event_log) return result