Print this page
Let webrev recognize git

Split Close
Expand all
Collapse all
          --- old/usr/src/tools/scripts/webrev.sh
          +++ new/usr/src/tools/scripts/webrev.sh
↓ open down ↓ 1771 lines elided ↑ open up ↑
1772 1772                  print -u2 "Error: hg-active tool not found.  Exiting"
1773 1773                  exit 1
1774 1774          fi
1775 1775          hg_active_wxfile $child $parent
1776 1776          
1777 1777          # flist_from_wx prints the Done, so we don't have to.
1778 1778          flist_from_wx $TMPFLIST
1779 1779  }
1780 1780  
1781 1781  #
     1782 +# Call git-active to get the active list output in the wx active list format
     1783 +#
     1784 +function git_active_wxfile
     1785 +{
     1786 +        typeset child=$1
     1787 +        typeset parent=$2
     1788 +
     1789 +        TMPFLIST=/tmp/$$.active
     1790 +        $GIT_ACTIVE -w $child -p $parent -o $TMPFLIST
     1791 +        wxfile=$TMPFLIST
     1792 +}
     1793 +
     1794 +#
     1795 +# flist_from_git
     1796 +# Call git-active to get a wx-style active list, and hand it off to
     1797 +# flist_from_wx
     1798 +#
     1799 +function flist_from_git 
     1800 +{
     1801 +        typeset child=$1
     1802 +        typeset parent=$2
     1803 +
     1804 +        print " File list from: git-active -p $parent ...\c"
     1805 +
     1806 +        if [[ ! -x $GIT_ACTIVE ]]; then
     1807 +                print           # Blank line for the \c above
     1808 +                print -u2 "Error: git-active tool not found.  Exiting"
     1809 +                exit 1
     1810 +        fi
     1811 +        git_active_wxfile $child $parent
     1812 +        
     1813 +        # flist_from_wx prints the Done, so we don't have to.
     1814 +        flist_from_wx $TMPFLIST
     1815 +}
     1816 +
     1817 +#
1782 1818  # flist_from_subversion
1783 1819  #
1784 1820  # Generate the file list by extracting file names from svn status.
1785 1821  #
1786 1822  function flist_from_subversion
1787 1823  {
1788 1824          CWS=$1
1789 1825          OLDPWD=$2
1790 1826  
1791 1827          cd $CWS
↓ open down ↓ 199 lines elided ↑ open up ↑
1991 2027                          if [[ -n $old_mode ]]; then
1992 2028                                  chmod $old_mode $olddir/$PDIR/$PF
1993 2029                          else
1994 2030                                  # should never happen
1995 2031                                  print -u2 "ERROR: set mode of $olddir/$PDIR/$PF"
1996 2032                          fi
1997 2033                  fi
1998 2034          fi
1999 2035  }
2000 2036  
     2037 +function build_old_new_git
     2038 +{
     2039 +        typeset olddir="$1"
     2040 +        typeset newdir="$2"
     2041 +        typeset old_mode=
     2042 +        typeset new_mode=
     2043 +        typeset old_object=
     2044 +        typeset new_object=
     2045 +        typeset file
     2046 +        typeset type
     2047 +
     2048 +        #
     2049 +        # Get old file and its mode from the git object tree
     2050 +        #
     2051 +        if [[ "$PDIR" == "." ]]; then
     2052 +                file="$PF"
     2053 +        else
     2054 +                file="$PDIR/$PF"
     2055 +        fi
     2056 +        git ls-tree $GIT_PARENT $file | read old_mode type old_object junk
     2057 +        git cat-file $type $old_object > $olddir/$file 2>/dev/null 
     2058 +
     2059 +        if (( $? != 0 )); then
     2060 +                rm -f $olddir/$PDIR/$PF
     2061 +        else
     2062 +                if [[ -n $old_mode ]]; then
     2063 +                        chmod $old_mode $olddir/$PDIR/$PF
     2064 +                else
     2065 +                        # should never happen
     2066 +                        print -u2 "ERROR: set mode of $olddir/$PDIR/$PF"
     2067 +                fi
     2068 +        fi
     2069 +
     2070 +        #
     2071 +        # new version of the file.
     2072 +        #
     2073 +        rm -rf $newdir/$DIR/$F
     2074 +        if [[ -e $CWS/../$DIR/$F ]]; then
     2075 +                cp $CWS/../$DIR/$F $newdir/$DIR/$F
     2076 +                # Temporary new_node = old_mode
     2077 +                new_mode=$old_mode
     2078 +                if [[ -n $new_mode ]]; then
     2079 +                        chmod $new_mode $newdir/$DIR/$F
     2080 +                else
     2081 +                        # should never happen
     2082 +                        print -u2 "ERROR: set mode of $newdir/$DIR/$F"
     2083 +                fi
     2084 +        fi
     2085 +
     2086 +}
     2087 +
2001 2088  function build_old_new_subversion
2002 2089  {
2003 2090          typeset olddir="$1"
2004 2091          typeset newdir="$2"
2005 2092  
2006 2093          # Snag new version of file.
2007 2094          rm -f $newdir/$DIR/$F
2008 2095          [[ -e $CWS/$DIR/$F ]] && cp $CWS/$DIR/$F $newdir/$DIR/$F
2009 2096  
2010 2097          if [[ -n $PWS && -e $PWS/$PDIR/$PF ]]; then
↓ open down ↓ 40 lines elided ↑ open up ↑
2051 2138          typeset olddir="$WDIR/raw_files/old"
2052 2139          typeset newdir="$WDIR/raw_files/new"
2053 2140  
2054 2141          mkdir -p $olddir/$PDIR
2055 2142          mkdir -p $newdir/$DIR
2056 2143  
2057 2144          if [[ $SCM_MODE == "teamware" ]]; then
2058 2145                  build_old_new_teamware "$olddir" "$newdir"
2059 2146          elif [[ $SCM_MODE == "mercurial" ]]; then
2060 2147                  build_old_new_mercurial "$olddir" "$newdir"
     2148 +        elif [[ $SCM_MODE == "git" ]]; then
     2149 +                build_old_new_git "$olddir" "$newdir"
2061 2150          elif [[ $SCM_MODE == "subversion" ]]; then
2062 2151                  build_old_new_subversion "$olddir" "$newdir"
2063 2152          elif [[ $SCM_MODE == "unknown" ]]; then
2064 2153                  build_old_new_unknown "$olddir" "$newdir"
2065 2154          fi
2066 2155  
2067 2156          if [[ ! -f $olddir/$PDIR/$PF && ! -f $newdir/$DIR/$F ]]; then
2068 2157                  print "*** Error: file not in parent or child"
2069 2158                  return 1
2070 2159          fi
↓ open down ↓ 46 lines elided ↑ open up ↑
2117 2206  
2118 2207  trap "rm -f /tmp/$$.* ; exit" 0 1 2 3 15
2119 2208  
2120 2209  set +o noclobber
2121 2210  
2122 2211  PATH=$(dirname $(whence $0)):$PATH
2123 2212  
2124 2213  [[ -z $WDIFF ]] && WDIFF=`look_for_prog wdiff`
2125 2214  [[ -z $WX ]] && WX=`look_for_prog wx`
2126 2215  [[ -z $HG_ACTIVE ]] && HG_ACTIVE=`look_for_prog hg-active`
     2216 +[[ -z $GIT_ACTIVE ]] && GIT_ACTIVE=`look_for_prog git-active`
2127 2217  [[ -z $WHICH_SCM ]] && WHICH_SCM=`look_for_prog which_scm`
2128 2218  [[ -z $CODEREVIEW ]] && CODEREVIEW=`look_for_prog codereview`
2129 2219  [[ -z $PS2PDF ]] && PS2PDF=`look_for_prog ps2pdf`
2130 2220  [[ -z $PERL ]] && PERL=`look_for_prog perl`
2131 2221  [[ -z $RSYNC ]] && RSYNC=`look_for_prog rsync`
2132 2222  [[ -z $SCCS ]] && SCCS=`look_for_prog sccs`
2133 2223  [[ -z $AWK ]] && AWK=`look_for_prog nawk`
2134 2224  [[ -z $AWK ]] && AWK=`look_for_prog gawk`
2135 2225  [[ -z $AWK ]] && AWK=`look_for_prog awk`
2136 2226  [[ -z $SCP ]] && SCP=`look_for_prog scp`
↓ open down ↓ 145 lines elided ↑ open up ↑
2282 2372  elif [[ $SCM_MODE == "mercurial" ]]; then
2283 2373          #
2284 2374          # Mercurial priorities:
2285 2375          # 1. hg root from CODEMGR_WS environment variable
2286 2376          # 2. hg root from directory of invocation
2287 2377          #
2288 2378          [[ -z $codemgr_ws && -n $CODEMGR_WS ]] && \
2289 2379              codemgr_ws=$(hg root -R $CODEMGR_WS 2>/dev/null)
2290 2380          [[ -z $codemgr_ws ]] && codemgr_ws=$(hg root 2>/dev/null)
2291 2381          CWS=$codemgr_ws
     2382 +elif [[ $SCM_MODE == "git" ]]; then
     2383 +        #
     2384 +        # Git priorities:
     2385 +        # 1. git rev-parse --git-dir from CODEMGR_WS environment variable
     2386 +        # 2. git rev-parse --git-dir from directory of invocation
     2387 +        #
     2388 +        [[ -z $codemgr_ws && -n $CODEMGR_WS ]] && \
     2389 +            codemgr_ws=$(git --git-dir=$CODEMGR_WS rev-parse --git-dir \
     2390 +                2>/dev/null)
     2391 +        [[ -z $codemgr_ws ]] && \
     2392 +            codemgr_ws=$(git rev-parse --git-dir 2>/dev/null)
     2393 +        CWS=$codemgr_ws
2292 2394  elif [[ $SCM_MODE == "subversion" ]]; then
2293 2395          #
2294 2396          # Subversion priorities:
2295 2397          # 1. CODEMGR_WS from environment
2296 2398          # 2. Relative path from current directory to SVN repository root
2297 2399          #
2298 2400          if [[ -n $CODEMGR_WS && -d $CODEMGR_WS/.svn ]]; then
2299 2401                  CWS=$CODEMGR_WS
2300 2402          else
2301 2403                  svn info | while read line; do
↓ open down ↓ 65 lines elided ↑ open up ↑
2367 2469          else
2368 2470                  flist_mode="auto"
2369 2471          fi
2370 2472  fi
2371 2473  
2372 2474  #
2373 2475  # Before we go on to further consider -l and -w, work out which SCM we think
2374 2476  # is in use.
2375 2477  #
2376 2478  case "$SCM_MODE" in
2377      -teamware|mercurial|subversion)
     2479 +teamware|mercurial|git|subversion)
2378 2480          ;;
2379 2481  unknown)
2380 2482          if [[ $flist_mode == "auto" ]]; then
2381 2483                  print -u2 "Unable to determine SCM in use and file list not specified"
2382 2484                  print -u2 "See which_scm(1) for SCM detection information."
2383 2485                  exit 1
2384 2486          fi
2385 2487          ;;
2386 2488  *)
2387 2489          if [[ $flist_mode == "auto" ]]; then
↓ open down ↓ 123 lines elided ↑ open up ↑
2511 2613          # (4) If we still don't have a value for codemgr_parent, get it
2512 2614          # from workspace.
2513 2615          #
2514 2616          [[ -z $codemgr_parent ]] && codemgr_parent=`workspace parent`
2515 2617          if [[ ! -d $codemgr_parent ]]; then
2516 2618                  print -u2 "$CODEMGR_PARENT: no such parent workspace"
2517 2619                  exit 1
2518 2620          fi
2519 2621  
2520 2622          PWS=$codemgr_parent
2521      -
     2623 +\
     2624 +    
2522 2625          [[ -n $parent_webrev ]] && RWS=$(workspace parent $CWS)
2523 2626  
2524 2627  elif [[ $SCM_MODE == "mercurial" ]]; then
2525 2628          #
2526 2629          # Parent can either be specified with -p
2527 2630          # Specified with CODEMGR_PARENT in the environment
2528 2631          # or taken from hg's default path.
2529 2632          #
2530 2633  
2531 2634          if [[ -z $codemgr_parent && -n $CODEMGR_PARENT ]]; then
↓ open down ↓ 61 lines elided ↑ open up ↑
2593 2696          # wx-style active list with no HG_PARENT specification, run
2594 2697          # hg-active and pull an HG_PARENT out of it, ignore the rest.
2595 2698          #
2596 2699          if [[ -z $HG_PARENT && -x $HG_ACTIVE ]]; then
2597 2700                  $HG_ACTIVE -w $codemgr_ws -p $real_parent | \
2598 2701                      eval `$SED -e "s/#.*$//" | $GREP HG_PARENT=`
2599 2702          elif [[ -z $HG_PARENT ]]; then
2600 2703                  print -u2 "Error: Cannot discover parent revision"
2601 2704                  exit 1
2602 2705          fi
     2706 +elif [[ $SCM_MODE == "git" ]]; then
     2707 +        #
     2708 +        # Parent can either be specified with -p
     2709 +        # Specified with CODEMGR_PARENT in the environment
     2710 +        # or taken from git config.
     2711 +        #
     2712 +
     2713 +        if [[ -z $codemgr_parent && -n $CODEMGR_PARENT ]]; then
     2714 +                codemgr_parent=$CODEMGR_PARENT
     2715 +        fi
     2716 +
     2717 +        if [[ -z $codemgr_parent ]]; then
     2718 +                codemgr_parent=$(git --git-dir=$codemgr_ws config \
     2719 +                    remote.origin.url 2>/dev/null)
     2720 +        fi
     2721 +
     2722 +        CWS_REV=$(git --git-dir=$codemgr_ws rev-parse HEAD 2>/dev/null)
     2723 +        PWS=$codemgr_parent
     2724 +
     2725 +        # 
     2726 +        # If the parent is a webrev, we want to do some things against
     2727 +        # the natural workspace parent (file list, comments, etc)
     2728 +        #
     2729 +        if [[ -n $parent_webrev ]]; then
     2730 +                real_parent=$(git --git-dir $codemgr_ws config \
     2731 +                    remote.origin.url 2>/dev/null)
     2732 +        else
     2733 +                real_parent=$PWS
     2734 +        fi
     2735 +
     2736 +        #
     2737 +        # If git-active exists, then we run it.  In the case of no explicit
     2738 +        # flist given, we'll use it for our comments.  In the case of an
     2739 +        # explicit flist given we'll try to use it for comments for any
     2740 +        # files mentioned in the flist.
     2741 +        #
     2742 +        if [[ -z $flist_done ]]; then
     2743 +                flist_from_git $CWS $real_parent
     2744 +                flist_done=1
     2745 +        fi
     2746 +
     2747 +        #
     2748 +        # If we have a file list now, pull out any variables set
     2749 +        # therein.  We do this now (rather than when we possibly use
     2750 +        # git-active to find comments) to avoid stomping specifications
     2751 +        # in the user-specified flist.
     2752 +        # 
     2753 +        if [[ -n $flist_done ]]; then
     2754 +                env_from_flist
     2755 +        fi
     2756 +
     2757 +        #
     2758 +        # Only call git-active if we don't have a wx formatted file already
     2759 +        #
     2760 +        if [[ -x $GIT_ACTIVE && -z $wxfile ]]; then
     2761 +                print "  Comments from: git-active -p $real_parent ...\c"
     2762 +                git_active_wxfile $CWS $real_parent
     2763 +                print " Done."
     2764 +        fi
     2765 +        
     2766 +        #
     2767 +        # At this point we must have a wx flist either from git-active,
     2768 +        # or in general.  Use it to try and find our parent revision,
     2769 +        # if we don't have one.
     2770 +        #
     2771 +        if [[ -z $GIT_PARENT ]]; then
     2772 +                eval `$SED -e "s/#.*$//" $wxfile | $GREP GIT_PARENT=`
     2773 +        fi
     2774 +
     2775 +        #
     2776 +        # If we still don't have a parent, we must have been given a
     2777 +        # wx-style active list with no GIT_PARENT specification, run
     2778 +        # git-active and pull an GIT_PARENT out of it, ignore the rest.
     2779 +        #
     2780 +        if [[ -z $GIT_PARENT && -x $GIT_ACTIVE ]]; then
     2781 +                $GIT_ACTIVE -w $codemgr_ws -p $real_parent | \
     2782 +                    eval `$SED -e "s/#.*$//" | $GREP GIT_PARENT=`
     2783 +        elif [[ -z $GIT_PARENT ]]; then
     2784 +                print -u2 "Error: Cannot discover parent revision"
     2785 +                exit 1
     2786 +        fi
     2787 +        WDIR=${WDIR:-$CWS/../webrev}
2603 2788  elif [[ $SCM_MODE == "subversion" ]]; then
2604 2789  
2605 2790          #
2606 2791          # We only will have a real parent workspace in the case one
2607 2792          # was specified (be it an older webrev, or another checkout).
2608 2793          #
2609 2794          [[ -n $codemgr_parent ]] && PWS=$codemgr_parent
2610 2795  
2611 2796          if [[ -z $flist_done && $flist_mode == "auto" ]]; then
2612 2797                  flist_from_subversion $CWS $OLDPWD
↓ open down ↓ 886 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX