From: Marco Costalba Date: Sun, 20 May 2007 20:55:17 GMT Subject: Re: [PATCH] Teach 'git-apply --whitespace=strip' to remove empty lines at the end of file Message-ID: In-Reply-To: <7vd50vl30r.fsf@assigned-by-dhcp.cox.net> On 5/20/07, Junio C Hamano wrote: > "Marco Costalba" writes: > > >> > 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; > >> > > Sorry I forgot to mention that that is "trivial" so there is no > reason to resend. I don't expect me doing much git stuff for > the rest of the day, but you'll hear from me about this patch > later (hopefully it would appear on 'next' -- we'll see). > Ok. Thanks for your help. P.S: I don't find a trivial way to avoid adding more lines then removed, the shortest trick I can find is int eof = (desc->size - oldsize - offset == 0); int diff = newsize - oldsize - eof * trailing_added_lines; unsigned long size = desc->size + diff; unsigned long alloc = desc->alloc; newsize -= eof * trailing_added_lines; But is not as elegant as the original.