Merge lp:~henninge/launchpad/on-edge into lp:launchpad

Proposed by Henning Eggers
Status: Merged
Approved by: Jeroen T. Vermeulen
Approved revision: not available
Merged at revision: not available
Proposed branch: lp:~henninge/launchpad/on-edge
Merge into: lp:launchpad
Diff against target: 79 lines (+43/-8)
1 file modified
utilities/on-edge (+43/-8)
To merge this branch: bzr merge lp:~henninge/launchpad/on-edge
Reviewer Review Type Date Requested Status
Jeroen T. Vermeulen (community) code Approve
Review via email: mp+18454@code.launchpad.net

Commit message

Improved the on-edge script to display the last automatic merge on db-stable.

To post a comment you must log in.
Revision history for this message
Henning Eggers (henninge) wrote :

Improved jml's "on-edge" script to show the last automatic merge on db-stable. Very useful if you can't wait to QA your branch on staging!

Also fixed a bug where the code was passing a string into dotted_revno_to_revision_id instead of a tuple, thus causing it to always throw an exception.

Finally, the script now also dectects when the local copy of a branch is actually older than what's on edge/staging.

Revision history for this message
Jeroen T. Vermeulen (jtv) wrote :

Looks fine. A few nits: "res" is not a very good variable name, so use "match" instead. Double blank line above get_last_automatic_stable_merge_revno. That's about it.

review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'utilities/on-edge'
2--- utilities/on-edge 2010-02-01 23:41:00 +0000
3+++ utilities/on-edge 2010-02-02 18:36:26 +0000
4@@ -61,25 +61,58 @@
5 return os.path.dirname(os.path.dirname(os.path.dirname(this_file)))
6
7
8+def print_revisions(branch, end_id):
9+ """Output revision messages up to end_id."""
10+ rev_iter = branch.iter_merge_sorted_revisions(
11+ None, end_id, 'include')
12+ for rev_info in rev_iter:
13+ (rev_id, depth, revno, end_of_merge) = rev_info
14+ if depth > 0:
15+ continue
16+ revision = branch.repository.get_revision(rev_id)
17+ revno_str = ".".join(map(str, revno))
18+ print "r%s:\n%s" % (revno_str, revision.message)
19+
20+
21 def report_difference_to_server(server, branch_path, revno, verbose):
22+ """Output if and how the local branch differs from the server."""
23 branch = Branch.open(branch_path)
24- print '%s is running %s r%s' % (server, branch.nick, revno)
25+ print '%s is running %s r%d.' % (server, branch.nick, revno)
26 try:
27- branch.dotted_revno_to_revision_id(str(revno + 1))
28+ current_id = branch.dotted_revno_to_revision_id((revno,))
29 except errors.NoSuchRevision:
30- print '%s is up-to-date' % (server,)
31+ print '%s has newer revisions than %s.' % (server, branch.nick)
32 else:
33- if verbose:
34- command = 'bzr log -r%s.. %s' % (revno, branch_path)
35- os.system(command)
36- print
37+ if current_id == branch.last_revision():
38+ print '%s is up-to-date.' % (server,)
39+ else:
40+ if verbose:
41+ print_revisions(branch, current_id)
42+
43+
44+automatic_merge_regex = re.compile(
45+ "automatic merge from stable[.] "
46+ "Revisions:[0-9,\s]*\s+([0-9]+)\s+included")
47+
48+
49+def get_last_automatic_stable_merge_revno(branch_path):
50+ """Find out which stable revision was last commited to db-stable."""
51+ branch = Branch.open(branch_path)
52+ for rev_info in branch.iter_merge_sorted_revisions():
53+ (rev_id, depth, revno, end_of_merge) = rev_info
54+ if depth > 0:
55+ continue
56+ revision = branch.repository.get_revision(rev_id)
57+ match = automatic_merge_regex.search(revision.message)
58+ if match is not None:
59+ return match.group(1)
60
61
62 def get_opt_parse():
63 parser = optparse.OptionParser(
64 description="Show local revisions that aren't on beta servers.")
65 parser.add_option(
66- '-v', '--verbose', action='store_true', help="Show revision log")
67+ '-v', '--verbose', action='store_true', help="Show revision log.")
68 parser.add_option(
69 '--edge-only', action='store_true',
70 help="Only show revisions not on edge. Do not consult staging.")
71@@ -103,6 +136,8 @@
72 db_stable_branch = os.path.join(parent_dir, 'db-stable')
73 report_difference_to_server(
74 'staging', db_stable_branch, staging_revision, verbose)
75+ print "Last automatic merge on db-stable was stable r%s." % (
76+ get_last_automatic_stable_merge_revno(db_stable_branch),)
77
78
79 def main(argv):