git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH] format-patch: fix skipping of blank-lines
@ 2005-07-09  0:46 Junio C Hamano
  2005-07-09  1:42 ` Linus Torvalds
  0 siblings, 1 reply; 3+ messages in thread
From: Junio C Hamano @ 2005-07-09  0:46 UTC (permalink / raw
  To: Linus Torvalds; +Cc: git

If it is fed a commit with more than one leading blank lines,
the sed scripts git-format-patch-script used looped forever.
This patch fixes it.

Signed-off-by: Junio C Hamano <junkio@cox.net>
---

 git-format-patch-script |   18 +++++++++++++-----
 1 files changed, 13 insertions(+), 5 deletions(-)

58a3c79b488a28897cd5556dab0dd599b4ed9f0c
diff --git a/git-format-patch-script b/git-format-patch-script
--- a/git-format-patch-script
+++ b/git-format-patch-script
@@ -66,9 +66,13 @@ trap 'rm -f $tmp-*' 0 1 2 3 15
 series=$tmp-series
 
 titleScript='
-	1,/^$/d
+	/./d
 	: loop
-	/^$/b loop
+	/^$/{
+		n
+		b loop
+	}
+	s/^\[PATCH[^]]*\] *//
 	s/[^-a-z.A-Z_0-9]/-/g
         s/\.\.\.*/\./g
 	s/\.*$//
@@ -76,6 +80,7 @@ titleScript='
 	s/^-//
 	s/-$//
 	s/$/./
+	p
 	q
 '
 
@@ -88,7 +93,7 @@ total=`wc -l <$series`
 i=$total
 while read commit
 do
-    title=`git-cat-file commit "$commit" | sed -e "$titleScript"`
+    title=`git-cat-file commit "$commit" | sed -ne "$titleScript"`
     case "$numbered" in
     '') num= ;;
     *)
@@ -102,9 +107,12 @@ do
     echo "$file"
     {
 	mailScript='
-	1,/^$/d
+	/./d
 	: loop
-	/^$/b loop
+	/^$/{
+		n
+		b loop
+	}
 	s|^|[PATCH'"$num"'] |
 	: body
 	p

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] format-patch: fix skipping of blank-lines
  2005-07-09  0:46 [PATCH] format-patch: fix skipping of blank-lines Junio C Hamano
@ 2005-07-09  1:42 ` Linus Torvalds
  2005-07-09  2:27   ` [PATCH] format-patch: fix skipping of blank-lines (take 2) Junio C Hamano
  0 siblings, 1 reply; 3+ messages in thread
From: Linus Torvalds @ 2005-07-09  1:42 UTC (permalink / raw
  To: Junio C Hamano; +Cc: git



On Fri, 8 Jul 2005, Junio C Hamano wrote:
>
> If it is fed a commit with more than one leading blank lines,
> the sed scripts git-format-patch-script used looped forever.
> This patch fixes it.

How about using "git-stripspace"? That's what it's there for. It strips
whitespace from the end of lines, from the beginning, and from the end. It
also removes multiple consecutive whitespace lines from within the body of
the message - which might turn some people off, but I use that same thing
when I do my automated email commits, so if you don't strip those lines
from the email, they _will_ get stripped at commit time, so..

"git-stripspace" also doesn't get confused by non-empty lines that have 
spaces in them, like your script seems to be (ie /^$/ won't match a line 
that has a space on it).

		Linus

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH] format-patch: fix skipping of blank-lines (take 2)
  2005-07-09  1:42 ` Linus Torvalds
@ 2005-07-09  2:27   ` Junio C Hamano
  0 siblings, 0 replies; 3+ messages in thread
From: Junio C Hamano @ 2005-07-09  2:27 UTC (permalink / raw
  To: Linus Torvalds; +Cc: git

If it is fed a commit with more than one leading blank lines,
the sed scripts git-format-patch-script used looped forever.
Using git-stripspace upfront makes the sed script somewhat
simpler to work around this problem.

Also use git-rev-parse so that we can say

    $ git-format-patch-script HEAD^^^^

to prepare the latest four patches for e-mail submission.

Signed-off-by: Junio C Hamano <junkio@cox.net>
---
 >>>>> "LT" == Linus Torvalds <torvalds@osdl.org> writes:

 LT> How about using "git-stripspace"?

 I first thought it would be an overkill, but it lets me cheat in
 the sed script.  Thanks for the suggestion.

 git-format-patch-script |   22 ++++++++++++++--------
 1 files changed, 14 insertions(+), 8 deletions(-)

3006f6c35d08a0f060e021573771b3cfc70c0682
diff --git a/git-format-patch-script b/git-format-patch-script
--- a/git-format-patch-script
+++ b/git-format-patch-script
@@ -53,6 +53,8 @@ case "$#" in
 1)    linus="$1" junio=HEAD ;;
 *)    usage ;;
 esac
+junio=`git-rev-parse --verify "$junio"`
+linus=`git-rev-parse --verify "$linus"`
 
 case "$outdir" in
 */) ;;
@@ -66,9 +68,9 @@ trap 'rm -f $tmp-*' 0 1 2 3 15
 series=$tmp-series
 
 titleScript='
-	1,/^$/d
-	: loop
-	/^$/b loop
+	/./d
+	/^$/n
+	s/^\[PATCH[^]]*\] *//
 	s/[^-a-z.A-Z_0-9]/-/g
         s/\.\.\.*/\./g
 	s/\.*$//
@@ -76,6 +78,7 @@ titleScript='
 	s/^-//
 	s/-$//
 	s/$/./
+	p
 	q
 '
 
@@ -88,7 +91,9 @@ total=`wc -l <$series`
 i=$total
 while read commit
 do
-    title=`git-cat-file commit "$commit" | sed -e "$titleScript"`
+    title=`git-cat-file commit "$commit" |
+    git-stripspace |
+    sed -ne "$titleScript"`
     case "$numbered" in
     '') num= ;;
     *)
@@ -102,16 +107,17 @@ do
     echo "$file"
     {
 	mailScript='
-	1,/^$/d
-	: loop
-	/^$/b loop
+	/./d
+	/^$/n
 	s|^|[PATCH'"$num"'] |
 	: body
 	p
 	n
 	b body'
 
-	git-cat-file commit "$commit" | sed -ne "$mailScript"
+	git-cat-file commit "$commit" |
+	git-stripspace |
+	sed -ne "$mailScript"
 	echo '---'
 	echo
 	git-diff-tree -p $diff_opts "$commit" | git-apply --stat --summary

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2005-07-09  2:28 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-07-09  0:46 [PATCH] format-patch: fix skipping of blank-lines Junio C Hamano
2005-07-09  1:42 ` Linus Torvalds
2005-07-09  2:27   ` [PATCH] format-patch: fix skipping of blank-lines (take 2) Junio C Hamano

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).