/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-04 00:16:27 UTC
  • mfrom: (7293 work)
  • mto: This revision was merged to the branch mainline in revision 7318.
  • Revision ID: jelmer@jelmer.uk-20190304001627-v6u7o6pf97tukhek
Merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
 
24
24
from __future__ import absolute_import
25
25
 
26
 
import breezy.bzr.bzrdir
 
26
import breezy.bzr  # noqa: F401
27
27
from ..commands import (
28
28
    Command,
29
29
    display_command,
45
45
    takes_args = ["src_location", "dest_location?"]
46
46
 
47
47
    takes_options = [
48
 
                     Option('colocated', help='Create colocated branches.'),
49
 
                     ]
 
48
        Option('colocated', help='Create colocated branches.'),
 
49
        ]
50
50
 
51
51
    def _get_colocated_branch(self, target_controldir, name):
52
52
        from ..errors import NotBranchError
71
71
 
72
72
    def run(self, src_location, dest_location=None, colocated=False):
73
73
        import os
74
 
        import urllib
75
74
        from .. import (
76
75
            controldir,
77
76
            trace,
82
81
            ControlDir,
83
82
            )
84
83
        from ..errors import (
 
84
            BzrError,
85
85
            BzrCommandError,
86
86
            NoRepositoryPresent,
87
87
            NotBranchError,
88
88
            )
89
 
        from . import gettext
 
89
        from ..i18n import gettext
90
90
        from ..repository import (
91
91
            InterRepository,
92
92
            Repository,
102
102
 
103
103
        dest_format = controldir.ControlDirFormat.get_default_format()
104
104
        if dest_format is None:
105
 
            raise errors.BzrError('no default format')
 
105
            raise BzrError('no default format')
106
106
 
107
107
        if dest_location is None:
108
108
            dest_location = os.path.basename(src_location.rstrip("/\\"))
111
111
 
112
112
        source_repo = Repository.open(src_location)
113
113
        if not isinstance(source_repo, GitRepository):
114
 
            raise BzrCommandError(gettext("%r is not a git repository") % src_location)
 
114
            raise BzrCommandError(
 
115
                gettext("%r is not a git repository") % src_location)
115
116
        try:
116
117
            target_controldir = ControlDir.open_from_transport(dest_transport)
117
118
        except NotBranchError:
123
124
            target_repo = target_controldir.create_repository(shared=True)
124
125
 
125
126
        if not target_repo.supports_rich_root():
126
 
            raise BzrCommandError(gettext("Target repository doesn't support rich roots"))
 
127
            raise BzrCommandError(
 
128
                gettext("Target repository doesn't support rich roots"))
127
129
 
128
130
        interrepo = InterRepository.get(source_repo, target_repo)
129
131
        mapping = source_repo.get_mapping()
137
139
                    # Not a branch, ignore
138
140
                    continue
139
141
                pb.update(gettext("creating branches"), i, len(refs))
140
 
                if getattr(target_controldir._format, "colocated_branches", False) and colocated:
 
142
                if (getattr(target_controldir._format, "colocated_branches",
 
143
                            False) and colocated):
141
144
                    if name == "HEAD":
142
145
                        branch_name = None
143
 
                    head_branch = self._get_colocated_branch(target_controldir, branch_name)
 
146
                    head_branch = self._get_colocated_branch(
 
147
                        target_controldir, branch_name)
144
148
                else:
145
 
                    head_branch = self._get_nested_branch(dest_transport, dest_format, branch_name)
 
149
                    head_branch = self._get_nested_branch(
 
150
                        dest_transport, dest_format, branch_name)
146
151
                revid = mapping.revision_id_foreign_to_bzr(sha)
147
 
                source_branch = LocalGitBranch(source_repo.controldir, source_repo,
148
 
                    sha)
 
152
                source_branch = LocalGitBranch(
 
153
                    source_repo.controldir, source_repo, sha)
149
154
                if head_branch.last_revision() != revid:
150
155
                    head_branch.generate_revision_history(revid)
151
156
                source_branch.tags.merge_to(head_branch.tags)
152
157
                if not head_branch.get_parent():
153
158
                    url = urlutils.join_segment_parameters(
154
 
                        source_branch.base, {"branch": urlutils.escape(branch_name)})
 
159
                        source_branch.base,
 
160
                        {"branch": urlutils.escape(branch_name)})
155
161
                    head_branch.set_parent(url)
156
162
        finally:
157
163
            pb.finished()
172
178
    aliases = ["git-objects", "git-cat"]
173
179
    takes_args = ["sha1?"]
174
180
    takes_options = [Option('directory',
175
 
        short_name='d',
176
 
        help='Location of repository.', type=text_type),
177
 
        Option('pretty', help='Pretty-print objects.')]
 
181
                            short_name='d',
 
182
                            help='Location of repository.', type=text_type),
 
183
                     Option('pretty', help='Pretty-print objects.')]
178
184
    encoding_type = 'exact'
179
185
 
180
186
    @display_command
188
194
        from .object_store import (
189
195
            get_object_store,
190
196
            )
191
 
        from . import gettext
 
197
        from ..i18n import gettext
192
198
        controldir, _ = ControlDir.open_containing(directory)
193
199
        repo = controldir.find_repository()
194
200
        object_store = get_object_store(repo)
195
201
        with object_store.lock_read():
196
202
            if sha1 is not None:
197
203
                try:
198
 
                    obj = object_store[str(sha1)]
 
204
                    obj = object_store[sha1.encode('ascii')]
199
205
                except KeyError:
200
 
                    raise BzrCommandError(gettext("Object not found: %s") % sha1)
 
206
                    raise BzrCommandError(
 
207
                        gettext("Object not found: %s") % sha1)
201
208
                if pretty:
202
209
                    text = obj.as_pretty_string()
203
210
                else:
205
212
                self.outf.write(text)
206
213
            else:
207
214
                for sha1 in object_store:
208
 
                    self.outf.write("%s\n" % sha1)
 
215
                    self.outf.write("%s\n" % sha1.decode('ascii'))
209
216
 
210
217
 
211
218
class cmd_git_refs(Command):
234
241
        with object_store.lock_read():
235
242
            refs = get_refs_container(controldir, object_store)
236
243
            for k, v in sorted(viewitems(refs.as_dict())):
237
 
                self.outf.write("%s -> %s\n" % (k.decode('utf-8'), v.decode('utf-8')))
 
244
                self.outf.write("%s -> %s\n" %
 
245
                                (k.decode('utf-8'), v.decode('utf-8')))
238
246
 
239
247
 
240
248
class cmd_git_apply(Command):
241
249
    """Apply a series of git-am style patches.
242
250
 
243
 
    This command will in the future probably be integrated into 
244
 
    "bzr pull".
 
251
    This command will in the future probably be integrated into "bzr pull".
245
252
    """
246
253
 
247
254
    takes_options = [
248
255
        Option('signoff', short_name='s', help='Add a Signed-off-by line.'),
249
256
        Option('force',
250
 
            help='Apply patches even if tree has uncommitted changes.')
 
257
               help='Apply patches even if tree has uncommitted changes.')
251
258
        ]
252
259
    takes_args = ["patches*"]
253
260
 
258
265
        :param f: Patch file to read.
259
266
        :param signoff: Add Signed-Off-By flag.
260
267
        """
261
 
        from . import gettext
 
268
        from ..i18n import gettext
262
269
        from ..errors import BzrCommandError
263
270
        from dulwich.patch import git_am_patch_split
264
271
        import subprocess
266
273
        # FIXME: Cope with git-specific bits in patch
267
274
        # FIXME: Add new files to working tree
268
275
        p = subprocess.Popen(["patch", "-p1"], stdin=subprocess.PIPE,
269
 
            cwd=wt.basedir)
 
276
                             cwd=wt.basedir)
270
277
        p.communicate(diff)
271
278
        exitcode = p.wait()
272
279
        if exitcode != 0:
273
280
            raise BzrCommandError(gettext("error running patch"))
274
 
        message = c.message
 
281
        message = c.message.decode('utf-8')
275
282
        if signoff:
276
283
            signed_off_by = wt.branch.get_config().username()
277
 
            message += "Signed-off-by: %s\n" % signed_off_by.encode('utf-8')
278
 
        wt.commit(authors=[c.author], message=message)
 
284
            message += "Signed-off-by: %s\n" % (signed_off_by, )
 
285
        wt.commit(authors=[c.author.decode('utf-8')], message=message)
279
286
 
280
287
    def run(self, patches_list=None, signoff=False, force=False):
281
288
        from ..errors import UncommittedChanges
296
303
    """Push pristine tar deltas to a git repository."""
297
304
 
298
305
    takes_options = [Option('directory',
299
 
        short_name='d',
300
 
        help='Location of repository.', type=text_type)]
 
306
                            short_name='d',
 
307
                            help='Location of repository.', type=text_type)]
301
308
    takes_args = ['target', 'package']
302
309
 
303
310
    def run(self, target, package, directory='.'):
331
338
                except KeyError:
332
339
                    continue
333
340
                gitid = git_store._lookup_revision_sha1(revid)
334
 
                if not (name.startswith('upstream/') or name.startswith('upstream-')):
335
 
                    warning("Unexpected pristine tar revision tagged %s. Ignoring.",
336
 
                         name)
 
341
                if (not (name.startswith('upstream/') or
 
342
                         name.startswith('upstream-'))):
 
343
                    warning(
 
344
                        "Unexpected pristine tar revision tagged %s. "
 
345
                        "Ignoring.", name)
337
346
                    continue
338
347
                upstream_version = name[len("upstream/"):]
339
 
                filename = '%s_%s.orig.tar.%s' % (package, upstream_version, kind)
340
 
                if not gitid in target:
341
 
                    warning("base git id %s for %s missing in target repository",
342
 
                            gitid, filename)
 
348
                filename = '%s_%s.orig.tar.%s' % (
 
349
                    package, upstream_version, kind)
 
350
                if gitid not in target:
 
351
                    warning(
 
352
                        "base git id %s for %s missing in target repository",
 
353
                        gitid, filename)
343
354
                store_git_pristine_tar_data(target, filename.encode('utf-8'),
344
 
                    delta, gitid)
 
355
                                            delta, gitid)