/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/builtins.py

  • Committer: Martin Pool
  • Date: 2009-03-03 03:01:49 UTC
  • mfrom: (4070 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4073.
  • Revision ID: mbp@sourcefrog.net-20090303030149-8p8o8hszdtqa7w8f
merge trunk

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,))
1227
1282
    """Show information about a working tree, branch or repository.
1228
1283
 
1229
1284
    This command will show all known locations and formats associated to the
1230
 
    tree, branch or repository.  Statistical information is included with
1231
 
    each report.
 
1285
    tree, branch or repository.
 
1286
 
 
1287
    In verbose mode, statistical information is included with each report.
 
1288
    To see extended statistic information, use a verbosity level of 2 or
 
1289
    higher by specifying the verbose option multiple times, e.g. -vv.
1232
1290
 
1233
1291
    Branches and working trees will also report any missing revisions.
 
1292
 
 
1293
    :Examples:
 
1294
 
 
1295
      Display information on the format and related locations:
 
1296
 
 
1297
        bzr info
 
1298
 
 
1299
      Display the above together with extended format information and
 
1300
      basic statistics (like the number of files in the working tree and
 
1301
      number of revisions in the branch and repository):
 
1302
 
 
1303
        bzr -v info
 
1304
 
 
1305
      Display the above together with number of committers to the branch:
 
1306
 
 
1307
        bzr -vv info
1234
1308
    """
1235
1309
    _see_also = ['revno', 'working-trees', 'repositories']
1236
1310
    takes_args = ['location?']
1240
1314
    @display_command
1241
1315
    def run(self, location=None, verbose=False):
1242
1316
        if verbose:
1243
 
            noise_level = 2
 
1317
            noise_level = get_verbosity_level()
1244
1318
        else:
1245
1319
            noise_level = 0
1246
1320
        from bzrlib.info import show_bzrdir_info
1353
1427
 
1354
1428
    This can correct data mismatches that may have been caused by
1355
1429
    previous ghost operations or bzr upgrades. You should only
1356
 
    need to run this command if 'bzr check' or a bzr developer 
 
1430
    need to run this command if 'bzr check' or a bzr developer
1357
1431
    advises you to run it.
1358
1432
 
1359
1433
    If a second branch is provided, cross-branch reconciliation is
1361
1435
    id which was not present in very early bzr versions is represented
1362
1436
    correctly in both branches.
1363
1437
 
1364
 
    At the same time it is run it may recompress data resulting in 
 
1438
    At the same time it is run it may recompress data resulting in
1365
1439
    a potential saving in disk space or performance gain.
1366
1440
 
1367
1441
    The branch *MUST* be on a listable system such as local disk or sftp.
1423
1497
    Use this to create an empty branch, or before importing an
1424
1498
    existing project.
1425
1499
 
1426
 
    If there is a repository in a parent directory of the location, then 
 
1500
    If there is a repository in a parent directory of the location, then
1427
1501
    the history of the branch will be stored in the repository.  Otherwise
1428
1502
    init creates a standalone branch which carries its own history
1429
1503
    in the .bzr directory.
1582
1656
 
1583
1657
class cmd_diff(Command):
1584
1658
    """Show differences in the working tree, between revisions or branches.
1585
 
    
 
1659
 
1586
1660
    If no arguments are given, all changes for the current tree are listed.
1587
1661
    If files are given, only the changes in those files are listed.
1588
1662
    Remote and multiple branches can be compared by using the --old and
1687
1761
                                         ' one or two revision specifiers')
1688
1762
 
1689
1763
        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, 
 
1764
                _get_trees_to_diff(file_list, revision, old, new,
 
1765
                apply_view=True)
 
1766
        return show_diff_trees(old_tree, new_tree, sys.stdout,
1692
1767
                               specific_files=specific_files,
1693
1768
                               external_diff_options=diff_options,
1694
1769
                               old_label=old_label, new_label=new_label,
1841
1916
    were merged.
1842
1917
 
1843
1918
    :Output control:
1844
 
 
 
1919
 
1845
1920
      The log format controls how information about each revision is
1846
1921
      displayed. The standard log formats are called ``long``, ``short``
1847
1922
      and ``line``. The default is long. See ``bzr help log-formats``
1849
1924
 
1850
1925
      The following options can be used to control what information is
1851
1926
      displayed::
1852
 
  
 
1927
 
1853
1928
        -l N        display a maximum of N revisions
1854
1929
        -n N        display N levels of revisions (0 for all, 1 for collapsed)
1855
1930
        -v          display a status summary (delta) for each revision
1856
1931
        -p          display a diff (patch) for each revision
1857
1932
        --show-ids  display revision-ids (and file-ids), not just revnos
1858
 
  
 
1933
 
1859
1934
      Note that the default number of levels to display is a function of the
1860
1935
      log format. If the -n option is not used, ``short`` and ``line`` show
1861
1936
      just the top level (mainline) while ``long`` shows all levels of merged
1862
1937
      revisions.
1863
 
  
 
1938
 
1864
1939
      Status summaries are shown using status flags like A, M, etc. To see
1865
1940
      the changes explained using words like ``added`` and ``modified``
1866
1941
      instead, use the -vv option.
1867
 
  
 
1942
 
1868
1943
    :Ordering control:
1869
 
  
 
1944
 
1870
1945
      To display revisions from oldest to newest, use the --forward option.
1871
1946
      In most cases, using this option will have little impact on the total
1872
1947
      time taken to produce a log, though --forward does not incrementally
1873
1948
      display revisions like --reverse does when it can.
1874
 
  
 
1949
 
1875
1950
    :Revision filtering:
1876
 
  
 
1951
 
1877
1952
      The -r option can be used to specify what revision or range of revisions
1878
1953
      to filter against. The various forms are shown below::
1879
 
  
 
1954
 
1880
1955
        -rX      display revision X
1881
1956
        -rX..    display revision X and later
1882
1957
        -r..Y    display up to and including revision Y
1883
1958
        -rX..Y   display from X to Y inclusive
1884
 
  
 
1959
 
1885
1960
      See ``bzr help revisionspec`` for details on how to specify X and Y.
1886
1961
      Some common examples are given below::
1887
 
  
 
1962
 
1888
1963
        -r-1                show just the tip
1889
1964
        -r-10..             show the last 10 mainline revisions
1890
1965
        -rsubmit:..         show what's new on this branch
1891
1966
        -rancestor:path..   show changes since the common ancestor of this
1892
1967
                            branch and the one at location path
1893
1968
        -rdate:yesterday..  show changes since yesterday
1894
 
  
 
1969
 
1895
1970
      When logging a range of revisions using -rX..Y, log starts at
1896
1971
      revision Y and searches back in history through the primary
1897
1972
      ("left-hand") parents until it finds X. When logging just the
1900
1975
      a nested merge revision and the log will be truncated accordingly.
1901
1976
 
1902
1977
    :Path filtering:
1903
 
  
 
1978
 
1904
1979
      If a parameter is given and it's not a branch, the log will be filtered
1905
1980
      to show only those revisions that changed the nominated file or
1906
1981
      directory.
1907
 
  
 
1982
 
1908
1983
      Filenames are interpreted within their historical context. To log a
1909
1984
      deleted file, specify a revision range so that the file existed at
1910
1985
      the end or start of the range.
1911
 
  
 
1986
 
1912
1987
      Historical context is also important when interpreting pathnames of
1913
1988
      renamed files/directories. Consider the following example:
1914
 
  
 
1989
 
1915
1990
      * revision 1: add tutorial.txt
1916
1991
      * revision 2: modify tutorial.txt
1917
1992
      * revision 3: rename tutorial.txt to guide.txt; add tutorial.txt
1918
 
  
 
1993
 
1919
1994
      In this case:
1920
 
  
 
1995
 
1921
1996
      * ``bzr log guide.txt`` will log the file added in revision 1
1922
 
  
 
1997
 
1923
1998
      * ``bzr log tutorial.txt`` will log the new file added in revision 3
1924
 
  
 
1999
 
1925
2000
      * ``bzr log -r2 -p tutorial.txt`` will show the changes made to
1926
2001
        the original file in revision 2.
1927
 
  
 
2002
 
1928
2003
      * ``bzr log -r2 -p guide.txt`` will display an error message as there
1929
2004
        was no file called guide.txt in revision 2.
1930
 
  
 
2005
 
1931
2006
      Renames are always followed by log. By design, there is no need to
1932
2007
      explicitly ask for this (and no way to stop logging a file back
1933
2008
      until it was last renamed).
1934
 
  
 
2009
 
1935
2010
      Note: If the path is a directory, only revisions that directly changed
1936
2011
      that directory object are currently shown. This is considered a bug.
1937
2012
      (Support for filtering against multiple files and for files within a
1938
2013
      directory is under development.)
1939
 
  
 
2014
 
1940
2015
    :Other filtering:
1941
 
  
 
2016
 
1942
2017
      The --message option can be used for finding revisions that match a
1943
2018
      regular expression in a commit message.
1944
 
  
 
2019
 
1945
2020
    :Tips & tricks:
1946
 
  
 
2021
 
1947
2022
      GUI tools and IDEs are often better at exploring history than command
1948
2023
      line tools. You may prefer qlog or glog from the QBzr and Bzr-Gtk packages
1949
2024
      respectively for example. (TortoiseBzr uses qlog for displaying logs.) See
1950
2025
      http://bazaar-vcs.org/BzrPlugins and http://bazaar-vcs.org/IDEIntegration.
1951
 
  
 
2026
 
1952
2027
      Web interfaces are often better at exploring history than command line
1953
2028
      tools, particularly for branches on servers. You may prefer Loggerhead
1954
2029
      or one of its alternatives. See http://bazaar-vcs.org/WebInterface.
1955
 
  
 
2030
 
1956
2031
      You may find it useful to add the aliases below to ``bazaar.conf``::
1957
 
  
 
2032
 
1958
2033
        [ALIASES]
1959
2034
        tip = log -r-1 -n1
1960
2035
        top = log -r-10.. --short --forward
1961
2036
        show = log -v -p -n1 --long
1962
 
  
 
2037
 
1963
2038
      ``bzr tip`` will then show the latest revision while ``bzr top``
1964
2039
      will show the last 10 mainline revisions. To see the details of a
1965
2040
      particular revision X,  ``bzr show -rX``.
1966
 
  
 
2041
 
1967
2042
      As many GUI tools and Web interfaces do, you may prefer viewing
1968
2043
      history collapsed initially. If you are interested in looking deeper
1969
2044
      into a particular merge X, use ``bzr log -n0 -rX``. If you like
1970
2045
      working this way, you may wish to either:
1971
 
  
 
2046
 
1972
2047
      * change your default log format to short (or line)
1973
2048
      * add this alias: log = log -n1
1974
 
  
 
2049
 
1975
2050
      ``bzr log -v`` on a branch with lots of history is currently
1976
2051
      very slow. A fix for this issue is currently under development.
1977
2052
      With or without that fix, it is recommended that a revision range
1978
2053
      be given when using the -v option.
1979
 
  
 
2054
 
1980
2055
      bzr has a generic full-text matching plugin, bzr-search, that can be
1981
2056
      used to find revisions matching user names, commit messages, etc.
1982
2057
      Among other features, this plugin can find all revisions containing
1983
2058
      a list of words but not others.
1984
 
  
 
2059
 
1985
2060
      When exploring non-mainline history on large projects with deep
1986
2061
      history, the performance of log can be greatly improved by installing
1987
2062
      the revnocache plugin. This plugin buffers historical information
2063
2138
                        location)
2064
2139
        else:
2065
2140
            # local dir only
2066
 
            # FIXME ? log the current subdir only RBC 20060203 
 
2141
            # FIXME ? log the current subdir only RBC 20060203
2067
2142
            if revision is not None \
2068
2143
                    and len(revision) > 0 and revision[0].get_branch():
2069
2144
                location = revision[0].get_branch()
2229
2304
        if revision is not None or tree is None:
2230
2305
            tree = _get_one_revision_tree('ls', revision, branch=branch)
2231
2306
 
 
2307
        apply_view = False
 
2308
        if isinstance(tree, WorkingTree) and tree.supports_views():
 
2309
            view_files = tree.views.lookup_view()
 
2310
            if view_files:
 
2311
                apply_view = True
 
2312
                view_str = views.view_display_str(view_files)
 
2313
                note("ignoring files outside view: %s" % view_str)
 
2314
 
2232
2315
        tree.lock_read()
2233
2316
        try:
2234
2317
            for fp, fc, fkind, fid, entry in tree.list_files(include_root=False):
2240
2323
                        continue
2241
2324
                    if kind is not None and fkind != kind:
2242
2325
                        continue
 
2326
                    if apply_view:
 
2327
                        try:
 
2328
                            views.check_path_in_view(tree, fp)
 
2329
                        except errors.FileOutsideView:
 
2330
                            continue
2243
2331
                    kindch = entry.kind_character()
2244
2332
                    outstring = fp + kindch
2245
2333
                    if verbose:
2290
2378
    using this command or directly by using an editor, be sure to commit
2291
2379
    it.
2292
2380
 
2293
 
    Note: ignore patterns containing shell wildcards must be quoted from 
 
2381
    Note: ignore patterns containing shell wildcards must be quoted from
2294
2382
    the shell on Unix.
2295
2383
 
2296
2384
    :Examples:
2321
2409
        Option('old-default-rules',
2322
2410
               help='Write out the ignore rules bzr < 0.9 always used.')
2323
2411
        ]
2324
 
    
 
2412
 
2325
2413
    def run(self, name_pattern_list=None, old_default_rules=None):
2326
2414
        from bzrlib import ignores
2327
2415
        if old_default_rules is not None:
2332
2420
        if not name_pattern_list:
2333
2421
            raise errors.BzrCommandError("ignore requires at least one "
2334
2422
                                  "NAME_PATTERN or --old-default-rules")
2335
 
        name_pattern_list = [globbing.normalize_pattern(p) 
 
2423
        name_pattern_list = [globbing.normalize_pattern(p)
2336
2424
                             for p in name_pattern_list]
2337
2425
        for name_pattern in name_pattern_list:
2338
 
            if (name_pattern[0] == '/' or 
 
2426
            if (name_pattern[0] == '/' or
2339
2427
                (len(name_pattern) > 1 and name_pattern[1] == ':')):
2340
2428
                raise errors.BzrCommandError(
2341
2429
                    "NAME_PATTERN should not be an absolute path")
2393
2481
    """
2394
2482
    hidden = True
2395
2483
    takes_args = ['revno']
2396
 
    
 
2484
 
2397
2485
    @display_command
2398
2486
    def run(self, revno):
2399
2487
        try:
2467
2555
    If no revision is nominated, the last revision is used.
2468
2556
 
2469
2557
    Note: Take care to redirect standard output when using this command on a
2470
 
    binary file. 
 
2558
    binary file.
2471
2559
    """
2472
2560
 
2473
2561
    _see_also = ['ls']
2520
2608
 
2521
2609
class cmd_local_time_offset(Command):
2522
2610
    """Show the offset in seconds from GMT to local time."""
2523
 
    hidden = True    
 
2611
    hidden = True
2524
2612
    @display_command
2525
2613
    def run(self):
2526
2614
        print osutils.local_time_offset()
2529
2617
 
2530
2618
class cmd_commit(Command):
2531
2619
    """Commit changes into a new revision.
2532
 
    
 
2620
 
2533
2621
    If no arguments are given, the entire tree is committed.
2534
2622
 
2535
2623
    If selected files are specified, only changes to those files are
2536
 
    committed.  If a directory is specified then the directory and everything 
 
2624
    committed.  If a directory is specified then the directory and everything
2537
2625
    within it is committed.
2538
2626
 
2539
2627
    When excludes are given, they take precedence over selected files.
2648
2736
        # TODO: Need a blackbox test for invoking the external editor; may be
2649
2737
        # slightly problematic to run this cross-platform.
2650
2738
 
2651
 
        # TODO: do more checks that the commit will succeed before 
 
2739
        # TODO: do more checks that the commit will succeed before
2652
2740
        # spending the user's valuable time typing a commit message.
2653
2741
 
2654
2742
        properties = {}
2677
2765
                        selected_list, diff=show_diff,
2678
2766
                        output_encoding=osutils.get_user_encoding())
2679
2767
                start_message = generate_commit_message_template(commit_obj)
2680
 
                my_message = edit_commit_message_encoded(t, 
 
2768
                my_message = edit_commit_message_encoded(t,
2681
2769
                    start_message=start_message)
2682
2770
                if my_message is None:
2683
2771
                    raise errors.BzrCommandError("please specify a commit"
2807
2895
 
2808
2896
class cmd_whoami(Command):
2809
2897
    """Show or set bzr user id.
2810
 
    
 
2898
 
2811
2899
    :Examples:
2812
2900
        Show the email of the current user::
2813
2901
 
2825
2913
                    ]
2826
2914
    takes_args = ['name?']
2827
2915
    encoding_type = 'replace'
2828
 
    
 
2916
 
2829
2917
    @display_command
2830
2918
    def run(self, email=False, branch=False, name=None):
2831
2919
        if name is None:
2846
2934
        except errors.NoEmailInUsername, e:
2847
2935
            warning('"%s" does not seem to contain an email address.  '
2848
2936
                    'This is allowed, but not recommended.', name)
2849
 
        
 
2937
 
2850
2938
        # use global config unless --branch given
2851
2939
        if branch:
2852
2940
            c = Branch.open_containing('.')[0].get_config()
2951
3039
 
2952
3040
class cmd_selftest(Command):
2953
3041
    """Run internal test suite.
2954
 
    
 
3042
 
2955
3043
    If arguments are given, they are regular expressions that say which tests
2956
3044
    should run.  Tests matching any expression are run, and other tests are
2957
3045
    not run.
2980
3068
    modified by plugins will not be tested, and tests provided by plugins will
2981
3069
    not be run.
2982
3070
 
2983
 
    Tests that need working space on disk use a common temporary directory, 
 
3071
    Tests that need working space on disk use a common temporary directory,
2984
3072
    typically inside $TMPDIR or /tmp.
2985
3073
 
2986
3074
    :Examples:
3156
3244
    #       merging only part of the history.
3157
3245
    takes_args = ['branch', 'other']
3158
3246
    hidden = True
3159
 
    
 
3247
 
3160
3248
    @display_command
3161
3249
    def run(self, branch, other):
3162
3250
        from bzrlib.revision import ensure_null
3163
 
        
 
3251
 
3164
3252
        branch1 = Branch.open_containing(branch)[0]
3165
3253
        branch2 = Branch.open_containing(other)[0]
3166
3254
        branch1.lock_read()
3182
3270
 
3183
3271
class cmd_merge(Command):
3184
3272
    """Perform a three-way merge.
3185
 
    
 
3273
 
3186
3274
    The source of the merge can be specified either in the form of a branch,
3187
3275
    or in the form of a path to a file containing a merge directive generated
3188
3276
    with bzr send. If neither is specified, the default is the upstream branch
3198
3286
    By default, bzr will try to merge in all new work from the other
3199
3287
    branch, automatically determining an appropriate base.  If this
3200
3288
    fails, you may need to give an explicit base.
3201
 
    
 
3289
 
3202
3290
    Merge will do its best to combine the changes in two branches, but there
3203
3291
    are some kinds of problems only a human can fix.  When it encounters those,
3204
3292
    it will mark a conflict.  A conflict means that you need to fix something,
3214
3302
    The results of the merge are placed into the destination working
3215
3303
    directory, where they can be reviewed (with bzr diff), tested, and then
3216
3304
    committed to record the result of the merge.
3217
 
    
 
3305
 
3218
3306
    merge refuses to run if there are any uncommitted changes, unless
3219
3307
    --force is given.
3220
3308
 
3279
3367
        allow_pending = True
3280
3368
        verified = 'inapplicable'
3281
3369
        tree = WorkingTree.open_containing(directory)[0]
 
3370
        view_info = _get_view_info_for_change_reporter(tree)
3282
3371
        change_reporter = delta._ChangeReporter(
3283
 
            unversioned_filter=tree.is_ignored)
 
3372
            unversioned_filter=tree.is_ignored, view_info=view_info)
3284
3373
        cleanups = []
3285
3374
        try:
3286
3375
            pb = ui.ui_factory.nested_progress_bar()
3485
3574
    """Redo a merge.
3486
3575
 
3487
3576
    Use this if you want to try a different merge technique while resolving
3488
 
    conflicts.  Some merge techniques are better than others, and remerge 
 
3577
    conflicts.  Some merge techniques are better than others, and remerge
3489
3578
    lets you try different ones on different files.
3490
3579
 
3491
3580
    The options for remerge have the same meaning and defaults as the ones for
3495
3584
    :Examples:
3496
3585
        Re-do the merge of all conflicted files, and show the base text in
3497
3586
        conflict regions, in addition to the usual THIS and OTHER texts::
3498
 
      
 
3587
 
3499
3588
            bzr remerge --show-base
3500
3589
 
3501
3590
        Re-do the merge of "foobar", using the weave merge algorithm, with
3502
3591
        additional processing to reduce the size of conflict regions::
3503
 
      
 
3592
 
3504
3593
            bzr remerge --merge-type weave --reprocess foobar
3505
3594
    """
3506
3595
    takes_args = ['file*']
3536
3625
                    interesting_ids.add(file_id)
3537
3626
                    if tree.kind(file_id) != "directory":
3538
3627
                        continue
3539
 
                    
 
3628
 
3540
3629
                    for name, ie in tree.inventory.iter_entries(file_id):
3541
3630
                        interesting_ids.add(ie.file_id)
3542
3631
                new_conflicts = conflicts.select_conflicts(tree, file_list)[0]
3591
3680
    merge instead.  For example, "merge . --revision -2..-3" will remove the
3592
3681
    changes introduced by -2, without affecting the changes introduced by -1.
3593
3682
    Or to remove certain changes on a hunk-by-hunk basis, see the Shelf plugin.
3594
 
    
 
3683
 
3595
3684
    By default, any files that have been manually changed will be backed up
3596
3685
    first.  (Files changed only by merge are not backed up.)  Backup files have
3597
3686
    '.~#~' appended to their name, where # is a number.
3666
3755
            ]
3667
3756
    takes_args = ['topic?']
3668
3757
    aliases = ['?', '--help', '-?', '-h']
3669
 
    
 
3758
 
3670
3759
    @display_command
3671
3760
    def run(self, topic=None, long=False):
3672
3761
        import bzrlib.help
3683
3772
    takes_args = ['context?']
3684
3773
    aliases = ['s-c']
3685
3774
    hidden = True
3686
 
    
 
3775
 
3687
3776
    @display_command
3688
3777
    def run(self, context=None):
3689
3778
        import shellcomplete
3879
3968
 
3880
3969
class cmd_plugins(Command):
3881
3970
    """List the installed plugins.
3882
 
    
 
3971
 
3883
3972
    This command displays the list of installed plugins including
3884
3973
    version of plugin and a short description of each.
3885
3974
 
3962
4051
    This prints out the given file with an annotation on the left side
3963
4052
    indicating which revision, author and date introduced the change.
3964
4053
 
3965
 
    If the origin is the same for a run of consecutive lines, it is 
 
4054
    If the origin is the same for a run of consecutive lines, it is
3966
4055
    shown only at the top, unless the --all option is given.
3967
4056
    """
3968
4057
    # TODO: annotate directories; showing when each file was last changed
3969
 
    # TODO: if the working copy is modified, show annotations on that 
 
4058
    # TODO: if the working copy is modified, show annotations on that
3970
4059
    #       with new uncommitted lines marked
3971
4060
    aliases = ['ann', 'blame', 'praise']
3972
4061
    takes_args = ['filename']
4018
4107
    hidden = True # is this right ?
4019
4108
    takes_args = ['revision_id*']
4020
4109
    takes_options = ['revision']
4021
 
    
 
4110
 
4022
4111
    def run(self, revision_id_list=None, revision=None):
4023
4112
        if revision_id_list is not None and revision is not None:
4024
4113
            raise errors.BzrCommandError('You can only supply one of revision_id or --revision')
4254
4343
    holding the lock has been stopped.
4255
4344
 
4256
4345
    You can get information on what locks are open via the 'bzr info' command.
4257
 
    
 
4346
 
4258
4347
    :Examples:
4259
4348
        bzr break-lock
4260
4349
    """
4268
4357
            control.break_lock()
4269
4358
        except NotImplementedError:
4270
4359
            pass
4271
 
        
 
4360
 
4272
4361
 
4273
4362
class cmd_wait_until_signalled(Command):
4274
4363
    """Test helper for test_start_and_stop_bzr_subprocess_send_signal.
4388
4477
 
4389
4478
class cmd_join(Command):
4390
4479
    """Combine a subtree into its containing tree.
4391
 
    
 
4480
 
4392
4481
    This command is for experimental use only.  It requires the target tree
4393
4482
    to be in dirstate-with-subtree format, which cannot be converted into
4394
4483
    earlier formats.
4436
4525
            try:
4437
4526
                containing_tree.subsume(sub_tree)
4438
4527
            except errors.BadSubsumeSource, e:
4439
 
                raise errors.BzrCommandError("Cannot join %s.  %s" % 
 
4528
                raise errors.BzrCommandError("Cannot join %s.  %s" %
4440
4529
                                             (tree, e.reason))
4441
4530
 
4442
4531
 
4595
4684
    Mail is sent using your preferred mail program.  This should be transparent
4596
4685
    on Windows (it uses MAPI).  On Linux, it requires the xdg-email utility.
4597
4686
    If the preferred client can't be found (or used), your editor will be used.
4598
 
    
 
4687
 
4599
4688
    To use a specific mail program, set the mail_client configuration option.
4600
4689
    (For Thunderbird 1.5, this works around some bugs.)  Supported values for
4601
4690
    specific clients are "claws", "evolution", "kmail", "mutt", and
4604
4693
 
4605
4694
    If mail is being sent, a to address is required.  This can be supplied
4606
4695
    either on the commandline, by setting the submit_to configuration
4607
 
    option in the branch itself or the child_submit_to configuration option 
 
4696
    option in the branch itself or the child_submit_to configuration option
4608
4697
    in the submit branch.
4609
4698
 
4610
4699
    Two formats are currently supported: "4" uses revision bundle format 4 and
4612
4701
    older formats.  It is compatible with Bazaar 0.19 and later.  It is the
4613
4702
    default.  "0.9" uses revision bundle format 0.9 and merge directive
4614
4703
    format 1.  It is compatible with Bazaar 0.12 - 0.18.
4615
 
    
 
4704
 
4616
4705
    Merge directives are applied using the merge command or the pull command.
4617
4706
    """
4618
4707
 
4835
4924
 
4836
4925
class cmd_tag(Command):
4837
4926
    """Create, remove or modify a tag naming a revision.
4838
 
    
 
4927
 
4839
4928
    Tags give human-meaningful names to revisions.  Commands that take a -r
4840
4929
    (--revision) option can be given -rtag:X, where X is any previously
4841
4930
    created tag.
4843
4932
    Tags are stored in the branch.  Tags are copied from one branch to another
4844
4933
    along when you branch, push, pull or merge.
4845
4934
 
4846
 
    It is an error to give a tag name that already exists unless you pass 
 
4935
    It is an error to give a tag name that already exists unless you pass
4847
4936
    --force, in which case the tag is moved to point to the new revision.
4848
4937
 
4849
4938
    To rename a tag (change the name but keep it on the same revsion), run ``bzr
5034
5123
 
5035
5124
class cmd_switch(Command):
5036
5125
    """Set the branch of a checkout and update.
5037
 
    
 
5126
 
5038
5127
    For lightweight checkouts, this changes the branch being referenced.
5039
5128
    For heavyweight checkouts, this checks that there are no local commits
5040
5129
    versus the current bound branch, then it makes the local branch a mirror
5084
5173
            urlutils.unescape_for_display(to_branch.base, 'utf-8'))
5085
5174
 
5086
5175
 
 
5176
class cmd_view(Command):
 
5177
    """Manage filtered views.
 
5178
 
 
5179
    Views provide a mask over the tree so that users can focus on
 
5180
    a subset of a tree when doing their work. After creating a view,
 
5181
    commands that support a list of files - status, diff, commit, etc -
 
5182
    effectively have that list of files implicitly given each time.
 
5183
    An explicit list of files can still be given but those files
 
5184
    must be within the current view.
 
5185
 
 
5186
    In most cases, a view has a short life-span: it is created to make
 
5187
    a selected change and is deleted once that change is committed.
 
5188
    At other times, you may wish to create one or more named views
 
5189
    and switch between them.
 
5190
 
 
5191
    To disable the current view without deleting it, you can switch to
 
5192
    the pseudo view called ``off``. This can be useful when you need
 
5193
    to see the whole tree for an operation or two (e.g. merge) but
 
5194
    want to switch back to your view after that.
 
5195
 
 
5196
    :Examples:
 
5197
      To define the current view::
 
5198
 
 
5199
        bzr view file1 dir1 ...
 
5200
 
 
5201
      To list the current view::
 
5202
 
 
5203
        bzr view
 
5204
 
 
5205
      To delete the current view::
 
5206
 
 
5207
        bzr view --delete
 
5208
 
 
5209
      To disable the current view without deleting it::
 
5210
 
 
5211
        bzr view --switch off
 
5212
 
 
5213
      To define a named view and switch to it::
 
5214
 
 
5215
        bzr view --name view-name file1 dir1 ...
 
5216
 
 
5217
      To list a named view::
 
5218
 
 
5219
        bzr view --name view-name
 
5220
 
 
5221
      To delete a named view::
 
5222
 
 
5223
        bzr view --name view-name --delete
 
5224
 
 
5225
      To switch to a named view::
 
5226
 
 
5227
        bzr view --switch view-name
 
5228
 
 
5229
      To list all views defined::
 
5230
 
 
5231
        bzr view --all
 
5232
 
 
5233
      To delete all views::
 
5234
 
 
5235
        bzr view --delete --all
 
5236
    """
 
5237
 
 
5238
    _see_also = []
 
5239
    takes_args = ['file*']
 
5240
    takes_options = [
 
5241
        Option('all',
 
5242
            help='Apply list or delete action to all views.',
 
5243
            ),
 
5244
        Option('delete',
 
5245
            help='Delete the view.',
 
5246
            ),
 
5247
        Option('name',
 
5248
            help='Name of the view to define, list or delete.',
 
5249
            type=unicode,
 
5250
            ),
 
5251
        Option('switch',
 
5252
            help='Name of the view to switch to.',
 
5253
            type=unicode,
 
5254
            ),
 
5255
        ]
 
5256
 
 
5257
    def run(self, file_list,
 
5258
            all=False,
 
5259
            delete=False,
 
5260
            name=None,
 
5261
            switch=None,
 
5262
            ):
 
5263
        tree, file_list = tree_files(file_list, apply_view=False)
 
5264
        current_view, view_dict = tree.views.get_view_info()
 
5265
        if name is None:
 
5266
            name = current_view
 
5267
        if delete:
 
5268
            if file_list:
 
5269
                raise errors.BzrCommandError(
 
5270
                    "Both --delete and a file list specified")
 
5271
            elif switch:
 
5272
                raise errors.BzrCommandError(
 
5273
                    "Both --delete and --switch specified")
 
5274
            elif all:
 
5275
                tree.views.set_view_info(None, {})
 
5276
                self.outf.write("Deleted all views.\n")
 
5277
            elif name is None:
 
5278
                raise errors.BzrCommandError("No current view to delete")
 
5279
            else:
 
5280
                tree.views.delete_view(name)
 
5281
                self.outf.write("Deleted '%s' view.\n" % name)
 
5282
        elif switch:
 
5283
            if file_list:
 
5284
                raise errors.BzrCommandError(
 
5285
                    "Both --switch and a file list specified")
 
5286
            elif all:
 
5287
                raise errors.BzrCommandError(
 
5288
                    "Both --switch and --all specified")
 
5289
            elif switch == 'off':
 
5290
                if current_view is None:
 
5291
                    raise errors.BzrCommandError("No current view to disable")
 
5292
                tree.views.set_view_info(None, view_dict)
 
5293
                self.outf.write("Disabled '%s' view.\n" % (current_view))
 
5294
            else:
 
5295
                tree.views.set_view_info(switch, view_dict)
 
5296
                view_str = views.view_display_str(tree.views.lookup_view())
 
5297
                self.outf.write("Using '%s' view: %s\n" % (switch, view_str))
 
5298
        elif all:
 
5299
            if view_dict:
 
5300
                self.outf.write('Views defined:\n')
 
5301
                for view in sorted(view_dict):
 
5302
                    if view == current_view:
 
5303
                        active = "=>"
 
5304
                    else:
 
5305
                        active = "  "
 
5306
                    view_str = views.view_display_str(view_dict[view])
 
5307
                    self.outf.write('%s %-20s %s\n' % (active, view, view_str))
 
5308
            else:
 
5309
                self.outf.write('No views defined.\n')
 
5310
        elif file_list:
 
5311
            if name is None:
 
5312
                # No name given and no current view set
 
5313
                name = 'my'
 
5314
            elif name == 'off':
 
5315
                raise errors.BzrCommandError(
 
5316
                    "Cannot change the 'off' pseudo view")
 
5317
            tree.views.set_view(name, sorted(file_list))
 
5318
            view_str = views.view_display_str(tree.views.lookup_view())
 
5319
            self.outf.write("Using '%s' view: %s\n" % (name, view_str))
 
5320
        else:
 
5321
            # list the files
 
5322
            if name is None:
 
5323
                # No name given and no current view set
 
5324
                self.outf.write('No current view.\n')
 
5325
            else:
 
5326
                view_str = views.view_display_str(tree.views.lookup_view(name))
 
5327
                self.outf.write("'%s' view is: %s\n" % (name, view_str))
 
5328
 
 
5329
 
5087
5330
class cmd_hooks(Command):
5088
5331
    """Show a branch's currently registered hooks.
5089
5332
    """
5226
5469
 
5227
5470
# these get imported and then picked up by the scan for cmd_*
5228
5471
# TODO: Some more consistent way to split command definitions across files;
5229
 
# we do need to load at least some information about them to know of 
 
5472
# we do need to load at least some information about them to know of
5230
5473
# aliases.  ideally we would avoid loading the implementation until the
5231
5474
# details were needed.
5232
5475
from bzrlib.cmd_version_info import cmd_version_info