/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

Default to using global user id rather than making one up.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
 
from bzrlib.revision import NULL_REVISION
18
 
from bzrlib.versionedfile import VersionedFiles, AbsentContentFactory
 
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
 
19
74
 
20
75
class GitTexts(VersionedFiles):
 
76
    """A texts VersionedFiles instance that is backed onto a Git object store."""
21
77
 
22
78
    def __init__(self, repository):
23
79
        self.repository = repository
 
80
        self.object_store = self.repository._git.object_store
24
81
 
25
82
    def check(self, progressbar=None):
26
83
        return True
30
87
 
31
88
    def get_record_stream(self, keys, ordering, include_delta_closure):
32
89
        for key in keys:
33
 
            yield AbsentContentFactory(key)
 
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)
34
106
 
35
107
    def get_parent_map(self, keys):
36
108
        raise NotImplementedError(self.get_parent_map)
37
109
 
38
 
 
39