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