bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
|
0.200.206
by Jelmer Vernooij
Move commands to a separate python module and register them lazily. |
1 |
# Copyright (C) 2006-2009 Canonical Ltd
|
2 |
||
3 |
# Authors: Robert Collins <robert.collins@canonical.com>
|
|
4 |
# Jelmer Vernooij <jelmer@samba.org>
|
|
5 |
# John Carr <john.carr@unrouted.co.uk>
|
|
6 |
#
|
|
7 |
# This program is free software; you can redistribute it and/or modify
|
|
8 |
# it under the terms of the GNU General Public License as published by
|
|
9 |
# the Free Software Foundation; either version 2 of the License, or
|
|
10 |
# (at your option) any later version.
|
|
11 |
#
|
|
12 |
# This program is distributed in the hope that it will be useful,
|
|
13 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
14 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
15 |
# GNU General Public License for more details.
|
|
16 |
#
|
|
17 |
# You should have received a copy of the GNU General Public License
|
|
18 |
# along with this program; if not, write to the Free Software
|
|
19 |
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
20 |
||
21 |
"""Git-specific subcommands for Bazaar."""
|
|
22 |
||
|
0.200.292
by Jelmer Vernooij
Fix formatting. |
23 |
from bzrlib.commands import ( |
24 |
Command, |
|
|
0.200.423
by Jelmer Vernooij
Support pretty-printing git objects. |
25 |
display_command, |
|
0.200.292
by Jelmer Vernooij
Fix formatting. |
26 |
)
|
27 |
from bzrlib.option import ( |
|
28 |
Option, |
|
29 |
)
|
|
|
0.200.206
by Jelmer Vernooij
Move commands to a separate python module and register them lazily. |
30 |
|
|
0.228.1
by Jelmer Vernooij
Add basic tests for local fetch. |
31 |
|
|
0.200.206
by Jelmer Vernooij
Move commands to a separate python module and register them lazily. |
32 |
class cmd_git_import(Command): |
33 |
"""Import all branches from a git repository. |
|
34 |
||
35 |
"""
|
|
36 |
||
|
0.200.234
by Jelmer Vernooij
Derive to_location from from_location, simialr to bzr branch. |
37 |
takes_args = ["src_location", "dest_location?"] |
|
0.200.206
by Jelmer Vernooij
Move commands to a separate python module and register them lazily. |
38 |
|
|
0.200.1452
by Jelmer Vernooij
Support colocated branches in 'bzr git-import', flatten namespace. |
39 |
def _get_colocated_branch(self, target_bzrdir, name): |
40 |
from bzrlib.errors import NotBranchError |
|
41 |
try: |
|
42 |
return target_bzrdir.open_branch(name=name) |
|
43 |
except NotBranchError: |
|
44 |
return target_bzrdir.create_branch(name=name) |
|
45 |
||
46 |
def _get_nested_branch(self, dest_transport, dest_format, name): |
|
47 |
from bzrlib.bzrdir import BzrDir |
|
48 |
from bzrlib.errors import NotBranchError |
|
49 |
head_transport = dest_transport.clone(name) |
|
50 |
try: |
|
51 |
head_bzrdir = BzrDir.open_from_transport(head_transport) |
|
52 |
except NotBranchError: |
|
53 |
head_bzrdir = dest_format.initialize_on_transport_ex( |
|
54 |
head_transport, create_prefix=True)[1] |
|
55 |
try: |
|
56 |
return head_bzrdir.open_branch() |
|
57 |
except NotBranchError: |
|
58 |
return head_bzrdir.create_branch() |
|
59 |
||
|
0.200.234
by Jelmer Vernooij
Derive to_location from from_location, simialr to bzr branch. |
60 |
def run(self, src_location, dest_location=None): |
|
0.200.247
by Jelmer Vernooij
Fix git-import. |
61 |
import os |
|
0.200.1390
by Jelmer Vernooij
Set parent path in git-import. |
62 |
import urllib |
|
0.200.247
by Jelmer Vernooij
Fix git-import. |
63 |
from bzrlib import ( |
|
0.200.1141
by Jelmer Vernooij
Use transports in git-import. |
64 |
controldir, |
|
0.200.1143
by Jelmer Vernooij
Add note about creating working trees. |
65 |
trace, |
|
0.200.247
by Jelmer Vernooij
Fix git-import. |
66 |
ui, |
|
0.200.1390
by Jelmer Vernooij
Set parent path in git-import. |
67 |
urlutils, |
|
0.200.247
by Jelmer Vernooij
Fix git-import. |
68 |
)
|
69 |
from bzrlib.bzrdir import ( |
|
70 |
BzrDir, |
|
71 |
)
|
|
|
0.200.243
by Jelmer Vernooij
Error out on non-git repositories. |
72 |
from bzrlib.errors import ( |
73 |
BzrCommandError, |
|
74 |
NoRepositoryPresent, |
|
75 |
NotBranchError, |
|
76 |
)
|
|
|
0.200.1470
by Jelmer Vernooij
Import gettext from plugin. |
77 |
from bzrlib.plugins.git import gettext |
|
0.200.306
by Jelmer Vernooij
Fix tests, split up InterGitNonGitRepository. |
78 |
from bzrlib.repository import ( |
79 |
InterRepository, |
|
80 |
Repository, |
|
81 |
)
|
|
|
0.200.1141
by Jelmer Vernooij
Use transports in git-import. |
82 |
from bzrlib.transport import get_transport |
|
0.239.1
by Jelmer Vernooij
Avoid re-connecting to fetch tags we already know. |
83 |
from bzrlib.plugins.git.branch import ( |
84 |
GitBranch, |
|
|
0.200.1487
by Jelmer Vernooij
Use peeling. |
85 |
)
|
86 |
from bzrlib.plugins.git.refs import ( |
|
87 |
ref_to_branch_name, |
|
88 |
)
|
|
|
0.200.243
by Jelmer Vernooij
Error out on non-git repositories. |
89 |
from bzrlib.plugins.git.repository import GitRepository |
|
0.200.234
by Jelmer Vernooij
Derive to_location from from_location, simialr to bzr branch. |
90 |
|
|
0.200.1141
by Jelmer Vernooij
Use transports in git-import. |
91 |
dest_format = controldir.ControlDirFormat.get_default_format() |
92 |
||
|
0.200.234
by Jelmer Vernooij
Derive to_location from from_location, simialr to bzr branch. |
93 |
if dest_location is None: |
94 |
dest_location = os.path.basename(src_location.rstrip("/\\")) |
|
95 |
||
|
0.200.1141
by Jelmer Vernooij
Use transports in git-import. |
96 |
dest_transport = get_transport(dest_location) |
97 |
||
|
0.200.206
by Jelmer Vernooij
Move commands to a separate python module and register them lazily. |
98 |
source_repo = Repository.open(src_location) |
|
0.200.243
by Jelmer Vernooij
Error out on non-git repositories. |
99 |
if not isinstance(source_repo, GitRepository): |
|
0.200.1483
by Jelmer Vernooij
Translate more strings. |
100 |
raise BzrCommandError(gettext("%r is not a git repository") % src_location) |
|
0.200.206
by Jelmer Vernooij
Move commands to a separate python module and register them lazily. |
101 |
try: |
|
0.200.1141
by Jelmer Vernooij
Use transports in git-import. |
102 |
target_bzrdir = BzrDir.open_from_transport(dest_transport) |
|
0.200.206
by Jelmer Vernooij
Move commands to a separate python module and register them lazily. |
103 |
except NotBranchError: |
|
0.200.1141
by Jelmer Vernooij
Use transports in git-import. |
104 |
target_bzrdir = dest_format.initialize_on_transport_ex( |
|
0.200.1142
by Jelmer Vernooij
Fix use of initialize_on_transport_ex. |
105 |
dest_transport, shared_repo=True)[1] |
|
0.200.206
by Jelmer Vernooij
Move commands to a separate python module and register them lazily. |
106 |
try: |
|
0.200.612
by Jelmer Vernooij
Cope with Dulwich returning KeyError when a commit is not found. |
107 |
target_repo = target_bzrdir.find_repository() |
|
0.200.206
by Jelmer Vernooij
Move commands to a separate python module and register them lazily. |
108 |
except NoRepositoryPresent: |
109 |
target_repo = target_bzrdir.create_repository(shared=True) |
|
110 |
||
|
0.200.569
by Jelmer Vernooij
Check for rich root target repository. |
111 |
if not target_repo.supports_rich_root(): |
|
0.200.1483
by Jelmer Vernooij
Translate more strings. |
112 |
raise BzrCommandError(gettext("Target repository doesn't support rich roots")) |
|
0.200.569
by Jelmer Vernooij
Check for rich root target repository. |
113 |
|
|
0.200.306
by Jelmer Vernooij
Fix tests, split up InterGitNonGitRepository. |
114 |
interrepo = InterRepository.get(source_repo, target_repo) |
|
0.200.247
by Jelmer Vernooij
Fix git-import. |
115 |
mapping = source_repo.get_mapping() |
|
0.200.1002
by Jelmer Vernooij
Fix regression in git-import. |
116 |
refs = interrepo.fetch() |
|
0.200.1487
by Jelmer Vernooij
Use peeling. |
117 |
refs_dict = refs.as_dict() |
|
0.200.247
by Jelmer Vernooij
Fix git-import. |
118 |
pb = ui.ui_factory.nested_progress_bar() |
119 |
try: |
|
|
0.200.1487
by Jelmer Vernooij
Use peeling. |
120 |
for i, (name, sha) in enumerate(refs_dict.iteritems()): |
|
0.200.1055
by Jelmer Vernooij
Cope with unknown refs. |
121 |
try: |
|
0.200.1452
by Jelmer Vernooij
Support colocated branches in 'bzr git-import', flatten namespace. |
122 |
branch_name = ref_to_branch_name(name) |
|
0.200.1055
by Jelmer Vernooij
Cope with unknown refs. |
123 |
except ValueError: |
124 |
# Not a branch, ignore
|
|
|
0.200.271
by Jelmer Vernooij
Stop importing tags as branches as part of git-import. |
125 |
continue
|
|
0.200.1487
by Jelmer Vernooij
Use peeling. |
126 |
pb.update(gettext("creating branches"), i, len(refs_dict)) |
|
0.200.1455
by Jelmer Vernooij
Cope with .colocated_branches not being available. |
127 |
if getattr(target_bzrdir._format, "colocated_branches", False): |
|
0.200.1452
by Jelmer Vernooij
Support colocated branches in 'bzr git-import', flatten namespace. |
128 |
if name == "HEAD": |
129 |
branch_name = None |
|
130 |
head_branch = self._get_colocated_branch(target_bzrdir, branch_name) |
|
131 |
else: |
|
132 |
head_branch = self._get_nested_branch(dest_transport, dest_format, branch_name) |
|
|
0.200.1487
by Jelmer Vernooij
Use peeling. |
133 |
revid = mapping.revision_id_foreign_to_bzr(sha) |
|
0.200.695
by Jelmer Vernooij
Clean up trailing whitespace. |
134 |
source_branch = GitBranch(source_repo.bzrdir, source_repo, |
|
0.200.1487
by Jelmer Vernooij
Use peeling. |
135 |
sha) |
136 |
source_branch.head = sha |
|
|
0.239.1
by Jelmer Vernooij
Avoid re-connecting to fetch tags we already know. |
137 |
if head_branch.last_revision() != revid: |
138 |
head_branch.generate_revision_history(revid) |
|
|
0.200.273
by Jelmer Vernooij
Fix import of tags in git-import. |
139 |
source_branch.tags.merge_to(head_branch.tags) |
|
0.200.1390
by Jelmer Vernooij
Set parent path in git-import. |
140 |
if not head_branch.get_parent(): |
|
0.200.1452
by Jelmer Vernooij
Support colocated branches in 'bzr git-import', flatten namespace. |
141 |
url = urlutils.join_segment_parameters( |
142 |
source_branch.base, {"ref": urllib.quote(name, '')}) |
|
|
0.200.1390
by Jelmer Vernooij
Set parent path in git-import. |
143 |
head_branch.set_parent(url) |
|
0.200.247
by Jelmer Vernooij
Fix git-import. |
144 |
finally: |
145 |
pb.finished() |
|
|
0.200.1469
by Jelmer Vernooij
Add more strings. |
146 |
trace.note(gettext( |
147 |
"Use 'bzr checkout' to create a working tree in "
|
|
148 |
"the newly created branches.")) |
|
|
0.200.1143
by Jelmer Vernooij
Add note about creating working trees. |
149 |
|
|
0.200.206
by Jelmer Vernooij
Move commands to a separate python module and register them lazily. |
150 |
|
|
0.200.422
by Jelmer Vernooij
'bzr git-object' without arguments now prints the available git objects. |
151 |
class cmd_git_object(Command): |
152 |
"""List or display Git objects by SHA. |
|
|
0.200.695
by Jelmer Vernooij
Clean up trailing whitespace. |
153 |
|
|
0.200.422
by Jelmer Vernooij
'bzr git-object' without arguments now prints the available git objects. |
154 |
Cat a particular object's Git representation if a SHA is specified.
|
155 |
List all available SHAs otherwise.
|
|
156 |
"""
|
|
|
0.200.419
by Jelmer Vernooij
Add hidden git-cat command that can cat git objects from Bazaar repositories. |
157 |
|
158 |
hidden = True |
|
159 |
||
|
0.200.422
by Jelmer Vernooij
'bzr git-object' without arguments now prints the available git objects. |
160 |
aliases = ["git-objects", "git-cat"] |
161 |
takes_args = ["sha1?"] |
|
|
0.200.695
by Jelmer Vernooij
Clean up trailing whitespace. |
162 |
takes_options = [Option('directory', |
|
0.200.440
by Jelmer Vernooij
Remove silly mapping of timezones; dulwich uses offsets now as well. |
163 |
short_name='d', |
|
0.200.424
by Jelmer Vernooij
Fix formatting. |
164 |
help='Location of repository.', type=unicode), |
165 |
Option('pretty', help='Pretty-print objects.')] |
|
|
0.200.423
by Jelmer Vernooij
Support pretty-printing git objects. |
166 |
encoding_type = 'exact' |
|
0.200.419
by Jelmer Vernooij
Add hidden git-cat command that can cat git objects from Bazaar repositories. |
167 |
|
|
0.200.423
by Jelmer Vernooij
Support pretty-printing git objects. |
168 |
@display_command
|
169 |
def run(self, sha1=None, directory=".", pretty=False): |
|
|
0.200.419
by Jelmer Vernooij
Add hidden git-cat command that can cat git objects from Bazaar repositories. |
170 |
from bzrlib.errors import ( |
171 |
BzrCommandError, |
|
172 |
)
|
|
173 |
from bzrlib.bzrdir import ( |
|
174 |
BzrDir, |
|
175 |
)
|
|
|
0.200.1484
by Jelmer Vernooij
Fix import. |
176 |
from bzrlib.plugins.git.object_store import ( |
177 |
get_object_store, |
|
178 |
)
|
|
179 |
from bzrlib.plugins.git import gettext |
|
|
0.200.419
by Jelmer Vernooij
Add hidden git-cat command that can cat git objects from Bazaar repositories. |
180 |
bzrdir, _ = BzrDir.open_containing(directory) |
181 |
repo = bzrdir.find_repository() |
|
|
0.200.452
by Jelmer Vernooij
Rename converter -> object_store, provide utility function for getting ObjectStore's. |
182 |
object_store = get_object_store(repo) |
|
0.200.1212
by Jelmer Vernooij
Support read locking object stores. |
183 |
object_store.lock_read() |
|
0.200.419
by Jelmer Vernooij
Add hidden git-cat command that can cat git objects from Bazaar repositories. |
184 |
try: |
|
0.200.422
by Jelmer Vernooij
'bzr git-object' without arguments now prints the available git objects. |
185 |
if sha1 is not None: |
186 |
try: |
|
|
0.200.532
by Jelmer Vernooij
The object store requires plain strings. |
187 |
obj = object_store[str(sha1)] |
|
0.200.422
by Jelmer Vernooij
'bzr git-object' without arguments now prints the available git objects. |
188 |
except KeyError: |
|
0.200.1483
by Jelmer Vernooij
Translate more strings. |
189 |
raise BzrCommandError(gettext("Object not found: %s") % sha1) |
|
0.200.423
by Jelmer Vernooij
Support pretty-printing git objects. |
190 |
if pretty: |
191 |
text = obj.as_pretty_string() |
|
192 |
else: |
|
193 |
text = obj.as_raw_string() |
|
194 |
self.outf.write(text) |
|
|
0.200.419
by Jelmer Vernooij
Add hidden git-cat command that can cat git objects from Bazaar repositories. |
195 |
else: |
|
0.200.422
by Jelmer Vernooij
'bzr git-object' without arguments now prints the available git objects. |
196 |
for sha1 in object_store: |
197 |
self.outf.write("%s\n" % sha1) |
|
|
0.200.419
by Jelmer Vernooij
Add hidden git-cat command that can cat git objects from Bazaar repositories. |
198 |
finally: |
|
0.200.1212
by Jelmer Vernooij
Support read locking object stores. |
199 |
object_store.unlock() |
|
0.200.873
by Jelmer Vernooij
Add convenience command for accessing virtual git refs. |
200 |
|
201 |
||
202 |
class cmd_git_refs(Command): |
|
203 |
"""Output all of the virtual refs for a repository. |
|
204 |
||
205 |
"""
|
|
206 |
||
207 |
hidden = True |
|
208 |
||
209 |
takes_options = [Option('directory', |
|
210 |
short_name='d', |
|
211 |
help='Location of repository.', type=unicode)] |
|
212 |
||
213 |
@display_command
|
|
214 |
def run(self, directory="."): |
|
215 |
from bzrlib.bzrdir import ( |
|
216 |
BzrDir, |
|
217 |
)
|
|
218 |
from bzrlib.plugins.git.refs import ( |
|
|
0.200.1487
by Jelmer Vernooij
Use peeling. |
219 |
get_refs_container, |
|
0.200.873
by Jelmer Vernooij
Add convenience command for accessing virtual git refs. |
220 |
)
|
221 |
from bzrlib.plugins.git.object_store import ( |
|
222 |
get_object_store, |
|
223 |
)
|
|
224 |
bzrdir, _ = BzrDir.open_containing(directory) |
|
225 |
repo = bzrdir.find_repository() |
|
|
0.200.1212
by Jelmer Vernooij
Support read locking object stores. |
226 |
object_store = get_object_store(repo) |
227 |
object_store.lock_read() |
|
|
0.200.873
by Jelmer Vernooij
Add convenience command for accessing virtual git refs. |
228 |
try: |
|
0.200.1487
by Jelmer Vernooij
Use peeling. |
229 |
refs = get_refs_container(bzrdir) |
230 |
for k, v in refs.as_dict().iteritems(): |
|
|
0.200.873
by Jelmer Vernooij
Add convenience command for accessing virtual git refs. |
231 |
self.outf.write("%s -> %s\n" % (k, v)) |
232 |
finally: |
|
|
0.200.1212
by Jelmer Vernooij
Support read locking object stores. |
233 |
object_store.unlock() |
|
0.200.895
by Jelmer Vernooij
Add initial work on git-apply. |
234 |
|
235 |
||
236 |
class cmd_git_apply(Command): |
|
237 |
"""Apply a series of git-am style patches. |
|
238 |
||
239 |
This command will in the future probably be integrated into
|
|
240 |
"bzr pull".
|
|
241 |
"""
|
|
242 |
||
|
0.200.1050
by Jelmer Vernooij
Add --force option to 'bzr git-apply'. |
243 |
takes_options = [ |
244 |
Option('signoff', short_name='s', help='Add a Signed-off-by line.'), |
|
|
0.272.1
by Martin Packman
Add help for git-apply --force option |
245 |
Option('force', |
246 |
help='Apply patches even if tree has uncommitted changes.') |
|
247 |
]
|
|
|
0.200.895
by Jelmer Vernooij
Add initial work on git-apply. |
248 |
takes_args = ["patches*"] |
249 |
||
|
0.200.1049
by Jelmer Vernooij
Add --signoff option to 'bzr git-apply'. |
250 |
def _apply_patch(self, wt, f, signoff): |
251 |
"""Apply a patch. |
|
252 |
||
253 |
:param wt: A Bazaar working tree object.
|
|
254 |
:param f: Patch file to read.
|
|
255 |
:param signoff: Add Signed-Off-By flag.
|
|
256 |
"""
|
|
|
0.200.1043
by Jelmer Vernooij
Finish git-apply command. |
257 |
from bzrlib.errors import BzrCommandError |
|
0.200.895
by Jelmer Vernooij
Add initial work on git-apply. |
258 |
from dulwich.patch import git_am_patch_split |
|
0.200.1043
by Jelmer Vernooij
Finish git-apply command. |
259 |
import subprocess |
|
0.200.895
by Jelmer Vernooij
Add initial work on git-apply. |
260 |
(c, diff, version) = git_am_patch_split(f) |
|
0.200.1043
by Jelmer Vernooij
Finish git-apply command. |
261 |
# FIXME: Cope with git-specific bits in patch
|
|
0.200.1298
by Jelmer Vernooij
Fix compatibility with newer versions of dulwich. |
262 |
# FIXME: Add new files to working tree
|
263 |
p = subprocess.Popen(["patch", "-p1"], stdin=subprocess.PIPE, |
|
264 |
cwd=wt.basedir) |
|
|
0.200.1043
by Jelmer Vernooij
Finish git-apply command. |
265 |
p.communicate(diff) |
266 |
exitcode = p.wait() |
|
267 |
if exitcode != 0: |
|
|
0.200.1483
by Jelmer Vernooij
Translate more strings. |
268 |
raise BzrCommandError(gettext("error running patch")) |
|
0.200.1049
by Jelmer Vernooij
Add --signoff option to 'bzr git-apply'. |
269 |
message = c.message |
270 |
if signoff: |
|
271 |
signed_off_by = wt.branch.get_config().username() |
|
272 |
message += "Signed-off-by: %s\n" % signed_off_by.encode('utf-8') |
|
273 |
wt.commit(authors=[c.author], message=message) |
|
|
0.200.895
by Jelmer Vernooij
Add initial work on git-apply. |
274 |
|
|
0.200.1050
by Jelmer Vernooij
Add --force option to 'bzr git-apply'. |
275 |
def run(self, patches_list=None, signoff=False, force=False): |
|
0.200.1040
by Jelmer Vernooij
Error out about applying to a tree with changes. |
276 |
from bzrlib.errors import UncommittedChanges |
|
0.200.895
by Jelmer Vernooij
Add initial work on git-apply. |
277 |
from bzrlib.workingtree import WorkingTree |
278 |
if patches_list is None: |
|
279 |
patches_list = [] |
|
|
0.200.1040
by Jelmer Vernooij
Error out about applying to a tree with changes. |
280 |
|
|
0.200.895
by Jelmer Vernooij
Add initial work on git-apply. |
281 |
tree, _ = WorkingTree.open_containing(".") |
|
0.200.1050
by Jelmer Vernooij
Add --force option to 'bzr git-apply'. |
282 |
if tree.basis_tree().changes_from(tree).has_changed() and not force: |
|
0.200.1040
by Jelmer Vernooij
Error out about applying to a tree with changes. |
283 |
raise UncommittedChanges(tree) |
|
0.200.895
by Jelmer Vernooij
Add initial work on git-apply. |
284 |
tree.lock_write() |
285 |
try: |
|
286 |
for patch in patches_list: |
|
287 |
f = open(patch, 'r') |
|
288 |
try: |
|
|
0.200.1049
by Jelmer Vernooij
Add --signoff option to 'bzr git-apply'. |
289 |
self._apply_patch(tree, f, signoff=signoff) |
|
0.200.895
by Jelmer Vernooij
Add initial work on git-apply. |
290 |
finally: |
291 |
f.close() |
|
292 |
finally: |
|
293 |
tree.unlock() |