]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
libxfs-apply: CLI should specify source of commits
authorDave Chinner <david@fromorbit.com>
Thu, 30 Jul 2015 23:06:58 +0000 (09:06 +1000)
committerDave Chinner <david@fromorbit.com>
Thu, 30 Jul 2015 23:06:58 +0000 (09:06 +1000)
Currently the CLI interface is:

$ libxfs-apply <destination repo> <source repo commits>

And assumes that it is is run in the source repo. It makes
more sense to run it in the destination repository and specify
both the source repo and the commit ids in which it comes from.

Change the CLI argument parsing to use options rather than trying to
guess the intention from the number of CLI options presented. Also
add checking to ensure the options are presented correctly, add more
meaningful error messages and check that the source/destination
repositories are recognised as either kernel or libxfs repositories.

The resulting usage is:

$ libxfs-apply
Need to specify both source repo and commit id

Usage:
        libxfs-apply --source <repodir> --commit <commit_id>
libxfs-apply --patch <patchfile>

libxfs-apply should be run in the destination git repository.
$

And so now option parsing can be expanded indefinitely.

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

index 9f79f8a2d6978907e983626d52046d740a1f2b93..e6538c806224488022a4215508e08796b1f1d87f 100755 (executable)
@@ -5,7 +5,13 @@
 
 usage()
 {
-       echo "libxfs-apply repodir [patchfile|commitid]"
+       echo $*
+       echo
+       echo "Usage:"
+       echo "  libxfs-apply --source <repodir> --commit <commit_id>"
+       echo "  libxfs-apply --patch <patchfile>"
+       echo
+       echo "libxfs-apply should be run in the destination git repository."
        exit
 }
 
@@ -16,35 +22,63 @@ cleanup()
 
 fail()
 {
+       echo "Fail:"
+       echo $*
        cleanup
-       cd $ORIG_DIR
        exit
 }
 
-if [ "$#" -eq 2 -a -d "$1" -a -f "$2" ]; then
-       REPO=$1
-       PATCH=$2
-elif [ "$#" -eq 2 -a -d "$1" ]; then
-       REPO=$1
-       PATCH=`mktemp`
-       git show $2 > $PATCH || usage
-else
-       usage
+# We should see repository contents we recognise, both at the source and
+# destination. Kernel repositorys will have fs/xfs/libxfs, and xfsprogs
+# repositories will have libxcmd.
+check_repo()
+{
+       if [ ! -d "fs/xfs/libxfs" -a ! -d "libxcmd" ]; then
+               usage "$1 repository contents not recognised!"
+       fi
+}
+
+REPO=
+PATCH=
+COMMIT_ID=
+GUILT=0
+
+while [ $# -gt 0 ]; do
+       case "$1" in
+       --source)       REPO=$2 ; shift ;;
+       --patch)        PATCH=$2; shift ;;
+       --commit)       COMMIT_ID=$2 ; shift ;;
+       *)              usage ;;
+       esac
+       shift
+done
+
+if [ -n "$PATCH" ]; then
+       if [ -n "$REPO" -o -n "$COMMIT_ID" ]; then
+               usage "Need to specify either patch or source epo/commit"
+       fi
+elif [ -z "$REPO" -o -z "$COMMIT_ID" ]; then
+       usage "Need to specify both source repo and commit id"
 fi
 
+check_repo Destination
 
-ORIG_DIR=`pwd`
 LIBXFS_FILES=`mktemp`
 NEWPATCH=`mktemp`
 
-cd $REPO
+# switch to source repo and pull the commit into the patch file
+if [ -n "$COMMIT_ID" ]; then
+       pushd $REPO > /dev/null
+       check_repo Source
+       PATCH=`mktemp`
+       git show $2 > $PATCH || usage "Bad source commit ID!"
+       popd > /dev/null
+fi
 
 # Are we using guilt? This works even if no patch is applied.
 guilt top &> /dev/null
 if [ $? -eq 0 ]; then
        GUILT=1
-else
-       GUILT=0
 fi
 
 # Filter the patch into the right format & files for the other tree
@@ -52,8 +86,7 @@ fi
 if   [ -d "fs/xfs/libxfs" ]; then      # We are applying a progs patch to the kernel tree
        lsdiff $PATCH | grep -q "a/libxfs/"
        if [ $? -ne 0 ]; then
-               echo "Doesn't look like an xfsprogs patch with libxfs changes"
-               fail
+               fail "Doesn't look like an xfsprogs patch with libxfs changes"
        fi
 
        # The files we will try to apply to
@@ -70,8 +103,7 @@ if   [ -d "fs/xfs/libxfs" ]; then    # We are applying a progs patch to the kernel
 elif [ -d "libxfs" -a -d "libxlog" ]; then     # We are applying a kernel patch to the xfsprogs tree
        lsdiff $PATCH | grep -q "a/fs/xfs/libxfs/"
        if [ $? -ne 0 ]; then
-               echo "Doesn't look like a kernel patch with libxfs changes"
-               fail
+               fail "Doesn't look like a kernel patch with libxfs changes"
        fi
 
        # The files we will try to apply to
@@ -84,9 +116,6 @@ elif [ -d "libxfs" -a -d "libxlog" ]; then   # We are applying a kernel patch to t
                --addoldprefix=a/ \
                --addnewprefix=b/ \
                $PATCH > $NEWPATCH 
-else
-       echo "Sorry, I don't recognize repo $REPO"
-       fail
 fi
 
 echo "Filtered patch for $REPO contains:"