Bobby R. Bruce has submitted this change. (
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
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/40015
Reviewed-by: Jason Lowe-Power <[email protected]>
Maintainer: Jason Lowe-Power <[email protected]>
Tested-by: kokoro <[email protected]>
---
M util/git-pre-commit.py
1 file changed, 10 insertions(+), 2 deletions(-)
Approvals:
Jason Lowe-Power: Looks good to me, approved; Looks good to me, approved
kokoro: Regressions pass
diff --git a/util/git-pre-commit.py b/util/git-pre-commit.py
index bf13f3b..82fcf39 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.",
file=sys.stderr)
+ 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: 3
Gerrit-Owner: Bobby R. Bruce <[email protected]>
Gerrit-Reviewer: Andreas Sandberg <[email protected]>
Gerrit-Reviewer: Bobby R. Bruce <[email protected]>
Gerrit-Reviewer: Gabe Black <[email protected]>
Gerrit-Reviewer: Jason Lowe-Power <[email protected]>
Gerrit-Reviewer: Jason Lowe-Power <[email protected]>
Gerrit-Reviewer: kokoro <[email protected]>
Gerrit-MessageType: merged
_______________________________________________
gem5-dev mailing list -- [email protected]
To unsubscribe send an email to [email protected]
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s