usage: patch-tags-from-git <filename> <kernel checkout> Adds a Git-commit: tag from the From header also adds a Patch-mainline: tag if <kernel checkout> is given
Signed-off-by: Brandon Philips bphilips@suse.de --- scripts/patch-tags-from-git | 62 +++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 62 insertions(+), 0 deletions(-) create mode 100755 scripts/patch-tags-from-git
diff --git a/scripts/patch-tags-from-git b/scripts/patch-tags-from-git new file mode 100755 index 0000000..2277376 --- /dev/null +++ b/scripts/patch-tags-from-git @@ -0,0 +1,62 @@ +#!/bin/bash +# Add suse Kernel repo headers to a patch created using git-format-patch +# +# Brandon Philips bphilips@suse.de + +if [ $# -lt 1 ]; then + echo "usage: $0 <filename> <kernel checkout>" + echo "Adds a Git-commit: tag from the From header" + echo "also adds a Patch-mainline: tag if <kernel checkout> is given" + exit 1 +fi + +FILE=$1 + +if [ ! -f $FILE ]; then + echo "No such file $1" + exit 2 +fi + +commit=$(head -n1 $FILE | sed -n "s%From\s([0-9a-f]*)\s.*%\1%p") + +if [ "z$commit" = "z" ]; then + echo "$FILE doesn't look like a patch from git" +else + patch-tag -A git-commit="$commit" $FILE +fi + +if [ $# -ne 2 ]; then + exit 0 +fi + +DIR=$2 + +commit=$(patch-tag -p git-commit $FILE | grep -i "git-commit:" | sed "s%.*:\s(.*)%\1%g") + +if [ "z$commit" = "z" ]; then + echo "No git-commit tag in $FILE" + exit 3 +fi + +export GIT_DIR=$DIR/.git + +if [ ! -d $GIT_DIR ]; then + echo "No such directory $GIT_DIR" + echo 4 +fi + +mainline=$(git describe --contains $commit 2> /dev/null) + +if [ "z$mainline" = "z" ]; then + git show $commit > /dev/null + if git show $commit > /dev/null 2> /dev/null; then + merged=$(basename $DIR) + patch-tag -A Patch-mainline="Merged into $merged" $FILE + exit 0 + else + echo "$commit from $FILE does not exist in $DIR" + exit 5 + fi +fi + +patch-tag -A Patch-mainline="$mainline" $FILE
On Thu, Nov 11, 2010 at 03:49:19PM -0800, Brandon Philips wrote:
usage: patch-tags-from-git <filename> <kernel checkout> Adds a Git-commit: tag from the From header also adds a Patch-mainline: tag if <kernel checkout> is given
Signed-off-by: Brandon Philips bphilips@suse.de
scripts/patch-tags-from-git | 62 +++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 62 insertions(+), 0 deletions(-) create mode 100755 scripts/patch-tags-from-git
diff --git a/scripts/patch-tags-from-git b/scripts/patch-tags-from-git new file mode 100755 index 0000000..2277376 --- /dev/null +++ b/scripts/patch-tags-from-git @@ -0,0 +1,62 @@ +#!/bin/bash +# Add suse Kernel repo headers to a patch created using git-format-patch +# +# Brandon Philips bphilips@suse.de
+if [ $# -lt 1 ]; then
- echo "usage: $0 <filename> <kernel checkout>"
- echo "Adds a Git-commit: tag from the From header"
- echo "also adds a Patch-mainline: tag if <kernel checkout> is given"
- exit 1
+fi
+FILE=$1
+if [ ! -f $FILE ]; then
- echo "No such file $1"
- exit 2
+fi
+commit=$(head -n1 $FILE | sed -n "s%From\s([0-9a-f]*)\s.*%\1%p")
+if [ "z$commit" = "z" ]; then
- echo "$FILE doesn't look like a patch from git"
+else
- patch-tag -A git-commit="$commit" $FILE
+fi
+if [ $# -ne 2 ]; then
- exit 0
+fi
+DIR=$2
+commit=$(patch-tag -p git-commit $FILE | grep -i "git-commit:" | sed "s%.*:\s(.*)%\1%g")
patch-tag is not in PATH.
+if [ "z$commit" = "z" ]; then
- echo "No git-commit tag in $FILE"
- exit 3
+fi
+export GIT_DIR=$DIR/.git
+if [ ! -d $GIT_DIR ]; then
- echo "No such directory $GIT_DIR"
- echo 4
+fi
+mainline=$(git describe --contains $commit 2> /dev/null)
+if [ "z$mainline" = "z" ]; then
- git show $commit > /dev/null
- if git show $commit > /dev/null 2> /dev/null; then
merged=$(basename $DIR)
patch-tag -A Patch-mainline="Merged into $merged" $FILE
exit 0
What's the intended use of this? I assume you have a separate checkout for each subsystem tree, but concluding anything from the directory name is too error-prone IMO. E.g. all patches from me would have "Merged into linux-2.6", people might rename their checkouts etc. If you want to guess some reliable name, you would probably have to find out what refs/remotes/$repository/$branch has the commit and then run 'git config remote.$repository.url' to get a name that makes sense in the Patch-mainline header. Or something among these lines.
Michal
On 16:21 Fri 12 Nov 2010, Michal Marek wrote:
On Thu, Nov 11, 2010 at 03:49:19PM -0800, Brandon Philips wrote:
+commit=$(patch-tag -p git-commit $FILE | grep -i "git-commit:" | sed "s%.*:\s(.*)%\1%g")
patch-tag is not in PATH.
Right, I will do one of these: $(dirname "$0"
+if [ "z$mainline" = "z" ]; then
- git show $commit > /dev/null
- if git show $commit > /dev/null 2> /dev/null; then
merged=$(basename $DIR)
patch-tag -A Patch-mainline="Merged into $merged" $FILE
exit 0
What's the intended use of this? I assume you have a separate checkout for each subsystem tree, but concluding anything from the directory name is too error-prone IMO.
Yes, this is my exact use case.
E.g. all patches from me would have "Merged into linux-2.6", people might rename their checkouts etc. If you want to guess some reliable name, you would probably have to find out what refs/remotes/$repository/$branch has the commit and then run 'git config remote.$repository.url' to get a name that makes sense in the Patch-mainline header. Or something among these lines.
Good point, I will add a command line argument to let the user specify what they would like the Merged into tag to say.
Thanks for the review.
Cheers,
Brandon
Hello Michal-
Here is the second version of this script taking your feedback. I think it works pretty well now. Let me know what you think.
Thanks,
Brandon
---
Add relevant headers for patches pulled from git
Adds a Git-commit: tag using the From header
Adds a Patch-mainline: tag if <kernel path> is given a useful tree name can be provided in <kernel name> otherwise basename <kernel path> will be used
example usage ------------- $0 NULL-pointer-fix.patch $0 NULL-pointer-fix.patch ~/kernel/linux-2.6 $0 NULL-pointer-fix.patch ~/kernel/linux-2.6 pci 2.6
Signed-off-by: Brandon Philips bphilips@suse.de --- scripts/patch-tags-from-git | 82 +++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 82 insertions(+), 0 deletions(-) create mode 100755 scripts/patch-tags-from-git
diff --git a/scripts/patch-tags-from-git b/scripts/patch-tags-from-git new file mode 100755 index 0000000..42b9ce6 --- /dev/null +++ b/scripts/patch-tags-from-git @@ -0,0 +1,82 @@ +#!/bin/bash +# Add suse Kernel repo headers to a patch created using git-format-patch +# +# Brandon Philips bphilips@suse.de + +PATH=$(dirname $0):$PATH + +if [ $# -lt 1 ]; then + echo "usage: $0 <filename> <kernel path> <kernel name>" + echo "Add relevant headers for patches pulled from git" + echo "" + echo "Adds a Git-commit: tag using the From header" + echo "" + echo "Adds a Patch-mainline: tag if <kernel path> is given" + echo " a useful tree name can be provided in <kernel name>" + echo " otherwise basename <kernel path> will be used" + echo "" + echo "example usage" + echo "-------------" + echo "$0 NULL-pointer-fix.patch" + echo "$0 NULL-pointer-fix.patch ~/kernel/linux-2.6" + echo "$0 NULL-pointer-fix.patch ~/kernel/linux-2.6 pci 2.6" + + exit 1 +fi + +FILE=$1 +shift + +if [ ! -f $FILE ]; then + echo "No such file $1" + exit 2 +fi + +commit=$(head -n1 $FILE | sed -n "s%From\s([0-9a-f]*)\s.*%\1%p") + +if [ "z$commit" = "z" ]; then + echo "$FILE doesn't look like a patch from git" +else + patch-tag -A git-commit="$commit" $FILE +fi + +if [ $# -eq 0 ]; then + exit 0 +fi + +DIR=$1 +shift + +commit=$(patch-tag -p git-commit $FILE | grep -i "git-commit:" | sed "s%.*:\s(.*)%\1%g") + +if [ "z$commit" = "z" ]; then + echo "No git-commit tag in $FILE" + exit 3 +fi + +export GIT_DIR=$DIR/.git + +if [ ! -d $GIT_DIR ]; then + echo "No such directory $GIT_DIR" + echo 4 +fi + +mainline=$(git describe --contains $commit 2> /dev/null) + +if [ "z$mainline" = "z" ]; then + git show $commit > /dev/null 2> /dev/null + if git show $commit > /dev/null 2> /dev/null; then + if [ $# -eq 0 ]; then + merged=$(basename $DIR) + else + merged="$@" + fi + patch-tag -A Patch-mainline="Merged into $merged" $FILE + exit 0 + else + echo "$commit from $FILE does not exist in $DIR" + exit 5 + fi +fi + +patch-tag -A Patch-mainline="$mainline" $FILE
On Tue, Mar 08, 2011 at 05:09:51PM -0800, Brandon Philips wrote:
Hello Michal-
Here is the second version of this script taking your feedback. I think it works pretty well now. Let me know what you think.
Thanks,
Brandon
Add relevant headers for patches pulled from git
Adds a Git-commit: tag using the From header
Adds a Patch-mainline: tag if <kernel path> is given a useful tree name can be provided in <kernel name> otherwise basename <kernel path> will be used
example usage
$0 NULL-pointer-fix.patch $0 NULL-pointer-fix.patch ~/kernel/linux-2.6 $0 NULL-pointer-fix.patch ~/kernel/linux-2.6 pci 2.6
Signed-off-by: Brandon Philips bphilips@suse.de
scripts/patch-tags-from-git | 82 +++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 82 insertions(+), 0 deletions(-) create mode 100755 scripts/patch-tags-from-git
diff --git a/scripts/patch-tags-from-git b/scripts/patch-tags-from-git new file mode 100755 index 0000000..42b9ce6 --- /dev/null +++ b/scripts/patch-tags-from-git @@ -0,0 +1,82 @@ +#!/bin/bash +# Add suse Kernel repo headers to a patch created using git-format-patch +# +# Brandon Philips bphilips@suse.de
+PATH=$(dirname $0):$PATH
+if [ $# -lt 1 ]; then
- echo "usage: $0 <filename> <kernel path> <kernel name>"
- echo "Add relevant headers for patches pulled from git"
- echo ""
- echo "Adds a Git-commit: tag using the From header"
- echo ""
- echo "Adds a Patch-mainline: tag if <kernel path> is given"
- echo " a useful tree name can be provided in <kernel name>"
- echo " otherwise basename <kernel path> will be used"
- echo ""
- echo "example usage"
- echo "-------------"
- echo "$0 NULL-pointer-fix.patch"
- echo "$0 NULL-pointer-fix.patch ~/kernel/linux-2.6"
- echo "$0 NULL-pointer-fix.patch ~/kernel/linux-2.6 pci 2.6"
- exit 1
+fi
+FILE=$1 +shift
+if [ ! -f $FILE ]; then
- echo "No such file $1"
- exit 2
+fi
+commit=$(head -n1 $FILE | sed -n "s%From\s([0-9a-f]*)\s.*%\1%p")
+if [ "z$commit" = "z" ]; then
- echo "$FILE doesn't look like a patch from git"
+else
- patch-tag -A git-commit="$commit" $FILE
+fi
+if [ $# -eq 0 ]; then
- exit 0
+fi
+DIR=$1 +shift
+commit=$(patch-tag -p git-commit $FILE | grep -i "git-commit:" | sed "s%.*:\s(.*)%\1%g")
+if [ "z$commit" = "z" ]; then
- echo "No git-commit tag in $FILE"
- exit 3
+fi
+export GIT_DIR=$DIR/.git
+if [ ! -d $GIT_DIR ]; then
- echo "No such directory $GIT_DIR"
- echo 4
+fi
+mainline=$(git describe --contains $commit 2> /dev/null)
+if [ "z$mainline" = "z" ]; then
- git show $commit > /dev/null 2> /dev/null
Stray line?
Otherwise the patch looks ok, I applied it to the scripts branch. When you need the script on a given branch, just type 'git merge origin/scripts'.
Michal
- if git show $commit > /dev/null 2> /dev/null; then
if [ $# -eq 0 ]; then
merged=$(basename $DIR)
else
merged="$@"
fi
patch-tag -A Patch-mainline="Merged into $merged" $FILE
exit 0
- else
echo "$commit from $FILE does not exist in $DIR"
exit 5
- fi
+fi
+patch-tag -A Patch-mainline="$mainline" $FILE
1.7.3.4
-- To unsubscribe, e-mail: opensuse-kernel+unsubscribe@opensuse.org For additional commands, e-mail: opensuse-kernel+help@opensuse.org