Commit daa76d2f authored by Edward Lesmes's avatar Edward Lesmes Committed by Commit Bot

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/951963Reviewed-by: 's avatarAaron Gable <agable@chromium.org>
Commit-Queue: Edward Lesmes <ehmaldonado@chromium.org>
parent 462839ea
......@@ -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:
......
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment