bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
|
0.436.115
by Jelmer Vernooij
Register commands lazily, use bzrlib,api to check bzr versions. |
1 |
# Copyright (C) 2007 by Jelmer Vernooij <jelmer@samba.org>
|
|
0.436.177
by Jelmer Vernooij
Remove trailing whitespace. |
2 |
#
|
|
0.436.115
by Jelmer Vernooij
Register commands lazily, use bzrlib,api to check bzr versions. |
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
|
|
|
0.436.131
by Jelmer Vernooij
Change license back to GPLv2+ |
5 |
# the Free Software Foundation; either version 2 of the License, or
|
|
0.436.115
by Jelmer Vernooij
Register commands lazily, use bzrlib,api to check bzr versions. |
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 |
"""Bazaar command-line subcommands."""
|
|
18 |
||
|
7406.3.2
by Jelmer Vernooij
Update for breezy. |
19 |
from ...commands import ( |
|
0.436.143
by Jelmer Vernooij
Remove unnecessary imports. |
20 |
Command, |
21 |
display_command, |
|
22 |
)
|
|
|
7406.3.2
by Jelmer Vernooij
Update for breezy. |
23 |
from ...errors import ( |
|
0.436.143
by Jelmer Vernooij
Remove unnecessary imports. |
24 |
BzrCommandError, |
25 |
ConflictsInTree, |
|
26 |
NoSuchFile, |
|
27 |
NoWorkingTree, |
|
28 |
UncommittedChanges, |
|
29 |
)
|
|
|
7406.3.2
by Jelmer Vernooij
Update for breezy. |
30 |
from ...option import ( |
|
0.436.143
by Jelmer Vernooij
Remove unnecessary imports. |
31 |
Option, |
32 |
)
|
|
|
7406.3.2
by Jelmer Vernooij
Update for breezy. |
33 |
from ...trace import ( |
|
0.436.167
by Jelmer Vernooij
Use trace.note rather than trace.info. |
34 |
note, |
|
0.436.143
by Jelmer Vernooij
Remove unnecessary imports. |
35 |
)
|
|
0.436.115
by Jelmer Vernooij
Register commands lazily, use bzrlib,api to check bzr versions. |
36 |
|
|
7406.3.2
by Jelmer Vernooij
Update for breezy. |
37 |
from ...i18n import gettext |
|
0.449.1
by Jonathan Riddell
add gettext to strings |
38 |
|
39 |
||
|
0.436.248
by Jelmer Vernooij
Use feature flags. |
40 |
def finish_rebase(state, wt, replace_map, replayer): |
|
7406.3.2
by Jelmer Vernooij
Update for breezy. |
41 |
from .rebase import ( |
|
0.436.248
by Jelmer Vernooij
Use feature flags. |
42 |
rebase, |
43 |
)
|
|
44 |
try: |
|
45 |
# Start executing plan from current Branch.last_revision()
|
|
46 |
rebase(wt.branch.repository, replace_map, replayer) |
|
47 |
except ConflictsInTree: |
|
|
7406.3.5
by Jelmer Vernooij
Fix formatting. |
48 |
raise BzrCommandError(gettext( |
49 |
"A conflict occurred replaying a commit."
|
|
|
7406.3.3
by Jelmer Vernooij
Fix python3 compatibility. |
50 |
" Resolve the conflict and run 'brz rebase-continue' or "
|
51 |
"run 'brz rebase-abort'.")) |
|
|
0.436.248
by Jelmer Vernooij
Use feature flags. |
52 |
# Remove plan file
|
53 |
state.remove_plan() |
|
54 |
||
55 |
||
|
0.436.115
by Jelmer Vernooij
Register commands lazily, use bzrlib,api to check bzr versions. |
56 |
class cmd_rebase(Command): |
57 |
"""Re-base a branch. |
|
58 |
||
59 |
Rebasing is the process of taking a branch and modifying the history so
|
|
60 |
that it appears to start from a different point. This can be useful
|
|
61 |
to clean up the history before submitting your changes. The tree at the
|
|
62 |
end of the process will be the same as if you had merged the other branch,
|
|
63 |
but the history will be different.
|
|
64 |
||
65 |
The command takes the location of another branch on to which the branch in
|
|
|
7406.3.5
by Jelmer Vernooij
Fix formatting. |
66 |
the specified directory (by default, the current working directory)
|
67 |
will be rebased. If a branch is not specified then the parent branch
|
|
|
0.436.213
by Levi Bard
Allow branch to operate on to be specified explicitly. |
68 |
is used, and this is usually the desired result.
|
|
0.436.115
by Jelmer Vernooij
Register commands lazily, use bzrlib,api to check bzr versions. |
69 |
|
70 |
The first step identifies the revisions that are in the current branch that
|
|
71 |
are not in the parent branch. The current branch is then set to be at the
|
|
72 |
same revision as the target branch, and each revision is replayed on top
|
|
73 |
of the branch. At the end of the process it will appear as though your
|
|
74 |
current branch was branched off the current last revision of the target.
|
|
75 |
||
76 |
Each revision that is replayed may cause conflicts in the tree. If this
|
|
77 |
happens the command will stop and allow you to fix them up. Resolve the
|
|
|
7406.3.3
by Jelmer Vernooij
Fix python3 compatibility. |
78 |
commits as you would for a merge, and then run 'brz resolve' to marked
|
|
0.436.115
by Jelmer Vernooij
Register commands lazily, use bzrlib,api to check bzr versions. |
79 |
them as resolved. Once you have resolved all the conflicts you should
|
|
7406.3.3
by Jelmer Vernooij
Fix python3 compatibility. |
80 |
run 'brz rebase-continue' to continue the rebase operation.
|
|
0.436.115
by Jelmer Vernooij
Register commands lazily, use bzrlib,api to check bzr versions. |
81 |
|
82 |
If conflicts are encountered and you decide that you do not wish to continue
|
|
|
7406.3.3
by Jelmer Vernooij
Fix python3 compatibility. |
83 |
you can run 'brz rebase-abort'.
|
|
0.436.115
by Jelmer Vernooij
Register commands lazily, use bzrlib,api to check bzr versions. |
84 |
|
85 |
The '--onto' option allows you to specify a different revision in the
|
|
86 |
target branch to start at when replaying the revisions. This means that
|
|
87 |
you can change the point at which the current branch will appear to be
|
|
88 |
branched from when the operation completes.
|
|
89 |
"""
|
|
90 |
takes_args = ['upstream_location?'] |
|
|
7406.3.5
by Jelmer Vernooij
Fix formatting. |
91 |
takes_options = [ |
92 |
'revision', 'merge-type', 'verbose', |
|
93 |
Option( |
|
94 |
'dry-run', |
|
|
0.436.115
by Jelmer Vernooij
Register commands lazily, use bzrlib,api to check bzr versions. |
95 |
help="Show what would be done, but don't actually do anything."), |
|
7406.3.5
by Jelmer Vernooij
Fix formatting. |
96 |
Option( |
97 |
'always-rebase-merges', |
|
|
0.436.115
by Jelmer Vernooij
Register commands lazily, use bzrlib,api to check bzr versions. |
98 |
help="Don't skip revisions that merge already present revisions."), |
|
7406.3.5
by Jelmer Vernooij
Fix formatting. |
99 |
Option( |
100 |
'pending-merges', |
|
|
0.436.115
by Jelmer Vernooij
Register commands lazily, use bzrlib,api to check bzr versions. |
101 |
help="Rebase pending merges onto local branch."), |
|
7406.3.5
by Jelmer Vernooij
Fix formatting. |
102 |
Option( |
103 |
'onto', help='Different revision to replay onto.', |
|
|
0.436.213
by Levi Bard
Allow branch to operate on to be specified explicitly. |
104 |
type=str), |
|
7406.3.5
by Jelmer Vernooij
Fix formatting. |
105 |
Option( |
106 |
'directory', |
|
|
0.436.213
by Levi Bard
Allow branch to operate on to be specified explicitly. |
107 |
short_name='d', |
108 |
help="Branch to replay onto, rather than the one containing the working directory.", |
|
|
7406.3.5
by Jelmer Vernooij
Fix formatting. |
109 |
type=str) |
|
0.436.213
by Levi Bard
Allow branch to operate on to be specified explicitly. |
110 |
]
|
|
0.436.177
by Jelmer Vernooij
Remove trailing whitespace. |
111 |
|
|
0.436.115
by Jelmer Vernooij
Register commands lazily, use bzrlib,api to check bzr versions. |
112 |
@display_command
|
113 |
def run(self, upstream_location=None, onto=None, revision=None, |
|
114 |
merge_type=None, verbose=False, dry_run=False, |
|
|
0.436.213
by Levi Bard
Allow branch to operate on to be specified explicitly. |
115 |
always_rebase_merges=False, pending_merges=False, |
116 |
directory="."): |
|
|
7406.3.2
by Jelmer Vernooij
Update for breezy. |
117 |
from ...branch import Branch |
118 |
from ...revisionspec import RevisionSpec |
|
119 |
from ...workingtree import WorkingTree |
|
120 |
from .rebase import ( |
|
|
0.436.157
by Jelmer Vernooij
use absolute imports everywhere. |
121 |
generate_simple_plan, |
122 |
rebase, |
|
|
0.436.192
by Jelmer Vernooij
Avoid reopening state when possible, allow subclasses. |
123 |
RebaseState1, |
|
0.436.203
by Jelmer Vernooij
Use camelcasing for class names. |
124 |
WorkingTreeRevisionRewriter, |
|
0.436.157
by Jelmer Vernooij
use absolute imports everywhere. |
125 |
regenerate_default_revid, |
126 |
rebase_todo, |
|
127 |
)
|
|
|
0.436.115
by Jelmer Vernooij
Register commands lazily, use bzrlib,api to check bzr versions. |
128 |
if revision is not None and pending_merges: |
|
0.449.4
by Jonathan Riddell
more gettext()ing |
129 |
raise BzrCommandError(gettext( |
130 |
"--revision and --pending-merges are mutually exclusive")) |
|
|
0.436.115
by Jelmer Vernooij
Register commands lazily, use bzrlib,api to check bzr versions. |
131 |
|
|
0.436.213
by Levi Bard
Allow branch to operate on to be specified explicitly. |
132 |
wt = WorkingTree.open_containing(directory)[0] |
|
0.436.115
by Jelmer Vernooij
Register commands lazily, use bzrlib,api to check bzr versions. |
133 |
wt.lock_write() |
134 |
try: |
|
|
0.436.216
by Jelmer Vernooij
Unlock working tree properly on all errors. |
135 |
state = RebaseState1(wt) |
136 |
if upstream_location is None: |
|
137 |
if pending_merges: |
|
138 |
upstream_location = directory |
|
139 |
else: |
|
140 |
upstream_location = wt.branch.get_parent() |
|
141 |
if upstream_location is None: |
|
|
0.449.4
by Jonathan Riddell
more gettext()ing |
142 |
raise BzrCommandError(gettext("No upstream branch specified.")) |
|
0.449.1
by Jonathan Riddell
add gettext to strings |
143 |
note(gettext("Rebasing on %s"), upstream_location) |
|
0.436.216
by Jelmer Vernooij
Unlock working tree properly on all errors. |
144 |
upstream = Branch.open_containing(upstream_location)[0] |
145 |
upstream_repository = upstream.repository |
|
146 |
upstream_revision = upstream.last_revision() |
|
|
0.436.115
by Jelmer Vernooij
Register commands lazily, use bzrlib,api to check bzr versions. |
147 |
# Abort if there already is a plan file
|
|
0.436.191
by Jelmer Vernooij
Move rebase state to a separate object. |
148 |
if state.has_plan(): |
|
7406.3.5
by Jelmer Vernooij
Fix formatting. |
149 |
raise BzrCommandError(gettext( |
150 |
"A rebase operation was interrupted. "
|
|
|
7406.3.3
by Jelmer Vernooij
Fix python3 compatibility. |
151 |
"Continue using 'brz rebase-continue' or abort using 'brz "
|
|
0.449.4
by Jonathan Riddell
more gettext()ing |
152 |
"rebase-abort'")) |
|
0.436.115
by Jelmer Vernooij
Register commands lazily, use bzrlib,api to check bzr versions. |
153 |
|
154 |
start_revid = None |
|
155 |
stop_revid = None |
|
156 |
if revision is not None: |
|
157 |
if len(revision) == 1: |
|
158 |
if revision[0] is not None: |
|
159 |
stop_revid = revision[0].as_revision_id(wt.branch) |
|
160 |
elif len(revision) == 2: |
|
161 |
if revision[0] is not None: |
|
162 |
start_revid = revision[0].as_revision_id(wt.branch) |
|
163 |
if revision[1] is not None: |
|
164 |
stop_revid = revision[1].as_revision_id(wt.branch) |
|
165 |
else: |
|
|
0.449.4
by Jonathan Riddell
more gettext()ing |
166 |
raise BzrCommandError(gettext( |
167 |
"--revision takes only one or two arguments")) |
|
|
0.436.115
by Jelmer Vernooij
Register commands lazily, use bzrlib,api to check bzr versions. |
168 |
|
169 |
if pending_merges: |
|
170 |
wt_parents = wt.get_parent_ids() |
|
171 |
if len(wt_parents) in (0, 1): |
|
|
0.449.4
by Jonathan Riddell
more gettext()ing |
172 |
raise BzrCommandError(gettext("No pending merges present.")) |
|
0.436.115
by Jelmer Vernooij
Register commands lazily, use bzrlib,api to check bzr versions. |
173 |
elif len(wt_parents) > 2: |
|
0.449.4
by Jonathan Riddell
more gettext()ing |
174 |
raise BzrCommandError(gettext( |
175 |
"Rebasing more than one pending merge not supported")) |
|
|
0.436.115
by Jelmer Vernooij
Register commands lazily, use bzrlib,api to check bzr versions. |
176 |
stop_revid = wt_parents[1] |
177 |
assert stop_revid is not None, "stop revid invalid" |
|
178 |
||
|
0.436.219
by Jelmer Vernooij
Warn about uncommitted changes before downloading history. |
179 |
# Check for changes in the working tree.
|
180 |
if (not pending_merges and |
|
|
7406.3.5
by Jelmer Vernooij
Fix formatting. |
181 |
wt.basis_tree().changes_from(wt).has_changed()): |
|
0.436.219
by Jelmer Vernooij
Warn about uncommitted changes before downloading history. |
182 |
raise UncommittedChanges(wt) |
183 |
||
|
0.436.115
by Jelmer Vernooij
Register commands lazily, use bzrlib,api to check bzr versions. |
184 |
# Pull required revisions
|
185 |
wt.branch.repository.fetch(upstream_repository, upstream_revision) |
|
186 |
if onto is None: |
|
187 |
onto = upstream.last_revision() |
|
188 |
else: |
|
189 |
rev_spec = RevisionSpec.from_string(onto) |
|
190 |
onto = rev_spec.as_revision_id(upstream) |
|
191 |
||
|
7406.3.3
by Jelmer Vernooij
Fix python3 compatibility. |
192 |
wt.branch.repository.fetch(upstream_repository, revision_id=onto) |
|
0.436.115
by Jelmer Vernooij
Register commands lazily, use bzrlib,api to check bzr versions. |
193 |
|
194 |
if stop_revid is None: |
|
195 |
stop_revid = wt.branch.last_revision() |
|
196 |
repo_graph = wt.branch.repository.get_graph() |
|
197 |
our_new, onto_unique = repo_graph.find_difference(stop_revid, onto) |
|
198 |
||
199 |
if start_revid is None: |
|
200 |
if not onto_unique: |
|
|
0.449.4
by Jonathan Riddell
more gettext()ing |
201 |
self.outf.write(gettext("No revisions to rebase.\n")) |
|
0.436.115
by Jelmer Vernooij
Register commands lazily, use bzrlib,api to check bzr versions. |
202 |
return
|
203 |
if not our_new: |
|
|
7406.3.5
by Jelmer Vernooij
Fix formatting. |
204 |
self.outf.write(gettext( |
205 |
"Base branch is descendant of current "
|
|
|
0.449.4
by Jonathan Riddell
more gettext()ing |
206 |
"branch. Pulling instead.\n")) |
|
0.436.212
by Jelmer Vernooij
Don't do pulls either when running with dry-run. |
207 |
if not dry_run: |
|
7406.3.3
by Jelmer Vernooij
Fix python3 compatibility. |
208 |
wt.pull(upstream, stop_revision=onto) |
|
0.436.115
by Jelmer Vernooij
Register commands lazily, use bzrlib,api to check bzr versions. |
209 |
return
|
210 |
# else: include extra revisions needed to make start_revid mean
|
|
211 |
# something.
|
|
212 |
||
213 |
# Create plan
|
|
214 |
replace_map = generate_simple_plan( |
|
|
7406.3.5
by Jelmer Vernooij
Fix formatting. |
215 |
our_new, start_revid, stop_revid, onto, repo_graph, |
216 |
lambda revid, ps: regenerate_default_revid( |
|
217 |
wt.branch.repository, revid), |
|
218 |
not always_rebase_merges) |
|
|
0.436.115
by Jelmer Vernooij
Register commands lazily, use bzrlib,api to check bzr versions. |
219 |
|
|
0.436.211
by Jelmer Vernooij
Fix typo. |
220 |
if verbose or dry_run: |
|
0.436.115
by Jelmer Vernooij
Register commands lazily, use bzrlib,api to check bzr versions. |
221 |
todo = list(rebase_todo(wt.branch.repository, replace_map)) |
|
0.449.1
by Jonathan Riddell
add gettext to strings |
222 |
note(gettext('%d revisions will be rebased:') % len(todo)) |
|
0.436.115
by Jelmer Vernooij
Register commands lazily, use bzrlib,api to check bzr versions. |
223 |
for revid in todo: |
|
0.436.167
by Jelmer Vernooij
Use trace.note rather than trace.info. |
224 |
note("%s" % revid) |
|
0.436.115
by Jelmer Vernooij
Register commands lazily, use bzrlib,api to check bzr versions. |
225 |
|
226 |
if not dry_run: |
|
227 |
# Write plan file
|
|
|
0.436.191
by Jelmer Vernooij
Move rebase state to a separate object. |
228 |
state.write_plan(replace_map) |
|
0.436.115
by Jelmer Vernooij
Register commands lazily, use bzrlib,api to check bzr versions. |
229 |
|
|
0.436.248
by Jelmer Vernooij
Use feature flags. |
230 |
replayer = WorkingTreeRevisionRewriter(wt, state, merge_type=merge_type) |
231 |
||
232 |
finish_rebase(state, wt, replace_map, replayer) |
|
|
0.436.115
by Jelmer Vernooij
Register commands lazily, use bzrlib,api to check bzr versions. |
233 |
finally: |
234 |
wt.unlock() |
|
235 |
||
236 |
||
237 |
class cmd_rebase_abort(Command): |
|
238 |
"""Abort an interrupted rebase.""" |
|
|
0.436.177
by Jelmer Vernooij
Remove trailing whitespace. |
239 |
|
|
7406.3.5
by Jelmer Vernooij
Fix formatting. |
240 |
takes_options = [ |
241 |
Option( |
|
242 |
'directory', |
|
|
0.436.213
by Levi Bard
Allow branch to operate on to be specified explicitly. |
243 |
short_name='d', |
244 |
help="Branch to replay onto, rather than the one containing the working directory.", |
|
245 |
type=str)] |
|
246 |
||
|
0.436.115
by Jelmer Vernooij
Register commands lazily, use bzrlib,api to check bzr versions. |
247 |
@display_command
|
|
0.436.213
by Levi Bard
Allow branch to operate on to be specified explicitly. |
248 |
def run(self, directory="."): |
|
7406.3.2
by Jelmer Vernooij
Update for breezy. |
249 |
from .rebase import ( |
|
0.436.192
by Jelmer Vernooij
Avoid reopening state when possible, allow subclasses. |
250 |
RebaseState1, |
|
0.436.157
by Jelmer Vernooij
use absolute imports everywhere. |
251 |
complete_revert, |
252 |
)
|
|
|
7406.3.2
by Jelmer Vernooij
Update for breezy. |
253 |
from ...workingtree import WorkingTree |
|
0.436.213
by Levi Bard
Allow branch to operate on to be specified explicitly. |
254 |
wt = WorkingTree.open_containing(directory)[0] |
|
0.436.115
by Jelmer Vernooij
Register commands lazily, use bzrlib,api to check bzr versions. |
255 |
wt.lock_write() |
256 |
try: |
|
|
0.436.216
by Jelmer Vernooij
Unlock working tree properly on all errors. |
257 |
state = RebaseState1(wt) |
|
0.436.115
by Jelmer Vernooij
Register commands lazily, use bzrlib,api to check bzr versions. |
258 |
# Read plan file and set last revision
|
259 |
try: |
|
|
0.436.191
by Jelmer Vernooij
Move rebase state to a separate object. |
260 |
last_rev_info = state.read_plan()[0] |
|
0.436.115
by Jelmer Vernooij
Register commands lazily, use bzrlib,api to check bzr versions. |
261 |
except NoSuchFile: |
262 |
raise BzrCommandError("No rebase to abort") |
|
263 |
complete_revert(wt, [last_rev_info[1]]) |
|
|
0.436.191
by Jelmer Vernooij
Move rebase state to a separate object. |
264 |
state.remove_plan() |
|
0.436.115
by Jelmer Vernooij
Register commands lazily, use bzrlib,api to check bzr versions. |
265 |
finally: |
266 |
wt.unlock() |
|
267 |
||
268 |
||
269 |
class cmd_rebase_continue(Command): |
|
270 |
"""Continue an interrupted rebase after resolving conflicts.""" |
|
|
7406.3.5
by Jelmer Vernooij
Fix formatting. |
271 |
takes_options = [ |
272 |
'merge-type', Option( |
|
273 |
'directory', |
|
|
0.436.213
by Levi Bard
Allow branch to operate on to be specified explicitly. |
274 |
short_name='d', |
275 |
help="Branch to replay onto, rather than the one containing the working directory.", |
|
276 |
type=str)] |
|
|
0.436.177
by Jelmer Vernooij
Remove trailing whitespace. |
277 |
|
|
0.436.115
by Jelmer Vernooij
Register commands lazily, use bzrlib,api to check bzr versions. |
278 |
@display_command
|
|
0.436.213
by Levi Bard
Allow branch to operate on to be specified explicitly. |
279 |
def run(self, merge_type=None, directory="."): |
|
7406.3.2
by Jelmer Vernooij
Update for breezy. |
280 |
from .rebase import ( |
|
0.436.192
by Jelmer Vernooij
Avoid reopening state when possible, allow subclasses. |
281 |
RebaseState1, |
|
0.436.203
by Jelmer Vernooij
Use camelcasing for class names. |
282 |
WorkingTreeRevisionRewriter, |
|
0.436.157
by Jelmer Vernooij
use absolute imports everywhere. |
283 |
)
|
|
7406.3.2
by Jelmer Vernooij
Update for breezy. |
284 |
from ...workingtree import WorkingTree |
|
0.436.213
by Levi Bard
Allow branch to operate on to be specified explicitly. |
285 |
wt = WorkingTree.open_containing(directory)[0] |
|
0.436.115
by Jelmer Vernooij
Register commands lazily, use bzrlib,api to check bzr versions. |
286 |
wt.lock_write() |
287 |
try: |
|
|
0.436.192
by Jelmer Vernooij
Avoid reopening state when possible, allow subclasses. |
288 |
state = RebaseState1(wt) |
|
0.436.203
by Jelmer Vernooij
Use camelcasing for class names. |
289 |
replayer = WorkingTreeRevisionRewriter(wt, state, merge_type=merge_type) |
|
0.436.115
by Jelmer Vernooij
Register commands lazily, use bzrlib,api to check bzr versions. |
290 |
# Abort if there are any conflicts
|
291 |
if len(wt.conflicts()) != 0: |
|
|
7406.3.5
by Jelmer Vernooij
Fix formatting. |
292 |
raise BzrCommandError(gettext( |
293 |
"There are still conflicts present. "
|
|
294 |
"Resolve the conflicts and then run "
|
|
295 |
"'brz resolve' and try again.")) |
|
|
0.436.115
by Jelmer Vernooij
Register commands lazily, use bzrlib,api to check bzr versions. |
296 |
# Read plan file
|
297 |
try: |
|
|
0.436.191
by Jelmer Vernooij
Move rebase state to a separate object. |
298 |
replace_map = state.read_plan()[1] |
|
0.436.115
by Jelmer Vernooij
Register commands lazily, use bzrlib,api to check bzr versions. |
299 |
except NoSuchFile: |
|
0.449.4
by Jonathan Riddell
more gettext()ing |
300 |
raise BzrCommandError(gettext("No rebase to continue")) |
|
0.436.191
by Jelmer Vernooij
Move rebase state to a separate object. |
301 |
oldrevid = state.read_active_revid() |
|
0.436.115
by Jelmer Vernooij
Register commands lazily, use bzrlib,api to check bzr versions. |
302 |
if oldrevid is not None: |
303 |
oldrev = wt.branch.repository.get_revision(oldrevid) |
|
|
0.436.200
by Jelmer Vernooij
Move in commit_rebase. |
304 |
replayer.commit_rebase(oldrev, replace_map[oldrevid][0]) |
|
0.436.248
by Jelmer Vernooij
Use feature flags. |
305 |
finish_rebase(state, wt, replace_map, replayer) |
|
0.436.115
by Jelmer Vernooij
Register commands lazily, use bzrlib,api to check bzr versions. |
306 |
finally: |
307 |
wt.unlock() |
|
308 |
||
309 |
||
310 |
class cmd_rebase_todo(Command): |
|
|
0.436.177
by Jelmer Vernooij
Remove trailing whitespace. |
311 |
"""Print list of revisions that still need to be replayed as part of the |
|
0.436.115
by Jelmer Vernooij
Register commands lazily, use bzrlib,api to check bzr versions. |
312 |
current rebase operation.
|
313 |
||
314 |
"""
|
|
|
0.436.177
by Jelmer Vernooij
Remove trailing whitespace. |
315 |
|
|
7406.3.5
by Jelmer Vernooij
Fix formatting. |
316 |
takes_options = [ |
317 |
Option( |
|
318 |
'directory', |
|
|
0.436.213
by Levi Bard
Allow branch to operate on to be specified explicitly. |
319 |
short_name='d', |
320 |
help="Branch to replay onto, rather than the one containing the working directory.", |
|
321 |
type=str)] |
|
322 |
||
323 |
def run(self, directory="."): |
|
|
7406.3.2
by Jelmer Vernooij
Update for breezy. |
324 |
from .rebase import ( |
|
0.436.192
by Jelmer Vernooij
Avoid reopening state when possible, allow subclasses. |
325 |
RebaseState1, |
|
0.436.157
by Jelmer Vernooij
use absolute imports everywhere. |
326 |
rebase_todo, |
327 |
)
|
|
|
7406.3.2
by Jelmer Vernooij
Update for breezy. |
328 |
from ...workingtree import WorkingTree |
|
0.436.213
by Levi Bard
Allow branch to operate on to be specified explicitly. |
329 |
wt = WorkingTree.open_containing(directory)[0] |
|
7406.3.5
by Jelmer Vernooij
Fix formatting. |
330 |
with wt.lock_read(): |
|
0.436.192
by Jelmer Vernooij
Avoid reopening state when possible, allow subclasses. |
331 |
state = RebaseState1(wt) |
|
0.436.115
by Jelmer Vernooij
Register commands lazily, use bzrlib,api to check bzr versions. |
332 |
try: |
|
0.436.191
by Jelmer Vernooij
Move rebase state to a separate object. |
333 |
replace_map = state.read_plan()[1] |
|
0.436.115
by Jelmer Vernooij
Register commands lazily, use bzrlib,api to check bzr versions. |
334 |
except NoSuchFile: |
|
0.449.4
by Jonathan Riddell
more gettext()ing |
335 |
raise BzrCommandError(gettext("No rebase in progress")) |
|
0.436.191
by Jelmer Vernooij
Move rebase state to a separate object. |
336 |
currentrevid = state.read_active_revid() |
|
0.436.115
by Jelmer Vernooij
Register commands lazily, use bzrlib,api to check bzr versions. |
337 |
if currentrevid is not None: |
|
0.449.1
by Jonathan Riddell
add gettext to strings |
338 |
note(gettext("Currently replaying: %s") % currentrevid) |
|
0.436.115
by Jelmer Vernooij
Register commands lazily, use bzrlib,api to check bzr versions. |
339 |
for revid in rebase_todo(wt.branch.repository, replace_map): |
|
0.449.1
by Jonathan Riddell
add gettext to strings |
340 |
note(gettext("{0} -> {1}").format(revid, replace_map[revid][0])) |
|
0.436.115
by Jelmer Vernooij
Register commands lazily, use bzrlib,api to check bzr versions. |
341 |
|
342 |
||
343 |
class cmd_replay(Command): |
|
344 |
"""Replay commits from another branch on top of this one. |
|
345 |
||
346 |
"""
|
|
|
0.436.177
by Jelmer Vernooij
Remove trailing whitespace. |
347 |
|
|
7406.3.5
by Jelmer Vernooij
Fix formatting. |
348 |
takes_options = [ |
349 |
'revision', 'merge-type', |
|
350 |
Option( |
|
351 |
'directory', |
|
|
0.436.213
by Levi Bard
Allow branch to operate on to be specified explicitly. |
352 |
short_name='d', |
353 |
help="Branch to replay onto, rather than the one containing the working directory.", |
|
354 |
type=str)] |
|
|
0.436.115
by Jelmer Vernooij
Register commands lazily, use bzrlib,api to check bzr versions. |
355 |
takes_args = ['location'] |
356 |
hidden = True |
|
357 |
||
|
0.436.213
by Levi Bard
Allow branch to operate on to be specified explicitly. |
358 |
def run(self, location, revision=None, merge_type=None, directory="."): |
|
7406.3.2
by Jelmer Vernooij
Update for breezy. |
359 |
from ...branch import Branch |
360 |
from ...workingtree import WorkingTree |
|
361 |
from ... import ui |
|
362 |
from .rebase import ( |
|
|
0.436.192
by Jelmer Vernooij
Avoid reopening state when possible, allow subclasses. |
363 |
RebaseState1, |
|
0.436.157
by Jelmer Vernooij
use absolute imports everywhere. |
364 |
regenerate_default_revid, |
|
0.436.203
by Jelmer Vernooij
Use camelcasing for class names. |
365 |
WorkingTreeRevisionRewriter, |
|
0.436.157
by Jelmer Vernooij
use absolute imports everywhere. |
366 |
)
|
|
0.436.115
by Jelmer Vernooij
Register commands lazily, use bzrlib,api to check bzr versions. |
367 |
|
368 |
from_branch = Branch.open_containing(location)[0] |
|
369 |
||
370 |
if revision is not None: |
|
371 |
if len(revision) == 1: |
|
372 |
if revision[0] is not None: |
|
373 |
todo = [revision[0].as_revision_id(from_branch)] |
|
374 |
elif len(revision) == 2: |
|
375 |
from_revno, from_revid = revision[0].in_history(from_branch) |
|
376 |
to_revno, to_revid = revision[1].in_history(from_branch) |
|
377 |
if to_revid is None: |
|
378 |
to_revno = from_branch.revno() |
|
379 |
todo = [] |
|
380 |
for revno in range(from_revno, to_revno + 1): |
|
381 |
todo.append(from_branch.get_rev_id(revno)) |
|
382 |
else: |
|
|
0.449.4
by Jonathan Riddell
more gettext()ing |
383 |
raise BzrCommandError(gettext( |
384 |
"--revision takes only one or two arguments")) |
|
|
0.436.115
by Jelmer Vernooij
Register commands lazily, use bzrlib,api to check bzr versions. |
385 |
else: |
|
0.449.4
by Jonathan Riddell
more gettext()ing |
386 |
raise BzrCommandError(gettext("--revision is mandatory")) |
|
0.436.115
by Jelmer Vernooij
Register commands lazily, use bzrlib,api to check bzr versions. |
387 |
|
|
0.436.213
by Levi Bard
Allow branch to operate on to be specified explicitly. |
388 |
wt = WorkingTree.open(directory) |
|
0.436.115
by Jelmer Vernooij
Register commands lazily, use bzrlib,api to check bzr versions. |
389 |
wt.lock_write() |
390 |
try: |
|
|
0.436.216
by Jelmer Vernooij
Unlock working tree properly on all errors. |
391 |
state = RebaseState1(wt) |
392 |
replayer = WorkingTreeRevisionRewriter(wt, state, merge_type=merge_type) |
|
393 |
pb = ui.ui_factory.nested_progress_bar() |
|
394 |
try: |
|
395 |
for revid in todo: |
|
|
0.449.4
by Jonathan Riddell
more gettext()ing |
396 |
pb.update(gettext("replaying commits"), todo.index(revid), len(todo)) |
|
0.436.216
by Jelmer Vernooij
Unlock working tree properly on all errors. |
397 |
wt.branch.repository.fetch(from_branch.repository, revid) |
398 |
newrevid = regenerate_default_revid(wt.branch.repository, revid) |
|
399 |
replayer(revid, newrevid, [wt.last_revision()]) |
|
400 |
finally: |
|
401 |
pb.finished() |
|
|
0.436.115
by Jelmer Vernooij
Register commands lazily, use bzrlib,api to check bzr versions. |
402 |
finally: |
403 |
wt.unlock() |
|
|
0.436.139
by Jelmer Vernooij
Import foreign-mapping-upgrade. |
404 |
|
405 |
||
|
0.436.169
by Jelmer Vernooij
Add 'pseudonyms' command. |
406 |
class cmd_pseudonyms(Command): |
407 |
"""Show a list of 'pseudonym' revisions. |
|
408 |
||
|
0.436.177
by Jelmer Vernooij
Remove trailing whitespace. |
409 |
Pseudonym revisions are revisions that are roughly the same revision,
|
410 |
usually because they were converted from the same revision in a
|
|
|
0.436.169
by Jelmer Vernooij
Add 'pseudonyms' command. |
411 |
foreign version control system.
|
412 |
"""
|
|
413 |
||
414 |
takes_args = ['repository?'] |
|
415 |
hidden = True |
|
416 |
||
417 |
def run(self, repository=None): |
|
|
7406.3.2
by Jelmer Vernooij
Update for breezy. |
418 |
from ...controldir import ControlDir |
419 |
dir, _ = ControlDir.open_containing(repository) |
|
|
0.436.172
by Jelmer Vernooij
Split up code for generating rebase map. |
420 |
r = dir.find_repository() |
|
7406.3.2
by Jelmer Vernooij
Update for breezy. |
421 |
from .pseudonyms import find_pseudonyms |
|
0.436.169
by Jelmer Vernooij
Add 'pseudonyms' command. |
422 |
for pseudonyms in find_pseudonyms(r, r.all_revision_ids()): |
423 |
self.outf.write(", ".join(pseudonyms) + "\n") |
|
|
0.436.173
by Jelmer Vernooij
Add rebase-foreign command. |
424 |
|
425 |
||
426 |
class cmd_rebase_foreign(Command): |
|
427 |
"""Rebase revisions based on a branch created with a different import tool. |
|
|
0.436.177
by Jelmer Vernooij
Remove trailing whitespace. |
428 |
|
429 |
This will change the identity of revisions whose parents
|
|
|
0.436.173
by Jelmer Vernooij
Add rebase-foreign command. |
430 |
were mapped from revisions in the other version control system.
|
431 |
||
|
7406.3.3
by Jelmer Vernooij
Fix python3 compatibility. |
432 |
You are recommended to run "brz check" in the local repository
|
|
0.436.173
by Jelmer Vernooij
Add rebase-foreign command. |
433 |
after running this command.
|
434 |
"""
|
|
435 |
takes_args = ['new_base?'] |
|
|
7406.3.5
by Jelmer Vernooij
Fix formatting. |
436 |
takes_options = [ |
437 |
'verbose', |
|
|
0.436.177
by Jelmer Vernooij
Remove trailing whitespace. |
438 |
Option("idmap-file", help="Write map with old and new revision ids.", |
|
0.436.213
by Levi Bard
Allow branch to operate on to be specified explicitly. |
439 |
type=str), |
|
7406.3.5
by Jelmer Vernooij
Fix formatting. |
440 |
Option( |
441 |
'directory', |
|
|
0.436.213
by Levi Bard
Allow branch to operate on to be specified explicitly. |
442 |
short_name='d', |
443 |
help="Branch to replay onto, rather than the one containing the working directory.", |
|
444 |
type=str) |
|
445 |
]
|
|
|
0.436.173
by Jelmer Vernooij
Add rebase-foreign command. |
446 |
|
|
0.436.213
by Levi Bard
Allow branch to operate on to be specified explicitly. |
447 |
def run(self, new_base=None, verbose=False, idmap_file=None, directory="."): |
|
7406.3.2
by Jelmer Vernooij
Update for breezy. |
448 |
from ... import ( |
|
0.436.173
by Jelmer Vernooij
Add rebase-foreign command. |
449 |
urlutils, |
450 |
)
|
|
|
7406.3.2
by Jelmer Vernooij
Update for breezy. |
451 |
from ...branch import Branch |
452 |
from ...workingtree import WorkingTree |
|
453 |
from .pseudonyms import ( |
|
|
0.436.173
by Jelmer Vernooij
Add rebase-foreign command. |
454 |
find_pseudonyms, |
455 |
generate_rebase_map_from_pseudonyms, |
|
456 |
pseudonyms_as_dict, |
|
457 |
)
|
|
|
7406.3.2
by Jelmer Vernooij
Update for breezy. |
458 |
from .upgrade import ( |
|
0.436.173
by Jelmer Vernooij
Add rebase-foreign command. |
459 |
create_deterministic_revid, |
460 |
upgrade_branch, |
|
|
0.436.196
by Jelmer Vernooij
Eliminate unnecessary function. |
461 |
)
|
|
7406.3.2
by Jelmer Vernooij
Update for breezy. |
462 |
from ...foreign import ( |
|
0.436.196
by Jelmer Vernooij
Eliminate unnecessary function. |
463 |
update_workingtree_fileids, |
464 |
)
|
|
465 |
||
|
0.436.173
by Jelmer Vernooij
Add rebase-foreign command. |
466 |
try: |
|
0.436.213
by Levi Bard
Allow branch to operate on to be specified explicitly. |
467 |
wt_to = WorkingTree.open(directory) |
|
0.436.173
by Jelmer Vernooij
Add rebase-foreign command. |
468 |
branch_to = wt_to.branch |
469 |
except NoWorkingTree: |
|
470 |
wt_to = None |
|
|
0.436.213
by Levi Bard
Allow branch to operate on to be specified explicitly. |
471 |
branch_to = Branch.open(directory) |
|
0.436.173
by Jelmer Vernooij
Add rebase-foreign command. |
472 |
|
473 |
stored_loc = branch_to.get_parent() |
|
474 |
if new_base is None: |
|
475 |
if stored_loc is None: |
|
|
7406.3.5
by Jelmer Vernooij
Fix formatting. |
476 |
raise BzrCommandError(gettext( |
477 |
"No pull location known or specified.")) |
|
|
0.436.173
by Jelmer Vernooij
Add rebase-foreign command. |
478 |
else: |
|
7406.3.5
by Jelmer Vernooij
Fix formatting. |
479 |
display_url = urlutils.unescape_for_display( |
480 |
stored_loc, self.outf.encoding) |
|
|
0.449.4
by Jonathan Riddell
more gettext()ing |
481 |
self.outf.write(gettext("Using saved location: %s\n") % display_url) |
|
0.436.211
by Jelmer Vernooij
Fix typo. |
482 |
new_base = Branch.open(stored_loc) |
|
0.436.173
by Jelmer Vernooij
Add rebase-foreign command. |
483 |
else: |
484 |
new_base = Branch.open(new_base) |
|
485 |
||
|
7406.3.5
by Jelmer Vernooij
Fix formatting. |
486 |
branch_to.repository.fetch( |
487 |
new_base.repository, revision_id=branch_to.last_revision()) |
|
|
0.436.177
by Jelmer Vernooij
Remove trailing whitespace. |
488 |
|
|
7406.3.5
by Jelmer Vernooij
Fix formatting. |
489 |
pseudonyms = pseudonyms_as_dict(find_pseudonyms( |
490 |
branch_to.repository, branch_to.repository.all_revision_ids())) |
|
|
0.436.173
by Jelmer Vernooij
Add rebase-foreign command. |
491 |
|
492 |
def generate_rebase_map(revision_id): |
|
|
7406.3.5
by Jelmer Vernooij
Fix formatting. |
493 |
return generate_rebase_map_from_pseudonyms( |
494 |
pseudonyms, branch_to.repository.get_ancestry(revision_id), |
|
|
0.436.173
by Jelmer Vernooij
Add rebase-foreign command. |
495 |
branch_to.repository.get_ancestry(new_base.last_revision())) |
496 |
def determine_new_revid(old_revid, new_parents): |
|
497 |
return create_deterministic_revid(old_revid, new_parents) |
|
498 |
branch_to.lock_write() |
|
499 |
try: |
|
500 |
graph = branch_to.repository.get_graph() |
|
|
7406.3.5
by Jelmer Vernooij
Fix formatting. |
501 |
renames = upgrade_branch( |
502 |
branch_to, generate_rebase_map, |
|
503 |
determine_new_revid, allow_changes=True, |
|
504 |
verbose=verbose) |
|
|
0.436.173
by Jelmer Vernooij
Add rebase-foreign command. |
505 |
if wt_to is not None: |
|
0.445.1
by Colin Watson
Get read lock on target basis tree around update_workingtree_fileids. |
506 |
basis_tree = wt_to.basis_tree() |
507 |
basis_tree.lock_read() |
|
508 |
try: |
|
509 |
update_workingtree_fileids(wt_to, basis_tree) |
|
510 |
finally: |
|
511 |
basis_tree.unlock() |
|
|
0.436.173
by Jelmer Vernooij
Add rebase-foreign command. |
512 |
finally: |
513 |
branch_to.unlock() |
|
514 |
||
515 |
if renames == {}: |
|
|
0.449.1
by Jonathan Riddell
add gettext to strings |
516 |
note(gettext("Nothing to do.")) |
|
0.436.173
by Jelmer Vernooij
Add rebase-foreign command. |
517 |
|
518 |
if idmap_file is not None: |
|
519 |
f = open(idmap_file, 'w') |
|
520 |
try: |
|
521 |
for oldid, newid in renames.iteritems(): |
|
522 |
f.write("%s\t%s\n" % (oldid, newid)) |
|
523 |
finally: |
|
524 |
f.close() |
|
525 |
||
526 |
if wt_to is not None: |
|
527 |
wt_to.set_last_revision(branch_to.last_revision()) |