/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/git/remote.py

  • Committer: Jelmer Vernooij
  • Date: 2020-02-13 23:57:28 UTC
  • mfrom: (7490 work)
  • mto: This revision was merged to the branch mainline in revision 7492.
  • Revision ID: jelmer@jelmer.uk-20200213235728-m6ds0mm3mbs4y182
Merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
48
48
    PermissionDenied,
49
49
    UninitializableFormat,
50
50
    )
 
51
from ..revision import NULL_REVISION
51
52
from ..revisiontree import RevisionTree
52
53
from ..transport import (
53
54
    Transport,
444
445
        else:
445
446
            pb = None
446
447
 
447
 
        def get_changed_refs_wrapper(refs):
448
 
            # TODO(jelmer): This drops symref information
449
 
            self._refs = remote_refs_dict_to_container(refs)
450
 
            return get_changed_refs(refs)
 
448
        def get_changed_refs_wrapper(remote_refs):
 
449
            if self._refs is not None:
 
450
                update_refs_container(self._refs, remote_refs)
 
451
            return get_changed_refs(remote_refs)
451
452
        try:
452
453
            return self._client.send_pack(
453
454
                self._client_path, get_changed_refs_wrapper,
463
464
        refname = self._get_selected_ref(name, ref)
464
465
        if refname != b'HEAD' and refname in self.get_refs_container():
465
466
            raise AlreadyBranchError(self.user_url)
466
 
        if refname in self.get_refs_container():
467
 
            ref_chain, unused_sha = self.get_refs_container().follow(
468
 
                self._get_selected_ref(None))
469
 
            if ref_chain[0] == b'HEAD':
470
 
                refname = ref_chain[1]
 
467
        ref_chain, unused_sha = self.get_refs_container().follow(
 
468
            self._get_selected_ref(name))
 
469
        if ref_chain and ref_chain[0] == b'HEAD':
 
470
            refname = ref_chain[1]
471
471
        repo = self.open_repository()
472
472
        return RemoteGitBranch(self, repo, refname)
473
473
 
562
562
        push_result.branch_push_result = None
563
563
        repo = self.find_repository()
564
564
        refname = self._get_selected_ref(name)
 
565
        ref_chain, old_sha = self.get_refs_container().follow(refname)
 
566
        if ref_chain:
 
567
            actual_refname = ref_chain[-1]
 
568
        else:
 
569
            actual_refname = refname
565
570
        if isinstance(source, GitBranch) and lossy:
566
571
            raise errors.LossyPushToSameVCS(source.controldir, self)
567
572
        source_store = get_object_store(source.repository)
568
573
        fetch_tags = source.get_config_stack().get('branch.fetch_tags')
569
 
        def get_changed_refs(refs):
570
 
            self._refs = remote_refs_dict_to_container(refs)
 
574
        def get_changed_refs(remote_refs):
 
575
            if self._refs is not None:
 
576
                update_refs_container(self._refs, remote_refs)
571
577
            ret = {}
572
578
            # TODO(jelmer): Unpeel if necessary
573
579
            push_result.new_original_revid = revision_id
580
586
                    raise errors.NoRoundtrippingSupport(
581
587
                        source, self.open_branch(name=name, nascent_ok=True))
582
588
            if not overwrite:
583
 
                if remote_divergence(ret.get(refname), new_sha,
584
 
                                     source_store):
 
589
                if remote_divergence(old_sha, new_sha, source_store):
585
590
                    raise DivergedBranches(
586
591
                        source, self.open_branch(name, nascent_ok=True))
587
 
            ret[refname] = new_sha
 
592
            ret[actual_refname] = new_sha
588
593
            if fetch_tags:
589
594
                for tagname, revid in source.tags.get_tag_dict().items():
590
595
                    if lossy:
591
 
                        new_sha = source_store._lookup_revision_sha1(revid)
 
596
                        try:
 
597
                            new_sha = source_store._lookup_revision_sha1(revid)
 
598
                        except KeyError:
 
599
                            if source.repository.has_revision(revid):
 
600
                                raise
592
601
                    else:
593
602
                        try:
594
603
                            new_sha = repo.lookup_bzr_revision_id(revid)[0]
603
612
                generate_pack_data = source_store.generate_pack_data
604
613
            new_refs = self.send_pack(get_changed_refs, generate_pack_data)
605
614
        push_result.new_revid = repo.lookup_foreign_revision_id(
606
 
            new_refs[refname])
607
 
        try:
608
 
            old_remote = self._refs[refname]
609
 
        except KeyError:
610
 
            old_remote = ZERO_SHA
611
 
        push_result.old_revid = repo.lookup_foreign_revision_id(old_remote)
612
 
        self._refs = remote_refs_dict_to_container(new_refs)
 
615
            new_refs[actual_refname])
 
616
        if old_sha is not None:
 
617
            push_result.old_revid = repo.lookup_foreign_revision_id(old_sha)
 
618
        else:
 
619
            push_result.old_revid = NULL_REVISION
 
620
        if self._refs is not None:
 
621
            update_refs_container(self._refs, new_refs)
613
622
        push_result.target_branch = self.open_branch(name)
614
 
        if old_remote != ZERO_SHA:
 
623
        if old_sha is not None:
615
624
            push_result.branch_push_result = GitBranchPushResult()
616
625
            push_result.branch_push_result.source_branch = source
617
626
            push_result.branch_push_result.target_branch = (
1021
1030
    ret = DictRefsContainer(base)
1022
1031
    ret._peeled = peeled
1023
1032
    return ret
 
1033
 
 
1034
 
 
1035
def update_refs_container(container, refs_dict):
 
1036
    peeled = {}
 
1037
    base = {}
 
1038
    for k, v in refs_dict.items():
 
1039
        if is_peeled(k):
 
1040
            peeled[k[:-3]] = v
 
1041
        else:
 
1042
            base[k] = v
 
1043
    container._peeled = peeled
 
1044
    container._refs.update(base)