/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: Jelmer Vernooij
  • Date: 2020-04-05 19:11:34 UTC
  • mto: (7490.7.16 work)
  • mto: This revision was merged to the branch mainline in revision 7501.
  • Revision ID: jelmer@jelmer.uk-20200405191134-0aebh8ikiwygxma5
Populate the .gitignore file.

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