git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCHv2 3/4] git-am foreign patch support: StGIT support

From
Junio C Hamano <gitster@pobox.com>
Date
May 27, 2009, 07:19 UTC
Message-ID
<7v7i03j9mb.fsf@alter.siamese.dyndns.org>
In-Reply-To
<1243298290-5909-4-git-send-email-giuseppe.bilotta@gmail.com>
Giuseppe Bilotta <giuseppe.bilotta@gmail.com> writes:
Show 40 quoted lines
> Support StGIT patches by implementing a simple awk-based converter
> mimicking StGIT's own parse_patch. Also support StGIT patch series by
> 'exploding' the index into a lif of files and re-running the mail
> splitting with patch_format set to stgit.
> ---
>  git-am.sh |   60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>  1 files changed, 60 insertions(+), 0 deletions(-)
>
> diff --git a/git-am.sh b/git-am.sh
> index 4cf66aa..1a00830 100755
> --- a/git-am.sh
> +++ b/git-am.sh
> @@ -203,6 +203,66 @@ split_patches () {
>  			exit 1
>  		}
>  		;;
> +	stgit-series)
> +		if test $# -ne 1
> +		then
> +			echo "Only one StGIT patch series can be applied at once"
> +			exit 1
> +		fi
> +		series_dir=`dirname "$1"`
> +		series_file="$1"
> +		shift
> +		{
> +			set x
> +			while read filename
> +			do
> +				set "$@" "$series_dir/$filename"
> +			done
> +			# remove the safety x
> +			shift
> +			# remove the arg coming from the first-line comment
> +			shift
> +		} < "$series_file"
> +		# set the patch format appropriately
> +		patch_format=stgit
> +		# now handle the actual StGIT patches
> +		split_patches "$@"

Can an stgit patch file (or the leading pathname for that matter) have IFS character in its name?

Show 8 quoted lines
> +		;;
> +	stgit)
> +		this=0
> +		for stgit in "$@"
> +		do
> +			this=`expr "$this" + 1`
> +			msgnum=`printf "%0${prec}d" $this`
> +			touch "$dotest/$msgnum"

Portability tip from an old timer: do not create a new empty file with "touch" (only use that command to update the timestamp of an existing file).

Instead say
	>"$dotest/$msgnum"
Show 10 quoted lines
> +			# Awk version of StGIT parse_patch. The first nonemptyline
> +			# not starting with Author, From or Date is the
> +			# subject, and the body starts with the next nonempty
> +			# line not starting with Author, From or Date
> +			awk 'BEGIN { subject=0 }
> +			{
> +				if (subject > 1)
> +					print ;
> +				else if (/^$/) next ;
> +				else if (/^Author:/) print sub("Author", "From"), $ORS ;

Can any token that match Author other than the initial "Author: " appear on this line?

Since we rely on Perl but not awk in core-ish part of the scripted Porcelains, it might be a good idea to write this in Perl as well.

Show 23 quoted lines
> +				else if (/^(From|Date)/) print ;
> +				else if (subject) {
> +					subject = 2 ;
> +					print "" ;
> +					print ;
> +				} else {
> +					print "Subject:", $0 ;
> +					subject = 1;
> +				}
> +			}' "$stgit" > "$dotest/$msgnum" || {
> +				echo "Failed to import $patch_format patch $stgit"
> +				exit 1
> +			}
> +		done
> +		echo "$this" > "$dotest/last"
> +		this=
> +		msgnum=
> +		;;
>  	*)
>  		echo "Patch format $patch_format is not supported."
>  		exit 1
> -- 
> 1.6.3.1.248.gb44be
Previous: Junio C HamanoNext: Giuseppe Bilotta
Message 7 of 11 in “[PATCHv2 0/4] git-am support for foreign patches”
  1. Giuseppe BilottaMay 26, 2009
  2. 1/4 git-am foreign patch support: introduce patch_formatGiuseppe Bilotta, May 26, 2009
  3. 2/4 git-am foreign patch support: autodetect some patch formatsGiuseppe Bilotta, May 26, 2009
  4. 3/4 git-am foreign patch support: StGIT supportGiuseppe Bilotta, May 26, 2009
  5. 4/4 git-am: refactor 'cleaning up and aborting'Giuseppe Bilotta, May 26, 2009
  6. Junio C HamanoMay 27, 2009
  7. Junio C HamanoMay 27, 2009
  8. Giuseppe BilottaMay 27, 2009
  9. Junio C HamanoMay 27, 2009
  10. Junio C HamanoMay 27, 2009
  11. Giuseppe BilottaMay 27, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.