From daa76d2f225cd7ae8f711ff0263bb04aa23131a4 Mon Sep 17 00:00:00 2001 From: Edward Lesmes Date: Tue, 6 Mar 2018 14:56:57 -0500 Subject: [PATCH] gclient revinfo: Add options to filter by path or url. Add --path and --url options to show only the dependencies that match one of the given paths or URLs. Bug: None Change-Id: I12c205545b7ce54b56abcd62f9bf1db229b4fd77 Reviewed-on: https://chromium-review.googlesource.com/951963 Reviewed-by: Aaron Gable Commit-Queue: Edward Lesmes --- gclient.py | 25 +++++++++++++++++--- tests/gclient_smoketest.py | 47 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+), 3 deletions(-) diff --git a/gclient.py b/gclient.py index e492b8c33..2febcff85 100755 --- a/gclient.py +++ b/gclient.py @@ -1762,6 +1762,15 @@ it or fix the checkout. work_queue.enqueue(s) work_queue.flush({}, None, [], options=self._options) + def ShouldPrintRevision(path, rev): + if not self._options.path and not self._options.url: + return True + if self._options.path and path in self._options.path: + return True + if self._options.url and rev and rev.split('@')[0] in self._options.url: + return True + return False + def GetURLAndRev(dep): """Returns the revision-qualified SCM url for a Dependency.""" if dep.parsed_url is None: @@ -1781,7 +1790,9 @@ it or fix the checkout. def GrabDeps(dep): """Recursively grab dependencies.""" for d in dep.dependencies: - entries[d.name] = GetURLAndRev(d) + rev = GetURLAndRev(d) + if ShouldPrintRevision(d.name, rev): + entries[d.name] = rev GrabDeps(d) GrabDeps(d) custom_deps = [] @@ -1804,9 +1815,11 @@ it or fix the checkout. entries = {} for d in self.root.subtree(False): if self._options.actual: - entries[d.name] = GetURLAndRev(d) + rev = GetURLAndRev(d) else: - entries[d.name] = d.parsed_url + rev = d.parsed_url + if ShouldPrintRevision(d.name, rev): + entries[d.name] = rev keys = sorted(entries.keys()) for x in keys: print('%s: %s' % (x, entries[x])) @@ -2784,6 +2797,12 @@ def CMDrevinfo(parser, args): help='creates a snapshot .gclient file of the current ' 'version of all repositories to reproduce the tree, ' 'implies -a') + parser.add_option('-u', '--url', action='append', + help='Display revision information only for the specified ' + 'URLs.') + parser.add_option('-p', '--path', action='append', + help='Display revision information only for the specified ' + 'paths.') (options, args) = parser.parse_args(args) client = GClient.LoadCurrentConfig(options) if not client: diff --git a/tests/gclient_smoketest.py b/tests/gclient_smoketest.py index 2c067c298..871d4b7b1 100755 --- a/tests/gclient_smoketest.py +++ b/tests/gclient_smoketest.py @@ -634,6 +634,12 @@ class GClientSmokeGIT(GClientSmokeBase): 'hash2': self.githash('repo_2', 1)[:7], }) self.check((out, '', 0), results) + + def testRevInfoActual(self): + if not self.enabled: + return + self.gclient(['config', self.git_base + 'repo_1', '--name', 'src']) + self.gclient(['sync', '--deps', 'mac']) results = self.gclient(['revinfo', '--deps', 'mac', '--actual']) out = ('src: %(base)srepo_1@%(hash1)s\n' 'src/repo2: %(base)srepo_2@%(hash2)s\n' @@ -646,6 +652,47 @@ class GClientSmokeGIT(GClientSmokeBase): }) self.check((out, '', 0), results) + def testRevInfoFilterPath(self): + if not self.enabled: + return + self.gclient(['config', self.git_base + 'repo_1', '--name', 'src']) + self.gclient(['sync', '--deps', 'mac']) + results = self.gclient(['revinfo', '--deps', 'mac', '--path', 'src']) + out = ('src: %(base)srepo_1\n' % + { + 'base': self.git_base, + }) + self.check((out, '', 0), results) + + def testRevInfoFilterURL(self): + if not self.enabled: + return + self.gclient(['config', self.git_base + 'repo_1', '--name', 'src']) + self.gclient(['sync', '--deps', 'mac']) + results = self.gclient(['revinfo', '--deps', 'mac', + '--url', '%srepo_2' % self.git_base]) + out = ('src/repo2: %(base)srepo_2@%(hash2)s\n' % + { + 'base': self.git_base, + 'hash2': self.githash('repo_2', 1)[:7], + }) + self.check((out, '', 0), results) + + def testRevInfoFilterURLOrPath(self): + if not self.enabled: + return + self.gclient(['config', self.git_base + 'repo_1', '--name', 'src']) + self.gclient(['sync', '--deps', 'mac']) + results = self.gclient(['revinfo', '--deps', 'mac', '--path', 'src', + '--url', '%srepo_2' % self.git_base]) + out = ('src: %(base)srepo_1\n' + 'src/repo2: %(base)srepo_2@%(hash2)s\n' % + { + 'base': self.git_base, + 'hash2': self.githash('repo_2', 1)[:7], + }) + self.check((out, '', 0), results) + def testFlatten(self): if not self.enabled: return