~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/versionedfile.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2010-08-16 06:46:17 UTC
  • mfrom: (5375.1.6 chk-canonicalizer-613698)
  • Revision ID: pqm@pqm.ubuntu.com-20100816064617-wizstoapjbffkj05
(spiv) Add hidden option 'bzr reconcile --canonicalize-chks' to repair repos
 affected by bug 522637. (Andrew Bennetts)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1725
1725
                yield (l, key)
1726
1726
 
1727
1727
 
 
1728
class NoDupeAddLinesDecorator(object):
 
1729
    """Decorator for a VersionedFiles that skips doing an add_lines if the key
 
1730
    is already present.
 
1731
    """
 
1732
 
 
1733
    def __init__(self, store):
 
1734
        self._store = store
 
1735
 
 
1736
    def add_lines(self, key, parents, lines, parent_texts=None,
 
1737
            left_matching_blocks=None, nostore_sha=None, random_id=False,
 
1738
            check_content=True):
 
1739
        """See VersionedFiles.add_lines.
 
1740
        
 
1741
        This implementation may return None as the third element of the return
 
1742
        value when the original store wouldn't.
 
1743
        """
 
1744
        if nostore_sha:
 
1745
            raise NotImplementedError(
 
1746
                "NoDupeAddLinesDecorator.add_lines does not implement the "
 
1747
                "nostore_sha behaviour.")
 
1748
        if key[-1] is None:
 
1749
            sha1 = osutils.sha_strings(lines)
 
1750
            key = ("sha1:" + sha1,)
 
1751
        else:
 
1752
            sha1 = None
 
1753
        if key in self._store.get_parent_map([key]):
 
1754
            # This key has already been inserted, so don't do it again.
 
1755
            if sha1 is None:
 
1756
                sha1 = osutils.sha_strings(lines)
 
1757
            return sha1, sum(map(len, lines)), None
 
1758
        return self._store.add_lines(key, parents, lines,
 
1759
                parent_texts=parent_texts,
 
1760
                left_matching_blocks=left_matching_blocks,
 
1761
                nostore_sha=nostore_sha, random_id=random_id,
 
1762
                check_content=check_content)
 
1763
 
 
1764
    def __getattr__(self, name):
 
1765
        return getattr(self._store, name)
 
1766
 
 
1767
 
1728
1768
def network_bytes_to_kind_and_offset(network_bytes):
1729
1769
    """Strip of a record kind from the front of network_bytes.
1730
1770