changeset 40177:41e2633bcd00

wireprotov2: extract file object emission to own function An upcoming commit will introduce another caller. Differential Revision: https://phab.mercurial-scm.org/D4980
author Gregory Szorc <gregory.szorc@gmail.com>
date Tue, 02 Oct 2018 10:31:36 -0700
parents 41263df08109
children 46a40bce3ae0
files mercurial/wireprotov2server.py
diffstat 1 files changed, 31 insertions(+), 27 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/wireprotov2server.py	Mon Oct 08 18:17:12 2018 -0700
+++ b/mercurial/wireprotov2server.py	Tue Oct 02 10:31:36 2018 -0700
@@ -975,6 +975,35 @@
 
     return fl
 
+def emitfilerevisions(revisions, fields):
+    for revision in revisions:
+        d = {
+            b'node': revision.node,
+        }
+
+        if b'parents' in fields:
+            d[b'parents'] = [revision.p1node, revision.p2node]
+
+        followingmeta = []
+        followingdata = []
+
+        if b'revision' in fields:
+            if revision.revision is not None:
+                followingmeta.append((b'revision', len(revision.revision)))
+                followingdata.append(revision.revision)
+            else:
+                d[b'deltabasenode'] = revision.basenode
+                followingmeta.append((b'delta', len(revision.delta)))
+                followingdata.append(revision.delta)
+
+        if followingmeta:
+            d[b'fieldsfollowing'] = followingmeta
+
+        yield d
+
+        for extra in followingdata:
+            yield extra
+
 @wireprotocommand(
     'filedata',
     args={
@@ -1026,33 +1055,8 @@
         b'totalitems': len(nodes),
     }
 
-    for revision in revisions:
-        d = {
-            b'node': revision.node,
-        }
-
-        if b'parents' in fields:
-            d[b'parents'] = [revision.p1node, revision.p2node]
-
-        followingmeta = []
-        followingdata = []
-
-        if b'revision' in fields:
-            if revision.revision is not None:
-                followingmeta.append((b'revision', len(revision.revision)))
-                followingdata.append(revision.revision)
-            else:
-                d[b'deltabasenode'] = revision.basenode
-                followingmeta.append((b'delta', len(revision.delta)))
-                followingdata.append(revision.delta)
-
-        if followingmeta:
-            d[b'fieldsfollowing'] = followingmeta
-
-        yield d
-
-        for extra in followingdata:
-            yield extra
+    for o in emitfilerevisions(revisions, fields):
+        yield o
 
 @wireprotocommand(
     'heads',