closehead.py
91 lines
| 2.6 KiB
| text/x-python
|
PythonLexer
/ hgext / closehead.py
Joerg Sonnenberger
|
r40029 | # 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 mercurial.i18n import _ | ||||
from mercurial import ( | ||||
bookmarks, | ||||
cmdutil, | ||||
context, | ||||
error, | ||||
Martin von Zweigbergk
|
r48930 | logcmdutil, | ||
Joerg Sonnenberger
|
r40029 | 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. | ||||
Augie Fackler
|
r43347 | testedwith = b'ships-with-hg-core' | ||
Joerg Sonnenberger
|
r40029 | |||
commitopts = cmdutil.commitopts | ||||
commitopts2 = cmdutil.commitopts2 | ||||
Augie Fackler
|
r43347 | commitopts3 = [(b'r', b'rev', [], _(b'revision to check'), _(b'REV'))] | ||
Augie Fackler
|
r43346 | |||
Joerg Sonnenberger
|
r40029 | |||
Augie Fackler
|
r43346 | @command( | ||
Augie Fackler
|
r43347 | b'close-head|close-heads', | ||
Augie Fackler
|
r43346 | commitopts + commitopts2 + commitopts3, | ||
Augie Fackler
|
r43347 | _(b'[OPTION]... [REV]...'), | ||
rdamazio@google.com
|
r40329 | helpcategory=command.CATEGORY_CHANGE_MANAGEMENT, | ||
Augie Fackler
|
r43346 | inferrepo=True, | ||
) | ||||
Joerg Sonnenberger
|
r40029 | 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. | ||||
""" | ||||
Augie Fackler
|
r43346 | |||
Joerg Sonnenberger
|
r40029 | def docommit(rev): | ||
Augie Fackler
|
r43346 | cctx = context.memctx( | ||
repo, | ||||
parents=[rev, None], | ||||
text=message, | ||||
files=[], | ||||
filectxfn=None, | ||||
Matt Harbison
|
r51766 | user=opts.get('user'), | ||
date=opts.get('date'), | ||||
Augie Fackler
|
r43346 | extra=extra, | ||
) | ||||
Matt Harbison
|
r51767 | with repo.transaction(b'commit'): | ||
ret = repo.commitctx(cctx, True) | ||||
bookmarks.update(repo, [rev, None], ret) | ||||
cctx.markcommitted(ret) | ||||
Joerg Sonnenberger
|
r40029 | |||
Matt Harbison
|
r51766 | revs += tuple(opts.get('rev', [])) | ||
Martin von Zweigbergk
|
r48928 | revs = logcmdutil.revrange(repo, revs) | ||
Joerg Sonnenberger
|
r40029 | |||
if not revs: | ||||
Augie Fackler
|
r43347 | raise error.Abort(_(b'no revisions specified')) | ||
Joerg Sonnenberger
|
r40029 | |||
heads = [] | ||||
for branch in repo.branchmap(): | ||||
heads.extend(repo.branchheads(branch)) | ||||
Augie Fackler
|
r44937 | heads = {repo[h].rev() for h in heads} | ||
Joerg Sonnenberger
|
r40029 | for rev in revs: | ||
if rev not in heads: | ||||
Augie Fackler
|
r43347 | raise error.Abort(_(b'revision is not an open head: %d') % rev) | ||
Joerg Sonnenberger
|
r40029 | |||
Matt Harbison
|
r51766 | message = cmdutil.logmessage(ui, pycompat.byteskwargs(opts)) | ||
Joerg Sonnenberger
|
r40029 | if not message: | ||
Augie Fackler
|
r43347 | raise error.Abort(_(b"no commit message specified with -l or -m")) | ||
extra = {b'close': b'1'} | ||||
Joerg Sonnenberger
|
r40029 | |||
with repo.wlock(), repo.lock(): | ||||
for rev in revs: | ||||
r = repo[rev] | ||||
branch = r.branch() | ||||
Augie Fackler
|
r43347 | extra[b'branch'] = branch | ||
Joerg Sonnenberger
|
r40029 | docommit(r) | ||
return 0 | ||||