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 ( |
20 |
ui, |
|
21 |
)
|
|
|
0.200.291
by Jelmer Vernooij
Print proper error about not supporting push. |
22 |
from bzrlib.repository import ( |
23 |
InterRepository, |
|
24 |
)
|
|
25 |
||
26 |
from bzrlib.plugins.git.errors import ( |
|
27 |
NoPushSupport, |
|
28 |
)
|
|
|
0.200.357
by Jelmer Vernooij
Move push code to push.py. |
29 |
from bzrlib.plugins.git.mapping import ( |
30 |
inventory_to_tree_and_blobs, |
|
31 |
revision_to_commit, |
|
32 |
)
|
|
|
0.200.291
by Jelmer Vernooij
Print proper error about not supporting push. |
33 |
from bzrlib.plugins.git.repository import ( |
34 |
GitRepository, |
|
35 |
GitRepositoryFormat, |
|
36 |
)
|
|
37 |
||
38 |
class InterToGitRepository(InterRepository): |
|
39 |
"""InterRepository that copies into a Git repository.""" |
|
40 |
||
41 |
_matching_repo_format = GitRepositoryFormat() |
|
42 |
||
43 |
@staticmethod
|
|
44 |
def _get_repo_format_to_test(): |
|
45 |
return None |
|
46 |
||
47 |
def copy_content(self, revision_id=None, pb=None): |
|
48 |
"""See InterRepository.copy_content.""" |
|
49 |
self.fetch(revision_id, pb, find_ghosts=False) |
|
50 |
||
51 |
def fetch(self, revision_id=None, pb=None, find_ghosts=False, |
|
52 |
fetch_spec=None): |
|
53 |
raise NoPushSupport() |
|
54 |
||
|
0.200.357
by Jelmer Vernooij
Move push code to push.py. |
55 |
def import_revision_gist(self, revid, parent_lookup): |
56 |
"""Import the gist of a revision into this Git repository. |
|
57 |
||
58 |
"""
|
|
59 |
objects = [] |
|
60 |
rev = self.source.get_revision(revid) |
|
61 |
for sha, object, path in inventory_to_tree_and_blobs( |
|
62 |
self.source.get_inventory(revid), self.source.texts, None): |
|
63 |
if path == "": |
|
64 |
tree_sha = sha |
|
65 |
objects.append((object, path)) |
|
66 |
commit = revision_to_commit(rev, tree_sha, parent_lookup) |
|
67 |
objects.append((commit, None)) |
|
68 |
self.target._git.object_store.add_objects(objects) |
|
69 |
return commit.sha().hexdigest() |
|
70 |
||
|
0.200.360
by Jelmer Vernooij
Remove dpush ghost support - it makes no sense, git doesn't do ghosts. |
71 |
def missing_revisions(self, stop_revision=None): |
|
0.200.357
by Jelmer Vernooij
Move push code to push.py. |
72 |
if stop_revision is not None: |
73 |
ancestry = [x for x in self.source.get_ancestry(stop_revision) if x is not None] |
|
74 |
else: |
|
75 |
ancestry = self.source.all_revision_ids() |
|
76 |
missing = [] |
|
77 |
graph = self.source.get_graph() |
|
78 |
for revid in graph.iter_topo_order(ancestry): |
|
79 |
if not self.target.has_revision(revid): |
|
80 |
missing.append(revid) |
|
81 |
return missing |
|
82 |
||
|
0.200.360
by Jelmer Vernooij
Remove dpush ghost support - it makes no sense, git doesn't do ghosts. |
83 |
def dfetch(self, stop_revision=None): |
|
0.200.357
by Jelmer Vernooij
Move push code to push.py. |
84 |
"""Import the gist of the ancestry of a particular revision.""" |
85 |
revidmap = {} |
|
86 |
gitidmap = {} |
|
87 |
def parent_lookup(revid): |
|
88 |
try: |
|
89 |
return gitidmap[revid] |
|
90 |
except KeyError: |
|
91 |
return self.target.lookup_git_revid(revid)[0] |
|
92 |
mapping = self.target.get_mapping() |
|
93 |
self.source.lock_write() |
|
94 |
try: |
|
95 |
todo = self.missing_revisions(stop_revision, ghosts=fetch_ghosts) |
|
96 |
pb = ui.ui_factory.nested_progress_bar() |
|
97 |
try: |
|
98 |
for i, revid in enumerate(todo): |
|
99 |
pb.update("pushing revisions", i, len(todo)) |
|
100 |
git_commit = self.import_revision_gist(revid, parent_lookup) |
|
101 |
gitidmap[revid] = git_commit |
|
102 |
git_revid = mapping.revision_id_foreign_to_bzr(git_commit) |
|
103 |
revidmap[revid] = git_revid |
|
104 |
finally: |
|
105 |
pb.finished() |
|
106 |
if revidmap != {}: |
|
107 |
self.source.fetch(self.target, |
|
108 |
revision_id=revidmap[stop_revision]) |
|
109 |
finally: |
|
110 |
self.source.unlock() |
|
111 |
return revidmap |
|
112 |
||
|
0.200.291
by Jelmer Vernooij
Print proper error about not supporting push. |
113 |
@staticmethod
|
114 |
def is_compatible(source, target): |
|
115 |
"""Be compatible with GitRepository.""" |
|
116 |
return (not isinstance(source, GitRepository) and |
|
117 |
isinstance(target, GitRepository)) |