patman: Refactor how the default subcommand works
At present patman tries to assume a default subcommand of 'send', to maintain backwards compatibility. However it does not cope with arguments added to the default command, so for example 'patman -t' does not work. Update the logic to handle this. Also update the CC command to use 'send' explicitly, since otherwise patman gets confused with the patch-filename argument. Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
		
							parent
							
								
									832bfad745
								
							
						
					
					
						commit
						4600767d29
					
				|  | @ -248,7 +248,7 @@ class TestFunctional(unittest.TestCase): | ||||||
|         self.assertEqual('      Cc:  %s' % rick, next(lines)) |         self.assertEqual('      Cc:  %s' % rick, next(lines)) | ||||||
|         expected = ('Git command: git send-email --annotate ' |         expected = ('Git command: git send-email --annotate ' | ||||||
|                     '--in-reply-to="%s" --to "u-boot@lists.denx.de" ' |                     '--in-reply-to="%s" --to "u-boot@lists.denx.de" ' | ||||||
|                     '--cc "%s" --cc-cmd "%s --cc-cmd %s" %s %s' |                     '--cc "%s" --cc-cmd "%s send --cc-cmd %s" %s %s' | ||||||
|                     % (in_reply_to, stefan, sys.argv[0], cc_file, cover_fname, |                     % (in_reply_to, stefan, sys.argv[0], cc_file, cover_fname, | ||||||
|                        ' '.join(args))) |                        ' '.join(args))) | ||||||
|         self.assertEqual(expected, tools.ToUnicode(next(lines))) |         self.assertEqual(expected, tools.ToUnicode(next(lines))) | ||||||
|  |  | ||||||
|  | @ -455,21 +455,21 @@ def EmailPatches(series, cover_fname, args, dry_run, raise_on_error, cc_fname, | ||||||
|     >>> EmailPatches(series, 'cover', ['p1', 'p2'], True, True, 'cc-fname', \ |     >>> EmailPatches(series, 'cover', ['p1', 'p2'], True, True, 'cc-fname', \ | ||||||
|             False, alias) |             False, alias) | ||||||
|     'git send-email --annotate --to "f.bloggs@napier.co.nz" --cc \ |     'git send-email --annotate --to "f.bloggs@napier.co.nz" --cc \ | ||||||
| "m.poppins@cloud.net" --cc-cmd "./patman --cc-cmd cc-fname" cover p1 p2' | "m.poppins@cloud.net" --cc-cmd "./patman send --cc-cmd cc-fname" cover p1 p2' | ||||||
|     >>> EmailPatches(series, None, ['p1'], True, True, 'cc-fname', False, \ |     >>> EmailPatches(series, None, ['p1'], True, True, 'cc-fname', False, \ | ||||||
|             alias) |             alias) | ||||||
|     'git send-email --annotate --to "f.bloggs@napier.co.nz" --cc \ |     'git send-email --annotate --to "f.bloggs@napier.co.nz" --cc \ | ||||||
| "m.poppins@cloud.net" --cc-cmd "./patman --cc-cmd cc-fname" p1' | "m.poppins@cloud.net" --cc-cmd "./patman send --cc-cmd cc-fname" p1' | ||||||
|     >>> series['cc'] = ['all'] |     >>> series['cc'] = ['all'] | ||||||
|     >>> EmailPatches(series, 'cover', ['p1', 'p2'], True, True, 'cc-fname', \ |     >>> EmailPatches(series, 'cover', ['p1', 'p2'], True, True, 'cc-fname', \ | ||||||
|             True, alias) |             True, alias) | ||||||
|     'git send-email --annotate --to "this-is-me@me.com" --cc-cmd "./patman \ |     'git send-email --annotate --to "this-is-me@me.com" --cc-cmd "./patman \ | ||||||
| --cc-cmd cc-fname" cover p1 p2' | send --cc-cmd cc-fname" cover p1 p2' | ||||||
|     >>> EmailPatches(series, 'cover', ['p1', 'p2'], True, True, 'cc-fname', \ |     >>> EmailPatches(series, 'cover', ['p1', 'p2'], True, True, 'cc-fname', \ | ||||||
|             False, alias) |             False, alias) | ||||||
|     'git send-email --annotate --to "f.bloggs@napier.co.nz" --cc \ |     'git send-email --annotate --to "f.bloggs@napier.co.nz" --cc \ | ||||||
| "f.bloggs@napier.co.nz" --cc "j.bloggs@napier.co.nz" --cc \ | "f.bloggs@napier.co.nz" --cc "j.bloggs@napier.co.nz" --cc \ | ||||||
| "m.poppins@cloud.net" --cc-cmd "./patman --cc-cmd cc-fname" cover p1 p2' | "m.poppins@cloud.net" --cc-cmd "./patman send --cc-cmd cc-fname" cover p1 p2' | ||||||
| 
 | 
 | ||||||
|     # Restore argv[0] since we clobbered it. |     # Restore argv[0] since we clobbered it. | ||||||
|     >>> sys.argv[0] = _old_argv0 |     >>> sys.argv[0] = _old_argv0 | ||||||
|  | @ -500,7 +500,7 @@ def EmailPatches(series, cover_fname, args, dry_run, raise_on_error, cc_fname, | ||||||
| 
 | 
 | ||||||
|     cmd += to |     cmd += to | ||||||
|     cmd += cc |     cmd += cc | ||||||
|     cmd += ['--cc-cmd', '"%s --cc-cmd %s"' % (sys.argv[0], cc_fname)] |     cmd += ['--cc-cmd', '"%s send --cc-cmd %s"' % (sys.argv[0], cc_fname)] | ||||||
|     if cover_fname: |     if cover_fname: | ||||||
|         cmd.append(cover_fname) |         cmd.append(cover_fname) | ||||||
|     cmd += args |     cmd += args | ||||||
|  |  | ||||||
|  | @ -28,26 +28,30 @@ from patman import terminal | ||||||
| from patman import test_util | from patman import test_util | ||||||
| from patman import test_checkpatch | 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('-D', '--debug', action='store_true', |  | ||||||
|         help='Enabling debugging (provides a full traceback on error)') |  | ||||||
|     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 | 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.''' | as specified by tags you place in the commits. Use -n to do a dry run first.''' | ||||||
| 
 | 
 | ||||||
| parser = ArgumentParser(epilog=epilog) | parser = ArgumentParser(epilog=epilog) | ||||||
|  | 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)') | ||||||
|  | parser.add_argument('-p', '--project', default=project.DetectProject(), | ||||||
|  |                     help="Project name; affects default option values and " | ||||||
|  |                     "aliases [default: %(default)s]") | ||||||
|  | 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') | ||||||
|  | 
 | ||||||
| subparsers = parser.add_subparsers(dest='cmd') | subparsers = parser.add_subparsers(dest='cmd') | ||||||
| send = subparsers.add_parser('send') | 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('-i', '--ignore-errors', action='store_true', | send.add_argument('-i', '--ignore-errors', action='store_true', | ||||||
|        dest='ignore_errors', default=False, |        dest='ignore_errors', default=False, | ||||||
|        help='Send patches email even if patch errors are found') |        help='Send patches email even if patch errors are found') | ||||||
|  | @ -58,15 +62,10 @@ send.add_argument('-m', '--no-maintainers', action='store_false', | ||||||
|        help="Don't cc the file maintainers automatically") |        help="Don't cc the file maintainers automatically") | ||||||
| send.add_argument('-n', '--dry-run', action='store_true', dest='dry_run', | send.add_argument('-n', '--dry-run', action='store_true', dest='dry_run', | ||||||
|        default=False, help="Do a dry run (create but don't email patches)") |        default=False, help="Do a dry run (create but don't email patches)") | ||||||
| send.add_argument('-p', '--project', default=project.DetectProject(), |  | ||||||
|                   help="Project name; affects default option values and " |  | ||||||
|                   "aliases [default: %(default)s]") |  | ||||||
| send.add_argument('-r', '--in-reply-to', type=str, action='store', | send.add_argument('-r', '--in-reply-to', type=str, action='store', | ||||||
|                   help="Message ID that this series is in reply to") |                   help="Message ID that this series is in reply to") | ||||||
| send.add_argument('-t', '--ignore-bad-tags', action='store_true', | send.add_argument('-t', '--ignore-bad-tags', action='store_true', | ||||||
|                   default=False, help='Ignore bad tags / aliases') |                   default=False, help='Ignore bad tags / aliases') | ||||||
| send.add_argument('-v', '--verbose', action='store_true', dest='verbose', |  | ||||||
|        default=False, help='Verbose output of errors and warnings') |  | ||||||
| send.add_argument('-T', '--thread', action='store_true', dest='thread', | send.add_argument('-T', '--thread', action='store_true', dest='thread', | ||||||
|                   default=False, help='Create patches as a single thread') |                   default=False, help='Create patches as a single thread') | ||||||
| send.add_argument('--cc-cmd', dest='cc_cmd', type=str, action='store', | send.add_argument('--cc-cmd', dest='cc_cmd', type=str, action='store', | ||||||
|  | @ -81,14 +80,12 @@ send.add_argument('--no-tags', action='store_false', dest='process_tags', | ||||||
|                   default=True, help="Don't process subject tags as aliases") |                   default=True, help="Don't process subject tags as aliases") | ||||||
| send.add_argument('--smtp-server', type=str, | send.add_argument('--smtp-server', type=str, | ||||||
|                   help="Specify the SMTP server to 'git send-email'") |                   help="Specify the SMTP server to 'git send-email'") | ||||||
| AddCommonArgs(send) |  | ||||||
| 
 | 
 | ||||||
| send.add_argument('patchfiles', nargs='*') | send.add_argument('patchfiles', nargs='*') | ||||||
| 
 | 
 | ||||||
| test_parser = subparsers.add_parser('test', help='Run tests') | test_parser = subparsers.add_parser('test', help='Run tests') | ||||||
| test_parser.add_argument('testname', type=str, default=None, nargs='?', | test_parser.add_argument('testname', type=str, default=None, nargs='?', | ||||||
|                          help="Specify the test to run") |                          help="Specify the test to run") | ||||||
| AddCommonArgs(test_parser) |  | ||||||
| 
 | 
 | ||||||
| status = subparsers.add_parser('status', | status = subparsers.add_parser('status', | ||||||
|                                help='Check status of patches in patchwork') |                                help='Check status of patches in patchwork') | ||||||
|  | @ -98,16 +95,24 @@ status.add_argument('-d', '--dest-branch', type=str, | ||||||
|                     help='Name of branch to create with collected responses') |                     help='Name of branch to create with collected responses') | ||||||
| status.add_argument('-f', '--force', action='store_true', | status.add_argument('-f', '--force', action='store_true', | ||||||
|                     help='Force overwriting an existing branch') |                     help='Force overwriting an existing branch') | ||||||
| AddCommonArgs(status) |  | ||||||
| 
 | 
 | ||||||
| # Parse options twice: first to get the project and second to handle | # Parse options twice: first to get the project and second to handle | ||||||
| # defaults properly (which depends on project). | # defaults properly (which depends on project) | ||||||
|  | # Use parse_known_args() in case 'cmd' is omitted | ||||||
| argv = sys.argv[1:] | argv = sys.argv[1:] | ||||||
| if len(argv) < 1 or argv[0].startswith('-'): | args, rest = parser.parse_known_args(argv) | ||||||
|     argv = ['send'] + argv |  | ||||||
| args = parser.parse_args(argv) |  | ||||||
| if hasattr(args, 'project'): | if hasattr(args, 'project'): | ||||||
|     settings.Setup(gitutil, send, args.project, '') |     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 | ||||||
|     args = parser.parse_args(argv) |     args = parser.parse_args(argv) | ||||||
| 
 | 
 | ||||||
| if __name__ != "__main__": | if __name__ != "__main__": | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue