scmutils: read the requires file before writing to avoid unnecessary rewrite
This lets us get away without the repo lock in situations where we need
to write requirements, but we know we're not changing the store requirements.
--- a/mercurial/scmutil.py Thu Aug 15 14:56:50 2024 +0100
+++ b/mercurial/scmutil.py Thu Aug 15 14:54:22 2024 +0100
@@ -1702,9 +1702,11 @@
def writerequires(opener, requirements) -> None:
- with opener(b'requires', b'w', atomictemp=True) as fp:
- for r in sorted(requirements):
- fp.write(b"%s\n" % r)
+ on_disk = readrequires(opener, True)
+ if not (on_disk == set(requirements)):
+ with opener(b'requires', b'w', atomictemp=True) as fp:
+ for r in sorted(requirements):
+ fp.write(b"%s\n" % r)
class filecachesubentry: