diff unixSoft/bin/patchpipe @ 344:4e83916a4303

patchpipe: tool to edit hg patches while piping them to 'hg import'
author Augie Fackler <raf@durin42.com>
date Wed, 10 Sep 2014 14:52:50 -0400
parents
children c7a9cd793e37
line wrap: on
line diff
new file mode 100755
--- /dev/null
+++ b/unixSoft/bin/patchpipe
@@ -0,0 +1,24 @@
+#!/usr/bin/env python
+import os
+import subprocess
+import sys
+import tempfile
+
+_PATCHHDR = '# HG changeset patch'
+
+
+def main(argv):
+    tf = tempfile.NamedTemporaryFile(suffix='.diff')
+    d = sys.stdin.read()
+    if _PATCHHDR in d:
+        junk, d = d.split(_PATCHHDR, 1)
+        d = _PATCHHDR + d
+    tf.write(d)
+    tf.flush()
+    subprocess.check_call([os.environ['EDITOR'], tf.name],
+                          stdout=sys.stderr)
+    sys.stdout.write(open(tf.name).read())
+
+
+if __name__ == '__main__':
+    main(argv=sys.argv)