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.548
by Jelmer Vernooij
Extract unusual file modes from revision when reconstructing Trees. |
33 |
from bzrlib.plugins.git.mapping import ( |
34 |
extract_unusual_modes, |
|
35 |
)
|
|
|
0.200.456
by Jelmer Vernooij
Fix git -> git fetching. |
36 |
from bzrlib.plugins.git.object_store import ( |
37 |
BazaarObjectStore, |
|
38 |
)
|
|
|
0.200.291
by Jelmer Vernooij
Print proper error about not supporting push. |
39 |
from bzrlib.plugins.git.repository import ( |
40 |
GitRepository, |
|
|
0.200.425
by Jelmer Vernooij
Split out push to remote git repositories. |
41 |
LocalGitRepository, |
|
0.200.291
by Jelmer Vernooij
Print proper error about not supporting push. |
42 |
GitRepositoryFormat, |
43 |
)
|
|
|
0.200.425
by Jelmer Vernooij
Split out push to remote git repositories. |
44 |
from bzrlib.plugins.git.remote import ( |
45 |
RemoteGitRepository, |
|
46 |
)
|
|
|
0.200.291
by Jelmer Vernooij
Print proper error about not supporting push. |
47 |
|
|
0.200.364
by Jelmer Vernooij
Reimplement dpush, but more efficient and only writing a single pack file rather than one per revision. |
48 |
|
49 |
class MissingObjectsIterator(object): |
|
50 |
"""Iterate over git objects that are missing from a target repository. |
|
51 |
||
52 |
"""
|
|
53 |
||
|
0.200.525
by Jelmer Vernooij
Simplify push a bit further, make dpush without rebase faster. |
54 |
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. |
55 |
"""Create a new missing objects iterator. |
56 |
||
57 |
"""
|
|
58 |
self.source = source |
|
|
0.200.525
by Jelmer Vernooij
Simplify push a bit further, make dpush without rebase faster. |
59 |
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. |
60 |
self._revids = set() |
61 |
self._sent_shas = set() |
|
62 |
self._pending = [] |
|
|
0.200.369
by Jelmer Vernooij
Report on pack objects progress. |
63 |
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. |
64 |
|
65 |
def import_revisions(self, revids): |
|
66 |
self._revids.update(revids) |
|
|
0.200.369
by Jelmer Vernooij
Report on pack objects progress. |
67 |
for i, revid in enumerate(revids): |
68 |
if self.pb: |
|
69 |
self.pb.update("pushing revisions", i, len(revids)) |
|
70 |
git_commit = self.import_revision(revid) |
|
71 |
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. |
72 |
|
73 |
def need_sha(self, sha): |
|
|
0.200.593
by Jelmer Vernooij
Avoid writing empty trees. |
74 |
if sha is None or sha in self._sent_shas: |
|
0.200.364
by Jelmer Vernooij
Reimplement dpush, but more efficient and only writing a single pack file rather than one per revision. |
75 |
return False |
76 |
(type, (fileid, revid)) = self._object_store._idmap.lookup_git_sha(sha) |
|
77 |
assert type in ("blob", "tree") |
|
78 |
if revid in self._revids: |
|
79 |
# Not sent yet, and part of the set of revisions to send
|
|
80 |
return True |
|
81 |
# Not changed in the revisions to send, so either not necessary
|
|
82 |
# or already present remotely (as git doesn't do ghosts)
|
|
83 |
return False |
|
84 |
||
|
0.200.581
by Jelmer Vernooij
Fix number of arguments. |
85 |
def queue(self, sha, obj, path, ie=None, inv=None, unusual_modes=None): |
|
0.200.364
by Jelmer Vernooij
Reimplement dpush, but more efficient and only writing a single pack file rather than one per revision. |
86 |
if obj is None: |
|
0.200.593
by Jelmer Vernooij
Avoid writing empty trees. |
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) |
|
|
0.200.364
by Jelmer Vernooij
Reimplement dpush, but more efficient and only writing a single pack file rather than one per revision. |
94 |
self._pending.append((obj, path)) |
95 |
self._sent_shas.add(sha) |
|
96 |
||
97 |
def import_revision(self, revid): |
|
98 |
"""Import the gist of a revision into this Git repository. |
|
99 |
||
100 |
"""
|
|
101 |
inv = self.source.get_inventory(revid) |
|
|
0.200.548
by Jelmer Vernooij
Extract unusual file modes from revision when reconstructing Trees. |
102 |
rev = self.source.get_revision(revid) |
103 |
unusual_modes = extract_unusual_modes(rev) |
|
|
0.200.364
by Jelmer Vernooij
Reimplement dpush, but more efficient and only writing a single pack file rather than one per revision. |
104 |
todo = [inv.root] |
105 |
tree_sha = None |
|
106 |
while todo: |
|
107 |
ie = todo.pop() |
|
|
0.200.548
by Jelmer Vernooij
Extract unusual file modes from revision when reconstructing Trees. |
108 |
(sha, object) = self._object_store._get_ie_object_or_sha1(ie, inv, unusual_modes) |
|
0.200.364
by Jelmer Vernooij
Reimplement dpush, but more efficient and only writing a single pack file rather than one per revision. |
109 |
if ie.parent_id is None: |
110 |
tree_sha = sha |
|
111 |
if not self.need_sha(sha): |
|
112 |
continue
|
|
|
0.200.581
by Jelmer Vernooij
Fix number of arguments. |
113 |
self.queue(sha, object, inv.id2path(ie.file_id), ie, inv, unusual_modes) |
|
0.200.364
by Jelmer Vernooij
Reimplement dpush, but more efficient and only writing a single pack file rather than one per revision. |
114 |
if ie.kind == "directory": |
115 |
todo.extend(ie.children.values()) |
|
116 |
assert tree_sha is not None |
|
|
0.200.548
by Jelmer Vernooij
Extract unusual file modes from revision when reconstructing Trees. |
117 |
commit = self._object_store._get_commit(rev, tree_sha) |
|
0.200.581
by Jelmer Vernooij
Fix number of arguments. |
118 |
self.queue(commit.id, commit, None, None) |
|
0.200.364
by Jelmer Vernooij
Reimplement dpush, but more efficient and only writing a single pack file rather than one per revision. |
119 |
return commit.id |
120 |
||
121 |
def __len__(self): |
|
122 |
return len(self._pending) |
|
123 |
||
124 |
def __iter__(self): |
|
|
0.200.369
by Jelmer Vernooij
Report on pack objects progress. |
125 |
for i, (object, path) in enumerate(self._pending): |
126 |
if self.pb: |
|
127 |
self.pb.update("writing pack objects", i, len(self)) |
|
|
0.200.364
by Jelmer Vernooij
Reimplement dpush, but more efficient and only writing a single pack file rather than one per revision. |
128 |
if isinstance(object, tuple): |
129 |
object = self._object_store._get_ie_object(*object) |
|
|
0.200.695
by Jelmer Vernooij
Clean up trailing whitespace. |
130 |
yield (object, path) |
|
0.200.364
by Jelmer Vernooij
Reimplement dpush, but more efficient and only writing a single pack file rather than one per revision. |
131 |
|
132 |
||
|
0.200.291
by Jelmer Vernooij
Print proper error about not supporting push. |
133 |
class InterToGitRepository(InterRepository): |
134 |
"""InterRepository that copies into a Git repository.""" |
|
135 |
||
136 |
_matching_repo_format = GitRepositoryFormat() |
|
137 |
||
|
0.200.435
by Jelmer Vernooij
Remember mapping per InterRepository. |
138 |
def __init__(self, source, target): |
139 |
super(InterToGitRepository, self).__init__(source, target) |
|
140 |
self.mapping = self.target.get_mapping() |
|
|
0.200.525
by Jelmer Vernooij
Simplify push a bit further, make dpush without rebase faster. |
141 |
self.source_store = BazaarObjectStore(self.source, self.mapping) |
|
0.200.435
by Jelmer Vernooij
Remember mapping per InterRepository. |
142 |
|
|
0.200.291
by Jelmer Vernooij
Print proper error about not supporting push. |
143 |
@staticmethod
|
144 |
def _get_repo_format_to_test(): |
|
145 |
return None |
|
146 |
||
147 |
def copy_content(self, revision_id=None, pb=None): |
|
148 |
"""See InterRepository.copy_content.""" |
|
149 |
self.fetch(revision_id, pb, find_ghosts=False) |
|
150 |
||
|
0.200.695
by Jelmer Vernooij
Clean up trailing whitespace. |
151 |
def fetch(self, revision_id=None, pb=None, find_ghosts=False, |
|
0.200.291
by Jelmer Vernooij
Print proper error about not supporting push. |
152 |
fetch_spec=None): |
153 |
raise NoPushSupport() |
|
154 |
||
|
0.200.425
by Jelmer Vernooij
Split out push to remote git repositories. |
155 |
|
156 |
class InterToLocalGitRepository(InterToGitRepository): |
|
157 |
||
|
0.200.525
by Jelmer Vernooij
Simplify push a bit further, make dpush without rebase faster. |
158 |
def missing_revisions(self, stop_revisions, check_revid): |
|
0.200.357
by Jelmer Vernooij
Move push code to push.py. |
159 |
missing = [] |
|
0.200.371
by Jelmer Vernooij
Add progress bar when determining revisions to dpush |
160 |
pb = ui.ui_factory.nested_progress_bar() |
161 |
try: |
|
162 |
graph = self.source.get_graph() |
|
|
0.200.524
by Jelmer Vernooij
Simplify dpushing multiple heads. |
163 |
for revid, _ in graph.iter_ancestry(stop_revisions): |
|
0.200.371
by Jelmer Vernooij
Add progress bar when determining revisions to dpush |
164 |
pb.update("determining revisions to fetch", len(missing)) |
|
0.200.525
by Jelmer Vernooij
Simplify push a bit further, make dpush without rebase faster. |
165 |
if not check_revid(revid): |
|
0.200.371
by Jelmer Vernooij
Add progress bar when determining revisions to dpush |
166 |
missing.append(revid) |
167 |
return graph.iter_topo_order(missing) |
|
168 |
finally: |
|
169 |
pb.finished() |
|
|
0.200.357
by Jelmer Vernooij
Move push code to push.py. |
170 |
|
|
0.200.428
by Jelmer Vernooij
use dfetch_refs, to prepare for dpush to remote repositories. |
171 |
def dfetch_refs(self, refs): |
|
0.200.438
by Jelmer Vernooij
Somewhat fix dpushing to remote repos. |
172 |
new_refs = {} |
|
0.200.524
by Jelmer Vernooij
Simplify dpushing multiple heads. |
173 |
revidmap, gitidmap = self.dfetch(refs.values()) |
|
0.200.428
by Jelmer Vernooij
use dfetch_refs, to prepare for dpush to remote repositories. |
174 |
for name, revid in refs.iteritems(): |
|
0.200.524
by Jelmer Vernooij
Simplify dpushing multiple heads. |
175 |
if revid in gitidmap: |
176 |
gitid = gitidmap[revid] |
|
|
0.200.435
by Jelmer Vernooij
Remember mapping per InterRepository. |
177 |
else: |
|
0.200.525
by Jelmer Vernooij
Simplify push a bit further, make dpush without rebase faster. |
178 |
gitid = self.source_store._lookup_revision_sha1(revid) |
|
0.200.480
by Jelmer Vernooij
Cope with API changes in Dulwich. |
179 |
self.target._git.refs[name] = gitid |
|
0.200.438
by Jelmer Vernooij
Somewhat fix dpushing to remote repos. |
180 |
new_refs[name] = gitid |
181 |
return revidmap, new_refs |
|
|
0.200.428
by Jelmer Vernooij
use dfetch_refs, to prepare for dpush to remote repositories. |
182 |
|
|
0.200.524
by Jelmer Vernooij
Simplify dpushing multiple heads. |
183 |
def dfetch(self, stop_revisions): |
|
0.200.357
by Jelmer Vernooij
Move push code to push.py. |
184 |
"""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. |
185 |
gitidmap = {} |
|
0.200.357
by Jelmer Vernooij
Move push code to push.py. |
186 |
revidmap = {} |
|
0.200.367
by Jelmer Vernooij
In dfetch, skip fetching pushed revisions back, as cmd_dpush will already take care of that. |
187 |
self.source.lock_read() |
|
0.200.357
by Jelmer Vernooij
Move push code to push.py. |
188 |
try: |
|
0.200.525
by Jelmer Vernooij
Simplify push a bit further, make dpush without rebase faster. |
189 |
target_store = self.target._git.object_store |
190 |
def check_revid(revid): |
|
191 |
if revid == NULL_REVISION: |
|
192 |
return True |
|
|
0.200.598
by Jelmer Vernooij
Cope with ghosts. |
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 |
|
|
0.200.525
by Jelmer Vernooij
Simplify push a bit further, make dpush without rebase faster. |
198 |
todo = list(self.missing_revisions(stop_revisions, check_revid)) |
|
0.200.369
by Jelmer Vernooij
Report on pack objects progress. |
199 |
pb = ui.ui_factory.nested_progress_bar() |
200 |
try: |
|
|
0.200.525
by Jelmer Vernooij
Simplify push a bit further, make dpush without rebase faster. |
201 |
object_generator = MissingObjectsIterator(self.source_store, self.source, pb) |
|
0.200.369
by Jelmer Vernooij
Report on pack objects progress. |
202 |
for old_bzr_revid, git_commit in object_generator.import_revisions( |
203 |
todo): |
|
|
0.200.435
by Jelmer Vernooij
Remember mapping per InterRepository. |
204 |
new_bzr_revid = self.mapping.revision_id_foreign_to_bzr(git_commit) |
|
0.200.369
by Jelmer Vernooij
Report on pack objects progress. |
205 |
revidmap[old_bzr_revid] = new_bzr_revid |
|
0.200.428
by Jelmer Vernooij
use dfetch_refs, to prepare for dpush to remote repositories. |
206 |
gitidmap[old_bzr_revid] = git_commit |
|
0.200.695
by Jelmer Vernooij
Clean up trailing whitespace. |
207 |
target_store.add_objects(object_generator) |
|
0.200.369
by Jelmer Vernooij
Report on pack objects progress. |
208 |
finally: |
209 |
pb.finished() |
|
|
0.200.357
by Jelmer Vernooij
Move push code to push.py. |
210 |
finally: |
211 |
self.source.unlock() |
|
|
0.200.428
by Jelmer Vernooij
use dfetch_refs, to prepare for dpush to remote repositories. |
212 |
return revidmap, gitidmap |
|
0.200.357
by Jelmer Vernooij
Move push code to push.py. |
213 |
|
|
0.200.291
by Jelmer Vernooij
Print proper error about not supporting push. |
214 |
@staticmethod
|
215 |
def is_compatible(source, target): |
|
216 |
"""Be compatible with GitRepository.""" |
|
|
0.200.695
by Jelmer Vernooij
Clean up trailing whitespace. |
217 |
return (not isinstance(source, GitRepository) and |
|
0.200.425
by Jelmer Vernooij
Split out push to remote git repositories. |
218 |
isinstance(target, LocalGitRepository)) |
219 |
||
220 |
||
221 |
class InterToRemoteGitRepository(InterToGitRepository): |
|
222 |
||
|
0.200.429
by Jelmer Vernooij
get remote dpush to a point where we now what to send. |
223 |
def dfetch_refs(self, new_refs): |
|
0.200.425
by Jelmer Vernooij
Split out push to remote git repositories. |
224 |
"""Import the gist of the ancestry of a particular revision.""" |
225 |
revidmap = {} |
|
|
0.200.452
by Jelmer Vernooij
Rename converter -> object_store, provide utility function for getting ObjectStore's. |
226 |
def determine_wants(refs): |
|
0.200.429
by Jelmer Vernooij
get remote dpush to a point where we now what to send. |
227 |
ret = {} |
228 |
for name, revid in new_refs.iteritems(): |
|
|
0.200.525
by Jelmer Vernooij
Simplify push a bit further, make dpush without rebase faster. |
229 |
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. |
230 |
return ret |
|
0.200.425
by Jelmer Vernooij
Split out push to remote git repositories. |
231 |
self.source.lock_read() |
232 |
try: |
|
|
0.200.460
by Jelmer Vernooij
Somewhat fix commit in git working trees. |
233 |
new_refs = self.target.send_pack(determine_wants, |
|
0.200.525
by Jelmer Vernooij
Simplify push a bit further, make dpush without rebase faster. |
234 |
self.source_store.generate_pack_contents) |
|
0.200.425
by Jelmer Vernooij
Split out push to remote git repositories. |
235 |
finally: |
236 |
self.source.unlock() |
|
|
0.200.438
by Jelmer Vernooij
Somewhat fix dpushing to remote repos. |
237 |
return revidmap, new_refs |
|
0.200.425
by Jelmer Vernooij
Split out push to remote git repositories. |
238 |
|
239 |
@staticmethod
|
|
240 |
def is_compatible(source, target): |
|
241 |
"""Be compatible with GitRepository.""" |
|
|
0.200.695
by Jelmer Vernooij
Clean up trailing whitespace. |
242 |
return (not isinstance(source, GitRepository) and |
|
0.200.425
by Jelmer Vernooij
Split out push to remote git repositories. |
243 |
isinstance(target, RemoteGitRepository)) |