[PATCH 1 of 2] requires: move requires file writing func from localrepo to scmutil

Drew Gottlieb drgott at google.com
Mon May 4 18:27:57 UTC 2015


# HG changeset patch
# User Drew Gottlieb <drgott at google.com>
# Date 1428963107 14400
#      Mon Apr 13 18:11:47 2015 -0400
# Node ID 3f86e3b2548def52732e1f782e89297db8075e8b
# Parent  e5b507efb36e2b9ad8edb1a38459d26c934d74dd
requires: move requires file writing func from localrepo to scmutil

The logic to read a requires file resides in scmutil, so it's only logical that
the logic to write the file should be there too.

And now I've typed logic too many times it no longer looks like a word.
Logically.

diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -353,10 +353,7 @@
             self.svfs.options['usetreemanifest'] = usetreemanifest
 
     def _writerequirements(self):
-        reqfile = self.vfs("requires", "w")
-        for r in sorted(self.requirements):
-            reqfile.write("%s\n" % r)
-        reqfile.close()
+        scmutil.writerequires(self.vfs, self.requirements)
 
     def _checknested(self, path):
         """Determine if path is a legal nested repository."""
diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py
--- a/mercurial/scmutil.py
+++ b/mercurial/scmutil.py
@@ -1011,6 +1011,12 @@
                    " for more information"))
     return requirements
 
+def writerequires(opener, requirements):
+    reqfile = opener("requires", "w")
+    for r in sorted(requirements):
+        reqfile.write("%s\n" % r)
+    reqfile.close()
+
 class filecachesubentry(object):
     def __init__(self, path, stat):
         self.path = path


More information about the Mercurial-devel mailing list