mirror of
https://github.com/facebook/sapling.git
synced 2024-10-16 11:52:02 +03:00
584656dff3
Summary: Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`. Then run `arc lint` again so some other autofixers like spellchecker etc. looked at the code base. Manually accept the changes whenever they make sense, or use a workaround (ex. changing "dict()" to "dict constructor") where autofix is false positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less interesting to fix (hgsubversion tests), or cannot be fixed without breaking OSS build (FBPYTHON4). Conflicted linters (test-check-module-imports.t, part of test-check-code.t, test-check-pyflakes.t) are removed or disabled. Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed. An issue of the auto-formatter is lines are no longer guarnateed to be <= 80 chars. But that seems less important comparing with the benefit auto-formatter provides. As we're here, also remove test-check-py3-compat.t, as it is currently broken if `PYTHON3=/bin/python3` is set. Reviewed By: wez, phillco, simpkins, pkaush, singhsrb Differential Revision: D8173629 fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
105 lines
3.2 KiB
Python
105 lines
3.2 KiB
Python
# myparent.py
|
|
#
|
|
# Copyright 2016 Facebook, Inc.
|
|
#
|
|
# This software may be used and distributed according to the terms of the
|
|
# GNU General Public License version 2 or any later version.
|
|
|
|
"""
|
|
myparent.py - Commit template keywords based on your previous commit
|
|
|
|
If your diff stacks are comprised of related diffs, many commits will share the
|
|
same reviewers, tasks and even the title prefix. With this extension, mercurial
|
|
can prefill the relevant fields based on your previous commit in the stack.
|
|
|
|
The extension adds five new keywords:
|
|
|
|
- *myparentdiff* the diff number of the parent commit
|
|
- *myparentreviewers* the reviewers of the parent commit
|
|
- *myparentsubscribers* the subscribers of the parent commit
|
|
- *myparenttasks* the tasks of the parent commit
|
|
- *myparenttitleprefix* the prefix as defined by [] of the parent commit.
|
|
E.g. '[e2e automation] foo bar' -> '[e2e automation]'
|
|
|
|
After enabling the extension, change the default commit template:
|
|
|
|
::
|
|
|
|
[committemplate]
|
|
emptymsg={myparenttitleprefix}
|
|
Summary: {myparentdiff}
|
|
Test Plan:
|
|
Reviewers: {myparentreviewers}
|
|
Subscribers: {myparentsubscribers}
|
|
Tasks: {myparenttasks}
|
|
Blame Revision:
|
|
|
|
In some (all?) repositories at Facebook the commit template is overridden at
|
|
the repository level. If that is the case, add the line above to the `.hg/hgrc`
|
|
file inside the repository (e.g. ~/www/.hg/hgrc).
|
|
"""
|
|
|
|
import re
|
|
|
|
from mercurial import registrar
|
|
|
|
|
|
templatekeyword = registrar.templatekeyword()
|
|
|
|
|
|
@templatekeyword("myparentdiff")
|
|
def showmyparentdiff(repo, ctx, templ, **args):
|
|
"""Show the differential revision of the commit's parent, if it has the
|
|
same author as this commit.
|
|
"""
|
|
return extract_from_parent(ctx, "Differential Revision:.*/(D\d+)")
|
|
|
|
|
|
@templatekeyword("myparentreviewers")
|
|
def showmyparentreviewers(repo, ctx, templ, **args):
|
|
"""Show the reviewers of the commit's parent, if it has the
|
|
same author as this commit.
|
|
"""
|
|
return extract_from_parent(ctx, "\s*Reviewers: (.*)")
|
|
|
|
|
|
@templatekeyword("myparentsubscribers")
|
|
def showmyparentsubscribers(repo, ctx, templ, **args):
|
|
"""Show the subscribers of the commit's parent, if it has the
|
|
same author as this commit.
|
|
"""
|
|
return extract_from_parent(ctx, "\s*Subscribers: (.*)")
|
|
|
|
|
|
@templatekeyword("myparenttasks")
|
|
def showmyparenttasks(repo, ctx, templ, **args):
|
|
"""Show the tasks from the commit's parent, if it has the
|
|
same author as this commit.
|
|
"""
|
|
return extract_from_parent(ctx, "\s*(?:Tasks|Task ID): (.*)")
|
|
|
|
|
|
@templatekeyword("myparenttitleprefix")
|
|
def showmyparenttitleprefix(repo, ctx, templ, **args):
|
|
"""Show the title prefix of the commit's parent, if it has the
|
|
same author as this commit.
|
|
"""
|
|
if not p1_is_same_user(ctx):
|
|
return ""
|
|
descr = ctx.p1().description()
|
|
title = descr.splitlines()[0]
|
|
prefix_end = title.find("]")
|
|
return title[0 : prefix_end + 1] if prefix_end > 0 else ""
|
|
|
|
|
|
def extract_from_parent(ctx, pattern):
|
|
if not p1_is_same_user(ctx):
|
|
return ""
|
|
descr = ctx.p1().description()
|
|
match = re.search(pattern, descr)
|
|
return match.group(1) if match else ""
|
|
|
|
|
|
def p1_is_same_user(ctx):
|
|
return ctx.user() == ctx.p1().user()
|