scmutils: read the requires file before writing to avoid unnecessary rewrite
authorArseniy Alekseyev <aalekseyev@janestreet.com>
Thu, 15 Aug 2024 14:54:22 +0100
changeset 51804 e69e3d585f07
parent 51803 45c467d8422c
child 51805 0d7ccb163b4f
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.
mercurial/scmutil.py
--- 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: