/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: 2019-03-05 07:32:38 UTC
  • mto: (7290.1.21 work)
  • mto: This revision was merged to the branch mainline in revision 7311.
  • Revision ID: jelmer@jelmer.uk-20190305073238-zlqn981opwnqsmzi
Add appveyor configuration.

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
 
from breezy import controldir
26
27
from ..commands import (
27
28
    Command,
28
29
    display_command,
29
30
    )
30
31
from ..option import (
31
32
    Option,
32
 
    RegistryOption,
 
33
    )
 
34
from ..sixish import (
 
35
    text_type,
 
36
    viewitems,
33
37
    )
34
38
 
35
39
 
42
46
 
43
47
    takes_options = [
44
48
        Option('colocated', help='Create colocated branches.'),
45
 
        RegistryOption('dest-format',
46
 
                       help='Specify a format for this branch. '
47
 
                       'See "help formats" for a full list.',
48
 
                       lazy_registry=('breezy.controldir', 'format_registry'),
49
 
                       converter=lambda name: controldir.format_registry.make_controldir(
50
 
                            name),
51
 
                       value_switches=True,
52
 
                       title="Branch format",
53
 
                       ),
54
49
        ]
55
50
 
56
51
    def _get_colocated_branch(self, target_controldir, name):
74
69
        except NotBranchError:
75
70
            return head_controldir.create_branch()
76
71
 
77
 
    def run(self, src_location, dest_location=None, colocated=False, dest_format=None):
 
72
    def run(self, src_location, dest_location=None, colocated=False):
78
73
        import os
79
74
        from .. import (
80
75
            controldir,
87
82
            )
88
83
        from ..errors import (
89
84
            BzrError,
90
 
            CommandError,
 
85
            BzrCommandError,
91
86
            NoRepositoryPresent,
92
87
            NotBranchError,
93
88
            )
105
100
            )
106
101
        from .repository import GitRepository
107
102
 
 
103
        dest_format = controldir.ControlDirFormat.get_default_format()
108
104
        if dest_format is None:
109
 
            dest_format = controldir.format_registry.make_controldir('default')
 
105
            raise BzrError('no default format')
110
106
 
111
107
        if dest_location is None:
112
108
            dest_location = os.path.basename(src_location.rstrip("/\\"))
115
111
 
116
112
        source_repo = Repository.open(src_location)
117
113
        if not isinstance(source_repo, GitRepository):
118
 
            raise CommandError(
 
114
            raise BzrCommandError(
119
115
                gettext("%r is not a git repository") % src_location)
120
116
        try:
121
117
            target_controldir = ControlDir.open_from_transport(dest_transport)
128
124
            target_repo = target_controldir.create_repository(shared=True)
129
125
 
130
126
        if not target_repo.supports_rich_root():
131
 
            raise CommandError(
 
127
            raise BzrCommandError(
132
128
                gettext("Target repository doesn't support rich roots"))
133
129
 
134
130
        interrepo = InterRepository.get(source_repo, target_repo)
135
131
        mapping = source_repo.get_mapping()
136
 
        result = interrepo.fetch()
137
 
        with ui.ui_factory.nested_progress_bar() as pb:
138
 
            for i, (name, sha) in enumerate(result.refs.items()):
 
132
        refs = interrepo.fetch()
 
133
        pb = ui.ui_factory.nested_progress_bar()
 
134
        try:
 
135
            for i, (name, sha) in enumerate(viewitems(refs)):
139
136
                try:
140
137
                    branch_name = ref_to_branch_name(name)
141
138
                except ValueError:
142
139
                    # Not a branch, ignore
143
140
                    continue
144
 
                pb.update(gettext("creating branches"), i, len(result.refs))
 
141
                pb.update(gettext("creating branches"), i, len(refs))
145
142
                if (getattr(target_controldir._format, "colocated_branches",
146
143
                            False) and colocated):
147
144
                    if name == "HEAD":
162
159
                        source_branch.base,
163
160
                        {"branch": urlutils.escape(branch_name)})
164
161
                    head_branch.set_parent(url)
 
162
        finally:
 
163
            pb.finished()
165
164
        trace.note(gettext(
166
165
            "Use 'bzr checkout' to create a working tree in "
167
166
            "the newly created branches."))
180
179
    takes_args = ["sha1?"]
181
180
    takes_options = [Option('directory',
182
181
                            short_name='d',
183
 
                            help='Location of repository.', type=str),
 
182
                            help='Location of repository.', type=text_type),
184
183
                     Option('pretty', help='Pretty-print objects.')]
185
184
    encoding_type = 'exact'
186
185
 
187
186
    @display_command
188
187
    def run(self, sha1=None, directory=".", pretty=False):
189
188
        from ..errors import (
190
 
            CommandError,
 
189
            BzrCommandError,
191
190
            )
192
191
        from ..controldir import (
193
192
            ControlDir,
204
203
                try:
205
204
                    obj = object_store[sha1.encode('ascii')]
206
205
                except KeyError:
207
 
                    raise CommandError(
 
206
                    raise BzrCommandError(
208
207
                        gettext("Object not found: %s") % sha1)
209
208
                if pretty:
210
209
                    text = obj.as_pretty_string()
241
240
        object_store = get_object_store(repo)
242
241
        with object_store.lock_read():
243
242
            refs = get_refs_container(controldir, object_store)
244
 
            for k, v in sorted(refs.as_dict().items()):
 
243
            for k, v in sorted(viewitems(refs.as_dict())):
245
244
                self.outf.write("%s -> %s\n" %
246
245
                                (k.decode('utf-8'), v.decode('utf-8')))
247
246
 
266
265
        :param f: Patch file to read.
267
266
        :param signoff: Add Signed-Off-By flag.
268
267
        """
 
268
        from ..i18n import gettext
 
269
        from ..errors import BzrCommandError
269
270
        from dulwich.patch import git_am_patch_split
270
 
        from breezy.patch import patch_tree
 
271
        import subprocess
271
272
        (c, diff, version) = git_am_patch_split(f)
272
273
        # FIXME: Cope with git-specific bits in patch
273
274
        # FIXME: Add new files to working tree
274
 
        patch_tree(wt, [diff], strip=1, out=self.outf)
 
275
        p = subprocess.Popen(["patch", "-p1"], stdin=subprocess.PIPE,
 
276
                             cwd=wt.basedir)
 
277
        p.communicate(diff)
 
278
        exitcode = p.wait()
 
279
        if exitcode != 0:
 
280
            raise BzrCommandError(gettext("error running patch"))
275
281
        message = c.message.decode('utf-8')
276
282
        if signoff:
277
283
            signed_off_by = wt.branch.get_config().username()
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)