~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/inventory.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2006-04-20 02:51:29 UTC
  • mfrom: (1662.1.16 bzr.mbp.integration)
  • Revision ID: pqm@pqm.ubuntu.com-20060420025129-8e219a634d2d4dbc
(mbp) #36963, #3619, #39657, other cleanups

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# (C) 2005 Canonical Ltd
 
1
# Copyright (C) 2005, 2006 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
349
349
        raise BzrCheckError('unknown entry kind %r in revision {%s}' % 
350
350
                            (self.kind, rev_id))
351
351
 
352
 
 
353
352
    def copy(self):
354
353
        """Clone this inventory entry."""
355
354
        raise NotImplementedError
356
355
 
357
 
    def _get_snapshot_change(self, previous_entries):
 
356
    def _describe_snapshot_change(self, previous_entries):
 
357
        """Describe how this entry will have changed in a new commit.
 
358
 
 
359
        :param previous_entries: Dictionary from revision_id to inventory entry.
 
360
 
 
361
        :returns: One-word description: "merged", "added", "renamed", "modified".
 
362
        """
 
363
        # XXX: This assumes that the file *has* changed -- it should probably
 
364
        # be fused with whatever does that detection.  Why not just a single
 
365
        # thing to compare the entries?
 
366
        #
 
367
        # TODO: Return some kind of object describing all the possible
 
368
        # dimensions that can change, not just a string.  That can then give
 
369
        # both old and new names for renames, etc.
 
370
        #
358
371
        if len(previous_entries) > 1:
359
372
            return 'merged'
360
373
        elif len(previous_entries) == 0:
361
374
            return 'added'
362
 
        else:
363
 
            return 'modified/renamed/reparented'
 
375
        the_parent, = previous_entries.values()
 
376
        if self.parent_id != the_parent.parent_id:
 
377
            # actually, moved to another directory
 
378
            return 'renamed'
 
379
        elif self.name != the_parent.name:
 
380
            return 'renamed'
 
381
        return 'modified'
364
382
 
365
383
    def __repr__(self):
366
384
        return ("%s(%r, %r, parent_id=%r)"
385
403
                mutter("found unchanged entry")
386
404
                self.revision = parent_ie.revision
387
405
                return "unchanged"
388
 
        return self.snapshot_revision(revision, previous_entries, 
389
 
                                      work_tree, weave_store, transaction)
390
 
 
391
 
    def snapshot_revision(self, revision, previous_entries, work_tree,
392
 
                          weave_store, transaction):
393
 
        """Record this revision unconditionally."""
394
 
        mutter('new revision for {%s}', self.file_id)
 
406
        return self._snapshot_into_revision(revision, previous_entries, 
 
407
                                            work_tree, weave_store, transaction)
 
408
 
 
409
    def _snapshot_into_revision(self, revision, previous_entries, work_tree,
 
410
                                weave_store, transaction):
 
411
        """Record this revision unconditionally into a store.
 
412
 
 
413
        The entry's last-changed revision property (`revision`) is updated to 
 
414
        that of the new revision.
 
415
        
 
416
        :param revision: id of the new revision that is being recorded.
 
417
 
 
418
        :returns: String description of the commit (e.g. "merged", "modified"), etc.
 
419
        """
 
420
        mutter('new revision {%s} for {%s}', revision, self.file_id)
395
421
        self.revision = revision
396
 
        change = self._get_snapshot_change(previous_entries)
 
422
        change = self._describe_snapshot_change(previous_entries)
397
423
        self._snapshot_text(previous_entries, work_tree, weave_store,
398
424
                            transaction)
399
425
        return change