Mercurial > dotfiles
comparison unixSoft/bin/havepatch @ 372:ce87db9038f5
havepatch: new script to easily check if a mailed patch is applied
Right now this only works on the hg repo, and it assumes the patch was
applied as a descendant of 3.5 to keep the checks quick. In a perfect
world I'd be able to do this all with obsolete marker checks, but that
doesn't seem to be a good option yet.
author | Augie Fackler <raf@durin42.com> |
---|---|
date | Tue, 13 Oct 2015 11:04:51 -0400 |
parents | |
children | d81eb79e4f4c |
comparison
equal
deleted
inserted
replaced
371:7d59b638f711 | 372:ce87db9038f5 |
---|---|
1 #!/usr/bin/env python | |
2 """Detect if a patch is already applied in a Mercurial repository.""" | |
3 import sys | |
4 import subprocess | |
5 import os | |
6 import re | |
7 | |
8 from mercurial import util | |
9 | |
10 def main(argv): | |
11 os.chdir(util.expandpath('~/Programming/hg/crew')) | |
12 os.environ['EDITOR'] = 'true' | |
13 pp = subprocess.Popen(['patchpipe'], stdin=sys.stdin, | |
14 stdout=subprocess.PIPE) | |
15 patchdata = pp.stdout.read() | |
16 summary = (l for l in patchdata.splitlines() | |
17 if not l.startswith('#')).next() | |
18 # First pass: look for exact summary matches after tag 3.5 | |
19 ret = subprocess.call(['hg', 'log', '-r', | |
20 '(not ::3.5) and grep(%r)' % summary]) | |
21 if ret != 0: | |
22 # Failing that, look for obsmarkers that might be relevant. If | |
23 # we could actually do something like 'hg log -r | |
24 # successors($NODE)', that'd be preferable to even the | |
25 # summary-matching from above. | |
26 print 'no exact match in hg log, checking obsmarkers' | |
27 nodematch = re.search('# Node ID ([0-9a-f]{40})', patchdata) | |
28 if nodematch: | |
29 os.system('hg debugobsolete | grep %s' % nodematch.group(1)) | |
30 sys.exit(ret) | |
31 | |
32 if __name__ == '__main__': | |
33 main(sys.argv) |