/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/tree.py

  • Committer: Jelmer Vernooij
  • Date: 2018-11-16 18:35:30 UTC
  • mfrom: (7143.15.15 more-cleanups)
  • mto: This revision was merged to the branch mainline in revision 7178.
  • Revision ID: jelmer@jelmer.uk-20181116183530-ue8yx60h5tinl2wy
Merge more-cleanups.

Show diffs side-by-side

added added

removed removed

Lines of Context:
140
140
        :param want_unchanged: An optional boolean requesting the inclusion of
141
141
            unchanged entries in the result.
142
142
        :param extra_trees: An optional list of additional trees to use when
143
 
            mapping the contents of specific_files (paths) to file_ids.
 
143
            mapping the contents of specific_files (paths) to their identities.
144
144
        :param require_versioned: An optional boolean (defaults to False). When
145
145
            supplied and True all the 'specific_files' must be versioned, or
146
146
            a PathsNotVersionedError will be thrown.
243
243
        """
244
244
        raise NotImplementedError(self.iter_entries_by_dir)
245
245
 
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.
248
248
 
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
253
252
        """
254
253
        raise NotImplementedError(self.iter_child_entries)
270
269
                if entry.kind == 'tree-reference':
271
270
                    yield path, entry.file_id
272
271
 
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__)
276
275
 
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.
279
278
 
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.
282
281
        """
283
 
        return self.kind(path, file_id)
 
282
        return self.kind(path)
284
283
 
285
284
    def path_content_summary(self, path):
286
285
        """Get a summary of the information about path.
300
299
        """
301
300
        raise NotImplementedError(self.path_content_summary)
302
301
 
303
 
    def get_reference_revision(self, path, file_id=None):
 
302
    def get_reference_revision(self, path):
304
303
        raise NotImplementedError("Tree subclass %s must implement "
305
304
                                  "get_reference_revision"
306
305
                                  % self.__class__.__name__)
316
315
        """
317
316
        raise NotImplementedError(self._comparison_data)
318
317
 
319
 
    def get_file(self, path, file_id=None):
320
 
        """Return a file object for the file file_id in the tree.
321
 
 
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.
324
320
        """
325
321
        raise NotImplementedError(self.get_file)
326
322
 
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.
329
325
 
330
326
        The default implementation returns (self.get_file, None) for backwards
331
327
        compatibility.
332
328
 
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.
338
333
        """
339
 
        return (self.get_file(path, file_id), None)
 
334
        return (self.get_file(path), None)
340
335
 
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.
343
338
 
344
339
        :param path: The path of the file.
345
 
        :param file_id: The file_id of the file.
346
 
 
347
 
        If both file_id and path are supplied, an implementation may use
348
 
        either one.
349
340
 
350
341
        :returns: A single byte string for the whole file.
351
342
        """
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()
354
345
 
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.
357
348
 
358
349
        :param path: The path of the file.
359
 
        :param file_id: The file_id of the file.
360
 
 
361
 
        If both file_id and path are supplied, an implementation may use
362
 
        either one.
363
350
        """
364
 
        return osutils.split_lines(self.get_file_text(path, file_id))
 
351
        return osutils.split_lines(self.get_file_text(path))
365
352
 
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.
368
355
 
369
356
        The default implementation returns a sha1.
370
357
 
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
376
362
        """
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))
379
364
 
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.
382
367
 
383
368
        :note: callers should use get_file_verifier instead
385
370
            have quicker access to a non-sha1 verifier.
386
371
 
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
391
374
        """
392
375
        raise NotImplementedError(self.get_file_sha1)
393
376
 
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.
396
379
 
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.
400
381
        """
401
382
        raise NotImplementedError(self.get_file_mtime)
402
383
 
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.
405
386
 
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
409
389
        """
410
390
        raise NotImplementedError(self.get_file_size)
411
391
 
412
 
    def is_executable(self, path, file_id=None):
 
392
    def is_executable(self, path):
413
393
        """Check if a file is executable.
414
394
 
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.
418
396
        """
419
397
        raise NotImplementedError(self.is_executable)
420
398
 
444
422
            cur_file = (self.get_file_text(path),)
445
423
            yield identifier, cur_file
446
424
 
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.
449
427
 
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
451
429
        a symlink.
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
455
 
        either one.
456
431
        :return: The path the symlink points to.
457
432
        """
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)
463
438
 
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.
467
442
 
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
474
449
            this value.
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)
964
939
        desired.
965
940
 
966
941
        :param tree: The tree to lookup the entry in.
967
 
        :param file_id: The file_id to lookup.
 
942
        :param path: The path to look up
968
943
        """
969
944
        # No inventory available.
970
945
        try:
1063
1038
 
1064
1039
    def file_content_matches(
1065
1040
            self, source_path, target_path,
1066
 
            source_file_id=None, target_file_id=None,
1067
1041
            source_stat=None, target_stat=None):
1068
1042
        """Check if two files are the same in the source and target trees.
1069
1043
 
1080
1054
        """
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