On Wed, Nov 29, 2023 at 10:37:45AM +0100, Uwe Kleine-König wrote:
> As the loop over the output of find moves files around, it can happen
> that find lists files more than once. In that case not only the "From "
> line is removed, but also the next one (usually the "From:" line).
> 
> To process each patch in series.auto exactly once, iterate over that
> file to remove the "From " line instead. Still be a bit conservative and
> make sure that only the intended line is dropped.
> 
> Reported-by: Thorsten Scherer <t.sche...@eckelmann.de>

Tested-by: Thorsten Scherer <t.sche...@eckelmann.de>

> Signed-off-by: Uwe Kleine-König <u.kleine-koe...@pengutronix.de>
> ---
>  scripts/git-ptx-patches | 12 +++++++++---
>  1 file changed, 9 insertions(+), 3 deletions(-)
> 
> diff --git a/scripts/git-ptx-patches b/scripts/git-ptx-patches
> index a063cb73a875..df004fb8a8a5 100755
> --- a/scripts/git-ptx-patches
> +++ b/scripts/git-ptx-patches
> @@ -221,6 +221,13 @@ cat .ptxdist/series | _md5sum >> .ptxdist/series
>  
>  # The first line of the patch is 'From <some-git-hash> ...'
>  # remove it to avoid unnecessary changes in the patch files.
> +while read patch para; do
> +     # There are no comments or empty lines in series.auto, so no need to
> +     # handle these. Also be a bit cautious to only remove lines matching
> +     # "^From ".
> +     sed -i '1{/^From /d}' ".ptxdist/patches/$patch"
> +done < .ptxdist/series.auto
> +
>  find .ptxdist/patches/ ! -type d | sed -e 's,^.ptxdist/patches/,,' | \
>  while read patch para; do
>       case "$patch" in
> @@ -228,9 +235,8 @@ while read patch para; do
>               *) ;;
>       esac
>       if grep -q "$patch" .ptxdist/series.auto; then
> -             p=".ptxdist/patches/$patch"
> -             tail -n+2 "$p" > ".$patch.ptx-patches"
> -             mv ".$patch.ptx-patches" "$p"
> +             # ok, this is one of the patches we just touched
> +             :
>       else
>               if grep -q "$patch" .ptxdist/series.{0,1}; then
>                       echo "Base patch \"$patch\"!"
> -- 
> 2.42.0
> 

Reply via email to