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.200.910
by Jelmer Vernooij
update copyright years |
2 |
# Copyright (C) 2010 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
|
|
16 |
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
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 |
|
|
0.200.1594
by Jelmer Vernooij
Use absolute_import everywhere. |
20 |
from __future__ import absolute_import |
21 |
||
|
0.200.1311
by Jelmer Vernooij
More work on colocated branch support. |
22 |
import urllib |
23 |
||
|
0.200.1641
by Jelmer Vernooij
Use relative imports where possible. |
24 |
from ... import ( |
|
0.200.1688
by Jelmer Vernooij
Fix stacking tests. |
25 |
branch as _mod_branch, |
|
0.239.13
by Jelmer Vernooij
Don't break "bzr info -v" when Dulwich is not installed. |
26 |
errors as bzr_errors, |
|
0.200.1137
by Jelmer Vernooij
Support BzrProber.known_formats(). |
27 |
trace, |
|
0.200.1172
by Jelmer Vernooij
Provide GitDir._available_backup_name. |
28 |
osutils, |
|
0.200.1566
by Jelmer Vernooij
Basic implementation of LocalGitDir.destroy_workingtree. |
29 |
revision as _mod_revision, |
|
0.200.18
by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc. |
30 |
urlutils, |
31 |
)
|
|
|
0.200.1702
by Jelmer Vernooij
Implement GitDir.acquire_repository. |
32 |
from ...controldir import RepositoryAcquisitionPolicy |
|
0.200.1641
by Jelmer Vernooij
Use relative imports where possible. |
33 |
from ...transport import do_catching_redirections |
|
0.200.18
by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc. |
34 |
|
|
0.200.1641
by Jelmer Vernooij
Use relative imports where possible. |
35 |
from ...controldir import ( |
|
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 |
|
|
0.200.123
by Jelmer Vernooij
Use central git module. |
42 |
|
|
0.200.1026
by Jelmer Vernooij
Fix typo. |
43 |
class GitDirConfig(object): |
|
0.200.1025
by Jelmer Vernooij
Implement GitDir.get_config(). |
44 |
|
45 |
def get_default_stack_on(self): |
|
46 |
return None |
|
47 |
||
48 |
def set_default_stack_on(self, value): |
|
49 |
raise bzr_errors.BzrError("Cannot set configuration") |
|
50 |
||
51 |
||
|
0.200.1137
by Jelmer Vernooij
Support BzrProber.known_formats(). |
52 |
class GitControlDirFormat(ControlDirFormat): |
53 |
||
54 |
colocated_branches = True |
|
55 |
fixed_components = True |
|
56 |
||
57 |
def __eq__(self, other): |
|
58 |
return type(self) == type(other) |
|
59 |
||
60 |
def is_supported(self): |
|
61 |
return True |
|
62 |
||
63 |
def network_name(self): |
|
64 |
return "git" |
|
65 |
||
66 |
||
|
0.200.1702
by Jelmer Vernooij
Implement GitDir.acquire_repository. |
67 |
class UseExistingRepository(RepositoryAcquisitionPolicy): |
68 |
"""A policy of reusing an existing repository""" |
|
69 |
||
70 |
def __init__(self, repository, stack_on=None, stack_on_pwd=None, |
|
71 |
require_stacking=False): |
|
72 |
"""Constructor. |
|
73 |
||
74 |
:param repository: The repository to use.
|
|
75 |
:param stack_on: A location to stack on
|
|
76 |
:param stack_on_pwd: If stack_on is relative, the location it is
|
|
77 |
relative to.
|
|
78 |
"""
|
|
79 |
super(UseExistingRepository, self).__init__( |
|
80 |
stack_on, stack_on_pwd, require_stacking) |
|
81 |
self._repository = repository |
|
82 |
||
83 |
def acquire_repository(self, make_working_trees=None, shared=False, |
|
84 |
possible_transports=None): |
|
85 |
"""Implementation of RepositoryAcquisitionPolicy.acquire_repository |
|
86 |
||
87 |
Returns an existing repository to use.
|
|
88 |
"""
|
|
89 |
return self._repository, False |
|
90 |
||
91 |
||
|
0.200.1012
by Jelmer Vernooij
Rename BzrDir to ControlDir. |
92 |
class GitDir(ControlDir): |
|
0.200.18
by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc. |
93 |
"""An adapter to the '.git' dir used by git.""" |
94 |
||
|
0.200.148
by Jelmer Vernooij
Share more infrastructure between LocalGitDir and RemoteGitDir. |
95 |
def is_supported(self): |
96 |
return True |
|
97 |
||
|
0.200.981
by Jelmer Vernooij
Mark git directories as not convertable (for now). |
98 |
def can_convert_format(self): |
99 |
return False |
|
100 |
||
|
0.200.1025
by Jelmer Vernooij
Implement GitDir.get_config(). |
101 |
def break_lock(self): |
102 |
pass
|
|
103 |
||
|
0.200.155
by Jelmer Vernooij
Fix formatting, remove catch-all for exceptions when opening local repositories. |
104 |
def cloning_metadir(self, stacked=False): |
|
0.200.1648
by Jelmer Vernooij
Fix compatibility with newer versions of breezy. |
105 |
return format_registry.make_controldir("default") |
|
0.200.155
by Jelmer Vernooij
Fix formatting, remove catch-all for exceptions when opening local repositories. |
106 |
|
|
0.200.1165
by Jelmer Vernooij
Implement GitDir.checkout_metadir. |
107 |
def checkout_metadir(self, stacked=False): |
|
0.200.1648
by Jelmer Vernooij
Fix compatibility with newer versions of breezy. |
108 |
return format_registry.make_controldir("default") |
|
0.200.1165
by Jelmer Vernooij
Implement GitDir.checkout_metadir. |
109 |
|
|
0.200.1561
by Jelmer Vernooij
Some fixes for colocated branch handling. |
110 |
def _get_default_ref(self): |
111 |
return "HEAD" |
|
112 |
||
|
0.269.8
by Jelmer Vernooij
Support push in git-remote-bzr. |
113 |
def _get_selected_ref(self, branch, ref=None): |
114 |
if ref is not None and branch is not None: |
|
115 |
raise bzr_errors.BzrError("can't specify both ref and branch") |
|
116 |
if ref is not None: |
|
117 |
return ref |
|
|
0.200.1559
by Jelmer Vernooij
Fix compatibility with bzr 2.5. |
118 |
segment_parameters = getattr( |
119 |
self.user_transport, "get_segment_parameters", lambda: {})() |
|
120 |
ref = segment_parameters.get("ref") |
|
121 |
if ref is not None: |
|
122 |
return urlutils.unescape(ref) |
|
|
0.200.1310
by Jelmer Vernooij
Add _get_selected_ref method. |
123 |
if branch is None and getattr(self, "_get_selected_branch", False): |
124 |
branch = self._get_selected_branch() |
|
125 |
if branch is not None: |
|
|
0.200.1644
by Jelmer Vernooij
More relative imports. |
126 |
from .refs import branch_name_to_ref |
|
0.200.1559
by Jelmer Vernooij
Fix compatibility with bzr 2.5. |
127 |
return branch_name_to_ref(branch) |
|
0.200.1561
by Jelmer Vernooij
Some fixes for colocated branch handling. |
128 |
return self._get_default_ref() |
|
0.200.1310
by Jelmer Vernooij
Add _get_selected_ref method. |
129 |
|
|
0.200.1025
by Jelmer Vernooij
Implement GitDir.get_config(). |
130 |
def get_config(self): |
131 |
return GitDirConfig() |
|
132 |
||
|
0.200.1172
by Jelmer Vernooij
Provide GitDir._available_backup_name. |
133 |
def _available_backup_name(self, base): |
134 |
return osutils.available_backup_name(base, self.root_transport.has) |
|
135 |
||
|
0.259.1
by Jelmer Vernooij
Provide custom GitDir.sprout() for bzr 2.4 compatibility. |
136 |
def sprout(self, url, revision_id=None, force_new_repo=False, |
137 |
recurse='down', possible_transports=None, |
|
138 |
accelerator_tree=None, hardlink=False, stacked=False, |
|
139 |
source_branch=None, create_tree_if_local=True): |
|
|
0.200.1644
by Jelmer Vernooij
More relative imports. |
140 |
from ...repository import InterRepository |
141 |
from ...transport.local import LocalTransport |
|
142 |
from ...transport import get_transport |
|
|
0.259.1
by Jelmer Vernooij
Provide custom GitDir.sprout() for bzr 2.4 compatibility. |
143 |
target_transport = get_transport(url, possible_transports) |
144 |
target_transport.ensure_base() |
|
145 |
cloning_format = self.cloning_metadir() |
|
146 |
# Create/update the result branch
|
|
147 |
result = cloning_format.initialize_on_transport(target_transport) |
|
|
0.200.1373
by Jelmer Vernooij
Prevent accidentally removing branch. |
148 |
source_branch = self.open_branch() |
|
0.259.1
by Jelmer Vernooij
Provide custom GitDir.sprout() for bzr 2.4 compatibility. |
149 |
source_repository = self.find_repository() |
150 |
try: |
|
151 |
result_repo = result.find_repository() |
|
152 |
except bzr_errors.NoRepositoryPresent: |
|
153 |
result_repo = result.create_repository() |
|
154 |
target_is_empty = True |
|
155 |
else: |
|
156 |
target_is_empty = None # Unknown |
|
157 |
if stacked: |
|
|
0.200.1688
by Jelmer Vernooij
Fix stacking tests. |
158 |
raise _mod_branch.UnstackableBranchFormat(self._format, self.user_url) |
|
0.259.1
by Jelmer Vernooij
Provide custom GitDir.sprout() for bzr 2.4 compatibility. |
159 |
interrepo = InterRepository.get(source_repository, result_repo) |
160 |
||
161 |
if revision_id is not None: |
|
|
0.259.4
by Jelmer Vernooij
Put determine_wants methods on InterRepo. |
162 |
determine_wants = interrepo.get_determine_wants_revids( |
|
0.200.1520
by Jelmer Vernooij
Don't fetch tag contents by default. |
163 |
[revision_id], include_tags=False) |
|
0.259.1
by Jelmer Vernooij
Provide custom GitDir.sprout() for bzr 2.4 compatibility. |
164 |
else: |
|
0.259.4
by Jelmer Vernooij
Put determine_wants methods on InterRepo. |
165 |
determine_wants = interrepo.determine_wants_all |
|
0.259.1
by Jelmer Vernooij
Provide custom GitDir.sprout() for bzr 2.4 compatibility. |
166 |
interrepo.fetch_objects(determine_wants=determine_wants, |
167 |
mapping=source_branch.mapping) |
|
168 |
result_branch = source_branch.sprout(result, |
|
169 |
revision_id=revision_id, repository=result_repo) |
|
|
0.200.1372
by Jelmer Vernooij
Fix formatting. |
170 |
if (create_tree_if_local |
171 |
and isinstance(target_transport, LocalTransport) |
|
|
0.259.1
by Jelmer Vernooij
Provide custom GitDir.sprout() for bzr 2.4 compatibility. |
172 |
and (result_repo is None or result_repo.make_working_trees())): |
173 |
wt = result.create_workingtree(accelerator_tree=accelerator_tree, |
|
174 |
hardlink=hardlink, from_branch=result_branch) |
|
175 |
wt.lock_write() |
|
176 |
try: |
|
177 |
if wt.path2id('') is None: |
|
178 |
try: |
|
179 |
wt.set_root_id(self.open_workingtree.get_root_id()) |
|
180 |
except bzr_errors.NoWorkingTree: |
|
181 |
pass
|
|
182 |
finally: |
|
183 |
wt.unlock() |
|
184 |
return result |
|
185 |
||
|
0.200.1117
by Jelmer Vernooij
Provide basic implementation of GitDir.clone_on_transport. |
186 |
def clone_on_transport(self, transport, revision_id=None, |
187 |
force_new_repo=False, preserve_stacking=False, stacked_on=None, |
|
188 |
create_prefix=False, use_existing_dir=True, no_tree=False): |
|
189 |
"""See ControlDir.clone_on_transport.""" |
|
|
0.200.1644
by Jelmer Vernooij
More relative imports. |
190 |
from ...repository import InterRepository |
191 |
from .mapping import default_mapping |
|
|
0.285.3
by Jelmer Vernooij
Fix handling of stacking requests. |
192 |
if stacked_on is not None: |
193 |
raise _mod_branch.UnstackableBranchFormat(self._format, self.user_url) |
|
|
0.200.1119
by Jelmer Vernooij
Refactor repository initialization. |
194 |
if no_tree: |
195 |
format = BareLocalGitControlDirFormat() |
|
196 |
else: |
|
197 |
format = LocalGitControlDirFormat() |
|
198 |
(target_repo, target_controldir, stacking, repo_policy) = format.initialize_on_transport_ex(transport, use_existing_dir=use_existing_dir, create_prefix=create_prefix, force_new_repo=force_new_repo) |
|
199 |
target_git_repo = target_repo._git |
|
|
0.200.1117
by Jelmer Vernooij
Provide basic implementation of GitDir.clone_on_transport. |
200 |
source_repo = self.open_repository() |
201 |
source_git_repo = source_repo._git |
|
|
0.200.1171
by Jelmer Vernooij
Fix some more tests. |
202 |
interrepo = InterRepository.get(source_repo, target_repo) |
|
0.200.1117
by Jelmer Vernooij
Provide basic implementation of GitDir.clone_on_transport. |
203 |
if revision_id is not None: |
|
0.200.1171
by Jelmer Vernooij
Fix some more tests. |
204 |
determine_wants = interrepo.get_determine_wants_revids([revision_id], include_tags=True) |
|
0.200.1117
by Jelmer Vernooij
Provide basic implementation of GitDir.clone_on_transport. |
205 |
else: |
|
0.200.1171
by Jelmer Vernooij
Fix some more tests. |
206 |
determine_wants = interrepo.determine_wants_all |
207 |
(pack_hint, _, refs) = interrepo.fetch_objects(determine_wants, |
|
208 |
mapping=default_mapping) |
|
|
0.200.1117
by Jelmer Vernooij
Provide basic implementation of GitDir.clone_on_transport. |
209 |
for name, val in refs.iteritems(): |
210 |
target_git_repo.refs[name] = val |
|
|
0.200.1411
by Jelmer Vernooij
Fix control files. |
211 |
return self.__class__(transport, target_git_repo, format) |
|
0.200.1117
by Jelmer Vernooij
Provide basic implementation of GitDir.clone_on_transport. |
212 |
|
|
0.259.2
by Jelmer Vernooij
Make sure RemoteGitDir.find_repository works. |
213 |
def find_repository(self): |
214 |
"""Find the repository that should be used. |
|
215 |
||
216 |
This does not require a branch as we use it to find the repo for
|
|
217 |
new branches as well as to hook existing branches up to their
|
|
218 |
repository.
|
|
219 |
"""
|
|
220 |
return self.open_repository() |
|
221 |
||
|
0.200.1487
by Jelmer Vernooij
Use peeling. |
222 |
def get_refs_container(self): |
223 |
"""Retrieve the refs container. |
|
|
0.200.1434
by Jelmer Vernooij
Move refs access to control dir. |
224 |
"""
|
|
0.200.1487
by Jelmer Vernooij
Use peeling. |
225 |
raise NotImplementedError(self.get_refs_container) |
|
0.200.1434
by Jelmer Vernooij
Move refs access to control dir. |
226 |
|
|
0.200.1701
by Jelmer Vernooij
Fix a few tests. |
227 |
def determine_repository_policy(self, force_new_repo=False, stack_on=None, |
228 |
stack_on_pwd=None, require_stacking=False): |
|
229 |
"""Return an object representing a policy to use. |
|
230 |
||
231 |
This controls whether a new repository is created, and the format of
|
|
232 |
that repository, or some existing shared repository used instead.
|
|
233 |
||
234 |
If stack_on is supplied, will not seek a containing shared repo.
|
|
235 |
||
236 |
:param force_new_repo: If True, require a new repository to be created.
|
|
237 |
:param stack_on: If supplied, the location to stack on. If not
|
|
238 |
supplied, a default_stack_on location may be used.
|
|
239 |
:param stack_on_pwd: If stack_on is relative, the location it is
|
|
240 |
relative to.
|
|
241 |
"""
|
|
|
0.200.1702
by Jelmer Vernooij
Implement GitDir.acquire_repository. |
242 |
return UseExistingRepository(self.open_repository()) |
|
0.200.1701
by Jelmer Vernooij
Fix a few tests. |
243 |
|
|
0.200.148
by Jelmer Vernooij
Share more infrastructure between LocalGitDir and RemoteGitDir. |
244 |
|
|
0.200.1137
by Jelmer Vernooij
Support BzrProber.known_formats(). |
245 |
class LocalGitControlDirFormat(GitControlDirFormat): |
246 |
"""The .git directory control format.""" |
|
247 |
||
248 |
bare = False |
|
249 |
||
250 |
@classmethod
|
|
251 |
def _known_formats(self): |
|
252 |
return set([LocalGitControlDirFormat()]) |
|
253 |
||
254 |
@property
|
|
255 |
def repository_format(self): |
|
|
0.200.1644
by Jelmer Vernooij
More relative imports. |
256 |
from .repository import GitRepositoryFormat |
|
0.200.1137
by Jelmer Vernooij
Support BzrProber.known_formats(). |
257 |
return GitRepositoryFormat() |
258 |
||
259 |
def get_branch_format(self): |
|
|
0.200.1644
by Jelmer Vernooij
More relative imports. |
260 |
from .branch import GitBranchFormat |
|
0.200.1137
by Jelmer Vernooij
Support BzrProber.known_formats(). |
261 |
return GitBranchFormat() |
262 |
||
263 |
def open(self, transport, _found=None): |
|
264 |
"""Open this directory. |
|
265 |
||
266 |
"""
|
|
|
0.200.1644
by Jelmer Vernooij
More relative imports. |
267 |
from .transportgit import TransportRepo |
|
0.200.1485
by Jelmer Vernooij
Keep track of refs text when opening bare repository. |
268 |
gitrepo = TransportRepo(transport, self.bare, |
269 |
refs_text=getattr(self, "_refs_text", None)) |
|
|
0.200.1411
by Jelmer Vernooij
Fix control files. |
270 |
return LocalGitDir(transport, gitrepo, self) |
|
0.200.1137
by Jelmer Vernooij
Support BzrProber.known_formats(). |
271 |
|
272 |
def get_format_description(self): |
|
273 |
return "Local Git Repository" |
|
274 |
||
275 |
def initialize_on_transport(self, transport): |
|
|
0.200.1644
by Jelmer Vernooij
More relative imports. |
276 |
from .transportgit import TransportRepo |
|
0.200.1559
by Jelmer Vernooij
Fix compatibility with bzr 2.5. |
277 |
repo = TransportRepo.init(transport, bare=self.bare) |
278 |
del repo.refs["HEAD"] |
|
|
0.200.1137
by Jelmer Vernooij
Support BzrProber.known_formats(). |
279 |
return self.open(transport) |
280 |
||
281 |
def initialize_on_transport_ex(self, transport, use_existing_dir=False, |
|
282 |
create_prefix=False, force_new_repo=False, stacked_on=None, |
|
283 |
stack_on_pwd=None, repo_format_name=None, make_working_trees=None, |
|
284 |
shared_repo=False, vfs_only=False): |
|
285 |
def make_directory(transport): |
|
286 |
transport.mkdir('.') |
|
287 |
return transport |
|
288 |
def redirected(transport, e, redirection_notice): |
|
289 |
trace.note(redirection_notice) |
|
290 |
return transport._redirected_to(e.source, e.target) |
|
291 |
try: |
|
292 |
transport = do_catching_redirections(make_directory, transport, |
|
293 |
redirected) |
|
294 |
except bzr_errors.FileExists: |
|
295 |
if not use_existing_dir: |
|
296 |
raise
|
|
297 |
except bzr_errors.NoSuchFile: |
|
298 |
if not create_prefix: |
|
299 |
raise
|
|
300 |
transport.create_prefix() |
|
301 |
controldir = self.initialize_on_transport(transport) |
|
302 |
repository = controldir.open_repository() |
|
303 |
repository.lock_write() |
|
|
0.200.1703
by Jelmer Vernooij
Implement apply_inventory_delta. |
304 |
return (repository, controldir, False, |
305 |
UseExistingRepository(controldir.open_repository())) |
|
|
0.200.1137
by Jelmer Vernooij
Support BzrProber.known_formats(). |
306 |
|
307 |
def is_supported(self): |
|
308 |
return True |
|
309 |
||
|
0.200.1412
by Jelmer Vernooij
Implement GitControlDirFormat.supports_transport. |
310 |
def supports_transport(self, transport): |
311 |
try: |
|
312 |
external_url = transport.external_url() |
|
313 |
except bzr_errors.InProcessTransport: |
|
314 |
raise bzr_errors.NotBranchError(path=transport.base) |
|
315 |
return (external_url.startswith("http:") or |
|
316 |
external_url.startswith("https:") or |
|
317 |
external_url.startswith("file:")) |
|
318 |
||
|
0.200.1137
by Jelmer Vernooij
Support BzrProber.known_formats(). |
319 |
|
320 |
class BareLocalGitControlDirFormat(LocalGitControlDirFormat): |
|
321 |
||
322 |
bare = True |
|
323 |
supports_workingtrees = False |
|
324 |
||
325 |
def get_format_description(self): |
|
326 |
return "Local Git Repository (bare)" |
|
327 |
||
328 |
||
|
0.200.148
by Jelmer Vernooij
Share more infrastructure between LocalGitDir and RemoteGitDir. |
329 |
class LocalGitDir(GitDir): |
330 |
"""An adapter to the '.git' dir used by git.""" |
|
331 |
||
|
0.239.13
by Jelmer Vernooij
Don't break "bzr info -v" when Dulwich is not installed. |
332 |
def _get_gitrepository_class(self): |
|
0.200.1644
by Jelmer Vernooij
More relative imports. |
333 |
from .repository import LocalGitRepository |
|
0.239.13
by Jelmer Vernooij
Don't break "bzr info -v" when Dulwich is not installed. |
334 |
return LocalGitRepository |
335 |
||
|
0.200.1313
by Jelmer Vernooij
Add __repr__ |
336 |
def __repr__(self): |
337 |
return "<%s at %r>" % ( |
|
338 |
self.__class__.__name__, self.root_transport.base) |
|
339 |
||
|
0.239.13
by Jelmer Vernooij
Don't break "bzr info -v" when Dulwich is not installed. |
340 |
_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. |
341 |
|
|
0.200.1014
by Jelmer Vernooij
Fix tests. |
342 |
@property
|
343 |
def user_transport(self): |
|
344 |
return self.root_transport |
|
345 |
||
346 |
@property
|
|
347 |
def control_transport(self): |
|
348 |
return self.transport |
|
349 |
||
|
0.200.1411
by Jelmer Vernooij
Fix control files. |
350 |
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. |
351 |
self._format = format |
352 |
self.root_transport = transport |
|
|
0.200.1018
by Jelmer Vernooij
Fix use with new control dir API. |
353 |
self._mode_check_done = False |
|
0.200.90
by Jelmer Vernooij
Basic support for opening working trees. |
354 |
self._git = gitrepo |
355 |
if gitrepo.bare: |
|
356 |
self.transport = transport |
|
357 |
else: |
|
358 |
self.transport = transport.clone('.git') |
|
|
0.200.381
by Jelmer Vernooij
Support working trees properly, status and ls. |
359 |
self._mode_check_done = None |
360 |
||
361 |
def is_control_filename(self, filename): |
|
|
0.200.1603
by Jelmer Vernooij
Ignore control directory filenames on Windows, too. |
362 |
return (filename == '.git' or |
363 |
filename.startswith('.git/') or |
|
364 |
filename.startswith('.git\\')) |
|
|
0.200.18
by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc. |
365 |
|
|
0.200.1311
by Jelmer Vernooij
More work on colocated branch support. |
366 |
def _get_symref(self, ref): |
367 |
from dulwich.repo import SYMREF |
|
368 |
refcontents = self._git.refs.read_ref(ref) |
|
369 |
if refcontents is None: # no such ref |
|
370 |
return None |
|
371 |
if refcontents.startswith(SYMREF): |
|
372 |
return refcontents[len(SYMREF):].rstrip("\n") |
|
373 |
return None |
|
374 |
||
|
0.200.1559
by Jelmer Vernooij
Fix compatibility with bzr 2.5. |
375 |
def set_branch_reference(self, target, name=None): |
|
0.200.1648
by Jelmer Vernooij
Fix compatibility with newer versions of breezy. |
376 |
if self.control_transport.base != target.controldir.control_transport.base: |
|
0.200.1559
by Jelmer Vernooij
Fix compatibility with bzr 2.5. |
377 |
raise bzr_errors.IncompatibleFormat(target._format, self._format) |
|
0.200.1311
by Jelmer Vernooij
More work on colocated branch support. |
378 |
ref = self._get_selected_ref(name) |
379 |
self._git.refs.set_symbolic_ref(ref, target.ref) |
|
380 |
||
381 |
def get_branch_reference(self, name=None): |
|
382 |
ref = self._get_selected_ref(name) |
|
383 |
target_ref = self._get_symref(ref) |
|
384 |
if target_ref is not None: |
|
|
0.200.1377
by Jelmer Vernooij
Fix get_branch_reference. |
385 |
return urlutils.join_segment_parameters( |
|
0.200.1379
by Jelmer Vernooij
Escape slashes. |
386 |
self.user_url.rstrip("/"), {"ref": urllib.quote(target_ref, '')}) |
|
0.200.1311
by Jelmer Vernooij
More work on colocated branch support. |
387 |
return None |
388 |
||
389 |
def find_branch_format(self, name=None): |
|
|
0.200.1644
by Jelmer Vernooij
More relative imports. |
390 |
from .branch import ( |
|
0.200.1311
by Jelmer Vernooij
More work on colocated branch support. |
391 |
GitBranchFormat, |
392 |
GitSymrefBranchFormat, |
|
393 |
)
|
|
394 |
ref = self._get_selected_ref(name) |
|
395 |
if self._get_symref(ref) is not None: |
|
396 |
return GitSymrefBranchFormat() |
|
397 |
else: |
|
398 |
return GitBranchFormat() |
|
399 |
||
|
0.200.978
by Jelmer Vernooij
Allow name argument to get_branch_transport to be missing. |
400 |
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. |
401 |
if branch_format is None: |
402 |
return self.transport |
|
|
0.200.1012
by Jelmer Vernooij
Rename BzrDir to ControlDir. |
403 |
if isinstance(branch_format, LocalGitControlDirFormat): |
|
0.200.18
by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc. |
404 |
return self.transport |
|
0.239.13
by Jelmer Vernooij
Don't break "bzr info -v" when Dulwich is not installed. |
405 |
raise bzr_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. |
406 |
|
|
0.200.887
by Jelmer Vernooij
get_branch_transport takes a name argument. |
407 |
def get_repository_transport(self, format): |
408 |
if format is None: |
|
409 |
return self.transport |
|
|
0.200.1012
by Jelmer Vernooij
Rename BzrDir to ControlDir. |
410 |
if isinstance(format, LocalGitControlDirFormat): |
|
0.200.887
by Jelmer Vernooij
get_branch_transport takes a name argument. |
411 |
return self.transport |
412 |
raise bzr_errors.IncompatibleFormat(format, self._format) |
|
413 |
||
414 |
def get_workingtree_transport(self, format): |
|
415 |
if format is None: |
|
416 |
return self.transport |
|
|
0.200.1012
by Jelmer Vernooij
Rename BzrDir to ControlDir. |
417 |
if isinstance(format, LocalGitControlDirFormat): |
|
0.200.887
by Jelmer Vernooij
get_branch_transport takes a name argument. |
418 |
return self.transport |
419 |
raise bzr_errors.IncompatibleFormat(format, self._format) |
|
|
0.200.18
by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc. |
420 |
|
|
0.269.8
by Jelmer Vernooij
Support push in git-remote-bzr. |
421 |
def open_branch(self, name=None, unsupported=False, ignore_fallbacks=None, |
|
0.200.1475
by Jelmer Vernooij
Cope with new possible_transports argument to open_branch(). |
422 |
ref=None, possible_transports=None): |
|
0.200.57
by Jelmer Vernooij
Fix more tests. |
423 |
"""'create' a branch for this dir.""" |
424 |
repo = self.open_repository() |
|
|
0.200.1644
by Jelmer Vernooij
More relative imports. |
425 |
from .branch import LocalGitBranch |
|
0.269.8
by Jelmer Vernooij
Support push in git-remote-bzr. |
426 |
ref = self._get_selected_ref(name, ref) |
|
0.284.3
by Jelmer Vernooij
Use new RefsContainer.follow(). |
427 |
ref_chain, sha = self._git.refs.follow(ref) |
428 |
if sha is None: |
|
|
0.200.1311
by Jelmer Vernooij
More work on colocated branch support. |
429 |
raise bzr_errors.NotBranchError(self.root_transport.base, |
|
0.200.1648
by Jelmer Vernooij
Fix compatibility with newer versions of breezy. |
430 |
controldir=self) |
|
0.200.1728
by Jelmer Vernooij
Support following branch references. |
431 |
return LocalGitBranch(self, repo, ref_chain[-1]) |
|
0.200.722
by Jelmer Vernooij
Implement GitDir.list_branches() and support name argument to open_branch. |
432 |
|
|
0.200.724
by Jelmer Vernooij
support destroy_branch |
433 |
def destroy_branch(self, name=None): |
|
0.200.1310
by Jelmer Vernooij
Add _get_selected_ref method. |
434 |
refname = self._get_selected_ref(name) |
|
0.200.1364
by Jelmer Vernooij
Fix .destroy_branch. |
435 |
try: |
436 |
del self._git.refs[refname] |
|
437 |
except KeyError: |
|
|
0.200.997
by Jelmer Vernooij
Implement BzrDir.needs_format_conversion. |
438 |
raise bzr_errors.NotBranchError(self.root_transport.base, |
|
0.200.1648
by Jelmer Vernooij
Fix compatibility with newer versions of breezy. |
439 |
controldir=self) |
|
0.200.724
by Jelmer Vernooij
support destroy_branch |
440 |
|
|
0.200.980
by Jelmer Vernooij
Implement LocalGitBzrDir.destroy_repository(). |
441 |
def destroy_repository(self): |
442 |
raise bzr_errors.UnsupportedOperation(self.destroy_repository, self) |
|
443 |
||
|
0.200.986
by Jelmer Vernooij
Implement GitDir.destroy_workingtree. |
444 |
def destroy_workingtree(self): |
|
0.200.1566
by Jelmer Vernooij
Basic implementation of LocalGitDir.destroy_workingtree. |
445 |
wt = self.open_workingtree(recommend_upgrade=False) |
446 |
repository = wt.branch.repository |
|
447 |
empty = repository.revision_tree(_mod_revision.NULL_REVISION) |
|
448 |
# We ignore the conflicts returned by wt.revert since we're about to
|
|
449 |
# delete the wt metadata anyway, all that should be left here are
|
|
450 |
# detritus. But see bug #634470 about subtree .bzr dirs.
|
|
451 |
conflicts = wt.revert(old_tree=empty) |
|
452 |
self.destroy_workingtree_metadata() |
|
453 |
||
454 |
def destroy_workingtree_metadata(self): |
|
455 |
self.transport.delete('index') |
|
|
0.200.986
by Jelmer Vernooij
Implement GitDir.destroy_workingtree. |
456 |
|
|
0.200.997
by Jelmer Vernooij
Implement BzrDir.needs_format_conversion. |
457 |
def needs_format_conversion(self, format=None): |
458 |
return not isinstance(self._format, format.__class__) |
|
459 |
||
|
0.200.722
by Jelmer Vernooij
Implement GitDir.list_branches() and support name argument to open_branch. |
460 |
def list_branches(self): |
|
0.200.1501
by Jelmer Vernooij
Provide ControlDir.get_branches. |
461 |
return self.get_branches().values() |
462 |
||
463 |
def get_branches(self): |
|
|
0.200.1644
by Jelmer Vernooij
More relative imports. |
464 |
from .refs import ref_to_branch_name |
|
0.200.1501
by Jelmer Vernooij
Provide ControlDir.get_branches. |
465 |
ret = {} |
466 |
for ref in self._git.refs.keys(): |
|
467 |
try: |
|
468 |
branch_name = ref_to_branch_name(ref) |
|
469 |
except ValueError: |
|
470 |
continue
|
|
471 |
except UnicodeDecodeError: |
|
472 |
trace.warning("Ignoring branch %r with unicode error ref", ref) |
|
473 |
continue
|
|
474 |
ret[branch_name] = self.open_branch(ref=ref) |
|
|
0.200.722
by Jelmer Vernooij
Implement GitDir.list_branches() and support name argument to open_branch. |
475 |
return ret |
|
0.200.18
by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc. |
476 |
|
|
0.200.1114
by Jelmer Vernooij
Properly raise exception when create_repository is called with shared=True |
477 |
def open_repository(self): |
|
0.200.18
by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc. |
478 |
"""'open' a repository for this dir.""" |
|
0.200.1411
by Jelmer Vernooij
Fix control files. |
479 |
return self._gitrepository_class(self) |
|
0.200.18
by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc. |
480 |
|
|
0.200.1537
by Jelmer Vernooij
Support unsupported= argument. |
481 |
def open_workingtree(self, recommend_upgrade=True, unsupported=False): |
|
0.246.5
by Jelmer Vernooij
Cope with has_index not existing. |
482 |
if not self._git.bare: |
483 |
from dulwich.errors import NoIndexPresent |
|
|
0.200.803
by Jelmer Vernooij
Default to non-bare repositories when initializing a control directory. |
484 |
repo = self.open_repository() |
|
0.246.5
by Jelmer Vernooij
Cope with has_index not existing. |
485 |
try: |
|
0.200.803
by Jelmer Vernooij
Default to non-bare repositories when initializing a control directory. |
486 |
index = repo._git.open_index() |
|
0.246.5
by Jelmer Vernooij
Cope with has_index not existing. |
487 |
except NoIndexPresent: |
488 |
pass
|
|
|
0.200.803
by Jelmer Vernooij
Default to non-bare repositories when initializing a control directory. |
489 |
else: |
|
0.200.1644
by Jelmer Vernooij
More relative imports. |
490 |
from .workingtree import GitWorkingTree |
|
0.200.921
by Jelmer Vernooij
fix init tests. |
491 |
try: |
492 |
branch = self.open_branch() |
|
493 |
except bzr_errors.NotBranchError: |
|
494 |
pass
|
|
495 |
else: |
|
496 |
return GitWorkingTree(self, repo, branch, index) |
|
|
0.200.392
by Jelmer Vernooij
Fix some tests now that working trees are supported. |
497 |
loc = urlutils.unescape_for_display(self.root_transport.base, 'ascii') |
|
0.239.13
by Jelmer Vernooij
Don't break "bzr info -v" when Dulwich is not installed. |
498 |
raise bzr_errors.NoWorkingTree(loc) |
|
0.200.18
by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc. |
499 |
|
|
0.200.108
by Jelmer Vernooij
Support bzr init --git. |
500 |
def create_repository(self, shared=False): |
|
0.200.1644
by Jelmer Vernooij
More relative imports. |
501 |
from .repository import GitRepositoryFormat |
|
0.200.1114
by Jelmer Vernooij
Properly raise exception when create_repository is called with shared=True |
502 |
if shared: |
503 |
raise bzr_errors.IncompatibleFormat(GitRepositoryFormat(), self._format) |
|
|
0.200.108
by Jelmer Vernooij
Support bzr init --git. |
504 |
return self.open_repository() |
|
0.200.288
by Jelmer Vernooij
Add test for init-repo. |
505 |
|
|
0.200.1377
by Jelmer Vernooij
Fix get_branch_reference. |
506 |
def create_branch(self, name=None, repository=None, |
|
0.269.8
by Jelmer Vernooij
Support push in git-remote-bzr. |
507 |
append_revisions_only=None, ref=None): |
508 |
refname = self._get_selected_ref(name, ref) |
|
|
0.200.891
by Jelmer Vernooij
Use ZERO_SHA constant where possible. |
509 |
from dulwich.protocol import ZERO_SHA |
|
0.200.1373
by Jelmer Vernooij
Prevent accidentally removing branch. |
510 |
if refname in self._git.refs: |
|
0.200.1559
by Jelmer Vernooij
Fix compatibility with bzr 2.5. |
511 |
raise bzr_errors.AlreadyBranchError(self.user_url) |
|
0.200.1373
by Jelmer Vernooij
Prevent accidentally removing branch. |
512 |
self._git.refs[refname] = ZERO_SHA |
|
0.200.1377
by Jelmer Vernooij
Fix get_branch_reference. |
513 |
branch = self.open_branch(name) |
|
0.200.1378
by Jelmer Vernooij
Fix branch. |
514 |
if append_revisions_only: |
|
0.200.1377
by Jelmer Vernooij
Fix get_branch_reference. |
515 |
branch.set_append_revisions_only(append_revisions_only) |
516 |
return branch |
|
|
0.200.535
by Jelmer Vernooij
use standard version to check for index. |
517 |
|
518 |
def backup_bzrdir(self): |
|
|
0.200.1549
by Jelmer Vernooij
Support backing up bare repositories. |
519 |
if not self._git.bare: |
|
0.200.535
by Jelmer Vernooij
use standard version to check for index. |
520 |
self.root_transport.copy_tree(".git", ".git.backup") |
521 |
return (self.root_transport.abspath(".git"), |
|
522 |
self.root_transport.abspath(".git.backup")) |
|
523 |
else: |
|
|
0.200.1549
by Jelmer Vernooij
Support backing up bare repositories. |
524 |
basename = urlutils.basename(self.root_transport.base) |
525 |
parent = self.root_transport.clone('..') |
|
526 |
parent.copy_tree(basename, basename + ".backup") |
|
|
0.200.535
by Jelmer Vernooij
use standard version to check for index. |
527 |
|
528 |
def create_workingtree(self, revision_id=None, from_branch=None, |
|
529 |
accelerator_tree=None, hardlink=False): |
|
530 |
if self._git.bare: |
|
|
0.200.1038
by Jelmer Vernooij
Raise UnsupportedOperation on create_workingtree. |
531 |
raise bzr_errors.UnsupportedOperation(self.create_workingtree, self) |
|
0.200.535
by Jelmer Vernooij
use standard version to check for index. |
532 |
from dulwich.index import write_index |
|
0.200.613
by Jelmer Vernooij
Support creating working tree for existing git repo. |
533 |
from dulwich.pack import SHA1Writer |
534 |
f = open(self.transport.local_abspath("index"), 'w+') |
|
535 |
try: |
|
536 |
f = SHA1Writer(f) |
|
537 |
write_index(f, []) |
|
538 |
finally: |
|
539 |
f.close() |
|
|
0.200.1721
by Jelmer Vernooij
Support passing in last revision. |
540 |
wt = self.open_workingtree() |
541 |
if revision_id is not None: |
|
542 |
wt.set_last_revision(revision_id) |
|
543 |
return wt |
|
|
0.200.1015
by Jelmer Vernooij
Fix GitControlDir.find_repository(). |
544 |
|
|
0.200.1114
by Jelmer Vernooij
Properly raise exception when create_repository is called with shared=True |
545 |
def _find_or_create_repository(self, force_new_repo=None): |
546 |
return self.create_repository(shared=False) |
|
547 |
||
|
0.200.1018
by Jelmer Vernooij
Fix use with new control dir API. |
548 |
def _find_creation_modes(self): |
549 |
"""Determine the appropriate modes for files and directories. |
|
550 |
||
551 |
They're always set to be consistent with the base directory,
|
|
552 |
assuming that this transport allows setting modes.
|
|
553 |
"""
|
|
554 |
# TODO: Do we need or want an option (maybe a config setting) to turn
|
|
555 |
# this off or override it for particular locations? -- mbp 20080512
|
|
556 |
if self._mode_check_done: |
|
557 |
return
|
|
558 |
self._mode_check_done = True |
|
559 |
try: |
|
560 |
st = self.transport.stat('.') |
|
|
0.200.1116
by Jelmer Vernooij
Fix missing import. |
561 |
except bzr_errors.TransportNotPossible: |
|
0.200.1018
by Jelmer Vernooij
Fix use with new control dir API. |
562 |
self._dir_mode = None |
563 |
self._file_mode = None |
|
564 |
else: |
|
565 |
# Check the directory mode, but also make sure the created
|
|
566 |
# directories and files are read-write for this user. This is
|
|
567 |
# mostly a workaround for filesystems which lie about being able to
|
|
568 |
# write to a directory (cygwin & win32)
|
|
569 |
if (st.st_mode & 07777 == 00000): |
|
570 |
# FTP allows stat but does not return dir/file modes
|
|
571 |
self._dir_mode = None |
|
572 |
self._file_mode = None |
|
573 |
else: |
|
574 |
self._dir_mode = (st.st_mode & 07777) | 00700 |
|
575 |
# Remove the sticky and execute bits for files
|
|
576 |
self._file_mode = self._dir_mode & ~07111 |
|
577 |
||
578 |
def _get_file_mode(self): |
|
579 |
"""Return Unix mode for newly created files, or None. |
|
580 |
"""
|
|
581 |
if not self._mode_check_done: |
|
582 |
self._find_creation_modes() |
|
583 |
return self._file_mode |
|
584 |
||
585 |
def _get_dir_mode(self): |
|
586 |
"""Return Unix mode for newly created directories, or None. |
|
587 |
"""
|
|
588 |
if not self._mode_check_done: |
|
589 |
self._find_creation_modes() |
|
590 |
return self._dir_mode |
|
591 |
||
|
0.200.1487
by Jelmer Vernooij
Use peeling. |
592 |
def get_refs_container(self): |
593 |
return self._git.refs |
|
|
0.200.1489
by Jelmer Vernooij
More fixes to peel handling. |
594 |
|
595 |
def get_peeled(self, ref): |
|
596 |
return self._git.get_peeled(ref) |