Merge lp:~jelmer/bzr-builddeb/722217-avoid-o-history into lp:bzr-builddeb

Proposed by Jelmer Vernooij
Status: Merged
Merged at revision: 524
Proposed branch: lp:~jelmer/bzr-builddeb/722217-avoid-o-history
Merge into: lp:bzr-builddeb
Diff against target: 135 lines (+29/-26)
3 files modified
cmds.py (+1/-1)
tests/test_upstream.py (+11/-9)
upstream/branch.py (+17/-16)
To merge this branch: bzr merge lp:~jelmer/bzr-builddeb/722217-avoid-o-history
Reviewer Review Type Date Requested Status
James Westby Approve
Review via email: mp+50628@code.launchpad.net

Description of the change

Avoid constructing the full upstream branch history when merging from an upstream branch. This can be quite expensive for large upstream branches, and is unnecessary.

To post a comment you must log in.
Revision history for this message
James Westby (james-w) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'cmds.py'
2--- cmds.py 2011-02-11 14:29:07 +0000
3+++ cmds.py 2011-02-21 16:22:07 +0000
4@@ -323,7 +323,7 @@
5 upstream_revision = upstream_branch.last_revision()
6 else:
7 upstream_revision = upstream_source.version_as_revision(
8- version)
9+ None, str(version))
10 finally:
11 upstream_branch.unlock()
12 return (upstream_branch, upstream_revision)
13
14=== modified file 'tests/test_upstream.py'
15--- tests/test_upstream.py 2011-02-11 14:21:19 +0000
16+++ tests/test_upstream.py 2011-02-21 16:22:07 +0000
17@@ -368,7 +368,7 @@
18 """
19
20 def get_suffix(self, version_string, revid):
21- revno = self.revhistory.index(revid)+1
22+ revno = len(self.revhistory) - self.revhistory.index(revid)
23 if "bzr" in version_string:
24 return "%sbzr%d" % (version_string.split("bzr")[0], revno)
25 return "%s+bzr%d" % (version_string, revno)
26@@ -390,18 +390,20 @@
27 _upstream_branch_version(self.revhistory, {"somerevid": ["1.3"]}, "bla", "1.2", self.get_suffix))
28
29 def test_refresh_snapshot_pre(self):
30- self.revhistory = ["oldrevid", "somerevid"]
31- self.assertEquals(Version("1.3~bzr2"),
32- _upstream_branch_version(self.revhistory, {}, "bla", "1.3~bzr1", self.get_suffix))
33+ self.revhistory = ["somerevid", "oldrevid"]
34+ self.assertEquals("1.3~bzr2",
35+ _upstream_branch_version(self.revhistory, {}, "bla", "1.3~bzr1",
36+ self.get_suffix))
37
38 def test_refresh_snapshot_post(self):
39- self.revhistory = ["oldrevid", "somerevid"]
40- self.assertEquals(Version("1.3+bzr2"),
41- _upstream_branch_version(self.revhistory, {}, "bla", "1.3+bzr1", self.get_suffix))
42+ self.revhistory = ["somerevid", "oldrevid"]
43+ self.assertEquals("1.3+bzr2",
44+ _upstream_branch_version(self.revhistory, {}, "bla", "1.3+bzr1",
45+ self.get_suffix))
46
47 def test_new_tag_refresh_snapshot(self):
48- self.revhistory = ["oldrevid", "somerevid", "newrevid"]
49- self.assertEquals(Version("1.3+bzr3"),
50+ self.revhistory = ["newrevid", "somerevid", "oldrevid"]
51+ self.assertEquals("1.3+bzr3",
52 _upstream_branch_version(self.revhistory,
53 {"somerevid": ["1.3"]}, "bla", "1.2+bzr1", self.get_suffix))
54
55
56=== modified file 'upstream/branch.py'
57--- upstream/branch.py 2011-01-29 01:03:18 +0000
58+++ upstream/branch.py 2011-02-21 16:22:07 +0000
59@@ -58,7 +58,7 @@
60 version is used and combined with the bzr revision number
61 (usually <version>+bzr<revno>).
62
63- :param revhistory: Branch revision history.
64+ :param revhistory: Reverse branch revision history.
65 :param reverse_tag_dict: Reverse tag dictionary (revid -> list of tags)
66 :param package: Name of package.
67 :param previous_version: Previous upstream version in debian changelog.
68@@ -68,7 +68,7 @@
69 if revhistory == []:
70 # No new version to merge
71 return previous_version
72- for r in reversed(revhistory):
73+ for r in revhistory:
74 if r in reverse_tag_dict:
75 # If there is a newer version tagged in branch,
76 # convert to upstream version
77@@ -77,11 +77,11 @@
78 upstream_version = upstream_tag_to_version(tag,
79 package=package)
80 if upstream_version is not None:
81- if r != revhistory[-1]:
82+ if r != revhistory[0]:
83 upstream_version = add_rev(
84- upstream_version, revhistory[-1])
85+ str(upstream_version), revhistory[0])
86 return upstream_version
87- return add_rev(previous_version, revhistory[-1])
88+ return add_rev(str(previous_version), revhistory[0])
89
90
91 def extract_svn_revno(rev):
92@@ -170,22 +170,19 @@
93 :param previous_version: The previous upstream version string
94 :return: Upstream version string for `upstream_revision`.
95 """
96- dotted_revno = upstream_branch.revision_id_to_dotted_revno(upstream_revision)
97- if len(dotted_revno) > 1:
98- revno = -2
99- else:
100- revno = dotted_revno[0]
101- revhistory = upstream_branch.revision_history()
102+ graph = upstream_branch.repository.get_graph()
103 previous_revision = get_snapshot_revision(previous_version)
104 if previous_revision is not None:
105 previous_revspec = RevisionSpec.from_string(previous_revision)
106- previous_revno, _ = previous_revspec.in_history(upstream_branch)
107+ previous_revno, previous_revid = previous_revspec.in_history(upstream_branch)
108 # Trim revision history - we don't care about any revisions
109 # before the revision of the previous version
110+ stop_revids = [previous_revid]
111 else:
112 previous_revno = 0
113- revhistory = revhistory[previous_revno:revno+1]
114- return _upstream_branch_version(revhistory,
115+ stop_revids = None
116+ revhistory = graph.iter_lefthand_ancestry(upstream_revision, stop_revids)
117+ return _upstream_branch_version(list(revhistory),
118 upstream_branch.tags.get_reverse_tag_dict(), package,
119 previous_version,
120 lambda version, revision: upstream_version_add_revision(upstream_branch, version, revision))
121@@ -241,8 +238,12 @@
122 self.upstream_branch.last_revision())
123
124 def get_version(self, package, current_version, revision):
125- return upstream_branch_version(self.upstream_branch,
126- revision, package, current_version)
127+ self.upstream_branch.lock_read()
128+ try:
129+ return upstream_branch_version(self.upstream_branch,
130+ revision, package, current_version)
131+ finally:
132+ self.upstream_branch.unlock()
133
134 def fetch_tarball(self, package, version, target_dir):
135 self.upstream_branch.lock_read()

Subscribers

People subscribed via source and target branches