--- old/usr/src/tools/scripts/which_scm.1 Sat May 9 16:08:43 2009 +++ new/usr/src/tools/scripts/which_scm.1 Sat May 9 16:08:43 2009 @@ -51,6 +51,7 @@ used in the output format): .nf cvs + git mercurial rcs sccs @@ -72,6 +73,7 @@ .SH SEE ALSO .IR cvs(1) , .IR hg(1) , +.IR git(1) , .IR sccs(1) .IR svn(1) , .IR workspace(1) --- old/usr/src/tools/scripts/which_scm.sh Sat May 9 16:08:43 2009 +++ new/usr/src/tools/scripts/which_scm.sh Sat May 9 16:08:43 2009 @@ -59,6 +59,7 @@ [ -d "$1/.hg" ] && scmid="$scmid mercurial" [ -d "$1/CVS" ] && scmid="$scmid cvs" [ -d "$1/.svn" ] && scmid="$scmid subversion" + [ -d "$1/.git" ] && scmid="$scmid git" echo $scmid } @@ -99,8 +100,8 @@ SCM_TYPE="$1" # We're done searching if we hit either a change in type or the top # of a "third type" control system. - if [[ "$SCM_TYPE" != "$CWD_TYPE" || "$SCM_TYPE" == mercurial || \ - "$SCM_TYPE" == teamware ]]; then + if [[ "$SCM_TYPE" != "$CWD_TYPE" || "$SCM_TYPE" == git || \ + "$SCM_TYPE" == mercurial || "$SCM_TYPE" == teamware ]]; then break fi PREVDIR="$DIR" --- old/usr/src/tools/scripts/Makefile Sat May 9 16:08:44 2009 +++ new/usr/src/tools/scripts/Makefile Sat May 9 16:08:44 2009 @@ -74,6 +74,7 @@ PYFILES= \ cddlchk \ copyrightchk \ + git-active \ hdrchk \ hg-active \ mapfilechk \ --- old/usr/src/tools/scripts/webrev.sh Sat May 9 16:08:44 2009 +++ new/usr/src/tools/scripts/webrev.sh Sat May 9 16:08:44 2009 @@ -1779,6 +1779,42 @@ } # +# Call git-active to get the active list output in the wx active list format +# +function git_active_wxfile +{ + typeset child=$1 + typeset parent=$2 + + TMPFLIST=/tmp/$$.active + $GIT_ACTIVE -w $child -p $parent -o $TMPFLIST + wxfile=$TMPFLIST +} + +# +# flist_from_git +# Call git-active to get a wx-style active list, and hand it off to +# flist_from_wx +# +function flist_from_git +{ + typeset child=$1 + typeset parent=$2 + + print " File list from: git-active -p $parent ...\c" + + if [[ ! -x $GIT_ACTIVE ]]; then + print # Blank line for the \c above + print -u2 "Error: git-active tool not found. Exiting" + exit 1 + fi + git_active_wxfile $child $parent + + # flist_from_wx prints the Done, so we don't have to. + flist_from_wx $TMPFLIST +} + +# # flist_from_subversion # # Generate the file list by extracting file names from svn status. @@ -1998,6 +2034,57 @@ fi } +function build_old_new_git +{ + typeset olddir="$1" + typeset newdir="$2" + typeset old_mode= + typeset new_mode= + typeset old_object= + typeset new_object= + typeset file + typeset type + + # + # Get old file and its mode from the git object tree + # + if [[ "$PDIR" == "." ]]; then + file="$PF" + else + file="$PDIR/$PF" + fi + git ls-tree $GIT_PARENT $file | read old_mode type old_object junk + git cat-file $type $old_object > $olddir/$file 2>/dev/null + + if (( $? != 0 )); then + rm -f $olddir/$PDIR/$PF + else + if [[ -n $old_mode ]]; then + chmod $old_mode $olddir/$PDIR/$PF + else + # should never happen + print -u2 "ERROR: set mode of $olddir/$PDIR/$PF" + fi + fi + + # + # new version of the file. + # + rm -rf $newdir/$DIR/$F + if [[ -e $CWS/../$DIR/$F ]]; then + cp $CWS/../$DIR/$F $newdir/$DIR/$F + # Temporary new_node = old_mode + new_mode=$old_mode + if [[ -n $new_mode ]]; then + chmod $new_mode $newdir/$DIR/$F + else + # should never happen + print -u2 "ERROR: set mode of $newdir/$DIR/$F" + fi + fi + +} + function build_old_new_subversion { typeset olddir="$1" @@ -2058,6 +2145,8 @@ build_old_new_teamware "$olddir" "$newdir" elif [[ $SCM_MODE == "mercurial" ]]; then build_old_new_mercurial "$olddir" "$newdir" + elif [[ $SCM_MODE == "git" ]]; then + build_old_new_git "$olddir" "$newdir" elif [[ $SCM_MODE == "subversion" ]]; then build_old_new_subversion "$olddir" "$newdir" elif [[ $SCM_MODE == "unknown" ]]; then @@ -2124,6 +2213,7 @@ [[ -z $WDIFF ]] && WDIFF=`look_for_prog wdiff` [[ -z $WX ]] && WX=`look_for_prog wx` [[ -z $HG_ACTIVE ]] && HG_ACTIVE=`look_for_prog hg-active` +[[ -z $GIT_ACTIVE ]] && GIT_ACTIVE=`look_for_prog git-active` [[ -z $WHICH_SCM ]] && WHICH_SCM=`look_for_prog which_scm` [[ -z $CODEREVIEW ]] && CODEREVIEW=`look_for_prog codereview` [[ -z $PS2PDF ]] && PS2PDF=`look_for_prog ps2pdf` @@ -2289,6 +2379,18 @@ codemgr_ws=$(hg root -R $CODEMGR_WS 2>/dev/null) [[ -z $codemgr_ws ]] && codemgr_ws=$(hg root 2>/dev/null) CWS=$codemgr_ws +elif [[ $SCM_MODE == "git" ]]; then + # + # Git priorities: + # 1. git rev-parse --git-dir from CODEMGR_WS environment variable + # 2. git rev-parse --git-dir from directory of invocation + # + [[ -z $codemgr_ws && -n $CODEMGR_WS ]] && \ + codemgr_ws=$(git --git-dir=$CODEMGR_WS rev-parse --git-dir \ + 2>/dev/null) + [[ -z $codemgr_ws ]] && \ + codemgr_ws=$(git rev-parse --git-dir 2>/dev/null) + CWS=$codemgr_ws elif [[ $SCM_MODE == "subversion" ]]; then # # Subversion priorities: @@ -2374,7 +2476,7 @@ # is in use. # case "$SCM_MODE" in -teamware|mercurial|subversion) +teamware|mercurial|git|subversion) ;; unknown) if [[ $flist_mode == "auto" ]]; then @@ -2518,7 +2620,8 @@ fi PWS=$codemgr_parent - +\ + [[ -n $parent_webrev ]] && RWS=$(workspace parent $CWS) elif [[ $SCM_MODE == "mercurial" ]]; then @@ -2600,6 +2703,88 @@ print -u2 "Error: Cannot discover parent revision" exit 1 fi +elif [[ $SCM_MODE == "git" ]]; then + # + # Parent can either be specified with -p + # Specified with CODEMGR_PARENT in the environment + # or taken from git config. + # + + if [[ -z $codemgr_parent && -n $CODEMGR_PARENT ]]; then + codemgr_parent=$CODEMGR_PARENT + fi + + if [[ -z $codemgr_parent ]]; then + codemgr_parent=$(git --git-dir=$codemgr_ws config \ + remote.origin.url 2>/dev/null) + fi + + CWS_REV=$(git --git-dir=$codemgr_ws rev-parse HEAD 2>/dev/null) + PWS=$codemgr_parent + + # + # If the parent is a webrev, we want to do some things against + # the natural workspace parent (file list, comments, etc) + # + if [[ -n $parent_webrev ]]; then + real_parent=$(git --git-dir $codemgr_ws config \ + remote.origin.url 2>/dev/null) + else + real_parent=$PWS + fi + + # + # If git-active exists, then we run it. In the case of no explicit + # flist given, we'll use it for our comments. In the case of an + # explicit flist given we'll try to use it for comments for any + # files mentioned in the flist. + # + if [[ -z $flist_done ]]; then + flist_from_git $CWS $real_parent + flist_done=1 + fi + + # + # If we have a file list now, pull out any variables set + # therein. We do this now (rather than when we possibly use + # git-active to find comments) to avoid stomping specifications + # in the user-specified flist. + # + if [[ -n $flist_done ]]; then + env_from_flist + fi + + # + # Only call git-active if we don't have a wx formatted file already + # + if [[ -x $GIT_ACTIVE && -z $wxfile ]]; then + print " Comments from: git-active -p $real_parent ...\c" + git_active_wxfile $CWS $real_parent + print " Done." + fi + + # + # At this point we must have a wx flist either from git-active, + # or in general. Use it to try and find our parent revision, + # if we don't have one. + # + if [[ -z $GIT_PARENT ]]; then + eval `$SED -e "s/#.*$//" $wxfile | $GREP GIT_PARENT=` + fi + + # + # If we still don't have a parent, we must have been given a + # wx-style active list with no GIT_PARENT specification, run + # git-active and pull an GIT_PARENT out of it, ignore the rest. + # + if [[ -z $GIT_PARENT && -x $GIT_ACTIVE ]]; then + $GIT_ACTIVE -w $codemgr_ws -p $real_parent | \ + eval `$SED -e "s/#.*$//" | $GREP GIT_PARENT=` + elif [[ -z $GIT_PARENT ]]; then + print -u2 "Error: Cannot discover parent revision" + exit 1 + fi + WDIR=${WDIR:-$CWS/../webrev} elif [[ $SCM_MODE == "subversion" ]]; then # --- /dev/null Sat May 9 16:08:44 2009 +++ new/usr/src/tools/findunref/exception_list.git Sat May 9 16:08:44 2009 @@ -0,0 +1,39 @@ +# +# CDDL HEADER START +# +# The contents of this file are subject to the terms of the +# Common Development and Distribution License (the "License"). +# You may not use this file except in compliance with the License. +# +# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE +# or http://www.opensolaris.org/os/licensing. +# See the License for the specific language governing permissions +# and limitations under the License. +# +# When distributing Covered Code, include this CDDL HEADER in each +# file and include the License file at usr/src/OPENSOLARIS.LICENSE. +# If applicable, add the following below this CDDL HEADER, with the +# fields enclosed by brackets "[]" replaced with your own identifying +# information: Portions Copyright [yyyy] [name of copyright owner] +# +# CDDL HEADER END +# + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# + +# +# Git-specific exception list +# +# See README.exception_lists for details +# + +# +# Without nested repositories, this list could be empty, because ON +# checks for unref relative to usr, and the git files are all in the +# root of the repository. +# + +*/.git --- /dev/null Sat May 9 16:08:44 2009 +++ new/usr/src/tools/scripts/git-active.py Sat May 9 16:08:44 2009 @@ -0,0 +1,123 @@ +#! /usr/bin/python +# +# This program is free software; you can redistribute it and/or modify +# 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 2009 Grigale, Inc. All rights reserved. +# Use is subject to license terms. +# + +''' +Create a wx-style active list on stdout based on a Git +workspace in support of webrev's Git support. +''' + +# +# NB: This assumes the normal onbld directory structure +# +import os +import sys +import optparse +import subprocess + +def execCmd(cmd): + '''Executes external command''' + + p = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, + stderr=subprocess.PIPE) + (out, err) = p.communicate() + + if out == None: + out = "" + + return (p.returncode, out.splitlines(), err.splitlines()) + +def usage(): + sys.stderr.write("usage: %s [-p parent] -w workspace\n" % + os.path.basename(__file__)) + sys.exit(2) + +def main(argv): + + parser = optparse.OptionParser(version='%prog 1.0') + parser.add_option("-p", dest="parentpath", default="", help="parent repo") + parser.add_option("-w", dest="wspath", default="", help="workspace") + parser.add_option("-o", dest="outputfile", help="output file") + parser.disable_interspersed_args() + + (options, args) = parser.parse_args() + + if not options.wspath: + usage() + + fh = None + if options.outputfile: + try: + fh = open(options.outputfile, 'w') + except EnvironmentError, e: + sys.stderr.write("could not open output file: %s\n" % e) + sys.exit(1) + else: + fh = sys.stdout + + cmd = ["git", "--git-dir=%s" % options.wspath, "log", "--name-only", + "--parents", "--reverse", "--pretty=short", "master.."] + (rc, out, err) = execCmd(cmd) + + #print rc, out, err + + if "commit" in out[0]: + parent = out[0].split()[2] + + files = {} + comment = None + for i in out: + if "commit" in i: + comment = None + continue + if i == "" or i.startswith("Author"): + continue + if i.startswith(" "): + comment = i.strip() + continue + if comment: + if i not in files: + files[i] = [] + files[i].append(comment) + + fh.write("GIT_PARENT=%s\n" % parent) + + for file in files: + #if entry.is_renamed(): + # fh.write("%s %s\n" % (entry.name, entry.parentname)) + #else: + # fh.write("%s\n" % entry.name) + fh.write("%s\n\n" % file) + fh.write("%s\n\n" % '\n'.join(files[file])) + +#try: +# Version.check_version() +#except Version.VersionMismatch, e: +# sys.stderr.write("Error: %s\n" % e) +# sys.exit(1) + +if __name__ == '__main__': + try: + main(sys.argv[1:]) + except KeyboardInterrupt: + sys.exit(1) +# except util.Abort, msg: +# sys.stderr.write("Abort: %s\n" % msg) +# sys.exit(1) --- old/usr/src/tools/SUNWonbld/prototype_com Sat May 9 16:08:45 2009 +++ new/usr/src/tools/SUNWonbld/prototype_com Sat May 9 16:08:45 2009 @@ -70,6 +70,7 @@ f none opt/onbld/bin/flg.flp 555 root bin f none opt/onbld/bin/genoffsets 555 root bin f none opt/onbld/bin/get_depend_info 555 root bin +f none opt/onbld/bin/git-active 555 root bin f none opt/onbld/bin/hdrchk 555 root bin f none opt/onbld/bin/hg-active 555 root bin f none opt/onbld/bin/hgsetup 555 root bin --- old/usr/src/tools/README.tools Sat May 9 16:08:45 2009 +++ new/usr/src/tools/README.tools Sat May 9 16:08:45 2009 @@ -195,6 +195,9 @@ sort > ~/unref-sparc.out $ comm -12 ~/unref-i386.out ~/unref-sparc.out > ~/unref.out +git-active + helper used by webrev to generate file lists for Git workspaces. + hdrchk checks headers for compliance with OS/Net standards (form, includes, C++ guards).