scripts: make generate_git do something
authorPaul Gortmaker <paul.gortmaker@windriver.com>
Fri, 28 Sep 2012 15:12:42 +0000 (11:12 -0400)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 5 Dec 2012 22:49:54 +0000 (14:49 -0800)
Generate a git tree from the ltsi queue of patches, by
only using git commands.

Support a quasi intelligent auto resume feature in the case
where a patch fails to apply, by using the upstream ID (if
present) to determine the current patch used for the HEAD
commit.  If that fails, use a diffstat comparison to try
and find the current patch.

Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
scripts/generate_git

index 3c09e7acaca40d47a14805d8a26b1254914eccd3..cb1053d2ef88122aa557bb6c56039910a022452a 100755 (executable)
@@ -9,4 +9,121 @@
 #
 #
 
-echo "Not implemented yet, check back soon."
+UPSTREAM="git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git"
+if [ "$1" = "-a" ]; then
+       AUTORESUME=1
+       shift
+fi
+
+DIR=`dirname $0 |sed 's/scripts$//'`
+SERIES=$DIR/series
+
+if [ -z "$SERIES" ]; then
+       echo Cant find series file at $SERIES
+       exit 1
+fi
+
+if [ -n "$2" ];then
+       START=$2
+fi
+
+diffstat --help > /dev/null 2>&1
+if [ $? != 0 ]; then
+       echo It appears you dont have diffstat installed.
+       echo Please install it.
+       exit 1
+fi
+
+if [ ! -d .git ]; then
+       echo There does not appear to be a git tree in this dir.
+       echo You need a copy of:
+       echo $UPSTREAM
+       echo as a baseline.
+       exit 1
+fi
+
+KVER=`cat $DIR/KERNEL_VERSION`
+git rev-parse -q --verify v$KVER > /dev/null
+if [ $? != 0 ]; then
+       echo There is no \"v$KVER\" in this git repository.  Perhaps pull from:
+       echo $UPSTREAM
+       echo to get this tag?
+       exit 1
+fi
+
+if [ -n "$AUTORESUME" ]; then
+       PARENT=`git show|grep ommit|grep 'pstream\|herry\|tip'|sed 's/.* \([0-9a-f]\+\).*/\1/'`
+       CLEN=`echo $PARENT|wc -c`
+       if [ $CLEN -ne 41 ]; then
+               echo Failed to autodetect resume point -- no parent ID
+               echo falling back to diffstat detection
+               DS1=`mktemp`
+               DS2=`mktemp`
+               git show | diffstat -p0 > $DS1
+               for i in $DIR/*\.patch ; do
+                       cat $i | diffstat -p0 > $DS2
+                       cmp -s $DS1 $DS2
+                       if [ $? = 0 ]; then
+                               START=$i
+                               break
+                       fi
+               done
+               rm $DS1 $DS2
+               if [ -z "$START" ]; then
+                       echo diffstat detection failed
+                       exit 1
+               fi
+       fi
+
+       if [ -z "$START" ]; then
+               START=`grep -l $PARENT $DIR/patches.*/*`
+       fi
+
+       if [ -z "$START" ]; then
+               echo Failed to autodetect resume point - no matching filename
+               echo for patch that created current HEAD commit $PARENT
+               exit 1
+       fi
+
+       START=`basename $START`
+       echo resuming from current \"$START\"
+fi
+
+if [ -z "$START" ]; then
+       echo creating branch "$KVER-ltsi"
+       git checkout -b $KVER-ltsi v$KVER
+       if [ $? != 0 ]; then
+               echo Creation of branch $KVER-ltsi failed
+               exit 1
+       fi
+fi
+
+COUNT=`cat $SERIES | grep '^[a-zA-Z0-9_]'|wc -l`
+APPLIED=0
+
+for i in `cat $SERIES | grep '^[a-zA-Z0-9_]'`
+do
+
+       APPLIED=$[$APPLIED+1]
+
+       if [ -n "$START" ]; then
+               if [ "$START" != "$i" ];then
+                       continue
+               else
+                       START=""
+                       continue
+               fi
+       fi
+
+       if [ ! -f "$DIR/$i" ];then
+               echo $DIR/$i doesnt exist
+               break
+       fi
+
+       echo -n "($APPLIED/$COUNT) "
+       git am $DIR/$i
+       if [ $? != 0 ];then
+               echo git am of $i failed. STBU.
+               exit 1
+       fi
+done