Merge lp:~jelmer/bzr/get-known-graph-ancestry into lp:bzr

Proposed by Jelmer Vernooij
Status: Merged
Approved by: Vincent Ladeuil
Approved revision: no longer in the source branch.
Merged at revision: not available
Proposed branch: lp:~jelmer/bzr/get-known-graph-ancestry
Merge into: lp:bzr
Diff against target: 176 lines (+53/-12)
7 files modified
NEWS (+3/-0)
bzrlib/branch.py (+3/-4)
bzrlib/fetch.py (+2/-8)
bzrlib/graph.py (+6/-0)
bzrlib/remote.py (+10/-0)
bzrlib/repository.py (+10/-0)
bzrlib/tests/per_repository/test_repository.py (+19/-0)
To merge this branch: bzr merge lp:~jelmer/bzr/get-known-graph-ancestry
Reviewer Review Type Date Requested Status
Robert Collins (community) Disapprove
Vincent Ladeuil Approve
Review via email: mp+23143@code.launchpad.net

Description of the change

This patch adds Repository.get_known_graph_ancestry().

This method is necessary because not all repositories have VersionedFiles implementations; several things that already rely on VF.get_known_ancestry_graph() (such as qdiff) break with bzr-svn at the moment.

To post a comment you must log in.
Revision history for this message
Vincent Ladeuil (vila) wrote :

Sounds good to me, the tests are light and appropriate as smoke ones which is all that is needed to start.

We may want the same thing for file revisions.

review: Approve
Revision history for this message
Robert Collins (lifeless) wrote :

On Sat, 2010-04-10 at 01:26 +0000, Jelmer Vernooij wrote:
> Jelmer Vernooij has proposed merging lp:~jelmer/bzr/get-known-graph-ancestry into lp:bzr.

Just to say, I've got reservations about this - we want to shrink
Repository IMO, not expand it. Why can't bzr-svn just expose a VF object
- even if its slow if used for untuned things, it would work, wouldn't
it? And avoid the duplication that this adds.

 review: disapprove

review: Disapprove
Revision history for this message
Jelmer Vernooij (jelmer) wrote :

On Sun, 2010-04-11 at 02:48 +0000, Robert Collins wrote:
> Review: Disapprove
> On Sat, 2010-04-10 at 01:26 +0000, Jelmer Vernooij wrote:
> > Jelmer Vernooij has proposed merging lp:~jelmer/bzr/get-known-graph-ancestry into lp:bzr.
>
> Just to say, I've got reservations about this - we want to shrink
> Repository IMO, not expand it. Why can't bzr-svn just expose a VF object
> - even if its slow if used for untuned things, it would work, wouldn't
> it? And avoid the duplication that this adds.
I agree that we should reduce the number of methods on Repository in
general, and as you might have seen I have helped remove some methods
earlier. However, I think VersionedFiles is the wrong interface here and
putting repository methods on it only because Repository already has a
lot of methods is wrong imho.

get_known_graph_ancestry() also returns a helper object itself that can
be used for further extension.

Cheers,

Jelmer

Revision history for this message
Martin Pool (mbp) wrote :

On 12 April 2010 00:54, Jelmer Vernooij <email address hidden> wrote:
>> Just to say, I've got reservations about this - we want to shrink
>> Repository IMO, not expand it. Why can't bzr-svn just expose a VF object
>> - even if its slow if used for untuned things, it would work, wouldn't
>> it? And avoid the duplication that this adds.
> I agree that we should reduce the number of methods on Repository in
> general, and as you might have seen I have helped remove some methods
> earlier. However, I think VersionedFiles is the wrong interface here and
> putting repository methods on it only because Repository already has a
> lot of methods is wrong imho.

I agree.

--
Martin <http://launchpad.net/~mbp/>

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'NEWS'
2--- NEWS 2010-04-08 08:48:59 +0000
3+++ NEWS 2010-04-10 01:26:17 +0000
4@@ -284,6 +284,9 @@
5 * New method ``BzrDir.list_branches()`` that returns a sequence of branches
6 present in a control directory. (Jelmer Vernooij)
7
8+* New method ``Repository.get_known_graph_ancestry()``.
9+ (Jelmer Vernooij, #495502)
10+
11 * New transport methods ``readlink``, ``symlink`` and ``hardlink``.
12 (Neil Santos)
13
14
15=== modified file 'bzrlib/branch.py'
16--- bzrlib/branch.py 2010-04-02 15:06:55 +0000
17+++ bzrlib/branch.py 2010-04-10 01:26:17 +0000
18@@ -447,11 +447,10 @@
19 # start_revision_id.
20 if self._merge_sorted_revisions_cache is None:
21 last_revision = self.last_revision()
22- last_key = (last_revision,)
23- known_graph = self.repository.revisions.get_known_graph_ancestry(
24- [last_key])
25+ known_graph = self.repository.get_known_graph_ancestry(
26+ [last_revision])
27 self._merge_sorted_revisions_cache = known_graph.merge_sort(
28- last_key)
29+ last_revision)
30 filtered = self._filter_merge_sorted_revisions(
31 self._merge_sorted_revisions_cache, start_revision_id,
32 stop_revision_id, stop_rule)
33
34=== modified file 'bzrlib/fetch.py'
35--- bzrlib/fetch.py 2010-02-23 07:43:11 +0000
36+++ bzrlib/fetch.py 2010-04-10 01:26:17 +0000
37@@ -28,8 +28,6 @@
38 from bzrlib.lazy_import import lazy_import
39 lazy_import(globals(), """
40 from bzrlib import (
41- graph as _mod_graph,
42- static_tuple,
43 tsort,
44 versionedfile,
45 )
46@@ -249,7 +247,7 @@
47 if len(revs) > 100:
48 # XXX: not covered by tests, should have a flag to always run
49 # this. -- mbp 20100129
50- graph = _get_rich_root_heads_graph(self.source, revs)
51+ graph = self.source_repo.get_known_graph_ancestry(revs)
52 new_roots_stream = _new_root_data_stream(
53 root_id_order, rev_id_to_root_id, parent_map, self.source, graph)
54 return [('texts', new_roots_stream)]
55@@ -257,11 +255,7 @@
56
57 def _get_rich_root_heads_graph(source_repo, revision_ids):
58 """Get a Graph object suitable for asking heads() for new rich roots."""
59- st = static_tuple.StaticTuple
60- revision_keys = [st(r_id).intern() for r_id in revision_ids]
61- known_graph = source_repo.revisions.get_known_graph_ancestry(
62- revision_keys)
63- return _mod_graph.GraphThunkIdsToKeys(known_graph)
64+ return
65
66
67 def _new_root_data_stream(
68
69=== modified file 'bzrlib/graph.py'
70--- bzrlib/graph.py 2010-02-17 17:11:16 +0000
71+++ bzrlib/graph.py 2010-04-10 01:26:17 +0000
72@@ -1685,12 +1685,18 @@
73 def __init__(self, graph):
74 self._graph = graph
75
76+ def topo_sort(self):
77+ return [r for (r,) in self._graph.topo_sort()]
78+
79 def heads(self, ids):
80 """See Graph.heads()"""
81 as_keys = [(i,) for i in ids]
82 head_keys = self._graph.heads(as_keys)
83 return set([h[0] for h in head_keys])
84
85+ def merge_sort(self, tip_revision):
86+ return self._graph.merge_sort((tip_revision,))
87+
88
89 _counters = [0,0,0,0,0,0,0]
90 try:
91
92=== modified file 'bzrlib/remote.py'
93--- bzrlib/remote.py 2010-03-11 18:00:23 +0000
94+++ bzrlib/remote.py 2010-04-10 01:26:17 +0000
95@@ -29,6 +29,7 @@
96 repository,
97 revision,
98 revision as _mod_revision,
99+ static_tuple,
100 symbol_versioning,
101 )
102 from bzrlib.branch import BranchReferenceFormat
103@@ -903,6 +904,15 @@
104 parents_provider = self._make_parents_provider(other_repository)
105 return graph.Graph(parents_provider)
106
107+ @needs_read_lock
108+ def get_known_graph_ancestry(self, revision_ids):
109+ """Return the known graph for a set of revision ids and their ancestors.
110+ """
111+ st = static_tuple.StaticTuple
112+ revision_keys = [st(r_id).intern() for r_id in revision_ids]
113+ known_graph = self.revisions.get_known_graph_ancestry(revision_keys)
114+ return graph.GraphThunkIdsToKeys(known_graph)
115+
116 def gather_stats(self, revid=None, committers=None):
117 """See Repository.gather_stats()."""
118 path = self.bzrdir._path_for_remote_call(self._client)
119
120=== modified file 'bzrlib/repository.py'
121--- bzrlib/repository.py 2010-03-26 10:25:47 +0000
122+++ bzrlib/repository.py 2010-04-10 01:26:17 +0000
123@@ -40,6 +40,7 @@
124 lru_cache,
125 osutils,
126 revision as _mod_revision,
127+ static_tuple,
128 symbol_versioning,
129 trace,
130 tsort,
131@@ -2626,6 +2627,15 @@
132 def _make_parents_provider(self):
133 return self
134
135+ @needs_read_lock
136+ def get_known_graph_ancestry(self, revision_ids):
137+ """Return the known graph for a set of revision ids and their ancestors.
138+ """
139+ st = static_tuple.StaticTuple
140+ revision_keys = [st(r_id).intern() for r_id in revision_ids]
141+ known_graph = self.revisions.get_known_graph_ancestry(revision_keys)
142+ return graph.GraphThunkIdsToKeys(known_graph)
143+
144 def get_graph(self, other_repository=None):
145 """Return the graph walker for this repository format"""
146 parents_provider = self._make_parents_provider()
147
148=== modified file 'bzrlib/tests/per_repository/test_repository.py'
149--- bzrlib/tests/per_repository/test_repository.py 2010-02-23 07:43:11 +0000
150+++ bzrlib/tests/per_repository/test_repository.py 2010-04-10 01:26:17 +0000
151@@ -724,6 +724,25 @@
152 self.assertTrue('ghost' not in parents)
153 self.assertEqual(parents['rev2'], ('rev1', 'ghost'))
154
155+ def test_get_known_graph_ancestry(self):
156+ tree = self.make_branch_and_tree('here')
157+ tree.lock_write()
158+ self.addCleanup(tree.unlock)
159+ # A
160+ # |\
161+ # | B
162+ # |/
163+ # C
164+ tree.commit('initial commit', rev_id='A')
165+ tree_other = tree.bzrdir.sprout('there').open_workingtree()
166+ tree_other.commit('another', rev_id='B')
167+ tree.merge_from_branch(tree_other.branch)
168+ tree.commit('another', rev_id='C')
169+ kg = tree.branch.repository.get_known_graph_ancestry(
170+ ['C'])
171+ self.assertEqual(['C'], list(kg.heads(['A', 'B', 'C'])))
172+ self.assertEqual(['A', 'B', 'C'], list(kg.topo_sort()))
173+
174 def test_parent_map_type(self):
175 tree = self.make_branch_and_tree('here')
176 tree.lock_write()