graphlog: reduce duplication in --follow code
authorPatrick Mezard <patrick@mezard.eu>
Sat, 14 Apr 2012 11:16:57 +0200
changeset 16433 e38b29937118
parent 16432 365bb0fa73a4
child 16434 8b62a77d0895
graphlog: reduce duplication in --follow code
hgext/graphlog.py
--- a/hgext/graphlog.py	Sat Apr 14 10:44:13 2012 +0200
+++ b/hgext/graphlog.py	Sat Apr 14 11:16:57 2012 +0200
@@ -297,10 +297,10 @@
     opts = dict(opts)
     # follow or not follow?
     follow = opts.get('follow') or opts.get('follow_first')
-    followfirst = opts.get('follow_first')
+    followfirst = opts.get('follow_first') and 1 or 0
     # --follow with FILE behaviour depends on revs...
     startrev = revs[0]
-    followdescendants = len(revs) > 1 and revs[0] < revs[1]
+    followdescendants = (len(revs) > 1 and revs[0] < revs[1]) and 1 or 0
 
     # branch and only_branch are really aliases and must be handled at
     # the same time
@@ -349,22 +349,13 @@
         opts['_matchfiles'] = matchargs
     else:
         if follow:
-            if followfirst:
-                if pats:
-                    opts['_patsfollowfirst'] = list(pats)
-                else:
-                    if followdescendants:
-                        opts['_fdescendants'] = str(startrev)
-                    else:
-                        opts['_fancestors'] = str(startrev)
+            fpats = ('_patsfollow', '_patsfollowfirst')
+            fnopats = (('_ancestors', '_fancestors'),
+                       ('_descendants', '_fdescendants'))
+            if pats:
+                opts[fpats[followfirst]] = list(pats)
             else:
-                if pats:
-                    opts['_patsfollow'] = list(pats)
-                else:
-                    if followdescendants:
-                        opts['_descendants'] = str(startrev)
-                    else:
-                        opts['_ancestors'] = str(startrev)
+                opts[fnopats[followdescendants][followfirst]] = str(startrev)
         else:
             opts['_patslog'] = list(pats)