From 44f180b8a623d69ee5f5ed55ebcb61e1fef6205e Mon Sep 17 00:00:00 2001 From: Yuri Pankov Date: Sat, 26 Mar 2016 19:35:23 +0300 Subject: [PATCH] 6857 webrev: add -c and -h options to specify "head" revision Reviewed by: Toomas Soome Reviewed by: Igor Kozhukhov Approved by: Robert Mustacchi --- usr/src/tools/scripts/webrev.1onbld | 8 ++++- usr/src/tools/scripts/webrev.sh | 63 +++++++++++++++++++++++++++---------- 2 files changed, 54 insertions(+), 17 deletions(-) diff --git a/usr/src/tools/scripts/webrev.1onbld b/usr/src/tools/scripts/webrev.1onbld index 7d8ad9f33f..0bb65d4850 100644 --- a/usr/src/tools/scripts/webrev.1onbld +++ b/usr/src/tools/scripts/webrev.1onbld @@ -22,7 +22,7 @@ .\" Use is subject to license terms. .\" .\" -.TH WEBREV 1ONBLD "Feb 7, 2014" +.TH WEBREV 1ONBLD "Mar 27, 2016" .SH NAME webrev \- Generate HTML codereview materials .SH SYNOPSIS @@ -180,6 +180,9 @@ in /opt/onbld/etc/its.conf. These file formats are self documenting. Also see the -I and -C options below. .SH OPTIONS .TP 10 +.BI "-c " revision +Generate webrev for single commit specified by \fIrevision\fR (git only). +.TP 10 .BI "-C " priority-file In addition to the system default and an optional user-supplied ~/.its.conf, use the specified file to specify a local domain list and prioritize the list @@ -198,6 +201,9 @@ expected that the remote host periodically runs a script which deletes the contents of this directory. See the ENVIRONMENT VARIABLES section for more details about this directory. .TP 10 +.BI "-h " head-revision +Specify the explicit head to generate webrev from (git only). +.TP 10 .BI "-I " information-file Use the specified file to seed the list of information tracking systems. .TP 10 diff --git a/usr/src/tools/scripts/webrev.sh b/usr/src/tools/scripts/webrev.sh index 78a66359b9..5fbed75864 100644 --- a/usr/src/tools/scripts/webrev.sh +++ b/usr/src/tools/scripts/webrev.sh @@ -25,7 +25,7 @@ # Copyright 2008, 2010, Richard Lowe # Copyright 2012 Marcel Telka # Copyright 2014 Bart Coddens -# Copyright 2015 Nexenta Systems, Inc. All rights reserved. +# Copyright 2016 Nexenta Systems, Inc. # # @@ -1766,9 +1766,10 @@ function git_wxfile TMPFLIST=/tmp/$$.active $PERL -e 'my (%files, %realfiles, $msg); - my $branch = $ARGV[0]; + my $parent = $ARGV[0]; + my $child = $ARGV[1]; - open(F, "git diff -M --name-status $branch |"); + open(F, "git diff -M --name-status $parent..$child |"); while () { chomp; if (/^R(\d+)\s+([^ ]+)\s+([^ ]+)/) { # rename @@ -1786,7 +1787,7 @@ function git_wxfile close(F); my $state = 1; # 0|comments, 1|files - open(F, "git whatchanged --pretty=format:%B $branch.. |"); + open(F, "git whatchanged --pretty=format:%B $parent..$child |"); while () { chomp; if (/^:[0-9]{6}/) { @@ -1811,7 +1812,7 @@ function git_wxfile } else { print "$_\n$files{$_}\n\n" } - }' ${parent} > $TMPFLIST + }' ${parent} ${child} > $TMPFLIST wxfile=$TMPFLIST } @@ -2122,8 +2123,10 @@ function usage webrev [common-options] -w Options: + -c : generate webrev for single revision (git only) -C : Use for the information tracking configuration. -D: delete remote webrev + -h : specify "head" revision for comparison (git only) -i : Include in the index.html file. -I : Use for the information tracking registry. -n: do not generate the webrev (useful with -U) @@ -2213,10 +2216,12 @@ typeset -r DEFAULT_REMOTE_HOST="cr.opensolaris.org" typeset -r rsync_prefix="rsync://" typeset -r ssh_prefix="ssh://" +cflag= Cflag= Dflag= flist_mode= flist_file= +hflag= iflag= Iflag= lflag= @@ -2235,14 +2240,21 @@ remote_target= # NOTE: when adding/removing options it is necessary to sync the list # with usr/src/tools/onbld/hgext/cdm.py # -while getopts "C:Di:I:lnNo:Op:t:Uw" opt +while getopts "c:C:Dh:i:I:lnNo:Op:t:Uw" opt do case $opt in + c) cflag=1 + codemgr_head=$OPTARG + codemgr_parent=$OPTARG~1;; + C) Cflag=1 ITSCONF=$OPTARG;; D) Dflag=1;; + h) hflag=1 + codemgr_head=$OPTARG;; + i) iflag=1 INCLUDE_FILE=$OPTARG;; @@ -2571,11 +2583,21 @@ if [[ $SCM_MODE == "mercurial" ]]; then 2>/dev/null) PRETTY_CWS="${CWS} (at ${cnode})"} elif [[ $SCM_MODE == "git" ]]; then - # + # Check that "head" revision specified with -c or -h is sane + if [[ -n $cflag || -n $hflag ]]; then + head_rev=$($GIT rev-parse --verify --quiet "$codemgr_head") + if [[ -z $head_rev ]]; then + print -u2 "Error: bad revision ${codemgr_head}" + exit 1 + fi + fi + + if [[ -z $codemgr_head ]]; then + codemgr_head="HEAD"; + fi + # 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 @@ -2610,7 +2632,7 @@ elif [[ $SCM_MODE == "git" ]]; then fi if [[ -z $flist_done ]]; then - flist_from_git "$CWS" "$real_parent" + flist_from_git "$codemgr_head" "$real_parent" flist_done=1 fi @@ -2628,12 +2650,12 @@ elif [[ $SCM_MODE == "git" ]]; then # if [[ -z $wxfile ]]; then print " Comments from: git...\c" - git_wxfile "$CWS" "$real_parent" + git_wxfile "$codemgr_head" "$real_parent" print " Done." fi if [[ -z $GIT_PARENT ]]; then - GIT_PARENT=$($GIT merge-base "$real_parent" HEAD) + GIT_PARENT=$($GIT merge-base "$real_parent" "$codemgr_head") fi if [[ -z $GIT_PARENT ]]; then print -u2 "Error: Cannot discover parent revision" @@ -2642,18 +2664,27 @@ elif [[ $SCM_MODE == "git" ]]; then pnode=$(trim_digest $GIT_PARENT) - if [[ $real_parent == */* ]]; then + if [[ -n $cflag ]]; then + PRETTY_PWS="previous revision (at ${pnode})" + elif [[ $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})" + elif [[ -n $pflag && -z $parent_webrev ]]; then + PRETTY_PWS="${CWS} (explicit revision ${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})" + cnode=$($GIT --git-dir=${codemgr_ws}/.git rev-parse --short=12 \ + ${codemgr_head} 2>/dev/null) + + if [[ -n $cflag || -n $hflag ]]; then + PRETTY_CWS="${CWS} (explicit head at ${cnode})" + else + PRETTY_CWS="${CWS} (at ${cnode})" + fi elif [[ $SCM_MODE == "subversion" ]]; then # -- 2.11.4.GIT