scmutil: add `readrequires` next to `writerequires`
authorArseniy Alekseyev <aalekseyev@janestreet.com>
Thu, 15 Aug 2024 14:53:17 +0100
changeset 51802 eb952b2d224c
parent 51801 62b25293b620
child 51803 45c467d8422c
scmutil: add `readrequires` next to `writerequires` The code is copied from localrepo.py.
mercurial/scmutil.py
--- a/mercurial/scmutil.py	Wed Aug 14 03:25:16 2024 -0400
+++ b/mercurial/scmutil.py	Thu Aug 15 14:53:17 2024 +0100
@@ -1687,6 +1687,20 @@
         repo.svfs.tryunlink(b'requires')
 
 
+def readrequires(vfs, allowmissing):
+    """reads the require file present at root of this vfs
+    and return a set of requirements
+
+    If allowmissing is True, we suppress FileNotFoundError if raised"""
+    # requires file contains a newline-delimited list of
+    # features/capabilities the opener (us) must have in order to use
+    # the repository. This file was introduced in Mercurial 0.9.2,
+    # which means very old repositories may not have one. We assume
+    # a missing file translates to no requirements.
+    read = vfs.tryread if allowmissing else vfs.read
+    return set(read(b'requires').splitlines())
+
+
 def writerequires(opener, requirements) -> None:
     with opener(b'requires', b'w', atomictemp=True) as fp:
         for r in sorted(requirements):