/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

Use BazaarObjectStore to find matching SHA1s for bzr revisions.

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