/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

Update docs.

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
    Tree,
 
23
    )
 
24
 
 
25
from bzrlib.revision import (
 
26
    NULL_REVISION,
 
27
    )
 
28
from bzrlib.versionedfile import (
 
29
    AbsentContentFactory,
 
30
    FulltextContentFactory,
 
31
    VersionedFiles,
 
32
    )
 
33
 
19
34
 
20
35
class GitTexts(VersionedFiles):
 
36
    """A texts VersionedFiles instance that is backed onto a Git object store."""
21
37
 
22
38
    def __init__(self, repository):
23
39
        self.repository = repository
 
40
        self.object_store = self.repository._git.object_store
24
41
 
25
42
    def check(self, progressbar=None):
26
43
        return True
30
47
 
31
48
    def get_record_stream(self, keys, ordering, include_delta_closure):
32
49
        for key in keys:
33
 
            yield AbsentContentFactory(key)
 
50
            (fileid, revid) = key
 
51
            (foreign_revid, mapping) = self.repository.lookup_git_revid(revid)
 
52
            root_tree = self.object_store[foreign_revid].tree
 
53
            path = mapping.parse_file_id(fileid)
 
54
            try:
 
55
                obj = tree_lookup_path(self.object_store.__getitem__, 
 
56
                                       root_tree, path)
 
57
            except KeyError:
 
58
                yield AbsentContentFactory(key)
 
59
            else:
 
60
                if isinstance(obj, Tree):
 
61
                    yield FulltextContentFactory(key, None, None, "")
 
62
                elif isinstance(obj, Blob):
 
63
                    yield FulltextContentFactory(key, None, None, obj._text)
 
64
                else:
 
65
                    yield AbsentContentFactory(key)
34
66
 
35
67
    def get_parent_map(self, keys):
36
68
        raise NotImplementedError(self.get_parent_map)
37
69
 
38
 
 
39