Bobby R. Bruce has uploaded this change for review. ( https://gem5-review.googlesource.com/c/public/gem5/+/40015 )

Change subject: util,python: Add check to ensure files are utf-8 in pre-commit
......................................................................

util,python: Add check to ensure files are utf-8 in pre-commit

The `file_from_index` function throws a UnicodeDecodeError if a modified
file targetted for style-checking (i.e. source-code) cannot be decoded
using `.decode("utf-8")`.

This check throws an error informing the user a submitted file must be
utf-8 encoded if this case arises.

Change-Id: I2361017f2e7413ed60f897d2301f2e4c7995dd76
---
M util/git-pre-commit.py
1 file changed, 10 insertions(+), 2 deletions(-)



diff --git a/util/git-pre-commit.py b/util/git-pre-commit.py
index bf13f3b..50d93b5 100755
--- a/util/git-pre-commit.py
+++ b/util/git-pre-commit.py
@@ -76,8 +76,16 @@
     else:
         regions = all_regions

-    # Show they appropriate object and dump it to a file
-    status = git.file_from_index(fname)
+    # Show the appropriate object and dump it to a file
+    try:
+        status = git.file_from_index(fname)
+    except UnicodeDecodeError:
+        print("Decoding '" + fname
+            + "' throws a UnicodeDecodeError.", file=sys.stderr)
+        print("Please check '" + fname
+            + "' exclusively uses utf-8 character encoding.")
+        sys.exit(1)
+
     f = TemporaryFile()
     f.write(status.encode('utf-8'))


--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/40015
To unsubscribe, or for help writing mail filters, visit https://gem5-review.googlesource.com/settings

Gerrit-Project: public/gem5
Gerrit-Branch: develop
Gerrit-Change-Id: I2361017f2e7413ed60f897d2301f2e4c7995dd76
Gerrit-Change-Number: 40015
Gerrit-PatchSet: 1
Gerrit-Owner: Bobby R. Bruce <bbr...@ucdavis.edu>
Gerrit-MessageType: newchange
_______________________________________________
gem5-dev mailing list -- gem5-dev@gem5.org
To unsubscribe send an email to gem5-dev-le...@gem5.org
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s

Reply via email to