Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/util.py @ 35754:fb0be099063f
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)
author | Boris Feld <boris.feld@octobus.net> |
---|---|
date | Fri, 19 Jan 2018 20:51:35 +0100 |
parents | 72b91f905065 |
children | 2384523cee4d |
comparison
equal
deleted
inserted
replaced
35753:069df0b952e8 | 35754:fb0be099063f |
---|---|
3863 return fn | 3863 return fn |
3864 for n in itertools.count(1): | 3864 for n in itertools.count(1): |
3865 fn = '%s~%s~%s' % (f, tag, n) | 3865 fn = '%s~%s~%s' % (f, tag, n) |
3866 if fn not in ctx and fn not in others: | 3866 if fn not in ctx and fn not in others: |
3867 return fn | 3867 return fn |
3868 | |
3869 def readexactly(stream, n): | |
3870 '''read n bytes from stream.read and abort if less was available''' | |
3871 s = stream.read(n) | |
3872 if len(s) < n: | |
3873 raise error.Abort(_("stream ended unexpectedly" | |
3874 " (got %d bytes, expected %d)") | |
3875 % (len(s), n)) | |
3876 return s |