changeset 51804:e69e3d585f07

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.
author Arseniy Alekseyev <aalekseyev@janestreet.com>
date Thu, 15 Aug 2024 14:54:22 +0100
parents 45c467d8422c
children 0d7ccb163b4f
files mercurial/scmutil.py
diffstat 1 files changed, 5 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- 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: