Mercurial > hg
view hgext/closehead.py @ 42618:c17e6a3e7356
phabricator: handle local:commits time being string or int
When setting local:commits arcanist has different behaviour depending on
whether the repo is git or hg. With hg it sets the time as a number, since it
calls PHP's strtotime on the value, but with git it sets it as a string.
Normally this wouldn't be an issue since phabread wouldn't be interacting with
Phabricator Revisions for git repos, but Mozilla has a secondary workflow for
git users that uses the git-cinnabar tool to interact with their hg repos. When
a git-cinnabar user uses the moz-phab tool to submit patches for mozilla-central
it makes use of Mozilla's fork of arcanist, which works with their local git
version of m-c, and thus sets the local:commit time as a string, and then
translates the commit hashes.
Currently when encountering such DREVS phabread dies with "TypeError: %d format:
a number is required, not str".
phabsend also used to set it as a string but wouldn't have encountered the
issue with its own DREVs since it would read hg:meta first.
Differential Revision: https://phab.mercurial-scm.org/D6650
author | Ian Moody <moz-ian@perix.co.uk> |
---|---|
date | Tue, 16 Jul 2019 19:18:16 +0100 |
parents | c303d65d2e34 |
children | 2372284d9457 |
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, pycompat, registrar, scmutil, ) 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 = 'ships-with-hg-core' commitopts = cmdutil.commitopts commitopts2 = cmdutil.commitopts2 commitopts3 = [('r', 'rev', [], _('revision to check'), _('REV'))] @command('close-head|close-heads', commitopts + commitopts2 + commitopts3, _('[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('user'), date=opts.get('date'), extra=extra) tr = repo.transaction('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('rev', [])) revs = scmutil.revrange(repo, revs) if not revs: raise error.Abort(_('no revisions specified')) heads = [] for branch in repo.branchmap(): heads.extend(repo.branchheads(branch)) heads = set(repo[h].rev() for h in heads) for rev in revs: if rev not in heads: raise error.Abort(_('revision is not an open head: %d') % rev) message = cmdutil.logmessage(ui, opts) if not message: raise error.Abort(_("no commit message specified with -l or -m")) extra = { 'close': '1' } with repo.wlock(), repo.lock(): for rev in revs: r = repo[rev] branch = r.branch() extra['branch'] = branch docommit(r) return 0