Merge lp:~maxb/bzr-svn/remove-overcomplexity-find_commit_paths into lp:bzr-svn/1.0

Proposed by Max Bowsher
Status: Work in progress
Proposed branch: lp:~maxb/bzr-svn/remove-overcomplexity-find_commit_paths
Merge into: lp:bzr-svn/1.0
Diff against target: 157 lines (+30/-53)
4 files modified
layout/guess.py (+5/-15)
mapping3/scheme.py (+7/-10)
tests/mapping3/test_scheme.py (+0/-28)
tests/test_changes.py (+18/-0)
To merge this branch: bzr merge lp:~maxb/bzr-svn/remove-overcomplexity-find_commit_paths
Reviewer Review Type Date Requested Status
Jelmer Vernooij (community) code Disapprove
Review via email: mp+35490@code.launchpad.net

Description of the change

As I was looking at layout/guess.py, I noticed some code which was unnecessarily overcomplicated.

To post a comment you must log in.
Revision history for this message
Jelmer Vernooij (jelmer) wrote :

This complexity is there for good reason. Imagine e.g. a commit where a user changes both /trunk/bla/foo and /wiki in the same commit.

Previously we would add a +1 for TrunkLayout(). With these changes, we would add one for RootLayout().

I'd be interested in merging the common_prefix tests though.

review: Disapprove (code)
Revision history for this message
Max Bowsher (maxb) wrote :

> This complexity is there for good reason. Imagine e.g. a commit where a user
> changes both /trunk/bla/foo and /wiki in the same commit.
>
> Previously we would add a +1 for TrunkLayout(). With these changes, we would
> add one for RootLayout().

Huh. I was under the impression that these changes were functionally neutral. I will look again.

Revision history for this message
Max Bowsher (maxb) wrote :

> > This complexity is there for good reason. Imagine e.g. a commit where a user
> > changes both /trunk/bla/foo and /wiki in the same commit.
> >
> > Previously we would add a +1 for TrunkLayout(). With these changes, we would
> > add one for RootLayout().
>
> Huh. I was under the impression that these changes were functionally neutral.
> I will look again.

I looked again. I understand why you would desire changing trunk and wiki to result in a TrunkLayout, however, this is *not* what the current 1.0 code actually does - it returns RootLayout. lp:~maxb/bzr-svn/test-guess-layout is my attempt to demonstrate this.

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

On Fri, 2010-10-01 at 01:25 +0000, Max Bowsher wrote:
> > > This complexity is there for good reason. Imagine e.g. a commit where a user
> > > changes both /trunk/bla/foo and /wiki in the same commit.
> > >
> > > Previously we would add a +1 for TrunkLayout(). With these changes, we would
> > > add one for RootLayout().
> >
> > Huh. I was under the impression that these changes were functionally neutral.
> > I will look again.
>
> I looked again. I understand why you would desire changing trunk and
> wiki to result in a TrunkLayout, however, this is *not* what the
> current 1.0 code actually does - it returns RootLayout.
> lp:~maxb/bzr-svn/test-guess-layout is my attempt to demonstrate this.
Your test case is actually a corner case - we'd end up with the same
score for TrunkLayout and RootLayout so which one we should pick isn't
clear, but I see your point.

Patches welcome. :-)

Cheers,

Jelmer

Unmerged revisions

3467. By Max Bowsher

Remove layout.guess.find_commit_paths and associated overcomplexity.

3466. By Jelmer Vernooij

Properly encode paths when annotating.

3465. By Jelmer Vernooij

fix fetching of subvertpy repository.

3464. By Jelmer Vernooij

Fix compatibility with older versions of bzr.

3463. By Jelmer Vernooij

Fix root change.

3462. By Jelmer Vernooij

Cope with lockableconfig in newer versions of bzr.

3461. By Jelmer Vernooij

Fix svn parent tree retrieval.

3460. By Jelmer Vernooij

Simplify branch continuation handling.

3459. By Jelmer Vernooij

Some reformatting, don't let __len__ of RevisionMetadataBrowser depend on number of items iterated yet.

3458. By Jelmer Vernooij

Start on 1.0.5.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'layout/guess.py'
2--- layout/guess.py 2010-08-13 01:34:44 +0000
3+++ layout/guess.py 2010-09-15 00:37:50 +0000
4@@ -29,15 +29,6 @@
5 # Number of revisions to evaluate when guessing the repository layout
6 GUESS_SAMPLE_SIZE = 300
7
8-def find_commit_paths(changed_paths):
9- """Find the commit-paths used in a bunch of revisions.
10-
11- :param changed_paths: List of changed_paths (dictionary with path -> action)
12- :return: List of potential commit paths.
13- """
14- for changes in changed_paths:
15- yield common_prefix(changes.keys())
16-
17
18 def guess_layout_from_branch_path(relpath):
19 """Try to guess the branching layout from a branch path.
20@@ -104,12 +95,11 @@
21 last_revnum)
22 if revpaths == {}:
23 continue
24- for path in find_commit_paths([revpaths]):
25- layout = guess_layout_from_path(path)
26- if not potentials.has_key(str(layout)):
27- potentials[str(layout)] = 0
28- potentials[str(layout)] += 1
29- layout_cache[str(layout)] = layout
30+ layout = guess_layout_from_path(common_prefix(revpaths.keys()))
31+ if not potentials.has_key(str(layout)):
32+ potentials[str(layout)] = 0
33+ potentials[str(layout)] += 1
34+ layout_cache[str(layout)] = layout
35 finally:
36 pb.finished()
37
38
39=== modified file 'mapping3/scheme.py'
40--- mapping3/scheme.py 2010-07-26 21:59:02 +0000
41+++ mapping3/scheme.py 2010-09-15 00:37:50 +0000
42@@ -27,16 +27,14 @@
43 from bzrlib.errors import BzrError
44 from bzrlib.trace import mutter
45
46-from bzrlib.plugins.svn.layout.guess import (
47- GUESS_SAMPLE_SIZE,
48- find_commit_paths,
49- )
50+from bzrlib.plugins.svn.layout.guess import GUESS_SAMPLE_SIZE
51 from bzrlib.plugins.svn.layout.standard import (
52 CustomLayout,
53 RootLayout,
54 TrunkLayout,
55 )
56 from bzrlib.plugins.svn.errors import LayoutUnusable
57+from bzrlib.plugins.svn.changes import common_prefix
58
59
60 class InvalidSvnBranchPath(BzrError):
61@@ -500,12 +498,11 @@
62 last_revnum)
63 if revpaths == {}:
64 continue
65- for path in find_commit_paths([revpaths]):
66- scheme = guess_scheme_from_path(path)
67- if not potentials.has_key(str(scheme)):
68- potentials[str(scheme)] = 0
69- potentials[str(scheme)] += 1
70- scheme_cache[str(scheme)] = scheme
71+ scheme = guess_scheme_from_path(common_prefix(revpaths.keys()))
72+ if not potentials.has_key(str(scheme)):
73+ potentials[str(scheme)] = 0
74+ potentials[str(scheme)] += 1
75+ scheme_cache[str(scheme)] = scheme
76 finally:
77 pb.finished()
78
79
80=== modified file 'tests/mapping3/test_scheme.py'
81--- tests/mapping3/test_scheme.py 2009-04-01 01:24:58 +0000
82+++ tests/mapping3/test_scheme.py 2010-09-15 00:37:50 +0000
83@@ -28,7 +28,6 @@
84 SingleBranchingSchemev0,
85 SingleBranchingScheme,
86 UnknownBranchingScheme,
87- find_commit_paths,
88 guess_scheme_from_branch_path,
89 guess_scheme_from_history,
90 guess_scheme_from_path,
91@@ -537,33 +536,6 @@
92 self.assertEquals("single-ha/bla", str(SingleBranchingSchemev0("ha/bla")))
93
94
95-class FindCommitPathsTester(TestCase):
96-
97- def test_simple_trunk_only(self):
98- self.assertEquals(["trunk"],
99- list(find_commit_paths([{"trunk": ('M', None, None)}])))
100-
101- def test_branches(self):
102- self.assertEquals(["trunk", "branches/bar"],
103- list(find_commit_paths([{"trunk": ('M', None, None)},
104- {"branches/bar": ('A', None, None)}])))
105-
106- def test_trunk_more_files(self):
107- self.assertEquals(["trunk"],
108- list(find_commit_paths([{
109- "trunk/bfile": ('A', None, None),
110- "trunk/afile": ('M', None, None),
111- "trunk": ('A', None, None)
112- }])))
113-
114- def test_trunk_more_files_no_root(self):
115- self.assertEquals(["trunk"],
116- list(find_commit_paths([{
117- "trunk/bfile": ('A', None, None),
118- "trunk/afile": ('M', None, None)
119- }])))
120-
121-
122 class TestGuessBranchingSchemeFromBranchpath(TestCase):
123
124 def test_guess_empty(self):
125
126=== modified file 'tests/test_changes.py'
127--- tests/test_changes.py 2010-08-09 23:48:59 +0000
128+++ tests/test_changes.py 2010-09-15 00:37:50 +0000
129@@ -22,6 +22,7 @@
130 from bzrlib.plugins.svn.changes import (
131 apply_reverse_changes,
132 changes_root,
133+ common_prefix,
134 find_prev_location,
135 path_is_child,
136 under_prefixes,
137@@ -148,3 +149,20 @@
138
139 def test_none(self):
140 self.assertTrue(under_prefixes("foo", None))
141+
142+
143+class CommonPrefixTests(TestCase):
144+
145+ def test_simple_trunk_only(self):
146+ self.assertEquals("trunk", common_prefix(("trunk",)))
147+
148+ def test_branches(self):
149+ self.assertEquals("branches/bar", common_prefix(("branches/bar",)))
150+
151+ def test_trunk_more_files(self):
152+ self.assertEquals("trunk", common_prefix(("trunk/bfile",
153+ "trunk/afile", "trunk")))
154+
155+ def test_trunk_more_files_no_root(self):
156+ self.assertEquals("trunk", common_prefix(("trunk/bfile",
157+ "trunk/afile")))

Subscribers

People subscribed via source and target branches