~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/delta.py

  • Committer: Martin Pool
  • Date: 2005-11-28 08:03:42 UTC
  • mto: (1185.33.61 bzr.dev)
  • mto: This revision was merged to the branch mainline in revision 1518.
  • Revision ID: mbp@sourcefrog.net-20051128080342-b7db3190dca90484
[broken] start converting basic_io to more rfc822-like format

Suggestions from mailing list:
 
  no double quotes
  no cute right-alignment
  no escaping
  just indent continuation lines

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#! /usr/bin/env python
2
1
# -*- coding: UTF-8 -*-
3
2
 
4
3
# This program is free software; you can redistribute it and/or modify
15
14
# along with this program; if not, write to the Free Software
16
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
16
 
 
17
from bzrlib.inventory import InventoryEntry
18
18
from bzrlib.trace import mutter
19
19
 
20
20
class TreeDelta(object):
27
27
    removed
28
28
        (path, id, kind)
29
29
    renamed
30
 
        (oldpath, newpath, id, kind, text_modified)
 
30
        (oldpath, newpath, id, kind, text_modified, meta_modified)
31
31
    modified
32
 
        (path, id, kind)
 
32
        (path, id, kind, text_modified, meta_modified)
33
33
    unchanged
34
34
        (path, id, kind)
35
35
 
36
36
    Each id is listed only once.
37
37
 
38
38
    Files that are both modified and renamed are listed only in
39
 
    renamed, with the text_modified flag true.
 
39
    renamed, with the text_modified flag true. The text_modified
 
40
    applies either to the the content of the file or the target of the
 
41
    symbolic link, depending of the kind of file.
40
42
 
41
43
    Files are only considered renamed if their name has changed or
42
44
    their parent directory has changed.  Renaming a directory
69
71
            self.modified, self.unchanged)
70
72
 
71
73
    def has_changed(self):
72
 
        changes = len(self.added) + len(self.removed) + len(self.renamed)
73
 
        changes += len(self.modified) 
74
 
        return (changes != 0)
 
74
        return bool(self.modified
 
75
                    or self.added
 
76
                    or self.removed
 
77
                    or self.renamed)
75
78
 
76
79
    def touches_file_id(self, file_id):
77
80
        """Return True if file_id is modified by this delta."""
87
90
 
88
91
    def show(self, to_file, show_ids=False, show_unchanged=False):
89
92
        def show_list(files):
90
 
            for path, fid, kind in files:
 
93
            for item in files:
 
94
                path, fid, kind = item[:3]
 
95
 
91
96
                if kind == 'directory':
92
97
                    path += '/'
93
98
                elif kind == 'symlink':
94
99
                    path += '@'
95
 
                    
 
100
 
 
101
                if len(item) == 5 and item[4]:
 
102
                    path += '*'
 
103
 
96
104
                if show_ids:
97
105
                    print >>to_file, '  %-30s %s' % (path, fid)
98
106
                else:
106
114
            print >>to_file, 'added:'
107
115
            show_list(self.added)
108
116
 
 
117
        extra_modified = []
 
118
 
109
119
        if self.renamed:
110
120
            print >>to_file, 'renamed:'
111
 
            for oldpath, newpath, fid, kind, text_modified in self.renamed:
 
121
            for (oldpath, newpath, fid, kind,
 
122
                 text_modified, meta_modified) in self.renamed:
 
123
                if text_modified or meta_modified:
 
124
                    extra_modified.append((newpath, fid, kind,
 
125
                                           text_modified, meta_modified))
 
126
                if meta_modified:
 
127
                    newpath += '*'
112
128
                if show_ids:
113
129
                    print >>to_file, '  %s => %s %s' % (oldpath, newpath, fid)
114
130
                else:
115
131
                    print >>to_file, '  %s => %s' % (oldpath, newpath)
116
132
                    
117
 
        if self.modified:
 
133
        if self.modified or extra_modified:
118
134
            print >>to_file, 'modified:'
119
135
            show_list(self.modified)
 
136
            show_list(extra_modified)
120
137
            
121
138
        if show_unchanged and self.unchanged:
122
139
            print >>to_file, 'unchanged:'
161
178
            kind = old_ie.kind
162
179
            assert kind == new_ie.kind
163
180
            
164
 
            assert kind in ('file', 'directory', 'symlink', 'root_directory'), \
 
181
            assert kind in InventoryEntry.known_kinds, \
165
182
                   'invalid file kind %r' % kind
166
183
 
167
184
            if kind == 'root_directory':
172
189
                    and not is_inside_any(specific_files, new_inv.id2path(file_id))):
173
190
                    continue
174
191
 
175
 
            if kind == 'file':
176
 
                old_sha1 = old_tree.get_file_sha1(file_id)
177
 
                new_sha1 = new_tree.get_file_sha1(file_id)
178
 
                text_modified = (old_sha1 != new_sha1)
179
 
            else:
180
 
                ## mutter("no text to check for %r %r" % (file_id, kind))
181
 
                text_modified = False
 
192
            # temporary hack until all entries are populated before clients 
 
193
            # get them
 
194
            old_path = old_inv.id2path(file_id)
 
195
            new_path = new_inv.id2path(file_id)
 
196
            old_ie._read_tree_state(old_path, old_tree)
 
197
            new_ie._read_tree_state(new_path, new_tree)
 
198
            text_modified, meta_modified = new_ie.detect_changes(old_ie)
182
199
 
183
200
            # TODO: Can possibly avoid calculating path strings if the
184
201
            # two files are unchanged and their names and parents are
187
204
            
188
205
            if (old_ie.name != new_ie.name
189
206
                or old_ie.parent_id != new_ie.parent_id):
190
 
                delta.renamed.append((old_inv.id2path(file_id),
191
 
                                      new_inv.id2path(file_id),
 
207
                delta.renamed.append((old_path,
 
208
                                      new_path,
192
209
                                      file_id, kind,
193
 
                                      text_modified))
194
 
            elif text_modified:
195
 
                delta.modified.append((new_inv.id2path(file_id), file_id, kind))
 
210
                                      text_modified, meta_modified))
 
211
            elif text_modified or meta_modified:
 
212
                delta.modified.append((new_path, file_id, kind,
 
213
                                       text_modified, meta_modified))
196
214
            elif want_unchanged:
197
 
                delta.unchanged.append((new_inv.id2path(file_id), file_id, kind))
 
215
                delta.unchanged.append((new_path, file_id, kind))
198
216
        else:
199
217
            kind = old_inv.get_file_kind(file_id)
200
218
            if kind == 'root_directory':
207
225
 
208
226
    mutter('start looking for new files')
209
227
    for file_id in new_inv:
210
 
        if file_id in old_inv:
 
228
        if file_id in old_inv or file_id not in new_tree:
211
229
            continue
212
230
        kind = new_inv.get_file_kind(file_id)
213
231
        if kind == 'root_directory':