/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
0.200.291 by Jelmer Vernooij
Print proper error about not supporting push.
1
# Copyright (C) 2009 Jelmer Vernooij <jelmer@samba.org>
2
#
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
7
#
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
12
#
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
17
"""Push implementation that simply prints message saying push is not supported."""
18
0.200.357 by Jelmer Vernooij
Move push code to push.py.
19
from bzrlib import (
0.200.598 by Jelmer Vernooij
Cope with ghosts.
20
    errors,
0.200.357 by Jelmer Vernooij
Move push code to push.py.
21
    ui,
22
    )
0.200.291 by Jelmer Vernooij
Print proper error about not supporting push.
23
from bzrlib.repository import (
24
    InterRepository,
25
    )
0.200.371 by Jelmer Vernooij
Add progress bar when determining revisions to dpush
26
from bzrlib.revision import (
27
    NULL_REVISION,
28
    )
0.200.291 by Jelmer Vernooij
Print proper error about not supporting push.
29
30
from bzrlib.plugins.git.errors import (
31
    NoPushSupport,
32
    )
0.200.456 by Jelmer Vernooij
Fix git -> git fetching.
33
from bzrlib.plugins.git.object_store import (
34
    BazaarObjectStore,
35
    )
0.200.291 by Jelmer Vernooij
Print proper error about not supporting push.
36
from bzrlib.plugins.git.repository import (
37
    GitRepository,
0.200.425 by Jelmer Vernooij
Split out push to remote git repositories.
38
    LocalGitRepository,
0.200.291 by Jelmer Vernooij
Print proper error about not supporting push.
39
    GitRepositoryFormat,
40
    )
0.200.425 by Jelmer Vernooij
Split out push to remote git repositories.
41
from bzrlib.plugins.git.remote import (
42
    RemoteGitRepository,
43
    )
0.200.291 by Jelmer Vernooij
Print proper error about not supporting push.
44
0.200.364 by Jelmer Vernooij
Reimplement dpush, but more efficient and only writing a single pack file rather than one per revision.
45
46
class MissingObjectsIterator(object):
47
    """Iterate over git objects that are missing from a target repository.
48
49
    """
50
0.200.525 by Jelmer Vernooij
Simplify push a bit further, make dpush without rebase faster.
51
    def __init__(self, store, source, pb=None):
0.200.364 by Jelmer Vernooij
Reimplement dpush, but more efficient and only writing a single pack file rather than one per revision.
52
        """Create a new missing objects iterator.
53
54
        """
55
        self.source = source
0.200.525 by Jelmer Vernooij
Simplify push a bit further, make dpush without rebase faster.
56
        self._object_store = store
0.200.364 by Jelmer Vernooij
Reimplement dpush, but more efficient and only writing a single pack file rather than one per revision.
57
        self._pending = []
0.200.369 by Jelmer Vernooij
Report on pack objects progress.
58
        self.pb = pb
0.200.364 by Jelmer Vernooij
Reimplement dpush, but more efficient and only writing a single pack file rather than one per revision.
59
60
    def import_revisions(self, revids):
0.200.369 by Jelmer Vernooij
Report on pack objects progress.
61
        for i, revid in enumerate(revids):
62
            if self.pb:
63
                self.pb.update("pushing revisions", i, len(revids))
64
            git_commit = self.import_revision(revid)
65
            yield (revid, git_commit)
0.200.364 by Jelmer Vernooij
Reimplement dpush, but more efficient and only writing a single pack file rather than one per revision.
66
67
    def import_revision(self, revid):
68
        """Import the gist of a revision into this Git repository.
69
70
        """
0.200.789 by Jelmer Vernooij
Cope with ghosts, cache inventories.
71
        inv = self._object_store.parent_invs_cache.get_inventory(revid)
0.200.548 by Jelmer Vernooij
Extract unusual file modes from revision when reconstructing Trees.
72
        rev = self.source.get_revision(revid)
0.200.784 by Jelmer Vernooij
Use common object generation code in push.
73
        commit = None
0.200.837 by Jelmer Vernooij
Return inventory entries when creating git objects for a revision.
74
        for path, obj, ie in self._object_store._revision_to_objects(rev, inv):
0.200.829 by Jelmer Vernooij
Cope with the fact that _type is gone in upstream dulwich.
75
            if obj.type_name == "commit":
0.200.784 by Jelmer Vernooij
Use common object generation code in push.
76
                commit = obj
0.200.786 by Jelmer Vernooij
Simplify push code.
77
            self._pending.append((obj, path))
0.200.364 by Jelmer Vernooij
Reimplement dpush, but more efficient and only writing a single pack file rather than one per revision.
78
        return commit.id
79
80
    def __len__(self):
81
        return len(self._pending)
82
83
    def __iter__(self):
0.200.786 by Jelmer Vernooij
Simplify push code.
84
        return iter(self._pending)
0.200.364 by Jelmer Vernooij
Reimplement dpush, but more efficient and only writing a single pack file rather than one per revision.
85
86
0.200.291 by Jelmer Vernooij
Print proper error about not supporting push.
87
class InterToGitRepository(InterRepository):
88
    """InterRepository that copies into a Git repository."""
89
90
    _matching_repo_format = GitRepositoryFormat()
91
0.200.435 by Jelmer Vernooij
Remember mapping per InterRepository.
92
    def __init__(self, source, target):
93
        super(InterToGitRepository, self).__init__(source, target)
94
        self.mapping = self.target.get_mapping()
0.200.525 by Jelmer Vernooij
Simplify push a bit further, make dpush without rebase faster.
95
        self.source_store = BazaarObjectStore(self.source, self.mapping)
0.200.435 by Jelmer Vernooij
Remember mapping per InterRepository.
96
0.200.291 by Jelmer Vernooij
Print proper error about not supporting push.
97
    @staticmethod
98
    def _get_repo_format_to_test():
99
        return None
100
101
    def copy_content(self, revision_id=None, pb=None):
102
        """See InterRepository.copy_content."""
103
        self.fetch(revision_id, pb, find_ghosts=False)
104
0.200.695 by Jelmer Vernooij
Clean up trailing whitespace.
105
    def fetch(self, revision_id=None, pb=None, find_ghosts=False,
0.200.291 by Jelmer Vernooij
Print proper error about not supporting push.
106
            fetch_spec=None):
107
        raise NoPushSupport()
108
0.200.425 by Jelmer Vernooij
Split out push to remote git repositories.
109
110
class InterToLocalGitRepository(InterToGitRepository):
111
0.200.525 by Jelmer Vernooij
Simplify push a bit further, make dpush without rebase faster.
112
    def missing_revisions(self, stop_revisions, check_revid):
0.200.357 by Jelmer Vernooij
Move push code to push.py.
113
        missing = []
0.200.371 by Jelmer Vernooij
Add progress bar when determining revisions to dpush
114
        pb = ui.ui_factory.nested_progress_bar()
115
        try:
116
            graph = self.source.get_graph()
0.200.524 by Jelmer Vernooij
Simplify dpushing multiple heads.
117
            for revid, _ in graph.iter_ancestry(stop_revisions):
0.200.371 by Jelmer Vernooij
Add progress bar when determining revisions to dpush
118
                pb.update("determining revisions to fetch", len(missing))
0.200.525 by Jelmer Vernooij
Simplify push a bit further, make dpush without rebase faster.
119
                if not check_revid(revid):
0.200.371 by Jelmer Vernooij
Add progress bar when determining revisions to dpush
120
                    missing.append(revid)
121
            return graph.iter_topo_order(missing)
122
        finally:
123
            pb.finished()
0.200.357 by Jelmer Vernooij
Move push code to push.py.
124
0.200.428 by Jelmer Vernooij
use dfetch_refs, to prepare for dpush to remote repositories.
125
    def dfetch_refs(self, refs):
0.200.822 by Jelmer Vernooij
Fix indication of number of revisions pushed in dpush.
126
        old_refs = self.target._git.get_refs()
0.200.438 by Jelmer Vernooij
Somewhat fix dpushing to remote repos.
127
        new_refs = {}
0.200.524 by Jelmer Vernooij
Simplify dpushing multiple heads.
128
        revidmap, gitidmap = self.dfetch(refs.values())
0.200.428 by Jelmer Vernooij
use dfetch_refs, to prepare for dpush to remote repositories.
129
        for name, revid in refs.iteritems():
0.200.524 by Jelmer Vernooij
Simplify dpushing multiple heads.
130
            if revid in gitidmap:
131
                gitid = gitidmap[revid]
0.200.435 by Jelmer Vernooij
Remember mapping per InterRepository.
132
            else:
0.200.525 by Jelmer Vernooij
Simplify push a bit further, make dpush without rebase faster.
133
                gitid = self.source_store._lookup_revision_sha1(revid)
0.200.480 by Jelmer Vernooij
Cope with API changes in Dulwich.
134
            self.target._git.refs[name] = gitid
0.200.438 by Jelmer Vernooij
Somewhat fix dpushing to remote repos.
135
            new_refs[name] = gitid
0.200.822 by Jelmer Vernooij
Fix indication of number of revisions pushed in dpush.
136
        return revidmap, old_refs, new_refs
0.200.428 by Jelmer Vernooij
use dfetch_refs, to prepare for dpush to remote repositories.
137
0.200.524 by Jelmer Vernooij
Simplify dpushing multiple heads.
138
    def dfetch(self, stop_revisions):
0.200.357 by Jelmer Vernooij
Move push code to push.py.
139
        """Import the gist of the ancestry of a particular revision."""
0.200.428 by Jelmer Vernooij
use dfetch_refs, to prepare for dpush to remote repositories.
140
        gitidmap = {}
0.200.357 by Jelmer Vernooij
Move push code to push.py.
141
        revidmap = {}
0.200.367 by Jelmer Vernooij
In dfetch, skip fetching pushed revisions back, as cmd_dpush will already take care of that.
142
        self.source.lock_read()
0.200.357 by Jelmer Vernooij
Move push code to push.py.
143
        try:
0.200.525 by Jelmer Vernooij
Simplify push a bit further, make dpush without rebase faster.
144
            target_store = self.target._git.object_store
145
            def check_revid(revid):
146
                if revid == NULL_REVISION:
147
                    return True
0.200.598 by Jelmer Vernooij
Cope with ghosts.
148
                try:
149
                    return (self.source_store._lookup_revision_sha1(revid) in target_store)
150
                except errors.NoSuchRevision:
151
                    # Ghost, can't dpush
152
                    return True
0.200.525 by Jelmer Vernooij
Simplify push a bit further, make dpush without rebase faster.
153
            todo = list(self.missing_revisions(stop_revisions, check_revid))
0.200.369 by Jelmer Vernooij
Report on pack objects progress.
154
            pb = ui.ui_factory.nested_progress_bar()
155
            try:
0.200.525 by Jelmer Vernooij
Simplify push a bit further, make dpush without rebase faster.
156
                object_generator = MissingObjectsIterator(self.source_store, self.source, pb)
0.200.369 by Jelmer Vernooij
Report on pack objects progress.
157
                for old_bzr_revid, git_commit in object_generator.import_revisions(
158
                    todo):
0.200.435 by Jelmer Vernooij
Remember mapping per InterRepository.
159
                    new_bzr_revid = self.mapping.revision_id_foreign_to_bzr(git_commit)
0.200.369 by Jelmer Vernooij
Report on pack objects progress.
160
                    revidmap[old_bzr_revid] = new_bzr_revid
0.200.428 by Jelmer Vernooij
use dfetch_refs, to prepare for dpush to remote repositories.
161
                    gitidmap[old_bzr_revid] = git_commit
0.200.695 by Jelmer Vernooij
Clean up trailing whitespace.
162
                target_store.add_objects(object_generator)
0.200.369 by Jelmer Vernooij
Report on pack objects progress.
163
            finally:
164
                pb.finished()
0.200.357 by Jelmer Vernooij
Move push code to push.py.
165
        finally:
166
            self.source.unlock()
0.200.428 by Jelmer Vernooij
use dfetch_refs, to prepare for dpush to remote repositories.
167
        return revidmap, gitidmap
0.200.357 by Jelmer Vernooij
Move push code to push.py.
168
0.200.291 by Jelmer Vernooij
Print proper error about not supporting push.
169
    @staticmethod
170
    def is_compatible(source, target):
171
        """Be compatible with GitRepository."""
0.200.695 by Jelmer Vernooij
Clean up trailing whitespace.
172
        return (not isinstance(source, GitRepository) and
0.200.425 by Jelmer Vernooij
Split out push to remote git repositories.
173
                isinstance(target, LocalGitRepository))
174
175
176
class InterToRemoteGitRepository(InterToGitRepository):
177
0.200.429 by Jelmer Vernooij
get remote dpush to a point where we now what to send.
178
    def dfetch_refs(self, new_refs):
0.200.425 by Jelmer Vernooij
Split out push to remote git repositories.
179
        """Import the gist of the ancestry of a particular revision."""
180
        revidmap = {}
0.200.822 by Jelmer Vernooij
Fix indication of number of revisions pushed in dpush.
181
        old_refs = {}
0.200.452 by Jelmer Vernooij
Rename converter -> object_store, provide utility function for getting ObjectStore's.
182
        def determine_wants(refs):
0.200.429 by Jelmer Vernooij
get remote dpush to a point where we now what to send.
183
            ret = {}
0.200.822 by Jelmer Vernooij
Fix indication of number of revisions pushed in dpush.
184
            old_refs.update(new_refs)
0.200.429 by Jelmer Vernooij
get remote dpush to a point where we now what to send.
185
            for name, revid in new_refs.iteritems():
0.200.525 by Jelmer Vernooij
Simplify push a bit further, make dpush without rebase faster.
186
                ret[name] = self.source_store._lookup_revision_sha1(revid)
0.200.429 by Jelmer Vernooij
get remote dpush to a point where we now what to send.
187
            return ret
0.200.425 by Jelmer Vernooij
Split out push to remote git repositories.
188
        self.source.lock_read()
189
        try:
0.200.460 by Jelmer Vernooij
Somewhat fix commit in git working trees.
190
            new_refs = self.target.send_pack(determine_wants,
0.200.525 by Jelmer Vernooij
Simplify push a bit further, make dpush without rebase faster.
191
                    self.source_store.generate_pack_contents)
0.200.425 by Jelmer Vernooij
Split out push to remote git repositories.
192
        finally:
193
            self.source.unlock()
0.200.822 by Jelmer Vernooij
Fix indication of number of revisions pushed in dpush.
194
        return revidmap, old_refs, new_refs
0.200.425 by Jelmer Vernooij
Split out push to remote git repositories.
195
196
    @staticmethod
197
    def is_compatible(source, target):
198
        """Be compatible with GitRepository."""
0.200.695 by Jelmer Vernooij
Clean up trailing whitespace.
199
        return (not isinstance(source, GitRepository) and
0.200.425 by Jelmer Vernooij
Split out push to remote git repositories.
200
                isinstance(target, RemoteGitRepository))