432
445
raise errors.BzrCommandError('invalid kind specified')
434
447
work_tree, file_list = tree_files(file_list)
436
if revision is not None:
437
if len(revision) > 1:
438
raise errors.BzrCommandError('bzr inventory --revision takes'
439
' exactly one revision identifier')
440
revision_id = revision[0].in_history(work_tree.branch).rev_id
441
tree = work_tree.branch.repository.revision_tree(revision_id)
443
# We include work_tree as well as 'tree' here
444
# So that doing '-r 10 path/foo' will lookup whatever file
445
# exists now at 'path/foo' even if it has been renamed, as
446
# well as whatever files existed in revision 10 at path/foo
447
trees = [tree, work_tree]
452
if file_list is not None:
453
file_ids = _mod_tree.find_ids_across_trees(file_list, trees,
454
require_versioned=True)
455
# find_ids_across_trees may include some paths that don't
457
entries = sorted((tree.id2path(file_id), tree.inventory[file_id])
458
for file_id in file_ids if file_id in tree)
460
entries = tree.inventory.entries()
448
work_tree.lock_read()
450
if revision is not None:
451
if len(revision) > 1:
452
raise errors.BzrCommandError(
453
'bzr inventory --revision takes exactly one revision'
455
revision_id = revision[0].in_history(work_tree.branch).rev_id
456
tree = work_tree.branch.repository.revision_tree(revision_id)
458
extra_trees = [work_tree]
464
if file_list is not None:
465
file_ids = tree.paths2ids(file_list, trees=extra_trees,
466
require_versioned=True)
467
# find_ids_across_trees may include some paths that don't
469
entries = sorted((tree.id2path(file_id), tree.inventory[file_id])
470
for file_id in file_ids if file_id in tree)
472
entries = tree.inventory.entries()
475
if tree is not work_tree:
462
478
for path, entry in entries:
463
479
if kind and kind != entry.kind:
632
657
takes_options = ['remember', 'overwrite', 'verbose',
633
Option('create-prefix',
634
help='Create the path leading up to the branch '
635
'if it does not already exist'),
636
Option('use-existing-dir',
637
help='By default push will fail if the target'
638
' directory exists, but does not already'
639
' have a control directory. This flag will'
640
' allow push to proceed.'),
658
Option('create-prefix',
659
help='Create the path leading up to the branch '
660
'if it does not already exist'),
662
help='branch to push from, '
663
'rather than the one containing the working directory',
667
Option('use-existing-dir',
668
help='By default push will fail if the target'
669
' directory exists, but does not already'
670
' have a control directory. This flag will'
671
' allow push to proceed.'),
642
673
takes_args = ['location?']
643
674
encoding_type = 'replace'
645
676
def run(self, location=None, remember=False, overwrite=False,
646
create_prefix=False, verbose=False, use_existing_dir=False):
677
create_prefix=False, verbose=False,
678
use_existing_dir=False,
647
680
# FIXME: Way too big! Put this into a function called from the
650
br_from = Branch.open_containing('.')[0]
682
if directory is None:
684
br_from = Branch.open_containing(directory)[0]
651
685
stored_loc = br_from.get_push_location()
652
686
if location is None:
653
687
if stored_loc is None:
1225
1270
raise errors.BranchExistsWithoutWorkingTree(location)
1226
1271
raise errors.AlreadyBranchError(location)
1228
existing_bzrdir.create_branch()
1273
branch = existing_bzrdir.create_branch()
1229
1274
existing_bzrdir.create_workingtree()
1275
if append_revisions_only:
1277
branch.set_append_revisions_only(True)
1278
except errors.UpgradeRequired:
1279
raise errors.BzrCommandError('This branch format cannot be set'
1280
' to append-revisions-only. Try --experimental-branch6')
1232
1283
class cmd_init_repository(Command):
1233
1284
"""Create a shared repository to hold branches.
1235
1286
New branches created under the repository directory will store their revisions
1236
in the repository, not in the branch directory, if the branch format supports
1287
in the repository, not in the branch directory.
1290
bzr init-repo --no-trees repo
1241
1291
bzr init repo/trunk
1242
1292
bzr checkout --lightweight repo/trunk trunk-checkout
1243
1293
cd trunk-checkout
1244
1294
(add files here)
1246
takes_args = ["location"]
1297
takes_args = ["location"]
1247
1298
takes_options = [RegistryOption('format',
1248
1299
help='Specify a format for this repository. See'
1249
1300
' "bzr help formats" for details',
1250
1301
registry=bzrdir.format_registry,
1251
1302
converter=bzrdir.format_registry.make_bzrdir,
1252
1303
value_switches=True, title='Repository format'),
1254
help='Allows branches in repository to have'
1305
help='Branches in the repository will default to'
1306
' not having a working tree'),
1256
1308
aliases = ["init-repo"]
1257
def run(self, location, format=None, trees=False):
1310
def run(self, location, format=None, no_trees=False):
1258
1311
if format is None:
1259
1312
format = bzrdir.format_registry.make_bzrdir('default')
1534
1601
dir, relpath = bzrdir.BzrDir.open_containing(location)
1535
1602
b = dir.open_branch()
1537
if revision is None:
1540
elif len(revision) == 1:
1541
rev1 = rev2 = revision[0].in_history(b).revno
1542
elif len(revision) == 2:
1543
if revision[1].get_branch() != revision[0].get_branch():
1544
# b is taken from revision[0].get_branch(), and
1545
# show_log will use its revision_history. Having
1546
# different branches will lead to weird behaviors.
1606
if revision is None:
1609
elif len(revision) == 1:
1610
rev1 = rev2 = revision[0].in_history(b).revno
1611
elif len(revision) == 2:
1612
if revision[1].get_branch() != revision[0].get_branch():
1613
# b is taken from revision[0].get_branch(), and
1614
# show_log will use its revision_history. Having
1615
# different branches will lead to weird behaviors.
1616
raise errors.BzrCommandError(
1617
"Log doesn't accept two revisions in different"
1619
if revision[0].spec is None:
1620
# missing begin-range means first revision
1623
rev1 = revision[0].in_history(b).revno
1625
if revision[1].spec is None:
1626
# missing end-range means last known revision
1629
rev2 = revision[1].in_history(b).revno
1547
1631
raise errors.BzrCommandError(
1548
"Log doesn't accept two revisions in different branches.")
1549
if revision[0].spec is None:
1550
# missing begin-range means first revision
1553
rev1 = revision[0].in_history(b).revno
1555
if revision[1].spec is None:
1556
# missing end-range means last known revision
1559
rev2 = revision[1].in_history(b).revno
1561
raise errors.BzrCommandError('bzr log --revision takes one or two values.')
1563
# By this point, the revision numbers are converted to the +ve
1564
# form if they were supplied in the -ve form, so we can do
1565
# this comparison in relative safety
1567
(rev2, rev1) = (rev1, rev2)
1569
if log_format is None:
1570
log_format = log.log_formatter_registry.get_default(b)
1572
lf = log_format(show_ids=show_ids, to_file=self.outf,
1573
show_timezone=timezone)
1579
direction=direction,
1580
start_revision=rev1,
1632
'bzr log --revision takes one or two values.')
1634
# By this point, the revision numbers are converted to the +ve
1635
# form if they were supplied in the -ve form, so we can do
1636
# this comparison in relative safety
1638
(rev2, rev1) = (rev1, rev2)
1640
if log_format is None:
1641
log_format = log.log_formatter_registry.get_default(b)
1643
lf = log_format(show_ids=show_ids, to_file=self.outf,
1644
show_timezone=timezone)
1650
direction=direction,
1651
start_revision=rev1,
1585
1658
def get_log_format(long=False, short=False, line=False, default='long'):
1666
1738
elif tree is None:
1667
1739
tree = branch.basis_tree()
1669
for fp, fc, fkind, fid, entry in tree.list_files(include_root=False):
1670
if fp.startswith(relpath):
1671
fp = osutils.pathjoin(prefix, fp[len(relpath):])
1672
if non_recursive and '/' in fp:
1674
if not all and not selection[fc]:
1676
if kind is not None and fkind != kind:
1679
kindch = entry.kind_character()
1680
outstring = '%-8s %s%s' % (fc, fp, kindch)
1681
if show_ids and fid is not None:
1682
outstring = "%-50s %s" % (outstring, fid)
1683
self.outf.write(outstring + '\n')
1685
self.outf.write(fp + '\0')
1743
for fp, fc, fkind, fid, entry in tree.list_files(include_root=False):
1744
if fp.startswith(relpath):
1745
fp = osutils.pathjoin(prefix, fp[len(relpath):])
1746
if non_recursive and '/' in fp:
1748
if not all and not selection[fc]:
1750
if kind is not None and fkind != kind:
1753
kindch = entry.kind_character()
1754
outstring = '%-8s %s%s' % (fc, fp, kindch)
1755
if show_ids and fid is not None:
1756
outstring = "%-50s %s" % (outstring, fid)
1757
self.outf.write(outstring + '\n')
1759
self.outf.write(fp + '\0')
1762
self.outf.write(fid)
1763
self.outf.write('\0')
1687
1766
if fid is not None:
1688
self.outf.write(fid)
1689
self.outf.write('\0')
1697
self.outf.write('%-50s %s\n' % (fp, my_id))
1699
self.outf.write(fp + '\n')
1771
self.outf.write('%-50s %s\n' % (fp, my_id))
1773
self.outf.write(fp + '\n')
1702
1778
class cmd_unknowns(Command):
2372
2473
merge refuses to run if there are any uncommitted changes, unless
2373
2474
--force is given.
2375
The following merge types are available:
2377
2476
takes_args = ['branch?']
2378
2477
takes_options = ['revision', 'force', 'merge-type', 'reprocess', 'remember',
2379
Option('show-base', help="Show base revision text in "
2381
Option('uncommitted', help='Apply uncommitted changes'
2382
' from a working copy, instead of branch changes'),
2383
Option('pull', help='If the destination is already'
2384
' completely merged into the source, pull from the'
2385
' source rather than merging. When this happens,'
2386
' you do not need to commit the result.'),
2478
Option('show-base', help="Show base revision text in "
2480
Option('uncommitted', help='Apply uncommitted changes'
2481
' from a working copy, instead of branch changes'),
2482
Option('pull', help='If the destination is already'
2483
' completely merged into the source, pull from the'
2484
' source rather than merging. When this happens,'
2485
' you do not need to commit the result.'),
2487
help='Branch to merge into, '
2488
'rather than the one containing the working directory',
2389
2494
def run(self, branch=None, revision=None, force=False, merge_type=None,
2390
show_base=False, reprocess=False, remember=False,
2391
uncommitted=False, pull=False):
2495
show_base=False, reprocess=False, remember=False,
2496
uncommitted=False, pull=False,
2499
from bzrlib.tag import _merge_tags_if_possible
2392
2500
if merge_type is None:
2393
2501
merge_type = _mod_merge.Merge3Merger
2395
tree = WorkingTree.open_containing(u'.')[0]
2503
if directory is None: directory = u'.'
2504
# XXX: jam 20070225 WorkingTree should be locked before you extract its
2505
# inventory. Because merge is a mutating operation, it really
2506
# should be a lock_write() for the whole cmd_merge operation.
2507
# However, cmd_merge open's its own tree in _merge_helper, which
2508
# means if we lock here, the later lock_write() will always block.
2509
# Either the merge helper code should be updated to take a tree,
2510
# (What about tree.merge_from_branch?)
2511
tree = WorkingTree.open_containing(directory)[0]
2512
change_reporter = delta._ChangeReporter(
2513
unversioned_filter=tree.is_ignored)
2397
2515
if branch is not None:
3098
3231
t = get_transport(url)
3100
3233
server = smart.SmartServerPipeStreamMedium(sys.stdin, sys.stdout, t)
3101
elif port is not None:
3103
host, port = port.split(':')
3236
port = smart.BZR_DEFAULT_PORT
3105
3237
host = '127.0.0.1'
3106
server = smart.SmartTCPServer(t, host=host, port=int(port))
3240
host, port = port.split(':')
3244
server = smart.SmartTCPServer(t, host=host, port=port)
3107
3245
print 'listening on port: ', server.port
3108
3246
sys.stdout.flush()
3110
raise errors.BzrCommandError("bzr serve requires one of --inet or --port")
3249
class cmd_join(Command):
3250
"""Combine a subtree into its containing tree.
3252
This command is for experimental use only. It requires the target tree
3253
to be in dirstate-with-subtree format, which cannot be converted into
3256
The TREE argument should be an independent tree, inside another tree, but
3257
not part of it. (Such trees can be produced by "bzr split", but also by
3258
running "bzr branch" with the target inside a tree.)
3260
The result is a combined tree, with the subtree no longer an independant
3261
part. This is marked as a merge of the subtree into the containing tree,
3262
and all history is preserved.
3264
If --reference is specified, the subtree retains its independence. It can
3265
be branched by itself, and can be part of multiple projects at the same
3266
time. But operations performed in the containing tree, such as commit
3267
and merge, will recurse into the subtree.
3270
takes_args = ['tree']
3271
takes_options = [Option('reference', 'join by reference')]
3274
def run(self, tree, reference=False):
3275
sub_tree = WorkingTree.open(tree)
3276
parent_dir = osutils.dirname(sub_tree.basedir)
3277
containing_tree = WorkingTree.open_containing(parent_dir)[0]
3278
repo = containing_tree.branch.repository
3279
if not repo.supports_rich_root():
3280
raise errors.BzrCommandError(
3281
"Can't join trees because %s doesn't support rich root data.\n"
3282
"You can use bzr upgrade on the repository."
3286
containing_tree.add_reference(sub_tree)
3287
except errors.BadReferenceTarget, e:
3288
# XXX: Would be better to just raise a nicely printable
3289
# exception from the real origin. Also below. mbp 20070306
3290
raise errors.BzrCommandError("Cannot join %s. %s" %
3294
containing_tree.subsume(sub_tree)
3295
except errors.BadSubsumeSource, e:
3296
raise errors.BzrCommandError("Cannot join %s. %s" %
3300
class cmd_split(Command):
3301
"""Split a tree into two trees.
3303
This command is for experimental use only. It requires the target tree
3304
to be in dirstate-with-subtree format, which cannot be converted into
3307
The TREE argument should be a subdirectory of a working tree. That
3308
subdirectory will be converted into an independent tree, with its own
3309
branch. Commits in the top-level tree will not apply to the new subtree.
3310
If you want that behavior, do "bzr join --reference TREE".
3312
To undo this operation, do "bzr join TREE".
3315
takes_args = ['tree']
3319
def run(self, tree):
3320
containing_tree, subdir = WorkingTree.open_containing(tree)
3321
sub_id = containing_tree.path2id(subdir)
3323
raise errors.NotVersionedError(subdir)
3325
containing_tree.extract(sub_id)
3326
except errors.RootNotRich:
3327
raise errors.UpgradeRequired(containing_tree.branch.base)
3331
class cmd_merge_directive(Command):
3332
"""Generate a merge directive for auto-merge tools.
3334
A directive requests a merge to be performed, and also provides all the
3335
information necessary to do so. This means it must either include a
3336
revision bundle, or the location of a branch containing the desired
3339
A submit branch (the location to merge into) must be supplied the first
3340
time the command is issued. After it has been supplied once, it will
3341
be remembered as the default.
3343
A public branch is optional if a revision bundle is supplied, but required
3344
if --diff or --plain is specified. It will be remembered as the default
3345
after the first use.
3348
takes_args = ['submit_branch?', 'public_branch?']
3351
RegistryOption.from_kwargs('patch-type',
3352
'The type of patch to include in the directive',
3353
title='Patch type', value_switches=True, enum_switch=False,
3354
bundle='Bazaar revision bundle (default)',
3355
diff='Normal unified diff',
3356
plain='No patch, just directive'),
3357
Option('sign', help='GPG-sign the directive'), 'revision',
3358
Option('mail-to', type=str,
3359
help='Instead of printing the directive, email to this address'),
3360
Option('message', type=str, short_name='m',
3361
help='Message to use when committing this merge')
3364
def run(self, submit_branch=None, public_branch=None, patch_type='bundle',
3365
sign=False, revision=None, mail_to=None, message=None):
3366
if patch_type == 'plain':
3368
branch = Branch.open('.')
3369
stored_submit_branch = branch.get_submit_branch()
3370
if submit_branch is None:
3371
submit_branch = stored_submit_branch
3373
if stored_submit_branch is None:
3374
branch.set_submit_branch(submit_branch)
3375
if submit_branch is None:
3376
submit_branch = branch.get_parent()
3377
if submit_branch is None:
3378
raise errors.BzrCommandError('No submit branch specified or known')
3380
stored_public_branch = branch.get_public_branch()
3381
if public_branch is None:
3382
public_branch = stored_public_branch
3383
elif stored_public_branch is None:
3384
branch.set_public_branch(public_branch)
3385
if patch_type != "bundle" and public_branch is None:
3386
raise errors.BzrCommandError('No public branch specified or'
3388
if revision is not None:
3389
if len(revision) != 1:
3390
raise errors.BzrCommandError('bzr merge-directive takes '
3391
'exactly one revision identifier')
3393
revision_id = revision[0].in_history(branch).rev_id
3395
revision_id = branch.last_revision()
3396
directive = merge_directive.MergeDirective.from_objects(
3397
branch.repository, revision_id, time.time(),
3398
osutils.local_time_offset(), submit_branch,
3399
public_branch=public_branch, patch_type=patch_type,
3403
self.outf.write(directive.to_signed(branch))
3405
self.outf.writelines(directive.to_lines())
3407
message = directive.to_email(mail_to, branch, sign)
3409
server = branch.get_config().get_user_option('smtp_server')
3411
server = 'localhost'
3413
s.sendmail(message['From'], message['To'], message.as_string())
3416
class cmd_tag(Command):
3417
"""Create a tag naming a revision.
3419
Tags give human-meaningful names to revisions. Commands that take a -r
3420
(--revision) option can be given -rtag:X, where X is any previously
3423
Tags are stored in the branch. Tags are copied from one branch to another
3424
along when you branch, push, pull or merge.
3426
It is an error to give a tag name that already exists unless you pass
3427
--force, in which case the tag is moved to point to the new revision.
3430
takes_args = ['tag_name']
3433
help='Delete this tag rather than placing it.',
3436
help='Branch in which to place the tag.',
3441
help='Replace existing tags',
3446
def run(self, tag_name,
3452
branch, relpath = Branch.open_containing(directory)
3456
branch.tags.delete_tag(tag_name)
3457
self.outf.write('Deleted tag %s.\n' % tag_name)
3460
if len(revision) != 1:
3461
raise errors.BzrCommandError(
3462
"Tags can only be placed on a single revision, "
3464
revision_id = revision[0].in_history(branch).rev_id
3466
revision_id = branch.last_revision()
3467
if (not force) and branch.tags.has_tag(tag_name):
3468
raise errors.TagAlreadyExists(tag_name)
3469
branch.tags.set_tag(tag_name, revision_id)
3470
self.outf.write('Created tag %s.\n' % tag_name)
3475
class cmd_tags(Command):
3478
This tag shows a table of tag names and the revisions they reference.
3483
help='Branch whose tags should be displayed',
3493
branch, relpath = Branch.open_containing(directory)
3494
for tag_name, target in sorted(branch.tags.get_tag_dict().items()):
3495
self.outf.write('%-20s %s\n' % (tag_name, target))
3114
3498
# command-line interpretation helper for merge-related commands
3115
3499
def _merge_helper(other_revision, base_revision,