##// END OF EJS Templates
histedit: replaces patching logic by merges...
Pierre-Yves David -
r17647:d34ba499 default
parent child Browse files
Show More
@@ -142,7 +142,6 try:
142 import cPickle as pickle
142 import cPickle as pickle
143 except ImportError:
143 except ImportError:
144 import pickle
144 import pickle
145 import tempfile
146 import os
145 import os
147
146
148 from mercurial import bookmarks
147 from mercurial import bookmarks
@@ -154,10 +153,10 from mercurial import context
154 from mercurial import hg
153 from mercurial import hg
155 from mercurial import lock as lockmod
154 from mercurial import lock as lockmod
156 from mercurial import node
155 from mercurial import node
157 from mercurial import patch
158 from mercurial import repair
156 from mercurial import repair
159 from mercurial import scmutil
157 from mercurial import scmutil
160 from mercurial import util
158 from mercurial import util
159 from mercurial import merge as mergemod
161 from mercurial.i18n import _
160 from mercurial.i18n import _
162
161
163 cmdtable = {}
162 cmdtable = {}
@@ -177,25 +176,27 editcomment = _("""# Edit history betwee
177 #
176 #
178 """)
177 """)
179
178
180 def foldchanges(ui, repo, node1, node2, opts):
179 def applychanges(ui, repo, ctx, opts):
181 """Produce a new changeset that represents the diff from node1 to node2."""
180 """Merge changeset from ctx (only) in the current working directory"""
181 wcpar = repo.dirstate.parents()[0]
182 if ctx.p1().node() == wcpar:
183 # edition ar "in place" we do not need to make any merge,
184 # just applies changes on parent for edition
185 cmdutil.revert(ui, repo, ctx, (wcpar, node.nullid), all=True)
186 stats = None
187 else:
182 try:
188 try:
183 fd, patchfile = tempfile.mkstemp(prefix='hg-histedit-')
189 # ui.forcemerge is an internal variable, do not document
184 fp = os.fdopen(fd, 'w')
190 repo.ui.setconfig('ui', 'forcemerge', opts.get('tool', ''))
185 diffopts = patch.diffopts(ui, opts)
191 stats = mergemod.update(repo, ctx.node(), True, True, False,
186 diffopts.git = True
192 ctx.p1().node())
187 diffopts.ignorews = False
188 diffopts.ignorewsamount = False
189 diffopts.ignoreblanklines = False
190 gen = patch.diff(repo, node1, node2, opts=diffopts)
191 for chunk in gen:
192 fp.write(chunk)
193 fp.close()
194 files = set()
195 patch.patch(ui, repo, patchfile, files=files, eolmode=None)
196 finally:
193 finally:
197 os.unlink(patchfile)
194 repo.ui.setconfig('ui', 'forcemerge', '')
198 return files
195 repo.setparents(wcpar, node.nullid)
196 repo.dirstate.write()
197 # fix up dirstate for copies and renames
198 cmdutil.duplicatecopies(repo, ctx.rev(), ctx.p1().rev())
199 return stats
199
200
200 def collapse(repo, first, last, commitopts):
201 def collapse(repo, first, last, commitopts):
201 """collapse the set of revisions from first to last as new one.
202 """collapse the set of revisions from first to last as new one.
@@ -273,27 +274,24 def pick(ui, repo, ctx, ha, opts):
273 ui.debug('node %s unchanged\n' % ha)
274 ui.debug('node %s unchanged\n' % ha)
274 return oldctx, [], [], []
275 return oldctx, [], [], []
275 hg.update(repo, ctx.node())
276 hg.update(repo, ctx.node())
276 try:
277 stats = applychanges(ui, repo, oldctx, opts)
277 files = foldchanges(ui, repo, oldctx.p1().node() , ha, opts)
278 if stats and stats[3] > 0:
278 if not files:
279 raise util.Abort(_('Fix up the change and run '
279 ui.warn(_('%s: empty changeset')
280 'hg histedit --continue'))
281 # drop the second merge parent
282 n = repo.commit(text=oldctx.description(), user=oldctx.user(),
283 date=oldctx.date(), extra=oldctx.extra())
284 if n is None:
285 ui.warn(_('%s: empty changeset\n')
280 % node.hex(ha))
286 % node.hex(ha))
281 return ctx, [], [], []
287 return ctx, [], [], []
282 except Exception:
283 raise util.Abort(_('Fix up the change and run '
284 'hg histedit --continue'))
285 n = repo.commit(text=oldctx.description(), user=oldctx.user(),
286 date=oldctx.date(), extra=oldctx.extra())
287 return repo[n], [n], [oldctx.node()], []
288 return repo[n], [n], [oldctx.node()], []
288
289
289
290
290 def edit(ui, repo, ctx, ha, opts):
291 def edit(ui, repo, ctx, ha, opts):
291 oldctx = repo[ha]
292 oldctx = repo[ha]
292 hg.update(repo, ctx.node())
293 hg.update(repo, ctx.node())
293 try:
294 applychanges(ui, repo, oldctx, opts)
294 foldchanges(ui, repo, oldctx.p1().node() , ha, opts)
295 except Exception:
296 pass
297 raise util.Abort(_('Make changes as needed, you may commit or record as '
295 raise util.Abort(_('Make changes as needed, you may commit or record as '
298 'needed now.\nWhen you are finished, run hg'
296 'needed now.\nWhen you are finished, run hg'
299 ' histedit --continue to resume.'))
297 ' histedit --continue to resume.'))
@@ -301,17 +299,16 def edit(ui, repo, ctx, ha, opts):
301 def fold(ui, repo, ctx, ha, opts):
299 def fold(ui, repo, ctx, ha, opts):
302 oldctx = repo[ha]
300 oldctx = repo[ha]
303 hg.update(repo, ctx.node())
301 hg.update(repo, ctx.node())
304 try:
302 stats = applychanges(ui, repo, oldctx, opts)
305 files = foldchanges(ui, repo, oldctx.p1().node() , ha, opts)
303 if stats and stats[3] > 0:
306 if not files:
307 ui.warn(_('%s: empty changeset')
308 % node.hex(ha))
309 return ctx, [], [], []
310 except Exception:
311 raise util.Abort(_('Fix up the change and run '
304 raise util.Abort(_('Fix up the change and run '
312 'hg histedit --continue'))
305 'hg histedit --continue'))
313 n = repo.commit(text='fold-temp-revision %s' % ha, user=oldctx.user(),
306 n = repo.commit(text='fold-temp-revision %s' % ha, user=oldctx.user(),
314 date=oldctx.date(), extra=oldctx.extra())
307 date=oldctx.date(), extra=oldctx.extra())
308 if n is None:
309 ui.warn(_('%s: empty changeset')
310 % node.hex(ha))
311 return ctx, [], [], []
315 return finishfold(ui, repo, ctx, oldctx, n, opts, [])
312 return finishfold(ui, repo, ctx, oldctx, n, opts, [])
316
313
317 def finishfold(ui, repo, ctx, oldctx, newnode, opts, internalchanges):
314 def finishfold(ui, repo, ctx, oldctx, newnode, opts, internalchanges):
@@ -346,9 +343,8 def drop(ui, repo, ctx, ha, opts):
346 def message(ui, repo, ctx, ha, opts):
343 def message(ui, repo, ctx, ha, opts):
347 oldctx = repo[ha]
344 oldctx = repo[ha]
348 hg.update(repo, ctx.node())
345 hg.update(repo, ctx.node())
349 try:
346 stats = applychanges(ui, repo, oldctx, opts)
350 foldchanges(ui, repo, oldctx.p1().node() , ha, opts)
347 if stats and stats[3] > 0:
351 except Exception:
352 raise util.Abort(_('Fix up the change and run '
348 raise util.Abort(_('Fix up the change and run '
353 'hg histedit --continue'))
349 'hg histedit --continue'))
354 message = oldctx.description() + '\n'
350 message = oldctx.description() + '\n'
@@ -88,13 +88,14 log before edit
88 edit the history
88 edit the history
89 $ HGEDITOR="cat \"$EDITED\" > " hg histedit 3 2>&1 | fixbundle
89 $ HGEDITOR="cat \"$EDITED\" > " hg histedit 3 2>&1 | fixbundle
90 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
90 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
91 patching file e
91 merging e
92 Hunk #1 FAILED at 0
92 warning: conflicts during merge.
93 1 out of 1 hunks FAILED -- saving rejects to file e.rej
93 merging e incomplete! (edit conflicts, then use 'hg resolve --mark')
94 abort: Fix up the change and run hg histedit --continue
94 abort: Fix up the change and run hg histedit --continue
95
95
96 fix up
96 fix up
97 $ echo a > e
97 $ echo 'I can haz no commute' > e
98 $ hg resolve --mark e
98 $ cat > cat.py <<EOF
99 $ cat > cat.py <<EOF
99 > import sys
100 > import sys
100 > print open(sys.argv[1]).read()
101 > print open(sys.argv[1]).read()
@@ -121,25 +122,27 fix up
121
122
122 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
123 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
123 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
124 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
124 patching file e
125 merging e
125 Hunk #1 FAILED at 0
126 warning: conflicts during merge.
126 1 out of 1 hunks FAILED -- saving rejects to file e.rej
127 merging e incomplete! (edit conflicts, then use 'hg resolve --mark')
127 abort: Fix up the change and run hg histedit --continue
128 abort: Fix up the change and run hg histedit --continue
128
129
129 just continue this time
130 just continue this time
131 $ hg revert -r 'p1()' e
132 $ hg resolve --mark e
130 $ hg histedit --continue 2>&1 | fixbundle
133 $ hg histedit --continue 2>&1 | fixbundle
131 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
134 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
132 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
135 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
133
136
134 log after edit
137 log after edit
135 $ hg log --graph
138 $ hg log --graph
136 @ changeset: 5:45bd04206744
139 @ changeset: 5:2696a654c663
137 | tag: tip
140 | tag: tip
138 | user: test
141 | user: test
139 | date: Thu Jan 01 00:00:00 1970 +0000
142 | date: Thu Jan 01 00:00:00 1970 +0000
140 | summary: f
143 | summary: f
141 |
144 |
142 o changeset: 4:abff6367c13a
145 o changeset: 4:ec2c1cf833a8
143 | user: test
146 | user: test
144 | date: Thu Jan 01 00:00:00 1970 +0000
147 | date: Thu Jan 01 00:00:00 1970 +0000
145 | summary: d
148 | summary: d
@@ -167,7 +170,7 log after edit
167
170
168 contents of e
171 contents of e
169 $ hg cat e
172 $ hg cat e
170 a
173 I can haz no commute
171
174
172 manifest
175 manifest
173 $ hg manifest
176 $ hg manifest
@@ -157,16 +157,21 folding and creating no new change doesn
157
157
158 $ HGEDITOR='python editor.py' hg histedit 1
158 $ HGEDITOR='python editor.py' hg histedit 1
159 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
159 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
160 patching file file
160 merging file
161 Hunk #1 FAILED at 2
161 warning: conflicts during merge.
162 1 out of 1 hunks FAILED -- saving rejects to file file.rej
162 merging file incomplete! (edit conflicts, then use 'hg resolve --mark')
163 abort: Fix up the change and run hg histedit --continue
163 abort: Fix up the change and run hg histedit --continue
164 [255]
164 [255]
165 There were conflicts, but we'll continue without resolving. This
165 There were conflicts, we keep P1 content. This
166 should effectively drop the changes from +6.
166 should effectively drop the changes from +6.
167 $ hg status
167 $ hg status
168 M file
168 ? editor.py
169 ? editor.py
169 ? file.rej
170 ? file.orig
171 $ hg resolve -l
172 U file
173 $ hg revert -r 'p1()' file
174 $ hg resolve --mark file
170 $ hg histedit --continue
175 $ hg histedit --continue
171 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
176 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
172 saved backup bundle to $TESTTMP/*-backup.hg (glob)
177 saved backup bundle to $TESTTMP/*-backup.hg (glob)
@@ -217,12 +222,19 dropped revision.
217 > EOF
222 > EOF
218 $ HGEDITOR="cat $EDITED >" hg histedit 1
223 $ HGEDITOR="cat $EDITED >" hg histedit 1
219 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
224 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
220 patching file file
225 merging file
221 Hunk #1 FAILED at 2
226 warning: conflicts during merge.
222 1 out of 1 hunks FAILED -- saving rejects to file file.rej
227 merging file incomplete! (edit conflicts, then use 'hg resolve --mark')
223 abort: Fix up the change and run hg histedit --continue
228 abort: Fix up the change and run hg histedit --continue
224 [255]
229 [255]
225 $ echo 5 >> file
230 $ cat > file << EOF
231 > 1
232 > 2
233 > 3
234 > 4
235 > 5
236 > EOF
237 $ hg resolve --mark file
226 $ hg commit -m '+5.2'
238 $ hg commit -m '+5.2'
227 created new head
239 created new head
228 $ echo 6 >> file
240 $ echo 6 >> file
@@ -73,23 +73,21 log before edit
73 edit the history
73 edit the history
74 $ HGEDITOR="cat \"$EDITED\" > " hg histedit 177f92b77385 2>&1 | fixbundle
74 $ HGEDITOR="cat \"$EDITED\" > " hg histedit 177f92b77385 2>&1 | fixbundle
75 0 files updated, 0 files merged, 2 files removed, 0 files unresolved
75 0 files updated, 0 files merged, 2 files removed, 0 files unresolved
76 1 out of 1 hunks FAILED -- saving rejects to file e.rej
76 remote changed e which local deleted
77 use (c)hanged version or leave (d)eleted? c
78 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
79 merging e
80 warning: conflicts during merge.
81 merging e incomplete! (edit conflicts, then use 'hg resolve --mark')
77 abort: Fix up the change and run hg histedit --continue
82 abort: Fix up the change and run hg histedit --continue
78
83
79 fix up (pre abort)
80 $ echo a > e
81 $ hg add e
82 $ hg histedit --continue 2>&1 | fixbundle
83 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
84 file e already exists
85 1 out of 1 hunks FAILED -- saving rejects to file e.rej
86 abort: Fix up the change and run hg histedit --continue
87
84
88 abort the edit
85 abort the edit
89 $ hg histedit --abort 2>&1 | fixbundle
86 $ hg histedit --abort 2>&1 | fixbundle
90 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
87 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
91
88
92 log after abort
89 log after abort
90 $ hg resolve -l
93 $ hg log --graph
91 $ hg log --graph
94 @ changeset: 6:bfa474341cc9
92 @ changeset: 6:bfa474341cc9
95 | tag: tip
93 | tag: tip
@@ -89,9 +89,9 log before edit
89 edit the history
89 edit the history
90 $ HGEDITOR="cat \"$EDITED\" > " hg histedit 3 2>&1 | fixbundle
90 $ HGEDITOR="cat \"$EDITED\" > " hg histedit 3 2>&1 | fixbundle
91 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
91 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
92 patching file e
92 merging e
93 Hunk #1 FAILED at 0
93 warning: conflicts during merge.
94 1 out of 1 hunks FAILED -- saving rejects to file e.rej
94 merging e incomplete! (edit conflicts, then use 'hg resolve --mark')
95 abort: Fix up the change and run hg histedit --continue
95 abort: Fix up the change and run hg histedit --continue
96
96
97 abort the edit
97 abort the edit
@@ -147,21 +147,24 second edit set
147 edit the history
147 edit the history
148 $ HGEDITOR="cat \"$EDITED\" > " hg histedit 3 2>&1 | fixbundle
148 $ HGEDITOR="cat \"$EDITED\" > " hg histedit 3 2>&1 | fixbundle
149 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
149 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
150 patching file e
150 merging e
151 Hunk #1 FAILED at 0
151 warning: conflicts during merge.
152 1 out of 1 hunks FAILED -- saving rejects to file e.rej
152 merging e incomplete! (edit conflicts, then use 'hg resolve --mark')
153 abort: Fix up the change and run hg histedit --continue
153 abort: Fix up the change and run hg histedit --continue
154
154
155 fix up
155 fix up
156 $ echo 'I can haz no commute' > e
156 $ echo 'I can haz no commute' > e
157 $ hg resolve --mark e
157 $ hg histedit --continue 2>&1 | fixbundle
158 $ hg histedit --continue 2>&1 | fixbundle
158 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
159 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
159 patching file e
160 merging e
160 Hunk #1 FAILED at 0
161 warning: conflicts during merge.
161 1 out of 1 hunks FAILED -- saving rejects to file e.rej
162 merging e incomplete! (edit conflicts, then use 'hg resolve --mark')
162 abort: Fix up the change and run hg histedit --continue
163 abort: Fix up the change and run hg histedit --continue
163
164
164 just continue this time
165 just continue this time
166 $ hg revert -r 'p1()' e
167 $ hg resolve --mark e
165 $ hg histedit --continue 2>&1 | fixbundle
168 $ hg histedit --continue 2>&1 | fixbundle
166 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
169 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
167 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
170 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
@@ -227,19 +230,22 start over
227 edit the history, this time with a fold action
230 edit the history, this time with a fold action
228 $ HGEDITOR="cat \"$EDITED\" > " hg histedit 3 2>&1 | fixbundle
231 $ HGEDITOR="cat \"$EDITED\" > " hg histedit 3 2>&1 | fixbundle
229 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
232 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
230 patching file e
233 merging e
231 Hunk #1 FAILED at 0
234 warning: conflicts during merge.
232 1 out of 1 hunks FAILED -- saving rejects to file e.rej
235 merging e incomplete! (edit conflicts, then use 'hg resolve --mark')
233 abort: Fix up the change and run hg histedit --continue
236 abort: Fix up the change and run hg histedit --continue
234
237
235 $ echo 'I can haz no commute' > e
238 $ echo 'I can haz no commute' > e
239 $ hg resolve --mark e
236 $ HGEDITOR="cat \"$EDITED\" > " hg histedit --continue 2>&1 | fixbundle
240 $ HGEDITOR="cat \"$EDITED\" > " hg histedit --continue 2>&1 | fixbundle
237 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
241 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
238 patching file e
242 merging e
239 Hunk #1 FAILED at 0
243 warning: conflicts during merge.
240 1 out of 1 hunks FAILED -- saving rejects to file e.rej
244 merging e incomplete! (edit conflicts, then use 'hg resolve --mark')
241 abort: Fix up the change and run hg histedit --continue
245 abort: Fix up the change and run hg histedit --continue
242 second edit also fails, but just continue
246 second edit also fails, but just continue
247 $ hg revert -r 'p1()' e
248 $ hg resolve --mark e
243 $ hg histedit --continue 2>&1 | fixbundle
249 $ hg histedit --continue 2>&1 | fixbundle
244 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
250 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
245 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
251 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
General Comments 0
You need to be logged in to leave comments. Login now