graphlog: fix --follow --rev combinations
authorPatrick Mezard <patrick@mezard.eu>
Wed, 11 Apr 2012 11:22:40 +0200
changeset 16408 d74099ac2ac1
parent 16407 49ef1c382965
child 16409 2cbd7dd0cc1f
graphlog: fix --follow --rev combinations The previous behaviour of --follow was really a subset of what is really happening in log command: - If --rev is not passed, default to '.:0' - Resolve --rev into a revision list "revs" - Set the starting revision to revs[0] - If revs[1] > revs[0] keep descendants(revs[0]) in revs, otherwise keep ancestors.
hgext/graphlog.py
tests/test-glog.t
--- a/hgext/graphlog.py	Wed Apr 11 11:17:26 2012 +0200
+++ b/hgext/graphlog.py	Wed Apr 11 11:22:40 2012 +0200
@@ -279,10 +279,11 @@
     the files to be detailed when displaying the revision.
     """
     opt2revset = {
-        'follow':           ('follow()', None),
         'follow_first':     ('_followfirst()', None),
         'no_merges':        ('not merge()', None),
         'only_merges':      ('merge()', None),
+        '_ancestors':       ('ancestors(%(val)s)', None),
+        '_descendants':     ('descendants(%(val)s)', None),
         '_matchfiles':      ('_matchfiles(%(val)s)', None),
         'date':             ('date(%(val)r)', None),
         'branch':           ('branch(%(val)r)', ' or '),
@@ -298,10 +299,11 @@
     # follow or not follow?
     follow = opts.get('follow') or opts.get('follow_first')
     followfirst = opts.get('follow_first')
-    if 'follow' in opts:
-        del opts['follow']
     if 'follow_first' in opts:
         del opts['follow_first']
+    # --follow with FILE behaviour depends on revs...
+    startrev = revs[0]
+    followdescendants = len(revs) > 1 and revs[0] < revs[1]
 
     # branch and only_branch are really aliases and must be handled at
     # the same time
@@ -359,7 +361,10 @@
                 if pats:
                     opts['_patsfollow'] = list(pats)
                 else:
-                    opts['follow'] = True
+                    if followdescendants:
+                        opts['_descendants'] = str(startrev)
+                    else:
+                        opts['_ancestors'] = str(startrev)
         else:
             opts['_patslog'] = list(pats)
 
@@ -402,10 +407,16 @@
     """
     if not len(repo):
         return [], None, None
+    # Default --rev value depends on --follow but --follow behaviour
+    # depends on revisions resolved from --rev...
+    follow = opts.get('follow') or opts.get('follow_first')
     if opts.get('rev'):
         revs = scmutil.revrange(repo, opts['rev'])
     else:
-        revs = range(len(repo))
+        if follow and len(repo) > 0:
+            revs = scmutil.revrange(repo, ['.:0'])
+        else:
+            revs = range(len(repo) - 1, -1, -1)
     if not revs:
         return [], None, None
     expr, filematcher = _makelogrevset(repo, pats, opts, revs)
--- a/tests/test-glog.t	Wed Apr 11 11:17:26 2012 +0200
+++ b/tests/test-glog.t	Wed Apr 11 11:22:40 2012 +0200
@@ -1538,13 +1538,13 @@
   $ cd ..
   $ hg init follow
   $ cd follow
+  $ testlog --follow
+  []
+  []
   $ echo a > a
   $ echo aa > aa
   $ echo f > f
-  $ hg ci -Am "add a"
-  adding a
-  adding aa
-  adding f
+  $ hg ci -Am "add a" a aa f
   $ hg cp a b
   $ hg cp f g
   $ hg ci -m "copy a b"
@@ -1925,3 +1925,54 @@
   $ testlog -r 'foo-bar'
   ['foo-bar']
   []
+
+Test --follow and forward --rev
+
+  $ hg up -q 6
+  $ echo g > g
+  $ hg ci -Am 'add g' g
+  created new head
+  $ hg up -q 2
+  $ hg log -G --template "{rev} {desc|firstline}\n"
+  o  8 add g
+  |
+  | o  7 Added tag foo-bar for changeset fc281d8ff18d
+  |/
+  o    6 merge 5 and 4
+  |\
+  | o  5 add another e
+  | |
+  o |  4 mv dir/b e
+  |/
+  o  3 mv a b; add d
+  |
+  @  2 mv b dir/b
+  |
+  o  1 copy a b
+  |
+  o  0 add a
+  
+  $ testlog --follow -r6 -r8 -r5 -r7 -r4
+  ['6', '8', '5', '7', '4']
+  (group
+    (func
+      ('symbol', 'descendants')
+      ('symbol', '6')))
+  --- log.nodes	* (glob)
+  +++ glog.nodes	* (glob)
+  @@ -1,3 +1,3 @@
+  -nodetag 6
+   nodetag 8
+   nodetag 7
+  +nodetag 6
+  [1]
+
+Test --follow and backward --rev
+
+  $ testlog --follow -r6 -r5 -r7 -r8 -r4
+  ['6', '5', '7', '8', '4']
+  (group
+    (func
+      ('symbol', 'ancestors')
+      ('symbol', '6')))
+