From patchwork Tue Aug 29 03:05:08 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: D464: commit: use an unambiguous path suffix for the commit editor file From: phabricator X-Patchwork-Id: 23455 Message-Id: <6371f961385cc3fc98e6d8309160445c@localhost.localdomain> To: mercurial-devel@mercurial-scm.org Date: Tue, 29 Aug 2017 03:05:08 +0000 mbolin updated this revision to Diff 1380. mbolin added a comment. Created optional action param as suggested by @durin42 REPOSITORY rHG Mercurial CHANGES SINCE LAST UPDATE https://phab.mercurial-scm.org/D464?vs=1130&id=1380 BRANCH default REVISION DETAIL https://phab.mercurial-scm.org/D464 AFFECTED FILES hgext/histedit.py hgext/patchbomb.py mercurial/cmdutil.py mercurial/crecord.py mercurial/ui.py CHANGE DETAILS To: mbolin, quark, durin42, #hg-reviewers, ryanmce Cc: smf, ryanmce, mercurial-devel diff --git a/mercurial/ui.py b/mercurial/ui.py --- a/mercurial/ui.py +++ b/mercurial/ui.py @@ -1345,20 +1345,31 @@ self.write(*msg, **opts) def edit(self, text, user, extra=None, editform=None, pending=None, - repopath=None): + repopath=None, action=None): + if action is None: + self.develwarn('action is None but will soon be a required ' + 'parameter to ui.edit()') extra_defaults = { 'prefix': 'editor', 'suffix': '.txt', } if extra is not None: + if extra.get('suffix') is not None: + self.develwarn('extra.suffix is not None but will soon be ' + 'ignored by ui.edit()') extra_defaults.update(extra) extra = extra_defaults + if action: + suffix = '.hg%s.txt' % action + else: + suffix = extra['suffix'] + rdir = None if self.configbool('experimental', 'editortmpinhg'): rdir = repopath (fd, name) = tempfile.mkstemp(prefix='hg-' + extra['prefix'] + '-', - suffix=extra['suffix'], + suffix=suffix, dir=rdir) try: f = os.fdopen(fd, r'wb') diff --git a/mercurial/crecord.py b/mercurial/crecord.py --- a/mercurial/crecord.py +++ b/mercurial/crecord.py @@ -1553,7 +1553,7 @@ # start the editor and wait for it to complete try: patch = self.ui.edit(patch.getvalue(), "", - extra={"suffix": ".diff"}) + action=".diff") except error.Abort as exc: self.errorstr = str(exc) return None diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py --- a/mercurial/cmdutil.py +++ b/mercurial/cmdutil.py @@ -339,7 +339,7 @@ + crecordmod.patchhelptext + fp.read()) reviewedpatch = ui.edit(patchtext, "", - extra={"suffix": ".diff"}, + action="diff", repopath=repo.path) fp.truncate(0) fp.write(reviewedpatch) @@ -3215,7 +3215,7 @@ editortext = repo.ui.edit(committext, ctx.user(), ctx.extra(), editform=editform, pending=pending, - repopath=repo.path) + repopath=repo.path, action='commit') text = editortext # strip away anything below this special string (used for editors that want diff --git a/hgext/patchbomb.py b/hgext/patchbomb.py --- a/hgext/patchbomb.py +++ b/hgext/patchbomb.py @@ -308,7 +308,8 @@ else: ui.write(_('\nWrite the introductory message for the ' 'patch series.\n\n')) - body = ui.edit(defaultbody, sender, repopath=repo.path) + body = ui.edit(defaultbody, sender, repopath=repo.path, + action='patchbombbody') # Save series description in case sendmail fails msgfile = repo.vfs('last-email.txt', 'wb') msgfile.write(body) diff --git a/hgext/histedit.py b/hgext/histedit.py --- a/hgext/histedit.py +++ b/hgext/histedit.py @@ -1370,7 +1370,7 @@ rules += '\n\n' rules += editcomment rules = ui.edit(rules, ui.username(), {'prefix': 'histedit'}, - repopath=repo.path) + repopath=repo.path, action='histedit') # Save edit rules in .hg/histedit-last-edit.txt in case # the user needs to ask for help after something