##// END OF EJS Templates
histedit: fold in memory...
Pierre-Yves David -
r17644:9ae073f1 default
parent child Browse files
Show More
@@ -149,6 +149,8 b' from mercurial import bookmarks'
149 149 from mercurial import cmdutil
150 150 from mercurial import discovery
151 151 from mercurial import error
152 from mercurial import copies
153 from mercurial import context
152 154 from mercurial import hg
153 155 from mercurial import lock as lockmod
154 156 from mercurial import node
@@ -195,6 +197,76 b' def foldchanges(ui, repo, node1, node2, '
195 197 os.unlink(patchfile)
196 198 return files
197 199
200 def collapse(repo, first, last, commitopts):
201 """collapse the set of revisions from first to last as new one.
202
203 Expected commit options are:
204 - message
205 - date
206 - username
207 Edition of commit message is trigered in all case.
208
209 This function works in memory."""
210 ctxs = list(repo.set('%d::%d', first, last))
211 if not ctxs:
212 return None
213 base = first.parents()[0]
214
215 # commit a new version of the old changeset, including the update
216 # collect all files which might be affected
217 files = set()
218 for ctx in ctxs:
219 files.update(ctx.files())
220
221 # Recompute copies (avoid recording a -> b -> a)
222 copied = copies.pathcopies(first, last)
223
224 # prune files which were reverted by the updates
225 def samefile(f):
226 if f in last.manifest():
227 a = last.filectx(f)
228 if f in base.manifest():
229 b = base.filectx(f)
230 return (a.data() == b.data()
231 and a.flags() == b.flags())
232 else:
233 return False
234 else:
235 return f not in base.manifest()
236 files = [f for f in files if not samefile(f)]
237 # commit version of these files as defined by head
238 headmf = last.manifest()
239 def filectxfn(repo, ctx, path):
240 if path in headmf:
241 fctx = last[path]
242 flags = fctx.flags()
243 mctx = context.memfilectx(fctx.path(), fctx.data(),
244 islink='l' in flags,
245 isexec='x' in flags,
246 copied=copied.get(path))
247 return mctx
248 raise IOError()
249
250 if commitopts.get('message'):
251 message = commitopts['message']
252 else:
253 message = first.description()
254 user = commitopts.get('user')
255 date = commitopts.get('date')
256 extra = first.extra()
257
258 parents = (first.p1().node(), first.p2().node())
259 new = context.memctx(repo,
260 parents=parents,
261 text=message,
262 files=files,
263 filectxfn=filectxfn,
264 user=user,
265 date=date,
266 extra=extra)
267 new._text = cmdutil.commitforceeditor(repo, new, [])
268 return repo.commitctx(new)
269
198 270 def pick(ui, repo, ctx, ha, opts):
199 271 oldctx = repo[ha]
200 272 if oldctx.parents()[0] == ctx:
@@ -245,19 +317,26 b' def fold(ui, repo, ctx, ha, opts):'
245 317 def finishfold(ui, repo, ctx, oldctx, newnode, opts, internalchanges):
246 318 parent = ctx.parents()[0].node()
247 319 hg.update(repo, parent)
248 foldchanges(ui, repo, parent, newnode, opts)
320 ### prepare new commit data
321 commitopts = opts.copy()
322 # username
323 if ctx.user() == oldctx.user():
324 username = ctx.user()
325 else:
326 username = ui.username()
327 commitopts['user'] = username
328 # commit message
249 329 newmessage = '\n***\n'.join(
250 330 [ctx.description()] +
251 331 [repo[r].description() for r in internalchanges] +
252 332 [oldctx.description()]) + '\n'
253 # If the changesets are from the same author, keep it.
254 if ctx.user() == oldctx.user():
255 username = ctx.user()
256 else:
257 username = ui.username()
258 newmessage = ui.edit(newmessage, username)
259 n = repo.commit(text=newmessage, user=username,
260 date=max(ctx.date(), oldctx.date()), extra=oldctx.extra())
333 commitopts['message'] = newmessage
334 # date
335 commitopts['date'] = max(ctx.date(), oldctx.date())
336 n = collapse(repo, ctx, repo[newnode], commitopts)
337 if n is None:
338 return ctx, [], [], []
339 hg.update(repo, n)
261 340 return repo[n], [n], [oldctx.node(), ctx.node()], [newnode]
262 341
263 342 def drop(ui, repo, ctx, ha, opts):
@@ -92,6 +92,17 b' fix up'
92 92
93 93
94 94
95 HG: Enter commit message. Lines beginning with 'HG:' are removed.
96 HG: Leave message empty to abort commit.
97 HG: --
98 HG: user: test
99 HG: branch 'default'
100 HG: changed d
101 HG: changed e
102
103
104
105 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
95 106 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
96 107 file e already exists
97 108 1 out of 1 hunks FAILED -- saving rejects to file e.rej
@@ -66,6 +66,7 b' edit the history'
66 66 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
67 67 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
68 68 0 files updated, 0 files merged, 2 files removed, 0 files unresolved
69 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
69 70 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
70 71 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
71 72
@@ -232,6 +233,16 b' dropped revision.'
232 233 +5.2
233 234 ***
234 235 +6
236
237
238
239 HG: Enter commit message. Lines beginning with 'HG:' are removed.
240 HG: Leave message empty to abort commit.
241 HG: --
242 HG: user: test
243 HG: branch 'default'
244 HG: changed file
245 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
235 246 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
236 247 saved backup bundle to $TESTTMP/fold-with-dropped/.hg/strip-backup/617f94f13c0f-backup.hg (glob)
237 248 $ cd ..
General Comments 0
You need to be logged in to leave comments. Login now