diff -r 36a415b5a4b2 -r 8b571495d811 mercurial/sparse.py --- 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)