~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/changeset/serializer/v07.py

  • Committer: Aaron Bentley
  • Date: 2006-05-19 20:37:09 UTC
  • mto: This revision was merged to the branch mainline in revision 1738.
  • Revision ID: abentley@panoramicfeedback.com-20060519203709-04f80427ff5c00f5
Got first binary test passing

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
        CHANGESET_HEADER,
25
25
        format_highres_date, unpack_highres_date)
26
26
from bzrlib.changeset.common import testament_sha1
 
27
from bzrlib.changeset.serializer import binary_diff
27
28
from bzrlib.delta import compare_trees
28
29
from bzrlib.diff import internal_diff
29
30
import bzrlib.errors as errors
31
32
from bzrlib.revision import NULL_REVISION
32
33
from bzrlib.rio import RioWriter, read_stanzas
33
34
import bzrlib.ui
 
35
from bzrlib.textfile import text_file
34
36
 
35
37
bool_text = {True: 'yes', False: 'no'}
36
38
 
168
170
        new_label = ''
169
171
 
170
172
        def do_diff(old_path, file_id, new_path, kind):
171
 
            new_entry = new_tree.inventory[file_id]
172
 
            old_tree.inventory[file_id].diff(internal_diff,
173
 
                    pathjoin(old_label, old_path), old_tree,
174
 
                    pathjoin(new_label, new_path), new_entry, new_tree,
175
 
                    self.to_file)
 
173
            def tree_lines(tree, require_text=False):
 
174
                if file_id in tree:
 
175
                    tree_file = tree.get_file(file_id)
 
176
                    if require_text is True:
 
177
                        tree_file = text_file(tree_file)
 
178
                    return tree_file.readlines()
 
179
                else:
 
180
                    return []
 
181
 
 
182
            try:
 
183
                old_lines = tree_lines(old_tree, require_text=True)
 
184
                new_lines = tree_lines(new_tree, require_text=True)
 
185
                self.to_file.write('\n')
 
186
                internal_diff(old_path, old_lines, new_path, new_lines, 
 
187
                              self.to_file)
 
188
            except errors.BinaryFile:
 
189
                old_lines = tree_lines(old_tree, require_text=False)
 
190
                new_lines = tree_lines(new_tree, require_text=False)
 
191
                self.to_file.write(' // encoding:base64\n')
 
192
                binary_diff(old_path, old_lines, new_path, new_lines, 
 
193
                            self.to_file)
 
194
 
176
195
        def do_meta(file_id):
177
196
            ie = new_tree.inventory[file_id]
178
197
            w(' // executable:%s' % bool_text[ie.executable])
200
219
                do_meta(file_id)
201
220
            if kind == 'symlink':
202
221
                do_target(new_tree.inventory[file_id].symlink_target)
203
 
            w('\n')
204
222
            if kind == 'file':
205
 
                new_tree.inventory[file_id].diff(internal_diff,
206
 
                        pathjoin(new_label, path), new_tree,
207
 
                        DEVNULL, None, None,
208
 
                        self.to_file, reverse=True)
 
223
                do_diff(DEVNULL, file_id, path, kind)
 
224
            else:
 
225
                w('\n')
 
226
 
209
227
 
210
228
        for (old_path, new_path, file_id, kind,
211
229
             text_modified, meta_modified) in delta.renamed:
215
233
                do_meta(file_id)
216
234
            if text_modified and kind == "symlink":
217
235
                do_target(new_tree.inventory[file_id].symlink_target)
218
 
            w('\n')
219
236
            if text_modified and kind == "file":
220
237
                do_diff(old_path, file_id, new_path, text_modified)
 
238
            else:
 
239
                w('\n')
221
240
 
222
241
        for (path, file_id, kind,
223
242
             text_modified, meta_modified) in delta.modified:
229
248
                do_meta(file_id)
230
249
            if text_modified and kind == "symlink":
231
250
                do_target(new_tree.inventory[file_id].symlink_target)
232
 
            w('\n')
233
251
            if text_modified and kind == "file":
234
252
                do_diff(path, file_id, path, kind)
235
 
 
236
 
 
 
253
            else:
 
254
                w('\n')