diff options
Diffstat (limited to 'tools/patman/main.py')
-rwxr-xr-x | tools/patman/main.py | 75 |
1 files changed, 40 insertions, 35 deletions
diff --git a/tools/patman/main.py b/tools/patman/main.py index fee9bc848b..77f187e769 100755 --- a/tools/patman/main.py +++ b/tools/patman/main.py @@ -27,6 +27,16 @@ from patman import terminal from patman import test_util from patman import test_checkpatch +def AddCommonArgs(parser): + 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('-s', '--start', dest='start', type=int, + default=0, help='Commit to start creating patches from (0 = HEAD)') + 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.''' @@ -35,12 +45,6 @@ subparsers = parser.add_subparsers(dest='cmd') send = subparsers.add_parser('send') send.add_argument('-H', '--full-help', action='store_true', dest='full_help', default=False, help='Display the README file') -send.add_argument('-b', '--branch', type=str, - help="Branch to process (by default, the current branch)") -send.add_argument('-c', '--count', dest='count', type=int, - default=-1, help='Automatically create patches from top n commits') -send.add_argument('-e', '--end', type=int, default=0, - help='Commits to skip at end of patch list') send.add_argument('-i', '--ignore-errors', action='store_true', dest='ignore_errors', default=False, help='Send patches email even if patch errors are found') @@ -56,8 +60,6 @@ send.add_argument('-p', '--project', default=project.DetectProject(), "aliases [default: %(default)s]") send.add_argument('-r', '--in-reply-to', type=str, action='store', help="Message ID that this series is in reply to") -send.add_argument('-s', '--start', dest='start', type=int, - default=0, help='Commit to start creating patches from (0 = HEAD)') send.add_argument('-t', '--ignore-bad-tags', action='store_true', default=False, help='Ignore bad tags / aliases') send.add_argument('-v', '--verbose', action='store_true', dest='verbose', @@ -76,11 +78,13 @@ send.add_argument('--no-tags', action='store_false', dest='process_tags', default=True, help="Don't process subject tags as aliases") send.add_argument('--smtp-server', type=str, help="Specify the SMTP server to 'git send-email'") -send.add_argument('--test', action='store_true', dest='test', - default=False, help='run tests') +AddCommonArgs(send) send.add_argument('patchfiles', nargs='*') +test_parser = subparsers.add_parser('test', help='Run tests') +AddCommonArgs(test_parser) + # Parse options twice: first to get the project and second to handle # defaults properly (which depends on project). argv = sys.argv[1:] @@ -95,7 +99,7 @@ if __name__ != "__main__": pass # Run our meagre tests -elif args.test: +if args.cmd == 'test': import doctest from patman import func_test @@ -111,28 +115,29 @@ elif args.test: sys.exit(test_util.ReportResult('patman', None, result)) -# Called from git with a patch filename as argument -# Printout a list of additional CC recipients for this patch -elif 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: - pager = os.getenv('PAGER') - if not pager: - pager = 'more' - fname = os.path.join(os.path.dirname(os.path.realpath(sys.argv[0])), - 'README') - command.Run(pager, fname) - # Process commits, produce patches files, check them, email them -else: - control.send(args) +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: + pager = os.getenv('PAGER') + if not pager: + pager = 'more' + fname = os.path.join(os.path.dirname(os.path.realpath(sys.argv[0])), + 'README') + command.Run(pager, fname) + + else: + control.send(args) |