bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
0.200.18
by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc. |
1 |
# Copyright (C) 2007 Canonical Ltd
|
0.358.2
by Jelmer Vernooij
Refresh copyright headers, add my email. |
2 |
# Copyright (C) 2010-2018 Jelmer Vernooij
|
0.200.18
by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc. |
3 |
#
|
4 |
# This program is free software; you can redistribute it and/or modify
|
|
5 |
# it under the terms of the GNU General Public License as published by
|
|
6 |
# the Free Software Foundation; either version 2 of the License, or
|
|
7 |
# (at your option) any later version.
|
|
8 |
#
|
|
9 |
# This program is distributed in the hope that it will be useful,
|
|
10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12 |
# GNU General Public License for more details.
|
|
13 |
#
|
|
14 |
# You should have received a copy of the GNU General Public License
|
|
15 |
# along with this program; if not, write to the Free Software
|
|
0.358.1
by Jelmer Vernooij
Fix FSF address. |
16 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
0.200.18
by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc. |
17 |
|
0.200.1012
by Jelmer Vernooij
Rename BzrDir to ControlDir. |
18 |
"""An adapter between a Git control dir and a Bazaar ControlDir."""
|
0.200.18
by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc. |
19 |
|
7479.2.1
by Jelmer Vernooij
Drop python2 support. |
20 |
import contextlib |
21 |
||
6986.2.1
by Jelmer Vernooij
Move breezy.plugins.git to breezy.git. |
22 |
from .. import ( |
0.200.1688
by Jelmer Vernooij
Fix stacking tests. |
23 |
branch as _mod_branch, |
7143.7.1
by Jelmer Vernooij
Simplify brz-git, drop imports. |
24 |
errors as brz_errors, |
0.200.1137
by Jelmer Vernooij
Support BzrProber.known_formats(). |
25 |
trace, |
0.200.1172
by Jelmer Vernooij
Provide GitDir._available_backup_name. |
26 |
osutils, |
0.200.18
by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc. |
27 |
urlutils, |
28 |
)
|
|
6986.2.1
by Jelmer Vernooij
Move breezy.plugins.git to breezy.git. |
29 |
from ..transport import ( |
0.310.14
by Jelmer Vernooij
merge lightweight checkout-in-git support. |
30 |
do_catching_redirections, |
31 |
get_transport_from_path, |
|
32 |
)
|
|
0.200.18
by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc. |
33 |
|
6986.2.1
by Jelmer Vernooij
Move breezy.plugins.git to breezy.git. |
34 |
from ..controldir import ( |
0.416.1
by Jelmer Vernooij
Raise BranchReferenceLoop. |
35 |
BranchReferenceLoop, |
0.200.1111
by Jelmer Vernooij
Drop support for Bazaar < 2.3. |
36 |
ControlDir, |
0.200.1137
by Jelmer Vernooij
Support BzrProber.known_formats(). |
37 |
ControlDirFormat, |
0.200.1111
by Jelmer Vernooij
Drop support for Bazaar < 2.3. |
38 |
format_registry, |
0.200.1702
by Jelmer Vernooij
Implement GitDir.acquire_repository. |
39 |
RepositoryAcquisitionPolicy, |
0.200.1111
by Jelmer Vernooij
Drop support for Bazaar < 2.3. |
40 |
)
|
0.200.18
by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc. |
41 |
|
7490.70.1
by Jelmer Vernooij
Add functions for encoding/decoding git paths. |
42 |
from .mapping import ( |
43 |
decode_git_path, |
|
44 |
encode_git_path, |
|
45 |
)
|
|
0.419.1
by Jelmer Vernooij
Simplify pushing to Git directories. |
46 |
from .push import ( |
47 |
GitPushResult, |
|
48 |
)
|
|
0.311.3
by Jelmer Vernooij
Fix handling of lightweight checkouts. |
49 |
from .transportgit import ( |
50 |
OBJECTDIR, |
|
51 |
TransportObjectStore, |
|
52 |
)
|
|
53 |
||
0.200.123
by Jelmer Vernooij
Use central git module. |
54 |
|
0.200.1026
by Jelmer Vernooij
Fix typo. |
55 |
class GitDirConfig(object): |
0.200.1025
by Jelmer Vernooij
Implement GitDir.get_config(). |
56 |
|
57 |
def get_default_stack_on(self): |
|
58 |
return None |
|
59 |
||
60 |
def set_default_stack_on(self, value): |
|
7143.7.1
by Jelmer Vernooij
Simplify brz-git, drop imports. |
61 |
raise brz_errors.BzrError("Cannot set configuration") |
0.200.1025
by Jelmer Vernooij
Implement GitDir.get_config(). |
62 |
|
63 |
||
0.200.1137
by Jelmer Vernooij
Support BzrProber.known_formats(). |
64 |
class GitControlDirFormat(ControlDirFormat): |
65 |
||
66 |
colocated_branches = True |
|
67 |
fixed_components = True |
|
68 |
||
69 |
def __eq__(self, other): |
|
70 |
return type(self) == type(other) |
|
71 |
||
72 |
def is_supported(self): |
|
73 |
return True |
|
74 |
||
75 |
def network_name(self): |
|
7018.3.2
by Jelmer Vernooij
Fix some git tests. |
76 |
return b"git" |
0.200.1137
by Jelmer Vernooij
Support BzrProber.known_formats(). |
77 |
|
78 |
||
0.200.1702
by Jelmer Vernooij
Implement GitDir.acquire_repository. |
79 |
class UseExistingRepository(RepositoryAcquisitionPolicy): |
80 |
"""A policy of reusing an existing repository""" |
|
81 |
||
82 |
def __init__(self, repository, stack_on=None, stack_on_pwd=None, |
|
83 |
require_stacking=False): |
|
84 |
"""Constructor. |
|
85 |
||
86 |
:param repository: The repository to use.
|
|
87 |
:param stack_on: A location to stack on
|
|
88 |
:param stack_on_pwd: If stack_on is relative, the location it is
|
|
89 |
relative to.
|
|
90 |
"""
|
|
91 |
super(UseExistingRepository, self).__init__( |
|
7143.15.2
by Jelmer Vernooij
Run autopep8. |
92 |
stack_on, stack_on_pwd, require_stacking) |
0.200.1702
by Jelmer Vernooij
Implement GitDir.acquire_repository. |
93 |
self._repository = repository |
94 |
||
95 |
def acquire_repository(self, make_working_trees=None, shared=False, |
|
7143.15.2
by Jelmer Vernooij
Run autopep8. |
96 |
possible_transports=None): |
0.200.1702
by Jelmer Vernooij
Implement GitDir.acquire_repository. |
97 |
"""Implementation of RepositoryAcquisitionPolicy.acquire_repository |
98 |
||
99 |
Returns an existing repository to use.
|
|
100 |
"""
|
|
101 |
return self._repository, False |
|
102 |
||
103 |
||
0.200.1012
by Jelmer Vernooij
Rename BzrDir to ControlDir. |
104 |
class GitDir(ControlDir): |
0.200.18
by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc. |
105 |
"""An adapter to the '.git' dir used by git.""" |
106 |
||
0.200.148
by Jelmer Vernooij
Share more infrastructure between LocalGitDir and RemoteGitDir. |
107 |
def is_supported(self): |
108 |
return True |
|
109 |
||
0.200.981
by Jelmer Vernooij
Mark git directories as not convertable (for now). |
110 |
def can_convert_format(self): |
111 |
return False |
|
112 |
||
0.200.1025
by Jelmer Vernooij
Implement GitDir.get_config(). |
113 |
def break_lock(self): |
0.314.1
by Jelmer Vernooij
Mark ControlDir.break_lock as not implemented. |
114 |
# There are no global locks, so nothing to break.
|
115 |
raise NotImplementedError(self.break_lock) |
|
0.200.1025
by Jelmer Vernooij
Implement GitDir.get_config(). |
116 |
|
0.200.155
by Jelmer Vernooij
Fix formatting, remove catch-all for exceptions when opening local repositories. |
117 |
def cloning_metadir(self, stacked=False): |
0.288.1
by Jelmer Vernooij
Use git format as default for clones. |
118 |
return format_registry.make_controldir("git") |
0.200.155
by Jelmer Vernooij
Fix formatting, remove catch-all for exceptions when opening local repositories. |
119 |
|
0.200.1165
by Jelmer Vernooij
Implement GitDir.checkout_metadir. |
120 |
def checkout_metadir(self, stacked=False): |
0.288.1
by Jelmer Vernooij
Use git format as default for clones. |
121 |
return format_registry.make_controldir("git") |
0.200.1165
by Jelmer Vernooij
Implement GitDir.checkout_metadir. |
122 |
|
0.269.8
by Jelmer Vernooij
Support push in git-remote-bzr. |
123 |
def _get_selected_ref(self, branch, ref=None): |
124 |
if ref is not None and branch is not None: |
|
7143.7.1
by Jelmer Vernooij
Simplify brz-git, drop imports. |
125 |
raise brz_errors.BzrError("can't specify both ref and branch") |
0.269.8
by Jelmer Vernooij
Support push in git-remote-bzr. |
126 |
if ref is not None: |
127 |
return ref |
|
0.303.2
by Jelmer Vernooij
Fix resolution order for segment parameters. |
128 |
if branch is not None: |
129 |
from .refs import branch_name_to_ref |
|
130 |
return branch_name_to_ref(branch) |
|
0.200.1559
by Jelmer Vernooij
Fix compatibility with bzr 2.5. |
131 |
segment_parameters = getattr( |
132 |
self.user_transport, "get_segment_parameters", lambda: {})() |
|
133 |
ref = segment_parameters.get("ref") |
|
134 |
if ref is not None: |
|
7045.4.2
by Jelmer Vernooij
Fix some more gitty tests. |
135 |
return urlutils.unquote_to_bytes(ref) |
0.200.1310
by Jelmer Vernooij
Add _get_selected_ref method. |
136 |
if branch is None and getattr(self, "_get_selected_branch", False): |
137 |
branch = self._get_selected_branch() |
|
0.303.2
by Jelmer Vernooij
Fix resolution order for segment parameters. |
138 |
if branch is not None: |
139 |
from .refs import branch_name_to_ref |
|
140 |
return branch_name_to_ref(branch) |
|
0.303.1
by Jelmer Vernooij
Remove _get_default_ref. |
141 |
return b"HEAD" |
0.200.1310
by Jelmer Vernooij
Add _get_selected_ref method. |
142 |
|
0.200.1025
by Jelmer Vernooij
Implement GitDir.get_config(). |
143 |
def get_config(self): |
144 |
return GitDirConfig() |
|
145 |
||
0.200.1172
by Jelmer Vernooij
Provide GitDir._available_backup_name. |
146 |
def _available_backup_name(self, base): |
147 |
return osutils.available_backup_name(base, self.root_transport.has) |
|
148 |
||
0.259.1
by Jelmer Vernooij
Provide custom GitDir.sprout() for bzr 2.4 compatibility. |
149 |
def sprout(self, url, revision_id=None, force_new_repo=False, |
150 |
recurse='down', possible_transports=None, |
|
151 |
accelerator_tree=None, hardlink=False, stacked=False, |
|
152 |
source_branch=None, create_tree_if_local=True): |
|
6986.2.1
by Jelmer Vernooij
Move breezy.plugins.git to breezy.git. |
153 |
from ..repository import InterRepository |
154 |
from ..transport.local import LocalTransport |
|
155 |
from ..transport import get_transport |
|
0.259.1
by Jelmer Vernooij
Provide custom GitDir.sprout() for bzr 2.4 compatibility. |
156 |
target_transport = get_transport(url, possible_transports) |
157 |
target_transport.ensure_base() |
|
158 |
cloning_format = self.cloning_metadir() |
|
159 |
# Create/update the result branch
|
|
0.310.15
by Jelmer Vernooij
Handle destroy_workingtree. |
160 |
try: |
161 |
result = ControlDir.open_from_transport(target_transport) |
|
7143.7.1
by Jelmer Vernooij
Simplify brz-git, drop imports. |
162 |
except brz_errors.NotBranchError: |
0.310.15
by Jelmer Vernooij
Handle destroy_workingtree. |
163 |
result = cloning_format.initialize_on_transport(target_transport) |
0.200.1373
by Jelmer Vernooij
Prevent accidentally removing branch. |
164 |
source_branch = self.open_branch() |
0.259.1
by Jelmer Vernooij
Provide custom GitDir.sprout() for bzr 2.4 compatibility. |
165 |
source_repository = self.find_repository() |
166 |
try: |
|
167 |
result_repo = result.find_repository() |
|
7143.7.1
by Jelmer Vernooij
Simplify brz-git, drop imports. |
168 |
except brz_errors.NoRepositoryPresent: |
0.259.1
by Jelmer Vernooij
Provide custom GitDir.sprout() for bzr 2.4 compatibility. |
169 |
result_repo = result.create_repository() |
170 |
if stacked: |
|
7143.15.2
by Jelmer Vernooij
Run autopep8. |
171 |
raise _mod_branch.UnstackableBranchFormat( |
172 |
self._format, self.user_url) |
|
0.259.1
by Jelmer Vernooij
Provide custom GitDir.sprout() for bzr 2.4 compatibility. |
173 |
interrepo = InterRepository.get(source_repository, result_repo) |
174 |
||
175 |
if revision_id is not None: |
|
0.259.4
by Jelmer Vernooij
Put determine_wants methods on InterRepo. |
176 |
determine_wants = interrepo.get_determine_wants_revids( |
0.200.1777
by Jelmer Vernooij
Copy tags. |
177 |
[revision_id], include_tags=True) |
0.259.1
by Jelmer Vernooij
Provide custom GitDir.sprout() for bzr 2.4 compatibility. |
178 |
else: |
0.259.4
by Jelmer Vernooij
Put determine_wants methods on InterRepo. |
179 |
determine_wants = interrepo.determine_wants_all |
0.259.1
by Jelmer Vernooij
Provide custom GitDir.sprout() for bzr 2.4 compatibility. |
180 |
interrepo.fetch_objects(determine_wants=determine_wants, |
7143.15.2
by Jelmer Vernooij
Run autopep8. |
181 |
mapping=source_branch.mapping) |
7143.15.3
by Jelmer Vernooij
Fix pep8 issues in breezy.git. |
182 |
result_branch = source_branch.sprout( |
183 |
result, revision_id=revision_id, repository=result_repo) |
|
7143.15.2
by Jelmer Vernooij
Run autopep8. |
184 |
if (create_tree_if_local and |
7290.26.1
by Jelmer Vernooij
Fix switching in git repositories. |
185 |
result.open_branch(name="").name == result_branch.name and |
7143.15.2
by Jelmer Vernooij
Run autopep8. |
186 |
isinstance(target_transport, LocalTransport) and |
187 |
(result_repo is None or result_repo.make_working_trees())): |
|
7404.5.1
by Jelmer Vernooij
Support checking out nested trees, including for git repositories. |
188 |
wt = result.create_workingtree( |
7143.15.3
by Jelmer Vernooij
Fix pep8 issues in breezy.git. |
189 |
accelerator_tree=accelerator_tree, |
190 |
hardlink=hardlink, from_branch=result_branch) |
|
7404.5.1
by Jelmer Vernooij
Support checking out nested trees, including for git repositories. |
191 |
else: |
192 |
wt = None |
|
193 |
if recurse == 'down': |
|
7479.2.1
by Jelmer Vernooij
Drop python2 support. |
194 |
with contextlib.ExitStack() as stack: |
7404.5.5
by Jelmer Vernooij
Fix tests. |
195 |
basis = None |
196 |
if wt is not None: |
|
197 |
basis = wt.basis_tree() |
|
198 |
elif result_branch is not None: |
|
199 |
basis = result_branch.basis_tree() |
|
200 |
elif source_branch is not None: |
|
201 |
basis = source_branch.basis_tree() |
|
202 |
if basis is not None: |
|
203 |
stack.enter_context(basis.lock_read()) |
|
204 |
subtrees = basis.iter_references() |
|
205 |
else: |
|
206 |
subtrees = [] |
|
207 |
for path in subtrees: |
|
208 |
target = urlutils.join(url, urlutils.escape(path)) |
|
7447.3.1
by Jelmer Vernooij
Move tree reference info functions to workingtree. |
209 |
sublocation = wt.reference_parent( |
7404.5.5
by Jelmer Vernooij
Fix tests. |
210 |
path, possible_transports=possible_transports) |
7447.3.1
by Jelmer Vernooij
Move tree reference info functions to workingtree. |
211 |
if sublocation is None: |
212 |
trace.warning( |
|
213 |
'Ignoring nested tree %s, parent location unknown.', |
|
214 |
path) |
|
215 |
continue
|
|
7404.5.5
by Jelmer Vernooij
Fix tests. |
216 |
sublocation.controldir.sprout( |
217 |
target, basis.get_reference_revision(path), |
|
218 |
force_new_repo=force_new_repo, recurse=recurse, |
|
219 |
stacked=stacked) |
|
7490.95.2
by Jelmer Vernooij
Special case git. |
220 |
if getattr(result_repo, '_git', None): |
221 |
# Don't leak resources:
|
|
222 |
# TODO(jelmer): This shouldn't be git-specific, and possibly
|
|
223 |
# just use read locks.
|
|
224 |
result_repo._git.object_store.close() |
|
0.259.1
by Jelmer Vernooij
Provide custom GitDir.sprout() for bzr 2.4 compatibility. |
225 |
return result |
226 |
||
0.200.1117
by Jelmer Vernooij
Provide basic implementation of GitDir.clone_on_transport. |
227 |
def clone_on_transport(self, transport, revision_id=None, |
7143.15.3
by Jelmer Vernooij
Fix pep8 issues in breezy.git. |
228 |
force_new_repo=False, preserve_stacking=False, |
229 |
stacked_on=None, create_prefix=False, |
|
7489.4.2
by Jelmer Vernooij
Plumb through tag_selector. |
230 |
use_existing_dir=True, no_tree=False, |
231 |
tag_selector=None): |
|
0.200.1117
by Jelmer Vernooij
Provide basic implementation of GitDir.clone_on_transport. |
232 |
"""See ControlDir.clone_on_transport.""" |
6986.2.1
by Jelmer Vernooij
Move breezy.plugins.git to breezy.git. |
233 |
from ..repository import InterRepository |
0.200.1644
by Jelmer Vernooij
More relative imports. |
234 |
from .mapping import default_mapping |
7490.13.4
by Jelmer Vernooij
Fix git clone. |
235 |
from ..transport.local import LocalTransport |
0.285.3
by Jelmer Vernooij
Fix handling of stacking requests. |
236 |
if stacked_on is not None: |
7143.15.2
by Jelmer Vernooij
Run autopep8. |
237 |
raise _mod_branch.UnstackableBranchFormat( |
238 |
self._format, self.user_url) |
|
0.200.1119
by Jelmer Vernooij
Refactor repository initialization. |
239 |
if no_tree: |
240 |
format = BareLocalGitControlDirFormat() |
|
241 |
else: |
|
242 |
format = LocalGitControlDirFormat() |
|
0.200.1778
by Jelmer Vernooij
Fix cloning to non-last revision. |
243 |
(target_repo, target_controldir, stacking, |
7143.15.2
by Jelmer Vernooij
Run autopep8. |
244 |
repo_policy) = format.initialize_on_transport_ex( |
245 |
transport, use_existing_dir=use_existing_dir, |
|
246 |
create_prefix=create_prefix, |
|
247 |
force_new_repo=force_new_repo) |
|
0.330.1
by Jelmer Vernooij
Fix initialize_on_transport_ex without repo_format specified. |
248 |
target_repo = target_controldir.find_repository() |
0.200.1119
by Jelmer Vernooij
Refactor repository initialization. |
249 |
target_git_repo = target_repo._git |
0.302.1
by Jelmer Vernooij
Implement .find_repository. |
250 |
source_repo = self.find_repository() |
0.200.1171
by Jelmer Vernooij
Fix some more tests. |
251 |
interrepo = InterRepository.get(source_repo, target_repo) |
0.200.1117
by Jelmer Vernooij
Provide basic implementation of GitDir.clone_on_transport. |
252 |
if revision_id is not None: |
7143.15.2
by Jelmer Vernooij
Run autopep8. |
253 |
determine_wants = interrepo.get_determine_wants_revids( |
7489.4.2
by Jelmer Vernooij
Plumb through tag_selector. |
254 |
[revision_id], include_tags=True, tag_selector=tag_selector) |
0.200.1117
by Jelmer Vernooij
Provide basic implementation of GitDir.clone_on_transport. |
255 |
else: |
0.200.1171
by Jelmer Vernooij
Fix some more tests. |
256 |
determine_wants = interrepo.determine_wants_all |
257 |
(pack_hint, _, refs) = interrepo.fetch_objects(determine_wants, |
|
7143.15.2
by Jelmer Vernooij
Run autopep8. |
258 |
mapping=default_mapping) |
7479.2.1
by Jelmer Vernooij
Drop python2 support. |
259 |
for name, val in refs.items(): |
0.200.1117
by Jelmer Vernooij
Provide basic implementation of GitDir.clone_on_transport. |
260 |
target_git_repo.refs[name] = val |
7490.13.3
by Jelmer Vernooij
Fix git branch cloning. |
261 |
result_dir = LocalGitDir(transport, target_git_repo, format) |
0.336.7
by Jelmer Vernooij
Fix remaining tests. |
262 |
if revision_id is not None: |
263 |
result_dir.open_branch().set_last_revision(revision_id) |
|
7490.13.4
by Jelmer Vernooij
Fix git clone. |
264 |
if not no_tree and isinstance(result_dir.root_transport, LocalTransport): |
0.428.1
by Jelmer Vernooij
Fix clone_preserves_content test. |
265 |
if result_dir.open_repository().make_working_trees(): |
7490.13.6
by Jelmer Vernooij
Fix tests. |
266 |
try: |
267 |
local_wt = self.open_workingtree() |
|
7490.13.7
by Jelmer Vernooij
Fix git tests. |
268 |
except brz_errors.NoWorkingTree: |
269 |
pass
|
|
7490.13.6
by Jelmer Vernooij
Fix tests. |
270 |
except brz_errors.NotLocalUrl: |
271 |
result_dir.create_workingtree(revision_id=revision_id) |
|
272 |
else: |
|
273 |
local_wt.clone(result_dir, revision_id=revision_id) |
|
0.428.1
by Jelmer Vernooij
Fix clone_preserves_content test. |
274 |
|
0.336.7
by Jelmer Vernooij
Fix remaining tests. |
275 |
return result_dir |
0.200.1117
by Jelmer Vernooij
Provide basic implementation of GitDir.clone_on_transport. |
276 |
|
0.259.2
by Jelmer Vernooij
Make sure RemoteGitDir.find_repository works. |
277 |
def find_repository(self): |
278 |
"""Find the repository that should be used. |
|
279 |
||
280 |
This does not require a branch as we use it to find the repo for
|
|
281 |
new branches as well as to hook existing branches up to their
|
|
282 |
repository.
|
|
283 |
"""
|
|
0.310.14
by Jelmer Vernooij
merge lightweight checkout-in-git support. |
284 |
return self._gitrepository_class(self._find_commondir()) |
0.259.2
by Jelmer Vernooij
Make sure RemoteGitDir.find_repository works. |
285 |
|
0.200.1487
by Jelmer Vernooij
Use peeling. |
286 |
def get_refs_container(self): |
287 |
"""Retrieve the refs container. |
|
0.200.1434
by Jelmer Vernooij
Move refs access to control dir. |
288 |
"""
|
0.200.1487
by Jelmer Vernooij
Use peeling. |
289 |
raise NotImplementedError(self.get_refs_container) |
0.200.1434
by Jelmer Vernooij
Move refs access to control dir. |
290 |
|
0.200.1701
by Jelmer Vernooij
Fix a few tests. |
291 |
def determine_repository_policy(self, force_new_repo=False, stack_on=None, |
292 |
stack_on_pwd=None, require_stacking=False): |
|
293 |
"""Return an object representing a policy to use. |
|
294 |
||
295 |
This controls whether a new repository is created, and the format of
|
|
296 |
that repository, or some existing shared repository used instead.
|
|
297 |
||
298 |
If stack_on is supplied, will not seek a containing shared repo.
|
|
299 |
||
300 |
:param force_new_repo: If True, require a new repository to be created.
|
|
301 |
:param stack_on: If supplied, the location to stack on. If not
|
|
302 |
supplied, a default_stack_on location may be used.
|
|
303 |
:param stack_on_pwd: If stack_on is relative, the location it is
|
|
304 |
relative to.
|
|
305 |
"""
|
|
0.302.1
by Jelmer Vernooij
Implement .find_repository. |
306 |
return UseExistingRepository(self.find_repository()) |
0.200.1701
by Jelmer Vernooij
Fix a few tests. |
307 |
|
7490.13.2
by Jelmer Vernooij
Fix reference handling. |
308 |
def branch_names(self): |
309 |
from .refs import ref_to_branch_name |
|
310 |
ret = [] |
|
311 |
for ref in self.get_refs_container().keys(): |
|
312 |
try: |
|
313 |
branch_name = ref_to_branch_name(ref) |
|
314 |
except UnicodeDecodeError: |
|
315 |
trace.warning("Ignoring branch %r with unicode error ref", ref) |
|
316 |
continue
|
|
317 |
except ValueError: |
|
318 |
continue
|
|
319 |
ret.append(branch_name) |
|
320 |
return ret |
|
321 |
||
0.377.1
by Jelmer Vernooij
Fix some remote operations and add more tests. |
322 |
def get_branches(self): |
323 |
from .refs import ref_to_branch_name |
|
324 |
ret = {} |
|
325 |
for ref in self.get_refs_container().keys(): |
|
326 |
try: |
|
327 |
branch_name = ref_to_branch_name(ref) |
|
328 |
except UnicodeDecodeError: |
|
329 |
trace.warning("Ignoring branch %r with unicode error ref", ref) |
|
330 |
continue
|
|
7295.2.1
by Jelmer Vernooij
Fix some issues reported by lgtm.com. |
331 |
except ValueError: |
332 |
continue
|
|
0.377.1
by Jelmer Vernooij
Fix some remote operations and add more tests. |
333 |
ret[branch_name] = self.open_branch(ref=ref) |
334 |
return ret |
|
335 |
||
336 |
def list_branches(self): |
|
7045.4.1
by Jelmer Vernooij
Some brz-git fixes. |
337 |
return list(self.get_branches().values()) |
0.377.1
by Jelmer Vernooij
Fix some remote operations and add more tests. |
338 |
|
0.419.1
by Jelmer Vernooij
Simplify pushing to Git directories. |
339 |
def push_branch(self, source, revision_id=None, overwrite=False, |
340 |
remember=False, create_prefix=False, lossy=False, |
|
7489.4.4
by Jelmer Vernooij
Add more tests. |
341 |
name=None, tag_selector=None): |
0.419.1
by Jelmer Vernooij
Simplify pushing to Git directories. |
342 |
"""Push the source branch into this ControlDir.""" |
343 |
push_result = GitPushResult() |
|
344 |
push_result.workingtree_updated = None |
|
345 |
push_result.master_branch = None |
|
346 |
push_result.source_branch = source |
|
347 |
push_result.stacked_on = None |
|
348 |
from .branch import GitBranch |
|
349 |
if isinstance(source, GitBranch) and lossy: |
|
7143.7.1
by Jelmer Vernooij
Simplify brz-git, drop imports. |
350 |
raise brz_errors.LossyPushToSameVCS(source.controldir, self) |
0.419.1
by Jelmer Vernooij
Simplify pushing to Git directories. |
351 |
target = self.open_branch(name, nascent_ok=True) |
352 |
push_result.branch_push_result = source.push( |
|
7143.15.2
by Jelmer Vernooij
Run autopep8. |
353 |
target, overwrite=overwrite, stop_revision=revision_id, |
7489.4.4
by Jelmer Vernooij
Add more tests. |
354 |
lossy=lossy, tag_selector=tag_selector) |
0.419.1
by Jelmer Vernooij
Simplify pushing to Git directories. |
355 |
push_result.new_revid = push_result.branch_push_result.new_revid |
356 |
push_result.old_revid = push_result.branch_push_result.old_revid |
|
7290.26.1
by Jelmer Vernooij
Fix switching in git repositories. |
357 |
try: |
358 |
wt = self.open_workingtree() |
|
359 |
except brz_errors.NoWorkingTree: |
|
360 |
push_result.workingtree_updated = None |
|
361 |
else: |
|
362 |
if self.open_branch(name="").name == target.name: |
|
363 |
wt._update_git_tree( |
|
364 |
old_revision=push_result.old_revid, |
|
365 |
new_revision=push_result.new_revid) |
|
366 |
push_result.workingtree_updated = True |
|
367 |
else: |
|
368 |
push_result.workingtree_updated = False |
|
7143.15.3
by Jelmer Vernooij
Fix pep8 issues in breezy.git. |
369 |
push_result.target_branch = target |
0.419.1
by Jelmer Vernooij
Simplify pushing to Git directories. |
370 |
if source.get_push_location() is None or remember: |
371 |
source.set_push_location(push_result.target_branch.base) |
|
372 |
return push_result |
|
373 |
||
0.200.148
by Jelmer Vernooij
Share more infrastructure between LocalGitDir and RemoteGitDir. |
374 |
|
0.200.1137
by Jelmer Vernooij
Support BzrProber.known_formats(). |
375 |
class LocalGitControlDirFormat(GitControlDirFormat): |
376 |
"""The .git directory control format.""" |
|
377 |
||
378 |
bare = False |
|
379 |
||
380 |
@classmethod
|
|
381 |
def _known_formats(self): |
|
382 |
return set([LocalGitControlDirFormat()]) |
|
383 |
||
384 |
@property
|
|
385 |
def repository_format(self): |
|
0.200.1644
by Jelmer Vernooij
More relative imports. |
386 |
from .repository import GitRepositoryFormat |
0.200.1137
by Jelmer Vernooij
Support BzrProber.known_formats(). |
387 |
return GitRepositoryFormat() |
388 |
||
0.290.3
by Jelmer Vernooij
Set workingtree_format on LocalGitDirFormat. |
389 |
@property
|
390 |
def workingtree_format(self): |
|
391 |
from .workingtree import GitWorkingTreeFormat |
|
392 |
return GitWorkingTreeFormat() |
|
393 |
||
0.200.1137
by Jelmer Vernooij
Support BzrProber.known_formats(). |
394 |
def get_branch_format(self): |
0.295.1
by Jelmer Vernooij
Split up branch formats. |
395 |
from .branch import LocalGitBranchFormat |
396 |
return LocalGitBranchFormat() |
|
0.200.1137
by Jelmer Vernooij
Support BzrProber.known_formats(). |
397 |
|
398 |
def open(self, transport, _found=None): |
|
399 |
"""Open this directory. |
|
400 |
||
401 |
"""
|
|
0.200.1644
by Jelmer Vernooij
More relative imports. |
402 |
from .transportgit import TransportRepo |
7143.15.2
by Jelmer Vernooij
Run autopep8. |
403 |
|
7096.1.2
by Jelmer Vernooij
Fix redirection handling for git. |
404 |
def _open(transport): |
7380.1.1
by Jelmer Vernooij
Several more fixes for git merge proposals. |
405 |
try: |
406 |
return TransportRepo(transport, self.bare, |
|
407 |
refs_text=getattr(self, "_refs_text", None)) |
|
408 |
except ValueError as e: |
|
409 |
if e.args == ('Expected file to start with \'gitdir: \'', ): |
|
410 |
raise brz_errors.NotBranchError(path=transport.base) |
|
411 |
raise
|
|
7143.15.2
by Jelmer Vernooij
Run autopep8. |
412 |
|
7096.1.2
by Jelmer Vernooij
Fix redirection handling for git. |
413 |
def redirected(transport, e, redirection_notice): |
414 |
trace.note(redirection_notice) |
|
415 |
return transport._redirected_to(e.source, e.target) |
|
416 |
gitrepo = do_catching_redirections(_open, transport, redirected) |
|
7413.4.3
by Jelmer Vernooij
Don't re-probe when opening control directory. |
417 |
if not _found and not gitrepo._controltransport.has('objects'): |
7411.1.3
by Jelmer Vernooij
Fix tests. |
418 |
raise brz_errors.NotBranchError(path=transport.base) |
0.200.1411
by Jelmer Vernooij
Fix control files. |
419 |
return LocalGitDir(transport, gitrepo, self) |
0.200.1137
by Jelmer Vernooij
Support BzrProber.known_formats(). |
420 |
|
421 |
def get_format_description(self): |
|
422 |
return "Local Git Repository" |
|
423 |
||
424 |
def initialize_on_transport(self, transport): |
|
0.200.1644
by Jelmer Vernooij
More relative imports. |
425 |
from .transportgit import TransportRepo |
7143.15.3
by Jelmer Vernooij
Fix pep8 issues in breezy.git. |
426 |
git_repo = TransportRepo.init(transport, bare=self.bare) |
427 |
return LocalGitDir(transport, git_repo, self) |
|
0.200.1137
by Jelmer Vernooij
Support BzrProber.known_formats(). |
428 |
|
429 |
def initialize_on_transport_ex(self, transport, use_existing_dir=False, |
|
7143.15.3
by Jelmer Vernooij
Fix pep8 issues in breezy.git. |
430 |
create_prefix=False, force_new_repo=False, |
431 |
stacked_on=None, |
|
432 |
stack_on_pwd=None, repo_format_name=None, |
|
433 |
make_working_trees=None, |
|
7143.15.2
by Jelmer Vernooij
Run autopep8. |
434 |
shared_repo=False, vfs_only=False): |
7385.2.2
by Jelmer Vernooij
Raise exception when requesting shared repository be created. |
435 |
if shared_repo: |
436 |
raise brz_errors.SharedRepositoriesUnsupported(self) |
|
437 |
||
0.200.1137
by Jelmer Vernooij
Support BzrProber.known_formats(). |
438 |
def make_directory(transport): |
439 |
transport.mkdir('.') |
|
440 |
return transport |
|
7143.15.2
by Jelmer Vernooij
Run autopep8. |
441 |
|
0.200.1137
by Jelmer Vernooij
Support BzrProber.known_formats(). |
442 |
def redirected(transport, e, redirection_notice): |
443 |
trace.note(redirection_notice) |
|
444 |
return transport._redirected_to(e.source, e.target) |
|
445 |
try: |
|
7143.15.6
by Jelmer Vernooij
Merge trunk. |
446 |
transport = do_catching_redirections( |
447 |
make_directory, transport, redirected) |
|
7143.7.1
by Jelmer Vernooij
Simplify brz-git, drop imports. |
448 |
except brz_errors.FileExists: |
0.200.1137
by Jelmer Vernooij
Support BzrProber.known_formats(). |
449 |
if not use_existing_dir: |
450 |
raise
|
|
7143.7.1
by Jelmer Vernooij
Simplify brz-git, drop imports. |
451 |
except brz_errors.NoSuchFile: |
0.200.1137
by Jelmer Vernooij
Support BzrProber.known_formats(). |
452 |
if not create_prefix: |
453 |
raise
|
|
454 |
transport.create_prefix() |
|
455 |
controldir = self.initialize_on_transport(transport) |
|
0.330.1
by Jelmer Vernooij
Fix initialize_on_transport_ex without repo_format specified. |
456 |
if repo_format_name: |
457 |
result_repo = controldir.find_repository() |
|
458 |
repository_policy = UseExistingRepository(result_repo) |
|
459 |
result_repo.lock_write() |
|
460 |
else: |
|
461 |
result_repo = None |
|
462 |
repository_policy = None |
|
463 |
return (result_repo, controldir, False, |
|
464 |
repository_policy) |
|
0.200.1137
by Jelmer Vernooij
Support BzrProber.known_formats(). |
465 |
|
466 |
def is_supported(self): |
|
467 |
return True |
|
468 |
||
0.200.1412
by Jelmer Vernooij
Implement GitControlDirFormat.supports_transport. |
469 |
def supports_transport(self, transport): |
470 |
try: |
|
471 |
external_url = transport.external_url() |
|
7143.7.1
by Jelmer Vernooij
Simplify brz-git, drop imports. |
472 |
except brz_errors.InProcessTransport: |
473 |
raise brz_errors.NotBranchError(path=transport.base) |
|
0.332.1
by Jelmer Vernooij
Mark LocalGitControlDir as not supporting http. |
474 |
return external_url.startswith("file:") |
0.200.1412
by Jelmer Vernooij
Implement GitControlDirFormat.supports_transport. |
475 |
|
7311.2.3
by Jelmer Vernooij
Drop find_trees. |
476 |
def is_control_filename(self, filename): |
477 |
return (filename == '.git' |
|
478 |
or filename.startswith('.git/') |
|
479 |
or filename.startswith('.git\\')) |
|
480 |
||
0.200.1137
by Jelmer Vernooij
Support BzrProber.known_formats(). |
481 |
|
482 |
class BareLocalGitControlDirFormat(LocalGitControlDirFormat): |
|
483 |
||
484 |
bare = True |
|
485 |
supports_workingtrees = False |
|
486 |
||
487 |
def get_format_description(self): |
|
488 |
return "Local Git Repository (bare)" |
|
489 |
||
7311.2.3
by Jelmer Vernooij
Drop find_trees. |
490 |
def is_control_filename(self, filename): |
491 |
return False |
|
492 |
||
0.200.1137
by Jelmer Vernooij
Support BzrProber.known_formats(). |
493 |
|
0.200.148
by Jelmer Vernooij
Share more infrastructure between LocalGitDir and RemoteGitDir. |
494 |
class LocalGitDir(GitDir): |
495 |
"""An adapter to the '.git' dir used by git.""" |
|
496 |
||
0.239.13
by Jelmer Vernooij
Don't break "bzr info -v" when Dulwich is not installed. |
497 |
def _get_gitrepository_class(self): |
0.200.1644
by Jelmer Vernooij
More relative imports. |
498 |
from .repository import LocalGitRepository |
0.239.13
by Jelmer Vernooij
Don't break "bzr info -v" when Dulwich is not installed. |
499 |
return LocalGitRepository |
500 |
||
0.200.1313
by Jelmer Vernooij
Add __repr__ |
501 |
def __repr__(self): |
502 |
return "<%s at %r>" % ( |
|
503 |
self.__class__.__name__, self.root_transport.base) |
|
504 |
||
0.239.13
by Jelmer Vernooij
Don't break "bzr info -v" when Dulwich is not installed. |
505 |
_gitrepository_class = property(_get_gitrepository_class) |
0.202.2
by David Allouche
GitRepository.get_inventory and .revision_tree work for the null revision. Support for testing GitRepository without disk data. |
506 |
|
0.200.1014
by Jelmer Vernooij
Fix tests. |
507 |
@property
|
508 |
def user_transport(self): |
|
509 |
return self.root_transport |
|
510 |
||
511 |
@property
|
|
512 |
def control_transport(self): |
|
0.398.1
by Jelmer Vernooij
Support reading .git files. |
513 |
return self._git._controltransport |
0.200.1014
by Jelmer Vernooij
Fix tests. |
514 |
|
0.200.1411
by Jelmer Vernooij
Fix control files. |
515 |
def __init__(self, transport, gitrepo, format): |
0.200.18
by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc. |
516 |
self._format = format |
517 |
self.root_transport = transport |
|
0.200.1018
by Jelmer Vernooij
Fix use with new control dir API. |
518 |
self._mode_check_done = False |
0.200.90
by Jelmer Vernooij
Basic support for opening working trees. |
519 |
self._git = gitrepo |
520 |
if gitrepo.bare: |
|
521 |
self.transport = transport |
|
522 |
else: |
|
523 |
self.transport = transport.clone('.git') |
|
0.200.381
by Jelmer Vernooij
Support working trees properly, status and ls. |
524 |
self._mode_check_done = None |
525 |
||
0.200.1311
by Jelmer Vernooij
More work on colocated branch support. |
526 |
def _get_symref(self, ref): |
0.310.14
by Jelmer Vernooij
merge lightweight checkout-in-git support. |
527 |
ref_chain, unused_sha = self._git.refs.follow(ref) |
528 |
if len(ref_chain) == 1: |
|
0.200.1311
by Jelmer Vernooij
More work on colocated branch support. |
529 |
return None |
0.310.14
by Jelmer Vernooij
merge lightweight checkout-in-git support. |
530 |
return ref_chain[1] |
0.200.1311
by Jelmer Vernooij
More work on colocated branch support. |
531 |
|
0.200.1773
by Jelmer Vernooij
Fix argument name. |
532 |
def set_branch_reference(self, target_branch, name=None): |
0.200.1311
by Jelmer Vernooij
More work on colocated branch support. |
533 |
ref = self._get_selected_ref(name) |
7143.15.3
by Jelmer Vernooij
Fix pep8 issues in breezy.git. |
534 |
target_transport = target_branch.controldir.control_transport |
535 |
if self.control_transport.base == target_transport.base: |
|
0.416.1
by Jelmer Vernooij
Raise BranchReferenceLoop. |
536 |
if ref == target_branch.ref: |
537 |
raise BranchReferenceLoop(target_branch) |
|
0.311.1
by Jelmer Vernooij
Support git lightweight checkouts. |
538 |
self._git.refs.set_symbolic_ref(ref, target_branch.ref) |
539 |
else: |
|
540 |
try: |
|
7143.15.6
by Jelmer Vernooij
Merge trunk. |
541 |
target_path = ( |
542 |
target_branch.controldir.control_transport.local_abspath( |
|
543 |
'.')) |
|
7143.7.1
by Jelmer Vernooij
Simplify brz-git, drop imports. |
544 |
except brz_errors.NotLocalUrl: |
7143.15.6
by Jelmer Vernooij
Merge trunk. |
545 |
raise brz_errors.IncompatibleFormat( |
7143.15.2
by Jelmer Vernooij
Run autopep8. |
546 |
target_branch._format, self._format) |
0.310.14
by Jelmer Vernooij
merge lightweight checkout-in-git support. |
547 |
# TODO(jelmer): Do some consistency checking across branches..
|
7143.15.2
by Jelmer Vernooij
Run autopep8. |
548 |
self.control_transport.put_bytes( |
7490.70.1
by Jelmer Vernooij
Add functions for encoding/decoding git paths. |
549 |
'commondir', encode_git_path(target_path)) |
0.311.3
by Jelmer Vernooij
Fix handling of lightweight checkouts. |
550 |
# TODO(jelmer): Urgh, avoid mucking about with internals.
|
7143.15.3
by Jelmer Vernooij
Fix pep8 issues in breezy.git. |
551 |
self._git._commontransport = ( |
552 |
target_branch.repository._git._commontransport.clone()) |
|
7143.15.2
by Jelmer Vernooij
Run autopep8. |
553 |
self._git.object_store = TransportObjectStore( |
554 |
self._git._commontransport.clone(OBJECTDIR)) |
|
0.311.3
by Jelmer Vernooij
Fix handling of lightweight checkouts. |
555 |
self._git.refs.transport = self._git._commontransport |
7143.15.3
by Jelmer Vernooij
Fix pep8 issues in breezy.git. |
556 |
target_ref_chain, unused_sha = ( |
557 |
target_branch.controldir._git.refs.follow(target_branch.ref)) |
|
0.310.14
by Jelmer Vernooij
merge lightweight checkout-in-git support. |
558 |
for target_ref in target_ref_chain: |
559 |
if target_ref == b'HEAD': |
|
560 |
continue
|
|
561 |
break
|
|
562 |
else: |
|
563 |
# Can't create a reference to something that is not a in a repository.
|
|
7143.15.6
by Jelmer Vernooij
Merge trunk. |
564 |
raise brz_errors.IncompatibleFormat( |
7143.15.2
by Jelmer Vernooij
Run autopep8. |
565 |
self.set_branch_reference, self) |
0.310.14
by Jelmer Vernooij
merge lightweight checkout-in-git support. |
566 |
self._git.refs.set_symbolic_ref(ref, target_ref) |
0.200.1311
by Jelmer Vernooij
More work on colocated branch support. |
567 |
|
568 |
def get_branch_reference(self, name=None): |
|
569 |
ref = self._get_selected_ref(name) |
|
570 |
target_ref = self._get_symref(ref) |
|
571 |
if target_ref is not None: |
|
0.303.3
by Jelmer Vernooij
Prefer using branch segment parameter in reference branch URLs. |
572 |
from .refs import ref_to_branch_name |
573 |
try: |
|
574 |
branch_name = ref_to_branch_name(target_ref) |
|
575 |
except ValueError: |
|
7143.15.2
by Jelmer Vernooij
Run autopep8. |
576 |
params = {'ref': urlutils.quote( |
577 |
target_ref.decode('utf-8'), '')} |
|
0.303.3
by Jelmer Vernooij
Prefer using branch segment parameter in reference branch URLs. |
578 |
else: |
7018.3.3
by Jelmer Vernooij
Fix url handling. |
579 |
if branch_name != '': |
7018.3.2
by Jelmer Vernooij
Fix some git tests. |
580 |
params = {'branch': urlutils.quote(branch_name, '')} |
0.303.3
by Jelmer Vernooij
Prefer using branch segment parameter in reference branch URLs. |
581 |
else: |
582 |
params = {} |
|
0.310.14
by Jelmer Vernooij
merge lightweight checkout-in-git support. |
583 |
try: |
7045.3.1
by Jelmer Vernooij
Fix another ~500 tests. |
584 |
commondir = self.control_transport.get_bytes('commondir') |
7143.7.1
by Jelmer Vernooij
Simplify brz-git, drop imports. |
585 |
except brz_errors.NoSuchFile: |
0.310.14
by Jelmer Vernooij
merge lightweight checkout-in-git support. |
586 |
base_url = self.user_url.rstrip('/') |
7045.3.1
by Jelmer Vernooij
Fix another ~500 tests. |
587 |
else: |
7143.15.2
by Jelmer Vernooij
Run autopep8. |
588 |
base_url = urlutils.local_path_to_url( |
7490.70.1
by Jelmer Vernooij
Add functions for encoding/decoding git paths. |
589 |
decode_git_path(commondir)).rstrip('/.git/') + '/' |
0.310.14
by Jelmer Vernooij
merge lightweight checkout-in-git support. |
590 |
return urlutils.join_segment_parameters(base_url, params) |
0.200.1311
by Jelmer Vernooij
More work on colocated branch support. |
591 |
return None |
592 |
||
593 |
def find_branch_format(self, name=None): |
|
0.200.1644
by Jelmer Vernooij
More relative imports. |
594 |
from .branch import ( |
0.295.1
by Jelmer Vernooij
Split up branch formats. |
595 |
LocalGitBranchFormat, |
0.200.1311
by Jelmer Vernooij
More work on colocated branch support. |
596 |
)
|
0.321.1
by Jelmer Vernooij
Remove unused GitSymrefBranchFormat. |
597 |
return LocalGitBranchFormat() |
0.200.1311
by Jelmer Vernooij
More work on colocated branch support. |
598 |
|
0.200.978
by Jelmer Vernooij
Allow name argument to get_branch_transport to be missing. |
599 |
def get_branch_transport(self, branch_format, name=None): |
0.200.18
by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc. |
600 |
if branch_format is None: |
601 |
return self.transport |
|
0.200.1012
by Jelmer Vernooij
Rename BzrDir to ControlDir. |
602 |
if isinstance(branch_format, LocalGitControlDirFormat): |
0.200.18
by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc. |
603 |
return self.transport |
7143.7.1
by Jelmer Vernooij
Simplify brz-git, drop imports. |
604 |
raise brz_errors.IncompatibleFormat(branch_format, self._format) |
0.200.18
by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc. |
605 |
|
0.200.887
by Jelmer Vernooij
get_branch_transport takes a name argument. |
606 |
def get_repository_transport(self, format): |
607 |
if format is None: |
|
608 |
return self.transport |
|
0.200.1012
by Jelmer Vernooij
Rename BzrDir to ControlDir. |
609 |
if isinstance(format, LocalGitControlDirFormat): |
0.200.887
by Jelmer Vernooij
get_branch_transport takes a name argument. |
610 |
return self.transport |
7143.7.1
by Jelmer Vernooij
Simplify brz-git, drop imports. |
611 |
raise brz_errors.IncompatibleFormat(format, self._format) |
0.200.887
by Jelmer Vernooij
get_branch_transport takes a name argument. |
612 |
|
613 |
def get_workingtree_transport(self, format): |
|
614 |
if format is None: |
|
615 |
return self.transport |
|
0.200.1012
by Jelmer Vernooij
Rename BzrDir to ControlDir. |
616 |
if isinstance(format, LocalGitControlDirFormat): |
0.200.887
by Jelmer Vernooij
get_branch_transport takes a name argument. |
617 |
return self.transport |
7143.7.1
by Jelmer Vernooij
Simplify brz-git, drop imports. |
618 |
raise brz_errors.IncompatibleFormat(format, self._format) |
0.200.18
by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc. |
619 |
|
0.269.8
by Jelmer Vernooij
Support push in git-remote-bzr. |
620 |
def open_branch(self, name=None, unsupported=False, ignore_fallbacks=None, |
7143.15.2
by Jelmer Vernooij
Run autopep8. |
621 |
ref=None, possible_transports=None, nascent_ok=False): |
0.200.57
by Jelmer Vernooij
Fix more tests. |
622 |
"""'create' a branch for this dir.""" |
0.302.1
by Jelmer Vernooij
Implement .find_repository. |
623 |
repo = self.find_repository() |
0.200.1644
by Jelmer Vernooij
More relative imports. |
624 |
from .branch import LocalGitBranch |
0.269.8
by Jelmer Vernooij
Support push in git-remote-bzr. |
625 |
ref = self._get_selected_ref(name, ref) |
0.310.9
by Jelmer Vernooij
Some controldir fixes. |
626 |
if not nascent_ok and ref not in self._git.refs: |
7143.15.6
by Jelmer Vernooij
Merge trunk. |
627 |
raise brz_errors.NotBranchError( |
628 |
self.root_transport.base, controldir=self) |
|
0.310.9
by Jelmer Vernooij
Some controldir fixes. |
629 |
ref_chain, unused_sha = self._git.refs.follow(ref) |
0.310.14
by Jelmer Vernooij
merge lightweight checkout-in-git support. |
630 |
if ref_chain[-1] == b'HEAD': |
631 |
controldir = self |
|
632 |
else: |
|
633 |
controldir = self._find_commondir() |
|
634 |
return LocalGitBranch(controldir, repo, ref_chain[-1]) |
|
0.200.722
by Jelmer Vernooij
Implement GitDir.list_branches() and support name argument to open_branch. |
635 |
|
0.200.724
by Jelmer Vernooij
support destroy_branch |
636 |
def destroy_branch(self, name=None): |
0.200.1310
by Jelmer Vernooij
Add _get_selected_ref method. |
637 |
refname = self._get_selected_ref(name) |
0.310.2
by Jelmer Vernooij
Don't allow removing HEAD. |
638 |
if refname == b'HEAD': |
639 |
# HEAD can't be removed
|
|
7143.7.1
by Jelmer Vernooij
Simplify brz-git, drop imports. |
640 |
raise brz_errors.UnsupportedOperation( |
0.310.2
by Jelmer Vernooij
Don't allow removing HEAD. |
641 |
self.destroy_branch, self) |
0.200.1364
by Jelmer Vernooij
Fix .destroy_branch. |
642 |
try: |
643 |
del self._git.refs[refname] |
|
644 |
except KeyError: |
|
7143.15.6
by Jelmer Vernooij
Merge trunk. |
645 |
raise brz_errors.NotBranchError( |
646 |
self.root_transport.base, controldir=self) |
|
0.200.724
by Jelmer Vernooij
support destroy_branch |
647 |
|
0.200.980
by Jelmer Vernooij
Implement LocalGitBzrDir.destroy_repository(). |
648 |
def destroy_repository(self): |
7143.7.1
by Jelmer Vernooij
Simplify brz-git, drop imports. |
649 |
raise brz_errors.UnsupportedOperation(self.destroy_repository, self) |
0.200.980
by Jelmer Vernooij
Implement LocalGitBzrDir.destroy_repository(). |
650 |
|
0.200.986
by Jelmer Vernooij
Implement GitDir.destroy_workingtree. |
651 |
def destroy_workingtree(self): |
7143.7.1
by Jelmer Vernooij
Simplify brz-git, drop imports. |
652 |
raise brz_errors.UnsupportedOperation(self.destroy_workingtree, self) |
0.200.1566
by Jelmer Vernooij
Basic implementation of LocalGitDir.destroy_workingtree. |
653 |
|
654 |
def destroy_workingtree_metadata(self): |
|
7143.15.6
by Jelmer Vernooij
Merge trunk. |
655 |
raise brz_errors.UnsupportedOperation( |
7143.15.2
by Jelmer Vernooij
Run autopep8. |
656 |
self.destroy_workingtree_metadata, self) |
0.200.986
by Jelmer Vernooij
Implement GitDir.destroy_workingtree. |
657 |
|
0.200.997
by Jelmer Vernooij
Implement BzrDir.needs_format_conversion. |
658 |
def needs_format_conversion(self, format=None): |
659 |
return not isinstance(self._format, format.__class__) |
|
660 |
||
0.200.1114
by Jelmer Vernooij
Properly raise exception when create_repository is called with shared=True |
661 |
def open_repository(self): |
0.200.18
by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc. |
662 |
"""'open' a repository for this dir.""" |
0.302.1
by Jelmer Vernooij
Implement .find_repository. |
663 |
if self.control_transport.has('commondir'): |
7143.7.1
by Jelmer Vernooij
Simplify brz-git, drop imports. |
664 |
raise brz_errors.NoRepositoryPresent(self) |
0.200.1411
by Jelmer Vernooij
Fix control files. |
665 |
return self._gitrepository_class(self) |
0.200.18
by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc. |
666 |
|
0.310.3
by Jelmer Vernooij
Implement ControlDir.has_workingtree. |
667 |
def has_workingtree(self): |
668 |
return not self._git.bare |
|
669 |
||
0.200.1537
by Jelmer Vernooij
Support unsupported= argument. |
670 |
def open_workingtree(self, recommend_upgrade=True, unsupported=False): |
0.246.5
by Jelmer Vernooij
Cope with has_index not existing. |
671 |
if not self._git.bare: |
0.302.1
by Jelmer Vernooij
Implement .find_repository. |
672 |
repo = self.find_repository() |
0.415.3
by Jelmer Vernooij
Open index on demand. |
673 |
from .workingtree import GitWorkingTree |
674 |
branch = self.open_branch(ref=b'HEAD', nascent_ok=True) |
|
675 |
return GitWorkingTree(self, repo, branch) |
|
0.200.392
by Jelmer Vernooij
Fix some tests now that working trees are supported. |
676 |
loc = urlutils.unescape_for_display(self.root_transport.base, 'ascii') |
7143.7.1
by Jelmer Vernooij
Simplify brz-git, drop imports. |
677 |
raise brz_errors.NoWorkingTree(loc) |
0.200.18
by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc. |
678 |
|
0.200.108
by Jelmer Vernooij
Support bzr init --git. |
679 |
def create_repository(self, shared=False): |
0.200.1644
by Jelmer Vernooij
More relative imports. |
680 |
from .repository import GitRepositoryFormat |
0.200.1114
by Jelmer Vernooij
Properly raise exception when create_repository is called with shared=True |
681 |
if shared: |
7143.15.6
by Jelmer Vernooij
Merge trunk. |
682 |
raise brz_errors.IncompatibleFormat( |
7143.15.2
by Jelmer Vernooij
Run autopep8. |
683 |
GitRepositoryFormat(), self._format) |
0.302.1
by Jelmer Vernooij
Implement .find_repository. |
684 |
return self.find_repository() |
0.200.288
by Jelmer Vernooij
Add test for init-repo. |
685 |
|
0.200.1377
by Jelmer Vernooij
Fix get_branch_reference. |
686 |
def create_branch(self, name=None, repository=None, |
0.269.8
by Jelmer Vernooij
Support push in git-remote-bzr. |
687 |
append_revisions_only=None, ref=None): |
688 |
refname = self._get_selected_ref(name, ref) |
|
0.310.1
by Jelmer Vernooij
Support from_branch, don't raise AlreadyBranchError for HEAD. |
689 |
if refname != b'HEAD' and refname in self._git.refs: |
7143.7.1
by Jelmer Vernooij
Simplify brz-git, drop imports. |
690 |
raise brz_errors.AlreadyBranchError(self.user_url) |
0.310.9
by Jelmer Vernooij
Some controldir fixes. |
691 |
repo = self.open_repository() |
692 |
if refname in self._git.refs: |
|
7143.15.2
by Jelmer Vernooij
Run autopep8. |
693 |
ref_chain, unused_sha = self._git.refs.follow( |
694 |
self._get_selected_ref(None)) |
|
0.310.14
by Jelmer Vernooij
merge lightweight checkout-in-git support. |
695 |
if ref_chain[0] == b'HEAD': |
696 |
refname = ref_chain[1] |
|
697 |
from .branch import LocalGitBranch |
|
698 |
branch = LocalGitBranch(self, repo, refname) |
|
0.200.1378
by Jelmer Vernooij
Fix branch. |
699 |
if append_revisions_only: |
0.200.1377
by Jelmer Vernooij
Fix get_branch_reference. |
700 |
branch.set_append_revisions_only(append_revisions_only) |
701 |
return branch |
|
0.200.535
by Jelmer Vernooij
use standard version to check for index. |
702 |
|
703 |
def backup_bzrdir(self): |
|
0.200.1549
by Jelmer Vernooij
Support backing up bare repositories. |
704 |
if not self._git.bare: |
0.200.535
by Jelmer Vernooij
use standard version to check for index. |
705 |
self.root_transport.copy_tree(".git", ".git.backup") |
706 |
return (self.root_transport.abspath(".git"), |
|
707 |
self.root_transport.abspath(".git.backup")) |
|
708 |
else: |
|
0.200.1549
by Jelmer Vernooij
Support backing up bare repositories. |
709 |
basename = urlutils.basename(self.root_transport.base) |
710 |
parent = self.root_transport.clone('..') |
|
711 |
parent.copy_tree(basename, basename + ".backup") |
|
0.200.535
by Jelmer Vernooij
use standard version to check for index. |
712 |
|
713 |
def create_workingtree(self, revision_id=None, from_branch=None, |
|
7143.15.2
by Jelmer Vernooij
Run autopep8. |
714 |
accelerator_tree=None, hardlink=False): |
0.200.535
by Jelmer Vernooij
use standard version to check for index. |
715 |
if self._git.bare: |
7143.15.6
by Jelmer Vernooij
Merge trunk. |
716 |
raise brz_errors.UnsupportedOperation( |
7143.15.2
by Jelmer Vernooij
Run autopep8. |
717 |
self.create_workingtree, self) |
0.310.1
by Jelmer Vernooij
Support from_branch, don't raise AlreadyBranchError for HEAD. |
718 |
if from_branch is None: |
0.310.9
by Jelmer Vernooij
Some controldir fixes. |
719 |
from_branch = self.open_branch(nascent_ok=True) |
0.288.5
by Jelmer Vernooij
Fix working tree contruction. |
720 |
if revision_id is None: |
0.310.1
by Jelmer Vernooij
Support from_branch, don't raise AlreadyBranchError for HEAD. |
721 |
revision_id = from_branch.last_revision() |
0.302.1
by Jelmer Vernooij
Implement .find_repository. |
722 |
repo = self.find_repository() |
0.302.2
by Jelmer Vernooij
Use from_branch. |
723 |
from .workingtree import GitWorkingTree |
0.415.3
by Jelmer Vernooij
Open index on demand. |
724 |
wt = GitWorkingTree(self, repo, from_branch) |
0.373.1
by Jelmer Vernooij
Fix WorkingTree.reset_state(). |
725 |
wt.set_last_revision(revision_id) |
726 |
wt._build_checkout_with_index() |
|
0.200.1721
by Jelmer Vernooij
Support passing in last revision. |
727 |
return wt |
0.200.1015
by Jelmer Vernooij
Fix GitControlDir.find_repository(). |
728 |
|
0.200.1114
by Jelmer Vernooij
Properly raise exception when create_repository is called with shared=True |
729 |
def _find_or_create_repository(self, force_new_repo=None): |
730 |
return self.create_repository(shared=False) |
|
731 |
||
0.200.1018
by Jelmer Vernooij
Fix use with new control dir API. |
732 |
def _find_creation_modes(self): |
733 |
"""Determine the appropriate modes for files and directories. |
|
734 |
||
735 |
They're always set to be consistent with the base directory,
|
|
736 |
assuming that this transport allows setting modes.
|
|
737 |
"""
|
|
738 |
# TODO: Do we need or want an option (maybe a config setting) to turn
|
|
739 |
# this off or override it for particular locations? -- mbp 20080512
|
|
740 |
if self._mode_check_done: |
|
741 |
return
|
|
742 |
self._mode_check_done = True |
|
743 |
try: |
|
744 |
st = self.transport.stat('.') |
|
7143.7.1
by Jelmer Vernooij
Simplify brz-git, drop imports. |
745 |
except brz_errors.TransportNotPossible: |
0.200.1018
by Jelmer Vernooij
Fix use with new control dir API. |
746 |
self._dir_mode = None |
747 |
self._file_mode = None |
|
748 |
else: |
|
749 |
# Check the directory mode, but also make sure the created
|
|
750 |
# directories and files are read-write for this user. This is
|
|
751 |
# mostly a workaround for filesystems which lie about being able to
|
|
752 |
# write to a directory (cygwin & win32)
|
|
6964.2.1
by Jelmer Vernooij
Initial work to support brz-git on python3. |
753 |
if (st.st_mode & 0o7777 == 0o0000): |
0.200.1018
by Jelmer Vernooij
Fix use with new control dir API. |
754 |
# FTP allows stat but does not return dir/file modes
|
755 |
self._dir_mode = None |
|
756 |
self._file_mode = None |
|
757 |
else: |
|
6964.2.1
by Jelmer Vernooij
Initial work to support brz-git on python3. |
758 |
self._dir_mode = (st.st_mode & 0o7777) | 0o0700 |
0.200.1018
by Jelmer Vernooij
Fix use with new control dir API. |
759 |
# Remove the sticky and execute bits for files
|
6964.2.1
by Jelmer Vernooij
Initial work to support brz-git on python3. |
760 |
self._file_mode = self._dir_mode & ~0o7111 |
0.200.1018
by Jelmer Vernooij
Fix use with new control dir API. |
761 |
|
762 |
def _get_file_mode(self): |
|
763 |
"""Return Unix mode for newly created files, or None. |
|
764 |
"""
|
|
765 |
if not self._mode_check_done: |
|
766 |
self._find_creation_modes() |
|
767 |
return self._file_mode |
|
768 |
||
769 |
def _get_dir_mode(self): |
|
770 |
"""Return Unix mode for newly created directories, or None. |
|
771 |
"""
|
|
772 |
if not self._mode_check_done: |
|
773 |
self._find_creation_modes() |
|
774 |
return self._dir_mode |
|
775 |
||
0.200.1487
by Jelmer Vernooij
Use peeling. |
776 |
def get_refs_container(self): |
777 |
return self._git.refs |
|
0.200.1489
by Jelmer Vernooij
More fixes to peel handling. |
778 |
|
779 |
def get_peeled(self, ref): |
|
780 |
return self._git.get_peeled(ref) |
|
0.409.1
by Jelmer Vernooij
Don't probe for commondir over remote transport. |
781 |
|
782 |
def _find_commondir(self): |
|
783 |
try: |
|
784 |
commondir = self.control_transport.get_bytes('commondir') |
|
7143.7.1
by Jelmer Vernooij
Simplify brz-git, drop imports. |
785 |
except brz_errors.NoSuchFile: |
0.409.1
by Jelmer Vernooij
Don't probe for commondir over remote transport. |
786 |
return self |
787 |
else: |
|
7045.3.1
by Jelmer Vernooij
Fix another ~500 tests. |
788 |
commondir = commondir.rstrip(b'/.git/').decode(osutils._fs_enc) |
7143.15.3
by Jelmer Vernooij
Fix pep8 issues in breezy.git. |
789 |
return ControlDir.open_from_transport( |
790 |
get_transport_from_path(commondir)) |