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

  • Committer: Jelmer Vernooij
  • Date: 2009-05-16 21:13:17 UTC
  • mto: (0.200.527 trunk)
  • mto: This revision was merged to the branch mainline in revision 6960.
  • Revision ID: jelmer@samba.org-20090516211317-a0s14tsrf2qusapf
Fix tests.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
"""Push implementation that simply prints message saying push is not supported."""
18
18
 
19
19
from bzrlib import (
20
 
    errors,
21
20
    ui,
22
21
    )
23
22
from bzrlib.repository import (
30
29
from bzrlib.plugins.git.errors import (
31
30
    NoPushSupport,
32
31
    )
33
 
from bzrlib.plugins.git.mapping import (
34
 
    extract_unusual_modes,
35
 
    )
36
32
from bzrlib.plugins.git.object_store import (
37
33
    BazaarObjectStore,
38
34
    )
71
67
            yield (revid, git_commit)
72
68
 
73
69
    def need_sha(self, sha):
74
 
        if sha is None or sha in self._sent_shas:
 
70
        if sha in self._sent_shas:
75
71
            return False
76
72
        (type, (fileid, revid)) = self._object_store._idmap.lookup_git_sha(sha)
77
73
        assert type in ("blob", "tree")
82
78
        # or already present remotely (as git doesn't do ghosts)
83
79
        return False
84
80
 
85
 
    def queue(self, sha, obj, path, ie=None, inv=None, unusual_modes=None):
 
81
    def queue(self, sha, obj, path, ie=None, inv=None):
86
82
        if obj is None:
87
 
            # Can't lazy-evaluate directories, since they might be eliminated
88
 
            if ie.kind == "directory":
89
 
                obj = self._object_store._get_ie_object(ie, inv, unusual_modes)
90
 
                if obj is None:
91
 
                    return
92
 
            else:
93
 
                obj = (ie, inv, unusual_modes)
 
83
            obj = (ie, inv)
94
84
        self._pending.append((obj, path))
95
85
        self._sent_shas.add(sha)
96
86
 
99
89
 
100
90
        """
101
91
        inv = self.source.get_inventory(revid)
102
 
        rev = self.source.get_revision(revid)
103
 
        unusual_modes = extract_unusual_modes(rev)
104
92
        todo = [inv.root]
105
93
        tree_sha = None
106
94
        while todo:
107
95
            ie = todo.pop()
108
 
            (sha, object) = self._object_store._get_ie_object_or_sha1(ie, inv, unusual_modes)
 
96
            (sha, object) = self._object_store._get_ie_object_or_sha1(ie, inv)
109
97
            if ie.parent_id is None:
110
98
                tree_sha = sha
111
99
            if not self.need_sha(sha):
112
100
                continue
113
 
            self.queue(sha, object, inv.id2path(ie.file_id), ie, inv, unusual_modes)
 
101
            self.queue(sha, object, inv.id2path(ie.file_id), ie, inv)
114
102
            if ie.kind == "directory":
115
103
                todo.extend(ie.children.values())
116
104
        assert tree_sha is not None
117
 
        commit = self._object_store._get_commit(rev, tree_sha)
118
 
        self.queue(commit.id, commit, None, None)
 
105
        commit = self._object_store._get_commit(revid, tree_sha)
 
106
        self.queue(commit.id, commit, None)
119
107
        return commit.id
120
108
 
121
109
    def __len__(self):
127
115
                self.pb.update("writing pack objects", i, len(self))
128
116
            if isinstance(object, tuple):
129
117
                object = self._object_store._get_ie_object(*object)
130
 
            yield (object, path)
 
118
            yield (object, path)   
131
119
 
132
120
 
133
121
class InterToGitRepository(InterRepository):
148
136
        """See InterRepository.copy_content."""
149
137
        self.fetch(revision_id, pb, find_ghosts=False)
150
138
 
151
 
    def fetch(self, revision_id=None, pb=None, find_ghosts=False,
 
139
    def fetch(self, revision_id=None, pb=None, find_ghosts=False, 
152
140
            fetch_spec=None):
153
141
        raise NoPushSupport()
154
142
 
190
178
            def check_revid(revid):
191
179
                if revid == NULL_REVISION:
192
180
                    return True
193
 
                try:
194
 
                    return (self.source_store._lookup_revision_sha1(revid) in target_store)
195
 
                except errors.NoSuchRevision:
196
 
                    # Ghost, can't dpush
197
 
                    return True
 
181
                return (self.source_store._lookup_revision_sha1(revid) in target_store)
198
182
            todo = list(self.missing_revisions(stop_revisions, check_revid))
199
183
            pb = ui.ui_factory.nested_progress_bar()
200
184
            try:
204
188
                    new_bzr_revid = self.mapping.revision_id_foreign_to_bzr(git_commit)
205
189
                    revidmap[old_bzr_revid] = new_bzr_revid
206
190
                    gitidmap[old_bzr_revid] = git_commit
207
 
                target_store.add_objects(object_generator)
 
191
                target_store.add_objects(object_generator) 
208
192
            finally:
209
193
                pb.finished()
210
194
        finally:
214
198
    @staticmethod
215
199
    def is_compatible(source, target):
216
200
        """Be compatible with GitRepository."""
217
 
        return (not isinstance(source, GitRepository) and
 
201
        return (not isinstance(source, GitRepository) and 
218
202
                isinstance(target, LocalGitRepository))
219
203
 
220
204
 
239
223
    @staticmethod
240
224
    def is_compatible(source, target):
241
225
        """Be compatible with GitRepository."""
242
 
        return (not isinstance(source, GitRepository) and
 
226
        return (not isinstance(source, GitRepository) and 
243
227
                isinstance(target, RemoteGitRepository))