dm: tegra: pci: Move CONFIG_PCI_TEGRA to Kconfig
[oweals/u-boot.git] / tools / patman / patman.py
index b327c675f719eedd0a748c6a71b5ec5c34a85f39..6fe8fe068c36f5028c1ccb3ed65fc994450c11a6 100755 (executable)
@@ -1,24 +1,8 @@
-#!/usr/bin/python
+#!/usr/bin/env python
 #
 # Copyright (c) 2011 The Chromium OS Authors.
 #
-# See file CREDITS for list of people who contributed to this
-# project.
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License as
-# published by the Free Software Foundation; either version 2 of
-# the License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston,
-# MA 02111-1307 USA
+# SPDX-License-Identifier:     GPL-2.0+
 #
 
 """See README for more information"""
@@ -30,13 +14,18 @@ import sys
 import unittest
 
 # Our modules
-import checkpatch
-import command
-import gitutil
-import patchstream
-import settings
-import terminal
-import test
+try:
+    from patman import checkpatch, command, gitutil, patchstream, \
+        project, settings, terminal, test
+except ImportError:
+    import checkpatch
+    import command
+    import gitutil
+    import patchstream
+    import project
+    import settings
+    import terminal
+    import test
 
 
 parser = OptionParser()
@@ -47,30 +36,49 @@ parser.add_option('-c', '--count', dest='count', type='int',
 parser.add_option('-i', '--ignore-errors', action='store_true',
        dest='ignore_errors', default=False,
        help='Send patches email even if patch errors are found')
+parser.add_option('-m', '--no-maintainers', action='store_false',
+       dest='add_maintainers', default=True,
+       help="Don't cc the file maintainers automatically")
 parser.add_option('-n', '--dry-run', action='store_true', dest='dry_run',
-       default=False, help="Do a try run (create but don't email patches)")
+       default=False, help="Do a dry run (create but don't email patches)")
+parser.add_option('-p', '--project', default=project.DetectProject(),
+                  help="Project name; affects default option values and "
+                  "aliases [default: %default]")
+parser.add_option('-r', '--in-reply-to', type='string', action='store',
+                  help="Message ID that this series is in reply to")
 parser.add_option('-s', '--start', dest='start', type='int',
        default=0, help='Commit to start creating patches from (0 = HEAD)')
-parser.add_option('-t', '--test', action='store_true', dest='test',
+parser.add_option('-t', '--ignore-bad-tags', action='store_true',
+                  default=False, help='Ignore bad tags / aliases')
+parser.add_option('--test', action='store_true', dest='test',
                   default=False, help='run tests')
 parser.add_option('-v', '--verbose', action='store_true', dest='verbose',
        default=False, help='Verbose output of errors and warnings')
 parser.add_option('--cc-cmd', dest='cc_cmd', type='string', action='store',
        default=None, help='Output cc list for patch file (used by git)')
+parser.add_option('--no-check', action='store_false', dest='check_patch',
+                  default=True,
+                  help="Don't check for patch compliance")
 parser.add_option('--no-tags', action='store_false', dest='process_tags',
                   default=True, help="Don't process subject tags as aliaes")
 
-parser.usage = """patman [options]
+parser.usage += """
 
 Create patches from commits in a branch, check them and email them as
-specified by tags you place in the commits. Use -n to """
+specified by tags you place in the commits. Use -n to do a dry run first."""
 
 
-settings.Setup(parser, '')
+# Parse options twice: first to get the project and second to handle
+# defaults properly (which depends on project).
 (options, args) = parser.parse_args()
+settings.Setup(parser, options.project, '')
+(options, args) = parser.parse_args()
+
+if __name__ != "__main__":
+    pass
 
 # Run our meagre tests
-if options.test:
+elif options.test:
     import doctest
 
     sys.argv = [sys.argv[0]]
@@ -78,8 +86,9 @@ if options.test:
     result = unittest.TestResult()
     suite.run(result)
 
-    suite = doctest.DocTestSuite('gitutil')
-    suite.run(result)
+    for module in ['gitutil', 'settings']:
+        suite = doctest.DocTestSuite(module)
+        suite.run(result)
 
     # TODO: Surely we can just 'print' result?
     print result
@@ -120,8 +129,7 @@ else:
     col = terminal.Color()
     if not options.count:
         str = 'No commits found to process - please use -c flag'
-        print col.Color(col.RED, str)
-        sys.exit(1)
+        sys.exit(col.Color(col.RED, str))
 
     # Read the metadata from the commits
     if options.count:
@@ -138,21 +146,29 @@ else:
     series.DoChecks()
 
     # Check the patches, and run them through 'git am' just to be sure
-    ok = checkpatch.CheckPatches(options.verbose, args)
-    if not gitutil.ApplyPatches(options.verbose, args,
-            options.count + options.start):
-        ok = False
+    if options.check_patch:
+        ok = checkpatch.CheckPatches(options.verbose, args)
+    else:
+        ok = True
 
-    cc_file = series.MakeCcFile(options.process_tags, cover_fname)
+    cc_file = series.MakeCcFile(options.process_tags, cover_fname,
+                                not options.ignore_bad_tags,
+                                options.add_maintainers)
 
     # Email the patches out (giving the user time to check / cancel)
     cmd = ''
-    if ok or options.ignore_errors:
+    its_a_go = ok or options.ignore_errors
+    if its_a_go:
         cmd = gitutil.EmailPatches(series, cover_fname, args,
-                options.dry_run, cc_file)
+                options.dry_run, not options.ignore_bad_tags, cc_file,
+                in_reply_to=options.in_reply_to)
+    else:
+        print col.Color(col.RED, "Not sending emails due to errors/warnings")
 
     # For a dry run, just show our actions as a sanity check
     if options.dry_run:
         series.ShowActions(args, cmd, options.process_tags)
+        if not its_a_go:
+            print col.Color(col.RED, "Email would not be sent")
 
     os.remove(cc_file)