/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

Add docstring.

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,
20
21
    ui,
21
22
    )
22
23
from bzrlib.repository import (
70
71
            yield (revid, git_commit)
71
72
 
72
73
    def need_sha(self, sha):
73
 
        if sha in self._sent_shas:
 
74
        if sha is None or sha in self._sent_shas:
74
75
            return False
75
76
        (type, (fileid, revid)) = self._object_store._idmap.lookup_git_sha(sha)
76
77
        assert type in ("blob", "tree")
81
82
        # or already present remotely (as git doesn't do ghosts)
82
83
        return False
83
84
 
84
 
    def queue(self, sha, obj, path, ie=None, inv=None):
 
85
    def queue(self, sha, obj, path, ie=None, inv=None, unusual_modes=None):
85
86
        if obj is None:
86
 
            obj = (ie, inv)
 
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)
87
94
        self._pending.append((obj, path))
88
95
        self._sent_shas.add(sha)
89
96
 
93
100
        """
94
101
        inv = self.source.get_inventory(revid)
95
102
        rev = self.source.get_revision(revid)
 
103
        invshamap = self._object_store._idmap.get_inventory_sha_map(revid)
96
104
        unusual_modes = extract_unusual_modes(rev)
97
105
        todo = [inv.root]
98
106
        tree_sha = None
99
107
        while todo:
100
108
            ie = todo.pop()
101
 
            (sha, object) = self._object_store._get_ie_object_or_sha1(ie, inv, unusual_modes)
 
109
            (sha, object) = self._object_store._get_ie_object_or_sha1(ie, inv, invshamap, unusual_modes)
102
110
            if ie.parent_id is None:
103
111
                tree_sha = sha
104
112
            if not self.need_sha(sha):
105
113
                continue
106
 
            self.queue(sha, object, inv.id2path(ie.file_id), ie, inv)
 
114
            self.queue(sha, object, inv.id2path(ie.file_id), ie, inv, unusual_modes)
107
115
            if ie.kind == "directory":
108
116
                todo.extend(ie.children.values())
109
117
        assert tree_sha is not None
110
118
        commit = self._object_store._get_commit(rev, tree_sha)
111
 
        self.queue(commit.id, commit, None)
 
119
        self.queue(commit.id, commit, None, None)
112
120
        return commit.id
113
121
 
114
122
    def __len__(self):
120
128
                self.pb.update("writing pack objects", i, len(self))
121
129
            if isinstance(object, tuple):
122
130
                object = self._object_store._get_ie_object(*object)
123
 
            yield (object, path)   
 
131
            yield (object, path)
124
132
 
125
133
 
126
134
class InterToGitRepository(InterRepository):
141
149
        """See InterRepository.copy_content."""
142
150
        self.fetch(revision_id, pb, find_ghosts=False)
143
151
 
144
 
    def fetch(self, revision_id=None, pb=None, find_ghosts=False, 
 
152
    def fetch(self, revision_id=None, pb=None, find_ghosts=False,
145
153
            fetch_spec=None):
146
154
        raise NoPushSupport()
147
155
 
183
191
            def check_revid(revid):
184
192
                if revid == NULL_REVISION:
185
193
                    return True
186
 
                return (self.source_store._lookup_revision_sha1(revid) in target_store)
 
194
                try:
 
195
                    return (self.source_store._lookup_revision_sha1(revid) in target_store)
 
196
                except errors.NoSuchRevision:
 
197
                    # Ghost, can't dpush
 
198
                    return True
187
199
            todo = list(self.missing_revisions(stop_revisions, check_revid))
188
200
            pb = ui.ui_factory.nested_progress_bar()
189
201
            try:
193
205
                    new_bzr_revid = self.mapping.revision_id_foreign_to_bzr(git_commit)
194
206
                    revidmap[old_bzr_revid] = new_bzr_revid
195
207
                    gitidmap[old_bzr_revid] = git_commit
196
 
                target_store.add_objects(object_generator) 
 
208
                target_store.add_objects(object_generator)
197
209
            finally:
198
210
                pb.finished()
199
211
        finally:
203
215
    @staticmethod
204
216
    def is_compatible(source, target):
205
217
        """Be compatible with GitRepository."""
206
 
        return (not isinstance(source, GitRepository) and 
 
218
        return (not isinstance(source, GitRepository) and
207
219
                isinstance(target, LocalGitRepository))
208
220
 
209
221
 
228
240
    @staticmethod
229
241
    def is_compatible(source, target):
230
242
        """Be compatible with GitRepository."""
231
 
        return (not isinstance(source, GitRepository) and 
 
243
        return (not isinstance(source, GitRepository) and
232
244
                isinstance(target, RemoteGitRepository))