483
482
d.destroy_workingtree()
485
class cmd_repair_workingtree(Command):
486
__doc__ = """Reset the working tree state file.
488
This is not meant to be used normally, but more as a way to recover from
489
filesystem corruption, etc. This rebuilds the working inventory back to a
490
'known good' state. Any new modifications (adding a file, renaming, etc)
491
will be lost, though modified files will still be detected as such.
493
Most users will want something more like "bzr revert" or "bzr update"
494
unless the state file has become corrupted.
496
By default this attempts to recover the current state by looking at the
497
headers of the state file. If the state file is too corrupted to even do
498
that, you can supply --revision to force the state of the tree.
501
takes_options = ['revision', 'directory',
503
help='Reset the tree even if it doesn\'t appear to be'
508
def run(self, revision=None, directory='.', force=False):
509
tree, _ = WorkingTree.open_containing(directory)
510
self.add_cleanup(tree.lock_tree_write().unlock)
514
except errors.BzrError:
515
pass # There seems to be a real error here, so we'll reset
518
raise errors.BzrCommandError(
519
'The tree does not appear to be corrupt. You probably'
520
' want "bzr revert" instead. Use "--force" if you are'
521
' sure you want to reset the working tree.')
525
revision_ids = [r.as_revision_id(tree.branch) for r in revision]
527
tree.reset_state(revision_ids)
528
except errors.BzrError, e:
529
if revision_ids is None:
530
extra = (', the header appears corrupt, try passing -r -1'
531
' to set the state to the last commit')
534
raise errors.BzrCommandError('failed to reset the tree state'
486
538
class cmd_revno(Command):
487
539
__doc__ = """Show current revision number.
3330
3389
class cmd_upgrade(Command):
3331
__doc__ = """Upgrade branch storage to current format.
3333
The check command or bzr developers may sometimes advise you to run
3334
this command. When the default format has changed you may also be warned
3335
during other operations to upgrade.
3390
__doc__ = """Upgrade a repository, branch or working tree to a newer format.
3392
When the default format has changed after a major new release of
3393
Bazaar, you may be informed during certain operations that you
3394
should upgrade. Upgrading to a newer format may improve performance
3395
or make new features available. It may however limit interoperability
3396
with older repositories or with older versions of Bazaar.
3398
If you wish to upgrade to a particular format rather than the
3399
current default, that can be specified using the --format option.
3400
As a consequence, you can use the upgrade command this way to
3401
"downgrade" to an earlier format, though some conversions are
3402
a one way process (e.g. changing from the 1.x default to the
3403
2.x default) so downgrading is not always possible.
3405
A backup.bzr.~#~ directory is created at the start of the conversion
3406
process (where # is a number). By default, this is left there on
3407
completion. If the conversion fails, delete the new .bzr directory
3408
and rename this one back in its place. Use the --clean option to ask
3409
for the backup.bzr directory to be removed on successful conversion.
3410
Alternatively, you can delete it by hand if everything looks good
3413
If the location given is a shared repository, dependent branches
3414
are also converted provided the repository converts successfully.
3415
If the conversion of a branch fails, remaining branches are still
3418
For more information on upgrades, see the Bazaar Upgrade Guide,
3419
http://doc.bazaar.canonical.com/latest/en/upgrade-guide/.
3338
_see_also = ['check']
3422
_see_also = ['check', 'reconcile', 'formats']
3339
3423
takes_args = ['url?']
3340
3424
takes_options = [
3341
RegistryOption('format',
3342
help='Upgrade to a specific format. See "bzr help'
3343
' formats" for details.',
3344
lazy_registry=('bzrlib.bzrdir', 'format_registry'),
3345
converter=lambda name: bzrdir.format_registry.make_bzrdir(name),
3346
value_switches=True, title='Branch format'),
3425
RegistryOption('format',
3426
help='Upgrade to a specific format. See "bzr help'
3427
' formats" for details.',
3428
lazy_registry=('bzrlib.bzrdir', 'format_registry'),
3429
converter=lambda name: bzrdir.format_registry.make_bzrdir(name),
3430
value_switches=True, title='Branch format'),
3432
help='Remove the backup.bzr directory if successful.'),
3434
help="Show what would be done, but don't actually do anything."),
3349
def run(self, url='.', format=None):
3437
def run(self, url='.', format=None, clean=False, dry_run=False):
3350
3438
from bzrlib.upgrade import upgrade
3351
upgrade(url, format)
3439
exceptions = upgrade(url, format, clean_up=clean, dry_run=dry_run)
3441
if len(exceptions) == 1:
3442
# Compatibility with historical behavior
3354
3448
class cmd_whoami(Command):
4547
4645
@display_command
4548
4646
def run(self, verbose=False):
4549
import bzrlib.plugin
4550
from inspect import getdoc
4552
for name, plugin in bzrlib.plugin.plugins().items():
4553
version = plugin.__version__
4554
if version == 'unknown':
4556
name_ver = '%s %s' % (name, version)
4557
d = getdoc(plugin.module)
4559
doc = d.split('\n')[0]
4561
doc = '(no description)'
4562
result.append((name_ver, doc, plugin.path()))
4563
for name_ver, doc, path in sorted(result):
4564
self.outf.write("%s\n" % name_ver)
4565
self.outf.write(" %s\n" % doc)
4567
self.outf.write(" %s\n" % path)
4568
self.outf.write("\n")
4647
from bzrlib import plugin
4648
self.outf.writelines(
4649
plugin.describe_plugins(show_paths=verbose))
4571
4652
class cmd_testament(Command):
5447
5528
takes_options = [
5448
5529
custom_help('directory',
5449
5530
help='Branch whose tags should be displayed.'),
5450
RegistryOption.from_kwargs('sort',
5531
RegistryOption('sort',
5451
5532
'Sort tags by different criteria.', title='Sorting',
5452
natural='Sort numeric substrings as numbers:'
5453
' suitable for version numbers. (default)',
5454
alpha='Sort tags lexicographically.',
5455
time='Sort tags chronologically.',
5533
lazy_registry=('bzrlib.tag', 'tag_sort_methods')
5461
5539
@display_command
5540
def run(self, directory='.', sort=None, show_ids=False, revision=None):
5541
from bzrlib.tag import tag_sort_methods
5468
5542
branch, relpath = Branch.open_containing(directory)
5470
5544
tags = branch.tags.get_tag_dict().items()
5479
5553
# only show revisions between revid1 and revid2 (inclusive)
5480
5554
tags = [(tag, revid) for tag, revid in tags if
5481
5555
graph.is_between(revid, revid1, revid2)]
5482
if sort == 'natural':
5483
def natural_sort_key(tag):
5484
return [f(s) for f,s in
5485
zip(itertools.cycle((unicode.lower,int)),
5486
re.split('([0-9]+)', tag[0]))]
5487
tags.sort(key=natural_sort_key)
5488
elif sort == 'alpha':
5490
elif sort == 'time':
5492
for tag, revid in tags:
5494
revobj = branch.repository.get_revision(revid)
5495
except errors.NoSuchRevision:
5496
timestamp = sys.maxint # place them at the end
5498
timestamp = revobj.timestamp
5499
timestamps[revid] = timestamp
5500
tags.sort(key=lambda x: timestamps[x[1]])
5557
sort = tag_sort_methods.get()
5501
5559
if not show_ids:
5502
5560
# [ (tag, revid), ... ] -> [ (tag, dotted_revno), ... ]
5503
5561
for index, (tag, revid) in enumerate(tags):