diff options
author | João Valverde <joao.valverde@tecnico.ulisboa.pt> | 2016-01-30 03:49:41 +0000 |
---|---|---|
committer | João Valverde <j@v6e.pt> | 2016-02-25 12:34:50 +0000 |
commit | fe1de0146e607652333e729d6c11f43584744785 (patch) | |
tree | 6e8d2a38f50bb822fff6b08ff4a58d6c1b2d6f7f /tools/pre-commit-ignore.py | |
parent | fd9e71d15d4023438deb51b043332d61f7f5207c (diff) |
pre-commit: Avoid launching python subprocesses.
This makes Python required only for (portable) fnmatch().
Change the ignore script to work as a filter.
Multi-platform improvements.
Change-Id: I6ac757d48ba2ff965da5da3dc9c25047a0e37f92
Reviewed-on: https://code.wireshark.org/review/13693
Reviewed-by: Michael Mann <mmann78@netscape.net>
Reviewed-by: João Valverde <j@v6e.pt>
Diffstat (limited to 'tools/pre-commit-ignore.py')
-rwxr-xr-x | tools/pre-commit-ignore.py | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/tools/pre-commit-ignore.py b/tools/pre-commit-ignore.py new file mode 100755 index 0000000000..d043368a95 --- /dev/null +++ b/tools/pre-commit-ignore.py @@ -0,0 +1,72 @@ +#!/bin/env python +# +# Wireshark - Network traffic analyzer +# By Gerald Combs <gerald@wireshark.org> +# Copyright 1998 Gerald Combs +# +# 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +import sys +import os +import fnmatch + +IGNORE_CONF = "pre-commit-ignore.conf" + +if len(sys.argv) > 2: + print("Usage: {0} [path/to/ignore.conf]".format(sys.argv[0])) + sys.exit(1) + +if len(sys.argv) == 2: + ignore_path = sys.argv[1] +else: + ignore_path = IGNORE_CONF + +# Function to load our patterns from 'path' for modified files +# to be ignored (skipping any comments) +def load_checkignore(path): + try: + with open(path) as f: + patterns = f.read() + except OSError as err: + print(str(err)) + return [] + ign = [l.strip() for l in patterns.splitlines()] + ign = [l for l in ign if l and not l.startswith("#")] + return ign + +ignore_list = load_checkignore(ignore_path) + +def ignore_match(f): + for p in ignore_list: + if fnmatch.fnmatchcase(f, p): + return True + return False + +for line in sys.stdin: + line = line.strip() + if not ignore_match(line): + print(line) + +# +# Editor modelines +# +# Local Variables: +# c-basic-offset: 4 +# indent-tabs-mode: nil +# End: +# +# ex: set shiftwidth=4 expandtab: +# :indentSize=4:noTabs=true: +# |