~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/builtins.py

  • Committer: Jelmer Vernooij
  • Date: 2009-02-23 20:55:58 UTC
  • mfrom: (4034 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4053.
  • Revision ID: jelmer@samba.org-20090223205558-1cx2k4w1zgs8r5qa
Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
46
46
    tree as _mod_tree,
47
47
    ui,
48
48
    urlutils,
 
49
    views,
49
50
    )
50
51
from bzrlib.branch import Branch
51
52
from bzrlib.conflicts import ConflictList
65
66
from bzrlib.trace import mutter, note, warning, is_quiet, get_verbosity_level
66
67
 
67
68
 
68
 
def tree_files(file_list, default_branch=u'.', canonicalize=True):
 
69
def tree_files(file_list, default_branch=u'.', canonicalize=True,
 
70
    apply_view=True):
69
71
    try:
70
 
        return internal_tree_files(file_list, default_branch, canonicalize)
 
72
        return internal_tree_files(file_list, default_branch, canonicalize,
 
73
            apply_view)
71
74
    except errors.FileInWrongBranch, e:
72
75
        raise errors.BzrCommandError("%s is not in the same branch as %s" %
73
76
                                     (e.path, file_list[0]))
74
77
 
75
78
 
 
79
def tree_files_for_add(file_list):
 
80
    """Add handles files a bit differently so it a custom implementation."""
 
81
    if file_list:
 
82
        tree = WorkingTree.open_containing(file_list[0])[0]
 
83
        if tree.supports_views():
 
84
            view_files = tree.views.lookup_view()
 
85
            for filename in file_list:
 
86
                if not osutils.is_inside_any(view_files, filename):
 
87
                    raise errors.FileOutsideView(filename, view_files)
 
88
    else:
 
89
        tree = WorkingTree.open_containing(u'.')[0]
 
90
        if tree.supports_views():
 
91
            view_files = tree.views.lookup_view()
 
92
            if view_files:
 
93
                file_list = view_files
 
94
                view_str = views.view_display_str(view_files)
 
95
                note("ignoring files outside view: %s" % view_str)
 
96
    return tree, file_list
 
97
 
 
98
 
76
99
def _get_one_revision(command_name, revisions):
77
100
    if revisions is None:
78
101
        return None
99
122
 
100
123
# XXX: Bad function name; should possibly also be a class method of
101
124
# WorkingTree rather than a function.
102
 
def internal_tree_files(file_list, default_branch=u'.', canonicalize=True):
 
125
def internal_tree_files(file_list, default_branch=u'.', canonicalize=True,
 
126
    apply_view=True):
103
127
    """Convert command-line paths to a WorkingTree and relative paths.
104
128
 
105
129
    This is typically used for command-line processors that take one or
107
131
 
108
132
    The filenames given are not required to exist.
109
133
 
110
 
    :param file_list: Filenames to convert.  
 
134
    :param file_list: Filenames to convert.
111
135
 
112
136
    :param default_branch: Fallback tree path to use if file_list is empty or
113
137
        None.
114
138
 
 
139
    :param apply_view: if True and a view is set, apply it or check that
 
140
        specified files are within it
 
141
 
115
142
    :return: workingtree, [relative_paths]
116
143
    """
117
144
    if file_list is None or len(file_list) == 0:
118
 
        return WorkingTree.open_containing(default_branch)[0], file_list
 
145
        tree = WorkingTree.open_containing(default_branch)[0]
 
146
        if tree.supports_views() and apply_view:
 
147
            view_files = tree.views.lookup_view()
 
148
            if view_files:
 
149
                file_list = view_files
 
150
                view_str = views.view_display_str(view_files)
 
151
                note("ignoring files outside view: %s" % view_str)
 
152
        return tree, file_list
119
153
    tree = WorkingTree.open_containing(osutils.realpath(file_list[0]))[0]
120
 
    return tree, safe_relpath_files(tree, file_list, canonicalize)
121
 
 
122
 
 
123
 
def safe_relpath_files(tree, file_list, canonicalize=True):
 
154
    return tree, safe_relpath_files(tree, file_list, canonicalize,
 
155
        apply_view=apply_view)
 
156
 
 
157
 
 
158
def safe_relpath_files(tree, file_list, canonicalize=True, apply_view=True):
124
159
    """Convert file_list into a list of relpaths in tree.
125
160
 
126
161
    :param tree: A tree to operate on.
127
162
    :param file_list: A list of user provided paths or None.
 
163
    :param apply_view: if True and a view is set, apply it or check that
 
164
        specified files are within it
128
165
    :return: A list of relative paths.
129
166
    :raises errors.PathNotChild: When a provided path is in a different tree
130
167
        than tree.
131
168
    """
132
169
    if file_list is None:
133
170
        return None
 
171
    if tree.supports_views() and apply_view:
 
172
        view_files = tree.views.lookup_view()
 
173
    else:
 
174
        view_files = []
134
175
    new_list = []
135
176
    # tree.relpath exists as a "thunk" to osutils, but canonical_relpath
136
177
    # doesn't - fix that up here before we enter the loop.
140
181
        fixer = tree.relpath
141
182
    for filename in file_list:
142
183
        try:
143
 
            new_list.append(fixer(osutils.dereference_path(filename)))
 
184
            relpath = fixer(osutils.dereference_path(filename))
 
185
            if  view_files and not osutils.is_inside_any(view_files, relpath):
 
186
                raise errors.FileOutsideView(filename, view_files)
 
187
            new_list.append(relpath)
144
188
        except errors.PathNotChild:
145
189
            raise errors.FileInWrongBranch(tree.branch, filename)
146
190
    return new_list
147
191
 
148
192
 
 
193
def _get_view_info_for_change_reporter(tree):
 
194
    """Get the view information from a tree for change reporting."""
 
195
    view_info = None
 
196
    try:
 
197
        current_view = tree.views.get_view_info()[0]
 
198
        if current_view is not None:
 
199
            view_info = (current_view, tree.views.lookup_view())
 
200
    except errors.ViewsNotSupported:
 
201
        pass
 
202
    return view_info
 
203
 
 
204
 
149
205
# TODO: Make sure no commands unconditionally use the working directory as a
150
206
# branch.  If a filename argument is used, the first of them should be used to
151
207
# specify the branch.  (Perhaps this can be factored out into some kind of
181
237
 
182
238
    To see ignored files use 'bzr ignored'.  For details on the
183
239
    changes to file texts, use 'bzr diff'.
184
 
    
 
240
 
185
241
    Note that --short or -S gives status flags for each item, similar
186
242
    to Subversion's status command. To get output similar to svn -q,
187
243
    use bzr status -SV.
199
255
    If a revision argument is given, the status is calculated against
200
256
    that revision, or between two revisions if two are provided.
201
257
    """
202
 
    
 
258
 
203
259
    # TODO: --no-recurse, --recurse options
204
 
    
 
260
 
205
261
    takes_args = ['file*']
206
262
    takes_options = ['show-ids', 'revision', 'change', 'verbose',
207
263
                     Option('short', help='Use short status indicators.',
215
271
 
216
272
    encoding_type = 'replace'
217
273
    _see_also = ['diff', 'revert', 'status-flags']
218
 
    
 
274
 
219
275
    @display_command
220
276
    def run(self, show_ids=False, file_list=None, revision=None, short=False,
221
277
            versioned=False, no_pending=False, verbose=False):
243
299
 
244
300
class cmd_cat_revision(Command):
245
301
    """Write out metadata for a revision.
246
 
    
 
302
 
247
303
    The revision to print can either be specified by a specific
248
304
    revision identifier, or you can use --revision.
249
305
    """
253
309
    takes_options = ['revision']
254
310
    # cat-revision is more for frontends so should be exact
255
311
    encoding = 'strict'
256
 
    
 
312
 
257
313
    @display_command
258
314
    def run(self, revision_id=None, revision=None):
259
315
        if revision_id is not None and revision is not None:
374
430
 
375
431
    def run(self, location='.', force=False):
376
432
        d = bzrdir.BzrDir.open(location)
377
 
        
 
433
 
378
434
        try:
379
435
            working = d.open_workingtree()
380
436
        except errors.NoWorkingTree:
392
448
        if working_path != branch_path:
393
449
            raise errors.BzrCommandError("You cannot remove the working tree from "
394
450
                                         "a lightweight checkout")
395
 
        
 
451
 
396
452
        d.destroy_workingtree()
397
 
        
 
453
 
398
454
 
399
455
class cmd_revno(Command):
400
456
    """Show current revision number.
450
506
                revno = '.'.join(str(i) for i in dotted_map[revision_id])
451
507
            print '%s %s' % (revno, revision_id)
452
508
 
453
 
    
 
509
 
454
510
class cmd_add(Command):
455
511
    """Add specified files or directories.
456
512
 
474
530
    you should never need to explicitly add a directory, they'll just
475
531
    get added when you add a file in the directory.
476
532
 
477
 
    --dry-run will show which files would be added, but not actually 
 
533
    --dry-run will show which files would be added, but not actually
478
534
    add them.
479
535
 
480
536
    --file-ids-from will try to use the file ids from the supplied path.
523
579
            base_tree.lock_read()
524
580
        try:
525
581
            file_list = self._maybe_expand_globs(file_list)
526
 
            if file_list:
527
 
                tree = WorkingTree.open_containing(file_list[0])[0]
528
 
            else:
529
 
                tree = WorkingTree.open_containing(u'.')[0]
 
582
            tree, file_list = tree_files_for_add(file_list)
530
583
            added, ignored = tree.smart_add(file_list, not
531
584
                no_recurse, action=action, save=not dry_run)
532
585
        finally:
538
591
            if verbose:
539
592
                for glob in sorted(ignored.keys()):
540
593
                    for path in ignored[glob]:
541
 
                        self.outf.write("ignored %s matching \"%s\"\n" 
 
594
                        self.outf.write("ignored %s matching \"%s\"\n"
542
595
                                        % (path, glob))
543
596
            else:
544
597
                match_len = 0
571
624
 
572
625
    takes_args = ['filename']
573
626
    hidden = True
574
 
    
 
627
 
575
628
    @display_command
576
629
    def run(self, filename):
577
630
        # TODO: jam 20050106 Can relpath return a munged path if
748
801
                        # pathjoin with an empty tail adds a slash, which breaks
749
802
                        # relpath :(
750
803
                        dest_parent_fq = tree.basedir
751
 
    
 
804
 
752
805
                    dest_tail = osutils.canonical_relpath(
753
806
                                    dest_parent_fq,
754
807
                                    osutils.pathjoin(dest_parent_fq, spec_tail))
859
912
        branch_to.lock_write()
860
913
        try:
861
914
            if tree_to is not None:
 
915
                view_info = _get_view_info_for_change_reporter(tree_to)
862
916
                change_reporter = delta._ChangeReporter(
863
 
                    unversioned_filter=tree_to.is_ignored)
 
917
                    unversioned_filter=tree_to.is_ignored, view_info=view_info)
864
918
                result = tree_to.pull(branch_from, overwrite, revision_id,
865
919
                                      change_reporter,
866
920
                                      possible_transports=possible_transports)
877
931
 
878
932
class cmd_push(Command):
879
933
    """Update a mirror of this branch.
880
 
    
 
934
 
881
935
    The target branch will not have its working tree populated because this
882
936
    is both expensive, and is not supported on remote file systems.
883
 
    
 
937
 
884
938
    Some smart servers or protocols *may* put the working tree in place in
885
939
    the future.
886
940
 
890
944
 
891
945
    If branches have diverged, you can use 'bzr push --overwrite' to replace
892
946
    the other branch completely, discarding its unmerged changes.
893
 
    
 
947
 
894
948
    If you want to ensure you have the different changes in the other branch,
895
949
    do a merge (see bzr help merge) from the other branch, and commit that.
896
950
    After that you will be able to do a push without '--overwrite'.
1073
1127
    the branch found in '.'. This is useful if you have removed the working tree
1074
1128
    or if it was never created - i.e. if you pushed the branch to its current
1075
1129
    location using SFTP.
1076
 
    
 
1130
 
1077
1131
    If the TO_LOCATION is omitted, the last component of the BRANCH_LOCATION will
1078
1132
    be used.  In other words, "checkout ../foo/bar" will attempt to create ./bar.
1079
1133
    If the BRANCH_LOCATION has no / or path separator embedded, the TO_LOCATION
1121
1175
            revision_id = None
1122
1176
        if to_location is None:
1123
1177
            to_location = urlutils.derive_to_location(branch_location)
1124
 
        # if the source and to_location are the same, 
 
1178
        # if the source and to_location are the same,
1125
1179
        # and there is no working tree,
1126
1180
        # then reconstitute a branch
1127
1181
        if (osutils.abspath(to_location) ==
1173
1227
 
1174
1228
class cmd_update(Command):
1175
1229
    """Update a tree to have the latest code committed to its branch.
1176
 
    
 
1230
 
1177
1231
    This will perform a merge into the working tree, and may generate
1178
 
    conflicts. If you have any local changes, you will still 
 
1232
    conflicts. If you have any local changes, you will still
1179
1233
    need to commit them after the update for the update to be complete.
1180
 
    
1181
 
    If you want to discard your local changes, you can just do a 
 
1234
 
 
1235
    If you want to discard your local changes, you can just do a
1182
1236
    'bzr revert' instead of 'bzr commit' after the update.
1183
1237
    """
1184
1238
 
1206
1260
                    revno = tree.branch.revision_id_to_revno(last_rev)
1207
1261
                    note("Tree is up to date at revision %d." % (revno,))
1208
1262
                    return 0
 
1263
            view_info = _get_view_info_for_change_reporter(tree)
1209
1264
            conflicts = tree.update(
1210
 
                delta._ChangeReporter(unversioned_filter=tree.is_ignored),
1211
 
                possible_transports=possible_transports)
 
1265
                delta._ChangeReporter(unversioned_filter=tree.is_ignored,
 
1266
                view_info=view_info), possible_transports=possible_transports)
1212
1267
            revno = tree.branch.revision_id_to_revno(
1213
1268
                _mod_revision.ensure_null(tree.last_revision()))
1214
1269
            note('Updated to revision %d.' % (revno,))
1353
1408
 
1354
1409
    This can correct data mismatches that may have been caused by
1355
1410
    previous ghost operations or bzr upgrades. You should only
1356
 
    need to run this command if 'bzr check' or a bzr developer 
 
1411
    need to run this command if 'bzr check' or a bzr developer
1357
1412
    advises you to run it.
1358
1413
 
1359
1414
    If a second branch is provided, cross-branch reconciliation is
1361
1416
    id which was not present in very early bzr versions is represented
1362
1417
    correctly in both branches.
1363
1418
 
1364
 
    At the same time it is run it may recompress data resulting in 
 
1419
    At the same time it is run it may recompress data resulting in
1365
1420
    a potential saving in disk space or performance gain.
1366
1421
 
1367
1422
    The branch *MUST* be on a listable system such as local disk or sftp.
1423
1478
    Use this to create an empty branch, or before importing an
1424
1479
    existing project.
1425
1480
 
1426
 
    If there is a repository in a parent directory of the location, then 
 
1481
    If there is a repository in a parent directory of the location, then
1427
1482
    the history of the branch will be stored in the repository.  Otherwise
1428
1483
    init creates a standalone branch which carries its own history
1429
1484
    in the .bzr directory.
1582
1637
 
1583
1638
class cmd_diff(Command):
1584
1639
    """Show differences in the working tree, between revisions or branches.
1585
 
    
 
1640
 
1586
1641
    If no arguments are given, all changes for the current tree are listed.
1587
1642
    If files are given, only the changes in those files are listed.
1588
1643
    Remote and multiple branches can be compared by using the --old and
1687
1742
                                         ' one or two revision specifiers')
1688
1743
 
1689
1744
        old_tree, new_tree, specific_files, extra_trees = \
1690
 
                _get_trees_to_diff(file_list, revision, old, new)
1691
 
        return show_diff_trees(old_tree, new_tree, sys.stdout, 
 
1745
                _get_trees_to_diff(file_list, revision, old, new,
 
1746
                apply_view=True)
 
1747
        return show_diff_trees(old_tree, new_tree, sys.stdout,
1692
1748
                               specific_files=specific_files,
1693
1749
                               external_diff_options=diff_options,
1694
1750
                               old_label=old_label, new_label=new_label,
1822
1878
 
1823
1879
 
1824
1880
class cmd_log(Command):
1825
 
    """Show log of a branch, file, or directory.
1826
 
 
1827
 
    By default show the log of the branch containing the working directory.
1828
 
 
1829
 
    To request a range of logs, you can use the command -r begin..end
1830
 
    -r revision requests a specific revision, -r ..end or -r begin.. are
1831
 
    also valid.
1832
 
 
1833
 
    :Examples:
1834
 
        Log the current branch::
1835
 
 
1836
 
            bzr log
1837
 
 
1838
 
        Log a file::
1839
 
 
1840
 
            bzr log foo.c
1841
 
 
1842
 
        Log the last 10 revisions of a branch::
1843
 
 
1844
 
            bzr log -r -10.. http://server/branch
 
1881
    """Show historical log for a branch or subset of a branch.
 
1882
 
 
1883
    log is bzr's default tool for exploring the history of a branch.
 
1884
    The branch to use is taken from the first parameter. If no parameters
 
1885
    are given, the branch containing the working directory is logged.
 
1886
    Here are some simple examples::
 
1887
 
 
1888
      bzr log                       log the current branch
 
1889
      bzr log foo.py                log a file in its branch
 
1890
      bzr log http://server/branch  log a branch on a server
 
1891
 
 
1892
    The filtering, ordering and information shown for each revision can
 
1893
    be controlled as explained below. By default, all revisions are
 
1894
    shown sorted (topologically) so that newer revisions appear before
 
1895
    older ones and descendants always appear before ancestors. If displayed,
 
1896
    merged revisions are shown indented under the revision in which they
 
1897
    were merged.
 
1898
 
 
1899
    :Output control:
 
1900
 
 
1901
      The log format controls how information about each revision is
 
1902
      displayed. The standard log formats are called ``long``, ``short``
 
1903
      and ``line``. The default is long. See ``bzr help log-formats``
 
1904
      for more details on log formats.
 
1905
 
 
1906
      The following options can be used to control what information is
 
1907
      displayed::
 
1908
 
 
1909
        -l N        display a maximum of N revisions
 
1910
        -n N        display N levels of revisions (0 for all, 1 for collapsed)
 
1911
        -v          display a status summary (delta) for each revision
 
1912
        -p          display a diff (patch) for each revision
 
1913
        --show-ids  display revision-ids (and file-ids), not just revnos
 
1914
 
 
1915
      Note that the default number of levels to display is a function of the
 
1916
      log format. If the -n option is not used, ``short`` and ``line`` show
 
1917
      just the top level (mainline) while ``long`` shows all levels of merged
 
1918
      revisions.
 
1919
 
 
1920
      Status summaries are shown using status flags like A, M, etc. To see
 
1921
      the changes explained using words like ``added`` and ``modified``
 
1922
      instead, use the -vv option.
 
1923
 
 
1924
    :Ordering control:
 
1925
 
 
1926
      To display revisions from oldest to newest, use the --forward option.
 
1927
      In most cases, using this option will have little impact on the total
 
1928
      time taken to produce a log, though --forward does not incrementally
 
1929
      display revisions like --reverse does when it can.
 
1930
 
 
1931
    :Revision filtering:
 
1932
 
 
1933
      The -r option can be used to specify what revision or range of revisions
 
1934
      to filter against. The various forms are shown below::
 
1935
 
 
1936
        -rX      display revision X
 
1937
        -rX..    display revision X and later
 
1938
        -r..Y    display up to and including revision Y
 
1939
        -rX..Y   display from X to Y inclusive
 
1940
 
 
1941
      See ``bzr help revisionspec`` for details on how to specify X and Y.
 
1942
      Some common examples are given below::
 
1943
 
 
1944
        -r-1                show just the tip
 
1945
        -r-10..             show the last 10 mainline revisions
 
1946
        -rsubmit:..         show what's new on this branch
 
1947
        -rancestor:path..   show changes since the common ancestor of this
 
1948
                            branch and the one at location path
 
1949
        -rdate:yesterday..  show changes since yesterday
 
1950
 
 
1951
      When logging a range of revisions using -rX..Y, log starts at
 
1952
      revision Y and searches back in history through the primary
 
1953
      ("left-hand") parents until it finds X. When logging just the
 
1954
      top level (using -n1), an error is reported if X is not found
 
1955
      along the way. If multi-level logging is used (-n0), X may be
 
1956
      a nested merge revision and the log will be truncated accordingly.
 
1957
 
 
1958
    :Path filtering:
 
1959
 
 
1960
      If a parameter is given and it's not a branch, the log will be filtered
 
1961
      to show only those revisions that changed the nominated file or
 
1962
      directory.
 
1963
 
 
1964
      Filenames are interpreted within their historical context. To log a
 
1965
      deleted file, specify a revision range so that the file existed at
 
1966
      the end or start of the range.
 
1967
 
 
1968
      Historical context is also important when interpreting pathnames of
 
1969
      renamed files/directories. Consider the following example:
 
1970
 
 
1971
      * revision 1: add tutorial.txt
 
1972
      * revision 2: modify tutorial.txt
 
1973
      * revision 3: rename tutorial.txt to guide.txt; add tutorial.txt
 
1974
 
 
1975
      In this case:
 
1976
 
 
1977
      * ``bzr log guide.txt`` will log the file added in revision 1
 
1978
 
 
1979
      * ``bzr log tutorial.txt`` will log the new file added in revision 3
 
1980
 
 
1981
      * ``bzr log -r2 -p tutorial.txt`` will show the changes made to
 
1982
        the original file in revision 2.
 
1983
 
 
1984
      * ``bzr log -r2 -p guide.txt`` will display an error message as there
 
1985
        was no file called guide.txt in revision 2.
 
1986
 
 
1987
      Renames are always followed by log. By design, there is no need to
 
1988
      explicitly ask for this (and no way to stop logging a file back
 
1989
      until it was last renamed).
 
1990
 
 
1991
      Note: If the path is a directory, only revisions that directly changed
 
1992
      that directory object are currently shown. This is considered a bug.
 
1993
      (Support for filtering against multiple files and for files within a
 
1994
      directory is under development.)
 
1995
 
 
1996
    :Other filtering:
 
1997
 
 
1998
      The --message option can be used for finding revisions that match a
 
1999
      regular expression in a commit message.
 
2000
 
 
2001
    :Tips & tricks:
 
2002
 
 
2003
      GUI tools and IDEs are often better at exploring history than command
 
2004
      line tools. You may prefer qlog or glog from the QBzr and Bzr-Gtk packages
 
2005
      respectively for example. (TortoiseBzr uses qlog for displaying logs.) See
 
2006
      http://bazaar-vcs.org/BzrPlugins and http://bazaar-vcs.org/IDEIntegration.
 
2007
 
 
2008
      Web interfaces are often better at exploring history than command line
 
2009
      tools, particularly for branches on servers. You may prefer Loggerhead
 
2010
      or one of its alternatives. See http://bazaar-vcs.org/WebInterface.
 
2011
 
 
2012
      You may find it useful to add the aliases below to ``bazaar.conf``::
 
2013
 
 
2014
        [ALIASES]
 
2015
        tip = log -r-1 -n1
 
2016
        top = log -r-10.. --short --forward
 
2017
        show = log -v -p -n1 --long
 
2018
 
 
2019
      ``bzr tip`` will then show the latest revision while ``bzr top``
 
2020
      will show the last 10 mainline revisions. To see the details of a
 
2021
      particular revision X,  ``bzr show -rX``.
 
2022
 
 
2023
      As many GUI tools and Web interfaces do, you may prefer viewing
 
2024
      history collapsed initially. If you are interested in looking deeper
 
2025
      into a particular merge X, use ``bzr log -n0 -rX``. If you like
 
2026
      working this way, you may wish to either:
 
2027
 
 
2028
      * change your default log format to short (or line)
 
2029
      * add this alias: log = log -n1
 
2030
 
 
2031
      ``bzr log -v`` on a branch with lots of history is currently
 
2032
      very slow. A fix for this issue is currently under development.
 
2033
      With or without that fix, it is recommended that a revision range
 
2034
      be given when using the -v option.
 
2035
 
 
2036
      bzr has a generic full-text matching plugin, bzr-search, that can be
 
2037
      used to find revisions matching user names, commit messages, etc.
 
2038
      Among other features, this plugin can find all revisions containing
 
2039
      a list of words but not others.
 
2040
 
 
2041
      When exploring non-mainline history on large projects with deep
 
2042
      history, the performance of log can be greatly improved by installing
 
2043
      the revnocache plugin. This plugin buffers historical information
 
2044
      trading disk space for faster speed.
1845
2045
    """
1846
 
 
1847
 
    # TODO: Make --revision support uuid: and hash: [future tag:] notation.
1848
 
 
1849
2046
    takes_args = ['location?']
 
2047
    _see_also = ['log-formats', 'revisionspec']
1850
2048
    takes_options = [
1851
2049
            Option('forward',
1852
2050
                   help='Show from oldest to newest.'),
1921
2119
                        location)
1922
2120
        else:
1923
2121
            # local dir only
1924
 
            # FIXME ? log the current subdir only RBC 20060203 
 
2122
            # FIXME ? log the current subdir only RBC 20060203
1925
2123
            if revision is not None \
1926
2124
                    and len(revision) > 0 and revision[0].get_branch():
1927
2125
                location = revision[0].get_branch()
2148
2346
    using this command or directly by using an editor, be sure to commit
2149
2347
    it.
2150
2348
 
2151
 
    Note: ignore patterns containing shell wildcards must be quoted from 
 
2349
    Note: ignore patterns containing shell wildcards must be quoted from
2152
2350
    the shell on Unix.
2153
2351
 
2154
2352
    :Examples:
2179
2377
        Option('old-default-rules',
2180
2378
               help='Write out the ignore rules bzr < 0.9 always used.')
2181
2379
        ]
2182
 
    
 
2380
 
2183
2381
    def run(self, name_pattern_list=None, old_default_rules=None):
2184
2382
        from bzrlib import ignores
2185
2383
        if old_default_rules is not None:
2190
2388
        if not name_pattern_list:
2191
2389
            raise errors.BzrCommandError("ignore requires at least one "
2192
2390
                                  "NAME_PATTERN or --old-default-rules")
2193
 
        name_pattern_list = [globbing.normalize_pattern(p) 
 
2391
        name_pattern_list = [globbing.normalize_pattern(p)
2194
2392
                             for p in name_pattern_list]
2195
2393
        for name_pattern in name_pattern_list:
2196
 
            if (name_pattern[0] == '/' or 
 
2394
            if (name_pattern[0] == '/' or
2197
2395
                (len(name_pattern) > 1 and name_pattern[1] == ':')):
2198
2396
                raise errors.BzrCommandError(
2199
2397
                    "NAME_PATTERN should not be an absolute path")
2251
2449
    """
2252
2450
    hidden = True
2253
2451
    takes_args = ['revno']
2254
 
    
 
2452
 
2255
2453
    @display_command
2256
2454
    def run(self, revno):
2257
2455
        try:
2325
2523
    If no revision is nominated, the last revision is used.
2326
2524
 
2327
2525
    Note: Take care to redirect standard output when using this command on a
2328
 
    binary file. 
 
2526
    binary file.
2329
2527
    """
2330
2528
 
2331
2529
    _see_also = ['ls']
2378
2576
 
2379
2577
class cmd_local_time_offset(Command):
2380
2578
    """Show the offset in seconds from GMT to local time."""
2381
 
    hidden = True    
 
2579
    hidden = True
2382
2580
    @display_command
2383
2581
    def run(self):
2384
2582
        print osutils.local_time_offset()
2387
2585
 
2388
2586
class cmd_commit(Command):
2389
2587
    """Commit changes into a new revision.
2390
 
    
 
2588
 
2391
2589
    If no arguments are given, the entire tree is committed.
2392
2590
 
2393
2591
    If selected files are specified, only changes to those files are
2394
 
    committed.  If a directory is specified then the directory and everything 
 
2592
    committed.  If a directory is specified then the directory and everything
2395
2593
    within it is committed.
2396
2594
 
2397
2595
    When excludes are given, they take precedence over selected files.
2506
2704
        # TODO: Need a blackbox test for invoking the external editor; may be
2507
2705
        # slightly problematic to run this cross-platform.
2508
2706
 
2509
 
        # TODO: do more checks that the commit will succeed before 
 
2707
        # TODO: do more checks that the commit will succeed before
2510
2708
        # spending the user's valuable time typing a commit message.
2511
2709
 
2512
2710
        properties = {}
2535
2733
                        selected_list, diff=show_diff,
2536
2734
                        output_encoding=osutils.get_user_encoding())
2537
2735
                start_message = generate_commit_message_template(commit_obj)
2538
 
                my_message = edit_commit_message_encoded(t, 
 
2736
                my_message = edit_commit_message_encoded(t,
2539
2737
                    start_message=start_message)
2540
2738
                if my_message is None:
2541
2739
                    raise errors.BzrCommandError("please specify a commit"
2665
2863
 
2666
2864
class cmd_whoami(Command):
2667
2865
    """Show or set bzr user id.
2668
 
    
 
2866
 
2669
2867
    :Examples:
2670
2868
        Show the email of the current user::
2671
2869
 
2683
2881
                    ]
2684
2882
    takes_args = ['name?']
2685
2883
    encoding_type = 'replace'
2686
 
    
 
2884
 
2687
2885
    @display_command
2688
2886
    def run(self, email=False, branch=False, name=None):
2689
2887
        if name is None:
2704
2902
        except errors.NoEmailInUsername, e:
2705
2903
            warning('"%s" does not seem to contain an email address.  '
2706
2904
                    'This is allowed, but not recommended.', name)
2707
 
        
 
2905
 
2708
2906
        # use global config unless --branch given
2709
2907
        if branch:
2710
2908
            c = Branch.open_containing('.')[0].get_config()
2809
3007
 
2810
3008
class cmd_selftest(Command):
2811
3009
    """Run internal test suite.
2812
 
    
 
3010
 
2813
3011
    If arguments are given, they are regular expressions that say which tests
2814
3012
    should run.  Tests matching any expression are run, and other tests are
2815
3013
    not run.
2838
3036
    modified by plugins will not be tested, and tests provided by plugins will
2839
3037
    not be run.
2840
3038
 
2841
 
    Tests that need working space on disk use a common temporary directory, 
 
3039
    Tests that need working space on disk use a common temporary directory,
2842
3040
    typically inside $TMPDIR or /tmp.
2843
3041
 
2844
3042
    :Examples:
2912
3110
                     ]
2913
3111
    encoding_type = 'replace'
2914
3112
 
 
3113
    def __init__(self):
 
3114
        Command.__init__(self)
 
3115
        self.additional_selftest_args = {}
 
3116
 
2915
3117
    def run(self, testspecs_list=None, verbose=False, one=False,
2916
3118
            transport=None, benchmark=None,
2917
3119
            lsprof_timed=None, cache_dir=None,
2949
3151
            test_suite_factory = None
2950
3152
            benchfile = None
2951
3153
        try:
2952
 
            result = selftest(verbose=verbose,
2953
 
                              pattern=pattern,
2954
 
                              stop_on_failure=one,
2955
 
                              transport=transport,
2956
 
                              test_suite_factory=test_suite_factory,
2957
 
                              lsprof_timed=lsprof_timed,
2958
 
                              bench_history=benchfile,
2959
 
                              matching_tests_first=first,
2960
 
                              list_only=list_only,
2961
 
                              random_seed=randomize,
2962
 
                              exclude_pattern=exclude,
2963
 
                              strict=strict,
2964
 
                              load_list=load_list,
2965
 
                              debug_flags=debugflag,
2966
 
                              starting_with=starting_with,
2967
 
                              )
 
3154
            selftest_kwargs = {"verbose": verbose,
 
3155
                              "pattern": pattern,
 
3156
                              "stop_on_failure": one,
 
3157
                              "transport": transport,
 
3158
                              "test_suite_factory": test_suite_factory,
 
3159
                              "lsprof_timed": lsprof_timed,
 
3160
                              "bench_history": benchfile,
 
3161
                              "matching_tests_first": first,
 
3162
                              "list_only": list_only,
 
3163
                              "random_seed": randomize,
 
3164
                              "exclude_pattern": exclude,
 
3165
                              "strict": strict,
 
3166
                              "load_list": load_list,
 
3167
                              "debug_flags": debugflag,
 
3168
                              "starting_with": starting_with
 
3169
                              }
 
3170
            selftest_kwargs.update(self.additional_selftest_args)
 
3171
            result = selftest(**selftest_kwargs)
2968
3172
        finally:
2969
3173
            if benchfile is not None:
2970
3174
                benchfile.close()
3008
3212
    #       merging only part of the history.
3009
3213
    takes_args = ['branch', 'other']
3010
3214
    hidden = True
3011
 
    
 
3215
 
3012
3216
    @display_command
3013
3217
    def run(self, branch, other):
3014
3218
        from bzrlib.revision import ensure_null
3015
 
        
 
3219
 
3016
3220
        branch1 = Branch.open_containing(branch)[0]
3017
3221
        branch2 = Branch.open_containing(other)[0]
3018
3222
        branch1.lock_read()
3034
3238
 
3035
3239
class cmd_merge(Command):
3036
3240
    """Perform a three-way merge.
3037
 
    
 
3241
 
3038
3242
    The source of the merge can be specified either in the form of a branch,
3039
3243
    or in the form of a path to a file containing a merge directive generated
3040
3244
    with bzr send. If neither is specified, the default is the upstream branch
3050
3254
    By default, bzr will try to merge in all new work from the other
3051
3255
    branch, automatically determining an appropriate base.  If this
3052
3256
    fails, you may need to give an explicit base.
3053
 
    
 
3257
 
3054
3258
    Merge will do its best to combine the changes in two branches, but there
3055
3259
    are some kinds of problems only a human can fix.  When it encounters those,
3056
3260
    it will mark a conflict.  A conflict means that you need to fix something,
3066
3270
    The results of the merge are placed into the destination working
3067
3271
    directory, where they can be reviewed (with bzr diff), tested, and then
3068
3272
    committed to record the result of the merge.
3069
 
    
 
3273
 
3070
3274
    merge refuses to run if there are any uncommitted changes, unless
3071
3275
    --force is given.
3072
3276
 
3131
3335
        allow_pending = True
3132
3336
        verified = 'inapplicable'
3133
3337
        tree = WorkingTree.open_containing(directory)[0]
 
3338
        view_info = _get_view_info_for_change_reporter(tree)
3134
3339
        change_reporter = delta._ChangeReporter(
3135
 
            unversioned_filter=tree.is_ignored)
 
3340
            unversioned_filter=tree.is_ignored, view_info=view_info)
3136
3341
        cleanups = []
3137
3342
        try:
3138
3343
            pb = ui.ui_factory.nested_progress_bar()
3337
3542
    """Redo a merge.
3338
3543
 
3339
3544
    Use this if you want to try a different merge technique while resolving
3340
 
    conflicts.  Some merge techniques are better than others, and remerge 
 
3545
    conflicts.  Some merge techniques are better than others, and remerge
3341
3546
    lets you try different ones on different files.
3342
3547
 
3343
3548
    The options for remerge have the same meaning and defaults as the ones for
3347
3552
    :Examples:
3348
3553
        Re-do the merge of all conflicted files, and show the base text in
3349
3554
        conflict regions, in addition to the usual THIS and OTHER texts::
3350
 
      
 
3555
 
3351
3556
            bzr remerge --show-base
3352
3557
 
3353
3558
        Re-do the merge of "foobar", using the weave merge algorithm, with
3354
3559
        additional processing to reduce the size of conflict regions::
3355
 
      
 
3560
 
3356
3561
            bzr remerge --merge-type weave --reprocess foobar
3357
3562
    """
3358
3563
    takes_args = ['file*']
3388
3593
                    interesting_ids.add(file_id)
3389
3594
                    if tree.kind(file_id) != "directory":
3390
3595
                        continue
3391
 
                    
 
3596
 
3392
3597
                    for name, ie in tree.inventory.iter_entries(file_id):
3393
3598
                        interesting_ids.add(ie.file_id)
3394
3599
                new_conflicts = conflicts.select_conflicts(tree, file_list)[0]
3443
3648
    merge instead.  For example, "merge . --revision -2..-3" will remove the
3444
3649
    changes introduced by -2, without affecting the changes introduced by -1.
3445
3650
    Or to remove certain changes on a hunk-by-hunk basis, see the Shelf plugin.
3446
 
    
 
3651
 
3447
3652
    By default, any files that have been manually changed will be backed up
3448
3653
    first.  (Files changed only by merge are not backed up.)  Backup files have
3449
3654
    '.~#~' appended to their name, where # is a number.
3518
3723
            ]
3519
3724
    takes_args = ['topic?']
3520
3725
    aliases = ['?', '--help', '-?', '-h']
3521
 
    
 
3726
 
3522
3727
    @display_command
3523
3728
    def run(self, topic=None, long=False):
3524
3729
        import bzrlib.help
3535
3740
    takes_args = ['context?']
3536
3741
    aliases = ['s-c']
3537
3742
    hidden = True
3538
 
    
 
3743
 
3539
3744
    @display_command
3540
3745
    def run(self, context=None):
3541
3746
        import shellcomplete
3731
3936
 
3732
3937
class cmd_plugins(Command):
3733
3938
    """List the installed plugins.
3734
 
    
 
3939
 
3735
3940
    This command displays the list of installed plugins including
3736
3941
    version of plugin and a short description of each.
3737
3942
 
3814
4019
    This prints out the given file with an annotation on the left side
3815
4020
    indicating which revision, author and date introduced the change.
3816
4021
 
3817
 
    If the origin is the same for a run of consecutive lines, it is 
 
4022
    If the origin is the same for a run of consecutive lines, it is
3818
4023
    shown only at the top, unless the --all option is given.
3819
4024
    """
3820
4025
    # TODO: annotate directories; showing when each file was last changed
3821
 
    # TODO: if the working copy is modified, show annotations on that 
 
4026
    # TODO: if the working copy is modified, show annotations on that
3822
4027
    #       with new uncommitted lines marked
3823
4028
    aliases = ['ann', 'blame', 'praise']
3824
4029
    takes_args = ['filename']
3870
4075
    hidden = True # is this right ?
3871
4076
    takes_args = ['revision_id*']
3872
4077
    takes_options = ['revision']
3873
 
    
 
4078
 
3874
4079
    def run(self, revision_id_list=None, revision=None):
3875
4080
        if revision_id_list is not None and revision is not None:
3876
4081
            raise errors.BzrCommandError('You can only supply one of revision_id or --revision')
4106
4311
    holding the lock has been stopped.
4107
4312
 
4108
4313
    You can get information on what locks are open via the 'bzr info' command.
4109
 
    
 
4314
 
4110
4315
    :Examples:
4111
4316
        bzr break-lock
4112
4317
    """
4120
4325
            control.break_lock()
4121
4326
        except NotImplementedError:
4122
4327
            pass
4123
 
        
 
4328
 
4124
4329
 
4125
4330
class cmd_wait_until_signalled(Command):
4126
4331
    """Test helper for test_start_and_stop_bzr_subprocess_send_signal.
4240
4445
 
4241
4446
class cmd_join(Command):
4242
4447
    """Combine a subtree into its containing tree.
4243
 
    
 
4448
 
4244
4449
    This command is for experimental use only.  It requires the target tree
4245
4450
    to be in dirstate-with-subtree format, which cannot be converted into
4246
4451
    earlier formats.
4288
4493
            try:
4289
4494
                containing_tree.subsume(sub_tree)
4290
4495
            except errors.BadSubsumeSource, e:
4291
 
                raise errors.BzrCommandError("Cannot join %s.  %s" % 
 
4496
                raise errors.BzrCommandError("Cannot join %s.  %s" %
4292
4497
                                             (tree, e.reason))
4293
4498
 
4294
4499
 
4447
4652
    Mail is sent using your preferred mail program.  This should be transparent
4448
4653
    on Windows (it uses MAPI).  On Linux, it requires the xdg-email utility.
4449
4654
    If the preferred client can't be found (or used), your editor will be used.
4450
 
    
 
4655
 
4451
4656
    To use a specific mail program, set the mail_client configuration option.
4452
4657
    (For Thunderbird 1.5, this works around some bugs.)  Supported values for
4453
4658
    specific clients are "claws", "evolution", "kmail", "mutt", and
4456
4661
 
4457
4662
    If mail is being sent, a to address is required.  This can be supplied
4458
4663
    either on the commandline, by setting the submit_to configuration
4459
 
    option in the branch itself or the child_submit_to configuration option 
 
4664
    option in the branch itself or the child_submit_to configuration option
4460
4665
    in the submit branch.
4461
4666
 
4462
4667
    Two formats are currently supported: "4" uses revision bundle format 4 and
4464
4669
    older formats.  It is compatible with Bazaar 0.19 and later.  It is the
4465
4670
    default.  "0.9" uses revision bundle format 0.9 and merge directive
4466
4671
    format 1.  It is compatible with Bazaar 0.12 - 0.18.
4467
 
    
 
4672
 
4468
4673
    Merge directives are applied using the merge command or the pull command.
4469
4674
    """
4470
4675
 
4687
4892
 
4688
4893
class cmd_tag(Command):
4689
4894
    """Create, remove or modify a tag naming a revision.
4690
 
    
 
4895
 
4691
4896
    Tags give human-meaningful names to revisions.  Commands that take a -r
4692
4897
    (--revision) option can be given -rtag:X, where X is any previously
4693
4898
    created tag.
4695
4900
    Tags are stored in the branch.  Tags are copied from one branch to another
4696
4901
    along when you branch, push, pull or merge.
4697
4902
 
4698
 
    It is an error to give a tag name that already exists unless you pass 
 
4903
    It is an error to give a tag name that already exists unless you pass
4699
4904
    --force, in which case the tag is moved to point to the new revision.
4700
4905
 
4701
4906
    To rename a tag (change the name but keep it on the same revsion), run ``bzr
4832
5037
 
4833
5038
    _see_also = ['branches', 'checkouts', 'standalone-trees', 'working-trees']
4834
5039
    takes_args = ['location?']
4835
 
    takes_options = [RegistryOption.from_kwargs('target_type',
4836
 
                     title='Target type',
4837
 
                     help='The type to reconfigure the directory to.',
4838
 
                     value_switches=True, enum_switch=False,
4839
 
                     branch='Reconfigure to be an unbound branch '
4840
 
                        'with no working tree.',
4841
 
                     tree='Reconfigure to be an unbound branch '
4842
 
                        'with a working tree.',
4843
 
                     checkout='Reconfigure to be a bound branch '
4844
 
                        'with a working tree.',
4845
 
                     lightweight_checkout='Reconfigure to be a lightweight'
4846
 
                     ' checkout (with no local history).',
4847
 
                     standalone='Reconfigure to be a standalone branch '
4848
 
                        '(i.e. stop using shared repository).',
4849
 
                     use_shared='Reconfigure to use a shared repository.'),
4850
 
                     Option('bind-to', help='Branch to bind checkout to.',
4851
 
                            type=str),
4852
 
                     Option('force',
4853
 
                        help='Perform reconfiguration even if local changes'
4854
 
                        ' will be lost.')
4855
 
                     ]
 
5040
    takes_options = [
 
5041
        RegistryOption.from_kwargs(
 
5042
            'target_type',
 
5043
            title='Target type',
 
5044
            help='The type to reconfigure the directory to.',
 
5045
            value_switches=True, enum_switch=False,
 
5046
            branch='Reconfigure to be an unbound branch with no working tree.',
 
5047
            tree='Reconfigure to be an unbound branch with a working tree.',
 
5048
            checkout='Reconfigure to be a bound branch with a working tree.',
 
5049
            lightweight_checkout='Reconfigure to be a lightweight'
 
5050
                ' checkout (with no local history).',
 
5051
            standalone='Reconfigure to be a standalone branch '
 
5052
                '(i.e. stop using shared repository).',
 
5053
            use_shared='Reconfigure to use a shared repository.',
 
5054
            with_trees='Reconfigure repository to create '
 
5055
                'working trees on branches by default.',
 
5056
            with_no_trees='Reconfigure repository to not create '
 
5057
                'working trees on branches by default.'
 
5058
            ),
 
5059
        Option('bind-to', help='Branch to bind checkout to.', type=str),
 
5060
        Option('force',
 
5061
               help='Perform reconfiguration even if local changes'
 
5062
               ' will be lost.')
 
5063
        ]
4856
5064
 
4857
5065
    def run(self, location=None, target_type=None, bind_to=None, force=False):
4858
5066
        directory = bzrdir.BzrDir.open(location)
4863
5071
        elif target_type == 'tree':
4864
5072
            reconfiguration = reconfigure.Reconfigure.to_tree(directory)
4865
5073
        elif target_type == 'checkout':
4866
 
            reconfiguration = reconfigure.Reconfigure.to_checkout(directory,
4867
 
                                                                  bind_to)
 
5074
            reconfiguration = reconfigure.Reconfigure.to_checkout(
 
5075
                directory, bind_to)
4868
5076
        elif target_type == 'lightweight-checkout':
4869
5077
            reconfiguration = reconfigure.Reconfigure.to_lightweight_checkout(
4870
5078
                directory, bind_to)
4872
5080
            reconfiguration = reconfigure.Reconfigure.to_use_shared(directory)
4873
5081
        elif target_type == 'standalone':
4874
5082
            reconfiguration = reconfigure.Reconfigure.to_standalone(directory)
 
5083
        elif target_type == 'with-trees':
 
5084
            reconfiguration = reconfigure.Reconfigure.set_repository_trees(
 
5085
                directory, True)
 
5086
        elif target_type == 'with-no-trees':
 
5087
            reconfiguration = reconfigure.Reconfigure.set_repository_trees(
 
5088
                directory, False)
4875
5089
        reconfiguration.apply(force)
4876
5090
 
4877
5091
 
4878
5092
class cmd_switch(Command):
4879
5093
    """Set the branch of a checkout and update.
4880
 
    
 
5094
 
4881
5095
    For lightweight checkouts, this changes the branch being referenced.
4882
5096
    For heavyweight checkouts, this checks that there are no local commits
4883
5097
    versus the current bound branch, then it makes the local branch a mirror
4927
5141
            urlutils.unescape_for_display(to_branch.base, 'utf-8'))
4928
5142
 
4929
5143
 
 
5144
class cmd_view(Command):
 
5145
    """Manage filtered views.
 
5146
 
 
5147
    Views provide a mask over the tree so that users can focus on
 
5148
    a subset of a tree when doing their work. After creating a view,
 
5149
    commands that support a list of files - status, diff, commit, etc -
 
5150
    effectively have that list of files implicitly given each time.
 
5151
    An explicit list of files can still be given but those files
 
5152
    must be within the current view.
 
5153
 
 
5154
    In most cases, a view has a short life-span: it is created to make
 
5155
    a selected change and is deleted once that change is committed.
 
5156
    At other times, you may wish to create one or more named views
 
5157
    and switch between them.
 
5158
 
 
5159
    To disable the current view without deleting it, you can switch to
 
5160
    the pseudo view called ``off``. This can be useful when you need
 
5161
    to see the whole tree for an operation or two (e.g. merge) but
 
5162
    want to switch back to your view after that.
 
5163
 
 
5164
    :Examples:
 
5165
      To define the current view::
 
5166
 
 
5167
        bzr view file1 dir1 ...
 
5168
 
 
5169
      To list the current view::
 
5170
 
 
5171
        bzr view
 
5172
 
 
5173
      To delete the current view::
 
5174
 
 
5175
        bzr view --delete
 
5176
 
 
5177
      To disable the current view without deleting it::
 
5178
 
 
5179
        bzr view --switch off
 
5180
 
 
5181
      To define a named view and switch to it::
 
5182
 
 
5183
        bzr view --name view-name file1 dir1 ...
 
5184
 
 
5185
      To list a named view::
 
5186
 
 
5187
        bzr view --name view-name
 
5188
 
 
5189
      To delete a named view::
 
5190
 
 
5191
        bzr view --name view-name --delete
 
5192
 
 
5193
      To switch to a named view::
 
5194
 
 
5195
        bzr view --switch view-name
 
5196
 
 
5197
      To list all views defined::
 
5198
 
 
5199
        bzr view --all
 
5200
 
 
5201
      To delete all views::
 
5202
 
 
5203
        bzr view --delete --all
 
5204
    """
 
5205
 
 
5206
    _see_also = []
 
5207
    takes_args = ['file*']
 
5208
    takes_options = [
 
5209
        Option('all',
 
5210
            help='Apply list or delete action to all views.',
 
5211
            ),
 
5212
        Option('delete',
 
5213
            help='Delete the view.',
 
5214
            ),
 
5215
        Option('name',
 
5216
            help='Name of the view to define, list or delete.',
 
5217
            type=unicode,
 
5218
            ),
 
5219
        Option('switch',
 
5220
            help='Name of the view to switch to.',
 
5221
            type=unicode,
 
5222
            ),
 
5223
        ]
 
5224
 
 
5225
    def run(self, file_list,
 
5226
            all=False,
 
5227
            delete=False,
 
5228
            name=None,
 
5229
            switch=None,
 
5230
            ):
 
5231
        tree, file_list = tree_files(file_list, apply_view=False)
 
5232
        current_view, view_dict = tree.views.get_view_info()
 
5233
        if name is None:
 
5234
            name = current_view
 
5235
        if delete:
 
5236
            if file_list:
 
5237
                raise errors.BzrCommandError(
 
5238
                    "Both --delete and a file list specified")
 
5239
            elif switch:
 
5240
                raise errors.BzrCommandError(
 
5241
                    "Both --delete and --switch specified")
 
5242
            elif all:
 
5243
                tree.views.set_view_info(None, {})
 
5244
                self.outf.write("Deleted all views.\n")
 
5245
            elif name is None:
 
5246
                raise errors.BzrCommandError("No current view to delete")
 
5247
            else:
 
5248
                tree.views.delete_view(name)
 
5249
                self.outf.write("Deleted '%s' view.\n" % name)
 
5250
        elif switch:
 
5251
            if file_list:
 
5252
                raise errors.BzrCommandError(
 
5253
                    "Both --switch and a file list specified")
 
5254
            elif all:
 
5255
                raise errors.BzrCommandError(
 
5256
                    "Both --switch and --all specified")
 
5257
            elif switch == 'off':
 
5258
                if current_view is None:
 
5259
                    raise errors.BzrCommandError("No current view to disable")
 
5260
                tree.views.set_view_info(None, view_dict)
 
5261
                self.outf.write("Disabled '%s' view.\n" % (current_view))
 
5262
            else:
 
5263
                tree.views.set_view_info(switch, view_dict)
 
5264
                view_str = views.view_display_str(tree.views.lookup_view())
 
5265
                self.outf.write("Using '%s' view: %s\n" % (switch, view_str))
 
5266
        elif all:
 
5267
            if view_dict:
 
5268
                self.outf.write('Views defined:\n')
 
5269
                for view in sorted(view_dict):
 
5270
                    if view == current_view:
 
5271
                        active = "=>"
 
5272
                    else:
 
5273
                        active = "  "
 
5274
                    view_str = views.view_display_str(view_dict[view])
 
5275
                    self.outf.write('%s %-20s %s\n' % (active, view, view_str))
 
5276
            else:
 
5277
                self.outf.write('No views defined.\n')
 
5278
        elif file_list:
 
5279
            if name is None:
 
5280
                # No name given and no current view set
 
5281
                name = 'my'
 
5282
            elif name == 'off':
 
5283
                raise errors.BzrCommandError(
 
5284
                    "Cannot change the 'off' pseudo view")
 
5285
            tree.views.set_view(name, sorted(file_list))
 
5286
            view_str = views.view_display_str(tree.views.lookup_view())
 
5287
            self.outf.write("Using '%s' view: %s\n" % (name, view_str))
 
5288
        else:
 
5289
            # list the files
 
5290
            if name is None:
 
5291
                # No name given and no current view set
 
5292
                self.outf.write('No current view.\n')
 
5293
            else:
 
5294
                view_str = views.view_display_str(tree.views.lookup_view(name))
 
5295
                self.outf.write("'%s' view is: %s\n" % (name, view_str))
 
5296
 
 
5297
 
4930
5298
class cmd_hooks(Command):
4931
5299
    """Show a branch's currently registered hooks.
4932
5300
    """
5069
5437
 
5070
5438
# these get imported and then picked up by the scan for cmd_*
5071
5439
# TODO: Some more consistent way to split command definitions across files;
5072
 
# we do need to load at least some information about them to know of 
 
5440
# we do need to load at least some information about them to know of
5073
5441
# aliases.  ideally we would avoid loading the implementation until the
5074
5442
# details were needed.
5075
5443
from bzrlib.cmd_version_info import cmd_version_info