~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/status.py

  • Committer: Lalo Martins
  • Date: 2005-09-14 05:22:13 UTC
  • mfrom: (1185.1.10)
  • mto: (1185.1.22)
  • mto: This revision was merged to the branch mainline in revision 1390.
  • Revision ID: lalo@exoweb.net-20050914052213-2aa5c1005959abdf
merging from Robert's integration branch

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# (C) 2005 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
5
5
# the Free Software Foundation; either version 2 of the License, or
6
6
# (at your option) any later version.
7
 
#
 
7
 
8
8
# This program is distributed in the hope that it will be useful,
9
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
11
# GNU General Public License for more details.
12
 
#
 
12
 
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
 
import sys
18
 
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
22
 
 
23
 
# TODO: when showing single-line logs, truncate to the width of the terminal
24
 
# if known, but only if really going to the terminal (not into a file)
25
17
 
26
18
 
27
19
def show_status(branch, show_unchanged=False,
28
20
                specific_files=None,
29
21
                show_ids=False,
30
22
                to_file=None,
31
 
                show_pending=True,
32
 
                revision=None):
33
 
    """Display summary of changes.
34
 
 
35
 
    By default this compares the working tree to a previous revision. 
36
 
    If the revision argument is given, summarizes changes between the 
37
 
    working tree and another, or between two revisions.
38
 
 
39
 
    The result is written out as Unicode and to_file should be able 
40
 
    to encode that.
 
23
                show_pending=True):
 
24
    """Display status for non-ignored working files.
41
25
 
42
26
    show_unchanged
43
27
        If set, includes unchanged files.
53
37
 
54
38
    show_pending
55
39
        If set, write pending merges.
56
 
 
57
 
    revision
58
 
        If None the compare latest revision with working tree
59
 
        If one revision show compared it with working tree.
60
 
        If two revisions show status between first and second.
61
40
    """
 
41
    import sys
 
42
    from bzrlib.delta import compare_trees
 
43
 
62
44
    if to_file == None:
63
45
        to_file = sys.stdout
64
46
    
65
47
    branch.lock_read()
66
48
    try:
67
 
        new_is_working_tree = True
68
 
        if revision is None:
69
 
            old = branch.basis_tree()
70
 
            new = branch.working_tree()
71
 
        elif len(revision) > 0:
72
 
            try:
73
 
                rev_id = revision[0].in_history(branch).rev_id
74
 
                old = branch.revision_tree(rev_id)
75
 
            except NoSuchRevision, e:
76
 
                raise BzrCommandError(str(e))
77
 
            if len(revision) > 1:
78
 
                try:
79
 
                    rev_id = revision[1].in_history(branch).rev_id
80
 
                    new = branch.revision_tree(rev_id)
81
 
                    new_is_working_tree = False
82
 
                except NoSuchRevision, e:
83
 
                    raise BzrCommandError(str(e))
84
 
            else:
85
 
                new = branch.working_tree()
86
 
                
 
49
 
 
50
        old = branch.basis_tree()
 
51
        new = branch.working_tree()
87
52
 
88
53
        delta = compare_trees(old, new, want_unchanged=show_unchanged,
89
54
                              specific_files=specific_files)
92
57
                   show_ids=show_ids,
93
58
                   show_unchanged=show_unchanged)
94
59
 
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)
 
60
        unknowns = new.unknowns()
 
61
        done_header = False
 
62
        for path in unknowns:
 
63
            # FIXME: Should also match if the unknown file is within a
 
64
            # specified directory.
 
65
            if specific_files:
 
66
                if path not in specific_files:
 
67
                    continue
 
68
            if not done_header:
 
69
                print >>to_file, 'unknown:'
 
70
                done_header = True
 
71
            print >>to_file, ' ', path
 
72
        if show_pending and len(branch.pending_merges()) > 0:
 
73
            print >>to_file, 'pending merges:'
 
74
            for merge in branch.pending_merges():
 
75
                print >> to_file, ' ', merge
100
76
    finally:
101
77
        branch.unlock()
102
 
 
103
 
def show_pending_merges(new, to_file):
104
 
    """Write out a display of pending merges in a working tree."""
105
 
    pending = new.pending_merges()
106
 
    branch = new.branch
107
 
    if len(pending) == 0:
108
 
        return
109
 
    print >>to_file, 'pending merges:'
110
 
    last_revision = branch.last_revision()
111
 
    if last_revision is not None:
112
 
        ignore = set(branch.get_ancestry(last_revision))
113
 
    else:
114
 
        ignore = set()
115
 
    for merge in new.pending_merges():
116
 
        ignore.add(merge)
117
 
        try:
118
 
            m_revision = branch.get_revision(merge)
119
 
            print >> to_file, ' ', line_log(m_revision, 77)
120
 
            inner_merges = branch.get_ancestry(merge)
121
 
            inner_merges.reverse()
122
 
            for mmerge in inner_merges:
123
 
                if mmerge in ignore:
124
 
                    continue
125
 
                mm_revision = branch.get_revision(mmerge)
126
 
                print >> to_file, '   ', line_log(mm_revision, 75)
127
 
                ignore.add(mmerge)
128
 
        except NoSuchRevision:
129
 
            print >> to_file, ' ', merge 
130
78
        
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