/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/branch.py

  • Committer: Jelmer Vernooij
  • Date: 2020-03-22 20:02:36 UTC
  • mto: (7490.7.7 work)
  • mto: This revision was merged to the branch mainline in revision 7501.
  • Revision ID: jelmer@jelmer.uk-20200322200236-fsbl91ktcn6fcbdd
Fix tests.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 
18
18
"""An adapter between a Git Branch and a Bazaar Branch"""
19
19
 
 
20
from __future__ import absolute_import
20
21
 
21
 
import contextlib
22
22
from io import BytesIO
23
23
from collections import defaultdict
24
24
 
35
35
 
36
36
from .. import (
37
37
    branch,
 
38
    cleanup,
38
39
    config,
39
40
    controldir,
40
41
    errors,
49
50
from ..revision import (
50
51
    NULL_REVISION,
51
52
    )
 
53
from ..sixish import (
 
54
    text_type,
 
55
    viewitems,
 
56
    )
52
57
from ..tag import (
53
58
    Tags,
54
59
    InterTags,
59
64
    warning,
60
65
    )
61
66
 
 
67
from .config import (
 
68
    GitBranchConfig,
 
69
    GitBranchStack,
 
70
    )
62
71
from .errors import (
63
72
    NoPushSupport,
64
73
    )
65
 
from .mapping import (
66
 
    encode_git_path,
67
 
    decode_git_path,
68
 
    )
69
74
from .push import (
70
75
    remote_divergence,
71
76
    )
132
137
        updates = {}
133
138
        conflicts = []
134
139
        source_tag_refs = self.source.branch.get_tag_refs()
135
 
        ref_to_tag_map = {}
136
140
 
137
141
        def get_changed_refs(old_refs):
138
142
            ret = dict(old_refs)
146
150
                    ret[ref_name] = unpeeled
147
151
                    updates[tag_name] = self.target.branch.repository.lookup_foreign_revision_id(
148
152
                        peeled)
149
 
                    ref_to_tag_map[ref_name] = tag_name
150
153
                    self.target.branch._tag_refs = None
151
154
                else:
152
155
                    conflicts.append(
155
158
                         self.target.branch.repository.lookup_foreign_revision_id(
156
159
                             old_refs[ref_name])))
157
160
            return ret
158
 
        result = self.target.branch.repository.controldir.send_pack(
 
161
        self.target.branch.repository.controldir.send_pack(
159
162
            get_changed_refs, lambda have, want: [])
160
 
        if result is not None and not isinstance(result, dict):
161
 
            for ref, error in result.ref_status.items():
162
 
                if error:
163
 
                    warning('unable to update ref %s: %s',
164
 
                            ref, error)
165
 
                    del updates[ref_to_tag_map[ref]]
166
163
        return updates, set(conflicts)
167
164
 
168
165
 
242
239
            master = None
243
240
        else:
244
241
            master = self.target.branch.get_master_branch()
245
 
        with contextlib.ExitStack() as es:
 
242
        with cleanup.ExitStack() as es:
246
243
            if master is not None:
247
244
                es.enter_context(master.lock_write())
248
245
            updates, conflicts = self._merge_to(
330
327
 
331
328
    def _set_tag_dict(self, to_dict):
332
329
        extra = set(self.refs.allkeys())
333
 
        for k, revid in to_dict.items():
 
330
        for k, revid in viewitems(to_dict):
334
331
            name = tag_name_to_ref(k)
335
332
            if name in extra:
336
333
                extra.remove(name)
482
479
        return "git"
483
480
 
484
481
    def get_config(self):
485
 
        from .config import GitBranchConfig
486
482
        return GitBranchConfig(self)
487
483
 
488
484
    def get_config_stack(self):
489
 
        from .config import GitBranchStack
490
485
        return GitBranchStack(self)
491
486
 
492
487
    def _get_nick(self, local=False, possible_master_transports=None):
498
493
            cs = self.repository._git.get_config_stack()
499
494
            try:
500
495
                return cs.get((b"branch", self.name.encode('utf-8')),
501
 
                        b"nick").decode("utf-8")
 
496
                              b"nick").decode("utf-8")
502
497
            except KeyError:
503
498
                pass
504
499
        return self.name or u"HEAD"
854
849
        :return: iterator over (ref_name, tag_name, peeled_sha1, unpeeled_sha1)
855
850
        """
856
851
        refs = self.repository.controldir.get_refs_container()
857
 
        for ref_name, unpeeled in refs.as_dict().items():
 
852
        for ref_name, unpeeled in viewitems(refs.as_dict()):
858
853
            try:
859
854
                tag_name = ref_to_tag_name(ref_name)
860
855
            except (ValueError, UnicodeDecodeError):
862
857
            peeled = refs.get_peeled(ref_name)
863
858
            if peeled is None:
864
859
                peeled = unpeeled
865
 
            if not isinstance(tag_name, str):
 
860
            if not isinstance(tag_name, text_type):
866
861
                raise TypeError(tag_name)
867
862
            yield (ref_name, tag_name, peeled, unpeeled)
868
863
 
1043
1038
                for path, url, section in parse_submodules(
1044
1039
                        GitConfigFile.from_file(f)):
1045
1040
                    self.target.set_reference_info(
1046
 
                        tree.path2id(decode_git_path(path)), url.decode('utf-8'),
1047
 
                        decode_git_path(path))
 
1041
                        tree.path2id(path.decode('utf-8')), url.decode('utf-8'),
 
1042
                        path.decode('utf-8'))
1048
1043
        except errors.NoSuchFile:
1049
1044
            pass
1050
1045
 
1106
1101
        if local and not bound_location:
1107
1102
            raise errors.LocalRequiresBoundBranch()
1108
1103
        source_is_master = False
1109
 
        with contextlib.ExitStack() as es:
 
1104
        with cleanup.ExitStack() as es:
1110
1105
            es.enter_context(self.source.lock_read())
1111
1106
            if bound_location:
1112
1107
                # bound_location comes from a config file, some care has to be
1175
1170
                isinstance(target, RemoteGitBranch))
1176
1171
 
1177
1172
    def _basic_push(self, overwrite, stop_revision, tag_selector=None):
1178
 
        from .remote import parse_git_error
1179
1173
        result = GitBranchPushResult()
1180
1174
        result.source_branch = self.source
1181
1175
        result.target_branch = self.target
1198
1192
                    raise errors.DivergedBranches(self.source, self.target)
1199
1193
            refs = {self.target.ref: new_ref}
1200
1194
            result.new_revid = stop_revision
1201
 
            for name, sha in (
1202
 
                    self.source.repository._git.refs.as_dict(b"refs/tags").items()):
 
1195
            for name, sha in viewitems(
 
1196
                    self.source.repository._git.refs.as_dict(b"refs/tags")):
1203
1197
                if tag_selector and not tag_selector(name):
1204
1198
                    continue
1205
1199
                if sha not in self.source.repository._git:
1207
1201
                    continue
1208
1202
                refs[tag_name_to_ref(name)] = sha
1209
1203
            return refs
1210
 
        dw_result = self.target.repository.send_pack(
 
1204
        self.target.repository.send_pack(
1211
1205
            get_changed_refs,
1212
 
            self.source.repository._git.generate_pack_data)
1213
 
        if dw_result is not None and not isinstance(dw_result, dict):
1214
 
            error = dw_result.ref_status.get(self.target.ref)
1215
 
            if error:
1216
 
                raise parse_git_error(self.target.user_url, error)
1217
 
            for ref, error in dw_result.ref_status.items():
1218
 
                if error:
1219
 
                    trace.warning('unable to open ref %s: %s', ref, error)
 
1206
            self.source.repository._git.object_store.generate_pack_data)
1220
1207
        return result
1221
1208
 
1222
1209
 
1371
1358
        if fetch_tags is None:
1372
1359
            c = self.source.get_config_stack()
1373
1360
            fetch_tags = c.get('branch.fetch_tags')
1374
 
        for name, revid in self.source.tags.get_tag_dict().items():
 
1361
        for name, revid in viewitems(self.source.tags.get_tag_dict()):
1375
1362
            if self.source.repository.has_revision(revid):
1376
1363
                ref = tag_name_to_ref(name)
1377
1364
                if not check_ref_format(ref):
1388
1375
               old_refs, new_refs)
1389
1376
        result.tag_updates = {}
1390
1377
        result.tag_conflicts = []
1391
 
        ret = {}
 
1378
        ret = dict(old_refs)
1392
1379
 
1393
1380
        def ref_equals(refs, ref, git_sha, revid):
1394
1381
            try:
1408
1395
            # updated that hasn't actually been updated.
1409
1396
            return False
1410
1397
        # FIXME: Check for diverged branches
1411
 
        for ref, (git_sha, revid) in new_refs.items():
 
1398
        for ref, (git_sha, revid) in viewitems(new_refs):
1412
1399
            if ref_equals(ret, ref, git_sha, revid):
1413
1400
                # Already up to date
1414
1401
                if git_sha is None:
1447
1434
            stop_revision = self.source.last_revision()
1448
1435
        ret = []
1449
1436
        if fetch_tags:
1450
 
            for k, v in self.source.tags.get_tag_dict().items():
 
1437
            for k, v in viewitems(self.source.tags.get_tag_dict()):
1451
1438
                ret.append((None, v))
1452
1439
        ret.append((None, stop_revision))
1453
1440
        try: