##// END OF EJS Templates
histedit: refuse to edit history that contains merges (issue3962)
Augie Fackler -
r19473:10a0ae66 stable
parent child Browse files
Show More
@@ -1,872 +1,874 b''
1 # histedit.py - interactive history editing for mercurial
1 # histedit.py - interactive history editing for mercurial
2 #
2 #
3 # Copyright 2009 Augie Fackler <raf@durin42.com>
3 # Copyright 2009 Augie Fackler <raf@durin42.com>
4 #
4 #
5 # This software may be used and distributed according to the terms of the
5 # This software may be used and distributed according to the terms of the
6 # GNU General Public License version 2 or any later version.
6 # GNU General Public License version 2 or any later version.
7 """interactive history editing
7 """interactive history editing
8
8
9 With this extension installed, Mercurial gains one new command: histedit. Usage
9 With this extension installed, Mercurial gains one new command: histedit. Usage
10 is as follows, assuming the following history::
10 is as follows, assuming the following history::
11
11
12 @ 3[tip] 7c2fd3b9020c 2009-04-27 18:04 -0500 durin42
12 @ 3[tip] 7c2fd3b9020c 2009-04-27 18:04 -0500 durin42
13 | Add delta
13 | Add delta
14 |
14 |
15 o 2 030b686bedc4 2009-04-27 18:04 -0500 durin42
15 o 2 030b686bedc4 2009-04-27 18:04 -0500 durin42
16 | Add gamma
16 | Add gamma
17 |
17 |
18 o 1 c561b4e977df 2009-04-27 18:04 -0500 durin42
18 o 1 c561b4e977df 2009-04-27 18:04 -0500 durin42
19 | Add beta
19 | Add beta
20 |
20 |
21 o 0 d8d2fcd0e319 2009-04-27 18:04 -0500 durin42
21 o 0 d8d2fcd0e319 2009-04-27 18:04 -0500 durin42
22 Add alpha
22 Add alpha
23
23
24 If you were to run ``hg histedit c561b4e977df``, you would see the following
24 If you were to run ``hg histedit c561b4e977df``, you would see the following
25 file open in your editor::
25 file open in your editor::
26
26
27 pick c561b4e977df Add beta
27 pick c561b4e977df Add beta
28 pick 030b686bedc4 Add gamma
28 pick 030b686bedc4 Add gamma
29 pick 7c2fd3b9020c Add delta
29 pick 7c2fd3b9020c Add delta
30
30
31 # Edit history between c561b4e977df and 7c2fd3b9020c
31 # Edit history between c561b4e977df and 7c2fd3b9020c
32 #
32 #
33 # Commands:
33 # Commands:
34 # p, pick = use commit
34 # p, pick = use commit
35 # e, edit = use commit, but stop for amending
35 # e, edit = use commit, but stop for amending
36 # f, fold = use commit, but fold into previous commit (combines N and N-1)
36 # f, fold = use commit, but fold into previous commit (combines N and N-1)
37 # d, drop = remove commit from history
37 # d, drop = remove commit from history
38 # m, mess = edit message without changing commit content
38 # m, mess = edit message without changing commit content
39 #
39 #
40
40
41 In this file, lines beginning with ``#`` are ignored. You must specify a rule
41 In this file, lines beginning with ``#`` are ignored. You must specify a rule
42 for each revision in your history. For example, if you had meant to add gamma
42 for each revision in your history. For example, if you had meant to add gamma
43 before beta, and then wanted to add delta in the same revision as beta, you
43 before beta, and then wanted to add delta in the same revision as beta, you
44 would reorganize the file to look like this::
44 would reorganize the file to look like this::
45
45
46 pick 030b686bedc4 Add gamma
46 pick 030b686bedc4 Add gamma
47 pick c561b4e977df Add beta
47 pick c561b4e977df Add beta
48 fold 7c2fd3b9020c Add delta
48 fold 7c2fd3b9020c Add delta
49
49
50 # Edit history between c561b4e977df and 7c2fd3b9020c
50 # Edit history between c561b4e977df and 7c2fd3b9020c
51 #
51 #
52 # Commands:
52 # Commands:
53 # p, pick = use commit
53 # p, pick = use commit
54 # e, edit = use commit, but stop for amending
54 # e, edit = use commit, but stop for amending
55 # f, fold = use commit, but fold into previous commit (combines N and N-1)
55 # f, fold = use commit, but fold into previous commit (combines N and N-1)
56 # d, drop = remove commit from history
56 # d, drop = remove commit from history
57 # m, mess = edit message without changing commit content
57 # m, mess = edit message without changing commit content
58 #
58 #
59
59
60 At which point you close the editor and ``histedit`` starts working. When you
60 At which point you close the editor and ``histedit`` starts working. When you
61 specify a ``fold`` operation, ``histedit`` will open an editor when it folds
61 specify a ``fold`` operation, ``histedit`` will open an editor when it folds
62 those revisions together, offering you a chance to clean up the commit message::
62 those revisions together, offering you a chance to clean up the commit message::
63
63
64 Add beta
64 Add beta
65 ***
65 ***
66 Add delta
66 Add delta
67
67
68 Edit the commit message to your liking, then close the editor. For
68 Edit the commit message to your liking, then close the editor. For
69 this example, let's assume that the commit message was changed to
69 this example, let's assume that the commit message was changed to
70 ``Add beta and delta.`` After histedit has run and had a chance to
70 ``Add beta and delta.`` After histedit has run and had a chance to
71 remove any old or temporary revisions it needed, the history looks
71 remove any old or temporary revisions it needed, the history looks
72 like this::
72 like this::
73
73
74 @ 2[tip] 989b4d060121 2009-04-27 18:04 -0500 durin42
74 @ 2[tip] 989b4d060121 2009-04-27 18:04 -0500 durin42
75 | Add beta and delta.
75 | Add beta and delta.
76 |
76 |
77 o 1 081603921c3f 2009-04-27 18:04 -0500 durin42
77 o 1 081603921c3f 2009-04-27 18:04 -0500 durin42
78 | Add gamma
78 | Add gamma
79 |
79 |
80 o 0 d8d2fcd0e319 2009-04-27 18:04 -0500 durin42
80 o 0 d8d2fcd0e319 2009-04-27 18:04 -0500 durin42
81 Add alpha
81 Add alpha
82
82
83 Note that ``histedit`` does *not* remove any revisions (even its own temporary
83 Note that ``histedit`` does *not* remove any revisions (even its own temporary
84 ones) until after it has completed all the editing operations, so it will
84 ones) until after it has completed all the editing operations, so it will
85 probably perform several strip operations when it's done. For the above example,
85 probably perform several strip operations when it's done. For the above example,
86 it had to run strip twice. Strip can be slow depending on a variety of factors,
86 it had to run strip twice. Strip can be slow depending on a variety of factors,
87 so you might need to be a little patient. You can choose to keep the original
87 so you might need to be a little patient. You can choose to keep the original
88 revisions by passing the ``--keep`` flag.
88 revisions by passing the ``--keep`` flag.
89
89
90 The ``edit`` operation will drop you back to a command prompt,
90 The ``edit`` operation will drop you back to a command prompt,
91 allowing you to edit files freely, or even use ``hg record`` to commit
91 allowing you to edit files freely, or even use ``hg record`` to commit
92 some changes as a separate commit. When you're done, any remaining
92 some changes as a separate commit. When you're done, any remaining
93 uncommitted changes will be committed as well. When done, run ``hg
93 uncommitted changes will be committed as well. When done, run ``hg
94 histedit --continue`` to finish this step. You'll be prompted for a
94 histedit --continue`` to finish this step. You'll be prompted for a
95 new commit message, but the default commit message will be the
95 new commit message, but the default commit message will be the
96 original message for the ``edit`` ed revision.
96 original message for the ``edit`` ed revision.
97
97
98 The ``message`` operation will give you a chance to revise a commit
98 The ``message`` operation will give you a chance to revise a commit
99 message without changing the contents. It's a shortcut for doing
99 message without changing the contents. It's a shortcut for doing
100 ``edit`` immediately followed by `hg histedit --continue``.
100 ``edit`` immediately followed by `hg histedit --continue``.
101
101
102 If ``histedit`` encounters a conflict when moving a revision (while
102 If ``histedit`` encounters a conflict when moving a revision (while
103 handling ``pick`` or ``fold``), it'll stop in a similar manner to
103 handling ``pick`` or ``fold``), it'll stop in a similar manner to
104 ``edit`` with the difference that it won't prompt you for a commit
104 ``edit`` with the difference that it won't prompt you for a commit
105 message when done. If you decide at this point that you don't like how
105 message when done. If you decide at this point that you don't like how
106 much work it will be to rearrange history, or that you made a mistake,
106 much work it will be to rearrange history, or that you made a mistake,
107 you can use ``hg histedit --abort`` to abandon the new changes you
107 you can use ``hg histedit --abort`` to abandon the new changes you
108 have made and return to the state before you attempted to edit your
108 have made and return to the state before you attempted to edit your
109 history.
109 history.
110
110
111 If we clone the histedit-ed example repository above and add four more
111 If we clone the histedit-ed example repository above and add four more
112 changes, such that we have the following history::
112 changes, such that we have the following history::
113
113
114 @ 6[tip] 038383181893 2009-04-27 18:04 -0500 stefan
114 @ 6[tip] 038383181893 2009-04-27 18:04 -0500 stefan
115 | Add theta
115 | Add theta
116 |
116 |
117 o 5 140988835471 2009-04-27 18:04 -0500 stefan
117 o 5 140988835471 2009-04-27 18:04 -0500 stefan
118 | Add eta
118 | Add eta
119 |
119 |
120 o 4 122930637314 2009-04-27 18:04 -0500 stefan
120 o 4 122930637314 2009-04-27 18:04 -0500 stefan
121 | Add zeta
121 | Add zeta
122 |
122 |
123 o 3 836302820282 2009-04-27 18:04 -0500 stefan
123 o 3 836302820282 2009-04-27 18:04 -0500 stefan
124 | Add epsilon
124 | Add epsilon
125 |
125 |
126 o 2 989b4d060121 2009-04-27 18:04 -0500 durin42
126 o 2 989b4d060121 2009-04-27 18:04 -0500 durin42
127 | Add beta and delta.
127 | Add beta and delta.
128 |
128 |
129 o 1 081603921c3f 2009-04-27 18:04 -0500 durin42
129 o 1 081603921c3f 2009-04-27 18:04 -0500 durin42
130 | Add gamma
130 | Add gamma
131 |
131 |
132 o 0 d8d2fcd0e319 2009-04-27 18:04 -0500 durin42
132 o 0 d8d2fcd0e319 2009-04-27 18:04 -0500 durin42
133 Add alpha
133 Add alpha
134
134
135 If you run ``hg histedit --outgoing`` on the clone then it is the same
135 If you run ``hg histedit --outgoing`` on the clone then it is the same
136 as running ``hg histedit 836302820282``. If you need plan to push to a
136 as running ``hg histedit 836302820282``. If you need plan to push to a
137 repository that Mercurial does not detect to be related to the source
137 repository that Mercurial does not detect to be related to the source
138 repo, you can add a ``--force`` option.
138 repo, you can add a ``--force`` option.
139 """
139 """
140
140
141 try:
141 try:
142 import cPickle as pickle
142 import cPickle as pickle
143 pickle.dump # import now
143 pickle.dump # import now
144 except ImportError:
144 except ImportError:
145 import pickle
145 import pickle
146 import os
146 import os
147 import sys
147 import sys
148
148
149 from mercurial import cmdutil
149 from mercurial import cmdutil
150 from mercurial import discovery
150 from mercurial import discovery
151 from mercurial import error
151 from mercurial import error
152 from mercurial import copies
152 from mercurial import copies
153 from mercurial import context
153 from mercurial import context
154 from mercurial import hg
154 from mercurial import hg
155 from mercurial import lock as lockmod
155 from mercurial import lock as lockmod
156 from mercurial import node
156 from mercurial import node
157 from mercurial import repair
157 from mercurial import repair
158 from mercurial import scmutil
158 from mercurial import scmutil
159 from mercurial import util
159 from mercurial import util
160 from mercurial import obsolete
160 from mercurial import obsolete
161 from mercurial import merge as mergemod
161 from mercurial import merge as mergemod
162 from mercurial.i18n import _
162 from mercurial.i18n import _
163
163
164 cmdtable = {}
164 cmdtable = {}
165 command = cmdutil.command(cmdtable)
165 command = cmdutil.command(cmdtable)
166
166
167 testedwith = 'internal'
167 testedwith = 'internal'
168
168
169 # i18n: command names and abbreviations must remain untranslated
169 # i18n: command names and abbreviations must remain untranslated
170 editcomment = _("""# Edit history between %s and %s
170 editcomment = _("""# Edit history between %s and %s
171 #
171 #
172 # Commands:
172 # Commands:
173 # p, pick = use commit
173 # p, pick = use commit
174 # e, edit = use commit, but stop for amending
174 # e, edit = use commit, but stop for amending
175 # f, fold = use commit, but fold into previous commit (combines N and N-1)
175 # f, fold = use commit, but fold into previous commit (combines N and N-1)
176 # d, drop = remove commit from history
176 # d, drop = remove commit from history
177 # m, mess = edit message without changing commit content
177 # m, mess = edit message without changing commit content
178 #
178 #
179 """)
179 """)
180
180
181 def commitfuncfor(repo, src):
181 def commitfuncfor(repo, src):
182 """Build a commit function for the replacement of <src>
182 """Build a commit function for the replacement of <src>
183
183
184 This function ensure we apply the same treatment to all changesets.
184 This function ensure we apply the same treatment to all changesets.
185
185
186 - Add a 'histedit_source' entry in extra.
186 - Add a 'histedit_source' entry in extra.
187
187
188 Note that fold have its own separated logic because its handling is a bit
188 Note that fold have its own separated logic because its handling is a bit
189 different and not easily factored out of the fold method.
189 different and not easily factored out of the fold method.
190 """
190 """
191 phasemin = src.phase()
191 phasemin = src.phase()
192 def commitfunc(**kwargs):
192 def commitfunc(**kwargs):
193 phasebackup = repo.ui.backupconfig('phases', 'new-commit')
193 phasebackup = repo.ui.backupconfig('phases', 'new-commit')
194 try:
194 try:
195 repo.ui.setconfig('phases', 'new-commit', phasemin)
195 repo.ui.setconfig('phases', 'new-commit', phasemin)
196 extra = kwargs.get('extra', {}).copy()
196 extra = kwargs.get('extra', {}).copy()
197 extra['histedit_source'] = src.hex()
197 extra['histedit_source'] = src.hex()
198 kwargs['extra'] = extra
198 kwargs['extra'] = extra
199 return repo.commit(**kwargs)
199 return repo.commit(**kwargs)
200 finally:
200 finally:
201 repo.ui.restoreconfig(phasebackup)
201 repo.ui.restoreconfig(phasebackup)
202 return commitfunc
202 return commitfunc
203
203
204
204
205
205
206 def applychanges(ui, repo, ctx, opts):
206 def applychanges(ui, repo, ctx, opts):
207 """Merge changeset from ctx (only) in the current working directory"""
207 """Merge changeset from ctx (only) in the current working directory"""
208 wcpar = repo.dirstate.parents()[0]
208 wcpar = repo.dirstate.parents()[0]
209 if ctx.p1().node() == wcpar:
209 if ctx.p1().node() == wcpar:
210 # edition ar "in place" we do not need to make any merge,
210 # edition ar "in place" we do not need to make any merge,
211 # just applies changes on parent for edition
211 # just applies changes on parent for edition
212 cmdutil.revert(ui, repo, ctx, (wcpar, node.nullid), all=True)
212 cmdutil.revert(ui, repo, ctx, (wcpar, node.nullid), all=True)
213 stats = None
213 stats = None
214 else:
214 else:
215 try:
215 try:
216 # ui.forcemerge is an internal variable, do not document
216 # ui.forcemerge is an internal variable, do not document
217 repo.ui.setconfig('ui', 'forcemerge', opts.get('tool', ''))
217 repo.ui.setconfig('ui', 'forcemerge', opts.get('tool', ''))
218 stats = mergemod.update(repo, ctx.node(), True, True, False,
218 stats = mergemod.update(repo, ctx.node(), True, True, False,
219 ctx.p1().node())
219 ctx.p1().node())
220 finally:
220 finally:
221 repo.ui.setconfig('ui', 'forcemerge', '')
221 repo.ui.setconfig('ui', 'forcemerge', '')
222 repo.setparents(wcpar, node.nullid)
222 repo.setparents(wcpar, node.nullid)
223 repo.dirstate.write()
223 repo.dirstate.write()
224 # fix up dirstate for copies and renames
224 # fix up dirstate for copies and renames
225 cmdutil.duplicatecopies(repo, ctx.rev(), ctx.p1().rev())
225 cmdutil.duplicatecopies(repo, ctx.rev(), ctx.p1().rev())
226 return stats
226 return stats
227
227
228 def collapse(repo, first, last, commitopts):
228 def collapse(repo, first, last, commitopts):
229 """collapse the set of revisions from first to last as new one.
229 """collapse the set of revisions from first to last as new one.
230
230
231 Expected commit options are:
231 Expected commit options are:
232 - message
232 - message
233 - date
233 - date
234 - username
234 - username
235 Commit message is edited in all cases.
235 Commit message is edited in all cases.
236
236
237 This function works in memory."""
237 This function works in memory."""
238 ctxs = list(repo.set('%d::%d', first, last))
238 ctxs = list(repo.set('%d::%d', first, last))
239 if not ctxs:
239 if not ctxs:
240 return None
240 return None
241 base = first.parents()[0]
241 base = first.parents()[0]
242
242
243 # commit a new version of the old changeset, including the update
243 # commit a new version of the old changeset, including the update
244 # collect all files which might be affected
244 # collect all files which might be affected
245 files = set()
245 files = set()
246 for ctx in ctxs:
246 for ctx in ctxs:
247 files.update(ctx.files())
247 files.update(ctx.files())
248
248
249 # Recompute copies (avoid recording a -> b -> a)
249 # Recompute copies (avoid recording a -> b -> a)
250 copied = copies.pathcopies(base, last)
250 copied = copies.pathcopies(base, last)
251
251
252 # prune files which were reverted by the updates
252 # prune files which were reverted by the updates
253 def samefile(f):
253 def samefile(f):
254 if f in last.manifest():
254 if f in last.manifest():
255 a = last.filectx(f)
255 a = last.filectx(f)
256 if f in base.manifest():
256 if f in base.manifest():
257 b = base.filectx(f)
257 b = base.filectx(f)
258 return (a.data() == b.data()
258 return (a.data() == b.data()
259 and a.flags() == b.flags())
259 and a.flags() == b.flags())
260 else:
260 else:
261 return False
261 return False
262 else:
262 else:
263 return f not in base.manifest()
263 return f not in base.manifest()
264 files = [f for f in files if not samefile(f)]
264 files = [f for f in files if not samefile(f)]
265 # commit version of these files as defined by head
265 # commit version of these files as defined by head
266 headmf = last.manifest()
266 headmf = last.manifest()
267 def filectxfn(repo, ctx, path):
267 def filectxfn(repo, ctx, path):
268 if path in headmf:
268 if path in headmf:
269 fctx = last[path]
269 fctx = last[path]
270 flags = fctx.flags()
270 flags = fctx.flags()
271 mctx = context.memfilectx(fctx.path(), fctx.data(),
271 mctx = context.memfilectx(fctx.path(), fctx.data(),
272 islink='l' in flags,
272 islink='l' in flags,
273 isexec='x' in flags,
273 isexec='x' in flags,
274 copied=copied.get(path))
274 copied=copied.get(path))
275 return mctx
275 return mctx
276 raise IOError()
276 raise IOError()
277
277
278 if commitopts.get('message'):
278 if commitopts.get('message'):
279 message = commitopts['message']
279 message = commitopts['message']
280 else:
280 else:
281 message = first.description()
281 message = first.description()
282 user = commitopts.get('user')
282 user = commitopts.get('user')
283 date = commitopts.get('date')
283 date = commitopts.get('date')
284 extra = commitopts.get('extra')
284 extra = commitopts.get('extra')
285
285
286 parents = (first.p1().node(), first.p2().node())
286 parents = (first.p1().node(), first.p2().node())
287 new = context.memctx(repo,
287 new = context.memctx(repo,
288 parents=parents,
288 parents=parents,
289 text=message,
289 text=message,
290 files=files,
290 files=files,
291 filectxfn=filectxfn,
291 filectxfn=filectxfn,
292 user=user,
292 user=user,
293 date=date,
293 date=date,
294 extra=extra)
294 extra=extra)
295 new._text = cmdutil.commitforceeditor(repo, new, [])
295 new._text = cmdutil.commitforceeditor(repo, new, [])
296 return repo.commitctx(new)
296 return repo.commitctx(new)
297
297
298 def pick(ui, repo, ctx, ha, opts):
298 def pick(ui, repo, ctx, ha, opts):
299 oldctx = repo[ha]
299 oldctx = repo[ha]
300 if oldctx.parents()[0] == ctx:
300 if oldctx.parents()[0] == ctx:
301 ui.debug('node %s unchanged\n' % ha)
301 ui.debug('node %s unchanged\n' % ha)
302 return oldctx, []
302 return oldctx, []
303 hg.update(repo, ctx.node())
303 hg.update(repo, ctx.node())
304 stats = applychanges(ui, repo, oldctx, opts)
304 stats = applychanges(ui, repo, oldctx, opts)
305 if stats and stats[3] > 0:
305 if stats and stats[3] > 0:
306 raise error.InterventionRequired(_('Fix up the change and run '
306 raise error.InterventionRequired(_('Fix up the change and run '
307 'hg histedit --continue'))
307 'hg histedit --continue'))
308 # drop the second merge parent
308 # drop the second merge parent
309 commit = commitfuncfor(repo, oldctx)
309 commit = commitfuncfor(repo, oldctx)
310 n = commit(text=oldctx.description(), user=oldctx.user(),
310 n = commit(text=oldctx.description(), user=oldctx.user(),
311 date=oldctx.date(), extra=oldctx.extra())
311 date=oldctx.date(), extra=oldctx.extra())
312 if n is None:
312 if n is None:
313 ui.warn(_('%s: empty changeset\n')
313 ui.warn(_('%s: empty changeset\n')
314 % node.hex(ha))
314 % node.hex(ha))
315 return ctx, []
315 return ctx, []
316 new = repo[n]
316 new = repo[n]
317 return new, [(oldctx.node(), (n,))]
317 return new, [(oldctx.node(), (n,))]
318
318
319
319
320 def edit(ui, repo, ctx, ha, opts):
320 def edit(ui, repo, ctx, ha, opts):
321 oldctx = repo[ha]
321 oldctx = repo[ha]
322 hg.update(repo, ctx.node())
322 hg.update(repo, ctx.node())
323 applychanges(ui, repo, oldctx, opts)
323 applychanges(ui, repo, oldctx, opts)
324 raise error.InterventionRequired(
324 raise error.InterventionRequired(
325 _('Make changes as needed, you may commit or record as needed now.\n'
325 _('Make changes as needed, you may commit or record as needed now.\n'
326 'When you are finished, run hg histedit --continue to resume.'))
326 'When you are finished, run hg histedit --continue to resume.'))
327
327
328 def fold(ui, repo, ctx, ha, opts):
328 def fold(ui, repo, ctx, ha, opts):
329 oldctx = repo[ha]
329 oldctx = repo[ha]
330 hg.update(repo, ctx.node())
330 hg.update(repo, ctx.node())
331 stats = applychanges(ui, repo, oldctx, opts)
331 stats = applychanges(ui, repo, oldctx, opts)
332 if stats and stats[3] > 0:
332 if stats and stats[3] > 0:
333 raise error.InterventionRequired(
333 raise error.InterventionRequired(
334 _('Fix up the change and run hg histedit --continue'))
334 _('Fix up the change and run hg histedit --continue'))
335 n = repo.commit(text='fold-temp-revision %s' % ha, user=oldctx.user(),
335 n = repo.commit(text='fold-temp-revision %s' % ha, user=oldctx.user(),
336 date=oldctx.date(), extra=oldctx.extra())
336 date=oldctx.date(), extra=oldctx.extra())
337 if n is None:
337 if n is None:
338 ui.warn(_('%s: empty changeset')
338 ui.warn(_('%s: empty changeset')
339 % node.hex(ha))
339 % node.hex(ha))
340 return ctx, []
340 return ctx, []
341 return finishfold(ui, repo, ctx, oldctx, n, opts, [])
341 return finishfold(ui, repo, ctx, oldctx, n, opts, [])
342
342
343 def finishfold(ui, repo, ctx, oldctx, newnode, opts, internalchanges):
343 def finishfold(ui, repo, ctx, oldctx, newnode, opts, internalchanges):
344 parent = ctx.parents()[0].node()
344 parent = ctx.parents()[0].node()
345 hg.update(repo, parent)
345 hg.update(repo, parent)
346 ### prepare new commit data
346 ### prepare new commit data
347 commitopts = opts.copy()
347 commitopts = opts.copy()
348 # username
348 # username
349 if ctx.user() == oldctx.user():
349 if ctx.user() == oldctx.user():
350 username = ctx.user()
350 username = ctx.user()
351 else:
351 else:
352 username = ui.username()
352 username = ui.username()
353 commitopts['user'] = username
353 commitopts['user'] = username
354 # commit message
354 # commit message
355 newmessage = '\n***\n'.join(
355 newmessage = '\n***\n'.join(
356 [ctx.description()] +
356 [ctx.description()] +
357 [repo[r].description() for r in internalchanges] +
357 [repo[r].description() for r in internalchanges] +
358 [oldctx.description()]) + '\n'
358 [oldctx.description()]) + '\n'
359 commitopts['message'] = newmessage
359 commitopts['message'] = newmessage
360 # date
360 # date
361 commitopts['date'] = max(ctx.date(), oldctx.date())
361 commitopts['date'] = max(ctx.date(), oldctx.date())
362 extra = ctx.extra().copy()
362 extra = ctx.extra().copy()
363 # histedit_source
363 # histedit_source
364 # note: ctx is likely a temporary commit but that the best we can do here
364 # note: ctx is likely a temporary commit but that the best we can do here
365 # This is sufficient to solve issue3681 anyway
365 # This is sufficient to solve issue3681 anyway
366 extra['histedit_source'] = '%s,%s' % (ctx.hex(), oldctx.hex())
366 extra['histedit_source'] = '%s,%s' % (ctx.hex(), oldctx.hex())
367 commitopts['extra'] = extra
367 commitopts['extra'] = extra
368 phasebackup = repo.ui.backupconfig('phases', 'new-commit')
368 phasebackup = repo.ui.backupconfig('phases', 'new-commit')
369 try:
369 try:
370 phasemin = max(ctx.phase(), oldctx.phase())
370 phasemin = max(ctx.phase(), oldctx.phase())
371 repo.ui.setconfig('phases', 'new-commit', phasemin)
371 repo.ui.setconfig('phases', 'new-commit', phasemin)
372 n = collapse(repo, ctx, repo[newnode], commitopts)
372 n = collapse(repo, ctx, repo[newnode], commitopts)
373 finally:
373 finally:
374 repo.ui.restoreconfig(phasebackup)
374 repo.ui.restoreconfig(phasebackup)
375 if n is None:
375 if n is None:
376 return ctx, []
376 return ctx, []
377 hg.update(repo, n)
377 hg.update(repo, n)
378 replacements = [(oldctx.node(), (newnode,)),
378 replacements = [(oldctx.node(), (newnode,)),
379 (ctx.node(), (n,)),
379 (ctx.node(), (n,)),
380 (newnode, (n,)),
380 (newnode, (n,)),
381 ]
381 ]
382 for ich in internalchanges:
382 for ich in internalchanges:
383 replacements.append((ich, (n,)))
383 replacements.append((ich, (n,)))
384 return repo[n], replacements
384 return repo[n], replacements
385
385
386 def drop(ui, repo, ctx, ha, opts):
386 def drop(ui, repo, ctx, ha, opts):
387 return ctx, [(repo[ha].node(), ())]
387 return ctx, [(repo[ha].node(), ())]
388
388
389
389
390 def message(ui, repo, ctx, ha, opts):
390 def message(ui, repo, ctx, ha, opts):
391 oldctx = repo[ha]
391 oldctx = repo[ha]
392 hg.update(repo, ctx.node())
392 hg.update(repo, ctx.node())
393 stats = applychanges(ui, repo, oldctx, opts)
393 stats = applychanges(ui, repo, oldctx, opts)
394 if stats and stats[3] > 0:
394 if stats and stats[3] > 0:
395 raise error.InterventionRequired(
395 raise error.InterventionRequired(
396 _('Fix up the change and run hg histedit --continue'))
396 _('Fix up the change and run hg histedit --continue'))
397 message = oldctx.description() + '\n'
397 message = oldctx.description() + '\n'
398 message = ui.edit(message, ui.username())
398 message = ui.edit(message, ui.username())
399 commit = commitfuncfor(repo, oldctx)
399 commit = commitfuncfor(repo, oldctx)
400 new = commit(text=message, user=oldctx.user(), date=oldctx.date(),
400 new = commit(text=message, user=oldctx.user(), date=oldctx.date(),
401 extra=oldctx.extra())
401 extra=oldctx.extra())
402 newctx = repo[new]
402 newctx = repo[new]
403 if oldctx.node() != newctx.node():
403 if oldctx.node() != newctx.node():
404 return newctx, [(oldctx.node(), (new,))]
404 return newctx, [(oldctx.node(), (new,))]
405 # We didn't make an edit, so just indicate no replaced nodes
405 # We didn't make an edit, so just indicate no replaced nodes
406 return newctx, []
406 return newctx, []
407
407
408 def findoutgoing(ui, repo, remote=None, force=False, opts={}):
408 def findoutgoing(ui, repo, remote=None, force=False, opts={}):
409 """utility function to find the first outgoing changeset
409 """utility function to find the first outgoing changeset
410
410
411 Used by initialisation code"""
411 Used by initialisation code"""
412 dest = ui.expandpath(remote or 'default-push', remote or 'default')
412 dest = ui.expandpath(remote or 'default-push', remote or 'default')
413 dest, revs = hg.parseurl(dest, None)[:2]
413 dest, revs = hg.parseurl(dest, None)[:2]
414 ui.status(_('comparing with %s\n') % util.hidepassword(dest))
414 ui.status(_('comparing with %s\n') % util.hidepassword(dest))
415
415
416 revs, checkout = hg.addbranchrevs(repo, repo, revs, None)
416 revs, checkout = hg.addbranchrevs(repo, repo, revs, None)
417 other = hg.peer(repo, opts, dest)
417 other = hg.peer(repo, opts, dest)
418
418
419 if revs:
419 if revs:
420 revs = [repo.lookup(rev) for rev in revs]
420 revs = [repo.lookup(rev) for rev in revs]
421
421
422 # hexlify nodes from outgoing, because we're going to parse
422 # hexlify nodes from outgoing, because we're going to parse
423 # parent[0] using revsingle below, and if the binary hash
423 # parent[0] using revsingle below, and if the binary hash
424 # contains special revset characters like ":" the revset
424 # contains special revset characters like ":" the revset
425 # parser can choke.
425 # parser can choke.
426 outgoing = discovery.findcommonoutgoing(repo, other, revs, force=force)
426 outgoing = discovery.findcommonoutgoing(repo, other, revs, force=force)
427 if not outgoing.missing:
427 if not outgoing.missing:
428 raise util.Abort(_('no outgoing ancestors'))
428 raise util.Abort(_('no outgoing ancestors'))
429 return outgoing.missing[0]
429 return outgoing.missing[0]
430
430
431 actiontable = {'p': pick,
431 actiontable = {'p': pick,
432 'pick': pick,
432 'pick': pick,
433 'e': edit,
433 'e': edit,
434 'edit': edit,
434 'edit': edit,
435 'f': fold,
435 'f': fold,
436 'fold': fold,
436 'fold': fold,
437 'd': drop,
437 'd': drop,
438 'drop': drop,
438 'drop': drop,
439 'm': message,
439 'm': message,
440 'mess': message,
440 'mess': message,
441 }
441 }
442
442
443 @command('histedit',
443 @command('histedit',
444 [('', 'commands', '',
444 [('', 'commands', '',
445 _('Read history edits from the specified file.')),
445 _('Read history edits from the specified file.')),
446 ('c', 'continue', False, _('continue an edit already in progress')),
446 ('c', 'continue', False, _('continue an edit already in progress')),
447 ('k', 'keep', False,
447 ('k', 'keep', False,
448 _("don't strip old nodes after edit is complete")),
448 _("don't strip old nodes after edit is complete")),
449 ('', 'abort', False, _('abort an edit in progress')),
449 ('', 'abort', False, _('abort an edit in progress')),
450 ('o', 'outgoing', False, _('changesets not found in destination')),
450 ('o', 'outgoing', False, _('changesets not found in destination')),
451 ('f', 'force', False,
451 ('f', 'force', False,
452 _('force outgoing even for unrelated repositories')),
452 _('force outgoing even for unrelated repositories')),
453 ('r', 'rev', [], _('first revision to be edited'))],
453 ('r', 'rev', [], _('first revision to be edited'))],
454 _("[PARENT]"))
454 _("[PARENT]"))
455 def histedit(ui, repo, *freeargs, **opts):
455 def histedit(ui, repo, *freeargs, **opts):
456 """interactively edit changeset history
456 """interactively edit changeset history
457 """
457 """
458 # TODO only abort if we try and histedit mq patches, not just
458 # TODO only abort if we try and histedit mq patches, not just
459 # blanket if mq patches are applied somewhere
459 # blanket if mq patches are applied somewhere
460 mq = getattr(repo, 'mq', None)
460 mq = getattr(repo, 'mq', None)
461 if mq and mq.applied:
461 if mq and mq.applied:
462 raise util.Abort(_('source has mq patches applied'))
462 raise util.Abort(_('source has mq patches applied'))
463
463
464 # basic argument incompatibility processing
464 # basic argument incompatibility processing
465 outg = opts.get('outgoing')
465 outg = opts.get('outgoing')
466 cont = opts.get('continue')
466 cont = opts.get('continue')
467 abort = opts.get('abort')
467 abort = opts.get('abort')
468 force = opts.get('force')
468 force = opts.get('force')
469 rules = opts.get('commands', '')
469 rules = opts.get('commands', '')
470 revs = opts.get('rev', [])
470 revs = opts.get('rev', [])
471 goal = 'new' # This invocation goal, in new, continue, abort
471 goal = 'new' # This invocation goal, in new, continue, abort
472 if force and not outg:
472 if force and not outg:
473 raise util.Abort(_('--force only allowed with --outgoing'))
473 raise util.Abort(_('--force only allowed with --outgoing'))
474 if cont:
474 if cont:
475 if util.any((outg, abort, revs, freeargs, rules)):
475 if util.any((outg, abort, revs, freeargs, rules)):
476 raise util.Abort(_('no arguments allowed with --continue'))
476 raise util.Abort(_('no arguments allowed with --continue'))
477 goal = 'continue'
477 goal = 'continue'
478 elif abort:
478 elif abort:
479 if util.any((outg, revs, freeargs, rules)):
479 if util.any((outg, revs, freeargs, rules)):
480 raise util.Abort(_('no arguments allowed with --abort'))
480 raise util.Abort(_('no arguments allowed with --abort'))
481 goal = 'abort'
481 goal = 'abort'
482 else:
482 else:
483 if os.path.exists(os.path.join(repo.path, 'histedit-state')):
483 if os.path.exists(os.path.join(repo.path, 'histedit-state')):
484 raise util.Abort(_('history edit already in progress, try '
484 raise util.Abort(_('history edit already in progress, try '
485 '--continue or --abort'))
485 '--continue or --abort'))
486 if outg:
486 if outg:
487 if revs:
487 if revs:
488 raise util.Abort(_('no revisions allowed with --outgoing'))
488 raise util.Abort(_('no revisions allowed with --outgoing'))
489 if len(freeargs) > 1:
489 if len(freeargs) > 1:
490 raise util.Abort(
490 raise util.Abort(
491 _('only one repo argument allowed with --outgoing'))
491 _('only one repo argument allowed with --outgoing'))
492 else:
492 else:
493 revs.extend(freeargs)
493 revs.extend(freeargs)
494 if len(revs) != 1:
494 if len(revs) != 1:
495 raise util.Abort(
495 raise util.Abort(
496 _('histedit requires exactly one parent revision'))
496 _('histedit requires exactly one parent revision'))
497
497
498
498
499 if goal == 'continue':
499 if goal == 'continue':
500 (parentctxnode, rules, keep, topmost, replacements) = readstate(repo)
500 (parentctxnode, rules, keep, topmost, replacements) = readstate(repo)
501 currentparent, wantnull = repo.dirstate.parents()
501 currentparent, wantnull = repo.dirstate.parents()
502 parentctx = repo[parentctxnode]
502 parentctx = repo[parentctxnode]
503 parentctx, repl = bootstrapcontinue(ui, repo, parentctx, rules, opts)
503 parentctx, repl = bootstrapcontinue(ui, repo, parentctx, rules, opts)
504 replacements.extend(repl)
504 replacements.extend(repl)
505 elif goal == 'abort':
505 elif goal == 'abort':
506 (parentctxnode, rules, keep, topmost, replacements) = readstate(repo)
506 (parentctxnode, rules, keep, topmost, replacements) = readstate(repo)
507 mapping, tmpnodes, leafs, _ntm = processreplacement(repo, replacements)
507 mapping, tmpnodes, leafs, _ntm = processreplacement(repo, replacements)
508 ui.debug('restore wc to old parent %s\n' % node.short(topmost))
508 ui.debug('restore wc to old parent %s\n' % node.short(topmost))
509 hg.clean(repo, topmost)
509 hg.clean(repo, topmost)
510 cleanupnode(ui, repo, 'created', tmpnodes)
510 cleanupnode(ui, repo, 'created', tmpnodes)
511 cleanupnode(ui, repo, 'temp', leafs)
511 cleanupnode(ui, repo, 'temp', leafs)
512 os.unlink(os.path.join(repo.path, 'histedit-state'))
512 os.unlink(os.path.join(repo.path, 'histedit-state'))
513 return
513 return
514 else:
514 else:
515 cmdutil.bailifchanged(repo)
515 cmdutil.bailifchanged(repo)
516
516
517 topmost, empty = repo.dirstate.parents()
517 topmost, empty = repo.dirstate.parents()
518 if outg:
518 if outg:
519 if freeargs:
519 if freeargs:
520 remote = freeargs[0]
520 remote = freeargs[0]
521 else:
521 else:
522 remote = None
522 remote = None
523 root = findoutgoing(ui, repo, remote, force, opts)
523 root = findoutgoing(ui, repo, remote, force, opts)
524 else:
524 else:
525 root = revs[0]
525 root = revs[0]
526 root = scmutil.revsingle(repo, root).node()
526 root = scmutil.revsingle(repo, root).node()
527
527
528 keep = opts.get('keep', False)
528 keep = opts.get('keep', False)
529 revs = between(repo, root, topmost, keep)
529 revs = between(repo, root, topmost, keep)
530 if not revs:
530 if not revs:
531 raise util.Abort(_('%s is not an ancestor of working directory') %
531 raise util.Abort(_('%s is not an ancestor of working directory') %
532 node.short(root))
532 node.short(root))
533
533
534 ctxs = [repo[r] for r in revs]
534 ctxs = [repo[r] for r in revs]
535 if not rules:
535 if not rules:
536 rules = '\n'.join([makedesc(c) for c in ctxs])
536 rules = '\n'.join([makedesc(c) for c in ctxs])
537 rules += '\n\n'
537 rules += '\n\n'
538 rules += editcomment % (node.short(root), node.short(topmost))
538 rules += editcomment % (node.short(root), node.short(topmost))
539 rules = ui.edit(rules, ui.username())
539 rules = ui.edit(rules, ui.username())
540 # Save edit rules in .hg/histedit-last-edit.txt in case
540 # Save edit rules in .hg/histedit-last-edit.txt in case
541 # the user needs to ask for help after something
541 # the user needs to ask for help after something
542 # surprising happens.
542 # surprising happens.
543 f = open(repo.join('histedit-last-edit.txt'), 'w')
543 f = open(repo.join('histedit-last-edit.txt'), 'w')
544 f.write(rules)
544 f.write(rules)
545 f.close()
545 f.close()
546 else:
546 else:
547 if rules == '-':
547 if rules == '-':
548 f = sys.stdin
548 f = sys.stdin
549 else:
549 else:
550 f = open(rules)
550 f = open(rules)
551 rules = f.read()
551 rules = f.read()
552 f.close()
552 f.close()
553 rules = [l for l in (r.strip() for r in rules.splitlines())
553 rules = [l for l in (r.strip() for r in rules.splitlines())
554 if l and not l[0] == '#']
554 if l and not l[0] == '#']
555 rules = verifyrules(rules, repo, ctxs)
555 rules = verifyrules(rules, repo, ctxs)
556
556
557 parentctx = repo[root].parents()[0]
557 parentctx = repo[root].parents()[0]
558 keep = opts.get('keep', False)
558 keep = opts.get('keep', False)
559 replacements = []
559 replacements = []
560
560
561
561
562 while rules:
562 while rules:
563 writestate(repo, parentctx.node(), rules, keep, topmost, replacements)
563 writestate(repo, parentctx.node(), rules, keep, topmost, replacements)
564 action, ha = rules.pop(0)
564 action, ha = rules.pop(0)
565 ui.debug('histedit: processing %s %s\n' % (action, ha))
565 ui.debug('histedit: processing %s %s\n' % (action, ha))
566 actfunc = actiontable[action]
566 actfunc = actiontable[action]
567 parentctx, replacement_ = actfunc(ui, repo, parentctx, ha, opts)
567 parentctx, replacement_ = actfunc(ui, repo, parentctx, ha, opts)
568 replacements.extend(replacement_)
568 replacements.extend(replacement_)
569
569
570 hg.update(repo, parentctx.node())
570 hg.update(repo, parentctx.node())
571
571
572 mapping, tmpnodes, created, ntm = processreplacement(repo, replacements)
572 mapping, tmpnodes, created, ntm = processreplacement(repo, replacements)
573 if mapping:
573 if mapping:
574 for prec, succs in mapping.iteritems():
574 for prec, succs in mapping.iteritems():
575 if not succs:
575 if not succs:
576 ui.debug('histedit: %s is dropped\n' % node.short(prec))
576 ui.debug('histedit: %s is dropped\n' % node.short(prec))
577 else:
577 else:
578 ui.debug('histedit: %s is replaced by %s\n' % (
578 ui.debug('histedit: %s is replaced by %s\n' % (
579 node.short(prec), node.short(succs[0])))
579 node.short(prec), node.short(succs[0])))
580 if len(succs) > 1:
580 if len(succs) > 1:
581 m = 'histedit: %s'
581 m = 'histedit: %s'
582 for n in succs[1:]:
582 for n in succs[1:]:
583 ui.debug(m % node.short(n))
583 ui.debug(m % node.short(n))
584
584
585 if not keep:
585 if not keep:
586 if mapping:
586 if mapping:
587 movebookmarks(ui, repo, mapping, topmost, ntm)
587 movebookmarks(ui, repo, mapping, topmost, ntm)
588 # TODO update mq state
588 # TODO update mq state
589 if obsolete._enabled:
589 if obsolete._enabled:
590 markers = []
590 markers = []
591 # sort by revision number because it sound "right"
591 # sort by revision number because it sound "right"
592 for prec in sorted(mapping, key=repo.changelog.rev):
592 for prec in sorted(mapping, key=repo.changelog.rev):
593 succs = mapping[prec]
593 succs = mapping[prec]
594 markers.append((repo[prec],
594 markers.append((repo[prec],
595 tuple(repo[s] for s in succs)))
595 tuple(repo[s] for s in succs)))
596 if markers:
596 if markers:
597 obsolete.createmarkers(repo, markers)
597 obsolete.createmarkers(repo, markers)
598 else:
598 else:
599 cleanupnode(ui, repo, 'replaced', mapping)
599 cleanupnode(ui, repo, 'replaced', mapping)
600
600
601 cleanupnode(ui, repo, 'temp', tmpnodes)
601 cleanupnode(ui, repo, 'temp', tmpnodes)
602 os.unlink(os.path.join(repo.path, 'histedit-state'))
602 os.unlink(os.path.join(repo.path, 'histedit-state'))
603 if os.path.exists(repo.sjoin('undo')):
603 if os.path.exists(repo.sjoin('undo')):
604 os.unlink(repo.sjoin('undo'))
604 os.unlink(repo.sjoin('undo'))
605
605
606
606
607 def bootstrapcontinue(ui, repo, parentctx, rules, opts):
607 def bootstrapcontinue(ui, repo, parentctx, rules, opts):
608 action, currentnode = rules.pop(0)
608 action, currentnode = rules.pop(0)
609 ctx = repo[currentnode]
609 ctx = repo[currentnode]
610 # is there any new commit between the expected parent and "."
610 # is there any new commit between the expected parent and "."
611 #
611 #
612 # note: does not take non linear new change in account (but previous
612 # note: does not take non linear new change in account (but previous
613 # implementation didn't used them anyway (issue3655)
613 # implementation didn't used them anyway (issue3655)
614 newchildren = [c.node() for c in repo.set('(%d::.)', parentctx)]
614 newchildren = [c.node() for c in repo.set('(%d::.)', parentctx)]
615 if parentctx.node() != node.nullid:
615 if parentctx.node() != node.nullid:
616 if not newchildren:
616 if not newchildren:
617 # `parentctxnode` should match but no result. This means that
617 # `parentctxnode` should match but no result. This means that
618 # currentnode is not a descendant from parentctxnode.
618 # currentnode is not a descendant from parentctxnode.
619 msg = _('%s is not an ancestor of working directory')
619 msg = _('%s is not an ancestor of working directory')
620 hint = _('update to %s or descendant and run "hg histedit '
620 hint = _('update to %s or descendant and run "hg histedit '
621 '--continue" again') % parentctx
621 '--continue" again') % parentctx
622 raise util.Abort(msg % parentctx, hint=hint)
622 raise util.Abort(msg % parentctx, hint=hint)
623 newchildren.pop(0) # remove parentctxnode
623 newchildren.pop(0) # remove parentctxnode
624 # Commit dirty working directory if necessary
624 # Commit dirty working directory if necessary
625 new = None
625 new = None
626 m, a, r, d = repo.status()[:4]
626 m, a, r, d = repo.status()[:4]
627 if m or a or r or d:
627 if m or a or r or d:
628 # prepare the message for the commit to comes
628 # prepare the message for the commit to comes
629 if action in ('f', 'fold'):
629 if action in ('f', 'fold'):
630 message = 'fold-temp-revision %s' % currentnode
630 message = 'fold-temp-revision %s' % currentnode
631 else:
631 else:
632 message = ctx.description() + '\n'
632 message = ctx.description() + '\n'
633 if action in ('e', 'edit', 'm', 'mess'):
633 if action in ('e', 'edit', 'm', 'mess'):
634 editor = cmdutil.commitforceeditor
634 editor = cmdutil.commitforceeditor
635 else:
635 else:
636 editor = False
636 editor = False
637 commit = commitfuncfor(repo, ctx)
637 commit = commitfuncfor(repo, ctx)
638 new = commit(text=message, user=ctx.user(),
638 new = commit(text=message, user=ctx.user(),
639 date=ctx.date(), extra=ctx.extra(),
639 date=ctx.date(), extra=ctx.extra(),
640 editor=editor)
640 editor=editor)
641 if new is not None:
641 if new is not None:
642 newchildren.append(new)
642 newchildren.append(new)
643
643
644 replacements = []
644 replacements = []
645 # track replacements
645 # track replacements
646 if ctx.node() not in newchildren:
646 if ctx.node() not in newchildren:
647 # note: new children may be empty when the changeset is dropped.
647 # note: new children may be empty when the changeset is dropped.
648 # this happen e.g during conflicting pick where we revert content
648 # this happen e.g during conflicting pick where we revert content
649 # to parent.
649 # to parent.
650 replacements.append((ctx.node(), tuple(newchildren)))
650 replacements.append((ctx.node(), tuple(newchildren)))
651
651
652 if action in ('f', 'fold'):
652 if action in ('f', 'fold'):
653 if newchildren:
653 if newchildren:
654 # finalize fold operation if applicable
654 # finalize fold operation if applicable
655 if new is None:
655 if new is None:
656 new = newchildren[-1]
656 new = newchildren[-1]
657 else:
657 else:
658 newchildren.pop() # remove new from internal changes
658 newchildren.pop() # remove new from internal changes
659 parentctx, repl = finishfold(ui, repo, parentctx, ctx, new, opts,
659 parentctx, repl = finishfold(ui, repo, parentctx, ctx, new, opts,
660 newchildren)
660 newchildren)
661 replacements.extend(repl)
661 replacements.extend(repl)
662 else:
662 else:
663 # newchildren is empty if the fold did not result in any commit
663 # newchildren is empty if the fold did not result in any commit
664 # this happen when all folded change are discarded during the
664 # this happen when all folded change are discarded during the
665 # merge.
665 # merge.
666 replacements.append((ctx.node(), (parentctx.node(),)))
666 replacements.append((ctx.node(), (parentctx.node(),)))
667 elif newchildren:
667 elif newchildren:
668 # otherwise update "parentctx" before proceeding to further operation
668 # otherwise update "parentctx" before proceeding to further operation
669 parentctx = repo[newchildren[-1]]
669 parentctx = repo[newchildren[-1]]
670 return parentctx, replacements
670 return parentctx, replacements
671
671
672
672
673 def between(repo, old, new, keep):
673 def between(repo, old, new, keep):
674 """select and validate the set of revision to edit
674 """select and validate the set of revision to edit
675
675
676 When keep is false, the specified set can't have children."""
676 When keep is false, the specified set can't have children."""
677 ctxs = list(repo.set('%n::%n', old, new))
677 ctxs = list(repo.set('%n::%n', old, new))
678 if ctxs and not keep:
678 if ctxs and not keep:
679 if (not obsolete._enabled and
679 if (not obsolete._enabled and
680 repo.revs('(%ld::) - (%ld)', ctxs, ctxs)):
680 repo.revs('(%ld::) - (%ld)', ctxs, ctxs)):
681 raise util.Abort(_('cannot edit history that would orphan nodes'))
681 raise util.Abort(_('cannot edit history that would orphan nodes'))
682 if repo.revs('(%ld) and merge()', ctxs):
683 raise util.Abort(_('cannot edit history that contains merges'))
682 root = ctxs[0] # list is already sorted by repo.set
684 root = ctxs[0] # list is already sorted by repo.set
683 if not root.phase():
685 if not root.phase():
684 raise util.Abort(_('cannot edit immutable changeset: %s') % root)
686 raise util.Abort(_('cannot edit immutable changeset: %s') % root)
685 return [c.node() for c in ctxs]
687 return [c.node() for c in ctxs]
686
688
687
689
688 def writestate(repo, parentnode, rules, keep, topmost, replacements):
690 def writestate(repo, parentnode, rules, keep, topmost, replacements):
689 fp = open(os.path.join(repo.path, 'histedit-state'), 'w')
691 fp = open(os.path.join(repo.path, 'histedit-state'), 'w')
690 pickle.dump((parentnode, rules, keep, topmost, replacements), fp)
692 pickle.dump((parentnode, rules, keep, topmost, replacements), fp)
691 fp.close()
693 fp.close()
692
694
693 def readstate(repo):
695 def readstate(repo):
694 """Returns a tuple of (parentnode, rules, keep, topmost, replacements).
696 """Returns a tuple of (parentnode, rules, keep, topmost, replacements).
695 """
697 """
696 fp = open(os.path.join(repo.path, 'histedit-state'))
698 fp = open(os.path.join(repo.path, 'histedit-state'))
697 return pickle.load(fp)
699 return pickle.load(fp)
698
700
699
701
700 def makedesc(c):
702 def makedesc(c):
701 """build a initial action line for a ctx `c`
703 """build a initial action line for a ctx `c`
702
704
703 line are in the form:
705 line are in the form:
704
706
705 pick <hash> <rev> <summary>
707 pick <hash> <rev> <summary>
706 """
708 """
707 summary = ''
709 summary = ''
708 if c.description():
710 if c.description():
709 summary = c.description().splitlines()[0]
711 summary = c.description().splitlines()[0]
710 line = 'pick %s %d %s' % (c, c.rev(), summary)
712 line = 'pick %s %d %s' % (c, c.rev(), summary)
711 return line[:80] # trim to 80 chars so it's not stupidly wide in my editor
713 return line[:80] # trim to 80 chars so it's not stupidly wide in my editor
712
714
713 def verifyrules(rules, repo, ctxs):
715 def verifyrules(rules, repo, ctxs):
714 """Verify that there exists exactly one edit rule per given changeset.
716 """Verify that there exists exactly one edit rule per given changeset.
715
717
716 Will abort if there are to many or too few rules, a malformed rule,
718 Will abort if there are to many or too few rules, a malformed rule,
717 or a rule on a changeset outside of the user-given range.
719 or a rule on a changeset outside of the user-given range.
718 """
720 """
719 parsed = []
721 parsed = []
720 expected = set(str(c) for c in ctxs)
722 expected = set(str(c) for c in ctxs)
721 seen = set()
723 seen = set()
722 for r in rules:
724 for r in rules:
723 if ' ' not in r:
725 if ' ' not in r:
724 raise util.Abort(_('malformed line "%s"') % r)
726 raise util.Abort(_('malformed line "%s"') % r)
725 action, rest = r.split(' ', 1)
727 action, rest = r.split(' ', 1)
726 ha = rest.strip().split(' ', 1)[0]
728 ha = rest.strip().split(' ', 1)[0]
727 try:
729 try:
728 ha = str(repo[ha]) # ensure its a short hash
730 ha = str(repo[ha]) # ensure its a short hash
729 except error.RepoError:
731 except error.RepoError:
730 raise util.Abort(_('unknown changeset %s listed') % ha)
732 raise util.Abort(_('unknown changeset %s listed') % ha)
731 if ha not in expected:
733 if ha not in expected:
732 raise util.Abort(
734 raise util.Abort(
733 _('may not use changesets other than the ones listed'))
735 _('may not use changesets other than the ones listed'))
734 if ha in seen:
736 if ha in seen:
735 raise util.Abort(_('duplicated command for changeset %s') % ha)
737 raise util.Abort(_('duplicated command for changeset %s') % ha)
736 seen.add(ha)
738 seen.add(ha)
737 if action not in actiontable:
739 if action not in actiontable:
738 raise util.Abort(_('unknown action "%s"') % action)
740 raise util.Abort(_('unknown action "%s"') % action)
739 parsed.append([action, ha])
741 parsed.append([action, ha])
740 missing = sorted(expected - seen) # sort to stabilize output
742 missing = sorted(expected - seen) # sort to stabilize output
741 if missing:
743 if missing:
742 raise util.Abort(_('missing rules for changeset %s') % missing[0],
744 raise util.Abort(_('missing rules for changeset %s') % missing[0],
743 hint=_('do you want to use the drop action?'))
745 hint=_('do you want to use the drop action?'))
744 return parsed
746 return parsed
745
747
746 def processreplacement(repo, replacements):
748 def processreplacement(repo, replacements):
747 """process the list of replacements to return
749 """process the list of replacements to return
748
750
749 1) the final mapping between original and created nodes
751 1) the final mapping between original and created nodes
750 2) the list of temporary node created by histedit
752 2) the list of temporary node created by histedit
751 3) the list of new commit created by histedit"""
753 3) the list of new commit created by histedit"""
752 allsuccs = set()
754 allsuccs = set()
753 replaced = set()
755 replaced = set()
754 fullmapping = {}
756 fullmapping = {}
755 # initialise basic set
757 # initialise basic set
756 # fullmapping record all operation recorded in replacement
758 # fullmapping record all operation recorded in replacement
757 for rep in replacements:
759 for rep in replacements:
758 allsuccs.update(rep[1])
760 allsuccs.update(rep[1])
759 replaced.add(rep[0])
761 replaced.add(rep[0])
760 fullmapping.setdefault(rep[0], set()).update(rep[1])
762 fullmapping.setdefault(rep[0], set()).update(rep[1])
761 new = allsuccs - replaced
763 new = allsuccs - replaced
762 tmpnodes = allsuccs & replaced
764 tmpnodes = allsuccs & replaced
763 # Reduce content fullmapping into direct relation between original nodes
765 # Reduce content fullmapping into direct relation between original nodes
764 # and final node created during history edition
766 # and final node created during history edition
765 # Dropped changeset are replaced by an empty list
767 # Dropped changeset are replaced by an empty list
766 toproceed = set(fullmapping)
768 toproceed = set(fullmapping)
767 final = {}
769 final = {}
768 while toproceed:
770 while toproceed:
769 for x in list(toproceed):
771 for x in list(toproceed):
770 succs = fullmapping[x]
772 succs = fullmapping[x]
771 for s in list(succs):
773 for s in list(succs):
772 if s in toproceed:
774 if s in toproceed:
773 # non final node with unknown closure
775 # non final node with unknown closure
774 # We can't process this now
776 # We can't process this now
775 break
777 break
776 elif s in final:
778 elif s in final:
777 # non final node, replace with closure
779 # non final node, replace with closure
778 succs.remove(s)
780 succs.remove(s)
779 succs.update(final[s])
781 succs.update(final[s])
780 else:
782 else:
781 final[x] = succs
783 final[x] = succs
782 toproceed.remove(x)
784 toproceed.remove(x)
783 # remove tmpnodes from final mapping
785 # remove tmpnodes from final mapping
784 for n in tmpnodes:
786 for n in tmpnodes:
785 del final[n]
787 del final[n]
786 # we expect all changes involved in final to exist in the repo
788 # we expect all changes involved in final to exist in the repo
787 # turn `final` into list (topologically sorted)
789 # turn `final` into list (topologically sorted)
788 nm = repo.changelog.nodemap
790 nm = repo.changelog.nodemap
789 for prec, succs in final.items():
791 for prec, succs in final.items():
790 final[prec] = sorted(succs, key=nm.get)
792 final[prec] = sorted(succs, key=nm.get)
791
793
792 # computed topmost element (necessary for bookmark)
794 # computed topmost element (necessary for bookmark)
793 if new:
795 if new:
794 newtopmost = sorted(new, key=repo.changelog.rev)[-1]
796 newtopmost = sorted(new, key=repo.changelog.rev)[-1]
795 elif not final:
797 elif not final:
796 # Nothing rewritten at all. we won't need `newtopmost`
798 # Nothing rewritten at all. we won't need `newtopmost`
797 # It is the same as `oldtopmost` and `processreplacement` know it
799 # It is the same as `oldtopmost` and `processreplacement` know it
798 newtopmost = None
800 newtopmost = None
799 else:
801 else:
800 # every body died. The newtopmost is the parent of the root.
802 # every body died. The newtopmost is the parent of the root.
801 newtopmost = repo[sorted(final, key=repo.changelog.rev)[0]].p1().node()
803 newtopmost = repo[sorted(final, key=repo.changelog.rev)[0]].p1().node()
802
804
803 return final, tmpnodes, new, newtopmost
805 return final, tmpnodes, new, newtopmost
804
806
805 def movebookmarks(ui, repo, mapping, oldtopmost, newtopmost):
807 def movebookmarks(ui, repo, mapping, oldtopmost, newtopmost):
806 """Move bookmark from old to newly created node"""
808 """Move bookmark from old to newly created node"""
807 if not mapping:
809 if not mapping:
808 # if nothing got rewritten there is not purpose for this function
810 # if nothing got rewritten there is not purpose for this function
809 return
811 return
810 moves = []
812 moves = []
811 for bk, old in sorted(repo._bookmarks.iteritems()):
813 for bk, old in sorted(repo._bookmarks.iteritems()):
812 if old == oldtopmost:
814 if old == oldtopmost:
813 # special case ensure bookmark stay on tip.
815 # special case ensure bookmark stay on tip.
814 #
816 #
815 # This is arguably a feature and we may only want that for the
817 # This is arguably a feature and we may only want that for the
816 # active bookmark. But the behavior is kept compatible with the old
818 # active bookmark. But the behavior is kept compatible with the old
817 # version for now.
819 # version for now.
818 moves.append((bk, newtopmost))
820 moves.append((bk, newtopmost))
819 continue
821 continue
820 base = old
822 base = old
821 new = mapping.get(base, None)
823 new = mapping.get(base, None)
822 if new is None:
824 if new is None:
823 continue
825 continue
824 while not new:
826 while not new:
825 # base is killed, trying with parent
827 # base is killed, trying with parent
826 base = repo[base].p1().node()
828 base = repo[base].p1().node()
827 new = mapping.get(base, (base,))
829 new = mapping.get(base, (base,))
828 # nothing to move
830 # nothing to move
829 moves.append((bk, new[-1]))
831 moves.append((bk, new[-1]))
830 if moves:
832 if moves:
831 marks = repo._bookmarks
833 marks = repo._bookmarks
832 for mark, new in moves:
834 for mark, new in moves:
833 old = marks[mark]
835 old = marks[mark]
834 ui.note(_('histedit: moving bookmarks %s from %s to %s\n')
836 ui.note(_('histedit: moving bookmarks %s from %s to %s\n')
835 % (mark, node.short(old), node.short(new)))
837 % (mark, node.short(old), node.short(new)))
836 marks[mark] = new
838 marks[mark] = new
837 marks.write()
839 marks.write()
838
840
839 def cleanupnode(ui, repo, name, nodes):
841 def cleanupnode(ui, repo, name, nodes):
840 """strip a group of nodes from the repository
842 """strip a group of nodes from the repository
841
843
842 The set of node to strip may contains unknown nodes."""
844 The set of node to strip may contains unknown nodes."""
843 ui.debug('should strip %s nodes %s\n' %
845 ui.debug('should strip %s nodes %s\n' %
844 (name, ', '.join([node.short(n) for n in nodes])))
846 (name, ', '.join([node.short(n) for n in nodes])))
845 lock = None
847 lock = None
846 try:
848 try:
847 lock = repo.lock()
849 lock = repo.lock()
848 # Find all node that need to be stripped
850 # Find all node that need to be stripped
849 # (we hg %lr instead of %ln to silently ignore unknown item
851 # (we hg %lr instead of %ln to silently ignore unknown item
850 nm = repo.changelog.nodemap
852 nm = repo.changelog.nodemap
851 nodes = [n for n in nodes if n in nm]
853 nodes = [n for n in nodes if n in nm]
852 roots = [c.node() for c in repo.set("roots(%ln)", nodes)]
854 roots = [c.node() for c in repo.set("roots(%ln)", nodes)]
853 for c in roots:
855 for c in roots:
854 # We should process node in reverse order to strip tip most first.
856 # We should process node in reverse order to strip tip most first.
855 # but this trigger a bug in changegroup hook.
857 # but this trigger a bug in changegroup hook.
856 # This would reduce bundle overhead
858 # This would reduce bundle overhead
857 repair.strip(ui, repo, c)
859 repair.strip(ui, repo, c)
858 finally:
860 finally:
859 lockmod.release(lock)
861 lockmod.release(lock)
860
862
861 def summaryhook(ui, repo):
863 def summaryhook(ui, repo):
862 if not os.path.exists(repo.join('histedit-state')):
864 if not os.path.exists(repo.join('histedit-state')):
863 return
865 return
864 (parentctxnode, rules, keep, topmost, replacements) = readstate(repo)
866 (parentctxnode, rules, keep, topmost, replacements) = readstate(repo)
865 if rules:
867 if rules:
866 # i18n: column positioning for "hg summary"
868 # i18n: column positioning for "hg summary"
867 ui.write(_('hist: %s (histedit --continue)\n') %
869 ui.write(_('hist: %s (histedit --continue)\n') %
868 (ui.label(_('%d remaining'), 'histedit.remaining') %
870 (ui.label(_('%d remaining'), 'histedit.remaining') %
869 len(rules)))
871 len(rules)))
870
872
871 def extsetup(ui):
873 def extsetup(ui):
872 cmdutil.summaryhooks.add('histedit', summaryhook)
874 cmdutil.summaryhooks.add('histedit', summaryhook)
@@ -1,444 +1,459 b''
1 $ . "$TESTDIR/histedit-helpers.sh"
1 $ . "$TESTDIR/histedit-helpers.sh"
2
2
3 Enable obsolete
3 Enable obsolete
4
4
5 $ cat > ${TESTTMP}/obs.py << EOF
5 $ cat > ${TESTTMP}/obs.py << EOF
6 > import mercurial.obsolete
6 > import mercurial.obsolete
7 > mercurial.obsolete._enabled = True
7 > mercurial.obsolete._enabled = True
8 > EOF
8 > EOF
9
9
10 $ cat >> $HGRCPATH << EOF
10 $ cat >> $HGRCPATH << EOF
11 > [ui]
11 > [ui]
12 > logtemplate= {rev}:{node|short} {desc|firstline}
12 > logtemplate= {rev}:{node|short} {desc|firstline}
13 > [phases]
13 > [phases]
14 > publish=False
14 > publish=False
15 > [extensions]'
15 > [extensions]'
16 > histedit=
16 > histedit=
17 > rebase=
17 > rebase=
18 >
18 >
19 > obs=${TESTTMP}/obs.py
19 > obs=${TESTTMP}/obs.py
20 > EOF
20 > EOF
21
21
22 $ hg init base
22 $ hg init base
23 $ cd base
23 $ cd base
24
24
25 $ for x in a b c d e f ; do
25 $ for x in a b c d e f ; do
26 > echo $x > $x
26 > echo $x > $x
27 > hg add $x
27 > hg add $x
28 > hg ci -m $x
28 > hg ci -m $x
29 > done
29 > done
30
30
31 $ hg log --graph
31 $ hg log --graph
32 @ 5:652413bf663e f
32 @ 5:652413bf663e f
33 |
33 |
34 o 4:e860deea161a e
34 o 4:e860deea161a e
35 |
35 |
36 o 3:055a42cdd887 d
36 o 3:055a42cdd887 d
37 |
37 |
38 o 2:177f92b77385 c
38 o 2:177f92b77385 c
39 |
39 |
40 o 1:d2ae7f538514 b
40 o 1:d2ae7f538514 b
41 |
41 |
42 o 0:cb9a9f314b8b a
42 o 0:cb9a9f314b8b a
43
43
44
44
45 $ HGEDITOR=cat hg histedit 1
45 $ HGEDITOR=cat hg histedit 1
46 pick d2ae7f538514 1 b
46 pick d2ae7f538514 1 b
47 pick 177f92b77385 2 c
47 pick 177f92b77385 2 c
48 pick 055a42cdd887 3 d
48 pick 055a42cdd887 3 d
49 pick e860deea161a 4 e
49 pick e860deea161a 4 e
50 pick 652413bf663e 5 f
50 pick 652413bf663e 5 f
51
51
52 # Edit history between d2ae7f538514 and 652413bf663e
52 # Edit history between d2ae7f538514 and 652413bf663e
53 #
53 #
54 # Commands:
54 # Commands:
55 # p, pick = use commit
55 # p, pick = use commit
56 # e, edit = use commit, but stop for amending
56 # e, edit = use commit, but stop for amending
57 # f, fold = use commit, but fold into previous commit (combines N and N-1)
57 # f, fold = use commit, but fold into previous commit (combines N and N-1)
58 # d, drop = remove commit from history
58 # d, drop = remove commit from history
59 # m, mess = edit message without changing commit content
59 # m, mess = edit message without changing commit content
60 #
60 #
61 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
61 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
62 $ hg histedit 1 --commands - --verbose <<EOF | grep histedit
62 $ hg histedit 1 --commands - --verbose <<EOF | grep histedit
63 > pick 177f92b77385 2 c
63 > pick 177f92b77385 2 c
64 > drop d2ae7f538514 1 b
64 > drop d2ae7f538514 1 b
65 > pick 055a42cdd887 3 d
65 > pick 055a42cdd887 3 d
66 > fold e860deea161a 4 e
66 > fold e860deea161a 4 e
67 > pick 652413bf663e 5 f
67 > pick 652413bf663e 5 f
68 > EOF
68 > EOF
69 saved backup bundle to $TESTTMP/base/.hg/strip-backup/96e494a2d553-backup.hg (glob)
69 saved backup bundle to $TESTTMP/base/.hg/strip-backup/96e494a2d553-backup.hg (glob)
70 $ hg log --graph --hidden
70 $ hg log --graph --hidden
71 @ 8:cacdfd884a93 f
71 @ 8:cacdfd884a93 f
72 |
72 |
73 o 7:59d9f330561f d
73 o 7:59d9f330561f d
74 |
74 |
75 o 6:b346ab9a313d c
75 o 6:b346ab9a313d c
76 |
76 |
77 | x 5:652413bf663e f
77 | x 5:652413bf663e f
78 | |
78 | |
79 | x 4:e860deea161a e
79 | x 4:e860deea161a e
80 | |
80 | |
81 | x 3:055a42cdd887 d
81 | x 3:055a42cdd887 d
82 | |
82 | |
83 | x 2:177f92b77385 c
83 | x 2:177f92b77385 c
84 | |
84 | |
85 | x 1:d2ae7f538514 b
85 | x 1:d2ae7f538514 b
86 |/
86 |/
87 o 0:cb9a9f314b8b a
87 o 0:cb9a9f314b8b a
88
88
89 $ hg debugobsolete
89 $ hg debugobsolete
90 d2ae7f538514cd87c17547b0de4cea71fe1af9fb 0 {'date': '* *', 'user': 'test'} (glob)
90 d2ae7f538514cd87c17547b0de4cea71fe1af9fb 0 {'date': '* *', 'user': 'test'} (glob)
91 177f92b773850b59254aa5e923436f921b55483b b346ab9a313db8537ecf96fca3ca3ca984ef3bd7 0 {'date': '* *', 'user': 'test'} (glob)
91 177f92b773850b59254aa5e923436f921b55483b b346ab9a313db8537ecf96fca3ca3ca984ef3bd7 0 {'date': '* *', 'user': 'test'} (glob)
92 055a42cdd88768532f9cf79daa407fc8d138de9b 59d9f330561fd6c88b1a6b32f0e45034d88db784 0 {'date': '* *', 'user': 'test'} (glob)
92 055a42cdd88768532f9cf79daa407fc8d138de9b 59d9f330561fd6c88b1a6b32f0e45034d88db784 0 {'date': '* *', 'user': 'test'} (glob)
93 e860deea161a2f77de56603b340ebbb4536308ae 59d9f330561fd6c88b1a6b32f0e45034d88db784 0 {'date': '* *', 'user': 'test'} (glob)
93 e860deea161a2f77de56603b340ebbb4536308ae 59d9f330561fd6c88b1a6b32f0e45034d88db784 0 {'date': '* *', 'user': 'test'} (glob)
94 652413bf663ef2a641cab26574e46d5f5a64a55a cacdfd884a9321ec4e1de275ef3949fa953a1f83 0 {'date': '* *', 'user': 'test'} (glob)
94 652413bf663ef2a641cab26574e46d5f5a64a55a cacdfd884a9321ec4e1de275ef3949fa953a1f83 0 {'date': '* *', 'user': 'test'} (glob)
95
95
96
96
97 Ensure hidden revision does not prevent histedit
97 Ensure hidden revision does not prevent histedit
98 -------------------------------------------------
98 -------------------------------------------------
99
99
100 create an hidden revision
100 create an hidden revision
101
101
102 $ hg histedit 6 --commands - << EOF
102 $ hg histedit 6 --commands - << EOF
103 > pick b346ab9a313d 6 c
103 > pick b346ab9a313d 6 c
104 > drop 59d9f330561f 7 d
104 > drop 59d9f330561f 7 d
105 > pick cacdfd884a93 8 f
105 > pick cacdfd884a93 8 f
106 > EOF
106 > EOF
107 0 files updated, 0 files merged, 3 files removed, 0 files unresolved
107 0 files updated, 0 files merged, 3 files removed, 0 files unresolved
108 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
108 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
109 $ hg log --graph
109 $ hg log --graph
110 @ 9:c13eb81022ca f
110 @ 9:c13eb81022ca f
111 |
111 |
112 o 6:b346ab9a313d c
112 o 6:b346ab9a313d c
113 |
113 |
114 o 0:cb9a9f314b8b a
114 o 0:cb9a9f314b8b a
115
115
116 check hidden revision are ignored (6 have hidden children 7 and 8)
116 check hidden revision are ignored (6 have hidden children 7 and 8)
117
117
118 $ hg histedit 6 --commands - << EOF
118 $ hg histedit 6 --commands - << EOF
119 > pick b346ab9a313d 6 c
119 > pick b346ab9a313d 6 c
120 > pick c13eb81022ca 8 f
120 > pick c13eb81022ca 8 f
121 > EOF
121 > EOF
122 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
122 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
123
123
124
124
125
125
126 Test that rewriting leaving instability behind is allowed
126 Test that rewriting leaving instability behind is allowed
127 ---------------------------------------------------------------------
127 ---------------------------------------------------------------------
128
128
129 $ hg up '.^'
129 $ hg up '.^'
130 0 files updated, 0 files merged, 1 files removed, 0 files unresolved
130 0 files updated, 0 files merged, 1 files removed, 0 files unresolved
131 $ hg log -r 'children(.)'
131 $ hg log -r 'children(.)'
132 9:c13eb81022ca f (no-eol)
132 9:c13eb81022ca f (no-eol)
133 $ hg histedit -r '.' --commands - <<EOF
133 $ hg histedit -r '.' --commands - <<EOF
134 > edit b346ab9a313d 6 c
134 > edit b346ab9a313d 6 c
135 > EOF
135 > EOF
136 0 files updated, 0 files merged, 1 files removed, 0 files unresolved
136 0 files updated, 0 files merged, 1 files removed, 0 files unresolved
137 adding c
137 adding c
138 Make changes as needed, you may commit or record as needed now.
138 Make changes as needed, you may commit or record as needed now.
139 When you are finished, run hg histedit --continue to resume.
139 When you are finished, run hg histedit --continue to resume.
140 [1]
140 [1]
141 $ echo c >> c
141 $ echo c >> c
142 $ hg histedit --continue
142 $ hg histedit --continue
143 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
143 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
144
144
145 $ hg log -r 'unstable()'
145 $ hg log -r 'unstable()'
146 9:c13eb81022ca f (no-eol)
146 9:c13eb81022ca f (no-eol)
147
147
148 stabilise
148 stabilise
149
149
150 $ hg rebase -r 'unstable()' -d .
150 $ hg rebase -r 'unstable()' -d .
151
151
152 Test dropping of changeset on the top of the stack
152 Test dropping of changeset on the top of the stack
153 -------------------------------------------------------
153 -------------------------------------------------------
154
154
155 Nothing is rewritten below, the working directory parent must be change for the
155 Nothing is rewritten below, the working directory parent must be change for the
156 dropped changeset to be hidden.
156 dropped changeset to be hidden.
157
157
158 $ cd ..
158 $ cd ..
159 $ hg clone base droplast
159 $ hg clone base droplast
160 updating to branch default
160 updating to branch default
161 3 files updated, 0 files merged, 0 files removed, 0 files unresolved
161 3 files updated, 0 files merged, 0 files removed, 0 files unresolved
162 $ cd droplast
162 $ cd droplast
163 $ hg histedit -r '40db8afa467b' --commands - << EOF
163 $ hg histedit -r '40db8afa467b' --commands - << EOF
164 > pick 40db8afa467b 10 c
164 > pick 40db8afa467b 10 c
165 > drop b449568bf7fc 11 f
165 > drop b449568bf7fc 11 f
166 > EOF
166 > EOF
167 0 files updated, 0 files merged, 1 files removed, 0 files unresolved
167 0 files updated, 0 files merged, 1 files removed, 0 files unresolved
168 $ hg log -G
168 $ hg log -G
169 @ 10:40db8afa467b c
169 @ 10:40db8afa467b c
170 |
170 |
171 o 0:cb9a9f314b8b a
171 o 0:cb9a9f314b8b a
172
172
173
173
174 With rewritten ancestors
174 With rewritten ancestors
175
175
176 $ echo e > e
176 $ echo e > e
177 $ hg add e
177 $ hg add e
178 $ hg commit -m g
178 $ hg commit -m g
179 $ echo f > f
179 $ echo f > f
180 $ hg add f
180 $ hg add f
181 $ hg commit -m h
181 $ hg commit -m h
182 $ hg histedit -r '40db8afa467b' --commands - << EOF
182 $ hg histedit -r '40db8afa467b' --commands - << EOF
183 > pick 47a8561c0449 12 g
183 > pick 47a8561c0449 12 g
184 > pick 40db8afa467b 10 c
184 > pick 40db8afa467b 10 c
185 > drop 1b3b05f35ff0 13 h
185 > drop 1b3b05f35ff0 13 h
186 > EOF
186 > EOF
187 0 files updated, 0 files merged, 3 files removed, 0 files unresolved
187 0 files updated, 0 files merged, 3 files removed, 0 files unresolved
188 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
188 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
189 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
189 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
190 $ hg log -G
190 $ hg log -G
191 @ 15:ee6544123ab8 c
191 @ 15:ee6544123ab8 c
192 |
192 |
193 o 14:269e713e9eae g
193 o 14:269e713e9eae g
194 |
194 |
195 o 0:cb9a9f314b8b a
195 o 0:cb9a9f314b8b a
196
196
197 $ cd ../base
197 $ cd ../base
198
198
199
199
200
200
201 Test phases support
201 Test phases support
202 ===========================================
202 ===========================================
203
203
204 Check that histedit respect immutability
204 Check that histedit respect immutability
205 -------------------------------------------
205 -------------------------------------------
206
206
207 $ cat >> $HGRCPATH << EOF
207 $ cat >> $HGRCPATH << EOF
208 > [ui]
208 > [ui]
209 > logtemplate= {rev}:{node|short} ({phase}) {desc|firstline}\n
209 > logtemplate= {rev}:{node|short} ({phase}) {desc|firstline}\n
210 > EOF
210 > EOF
211
211
212 $ hg ph -pv '.^'
212 $ hg ph -pv '.^'
213 phase changed for 2 changesets
213 phase changed for 2 changesets
214 $ hg log -G
214 $ hg log -G
215 @ 11:b449568bf7fc (draft) f
215 @ 11:b449568bf7fc (draft) f
216 |
216 |
217 o 10:40db8afa467b (public) c
217 o 10:40db8afa467b (public) c
218 |
218 |
219 o 0:cb9a9f314b8b (public) a
219 o 0:cb9a9f314b8b (public) a
220
220
221 $ hg histedit -r '.~2'
221 $ hg histedit -r '.~2'
222 abort: cannot edit immutable changeset: cb9a9f314b8b
222 abort: cannot edit immutable changeset: cb9a9f314b8b
223 [255]
223 [255]
224
224
225
225
226 Prepare further testing
226 Prepare further testing
227 -------------------------------------------
227 -------------------------------------------
228
228
229 $ for x in g h i j k ; do
229 $ for x in g h i j k ; do
230 > echo $x > $x
230 > echo $x > $x
231 > hg add $x
231 > hg add $x
232 > hg ci -m $x
232 > hg ci -m $x
233 > done
233 > done
234 $ hg phase --force --secret .~2
234 $ hg phase --force --secret .~2
235 $ hg log -G
235 $ hg log -G
236 @ 16:ee118ab9fa44 (secret) k
236 @ 16:ee118ab9fa44 (secret) k
237 |
237 |
238 o 15:3a6c53ee7f3d (secret) j
238 o 15:3a6c53ee7f3d (secret) j
239 |
239 |
240 o 14:b605fb7503f2 (secret) i
240 o 14:b605fb7503f2 (secret) i
241 |
241 |
242 o 13:7395e1ff83bd (draft) h
242 o 13:7395e1ff83bd (draft) h
243 |
243 |
244 o 12:6b70183d2492 (draft) g
244 o 12:6b70183d2492 (draft) g
245 |
245 |
246 o 11:b449568bf7fc (draft) f
246 o 11:b449568bf7fc (draft) f
247 |
247 |
248 o 10:40db8afa467b (public) c
248 o 10:40db8afa467b (public) c
249 |
249 |
250 o 0:cb9a9f314b8b (public) a
250 o 0:cb9a9f314b8b (public) a
251
251
252 $ cd ..
252 $ cd ..
253
253
254 simple phase conservation
254 simple phase conservation
255 -------------------------------------------
255 -------------------------------------------
256
256
257 Resulting changeset should conserve the phase of the original one whatever the
257 Resulting changeset should conserve the phase of the original one whatever the
258 phases.new-commit option is.
258 phases.new-commit option is.
259
259
260 New-commit as draft (default)
260 New-commit as draft (default)
261
261
262 $ cp -r base simple-draft
262 $ cp -r base simple-draft
263 $ cd simple-draft
263 $ cd simple-draft
264 $ hg histedit -r 'b449568bf7fc' --commands - << EOF
264 $ hg histedit -r 'b449568bf7fc' --commands - << EOF
265 > edit b449568bf7fc 11 f
265 > edit b449568bf7fc 11 f
266 > pick 6b70183d2492 12 g
266 > pick 6b70183d2492 12 g
267 > pick 7395e1ff83bd 13 h
267 > pick 7395e1ff83bd 13 h
268 > pick b605fb7503f2 14 i
268 > pick b605fb7503f2 14 i
269 > pick 3a6c53ee7f3d 15 j
269 > pick 3a6c53ee7f3d 15 j
270 > pick ee118ab9fa44 16 k
270 > pick ee118ab9fa44 16 k
271 > EOF
271 > EOF
272 0 files updated, 0 files merged, 6 files removed, 0 files unresolved
272 0 files updated, 0 files merged, 6 files removed, 0 files unresolved
273 adding f
273 adding f
274 Make changes as needed, you may commit or record as needed now.
274 Make changes as needed, you may commit or record as needed now.
275 When you are finished, run hg histedit --continue to resume.
275 When you are finished, run hg histedit --continue to resume.
276 [1]
276 [1]
277 $ echo f >> f
277 $ echo f >> f
278 $ hg histedit --continue
278 $ hg histedit --continue
279 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
279 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
280 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
280 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
281 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
281 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
282 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
282 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
283 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
283 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
284 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
284 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
285 $ hg log -G
285 $ hg log -G
286 @ 22:12e89af74238 (secret) k
286 @ 22:12e89af74238 (secret) k
287 |
287 |
288 o 21:636a8687b22e (secret) j
288 o 21:636a8687b22e (secret) j
289 |
289 |
290 o 20:ccaf0a38653f (secret) i
290 o 20:ccaf0a38653f (secret) i
291 |
291 |
292 o 19:11a89d1c2613 (draft) h
292 o 19:11a89d1c2613 (draft) h
293 |
293 |
294 o 18:c1dec7ca82ea (draft) g
294 o 18:c1dec7ca82ea (draft) g
295 |
295 |
296 o 17:087281e68428 (draft) f
296 o 17:087281e68428 (draft) f
297 |
297 |
298 o 10:40db8afa467b (public) c
298 o 10:40db8afa467b (public) c
299 |
299 |
300 o 0:cb9a9f314b8b (public) a
300 o 0:cb9a9f314b8b (public) a
301
301
302 $ cd ..
302 $ cd ..
303
303
304
304
305 New-commit as draft (default)
305 New-commit as draft (default)
306
306
307 $ cp -r base simple-secret
307 $ cp -r base simple-secret
308 $ cd simple-secret
308 $ cd simple-secret
309 $ cat >> .hg/hgrc << EOF
309 $ cat >> .hg/hgrc << EOF
310 > [phases]
310 > [phases]
311 > new-commit=secret
311 > new-commit=secret
312 > EOF
312 > EOF
313 $ hg histedit -r 'b449568bf7fc' --commands - << EOF
313 $ hg histedit -r 'b449568bf7fc' --commands - << EOF
314 > edit b449568bf7fc 11 f
314 > edit b449568bf7fc 11 f
315 > pick 6b70183d2492 12 g
315 > pick 6b70183d2492 12 g
316 > pick 7395e1ff83bd 13 h
316 > pick 7395e1ff83bd 13 h
317 > pick b605fb7503f2 14 i
317 > pick b605fb7503f2 14 i
318 > pick 3a6c53ee7f3d 15 j
318 > pick 3a6c53ee7f3d 15 j
319 > pick ee118ab9fa44 16 k
319 > pick ee118ab9fa44 16 k
320 > EOF
320 > EOF
321 0 files updated, 0 files merged, 6 files removed, 0 files unresolved
321 0 files updated, 0 files merged, 6 files removed, 0 files unresolved
322 adding f
322 adding f
323 Make changes as needed, you may commit or record as needed now.
323 Make changes as needed, you may commit or record as needed now.
324 When you are finished, run hg histedit --continue to resume.
324 When you are finished, run hg histedit --continue to resume.
325 [1]
325 [1]
326 $ echo f >> f
326 $ echo f >> f
327 $ hg histedit --continue
327 $ hg histedit --continue
328 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
328 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
329 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
329 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
330 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
330 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
331 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
331 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
332 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
332 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
333 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
333 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
334 $ hg log -G
334 $ hg log -G
335 @ 22:12e89af74238 (secret) k
335 @ 22:12e89af74238 (secret) k
336 |
336 |
337 o 21:636a8687b22e (secret) j
337 o 21:636a8687b22e (secret) j
338 |
338 |
339 o 20:ccaf0a38653f (secret) i
339 o 20:ccaf0a38653f (secret) i
340 |
340 |
341 o 19:11a89d1c2613 (draft) h
341 o 19:11a89d1c2613 (draft) h
342 |
342 |
343 o 18:c1dec7ca82ea (draft) g
343 o 18:c1dec7ca82ea (draft) g
344 |
344 |
345 o 17:087281e68428 (draft) f
345 o 17:087281e68428 (draft) f
346 |
346 |
347 o 10:40db8afa467b (public) c
347 o 10:40db8afa467b (public) c
348 |
348 |
349 o 0:cb9a9f314b8b (public) a
349 o 0:cb9a9f314b8b (public) a
350
350
351 $ cd ..
351 $ cd ..
352
352
353
353
354 Changeset reordering
354 Changeset reordering
355 -------------------------------------------
355 -------------------------------------------
356
356
357 If a secret changeset is put before a draft one, all descendant should be secret.
357 If a secret changeset is put before a draft one, all descendant should be secret.
358 It seems more important to present the secret phase.
358 It seems more important to present the secret phase.
359
359
360 $ cp -r base reorder
360 $ cp -r base reorder
361 $ cd reorder
361 $ cd reorder
362 $ hg histedit -r 'b449568bf7fc' --commands - << EOF
362 $ hg histedit -r 'b449568bf7fc' --commands - << EOF
363 > pick b449568bf7fc 11 f
363 > pick b449568bf7fc 11 f
364 > pick 3a6c53ee7f3d 15 j
364 > pick 3a6c53ee7f3d 15 j
365 > pick 6b70183d2492 12 g
365 > pick 6b70183d2492 12 g
366 > pick b605fb7503f2 14 i
366 > pick b605fb7503f2 14 i
367 > pick 7395e1ff83bd 13 h
367 > pick 7395e1ff83bd 13 h
368 > pick ee118ab9fa44 16 k
368 > pick ee118ab9fa44 16 k
369 > EOF
369 > EOF
370 0 files updated, 0 files merged, 5 files removed, 0 files unresolved
370 0 files updated, 0 files merged, 5 files removed, 0 files unresolved
371 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
371 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
372 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
372 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
373 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
373 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
374 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
374 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
375 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
375 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
376 $ hg log -G
376 $ hg log -G
377 @ 21:558246857888 (secret) k
377 @ 21:558246857888 (secret) k
378 |
378 |
379 o 20:28bd44768535 (secret) h
379 o 20:28bd44768535 (secret) h
380 |
380 |
381 o 19:d5395202aeb9 (secret) i
381 o 19:d5395202aeb9 (secret) i
382 |
382 |
383 o 18:21edda8e341b (secret) g
383 o 18:21edda8e341b (secret) g
384 |
384 |
385 o 17:5ab64f3a4832 (secret) j
385 o 17:5ab64f3a4832 (secret) j
386 |
386 |
387 o 11:b449568bf7fc (draft) f
387 o 11:b449568bf7fc (draft) f
388 |
388 |
389 o 10:40db8afa467b (public) c
389 o 10:40db8afa467b (public) c
390 |
390 |
391 o 0:cb9a9f314b8b (public) a
391 o 0:cb9a9f314b8b (public) a
392
392
393 $ cd ..
393 $ cd ..
394
394
395 Changeset folding
395 Changeset folding
396 -------------------------------------------
396 -------------------------------------------
397
397
398 Folding a secret changeset with a draft one turn the result secret (again,
398 Folding a secret changeset with a draft one turn the result secret (again,
399 better safe than sorry). Folding between same phase changeset still works
399 better safe than sorry). Folding between same phase changeset still works
400
400
401 Note that there is a few reordering in this series for more extensive test
401 Note that there is a few reordering in this series for more extensive test
402
402
403 $ cp -r base folding
403 $ cp -r base folding
404 $ cd folding
404 $ cd folding
405 $ cat >> .hg/hgrc << EOF
405 $ cat >> .hg/hgrc << EOF
406 > [phases]
406 > [phases]
407 > new-commit=secret
407 > new-commit=secret
408 > EOF
408 > EOF
409 $ hg histedit -r 'b449568bf7fc' --commands - << EOF
409 $ hg histedit -r 'b449568bf7fc' --commands - << EOF
410 > pick 7395e1ff83bd 13 h
410 > pick 7395e1ff83bd 13 h
411 > fold b449568bf7fc 11 f
411 > fold b449568bf7fc 11 f
412 > pick 6b70183d2492 12 g
412 > pick 6b70183d2492 12 g
413 > fold 3a6c53ee7f3d 15 j
413 > fold 3a6c53ee7f3d 15 j
414 > pick b605fb7503f2 14 i
414 > pick b605fb7503f2 14 i
415 > fold ee118ab9fa44 16 k
415 > fold ee118ab9fa44 16 k
416 > EOF
416 > EOF
417 0 files updated, 0 files merged, 6 files removed, 0 files unresolved
417 0 files updated, 0 files merged, 6 files removed, 0 files unresolved
418 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
418 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
419 0 files updated, 0 files merged, 2 files removed, 0 files unresolved
419 0 files updated, 0 files merged, 2 files removed, 0 files unresolved
420 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
420 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
421 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
421 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
422 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
422 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
423 0 files updated, 0 files merged, 2 files removed, 0 files unresolved
423 0 files updated, 0 files merged, 2 files removed, 0 files unresolved
424 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
424 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
425 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
425 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
426 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
426 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
427 0 files updated, 0 files merged, 2 files removed, 0 files unresolved
427 0 files updated, 0 files merged, 2 files removed, 0 files unresolved
428 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
428 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
429 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
429 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
430 saved backup bundle to $TESTTMP/folding/.hg/strip-backup/58019c66f35f-backup.hg (glob)
430 saved backup bundle to $TESTTMP/folding/.hg/strip-backup/58019c66f35f-backup.hg (glob)
431 saved backup bundle to $TESTTMP/folding/.hg/strip-backup/83d1858e070b-backup.hg (glob)
431 saved backup bundle to $TESTTMP/folding/.hg/strip-backup/83d1858e070b-backup.hg (glob)
432 saved backup bundle to $TESTTMP/folding/.hg/strip-backup/859969f5ed7e-backup.hg (glob)
432 saved backup bundle to $TESTTMP/folding/.hg/strip-backup/859969f5ed7e-backup.hg (glob)
433 $ hg log -G
433 $ hg log -G
434 @ 19:f9daec13fb98 (secret) i
434 @ 19:f9daec13fb98 (secret) i
435 |
435 |
436 o 18:49807617f46a (secret) g
436 o 18:49807617f46a (secret) g
437 |
437 |
438 o 17:050280826e04 (draft) h
438 o 17:050280826e04 (draft) h
439 |
439 |
440 o 10:40db8afa467b (public) c
440 o 10:40db8afa467b (public) c
441 |
441 |
442 o 0:cb9a9f314b8b (public) a
442 o 0:cb9a9f314b8b (public) a
443
443
444 $ hg co 18
445 0 files updated, 0 files merged, 2 files removed, 0 files unresolved
446 $ echo wat >> wat
447 $ hg add wat
448 $ hg ci -m 'add wat'
449 created new head
450 $ hg merge 19
451 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
452 (branch merge, don't forget to commit)
453 $ hg ci -m 'merge'
454 $ echo not wat > wat
455 $ hg ci -m 'modify wat'
456 $ hg histedit 17
457 abort: cannot edit history that contains merges
458 [255]
444 $ cd ..
459 $ cd ..
General Comments 0
You need to be logged in to leave comments. Login now