Merge lp:~mwhudson/bzr-svn/incremental-imports into lp:bzr-svn/1.0

Proposed by Michael Hudson-Doyle
Status: Merged
Merged at revision: not available
Proposed branch: lp:~mwhudson/bzr-svn/incremental-imports
Merge into: lp:bzr-svn/1.0
Diff against target: 187 lines (+87/-13)
3 files modified
branch.py (+22/-11)
fetch.py (+11/-2)
tests/test_branch.py (+54/-0)
To merge this branch: bzr merge lp:~mwhudson/bzr-svn/incremental-imports
Reviewer Review Type Date Requested Status
Jelmer Vernooij Pending
Review via email: mp+20518@code.launchpad.net

Commit message

Add incremental pull support.

To post a comment you must log in.
Revision history for this message
Michael Hudson-Doyle (mwhudson) wrote :

Hi Jelmer,

This branch adds incremental pull support to bzr-svn, very much following the pattern of the changes I made to bzr-git. The tests don't seem to be very much like the tests around them, but maybe that's OK.

The new tests pass, I haven't managed to get a clean test run of the whole suite yet, but I don't think the failures are my fault...

Cheers,
mwh

Revision history for this message
Michael Hudson-Doyle (mwhudson) wrote :

Michael Hudson wrote:
> The new tests pass, I haven't managed to get a clean test run of the whole suite yet, but I don't think the failures are my fault...

I have now, and they pass (my subvertpy wasn't up to date).

Cheers,
mwh

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'branch.py'
2--- branch.py 2010-02-27 19:20:20 +0000
3+++ branch.py 2010-03-03 06:04:29 +0000
4@@ -660,7 +660,12 @@
5 history browsing operations
6 """
7
8- def update_revisions(self, stop_revision=None, overwrite=False, graph=None):
9+ def update_revisions(self, stop_revision=None, overwrite=False,
10+ graph=None):
11+ self._update_revisions(stop_revision, overwrite, graph)
12+
13+ def _update_revisions(self, stop_revision=None, overwrite=False,
14+ graph=None, limit=None):
15 """See InterBranch.update_revisions()."""
16 self.source.lock_read()
17 try:
18@@ -680,17 +685,23 @@
19 # graph, which will be cached in memory.
20 interrepo = InterFromSvnRepository(self.source.repository,
21 self.target.repository)
22- interrepo.fetch(stop_revision, project=self.source.project,
23- mapping=self.source.mapping)
24- # Check to see if one is an ancestor of the other
25+ new_head = interrepo._fetch(
26+ stop_revision, project=self.source.project,
27+ mapping=self.source.mapping, limit=limit)
28+ if new_head is not None:
29+ stop_revision = new_head[0].get_revision_id(new_head[1])
30 if not overwrite:
31 if graph is None:
32 graph = self.target.repository.get_graph()
33- if self.target._check_if_descendant_or_diverged(
34- stop_revision, last_rev, graph, self.source):
35- # stop_revision is a descendant of last_rev, but we
36- # aren't overwriting, so we're done.
37- return
38+ self.target.lock_read()
39+ try:
40+ if self.target._check_if_descendant_or_diverged(
41+ stop_revision, last_rev, graph, self.source):
42+ # stop_revision is a descendant of last_rev, but we
43+ # aren't overwriting, so we're done.
44+ return
45+ finally:
46+ self.target.unlock()
47 self.target.generate_revision_history(stop_revision)
48 finally:
49 self.source.unlock()
50@@ -708,7 +719,7 @@
51
52 def pull(self, overwrite=False, stop_revision=None,
53 _hook_master=None, run_hooks=True, possible_transports=None,
54- _override_hook_target=None, local=False):
55+ _override_hook_target=None, local=False, limit=None):
56 """See InterBranch.pull()."""
57 if local:
58 raise LocalRequiresBoundBranch()
59@@ -746,7 +757,7 @@
60 else:
61 result.new_revmeta = None
62 tags_until_revnum = self.source.repository.get_latest_revnum()
63- self.update_revisions(stop_revision, overwrite)
64+ self._update_revisions(stop_revision, overwrite, limit=limit)
65 (result.new_revno, result.new_revid) = \
66 self.target.last_revision_info()
67 if self.source.supports_tags():
68
69=== modified file 'fetch.py'
70--- fetch.py 2010-02-27 19:20:20 +0000
71+++ fetch.py 2010-03-03 06:04:29 +0000
72@@ -1261,6 +1261,13 @@
73
74 def fetch(self, revision_id=None, pb=None, find_ghosts=False,
75 needed=None, mapping=None, project=None, fetch_spec=None):
76+ self._fetch(
77+ revision_id, pb, find_ghosts, needed, mapping, project,
78+ fetch_spec)
79+
80+ def _fetch(self, revision_id=None, pb=None, find_ghosts=False,
81+ needed=None, mapping=None, project=None, fetch_spec=None,
82+ limit=None):
83 """Fetch revisions. """
84 if revision_id == NULL_REVISION:
85 return
86@@ -1300,7 +1307,7 @@
87
88 if len(needed) == 0:
89 # Nothing to fetch
90- return
91+ return None
92
93 if pb:
94 pb.update("fetch phase", 1, 2)
95@@ -1310,10 +1317,13 @@
96 nested_pb = pb
97 else:
98 nested_pb = None
99+ if limit is not None:
100+ needed = needed[:limit]
101 try:
102 pack_hint = self._fetch_revisions(needed, pb)
103 if pack_hint is not None and self.target._format.pack_compresses:
104 self.target.pack(hint=pack_hint)
105+ return needed[-1]
106 finally:
107 if nested_pb is not None:
108 nested_pb.finished()
109@@ -1334,7 +1344,6 @@
110 :param pb: Optional progress bar
111 """
112 self._prev_inv = None
113- currange = None
114 activeranges = defaultdict(list)
115 pb = ui.ui_factory.nested_progress_bar()
116 try:
117
118=== modified file 'tests/test_branch.py'
119--- tests/test_branch.py 2009-11-18 18:00:27 +0000
120+++ tests/test_branch.py 2010-03-03 06:04:29 +0000
121@@ -22,6 +22,7 @@
122 from bzrlib import urlutils
123 from bzrlib.branch import (
124 Branch,
125+ InterBranch,
126 )
127 from bzrlib.bzrdir import (
128 BzrDir,
129@@ -305,6 +306,59 @@
130 self.assertEquals(result.source_branch, otherbranch)
131 self.assertEquals(result.target_branch, branch)
132
133+ def make_tworev_branch(self):
134+ repos_url = self.make_repository("a")
135+
136+ dc = self.get_commit_editor(repos_url)
137+ dc.add_file('foo')
138+ dc.close()
139+
140+ b = Branch.open(repos_url)
141+ mapping = b.repository.get_mapping()
142+ uuid = b.repository.uuid
143+ revid1 = mapping.revision_id_foreign_to_bzr((uuid, '', 0))
144+ revid2 = mapping.revision_id_foreign_to_bzr((uuid, '', 1))
145+ return b, (revid1, revid2)
146+
147+ def make_branch(self, relpath):
148+ # The inherited make_branch is broken, thanks to the make_repository
149+ # from subvertpy.
150+ bzrdir = self.make_bzrdir(relpath)
151+ bzrdir._find_or_create_repository(True)
152+ return bzrdir.create_branch()
153+
154+ def test_interbranch_pull(self):
155+ svn_branch, (revid1, revid2) = self.make_tworev_branch()
156+ new_branch = self.make_branch("b")
157+ inter_branch = InterBranch.get(svn_branch, new_branch)
158+ inter_branch.pull()
159+ self.assertEquals(revid2, new_branch.last_revision())
160+
161+ def test_interbranch_pull_noop(self):
162+ svn_branch, (revid1, revid2) = self.make_tworev_branch()
163+ new_branch = self.make_branch("b")
164+ inter_branch = InterBranch.get(svn_branch, new_branch)
165+ inter_branch.pull()
166+ # This is basically "assertNotRaises"
167+ inter_branch.pull()
168+ self.assertEquals(revid2, new_branch.last_revision())
169+
170+ def test_interbranch_pull_stop_revision(self):
171+ svn_branch, (revid1, revid2) = self.make_tworev_branch()
172+ new_branch = self.make_branch("b")
173+ inter_branch = InterBranch.get(svn_branch, new_branch)
174+ inter_branch.pull(stop_revision=revid1)
175+ self.assertEquals(revid1, new_branch.last_revision())
176+
177+ def test_interbranch_limited_pull(self):
178+ svn_branch, (revid1, revid2) = self.make_tworev_branch()
179+ new_branch = self.make_branch("b")
180+ inter_branch = InterBranch.get(svn_branch, new_branch)
181+ inter_branch.pull(limit=1)
182+ self.assertEquals(revid1, new_branch.last_revision())
183+ inter_branch.pull(limit=1)
184+ self.assertEquals(revid2, new_branch.last_revision())
185+
186 def test_get_branch_path_subdir(self):
187 repos_url = self.make_repository("a")
188

Subscribers

People subscribed via source and target branches