summaryrefslogblamecommitdiffstats
path: root/merge-helpers/mkChangeLogList
blob: a97bb28bf153791bedf01e5d8f1735d295cdce3b (plain) (tree)
1
2
3
4
5
6
7

          
                                                             

                                              
                                      
 






                                        
                                   













                                                                                  
                
         
                                  


                         
                            

                          
                              












                                              
                   
 
                      
















                             
         
                      
         
    
                                                                    
        

  





                                                         

























                                                                                  


























                                                                         


                                            
 

































                                                                         
 

    
           
      
#! /bin/sh
#
#   Use git from the current directory and put the file names
#   in suitable format for use in a ChangeLog.
#
#   TODO:  Initial conversion from cvs
#

mklog_()
{
  cat >XXX
  if test `cat XXX | wc -l` -ne 0 ; then
    (cat XXX | cut -d':' -f2 | \
    sed -e '$!s/$/,/' -e '$s/$/:/' ; \
    test $? -ne 0 || echo "$*" )| \
    xargs -s80 | sed -e '1s/^/	\* /' -e '2,$s/^/	/' 
  fi
  rm -f XXX
}

progname=${0##*/}
usage()
{
  echo "$progname [-ln] [-u user] [-U user_information] [-m message] [-M msgfile]"
  exit 1
}

print_name="no"
user=$LOGNAME
git_local_arg=""
basedir=.
while getopts d:lnM:m:p:c:u:U: OPT
do
  case "$OPT" in 
    d) basedir=$OPTARG ;;
    l) git_local_arg="-l" ;;
    n) print_name="yes" ;;
    p) prnum=$OPTARG ;;
    c) coverity_num=$OPTARG ;;
    m) message=$OPTARG ;; 
    M) message=`cat $OPTARG` ;; 
    u) user=$OPTARG ; print_name="yes" ;;
    U) user_name=$OPTARG ; print_name="yes" ;;
    *) usage ;;
  esac
done

let $((shiftcount = $OPTIND - 1))
shift #shiftcount

args=$*

dirarg="${basedir}"

# Determine VCS in use
isgit()
{
  depth=0
  dir=.git
  while [ $depth -lt 10 ]
  do
    if [ -d ${dir} ] ; then
      return 1
    fi
    dir=../${dir}
    depth=`expr ${depth} + 1`
  done  
  return 0
}

isgit
if [ $? -eq 1 ] ; then
  VCS=git
elif [ -d CVS ] ; then
  VCS=cvs
else
  echo "This does not look like a checkout from a VCS I understand."
  exit 1
fi

if [ ! -r ChangeLog ] ; then
  ( echo "There is no ChangeLog in this directory." ;
    echo "Where are you putting the entry?" )>/dev/stderr
  exit 1
fi

case ${VCS} in
  cvs)
    # done parsing arguments, now work 
    if [ "X${CVSROOT}" = "X" ] ; then
      CVS=cvs
    else
      CVS="cvs -d ${CVSROOT}"
    fi
    CVS="${CVS}"

    files_modded=`${CVS} diff ${dirarg} 2>&1 | grep ^Index | wc -l`
    files_added=`${CVS} diff ${dirarg} 2>&1 | grep "is a new entry, no " | wc -l`
    files_deleted=`${CVS} diff ${dirarg} 2>&1 | grep " was removed, no " | wc -l`
    ;;
  git)
    files_modded=`git status ${dirarg} 2>&1 | grep "modified: " | wc -l`
    files_added=`git status ${dirarg} 2>&1 | grep "new file: " | wc -l`
    files_deleted=0
    #files_deleted=`${CVS} diff ${dirarg} 2>&1 | grep " was removed, no " | wc -l`
    ;;
  *)
    echo "${VCS} to be implemented"
    exit 1
    ;;
esac

files_changed=`expr ${files_modded} + ${files_added} + ${files_deleted}`
if test ${files_changed} -eq 0 ; then
  exit 0
fi

if test ${print_name} = "yes" ; then
  if test "X${user_name}" = "X" ; then
    if test "X${user}" = "X" ; then
      echo "User not specified (LOGNAME not set or no -u option)"
      usage
    fi

    user_name=`grep ^${user} /etc/passwd | cut -d':' -f5 | cut -d',' -f1`
    if test "X${user_name}" = "X" ; then
      echo "User information not set"
      usage
    fi
  fi

  date=`date +%Y-%m-%d`
  echo "${date}	${user_name}"
  echo
fi

if test "X${prnum}" != "X" ; then
  echo "	PR ${prnum}"
fi
if test "X${coverity_num}" != "X" ; then
  echo "	Coverity Id ${coverity_num}"
fi

case ${VCS} in
  cvs)
    # Generate list of modified files
    ${CVS} diff ${dirarg} 2>/dev/null | grep ^Index | mklog_ ${message}

    # Generate list of deleted files
    test ${files_added} -gt 1 && plural=s
    ${CVS} diff ${dirarg} 2>&1 | grep "is a new entry, no comparison" | \
      sed -e 's/^.*: //' -e 's/ is a .*$//' | mklog_ "New file${plural}."

    # Generate list of removed files
    ${CVS} diff ${dirarg} 2>&1 | grep "was removed, no comparison" | \
      sed -e 's/^.*: //' -e 's/ was removed, no comparison.*$//' | \
      mklog_ Removed.
    ;;
  git)
    # Generate list of modified files
    git status 2>&1 | grep "modified: " | mklog_ ${message}

    # Generate list of deleted files
    test ${files_added} -gt 1 && plural=s
    git status 2>&1 | grep "new file: " | \
      sed -e 's/^.*: //' -e 's/ is a .*$//' | mklog_ "New file${plural}."

    # Generate list of removed files
    #${CVS} diff ${dirarg} 2>&1 | grep "was removed, no comparison" | \
    #  sed -e 's/^.*: //' -e 's/ was removed, no comparison.*$//' | \
    #  mklog_ Removed.
    ;;
  *)
    echo "${VCS} to be implemented"
    exit 1
    ;;
esac

echo

# rm -f XXX
exit 0