gpu-compute, mem-ruby, configs: Add GCN3 ISA support to GPU model
[gem5.git] / util / git-pre-commit.py
index 33437faf3e8534463ff81ee37a27fa02598a73d8..b6d124abba08a2396f9ac37bfefc0d24a903c8c3 100755 (executable)
 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-#
-# Authors: Andreas Sandberg
 
+from __future__ import print_function
+
+from tempfile import TemporaryFile
 import os
+import subprocess
 import sys
 
 from style.repo import GitRepo
 from style.verifiers import all_verifiers, all_regions
-from style.style import StdioUI
+from style.style import StdioUI, check_ignores
 
 import argparse
 
@@ -62,27 +64,56 @@ ui = StdioUI()
 
 os.chdir(repo_base)
 failing_files = set()
+staged_mismatch = set()
 
 for status, fname in git.status(filter="MA", cached=True):
     if args.verbose:
-        print "Checking %s..." % fname
+        print("Checking {}...".format(fname))
+    if check_ignores(fname):
+        continue
     if status == "M":
         regions = git.staged_regions(fname)
     else:
         regions = all_regions
 
+    # Show they appropriate object and dump it to a file
+    status = git.file_from_index(fname)
+    f = TemporaryFile()
+    f.write(status.encode())
+
     verifiers = [ v(ui, opts, base=repo_base) for v in all_verifiers ]
     for v in verifiers:
-        if v.check(fname, regions):
+        f.seek(0)
+        # It is prefered that the first check is silent as it is in the
+        # staged file. If the check fails, then we will do it non-silently
+        # on the current file, reporting meaningful shortcomings
+        if not v.skip(fname) and v.check(fname, regions, fobj=f, silent=True):
             failing_files.add(fname)
+            if not v.check(fname, regions):
+                staged_mismatch.add(fname)
+    f.close()
 
 if failing_files:
-    print >> sys.stderr
-    print >> sys.stderr, "Style checker failed for the following files:"
-    for f in failing_files:
-        print >> sys.stderr, "\t%s" % f
-    print >> sys.stderr
-    print >> sys.stderr, \
-        "Please run the style checker manually to fix the offending files.\n" \
-        "To check your modifications, run: util/style.py -m"
+    if len(failing_files) > len(staged_mismatch):
+        print("\n", file=sys.stderr)
+        print("Style checker failed for the following files:", file=sys.stderr)
+        for f in failing_files:
+            if f not in staged_mismatch:
+                print("\t{}".format(f), file=sys.stderr)
+        print("\n", file=sys.stderr)
+        print(
+            "Please run the style checker manually to fix "
+            "the offending files.\n"
+            "To check your modifications, run: util/style.py -m",
+            file=sys.stderr)
+
+    print("\n", file=sys.stderr)
+    if staged_mismatch:
+        print(
+            "It looks like you have forgotten to stage your "
+            "fixes for commit in\n"
+            "the following files: ", file=sys.stderr)
+        for f in staged_mismatch:
+            print("\t%s".format(f), file=sys.stderr)
+        print("Please `git --add' them", file=sys.stderr)
     sys.exit(1)