##// 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 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
153 from mercurial import context
152 from mercurial import hg
154 from mercurial import hg
153 from mercurial import lock as lockmod
155 from mercurial import lock as lockmod
154 from mercurial import node
156 from mercurial import node
@@ -195,6 +197,76 b' def foldchanges(ui, repo, node1, node2, '
195 os.unlink(patchfile)
197 os.unlink(patchfile)
196 return files
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 def pick(ui, repo, ctx, ha, opts):
270 def pick(ui, repo, ctx, ha, opts):
199 oldctx = repo[ha]
271 oldctx = repo[ha]
200 if oldctx.parents()[0] == ctx:
272 if oldctx.parents()[0] == ctx:
@@ -245,19 +317,26 b' def fold(ui, repo, ctx, ha, opts):'
245 def finishfold(ui, repo, ctx, oldctx, newnode, opts, internalchanges):
317 def finishfold(ui, repo, ctx, oldctx, newnode, opts, internalchanges):
246 parent = ctx.parents()[0].node()
318 parent = ctx.parents()[0].node()
247 hg.update(repo, parent)
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 newmessage = '\n***\n'.join(
329 newmessage = '\n***\n'.join(
250 [ctx.description()] +
330 [ctx.description()] +
251 [repo[r].description() for r in internalchanges] +
331 [repo[r].description() for r in internalchanges] +
252 [oldctx.description()]) + '\n'
332 [oldctx.description()]) + '\n'
253 # If the changesets are from the same author, keep it.
333 commitopts['message'] = newmessage
254 if ctx.user() == oldctx.user():
334 # date
255 username = ctx.user()
335 commitopts['date'] = max(ctx.date(), oldctx.date())
256 else:
336 n = collapse(repo, ctx, repo[newnode], commitopts)
257 username = ui.username()
337 if n is None:
258 newmessage = ui.edit(newmessage, username)
338 return ctx, [], [], []
259 n = repo.commit(text=newmessage, user=username,
339 hg.update(repo, n)
260 date=max(ctx.date(), oldctx.date()), extra=oldctx.extra())
261 return repo[n], [n], [oldctx.node(), ctx.node()], [newnode]
340 return repo[n], [n], [oldctx.node(), ctx.node()], [newnode]
262
341
263 def drop(ui, repo, ctx, ha, opts):
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 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
106 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
96 file e already exists
107 file e already exists
97 1 out of 1 hunks FAILED -- saving rejects to file e.rej
108 1 out of 1 hunks FAILED -- saving rejects to file e.rej
@@ -66,6 +66,7 b' edit the history'
66 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
66 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
67 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
67 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
68 0 files updated, 0 files merged, 2 files removed, 0 files unresolved
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 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
70 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
70 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
71 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
71
72
@@ -232,6 +233,16 b' dropped revision.'
232 +5.2
233 +5.2
233 ***
234 ***
234 +6
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 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
246 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
236 saved backup bundle to $TESTTMP/fold-with-dropped/.hg/strip-backup/617f94f13c0f-backup.hg (glob)
247 saved backup bundle to $TESTTMP/fold-with-dropped/.hg/strip-backup/617f94f13c0f-backup.hg (glob)
237 $ cd ..
248 $ cd ..
General Comments 0
You need to be logged in to leave comments. Login now