~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/delta.py

  • Committer: Martin Pool
  • Date: 2005-10-04 11:13:33 UTC
  • mto: (1185.13.3)
  • mto: This revision was merged to the branch mainline in revision 1403.
  • Revision ID: mbp@sourcefrog.net-20051004111332-f7b8a6bd41b9fe22
- tweak capture_tree formatting

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
88
90
 
89
91
    def show(self, to_file, show_ids=False, show_unchanged=False):
90
92
        def show_list(files):
91
 
            for path, fid, kind in files:
 
93
            for item in files:
 
94
                path, fid, kind = item[:3]
 
95
 
92
96
                if kind == 'directory':
93
97
                    path += '/'
94
98
                elif kind == 'symlink':
95
99
                    path += '@'
96
 
                    
 
100
 
 
101
                if len(item) == 5 and item[4]:
 
102
                    path += '*'
 
103
 
97
104
                if show_ids:
98
105
                    print >>to_file, '  %-30s %s' % (path, fid)
99
106
                else:
109
116
 
110
117
        if self.renamed:
111
118
            print >>to_file, 'renamed:'
112
 
            for oldpath, newpath, fid, kind, text_modified in self.renamed:
 
119
            for (oldpath, newpath, fid, kind,
 
120
                 text_modified, meta_modified) in self.renamed:
 
121
                if meta_modified:
 
122
                    newpath += '*'
113
123
                if show_ids:
114
124
                    print >>to_file, '  %s => %s %s' % (oldpath, newpath, fid)
115
125
                else:
162
172
            kind = old_ie.kind
163
173
            assert kind == new_ie.kind
164
174
            
165
 
            assert kind in ('file', 'directory', 'symlink', 'root_directory'), \
 
175
            assert kind in InventoryEntry.known_kinds, \
166
176
                   'invalid file kind %r' % kind
167
177
 
168
178
            if kind == 'root_directory':
173
183
                    and not is_inside_any(specific_files, new_inv.id2path(file_id))):
174
184
                    continue
175
185
 
176
 
            if kind == 'file':
177
 
                old_sha1 = old_tree.get_file_sha1(file_id)
178
 
                new_sha1 = new_tree.get_file_sha1(file_id)
179
 
                text_modified = (old_sha1 != new_sha1)
180
 
            else:
181
 
                ## mutter("no text to check for %r %r" % (file_id, kind))
182
 
                text_modified = False
 
186
            # temporary hack until all entries are populated before clients 
 
187
            # get them
 
188
            old_path = old_inv.id2path(file_id)
 
189
            new_path = new_inv.id2path(file_id)
 
190
            old_ie._read_tree_state(old_path, old_tree)
 
191
            new_ie._read_tree_state(new_path, new_tree)
 
192
            text_modified, meta_modified = new_ie.detect_changes(old_ie)
183
193
 
184
194
            # TODO: Can possibly avoid calculating path strings if the
185
195
            # two files are unchanged and their names and parents are
188
198
            
189
199
            if (old_ie.name != new_ie.name
190
200
                or old_ie.parent_id != new_ie.parent_id):
191
 
                delta.renamed.append((old_inv.id2path(file_id),
192
 
                                      new_inv.id2path(file_id),
 
201
                delta.renamed.append((old_path,
 
202
                                      new_path,
193
203
                                      file_id, kind,
194
 
                                      text_modified))
195
 
            elif text_modified:
196
 
                delta.modified.append((new_inv.id2path(file_id), file_id, kind))
 
204
                                      text_modified, meta_modified))
 
205
            elif text_modified or meta_modified:
 
206
                delta.modified.append((new_path, file_id, kind,
 
207
                                       text_modified, meta_modified))
197
208
            elif want_unchanged:
198
 
                delta.unchanged.append((new_inv.id2path(file_id), file_id, kind))
 
209
                delta.unchanged.append((new_path, file_id, kind))
199
210
        else:
200
211
            kind = old_inv.get_file_kind(file_id)
201
212
            if kind == 'root_directory':