[rtems-testing commit] Add initial git support to merge-helper scripts

Joel Sherrill joel at rtems.org
Thu Feb 23 14:02:53 UTC 2012


Module:    rtems-testing
Branch:    master
Commit:    07bc90a71759dd653adf4df5b5c3f6bdabceb04a
Changeset: http://git.rtems.org/rtems-testing/commit/?id=07bc90a71759dd653adf4df5b5c3f6bdabceb04a

Author:    Joel Sherrill <joel.sherrill at oarcorp.com>
Date:      Thu Feb 23 07:51:50 2012 -0600

Add initial git support to merge-helper scripts

---

 merge-helpers/ChangeLog       |  184 +++++++++++++++++++++++++++++++++++++++++
 merge-helpers/commit          |   43 ++++++++--
 merge-helpers/mkChangeLogList |   18 ++++-
 3 files changed, 236 insertions(+), 9 deletions(-)

diff --git a/merge-helpers/ChangeLog b/merge-helpers/ChangeLog
index 9ba8d76..307d47b 100644
--- a/merge-helpers/ChangeLog
+++ b/merge-helpers/ChangeLog
@@ -1,3 +1,187 @@
+#! /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
+#
+#  $Id: mkChangeLogList,v 1.6 2011/01/04 19:53:53 joel Exp $
+#
+
+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
 2011-08-31	Joel Sherrill <joel.sherrill at oarcorp.com>
 
 	* check_submission: Check for tabs in source files.
diff --git a/merge-helpers/commit b/merge-helpers/commit
index 8d32ebc..1f9b473 100755
--- a/merge-helpers/commit
+++ b/merge-helpers/commit
@@ -26,7 +26,23 @@ usage()
 }
 
 # Determine VCS in use
-if [ -d .git ] ; then
+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
@@ -104,7 +120,7 @@ if test "X${userInfo}" = "X" ; then
   fi
 fi
 
-commit()
+commit_helper()
 {
   if [ $? -ne 0 ] ; then
     return
@@ -120,7 +136,8 @@ commit()
       ;;
     git)
       echo "git commit -F ${changefile}"
-      git commit -a -F ${changefile}
+      git add ${changefile} 
+      git commit -F ${changefile}
       ;;
     *) echo "${VCS} to be implemented" ;  exit 1 ;;
   esac
@@ -141,10 +158,20 @@ for ddir in ${subdirs} ; do
   test "${ddir}" = "autom4te.cache" && continue
   test "${ddir}" = "install" && continue
   if [ -d "${ddir}" ]; then
-    if [ ! -d "${ddir}/${VCSDIR}" ] ; then
-      echo "WARNING - ${ddir} is not in .git"
-      continue
-    fi
+    case ${VCS} in
+      cvs) 
+	if [ ! -d "${ddir}/${VCSDIR}" ] ; then
+	  echo "WARNING - ${ddir} is not in .git"
+	  continue
+	fi
+        ;;
+      git)
+        ;;
+      *)
+        echo "${VCS} to be implemented"
+        exit 1
+        ;;
+    esac
     test -f "${ddir}/ChangeLog" || continue
     cd "$ddir" >/dev/null
     mkChangeLogList ${mkchoptions} ${userArg} "${userInfo}" \
@@ -157,7 +184,7 @@ for ddir in ${subdirs} ; do
       response="n"
       read -p "Commit changes? [y/n/e(edit)]: " response
       case ${response} in
-        y) commit; break ;;
+        y) commit_helper; break ;;
         n) break ;;
         e) ${editor} ${changefile} ;;
         *) echo "*** enter y,n, or e ***" ;;
diff --git a/merge-helpers/mkChangeLogList b/merge-helpers/mkChangeLogList
index 5d9fe9c..007297b 100755
--- a/merge-helpers/mkChangeLogList
+++ b/merge-helpers/mkChangeLogList
@@ -55,7 +55,23 @@ args=$*
 dirarg="${basedir}"
 
 # Determine VCS in use
-if [ -d .git ] ; then
+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




More information about the vc mailing list