/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 repository.py

Implement to_files() for git merge directives.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 
20
20
from bzrlib import (
21
21
    errors,
 
22
    graph,
22
23
    inventory,
23
24
    repository,
24
25
    revision,
45
46
    )
46
47
 
47
48
 
48
 
from dulwich.objects import (
49
 
    Commit,
50
 
    )
51
 
 
52
 
 
53
49
class GitRepository(ForeignRepository):
54
50
    """An adapter to git repositories for bzr."""
55
51
 
69
65
            repository.InterRepository.register_optimiser(optimiser)
70
66
 
71
67
    def is_shared(self):
72
 
        return False
 
68
        return True
73
69
 
74
70
    def supports_rich_root(self):
75
71
        return True
95
91
        interrepo = repository.InterRepository.get(source, self)
96
92
        return interrepo.dfetch_refs(stop_revision)
97
93
 
98
 
    def fetch_refs(self, source, stop_revision):
99
 
        interrepo = repository.InterRepository.get(source, self)
100
 
        return interrepo.fetch_refs(stop_revision)
101
 
 
102
94
 
103
95
class LocalGitRepository(GitRepository):
104
96
    """Git repository on the file system."""
105
97
 
106
98
    def __init__(self, gitdir, lockfiles):
 
99
        # FIXME: This also caches negatives. Need to be more careful
 
100
        # about this once we start writing to git
 
101
        self._parents_provider = graph.CachingParentsProvider(self)
107
102
        GitRepository.__init__(self, gitdir, lockfiles)
108
103
        self.base = gitdir.root_transport.base
109
104
        self._git = gitdir._git
114
109
 
115
110
    def all_revision_ids(self):
116
111
        ret = set([])
117
 
        for sha in self._git.object_store:
118
 
            o = self._git.object_store[sha]
119
 
            if not isinstance(o, Commit):
120
 
                continue
121
 
            rev = self.get_mapping().import_commit(o)
122
 
            ret.append(rev.revision_id)
 
112
        heads = self._git.refs.as_dict('refs/heads')
 
113
        if heads == {}:
 
114
            return ret
 
115
        bzr_heads = [self.get_mapping().revision_id_foreign_to_bzr(h) for h in heads.itervalues()]
 
116
        ret = set(bzr_heads)
 
117
        graph = self.get_graph()
 
118
        for rev, parents in graph.iter_ancestry(bzr_heads):
 
119
            ret.add(rev)
123
120
        return ret
124
121
 
 
122
    def _make_parents_provider(self):
 
123
        """See Repository._make_parents_provider()."""
 
124
        return self._parents_provider
 
125
 
125
126
    def get_parent_map(self, revids):
126
127
        parent_map = {}
127
128
        for revision_id in revids:
131
132
                continue
132
133
            hexsha, mapping = self.lookup_bzr_revision_id(revision_id)
133
134
            try:
134
 
                commit = self._git[hexsha]
 
135
                commit = self._git.commit(hexsha)
135
136
            except KeyError:
136
137
                continue
137
 
            parent_map[revision_id] = [mapping.revision_id_foreign_to_bzr(p) for p in commit.parents]
 
138
            if commit is None:
 
139
                # Older versions of Dulwich used to return None rather than
 
140
                # raise KeyError.
 
141
                continue
 
142
            else:
 
143
                parent_map[revision_id] = [mapping.revision_id_foreign_to_bzr(p) for p in commit.parents]
138
144
        return parent_map
139
145
 
140
146
    def get_ancestry(self, revision_id, topo_sorted=True):
168
174
        try:
169
175
            return mapping_registry.revision_id_bzr_to_foreign(bzr_revid)
170
176
        except errors.InvalidRevisionId:
171
 
            mapping = self.get_mapping()
172
 
            try:
173
 
                return self._git.refs[mapping.revid_as_refname(bzr_revid)], mapping
174
 
            except KeyError:
175
 
                raise errors.NoSuchRevision(self, bzr_revid)
 
177
            raise errors.NoSuchRevision(self, bzr_revid)
176
178
 
177
179
    def get_revision(self, revision_id):
178
180
        git_commit_id, mapping = self.lookup_bzr_revision_id(revision_id)
179
181
        try:
180
 
            commit = self._git[git_commit_id]
 
182
            commit = self._git.commit(git_commit_id)
181
183
        except KeyError:
182
184
            raise errors.NoSuchRevision(self, revision_id)
183
185
        # print "fetched revision:", git_commit_id
187
189
 
188
190
    def has_revision(self, revision_id):
189
191
        try:
190
 
            git_commit_id, mapping = self.lookup_bzr_revision_id(revision_id)
 
192
            self.get_revision(revision_id)
191
193
        except errors.NoSuchRevision:
192
194
            return False
193
 
        return (git_commit_id in self._git)
194
 
 
195
 
    def has_revisions(self, revision_ids):
196
 
        ret = set()
197
 
        for revid in revision_ids:
198
 
            if self.has_revision(revid):
199
 
                ret.add(revid)
200
 
        return ret
 
195
        else:
 
196
            return True
201
197
 
202
198
    def get_revisions(self, revids):
203
199
        return [self.get_revision(r) for r in revids]