~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/inventory.py

  • Committer: Martin Pool
  • Date: 2005-05-25 03:27:02 UTC
  • Revision ID: mbp@sourcefrog.net-20050525032702-395f038adb33c235
- clean up statcache code
- stat files in order by inum
- report on added/deleted files

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
 
22
22
 
23
23
import sys, os.path, types, re
24
 
from sets import Set
25
24
 
26
25
try:
27
26
    from cElementTree import Element, ElementTree, SubElement
211
210
 
212
211
    from_element = classmethod(from_element)
213
212
 
214
 
    def __cmp__(self, other):
215
 
        if self is other:
216
 
            return 0
 
213
    def __eq__(self, other):
217
214
        if not isinstance(other, InventoryEntry):
218
215
            return NotImplemented
219
216
 
220
 
        return cmp(self.file_id, other.file_id) \
221
 
               or cmp(self.name, other.name) \
222
 
               or cmp(self.text_sha1, other.text_sha1) \
223
 
               or cmp(self.text_size, other.text_size) \
224
 
               or cmp(self.text_id, other.text_id) \
225
 
               or cmp(self.parent_id, other.parent_id) \
226
 
               or cmp(self.kind, other.kind)
 
217
        return (self.file_id == other.file_id) \
 
218
               and (self.name == other.name) \
 
219
               and (self.text_sha1 == other.text_sha1) \
 
220
               and (self.text_size == other.text_size) \
 
221
               and (self.text_id == other.text_id) \
 
222
               and (self.parent_id == other.parent_id) \
 
223
               and (self.kind == other.kind)
 
224
 
 
225
 
 
226
    def __ne__(self, other):
 
227
        return not (self == other)
 
228
 
 
229
    def __hash__(self):
 
230
        raise ValueError('not hashable')
227
231
 
228
232
 
229
233
 
235
239
        self.parent_id = None
236
240
        self.name = ''
237
241
 
238
 
    def __cmp__(self, other):
239
 
        if self is other:
240
 
            return 0
 
242
    def __eq__(self, other):
241
243
        if not isinstance(other, RootEntry):
242
244
            return NotImplemented
243
 
        return cmp(self.file_id, other.file_id) \
244
 
               or cmp(self.children, other.children)
 
245
        
 
246
        return (self.file_id == other.file_id) \
 
247
               and (self.children == other.children)
245
248
 
246
249
 
247
250
 
454
457
        del self[ie.parent_id].children[ie.name]
455
458
 
456
459
 
457
 
    def id_set(self):
458
 
        return Set(self._byid)
459
 
 
460
 
 
461
460
    def to_element(self):
462
461
        """Convert to XML Element"""
463
462
        e = Element('inventory')
486
485
    from_element = classmethod(from_element)
487
486
 
488
487
 
489
 
    def __cmp__(self, other):
 
488
    def __eq__(self, other):
490
489
        """Compare two sets by comparing their contents.
491
490
 
492
491
        >>> i1 = Inventory()
500
499
        >>> i1 == i2
501
500
        True
502
501
        """
503
 
        if self is other:
504
 
            return 0
505
 
        
506
502
        if not isinstance(other, Inventory):
507
503
            return NotImplemented
508
504
 
509
 
        if self.id_set() ^ other.id_set():
510
 
            return 1
511
 
 
512
 
        for file_id in self._byid:
513
 
            c = cmp(self[file_id], other[file_id])
514
 
            if c: return c
515
 
 
516
 
        return 0
 
505
        if len(self._byid) != len(other._byid):
 
506
            # shortcut: obviously not the same
 
507
            return False
 
508
 
 
509
        return self._byid == other._byid
 
510
 
 
511
 
 
512
    def __ne__(self, other):
 
513
        return not (self == other)
 
514
 
 
515
 
 
516
    def __hash__(self):
 
517
        raise ValueError('not hashable')
 
518
 
517
519
 
518
520
 
519
521
    def get_idpath(self, file_id):