Skip to contentSkip to conversation

dim: Properly handle series on apply_branch

PATCH In review Rodrigo Vivi 3 participants 12 messages Aug 17, 2017 – Aug 24, 2017

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 dim: Properly handle series on apply_branch

So far we could use *dim* to apply a whole series in a mbox, but only the very last patch was receiving all the checks and patchwork link.

So this patch remove this limitation by using git mailsplit to split the mbox and than use git am and checks individually on each patch.

Cc Jani Nikula <[email protected]>
Cc Daniel Vetter <[email protected]>
---
 dim | 45 +++++++++++++++++++++++++--------------------
 1 file changed, 25 insertions(+), 20 deletions(-)
dim +25 -20
index 11aa675cc3bc..5457006631d6 100755
@@ -767,38 +767,43 @@ function dim_apply_branch
 	branch=${1:?$usage}
 	shift
 	file=$(mktemp)
+	dir=$(mktemp -d)
 
 	assert_branch $branch
 	assert_repo_clean
 
+	committer_email=$(git_committer_email)
+
 	cat > $file
+	git mailsplit -o$dir $file > /dev/null
 
-	message_id=$(message_get_id $file)
+	for patch in `ls $dir`; do
 
-	committer_email=$(git_committer_email)
+		message_id=$(message_get_id $dir/$patch)
 
-	patch_from=$(grep "From:" "$file" | head -1)
-	if [[ "$patch_from" != *"$committer_email"* ]] ; then
-		sob=-s
-	fi
+		patch_from=$(grep "From:" "$dir/$patch" | head -1)
+		if [[ "$patch_from" != *"$committer_email"* ]] ; then
+			sob=-s
+		fi
 
-	git am --scissors -3 $sob "$@" $file
+		git am --scissors -3 $sob "$@" $dir/$patch
 
-	if [ -n "$message_id" ]; then
-		dim_commit_add_tag "Link: https://patchwork.freedesktop.org/patch/msgid/$message_id"
-	else
-		echoerr "WARNING: No message-id found in the patch file."
-		rv=1
-	fi
+		if [ -n "$message_id" ]; then
+			dim_commit_add_tag "Link: https://patchwork.freedesktop.org/patch/msgid/$message_id"
+		else
+			echoerr "WARNING: No message-id found in the patch file."
+			rv=1
+		fi
 
-	if ! checkpatch_commit HEAD; then
-		rv=1
-	fi
-	if ! check_maintainer $branch HEAD; then
-		rv=1
-	fi
+		if ! checkpatch_commit HEAD; then
+			rv=1
+		fi
+		if ! check_maintainer $branch HEAD; then
+			rv=1
+		fi
 
-	eval $DRY $DIM_POST_APPLY_ACTION
+		eval $DRY $DIM_POST_APPLY_ACTION
+	done
 
 	return $rv
 }
Signature · 6 lines
2.13.2

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#1 lore raw
Quoted 22 lines · Rodrigo Vivi

So far we could use *dim* to apply a whole series in a mbox, but only the very last patch was receiving all the checks and patchwork link.

So this patch remove this limitation by using git mailsplit to split the mbox and than use git am and checks individually on each patch.

Cc Jani Nikula <[email protected]>
Cc Daniel Vetter <[email protected]>
---
 dim | 45 +++++++++++++++++++++++++--------------------
 1 file changed, 25 insertions(+), 20 deletions(-)
dim +0 -0
index 11aa675cc3bc..5457006631d6 100755
@@ -767,38 +767,43 @@ function dim_apply_branch
 	branch=${1:?$usage}
 	shift

dim function dim_apply_branch · line 778

Quoted 10 lines
dim +4 -0
 	file=$(mktemp)
+	dir=$(mktemp -d)
 
 	assert_branch $branch
 	assert_repo_clean
 
+	committer_email=$(git_committer_email)
+
 	cat > $file
+	git mailsplit -o$dir $file > /dev/null

Oh, git mailsplit must have been introduced after I looked into this the last time. Nice.

The downside is that this doesn't work on patches piped from the MUA, because git mailsplit expects an mbox. Fail.

I notice that you indent most of the function in the for loop, perhaps that's an indication you should turn this one into a single patch helper, and do the mailsplit in a new dim_apply_branch that only does that?

dim function dim_apply_branch · line 780

Quoted 3 lines
dim +1 -1
-	message_id=$(message_get_id $file)
+	for patch in `ls $dir`; do

Please use $(...) instead of .... Didn't test, but I think shellcheck would complain.

I think you should do $(find $dir | sort) instead of ls.

Otherwise seems like this should work.

BR,
Jani.

Quoted 48 lines
dim +20 -19
-	committer_email=$(git_committer_email)
+		message_id=$(message_get_id $dir/$patch)
 
-	patch_from=$(grep "From:" "$file" | head -1)
-	if [[ "$patch_from" != *"$committer_email"* ]] ; then
-		sob=-s
-	fi
+		patch_from=$(grep "From:" "$dir/$patch" | head -1)
+		if [[ "$patch_from" != *"$committer_email"* ]] ; then
+			sob=-s
+		fi
 
-	git am --scissors -3 $sob "$@" $file
+		git am --scissors -3 $sob "$@" $dir/$patch
 
-	if [ -n "$message_id" ]; then
-		dim_commit_add_tag "Link: https://patchwork.freedesktop.org/patch/msgid/$message_id"
-	else
-		echoerr "WARNING: No message-id found in the patch file."
-		rv=1
-	fi
+		if [ -n "$message_id" ]; then
+			dim_commit_add_tag "Link: https://patchwork.freedesktop.org/patch/msgid/$message_id"
+		else
+			echoerr "WARNING: No message-id found in the patch file."
+			rv=1
+		fi
 
-	if ! checkpatch_commit HEAD; then
-		rv=1
-	fi
-	if ! check_maintainer $branch HEAD; then
-		rv=1
-	fi
+		if ! checkpatch_commit HEAD; then
+			rv=1
+		fi
+		if ! check_maintainer $branch HEAD; then
+			rv=1
+		fi
 
-	eval $DRY $DIM_POST_APPLY_ACTION
+		eval $DRY $DIM_POST_APPLY_ACTION
+	done
 
 	return $rv
 }
Signature · 5 lines
Jani Nikula, Intel Open Source Technology Center
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#2 lore raw
Quoted 37 lines · Jani Nikula
Quoted 22 lines · Rodrigo Vivi

So far we could use *dim* to apply a whole series in a mbox, but only the very last patch was receiving all the checks and patchwork link.

So this patch remove this limitation by using git mailsplit to split the mbox and than use git am and checks individually on each patch.

Cc Jani Nikula <[email protected]>
Cc Daniel Vetter <[email protected]>
---
 dim | 45 +++++++++++++++++++++++++--------------------
 1 file changed, 25 insertions(+), 20 deletions(-)
dim +0 -0
index 11aa675cc3bc..5457006631d6 100755
@@ -767,38 +767,43 @@ function dim_apply_branch
      branch=${1:?$usage}
      shift

dim function dim_apply_branch · line 778

Quoted 10 lines
dim +4 -0
      file=$(mktemp)
+     dir=$(mktemp -d)
 
      assert_branch $branch
      assert_repo_clean
 
+     committer_email=$(git_committer_email)
+
      cat > $file
+     git mailsplit -o$dir $file > /dev/null

Oh, git mailsplit must have been introduced after I looked into this the last time. Nice.

Quoted 2 lines

The downside is that this doesn't work on patches piped from the MUA, because git mailsplit expects an mbox. Fail.

How do you guys send directly from MUA?
When I was sending from mutt I was saving in an mbox anyway, but nowadays I prefer to get from patchwork that gives exactly the mbox that was validated on CI.
(Reason why I tweaked my dimrc to download directly mbox from a link and apply to dinq...

Anyway are you sure this wouldn't work?!
git mailsplit works with a single patch or single email anyway and I put in a way that I keep the cat > $file

so I don't see reasons why that shouldn't work..

maybe the missing \r and something that
-keep-cr could help with?

Quoted 5 lines

I notice that you indent most of the function in the for loop, perhaps that's an indication you should turn this one into a single patch helper, and do the mailsplit in a new dim_apply_branch that only does that?

good idea... at least I don't mess with current people using directly from mail clients without mbox intermediate...

Quoted 9 lines

dim function dim_apply_branch · line 780

Quoted 4 lines
dim +1 -1
-     message_id=$(message_get_id $file)
+     for patch in `ls $dir`; do

Please use $(...) instead of .... Didn't test, but I think shellcheck would complain.

I think you should do $(find $dir | sort) instead of ls.

yep, make check complained now that I have a version of shellcheck that works ;)

Quoted 61 lines

Otherwise seems like this should work.

BR,
Jani.

Quoted 38 lines
dim +15 -18
-     committer_email=$(git_committer_email)
+             message_id=$(message_get_id $dir/$patch)
 
-     patch_from=$(grep "From:" "$file" | head -1)
-     if [[ "$patch_from" != *"$committer_email"* ]] ; then
-             sob=-s
-     fi
+             patch_from=$(grep "From:" "$dir/$patch" | head -1)
+             if [[ "$patch_from" != *"$committer_email"* ]] ; then
+                     sob=-s
+             fi
 
-     git am --scissors -3 $sob "$@" $file
+             git am --scissors -3 $sob "$@" $dir/$patch
 
-     if [ -n "$message_id" ]; then
-             dim_commit_add_tag "Link: https://patchwork.freedesktop.org/patch/msgid/$message_id"
-     else
-             echoerr "WARNING: No message-id found in the patch file."
-             rv=1
-     fi
+             if [ -n "$message_id" ]; then
+                     dim_commit_add_tag "Link: https://patchwork.freedesktop.org/patch/msgid/$message_id"
+             else
+                     echoerr "WARNING: No message-id found in the patch file."
+                     rv=1
+             fi
 
-     if ! checkpatch_commit HEAD; then
-             rv=1
-     fi
-     if ! check_maintainer $branch HEAD; then
-             rv=1
-     fi
+             if ! checkpatch_commit HEAD; then
+                     rv=1
+             fi

dim function dim_apply_branch · line 809

Quoted 10 lines
dim +5 -1
+             if ! check_maintainer $branch HEAD; then
+                     rv=1
+             fi
 
-     eval $DRY $DIM_POST_APPLY_ACTION
+             eval $DRY $DIM_POST_APPLY_ACTION
+     done
 
      return $rv
 }

--
Jani Nikula, Intel Open Source Technology Center
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

Signature · 6 lines
Rodrigo Vivi
Blog: http://blog.vivi.eng.br
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#3 lore raw
Quoted 38 lines · Rodrigo Vivi
Quoted 37 lines · Jani Nikula
Quoted 22 lines · Rodrigo Vivi

So far we could use *dim* to apply a whole series in a mbox, but only the very last patch was receiving all the checks and patchwork link.

So this patch remove this limitation by using git mailsplit to split the mbox and than use git am and checks individually on each patch.

Cc Jani Nikula <[email protected]>
Cc Daniel Vetter <[email protected]>
---
 dim | 45 +++++++++++++++++++++++++--------------------
 1 file changed, 25 insertions(+), 20 deletions(-)
dim +0 -0
index 11aa675cc3bc..5457006631d6 100755
@@ -767,38 +767,43 @@ function dim_apply_branch
      branch=${1:?$usage}
      shift

dim function dim_apply_branch · line 778

Quoted 10 lines
dim +4 -0
      file=$(mktemp)
+     dir=$(mktemp -d)
 
      assert_branch $branch
      assert_repo_clean
 
+     committer_email=$(git_committer_email)
+
      cat > $file
+     git mailsplit -o$dir $file > /dev/null

Oh, git mailsplit must have been introduced after I looked into this the last time. Nice.

Quoted 4 lines
Quoted 2 lines

The downside is that this doesn't work on patches piped from the MUA, because git mailsplit expects an mbox. Fail.

How do you guys send directly from MUA?

notmuch-emacs lets you pipe the original message as-is.

Quoted 7 lines

When I was sending from mutt I was saving in an mbox anyway, but nowadays I prefer to get from patchwork that gives exactly the mbox that was validated on CI.
(Reason why I tweaked my dimrc to download directly mbox from a link and apply to dinq...

Anyway are you sure this wouldn't work?!

I tried, it didn't work.

Quoted 2 lines

git mailsplit works with a single patch or single email anyway and I put in a way that I keep the cat > $file

It appears to only work if the email is wrapped in an mbox. There is no reason for a MUA to wrap single messages in an mbox. Running git mailsplit on a plain message file in maildir results in "corrupt mailbox" error.

BR,
Jani.

Quoted 88 lines

so I don't see reasons why that shouldn't work..

maybe the missing \r and something that
-keep-cr could help with?

Quoted 5 lines

I notice that you indent most of the function in the for loop, perhaps that's an indication you should turn this one into a single patch helper, and do the mailsplit in a new dim_apply_branch that only does that?

good idea... at least I don't mess with current people using directly from mail clients without mbox intermediate...

Quoted 9 lines

dim function dim_apply_branch · line 780

Quoted 4 lines
dim +1 -1
-     message_id=$(message_get_id $file)
+     for patch in `ls $dir`; do

Please use $(...) instead of .... Didn't test, but I think shellcheck would complain.

I think you should do $(find $dir | sort) instead of ls.

yep, make check complained now that I have a version of shellcheck that works ;)

Quoted 61 lines

Otherwise seems like this should work.

BR,
Jani.

Quoted 38 lines
dim +15 -18
-     committer_email=$(git_committer_email)
+             message_id=$(message_get_id $dir/$patch)
 
-     patch_from=$(grep "From:" "$file" | head -1)
-     if [[ "$patch_from" != *"$committer_email"* ]] ; then
-             sob=-s
-     fi
+             patch_from=$(grep "From:" "$dir/$patch" | head -1)
+             if [[ "$patch_from" != *"$committer_email"* ]] ; then
+                     sob=-s
+             fi
 
-     git am --scissors -3 $sob "$@" $file
+             git am --scissors -3 $sob "$@" $dir/$patch
 
-     if [ -n "$message_id" ]; then
-             dim_commit_add_tag "Link: https://patchwork.freedesktop.org/patch/msgid/$message_id"
-     else
-             echoerr "WARNING: No message-id found in the patch file."
-             rv=1
-     fi
+             if [ -n "$message_id" ]; then
+                     dim_commit_add_tag "Link: https://patchwork.freedesktop.org/patch/msgid/$message_id"
+             else
+                     echoerr "WARNING: No message-id found in the patch file."
+                     rv=1
+             fi
 
-     if ! checkpatch_commit HEAD; then
-             rv=1
-     fi
-     if ! check_maintainer $branch HEAD; then
-             rv=1
-     fi
+             if ! checkpatch_commit HEAD; then
+                     rv=1
+             fi

dim function dim_apply_branch · line 809

Quoted 10 lines
dim +5 -1
+             if ! check_maintainer $branch HEAD; then
+                     rv=1
+             fi
 
-     eval $DRY $DIM_POST_APPLY_ACTION
+             eval $DRY $DIM_POST_APPLY_ACTION
+     done
 
      return $rv
 }

--
Jani Nikula, Intel Open Source Technology Center
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

Signature · 5 lines
Jani Nikula, Intel Open Source Technology Center
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#4 lore raw

PATCH 1/1 dim: Properly handle series on apply_branch

So far we could use *dim* to apply a whole series in a mbox, but only the very last patch was receiving all the checks and patchwork link.

So this patch remove this limitation by using git mailsplit to split the mbox and than use git am and checks individually on each patch.

v2: a. Don't loop with ls $dir nor use ls. Shellcheck recommends
globs instead. Reference: SC2045
c. Split the apply patch in a separated function as suggested
by Jani.
b. Use -b on git mailsplit so it will automatically it is not
an mbox file and parse it assuming a single mail message. This fixes the issue Jani notice with input directly from
MUA: "corrupt mailbox".

Cc Jani Nikula <[email protected]>
Cc Daniel Vetter <[email protected]>
---
 dim | 65 ++++++++++++++++++++++++++++++++++++++---------------------------
 1 file changed, 38 insertions(+), 27 deletions(-)
dim +38 -27
index 11aa675cc3bc..866563624eb5 100755
@@ -756,49 +756,60 @@ function dim_push
 	dim_push_branch $(git_current_branch) "$@"
 }
 
+function apply_patch #patch_file
+{
+	local patch message_id committer_email patch_from sob rv
+
+	patch="$1"
+	message_id=$(message_get_id $patch)
+	committer_email=$(git_committer_email)
+
+	patch_from=$(grep "From:" "$patch" | head -1)
+	if [[ "$patch_from" != *"$committer_email"* ]] ; then
+		sob=-s
+	fi
+
+	git am --scissors -3 $sob "$@" $patch
+
+	if [ -n "$message_id" ]; then
+		dim_commit_add_tag "Link: https://patchwork.freedesktop.org/patch/msgid/$message_id"
+	else
+		echoerr "WARNING: No message-id found in the patch file."
+		rv=1
+	fi
+
+	if ! checkpatch_commit HEAD; then
+		rv=1
+	fi
+	if ! check_maintainer $branch HEAD; then
+		rv=1
+	fi
+
+	eval $DRY $DIM_POST_APPLY_ACTION
+}
+
 # ensure we're on branch $1, and apply patches. the rest of the arguments are
 # passed to git am.
 dim_alias_ab=apply-branch
 dim_alias_sob=apply-branch
 function dim_apply_branch
 {
-	local branch file message_id committer_email patch_from sob rv
+	local branch file
 
 	branch=${1:?$usage}
 	shift
 	file=$(mktemp)
+	dir=$(mktemp -d)
 
 	assert_branch $branch
 	assert_repo_clean
 
 	cat > $file
+	git mailsplit -b -o$dir $file > /dev/null
 
-	message_id=$(message_get_id $file)
-
-	committer_email=$(git_committer_email)
-
-	patch_from=$(grep "From:" "$file" | head -1)
-	if [[ "$patch_from" != *"$committer_email"* ]] ; then
-		sob=-s
-	fi
-
-	git am --scissors -3 $sob "$@" $file
-
-	if [ -n "$message_id" ]; then
-		dim_commit_add_tag "Link: https://patchwork.freedesktop.org/patch/msgid/$message_id"
-	else
-		echoerr "WARNING: No message-id found in the patch file."
-		rv=1
-	fi
-
-	if ! checkpatch_commit HEAD; then
-		rv=1
-	fi
-	if ! check_maintainer $branch HEAD; then
-		rv=1
-	fi
-
-	eval $DRY $DIM_POST_APPLY_ACTION
+	for patch in $dir/*; do
+		apply_patch $patch
+	done
 
 	return $rv
 }
Signature · 6 lines
2.13.2

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#5 lore raw
Quoted 29 lines · Rodrigo Vivi

So far we could use *dim* to apply a whole series in a mbox, but only the very last patch was receiving all the checks and patchwork link.

So this patch remove this limitation by using git mailsplit to split the mbox and than use git am and checks individually on each patch.

v2: a. Don't loop with ls $dir nor use ls. Shellcheck recommends
globs instead. Reference: SC2045
c. Split the apply patch in a separated function as suggested
by Jani.
b. Use -b on git mailsplit so it will automatically it is not
an mbox file and parse it assuming a single mail message. This fixes the issue Jani notice with input directly from
MUA: "corrupt mailbox".

Cc Jani Nikula <[email protected]>
Cc Daniel Vetter <[email protected]>
---
 dim | 65 ++++++++++++++++++++++++++++++++++++++---------------------------
 1 file changed, 38 insertions(+), 27 deletions(-)
dim +0 -0
index 11aa675cc3bc..866563624eb5 100755

dim function dim_push · line 763

Quoted 8 lines
dim +5 -0
@@ -756,49 +756,60 @@ function dim_push
 	dim_push_branch $(git_current_branch) "$@"
 }
 
+function apply_patch #patch_file
+{
+	local patch message_id committer_email patch_from sob rv
+
+	patch="$1"

shift here

dim function dim_push · line 772

Quoted 9 lines
dim +9 -0
+	message_id=$(message_get_id $patch)
+	committer_email=$(git_committer_email)
+
+	patch_from=$(grep "From:" "$patch" | head -1)
+	if [[ "$patch_from" != *"$committer_email"* ]] ; then
+		sob=-s
+	fi
+
+	git am --scissors -3 $sob "$@" $patch

The "$@" no longer gets passed all the way here.

Quoted 6 lines
dim +6 -0
+
+	if [ -n "$message_id" ]; then
+		dim_commit_add_tag "Link: https://patchwork.freedesktop.org/patch/msgid/$message_id"
+	else
+		echoerr "WARNING: No message-id found in the patch file."
+		rv=1

dim function dim_push · line 788

Quoted 10 lines
dim +10 -0
+	fi
+
+	if ! checkpatch_commit HEAD; then
+		rv=1
+	fi
+	if ! check_maintainer $branch HEAD; then
+		rv=1
+	fi
+
+	eval $DRY $DIM_POST_APPLY_ACTION

return $rv.

Quoted 11 lines
dim +3 -1
+}
+
 # ensure we're on branch $1, and apply patches. the rest of the arguments are
 # passed to git am.
 dim_alias_ab=apply-branch
 dim_alias_sob=apply-branch
 function dim_apply_branch
 {
-	local branch file message_id committer_email patch_from sob rv
+	local branch file
 

dim function dim_push · line 808

Quoted 10 lines
dim +2 -0
 	branch=${1:?$usage}
 	shift
 	file=$(mktemp)
+	dir=$(mktemp -d)
 
 	assert_branch $branch
 	assert_repo_clean
 
 	cat > $file
+	git mailsplit -b -o$dir $file > /dev/null

Nitpick, git mailsplit could consume the file directly from stdin, so we no longer have a need for the temp $file.

Quoted 19 lines
dim +0 -18
-	message_id=$(message_get_id $file)
-
-	committer_email=$(git_committer_email)
-
-	patch_from=$(grep "From:" "$file" | head -1)
-	if [[ "$patch_from" != *"$committer_email"* ]] ; then
-		sob=-s
-	fi
-
-	git am --scissors -3 $sob "$@" $file
-
-	if [ -n "$message_id" ]; then
-		dim_commit_add_tag "Link: https://patchwork.freedesktop.org/patch/msgid/$message_id"
-	else
-		echoerr "WARNING: No message-id found in the patch file."
-		rv=1
-	fi
-

dim function dim_push · line 811

Quoted 10 lines
dim +2 -8
-	if ! checkpatch_commit HEAD; then
-		rv=1
-	fi
-	if ! check_maintainer $branch HEAD; then
-		rv=1
-	fi
-
-	eval $DRY $DIM_POST_APPLY_ACTION
+	for patch in $dir/*; do
+		apply_patch $patch

Need to pass "$@" to apply_patch.

Need to handle the return value from apply_patch, and I presume we don't want checkpatch warnings in a single patch to stop applying the rest of the mbox (set -e would abort on errors otherwise). But we want to return non-zero exit status in that case.

BR,
Jani.

Quoted 4 lines
dim +1 -0
+	done
 
 	return $rv
 }
Signature · 5 lines
Jani Nikula, Intel Open Source Technology Center
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#6 lore raw

PATCH 1/1 dim: Properly handle series on apply_branch

So far we could use *dim* to apply a whole series in a mbox, but only the very last patch was receiving all the checks and patchwork link.

So this patch remove this limitation by using git mailsplit to split the mbox and than use git am and checks individually on each patch.

v2: a. Don't loop with ls $dir nor use ls. Shellcheck recommends
globs instead. Reference: SC2045
c. Split the apply patch in a separated function as suggested
by Jani.
b. Use -b on git mailsplit so it will automatically it is not
an mbox file and parse it assuming a single mail message. This fixes the issue Jani notice with input directly from
MUA: "corrupt mailbox".
v3: Pass $@ to apply_patch function and properly handle the shift.
Handle returns. If any patch in the series had some kind of goof return 1.

Cc Jani Nikula <[email protected]>
Cc Daniel Vetter <[email protected]>
---
 dim | 52 ++++++++++++++++++++++++++++++++++------------------
 1 file changed, 34 insertions(+), 18 deletions(-)
dim +34 -18
index 11aa675cc3bc..80ad23a1cd31 100755
@@ -756,33 +756,21 @@ function dim_push
 	dim_push_branch $(git_current_branch) "$@"
 }
 
-# ensure we're on branch $1, and apply patches. the rest of the arguments are
-# passed to git am.
-dim_alias_ab=apply-branch
-dim_alias_sob=apply-branch
-function dim_apply_branch
+function apply_patch #patch_file
 {
-	local branch file message_id committer_email patch_from sob rv
+	local patch message_id committer_email patch_from sob rv
 
-	branch=${1:?$usage}
+	patch="$1"
 	shift
-	file=$(mktemp)
-
-	assert_branch $branch
-	assert_repo_clean
-
-	cat > $file
-
-	message_id=$(message_get_id $file)
-
+	message_id=$(message_get_id $patch)
 	committer_email=$(git_committer_email)
 
-	patch_from=$(grep "From:" "$file" | head -1)
+	patch_from=$(grep "From:" "$patch" | head -1)
 	if [[ "$patch_from" != *"$committer_email"* ]] ; then
 		sob=-s
 	fi
 
-	git am --scissors -3 $sob "$@" $file
+	git am --scissors -3 $sob "$@" $patch
 
 	if [ -n "$message_id" ]; then
 		dim_commit_add_tag "Link: https://patchwork.freedesktop.org/patch/msgid/$message_id"
@@ -799,6 +787,34 @@ function dim_apply_branch
 	fi
 
 	eval $DRY $DIM_POST_APPLY_ACTION
+	return $rv
+}
+
+# ensure we're on branch $1, and apply patches. the rest of the arguments are
+# passed to git am.
+dim_alias_ab=apply-branch
+dim_alias_sob=apply-branch
+function dim_apply_branch
+{
+	local branch file rv
+
+	branch=${1:?$usage}
+	shift
+	file=$(mktemp)
+	dir=$(mktemp -d)
+
+	assert_branch $branch
+	assert_repo_clean
+
+	cat > $file
+	git mailsplit -b -o$dir $file > /dev/null
+
+	for patch in $dir/*; do
+		apply_patch $patch $@
+		if [[ $? -eq "1" ]] ; then
+			rv=1
+		fi
+	done
 
 	return $rv
 }
Signature · 6 lines
2.13.2

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#7 lore raw
Quoted 89 lines · Rodrigo Vivi

So far we could use *dim* to apply a whole series in a mbox, but only the very last patch was receiving all the checks and patchwork link.

So this patch remove this limitation by using git mailsplit to split the mbox and than use git am and checks individually on each patch.

v2: a. Don't loop with ls $dir nor use ls. Shellcheck recommends
globs instead. Reference: SC2045
c. Split the apply patch in a separated function as suggested
by Jani.
b. Use -b on git mailsplit so it will automatically it is not
an mbox file and parse it assuming a single mail message. This fixes the issue Jani notice with input directly from
MUA: "corrupt mailbox".
v3: Pass $@ to apply_patch function and properly handle the shift.
Handle returns. If any patch in the series had some kind of goof return 1.

Cc Jani Nikula <[email protected]>
Cc Daniel Vetter <[email protected]>
---
 dim | 52 ++++++++++++++++++++++++++++++++++------------------
 1 file changed, 34 insertions(+), 18 deletions(-)
dim +20 -18
index 11aa675cc3bc..80ad23a1cd31 100755
@@ -756,33 +756,21 @@ function dim_push
 	dim_push_branch $(git_current_branch) "$@"
 }
 
-# ensure we're on branch $1, and apply patches. the rest of the arguments are
-# passed to git am.
-dim_alias_ab=apply-branch
-dim_alias_sob=apply-branch
-function dim_apply_branch
+function apply_patch #patch_file
 {
-	local branch file message_id committer_email patch_from sob rv
+	local patch message_id committer_email patch_from sob rv
 
-	branch=${1:?$usage}
+	patch="$1"
 	shift
-	file=$(mktemp)
-
-	assert_branch $branch
-	assert_repo_clean
-
-	cat > $file
-
-	message_id=$(message_get_id $file)
-
+	message_id=$(message_get_id $patch)
 	committer_email=$(git_committer_email)
 
-	patch_from=$(grep "From:" "$file" | head -1)
+	patch_from=$(grep "From:" "$patch" | head -1)
 	if [[ "$patch_from" != *"$committer_email"* ]] ; then
 		sob=-s
 	fi
 
-	git am --scissors -3 $sob "$@" $file
+	git am --scissors -3 $sob "$@" $patch
 
 	if [ -n "$message_id" ]; then
 		dim_commit_add_tag "Link: https://patchwork.freedesktop.org/patch/msgid/$message_id"
@@ -799,6 +787,34 @@ function dim_apply_branch
 	fi
 
 	eval $DRY $DIM_POST_APPLY_ACTION
+	return $rv
+}
+
+# ensure we're on branch $1, and apply patches. the rest of the arguments are
+# passed to git am.
+dim_alias_ab=apply-branch
+dim_alias_sob=apply-branch
+function dim_apply_branch
+{
+	local branch file rv
+
+	branch=${1:?$usage}
+	shift
+	file=$(mktemp)

dim function dim_apply_branch · line 813

Quoted 10 lines
dim +10 -0
+	dir=$(mktemp -d)
+
+	assert_branch $branch
+	assert_repo_clean
+
+	cat > $file
+	git mailsplit -b -o$dir $file > /dev/null
+
+	for patch in $dir/*; do
+		apply_patch $patch $@

Should be quoted "$@".

dim function dim_apply_branch · line 814

Quoted 1 line
dim +1 -0
+		if [[ $? -eq "1" ]] ; then

This if will never be executed if apply_patch exit code is != 0 because of set -e. I gave you the example how to call apply_patch! ;)

dim function dim_apply_branch · line 817

Quoted 3 lines
dim +3 -0
+			rv=1
+		fi
+	done

Hmm, could do rm -rf $(file) $(dir) here.

Quoted 3 lines
dim +0 -0
 	return $rv
 }
Signature · 5 lines
Jani Nikula, Intel Open Source Technology Center
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#8 lore raw
Quoted 1 line · Jani Nikula

I gave you the example how to call apply_patch! ;)

Huh, I *thought* I did, maybe I didn't. Sorry.

	if ! apply_patch $patch "$@"; then
		rv=1
	fi

Similar to the checkpatch_commit call in dim_apply_branch.

BR
Jani.

Signature · 5 lines
Jani Nikula, Intel Open Source Technology Center
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#9 lore raw

PATCH 1/1 dim: Properly handle series on apply_branch

So far we could use *dim* to apply a whole series in a mbox, but only the very last patch was receiving all the checks and patchwork link.

So this patch remove this limitation by using git mailsplit to split the mbox and than use git am and checks individually on each patch.

v2: a. Don't loop with ls $dir nor use ls. Shellcheck recommends
globs instead. Reference: SC2045
c. Split the apply patch in a separated function as suggested
by Jani.
b. Use -b on git mailsplit so it will automatically it is not
an mbox file and parse it assuming a single mail message. This fixes the issue Jani notice with input directly from
MUA: "corrupt mailbox".
v3: Pass $@ to apply_patch function and properly handle the shift.
Handle returns. If any patch in the series had some kind of goof return 1.
v4: a. Fix "@"
b. handle in a way that rv gets propagated with set -e c. Delete temporary files and directory.

Cc Jani Nikula <[email protected]>
Cc Daniel Vetter <[email protected]>
---
 dim | 52 ++++++++++++++++++++++++++++++++++------------------
 1 file changed, 34 insertions(+), 18 deletions(-)
dim +34 -18
index 11aa675cc3bc..46bd66f3cd3d 100755
@@ -756,33 +756,21 @@ function dim_push
 	dim_push_branch $(git_current_branch) "$@"
 }
 
-# ensure we're on branch $1, and apply patches. the rest of the arguments are
-# passed to git am.
-dim_alias_ab=apply-branch
-dim_alias_sob=apply-branch
-function dim_apply_branch
+function apply_patch #patch_file
 {
-	local branch file message_id committer_email patch_from sob rv
+	local patch message_id committer_email patch_from sob rv
 
-	branch=${1:?$usage}
+	patch="$1"
 	shift
-	file=$(mktemp)
-
-	assert_branch $branch
-	assert_repo_clean
-
-	cat > $file
-
-	message_id=$(message_get_id $file)
-
+	message_id=$(message_get_id $patch)
 	committer_email=$(git_committer_email)
 
-	patch_from=$(grep "From:" "$file" | head -1)
+	patch_from=$(grep "From:" "$patch" | head -1)
 	if [[ "$patch_from" != *"$committer_email"* ]] ; then
 		sob=-s
 	fi
 
-	git am --scissors -3 $sob "$@" $file
+	git am --scissors -3 $sob "$@" $patch
 
 	if [ -n "$message_id" ]; then
 		dim_commit_add_tag "Link: https://patchwork.freedesktop.org/patch/msgid/$message_id"
@@ -799,6 +787,34 @@ function dim_apply_branch
 	fi
 
 	eval $DRY $DIM_POST_APPLY_ACTION
+	return $rv
+}
+
+# ensure we're on branch $1, and apply patches. the rest of the arguments are
+# passed to git am.
+dim_alias_ab=apply-branch
+dim_alias_sob=apply-branch
+function dim_apply_branch
+{
+	local branch file rv
+
+	branch=${1:?$usage}
+	shift
+	file=$(mktemp)
+	dir=$(mktemp -d)
+
+	assert_branch $branch
+	assert_repo_clean
+
+	cat > $file
+	git mailsplit -b -o$dir $file > /dev/null
+
+	for patch in $dir/*; do
+		if ! apply_patch $patch "$@"; then
+			rv=1
+		fi
+	done
+	rm -rf $file $dir
 
 	return $rv
 }
Signature · 6 lines
2.13.2

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#10 lore raw
Quoted 23 lines · Rodrigo Vivi

So far we could use *dim* to apply a whole series in a mbox, but only the very last patch was receiving all the checks and patchwork link.

So this patch remove this limitation by using git mailsplit to split the mbox and than use git am and checks individually on each patch.

v2: a. Don't loop with ls $dir nor use ls. Shellcheck recommends
globs instead. Reference: SC2045
c. Split the apply patch in a separated function as suggested
by Jani.
b. Use -b on git mailsplit so it will automatically it is not
an mbox file and parse it assuming a single mail message. This fixes the issue Jani notice with input directly from
MUA: "corrupt mailbox".
v3: Pass $@ to apply_patch function and properly handle the shift.
Handle returns. If any patch in the series had some kind of goof return 1.
v4: a. Fix "@"
b. handle in a way that rv gets propagated with set -e c. Delete temporary files and directory.

Quoted 3 lines
Cc Jani Nikula <[email protected]>
Cc Daniel Vetter <[email protected]>

LGTM, and seems to work in my workflow.

BR,
Jani.

Quoted 83 lines
---
 dim | 52 ++++++++++++++++++++++++++++++++++------------------
 1 file changed, 34 insertions(+), 18 deletions(-)
dim +34 -18
index 11aa675cc3bc..46bd66f3cd3d 100755
@@ -756,33 +756,21 @@ function dim_push
 	dim_push_branch $(git_current_branch) "$@"
 }
 
-# ensure we're on branch $1, and apply patches. the rest of the arguments are
-# passed to git am.
-dim_alias_ab=apply-branch
-dim_alias_sob=apply-branch
-function dim_apply_branch
+function apply_patch #patch_file
 {
-	local branch file message_id committer_email patch_from sob rv
+	local patch message_id committer_email patch_from sob rv
 
-	branch=${1:?$usage}
+	patch="$1"
 	shift
-	file=$(mktemp)
-
-	assert_branch $branch
-	assert_repo_clean
-
-	cat > $file
-
-	message_id=$(message_get_id $file)
-
+	message_id=$(message_get_id $patch)
 	committer_email=$(git_committer_email)
 
-	patch_from=$(grep "From:" "$file" | head -1)
+	patch_from=$(grep "From:" "$patch" | head -1)
 	if [[ "$patch_from" != *"$committer_email"* ]] ; then
 		sob=-s
 	fi
 
-	git am --scissors -3 $sob "$@" $file
+	git am --scissors -3 $sob "$@" $patch
 
 	if [ -n "$message_id" ]; then
 		dim_commit_add_tag "Link: https://patchwork.freedesktop.org/patch/msgid/$message_id"
@@ -799,6 +787,34 @@ function dim_apply_branch
 	fi
 
 	eval $DRY $DIM_POST_APPLY_ACTION
+	return $rv
+}
+
+# ensure we're on branch $1, and apply patches. the rest of the arguments are
+# passed to git am.
+dim_alias_ab=apply-branch
+dim_alias_sob=apply-branch
+function dim_apply_branch
+{
+	local branch file rv
+
+	branch=${1:?$usage}
+	shift
+	file=$(mktemp)
+	dir=$(mktemp -d)
+
+	assert_branch $branch
+	assert_repo_clean
+
+	cat > $file
+	git mailsplit -b -o$dir $file > /dev/null
+
+	for patch in $dir/*; do
+		if ! apply_patch $patch "$@"; then
+			rv=1
+		fi
+	done
+	rm -rf $file $dir
 
 	return $rv
 }
Signature · 5 lines
Jani Nikula, Intel Open Source Technology Center
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#11 lore raw
In reply to Jani Nikula
Quoted 88 lines · Jani Nikula
Quoted 29 lines · Rodrigo Vivi

So far we could use *dim* to apply a whole series in a mbox, but only the very last patch was receiving all the checks and patchwork link.

So this patch remove this limitation by using git mailsplit to split the mbox and than use git am and checks individually on each patch.

v2: a. Don't loop with ls $dir nor use ls. Shellcheck recommends
globs instead. Reference: SC2045
c. Split the apply patch in a separated function as suggested
by Jani.
b. Use -b on git mailsplit so it will automatically it is not
an mbox file and parse it assuming a single mail message. This fixes the issue Jani notice with input directly from
MUA: "corrupt mailbox".

Cc Jani Nikula <[email protected]>
Cc Daniel Vetter <[email protected]>
---
 dim | 65 ++++++++++++++++++++++++++++++++++++++---------------------------
 1 file changed, 38 insertions(+), 27 deletions(-)
dim +0 -0
index 11aa675cc3bc..866563624eb5 100755

dim function dim_push · line 763

Quoted 8 lines
dim +5 -0
@@ -756,49 +756,60 @@ function dim_push
      dim_push_branch $(git_current_branch) "$@"
 }
 
+function apply_patch #patch_file
+{
+     local patch message_id committer_email patch_from sob rv
+
+     patch="$1"

shift here

dim function dim_push · line 772

Quoted 9 lines
dim +9 -0
+     message_id=$(message_get_id $patch)
+     committer_email=$(git_committer_email)
+
+     patch_from=$(grep "From:" "$patch" | head -1)
+     if [[ "$patch_from" != *"$committer_email"* ]] ; then
+             sob=-s
+     fi
+
+     git am --scissors -3 $sob "$@" $patch

The "$@" no longer gets passed all the way here.

Quoted 6 lines
dim +6 -0
+
+     if [ -n "$message_id" ]; then
+             dim_commit_add_tag "Link: https://patchwork.freedesktop.org/patch/msgid/$message_id"
+     else
+             echoerr "WARNING: No message-id found in the patch file."
+             rv=1

dim function dim_push · line 788

Quoted 10 lines
dim +10 -0
+     fi
+
+     if ! checkpatch_commit HEAD; then
+             rv=1
+     fi
+     if ! check_maintainer $branch HEAD; then
+             rv=1
+     fi
+
+     eval $DRY $DIM_POST_APPLY_ACTION

return $rv.

Quoted 16 lines
dim +4 -1
+}
+
 # ensure we're on branch $1, and apply patches. the rest of the arguments are
 # passed to git am.
 dim_alias_ab=apply-branch
 dim_alias_sob=apply-branch
 function dim_apply_branch
 {
-     local branch file message_id committer_email patch_from sob rv
+     local branch file
 
      branch=${1:?$usage}
      shift
      file=$(mktemp)
+     dir=$(mktemp -d)
 
Quoted 8 lines

dim function dim_push · line 808

Quoted 5 lines
dim +1 -0
      assert_branch $branch
      assert_repo_clean
 
      cat > $file
+     git mailsplit -b -o$dir $file > /dev/null

Nitpick, git mailsplit could consume the file directly from stdin, so we no longer have a need for the temp $file.

I had considered and tried this here, but didn't worked as I expected... maybe in a separate patch later after playing a bit and test more?

Quoted 53 lines
Quoted 20 lines
dim +0 -18
-     message_id=$(message_get_id $file)
-
-     committer_email=$(git_committer_email)
-
-     patch_from=$(grep "From:" "$file" | head -1)
-     if [[ "$patch_from" != *"$committer_email"* ]] ; then
-             sob=-s
-     fi
-
-     git am --scissors -3 $sob "$@" $file
-
-     if [ -n "$message_id" ]; then
-             dim_commit_add_tag "Link: https://patchwork.freedesktop.org/patch/msgid/$message_id"
-     else
-             echoerr "WARNING: No message-id found in the patch file."
-             rv=1
-     fi
-

dim function dim_push · line 811

Quoted 10 lines
dim +2 -8
-     if ! checkpatch_commit HEAD; then
-             rv=1
-     fi
-     if ! check_maintainer $branch HEAD; then
-             rv=1
-     fi
-
-     eval $DRY $DIM_POST_APPLY_ACTION
+     for patch in $dir/*; do
+             apply_patch $patch

Need to pass "$@" to apply_patch.

Need to handle the return value from apply_patch, and I presume we don't want checkpatch warnings in a single patch to stop applying the rest of the mbox (set -e would abort on errors otherwise). But we want to return non-zero exit status in that case.

BR,
Jani.

dim function dim_push · line 815

Quoted 4 lines
dim +1 -0
+     done
 
      return $rv
 }

--
Jani Nikula, Intel Open Source Technology Center
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

Signature · 6 lines
Rodrigo Vivi
Blog: http://blog.vivi.eng.br
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx