~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/status.py

  • Committer: John Arbash Meinel
  • Date: 2007-02-08 23:10:37 UTC
  • mto: This revision was merged to the branch mainline in revision 2294.
  • Revision ID: john@arbash-meinel.com-20070208231037-xzuzlh339rmgfhk6
Add a get_cached_utf8, which will ensure it is really utf8, and cache the strings

Show diffs side-by-side

added added

removed removed

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