17
17
"""builtin bzr commands"""
21
from bzrlib.lazy_import import lazy_import
22
lazy_import(globals(), """
27
29
from bzrlib import (
41
from bzrlib.branch import Branch, BranchReferenceFormat
42
from bzrlib.bundle import read_bundle_from_url
46
from bzrlib.branch import Branch
43
47
from bzrlib.bundle.apply_bundle import install_bundle, merge_bundle
44
48
from bzrlib.conflicts import ConflictList
49
from bzrlib.revision import common_ancestor
50
from bzrlib.revisionspec import RevisionSpec
51
from bzrlib.workingtree import WorkingTree
45
54
from bzrlib.commands import Command, display_command
46
from bzrlib.errors import (BzrError, BzrCheckError, BzrCommandError,
47
NotBranchError, DivergedBranches, NotConflicted,
48
NoSuchFile, NoWorkingTree, FileInWrongBranch,
49
NotVersionedError, NotABundle)
50
from bzrlib.merge import Merge3Merger
51
from bzrlib.option import Option
55
from bzrlib.option import Option, RegistryOption
52
56
from bzrlib.progress import DummyProgress, ProgressPhase
53
from bzrlib.revision import common_ancestor
54
from bzrlib.revisionspec import RevisionSpec
55
57
from bzrlib.trace import mutter, note, log_error, warning, is_quiet, info
56
from bzrlib.transport.local import LocalTransport
57
from bzrlib.workingtree import WorkingTree
60
60
def tree_files(file_list, default_branch=u'.'):
62
62
return internal_tree_files(file_list, default_branch)
63
except FileInWrongBranch, e:
64
raise BzrCommandError("%s is not in the same branch as %s" %
65
(e.path, file_list[0]))
63
except errors.FileInWrongBranch, e:
64
raise errors.BzrCommandError("%s is not in the same branch as %s" %
65
(e.path, file_list[0]))
68
68
# XXX: Bad function name; should possibly also be a class method of
78
78
:param file_list: Filenames to convert.
80
:param default_branch: Fallback tree path to use if file_list is empty or None.
80
:param default_branch: Fallback tree path to use if file_list is empty or
82
83
:return: workingtree, [relative_paths]
84
85
if file_list is None or len(file_list) == 0:
85
86
return WorkingTree.open_containing(default_branch)[0], file_list
86
tree = WorkingTree.open_containing(file_list[0])[0]
87
tree = WorkingTree.open_containing(osutils.realpath(file_list[0]))[0]
88
89
for filename in file_list:
90
new_list.append(tree.relpath(filename))
91
new_list.append(tree.relpath(osutils.dereference_path(filename)))
91
92
except errors.PathNotChild:
92
raise FileInWrongBranch(tree.branch, filename)
93
raise errors.FileInWrongBranch(tree.branch, filename)
93
94
return tree, new_list
96
97
def get_format_type(typestring):
97
98
"""Parse and return a format specifier."""
98
if typestring == "weave":
99
return bzrdir.BzrDirFormat6()
99
# Have to use BzrDirMetaFormat1 directly, so that
100
# RepositoryFormat.set_default_format works
100
101
if typestring == "default":
101
102
return bzrdir.BzrDirMetaFormat1()
102
if typestring == "metaweave":
103
format = bzrdir.BzrDirMetaFormat1()
104
format.repository_format = repository.RepositoryFormat7()
106
if typestring == "knit":
107
format = bzrdir.BzrDirMetaFormat1()
108
format.repository_format = repository.RepositoryFormatKnit1()
110
msg = "Unknown bzr format %s. Current formats are: default, knit,\n" \
111
"metaweave and weave" % typestring
112
raise BzrCommandError(msg)
104
return bzrdir.format_registry.make_bzrdir(typestring)
106
msg = 'Unknown bzr format "%s". See "bzr help formats".' % typestring
107
raise errors.BzrCommandError(msg)
115
110
# TODO: Make sure no commands unconditionally use the working directory as a
124
119
This reports on versioned and unknown files, reporting them
125
120
grouped by state. Possible states are:
128
123
Versioned in the working copy but not in the previous revision.
131
126
Versioned in the previous revision but removed or deleted
132
127
in the working copy.
135
130
Path of this file changed from the previous revision;
136
131
the text may also have changed. This includes files whose
137
132
parent directory was renamed.
140
135
Text has changed since the previous revision.
143
138
Not versioned and not matching an ignore pattern.
145
140
To see ignored files use 'bzr ignored'. For details in the
146
141
changes to file texts, use 'bzr diff'.
143
--short gives a one character status flag for each item, similar
144
to the SVN's status command.
148
146
If no arguments are specified, the status of the entire working
149
147
directory is shown. Otherwise, only the status of the specified
157
155
# TODO: --no-recurse, --recurse options
159
157
takes_args = ['file*']
160
takes_options = ['show-ids', 'revision']
158
takes_options = ['show-ids', 'revision', 'short']
161
159
aliases = ['st', 'stat']
163
161
encoding_type = 'replace'
166
def run(self, show_ids=False, file_list=None, revision=None):
164
def run(self, show_ids=False, file_list=None, revision=None, short=False):
167
165
from bzrlib.status import show_tree_status
169
167
tree, file_list = tree_files(file_list)
171
169
show_tree_status(tree, show_ids=show_ids,
172
170
specific_files=file_list, revision=revision,
176
175
class cmd_cat_revision(Command):
190
189
def run(self, revision_id=None, revision=None):
192
191
if revision_id is not None and revision is not None:
193
raise BzrCommandError('You can only supply one of revision_id or --revision')
192
raise errors.BzrCommandError('You can only supply one of'
193
' revision_id or --revision')
194
194
if revision_id is None and revision is None:
195
raise BzrCommandError('You must supply either --revision or a revision_id')
195
raise errors.BzrCommandError('You must supply either'
196
' --revision or a revision_id')
196
197
b = WorkingTree.open_containing(u'.')[0].branch
198
199
# TODO: jam 20060112 should cat-revision always output utf-8?
201
202
elif revision is not None:
202
203
for rev in revision:
204
raise BzrCommandError('You cannot specify a NULL revision.')
205
raise errors.BzrCommandError('You cannot specify a NULL'
205
207
revno, rev_id = rev.in_history(b)
206
208
self.outf.write(b.repository.get_revision_xml(rev_id).decode('utf-8'))
211
class cmd_remove_tree(Command):
212
"""Remove the working tree from a given branch/checkout.
214
Since a lightweight checkout is little more than a working tree
215
this will refuse to run against one.
220
takes_args = ['location?']
222
def run(self, location='.'):
223
d = bzrdir.BzrDir.open(location)
226
working = d.open_workingtree()
227
except errors.NoWorkingTree:
228
raise errors.BzrCommandError("No working tree to remove")
229
except errors.NotLocalUrl:
230
raise errors.BzrCommandError("You cannot remove the working tree of a "
233
working_path = working.bzrdir.root_transport.base
234
branch_path = working.branch.bzrdir.root_transport.base
235
if working_path != branch_path:
236
raise errors.BzrCommandError("You cannot remove the working tree from "
237
"a lightweight checkout")
239
d.destroy_workingtree()
209
242
class cmd_revno(Command):
210
243
"""Show current revision number.
275
308
--dry-run will show which files would be added, but not actually
311
--file-ids-from will try to use the file ids from the supplied path.
312
It looks up ids trying to find a matching parent directory with the
313
same filename, and then by pure path.
278
315
takes_args = ['file*']
279
takes_options = ['no-recurse', 'dry-run', 'verbose']
316
takes_options = ['no-recurse', 'dry-run', 'verbose',
317
Option('file-ids-from', type=unicode,
318
help='Lookup file ids from here')]
280
319
encoding_type = 'replace'
282
def run(self, file_list, no_recurse=False, dry_run=False, verbose=False):
321
def run(self, file_list, no_recurse=False, dry_run=False, verbose=False,
283
323
import bzrlib.add
285
action = bzrlib.add.AddAction(to_file=self.outf,
286
should_print=(not is_quiet()))
288
added, ignored = bzrlib.add.smart_add(file_list, not no_recurse,
325
if file_ids_from is not None:
327
base_tree, base_path = WorkingTree.open_containing(
329
except errors.NoWorkingTree:
330
base_branch, base_path = Branch.open_containing(
332
base_tree = base_branch.basis_tree()
334
action = bzrlib.add.AddFromBaseAction(base_tree, base_path,
335
to_file=self.outf, should_print=(not is_quiet()))
337
action = bzrlib.add.AddAction(to_file=self.outf,
338
should_print=(not is_quiet()))
340
added, ignored = bzrlib.add.smart_add(file_list, not no_recurse,
289
341
action=action, save=not dry_run)
290
342
if len(ignored) > 0:
338
390
"""Show inventory of the current working copy or a revision.
340
392
It is possible to limit the output to a particular entry
341
type using the --kind option. For example; --kind file.
393
type using the --kind option. For example: --kind file.
395
It is also possible to restrict the list of files to a specific
396
set. For example: bzr inventory --show-ids this/file
344
399
takes_options = ['revision', 'show-ids', 'kind']
400
takes_args = ['file*']
347
def run(self, revision=None, show_ids=False, kind=None):
403
def run(self, revision=None, show_ids=False, kind=None, file_list=None):
348
404
if kind and kind not in ['file', 'directory', 'symlink']:
349
raise BzrCommandError('invalid kind specified')
350
tree = WorkingTree.open_containing(u'.')[0]
352
inv = tree.read_working_inventory()
405
raise errors.BzrCommandError('invalid kind specified')
407
work_tree, file_list = tree_files(file_list)
409
if revision is not None:
354
410
if len(revision) > 1:
355
raise BzrCommandError('bzr inventory --revision takes'
356
' exactly one revision identifier')
357
inv = tree.branch.repository.get_revision_inventory(
358
revision[0].in_history(tree.branch).rev_id)
360
for path, entry in inv.entries():
411
raise errors.BzrCommandError('bzr inventory --revision takes'
412
' exactly one revision identifier')
413
revision_id = revision[0].in_history(work_tree.branch).rev_id
414
tree = work_tree.branch.repository.revision_tree(revision_id)
416
# We include work_tree as well as 'tree' here
417
# So that doing '-r 10 path/foo' will lookup whatever file
418
# exists now at 'path/foo' even if it has been renamed, as
419
# well as whatever files existed in revision 10 at path/foo
420
trees = [tree, work_tree]
425
if file_list is not None:
426
file_ids = _mod_tree.find_ids_across_trees(file_list, trees,
427
require_versioned=True)
428
# find_ids_across_trees may include some paths that don't
430
entries = sorted((tree.id2path(file_id), tree.inventory[file_id])
431
for file_id in file_ids if file_id in tree)
433
entries = tree.inventory.entries()
435
for path, entry in entries:
361
436
if kind and kind != entry.kind:
377
452
If the last argument is a versioned directory, all the other names
378
453
are moved into it. Otherwise, there must be exactly two arguments
379
and the file is changed to a new name, which must not already exist.
454
and the file is changed to a new name.
456
If OLDNAME does not exist on the filesystem but is versioned and
457
NEWNAME does exist on the filesystem but is not versioned, mv
458
assumes that the file has been manually moved and only updates
459
its internal inventory to reflect that change.
460
The same is valid when moving many SOURCE files to a DESTINATION.
381
462
Files cannot be moved between branches.
384
465
takes_args = ['names*']
466
takes_options = [Option("after", help="move only the bzr identifier"
467
" of the file (file has already been moved). Use this flag if"
468
" bzr is not able to detect this itself.")]
385
469
aliases = ['move', 'rename']
386
470
encoding_type = 'replace'
388
def run(self, names_list):
472
def run(self, names_list, after=False):
389
473
if names_list is None:
392
476
if len(names_list) < 2:
393
raise BzrCommandError("missing file argument")
477
raise errors.BzrCommandError("missing file argument")
394
478
tree, rel_names = tree_files(names_list)
396
480
if os.path.isdir(names_list[-1]):
397
481
# move into existing directory
398
for pair in tree.move(rel_names[:-1], rel_names[-1]):
482
for pair in tree.move(rel_names[:-1], rel_names[-1], after=after):
399
483
self.outf.write("%s => %s\n" % pair)
401
485
if len(names_list) != 2:
402
raise BzrCommandError('to mv multiple files the destination '
403
'must be a versioned directory')
404
tree.rename_one(rel_names[0], rel_names[1])
486
raise errors.BzrCommandError('to mv multiple files the'
487
' destination must be a versioned'
489
tree.rename_one(rel_names[0], rel_names[1], after=after)
405
490
self.outf.write("%s => %s\n" % (rel_names[0], rel_names[1]))
565
651
to_transport, relpath = needed[-1]
566
652
to_transport.mkdir(relpath)
654
except errors.NoSuchFile:
569
655
new_transport = to_transport.clone('..')
570
656
needed.append((new_transport,
571
657
new_transport.relpath(to_transport.base)))
572
658
if new_transport.base == to_transport.base:
573
raise BzrCommandError("Could not create "
659
raise errors.BzrCommandError("Could not create "
575
661
dir_to = br_from.bzrdir.clone(location_url,
576
662
revision_id=br_from.last_revision())
577
663
br_to = dir_to.open_branch()
591
677
except errors.NotLocalUrl:
592
678
warning('This transport does not update the working '
593
679
'tree of: %s' % (br_to.base,))
594
count = br_to.pull(br_from, overwrite)
595
except NoWorkingTree:
596
count = br_to.pull(br_from, overwrite)
680
count = br_from.push(br_to, overwrite)
681
except errors.NoWorkingTree:
682
count = br_from.push(br_to, overwrite)
598
count = tree_to.pull(br_from, overwrite)
599
except DivergedBranches:
600
raise BzrCommandError("These branches have diverged."
601
" Try a merge then push with overwrite.")
686
count = br_from.push(tree_to.branch, overwrite)
690
except errors.DivergedBranches:
691
raise errors.BzrCommandError('These branches have diverged.'
692
' Try using "merge" and then "push".')
602
693
note('%d revision(s) pushed.' % (count,))
677
768
except errors.NoSuchRevision:
678
769
to_transport.delete_tree('.')
679
770
msg = "The branch %s has no revision %s." % (from_location, revision[0])
680
raise BzrCommandError(msg)
771
raise errors.BzrCommandError(msg)
681
772
except errors.UnlistableBranch:
682
773
osutils.rmtree(to_location)
683
774
msg = "The branch %s cannot be used as a --basis" % (basis,)
684
raise BzrCommandError(msg)
775
raise errors.BzrCommandError(msg)
686
777
branch.control_files.put_utf8('branch-name', name)
687
778
note('Branched %d revision(s).' % branch.revno())
752
843
os.mkdir(to_location)
753
844
except OSError, e:
754
845
if e.errno == errno.EEXIST:
755
raise BzrCommandError('Target directory "%s" already'
756
' exists.' % to_location)
846
raise errors.BzrCommandError('Target directory "%s" already'
847
' exists.' % to_location)
757
848
if e.errno == errno.ENOENT:
758
raise BzrCommandError('Parent of "%s" does not exist.' %
849
raise errors.BzrCommandError('Parent of "%s" does not exist.'
762
old_format = bzrdir.BzrDirFormat.get_default_format()
763
bzrdir.BzrDirFormat.set_default_format(bzrdir.BzrDirMetaFormat1())
766
checkout = bzrdir.BzrDirMetaFormat1().initialize(to_location)
767
branch.BranchReferenceFormat().initialize(checkout, source)
769
checkout_branch = bzrdir.BzrDir.create_branch_convenience(
770
to_location, force_new_tree=False)
771
checkout = checkout_branch.bzrdir
772
checkout_branch.bind(source)
773
if revision_id is not None:
774
rh = checkout_branch.revision_history()
775
checkout_branch.set_revision_history(rh[:rh.index(revision_id) + 1])
776
checkout.create_workingtree(revision_id)
778
bzrdir.BzrDirFormat.set_default_format(old_format)
853
source.create_checkout(to_location, revision_id, lightweight)
781
856
class cmd_renames(Command):
873
955
tree, file_list = tree_files(file_list)
875
957
if file_list is None:
876
raise BzrCommandError('Specify one or more files to remove, or'
958
raise errors.BzrCommandError('Specify one or more files to'
959
' remove, or use --new.')
879
961
added = tree.changes_from(tree.basis_tree(),
880
962
specific_files=file_list).added
881
963
file_list = sorted([f[0] for f in added], reverse=True)
882
964
if len(file_list) == 0:
883
raise BzrCommandError('No matching files.')
965
raise errors.BzrCommandError('No matching files.')
884
966
tree.remove(file_list, verbose=verbose, to_file=self.outf)
1070
1155
(add files here)
1072
1157
takes_args = ["location"]
1073
takes_options = [Option('format',
1158
takes_options = [RegistryOption('format',
1074
1159
help='Specify a format for this repository.'
1075
1160
' Current formats are: default, knit,'
1076
1161
' metaweave and weave. Default is knit;'
1077
1162
' metaweave and weave are deprecated',
1078
type=get_format_type),
1163
registry=bzrdir.format_registry,
1164
converter=get_format_type,
1165
value_switches=True),
1079
1166
Option('trees',
1080
1167
help='Allows branches in repository to have'
1081
1168
' a working tree')]
1149
1241
elif prefix == '1':
1150
1242
old_label = 'old/'
1151
1243
new_label = 'new/'
1153
if not ':' in prefix:
1154
raise BzrError("--diff-prefix expects two values separated by a colon")
1155
1245
old_label, new_label = prefix.split(":")
1247
raise BzrCommandError(
1248
"--prefix expects two values separated by a colon")
1250
if revision and len(revision) > 2:
1251
raise errors.BzrCommandError('bzr diff --revision takes exactly'
1252
' one or two revision specifiers')
1158
1255
tree1, file_list = internal_tree_files(file_list)
1162
except FileInWrongBranch:
1259
except errors.FileInWrongBranch:
1163
1260
if len(file_list) != 2:
1164
raise BzrCommandError("Files are in different branches")
1261
raise errors.BzrCommandError("Files are in different branches")
1166
1263
tree1, file1 = WorkingTree.open_containing(file_list[0])
1167
1264
tree2, file2 = WorkingTree.open_containing(file_list[1])
1168
1265
if file1 != "" or file2 != "":
1169
1266
# FIXME diff those two files. rbc 20051123
1170
raise BzrCommandError("Files are in different branches")
1267
raise errors.BzrCommandError("Files are in different branches")
1171
1268
file_list = None
1172
except NotBranchError:
1269
except errors.NotBranchError:
1173
1270
if (revision is not None and len(revision) == 2
1174
1271
and not revision[0].needs_branch()
1175
1272
and not revision[1].needs_branch()):
1178
1275
tree1, tree2 = None, None
1181
if revision is not None:
1182
if tree2 is not None:
1183
raise BzrCommandError("Can't specify -r with two branches")
1184
if (len(revision) == 1) or (revision[1].spec is None):
1185
return diff_cmd_helper(tree1, file_list, diff_options,
1187
old_label=old_label, new_label=new_label)
1188
elif len(revision) == 2:
1189
return diff_cmd_helper(tree1, file_list, diff_options,
1190
revision[0], revision[1],
1191
old_label=old_label, new_label=new_label)
1193
raise BzrCommandError('bzr diff --revision takes exactly one or two revision identifiers')
1195
if tree2 is not None:
1196
return show_diff_trees(tree1, tree2, sys.stdout,
1197
specific_files=file_list,
1198
external_diff_options=diff_options,
1199
old_label=old_label, new_label=new_label)
1201
return diff_cmd_helper(tree1, file_list, diff_options,
1202
old_label=old_label, new_label=new_label)
1279
if tree2 is not None:
1280
if revision is not None:
1281
# FIXME: but there should be a clean way to diff between
1282
# non-default versions of two trees, it's not hard to do
1284
raise errors.BzrCommandError(
1285
"Sorry, diffing arbitrary revisions across branches "
1286
"is not implemented yet")
1287
return show_diff_trees(tree1, tree2, sys.stdout,
1288
specific_files=file_list,
1289
external_diff_options=diff_options,
1290
old_label=old_label, new_label=new_label)
1292
return diff_cmd_helper(tree1, file_list, diff_options,
1293
revision_specs=revision,
1294
old_label=old_label, new_label=new_label)
1205
1297
class cmd_deleted(Command):
1331
1427
# either no tree, or is remote.
1332
1428
inv = b.basis_tree().inventory
1333
1429
file_id = inv.path2id(fp)
1431
raise errors.BzrCommandError(
1432
"Path does not have any revision history: %s" %
1335
1435
# local dir only
1336
1436
# FIXME ? log the current subdir only RBC 20060203
1337
dir, relpath = bzrdir.BzrDir.open_containing('.')
1437
if revision is not None \
1438
and len(revision) > 0 and revision[0].get_branch():
1439
location = revision[0].get_branch()
1442
dir, relpath = bzrdir.BzrDir.open_containing(location)
1338
1443
b = dir.open_branch()
1340
1445
if revision is None:
1427
1539
Option('ignored', help='Print ignored files'),
1429
1541
Option('null', help='Null separate the files'),
1431
1544
@display_command
1432
1545
def run(self, revision=None, verbose=False,
1433
1546
non_recursive=False, from_root=False,
1434
1547
unknown=False, versioned=False, ignored=False,
1548
null=False, kind=None, show_ids=False, path=None):
1550
if kind and kind not in ('file', 'directory', 'symlink'):
1551
raise errors.BzrCommandError('invalid kind specified')
1437
1553
if verbose and null:
1438
raise BzrCommandError('Cannot set both --verbose and --null')
1554
raise errors.BzrCommandError('Cannot set both --verbose and --null')
1439
1555
all = not (unknown or versioned or ignored)
1441
1557
selection = {'I':ignored, '?':unknown, 'V':versioned}
1443
tree, relpath = WorkingTree.open_containing(u'.')
1564
raise errors.BzrCommandError('cannot specify both --from-root'
1568
tree, branch, relpath = bzrdir.BzrDir.open_containing_tree_or_branch(
1448
1574
if revision is not None:
1449
tree = tree.branch.repository.revision_tree(
1450
revision[0].in_history(tree.branch).rev_id)
1575
tree = branch.repository.revision_tree(
1576
revision[0].in_history(branch).rev_id)
1578
tree = branch.basis_tree()
1452
for fp, fc, kind, fid, entry in tree.list_files():
1580
for fp, fc, fkind, fid, entry in tree.list_files(include_root=False):
1453
1581
if fp.startswith(relpath):
1454
fp = fp[len(relpath):]
1582
fp = osutils.pathjoin(prefix, fp[len(relpath):])
1455
1583
if non_recursive and '/' in fp:
1457
1585
if not all and not selection[fc]:
1587
if kind is not None and fkind != kind:
1460
1590
kindch = entry.kind_character()
1461
self.outf.write('%-8s %s%s\n' % (fc, fp, kindch))
1591
outstring = '%-8s %s%s' % (fc, fp, kindch)
1592
if show_ids and fid is not None:
1593
outstring = "%-50s %s" % (outstring, fid)
1594
self.outf.write(outstring + '\n')
1463
1596
self.outf.write(fp + '\0')
1599
self.outf.write(fid)
1600
self.outf.write('\0')
1464
1601
self.outf.flush()
1466
self.outf.write(fp + '\n')
1608
self.outf.write('%-50s %s\n' % (fp, my_id))
1610
self.outf.write(fp + '\n')
1469
1613
class cmd_unknowns(Command):
1477
1621
class cmd_ignore(Command):
1478
"""Ignore a command or pattern.
1622
"""Ignore specified files or patterns.
1480
1624
To remove patterns from the ignore list, edit the .bzrignore file.
1482
If the pattern contains a slash, it is compared to the whole path
1483
from the branch root. Otherwise, it is compared to only the last
1484
component of the path. To match a file only in the root directory,
1487
Ignore patterns are case-insensitive on case-insensitive systems.
1489
Note: wildcards must be quoted from the shell on Unix.
1626
Trailing slashes on patterns are ignored.
1627
If the pattern contains a slash or is a regular expression, it is compared
1628
to the whole path from the branch root. Otherwise, it is compared to only
1629
the last component of the path. To match a file only in the root
1630
directory, prepend './'.
1632
Ignore patterns specifying absolute paths are not allowed.
1634
Ignore patterns may include globbing wildcards such as:
1635
? - Matches any single character except '/'
1636
* - Matches 0 or more characters except '/'
1637
/**/ - Matches 0 or more directories in a path
1638
[a-z] - Matches a single character from within a group of characters
1640
Ignore patterns may also be Python regular expressions.
1641
Regular expression ignore patterns are identified by a 'RE:' prefix
1642
followed by the regular expression. Regular expression ignore patterns
1643
may not include named or numbered groups.
1645
Note: ignore patterns containing shell wildcards must be quoted from
1492
1649
bzr ignore ./Makefile
1493
1650
bzr ignore '*.class'
1651
bzr ignore 'lib/**/*.o'
1652
bzr ignore 'RE:lib/.*\.o'
1495
# TODO: Complain if the filename is absolute
1496
takes_args = ['name_pattern?']
1654
takes_args = ['name_pattern*']
1497
1655
takes_options = [
1498
1656
Option('old-default-rules',
1499
1657
help='Out the ignore rules bzr < 0.9 always used.')
1502
def run(self, name_pattern=None, old_default_rules=None):
1660
def run(self, name_pattern_list=None, old_default_rules=None):
1503
1661
from bzrlib.atomicfile import AtomicFile
1504
1662
if old_default_rules is not None:
1505
1663
# dump the rules and exit
1506
1664
for pattern in ignores.OLD_DEFAULTS:
1509
if name_pattern is None:
1510
raise BzrCommandError("ignore requires a NAME_PATTERN")
1667
if not name_pattern_list:
1668
raise errors.BzrCommandError("ignore requires at least one "
1669
"NAME_PATTERN or --old-default-rules")
1670
for name_pattern in name_pattern_list:
1671
if name_pattern[0] == '/':
1672
raise errors.BzrCommandError(
1673
"NAME_PATTERN should not be an absolute path")
1511
1674
tree, relpath = WorkingTree.open_containing(u'.')
1512
1675
ifn = tree.abspath('.bzrignore')
1513
1676
if os.path.exists(ifn):
1597
1763
tgz .tar.gz, .tgz
1600
takes_args = ['dest']
1766
takes_args = ['dest', 'branch?']
1601
1767
takes_options = ['revision', 'format', 'root']
1602
def run(self, dest, revision=None, format=None, root=None):
1768
def run(self, dest, branch=None, revision=None, format=None, root=None):
1603
1769
from bzrlib.export import export
1604
tree = WorkingTree.open_containing(u'.')[0]
1772
tree = WorkingTree.open_containing(u'.')[0]
1775
b = Branch.open(branch)
1606
1777
if revision is None:
1607
1778
# should be tree.last_revision FIXME
1608
1779
rev_id = b.last_revision()
1610
1781
if len(revision) != 1:
1611
raise BzrError('bzr export --revision takes exactly 1 argument')
1782
raise errors.BzrCommandError('bzr export --revision takes exactly 1 argument')
1612
1783
rev_id = revision[0].in_history(b).rev_id
1613
1784
t = b.repository.revision_tree(rev_id)
1615
1786
export(t, dest, format, root)
1616
1787
except errors.NoSuchExportFormat, e:
1617
raise BzrCommandError('Unsupported export format: %s' % e.format)
1788
raise errors.BzrCommandError('Unsupported export format: %s' % e.format)
1620
1791
class cmd_cat(Command):
1621
1792
"""Write a file's text from a previous revision."""
1623
takes_options = ['revision']
1794
takes_options = ['revision', 'name-from-revision']
1624
1795
takes_args = ['filename']
1796
encoding_type = 'exact'
1626
1798
@display_command
1627
def run(self, filename, revision=None):
1799
def run(self, filename, revision=None, name_from_revision=False):
1628
1800
if revision is not None and len(revision) != 1:
1629
raise BzrCommandError("bzr cat --revision takes exactly one number")
1801
raise errors.BzrCommandError("bzr cat --revision takes exactly"
1632
1806
tree, relpath = WorkingTree.open_containing(filename)
1633
1807
b = tree.branch
1634
except NotBranchError:
1808
except (errors.NotBranchError, errors.NotLocalUrl):
1811
if revision is not None and revision[0].get_branch() is not None:
1812
b = Branch.open(revision[0].get_branch())
1637
1813
if tree is None:
1638
1814
b, relpath = Branch.open_containing(filename)
1815
tree = b.basis_tree()
1639
1816
if revision is None:
1640
1817
revision_id = b.last_revision()
1642
1819
revision_id = revision[0].in_history(b).rev_id
1643
b.print_file(relpath, revision_id)
1821
cur_file_id = tree.path2id(relpath)
1822
rev_tree = b.repository.revision_tree(revision_id)
1823
old_file_id = rev_tree.path2id(relpath)
1825
if name_from_revision:
1826
if old_file_id is None:
1827
raise errors.BzrCommandError("%r is not present in revision %s"
1828
% (filename, revision_id))
1830
rev_tree.print_file(old_file_id)
1831
elif cur_file_id is not None:
1832
rev_tree.print_file(cur_file_id)
1833
elif old_file_id is not None:
1834
rev_tree.print_file(old_file_id)
1836
raise errors.BzrCommandError("%r is not present in revision %s" %
1837
(filename, revision_id))
1646
1840
class cmd_local_time_offset(Command):
1700
1895
StrictCommitFailed)
1701
1896
from bzrlib.msgeditor import edit_commit_message, \
1702
1897
make_commit_message_template
1703
from tempfile import TemporaryFile
1705
1899
# TODO: Need a blackbox test for invoking the external editor; may be
1706
1900
# slightly problematic to run this cross-platform.
1708
1902
# TODO: do more checks that the commit will succeed before
1709
1903
# spending the user's valuable time typing a commit message.
1711
# TODO: if the commit *does* happen to fail, then save the commit
1712
# message to a temporary file where it can be recovered
1713
1904
tree, selected_list = tree_files(selected_list)
1714
1905
if selected_list == ['']:
1715
1906
# workaround - commit of root of tree should be exactly the same
1720
1911
if local and not tree.branch.get_bound_location():
1721
1912
raise errors.LocalRequiresBoundBranch()
1722
if message is None and not file:
1723
template = make_commit_message_template(tree, selected_list)
1724
message = edit_commit_message(template)
1726
raise BzrCommandError("please specify a commit message"
1727
" with either --message or --file")
1728
elif message and file:
1729
raise BzrCommandError("please specify either --message or --file")
1732
message = codecs.open(file, 'rt', bzrlib.user_encoding).read()
1735
raise BzrCommandError("empty commit message specified")
1914
def get_message(commit_obj):
1915
"""Callback to get commit message"""
1916
my_message = message
1917
if my_message is None and not file:
1918
template = make_commit_message_template(tree, selected_list)
1919
my_message = edit_commit_message(template)
1920
if my_message is None:
1921
raise errors.BzrCommandError("please specify a commit"
1922
" message with either --message or --file")
1923
elif my_message and file:
1924
raise errors.BzrCommandError(
1925
"please specify either --message or --file")
1927
my_message = codecs.open(file, 'rt',
1928
bzrlib.user_encoding).read()
1929
if my_message == "":
1930
raise errors.BzrCommandError("empty commit message specified")
1738
1934
reporter = ReportCommitToLog()
1740
1936
reporter = NullCommitReporter()
1743
tree.commit(message, specific_files=selected_list,
1939
tree.commit(message_callback=get_message,
1940
specific_files=selected_list,
1744
1941
allow_pointless=unchanged, strict=strict, local=local,
1745
1942
reporter=reporter)
1746
1943
except PointlessCommit:
1747
1944
# FIXME: This should really happen before the file is read in;
1748
1945
# perhaps prepare the commit; get the message; then actually commit
1749
raise BzrCommandError("no changes to commit."
1750
" use --unchanged to commit anyhow")
1946
raise errors.BzrCommandError("no changes to commit."
1947
" use --unchanged to commit anyhow")
1751
1948
except ConflictsInTree:
1752
raise BzrCommandError("Conflicts detected in working tree. "
1753
'Use "bzr conflicts" to list, "bzr resolve FILE" to resolve.')
1949
raise errors.BzrCommandError('Conflicts detected in working '
1950
'tree. Use "bzr conflicts" to list, "bzr resolve FILE" to'
1754
1952
except StrictCommitFailed:
1755
raise BzrCommandError("Commit refused because there are unknown "
1756
"files in the working tree.")
1953
raise errors.BzrCommandError("Commit refused because there are"
1954
" unknown files in the working tree.")
1757
1955
except errors.BoundBranchOutOfDate, e:
1758
raise BzrCommandError(str(e)
1759
+ ' Either unbind, update, or'
1760
' pass --local to commit.')
1956
raise errors.BzrCommandError(str(e) + "\n"
1957
'To commit to master branch, run update and then commit.\n'
1958
'You can also pass --local to commit to continue working '
1763
1962
class cmd_check(Command):
1890
2072
class cmd_selftest(Command):
1891
2073
"""Run internal test suite.
1893
This creates temporary test directories in the working directory,
1894
but not existing data is affected. These directories are deleted
1895
if the tests pass, or left behind to help in debugging if they
1896
fail and --keep-output is specified.
2075
This creates temporary test directories in the working directory, but not
2076
existing data is affected. These directories are deleted if the tests
2077
pass, or left behind to help in debugging if they fail and --keep-output
1898
If arguments are given, they are regular expressions that say
1899
which tests should run.
2080
If arguments are given, they are regular expressions that say which tests
2081
should run. Tests matching any expression are run, and other tests are
2084
Alternatively if --first is given, matching tests are run first and then
2085
all other tests are run. This is useful if you have been working in a
2086
particular area, but want to make sure nothing else was broken.
1901
2088
If the global option '--no-plugins' is given, plugins are not loaded
1902
2089
before running the selftests. This has two effects: features provided or
1903
2090
modified by plugins will not be tested, and tests provided by plugins will
1907
2094
bzr selftest ignore
2095
run only tests relating to 'ignore'
1908
2096
bzr --no-plugins selftest -v
2097
disable plugins and list tests as they're run
1910
2099
# TODO: --list should give a list of all available tests
1940
2129
Option('lsprof-timed',
1941
2130
help='generate lsprof output for benchmarked'
1942
2131
' sections of code.'),
2132
Option('cache-dir', type=str,
2133
help='a directory to cache intermediate'
2134
' benchmark steps'),
2135
Option('clean-output',
2136
help='clean temporary tests directories'
2137
' without running tests'),
2139
help='run all tests, but run specified tests first',
2142
encoding_type = 'replace'
1945
2144
def run(self, testspecs_list=None, verbose=None, one=False,
1946
2145
keep_output=False, transport=None, benchmark=None,
2146
lsprof_timed=None, cache_dir=None, clean_output=False,
1948
2148
import bzrlib.ui
1949
2149
from bzrlib.tests import selftest
1950
2150
import bzrlib.benchmarks as benchmarks
1951
# we don't want progress meters from the tests to go to the
1952
# real output; and we don't want log messages cluttering up
1954
save_ui = ui.ui_factory
2151
from bzrlib.benchmarks import tree_creator
2154
from bzrlib.tests import clean_selftest_output
2155
clean_selftest_output()
2158
if cache_dir is not None:
2159
tree_creator.TreeCreator.CACHE_ROOT = osutils.abspath(cache_dir)
1955
2160
print '%10s: %s' % ('bzr', osutils.realpath(sys.argv[0]))
1956
2161
print '%10s: %s' % ('bzrlib', bzrlib.__path__[0])
1958
info('running tests...')
2163
if testspecs_list is not None:
2164
pattern = '|'.join(testspecs_list)
2168
test_suite_factory = benchmarks.test_suite
2171
# TODO: should possibly lock the history file...
2172
benchfile = open(".perf_history", "at", buffering=1)
2174
test_suite_factory = None
1960
ui.ui_factory = ui.SilentUIFactory()
1961
if testspecs_list is not None:
1962
pattern = '|'.join(testspecs_list)
1966
test_suite_factory = benchmarks.test_suite
1970
test_suite_factory = None
1973
2179
result = selftest(verbose=verbose,
1974
2180
pattern=pattern,
1975
2181
stop_on_failure=one,
1976
2182
keep_output=keep_output,
1977
2183
transport=transport,
1978
2184
test_suite_factory=test_suite_factory,
1979
lsprof_timed=lsprof_timed)
1981
info('tests passed')
1983
info('tests failed')
1984
return int(not result)
2185
lsprof_timed=lsprof_timed,
2186
bench_history=benchfile,
2187
matching_tests_first=first,
1986
ui.ui_factory = save_ui
1989
def _get_bzr_branch():
1990
"""If bzr is run from a branch, return Branch or None"""
1991
from os.path import dirname
1994
branch = Branch.open(dirname(osutils.abspath(dirname(__file__))))
1996
except errors.BzrError:
2002
print "bzr (bazaar-ng) %s" % bzrlib.__version__
2003
# is bzrlib itself in a branch?
2004
branch = _get_bzr_branch()
2006
rh = branch.revision_history()
2008
print " bzr checkout, revision %d" % (revno,)
2009
print " nick: %s" % (branch.nick,)
2011
print " revid: %s" % (rh[-1],)
2012
print "Using python interpreter:", sys.executable
2014
print "Using python standard library:", os.path.dirname(site.__file__)
2015
print "Using bzrlib:",
2016
if len(bzrlib.__path__) > 1:
2017
# print repr, which is a good enough way of making it clear it's
2018
# more than one element (eg ['/foo/bar', '/foo/bzr'])
2019
print repr(bzrlib.__path__)
2021
print bzrlib.__path__[0]
2024
print bzrlib.__copyright__
2025
print "http://bazaar-vcs.org/"
2027
print "bzr comes with ABSOLUTELY NO WARRANTY. bzr is free software, and"
2028
print "you may use, modify and redistribute it under the terms of the GNU"
2029
print "General Public License version 2 or later."
2190
if benchfile is not None:
2193
info('tests passed')
2195
info('tests failed')
2196
return int(not result)
2032
2199
class cmd_version(Command):
2119
2287
takes_args = ['branch?']
2120
2288
takes_options = ['revision', 'force', 'merge-type', 'reprocess', 'remember',
2121
2289
Option('show-base', help="Show base revision text in "
2291
Option('uncommitted', help='Apply uncommitted changes'
2292
' from a working copy, instead of branch changes'),
2293
Option('pull', help='If the destination is already'
2294
' completely merged into the source, pull from the'
2295
' source rather than merging. When this happens,'
2296
' you do not need to commit the result.'),
2124
2299
def help(self):
2125
from merge import merge_type_help
2126
2300
from inspect import getdoc
2127
return getdoc(self) + '\n' + merge_type_help()
2301
return getdoc(self) + '\n' + _mod_merge.merge_type_help()
2129
2303
def run(self, branch=None, revision=None, force=False, merge_type=None,
2130
show_base=False, reprocess=False, remember=False):
2304
show_base=False, reprocess=False, remember=False,
2305
uncommitted=False, pull=False):
2131
2306
if merge_type is None:
2132
merge_type = Merge3Merger
2307
merge_type = _mod_merge.Merge3Merger
2134
2309
tree = WorkingTree.open_containing(u'.')[0]
2136
2311
if branch is not None:
2138
2313
reader = bundle.read_bundle_from_url(branch)
2314
except errors.NotABundle:
2140
2315
pass # Continue on considering this url a Branch
2142
2317
conflicts = merge_bundle(reader, tree, not force, merge_type,
2149
branch = self._get_remembered_parent(tree, branch, 'Merging from')
2324
if revision is None \
2325
or len(revision) < 1 or revision[0].needs_branch():
2326
branch = self._get_remembered_parent(tree, branch, 'Merging from')
2151
2328
if revision is None or len(revision) < 1:
2153
other = [branch, -1]
2331
other = [branch, None]
2334
other = [branch, -1]
2154
2335
other_branch, path = Branch.open_containing(branch)
2338
raise errors.BzrCommandError('Cannot use --uncommitted and'
2339
' --revision at the same time.')
2340
branch = revision[0].get_branch() or branch
2156
2341
if len(revision) == 1:
2157
2342
base = [None, None]
2158
2343
other_branch, path = Branch.open_containing(branch)
2162
2347
assert len(revision) == 2
2163
2348
if None in revision:
2164
raise BzrCommandError(
2165
"Merge doesn't permit that revision specifier.")
2166
other_branch, path = Branch.open_containing(branch)
2349
raise errors.BzrCommandError(
2350
"Merge doesn't permit empty revision specifier.")
2351
base_branch, path = Branch.open_containing(branch)
2352
branch1 = revision[1].get_branch() or branch
2353
other_branch, path1 = Branch.open_containing(branch1)
2354
if revision[0].get_branch() is not None:
2355
# then path was obtained from it, and is None.
2168
base = [branch, revision[0].in_history(other_branch).revno]
2169
other = [branch, revision[1].in_history(other_branch).revno]
2358
base = [branch, revision[0].in_history(base_branch).revno]
2359
other = [branch1, revision[1].in_history(other_branch).revno]
2171
2361
if tree.branch.get_parent() is None or remember:
2172
2362
tree.branch.set_parent(other_branch.base)
2244
2436
def help(self):
2245
from merge import merge_type_help
2246
2437
from inspect import getdoc
2247
return getdoc(self) + '\n' + merge_type_help()
2438
return getdoc(self) + '\n' + _mod_merge.merge_type_help()
2249
2440
def run(self, file_list=None, merge_type=None, show_base=False,
2250
2441
reprocess=False):
2251
from bzrlib.merge import merge_inner, transform_tree
2252
2442
if merge_type is None:
2253
merge_type = Merge3Merger
2443
merge_type = _mod_merge.Merge3Merger
2254
2444
tree, file_list = tree_files(file_list)
2255
2445
tree.lock_write()
2257
pending_merges = tree.pending_merges()
2258
if len(pending_merges) != 1:
2259
raise BzrCommandError("Sorry, remerge only works after normal"
2260
" merges. Not cherrypicking or"
2447
parents = tree.get_parent_ids()
2448
if len(parents) != 2:
2449
raise errors.BzrCommandError("Sorry, remerge only works after normal"
2450
" merges. Not cherrypicking or"
2262
2452
repository = tree.branch.repository
2263
base_revision = common_ancestor(tree.branch.last_revision(),
2264
pending_merges[0], repository)
2453
base_revision = common_ancestor(parents[0],
2454
parents[1], repository)
2265
2455
base_tree = repository.revision_tree(base_revision)
2266
other_tree = repository.revision_tree(pending_merges[0])
2456
other_tree = repository.revision_tree(parents[1])
2267
2457
interesting_ids = None
2268
2458
new_conflicts = []
2269
2459
conflicts = tree.conflicts()
2280
2470
for name, ie in tree.inventory.iter_entries(file_id):
2281
2471
interesting_ids.add(ie.file_id)
2282
2472
new_conflicts = conflicts.select_conflicts(tree, file_list)[0]
2283
transform_tree(tree, tree.basis_tree(), interesting_ids)
2474
# Remerge only supports resolving contents conflicts
2475
allowed_conflicts = ('text conflict', 'contents conflict')
2476
restore_files = [c.path for c in conflicts
2477
if c.typestring in allowed_conflicts]
2478
_mod_merge.transform_tree(tree, tree.basis_tree(), interesting_ids)
2284
2479
tree.set_conflicts(ConflictList(new_conflicts))
2285
if file_list is None:
2286
restore_files = list(tree.iter_conflicts())
2480
if file_list is not None:
2288
2481
restore_files = file_list
2289
2482
for filename in restore_files:
2291
2484
restore(tree.abspath(filename))
2292
except NotConflicted:
2485
except errors.NotConflicted:
2294
conflicts = merge_inner(tree.branch, other_tree, base_tree,
2296
interesting_ids=interesting_ids,
2297
other_rev_id=pending_merges[0],
2298
merge_type=merge_type,
2299
show_base=show_base,
2300
reprocess=reprocess)
2487
conflicts = _mod_merge.merge_inner(
2488
tree.branch, other_tree, base_tree,
2490
interesting_ids=interesting_ids,
2491
other_rev_id=parents[1],
2492
merge_type=merge_type,
2493
show_base=show_base,
2494
reprocess=reprocess)
2303
2497
if conflicts > 0:
2308
2503
class cmd_revert(Command):
2309
"""Reverse all changes since the last commit.
2311
Only versioned files are affected. Specify filenames to revert only
2312
those files. By default, any files that are changed will be backed up
2313
first. Backup files have a '~' appended to their name.
2504
"""Revert files to a previous revision.
2506
Giving a list of files will revert only those files. Otherwise, all files
2507
will be reverted. If the revision is not specified with '--revision', the
2508
last committed revision is used.
2510
To remove only some changes, without reverting to a prior version, use
2511
merge instead. For example, "merge . --r-2..-3" will remove the changes
2512
introduced by -2, without affecting the changes introduced by -1. Or
2513
to remove certain changes on a hunk-by-hunk basis, see the Shelf plugin.
2515
By default, any files that have been manually changed will be backed up
2516
first. (Files changed only by merge are not backed up.) Backup files have
2517
'.~#~' appended to their name, where # is a number.
2519
When you provide files, you can use their current pathname or the pathname
2520
from the target revision. So you can use revert to "undelete" a file by
2521
name. If you name a directory, all the contents of that directory will be
2315
2524
takes_options = ['revision', 'no-backup']
2316
2525
takes_args = ['file*']
2317
2526
aliases = ['merge-revert']
2319
2528
def run(self, revision=None, no_backup=False, file_list=None):
2320
from bzrlib.commands import parse_spec
2321
2529
if file_list is not None:
2322
2530
if len(file_list) == 0:
2323
raise BzrCommandError("No files specified")
2531
raise errors.BzrCommandError("No files specified")
2329
2537
# FIXME should be tree.last_revision
2330
2538
rev_id = tree.last_revision()
2331
2539
elif len(revision) != 1:
2332
raise BzrCommandError('bzr revert --revision takes exactly 1 argument')
2540
raise errors.BzrCommandError('bzr revert --revision takes exactly 1 argument')
2334
2542
rev_id = revision[0].in_history(tree.branch).rev_id
2335
2543
pb = ui.ui_factory.nested_progress_bar()
2337
2545
tree.revert(file_list,
2338
2546
tree.branch.repository.revision_tree(rev_id),
2547
not no_backup, pb, report_changes=True)
2344
2552
class cmd_assert_fail(Command):
2345
2553
"""Test reporting of assertion failures"""
2554
# intended just for use in testing
2348
assert False, "always fails"
2559
raise AssertionError("always fails")
2351
2562
class cmd_help(Command):
2352
2563
"""Show help on a command or other topic.
2354
For a list of all available commands, say 'bzr help commands'."""
2565
For a list of all available commands, say 'bzr help commands'.
2355
2567
takes_options = [Option('long', 'show help on all commands')]
2356
2568
takes_args = ['topic?']
2357
2569
aliases = ['?', '--help', '-?', '-h']
2359
2571
@display_command
2360
2572
def run(self, topic=None, long=False):
2362
2574
if topic is None and long:
2363
2575
topic = "commands"
2576
bzrlib.help.help(topic)
2367
2579
class cmd_shell_complete(Command):
2368
2580
"""Show appropriate completions for context.
2370
For a list of all available commands, say 'bzr shell-complete'."""
2582
For a list of all available commands, say 'bzr shell-complete'.
2371
2584
takes_args = ['context?']
2372
2585
aliases = ['s-c']
2542
2761
takes_args = ['filename']
2543
2762
takes_options = [Option('all', help='show annotations on all lines'),
2544
2763
Option('long', help='show date in annotations'),
2548
2768
@display_command
2549
def run(self, filename, all=False, long=False, revision=None):
2769
def run(self, filename, all=False, long=False, revision=None,
2550
2771
from bzrlib.annotate import annotate_file
2551
2772
tree, relpath = WorkingTree.open_containing(filename)
2552
2773
branch = tree.branch
2555
2776
if revision is None:
2556
2777
revision_id = branch.last_revision()
2557
2778
elif len(revision) != 1:
2558
raise BzrCommandError('bzr annotate --revision takes exactly 1 argument')
2779
raise errors.BzrCommandError('bzr annotate --revision takes exactly 1 argument')
2560
2781
revision_id = revision[0].in_history(branch).rev_id
2561
2782
file_id = tree.inventory.path2id(relpath)
2562
2783
tree = branch.repository.revision_tree(revision_id)
2563
2784
file_version = tree.inventory[file_id].revision
2564
annotate_file(branch, file_version, file_id, long, all, sys.stdout)
2785
annotate_file(branch, file_version, file_id, long, all, sys.stdout,
2566
2788
branch.unlock()
2577
2799
def run(self, revision_id_list=None, revision=None):
2578
2800
import bzrlib.gpg as gpg
2579
2801
if revision_id_list is not None and revision is not None:
2580
raise BzrCommandError('You can only supply one of revision_id or --revision')
2802
raise errors.BzrCommandError('You can only supply one of revision_id or --revision')
2581
2803
if revision_id_list is None and revision is None:
2582
raise BzrCommandError('You must supply either --revision or a revision_id')
2804
raise errors.BzrCommandError('You must supply either --revision or a revision_id')
2583
2805
b = WorkingTree.open_containing(u'.')[0].branch
2584
2806
gpg_strategy = gpg.GPGStrategy(b.get_config())
2585
2807
if revision_id_list is not None:
2972
class cmd_wait_until_signalled(Command):
2973
"""Test helper for test_start_and_stop_bzr_subprocess_send_signal.
2975
This just prints a line to signal when it is ready, then blocks on stdin.
2981
sys.stdout.write("running\n")
2983
sys.stdin.readline()
2986
class cmd_serve(Command):
2987
"""Run the bzr server."""
2989
aliases = ['server']
2993
help='serve on stdin/out for use from inetd or sshd'),
2995
help='listen for connections on nominated port of the form '
2996
'[hostname:]portnumber. Passing 0 as the port number will '
2997
'result in a dynamically allocated port.',
3000
help='serve contents of directory',
3002
Option('allow-writes',
3003
help='By default the server is a readonly server. Supplying '
3004
'--allow-writes enables write access to the contents of '
3005
'the served directory and below. '
3009
def run(self, port=None, inet=False, directory=None, allow_writes=False):
3010
from bzrlib.transport import smart
3011
from bzrlib.transport import get_transport
3012
if directory is None:
3013
directory = os.getcwd()
3014
url = urlutils.local_path_to_url(directory)
3015
if not allow_writes:
3016
url = 'readonly+' + url
3017
t = get_transport(url)
3019
server = smart.SmartServerPipeStreamMedium(sys.stdin, sys.stdout, t)
3020
elif port is not None:
3022
host, port = port.split(':')
3025
server = smart.SmartTCPServer(t, host=host, port=int(port))
3026
print 'listening on port: ', server.port
3029
raise errors.BzrCommandError("bzr serve requires one of --inet or --port")
2751
3033
# command-line interpretation helper for merge-related commands
2752
def merge(other_revision, base_revision,
2753
check_clean=True, ignore_zero=False,
2754
this_dir=None, backup_files=False, merge_type=Merge3Merger,
2755
file_list=None, show_base=False, reprocess=False,
2756
pb=DummyProgress()):
3034
def _merge_helper(other_revision, base_revision,
3035
check_clean=True, ignore_zero=False,
3036
this_dir=None, backup_files=False,
3038
file_list=None, show_base=False, reprocess=False,
3040
pb=DummyProgress()):
2757
3041
"""Merge changes into a tree.
2781
3065
clients might prefer to call merge.merge_inner(), which has less magic
2784
from bzrlib.merge import Merger
3068
# Loading it late, so that we don't always have to import bzrlib.merge
3069
if merge_type is None:
3070
merge_type = _mod_merge.Merge3Merger
2785
3071
if this_dir is None:
2786
3072
this_dir = u'.'
2787
3073
this_tree = WorkingTree.open_containing(this_dir)[0]
2788
if show_base and not merge_type is Merge3Merger:
2789
raise BzrCommandError("Show-base is not supported for this merge"
2790
" type. %s" % merge_type)
3074
if show_base and not merge_type is _mod_merge.Merge3Merger:
3075
raise errors.BzrCommandError("Show-base is not supported for this merge"
3076
" type. %s" % merge_type)
2791
3077
if reprocess and not merge_type.supports_reprocess:
2792
raise BzrCommandError("Conflict reduction is not supported for merge"
2793
" type %s." % merge_type)
3078
raise errors.BzrCommandError("Conflict reduction is not supported for merge"
3079
" type %s." % merge_type)
2794
3080
if reprocess and show_base:
2795
raise BzrCommandError("Cannot do conflict reduction and show base.")
3081
raise errors.BzrCommandError("Cannot do conflict reduction and show base.")
2797
merger = Merger(this_tree.branch, this_tree=this_tree, pb=pb)
3083
merger = _mod_merge.Merger(this_tree.branch, this_tree=this_tree,
2798
3085
merger.pp = ProgressPhase("Merge phase", 5, pb)
2799
3086
merger.pp.next_phase()
2800
3087
merger.check_basis(check_clean)