~ubuntu-branches/ubuntu/raring/bzr-svn/raring

« back to all changes in this revision

Viewing changes to layout/custom.py

  • Committer: Bazaar Package Importer
  • Author(s): Jelmer Vernooij
  • Date: 2010-07-30 23:14:36 UTC
  • mfrom: (1.1.28 upstream) (3.3.4 sid)
  • Revision ID: james.westby@ubuntu.com-20100730231436-po8j0ibgjn2d6hy0
Tags: 1.0.3-1
* New upstream release.
 + Provides BranchConfig._get_change_editor. Closes: #572109
 + Supports more trunk layout levels. Closes: #573988
* Bump standards version to 3.9.1.
* Mark as supporting bzr 2.2.
* Suggest bzr-rewrite rather than bzr-rebase. LP: #481730

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# Copyright (C) 2005-2009 Jelmer Vernooij <jelmer@samba.org>
2
 
 
 
2
 
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
5
5
# the Free Software Foundation; either version 2 of the License, or
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
15
15
 
 
16
from bzrlib import urlutils
 
17
from bzrlib.plugins.svn import errors as svn_errors
 
18
from bzrlib.plugins.svn.layout import (
 
19
    RepositoryLayout,
 
20
    RootPathFinder,
 
21
    )
16
22
from bzrlib.plugins.svn.layout.standard import (
17
 
    InverseTrunkLayout,
18
23
    TrunkLayout,
19
24
    )
20
25
 
21
 
class KDELayout(InverseTrunkLayout):
 
26
class KDELayout(RepositoryLayout):
22
27
    """Layout for the KDE repository."""
23
28
 
24
 
    def __init__(self):
25
 
        InverseTrunkLayout.__init__(self, 1)
 
29
    def get_project_prefixes(self, project):
 
30
        sproject = project.strip("/").split("/")
 
31
        return [urlutils.join("trunk", project),
 
32
                urlutils.join("branches", sproject[0]),
 
33
                urlutils.join("tags", sproject[0])]
 
34
 
 
35
    def __repr__(self):
 
36
        return "KDELayout()"
 
37
 
 
38
    def get_tag_path(self, name, project=None):
 
39
        if project is None:
 
40
            raise AssertionError
 
41
        p = project.strip("/").split("/")
 
42
        return urlutils.join("tags", p[0], name.encode("utf-8"), *p[1:])
 
43
 
 
44
    def _is_parent(self, path, project, kind):
 
45
        path = path.strip("/")
 
46
        if path == "":
 
47
            return True
 
48
        spath = path.strip("/").split("/")
 
49
        if len(spath) == 0:
 
50
            return True
 
51
        if spath[0] == "trunk":
 
52
            if kind != "branches":
 
53
                return False
 
54
            candidate = spath[1:]
 
55
        elif spath[0] == kind:
 
56
            candidate = []
 
57
            if len(spath) > 1:
 
58
                candidate.append(spath[1])
 
59
            if len(spath) > 2:
 
60
                candidate += spath[3:]
 
61
        else:
 
62
            return False
 
63
        if len(candidate) == 0:
 
64
            return True
 
65
        if candidate[0] == "KDE" and len(candidate) == 1:
 
66
            return True
 
67
        return False
 
68
 
 
69
    def is_branch_parent(self, path, project=""):
 
70
        return self._is_parent(path, project, "branches")
 
71
 
 
72
    def is_tag_parent(self, path, project=""):
 
73
        return self._is_parent(path, project, "tags")
 
74
 
 
75
    def get_tag_name(self, path, project=""):
 
76
        pts = path.strip("/").split("/")
 
77
        assert pts[0] == "tags"
 
78
        return pts[2]
 
79
 
 
80
    def push_merged_revisions(self, project=""):
 
81
        return False
 
82
 
 
83
    def get_branch_path(self, name, project=None):
 
84
        if project is None:
 
85
            raise AssertionError
 
86
        pts = project.strip("/").split("/")
 
87
        if name == "trunk":
 
88
            return urlutils.join("trunk", project)
 
89
        return urlutils.join("branches", pts[0], name, *pts[1:])
 
90
 
 
91
    def parse(self, path):
 
92
        pts = path.strip("/").split("/")
 
93
        if pts[0] == "trunk":
 
94
            try:
 
95
                first = pts[1]
 
96
            except IndexError:
 
97
                raise svn_errors.NotSvnBranchPath(path, self)
 
98
            name = "trunk"
 
99
            kind = "branch"
 
100
            rest = pts[2:]
 
101
        elif pts[0] == "branches":
 
102
            # branches / FIRST / NAME / IPATH
 
103
            try:
 
104
                first = pts[1]
 
105
                name = pts[2]
 
106
                rest = pts[3:]
 
107
            except IndexError:
 
108
                raise svn_errors.NotSvnBranchPath(path, self)
 
109
            kind = "branch"
 
110
        elif pts[0] == "tags":
 
111
            try:
 
112
                first = pts[1]
 
113
                name = pts[2]
 
114
                rest = pts[3:]
 
115
            except IndexError:
 
116
                raise svn_errors.NotSvnBranchPath(path, self)
 
117
            kind = "tag"
 
118
        else:
 
119
            raise svn_errors.NotSvnBranchPath(path, self)
 
120
        project = [first]
 
121
        if first == "KDE":
 
122
            try:
 
123
                project.append(rest[0])
 
124
            except IndexError:
 
125
                raise svn_errors.NotSvnBranchPath(path, self)
 
126
            else:
 
127
                rest = rest[1:]
 
128
        ipath = "/".join(rest)
 
129
        return (kind, "/".join(project), path[:len(path)-len(ipath)].strip("/"),
 
130
                ipath)
 
131
 
 
132
    def _children_helper(self, rpf, name, trunk=False):
 
133
        if trunk:
 
134
            return [("trunk", None)]
 
135
        else:
 
136
            return [(urlutils.join(name, subname), has_props) for (subname, has_props) in rpf.find_children(name)]
 
137
 
 
138
    def _get_project_items(self, name, repository, revnum, project, pb, trunk=False):
 
139
        ret = []
 
140
        rpf = RootPathFinder(repository, revnum)
 
141
        children = self._children_helper(rpf, name, trunk)
 
142
        for subpath, has_props in children:
 
143
            cp = urlutils.join(subpath, project)
 
144
            if rpf.check_path(cp):
 
145
                ret.append((project, cp, urlutils.split(subpath)[-1], has_props))
 
146
        return ret
 
147
 
 
148
    def _get_all_items(self, name, repository, revnum, pb, trunk=False):
 
149
        ret = []
 
150
        rpf = RootPathFinder(repository, revnum)
 
151
        children = self._children_helper(rpf, name, trunk)
 
152
        for subpath, _ in children:
 
153
            for p, has_props in rpf.find_children(subpath):
 
154
                pp = urlutils.join(subpath, p)
 
155
                if p == "KDE":
 
156
                    for kdep, has_props in rpf.find_children(pp):
 
157
                        ret.append(("KDE/" + kdep, urlutils.join(pp, kdep), urlutils.split(subpath)[-1], has_props))
 
158
                else:
 
159
                    ret.append((p, pp, urlutils.split(subpath)[-1], has_props))
 
160
        return ret
 
161
 
 
162
    def _get_items(self, name, repository, revnum, project, pb, trunk=False):
 
163
        if project is None:
 
164
            return self._get_all_items(name, repository, revnum, pb, trunk)
 
165
        else:
 
166
            return self._get_project_items(name, repository, revnum, project, pb, trunk)
 
167
 
 
168
    def get_branches(self, repository, revnum, project=None, pb=None):
 
169
        return self._get_items("branches", repository, revnum,
 
170
            project, pb, trunk=False) + self._get_items("trunk", repository,
 
171
                revnum, project, pb, trunk=True)
 
172
 
 
173
    def get_tags(self, repository, revnum, project=None, pb=None):
 
174
        return self._get_items("tags", repository, revnum, project, pb,
 
175
            trunk=False)
 
176
 
 
177
    def __str__(self):
 
178
        return "kde"
26
179
 
27
180
 
28
181
class ApacheLayout(TrunkLayout):