util: Port git hooks to python3

This involves changing:
* git-commit
* git-pre-commit
* style verifiers

JIRA: https://gem5.atlassian.net/browse/GEM5-473

Change-Id: I7bd0b54469f942bf927c8be1fd94d12f67594d48
Signed-off-by: Giacomo Travaglini <giacomo.travaglini@arm.com>
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/28588
Maintainer: Bobby R. Bruce <bbruce@ucdavis.edu>
Reviewed-by: Jason Lowe-Power <power.jg@gmail.com>
Reviewed-by: Daniel Carvalho <odanrc@yahoo.com.br>
Tested-by: kokoro <noreply+kokoro@google.com>
This commit is contained in:
Giacomo Travaglini
2020-05-04 14:16:08 +01:00
parent 003c08418f
commit 86454a3539
8 changed files with 78 additions and 66 deletions

View File

@@ -1,4 +1,4 @@
#!/usr/bin/env python2.7
#!/usr/bin/env python
#
# Copyright (c) 2016 ARM Limited
# All rights reserved
@@ -35,6 +35,8 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
from __future__ import print_function
from tempfile import TemporaryFile
import os
import subprocess
@@ -66,7 +68,7 @@ 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":
@@ -77,7 +79,7 @@ for status, fname in git.status(filter="MA", cached=True):
# Show they appropriate object and dump it to a file
status = git.file_from_index(fname)
f = TemporaryFile()
f.write(status)
f.write(status.encode())
verifiers = [ v(ui, opts, base=repo_base) for v in all_verifiers ]
for v in verifiers:
@@ -93,22 +95,25 @@ for status, fname in git.status(filter="MA", cached=True):
if failing_files:
if len(failing_files) > len(staged_mismatch):
print >> sys.stderr
print >> sys.stderr, "Style checker failed for the following files:"
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 >> 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"
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 >> sys.stderr
print("\n", file=sys.stderr)
if staged_mismatch:
print >> sys.stderr, \
"It looks like you have forgotten to stage your fixes for commit in\n"\
"the following files: "
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 >> sys.stderr, "\t%s" % f
print >> sys.stderr, "Please `git --add' them"
print("\t%s".format(f), file=sys.stderr)
print("Please `git --add' them", file=sys.stderr)
sys.exit(1)