summaryrefslogtreecommitdiffstats
path: root/subcmds/grep.py
diff options
context:
space:
mode:
Diffstat (limited to 'subcmds/grep.py')
-rw-r--r--subcmds/grep.py24
1 files changed, 12 insertions, 12 deletions
diff --git a/subcmds/grep.py b/subcmds/grep.py
index 0dc8f9f6..dd391cfa 100644
--- a/subcmds/grep.py
+++ b/subcmds/grep.py
@@ -13,6 +13,7 @@
13# See the License for the specific language governing permissions and 13# See the License for the specific language governing permissions and
14# limitations under the License. 14# limitations under the License.
15 15
16from __future__ import print_function
16import sys 17import sys
17from color import Coloring 18from color import Coloring
18from command import PagedCommand 19from command import PagedCommand
@@ -51,7 +52,7 @@ Examples
51 52
52Look for a line that has '#define' and either 'MAX_PATH or 'PATH_MAX': 53Look for a line that has '#define' and either 'MAX_PATH or 'PATH_MAX':
53 54
54 repo grep -e '#define' --and -\( -e MAX_PATH -e PATH_MAX \) 55 repo grep -e '#define' --and -\\( -e MAX_PATH -e PATH_MAX \\)
55 56
56Look for a line that has 'NODE' or 'Unexpected' in files that 57Look for a line that has 'NODE' or 'Unexpected' in files that
57contain a line that matches both expressions: 58contain a line that matches both expressions:
@@ -84,7 +85,7 @@ contain a line that matches both expressions:
84 g.add_option('--cached', 85 g.add_option('--cached',
85 action='callback', callback=carry, 86 action='callback', callback=carry,
86 help='Search the index, instead of the work tree') 87 help='Search the index, instead of the work tree')
87 g.add_option('-r','--revision', 88 g.add_option('-r', '--revision',
88 dest='revision', action='append', metavar='TREEish', 89 dest='revision', action='append', metavar='TREEish',
89 help='Search TREEish, instead of the work tree') 90 help='Search TREEish, instead of the work tree')
90 91
@@ -96,7 +97,7 @@ contain a line that matches both expressions:
96 g.add_option('-i', '--ignore-case', 97 g.add_option('-i', '--ignore-case',
97 action='callback', callback=carry, 98 action='callback', callback=carry,
98 help='Ignore case differences') 99 help='Ignore case differences')
99 g.add_option('-a','--text', 100 g.add_option('-a', '--text',
100 action='callback', callback=carry, 101 action='callback', callback=carry,
101 help="Process binary files as if they were text") 102 help="Process binary files as if they were text")
102 g.add_option('-I', 103 g.add_option('-I',
@@ -125,7 +126,7 @@ contain a line that matches both expressions:
125 g.add_option('--and', '--or', '--not', 126 g.add_option('--and', '--or', '--not',
126 action='callback', callback=carry, 127 action='callback', callback=carry,
127 help='Boolean operators to combine patterns') 128 help='Boolean operators to combine patterns')
128 g.add_option('-(','-)', 129 g.add_option('-(', '-)',
129 action='callback', callback=carry, 130 action='callback', callback=carry,
130 help='Boolean operator grouping') 131 help='Boolean operator grouping')
131 132
@@ -145,10 +146,10 @@ contain a line that matches both expressions:
145 action='callback', callback=carry, 146 action='callback', callback=carry,
146 metavar='CONTEXT', type='str', 147 metavar='CONTEXT', type='str',
147 help='Show CONTEXT lines after match') 148 help='Show CONTEXT lines after match')
148 g.add_option('-l','--name-only','--files-with-matches', 149 g.add_option('-l', '--name-only', '--files-with-matches',
149 action='callback', callback=carry, 150 action='callback', callback=carry,
150 help='Show only file names containing matching lines') 151 help='Show only file names containing matching lines')
151 g.add_option('-L','--files-without-match', 152 g.add_option('-L', '--files-without-match',
152 action='callback', callback=carry, 153 action='callback', callback=carry,
153 help='Show only file names not containing matching lines') 154 help='Show only file names not containing matching lines')
154 155
@@ -157,9 +158,9 @@ contain a line that matches both expressions:
157 out = GrepColoring(self.manifest.manifestProject.config) 158 out = GrepColoring(self.manifest.manifestProject.config)
158 159
159 cmd_argv = ['grep'] 160 cmd_argv = ['grep']
160 if out.is_on and git_require((1,6,3)): 161 if out.is_on and git_require((1, 6, 3)):
161 cmd_argv.append('--color') 162 cmd_argv.append('--color')
162 cmd_argv.extend(getattr(opt,'cmd_argv',[])) 163 cmd_argv.extend(getattr(opt, 'cmd_argv', []))
163 164
164 if '-e' not in cmd_argv: 165 if '-e' not in cmd_argv:
165 if not args: 166 if not args:
@@ -178,8 +179,7 @@ contain a line that matches both expressions:
178 have_rev = False 179 have_rev = False
179 if opt.revision: 180 if opt.revision:
180 if '--cached' in cmd_argv: 181 if '--cached' in cmd_argv:
181 print >>sys.stderr,\ 182 print('fatal: cannot combine --cached and --revision', file=sys.stderr)
182 'fatal: cannot combine --cached and --revision'
183 sys.exit(1) 183 sys.exit(1)
184 have_rev = True 184 have_rev = True
185 cmd_argv.extend(opt.revision) 185 cmd_argv.extend(opt.revision)
@@ -230,13 +230,13 @@ contain a line that matches both expressions:
230 out.nl() 230 out.nl()
231 else: 231 else:
232 for line in r: 232 for line in r:
233 print line 233 print(line)
234 234
235 if have_match: 235 if have_match:
236 sys.exit(0) 236 sys.exit(0)
237 elif have_rev and bad_rev: 237 elif have_rev and bad_rev:
238 for r in opt.revision: 238 for r in opt.revision:
239 print >>sys.stderr, "error: can't search revision %s" % r 239 print("error: can't search revision %s" % r, file=sys.stderr)
240 sys.exit(1) 240 sys.exit(1)
241 else: 241 else:
242 sys.exit(1) 242 sys.exit(1)