Mercurial > hg
comparison hgext/histedit.py @ 17642:bea381c16809
histedit: move `between function` outside the action logic
Having this function in the middle of action and patching logic did not make
sense
author | Pierre-Yves David <pierre-yves.david@ens-lyon.org> |
---|---|
date | Fri, 21 Sep 2012 19:14:04 +0200 |
parents | 811a657fae48 |
children | 64e0f0cfb569 |
comparison
equal
deleted
inserted
replaced
17641:811a657fae48 | 17642:bea381c16809 |
---|---|
192 files = set() | 192 files = set() |
193 patch.patch(ui, repo, patchfile, files=files, eolmode=None) | 193 patch.patch(ui, repo, patchfile, files=files, eolmode=None) |
194 finally: | 194 finally: |
195 os.unlink(patchfile) | 195 os.unlink(patchfile) |
196 return files | 196 return files |
197 | |
198 def between(repo, old, new, keep): | |
199 """select and validate the set of revision to edit | |
200 | |
201 When keep is false, the specified set can't have children.""" | |
202 revs = [old] | |
203 current = old | |
204 while current != new: | |
205 ctx = repo[current] | |
206 if not keep and len(ctx.children()) > 1: | |
207 raise util.Abort(_('cannot edit history that would orphan nodes')) | |
208 if len(ctx.parents()) != 1 and ctx.parents()[1] != node.nullid: | |
209 raise util.Abort(_("can't edit history with merges")) | |
210 if not ctx.children(): | |
211 current = new | |
212 else: | |
213 current = ctx.children()[0].node() | |
214 revs.append(current) | |
215 if len(repo[current].children()) and not keep: | |
216 raise util.Abort(_('cannot edit history that would orphan nodes')) | |
217 return revs | |
218 | |
219 | 197 |
220 def pick(ui, repo, ctx, ha, opts): | 198 def pick(ui, repo, ctx, ha, opts): |
221 oldctx = repo[ha] | 199 oldctx = repo[ha] |
222 if oldctx.parents()[0] == ctx: | 200 if oldctx.parents()[0] == ctx: |
223 ui.debug('node %s unchanged\n' % ha) | 201 ui.debug('node %s unchanged\n' % ha) |
623 os.unlink(os.path.join(repo.path, 'histedit-state')) | 601 os.unlink(os.path.join(repo.path, 'histedit-state')) |
624 if os.path.exists(repo.sjoin('undo')): | 602 if os.path.exists(repo.sjoin('undo')): |
625 os.unlink(repo.sjoin('undo')) | 603 os.unlink(repo.sjoin('undo')) |
626 | 604 |
627 | 605 |
606 def between(repo, old, new, keep): | |
607 """select and validate the set of revision to edit | |
608 | |
609 When keep is false, the specified set can't have children.""" | |
610 revs = [old] | |
611 current = old | |
612 while current != new: | |
613 ctx = repo[current] | |
614 if not keep and len(ctx.children()) > 1: | |
615 raise util.Abort(_('cannot edit history that would orphan nodes')) | |
616 if len(ctx.parents()) != 1 and ctx.parents()[1] != node.nullid: | |
617 raise util.Abort(_("can't edit history with merges")) | |
618 if not ctx.children(): | |
619 current = new | |
620 else: | |
621 current = ctx.children()[0].node() | |
622 revs.append(current) | |
623 if len(repo[current].children()) and not keep: | |
624 raise util.Abort(_('cannot edit history that would orphan nodes')) | |
625 return revs | |
626 | |
627 | |
628 def writestate(repo, parentctxnode, created, replaced, | 628 def writestate(repo, parentctxnode, created, replaced, |
629 tmpnodes, existing, rules, keep, oldtip, replacemap): | 629 tmpnodes, existing, rules, keep, oldtip, replacemap): |
630 fp = open(os.path.join(repo.path, 'histedit-state'), 'w') | 630 fp = open(os.path.join(repo.path, 'histedit-state'), 'w') |
631 pickle.dump((parentctxnode, created, replaced, | 631 pickle.dump((parentctxnode, created, replaced, |
632 tmpnodes, existing, rules, keep, oldtip, replacemap), | 632 tmpnodes, existing, rules, keep, oldtip, replacemap), |