summaryrefslogtreecommitdiff
path: root/usr/src/tools/scripts/webrev.sh
diff options
context:
space:
mode:
Diffstat (limited to 'usr/src/tools/scripts/webrev.sh')
-rw-r--r--usr/src/tools/scripts/webrev.sh258
1 files changed, 149 insertions, 109 deletions
diff --git a/usr/src/tools/scripts/webrev.sh b/usr/src/tools/scripts/webrev.sh
index 018341fe71..318feff6cb 100644
--- a/usr/src/tools/scripts/webrev.sh
+++ b/usr/src/tools/scripts/webrev.sh
@@ -516,6 +516,16 @@ html_quote()
$SED -e "s/&/\&amp;/g" -e "s/</\&lt;/g" -e "s/>/\&gt;/g" "$@" | expand
}
+#
+# Trim a digest-style revision to a conventionally readable yet useful length
+#
+trim_digest()
+{
+ typeset digest=$1
+
+ echo $digest | $SED -e 's/\([0-9a-f]\{12\}\).*/\1/'
+}
+
#
# input_cmd | its2url | output_cmd
#
@@ -1780,36 +1790,75 @@ function flist_from_mercurial
}
#
-# Call git-active to get the active list output in the wx active list format
+# Transform a specified 'git log' output format into a wx-like active list.
#
-function git_active_wxfile
+function git_wxfile
{
- typeset child=$1
- typeset parent=$2
+ typeset child="$1"
+ typeset parent="$2"
TMPFLIST=/tmp/$$.active
- $GIT_ACTIVE -w $child -p $parent -o $TMPFLIST
+ $PERL -e 'my (%files, %realfiles, $msg);
+ my $branch = $ARGV[0];
+
+ open(F, "git diff -M --name-status $branch |");
+ while (<F>) {
+ chomp;
+ if (/^R(\d+)\s+([^ ]+)\s+([^ ]+)/) { # rename
+ if ($1 >= 75) { # Probably worth treating as a rename
+ $realfiles{$3} = $2
+ } else {
+ $realfiles{$3} = $3;
+ $realfiles{$2} = $2;
+ }
+ } else {
+ my $f = (split /\s+/, $_)[1];
+ $realfiles{$f} = $f;
+ }
+ }
+ close(F);
+
+ my $state = 1; # 0|comments, 1|files
+ open(F, "git whatchanged --pretty=format:%B $branch.. |");
+ while (<F>) {
+ chomp;
+ if (/^:[0-9]{6}/) {
+ my $fname = (split /\t/, $_)[1];
+ next if !defined($realfiles{$fname}); # No real change
+ $state = 1;
+ $files{$fname} = $msg;
+ } else {
+ if ($state == 1) {
+ $state = 0;
+ $msg = /^\n/ ? "" : "\n";
+ }
+ $msg .= "$_\n" if ($_);
+ }
+ }
+ close(F);
+
+ for (sort keys %files) {
+ if ($realfiles{$_} ne $_) {
+ print "$_ $realfiles{$_}\n$files{$_}\n";
+ } else {
+ print "$_\n$files{$_}\n"
+ }
+ }' ${parent} > $TMPFLIST
+
wxfile=$TMPFLIST
}
#
# flist_from_git
-# Call git-active to get a wx-style active list, and hand it off to
-# flist_from_wx
+# Build 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
+ print " File list from: git ...\c"
+ git_wxfile "$child" "$parent";
# flist_from_wx prints the Done, so we don't have to.
flist_from_wx $TMPFLIST
@@ -2039,36 +2088,41 @@ function build_old_new_git
{
typeset olddir="$1"
typeset newdir="$2"
- typeset ws_top_dir=$(dirname $3)
typeset o_mode=
typeset n_mode=
typeset o_object=
typeset n_object=
+ typeset OWD=$PWD
typeset file
typeset type
+ cd $CWS
+
#
# Get old file and its mode from the git object tree
#
if [[ "$PDIR" == "." ]]; then
file="$PF"
else
- file="$PDIR/$PF"
+ file="$PDIR/$PF"
fi
- curr_dir=$(pwd)
- cd $ws_top_dir
-
- git ls-tree $GIT_PARENT $file | read o_mode type o_object junk
- git cat-file $type $o_object > $olddir/$file 2>/dev/null
-
- if (( $? != 0 )); then
- rm -f $olddir/$file
- elif [[ -n $o_mode ]]; then
- chmod $o_mode $olddir/$file
+ if [[ -n $parent_webrev && -e $PWS/$PDIR/$PF ]]; then
+ cp $PWS/$PDIR/$PF $olddir/$PDIR/$PF
else
- # should never happen
- print -u2 "ERROR: set mode of $olddir/$file"
+ $GIT ls-tree $GIT_PARENT $file | read o_mode type o_object junk
+ $GIT cat-file $type $o_object > $olddir/$file 2>/dev/null
+
+ if (( $? != 0 )); then
+ rm -f $olddir/$file
+ elif [[ -n $o_mode ]]; then
+ # Strip the first 3 digits, to get a regular octal mode
+ o_mode=${o_mode/???/}
+ chmod $o_mode $olddir/$file
+ else
+ # should never happen
+ print -u2 "ERROR: set mode of $olddir/$file"
+ fi
fi
#
@@ -2080,16 +2134,12 @@ function build_old_new_git
file="$DIR/$F"
fi
rm -rf $newdir/$file
- git ls-tree HEAD $file | read n_mode type n_object junk
- git cat-file $type $n_object > $newdir/$file 2>/dev/null
- cd $curr_dir
- if [[ -n $n_mode ]]; then
- chmod $n_mode $newdir/$file
- else
- # should never happen
- print -u2 "ERROR: set mode of $newdir/$file"
- fi
+ if [[ -e $CWS/$DIR/$F ]]; then
+ cp $CWS/$DIR/$F $newdir/$DIR/$F
+ chmod $(get_file_mode $CWS/$DIR/$F) $newdir/$DIR/$F
+ fi
+ cd $OWD
}
function build_old_new_subversion
@@ -2153,7 +2203,7 @@ function build_old_new
elif [[ $SCM_MODE == "mercurial" ]]; then
build_old_new_mercurial "$olddir" "$newdir"
elif [[ $SCM_MODE == "git" ]]; then
- build_old_new_git "$olddir" "$newdir" "$CWS"
+ build_old_new_git "$olddir" "$newdir"
elif [[ $SCM_MODE == "subversion" ]]; then
build_old_new_subversion "$olddir" "$newdir"
elif [[ $SCM_MODE == "unknown" ]]; then
@@ -2215,12 +2265,12 @@ trap "rm -f /tmp/$$.* ; exit" 0 1 2 3 15
set +o noclobber
-PATH=$(dirname $(whence $0)):$PATH
+PATH=$(dirname "$(whence $0)"):$PATH
[[ -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 $GIT ]] && GIT=`look_for_prog git`
[[ -z $WHICH_SCM ]] && WHICH_SCM=`look_for_prog which_scm`
[[ -z $CODEREVIEW ]] && CODEREVIEW=`look_for_prog codereview`
[[ -z $PS2PDF ]] && PS2PDF=`look_for_prog ps2pdf`
@@ -2410,15 +2460,16 @@ elif [[ $SCM_MODE == "git" ]]; then
# 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)
+ codemgr_ws=$($GIT --git-dir=$CODEMGR_WS/.git rev-parse --git-dir \
+ 2>/dev/null)
[[ -z $codemgr_ws ]] && \
- codemgr_ws=$(git rev-parse --git-dir 2>/dev/null)
+ codemgr_ws=$($GIT rev-parse --git-dir 2>/dev/null)
if [[ "$codemgr_ws" == ".git" ]]; then
- codemgr_ws="$PWD/.git"
+ codemgr_ws="${PWD}/${codemgr_ws}"
fi
+ codemgr_ws=$(dirname $codemgr_ws) # Lose the '/.git'
CWS="$codemgr_ws"
elif [[ $SCM_MODE == "subversion" ]]; then
#
@@ -2471,8 +2522,8 @@ fi
# then note that fact and set the parent to the raw_files/new subdirectory.
#
if [[ -n $pflag && -d $codemgr_parent/raw_files/new ]]; then
- parent_webrev="$codemgr_parent"
- codemgr_parent="$codemgr_parent/raw_files/new"
+ parent_webrev=$(readlink -f "$codemgr_parent")
+ codemgr_parent=$(readlink -f "$codemgr_parent/raw_files/new")
fi
if [[ -z $wflag && -z $lflag ]]; then
@@ -2665,7 +2716,6 @@ elif [[ $SCM_MODE == "mercurial" ]]; then
codemgr_parent=`hg path -R $codemgr_ws default 2>/dev/null`
fi
- CWS_REV=`hg parent -R $codemgr_ws --template '{node|short}' 2>/dev/null`
PWS=$codemgr_parent
#
@@ -2729,23 +2779,36 @@ elif [[ $SCM_MODE == "mercurial" ]]; then
print -u2 "Error: Cannot discover parent revision"
exit 1
fi
+
+ pnode=$(trim_digest $HG_PARENT)
+ PRETTY_PWS="${PWS} (at ${pnode})"
+ cnode=$(hg parent -R $codemgr_ws --template '{node|short}' \
+ 2>/dev/null)
+ PRETTY_CWS="${CWS} (at ${cnode})"}
elif [[ $SCM_MODE == "git" ]]; then
#
- # Parent can either be specified with -p
- # Specified with CODEMGR_PARENT in the environment
- # or taken from git config.
+ # Parent can either be specified with -p, or specified with
+ # CODEMGR_PARENT in the environment.
#
if [[ -z $codemgr_parent && -n $CODEMGR_PARENT ]]; then
codemgr_parent=$CODEMGR_PARENT
fi
+ # Try to figure out the parent based on the branch the current
+ # branch is tracking, if we fail, use origin/master
+ this_branch=$($GIT branch | nawk '$1 == "*" { print $2 }')
+ par_branch="origin/master"
+
+ $GIT for-each-ref \
+ --format='%(refname:short) %(upstream:short)' refs/heads/ | \
+ while read local remote; do \
+ [[ "$local" == "$this_branch" ]] && par_branch="$remote"; \
+ done
+
if [[ -z $codemgr_parent ]]; then
- codemgr_parent=$(git --git-dir=$codemgr_ws config \
- remote.origin.url 2>/dev/null)
+ codemgr_parent=$par_branch
fi
-
- CWS_REV=$(git --git-dir=$codemgr_ws rev-parse HEAD 2>/dev/null)
PWS=$codemgr_parent
#
@@ -2753,63 +2816,56 @@ elif [[ $SCM_MODE == "git" ]]; then
# 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)
+ real_parent=$par_branch
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_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.
+ # therein.
#
if [[ -n $flist_done ]]; then
env_from_flist
fi
#
- # Only call git-active if we don't have a wx formatted file already
+ # If we don't have a wx-format file list, build one we can pull change
+ # comments from.
#
- if [[ -x $GIT_ACTIVE && -z $wxfile ]]; then
- print " Comments from: git-active -p $real_parent ...\c"
- git_active_wxfile $CWS $real_parent
+ if [[ -z $wxfile ]]; then
+ print " Comments from: git...\c"
+ git_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=`
+ GIT_PARENT=$($GIT merge-base "$real_parent" HEAD)
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
+ if [[ -z $GIT_PARENT ]]; then
print -u2 "Error: Cannot discover parent revision"
exit 1
fi
+
+ pnode=$(trim_digest $GIT_PARENT)
+
+ if [[ $real_parent == */* ]]; then
+ origin=$(echo $real_parent | cut -d/ -f1)
+ origin=$($GIT remote -v | \
+ $AWK '$1 == "'$origin'" { print $2; exit }')
+ PRETTY_PWS="${PWS} (${origin} at ${pnode})"
+ else
+ PRETTY_PWS="${PWS} (at ${pnode})"
+ fi
+
+ cnode=$($GIT --git-dir=${codemgr_ws}/.git rev-parse --short=12 HEAD \
+ 2>/dev/null)
+ PRETTY_CWS="${CWS} (at ${cnode})"
elif [[ $SCM_MODE == "subversion" ]]; then
#
@@ -2876,7 +2932,7 @@ typeset -A itsinfo
typeset -r its_sed_script=/tmp/$$.its_sed
valid_prefixes=
if [[ -z $nflag ]]; then
- DEFREGFILE="$(dirname $(whence $0))/../etc/its.reg"
+ DEFREGFILE="$(dirname "$(whence $0)")/../etc/its.reg"
if [[ -n $Iflag ]]; then
REGFILE=$ITSREG
elif [[ -r $HOME/.its.reg ]]; then
@@ -2905,7 +2961,7 @@ if [[ -z $nflag ]]; then
done
- DEFCONFFILE="$(dirname $(whence $0))/../etc/its.conf"
+ DEFCONFFILE="$(dirname "$(whence $0)")/../etc/its.conf"
CONFFILES=$DEFCONFFILE
if [[ -r $HOME/.its.conf ]]; then
CONFFILES="${CONFFILES} $HOME/.its.conf"
@@ -3094,21 +3150,11 @@ fi
#
# Summarize what we're going to do.
#
-if [[ -n $CWS_REV ]]; then
- print " Workspace: $CWS (at $CWS_REV)"
-else
- print " Workspace: $CWS"
-fi
+print " Workspace: ${PRETTY_CWS:-$CWS}"
if [[ -n $parent_webrev ]]; then
print "Compare against: webrev at $parent_webrev"
else
- if [[ -n $HG_PARENT ]]; then
- hg_parent_short=`echo $HG_PARENT \
- | $SED -e 's/\([0-9a-f]\{12\}\).*/\1/'`
- print "Compare against: $PWS (at $hg_parent_short)"
- else
- print "Compare against: $PWS"
- fi
+ print "Compare against: ${PRETTY_PWS:-$PWS}"
fi
[[ -n $INCLUDE_FILE ]] && print " Including: $INCLUDE_FILE"
@@ -3459,19 +3505,13 @@ fi
PREPDATE=$(LC_ALL=C /usr/bin/date +%Y-%b-%d\ %R\ %z\ %Z)
print "<tr><th>Prepared by:</th><td>$preparer on $PREPDATE</td></tr>"
-print "<tr><th>Workspace:</th><td>$CWS"
-if [[ -n $CWS_REV ]]; then
- print "(at $CWS_REV)"
-fi
+print "<tr><th>Workspace:</th><td>${PRETTY_CWS:-$CWS}"
print "</td></tr>"
print "<tr><th>Compare against:</th><td>"
if [[ -n $parent_webrev ]]; then
print "webrev at $parent_webrev"
else
- print "$PWS"
- if [[ -n $hg_parent_short ]]; then
- print "(at $hg_parent_short)"
- fi
+ print "${PRETTY_PWS:-$PWS}"
fi
print "</td></tr>"
print "<tr><th>Summary of changes:</th><td>"