~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/store/weave.py

merge integration.

Show diffs side-by-side

added added

removed removed

Lines of Context:
40
40
    """
41
41
    FILE_SUFFIX = '.weave'
42
42
 
43
 
    def __init__(self, transport, prefixed=False, precious=False):
44
 
        self._transport = transport
45
 
        self._prefixed = prefixed
 
43
    def __init__(self, transport, prefixed=False, precious=False,
 
44
                 dir_mode=None, file_mode=None):
 
45
        super(WeaveStore, self).__init__(transport,
 
46
                dir_mode=dir_mode, file_mode=file_mode,
 
47
                prefixed=prefixed, compressed=False)
46
48
        self._precious = precious
47
49
 
48
50
    def filename(self, file_id):
67
69
    def _put(self, file_id, f):
68
70
        if self._prefixed:
69
71
            try:
70
 
                self._transport.mkdir(hash_prefix(file_id))
 
72
                self._transport.mkdir(hash_prefix(file_id), mode=self._dir_mode)
71
73
            except FileExists:
72
74
                pass
73
 
        return self._transport.put(self.filename(file_id), f)
 
75
        return self._transport.put(self.filename(file_id), f, mode=self._file_mode)
74
76
 
75
77
    def get_weave(self, file_id, transaction):
76
78
        weave = transaction.map.find_weave(file_id)
80
82
        w = read_weave(self._get(file_id))
81
83
        transaction.map.add_weave(file_id, w)
82
84
        transaction.register_clean(w, precious=self._precious)
 
85
        # TODO: jam 20051219 This should check if there is a prelude
 
86
        #       which is already cached, and if so, should remove it
 
87
        #       But transaction doesn't seem to have a 'remove'
 
88
        #       One workaround would be to re-add the object with
 
89
        #       the PRELUDE marker.
 
90
        return w
 
91
 
 
92
    def get_weave_prelude(self, file_id, transaction):
 
93
        weave_id = file_id
 
94
        weave = transaction.map.find_weave(weave_id)
 
95
        if weave:
 
96
            mutter("cache hit in %s for %s", self, weave_id)
 
97
            return weave
 
98
        # We want transactions to also cache preludes if that
 
99
        # is all that we are loading. So we need a unique
 
100
        # identifier, so that someone who wants the whole text
 
101
        # won't get just the prelude
 
102
        weave_id = 'PRELUDE-' + file_id
 
103
        weave = transaction.map.find_weave(weave_id)
 
104
        if weave:
 
105
            mutter("cache hit in %s for %s", self, weave_id)
 
106
            return weave
 
107
        w = read_weave(self._get(file_id), prelude=True)
 
108
        transaction.map.add_weave(weave_id, w)
 
109
        transaction.register_clean(w, precious=self._precious)
83
110
        return w
84
111
 
85
112
    def get_lines(self, file_id, rev_id, transaction):
92
119
    def get_weave_prelude_or_empty(self, file_id, transaction):
93
120
        """cheap version that reads the prelude but not the lines
94
121
        """
95
 
        weave = transaction.map.find_weave(file_id)
96
 
        if weave:
97
 
            mutter("cache hit in %s for %s", self, file_id)
98
 
            return weave
99
122
        try:
100
 
            return read_weave(self._get(file_id),prelude=True)
 
123
            return self.get_weave_prelude(file_id, transaction)
101
124
        except NoSuchFile:
102
 
            return Weave(weave_name=file_id)
 
125
            # We can cache here, because we know that there
 
126
            # is no complete object, since we got NoSuchFile
 
127
            weave = Weave(weave_name=file_id)
 
128
            transaction.map.add_weave(file_id, weave)
 
129
            transaction.register_clean(weave, precious=self._precious)
 
130
            return weave
103
131
 
104
132
    def get_weave_or_empty(self, file_id, transaction):
105
133
        """Return a weave, or an empty one if it doesn't exist."""