Mercurial > hg
comparison hgext/histedit.py @ 38548:7b57b1ed5c0f
histedit: add --no-backup option (issue5825)
This option provides a functionality to not store a backup
while aborting histedit in between. Also added tests for the
same.
Differential Revision: https://phab.mercurial-scm.org/D3872
author | Sushil khanchi <sushilkhanchi97@gmail.com> |
---|---|
date | Fri, 22 Jun 2018 23:53:43 +0530 |
parents | 39db5a01cd53 |
children | 88e6630dc8d0 |
comparison
equal
deleted
inserted
replaced
38547:404eab7ff33f | 38548:7b57b1ed5c0f |
---|---|
923 ('', 'edit-plan', False, _('edit remaining actions list')), | 923 ('', 'edit-plan', False, _('edit remaining actions list')), |
924 ('k', 'keep', False, | 924 ('k', 'keep', False, |
925 _("don't strip old nodes after edit is complete")), | 925 _("don't strip old nodes after edit is complete")), |
926 ('', 'abort', False, _('abort an edit in progress')), | 926 ('', 'abort', False, _('abort an edit in progress')), |
927 ('o', 'outgoing', False, _('changesets not found in destination')), | 927 ('o', 'outgoing', False, _('changesets not found in destination')), |
928 ('', 'no-backup', False, _('no backup')), | |
928 ('f', 'force', False, | 929 ('f', 'force', False, |
929 _('force outgoing even for unrelated repositories')), | 930 _('force outgoing even for unrelated repositories')), |
930 ('r', 'rev', [], _('first revision to be edited'), _('REV'))] + | 931 ('r', 'rev', [], _('first revision to be edited'), _('REV'))] + |
931 cmdutil.formatteropts, | 932 cmdutil.formatteropts, |
932 _("[OPTIONS] ([ANCESTOR] | --outgoing [URL])")) | 933 _("[OPTIONS] ([ANCESTOR] | --outgoing [URL])")) |
1108 opts = pycompat.byteskwargs(opts) | 1109 opts = pycompat.byteskwargs(opts) |
1109 fm = ui.formatter('histedit', opts) | 1110 fm = ui.formatter('histedit', opts) |
1110 fm.startitem() | 1111 fm.startitem() |
1111 goal = _getgoal(opts) | 1112 goal = _getgoal(opts) |
1112 revs = opts.get('rev', []) | 1113 revs = opts.get('rev', []) |
1114 nobackup = opts.get('no_backup') | |
1113 rules = opts.get('commands', '') | 1115 rules = opts.get('commands', '') |
1114 state.keep = opts.get('keep', False) | 1116 state.keep = opts.get('keep', False) |
1115 | 1117 |
1116 _validateargs(ui, repo, state, freeargs, opts, goal, rules, revs) | 1118 _validateargs(ui, repo, state, freeargs, opts, goal, rules, revs) |
1117 | 1119 |
1121 state = bootstrapcontinue(ui, state, opts) | 1123 state = bootstrapcontinue(ui, state, opts) |
1122 elif goal == goaleditplan: | 1124 elif goal == goaleditplan: |
1123 _edithisteditplan(ui, repo, state, rules) | 1125 _edithisteditplan(ui, repo, state, rules) |
1124 return | 1126 return |
1125 elif goal == goalabort: | 1127 elif goal == goalabort: |
1126 _aborthistedit(ui, repo, state) | 1128 _aborthistedit(ui, repo, state, nobackup=nobackup) |
1127 return | 1129 return |
1128 else: | 1130 else: |
1129 # goal == goalnew | 1131 # goal == goalnew |
1130 _newhistedit(ui, repo, state, revs, freeargs, opts) | 1132 _newhistedit(ui, repo, state, revs, freeargs, opts) |
1131 | 1133 |
1219 if os.path.exists(repo.sjoin('undo')): | 1221 if os.path.exists(repo.sjoin('undo')): |
1220 os.unlink(repo.sjoin('undo')) | 1222 os.unlink(repo.sjoin('undo')) |
1221 if repo.vfs.exists('histedit-last-edit.txt'): | 1223 if repo.vfs.exists('histedit-last-edit.txt'): |
1222 repo.vfs.unlink('histedit-last-edit.txt') | 1224 repo.vfs.unlink('histedit-last-edit.txt') |
1223 | 1225 |
1224 def _aborthistedit(ui, repo, state): | 1226 def _aborthistedit(ui, repo, state, nobackup=False): |
1225 try: | 1227 try: |
1226 state.read() | 1228 state.read() |
1227 __, leafs, tmpnodes, __ = processreplacement(state) | 1229 __, leafs, tmpnodes, __ = processreplacement(state) |
1228 ui.debug('restore wc to old parent %s\n' | 1230 ui.debug('restore wc to old parent %s\n' |
1229 % node.short(state.topmost)) | 1231 % node.short(state.topmost)) |
1241 | 1243 |
1242 # check whether we should update away | 1244 # check whether we should update away |
1243 if repo.unfiltered().revs('parents() and (%n or %ln::)', | 1245 if repo.unfiltered().revs('parents() and (%n or %ln::)', |
1244 state.parentctxnode, leafs | tmpnodes): | 1246 state.parentctxnode, leafs | tmpnodes): |
1245 hg.clean(repo, state.topmost, show_stats=True, quietempty=True) | 1247 hg.clean(repo, state.topmost, show_stats=True, quietempty=True) |
1246 cleanupnode(ui, repo, tmpnodes) | 1248 cleanupnode(ui, repo, tmpnodes, nobackup=nobackup) |
1247 cleanupnode(ui, repo, leafs) | 1249 cleanupnode(ui, repo, leafs, nobackup=nobackup) |
1248 except Exception: | 1250 except Exception: |
1249 if state.inprogress(): | 1251 if state.inprogress(): |
1250 ui.warn(_('warning: encountered an exception during histedit ' | 1252 ui.warn(_('warning: encountered an exception during histedit ' |
1251 '--abort; the repository may not have been completely ' | 1253 '--abort; the repository may not have been completely ' |
1252 'cleaned up\n')) | 1254 'cleaned up\n')) |
1599 changes = [] | 1601 changes = [] |
1600 for name in oldbmarks: | 1602 for name in oldbmarks: |
1601 changes.append((name, newtopmost)) | 1603 changes.append((name, newtopmost)) |
1602 marks.applychanges(repo, tr, changes) | 1604 marks.applychanges(repo, tr, changes) |
1603 | 1605 |
1604 def cleanupnode(ui, repo, nodes): | 1606 def cleanupnode(ui, repo, nodes, nobackup=False): |
1605 """strip a group of nodes from the repository | 1607 """strip a group of nodes from the repository |
1606 | 1608 |
1607 The set of node to strip may contains unknown nodes.""" | 1609 The set of node to strip may contains unknown nodes.""" |
1608 with repo.lock(): | 1610 with repo.lock(): |
1609 # do not let filtering get in the way of the cleanse | 1611 # do not let filtering get in the way of the cleanse |
1614 # (we use %lr instead of %ln to silently ignore unknown items) | 1616 # (we use %lr instead of %ln to silently ignore unknown items) |
1615 nm = repo.changelog.nodemap | 1617 nm = repo.changelog.nodemap |
1616 nodes = sorted(n for n in nodes if n in nm) | 1618 nodes = sorted(n for n in nodes if n in nm) |
1617 roots = [c.node() for c in repo.set("roots(%ln)", nodes)] | 1619 roots = [c.node() for c in repo.set("roots(%ln)", nodes)] |
1618 if roots: | 1620 if roots: |
1619 repair.strip(ui, repo, roots) | 1621 backup = not nobackup |
1622 repair.strip(ui, repo, roots, backup=backup) | |
1620 | 1623 |
1621 def stripwrapper(orig, ui, repo, nodelist, *args, **kwargs): | 1624 def stripwrapper(orig, ui, repo, nodelist, *args, **kwargs): |
1622 if isinstance(nodelist, str): | 1625 if isinstance(nodelist, str): |
1623 nodelist = [nodelist] | 1626 nodelist = [nodelist] |
1624 if os.path.exists(os.path.join(repo.path, 'histedit-state')): | 1627 if os.path.exists(os.path.join(repo.path, 'histedit-state')): |