/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: Breezy landing bot
  • Author(s): Jelmer Vernooij
  • Date: 2020-02-08 23:15:51 UTC
  • mfrom: (7484.1.3 git-follow-symref)
  • Revision ID: breezy.the.bot@gmail.com-20200208231551-ir5l2ihfj47gzug0
Follow symrefs when pushing to git repositories.

Merged from https://code.launchpad.net/~jelmer/brz/git-follow-symref/+merge/378769

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 ..sixish import (
53
54
    text_type,
452
453
        else:
453
454
            pb = None
454
455
 
455
 
        def get_changed_refs_wrapper(refs):
456
 
            # TODO(jelmer): This drops symref information
457
 
            self._refs = remote_refs_dict_to_container(refs)
458
 
            return get_changed_refs(refs)
 
456
        def get_changed_refs_wrapper(remote_refs):
 
457
            if self._refs is not None:
 
458
                update_refs_container(self._refs, remote_refs)
 
459
            return get_changed_refs(remote_refs)
459
460
        try:
460
461
            return self._client.send_pack(
461
462
                self._client_path, get_changed_refs_wrapper,
471
472
        refname = self._get_selected_ref(name, ref)
472
473
        if refname != b'HEAD' and refname in self.get_refs_container():
473
474
            raise AlreadyBranchError(self.user_url)
474
 
        if refname in self.get_refs_container():
475
 
            ref_chain, unused_sha = self.get_refs_container().follow(
476
 
                self._get_selected_ref(None))
477
 
            if ref_chain[0] == b'HEAD':
478
 
                refname = ref_chain[1]
 
475
        ref_chain, unused_sha = self.get_refs_container().follow(
 
476
            self._get_selected_ref(name))
 
477
        if ref_chain and ref_chain[0] == b'HEAD':
 
478
            refname = ref_chain[1]
479
479
        repo = self.open_repository()
480
480
        return RemoteGitBranch(self, repo, refname)
481
481
 
570
570
        push_result.branch_push_result = None
571
571
        repo = self.find_repository()
572
572
        refname = self._get_selected_ref(name)
 
573
        ref_chain, old_sha = self.get_refs_container().follow(refname)
 
574
        if ref_chain:
 
575
            actual_refname = ref_chain[-1]
 
576
        else:
 
577
            actual_refname = refname
573
578
        if isinstance(source, GitBranch) and lossy:
574
579
            raise errors.LossyPushToSameVCS(source.controldir, self)
575
580
        source_store = get_object_store(source.repository)
576
581
        fetch_tags = source.get_config_stack().get('branch.fetch_tags')
577
 
        def get_changed_refs(refs):
578
 
            self._refs = remote_refs_dict_to_container(refs)
 
582
        def get_changed_refs(remote_refs):
 
583
            if self._refs is not None:
 
584
                update_refs_container(self._refs, remote_refs)
579
585
            ret = {}
580
586
            # TODO(jelmer): Unpeel if necessary
581
587
            push_result.new_original_revid = revision_id
588
594
                    raise errors.NoRoundtrippingSupport(
589
595
                        source, self.open_branch(name=name, nascent_ok=True))
590
596
            if not overwrite:
591
 
                if remote_divergence(ret.get(refname), new_sha,
592
 
                                     source_store):
 
597
                if remote_divergence(old_sha, new_sha, source_store):
593
598
                    raise DivergedBranches(
594
599
                        source, self.open_branch(name, nascent_ok=True))
595
 
            ret[refname] = new_sha
 
600
            ret[actual_refname] = new_sha
596
601
            if fetch_tags:
597
602
                for tagname, revid in viewitems(source.tags.get_tag_dict()):
598
603
                    if lossy:
611
616
                generate_pack_data = source_store.generate_pack_data
612
617
            new_refs = self.send_pack(get_changed_refs, generate_pack_data)
613
618
        push_result.new_revid = repo.lookup_foreign_revision_id(
614
 
            new_refs[refname])
615
 
        try:
616
 
            old_remote = self._refs[refname]
617
 
        except KeyError:
618
 
            old_remote = ZERO_SHA
619
 
        push_result.old_revid = repo.lookup_foreign_revision_id(old_remote)
620
 
        self._refs = remote_refs_dict_to_container(new_refs)
 
619
            new_refs[actual_refname])
 
620
        if old_sha is not None:
 
621
            push_result.old_revid = repo.lookup_foreign_revision_id(old_sha)
 
622
        else:
 
623
            push_result.old_revid = NULL_REVISION
 
624
        if self._refs is not None:
 
625
            update_refs_container(self._refs, new_refs)
621
626
        push_result.target_branch = self.open_branch(name)
622
 
        if old_remote != ZERO_SHA:
 
627
        if old_sha is not None:
623
628
            push_result.branch_push_result = GitBranchPushResult()
624
629
            push_result.branch_push_result.source_branch = source
625
630
            push_result.branch_push_result.target_branch = (
1029
1034
    ret = DictRefsContainer(base)
1030
1035
    ret._peeled = peeled
1031
1036
    return ret
 
1037
 
 
1038
 
 
1039
def update_refs_container(container, refs_dict):
 
1040
    peeled = {}
 
1041
    base = {}
 
1042
    for k, v in refs_dict.items():
 
1043
        if is_peeled(k):
 
1044
            peeled[k[:-3]] = v
 
1045
        else:
 
1046
            base[k] = v
 
1047
    container._peeled = peeled
 
1048
    container._refs.update(base)