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 |
74 |
for path, obj in self._object_store._revision_to_objects(rev, inv): |
|
75 |
if obj._type == "commit": |
|
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.438
by Jelmer Vernooij
Somewhat fix dpushing to remote repos. |
126 |
new_refs = {} |
0.200.524
by Jelmer Vernooij
Simplify dpushing multiple heads. |
127 |
revidmap, gitidmap = self.dfetch(refs.values()) |
0.200.428
by Jelmer Vernooij
use dfetch_refs, to prepare for dpush to remote repositories. |
128 |
for name, revid in refs.iteritems(): |
0.200.524
by Jelmer Vernooij
Simplify dpushing multiple heads. |
129 |
if revid in gitidmap: |
130 |
gitid = gitidmap[revid] |
|
0.200.435
by Jelmer Vernooij
Remember mapping per InterRepository. |
131 |
else: |
0.200.525
by Jelmer Vernooij
Simplify push a bit further, make dpush without rebase faster. |
132 |
gitid = self.source_store._lookup_revision_sha1(revid) |
0.200.480
by Jelmer Vernooij
Cope with API changes in Dulwich. |
133 |
self.target._git.refs[name] = gitid |
0.200.438
by Jelmer Vernooij
Somewhat fix dpushing to remote repos. |
134 |
new_refs[name] = gitid |
135 |
return revidmap, new_refs |
|
0.200.428
by Jelmer Vernooij
use dfetch_refs, to prepare for dpush to remote repositories. |
136 |
|
0.200.524
by Jelmer Vernooij
Simplify dpushing multiple heads. |
137 |
def dfetch(self, stop_revisions): |
0.200.357
by Jelmer Vernooij
Move push code to push.py. |
138 |
"""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. |
139 |
gitidmap = {} |
0.200.357
by Jelmer Vernooij
Move push code to push.py. |
140 |
revidmap = {} |
0.200.367
by Jelmer Vernooij
In dfetch, skip fetching pushed revisions back, as cmd_dpush will already take care of that. |
141 |
self.source.lock_read() |
0.200.357
by Jelmer Vernooij
Move push code to push.py. |
142 |
try: |
0.200.525
by Jelmer Vernooij
Simplify push a bit further, make dpush without rebase faster. |
143 |
target_store = self.target._git.object_store |
144 |
def check_revid(revid): |
|
145 |
if revid == NULL_REVISION: |
|
146 |
return True |
|
0.200.598
by Jelmer Vernooij
Cope with ghosts. |
147 |
try: |
148 |
return (self.source_store._lookup_revision_sha1(revid) in target_store) |
|
149 |
except errors.NoSuchRevision: |
|
150 |
# Ghost, can't dpush
|
|
151 |
return True |
|
0.200.525
by Jelmer Vernooij
Simplify push a bit further, make dpush without rebase faster. |
152 |
todo = list(self.missing_revisions(stop_revisions, check_revid)) |
0.200.369
by Jelmer Vernooij
Report on pack objects progress. |
153 |
pb = ui.ui_factory.nested_progress_bar() |
154 |
try: |
|
0.200.525
by Jelmer Vernooij
Simplify push a bit further, make dpush without rebase faster. |
155 |
object_generator = MissingObjectsIterator(self.source_store, self.source, pb) |
0.200.369
by Jelmer Vernooij
Report on pack objects progress. |
156 |
for old_bzr_revid, git_commit in object_generator.import_revisions( |
157 |
todo): |
|
0.200.435
by Jelmer Vernooij
Remember mapping per InterRepository. |
158 |
new_bzr_revid = self.mapping.revision_id_foreign_to_bzr(git_commit) |
0.200.369
by Jelmer Vernooij
Report on pack objects progress. |
159 |
revidmap[old_bzr_revid] = new_bzr_revid |
0.200.428
by Jelmer Vernooij
use dfetch_refs, to prepare for dpush to remote repositories. |
160 |
gitidmap[old_bzr_revid] = git_commit |
0.200.695
by Jelmer Vernooij
Clean up trailing whitespace. |
161 |
target_store.add_objects(object_generator) |
0.200.369
by Jelmer Vernooij
Report on pack objects progress. |
162 |
finally: |
163 |
pb.finished() |
|
0.200.357
by Jelmer Vernooij
Move push code to push.py. |
164 |
finally: |
165 |
self.source.unlock() |
|
0.200.428
by Jelmer Vernooij
use dfetch_refs, to prepare for dpush to remote repositories. |
166 |
return revidmap, gitidmap |
0.200.357
by Jelmer Vernooij
Move push code to push.py. |
167 |
|
0.200.291
by Jelmer Vernooij
Print proper error about not supporting push. |
168 |
@staticmethod
|
169 |
def is_compatible(source, target): |
|
170 |
"""Be compatible with GitRepository.""" |
|
0.200.695
by Jelmer Vernooij
Clean up trailing whitespace. |
171 |
return (not isinstance(source, GitRepository) and |
0.200.425
by Jelmer Vernooij
Split out push to remote git repositories. |
172 |
isinstance(target, LocalGitRepository)) |
173 |
||
174 |
||
175 |
class InterToRemoteGitRepository(InterToGitRepository): |
|
176 |
||
0.200.429
by Jelmer Vernooij
get remote dpush to a point where we now what to send. |
177 |
def dfetch_refs(self, new_refs): |
0.200.425
by Jelmer Vernooij
Split out push to remote git repositories. |
178 |
"""Import the gist of the ancestry of a particular revision.""" |
179 |
revidmap = {} |
|
0.200.452
by Jelmer Vernooij
Rename converter -> object_store, provide utility function for getting ObjectStore's. |
180 |
def determine_wants(refs): |
0.200.429
by Jelmer Vernooij
get remote dpush to a point where we now what to send. |
181 |
ret = {} |
182 |
for name, revid in new_refs.iteritems(): |
|
0.200.525
by Jelmer Vernooij
Simplify push a bit further, make dpush without rebase faster. |
183 |
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. |
184 |
return ret |
0.200.425
by Jelmer Vernooij
Split out push to remote git repositories. |
185 |
self.source.lock_read() |
186 |
try: |
|
0.200.460
by Jelmer Vernooij
Somewhat fix commit in git working trees. |
187 |
new_refs = self.target.send_pack(determine_wants, |
0.200.525
by Jelmer Vernooij
Simplify push a bit further, make dpush without rebase faster. |
188 |
self.source_store.generate_pack_contents) |
0.200.425
by Jelmer Vernooij
Split out push to remote git repositories. |
189 |
finally: |
190 |
self.source.unlock() |
|
0.200.438
by Jelmer Vernooij
Somewhat fix dpushing to remote repos. |
191 |
return revidmap, new_refs |
0.200.425
by Jelmer Vernooij
Split out push to remote git repositories. |
192 |
|
193 |
@staticmethod
|
|
194 |
def is_compatible(source, target): |
|
195 |
"""Be compatible with GitRepository.""" |
|
0.200.695
by Jelmer Vernooij
Clean up trailing whitespace. |
196 |
return (not isinstance(source, GitRepository) and |
0.200.425
by Jelmer Vernooij
Split out push to remote git repositories. |
197 |
isinstance(target, RemoteGitRepository)) |