/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 bzrlib/inventory.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2010-08-05 07:02:32 UTC
  • mfrom: (5365.2.2 smaller-inventory-entries)
  • Revision ID: pqm@pqm.ubuntu.com-20100805070232-ezo69a4k078j1xmp
(spiv) Reduce the memory consumption of InventoryEntry instances. (Andrew
 Bennetts)

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
import re
36
36
import tarfile
37
37
 
38
 
import bzrlib
39
38
from bzrlib import (
40
39
    chk_map,
41
40
    errors,
42
41
    generate_ids,
43
42
    osutils,
44
 
    symbol_versioning,
45
43
    )
46
44
""")
47
45
 
49
47
    BzrCheckError,
50
48
    BzrError,
51
49
    )
52
 
from bzrlib.symbol_versioning import deprecated_in, deprecated_method
53
50
from bzrlib.trace import mutter
54
51
from bzrlib.static_tuple import StaticTuple
55
52
 
131
128
    RENAMED = 'renamed'
132
129
    MODIFIED_AND_RENAMED = 'modified and renamed'
133
130
 
134
 
    __slots__ = []
 
131
    __slots__ = ['file_id', 'revision', 'parent_id', 'name']
 
132
 
 
133
    # Attributes that all InventoryEntry instances are expected to have, but
 
134
    # that don't vary for all kinds of entry.  (e.g. symlink_target is only
 
135
    # relevant to InventoryLink, so there's no reason to make every
 
136
    # InventoryFile instance allocate space to hold a value for it.)
 
137
    # Attributes that only vary for files: executable, text_sha1, text_size,
 
138
    # text_id
 
139
    executable = False
 
140
    text_sha1 = None
 
141
    text_size = None
 
142
    text_id = None
 
143
    # Attributes that only vary for symlinks: symlink_target
 
144
    symlink_target = None
 
145
    # Attributes that only vary for tree-references: reference_revision
 
146
    reference_revision = None
 
147
 
135
148
 
136
149
    def detect_changes(self, old_entry):
137
150
        """Return a (text_modified, meta_modified) from this to old_entry.
187
200
        """
188
201
        return False
189
202
 
190
 
    def __init__(self, file_id, name, parent_id, text_id=None):
 
203
    def __init__(self, file_id, name, parent_id):
191
204
        """Create an InventoryEntry
192
205
 
193
206
        The filename must be a single component, relative to the
204
217
        """
205
218
        if '/' in name or '\\' in name:
206
219
            raise errors.InvalidEntryName(name=name)
207
 
        self.executable = False
 
220
        self.file_id = file_id
208
221
        self.revision = None
209
 
        self.text_sha1 = None
210
 
        self.text_size = None
211
 
        self.file_id = file_id
212
222
        self.name = name
213
 
        self.text_id = text_id
214
223
        self.parent_id = parent_id
215
 
        self.symlink_target = None
216
 
        self.reference_revision = None
217
224
 
218
225
    def kind_character(self):
219
226
        """Return a short kind indicator useful for appending to names."""
379
386
class InventoryDirectory(InventoryEntry):
380
387
    """A directory in an inventory."""
381
388
 
382
 
    __slots__ = ['text_sha1', 'text_size', 'file_id', 'name', 'kind',
383
 
                 'text_id', 'parent_id', 'children', 'executable',
384
 
                 'revision', 'symlink_target', 'reference_revision']
 
389
    __slots__ = ['children']
 
390
 
 
391
    kind = 'directory'
385
392
 
386
393
    def _check(self, checker, rev_id):
387
394
        """See InventoryEntry._check"""
388
 
        if (self.text_sha1 is not None or self.text_size is not None or
389
 
            self.text_id is not None):
390
 
            checker._report_items.append('directory {%s} has text in revision {%s}'
391
 
                                % (self.file_id, rev_id))
392
395
        # In non rich root repositories we do not expect a file graph for the
393
396
        # root.
394
397
        if self.name == '' and not checker.rich_roots:
410
413
    def __init__(self, file_id, name, parent_id):
411
414
        super(InventoryDirectory, self).__init__(file_id, name, parent_id)
412
415
        self.children = {}
413
 
        self.kind = 'directory'
414
416
 
415
417
    def kind_character(self):
416
418
        """See InventoryEntry.kind_character."""
433
435
class InventoryFile(InventoryEntry):
434
436
    """A file in an inventory."""
435
437
 
436
 
    __slots__ = ['text_sha1', 'text_size', 'file_id', 'name', 'kind',
437
 
                 'text_id', 'parent_id', 'children', 'executable',
438
 
                 'revision', 'symlink_target', 'reference_revision']
 
438
    __slots__ = ['text_sha1', 'text_size', 'text_id', 'executable']
 
439
 
 
440
    kind = 'file'
 
441
 
 
442
    def __init__(self, file_id, name, parent_id):
 
443
        super(InventoryFile, self).__init__(file_id, name, parent_id)
 
444
        self.text_sha1 = None
 
445
        self.text_size = None
 
446
        self.text_id = None
 
447
        self.executable = False
439
448
 
440
449
    def _check(self, checker, tree_revision_id):
441
450
        """See InventoryEntry._check"""
484
493
        """See InventoryEntry.has_text."""
485
494
        return True
486
495
 
487
 
    def __init__(self, file_id, name, parent_id):
488
 
        super(InventoryFile, self).__init__(file_id, name, parent_id)
489
 
        self.kind = 'file'
490
 
 
491
496
    def kind_character(self):
492
497
        """See InventoryEntry.kind_character."""
493
498
        return ''
546
551
class InventoryLink(InventoryEntry):
547
552
    """A file in an inventory."""
548
553
 
549
 
    __slots__ = ['text_sha1', 'text_size', 'file_id', 'name', 'kind',
550
 
                 'text_id', 'parent_id', 'children', 'executable',
551
 
                 'revision', 'symlink_target', 'reference_revision']
 
554
    __slots__ = ['symlink_target']
 
555
 
 
556
    kind = 'symlink'
 
557
 
 
558
    def __init__(self, file_id, name, parent_id):
 
559
        super(InventoryLink, self).__init__(file_id, name, parent_id)
 
560
        self.symlink_target = None
552
561
 
553
562
    def _check(self, checker, tree_revision_id):
554
563
        """See InventoryEntry._check"""
555
 
        if self.text_sha1 is not None or self.text_size is not None or self.text_id is not None:
556
 
            checker._report_items.append(
557
 
               'symlink {%s} has text in revision {%s}'
558
 
                    % (self.file_id, tree_revision_id))
559
564
        if self.symlink_target is None:
560
565
            checker._report_items.append(
561
566
                'symlink {%s} has no target in revision {%s}'
599
604
        differ = DiffSymlink(old_tree, new_tree, output_to)
600
605
        return differ.diff_symlink(old_target, new_target)
601
606
 
602
 
    def __init__(self, file_id, name, parent_id):
603
 
        super(InventoryLink, self).__init__(file_id, name, parent_id)
604
 
        self.kind = 'symlink'
605
 
 
606
607
    def kind_character(self):
607
608
        """See InventoryEntry.kind_character."""
608
609
        return ''
640
641
 
641
642
class TreeReference(InventoryEntry):
642
643
 
 
644
    __slots__ = ['reference_revision']
 
645
 
643
646
    kind = 'tree-reference'
644
647
 
645
648
    def __init__(self, file_id, name, parent_id, revision=None,
2192
2195
class CHKInventoryDirectory(InventoryDirectory):
2193
2196
    """A directory in an inventory."""
2194
2197
 
2195
 
    __slots__ = ['text_sha1', 'text_size', 'file_id', 'name', 'kind',
2196
 
                 'text_id', 'parent_id', '_children', 'executable',
2197
 
                 'revision', 'symlink_target', 'reference_revision',
2198
 
                 '_chk_inventory']
 
2198
    __slots__ = ['_children', '_chk_inventory']
2199
2199
 
2200
2200
    def __init__(self, file_id, name, parent_id, chk_inventory):
2201
2201
        # Don't call InventoryDirectory.__init__ - it isn't right for this
2202
2202
        # class.
2203
2203
        InventoryEntry.__init__(self, file_id, name, parent_id)
2204
2204
        self._children = None
2205
 
        self.kind = 'directory'
2206
2205
        self._chk_inventory = chk_inventory
2207
2206
 
2208
2207
    @property