264
264
specific_files, external_diff_options,
265
265
old_label='a/', new_label='b/' ):
267
# GNU Patch uses the epoch date to detect files that are being added
268
# or removed in a diff.
269
EPOCH_DATE = '1970-01-01 00:00:00 +0000'
267
271
# TODO: Generation of pseudo-diffs for added/deleted files could
268
272
# be usefully made into a much faster special case.
284
288
for path, file_id, kind in delta.removed:
286
290
print >>to_file, '=== removed %s %r' % (kind, path)
287
old_date = time.strftime('%Y-%m-%d %H:%M:%S +0000',
288
time.gmtime(old_tree.get_file_mtime(file_id)))
289
old_name = '%s%s\t%s' % (old_label, path, old_date)
290
new_name = '%s%s\t1970-01-01 00:00:00 +0000' % (new_label, path)
291
old_name = '%s%s\t%s' % (old_label, path,
292
_patch_header_date(old_tree, file_id))
293
new_name = '%s%s\t%s' % (new_label, path, EPOCH_DATE)
291
294
old_tree.inventory[file_id].diff(diff_file, old_name, old_tree,
292
295
new_name, None, None, to_file)
293
296
for path, file_id, kind in delta.added:
295
298
print >>to_file, '=== added %s %r' % (kind, path)
296
old_name = '%s%s\t1970-01-01 00:00:00 +0000' % (old_label, path)
297
new_date = time.strftime('%Y-%m-%d %H:%M:%S +0000',
298
time.gmtime(new_tree.get_file_mtime(file_id)))
299
new_name = '%s%s\t%s' % (new_label, path, new_date)
299
old_name = '%s%s\t%s' % (old_label, path, EPOCH_DATE)
300
new_name = '%s%s\t%s' % (new_label, path,
301
_patch_header_date(new_tree, file_id))
300
302
new_tree.inventory[file_id].diff(diff_file, new_name, new_tree,
301
303
old_name, None, None, to_file,
306
308
prop_str = get_prop_change(meta_modified)
307
309
print >>to_file, '=== renamed %s %r => %r%s' % (
308
310
kind, old_path, new_path, prop_str)
309
old_date = time.strftime('%Y-%m-%d %H:%M:%S +0000',
310
time.gmtime(old_tree.get_file_mtime(file_id)))
311
old_name = '%s%s\t%s' % (old_label, old_path, old_date)
312
new_date = time.strftime('%Y-%m-%d %H:%M:%S +0000',
313
time.gmtime(new_tree.get_file_mtime(file_id)))
314
new_name = '%s%s\t%s' % (new_label, new_path, new_date)
311
old_name = '%s%s\t%s' % (old_label, old_path,
312
_patch_header_date(old_tree, file_id))
313
new_name = '%s%s\t%s' % (new_label, new_path,
314
_patch_header_date(new_tree, file_id))
315
315
_maybe_diff_file_or_symlink(old_name, old_tree, file_id,
316
316
new_name, new_tree,
317
317
text_modified, kind, to_file, diff_file)
320
320
prop_str = get_prop_change(meta_modified)
321
321
print >>to_file, '=== modified %s %r%s' % (kind, path, prop_str)
322
old_date = time.strftime('%Y-%m-%d %H:%M:%S +0000',
323
time.gmtime(old_tree.get_file_mtime(file_id)))
324
old_name = '%s%s\t%s' % (old_label, path, old_date)
325
new_date = time.strftime('%Y-%m-%d %H:%M:%S +0000',
326
time.gmtime(new_tree.get_file_mtime(file_id)))
327
new_name = '%s%s\t%s' % (new_label, path, new_date)
322
old_name = '%s%s\t%s' % (old_label, path,
323
_patch_header_date(old_tree, file_id))
324
new_name = '%s%s\t%s' % (new_label, path,
325
_patch_header_date(new_tree, file_id))
328
326
if text_modified:
329
327
_maybe_diff_file_or_symlink(old_name, old_tree, file_id,
330
328
new_name, new_tree,
333
331
return has_changes
334
def _patch_header_date(tree, file_id):
335
"""Returns a timestamp suitable for use in a patch header."""
336
tm = time.gmtime(tree.get_file_mtime(file_id))
337
return time.strftime('%Y-%m-%d %H:%M:%S +0000', tm)
336
340
def _raise_if_doubly_unversioned(specific_files, old_tree, new_tree):
337
341
"""Complain if paths are not versioned in either tree."""
338
342
if not specific_files: