Mercurial > public > mercurial-scm > hg
comparison mercurial/scmutil.py @ 51798: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 | 43460c311c0c |
children | e69e3d585f07 |
comparison
equal
deleted
inserted
replaced
51797:62b25293b620 | 51798:eb952b2d224c |
---|---|
1685 elif repo.ui.configbool(b'format', b'usestore'): | 1685 elif repo.ui.configbool(b'format', b'usestore'): |
1686 # only remove store requires if we are using store | 1686 # only remove store requires if we are using store |
1687 repo.svfs.tryunlink(b'requires') | 1687 repo.svfs.tryunlink(b'requires') |
1688 | 1688 |
1689 | 1689 |
1690 def readrequires(vfs, allowmissing): | |
1691 """reads the require file present at root of this vfs | |
1692 and return a set of requirements | |
1693 | |
1694 If allowmissing is True, we suppress FileNotFoundError if raised""" | |
1695 # requires file contains a newline-delimited list of | |
1696 # features/capabilities the opener (us) must have in order to use | |
1697 # the repository. This file was introduced in Mercurial 0.9.2, | |
1698 # which means very old repositories may not have one. We assume | |
1699 # a missing file translates to no requirements. | |
1700 read = vfs.tryread if allowmissing else vfs.read | |
1701 return set(read(b'requires').splitlines()) | |
1702 | |
1703 | |
1690 def writerequires(opener, requirements) -> None: | 1704 def writerequires(opener, requirements) -> None: |
1691 with opener(b'requires', b'w', atomictemp=True) as fp: | 1705 with opener(b'requires', b'w', atomictemp=True) as fp: |
1692 for r in sorted(requirements): | 1706 for r in sorted(requirements): |
1693 fp.write(b"%s\n" % r) | 1707 fp.write(b"%s\n" % r) |
1694 | 1708 |