diff mercurial/sparse.py @ 33303:8b571495d811

sparse: move config file writing into core The code was refactored during the move to be more procedural instead of using string formatting. This has the benefit of not writing empty sections, which changed tests.
author Gregory Szorc <gregory.szorc@gmail.com>
date Thu, 06 Jul 2017 12:24:55 -0700
parents 36a415b5a4b2
children 3e1accab7447
line wrap: on
line diff
--- a/mercurial/sparse.py	Thu Jul 06 12:20:53 2017 -0700
+++ b/mercurial/sparse.py	Thu Jul 06 12:24:55 2017 -0700
@@ -129,3 +129,23 @@
 
 def invalidatesignaturecache(repo):
     repo._sparsesignaturecache.clear()
+
+def writeconfig(repo, includes, excludes, profiles):
+    """Write the sparse config file given a sparse configuration."""
+    with repo.vfs('sparse', 'wb') as fh:
+        for p in sorted(profiles):
+            fh.write('%%include %s\n' % p)
+
+        if includes:
+            fh.write('[include]\n')
+            for i in sorted(includes):
+                fh.write(i)
+                fh.write('\n')
+
+        if excludes:
+            fh.write('[exclude]\n')
+            for e in sorted(excludes):
+                fh.write(e)
+                fh.write('\n')
+
+    invalidatesignaturecache(repo)