Mercurial > hg
view hgext/closehead.py @ 48185:2f2107c01dee
dispatch: ignore failure to flush ui
When the pager dies, we get a `SIGPIPE`. That causes
`error.SignalInterrupt` to be raised ` (from `ui._catchterm()`). Any
further writes or flushes will cause further `SIGPIPE`s and furhter
`error.SignalInterrupt`. If we write or flush outside of the
try/except that handle `KeyboardInterrupt` (which
`error.SignalInterrupt` is a subclass of), then control will escape
from the `dispatch` module. Let's fix that by ignoring errors from
flushing the ui.
I would have rather fixed this by restoring the stdout and stderr
streams when the pager dies, but it gets complicated because of
multiple ui instances (ui/lui) and different pager setups between
regular hg and chg.
This changes a test in `test-pager.t`, but I don't understand why. I
would have thought that all the output from the command should have
gone to the broken pager.
Differential Revision: https://phab.mercurial-scm.org/D11627
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Fri, 08 Oct 2021 13:36:02 -0700 |
parents | 5105a9975407 |
children | 6000f5b25c9b |
line wrap: on
line source
# closehead.py - Close arbitrary heads without checking them out first # # This software may be used and distributed according to the terms of the # GNU General Public License version 2 or any later version. '''close arbitrary heads without checking them out first''' from __future__ import absolute_import from mercurial.i18n import _ from mercurial import ( bookmarks, cmdutil, context, error, logcmdutil, pycompat, registrar, ) cmdtable = {} command = registrar.command(cmdtable) # Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should # be specifying the version(s) of Mercurial they are tested with, or # leave the attribute unspecified. testedwith = b'ships-with-hg-core' commitopts = cmdutil.commitopts commitopts2 = cmdutil.commitopts2 commitopts3 = [(b'r', b'rev', [], _(b'revision to check'), _(b'REV'))] @command( b'close-head|close-heads', commitopts + commitopts2 + commitopts3, _(b'[OPTION]... [REV]...'), helpcategory=command.CATEGORY_CHANGE_MANAGEMENT, inferrepo=True, ) def close_branch(ui, repo, *revs, **opts): """close the given head revisions This is equivalent to checking out each revision in a clean tree and running ``hg commit --close-branch``, except that it doesn't change the working directory. The commit message must be specified with -l or -m. """ def docommit(rev): cctx = context.memctx( repo, parents=[rev, None], text=message, files=[], filectxfn=None, user=opts.get(b'user'), date=opts.get(b'date'), extra=extra, ) tr = repo.transaction(b'commit') ret = repo.commitctx(cctx, True) bookmarks.update(repo, [rev, None], ret) cctx.markcommitted(ret) tr.close() opts = pycompat.byteskwargs(opts) revs += tuple(opts.get(b'rev', [])) revs = logcmdutil.revrange(repo, revs) if not revs: raise error.Abort(_(b'no revisions specified')) heads = [] for branch in repo.branchmap(): heads.extend(repo.branchheads(branch)) heads = {repo[h].rev() for h in heads} for rev in revs: if rev not in heads: raise error.Abort(_(b'revision is not an open head: %d') % rev) message = cmdutil.logmessage(ui, opts) if not message: raise error.Abort(_(b"no commit message specified with -l or -m")) extra = {b'close': b'1'} with repo.wlock(), repo.lock(): for rev in revs: r = repo[rev] branch = r.branch() extra[b'branch'] = branch docommit(r) return 0