88
167
:param url: Git URL
89
168
:return: Tuple with host, port, username, path.
91
(scheme, netloc, loc, _, _) = urlparse.urlsplit(url)
92
path = urllib.unquote(loc)
170
parsed_url = urlparse.urlparse(url)
171
path = urlparse.unquote(parsed_url.path)
93
172
if path.startswith("/~"):
95
(username, hostport) = urllib.splituser(netloc)
96
(host, port) = urllib.splitnport(hostport, None)
97
return (host, port, username, path)
174
return ((parsed_url.hostname or '', parsed_url.port, parsed_url.username, path))
177
class RemoteGitError(BzrError):
179
_fmt = "Remote server error: %(msg)s"
182
class HeadUpdateFailed(BzrError):
184
_fmt = ("Unable to update remote HEAD branch. To update the master "
185
"branch, specify the URL %(base_url)s,branch=master.")
187
def __init__(self, base_url):
188
super(HeadUpdateFailed, self).__init__()
189
self.base_url = base_url
192
def parse_git_error(url, message):
193
"""Parse a remote git server error and return a bzr exception.
195
:param url: URL of the remote repository
196
:param message: Message sent by the remote git server
198
message = str(message).strip()
199
if (message.startswith("Could not find Repository ")
200
or message == 'Repository not found.'
201
or (message.startswith('Repository ') and
202
message.endswith(' not found.'))):
203
return NotBranchError(url, message)
204
if message == "HEAD failed to update":
205
base_url = urlutils.strip_segment_parameters(url)
206
return HeadUpdateFailed(base_url)
207
if message.startswith('access denied or repository not exported:'):
208
extra, path = message.split(':', 1)
209
return PermissionDenied(path.strip(), extra)
210
if message.endswith('You are not allowed to push code to this project.'):
211
return PermissionDenied(url, message)
212
if message.endswith(' does not appear to be a git repository'):
213
return NotBranchError(url, message)
214
if message == 'pre-receive hook declined':
215
return PermissionDenied(url, message)
216
if re.match('(.+) is not a valid repository name',
217
message.splitlines()[0]):
218
return NotBranchError(url, message)
220
'GitLab: You are not allowed to push code to protected branches '
222
return PermissionDenied(url, message)
223
m = re.match(r'Permission to ([^ ]+) denied to ([^ ]+)\.', message)
225
return PermissionDenied(m.group(1), 'denied to %s' % m.group(2))
226
# Don't know, just return it to the user as-is
227
return RemoteGitError(message)
230
def parse_git_hangup(url, e):
231
"""Parse the error lines from a git servers stderr on hangup.
233
:param url: URL of the remote repository
234
:param e: A HangupException
236
stderr_lines = getattr(e, 'stderr_lines', None)
239
if all(line.startswith(b'remote: ') for line in stderr_lines):
241
line[len(b'remote: '):] for line in stderr_lines]
242
interesting_lines = [
243
line for line in stderr_lines
244
if line and line.replace(b'=', b'')]
245
if len(interesting_lines) == 1:
246
interesting_line = interesting_lines[0]
247
return parse_git_error(
248
url, interesting_line.decode('utf-8', 'surrogateescape'))
249
return RemoteGitError(
250
b'\n'.join(stderr_lines).decode('utf-8', 'surrogateescape'))
100
253
class GitSmartTransport(Transport):
373
class RemoteGitBranchFormat(GitBranchFormat):
375
def get_format_description(self):
376
return 'Remote Git Branch'
379
def _matchingcontroldir(self):
380
return RemoteGitControlDirFormat()
382
def initialize(self, a_controldir, name=None, repository=None,
383
append_revisions_only=None):
384
raise UninitializableFormat(self)
387
class DefaultProgressReporter(object):
389
_GIT_PROGRESS_PARTIAL_RE = re.compile(r"(.*?): +(\d+)% \((\d+)/(\d+)\)")
390
_GIT_PROGRESS_TOTAL_RE = re.compile(r"(.*?): (\d+)")
392
def __init__(self, pb):
395
def progress(self, text):
396
text = text.rstrip(b"\r\n")
397
text = text.decode('utf-8')
398
if text.lower().startswith('error: '):
399
trace.show_error('git: %s', text[len(b'error: '):])
401
trace.mutter("git: %s", text)
402
g = self._GIT_PROGRESS_PARTIAL_RE.match(text)
404
(text, pct, current, total) = g.groups()
405
self.pb.update(text, int(current), int(total))
407
g = self._GIT_PROGRESS_TOTAL_RE.match(text)
409
(text, total) = g.groups()
410
self.pb.update(text, None, int(total))
412
trace.note("%s", text)
198
415
class RemoteGitDir(GitDir):
200
def __init__(self, transport, lockfiles, format):
417
def __init__(self, transport, format, client, client_path):
201
418
self._format = format
202
419
self.root_transport = transport
203
420
self.transport = transport
204
self._lockfiles = lockfiles
205
421
self._mode_check_done = None
207
def _branch_name_to_ref(self, name, default=None):
208
return branch_name_to_ref(name, default=default)
422
self._client = client
423
self._client_path = client_path
424
self.base = self.root_transport.base
428
def _gitrepository_class(self):
429
return RemoteGitRepository
431
def archive(self, format, committish, write_data, progress=None,
432
write_error=None, subdirs=None, prefix=None):
434
pb = ui.ui_factory.nested_progress_bar()
435
progress = DefaultProgressReporter(pb).progress
438
def progress_wrapper(message):
439
if message.startswith(b"fatal: Unknown archive format \'"):
440
format = message.strip()[len(b"fatal: Unknown archive format '"):-1]
441
raise errors.NoSuchExportFormat(format.decode('ascii'))
442
return progress(message)
444
self._client.archive(
445
self._client_path, committish, write_data, progress_wrapper,
447
format=(format.encode('ascii') if format else None),
449
prefix=(encode_git_path(prefix) if prefix else None))
450
except HangupException as e:
451
raise parse_git_hangup(self.transport.external_url(), e)
452
except GitProtocolError as e:
453
raise parse_git_error(self.transport.external_url(), e)
458
def fetch_pack(self, determine_wants, graph_walker, pack_data,
461
pb = ui.ui_factory.nested_progress_bar()
462
progress = DefaultProgressReporter(pb).progress
466
result = self._client.fetch_pack(
467
self._client_path, determine_wants, graph_walker, pack_data,
469
if result.refs is None:
471
self._refs = remote_refs_dict_to_container(
472
result.refs, result.symrefs)
474
except HangupException as e:
475
raise parse_git_hangup(self.transport.external_url(), e)
476
except GitProtocolError as e:
477
raise parse_git_error(self.transport.external_url(), e)
482
def send_pack(self, get_changed_refs, generate_pack_data, progress=None):
484
pb = ui.ui_factory.nested_progress_bar()
485
progress = DefaultProgressReporter(pb).progress
489
def get_changed_refs_wrapper(remote_refs):
490
if self._refs is not None:
491
update_refs_container(self._refs, remote_refs)
492
return get_changed_refs(remote_refs)
494
return self._client.send_pack(
495
self._client_path, get_changed_refs_wrapper,
496
generate_pack_data, progress)
497
except HangupException as e:
498
raise parse_git_hangup(self.transport.external_url(), e)
499
except GitProtocolError as e:
500
raise parse_git_error(self.transport.external_url(), e)
505
def create_branch(self, name=None, repository=None,
506
append_revisions_only=None, ref=None):
507
refname = self._get_selected_ref(name, ref)
508
if refname != b'HEAD' and refname in self.get_refs_container():
509
raise AlreadyBranchError(self.user_url)
510
ref_chain, unused_sha = self.get_refs_container().follow(
511
self._get_selected_ref(name))
512
if ref_chain and ref_chain[0] == b'HEAD':
513
refname = ref_chain[1]
514
repo = self.open_repository()
515
return RemoteGitBranch(self, repo, refname)
517
def destroy_branch(self, name=None):
518
refname = self._get_selected_ref(name)
520
def get_changed_refs(old_refs):
522
if refname not in old_refs:
523
raise NotBranchError(self.user_url)
524
ret[refname] = dulwich.client.ZERO_SHA
527
def generate_pack_data(have, want, ofs_delta=False):
528
return pack_objects_to_data([])
529
result = self.send_pack(get_changed_refs, generate_pack_data)
530
if result is not None and not isinstance(result, dict):
531
error = result.ref_status.get(refname)
533
raise RemoteGitError(error)
537
return self.control_url
540
def user_transport(self):
541
return self.root_transport
544
def control_url(self):
545
return self.control_transport.base
548
def control_transport(self):
549
return self.root_transport
210
551
def open_repository(self):
211
return RemoteGitRepository(self, self._lockfiles)
213
def _open_branch(self, name=None, ignore_fallbacks=False,
552
return RemoteGitRepository(self)
554
def get_branch_reference(self, name=None):
555
ref = branch_name_to_ref(name)
556
val = self.get_refs_container().read_ref(ref)
557
if val.startswith(SYMREF):
558
return val[len(SYMREF):]
561
def open_branch(self, name=None, unsupported=False,
562
ignore_fallbacks=False, ref=None, possible_transports=None,
215
564
repo = self.open_repository()
216
refname = self._branch_name_to_ref(name)
217
return RemoteGitBranch(self, repo, refname, self._lockfiles)
565
ref = self._get_selected_ref(name, ref)
567
if not nascent_ok and ref not in self.get_refs_container():
568
raise NotBranchError(
569
self.root_transport.base, controldir=self)
570
except NotGitRepository:
571
raise NotBranchError(self.root_transport.base,
573
ref_chain, unused_sha = self.get_refs_container().follow(ref)
574
return RemoteGitBranch(self, repo, ref_chain[-1])
219
576
def open_workingtree(self, recommend_upgrade=False):
220
577
raise NotLocalUrl(self.transport.base)
579
def has_workingtree(self):
582
def get_peeled(self, name):
583
return self.get_refs_container().get_peeled(name)
585
def get_refs_container(self):
586
if self._refs is not None:
588
result = self.fetch_pack(lambda x: None, None,
590
lambda x: trace.mutter("git: %s" % x))
591
self._refs = remote_refs_dict_to_container(
592
result.refs, result.symrefs)
595
def push_branch(self, source, revision_id=None, overwrite=False,
596
remember=False, create_prefix=False, lossy=False,
597
name=None, tag_selector=None):
598
"""Push the source branch into this ControlDir."""
599
if revision_id is None:
600
# No revision supplied by the user, default to the branch
602
revision_id = source.last_revision()
604
if not source.repository.has_revision(revision_id):
605
raise NoSuchRevision(source, revision_id)
607
push_result = GitPushResult()
608
push_result.workingtree_updated = None
609
push_result.master_branch = None
610
push_result.source_branch = source
611
push_result.stacked_on = None
612
push_result.branch_push_result = None
613
repo = self.find_repository()
614
refname = self._get_selected_ref(name)
616
ref_chain, old_sha = self.get_refs_container().follow(refname)
617
except NotBranchError:
618
actual_refname = refname
622
actual_refname = ref_chain[-1]
624
actual_refname = refname
625
if isinstance(source, GitBranch) and lossy:
626
raise errors.LossyPushToSameVCS(source.controldir, self)
627
source_store = get_object_store(source.repository)
628
fetch_tags = source.get_config_stack().get('branch.fetch_tags')
629
def get_changed_refs(remote_refs):
630
if self._refs is not None:
631
update_refs_container(self._refs, remote_refs)
633
# TODO(jelmer): Unpeel if necessary
634
push_result.new_original_revid = revision_id
636
new_sha = source_store._lookup_revision_sha1(revision_id)
639
new_sha = repo.lookup_bzr_revision_id(revision_id)[0]
640
except errors.NoSuchRevision:
641
raise errors.NoRoundtrippingSupport(
642
source, self.open_branch(name=name, nascent_ok=True))
644
old_sha = remote_refs.get(actual_refname)
645
if remote_divergence(old_sha, new_sha, source_store):
646
raise DivergedBranches(
647
source, self.open_branch(name, nascent_ok=True))
648
ret[actual_refname] = new_sha
650
for tagname, revid in viewitems(source.tags.get_tag_dict()):
651
if tag_selector and not tag_selector(tagname):
655
new_sha = source_store._lookup_revision_sha1(revid)
657
if source.repository.has_revision(revid):
661
new_sha = repo.lookup_bzr_revision_id(revid)[0]
662
except errors.NoSuchRevision:
665
if not source.repository.has_revision(revid):
667
ret[tag_name_to_ref(tagname)] = new_sha
669
with source_store.lock_read():
670
def generate_pack_data(have, want, progress=None,
672
git_repo = getattr(source.repository, '_git', None)
674
shallow = git_repo.get_shallow()
678
return source_store.generate_lossy_pack_data(
679
have, want, shallow=shallow,
680
progress=progress, ofs_delta=ofs_delta)
682
return source_store.generate_pack_data(
683
have, want, shallow=shallow,
684
progress=progress, ofs_delta=ofs_delta)
686
return source_store.generate_pack_data(
687
have, want, progress=progress, ofs_delta=ofs_delta)
688
dw_result = self.send_pack(get_changed_refs, generate_pack_data)
689
if not isinstance(dw_result, dict):
690
new_refs = dw_result.refs
691
error = dw_result.ref_status.get(actual_refname)
693
raise RemoteGitError(error)
694
for ref, error in dw_result.ref_status.items():
696
trace.warning('unable to open ref %s: %s',
698
else: # dulwich < 0.20.4
700
push_result.new_revid = repo.lookup_foreign_revision_id(
701
new_refs[actual_refname])
702
if old_sha is not None:
703
push_result.old_revid = repo.lookup_foreign_revision_id(old_sha)
705
push_result.old_revid = NULL_REVISION
706
if self._refs is not None:
707
update_refs_container(self._refs, new_refs)
708
push_result.target_branch = self.open_branch(name)
709
if old_sha is not None:
710
push_result.branch_push_result = GitBranchPushResult()
711
push_result.branch_push_result.source_branch = source
712
push_result.branch_push_result.target_branch = (
713
push_result.target_branch)
714
push_result.branch_push_result.local_branch = None
715
push_result.branch_push_result.master_branch = (
716
push_result.target_branch)
717
push_result.branch_push_result.old_revid = push_result.old_revid
718
push_result.branch_push_result.new_revid = push_result.new_revid
719
push_result.branch_push_result.new_original_revid = (
720
push_result.new_original_revid)
721
if source.get_push_location() is None or remember:
722
source.set_push_location(push_result.target_branch.base)
725
def _find_commondir(self):
726
# There is no way to find the commondir, if there is any.
223
730
class EmptyObjectStoreIterator(dict):
262
757
os.remove(self._data_path)
760
class BzrGitHttpClient(dulwich.client.HttpGitClient):
762
def __init__(self, transport, *args, **kwargs):
763
self.transport = transport
764
url = urlutils.URL.from_string(transport.external_url())
765
url.user = url.quoted_user = None
766
url.password = url.quoted_password = None
767
url = urlutils.strip_segment_parameters(str(url))
768
super(BzrGitHttpClient, self).__init__(url, *args, **kwargs)
770
def _http_request(self, url, headers=None, data=None,
771
allow_compression=False):
772
"""Perform HTTP request.
774
:param url: Request URL.
775
:param headers: Optional custom headers to override defaults.
776
:param data: Request data.
777
:param allow_compression: Allow GZipped communication.
778
:return: Tuple (`response`, `read`), where response is an `urllib3`
779
response object with additional `content_type` and
780
`redirect_location` properties, and `read` is a consumable read
781
method for the response data.
783
if is_github_url(url):
784
headers['User-agent'] = user_agent_for_github()
785
headers["Pragma"] = "no-cache"
786
if allow_compression:
787
headers["Accept-Encoding"] = "gzip"
789
headers["Accept-Encoding"] = "identity"
791
response = self.transport.request(
792
('GET' if data is None else 'POST'),
795
headers=headers, retries=8)
797
if response.status == 404:
798
raise NotGitRepository()
799
elif response.status != 200:
800
raise GitProtocolError("unexpected http resp %d for %s" %
801
(response.status, url))
803
# TODO: Optimization available by adding `preload_content=False` to the
804
# request and just passing the `read` method on instead of going via
805
# `BytesIO`, if we can guarantee that the entire response is consumed
806
# before issuing the next to still allow for connection reuse from the
808
if response.getheader("Content-Encoding") == "gzip":
809
read = gzip.GzipFile(fileobj=BytesIO(response.read())).read
813
class WrapResponse(object):
815
def __init__(self, response):
816
self._response = response
817
self.status = response.status
818
self.content_type = response.getheader("Content-Type")
819
self.redirect_location = response._actual.geturl()
822
return self._response.readlines()
827
return WrapResponse(response), read
830
def _git_url_and_path_from_transport(external_url):
831
url = urlutils.strip_segment_parameters(external_url)
832
return urlparse.urlsplit(url)
835
class RemoteGitControlDirFormat(GitControlDirFormat):
836
"""The .git directory control format."""
838
supports_workingtrees = False
841
def _known_formats(self):
842
return set([RemoteGitControlDirFormat()])
844
def get_branch_format(self):
845
return RemoteGitBranchFormat()
848
def repository_format(self):
849
return GitRepositoryFormat()
851
def is_initializable(self):
854
def is_supported(self):
857
def open(self, transport, _found=None):
858
"""Open this directory.
861
split_url = _git_url_and_path_from_transport(transport.external_url())
862
if isinstance(transport, GitSmartTransport):
863
client = transport._get_client()
864
elif split_url.scheme in ("http", "https"):
865
client = BzrGitHttpClient(transport)
866
elif split_url.scheme in ('file', ):
867
client = dulwich.client.LocalGitClient()
869
raise NotBranchError(transport.base)
871
pass # TODO(jelmer): Actually probe for something
872
return RemoteGitDir(transport, self, client, split_url.path)
874
def get_format_description(self):
875
return "Remote Git Repository"
877
def initialize_on_transport(self, transport):
878
raise UninitializableFormat(self)
880
def supports_transport(self, transport):
882
external_url = transport.external_url()
883
except InProcessTransport:
884
raise NotBranchError(path=transport.base)
885
return (external_url.startswith("http:")
886
or external_url.startswith("https:")
887
or external_url.startswith("git+")
888
or external_url.startswith("git:"))
891
class GitRemoteRevisionTree(RevisionTree):
893
def archive(self, format, name, root=None, subdir=None, force_mtime=None):
894
"""Create an archive of this tree.
896
:param format: Format name (e.g. 'tar')
897
:param name: target file name
898
:param root: Root directory name (or None)
899
:param subdir: Subdirectory to export (or None)
900
:return: Iterator over archive chunks
902
commit = self._repository.lookup_bzr_revision_id(
903
self.get_revision_id())[0]
905
f = tempfile.SpooledTemporaryFile()
906
# git-upload-archive(1) generaly only supports refs. So let's see if we
910
self._repository.controldir.get_refs_container().as_dict().items()}
912
committish = reverse_refs[commit]
914
# No? Maybe the user has uploadArchive.allowUnreachable enabled.
915
# Let's hope for the best.
917
self._repository.archive(
918
format, committish, f.write,
919
subdirs=([subdir] if subdir else None),
920
prefix=(root + '/') if root else '')
922
return osutils.file_iterator(f)
924
def is_versioned(self, path):
925
raise GitSmartRemoteNotSupported(self.is_versioned, self)
927
def has_filename(self, path):
928
raise GitSmartRemoteNotSupported(self.has_filename, self)
930
def get_file_text(self, path):
931
raise GitSmartRemoteNotSupported(self.get_file_text, self)
933
def list_files(self, include_root=False, from_dir=None, recursive=True):
934
raise GitSmartRemoteNotSupported(self.list_files, self)
265
937
class RemoteGitRepository(GitRepository):
267
def __init__(self, gitdir, lockfiles):
268
GitRepository.__init__(self, gitdir, lockfiles)
272
def inventories(self):
273
raise GitSmartRemoteNotSupported()
277
raise GitSmartRemoteNotSupported()
281
raise GitSmartRemoteNotSupported()
284
if self._refs is not None:
286
self._refs = self.bzrdir.root_transport.fetch_pack(lambda x: [], None,
287
lambda x: None, lambda x: trace.mutter("git: %s" % x))
939
supports_random_access = False
943
return self.control_url
945
def get_parent_map(self, revids):
946
raise GitSmartRemoteNotSupported(self.get_parent_map, self)
948
def archive(self, *args, **kwargs):
949
return self.controldir.archive(*args, **kwargs)
290
951
def fetch_pack(self, determine_wants, graph_walker, pack_data,
292
return self._transport.fetch_pack(determine_wants, graph_walker,
953
return self.controldir.fetch_pack(
954
determine_wants, graph_walker, pack_data, progress)
295
def send_pack(self, get_changed_refs, generate_pack_contents):
296
return self._transport.send_pack(get_changed_refs, generate_pack_contents)
956
def send_pack(self, get_changed_refs, generate_pack_data):
957
return self.controldir.send_pack(get_changed_refs, generate_pack_data)
298
959
def fetch_objects(self, determine_wants, graph_walker, resolve_ext_ref,
300
962
fd, path = tempfile.mkstemp(suffix=".pack")
301
self.fetch_pack(determine_wants, graph_walker,
302
lambda x: os.write(fd, x), progress)
964
self.fetch_pack(determine_wants, graph_walker,
965
lambda x: os.write(fd, x), progress)
304
968
if os.path.getsize(path) == 0:
305
969
return EmptyObjectStoreIterator()
306
970
return TemporaryPackIterator(path[:-len(".pack")], resolve_ext_ref)
308
def lookup_bzr_revision_id(self, bzr_revid):
309
# This won't work for any round-tripped bzr revisions, but it's a start..
972
def lookup_bzr_revision_id(self, bzr_revid, mapping=None):
973
# This won't work for any round-tripped bzr revisions, but it's a
311
976
return mapping_registry.revision_id_bzr_to_foreign(bzr_revid)
312
977
except InvalidRevisionId:
321
986
# Not really an easy way to parse foreign revids here..
322
987
return mapping.revision_id_foreign_to_bzr(foreign_revid)
325
class RemoteGitTagDict(tag.BasicTags):
327
def __init__(self, branch):
329
self.repository = branch.repository
331
def get_tag_dict(self):
333
for k, v in extract_tags(self.repository.get_refs()).iteritems():
334
tags[k] = self.branch.mapping.revision_id_foreign_to_bzr(v)
989
def revision_tree(self, revid):
990
return GitRemoteRevisionTree(self, revid)
992
def get_revisions(self, revids):
993
raise GitSmartRemoteNotSupported(self.get_revisions, self)
995
def has_revisions(self, revids):
996
raise GitSmartRemoteNotSupported(self.get_revisions, self)
999
class RemoteGitTagDict(GitTags):
337
1001
def set_tag(self, name, revid):
338
# FIXME: Not supported yet, should do a push of a new ref
339
raise NotImplementedError(self.set_tag)
1002
sha = self.branch.lookup_bzr_revision_id(revid)[0]
1003
self._set_ref(name, sha)
1005
def delete_tag(self, name):
1006
self._set_ref(name, dulwich.client.ZERO_SHA)
1008
def _set_ref(self, name, sha):
1009
ref = tag_name_to_ref(name)
1011
def get_changed_refs(old_refs):
1013
if sha == dulwich.client.ZERO_SHA and ref not in old_refs:
1014
raise NoSuchTag(name)
1018
def generate_pack_data(have, want, ofs_delta=False):
1019
return pack_objects_to_data([])
1020
result = self.repository.send_pack(
1021
get_changed_refs, generate_pack_data)
1022
if result and not isinstance(result, dict):
1023
error = result.ref_status.get(ref)
1025
raise RemoteGitError(error)
342
1028
class RemoteGitBranch(GitBranch):
344
def __init__(self, bzrdir, repository, name, lockfiles):
1030
def __init__(self, controldir, repository, name):
345
1031
self._sha = None
346
super(RemoteGitBranch, self).__init__(bzrdir, repository, name,
349
def revision_history(self):
350
raise GitSmartRemoteNotSupported()
1032
super(RemoteGitBranch, self).__init__(controldir, repository, name,
1033
RemoteGitBranchFormat())
1035
def last_revision_info(self):
1036
raise GitSmartRemoteNotSupported(self.last_revision_info, self)
1040
return self.control_url
1043
def control_url(self):
1046
def revision_id_to_revno(self, revision_id):
1047
raise GitSmartRemoteNotSupported(self.revision_id_to_revno, self)
352
1049
def last_revision(self):
353
1050
return self.lookup_foreign_revision_id(self.head)
355
def _get_config(self):
356
class EmptyConfig(object):
358
def _get_configobj(self):
359
return config.ConfigObj()
365
1054
if self._sha is not None:
366
1055
return self._sha
367
heads = self.repository.get_refs()
368
name = self.bzrdir._branch_name_to_ref(self.name, "HEAD")
370
self._sha = heads[name]
372
raise NoSuchRef(self.name)
1056
refs = self.controldir.get_refs_container()
1057
name = branch_name_to_ref(self.name)
1059
self._sha = refs[name]
1061
raise NoSuchRef(name, self.repository.user_url, refs)
373
1062
return self._sha
375
1064
def _synchronize_history(self, destination, revision_id):
376
1065
"""See Branch._synchronize_history()."""
377
destination.generate_revision_history(self.last_revision())
1066
if revision_id is None:
1067
revision_id = self.last_revision()
1068
destination.generate_revision_history(revision_id)
1070
def _get_parent_location(self):
379
1073
def get_push_location(self):
382
1076
def set_push_location(self, url):
1079
def _iter_tag_refs(self):
1080
"""Iterate over the tag refs.
1082
:param refs: Refs dictionary (name -> git sha1)
1083
:return: iterator over (ref_name, tag_name, peeled_sha1, unpeeled_sha1)
1085
refs = self.controldir.get_refs_container()
1086
for ref_name, unpeeled in refs.as_dict().items():
1088
tag_name = ref_to_tag_name(ref_name)
1089
except (ValueError, UnicodeDecodeError):
1091
peeled = refs.get_peeled(ref_name)
1093
# Let's just hope it's a commit
1095
if not isinstance(tag_name, text_type):
1096
raise TypeError(tag_name)
1097
yield (ref_name, tag_name, peeled, unpeeled)
1099
def set_last_revision_info(self, revno, revid):
1100
self.generate_revision_history(revid)
1102
def generate_revision_history(self, revision_id, last_rev=None,
1104
sha = self.lookup_bzr_revision_id(revision_id)[0]
1105
def get_changed_refs(old_refs):
1106
return {self.ref: sha}
1107
def generate_pack_data(have, want, ofs_delta=False):
1108
return pack_objects_to_data([])
1109
result = self.repository.send_pack(
1110
get_changed_refs, generate_pack_data)
1111
if result is not None and not isinstance(result, dict):
1112
error = result.ref_status.get(self.ref)
1114
raise RemoteGitError(error)
1118
def remote_refs_dict_to_container(refs_dict, symrefs_dict={}):
1121
for k, v in refs_dict.items():
1126
for name, target in symrefs_dict.items():
1127
base[name] = SYMREF + target
1128
ret = DictRefsContainer(base)
1129
ret._peeled = peeled
1133
def update_refs_container(container, refs_dict):
1136
for k, v in refs_dict.items():
1141
container._peeled = peeled
1142
container._refs.update(base)