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

  • Committer: Breezy landing bot
  • Author(s): Jelmer Vernooij
  • Date: 2020-07-28 02:47:10 UTC
  • mfrom: (7519.1.1 merge-3.1)
  • Revision ID: breezy.the.bot@gmail.com-20200728024710-a2ylds219f1lsl62
Merge lp:brz/3.1.

Merged from https://code.launchpad.net/~jelmer/brz/merge-3.1/+merge/388173

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
 
22
22
"""Git-specific subcommands for Bazaar."""
23
23
 
24
 
from __future__ import absolute_import
25
 
 
26
24
import breezy.bzr  # noqa: F401
27
25
from breezy import controldir
28
26
from ..commands import (
33
31
    Option,
34
32
    RegistryOption,
35
33
    )
36
 
from ..sixish import (
37
 
    text_type,
38
 
    viewitems,
39
 
    )
40
34
 
41
35
 
42
36
class cmd_git_import(Command):
93
87
            )
94
88
        from ..errors import (
95
89
            BzrError,
96
 
            BzrCommandError,
 
90
            CommandError,
97
91
            NoRepositoryPresent,
98
92
            NotBranchError,
99
93
            )
121
115
 
122
116
        source_repo = Repository.open(src_location)
123
117
        if not isinstance(source_repo, GitRepository):
124
 
            raise BzrCommandError(
 
118
            raise CommandError(
125
119
                gettext("%r is not a git repository") % src_location)
126
120
        try:
127
121
            target_controldir = ControlDir.open_from_transport(dest_transport)
134
128
            target_repo = target_controldir.create_repository(shared=True)
135
129
 
136
130
        if not target_repo.supports_rich_root():
137
 
            raise BzrCommandError(
 
131
            raise CommandError(
138
132
                gettext("Target repository doesn't support rich roots"))
139
133
 
140
134
        interrepo = InterRepository.get(source_repo, target_repo)
141
135
        mapping = source_repo.get_mapping()
142
136
        result = interrepo.fetch()
143
137
        with ui.ui_factory.nested_progress_bar() as pb:
144
 
            for i, (name, sha) in enumerate(viewitems(result.refs)):
 
138
            for i, (name, sha) in enumerate(result.refs.items()):
145
139
                try:
146
140
                    branch_name = ref_to_branch_name(name)
147
141
                except ValueError:
186
180
    takes_args = ["sha1?"]
187
181
    takes_options = [Option('directory',
188
182
                            short_name='d',
189
 
                            help='Location of repository.', type=text_type),
 
183
                            help='Location of repository.', type=str),
190
184
                     Option('pretty', help='Pretty-print objects.')]
191
185
    encoding_type = 'exact'
192
186
 
193
187
    @display_command
194
188
    def run(self, sha1=None, directory=".", pretty=False):
195
189
        from ..errors import (
196
 
            BzrCommandError,
 
190
            CommandError,
197
191
            )
198
192
        from ..controldir import (
199
193
            ControlDir,
210
204
                try:
211
205
                    obj = object_store[sha1.encode('ascii')]
212
206
                except KeyError:
213
 
                    raise BzrCommandError(
 
207
                    raise CommandError(
214
208
                        gettext("Object not found: %s") % sha1)
215
209
                if pretty:
216
210
                    text = obj.as_pretty_string()
247
241
        object_store = get_object_store(repo)
248
242
        with object_store.lock_read():
249
243
            refs = get_refs_container(controldir, object_store)
250
 
            for k, v in sorted(viewitems(refs.as_dict())):
 
244
            for k, v in sorted(refs.as_dict().items()):
251
245
                self.outf.write("%s -> %s\n" %
252
246
                                (k.decode('utf-8'), v.decode('utf-8')))
253
247
 
304
298
 
305
299
    takes_options = [Option('directory',
306
300
                            short_name='d',
307
 
                            help='Location of repository.', type=text_type)]
 
301
                            help='Location of repository.', type=str)]
308
302
    takes_args = ['target', 'package']
309
303
 
310
304
    def run(self, target, package, directory='.'):
311
305
        from ..branch import Branch
312
306
        from ..errors import (
313
 
            BzrCommandError,
 
307
            CommandError,
314
308
            NoSuchRevision,
315
309
            )
316
310
        from ..trace import warning
317
311
        from ..repository import Repository
 
312
        from .mapping import encode_git_path
318
313
        from .object_store import get_object_store
319
314
        from .pristine_tar import (
320
315
            revision_pristine_tar_data,
324
319
        target_bzr = Repository.open(target)
325
320
        target = getattr(target_bzr, '_git', None)
326
321
        if target is None:
327
 
            raise BzrCommandError("Target not a git repository")
 
322
            raise CommandError("Target not a git repository")
328
323
        git_store = get_object_store(source.repository)
329
324
        with git_store.lock_read():
330
325
            tag_dict = source.tags.get_tag_dict()
351
346
                    warning(
352
347
                        "base git id %s for %s missing in target repository",
353
348
                        gitid, filename)
354
 
                store_git_pristine_tar_data(target, filename.encode('utf-8'),
 
349
                store_git_pristine_tar_data(target, encode_git_path(filename),
355
350
                                            delta, gitid)