##// END OF EJS Templates
phabricator: combine commit messages into the review when folding commits...
phabricator: combine commit messages into the review when folding commits No visible changes here, until an option to enable it is added to `phabsend`. This combines the Differential fields like Arcanist does, rather than simply concatenating the text blocks. Aside from populating everything properly in the web interface, Phabricator fails the review create/update if repeated fields are seen as would happen with simple concatenation. On the flip side, now that the Summary and Test Plan fields can contain data from multiple commits, we can't just join these fields together to determine if an amend is needed. If that were to happen, every single commit in the folded range would get amended with the combined commit message, which seems clearly wrong. Aside from making a minor assumption about the content of the Differential Revision field (it seems they allow some minor variances with spacing), this means that for folded reviews, you can't post it, go to the web page add a missing Test Plan, and then get it added to the commit message by re-posting it. I don't think that's a big deal. Differential Revision: https://phab.mercurial-scm.org/D8309

File last commit:

r43812:2fe6121c default
r45134:dbe9182c default
Show More
bookflow.py
126 lines | 3.7 KiB | text/x-python | PythonLexer
bookflow: new extension for bookmark-based branching...
r40869 """implements bookmark-based branching (EXPERIMENTAL)
- Disables creation of new branches (config: enable_branches=False).
- Requires an active bookmark on commit (config: require_bookmark=True).
- Doesn't move the active bookmark on update, only on commit.
- Requires '--rev' for moving an existing bookmark.
- Protects special bookmarks (config: protect=@).
flow related commands
:hg book NAME: create a new bookmark
:hg book NAME -r REV: move bookmark to revision (fast-forward)
:hg up|co NAME: switch to bookmark
:hg push -B .: push active bookmark
"""
from __future__ import absolute_import
from mercurial.i18n import _
from mercurial import (
bookmarks,
commands,
error,
extensions,
registrar,
)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 MY_NAME = b'bookflow'
bookflow: new extension for bookmark-based branching...
r40869
configtable = {}
configitem = registrar.configitem(configtable)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 configitem(MY_NAME, b'protect', [b'@'])
configitem(MY_NAME, b'require-bookmark', True)
configitem(MY_NAME, b'enable-branches', False)
bookflow: new extension for bookmark-based branching...
r40869
cmdtable = {}
command = registrar.command(cmdtable)
Augie Fackler
formatting: blacken the codebase...
r43346
bookflow: new extension for bookmark-based branching...
r40869 def commit_hook(ui, repo, **kwargs):
active = repo._bookmarks.active
if active:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if active in ui.configlist(MY_NAME, b'protect'):
bookflow: new extension for bookmark-based branching...
r40869 raise error.Abort(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 _(b'cannot commit, bookmark %s is protected') % active
Augie Fackler
formatting: blacken the codebase...
r43346 )
bookflow: new extension for bookmark-based branching...
r40869 if not cwd_at_bookmark(repo, active):
raise error.Abort(
Augie Fackler
formatting: blacken the codebase...
r43346 _(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'cannot commit, working directory out of sync with active bookmark'
Augie Fackler
formatting: blacken the codebase...
r43346 ),
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 hint=_(b"run 'hg up %s'") % active,
Augie Fackler
formatting: blacken the codebase...
r43346 )
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 elif ui.configbool(MY_NAME, b'require-bookmark', True):
raise error.Abort(_(b'cannot commit without an active bookmark'))
bookflow: new extension for bookmark-based branching...
r40869 return 0
Augie Fackler
formatting: blacken the codebase...
r43346
bookflow: new extension for bookmark-based branching...
r40869 def bookmarks_update(orig, repo, parents, node):
if len(parents) == 2:
# called during commit
return orig(repo, parents, node)
else:
# called during update
return False
Augie Fackler
formatting: blacken the codebase...
r43346
bookflow: new extension for bookmark-based branching...
r40869 def bookmarks_addbookmarks(
Augie Fackler
formatting: blacken the codebase...
r43346 orig, repo, tr, names, rev=None, force=False, inactive=False
):
bookflow: new extension for bookmark-based branching...
r40869 if not rev:
marks = repo._bookmarks
for name in names:
if name in marks:
Augie Fackler
formatting: blacken the codebase...
r43346 raise error.Abort(
_(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b"bookmark %s already exists, to move use the --rev option"
Augie Fackler
formatting: blacken the codebase...
r43346 )
% name
)
bookflow: new extension for bookmark-based branching...
r40869 return orig(repo, tr, names, rev, force, inactive)
Augie Fackler
formatting: blacken the codebase...
r43346
bookflow: new extension for bookmark-based branching...
r40869 def commands_commit(orig, ui, repo, *args, **opts):
commit_hook(ui, repo)
return orig(ui, repo, *args, **opts)
Augie Fackler
formatting: blacken the codebase...
r43346
bookflow: new extension for bookmark-based branching...
r40869 def commands_pull(orig, ui, repo, *args, **opts):
rc = orig(ui, repo, *args, **opts)
active = repo._bookmarks.active
if active and not cwd_at_bookmark(repo, active):
Augie Fackler
formatting: blacken the codebase...
r43346 ui.warn(
_(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b"working directory out of sync with active bookmark, run "
b"'hg up %s'"
Augie Fackler
formatting: blacken the codebase...
r43346 )
% active
)
bookflow: new extension for bookmark-based branching...
r40869 return rc
Augie Fackler
formatting: blacken the codebase...
r43346
bookflow: new extension for bookmark-based branching...
r40869 def commands_branch(orig, ui, repo, label=None, **opts):
Augie Fackler
cleanup: remove pointless r-prefixes on single-quoted strings...
r43906 if label and not opts.get('clean') and not opts.get('rev'):
bookflow: new extension for bookmark-based branching...
r40869 raise error.Abort(
Augie Fackler
formatting: blacken the codebase...
r43346 _(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b"creating named branches is disabled and you should use bookmarks"
Augie Fackler
formatting: blacken the codebase...
r43346 ),
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 hint=b"see 'hg help bookflow'",
Augie Fackler
formatting: blacken the codebase...
r43346 )
bookflow: new extension for bookmark-based branching...
r40869 return orig(ui, repo, label, **opts)
Augie Fackler
formatting: blacken the codebase...
r43346
bookflow: new extension for bookmark-based branching...
r40869 def cwd_at_bookmark(repo, mark):
mark_id = repo._bookmarks[mark]
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 cur_id = repo.lookup(b'.')
bookflow: new extension for bookmark-based branching...
r40869 return cur_id == mark_id
Augie Fackler
formatting: blacken the codebase...
r43346
bookflow: new extension for bookmark-based branching...
r40869 def uisetup(ui):
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 extensions.wrapfunction(bookmarks, b'update', bookmarks_update)
extensions.wrapfunction(bookmarks, b'addbookmarks', bookmarks_addbookmarks)
extensions.wrapcommand(commands.table, b'commit', commands_commit)
extensions.wrapcommand(commands.table, b'pull', commands_pull)
if not ui.configbool(MY_NAME, b'enable-branches'):
extensions.wrapcommand(commands.table, b'branch', commands_branch)