changeset 3952:32c1653b7dad

merge with crew
author Benoit Boissinot <benoit.boissinot@ens-lyon.org>
date Fri, 22 Dec 2006 22:53:16 +0100
parents cb66641cdee3 (diff) 6257030134f4 (current diff)
children fad134931327 a8eb050c6489
files
diffstat 3 files changed, 50 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/commands.py	Thu Dec 21 23:17:20 2006 -0600
+++ b/mercurial/commands.py	Fri Dec 22 22:53:16 2006 +0100
@@ -1149,13 +1149,14 @@
 
     prev = {}
     def display(fn, rev, states, prevstates):
-        counts = {'-': 0, '+': 0}
+        found = False
         filerevmatches = {}
-        if incrementing or not opts['all']:
-            a, b, r = prevstates, states, rev
+        r = prev.get(fn, -1)
+        if opts['all']:
+            iter = difflinestates(states, prevstates)
         else:
-            a, b, r = states, prevstates, prev.get(fn, -1)
-        for change, l in difflinestates(a, b):
+            iter = [('', l) for l in prevstates]
+        for change, l in iter:
             cols = [fn, str(r)]
             if opts['line_number']:
                 cols.append(str(l.linenum))
@@ -1171,19 +1172,17 @@
             else:
                 cols.append(l.line)
             ui.write(sep.join(cols), eol)
-            counts[change] += 1
-        return counts['+'], counts['-']
+            found = True
+        return found
 
     fstate = {}
     skip = {}
     get = util.cachefunc(lambda r: repo.changectx(r).changeset())
     changeiter, matchfn = cmdutil.walkchangerevs(ui, repo, pats, get, opts)
-    count = 0
-    incrementing = False
+    found = False
     follow = opts.get('follow')
     for st, rev, fns in changeiter:
         if st == 'window':
-            incrementing = rev
             matches.clear()
         elif st == 'add':
             mf = repo.changectx(rev).manifest()
@@ -1209,10 +1208,10 @@
                     if copy:
                         skip[copy] = True
                     continue
-                if incrementing or not opts['all'] or fstate[fn]:
-                    pos, neg = display(fn, rev, m, fstate[fn])
-                    count += pos + neg
-                    if pos and not opts['all']:
+                if fn in prev or fstate[fn]:
+                    r = display(fn, rev, m, fstate[fn])
+                    found = found or r
+                    if r and not opts['all']:
                         skip[fn] = True
                         if copy:
                             skip[copy] = True
@@ -1221,15 +1220,14 @@
                     fstate[copy] = m
                 prev[fn] = rev
 
-    if not incrementing:
-        fstate = fstate.items()
-        fstate.sort()
-        for fn, state in fstate:
-            if fn in skip:
-                continue
-            if fn not in copies.get(prev[fn], {}):
-                display(fn, rev, {}, state)
-    return (count == 0 and 1) or 0
+    fstate = fstate.items()
+    fstate.sort()
+    for fn, state in fstate:
+        if fn in skip:
+            continue
+        if fn not in copies.get(prev[fn], {}):
+            found = display(fn, rev, {}, state) or found
+    return (not found and 1) or 0
 
 def heads(ui, repo, **opts):
     """show current repository heads
--- a/tests/test-grep	Thu Dec 21 23:17:20 2006 -0600
+++ b/tests/test-grep	Fri Dec 22 22:53:16 2006 +0100
@@ -17,8 +17,11 @@
 head -n 3 port > port1
 mv port1 port
 hg commit -m 4 -u spam -d '4 0'
+echo % simple
 hg grep port port
+echo % all
 hg grep --all -nu port port
+echo % other
 hg grep import port
 
 hg cp port port2
@@ -28,3 +31,22 @@
 echo deport >> port2
 hg commit -m 5 -u eggs -d '6 0'
 hg grep -f --all -nu port port2
+
+cd ..
+hg init t2
+cd t2
+hg grep foobar foo
+hg grep foobar
+echo blue >> color
+echo black >> color
+hg add color
+hg ci -m 0 -d '0 0'
+echo orange >> color
+hg ci -m 1 -d '0 0'
+echo black > color
+hg ci -m 2 -d '0 0'
+echo orange >> color
+echo blue >> color
+hg ci -m 3 -d '0 0'
+hg grep orange
+hg grep --all orange
--- a/tests/test-grep.out	Thu Dec 21 23:17:20 2006 -0600
+++ b/tests/test-grep.out	Fri Dec 22 22:53:16 2006 +0100
@@ -1,6 +1,8 @@
+% simple
 port:4:export
 port:4:vaportight
 port:4:import/export
+% all
 port:4:4:-:spam:import/export
 port:3:4:+:eggs:import/export
 port:2:1:-:spam:import
@@ -10,6 +12,7 @@
 port:2:3:+:spam:import/export
 port:1:2:+:eggs:export
 port:0:1:+:spam:import
+% other
 port:4:import/export
 % follow
 port:0:import
@@ -23,3 +26,7 @@
 port:2:3:+:spam:import/export
 port:1:2:+:eggs:export
 port:0:1:+:spam:import
+color:3:orange
+color:3:+:orange
+color:2:-:orange
+color:1:+:orange