obslog: extra patch indentation code
authorPierre-Yves David <pierre-yves.david@octobus.net>
Wed, 21 Jun 2017 11:11:37 +0200
changeset 2638 9290f985868c
parent 2637 49f2741c4dd7
child 2639 a5d8062f55ba
obslog: extra patch indentation code The code is simple and we need to reuse it.
hgext3rd/evolve/obshistory.py
--- a/hgext3rd/evolve/obshistory.py	Tue Jun 20 13:49:40 2017 +0200
+++ b/hgext3rd/evolve/obshistory.py	Wed Jun 21 11:11:37 2017 +0200
@@ -141,6 +141,10 @@
 
     return True, succ
 
+def _indent(content, indent=4):
+    extra = ' ' * indent
+    return "".join(extra + line for line in content.splitlines(True))
+
 def getmarkerpatch(repo, node, succ):
     # Todo get the ops from the cmd
     diffopts = patch.diffallopts(repo.ui, {})
@@ -151,10 +155,7 @@
                            match=matchfn, stat=False)
     buffer = repo.ui.popbuffer()
 
-    # Indent the buffer a little
-    splitted = buffer.splitlines(True)
-    splitted = ['    %s' % line for line in splitted]
-    return "".join(splitted)
+    return _indent(buffer)
 
 class missingchangectx(object):
     ''' a minimal object mimicking changectx for change contexts