244
244
raise NotImplementedError(self.iter_entries_by_dir)
246
def iter_child_entries(self, path, file_id=None):
246
def iter_child_entries(self, path):
247
247
"""Iterate over the children of a directory or tree reference.
249
249
:param path: Path of the directory
250
:param file_id: Optional file id of the directory/tree-reference
251
:raise NoSuchId: When the file_id does not exist
250
:raise NoSuchFile: When the path does not exist
252
251
:return: Iterator over entries in the directory
254
253
raise NotImplementedError(self.iter_child_entries)
270
269
if entry.kind == 'tree-reference':
271
270
yield path, entry.file_id
273
def kind(self, path, file_id=None):
272
def kind(self, path):
274
273
raise NotImplementedError("Tree subclass %s must implement kind"
275
274
% self.__class__.__name__)
277
def stored_kind(self, path, file_id=None):
278
"""File kind stored for this file_id.
276
def stored_kind(self, path):
277
"""File kind stored for this path.
280
279
May not match kind on disk for working trees. Always available
281
280
for versioned files, even when the file itself is missing.
283
return self.kind(path, file_id)
282
return self.kind(path)
285
284
def path_content_summary(self, path):
286
285
"""Get a summary of the information about path.
317
316
raise NotImplementedError(self._comparison_data)
319
def get_file(self, path, file_id=None):
320
"""Return a file object for the file file_id in the tree.
322
If both file_id and path are defined, it is implementation defined as
323
to which one is used.
318
def get_file(self, path):
319
"""Return a file object for the file path in the tree.
325
321
raise NotImplementedError(self.get_file)
327
def get_file_with_stat(self, path, file_id=None):
328
"""Get a file handle and stat object for file_id.
323
def get_file_with_stat(self, path):
324
"""Get a file handle and stat object for path.
330
326
The default implementation returns (self.get_file, None) for backwards
333
329
:param path: The path of the file.
334
:param file_id: The file id to read, if it is known.
335
330
:return: A tuple (file_handle, stat_value_or_None). If the tree has
336
331
no stat facility, or need for a stat cache feedback during commit,
337
332
it may return None for the second element of the tuple.
339
return (self.get_file(path, file_id), None)
334
return (self.get_file(path), None)
341
def get_file_text(self, path, file_id=None):
336
def get_file_text(self, path):
342
337
"""Return the byte content of a file.
344
339
:param path: The path of the file.
345
:param file_id: The file_id of the file.
347
If both file_id and path are supplied, an implementation may use
350
341
:returns: A single byte string for the whole file.
352
with self.get_file(path, file_id) as my_file:
343
with self.get_file(path) as my_file:
353
344
return my_file.read()
355
def get_file_lines(self, path, file_id=None):
346
def get_file_lines(self, path):
356
347
"""Return the content of a file, as lines.
358
349
:param path: The path of the file.
359
:param file_id: The file_id of the file.
361
If both file_id and path are supplied, an implementation may use
364
return osutils.split_lines(self.get_file_text(path, file_id))
351
return osutils.split_lines(self.get_file_text(path))
366
def get_file_verifier(self, path, file_id=None, stat_value=None):
353
def get_file_verifier(self, path, stat_value=None):
367
354
"""Return a verifier for a file.
369
356
The default implementation returns a sha1.
371
:param file_id: The handle for this file.
372
358
:param path: The path that this file can be found at.
373
359
These must point to the same object.
374
360
:param stat_value: Optional stat value for the object
375
361
:return: Tuple with verifier name and verifier data
377
return ("SHA1", self.get_file_sha1(path, file_id,
378
stat_value=stat_value))
363
return ("SHA1", self.get_file_sha1(path, stat_value=stat_value))
380
def get_file_sha1(self, path, file_id=None, stat_value=None):
365
def get_file_sha1(self, path, stat_value=None):
381
366
"""Return the SHA1 file for a file.
383
368
:note: callers should use get_file_verifier instead
385
370
have quicker access to a non-sha1 verifier.
387
372
:param path: The path that this file can be found at.
388
:param file_id: The handle for this file.
389
These must point to the same object.
390
373
:param stat_value: Optional stat value for the object
392
375
raise NotImplementedError(self.get_file_sha1)
394
def get_file_mtime(self, path, file_id=None):
377
def get_file_mtime(self, path):
395
378
"""Return the modification time for a file.
397
380
:param path: The path that this file can be found at.
398
:param file_id: The handle for this file.
399
These must point to the same object.
401
382
raise NotImplementedError(self.get_file_mtime)
403
def get_file_size(self, path, file_id=None):
384
def get_file_size(self, path):
404
385
"""Return the size of a file in bytes.
406
387
This applies only to regular files. If invoked on directories or
407
388
symlinks, it will return None.
408
:param file_id: The file-id of the file
410
390
raise NotImplementedError(self.get_file_size)
412
def is_executable(self, path, file_id=None):
392
def is_executable(self, path):
413
393
"""Check if a file is executable.
415
395
:param path: The path that this file can be found at.
416
:param file_id: The handle for this file.
417
These must point to the same object.
419
397
raise NotImplementedError(self.is_executable)
444
422
cur_file = (self.get_file_text(path),)
445
423
yield identifier, cur_file
447
def get_symlink_target(self, path, file_id=None):
448
"""Get the target for a given file_id.
425
def get_symlink_target(self, path):
426
"""Get the target for a given path.
450
It is assumed that the caller already knows that file_id is referencing
428
It is assumed that the caller already knows that path is referencing
452
:param file_id: Handle for the symlink entry.
453
430
:param path: The path of the file.
454
If both file_id and path are supplied, an implementation may use
456
431
:return: The path the symlink points to.
458
433
raise NotImplementedError(self.get_symlink_target)
461
436
"""Return the file_id for the root of this tree."""
462
437
raise NotImplementedError(self.get_root_id)
464
def annotate_iter(self, path, file_id=None,
439
def annotate_iter(self, path,
465
440
default_revision=_mod_revision.CURRENT_REVISION):
466
441
"""Return an iterator of revision_id, line tuples.
468
443
For working trees (and mutable trees in general), the special
469
444
revision_id 'current:' will be used for lines that are new in this
470
445
tree, e.g. uncommitted changes.
471
:param file_id: The file to produce an annotated version from
446
:param path: The file to produce an annotated version from
472
447
:param default_revision: For lines that don't match a basis, mark them
473
448
with this revision id. Not all implementations will make use of
748
723
elif source_kind == 'file':
749
724
if not self.file_content_matches(
750
725
source_path, target_path,
751
file_id, file_id, source_stat, target_stat):
726
source_stat, target_stat):
752
727
changed_content = True
753
728
elif source_kind == 'symlink':
754
if (self.source.get_symlink_target(source_path, file_id) !=
755
self.target.get_symlink_target(target_path, file_id)):
729
if (self.source.get_symlink_target(source_path) !=
730
self.target.get_symlink_target(target_path)):
756
731
changed_content = True
757
732
elif source_kind == 'tree-reference':
758
if (self.source.get_reference_revision(source_path, file_id)
759
!= self.target.get_reference_revision(target_path, file_id)):
760
changed_content = True
733
if (self.source.get_reference_revision(source_path)
734
!= self.target.get_reference_revision(target_path)):
735
changed_content = True
761
736
parent = (source_parent, target_parent)
762
737
name = (source_name, target_name)
763
738
executable = (source_executable, target_executable)
1081
1055
with self.lock_read():
1082
1056
source_verifier_kind, source_verifier_data = (
1083
self.source.get_file_verifier(
1084
source_path, source_file_id, source_stat))
1057
self.source.get_file_verifier(source_path, source_stat))
1085
1058
target_verifier_kind, target_verifier_data = (
1086
1059
self.target.get_file_verifier(
1087
target_path, target_file_id, target_stat))
1060
target_path, target_stat))
1088
1061
if source_verifier_kind == target_verifier_kind:
1089
1062
return (source_verifier_data == target_verifier_data)
1090
1063
# Fall back to SHA1 for now