Follow-up to r29036: Now that the "mergeinfo" transaction file is no
[svn.git] / tools / dev / svn-merge-revs.py
blob05738da508d3376827198301e29e2fb172c7a3b3
1 #!/usr/bin/env python
3 import sys
4 import os
6 progname = os.path.basename(sys.argv[0])
8 def usage():
9 print "Usage: %s SOURCEURL WCPATH [r]REVNUM[,] [...]" % progname
10 print "Try '%s --help' for more information" % progname
12 def help():
13 val = """This script is meant to ease the pain of merging and
14 reviewing revision(s) on a release branch (although it can be used to
15 merge and review revisions from any line of development to another).
17 To allow cutting and pasting from the STATUS file, revision numbers
18 can be space or comma-separated, and may also include the prefix
19 'r'.
21 Lastly, a file (named 'rev1-rev2-rev3.log') is created for you.
22 This file contains each merge command that was run, the log of the
23 revision that was merged, and the diff from the previous revision.
25 Examples:
27 %s http://svn.collab.net/repos/svn/trunk svn-1.2.x-branch \
28 r14041, r14149, r14186, r14194, r14238, r14273
30 %s http://svn.collab.net/repos/svn/trunk svn-1.2.x-branch \
31 14041 14149 14186 14194 14238 14273""" % (progname, progname)
32 print val
35 if len(sys.argv) > 1 and sys.argv[1] == '--help':
36 help()
37 sys.exit(0)
39 if len(sys.argv) < 4:
40 usage()
41 sys.exit(255)
43 src_url = sys.argv[1]
44 wc_path = sys.argv[2]
46 # Tolerate comma separated lists of revs (e.g. "r234, r245, r251")
47 revs = []
48 for rev in sys.argv[3:]:
49 orig_rev = rev
50 if rev[-1:] == ',':
51 rev = rev[:-1]
53 if rev[:1] == 'r':
54 rev = rev[1:]
56 try:
57 rev = int(rev)
58 except ValueError:
59 print "Encountered non integer revision '%s'" % orig_rev
60 usage()
61 sys.exit(254)
62 revs.append(rev)
64 # Make an easily reviewable logfile
65 logfile = "-".join(map(lambda x: str(x), revs)) + ".log"
66 log = open(logfile, 'w')
68 for rev in revs:
69 merge_cmd = ("svn merge -r%i:%i %s %s" % (rev - 1, rev, src_url, wc_path))
70 log_cmd = 'svn log -v -r%i %s' % (rev, src_url)
71 diff_cmd = 'svn diff -r%i:%i %s' % (rev -1, rev, src_url)
73 # Do the merge
74 os.system(merge_cmd)
76 # Write our header
77 log.write("=" * 72 + '\n')
78 log.write(merge_cmd + '\n')
80 # Get our log
81 fh = os.popen(log_cmd)
82 while 1:
83 line = fh.readline()
84 if not line:
85 break
86 log.write(line)
87 fh.close()
89 # Get our diff
90 fh = os.popen(diff_cmd)
91 while 1:
92 line = fh.readline()
93 if not line:
94 break
95 log.write(line)
97 # Write our footer
98 log.write("=" * 72 + '\n' * 10)
101 log.close()
102 print "\nYour logfile is '%s'" % logfile