Patchwork D10382: outgoing: move filtering logic in its own function

login
register
mail settings
Submitter phabricator
Date April 13, 2021, 2:52 p.m.
Message ID <differential-rev-PHID-DREV-ykupvbyt64ras26tablc-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/48699/
State Superseded
Headers show

Comments

phabricator - April 13, 2021, 2:52 p.m.
marmoute created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  This move code dedicated to a single purpose together and make the main code
  simpler. Right when we are getting ready to make it more complex :-D

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D10382

AFFECTED FILES
  mercurial/hg.py

CHANGE DETAILS




To: marmoute, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

diff --git a/mercurial/hg.py b/mercurial/hg.py
--- a/mercurial/hg.py
+++ b/mercurial/hg.py
@@ -1358,27 +1358,40 @@ 
     return ret
 
 
+def _outgoing_filter(repo, revs, opts):
+    """apply revision filtering/ordering option for outgoing"""
+    limit = logcmdutil.getlimit(opts)
+    no_merges = opts.get(b'no_merges')
+    if opts.get(b'newest_first'):
+        revs.reverse()
+    if limit is None and not no_merges:
+        for r in revs:
+            yield r
+        return
+
+    count = 0
+    cl = repo.changelog
+    for n in revs:
+        if limit is not None and count >= limit:
+            break
+        parents = [p for p in cl.parents(n) if p != nullid]
+        if no_merges and len(parents) == 2:
+            continue
+        count += 1
+        yield n
+
+
 def outgoing(ui, repo, dest, opts):
 
-    limit = logcmdutil.getlimit(opts)
     o, other = _outgoing(ui, repo, dest, opts)
     ret = 1
     try:
         if o:
             ret = 0
 
-            if opts.get(b'newest_first'):
-                o.reverse()
             ui.pager(b'outgoing')
             displayer = logcmdutil.changesetdisplayer(ui, repo, opts)
-            count = 0
-            for n in o:
-                if limit is not None and count >= limit:
-                    break
-                parents = [p for p in repo.changelog.parents(n) if p != nullid]
-                if opts.get(b'no_merges') and len(parents) == 2:
-                    continue
-                count += 1
+            for n in _outgoing_filter(repo, o, opts):
                 displayer.show(repo[n])
             displayer.close()
         cmdutil.outgoinghooks(ui, repo, other, opts, o)