Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Unified Diff: gclient.py

Issue 11316213: gclient grep: support pathspec arguments (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gclient.py
diff --git a/gclient.py b/gclient.py
index a8dcf236198a83a936131b4eb5c9f430c613f1c6..059483a67ce70bcfc39423a4ebb9da8852967591 100644
--- a/gclient.py
+++ b/gclient.py
@@ -642,23 +642,31 @@ class Dependency(gclient_utils.WorkItem, DependencySettings):
if parsed_url:
env['GCLIENT_URL'] = parsed_url
env['GCLIENT_DEP_PATH'] = self.name
- if options.prepend_dir:
+ if options.prepend_dir and scm == 'git':
print_stdout = False
def filter_fn(line):
+ """Git-specific path marshaling. It is optimized for git-grep."""
+
+ def mod_path(git_pathspec):
+ match = re.match('^(\\S+?:)?([^\0]+)$', git_pathspec)
+ modified_path = os.path.join(self.name, match.group(2))
+ branch = match.group(1) or ''
+ return '%s%s' % (branch, modified_path)
+
+ match = re.match('^Binary file ([^\0]+) matches$', line)
+ if match:
+ print 'Binary file %s matches' % mod_path(match.group(1))
+ return
+
items = line.split('\0')
- if len(items) == 1:
- match = re.match('Binary file (.*) matches$', line)
- if match:
- print 'Binary file %s matches' % os.path.join(
- self.name, match.group(1))
- else:
- print line
- elif len(items) == 2 and items[1]:
- print '%s : %s' % (os.path.join(self.name, items[0]), items[1])
- else:
+ if len(items) == 2 and items[1]:
+ print '%s : %s' % (mod_path(items[0]), items[1])
+ elif len(items) >= 2:
# Multiple null bytes or a single trailing null byte indicate
# git is likely displaying filenames only (such as with -l)
- print '\n'.join(os.path.join(self.name, f) for f in items if f)
+ print '\n'.join(mod_path(path) for path in items if path)
+ else:
+ print line
else:
print_stdout = True
filter_fn = None
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698