hgmolib: open file in regular mode when parsing `requires` files (Bug 1727342) r=zeid
authorConnor Sheehan <sheehan@mozilla.com>
Tue, 24 Aug 2021 16:03:47 +0000
changeset 7723 108acc3026467634ad5ef1d032088181efff4914
parent 7722 af87b4de9db82d9e7f20cd0389e375de5f8f521f
child 7724 b9a13f98f0cf6d8533e67f63430a6409f673d0c8
push id3863
push usercosheehan@mozilla.com
push dateTue, 24 Aug 2021 16:05:52 +0000
treeherderversion-control-tools@177006efefb3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerszeid
bugs1727342
hgmolib: open file in regular mode when parsing `requires` files (Bug 1727342) r=zeid The value for `--requirement` was being passed as a `str`, while the was being read and each line in the file was passed as a `bytes`, leading to comparisons like `"store" == b"store"`, which is `False`. Opening the file in regular read mode makes both values `str` and the comparison is correct again. Depends on D123479 Differential Revision: https://phabricator.services.mozilla.com/D123480
hgserver/hgmolib/hgmolib/environment.py
--- a/hgserver/hgmolib/hgmolib/environment.py
+++ b/hgserver/hgmolib/hgmolib/environment.py
@@ -54,18 +54,18 @@ def script_find_hg_repos():
                 return False
 
         if args.hgrc:
             if not os.path.exists(os.path.join(path, '.hg', 'hgrc')):
                 return False
 
         if args.requirement or args.no_requirement:
             try:
-                with open(os.path.join(path, '.hg', 'requires'), 'rb') as fh:
-                    requirements = set(fh.read().split())
+                with open(os.path.join(path, '.hg', 'requires'), 'r') as fh:
+                    requirements = set(fh.read().splitlines())
             except IOError as e:
                 if e.errno != errno.ENOENT:
                     raise
 
                 requirements = set()
 
             if args.requirement and args.requirement not in requirements:
                 return False