/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/builtins.py

  • Committer: Jelmer Vernooij
  • Date: 2019-06-03 23:48:08 UTC
  • mfrom: (7316 work)
  • mto: This revision was merged to the branch mainline in revision 7328.
  • Revision ID: jelmer@jelmer.uk-20190603234808-15yk5c7054tj8e2b
Merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
from breezy import (
34
34
    branch as _mod_branch,
35
35
    bugtracker,
36
 
    bundle,
37
36
    cache_utf8,
38
37
    controldir,
39
38
    directory_service,
46
45
    lazy_regex,
47
46
    log,
48
47
    merge as _mod_merge,
 
48
    mergeable as _mod_mergeable,
49
49
    merge_directive,
50
50
    osutils,
51
51
    reconfigure,
1210
1210
        possible_transports = []
1211
1211
        if location is not None:
1212
1212
            try:
1213
 
                mergeable = bundle.read_mergeable_from_url(location,
1214
 
                                                           possible_transports=possible_transports)
 
1213
                mergeable = _mod_mergeable.read_mergeable_from_url(
 
1214
                    location, possible_transports=possible_transports)
1215
1215
            except errors.NotABundle:
1216
1216
                mergeable = None
1217
1217
 
4438
4438
        self.add_cleanup(tree.lock_write().unlock)
4439
4439
        if location is not None:
4440
4440
            try:
4441
 
                mergeable = bundle.read_mergeable_from_url(location,
4442
 
                                                           possible_transports=possible_transports)
 
4441
                mergeable = _mod_mergeable.read_mergeable_from_url(
 
4442
                    location, possible_transports=possible_transports)
4443
4443
            except errors.NotABundle:
4444
4444
                mergeable = None
4445
4445
            else:
5260
5260
        return self._run(b, revision_id_list, revision)
5261
5261
 
5262
5262
    def _run(self, b, revision_id_list, revision):
 
5263
        from .repository import WriteGroup
5263
5264
        gpg_strategy = gpg.GPGStrategy(b.get_config_stack())
5264
5265
        if revision_id_list is not None:
5265
 
            b.repository.start_write_group()
5266
 
            try:
 
5266
            with WriteGroup(b.repository):
5267
5267
                for revision_id in revision_id_list:
5268
5268
                    revision_id = cache_utf8.encode(revision_id)
5269
5269
                    b.repository.sign_revision(revision_id, gpg_strategy)
5270
 
            except BaseException:
5271
 
                b.repository.abort_write_group()
5272
 
                raise
5273
 
            else:
5274
 
                b.repository.commit_write_group()
5275
5270
        elif revision is not None:
5276
5271
            if len(revision) == 1:
5277
5272
                revno, rev_id = revision[0].in_history(b)
5278
 
                b.repository.start_write_group()
5279
 
                try:
 
5273
                with WriteGroup(b.repository):
5280
5274
                    b.repository.sign_revision(rev_id, gpg_strategy)
5281
 
                except BaseException:
5282
 
                    b.repository.abort_write_group()
5283
 
                    raise
5284
 
                else:
5285
 
                    b.repository.commit_write_group()
5286
5275
            elif len(revision) == 2:
5287
5276
                # are they both on rh- if so we can walk between them
5288
5277
                # might be nice to have a range helper for arbitrary
5294
5283
                if from_revno is None or to_revno is None:
5295
5284
                    raise errors.BzrCommandError(
5296
5285
                        gettext('Cannot sign a range of non-revision-history revisions'))
5297
 
                b.repository.start_write_group()
5298
 
                try:
 
5286
                with WriteGroup(b.repository):
5299
5287
                    for revno in range(from_revno, to_revno + 1):
5300
5288
                        b.repository.sign_revision(b.get_rev_id(revno),
5301
5289
                                                   gpg_strategy)
5302
 
                except BaseException:
5303
 
                    b.repository.abort_write_group()
5304
 
                    raise
5305
 
                else:
5306
 
                    b.repository.commit_write_group()
5307
5290
            else:
5308
5291
                raise errors.BzrCommandError(
5309
5292
                    gettext('Please supply either one revision, or a range.'))
7018
7001
            grep.versioned_grep(opts)
7019
7002
 
7020
7003
 
 
7004
class cmd_patch(Command):
 
7005
    """Apply a named patch to the current tree.
 
7006
 
 
7007
    """
 
7008
 
 
7009
    takes_args = ['filename?']
 
7010
    takes_options = [Option('strip', type=int, short_name='p',
 
7011
                            help=("Strip the smallest prefix containing num "
 
7012
                                  "leading slashes from filenames.")),
 
7013
                     Option('silent', help='Suppress chatter.')]
 
7014
 
 
7015
    def run(self, filename=None, strip=None, silent=False):
 
7016
        from .patch import patch_tree
 
7017
        wt = WorkingTree.open_containing('.')[0]
 
7018
        if strip is None:
 
7019
            strip = 1
 
7020
        my_file = None
 
7021
        if filename is None:
 
7022
            my_file = getattr(sys.stdin, 'buffer', sys.stdin)
 
7023
        else:
 
7024
            my_file = open(filename, 'rb')
 
7025
        patches = [my_file.read()]
 
7026
        return patch_tree(wt, patches, strip, quiet=is_quiet(), out=self.outf)
 
7027
 
 
7028
 
 
7029
class cmd_resolve_location(Command):
 
7030
    __doc__ = """Expand a location to a full URL.
 
7031
 
 
7032
    :Examples:
 
7033
        Look up a Launchpad URL.
 
7034
 
 
7035
            brz resolve-location lp:brz
 
7036
    """
 
7037
    takes_args = ['location']
 
7038
    hidden = True
 
7039
 
 
7040
    def run(self, location):
 
7041
        from .location import location_to_url
 
7042
        url = location_to_url(location)
 
7043
        display_url = urlutils.unescape_for_display(url, self.outf.encoding)
 
7044
        self.outf.write('%s\n' % display_url)
 
7045
 
 
7046
 
7021
7047
def _register_lazy_builtins():
7022
7048
    # register lazy builtins from other modules; called at startup and should
7023
7049
    # be only called once.