~bzr-pqm/bzr/bzr.dev

362 by Martin Pool
- Import stat-cache code
1
# (C) 2005 Canonical Ltd
1185.13.2 by Robert Collins
Merge Aarons conflict plugin for 0.1rc1
2
#
362 by Martin Pool
- Import stat-cache code
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
1185.13.2 by Robert Collins
Merge Aarons conflict plugin for 0.1rc1
7
#
362 by Martin Pool
- Import stat-cache code
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
1185.13.2 by Robert Collins
Merge Aarons conflict plugin for 0.1rc1
12
#
362 by Martin Pool
- Import stat-cache code
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
1185.13.2 by Robert Collins
Merge Aarons conflict plugin for 0.1rc1
17
import sys
18
from bzrlib.osutils import is_inside_any
19
from bzrlib.delta import compare_trees
1185.12.27 by Aaron Bentley
Use line log for pending merges
20
from bzrlib.log import line_log
21
from bzrlib.errors import NoSuchRevision
362 by Martin Pool
- Import stat-cache code
22
465 by Martin Pool
- Move show_status() out of Branch into a new function in
23
24
def show_status(branch, show_unchanged=False,
483 by Martin Pool
- change 'file_list' to more explanatory 'specific_files'
25
                specific_files=None,
915 by Martin Pool
- add simple test case for bzr status
26
                show_ids=False,
974.1.48 by Aaron Bentley
Status command shows pending merges
27
                to_file=None,
1185.1.35 by Robert Collins
Heikki Paajanen's status -r patch
28
                show_pending=True,
29
                revision=None):
1185.3.1 by Martin Pool
- docstring fix from Magnus Therning
30
    """Display status for non-ignored working files.
465 by Martin Pool
- Move show_status() out of Branch into a new function in
31
1185.3.1 by Martin Pool
- docstring fix from Magnus Therning
32
    show_unchanged
33
        If set, includes unchanged files.
465 by Martin Pool
- Move show_status() out of Branch into a new function in
34
483 by Martin Pool
- change 'file_list' to more explanatory 'specific_files'
35
    specific_files
465 by Martin Pool
- Move show_status() out of Branch into a new function in
36
        If set, only show the status of files in this list.
915 by Martin Pool
- add simple test case for bzr status
37
1185.3.1 by Martin Pool
- docstring fix from Magnus Therning
38
    show_ids
39
        If set, includes each file's id.
40
915 by Martin Pool
- add simple test case for bzr status
41
    to_file
42
        If set, write to this file (default stdout.)
1185.3.1 by Martin Pool
- docstring fix from Magnus Therning
43
44
    show_pending
45
        If set, write pending merges.
1092.3.4 by Robert Collins
update symlink branch to integration
46
1185.1.35 by Robert Collins
Heikki Paajanen's status -r patch
47
    revision
48
        If None the compare latest revision with working tree
49
        If one revision show compared it with working tree.
50
        If two revisions show status between first and second.
465 by Martin Pool
- Move show_status() out of Branch into a new function in
51
    """
915 by Martin Pool
- add simple test case for bzr status
52
    if to_file == None:
53
        to_file = sys.stdout
580 by Martin Pool
- Use explicit lock methods on a branch, rather than doing it
54
    
610 by Martin Pool
- replace Branch.lock(mode) with separate lock_read and lock_write
55
    branch.lock_read()
580 by Martin Pool
- Use explicit lock methods on a branch, rather than doing it
56
    try:
1185.1.35 by Robert Collins
Heikki Paajanen's status -r patch
57
        new_is_working_tree = True
58
        if revision is None:
59
            old = branch.basis_tree()
60
            new = branch.working_tree()
61
        elif len(revision) > 0:
62
            try:
63
                rev_id = revision[0].in_history(branch).rev_id
64
                old = branch.revision_tree(rev_id)
65
            except NoSuchRevision, e:
66
                raise BzrCommandError(str(e))
67
            if len(revision) > 1:
68
                try:
69
                    rev_id = revision[1].in_history(branch).rev_id
70
                    new = branch.revision_tree(rev_id)
71
                    new_is_working_tree = False
72
                except NoSuchRevision, e:
73
                    raise BzrCommandError(str(e))
74
            else:
75
                new = branch.working_tree()
76
                
580 by Martin Pool
- Use explicit lock methods on a branch, rather than doing it
77
78
        delta = compare_trees(old, new, want_unchanged=show_unchanged,
79
                              specific_files=specific_files)
80
915 by Martin Pool
- add simple test case for bzr status
81
        delta.show(to_file,
82
                   show_ids=show_ids,
580 by Martin Pool
- Use explicit lock methods on a branch, rather than doing it
83
                   show_unchanged=show_unchanged)
84
1185.1.35 by Robert Collins
Heikki Paajanen's status -r patch
85
        if new_is_working_tree:
1185.14.11 by Aaron Bentley
moved conflict listing into status and stopped monkey-patching
86
            conflicts = new.iter_conflicts()
1185.1.35 by Robert Collins
Heikki Paajanen's status -r patch
87
            unknowns = new.unknowns()
1185.14.11 by Aaron Bentley
moved conflict listing into status and stopped monkey-patching
88
            list_paths('unknown', unknowns, specific_files, to_file)
89
            list_paths('conflicts', conflicts, specific_files, to_file)
1185.1.35 by Robert Collins
Heikki Paajanen's status -r patch
90
            if show_pending and len(branch.pending_merges()) > 0:
91
                print >>to_file, 'pending merges:'
92
                for merge in branch.pending_merges():
1185.12.27 by Aaron Bentley
Use line log for pending merges
93
                    try:
94
                        m_revision = branch.get_revision(merge)
95
                        print >> to_file, ' ', line_log(m_revision, 77)
96
                    except NoSuchRevision:
97
                        print >> to_file, ' ', merge 
98
                        
580 by Martin Pool
- Use explicit lock methods on a branch, rather than doing it
99
    finally:
100
        branch.unlock()
101
        
1185.14.11 by Aaron Bentley
moved conflict listing into status and stopped monkey-patching
102
def list_paths(header, paths, specific_files, to_file):
103
    done_header = False
104
    for path in paths:
105
        if specific_files and not is_inside_any(specific_files, path):
106
            continue
107
        if not done_header:
108
            print >>to_file, '%s:' % header
109
            done_header = True
110
        print >>to_file, ' ', path