annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
344
4e83916a4303 patchpipe: tool to edit hg patches while piping them to 'hg import'
Augie Fackler <raf@durin42.com>
parents:
diff changeset
1 #!/usr/bin/env python
4e83916a4303 patchpipe: tool to edit hg patches while piping them to 'hg import'
Augie Fackler <raf@durin42.com>
parents:
diff changeset
2 import os
4e83916a4303 patchpipe: tool to edit hg patches while piping them to 'hg import'
Augie Fackler <raf@durin42.com>
parents:
diff changeset
3 import subprocess
4e83916a4303 patchpipe: tool to edit hg patches while piping them to 'hg import'
Augie Fackler <raf@durin42.com>
parents:
diff changeset
4 import sys
4e83916a4303 patchpipe: tool to edit hg patches while piping them to 'hg import'
Augie Fackler <raf@durin42.com>
parents:
diff changeset
5 import tempfile
4e83916a4303 patchpipe: tool to edit hg patches while piping them to 'hg import'
Augie Fackler <raf@durin42.com>
parents:
diff changeset
6
4e83916a4303 patchpipe: tool to edit hg patches while piping them to 'hg import'
Augie Fackler <raf@durin42.com>
parents:
diff changeset
7 _PATCHHDR = '# HG changeset patch'
4e83916a4303 patchpipe: tool to edit hg patches while piping them to 'hg import'
Augie Fackler <raf@durin42.com>
parents:
diff changeset
8
4e83916a4303 patchpipe: tool to edit hg patches while piping them to 'hg import'
Augie Fackler <raf@durin42.com>
parents:
diff changeset
9
4e83916a4303 patchpipe: tool to edit hg patches while piping them to 'hg import'
Augie Fackler <raf@durin42.com>
parents:
diff changeset
10 def main(argv):
4e83916a4303 patchpipe: tool to edit hg patches while piping them to 'hg import'
Augie Fackler <raf@durin42.com>
parents:
diff changeset
11 tf = tempfile.NamedTemporaryFile(suffix='.diff')
4e83916a4303 patchpipe: tool to edit hg patches while piping them to 'hg import'
Augie Fackler <raf@durin42.com>
parents:
diff changeset
12 d = sys.stdin.read()
4e83916a4303 patchpipe: tool to edit hg patches while piping them to 'hg import'
Augie Fackler <raf@durin42.com>
parents:
diff changeset
13 if _PATCHHDR in d:
4e83916a4303 patchpipe: tool to edit hg patches while piping them to 'hg import'
Augie Fackler <raf@durin42.com>
parents:
diff changeset
14 junk, d = d.split(_PATCHHDR, 1)
4e83916a4303 patchpipe: tool to edit hg patches while piping them to 'hg import'
Augie Fackler <raf@durin42.com>
parents:
diff changeset
15 d = _PATCHHDR + d
4e83916a4303 patchpipe: tool to edit hg patches while piping them to 'hg import'
Augie Fackler <raf@durin42.com>
parents:
diff changeset
16 tf.write(d)
4e83916a4303 patchpipe: tool to edit hg patches while piping them to 'hg import'
Augie Fackler <raf@durin42.com>
parents:
diff changeset
17 tf.flush()
4e83916a4303 patchpipe: tool to edit hg patches while piping them to 'hg import'
Augie Fackler <raf@durin42.com>
parents:
diff changeset
18 subprocess.check_call([os.environ['EDITOR'], tf.name],
4e83916a4303 patchpipe: tool to edit hg patches while piping them to 'hg import'
Augie Fackler <raf@durin42.com>
parents:
diff changeset
19 stdout=sys.stderr)
4e83916a4303 patchpipe: tool to edit hg patches while piping them to 'hg import'
Augie Fackler <raf@durin42.com>
parents:
diff changeset
20 sys.stdout.write(open(tf.name).read())
4e83916a4303 patchpipe: tool to edit hg patches while piping them to 'hg import'
Augie Fackler <raf@durin42.com>
parents:
diff changeset
21
4e83916a4303 patchpipe: tool to edit hg patches while piping them to 'hg import'
Augie Fackler <raf@durin42.com>
parents:
diff changeset
22
4e83916a4303 patchpipe: tool to edit hg patches while piping them to 'hg import'
Augie Fackler <raf@durin42.com>
parents:
diff changeset
23 if __name__ == '__main__':
4e83916a4303 patchpipe: tool to edit hg patches while piping them to 'hg import'
Augie Fackler <raf@durin42.com>
parents:
diff changeset
24 main(argv=sys.argv)