Mercurial > hg
comparison hgext/histedit.py @ 35126:a9cc233de513
histedit: add support to output nodechanges using formatter
The JSON output of nodechanges will help in automation and to improve editor
integrations such as for Nuclide.
Differential Revision: https://phab.mercurial-scm.org/D1348
author | Pulkit Goyal <7895pulkit@gmail.com> |
---|---|
date | Sat, 28 Oct 2017 19:03:23 +0530 |
parents | c4b769bc86da |
children | 8a0cac20a1ad |
comparison
equal
deleted
inserted
replaced
35125:f56a30b844aa | 35126:a9cc233de513 |
---|---|
915 _("don't strip old nodes after edit is complete")), | 915 _("don't strip old nodes after edit is complete")), |
916 ('', 'abort', False, _('abort an edit in progress')), | 916 ('', 'abort', False, _('abort an edit in progress')), |
917 ('o', 'outgoing', False, _('changesets not found in destination')), | 917 ('o', 'outgoing', False, _('changesets not found in destination')), |
918 ('f', 'force', False, | 918 ('f', 'force', False, |
919 _('force outgoing even for unrelated repositories')), | 919 _('force outgoing even for unrelated repositories')), |
920 ('r', 'rev', [], _('first revision to be edited'), _('REV'))], | 920 ('r', 'rev', [], _('first revision to be edited'), _('REV'))] + |
921 cmdutil.formatteropts, | |
921 _("[OPTIONS] ([ANCESTOR] | --outgoing [URL])")) | 922 _("[OPTIONS] ([ANCESTOR] | --outgoing [URL])")) |
922 def histedit(ui, repo, *freeargs, **opts): | 923 def histedit(ui, repo, *freeargs, **opts): |
923 """interactively edit changeset history | 924 """interactively edit changeset history |
924 | 925 |
925 This command lets you edit a linear series of changesets (up to | 926 This command lets you edit a linear series of changesets (up to |
1093 raise error.Abort( | 1094 raise error.Abort( |
1094 _('histedit requires exactly one ancestor revision')) | 1095 _('histedit requires exactly one ancestor revision')) |
1095 | 1096 |
1096 def _histedit(ui, repo, state, *freeargs, **opts): | 1097 def _histedit(ui, repo, state, *freeargs, **opts): |
1097 opts = pycompat.byteskwargs(opts) | 1098 opts = pycompat.byteskwargs(opts) |
1099 fm = ui.formatter('histedit', opts) | |
1100 fm.startitem() | |
1098 goal = _getgoal(opts) | 1101 goal = _getgoal(opts) |
1099 revs = opts.get('rev', []) | 1102 revs = opts.get('rev', []) |
1100 rules = opts.get('commands', '') | 1103 rules = opts.get('commands', '') |
1101 state.keep = opts.get('keep', False) | 1104 state.keep = opts.get('keep', False) |
1102 | 1105 |
1115 else: | 1118 else: |
1116 # goal == goalnew | 1119 # goal == goalnew |
1117 _newhistedit(ui, repo, state, revs, freeargs, opts) | 1120 _newhistedit(ui, repo, state, revs, freeargs, opts) |
1118 | 1121 |
1119 _continuehistedit(ui, repo, state) | 1122 _continuehistedit(ui, repo, state) |
1120 _finishhistedit(ui, repo, state) | 1123 _finishhistedit(ui, repo, state, fm) |
1124 fm.end() | |
1121 | 1125 |
1122 def _continuehistedit(ui, repo, state): | 1126 def _continuehistedit(ui, repo, state): |
1123 """This function runs after either: | 1127 """This function runs after either: |
1124 - bootstrapcontinue (if the goal is 'continue') | 1128 - bootstrapcontinue (if the goal is 'continue') |
1125 - _newhistedit (if the goal is 'new') | 1129 - _newhistedit (if the goal is 'new') |
1162 state.actions.pop(0) | 1166 state.actions.pop(0) |
1163 | 1167 |
1164 state.write() | 1168 state.write() |
1165 ui.progress(_("editing"), None) | 1169 ui.progress(_("editing"), None) |
1166 | 1170 |
1167 def _finishhistedit(ui, repo, state): | 1171 def _finishhistedit(ui, repo, state, fm): |
1168 """This action runs when histedit is finishing its session""" | 1172 """This action runs when histedit is finishing its session""" |
1169 repo.ui.pushbuffer() | 1173 repo.ui.pushbuffer() |
1170 hg.update(repo, state.parentctxnode, quietempty=True) | 1174 hg.update(repo, state.parentctxnode, quietempty=True) |
1171 repo.ui.popbuffer() | 1175 repo.ui.popbuffer() |
1172 | 1176 |
1196 # remove entries about unknown nodes | 1200 # remove entries about unknown nodes |
1197 nodemap = repo.unfiltered().changelog.nodemap | 1201 nodemap = repo.unfiltered().changelog.nodemap |
1198 mapping = {k: v for k, v in mapping.items() | 1202 mapping = {k: v for k, v in mapping.items() |
1199 if k in nodemap and all(n in nodemap for n in v)} | 1203 if k in nodemap and all(n in nodemap for n in v)} |
1200 scmutil.cleanupnodes(repo, mapping, 'histedit') | 1204 scmutil.cleanupnodes(repo, mapping, 'histedit') |
1205 hf = fm.hexfunc | |
1206 fl = fm.formatlist | |
1207 fd = fm.formatdict | |
1208 nodechanges = fd({hf(oldn): fl([hf(n) for n in newn], name='node') | |
1209 for oldn, newn in mapping.iteritems()}, | |
1210 key="oldnode", value="newnodes") | |
1211 fm.data(nodechanges=nodechanges) | |
1201 | 1212 |
1202 state.clear() | 1213 state.clear() |
1203 if os.path.exists(repo.sjoin('undo')): | 1214 if os.path.exists(repo.sjoin('undo')): |
1204 os.unlink(repo.sjoin('undo')) | 1215 os.unlink(repo.sjoin('undo')) |
1205 if repo.vfs.exists('histedit-last-edit.txt'): | 1216 if repo.vfs.exists('histedit-last-edit.txt'): |