~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/inventory.py

  • Committer: Martin Pool
  • Date: 2005-03-12 08:54:12 UTC
  • Revision ID: mbp@sourcefrog.net-20050312085412-13373aa129ccbad3
doc: notes on implementing codeville-style merge on
top of a weave; looks nice but opens a can of worms

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
 
32
32
from xml import XMLMixin
33
33
from errors import bailout
34
 
 
35
 
import bzrlib
36
 
from bzrlib.osutils import uuid, quotefn, splitpath, joinpath, appendpath
37
 
from bzrlib.trace import mutter
 
34
from osutils import uuid, quotefn, splitpath, joinpath, appendpath
 
35
from trace import mutter
38
36
 
39
37
class InventoryEntry(XMLMixin):
40
38
    """Description of a versioned file.
362
360
            self._tree[entry.file_id] = {}
363
361
 
364
362
 
365
 
    def add_path(self, relpath, kind, file_id=None):
366
 
        """Add entry from a path.
367
 
 
368
 
        The immediate parent must already be versioned"""
369
 
        parts = bzrlib.osutils.splitpath(relpath)
370
 
        if len(parts) == 0:
371
 
            bailout("cannot re-add root of inventory")
372
 
 
373
 
        if file_id is None:
374
 
            file_id = bzrlib.branch.gen_file_id(relpath)
375
 
 
376
 
        parent_id = self.path2id(parts[:-1])
377
 
        ie = InventoryEntry(file_id, parts[-1],
378
 
                            kind=kind, parent_id=parent_id)
379
 
        return self.add(ie)
380
 
 
381
 
 
382
363
    def __delitem__(self, file_id):
383
364
        """Remove entry by id.
384
365
 
487
468
        This returns the entry of the last component in the path,
488
469
        which may be either a file or a directory.
489
470
        """
490
 
        if isinstance(name, types.StringTypes):
491
 
            name = splitpath(name)
 
471
        assert isinstance(name, types.StringTypes)
492
472
 
493
473
        parent_id = None
494
 
        for f in name:
 
474
        for f in splitpath(name):
495
475
            try:
496
476
                cie = self._tree[parent_id][f]
497
477
                assert cie.name == f
517
497
 
518
498
 
519
499
 
520
 
 
521
 
 
522
500
if __name__ == '__main__':
523
501
    import doctest, inventory
524
502
    doctest.testmod(inventory)