/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-06-02 02:35:46 UTC
  • mfrom: (7309 work)
  • mto: This revision was merged to the branch mainline in revision 7319.
  • Revision ID: jelmer@jelmer.uk-20190602023546-lqco868tnv26d8ow
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()
136
138
                    # Not a branch, ignore
137
139
                    continue
138
140
                pb.update(gettext("creating branches"), i, len(refs))
139
 
                if getattr(target_controldir._format, "colocated_branches", False) and colocated:
 
141
                if (getattr(target_controldir._format, "colocated_branches",
 
142
                            False) and colocated):
140
143
                    if name == "HEAD":
141
144
                        branch_name = None
142
 
                    head_branch = self._get_colocated_branch(target_controldir, branch_name)
 
145
                    head_branch = self._get_colocated_branch(
 
146
                        target_controldir, branch_name)
143
147
                else:
144
 
                    head_branch = self._get_nested_branch(dest_transport, dest_format, branch_name)
 
148
                    head_branch = self._get_nested_branch(
 
149
                        dest_transport, dest_format, branch_name)
145
150
                revid = mapping.revision_id_foreign_to_bzr(sha)
146
 
                source_branch = LocalGitBranch(source_repo.controldir, source_repo,
147
 
                    sha)
 
151
                source_branch = LocalGitBranch(
 
152
                    source_repo.controldir, source_repo, sha)
148
153
                if head_branch.last_revision() != revid:
149
154
                    head_branch.generate_revision_history(revid)
150
155
                source_branch.tags.merge_to(head_branch.tags)
151
156
                if not head_branch.get_parent():
152
157
                    url = urlutils.join_segment_parameters(
153
 
                        source_branch.base, {"branch": urlutils.escape(branch_name)})
 
158
                        source_branch.base,
 
159
                        {"branch": urlutils.escape(branch_name)})
154
160
                    head_branch.set_parent(url)
155
161
        trace.note(gettext(
156
162
            "Use 'bzr checkout' to create a working tree in "
169
175
    aliases = ["git-objects", "git-cat"]
170
176
    takes_args = ["sha1?"]
171
177
    takes_options = [Option('directory',
172
 
        short_name='d',
173
 
        help='Location of repository.', type=text_type),
174
 
        Option('pretty', help='Pretty-print objects.')]
 
178
                            short_name='d',
 
179
                            help='Location of repository.', type=text_type),
 
180
                     Option('pretty', help='Pretty-print objects.')]
175
181
    encoding_type = 'exact'
176
182
 
177
183
    @display_command
185
191
        from .object_store import (
186
192
            get_object_store,
187
193
            )
188
 
        from . import gettext
 
194
        from ..i18n import gettext
189
195
        controldir, _ = ControlDir.open_containing(directory)
190
196
        repo = controldir.find_repository()
191
197
        object_store = get_object_store(repo)
192
198
        with object_store.lock_read():
193
199
            if sha1 is not None:
194
200
                try:
195
 
                    obj = object_store[str(sha1)]
 
201
                    obj = object_store[sha1.encode('ascii')]
196
202
                except KeyError:
197
 
                    raise BzrCommandError(gettext("Object not found: %s") % sha1)
 
203
                    raise BzrCommandError(
 
204
                        gettext("Object not found: %s") % sha1)
198
205
                if pretty:
199
206
                    text = obj.as_pretty_string()
200
207
                else:
202
209
                self.outf.write(text)
203
210
            else:
204
211
                for sha1 in object_store:
205
 
                    self.outf.write("%s\n" % sha1)
 
212
                    self.outf.write("%s\n" % sha1.decode('ascii'))
206
213
 
207
214
 
208
215
class cmd_git_refs(Command):
231
238
        with object_store.lock_read():
232
239
            refs = get_refs_container(controldir, object_store)
233
240
            for k, v in sorted(viewitems(refs.as_dict())):
234
 
                self.outf.write("%s -> %s\n" % (k.decode('utf-8'), v.decode('utf-8')))
 
241
                self.outf.write("%s -> %s\n" %
 
242
                                (k.decode('utf-8'), v.decode('utf-8')))
235
243
 
236
244
 
237
245
class cmd_git_apply(Command):
238
246
    """Apply a series of git-am style patches.
239
247
 
240
 
    This command will in the future probably be integrated into 
241
 
    "bzr pull".
 
248
    This command will in the future probably be integrated into "bzr pull".
242
249
    """
243
250
 
244
251
    takes_options = [
245
252
        Option('signoff', short_name='s', help='Add a Signed-off-by line.'),
246
253
        Option('force',
247
 
            help='Apply patches even if tree has uncommitted changes.')
 
254
               help='Apply patches even if tree has uncommitted changes.')
248
255
        ]
249
256
    takes_args = ["patches*"]
250
257
 
255
262
        :param f: Patch file to read.
256
263
        :param signoff: Add Signed-Off-By flag.
257
264
        """
258
 
        from . import gettext
 
265
        from ..i18n import gettext
259
266
        from ..errors import BzrCommandError
260
267
        from dulwich.patch import git_am_patch_split
261
268
        import subprocess
263
270
        # FIXME: Cope with git-specific bits in patch
264
271
        # FIXME: Add new files to working tree
265
272
        p = subprocess.Popen(["patch", "-p1"], stdin=subprocess.PIPE,
266
 
            cwd=wt.basedir)
 
273
                             cwd=wt.basedir)
267
274
        p.communicate(diff)
268
275
        exitcode = p.wait()
269
276
        if exitcode != 0:
270
277
            raise BzrCommandError(gettext("error running patch"))
271
 
        message = c.message
 
278
        message = c.message.decode('utf-8')
272
279
        if signoff:
273
280
            signed_off_by = wt.branch.get_config().username()
274
 
            message += "Signed-off-by: %s\n" % signed_off_by.encode('utf-8')
275
 
        wt.commit(authors=[c.author], message=message)
 
281
            message += "Signed-off-by: %s\n" % (signed_off_by, )
 
282
        wt.commit(authors=[c.author.decode('utf-8')], message=message)
276
283
 
277
284
    def run(self, patches_list=None, signoff=False, force=False):
278
285
        from ..errors import UncommittedChanges
293
300
    """Push pristine tar deltas to a git repository."""
294
301
 
295
302
    takes_options = [Option('directory',
296
 
        short_name='d',
297
 
        help='Location of repository.', type=text_type)]
 
303
                            short_name='d',
 
304
                            help='Location of repository.', type=text_type)]
298
305
    takes_args = ['target', 'package']
299
306
 
300
307
    def run(self, target, package, directory='.'):
328
335
                except KeyError:
329
336
                    continue
330
337
                gitid = git_store._lookup_revision_sha1(revid)
331
 
                if not (name.startswith('upstream/') or name.startswith('upstream-')):
332
 
                    warning("Unexpected pristine tar revision tagged %s. Ignoring.",
333
 
                         name)
 
338
                if (not (name.startswith('upstream/') or
 
339
                         name.startswith('upstream-'))):
 
340
                    warning(
 
341
                        "Unexpected pristine tar revision tagged %s. "
 
342
                        "Ignoring.", name)
334
343
                    continue
335
344
                upstream_version = name[len("upstream/"):]
336
 
                filename = '%s_%s.orig.tar.%s' % (package, upstream_version, kind)
337
 
                if not gitid in target:
338
 
                    warning("base git id %s for %s missing in target repository",
339
 
                            gitid, filename)
 
345
                filename = '%s_%s.orig.tar.%s' % (
 
346
                    package, upstream_version, kind)
 
347
                if gitid not in target:
 
348
                    warning(
 
349
                        "base git id %s for %s missing in target repository",
 
350
                        gitid, filename)
340
351
                store_git_pristine_tar_data(target, filename.encode('utf-8'),
341
 
                    delta, gitid)
 
352
                                            delta, gitid)