changeset 51802:eb952b2d224c

scmutil: add `readrequires` next to `writerequires` The code is copied from localrepo.py.
author Arseniy Alekseyev <aalekseyev@janestreet.com>
date Thu, 15 Aug 2024 14:53:17 +0100
parents 62b25293b620
children 45c467d8422c
files mercurial/scmutil.py
diffstat 1 files changed, 14 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- 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):