Re: [PATCHv2 4/4] git-am: refactor 'cleaning up and aborting'

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Giuseppe Bilotta <giuseppe.bilotta@xxxxxxxxx> writes:

> Introduce a clean_abort function that echoes an optional error message
> to standard error, removes the dotest directory and exits with status 1.
>
> Use it when patch format detection or patch splitting fails early.
> ---

S-o-b;

>  git-am.sh |   29 +++++++++++++++--------------
>  1 files changed, 15 insertions(+), 14 deletions(-)
>
> diff --git a/git-am.sh b/git-am.sh
> index 1a00830..057acfe 100755
> --- a/git-am.sh
> +++ b/git-am.sh
> @@ -134,6 +134,15 @@ It does not apply to blobs recorded in its index."
>      unset GITHEAD_$his_tree
>  }
>  
> +clean_abort () {
> +	if test $# -gt 0
> +	then
> +		echo "$@" > /dev/stderr

	echo >&2 "$@"

> +	fi
> +	rm -fr "$dotest"
> +	exit 1
> +}
> +
>  patch_format=
>  
>  check_patch_format () {
> @@ -192,22 +201,18 @@ check_patch_format () {
>  				fi
>  				;;
>  		esac
> -	} < "$1"
> +	} < "$1" || clean_abort
>  }
>  
>  split_patches () {
>  	case "$patch_format" in
>  	mbox)
> -		git mailsplit -d"$prec" -o"$dotest" -b -- "$@" > "$dotest/last" ||  {
> -			rm -fr "$dotest"
> -			exit 1
> -		}
> +		git mailsplit -d"$prec" -o"$dotest" -b -- "$@" > "$dotest/last" || clean_abort
>  		;;
>  	stgit-series)
>  		if test $# -ne 1
>  		then
> -			echo "Only one StGIT patch series can be applied at once"
> -			exit 1
> +			clean_abort "Only one StGIT patch series can be applied at once"
>  		fi
>  		series_dir=`dirname "$1"`
>  		series_file="$1"
> @@ -222,7 +227,7 @@ split_patches () {
>  			shift
>  			# remove the arg coming from the first-line comment
>  			shift
> -		} < "$series_file"
> +		} < "$series_file" || clean_abort
>  		# set the patch format appropriately
>  		patch_format=stgit
>  		# now handle the actual StGIT patches
> @@ -254,18 +259,14 @@ split_patches () {
>  					print "Subject:", $0 ;
>  					subject = 1;
>  				}
> -			}' "$stgit" > "$dotest/$msgnum" || {
> -				echo "Failed to import $patch_format patch $stgit"
> -				exit 1
> -			}
> +			}' "$stgit" > "$dotest/$msgnum" || clean_abort
>  		done
>  		echo "$this" > "$dotest/last"
>  		this=
>  		msgnum=
>  		;;
>  	*)
> -		echo "Patch format $patch_format is not supported."
> -		exit 1
> +		clean_abort "Patch format $patch_format is not supported."
>  		;;
>  	esac
>  }
> -- 
> 1.6.3.1.248.gb44be
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]