/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-10-29 11:27:33 UTC
  • mto: This revision was merged to the branch mainline in revision 7170.
  • Revision ID: jelmer@jelmer.uk-20181029112733-bjvm24z12svwl53m
Get rid of file_ids in most of Tree.

Show diffs side-by-side

added added

removed removed

Lines of Context:
142
142
        :param want_unchanged: An optional boolean requesting the inclusion of
143
143
            unchanged entries in the result.
144
144
        :param extra_trees: An optional list of additional trees to use when
145
 
            mapping the contents of specific_files (paths) to file_ids.
 
145
            mapping the contents of specific_files (paths) to their identities.
146
146
        :param require_versioned: An optional boolean (defaults to False). When
147
147
            supplied and True all the 'specific_files' must be versioned, or
148
148
            a PathsNotVersionedError will be thrown.
245
245
        """
246
246
        raise NotImplementedError(self.iter_entries_by_dir)
247
247
 
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.
250
250
 
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
255
254
        """
256
255
        raise NotImplementedError(self.iter_child_entries)
272
271
                if entry.kind == 'tree-reference':
273
272
                    yield path, entry.file_id
274
273
 
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__)
278
277
 
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.
281
280
 
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.
284
283
        """
285
 
        return self.kind(path, file_id)
 
284
        return self.kind(path)
286
285
 
287
286
    def path_content_summary(self, path):
288
287
        """Get a summary of the information about path.
302
301
        """
303
302
        raise NotImplementedError(self.path_content_summary)
304
303
 
305
 
    def get_reference_revision(self, path, file_id=None):
 
304
    def get_reference_revision(self, path):
306
305
        raise NotImplementedError("Tree subclass %s must implement "
307
306
                                  "get_reference_revision"
308
307
            % self.__class__.__name__)
318
317
        """
319
318
        raise NotImplementedError(self._comparison_data)
320
319
 
321
 
    def get_file(self, path, file_id=None):
322
 
        """Return a file object for the file file_id in the tree.
323
 
 
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.
326
322
        """
327
323
        raise NotImplementedError(self.get_file)
328
324
 
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.
331
327
 
332
328
        The default implementation returns (self.get_file, None) for backwards
333
329
        compatibility.
334
330
 
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.
340
335
        """
341
 
        return (self.get_file(path, file_id), None)
 
336
        return (self.get_file(path), None)
342
337
 
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.
345
340
 
346
341
        :param path: The path of the file.
347
 
        :param file_id: The file_id of the file.
348
 
 
349
 
        If both file_id and path are supplied, an implementation may use
350
 
        either one.
351
342
 
352
343
        :returns: A single byte string for the whole file.
353
344
        """
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()
356
347
 
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.
359
350
 
360
351
        :param path: The path of the file.
361
 
        :param file_id: The file_id of the file.
362
 
 
363
 
        If both file_id and path are supplied, an implementation may use
364
 
        either one.
365
352
        """
366
 
        return osutils.split_lines(self.get_file_text(path, file_id))
 
353
        return osutils.split_lines(self.get_file_text(path))
367
354
 
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.
370
357
 
371
358
        The default implementation returns a sha1.
372
359
 
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
378
364
        """
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))
381
366
 
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.
384
369
 
385
370
        :note: callers should use get_file_verifier instead
387
372
            have quicker access to a non-sha1 verifier.
388
373
 
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
393
376
        """
394
377
        raise NotImplementedError(self.get_file_sha1)
395
378
 
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.
398
381
 
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.
402
383
        """
403
384
        raise NotImplementedError(self.get_file_mtime)
404
385
 
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.
407
388
 
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
411
391
        """
412
392
        raise NotImplementedError(self.get_file_size)
413
393
 
414
 
    def is_executable(self, path, file_id=None):
 
394
    def is_executable(self, path):
415
395
        """Check if a file is executable.
416
396
 
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.
420
398
        """
421
399
        raise NotImplementedError(self.is_executable)
422
400
 
446
424
            cur_file = (self.get_file_text(path),)
447
425
            yield identifier, cur_file
448
426
 
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.
451
429
 
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
453
431
        a symlink.
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
457
 
        either one.
458
433
        :return: The path the symlink points to.
459
434
        """
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)
465
440
 
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.
469
444
 
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
476
451
            this value.
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)
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:
1060
1035
 
1061
1036
    def file_content_matches(
1062
1037
            self, source_path, target_path,
1063
 
            source_file_id=None, target_file_id=None,
1064
1038
            source_stat=None, target_stat=None):
1065
1039
        """Check if two files are the same in the source and target trees.
1066
1040
 
1077
1051
        """
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