/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

Fix Branch.get_stacked_on_url() test.

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.versionedfile import (
 
27
    AbsentContentFactory,
 
28
    FulltextContentFactory,
 
29
    VersionedFiles,
 
30
    )
 
31
 
 
32
 
 
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:
 
56
                text = self.object_store.get_raw(sha)
 
57
            except KeyError:
 
58
                yield AbsentContentFactory(key)
 
59
            else:
 
60
                yield FulltextContentFactory(key, None, None, text)
 
61
 
 
62
    def get_parent_map(self, keys):
 
63
        ret = {}
 
64
        for (key,) in keys:
 
65
            try:
 
66
                ret[(key,)] = [(p,) for p in self.object_store[key].parents]
 
67
            except KeyError:
 
68
                ret[(key,)] = None
 
69
        return ret
 
70
 
 
71
 
 
72
class GitTexts(VersionedFiles):
 
73
    """A texts VersionedFiles instance that is backed onto a Git object store."""
 
74
 
 
75
    def __init__(self, repository):
 
76
        self.repository = repository
 
77
        self.object_store = self.repository._git.object_store
 
78
 
 
79
    def check(self, progressbar=None):
 
80
        return True
 
81
 
 
82
    def add_mpdiffs(self, records):
 
83
        raise NotImplementedError(self.add_mpdiffs)
 
84
 
 
85
    def get_record_stream(self, keys, ordering, include_delta_closure):
 
86
        for key in keys:
 
87
            (fileid, revid) = key
 
88
            (foreign_revid, mapping) = self.repository.lookup_git_revid(revid)
 
89
            root_tree = self.object_store[foreign_revid].tree
 
90
            path = mapping.parse_file_id(fileid)
 
91
            try:
 
92
                obj = tree_lookup_path(self.object_store.__getitem__, 
 
93
                                       root_tree, path)
 
94
            except KeyError:
 
95
                yield AbsentContentFactory(key)
 
96
            else:
 
97
                if isinstance(obj, Tree):
 
98
                    yield FulltextContentFactory(key, None, None, "")
 
99
                elif isinstance(obj, Blob):
 
100
                    yield FulltextContentFactory(key, None, None, obj._text)
 
101
                else:
 
102
                    yield AbsentContentFactory(key)
 
103
 
 
104
    def get_parent_map(self, keys):
 
105
        raise NotImplementedError(self.get_parent_map)
 
106