~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/versionedfile.py

  • Committer: Vincent Ladeuil
  • Date: 2011-05-15 16:07:11 UTC
  • mto: (5743.13.4 config-editor-option)
  • mto: This revision was merged to the branch mainline in revision 5944.
  • Revision ID: v.ladeuil+lp@free.fr-20110515160711-l0og3ady9wuahz1k
Stack.get() provides the registered option default value.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2010 Canonical Ltd
2
 
#
3
 
# Authors:
4
 
#   Johan Rydberg <jrydberg@gnu.org>
 
1
# Copyright (C) 2006-2011 Canonical Ltd
5
2
#
6
3
# This program is free software; you can redistribute it and/or modify
7
4
# it under the terms of the GNU General Public License as published by
31
28
 
32
29
from bzrlib import (
33
30
    annotate,
 
31
    bencode,
34
32
    errors,
35
33
    graph as _mod_graph,
36
34
    groupcompress,
40
38
    multiparent,
41
39
    tsort,
42
40
    revision,
43
 
    ui,
44
41
    )
45
 
from bzrlib.graph import DictParentsProvider, Graph, StackedParentsProvider
46
 
from bzrlib.transport.memory import MemoryTransport
47
42
""")
48
43
from bzrlib.registry import Registry
49
44
from bzrlib.textmerge import TextMerge
50
 
from bzrlib import bencode
51
45
 
52
46
 
53
47
adapter_registry = Registry()
930
924
 
931
925
    The use of tuples allows a single code base to support several different
932
926
    uses with only the mapping logic changing from instance to instance.
 
927
 
 
928
    :ivar _immediate_fallback_vfs: For subclasses that support stacking,
 
929
        this is a list of other VersionedFiles immediately underneath this
 
930
        one.  They may in turn each have further fallbacks.
933
931
    """
934
932
 
935
933
    def add_lines(self, key, parents, lines, parent_texts=None,
1193
1191
    def _extract_blocks(self, version_id, source, target):
1194
1192
        return None
1195
1193
 
 
1194
    def _transitive_fallbacks(self):
 
1195
        """Return the whole stack of fallback versionedfiles.
 
1196
 
 
1197
        This VersionedFiles may have a list of fallbacks, but it doesn't
 
1198
        necessarily know about the whole stack going down, and it can't know
 
1199
        at open time because they may change after the objects are opened.
 
1200
        """
 
1201
        all_fallbacks = []
 
1202
        for a_vfs in self._immediate_fallback_vfs:
 
1203
            all_fallbacks.append(a_vfs)
 
1204
            all_fallbacks.extend(a_vfs._transitive_fallbacks())
 
1205
        return all_fallbacks
 
1206
 
1196
1207
 
1197
1208
class ThunkedVersionedFiles(VersionedFiles):
1198
1209
    """Storage for many versioned files thunked onto a 'VersionedFile' class.
1437
1448
        # line data for locally held keys.
1438
1449
        self._lines = {}
1439
1450
        # key lookup providers
1440
 
        self._providers = [DictParentsProvider(self._parents)]
 
1451
        self._providers = [_mod_graph.DictParentsProvider(self._parents)]
1441
1452
 
1442
1453
    def plan_merge(self, ver_a, ver_b, base=None):
1443
1454
        """See VersionedFile.plan_merge"""
1450
1461
 
1451
1462
    def plan_lca_merge(self, ver_a, ver_b, base=None):
1452
1463
        from bzrlib.merge import _PlanLCAMerge
1453
 
        graph = Graph(self)
 
1464
        graph = _mod_graph.Graph(self)
1454
1465
        new_plan = _PlanLCAMerge(ver_a, ver_b, self, (self._file_id,), graph).plan_merge()
1455
1466
        if base is None:
1456
1467
            return new_plan
1508
1519
            result[revision.NULL_REVISION] = ()
1509
1520
        self._providers = self._providers[:1] + self.fallback_versionedfiles
1510
1521
        result.update(
1511
 
            StackedParentsProvider(self._providers).get_parent_map(keys))
 
1522
            _mod_graph.StackedParentsProvider(
 
1523
                self._providers).get_parent_map(keys))
1512
1524
        for key, parents in result.iteritems():
1513
1525
            if parents == ():
1514
1526
                result[key] = (revision.NULL_REVISION,)
1860
1872
    for prefix in sorted(per_prefix_map):
1861
1873
        present_keys.extend(reversed(tsort.topo_sort(per_prefix_map[prefix])))
1862
1874
    return present_keys
 
1875
 
 
1876
 
 
1877
class _KeyRefs(object):
 
1878
 
 
1879
    def __init__(self, track_new_keys=False):
 
1880
        # dict mapping 'key' to 'set of keys referring to that key'
 
1881
        self.refs = {}
 
1882
        if track_new_keys:
 
1883
            # set remembering all new keys
 
1884
            self.new_keys = set()
 
1885
        else:
 
1886
            self.new_keys = None
 
1887
 
 
1888
    def clear(self):
 
1889
        if self.refs:
 
1890
            self.refs.clear()
 
1891
        if self.new_keys:
 
1892
            self.new_keys.clear()
 
1893
 
 
1894
    def add_references(self, key, refs):
 
1895
        # Record the new references
 
1896
        for referenced in refs:
 
1897
            try:
 
1898
                needed_by = self.refs[referenced]
 
1899
            except KeyError:
 
1900
                needed_by = self.refs[referenced] = set()
 
1901
            needed_by.add(key)
 
1902
        # Discard references satisfied by the new key
 
1903
        self.add_key(key)
 
1904
 
 
1905
    def get_new_keys(self):
 
1906
        return self.new_keys
 
1907
    
 
1908
    def get_unsatisfied_refs(self):
 
1909
        return self.refs.iterkeys()
 
1910
 
 
1911
    def _satisfy_refs_for_key(self, key):
 
1912
        try:
 
1913
            del self.refs[key]
 
1914
        except KeyError:
 
1915
            # No keys depended on this key.  That's ok.
 
1916
            pass
 
1917
 
 
1918
    def add_key(self, key):
 
1919
        # satisfy refs for key, and remember that we've seen this key.
 
1920
        self._satisfy_refs_for_key(key)
 
1921
        if self.new_keys is not None:
 
1922
            self.new_keys.add(key)
 
1923
 
 
1924
    def satisfy_refs_for_keys(self, keys):
 
1925
        for key in keys:
 
1926
            self._satisfy_refs_for_key(key)
 
1927
 
 
1928
    def get_referrers(self):
 
1929
        result = set()
 
1930
        for referrers in self.refs.itervalues():
 
1931
            result.update(referrers)
 
1932
        return result
 
1933
 
 
1934
 
 
1935