2019-10-31 13:42:52 +00:00
|
|
|
#!/usr/bin/env python3
|
2018-05-06 21:58:06 +00:00
|
|
|
# SPDX-License-Identifier: GPL-2.0+
|
2012-01-14 15:12:45 +00:00
|
|
|
#
|
|
|
|
# Copyright (c) 2011 The Chromium OS Authors.
|
|
|
|
#
|
|
|
|
|
|
|
|
"""See README for more information"""
|
|
|
|
|
2020-07-06 03:41:53 +00:00
|
|
|
from argparse import ArgumentParser
|
2012-01-14 15:12:45 +00:00
|
|
|
import os
|
|
|
|
import re
|
|
|
|
import sys
|
2020-07-06 03:41:59 +00:00
|
|
|
import traceback
|
2012-01-14 15:12:45 +00:00
|
|
|
|
2020-04-18 00:08:52 +00:00
|
|
|
if __name__ == "__main__":
|
2020-04-18 00:09:05 +00:00
|
|
|
# Allow 'from patman import xxx to work'
|
2020-04-18 00:08:52 +00:00
|
|
|
our_path = os.path.dirname(os.path.realpath(__file__))
|
|
|
|
sys.path.append(os.path.join(our_path, '..'))
|
|
|
|
|
2012-01-14 15:12:45 +00:00
|
|
|
# Our modules
|
2020-07-06 03:41:49 +00:00
|
|
|
from patman import control
|
2020-04-18 00:09:04 +00:00
|
|
|
from patman import gitutil
|
|
|
|
from patman import project
|
|
|
|
from patman import settings
|
|
|
|
from patman import terminal
|
2020-07-06 03:41:48 +00:00
|
|
|
from patman import test_util
|
2020-06-14 16:54:04 +00:00
|
|
|
from patman import test_checkpatch
|
2021-09-08 11:38:01 +00:00
|
|
|
from patman import tools
|
2012-01-14 15:12:45 +00:00
|
|
|
|
2020-07-06 03:41:53 +00:00
|
|
|
epilog = '''Create patches from commits in a branch, check them and email them
|
|
|
|
as specified by tags you place in the commits. Use -n to do a dry run first.'''
|
2020-07-24 12:42:06 +00:00
|
|
|
|
2020-07-06 03:41:53 +00:00
|
|
|
parser = ArgumentParser(epilog=epilog)
|
2020-11-03 20:54:10 +00:00
|
|
|
parser.add_argument('-b', '--branch', type=str,
|
|
|
|
help="Branch to process (by default, the current branch)")
|
|
|
|
parser.add_argument('-c', '--count', dest='count', type=int,
|
|
|
|
default=-1, help='Automatically create patches from top n commits')
|
|
|
|
parser.add_argument('-e', '--end', type=int, default=0,
|
|
|
|
help='Commits to skip at end of patch list')
|
|
|
|
parser.add_argument('-D', '--debug', action='store_true',
|
|
|
|
help='Enabling debugging (provides a full traceback on error)')
|
2022-01-29 21:14:12 +00:00
|
|
|
parser.add_argument('-p', '--project', default=project.detect_project(),
|
2020-11-03 20:54:10 +00:00
|
|
|
help="Project name; affects default option values and "
|
|
|
|
"aliases [default: %(default)s]")
|
2020-11-03 20:54:15 +00:00
|
|
|
parser.add_argument('-P', '--patchwork-url',
|
|
|
|
default='https://patchwork.ozlabs.org',
|
|
|
|
help='URL of patchwork server [default: %(default)s]')
|
2020-11-03 20:54:10 +00:00
|
|
|
parser.add_argument('-s', '--start', dest='start', type=int,
|
|
|
|
default=0, help='Commit to start creating patches from (0 = HEAD)')
|
|
|
|
parser.add_argument('-v', '--verbose', action='store_true', dest='verbose',
|
|
|
|
default=False, help='Verbose output of errors and warnings')
|
|
|
|
parser.add_argument('-H', '--full-help', action='store_true', dest='full_help',
|
|
|
|
default=False, help='Display the README file')
|
|
|
|
|
2020-07-06 03:41:54 +00:00
|
|
|
subparsers = parser.add_subparsers(dest='cmd')
|
|
|
|
send = subparsers.add_parser('send')
|
|
|
|
send.add_argument('-i', '--ignore-errors', action='store_true',
|
2012-01-14 15:12:45 +00:00
|
|
|
dest='ignore_errors', default=False,
|
|
|
|
help='Send patches email even if patch errors are found')
|
2020-07-06 03:41:54 +00:00
|
|
|
send.add_argument('-l', '--limit-cc', dest='limit', type=int, default=None,
|
|
|
|
help='Limit the cc list to LIMIT entries [default: %(default)s]')
|
|
|
|
send.add_argument('-m', '--no-maintainers', action='store_false',
|
2014-09-15 02:23:17 +00:00
|
|
|
dest='add_maintainers', default=True,
|
|
|
|
help="Don't cc the file maintainers automatically")
|
2020-07-06 03:41:54 +00:00
|
|
|
send.add_argument('-n', '--dry-run', action='store_true', dest='dry_run',
|
2013-03-26 13:09:45 +00:00
|
|
|
default=False, help="Do a dry run (create but don't email patches)")
|
2020-07-06 03:41:54 +00:00
|
|
|
send.add_argument('-r', '--in-reply-to', type=str, action='store',
|
2013-03-17 10:31:04 +00:00
|
|
|
help="Message ID that this series is in reply to")
|
2020-07-06 03:41:54 +00:00
|
|
|
send.add_argument('-t', '--ignore-bad-tags', action='store_true',
|
2021-01-23 15:56:15 +00:00
|
|
|
default=False,
|
|
|
|
help='Ignore bad tags / aliases (default=warn)')
|
2020-07-06 03:41:54 +00:00
|
|
|
send.add_argument('-T', '--thread', action='store_true', dest='thread',
|
|
|
|
default=False, help='Create patches as a single thread')
|
|
|
|
send.add_argument('--cc-cmd', dest='cc_cmd', type=str, action='store',
|
2012-01-14 15:12:45 +00:00
|
|
|
default=None, help='Output cc list for patch file (used by git)')
|
2020-07-06 03:41:54 +00:00
|
|
|
send.add_argument('--no-binary', action='store_true', dest='ignore_binary',
|
|
|
|
default=False,
|
|
|
|
help="Do not output contents of changes in binary files")
|
|
|
|
send.add_argument('--no-check', action='store_false', dest='check_patch',
|
|
|
|
default=True,
|
|
|
|
help="Don't check for patch compliance")
|
2022-07-19 21:56:27 +00:00
|
|
|
send.add_argument('--tree', dest='check_patch_use_tree', default=False,
|
|
|
|
action='store_true',
|
|
|
|
help=("Set `tree` to True. If `tree` is False then we'll "
|
|
|
|
"pass '--no-tree' to checkpatch (default: tree=%(default)s)"))
|
|
|
|
send.add_argument('--no-tree', dest='check_patch_use_tree',
|
|
|
|
action='store_false', help="Set `tree` to False")
|
2020-07-06 03:41:54 +00:00
|
|
|
send.add_argument('--no-tags', action='store_false', dest='process_tags',
|
|
|
|
default=True, help="Don't process subject tags as aliases")
|
2020-11-24 17:14:52 +00:00
|
|
|
send.add_argument('--no-signoff', action='store_false', dest='add_signoff',
|
|
|
|
default=True, help="Don't add Signed-off-by to patches")
|
2020-07-06 03:41:54 +00:00
|
|
|
send.add_argument('--smtp-server', type=str,
|
|
|
|
help="Specify the SMTP server to 'git send-email'")
|
2020-07-06 03:41:53 +00:00
|
|
|
|
2020-07-06 03:41:54 +00:00
|
|
|
send.add_argument('patchfiles', nargs='*')
|
2020-07-06 03:41:55 +00:00
|
|
|
|
2020-07-06 03:41:55 +00:00
|
|
|
test_parser = subparsers.add_parser('test', help='Run tests')
|
2020-10-30 03:46:28 +00:00
|
|
|
test_parser.add_argument('testname', type=str, default=None, nargs='?',
|
|
|
|
help="Specify the test to run")
|
2020-07-06 03:41:55 +00:00
|
|
|
|
2020-10-30 03:46:35 +00:00
|
|
|
status = subparsers.add_parser('status',
|
|
|
|
help='Check status of patches in patchwork')
|
2020-10-30 03:46:38 +00:00
|
|
|
status.add_argument('-C', '--show-comments', action='store_true',
|
|
|
|
help='Show comments from each patch')
|
2020-10-30 03:46:36 +00:00
|
|
|
status.add_argument('-d', '--dest-branch', type=str,
|
|
|
|
help='Name of branch to create with collected responses')
|
|
|
|
status.add_argument('-f', '--force', action='store_true',
|
|
|
|
help='Force overwriting an existing branch')
|
2020-10-30 03:46:35 +00:00
|
|
|
|
2012-12-03 14:43:18 +00:00
|
|
|
# Parse options twice: first to get the project and second to handle
|
2020-11-03 20:54:10 +00:00
|
|
|
# defaults properly (which depends on project)
|
|
|
|
# Use parse_known_args() in case 'cmd' is omitted
|
2020-07-06 03:41:53 +00:00
|
|
|
argv = sys.argv[1:]
|
2020-11-03 20:54:10 +00:00
|
|
|
args, rest = parser.parse_known_args(argv)
|
2020-07-06 03:41:54 +00:00
|
|
|
if hasattr(args, 'project'):
|
2020-11-03 20:54:10 +00:00
|
|
|
settings.Setup(gitutil, parser, args.project, '')
|
|
|
|
args, rest = parser.parse_known_args(argv)
|
|
|
|
|
|
|
|
# If we have a command, it is safe to parse all arguments
|
|
|
|
if args.cmd:
|
|
|
|
args = parser.parse_args(argv)
|
|
|
|
else:
|
|
|
|
# No command, so insert it after the known arguments and before the ones
|
|
|
|
# that presumably relate to the 'send' subcommand
|
|
|
|
nargs = len(rest)
|
|
|
|
argv = argv[:-nargs] + ['send'] + rest
|
2020-07-06 03:41:54 +00:00
|
|
|
args = parser.parse_args(argv)
|
2012-01-14 15:12:45 +00:00
|
|
|
|
2015-07-30 19:47:41 +00:00
|
|
|
if __name__ != "__main__":
|
|
|
|
pass
|
|
|
|
|
2020-07-06 03:41:59 +00:00
|
|
|
if not args.debug:
|
|
|
|
sys.tracebacklimit = 0
|
|
|
|
|
2012-01-14 15:12:45 +00:00
|
|
|
# Run our meagre tests
|
2020-07-06 03:41:55 +00:00
|
|
|
if args.cmd == 'test':
|
2020-04-18 00:09:04 +00:00
|
|
|
from patman import func_test
|
2012-01-14 15:12:45 +00:00
|
|
|
|
2022-04-02 17:06:06 +00:00
|
|
|
result = test_util.run_test_suites(
|
|
|
|
'patman', False, False, False, None, None, None,
|
2022-01-22 12:07:28 +00:00
|
|
|
[test_checkpatch.TestPatch, func_test.TestFunctional,
|
|
|
|
'gitutil', 'settings', 'terminal'])
|
2012-01-14 15:12:45 +00:00
|
|
|
|
2022-04-02 17:06:06 +00:00
|
|
|
sys.exit(0 if result.wasSuccessful() else 1)
|
2020-07-24 12:42:06 +00:00
|
|
|
|
2012-01-14 15:12:45 +00:00
|
|
|
# Process commits, produce patches files, check them, email them
|
2020-07-06 03:41:55 +00:00
|
|
|
elif args.cmd == 'send':
|
|
|
|
# Called from git with a patch filename as argument
|
|
|
|
# Printout a list of additional CC recipients for this patch
|
|
|
|
if args.cc_cmd:
|
|
|
|
fd = open(args.cc_cmd, 'r')
|
|
|
|
re_line = re.compile('(\S*) (.*)')
|
|
|
|
for line in fd.readlines():
|
|
|
|
match = re_line.match(line)
|
|
|
|
if match and match.group(1) == args.patchfiles[0]:
|
|
|
|
for cc in match.group(2).split('\0'):
|
|
|
|
cc = cc.strip()
|
|
|
|
if cc:
|
|
|
|
print(cc)
|
|
|
|
fd.close()
|
|
|
|
|
|
|
|
elif args.full_help:
|
2022-01-29 21:14:04 +00:00
|
|
|
tools.print_full_help(
|
2022-08-09 19:49:57 +00:00
|
|
|
os.path.join(os.path.dirname(os.path.realpath(sys.argv[0])),
|
|
|
|
'README.rst')
|
2021-09-08 11:38:01 +00:00
|
|
|
)
|
2020-07-06 03:41:55 +00:00
|
|
|
|
|
|
|
else:
|
2021-01-23 15:56:15 +00:00
|
|
|
# If we are not processing tags, no need to warning about bad ones
|
|
|
|
if not args.process_tags:
|
|
|
|
args.ignore_bad_tags = True
|
2020-07-06 03:41:55 +00:00
|
|
|
control.send(args)
|
2020-10-30 03:46:35 +00:00
|
|
|
|
|
|
|
# Check status of patches in patchwork
|
|
|
|
elif args.cmd == 'status':
|
|
|
|
ret_code = 0
|
|
|
|
try:
|
2020-10-30 03:46:36 +00:00
|
|
|
control.patchwork_status(args.branch, args.count, args.start, args.end,
|
2020-10-30 03:46:38 +00:00
|
|
|
args.dest_branch, args.force,
|
2020-11-03 20:54:15 +00:00
|
|
|
args.show_comments, args.patchwork_url)
|
2020-10-30 03:46:35 +00:00
|
|
|
except Exception as e:
|
2022-01-29 21:14:18 +00:00
|
|
|
terminal.tprint('patman: %s: %s' % (type(e).__name__, e),
|
2022-12-17 01:45:27 +00:00
|
|
|
colour=terminal.Color.RED)
|
2020-10-30 03:46:35 +00:00
|
|
|
if args.debug:
|
|
|
|
print()
|
|
|
|
traceback.print_exc()
|
|
|
|
ret_code = 1
|
|
|
|
sys.exit(ret_code)
|