Re: [PATCH] Teach 'git-apply --whitespace=strip' to remove empty lines at the end of file
- From
Junio C Hamano <junkio@cox.net>
- Date
- May 20, 2007, 18:36 UTC
- Message-ID
- <7v1whbmjel.fsf@assigned-by-dhcp.cox.net>
- In-Reply-To
- <e5bfff550705200545kcf1f7f9n4f3f6d7d25955e1@mail.gmail.com>
"Marco Costalba" <mcostalba@gmail.com> writes:
Show 6 quoted lines
> Ok. This is take 3. It works correctly on standard patches and also on > u0 example that you gave above. > > This patch is on top of git 1.5.2 > > Please check it.
I think the checks and actions are at the right places (I haven't looked very closely nor tried to run it yet).
Show 19 quoted lines
> builtin-apply.c | 34 ++++++++++++++++++++++++++++++++++
> 1 files changed, 34 insertions(+), 0 deletions(-)
>
> diff --git a/builtin-apply.c b/builtin-apply.c
> index 0399743..6032f78 100644
> --- a/builtin-apply.c
> +++ b/builtin-apply.c
> ...
> @@ -1770,6 +1800,10 @@ static int apply_one_fragment(struct buffer_desc *desc,
> if (match_beginning && offset)
> offset = -1;
> if (offset >= 0) {
> +
> + if (desc->size - oldsize - offset == 0) /* end of file? */
> + newsize -= trailing_added_lines;
> +
> int diff = newsize - oldsize;
> unsigned long size = desc->size + diff;
> unsigned long alloc = desc->alloc;But we have kept our sources -Wdeclaration-after-statement clean so far, and this hunk needs a trivial adjustment.