##// END OF EJS Templates
grep: remove count handling, simplify, fix issue337
Benoit Boissinot -
r3951:cb66641c default
parent child Browse files
Show More
@@ -1149,13 +1149,14 b' def grep(ui, repo, pattern, *pats, **opt'
1149
1149
1150 prev = {}
1150 prev = {}
1151 def display(fn, rev, states, prevstates):
1151 def display(fn, rev, states, prevstates):
1152 counts = {'-': 0, '+': 0}
1152 found = False
1153 filerevmatches = {}
1153 filerevmatches = {}
1154 if not opts['all']:
1154 r = prev.get(fn, -1)
1155 a, b, r = prevstates, states, rev
1155 if opts['all']:
1156 iter = difflinestates(states, prevstates)
1156 else:
1157 else:
1157 a, b, r = states, prevstates, prev.get(fn, -1)
1158 iter = [('', l) for l in prevstates]
1158 for change, l in difflinestates(a, b):
1159 for change, l in iter:
1159 cols = [fn, str(r)]
1160 cols = [fn, str(r)]
1160 if opts['line_number']:
1161 if opts['line_number']:
1161 cols.append(str(l.linenum))
1162 cols.append(str(l.linenum))
@@ -1171,14 +1172,14 b' def grep(ui, repo, pattern, *pats, **opt'
1171 else:
1172 else:
1172 cols.append(l.line)
1173 cols.append(l.line)
1173 ui.write(sep.join(cols), eol)
1174 ui.write(sep.join(cols), eol)
1174 counts[change] += 1
1175 found = True
1175 return counts['+'], counts['-']
1176 return found
1176
1177
1177 fstate = {}
1178 fstate = {}
1178 skip = {}
1179 skip = {}
1179 get = util.cachefunc(lambda r: repo.changectx(r).changeset())
1180 get = util.cachefunc(lambda r: repo.changectx(r).changeset())
1180 changeiter, matchfn = cmdutil.walkchangerevs(ui, repo, pats, get, opts)
1181 changeiter, matchfn = cmdutil.walkchangerevs(ui, repo, pats, get, opts)
1181 count = 0
1182 found = False
1182 follow = opts.get('follow')
1183 follow = opts.get('follow')
1183 for st, rev, fns in changeiter:
1184 for st, rev, fns in changeiter:
1184 if st == 'window':
1185 if st == 'window':
@@ -1207,10 +1208,10 b' def grep(ui, repo, pattern, *pats, **opt'
1207 if copy:
1208 if copy:
1208 skip[copy] = True
1209 skip[copy] = True
1209 continue
1210 continue
1210 if not opts['all'] or fstate[fn]:
1211 if fn in prev or fstate[fn]:
1211 pos, neg = display(fn, rev, m, fstate[fn])
1212 r = display(fn, rev, m, fstate[fn])
1212 count += pos + neg
1213 found = found or r
1213 if pos and not opts['all']:
1214 if r and not opts['all']:
1214 skip[fn] = True
1215 skip[fn] = True
1215 if copy:
1216 if copy:
1216 skip[copy] = True
1217 skip[copy] = True
@@ -1225,8 +1226,8 b' def grep(ui, repo, pattern, *pats, **opt'
1225 if fn in skip:
1226 if fn in skip:
1226 continue
1227 continue
1227 if fn not in copies.get(prev[fn], {}):
1228 if fn not in copies.get(prev[fn], {}):
1228 display(fn, rev, {}, state)
1229 found = display(fn, rev, {}, state) or found
1229 return (count == 0 and 1) or 0
1230 return (not found and 1) or 0
1230
1231
1231 def heads(ui, repo, **opts):
1232 def heads(ui, repo, **opts):
1232 """show current repository heads
1233 """show current repository heads
@@ -31,3 +31,22 b" hg grep -f 'import$' port2"
31 echo deport >> port2
31 echo deport >> port2
32 hg commit -m 5 -u eggs -d '6 0'
32 hg commit -m 5 -u eggs -d '6 0'
33 hg grep -f --all -nu port port2
33 hg grep -f --all -nu port port2
34
35 cd ..
36 hg init t2
37 cd t2
38 hg grep foobar foo
39 hg grep foobar
40 echo blue >> color
41 echo black >> color
42 hg add color
43 hg ci -m 0 -d '0 0'
44 echo orange >> color
45 hg ci -m 1 -d '0 0'
46 echo black > color
47 hg ci -m 2 -d '0 0'
48 echo orange >> color
49 echo blue >> color
50 hg ci -m 3 -d '0 0'
51 hg grep orange
52 hg grep --all orange
@@ -26,3 +26,7 b' port:2:2:+:spam:vaportight'
26 port:2:3:+:spam:import/export
26 port:2:3:+:spam:import/export
27 port:1:2:+:eggs:export
27 port:1:2:+:eggs:export
28 port:0:1:+:spam:import
28 port:0:1:+:spam:import
29 color:3:orange
30 color:3:+:orange
31 color:2:-:orange
32 color:1:+:orange
General Comments 0
You need to be logged in to leave comments. Login now