Patchwork [11,of,11] changelog: assert that revlog files are opened with bytes in the mode

login
register
mail settings
Submitter Augie Fackler
Date March 26, 2017, 10:36 p.m.
Message ID <224f1d7dd46f52b3a102.1490567805@imladris.local>
Download mbox | patch
Permalink /patch/19710/
State Accepted
Headers show

Comments

Augie Fackler - March 26, 2017, 10:36 p.m.
# HG changeset patch
# User Augie Fackler <raf@durin42.com>
# Date 1490567481 14400
#      Sun Mar 26 18:31:21 2017 -0400
# Node ID 224f1d7dd46f52b3a10237d86f6dfbc0dcf4eada
# Parent  c5ecedb198527765f465da499c37cc53fc38ea53
changelog: assert that revlog files are opened with bytes in the mode

This helped me catch several opener errors, so I'm somewhat inclined
to keep it around, but I don't feel strongly either way.

Patch

diff --git a/mercurial/changelog.py b/mercurial/changelog.py
--- a/mercurial/changelog.py
+++ b/mercurial/changelog.py
@@ -127,6 +127,7 @@  class appender(object):
 def _divertopener(opener, target):
     """build an opener that writes in 'target.a' instead of 'target'"""
     def _divert(name, mode='rb', checkambig=False):
+        assert 'b' in mode, 'must open revlogs in binary mode! got %r' % mode
         if name != target:
             return opener(name, mode)
         return opener(name + ".a", mode)
@@ -135,6 +136,7 @@  def _divertopener(opener, target):
 def _delayopener(opener, target, buf):
     """build an opener that stores chunks in 'buf' instead of 'target'"""
     def _delay(name, mode='rb', checkambig=False):
+        assert 'b' in mode
         if name != target:
             return opener(name, mode)
         return appender(opener, name, mode, buf)