Re: [PATCH] Teach 'git-apply --whitespace=strip' to remove empty lines at the end of file

2 messages, 2 authors, 2016-06-15 · open the first message on its own page

Re: [PATCH] Teach 'git-apply --whitespace=strip' to remove empty lines at the end of file

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:43:11

"Marco Costalba" [off-list ref] writes:
On 5/20/07, Junio C Hamano [off-list ref] wrote:
...
quoted
quoted
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
??????

Wie bitte?
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).

Re: [PATCH] Teach 'git-apply --whitespace=strip' to remove empty lines at the end of file

From: Marco Costalba <hidden>
Date: 2016-06-15 22:43:11

On 5/20/07, Junio C Hamano [off-list ref] wrote:
"Marco Costalba" [off-list ref] writes:
quoted
quoted
quoted
              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.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help