#!@PYTHON@
#
# it under the terms of the GNU General Public License version 2
# as published by the Free Software Foundation.
#
# 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., 675 Mass Ave, Cambridge, MA 02139, USA.
#
#
# Copyright 2008, 2012 Richard Lowe
# Copyright 2014 Garrett D'Amore <garrett@damore.org>
# Copyright (c) 2014, Joyent, Inc.
# Copyright (c) 2015, 2016 by Delphix. All rights reserved.
#
import getopt
import os
import re
import subprocess
import sys
import tempfile
#
# Adjust the load path based on our location and the version of python into
# which it is being loaded. This assumes the normal onbld directory
# structure, where we are in bin/ and the modules are in
#
#
# from the source tree we use the modules also within the source tree.
#
pass
"""Run a command and return a stream containing its stdout (and write its
stderr to its stdout)"""
try:
except EnvironmentError, e:
raise GitError("Could not create temporary file: %s\n" % e)
try:
except OSError, e:
if err != 0:
return tmpfile
def git_root():
"""Return the root of the current git workspace"""
p = git('rev-parse --git-dir')
if not p:
def git_branch():
"""Return the current git branch"""
p = git('branch')
if not p:
for elt in p:
return None
"""Return the parent of the current git branch.
If this branch tracks a remote branch, return the remote branch which is
if not branch:
return None
p = git("for-each-ref --format=%(refname:short) %(upstream:short) " +
if not p:
for line in p:
# Git 1.7 will leave a ' ' trailing any non-tracking branch
return remote
"""Return a list of any checkin comments on this git branch"""
if not p:
"""Return the set of files which have ever changed on this branch.
NB: This includes files which no longer exist, or no longer actually
differ."""
p = git("log --name-only --pretty=format: %s.. %s" %
if not p:
for fname in p:
return ret
"""Return a function which returns True if a file given as an argument
should be excluded from the check named by 'cmd'"""
"""Return a function producing file names, relative to the current
directory, of any file changed on this branch (limited to 'paths' if
requested), and excluding files for which exclude returns a true value """
# Taken entirely from Python 2.6's os.path.relpath which we would use if we
# could.
if not select:
f = relpath(f, '.')
try:
except GitError, e:
# This ignores all the errors that can be thrown. Usually, this means
# that git returned non-zero because the file doesn't exist, but it
# could also fail if git can't create a new file or it can't be
# executed. Such errors are 1) unlikely, and 2) will be caught by other
# invocations of git().
continue
yield f
return ret
ret = 0
# We are interested in examining any file that has the following
# in its final path segment:
# - Contains the word 'mapfile'
# - Begins with 'map.'
# - Ends with '.map'
# We don't want to match unless these things occur in final path segment
# because directory names with these strings don't indicate a mapfile.
# We also ignore files with suffixes that tell us that the files
# are not mapfiles.
NotMapSuffixRE.match(x)):
return ret
ret = 0
for f in flist():
return ret
ret = 0
return ret
ret = 0
return ret
ret = 0
return ret
ret = 0
return ret
ret = 0
for f in flist():
return ret
"""Run the checks given in 'cmds', expected to have well-known signatures,
and report results for any which fail.
Return failure if any of them did.
NB: the function name of the commands passed in is used to name the NOT
file which excepts files from them."""
ret = 0
s = StringIO()
output=s)
if result != 0:
print s.getvalue()
return ret
parent_branch = None
try:
except getopt.GetoptError, e:
if opt == '-b':
if not parent_branch:
if cmd == 'git-pbchk':
if args:
if __name__ == '__main__':
try:
except GitError, e: