~jelmer/brz-loom/trunk

« back to all changes in this revision

Viewing changes to commands.py

  • Committer: Jelmer Vernooij
  • Date: 2018-05-20 13:59:05 UTC
  • Revision ID: jelmer@jelmer.uk-20180520135905-xprutd7e7785g94r
Port to breezy (mostly)

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 
20
20
from __future__ import absolute_import
21
21
 
22
 
from bzrlib import bzrdir, directory_service, workingtree
23
 
import bzrlib.commands
24
 
import bzrlib.branch
25
 
from bzrlib import errors
26
 
from bzrlib.lazy_import import lazy_import
27
 
from bzrlib.option import Option
28
 
import bzrlib.trace
29
 
import bzrlib.transport
 
22
from breezy import controldir, directory_service, workingtree
 
23
import breezy.commands
 
24
import breezy.branch
 
25
from breezy import errors
 
26
from breezy.lazy_import import lazy_import
 
27
from breezy.option import Option
 
28
import breezy.trace
 
29
import breezy.transport
30
30
 
31
31
lazy_import(globals(), """
32
 
from bzrlib.plugins.loom import branch
33
 
from bzrlib.plugins.loom.tree import LoomTreeDecorator
 
32
from breezy.plugins.loom import branch
 
33
from breezy.plugins.loom.tree import LoomTreeDecorator
34
34
""")
35
35
 
36
36
 
37
 
class cmd_loomify(bzrlib.commands.Command):
 
37
class cmd_loomify(breezy.commands.Command):
38
38
    """Add a loom to this branch.
39
39
 
40
40
    This creates a loom in your branch, which will alter the behaviour of
51
51
                            help='The name to use for the base thread.')]
52
52
 
53
53
    def run(self, location='.', base=None):
54
 
        (target, path) = bzrlib.branch.Branch.open_containing(location)
 
54
        (target, path) = breezy.branch.Branch.open_containing(location)
55
55
        target.lock_write()
56
56
        try:
57
57
            if base is not None:
61
61
                    'You must specify --base or have a branch nickname set to'
62
62
                    ' loomify a branch')
63
63
            branch.loomify(target)
64
 
            loom = target.bzrdir.open_branch()
 
64
            loom = target.controldir.open_branch()
65
65
        finally:
66
66
            target.unlock()
67
67
        # requires a new lock as its a new instance, XXX: teach bzrdir about
69
69
        loom.new_thread(loom.nick)
70
70
 
71
71
 
72
 
class cmd_combine_thread(bzrlib.commands.Command):
 
72
class cmd_combine_thread(breezy.commands.Command):
73
73
    __doc__ = """Combine the current thread with the thread below it.
74
74
    
75
75
    This will currently refuse to operate on the last thread, but in the future
125
125
        new_thread = state.get_new_thread_after_deleting(current_thread)
126
126
        if new_thread is None:
127
127
            raise branch.CannotCombineOnLastThread
128
 
        bzrlib.trace.note("Combining thread '%s' into '%s'",
 
128
        breezy.trace.note("Combining thread '%s' into '%s'",
129
129
            current_thread, new_thread)
130
130
        LoomTreeDecorator(tree).down_thread(new_thread)
131
131
        tree.branch.remove_thread(current_thread)
132
132
 
133
133
 
134
 
class cmd_create_thread(bzrlib.commands.Command):
 
134
class cmd_create_thread(breezy.commands.Command):
135
135
    """Add a thread to this loom.
136
136
 
137
137
    This creates a new thread in this loom and moves the branch onto that
146
146
    takes_args = ['thread']
147
147
 
148
148
    def run(self, thread):
149
 
        (loom, path) = bzrlib.branch.Branch.open_containing('.')
 
149
        (loom, path) = breezy.branch.Branch.open_containing('.')
150
150
        branch.create_thread(loom, thread)
151
151
 
152
152
 
153
 
class cmd_show_loom(bzrlib.commands.Command):
 
153
class cmd_show_loom(breezy.commands.Command):
154
154
    """Show the threads in this loom.
155
155
 
156
156
    Output the threads in this loom with the newest thread at the top and
161
161
    takes_args = ['location?']
162
162
 
163
163
    def run(self, location='.'):
164
 
        (loom, path) = bzrlib.branch.Branch.open_containing(location)
 
164
        (loom, path) = breezy.branch.Branch.open_containing(location)
165
165
        branch.require_loom_branch(loom)
166
166
        loom.lock_read()
167
167
        try:
172
172
                    symbol = '=>'
173
173
                else:
174
174
                    symbol = '  '
175
 
                print "%s%s" % (symbol, thread)
 
175
                self.outf.write(symbol + thread + '\n')
176
176
        finally:
177
177
            loom.unlock()
178
178
 
179
179
 
180
 
class cmd_switch(bzrlib.builtins.cmd_switch):
 
180
class cmd_switch(breezy.builtins.cmd_switch):
181
181
    """Set the branch of a checkout and update.
182
182
 
183
183
    For looms, this is equivalent to 'down-thread' when to_location is the name
215
215
        # enough.
216
216
        if directory is None:
217
217
            directory = u'.'
218
 
        control_dir, path = bzrdir.BzrDir.open_containing(directory)
 
218
        control_dir, path = controldir.ControlDir.open_containing(directory)
219
219
        if to_location is None:
220
220
            if revision is None:
221
221
                raise errors.BzrCommandError(
261
261
            self._original_command().run_argv_aliases(argv, alias_argv)
262
262
 
263
263
 
264
 
class cmd_record(bzrlib.commands.Command):
 
264
class cmd_record(breezy.commands.Command):
265
265
    """Record the current last-revision of this tree into the current thread."""
266
266
 
267
267
    takes_args = ['message']
268
268
 
269
269
    def run(self, message):
270
 
        (abranch, path) = bzrlib.branch.Branch.open_containing('.')
 
270
        (abranch, path) = breezy.branch.Branch.open_containing('.')
271
271
        branch.require_loom_branch(abranch)
272
272
        abranch.record_loom(message)
273
273
        print "Loom recorded."
274
274
 
275
275
 
276
 
class cmd_revert_loom(bzrlib.commands.Command):
 
276
class cmd_revert_loom(breezy.commands.Command):
277
277
    """Revert part or all of a loom.
278
278
    
279
279
    This will update the current loom to be the same as the basis when --all
289
289
 
290
290
    def run(self, thread=None, all=None):
291
291
        if thread is None and all is None:
292
 
            bzrlib.trace.note('Please see revert-loom -h.')
 
292
            breezy.trace.note('Please see revert-loom -h.')
293
293
            return
294
294
        (tree, path) = workingtree.WorkingTree.open_containing('.')
295
295
        branch.require_loom_branch(tree.branch)
296
296
        tree = LoomTreeDecorator(tree)
297
297
        if all:
298
298
            tree.revert_loom()
299
 
            bzrlib.trace.note('All threads reverted.')
 
299
            breezy.trace.note('All threads reverted.')
300
300
        else:
301
301
            tree.revert_loom(thread)
302
 
            bzrlib.trace.note("thread '%s' reverted.", thread)
303
 
 
304
 
 
305
 
class cmd_down_thread(bzrlib.commands.Command):
 
302
            breezy.trace.note("thread '%s' reverted.", thread)
 
303
 
 
304
 
 
305
class cmd_down_thread(breezy.commands.Command):
306
306
    """Move the branch down a thread in the loom.
307
307
 
308
308
    This removes the changes introduced by the current thread from the branch
335
335
            tree.unlock()
336
336
 
337
337
 
338
 
class cmd_up_thread(bzrlib.commands.Command):
 
338
class cmd_up_thread(breezy.commands.Command):
339
339
    """Move the branch up to the top thread in the loom.
340
340
 
341
341
    This merges the changes done in this thread but not incorporated into
366
366
            return tree.up_many(merge_type, thread)
367
367
 
368
368
 
369
 
class cmd_export_loom(bzrlib.commands.Command):
 
369
class cmd_export_loom(breezy.commands.Command):
370
370
    """Export loom threads as a full-fledged branches.
371
371
 
372
372
    LOCATION specifies the location to export the threads under.  If it does
381
381
 
382
382
    def run(self, location=None):
383
383
        root_transport = None
384
 
        loom = bzrlib.branch.Branch.open_containing('.')[0]
 
384
        loom = breezy.branch.Branch.open_containing('.')[0]
385
385
        if location is None:
386
386
            location = loom.get_config().get_user_option('export_loom_root')
387
387
        if location is None:
388
388
            raise errors.BzrCommandError('No export root known or specified.')
389
 
        root_transport = bzrlib.transport.get_transport(location,
390
 
            possible_transports=[loom.bzrdir.root_transport])
 
389
        root_transport = breezy.transport.get_transport(location,
 
390
            possible_transports=[loom.controldir.root_transport])
391
391
        root_transport.ensure_base()
392
392
        loom.export_threads(root_transport)