~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/status.py

  • Committer: Wouter van Heyst
  • Date: 2006-06-07 16:05:27 UTC
  • mto: This revision was merged to the branch mainline in revision 1752.
  • Revision ID: larstiq@larstiq.dyndns.org-20060607160527-2b3649154d0e2e84
more code cleanup

Show diffs side-by-side

added added

removed removed

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