/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
0.200.208 by Jelmer Vernooij
Add dummy Repository.texts.
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
0.200.320 by Jelmer Vernooij
Handle lightweight checkouts.
17
from dulwich.object_store import (
18
    tree_lookup_path,
19
    )
20
from dulwich.objects import (
21
    Blob,
0.200.506 by Jelmer Vernooij
Remove bzr-foreign.
22
    Commit,
0.200.320 by Jelmer Vernooij
Handle lightweight checkouts.
23
    Tree,
24
    )
25
0.200.292 by Jelmer Vernooij
Fix formatting.
26
from bzrlib.versionedfile import (
27
    AbsentContentFactory,
0.230.2 by Jelmer Vernooij
Fix versionedfiles.
28
    FulltextContentFactory,
0.200.292 by Jelmer Vernooij
Fix formatting.
29
    VersionedFiles,
30
    )
0.200.208 by Jelmer Vernooij
Add dummy Repository.texts.
31
0.230.2 by Jelmer Vernooij
Fix versionedfiles.
32
0.200.506 by Jelmer Vernooij
Remove bzr-foreign.
33
class GitRevisions(VersionedFiles):
34
35
    def __init__(self, object_store):
36
        self.object_store = object_store
37
38
    def check(self, progressbar=None):
39
        return True
40
41
    def iterkeys(self):
42
        for sha in self.object_store:
43
            if type(sha) == Commit:
44
                yield (sha,)
45
46
    def keys(self):
47
        return list(self.iterkeys())
48
49
    def add_mpdiffs(self, records):
50
        raise NotImplementedError(self.add_mpdiffs)
51
52
    def get_record_stream(self, keys, ordering, include_delta_closure):
53
        for key in keys:
54
            (sha,) = key
55
            try:
0.200.634 by Jelmer Vernooij
Cope with slight changes in dulwich API.
56
                commit = self.object_store[sha]
0.200.506 by Jelmer Vernooij
Remove bzr-foreign.
57
            except KeyError:
58
                yield AbsentContentFactory(key)
59
            else:
0.200.634 by Jelmer Vernooij
Cope with slight changes in dulwich API.
60
                yield FulltextContentFactory(key, 
61
                    tuple([(p,) for p in commit.parents]), None, 
62
                    commit.as_raw_string())
0.200.506 by Jelmer Vernooij
Remove bzr-foreign.
63
64
    def get_parent_map(self, keys):
65
        ret = {}
66
        for (key,) in keys:
67
            try:
68
                ret[(key,)] = [(p,) for p in self.object_store[key].parents]
69
            except KeyError:
70
                ret[(key,)] = None
71
        return ret
72
73
0.200.208 by Jelmer Vernooij
Add dummy Repository.texts.
74
class GitTexts(VersionedFiles):
0.200.320 by Jelmer Vernooij
Handle lightweight checkouts.
75
    """A texts VersionedFiles instance that is backed onto a Git object store."""
0.200.208 by Jelmer Vernooij
Add dummy Repository.texts.
76
0.200.209 by Jelmer Vernooij
Pass repository object to versionedfiles.
77
    def __init__(self, repository):
78
        self.repository = repository
0.200.320 by Jelmer Vernooij
Handle lightweight checkouts.
79
        self.object_store = self.repository._git.object_store
0.200.208 by Jelmer Vernooij
Add dummy Repository.texts.
80
81
    def check(self, progressbar=None):
82
        return True
83
84
    def add_mpdiffs(self, records):
85
        raise NotImplementedError(self.add_mpdiffs)
86
87
    def get_record_stream(self, keys, ordering, include_delta_closure):
88
        for key in keys:
0.230.2 by Jelmer Vernooij
Fix versionedfiles.
89
            (fileid, revid) = key
0.200.634 by Jelmer Vernooij
Cope with slight changes in dulwich API.
90
            (commit_id, mapping) = self.repository.lookup_git_revid(revid)
91
            root_tree = self.object_store[commit_id].tree
0.230.2 by Jelmer Vernooij
Fix versionedfiles.
92
            path = mapping.parse_file_id(fileid)
93
            try:
0.200.634 by Jelmer Vernooij
Cope with slight changes in dulwich API.
94
                (mode, item_id) = tree_lookup_path(
95
                    self.object_store.__getitem__, root_tree, path)
96
                obj = self.object_store[item_id]
0.230.2 by Jelmer Vernooij
Fix versionedfiles.
97
            except KeyError:
0.200.320 by Jelmer Vernooij
Handle lightweight checkouts.
98
                yield AbsentContentFactory(key)
99
            else:
100
                if isinstance(obj, Tree):
101
                    yield FulltextContentFactory(key, None, None, "")
102
                elif isinstance(obj, Blob):
0.200.634 by Jelmer Vernooij
Cope with slight changes in dulwich API.
103
                    yield FulltextContentFactory(key, None, None, obj.data)
0.200.320 by Jelmer Vernooij
Handle lightweight checkouts.
104
                else:
0.200.634 by Jelmer Vernooij
Cope with slight changes in dulwich API.
105
                    raise AssertionError("file text resolved to %r" % obj)
0.200.208 by Jelmer Vernooij
Add dummy Repository.texts.
106
107
    def get_parent_map(self, keys):
108
        raise NotImplementedError(self.get_parent_map)
109