/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: Gustav Hartvigsson
  • Date: 2021-01-09 21:36:27 UTC
  • Revision ID: gustav.hartvigsson@gmail.com-20210109213627-h1xwcutzy9m7a99b
Added 'Case Preserving Working Tree Use Cases' from Canonical Wiki

* Addod a page from the Canonical Bazaar wiki
  with information on the scmeatics of case
  perserving filesystems an a case insensitive
  filesystem works.
  
  * Needs re-work, but this will do as it is the
    same inforamoton as what was on the linked
    page in the currint documentation.

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
 
 
26
24
import breezy.bzr  # noqa: F401
 
25
from breezy import controldir
27
26
from ..commands import (
28
27
    Command,
29
28
    display_command,
30
29
    )
31
30
from ..option import (
32
31
    Option,
33
 
    )
34
 
from ..sixish import (
35
 
    text_type,
36
 
    viewitems,
 
32
    RegistryOption,
37
33
    )
38
34
 
39
35
 
46
42
 
47
43
    takes_options = [
48
44
        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
                       ),
49
54
        ]
50
55
 
51
56
    def _get_colocated_branch(self, target_controldir, name):
69
74
        except NotBranchError:
70
75
            return head_controldir.create_branch()
71
76
 
72
 
    def run(self, src_location, dest_location=None, colocated=False):
 
77
    def run(self, src_location, dest_location=None, colocated=False, dest_format=None):
73
78
        import os
74
79
        from .. import (
75
80
            controldir,
82
87
            )
83
88
        from ..errors import (
84
89
            BzrError,
85
 
            BzrCommandError,
 
90
            CommandError,
86
91
            NoRepositoryPresent,
87
92
            NotBranchError,
88
93
            )
100
105
            )
101
106
        from .repository import GitRepository
102
107
 
103
 
        dest_format = controldir.ControlDirFormat.get_default_format()
104
108
        if dest_format is None:
105
 
            raise BzrError('no default format')
 
109
            dest_format = controldir.format_registry.make_controldir('default')
106
110
 
107
111
        if dest_location is None:
108
112
            dest_location = os.path.basename(src_location.rstrip("/\\"))
111
115
 
112
116
        source_repo = Repository.open(src_location)
113
117
        if not isinstance(source_repo, GitRepository):
114
 
            raise BzrCommandError(
 
118
            raise CommandError(
115
119
                gettext("%r is not a git repository") % src_location)
116
120
        try:
117
121
            target_controldir = ControlDir.open_from_transport(dest_transport)
124
128
            target_repo = target_controldir.create_repository(shared=True)
125
129
 
126
130
        if not target_repo.supports_rich_root():
127
 
            raise BzrCommandError(
 
131
            raise CommandError(
128
132
                gettext("Target repository doesn't support rich roots"))
129
133
 
130
134
        interrepo = InterRepository.get(source_repo, target_repo)
131
135
        mapping = source_repo.get_mapping()
132
 
        refs = interrepo.fetch()
133
 
        pb = ui.ui_factory.nested_progress_bar()
134
 
        try:
135
 
            for i, (name, sha) in enumerate(viewitems(refs)):
 
136
        result = interrepo.fetch()
 
137
        with ui.ui_factory.nested_progress_bar() as pb:
 
138
            for i, (name, sha) in enumerate(result.refs.items()):
136
139
                try:
137
140
                    branch_name = ref_to_branch_name(name)
138
141
                except ValueError:
139
142
                    # Not a branch, ignore
140
143
                    continue
141
 
                pb.update(gettext("creating branches"), i, len(refs))
 
144
                pb.update(gettext("creating branches"), i, len(result.refs))
142
145
                if (getattr(target_controldir._format, "colocated_branches",
143
146
                            False) and colocated):
144
147
                    if name == "HEAD":
159
162
                        source_branch.base,
160
163
                        {"branch": urlutils.escape(branch_name)})
161
164
                    head_branch.set_parent(url)
162
 
        finally:
163
 
            pb.finished()
164
165
        trace.note(gettext(
165
166
            "Use 'bzr checkout' to create a working tree in "
166
167
            "the newly created branches."))
179
180
    takes_args = ["sha1?"]
180
181
    takes_options = [Option('directory',
181
182
                            short_name='d',
182
 
                            help='Location of repository.', type=text_type),
 
183
                            help='Location of repository.', type=str),
183
184
                     Option('pretty', help='Pretty-print objects.')]
184
185
    encoding_type = 'exact'
185
186
 
186
187
    @display_command
187
188
    def run(self, sha1=None, directory=".", pretty=False):
188
189
        from ..errors import (
189
 
            BzrCommandError,
 
190
            CommandError,
190
191
            )
191
192
        from ..controldir import (
192
193
            ControlDir,
194
195
        from .object_store import (
195
196
            get_object_store,
196
197
            )
197
 
        from . import gettext
 
198
        from ..i18n import gettext
198
199
        controldir, _ = ControlDir.open_containing(directory)
199
200
        repo = controldir.find_repository()
200
201
        object_store = get_object_store(repo)
201
202
        with object_store.lock_read():
202
203
            if sha1 is not None:
203
204
                try:
204
 
                    obj = object_store[str(sha1)]
 
205
                    obj = object_store[sha1.encode('ascii')]
205
206
                except KeyError:
206
 
                    raise BzrCommandError(
 
207
                    raise CommandError(
207
208
                        gettext("Object not found: %s") % sha1)
208
209
                if pretty:
209
210
                    text = obj.as_pretty_string()
212
213
                self.outf.write(text)
213
214
            else:
214
215
                for sha1 in object_store:
215
 
                    self.outf.write("%s\n" % sha1)
 
216
                    self.outf.write("%s\n" % sha1.decode('ascii'))
216
217
 
217
218
 
218
219
class cmd_git_refs(Command):
240
241
        object_store = get_object_store(repo)
241
242
        with object_store.lock_read():
242
243
            refs = get_refs_container(controldir, object_store)
243
 
            for k, v in sorted(viewitems(refs.as_dict())):
 
244
            for k, v in sorted(refs.as_dict().items()):
244
245
                self.outf.write("%s -> %s\n" %
245
246
                                (k.decode('utf-8'), v.decode('utf-8')))
246
247
 
265
266
        :param f: Patch file to read.
266
267
        :param signoff: Add Signed-Off-By flag.
267
268
        """
268
 
        from . import gettext
269
 
        from ..errors import BzrCommandError
270
269
        from dulwich.patch import git_am_patch_split
271
 
        import subprocess
 
270
        from breezy.patch import patch_tree
272
271
        (c, diff, version) = git_am_patch_split(f)
273
272
        # FIXME: Cope with git-specific bits in patch
274
273
        # FIXME: Add new files to working tree
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"))
281
 
        message = c.message
 
274
        patch_tree(wt, [diff], strip=1, out=self.outf)
 
275
        message = c.message.decode('utf-8')
282
276
        if signoff:
283
277
            signed_off_by = wt.branch.get_config().username()
284
 
            message += "Signed-off-by: %s\n" % signed_off_by.encode('utf-8')
285
 
        wt.commit(authors=[c.author], message=message)
 
278
            message += "Signed-off-by: %s\n" % (signed_off_by, )
 
279
        wt.commit(authors=[c.author.decode('utf-8')], message=message)
286
280
 
287
281
    def run(self, patches_list=None, signoff=False, force=False):
288
282
        from ..errors import UncommittedChanges
304
298
 
305
299
    takes_options = [Option('directory',
306
300
                            short_name='d',
307
 
                            help='Location of repository.', type=text_type)]
 
301
                            help='Location of repository.', type=str)]
308
302
    takes_args = ['target', 'package']
309
303
 
310
304
    def run(self, target, package, directory='.'):
311
305
        from ..branch import Branch
312
306
        from ..errors import (
313
 
            BzrCommandError,
 
307
            CommandError,
314
308
            NoSuchRevision,
315
309
            )
316
310
        from ..trace import warning
317
311
        from ..repository import Repository
 
312
        from .mapping import encode_git_path
318
313
        from .object_store import get_object_store
319
314
        from .pristine_tar import (
320
315
            revision_pristine_tar_data,
324
319
        target_bzr = Repository.open(target)
325
320
        target = getattr(target_bzr, '_git', None)
326
321
        if target is None:
327
 
            raise BzrCommandError("Target not a git repository")
 
322
            raise CommandError("Target not a git repository")
328
323
        git_store = get_object_store(source.repository)
329
324
        with git_store.lock_read():
330
325
            tag_dict = source.tags.get_tag_dict()
351
346
                    warning(
352
347
                        "base git id %s for %s missing in target repository",
353
348
                        gitid, filename)
354
 
                store_git_pristine_tar_data(target, filename.encode('utf-8'),
 
349
                store_git_pristine_tar_data(target, encode_git_path(filename),
355
350
                                            delta, gitid)