/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to versionedfiles.py

  • Committer: Martin Pool
  • Date: 2009-06-10 05:00:47 UTC
  • mto: This revision was merged to the branch mainline in revision 4426.
  • Revision ID: mbp@sourcefrog.net-20090610050047-a8ml6ntyco790o4c
Trim some outdated performance drive documentation, and the performance.png graph

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2009 Jelmer Vernooij <jelmer@samba.org>
2
 
 
3
 
# This program is free software; you can redistribute it and/or modify
4
 
# it under the terms of the GNU General Public License as published by
5
 
# the Free Software Foundation; either version 2 of the License, or
6
 
# (at your option) any later version.
7
 
#
8
 
# This program is distributed in the hope that it will be useful,
9
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
 
# GNU General Public License for more details.
12
 
#
13
 
# You should have received a copy of the GNU General Public License
14
 
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
 
 
17
 
from dulwich.object_store import (
18
 
    tree_lookup_path,
19
 
    )
20
 
from dulwich.objects import (
21
 
    Blob,
22
 
    Commit,
23
 
    Tree,
24
 
    )
25
 
 
26
 
from bzrlib.revision import (
27
 
    NULL_REVISION,
28
 
    )
29
 
from bzrlib.versionedfile import (
30
 
    AbsentContentFactory,
31
 
    FulltextContentFactory,
32
 
    VersionedFiles,
33
 
    )
34
 
 
35
 
 
36
 
class GitRevisions(VersionedFiles):
37
 
 
38
 
    def __init__(self, object_store):
39
 
        self.object_store = object_store
40
 
 
41
 
    def check(self, progressbar=None):
42
 
        return True
43
 
 
44
 
    def iterkeys(self):
45
 
        for sha in self.object_store:
46
 
            if type(sha) == Commit:
47
 
                yield (sha,)
48
 
 
49
 
    def keys(self):
50
 
        return list(self.iterkeys())
51
 
 
52
 
    def add_mpdiffs(self, records):
53
 
        raise NotImplementedError(self.add_mpdiffs)
54
 
 
55
 
    def get_record_stream(self, keys, ordering, include_delta_closure):
56
 
        for key in keys:
57
 
            (sha,) = key
58
 
            try:
59
 
                text = self.object_store.get_raw(sha)
60
 
            except KeyError:
61
 
                yield AbsentContentFactory(key)
62
 
            else:
63
 
                yield FulltextContentFactory(key, None, None, text)
64
 
 
65
 
    def get_parent_map(self, keys):
66
 
        ret = {}
67
 
        for (key,) in keys:
68
 
            try:
69
 
                ret[(key,)] = [(p,) for p in self.object_store[key].parents]
70
 
            except KeyError:
71
 
                ret[(key,)] = None
72
 
        return ret
73
 
 
74
 
 
75
 
class GitTexts(VersionedFiles):
76
 
    """A texts VersionedFiles instance that is backed onto a Git object store."""
77
 
 
78
 
    def __init__(self, repository):
79
 
        self.repository = repository
80
 
        self.object_store = self.repository._git.object_store
81
 
 
82
 
    def check(self, progressbar=None):
83
 
        return True
84
 
 
85
 
    def add_mpdiffs(self, records):
86
 
        raise NotImplementedError(self.add_mpdiffs)
87
 
 
88
 
    def get_record_stream(self, keys, ordering, include_delta_closure):
89
 
        for key in keys:
90
 
            (fileid, revid) = key
91
 
            (foreign_revid, mapping) = self.repository.lookup_git_revid(revid)
92
 
            root_tree = self.object_store[foreign_revid].tree
93
 
            path = mapping.parse_file_id(fileid)
94
 
            try:
95
 
                obj = tree_lookup_path(self.object_store.__getitem__, 
96
 
                                       root_tree, path)
97
 
            except KeyError:
98
 
                yield AbsentContentFactory(key)
99
 
            else:
100
 
                if isinstance(obj, Tree):
101
 
                    yield FulltextContentFactory(key, None, None, "")
102
 
                elif isinstance(obj, Blob):
103
 
                    yield FulltextContentFactory(key, None, None, obj._text)
104
 
                else:
105
 
                    yield AbsentContentFactory(key)
106
 
 
107
 
    def get_parent_map(self, keys):
108
 
        raise NotImplementedError(self.get_parent_map)
109