Patchwork [02,of,15] util: move 'readexactly' in the util module

login
register
mail settings
Submitter Boris Feld
Date Jan. 19, 2018, 8:08 p.m.
Message ID <f6baa2844ea380da1a63.1516392526@FB>
Download mbox | patch
Permalink /patch/26956/
State Deferred, archived
Headers show

Comments

Boris Feld - Jan. 19, 2018, 8:08 p.m.
# HG changeset patch
# User Boris Feld <boris.feld@octobus.net>
# Date 1516391495 -3600
#      Fri Jan 19 20:51:35 2018 +0100
# Node ID f6baa2844ea380da1a63832a35b1b83007c181a3
# Parent  bb08b77c4988817b0ff2d25e705b455169868c7e
# EXP-Topic b2-stream
# Available At https://bitbucket.org/octobus/mercurial-devel/
#              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r f6baa2844ea3
util: move 'readexactly' in the util module

This function is used in multiple place, having it in util would be better.
(existing caller will be migrated in another series)

Patch

diff --git a/mercurial/changegroup.py b/mercurial/changegroup.py
--- a/mercurial/changegroup.py
+++ b/mercurial/changegroup.py
@@ -32,14 +32,7 @@  from . import (
 _CHANGEGROUPV2_DELTA_HEADER = "20s20s20s20s20s"
 _CHANGEGROUPV3_DELTA_HEADER = ">20s20s20s20s20sH"
 
-def readexactly(stream, n):
-    '''read n bytes from stream.read and abort if less was available'''
-    s = stream.read(n)
-    if len(s) < n:
-        raise error.Abort(_("stream ended unexpectedly"
-                           " (got %d bytes, expected %d)")
-                          % (len(s), n))
-    return s
+readexactly = util.readexactly
 
 def getchunk(stream):
     """return the next chunk from stream as a string"""
diff --git a/mercurial/util.py b/mercurial/util.py
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -3865,3 +3865,12 @@  def safename(f, tag, ctx, others=None):
         fn = '%s~%s~%s' % (f, tag, n)
         if fn not in ctx and fn not in others:
             return fn
+
+def readexactly(stream, n):
+    '''read n bytes from stream.read and abort if less was available'''
+    s = stream.read(n)
+    if len(s) < n:
+        raise error.Abort(_("stream ended unexpectedly"
+                           " (got %d bytes, expected %d)")
+                          % (len(s), n))
+    return s