]> www.infradead.org Git - users/hch/xfsprogs.git/commitdiff
libxfs-apply: auto-name patches for guilt
authorDave Chinner <david@fromorbit.com>
Thu, 2 Jul 2015 03:07:01 +0000 (13:07 +1000)
committerDave Chinner <david@fromorbit.com>
Thu, 2 Jul 2015 03:07:01 +0000 (13:07 +1000)
When applying a series of commits, having to write a name for each
of them is time consuming. instead, just use the same method
'guilt import-commit' uses and use the commit header to generate the
filename automatically.

Again, this is simply lifted from guilt....

Signed-off-by: Dave Chinner <david@fromorbit.com>
tools/libxfs-apply

index 80ade23cd9ddfa5d2bf60cb4db9df83a526b8d94..acc53815ca82d7cfbe402fd3eb5f06e876ef0694 100755 (executable)
@@ -160,6 +160,8 @@ filter_xfsprogs_patch()
 apply_patch()
 {
        local _patch=$1
+       local _patch_name=$2
+       local _current_commit=$3
        local _new_patch=`mktemp`
 
        if [ -d "fs/xfs/libxfs" ]; then
@@ -182,19 +184,43 @@ apply_patch()
                        echo -n "Top patch is: "
                        guilt top
                fi
-               read -r -p "Create new Guilt patch? (Enter patch name or return to skip) " response
-               if [ -n "$response" ]; then
-                       guilt refresh;
-                       guilt import -P $response $_new_patch
-                       guilt push
+
+               guilt import -P $_patch_name $_new_patch
+               guilt push
+               if [ $? -ne 0 ]; then
+                       echo "Guilt push failed!"
+                       echo "Force push patch, fix and refresh."
+                       echo "Restart from commit $_current_commit"
+                       fail "Manual cleanup required!"
                fi
+               guilt refresh
        else
                echo "Applying with patch utility:"
                patch -p1 < $_new_patch
+               echo "Patch was applied in $REPO; check for rejects, etc"
        fi
 
        rm -f $_new_patch
-       echo "Patch was applied in $REPO; check for rejects, guilt push -f, etc"
+}
+
+# name a guilt patch. Code is lifted from guilt import-commit.
+name_patch()
+{
+       s=`git log --no-decorate --pretty=oneline -1 $1 | cut -c 42-`
+
+       # Try to convert the first line of the commit message to a
+       # valid patch name.
+       fname=`printf %s "$s" |  \
+                       sed -e "s/&/and/g" -e "s/[ :]/_/g" -e "s,[/\\],-,g" \
+                           -e "s/['\\[{}]//g" -e 's/]//g' -e 's/\*/-/g' \
+                           -e 's/\?/-/g' -e 's/\.\.\.*/./g' -e 's/^\.//' \
+                           -e 's/\.patch$//' -e 's/\.$//' | tr A-Z a-z`
+
+       # Try harder to make it a legal commit name by
+       # removing all but a few safe characters.
+       fname=`echo $fname|tr -d -c _a-zA-Z0-9---/\\n`
+
+       echo $fname
 }
 
 # single patch is easy.
@@ -228,9 +254,10 @@ for commit in $commit_list; do
        # switch to source repo and pull commit into a patch file
        pushd $REPO > /dev/null
        git show $commit > $PATCH || usage "Bad source commit ID!"
+       patch_name=`name_patch $commit`
        popd > /dev/null
 
-       apply_patch $PATCH
+       apply_patch $PATCH $patch_name $commit
 done