changeset 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 70e76c545606
children b9c8655f12f0
files unixSoft/bin/patchpipe
diffstat 1 files changed, 24 insertions(+), 0 deletions(-) [+]
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)