Merge lp:~abentley/launchpad/fix-update-cache into lp:launchpad

Proposed by Aaron Bentley
Status: Merged
Merged at revision: 13197
Proposed branch: lp:~abentley/launchpad/fix-update-cache
Merge into: lp:launchpad
Diff against target: 56 lines (+11/-8)
1 file modified
lib/devscripts/sourcecode.py (+11/-8)
To merge this branch: bzr merge lp:~abentley/launchpad/fix-update-cache
Reviewer Review Type Date Requested Status
Graham Binns (community) code Approve
Review via email: mp+63717@code.launchpad.net

Commit message

Fix stale cache detection

Description of the change

= Summary =
Fix bug #794088: update-sourcecode updates cache when already up-to-date

== Proposed fix ==
Change the check for whether to write the cache so that it is written only if it has changed.

== Pre-implementation notes ==
None

== Implementation details ==
We have to listify the last revision so that it is not a tuple (old cache values have lists, not tuples).

== Tests ==
None

== Demo and Q/A ==
Create a stale branch in sourcecode, e.g. by using "bzr pull --overwrite -r -2"
Run utilities/update-sourcecode

The branch will be updated, but the cache file will not be updated, and it will not print a message advising you to commit the cache file.

= Launchpad lint =

Checking for conflicts and issues in changed files.

Linting changed files:
  lib/devscripts/sourcecode.py

To post a comment you must log in.
Revision history for this message
Graham Binns (gmb) :
review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/devscripts/sourcecode.py'
2--- lib/devscripts/sourcecode.py 2011-05-24 17:13:58 +0000
3+++ lib/devscripts/sourcecode.py 2011-06-09 03:02:44 +0000
4@@ -63,6 +63,7 @@
5 optional = False
6 return branch_name, branch_url, revision, optional
7
8+
9 def load_cache(cache_filename):
10 try:
11 cache_file = open(cache_filename, 'rb')
12@@ -74,6 +75,7 @@
13 with cache_file:
14 return json.load(cache_file)
15
16+
17 def interpret_config(config_entries, public_only):
18 """Interpret a configuration stream, as parsed by 'parse_config_file'.
19
20@@ -214,16 +216,17 @@
21
22 def update_cache(cache, cache_filename, changed, sourcecode_directory, quiet):
23 """Update the cache with the changed branches."""
24- if len(changed) == 0:
25- return
26- if not quiet:
27- print 'Cache updated. Please commit "%s".' % cache_filename
28+ old_cache = dict(cache)
29 for project, (branch_url, revision, optional) in changed.iteritems():
30 destination = os.path.join(sourcecode_directory, project)
31 branch = Branch.open(destination)
32- cache[project] = branch.last_revision_info()
33+ cache[project] = list(branch.last_revision_info())
34+ if cache == old_cache:
35+ return
36 with open(cache_filename, 'wb') as cache_file:
37 json.dump(cache, cache_file, indent=4)
38+ if not quiet:
39+ print 'Cache updated. Please commit "%s".' % cache_filename
40
41
42 def update_branches(sourcecode_directory, update_branches,
43@@ -258,10 +261,10 @@
44 remote_branch, stop_revision=revision_id, overwrite=True,
45 possible_transports=possible_transports)
46 except IncompatibleRepositories:
47- # XXX JRV 20100407: Ideally remote_branch.bzrdir._format
48+ # XXX JRV 20100407: Ideally remote_branch.bzrdir._format
49 # should be passed into upgrade() to ensure the format is the same
50- # locally and remotely. Unfortunately smart server branches
51- # have their _format set to RemoteFormat rather than an actual
52+ # locally and remotely. Unfortunately smart server branches
53+ # have their _format set to RemoteFormat rather than an actual
54 # format instance.
55 upgrade(destination)
56 # Upgraded, repoen working tree