402.1.27
by Jelmer Vernooij
Update year |
1 |
# Copyright (C) 2006-2007 Jelmer Vernooij <jelmer@samba.org>
|
34
by Jelmer Vernooij
Add copyright headers, add test for branch format description |
2 |
|
3 |
# This program is free software; you can redistribute it and/or modify
|
|
4 |
# it under the terms of the GNU General Public License as published by
|
|
1022
by Jelmer Vernooij
Switch license to GPLv3 or later. |
5 |
# the Free Software Foundation; either version 3 of the License, or
|
34
by Jelmer Vernooij
Add copyright headers, add test for branch format description |
6 |
# (at your option) any later version.
|
7 |
||
8 |
# This program is distributed in the hope that it will be useful,
|
|
9 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
10 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
11 |
# GNU General Public License for more details.
|
|
12 |
||
13 |
# You should have received a copy of the GNU General Public License
|
|
14 |
# along with this program; if not, write to the Free Software
|
|
15 |
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
402.1.50
by Jelmer Vernooij
Add some documentation. |
16 |
"""Subversion BzrDir formats."""
|
28
by Jelmer Vernooij
Fix use of 'bzr info', update TODO |
17 |
|
586
by Jelmer Vernooij
Simplify import code, handle corner cases pushing deletes. |
18 |
from bzrlib import urlutils |
478
by Jelmer Vernooij
Require rich root repositories. |
19 |
from bzrlib.bzrdir import BzrDirFormat, BzrDir, format_registry |
402.1.44
by Jelmer Vernooij
Fix no working tree warning. |
20 |
from bzrlib.errors import (NotBranchError, NotLocalUrl, NoRepositoryPresent, |
639
by Jelmer Vernooij
Add more docstrings, general cleanups. |
21 |
NoWorkingTree, AlreadyBranchError) |
109
by Jelmer Vernooij
Little bit of work on initializing Subversion repositories. |
22 |
from bzrlib.transport.local import LocalTransport |
23 |
||
141
by Jelmer Vernooij
Add tests for dumpfiles. |
24 |
from svn.core import SubversionException |
25 |
import svn.core, svn.repos |
|
83
by Jelmer Vernooij
Use generators in logcacher. |
26 |
|
645
by Jelmer Vernooij
Fix some tests. |
27 |
from errors import NoSvnRepositoryPresent |
705
by Jelmer Vernooij
Move format code into separate file to improve import time when bzr-svn isn't used. |
28 |
from format import get_rich_root_format, SvnRemoteFormat |
83
by Jelmer Vernooij
Use generators in logcacher. |
29 |
from repository import SvnRepository |
1152
by Jelmer Vernooij
Remove unused import. |
30 |
from transport import bzr_to_svn_url, get_svn_ra_transport |
83
by Jelmer Vernooij
Use generators in logcacher. |
31 |
|
16
by Jelmer Vernooij
Fix up to connect |
32 |
|
17
by Jelmer Vernooij
Fix annoying bugs in RemoteSvnBranch |
33 |
class SvnRemoteAccess(BzrDir): |
141
by Jelmer Vernooij
Add tests for dumpfiles. |
34 |
"""BzrDir implementation for Subversion connections.
|
35 |
|
|
36 |
This is used for all non-checkout connections
|
|
37 |
to Subversion repositories.
|
|
38 |
"""
|
|
699
by Jelmer Vernooij
Simplify branch access of workingtree. |
39 |
def __init__(self, _transport, _format=None): |
141
by Jelmer Vernooij
Add tests for dumpfiles. |
40 |
"""See BzrDir.__init__()."""
|
246
by Jelmer Vernooij
Use existing transports and wrap them rather than registering new transports. |
41 |
_transport = get_svn_ra_transport(_transport) |
699
by Jelmer Vernooij
Simplify branch access of workingtree. |
42 |
if _format is None: |
705
by Jelmer Vernooij
Move format code into separate file to improve import time when bzr-svn isn't used. |
43 |
_format = SvnRemoteFormat() |
643
by Jelmer Vernooij
Don't open transport for .bzr directory if we don't have to. |
44 |
self._format = _format |
45 |
self.transport = None |
|
46 |
self.root_transport = _transport |
|
83
by Jelmer Vernooij
Use generators in logcacher. |
47 |
|
141
by Jelmer Vernooij
Add tests for dumpfiles. |
48 |
svn_url = bzr_to_svn_url(self.root_transport.base) |
723
by Jelmer Vernooij
Support svn+ hack when committing in bound branches. (#150699) |
49 |
self.svn_root_url = _transport.get_svn_repos_root() |
50 |
self.root_url = _transport.get_repos_root() |
|
141
by Jelmer Vernooij
Add tests for dumpfiles. |
51 |
|
342
by Jelmer Vernooij
Properly implement SvnRemoteAccess.open_repository() and |
52 |
assert svn_url.startswith(self.svn_root_url) |
53 |
self.branch_path = svn_url[len(self.svn_root_url):] |
|
98
by Jelmer Vernooij
Fix handling of ignores. |
54 |
|
402.1.43
by Jelmer Vernooij
Fix compatibility with bzr.dev. |
55 |
def clone(self, url, revision_id=None, force_new_repo=False): |
141
by Jelmer Vernooij
Add tests for dumpfiles. |
56 |
"""See BzrDir.clone().
|
57 |
||
58 |
Not supported on Subversion connections.
|
|
59 |
"""
|
|
17
by Jelmer Vernooij
Fix annoying bugs in RemoteSvnBranch |
60 |
raise NotImplementedError(SvnRemoteAccess.clone) |
45
by Jelmer Vernooij
Add stub functions for sprout() and copy_contents_into(). Full |
61 |
|
402.1.43
by Jelmer Vernooij
Fix compatibility with bzr.dev. |
62 |
def sprout(self, url, revision_id=None, force_new_repo=False, |
940
by Jelmer Vernooij
Support hardlink argument to BzrDir.sprout(). |
63 |
recurse='down', possible_transports=None, accelerator_tree=None, |
64 |
hardlink=False): |
|
141
by Jelmer Vernooij
Add tests for dumpfiles. |
65 |
"""See BzrDir.sprout()."""
|
639
by Jelmer Vernooij
Add more docstrings, general cleanups. |
66 |
# FIXME: Use possible_transports
|
402.1.36
by Jelmer Vernooij
General cleanups: remove unused imports, fix line lengths, unused parameters. |
67 |
# FIXME: Use recurse
|
478
by Jelmer Vernooij
Require rich root repositories. |
68 |
format = get_rich_root_format() |
69 |
result = format.initialize(url) |
|
342
by Jelmer Vernooij
Properly implement SvnRemoteAccess.open_repository() and |
70 |
repo = self.find_repository() |
191
by Jelmer Vernooij
Support using repositories, fix symlink support. |
71 |
if force_new_repo: |
402.1.43
by Jelmer Vernooij
Fix compatibility with bzr.dev. |
72 |
result_repo = repo.clone(result, revision_id) |
191
by Jelmer Vernooij
Support using repositories, fix symlink support. |
73 |
else: |
74 |
try: |
|
75 |
result_repo = result.find_repository() |
|
336
by Jelmer Vernooij
More consistent use of progress bars. |
76 |
result_repo.fetch(repo, revision_id=revision_id) |
191
by Jelmer Vernooij
Support using repositories, fix symlink support. |
77 |
except NoRepositoryPresent: |
402.1.43
by Jelmer Vernooij
Fix compatibility with bzr.dev. |
78 |
result_repo = repo.clone(result, revision_id) |
45
by Jelmer Vernooij
Add stub functions for sprout() and copy_contents_into(). Full |
79 |
branch = self.open_branch() |
269
by Jelmer Vernooij
Respect no_working_trees setting in repository when copying a branch. |
80 |
result_branch = branch.sprout(result, revision_id) |
81 |
if result_branch.repository.make_working_trees(): |
|
940
by Jelmer Vernooij
Support hardlink argument to BzrDir.sprout(). |
82 |
result.create_workingtree(hardlink=hardlink) |
45
by Jelmer Vernooij
Add stub functions for sprout() and copy_contents_into(). Full |
83 |
return result |
16
by Jelmer Vernooij
Fix up to connect |
84 |
|
639
by Jelmer Vernooij
Add more docstrings, general cleanups. |
85 |
def open_repository(self, _unsupported=False): |
141
by Jelmer Vernooij
Add tests for dumpfiles. |
86 |
"""Open the repository associated with this BzrDir.
|
87 |
|
|
88 |
:return: instance of SvnRepository.
|
|
89 |
"""
|
|
342
by Jelmer Vernooij
Properly implement SvnRemoteAccess.open_repository() and |
90 |
if self.branch_path == "": |
559
by Jelmer Vernooij
Improve heuristics for determining branching schemes. |
91 |
return SvnRepository(self, self.root_transport) |
645
by Jelmer Vernooij
Fix some tests. |
92 |
raise NoSvnRepositoryPresent(self.root_transport.base) |
31
by Jelmer Vernooij
Implement open_repository() as an alias to find_repository() |
93 |
|
342
by Jelmer Vernooij
Properly implement SvnRemoteAccess.open_repository() and |
94 |
def find_repository(self): |
95 |
"""Open the repository associated with this BzrDir.
|
|
96 |
|
|
97 |
:return: instance of SvnRepository.
|
|
98 |
"""
|
|
344
by Jelmer Vernooij
Avoid opening possibly remote branches if it can be avoided. |
99 |
transport = self.root_transport |
723
by Jelmer Vernooij
Support svn+ hack when committing in bound branches. (#150699) |
100 |
if self.root_url != transport.base: |
635
by Jelmer Vernooij
Don't try to open repository root for http:// or https:// URLs (#80553) |
101 |
transport = transport.clone_root() |
559
by Jelmer Vernooij
Improve heuristics for determining branching schemes. |
102 |
return SvnRepository(self, transport, self.branch_path) |
19
by Jelmer Vernooij
Start moving functionality to SvnRepository |
103 |
|
402.3.1
by Jelmer Vernooij
Fix compatibility with latest bzr.dev. |
104 |
def open_workingtree(self, _unsupported=False, |
105 |
recommend_upgrade=True): |
|
141
by Jelmer Vernooij
Add tests for dumpfiles. |
106 |
"""See BzrDir.open_workingtree().
|
107 |
||
108 |
Will always raise NotLocalUrl as this
|
|
109 |
BzrDir can not be associated with working trees.
|
|
110 |
"""
|
|
111 |
# Working trees never exist on remote Subversion repositories
|
|
402.1.44
by Jelmer Vernooij
Fix no working tree warning. |
112 |
raise NoWorkingTree(self.root_transport.base) |
24
by Jelmer Vernooij
Make lightweight checkouts (bzr co --lightweight) work. Files are still empty. |
113 |
|
940
by Jelmer Vernooij
Support hardlink argument to BzrDir.sprout(). |
114 |
def create_workingtree(self, revision_id=None, hardlink=None): |
141
by Jelmer Vernooij
Add tests for dumpfiles. |
115 |
"""See BzrDir.create_workingtree().
|
116 |
||
117 |
Will always raise NotLocalUrl as this
|
|
118 |
BzrDir can not be associated with working trees.
|
|
119 |
"""
|
|
120 |
raise NotLocalUrl(self.root_transport.base) |
|
109
by Jelmer Vernooij
Little bit of work on initializing Subversion repositories. |
121 |
|
496
by Jelmer Vernooij
Implement needs_format_conversion(). |
122 |
def needs_format_conversion(self, format=None): |
123 |
"""See BzrDir.needs_format_conversion()."""
|
|
124 |
# if the format is not the same as the system default,
|
|
125 |
# an upgrade is needed.
|
|
126 |
if format is None: |
|
127 |
format = BzrDirFormat.get_default_format() |
|
128 |
return not isinstance(self._format, format.__class__) |
|
129 |
||
520.1.13
by Jelmer Vernooij
Add -r option, rename svn-push-new-branch to svn-push-new. |
130 |
def import_branch(self, source, stop_revision=None): |
520.1.5
by Jelmer Vernooij
More work on supporting creating branches. |
131 |
"""Create a new branch in this repository, possibly
|
132 |
with the specified history, optionally importing revisions.
|
|
561
by Jelmer Vernooij
More work on intelligent guessing of branching schemes. |
133 |
|
134 |
:param source: Source branch
|
|
135 |
:param stop_revision: Tip of new branch
|
|
136 |
:return: Branch object
|
|
520.1.5
by Jelmer Vernooij
More work on supporting creating branches. |
137 |
"""
|
138 |
from commit import push_new |
|
520.1.13
by Jelmer Vernooij
Add -r option, rename svn-push-new-branch to svn-push-new. |
139 |
if stop_revision is None: |
140 |
stop_revision = source.last_revision() |
|
586
by Jelmer Vernooij
Simplify import code, handle corner cases pushing deletes. |
141 |
target_branch_path = self.branch_path.strip("/") |
585
by Jelmer Vernooij
Add some tests for import_branch(). |
142 |
repos = self.find_repository() |
1079
by Jelmer Vernooij
Cache revision number when repository is read locked. Significantly improves performance of push. |
143 |
repos.lock_write() |
144 |
try: |
|
145 |
full_branch_url = urlutils.join(repos.transport.base, |
|
146 |
target_branch_path) |
|
147 |
if repos.transport.check_path(target_branch_path, |
|
148 |
repos.get_latest_revnum()) != svn.core.svn_node_none: |
|
149 |
raise AlreadyBranchError(full_branch_url) |
|
150 |
push_new(repos, target_branch_path, source, stop_revision) |
|
1145
by Jelmer Vernooij
Fix write locking when pushing to new branch. |
151 |
finally: |
152 |
repos.unlock() |
|
153 |
branch = self.open_branch() |
|
154 |
branch.lock_write() |
|
155 |
try: |
|
1079
by Jelmer Vernooij
Cache revision number when repository is read locked. Significantly improves performance of push. |
156 |
branch.pull(source, stop_revision=stop_revision) |
157 |
finally: |
|
1145
by Jelmer Vernooij
Fix write locking when pushing to new branch. |
158 |
branch.unlock() |
520.1.9
by Jelmer Vernooij
Fill in functions for creating new branches. |
159 |
return branch |
520.1.5
by Jelmer Vernooij
More work on supporting creating branches. |
160 |
|
109
by Jelmer Vernooij
Little bit of work on initializing Subversion repositories. |
161 |
def create_branch(self): |
162 |
"""See BzrDir.create_branch()."""
|
|
421.1.24
by Jelmer Vernooij
Support commits in heavy checkouts. |
163 |
from branch import SvnBranch |
469
by Jelmer Vernooij
Implement create_branch(). |
164 |
repos = self.find_repository() |
165 |
||
166 |
if self.branch_path != "": |
|
561
by Jelmer Vernooij
More work on intelligent guessing of branching schemes. |
167 |
# TODO: Set NULL_REVISION in SVN_PROP_BZR_BRANCHING_SCHEME
|
636
by Jelmer Vernooij
Fix test. |
168 |
repos.transport.mkdir(self.branch_path.strip("/")) |
1077
by Jelmer Vernooij
Use Repository.get_latest_revnum() rather than Repository.transport.get_latest_revnum() so it can be cached when there is a read lock. |
169 |
elif repos.get_latest_revnum() > 0: |
562
by Jelmer Vernooij
Error out when creating a new branch in a repository that already has revisions. |
170 |
# Bail out if there are already revisions in this repository
|
171 |
raise AlreadyBranchError(self.root_transport.base) |
|
559
by Jelmer Vernooij
Improve heuristics for determining branching schemes. |
172 |
branch = SvnBranch(self.root_transport.base, repos, self.branch_path) |
222
by Jelmer Vernooij
Fix creating branches. |
173 |
branch.bzrdir = self |
174 |
return branch |
|
16
by Jelmer Vernooij
Fix up to connect |
175 |
|
176 |
def open_branch(self, unsupported=True): |
|
109
by Jelmer Vernooij
Little bit of work on initializing Subversion repositories. |
177 |
"""See BzrDir.open_branch()."""
|
421.1.24
by Jelmer Vernooij
Support commits in heavy checkouts. |
178 |
from branch import SvnBranch |
342
by Jelmer Vernooij
Properly implement SvnRemoteAccess.open_repository() and |
179 |
repos = self.find_repository() |
559
by Jelmer Vernooij
Improve heuristics for determining branching schemes. |
180 |
branch = SvnBranch(self.root_transport.base, repos, self.branch_path) |
22
by Jelmer Vernooij
Couple of small fixes |
181 |
branch.bzrdir = self |
18
by Jelmer Vernooij
Add some more dummy functions |
182 |
return branch |
109
by Jelmer Vernooij
Little bit of work on initializing Subversion repositories. |
183 |
|
639
by Jelmer Vernooij
Add more docstrings, general cleanups. |
184 |
def create_repository(self, shared=False, format=None): |
629.1.3
by Jelmer Vernooij
Remove test runs - can't be used inside Bazaar control dirs. |
185 |
"""See BzrDir.create_repository."""
|
186 |
return self.open_repository() |
|
187 |
||
15
by Jelmer Vernooij
Update to new bzr API's |
188 |