Merge lp:~gary/launchpad/bug643715 into lp:launchpad

Proposed by Gary Poster
Status: Work in progress
Proposed branch: lp:~gary/launchpad/bug643715
Merge into: lp:launchpad
Diff against target: 96 lines (+28/-9)
1 file modified
lib/devscripts/sourcecode.py (+28/-9)
To merge this branch: bzr merge lp:~gary/launchpad/bug643715
Reviewer Review Type Date Requested Status
Aaron Bentley (community) Needs Fixing
Jonathan Lange (community) Approve
Review via email: mp+36060@code.launchpad.net

Description of the change

This was just a quick itch to scratch as I was updating my tree after being away for a week. It makes calling update-sourcecode much faster.

To test, run

./utilities/update-sourcecode

If you want to play around, you can change utilities/sourcedeps.conf to revert a revision, then run update-sourcecode, and then change the revision back. I could optimize that too, but I don't think that's an important win for the common case, so I'm not worrying about it.

I made a variety of changes for lint, even though some of them didn't make a lot of sense to me. I was surprised in particular by the preference for ('foo', ) over ('foo',). It's alright.

Gary

To post a comment you must log in.
Revision history for this message
Jonathan Lange (jml) wrote :

Its preference for (foo, ) over (foo,) is wrong. Every linting tool that isn't pyflakes is terrible.

Thanks for doing this.

review: Approve
Revision history for this message
Aaron Bentley (abentley) wrote :

This branch treats revnos as if they were revision ids, which means that it may not notice cases where uncommit or push --overwrite have been used.

It also appears not to account for changes in the branch location.

It also assumes that "revision" is a revno, when other parts of the code treat it as a RevisionSpec instead.

review: Needs Fixing
Revision history for this message
Gary Poster (gary) wrote :

My change was an optimization for the common case. What we had already was "correct" for the edge cases you identified.

On one hand:

- I could make an additional change to handle the case of change in the branch location.

- We use revnos only, practically, so I think that's fine, myself.

However:

- I don't see how to handle an uncommit or an --overwrite.

I think those are pretty unlikely cases, but if we care about handling them, I think this is dead in the water. In that case, Aaron, isn't this actually a Rejected?

Revision history for this message
Aaron Bentley (abentley) wrote :

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 09/20/2010 04:03 PM, Gary Poster wrote:
> My change was an optimization for the common case. What we had already was "correct" for the edge cases you identified.
>
> On one hand:
>
> - I could make an additional change to handle the case of change in the branch location.
>
> - We use revnos only, practically, so I think that's fine, myself.

That's as may be, but it's actually faster and requires less code to
convert from revision_spec to revision_id and then compare to
wt.last_revision().

> However:
>
> - I don't see how to handle an uncommit or an --overwrite.

You could handle both branch location changes and revno redefinition by
auto-generating a list of revision-ids from update-sourcecode. The
output of this would need to be versioned.

> I think those are pretty unlikely cases

Also, there's merge trunk, commit, push to trunk.

But given that these are all PQM-managed branches and everyone who has
write access to them is pretty sane, I guess I'd agree that those cases
are unlikely.

, but if we care about handling them, I think this is dead in the water.
 In that case, Aaron, isn't this actually a Rejected?

I think we can make it faster without making it less effective.

Aaron
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkyXzFAACgkQ0F+nu1YWqI1pcQCgiU2lEcyIcXnrvBZaAw1Izulj
jVkAn09Z9jlR13ZuWc5Wgv6plAm4nl0p
=YDgF
-----END PGP SIGNATURE-----

Unmerged revisions

11582. By Gary Poster

make lint happy

11581. By Gary Poster

import missing exception

11580. By Gary Poster

optimize case in sourcecode update of already being on the desired revision.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'lib/devscripts/sourcecode.py'
--- lib/devscripts/sourcecode.py 2010-04-19 11:05:07 +0000
+++ lib/devscripts/sourcecode.py 2010-09-20 19:31:23 +0000
@@ -16,7 +16,11 @@
16import sys16import sys
1717
18from bzrlib.branch import Branch18from bzrlib.branch import Branch
19from bzrlib.errors import BzrError, NotBranchError, IncompatibleRepositories19from bzrlib.errors import (
20 BzrError,
21 NotBranchError,
22 IncompatibleRepositories,
23 NoSuchRevision)
20from bzrlib.plugin import load_plugins24from bzrlib.plugin import load_plugins
21from bzrlib.revisionspec import RevisionSpec25from bzrlib.revisionspec import RevisionSpec
22from bzrlib.trace import enable_default_logging, report_exception26from bzrlib.trace import enable_default_logging, report_exception
@@ -135,14 +139,13 @@
135 return spec.as_revision_id(from_branch)139 return spec.as_revision_id(from_branch)
136 # else return None140 # else return None
137141
138
139def _format_revision_name(revision, tip=False):142def _format_revision_name(revision, tip=False):
140 """Formatting helper to return human-readable identifier for revision.143 """Formatting helper to return human-readable identifier for revision.
141144
142 If ``tip`` is True, the revision value will be ignored.145 If ``tip`` is True, the revision value will be ignored.
143 """146 """
144 if not tip and revision:147 if not tip and revision:
145 return 'revision %s' % (revision,)148 return 'revision %s' % (revision, )
146 else:149 else:
147 return 'tip'150 return 'tip'
148151
@@ -178,6 +181,17 @@
178 possible_transports=possible_transports)181 possible_transports=possible_transports)
179182
180183
184def get_revno(wt):
185 """Get the revno of a working tree."""
186 # Ripped from bzrlib.builtins.cmd_revno.run.
187 revid = wt.last_revision()
188 try:
189 revno_t = wt.branch.revision_id_to_dotted_revno(revid)
190 except NoSuchRevision:
191 revno_t = ('???', )
192 return ".".join(str(n) for n in revno_t)
193
194
181def update_branches(sourcecode_directory, update_branches,195def update_branches(sourcecode_directory, update_branches,
182 possible_transports=None, tip=False, quiet=False):196 possible_transports=None, tip=False, quiet=False):
183 """Update the existing branches in sourcecode."""197 """Update the existing branches in sourcecode."""
@@ -193,6 +207,12 @@
193 print 'Updating %s to %s' % (207 print 'Updating %s to %s' % (
194 project, _format_revision_name(revision, tip))208 project, _format_revision_name(revision, tip))
195 local_tree = WorkingTree.open(destination)209 local_tree = WorkingTree.open(destination)
210 # See if we can shortcut: do we already have the desired revision?
211 if not tip and revision == get_revno(local_tree):
212 if not quiet:
213 print ' (No change)'
214 continue
215 # Apparently we do not. Open the remote branch.
196 try:216 try:
197 remote_branch = Branch.open(217 remote_branch = Branch.open(
198 branch_url, possible_transports=possible_transports)218 branch_url, possible_transports=possible_transports)
@@ -210,10 +230,10 @@
210 remote_branch, stop_revision=revision_id, overwrite=True,230 remote_branch, stop_revision=revision_id, overwrite=True,
211 possible_transports=possible_transports)231 possible_transports=possible_transports)
212 except IncompatibleRepositories:232 except IncompatibleRepositories:
213 # XXX JRV 20100407: Ideally remote_branch.bzrdir._format 233 # XXX JRV 20100407: Ideally remote_branch.bzrdir._format
214 # should be passed into upgrade() to ensure the format is the same234 # should be passed into upgrade() to ensure the format is the same
215 # locally and remotely. Unfortunately smart server branches 235 # locally and remotely. Unfortunately smart server branches
216 # have their _format set to RemoteFormat rather than an actual 236 # have their _format set to RemoteFormat rather than an actual
217 # format instance.237 # format instance.
218 upgrade(destination)238 upgrade(destination)
219 # Upgraded, repoen working tree239 # Upgraded, repoen working tree
@@ -277,7 +297,6 @@
277# differ from each other (because of developers fiddling with things), we can297# differ from each other (because of developers fiddling with things), we can
278# take a survey of all of them, and choose the most popular.298# take a survey of all of them, and choose the most popular.
279299
280
281def main(args):300def main(args):
282 parser = optparse.OptionParser("usage: %prog [options] [root [conffile]]")301 parser = optparse.OptionParser("usage: %prog [options] [root [conffile]]")
283 parser.add_option(302 parser.add_option(
@@ -305,8 +324,8 @@
305 if len(args) > 3:324 if len(args) > 3:
306 parser.error("Too many arguments.")325 parser.error("Too many arguments.")
307 if not options.quiet:326 if not options.quiet:
308 print 'Sourcecode: %s' % (sourcecode_directory,)327 print 'Sourcecode: %s' % (sourcecode_directory, )
309 print 'Config: %s' % (config_filename,)328 print 'Config: %s' % (config_filename, )
310 enable_default_logging()329 enable_default_logging()
311 # Tell bzr to use the terminal (if any) to show progress bars330 # Tell bzr to use the terminal (if any) to show progress bars
312 ui.ui_factory = ui.make_ui_for_terminal(331 ui.ui_factory = ui.make_ui_for_terminal(