/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

  • Committer: Jelmer Vernooij
  • Date: 2010-05-05 09:58:55 UTC
  • mto: (0.200.912 trunk)
  • mto: This revision was merged to the branch mainline in revision 6960.
  • Revision ID: jelmer@samba.org-20100505095855-i0165hooflvk9chy
Ignore control files in inventories.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 
20
20
from bzrlib import (
21
21
    errors,
22
 
    graph,
23
22
    inventory,
24
23
    repository,
25
24
    revision,
46
45
    )
47
46
 
48
47
 
 
48
from dulwich.objects import (
 
49
    Commit,
 
50
    )
 
51
 
 
52
 
49
53
class GitRepository(ForeignRepository):
50
54
    """An adapter to git repositories for bzr."""
51
55
 
65
69
            repository.InterRepository.register_optimiser(optimiser)
66
70
 
67
71
    def is_shared(self):
68
 
        return True
 
72
        return False
69
73
 
70
74
    def supports_rich_root(self):
71
75
        return True
91
95
        interrepo = repository.InterRepository.get(source, self)
92
96
        return interrepo.dfetch_refs(stop_revision)
93
97
 
 
98
    def fetch_refs(self, source, stop_revision):
 
99
        interrepo = repository.InterRepository.get(source, self)
 
100
        return interrepo.fetch_refs(stop_revision)
 
101
 
94
102
 
95
103
class LocalGitRepository(GitRepository):
96
104
    """Git repository on the file system."""
97
105
 
98
106
    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)
102
107
        GitRepository.__init__(self, gitdir, lockfiles)
103
108
        self.base = gitdir.root_transport.base
104
109
        self._git = gitdir._git
109
114
 
110
115
    def all_revision_ids(self):
111
116
        ret = set([])
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)
 
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)
120
123
        return ret
121
124
 
122
 
    def _make_parents_provider(self):
123
 
        """See Repository._make_parents_provider()."""
124
 
        return self._parents_provider
125
 
 
126
125
    def get_parent_map(self, revids):
127
126
        parent_map = {}
128
127
        for revision_id in revids:
132
131
                continue
133
132
            hexsha, mapping = self.lookup_bzr_revision_id(revision_id)
134
133
            try:
135
 
                commit = self._git.commit(hexsha)
 
134
                commit = self._git[hexsha]
136
135
            except KeyError:
137
136
                continue
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]
 
137
            parent_map[revision_id] = [mapping.revision_id_foreign_to_bzr(p) for p in commit.parents]
144
138
        return parent_map
145
139
 
146
140
    def get_ancestry(self, revision_id, topo_sorted=True):
174
168
        try:
175
169
            return mapping_registry.revision_id_bzr_to_foreign(bzr_revid)
176
170
        except errors.InvalidRevisionId:
177
 
            raise errors.NoSuchRevision(self, bzr_revid)
 
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)
178
176
 
179
177
    def get_revision(self, revision_id):
180
178
        git_commit_id, mapping = self.lookup_bzr_revision_id(revision_id)
181
179
        try:
182
 
            commit = self._git.commit(git_commit_id)
 
180
            commit = self._git[git_commit_id]
183
181
        except KeyError:
184
182
            raise errors.NoSuchRevision(self, revision_id)
185
183
        # print "fetched revision:", git_commit_id
189
187
 
190
188
    def has_revision(self, revision_id):
191
189
        try:
192
 
            self.get_revision(revision_id)
 
190
            git_commit_id, mapping = self.lookup_bzr_revision_id(revision_id)
193
191
        except errors.NoSuchRevision:
194
192
            return False
195
 
        else:
196
 
            return True
 
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
197
201
 
198
202
    def get_revisions(self, revids):
199
203
        return [self.get_revision(r) for r in revids]