[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    KDE/kdesdk/scripts
From:       Matthew Woehlke <mw_triad () users ! sourceforge ! net>
Date:       2008-02-29 21:49:06
Message-ID: 1204321746.653638.15558.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 780733 by mwoehlke:

updates to svn{back,forward}port: more "standard" usage information, more \
portable/liberal detection of -h/--help, branch specification (backport, optional, \
default still 4.0) or read-from-actual-url (forwardport), proper argument quoting / \
use of "$@" (hopefully now safe for files with spaces), be more picky about what is \
"yes" when asking to commit, other minor stuff...

NOTE: POSIX states that 'test' with more than three arguments is not portable, and \
it's right; the old code could do something like 'test -z -gt -o -gt = -h -o -gt = \
--help', which is an error; the correct way (as stated many times on bug-bash) is to \
use && and ||, not test's -a/-o. Also use '[', as it looks nicer and I'm not aware of \
any reasonable shell these days that lacks [ as a built-in (even Solaris /bin/sh, \
which is *not* POSIX-compliant, has it), and have used it in my own must-be-portable \
scripts for ages.


 M  +46 -37    svnbackport  
 M  +41 -34    svnforwardport  


--- trunk/KDE/kdesdk/scripts/svnbackport #780732:780733
@@ -1,67 +1,76 @@
 #!/bin/sh
 # Backport the last change in HEAD, to a branch.
-# Usage: svnbackport <files>
-# WARNING: the branch tag is hardcoded into the script, make sure to check it!
+# Usage: svnbackport [-b branch] <file> [<file> ...]
 #
 # This is a port of the "cvsbackport" script:
 # Initial author: Dirk Mueller
 # Support for multiple command-line arguments: David Faure
 # Ported to SVN: Till Gerken
-# Help message: Thomas Zander
+# Options and quote-safety: Matthew Woehlke
 #
-# It is a straight port and not very sophisticated. It might break. I hope
-# that someone else with more knowledge about Subversion will pick it up.
-# It needs to be used from within the repository so that it can guess
-# the remote URL correctly.
+# This isn't the most sophisticated script ever, and might break. It needs to be
+# used from within the repository so that it can guess the remote URL correctly.
 #
 
 #REPOSITORY=https://svn.kde.org/home/kde
 
-if test -z "$1" -o "$1" = "-h" -o "$1" = "--help"; then
-    echo "Usage: svnbackport recentlyCommittedFile";
-    exit;
-fi
+usage() {
+  echo "Usage: $0 [-b <branch>] <file> [<file> ...]"
+  echo "  default branch is $DEF_BRANCH"
+  exit
+}
 
-export LC_ALL="C"
+DEF_BRANCH=4.0
+BRANCH=$DEF_BRANCH
 
-BRANCH=4.0
+while getopts 'b:-:h' opt ; do
+  case $opt in
+    b) BRANCH="$OPTARG";;
+    *) usage;; # -h, --help will also trip this
+  esac
+done
+unset opt
+shift `expr ${OPTIND} - 1`
 
-SRC_REMOTE=`svn info | grep URL: | cut -c6-`
-TARGET_REMOTE=`echo $SRC_REMOTE | sed "s|trunk/KDE|branches/KDE/$BRANCH|"`
+[ -z "$*" ] && usage
 
+export LC_ALL="C"
 
+SRC_REMOTE="`svn info | sed -n '/URL:/s/^URL: //p'`"
+TARGET_REMOTE="`echo $SRC_REMOTE | sed "s|trunk/KDE|branches/KDE/$BRANCH|"`"
+
 echo "Backporting to $BRANCH"
 TMPFILE=`mktemp svnbackport.XXXXXX` || exit 1
-files=$*
-until test $# -eq 0; do
 
-  echo "looking for last change to $1..."
-  svnlastchange -ws $1 > $TMPFILE || exit 1
-  echo "browsing last change to $1..."
-  less $TMPFILE
+for file in "$@" ; do
 
-  FILE_PATH=$1
-  FROM_URL=$SRC_REMOTE/$1
-  TO_URL=$TARGET_REMOTE/$1
+  echo "Looking for last change to $file..."
+  svnlastchange -ws "$file" > $TMPFILE || exit 1
+  echo "Browsing last change to $file..."
+  less "$TMPFILE"
 
-  echo "switching to branch..."
-  svn switch $TO_URL $FILE_PATH
-  patch $FILE_PATH $TMPFILE
-  rm -f $TMPFILE
-  echo "showing diff for $1..."
-  svn diff $FILE_PATH | less
+  FILE_PATH="$file"
+  FROM_URL="$SRC_REMOTE/$file"
+  TO_URL="$TARGET_REMOTE/$file"
 
-  shift
+  echo "Switching to branch..."
+  svn switch "$TO_URL" "$FILE_PATH" || exit 1
+  patch "$FILE_PATH" "$TMPFILE"
+  rm -f "$TMPFILE"
+  echo "Showing diff for $file..."
+  svn diff "$FILE_PATH" | less
+
 done
 
 echo "Do you want to commit all changes? (y/n) [y]"
 read confirm
-if test "$confirm" != "n"; then
-  svn ci $files
+if [ -z "$confirm" ] || [ "`echo $confirm | cut -c 1 | tr Y y`" = "y" ] ; then
+  svn ci "$@"
+else
+  echo "Aborted!" >&2
 fi
 
-echo "switching back to trunk..."
-for file in $files
-do
-  svn switch $SRC_REMOTE/$file $file
+echo "Switching back to trunk..."
+for file in "$@" ; do
+  svn switch "$SRC_REMOTE/$file" "$file"
 done
--- trunk/KDE/kdesdk/scripts/svnforwardport #780732:780733
@@ -1,65 +1,72 @@
 #!/bin/sh
 # Backport the last change in HEAD, to a branch.
 # Usage: svnforwardport <files>
-# WARNING: the branch tag is hardcoded into the script, make sure to check it!
 #
 # This is a port of the "cvsbackport" script:
 # Initial author: Dirk Mueller
 # Support for multiple command-line arguments: David Faure
 # Ported to SVN: Till Gerken
-# Help message: Thomas Zander
+# Better usage, quote-safety: Matthew Woehlke
 #
-# It is a straight port and not very sophisticated. It might break. I hope
-# that someone else with more knowledge about Subversion will pick it up.
-# It needs to be used from within the repository so that it can guess
-# the remote URL correctly.
+# This isn't the most sophisticated script ever, and might break. It needs to be
+# used from within the repository so that it can guess the remote URL correctly.
 #
 
 #REPOSITORY=https://svn.kde.org/home/kde
 
-if test -z "$1" -o "$1" = "-h" -o "$1" = "--help"; then
-    echo "Usage: svnforwardport recentlyCommittedFile";
-    exit;
-fi
+usage() {
+  echo "Usage: $0 <file> [<file> ...]"
+  exit
+}
 
-BRANCH=4.0
+while getopts '-:h' opt ; do
+  case $opt in
+    *) usage;; # -h, --help will also trip this
+  esac
+done
+unset opt
+shift `expr ${OPTIND} - 1`
 
-SRC_REMOTE=`svn info | grep URL: | cut -c6-`
-TARGET_REMOTE=`echo $SRC_REMOTE | sed "s|branches/KDE/$BRANCH|trunk/KDE|"`
+[ -z "$*" ] && usage
 
+export LC_ALL="C"
 
+SRC_REMOTE="`svn info | sed -n '/URL:/s/^URL: //p'`"
+BRANCH="`echo $SRC_REMOTE | sed 's|.*branches/KDE/\([^/]*\).*|\1|'`"
+TARGET_REMOTE=`echo $SRC_REMOTE | sed "s|branches/KDE/$BRANCH|trunk/KDE\1|"`
+
 echo "Forward porting from $BRANCH to trunk"
-TMPFILE=`mktemp svnforport.XXXXXX` || exit 1
-files=$*
-until test $# -eq 0; do
+TMPFILE="`mktemp svnforport.XXXXXX`" || exit 1
 
-  echo "Looking for last change to $1..."
-  svnlastchange -ws $1 > $TMPFILE || exit 1
-  echo "Browsing last change to $1..."
-  less $TMPFILE
+for file in "$@" ; do
 
-  FILE_PATH=$1
-  FROM_URL=$SRC_REMOTE/$1
-  TO_URL=$TARGET_REMOTE/$1
+  echo "Looking for last change to $file..."
+  svnlastchange -ws "$file" > $TMPFILE || exit 1
+  echo "Browsing last change to $file..."
+  less "$TMPFILE"
 
+  FILE_PATH="$file"
+  FROM_URL="$SRC_REMOTE/$file"
+  TO_URL="$TARGET_REMOTE/$file"
+
   echo "Switching to trunk..."
-  svn switch $TO_URL $FILE_PATH
-  patch $FILE_PATH $TMPFILE
-  rm -f $TMPFILE
-  echo "Showing diff for $1..."
-  svn diff $FILE_PATH | less
+  svn switch "$TO_URL" "$FILE_PATH" || exit 1
+  patch "$FILE_PATH" "$TMPFILE"
+  rm -f "$TMPFILE"
+  echo "Showing diff for $file..."
+  svn diff "$FILE_PATH" | less
 
-  shift
 done
 
 echo "Do you want to commit all changes? (y/n) [y]"
 read confirm
-if test "$confirm" != "n"; then
-  svn ci $files
+if [ -z "$confirm" ] || [ "`echo $confirm | cut -c 1 | tr Y y`" = "y" ] ; then
+  svn ci "$@"
+else
+  echo "Aborted!" >&2
 fi
 
 echo "Switching back to branch..."
-for file in $files
-do
-  svn switch $SRC_REMOTE/$file $file
+for file in "$@" ; do
+  svn switch "$SRC_REMOTE/$file" "$file"
 done


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic