213
217
target, basis.get_reference_revision(path),
214
218
force_new_repo=force_new_repo, recurse=recurse,
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()
218
227
def clone_on_transport(self, transport, revision_id=None,
219
228
force_new_repo=False, preserve_stacking=False,
220
229
stacked_on=None, create_prefix=False,
221
use_existing_dir=True, no_tree=False):
230
use_existing_dir=True, no_tree=False,
222
232
"""See ControlDir.clone_on_transport."""
223
233
from ..repository import InterRepository
224
234
from .mapping import default_mapping
235
from ..transport.local import LocalTransport
225
236
if stacked_on is not None:
226
237
raise _mod_branch.UnstackableBranchFormat(
227
238
self._format, self.user_url)
240
251
interrepo = InterRepository.get(source_repo, target_repo)
241
252
if revision_id is not None:
242
253
determine_wants = interrepo.get_determine_wants_revids(
243
[revision_id], include_tags=True)
254
[revision_id], include_tags=True, tag_selector=tag_selector)
245
256
determine_wants = interrepo.determine_wants_all
246
257
(pack_hint, _, refs) = interrepo.fetch_objects(determine_wants,
247
258
mapping=default_mapping)
248
259
for name, val in refs.items():
249
260
target_git_repo.refs[name] = val
250
result_dir = self.__class__(transport, target_git_repo, format)
261
result_dir = LocalGitDir(transport, target_git_repo, format)
251
262
if revision_id is not None:
252
263
result_dir.open_branch().set_last_revision(revision_id)
254
# Cheaper to check if the target is not local, than to try making
256
result_dir.root_transport.local_abspath('.')
264
if not no_tree and isinstance(result_dir.root_transport, LocalTransport):
257
265
if result_dir.open_repository().make_working_trees():
258
self.open_workingtree().clone(
259
result_dir, revision_id=revision_id)
260
except (brz_errors.NoWorkingTree, brz_errors.NotLocalUrl):
267
local_wt = self.open_workingtree()
268
except brz_errors.NoWorkingTree:
270
except brz_errors.NotLocalUrl:
271
result_dir.create_workingtree(revision_id=revision_id)
273
local_wt.clone(result_dir, revision_id=revision_id)
263
275
return result_dir
294
306
return UseExistingRepository(self.find_repository())
308
def branch_names(self):
309
from .refs import ref_to_branch_name
311
for ref in self.get_refs_container().keys():
313
branch_name = ref_to_branch_name(ref)
314
except UnicodeDecodeError:
315
trace.warning("Ignoring branch %r with unicode error ref", ref)
319
ret.append(branch_name)
296
322
def get_branches(self):
297
323
from .refs import ref_to_branch_name
313
339
def push_branch(self, source, revision_id=None, overwrite=False,
314
340
remember=False, create_prefix=False, lossy=False,
341
name=None, tag_selector=None):
316
342
"""Push the source branch into this ControlDir."""
317
343
push_result = GitPushResult()
318
344
push_result.workingtree_updated = None
325
351
target = self.open_branch(name, nascent_ok=True)
326
352
push_result.branch_push_result = source.push(
327
353
target, overwrite=overwrite, stop_revision=revision_id,
354
lossy=lossy, tag_selector=tag_selector)
329
355
push_result.new_revid = push_result.branch_push_result.new_revid
330
356
push_result.old_revid = push_result.branch_push_result.old_revid
520
546
target_branch._format, self._format)
521
547
# TODO(jelmer): Do some consistency checking across branches..
522
548
self.control_transport.put_bytes(
523
'commondir', target_path.encode('utf-8'))
549
'commondir', encode_git_path(target_path))
524
550
# TODO(jelmer): Urgh, avoid mucking about with internals.
525
551
self._git._commontransport = (
526
552
target_branch.repository._git._commontransport.clone())
560
586
base_url = self.user_url.rstrip('/')
562
588
base_url = urlutils.local_path_to_url(
563
commondir.decode(osutils._fs_enc)).rstrip('/.git/') + '/'
589
decode_git_path(commondir)).rstrip('/.git/') + '/'
564
590
return urlutils.join_segment_parameters(base_url, params)