/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: 2018-11-16 18:59:44 UTC
  • mfrom: (7143.15.15 more-cleanups)
  • Revision ID: breezy.the.bot@gmail.com-20181116185944-biefv1sub37qfybm
Sprinkle some PEP8iness.

Merged from https://code.launchpad.net/~jelmer/brz/more-cleanups/+merge/358611

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
81
81
            ControlDir,
82
82
            )
83
83
        from ..errors import (
 
84
            BzrError,
84
85
            BzrCommandError,
85
86
            NoRepositoryPresent,
86
87
            NotBranchError,
101
102
 
102
103
        dest_format = controldir.ControlDirFormat.get_default_format()
103
104
        if dest_format is None:
104
 
            raise errors.BzrError('no default format')
 
105
            raise BzrError('no default format')
105
106
 
106
107
        if dest_location is None:
107
108
            dest_location = os.path.basename(src_location.rstrip("/\\"))
110
111
 
111
112
        source_repo = Repository.open(src_location)
112
113
        if not isinstance(source_repo, GitRepository):
113
 
            raise BzrCommandError(gettext("%r is not a git repository") % src_location)
 
114
            raise BzrCommandError(
 
115
                gettext("%r is not a git repository") % src_location)
114
116
        try:
115
117
            target_controldir = ControlDir.open_from_transport(dest_transport)
116
118
        except NotBranchError:
122
124
            target_repo = target_controldir.create_repository(shared=True)
123
125
 
124
126
        if not target_repo.supports_rich_root():
125
 
            raise BzrCommandError(gettext("Target repository doesn't support rich roots"))
 
127
            raise BzrCommandError(
 
128
                gettext("Target repository doesn't support rich roots"))
126
129
 
127
130
        interrepo = InterRepository.get(source_repo, target_repo)
128
131
        mapping = source_repo.get_mapping()
136
139
                    # Not a branch, ignore
137
140
                    continue
138
141
                pb.update(gettext("creating branches"), i, len(refs))
139
 
                if getattr(target_controldir._format, "colocated_branches", False) and colocated:
 
142
                if (getattr(target_controldir._format, "colocated_branches",
 
143
                            False) and colocated):
140
144
                    if name == "HEAD":
141
145
                        branch_name = None
142
 
                    head_branch = self._get_colocated_branch(target_controldir, branch_name)
 
146
                    head_branch = self._get_colocated_branch(
 
147
                        target_controldir, branch_name)
143
148
                else:
144
 
                    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)
145
151
                revid = mapping.revision_id_foreign_to_bzr(sha)
146
 
                source_branch = LocalGitBranch(source_repo.controldir, source_repo,
147
 
                    sha)
 
152
                source_branch = LocalGitBranch(
 
153
                    source_repo.controldir, source_repo, sha)
148
154
                if head_branch.last_revision() != revid:
149
155
                    head_branch.generate_revision_history(revid)
150
156
                source_branch.tags.merge_to(head_branch.tags)
151
157
                if not head_branch.get_parent():
152
158
                    url = urlutils.join_segment_parameters(
153
 
                        source_branch.base, {"branch": urlutils.escape(branch_name)})
 
159
                        source_branch.base,
 
160
                        {"branch": urlutils.escape(branch_name)})
154
161
                    head_branch.set_parent(url)
155
162
        finally:
156
163
            pb.finished()
171
178
    aliases = ["git-objects", "git-cat"]
172
179
    takes_args = ["sha1?"]
173
180
    takes_options = [Option('directory',
174
 
        short_name='d',
175
 
        help='Location of repository.', type=text_type),
176
 
        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.')]
177
184
    encoding_type = 'exact'
178
185
 
179
186
    @display_command
196
203
                try:
197
204
                    obj = object_store[str(sha1)]
198
205
                except KeyError:
199
 
                    raise BzrCommandError(gettext("Object not found: %s") % sha1)
 
206
                    raise BzrCommandError(
 
207
                        gettext("Object not found: %s") % sha1)
200
208
                if pretty:
201
209
                    text = obj.as_pretty_string()
202
210
                else:
233
241
        with object_store.lock_read():
234
242
            refs = get_refs_container(controldir, object_store)
235
243
            for k, v in sorted(viewitems(refs.as_dict())):
236
 
                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')))
237
246
 
238
247
 
239
248
class cmd_git_apply(Command):
240
249
    """Apply a series of git-am style patches.
241
250
 
242
 
    This command will in the future probably be integrated into 
243
 
    "bzr pull".
 
251
    This command will in the future probably be integrated into "bzr pull".
244
252
    """
245
253
 
246
254
    takes_options = [
247
255
        Option('signoff', short_name='s', help='Add a Signed-off-by line.'),
248
256
        Option('force',
249
 
            help='Apply patches even if tree has uncommitted changes.')
 
257
               help='Apply patches even if tree has uncommitted changes.')
250
258
        ]
251
259
    takes_args = ["patches*"]
252
260
 
265
273
        # FIXME: Cope with git-specific bits in patch
266
274
        # FIXME: Add new files to working tree
267
275
        p = subprocess.Popen(["patch", "-p1"], stdin=subprocess.PIPE,
268
 
            cwd=wt.basedir)
 
276
                             cwd=wt.basedir)
269
277
        p.communicate(diff)
270
278
        exitcode = p.wait()
271
279
        if exitcode != 0:
295
303
    """Push pristine tar deltas to a git repository."""
296
304
 
297
305
    takes_options = [Option('directory',
298
 
        short_name='d',
299
 
        help='Location of repository.', type=text_type)]
 
306
                            short_name='d',
 
307
                            help='Location of repository.', type=text_type)]
300
308
    takes_args = ['target', 'package']
301
309
 
302
310
    def run(self, target, package, directory='.'):
330
338
                except KeyError:
331
339
                    continue
332
340
                gitid = git_store._lookup_revision_sha1(revid)
333
 
                if not (name.startswith('upstream/') or name.startswith('upstream-')):
334
 
                    warning("Unexpected pristine tar revision tagged %s. Ignoring.",
335
 
                         name)
 
341
                if (not (name.startswith('upstream/') or
 
342
                         name.startswith('upstream-'))):
 
343
                    warning(
 
344
                        "Unexpected pristine tar revision tagged %s. "
 
345
                        "Ignoring.", name)
336
346
                    continue
337
347
                upstream_version = name[len("upstream/"):]
338
 
                filename = '%s_%s.orig.tar.%s' % (package, upstream_version, kind)
339
 
                if not gitid in target:
340
 
                    warning("base git id %s for %s missing in target repository",
341
 
                            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)
342
354
                store_git_pristine_tar_data(target, filename.encode('utf-8'),
343
 
                    delta, gitid)
 
355
                                            delta, gitid)