~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/status.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2007-03-12 17:30:53 UTC
  • mfrom: (2338.3.1 hide-nested)
  • Revision ID: pqm@pqm.ubuntu.com-20070312173053-4cdb4cd14190d29e
Hide nested-tree commands and improve their docs

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# (C) 2005 Canonical Ltd
 
1
# Copyright (C) 2005, 2006 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
import sys
 
18
 
 
19
from bzrlib import (
 
20
    delta as _mod_delta,
 
21
    tree,
 
22
    )
 
23
from bzrlib.diff import _raise_if_nonexistent
 
24
import bzrlib.errors as errors
 
25
from bzrlib.log import line_log
18
26
from bzrlib.osutils import is_inside_any
19
 
from bzrlib.delta import compare_trees
20
 
from bzrlib.log import line_log
21
 
from bzrlib.errors import NoSuchRevision
 
27
from bzrlib.symbol_versioning import (deprecated_function,
 
28
        zero_eight,
 
29
        )
 
30
from bzrlib.trace import warning
22
31
 
23
32
# TODO: when showing single-line logs, truncate to the width of the terminal
24
33
# if known, but only if really going to the terminal (not into a file)
25
34
 
26
35
 
27
 
def show_status(branch, show_unchanged=False,
 
36
@deprecated_function(zero_eight)
 
37
def show_status(branch, show_unchanged=None,
28
38
                specific_files=None,
29
39
                show_ids=False,
30
40
                to_file=None,
32
42
                revision=None):
33
43
    """Display summary of changes.
34
44
 
 
45
    Please use show_tree_status instead.
 
46
 
35
47
    By default this compares the working tree to a previous revision. 
36
48
    If the revision argument is given, summarizes changes between the 
37
49
    working tree and another, or between two revisions.
59
71
        If one revision show compared it with working tree.
60
72
        If two revisions show status between first and second.
61
73
    """
62
 
    if to_file == None:
 
74
    show_tree_status(branch.bzrdir.open_workingtree(), show_unchanged, 
 
75
                     specific_files, show_ids, to_file, show_pending, revision)
 
76
 
 
77
 
 
78
def show_tree_status(wt, show_unchanged=None,
 
79
                     specific_files=None,
 
80
                     show_ids=False,
 
81
                     to_file=None,
 
82
                     show_pending=True,
 
83
                     revision=None,
 
84
                     short=False):
 
85
    """Display summary of changes.
 
86
 
 
87
    By default this compares the working tree to a previous revision. 
 
88
    If the revision argument is given, summarizes changes between the 
 
89
    working tree and another, or between two revisions.
 
90
 
 
91
    The result is written out as Unicode and to_file should be able 
 
92
    to encode that.
 
93
 
 
94
    If showing the status of a working tree, extra information is included
 
95
    about unknown files, conflicts, and pending merges.
 
96
 
 
97
    :param show_unchanged: Deprecated parameter. If set, includes unchanged 
 
98
        files.
 
99
    :param specific_files: If set, a list of filenames whose status should be
 
100
        shown.  It is an error to give a filename that is not in the working 
 
101
        tree, or in the working inventory or in the basis inventory.
 
102
    :param show_ids: If set, includes each file's id.
 
103
    :param to_file: If set, write to this file (default stdout.)
 
104
    :param show_pending: If set, write pending merges.
 
105
    :param revision: If None the compare latest revision with working tree
 
106
        If not None it must be a RevisionSpec list.
 
107
        If one revision show compared it with working tree.
 
108
        If two revisions show status between first and second.
 
109
    :param short: If True, gives short SVN-style status lines
 
110
    """
 
111
    if show_unchanged is not None:
 
112
        warn("show_status_trees with show_unchanged has been deprecated "
 
113
             "since bzrlib 0.9", DeprecationWarning, stacklevel=2)
 
114
 
 
115
    if to_file is None:
63
116
        to_file = sys.stdout
64
117
    
65
 
    branch.lock_read()
 
118
    wt.lock_read()
66
119
    try:
67
120
        new_is_working_tree = True
68
121
        if revision is None:
69
 
            old = branch.basis_tree()
70
 
            new = branch.working_tree()
 
122
            if wt.last_revision() != wt.branch.last_revision():
 
123
                warning("working tree is out of date, run 'bzr update'")
 
124
            new = wt
 
125
            old = new.basis_tree()
71
126
        elif len(revision) > 0:
72
127
            try:
73
 
                rev_id = revision[0].in_history(branch).rev_id
74
 
                old = branch.repository.revision_tree(rev_id)
75
 
            except NoSuchRevision, e:
76
 
                raise BzrCommandError(str(e))
77
 
            if len(revision) > 1:
 
128
                rev_id = revision[0].in_history(wt.branch).rev_id
 
129
                old = wt.branch.repository.revision_tree(rev_id)
 
130
            except errors.NoSuchRevision, e:
 
131
                raise errors.BzrCommandError(str(e))
 
132
            if (len(revision) > 1) and (revision[1].spec is not None):
78
133
                try:
79
 
                    rev_id = revision[1].in_history(branch).rev_id
80
 
                    new = branch.repository.revision_tree(rev_id)
 
134
                    rev_id = revision[1].in_history(wt.branch).rev_id
 
135
                    new = wt.branch.repository.revision_tree(rev_id)
81
136
                    new_is_working_tree = False
82
 
                except NoSuchRevision, e:
83
 
                    raise BzrCommandError(str(e))
84
 
            else:
85
 
                new = branch.working_tree()
86
 
                
87
 
 
88
 
        delta = compare_trees(old, new, want_unchanged=show_unchanged,
89
 
                              specific_files=specific_files)
90
 
 
91
 
        delta.show(to_file,
92
 
                   show_ids=show_ids,
93
 
                   show_unchanged=show_unchanged)
94
 
 
95
 
        if new_is_working_tree:
96
 
            list_paths('unknown', new.unknowns(), specific_files, to_file)
97
 
            list_paths('conflicts', new.iter_conflicts(), specific_files, to_file)
98
 
        if new_is_working_tree and show_pending:
99
 
            show_pending_merges(new, to_file)
 
137
                except errors.NoSuchRevision, e:
 
138
                    raise errors.BzrCommandError(str(e))
 
139
            else:
 
140
                new = wt
 
141
        old.lock_read()
 
142
        new.lock_read()
 
143
        try:
 
144
            _raise_if_nonexistent(specific_files, old, new)
 
145
            if short:
 
146
                changes = new._iter_changes(old, show_unchanged, specific_files,
 
147
                    require_versioned=False, want_unversioned=True)
 
148
                reporter = _mod_delta._ChangeReporter(output_file=to_file,
 
149
                    unversioned_filter=new.is_ignored)
 
150
                _mod_delta.report_changes(changes, reporter)
 
151
            else:
 
152
                delta = new.changes_from(old, want_unchanged=show_unchanged,
 
153
                                      specific_files=specific_files,
 
154
                                      want_unversioned=True)
 
155
                # filter out unknown files. We may want a tree method for
 
156
                # this
 
157
                delta.unversioned = [unversioned for unversioned in
 
158
                    delta.unversioned if not new.is_ignored(unversioned[0])]
 
159
                delta.show(to_file,
 
160
                           show_ids=show_ids,
 
161
                           show_unchanged=show_unchanged,
 
162
                           short_status=False)
 
163
            conflict_title = False
 
164
            # show the new conflicts only for now. XXX: get them from the delta.
 
165
            for conflict in new.conflicts():
 
166
                if not short and conflict_title is False:
 
167
                    print >> to_file, "conflicts:"
 
168
                    conflict_title = True
 
169
                if short:
 
170
                    prefix = 'C  '
 
171
                else:
 
172
                    prefix = ' '
 
173
                print >> to_file, "%s %s" % (prefix, conflict)
 
174
            if new_is_working_tree and show_pending:
 
175
                show_pending_merges(new, to_file, short)
 
176
        finally:
 
177
            old.unlock()
 
178
            new.unlock()
100
179
    finally:
101
 
        branch.unlock()
 
180
        wt.unlock()
102
181
 
103
 
def show_pending_merges(new, to_file):
 
182
def show_pending_merges(new, to_file, short=False):
104
183
    """Write out a display of pending merges in a working tree."""
105
 
    pending = new.pending_merges()
 
184
    parents = new.get_parent_ids()
 
185
    if len(parents) < 2:
 
186
        return
 
187
    pending = parents[1:]
106
188
    branch = new.branch
107
 
    if len(pending) == 0:
108
 
        return
109
 
    print >>to_file, 'pending merges:'
110
 
    last_revision = branch.last_revision()
 
189
    last_revision = parents[0]
 
190
    if not short:
 
191
        print >>to_file, 'pending merges:'
111
192
    if last_revision is not None:
112
 
        ignore = set(branch.repository.get_ancestry(last_revision))
 
193
        try:
 
194
            ignore = set(branch.repository.get_ancestry(last_revision))
 
195
        except errors.NoSuchRevision:
 
196
            # the last revision is a ghost : assume everything is new 
 
197
            # except for it
 
198
            ignore = set([None, last_revision])
113
199
    else:
114
 
        ignore = set()
115
 
    for merge in new.pending_merges():
 
200
        ignore = set([None])
 
201
    # TODO: this could be improved using merge_sorted - we'd get the same 
 
202
    # output rather than one level of indent.
 
203
    for merge in pending:
116
204
        ignore.add(merge)
117
205
        try:
 
206
            from bzrlib.osutils import terminal_width
 
207
            width = terminal_width()
118
208
            m_revision = branch.repository.get_revision(merge)
119
 
            print >> to_file, ' ', line_log(m_revision, 77)
 
209
            if short:
 
210
                prefix = 'P  '
 
211
            else:
 
212
                prefix = ' '
 
213
            print >> to_file, prefix, line_log(m_revision, width - 4)
120
214
            inner_merges = branch.repository.get_ancestry(merge)
 
215
            assert inner_merges[0] is None
 
216
            inner_merges.pop(0)
121
217
            inner_merges.reverse()
122
218
            for mmerge in inner_merges:
123
219
                if mmerge in ignore:
124
220
                    continue
125
221
                mm_revision = branch.repository.get_revision(mmerge)
126
 
                print >> to_file, '   ', line_log(mm_revision, 75)
 
222
                if short:
 
223
                    prefix = 'P.  '
 
224
                else:
 
225
                    prefix = '   '
 
226
                print >> to_file, prefix, line_log(mm_revision, width - 5)
127
227
                ignore.add(mmerge)
128
 
        except NoSuchRevision:
129
 
            print >> to_file, ' ', merge 
130
 
        
131
 
def list_paths(header, paths, specific_files, to_file):
132
 
    done_header = False
133
 
    for path in paths:
134
 
        if specific_files and not is_inside_any(specific_files, path):
135
 
            continue
136
 
        if not done_header:
137
 
            print >>to_file, '%s:' % header
138
 
            done_header = True
139
 
        print >>to_file, ' ', path
 
228
        except errors.NoSuchRevision:
 
229
            if short:
 
230
                prefix = 'P  '
 
231
            else:
 
232
                prefix = ' '
 
233
            print >> to_file, prefix, merge