~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/diff.py

  • Committer: Martin Pool
  • Date: 2005-05-25 03:27:02 UTC
  • Revision ID: mbp@sourcefrog.net-20050525032702-395f038adb33c235
- clean up statcache code
- stat files in order by inum
- report on added/deleted files

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
# along with this program; if not, write to the Free Software
16
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
17
 
18
 
from sets import Set, ImmutableSet
19
 
 
20
18
from trace import mutter
21
19
from errors import BzrError
22
20
 
67
65
    print >>to_file
68
66
 
69
67
 
 
68
 
70
69
def show_diff(b, revision, specific_files):
71
70
    import sys
72
71
 
77
76
        
78
77
    new_tree = b.working_tree()
79
78
 
 
79
    show_diff_trees(old_tree, new_tree, sys.stdout, specific_files)
 
80
 
 
81
 
 
82
 
 
83
def show_diff_trees(old_tree, new_tree, to_file, specific_files=None):
 
84
    """Show in text form the changes from one tree to another.
 
85
 
 
86
    to_files
 
87
        If set, include only changes to these files.
 
88
    """
 
89
 
80
90
    # TODO: Options to control putting on a prefix or suffix, perhaps as a format string
81
91
    old_label = ''
82
92
    new_label = ''
97
107
        if kind == 'file':
98
108
            _diff_one(old_tree.get_file(file_id).readlines(),
99
109
                   [],
100
 
                   sys.stdout,
 
110
                   to_file,
101
111
                   fromfile=old_label + path,
102
112
                   tofile=DEVNULL)
103
113
 
106
116
        if kind == 'file':
107
117
            _diff_one([],
108
118
                   new_tree.get_file(file_id).readlines(),
109
 
                   sys.stdout,
 
119
                   to_file,
110
120
                   fromfile=DEVNULL,
111
121
                   tofile=new_label + path)
112
122
 
115
125
        if text_modified:
116
126
            _diff_one(old_tree.get_file(file_id).readlines(),
117
127
                   new_tree.get_file(file_id).readlines(),
118
 
                   sys.stdout,
 
128
                   to_file,
119
129
                   fromfile=old_label + old_path,
120
130
                   tofile=new_label + new_path)
121
131
 
124
134
        if kind == 'file':
125
135
            _diff_one(old_tree.get_file(file_id).readlines(),
126
136
                   new_tree.get_file(file_id).readlines(),
127
 
                   sys.stdout,
 
137
                   to_file,
128
138
                   fromfile=old_label + path,
129
139
                   tofile=new_label + path)
130
140
 
160
170
        self.modified = []
161
171
        self.unchanged = []
162
172
 
 
173
 
 
174
    def touches_file_id(self, file_id):
 
175
        """Return True if file_id is modified by this delta."""
 
176
        for l in self.added, self.removed, self.modified:
 
177
            for v in l:
 
178
                if v[1] == file_id:
 
179
                    return True
 
180
        for v in self.renamed:
 
181
            if v[2] == file_id:
 
182
                return True
 
183
        return False
 
184
            
 
185
 
163
186
    def show(self, to_file, show_ids=False, show_unchanged=False):
164
187
        def show_list(files):
165
188
            for path, fid, kind in files: