{"thread":{"id":"28503","subject":"git apply/am whitespace errors","startedAt":"2011-09-26T19:03:06Z","lastAt":"2011-09-26T20:39:03Z","messageCount":3,"participants":["neubyr","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"176246","messageId":"CALFxCvxxbsgZnhqK9nN7h=1ASJzfDJ7aVF+rM-8RUyKhpv8FzQ@mail.gmail.com","threadId":"28503","inReplyTo":null,"subject":"git apply/am whitespace errors","fromName":"neubyr","fromEmail":"neubyr@gmail.com","sentAt":"2011-09-26T19:03:06Z","receivedAt":"2011-09-26T19:03:06Z","isPatch":false,"sender":{"key":"neubyr@gmail.com","avatar":null},"body":"I am getting  following error while applying a patch using git-apply.\n\n{{{\n/tmp/patches/ticket11/0002-Commit-for-ticket-11.patch:51: new blank line at EOF.\n}}}\n\nWhat does number '51' after colon ':' indicate? There aren't 51 lines\nin that patch file. Also, I had used check and stat options before\napplying match and it didn't indicate any warnings/errors.\nI tried git am interactive and it gave following error:\n\n{{{\nApplying: Commit for [ticket:11]. Created a directory to download lens\nfiles and added .include_in_git empty hidden file.\n/tmp/galaxy/.git/rebase-apply/patch:10: new blank line at EOF.\n+\nwarning: 1 line adds whitespace errors.\nCommit Body is:\n}}}\n\nI am trying to add a directory with a hidden empty file. Any\nelaboration on above warning/error messages will be really helpful.\n\n--\nthanks,\nneuby.r\n"},{"id":"176251","messageId":"7vzkhr142r.fsf@alter.siamese.dyndns.org","threadId":"28503","inReplyTo":"CALFxCvxxbsgZnhqK9nN7h=1ASJzfDJ7aVF+rM-8RUyKhpv8FzQ@mail.gmail.com","subject":"Re: git apply/am whitespace errors","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2011-09-26T19:44:28Z","receivedAt":"2011-09-26T19:44:28Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"neubyr <neubyr@gmail.com> writes:\n\n> I am getting  following error while applying a patch using git-apply.\n>\n> {{{\n> /tmp/patches/ticket11/0002-Commit-for-ticket-11.patch:51: new blank line at EOF.\n> }}}\n>\n> What does number '51' after colon ':' indicate?\n\nLooks like \"apply --whitespace=error\" is not reporting the optimal line\nnumber for the blank at EOF case.\n\nIt ideally should point at the line number of the offending patch in the\ninput patch file (i.e. \"cat -n .git/apply-rebase/patch\" would show the \"+\"\nline that adds a blank line on 51th line), but it seems that it instead\npoints at the beginning of the hunk that introduces the issue.\n\nE.g. if we add an empty line at the end of COPYING (which is 360 lines\nlong), we would get a patch file that looks like this:\n\n     1\tdiff --git a/COPYING b/COPYING$\n     2\tindex 536e555..ccf4c7f 100644$\n     3\t--- a/COPYING$\n     4\t+++ b/COPYING$\n     5\t@@ -358,3 +358,4 @@ proprietary programs.  If your program is a subroutine library, you may$\n     6\t consider it more useful to permit linking proprietary applications with the$\n     7\t library.  If this is what you want to do, use the GNU Lesser General$\n     8\t Public License instead of this License.$\n     9\t+$\n\nand \"git apply --whitespace=error P.diff\" would report the hunk that\nbegins at line 5 is wrong:\n\n     P.diff:5: new blank line at EOF.\n     +\n     fatal: 1 line adds whitespace errors.\n\nwhen the true offending line is at line #9.\n"},{"id":"176257","messageId":"7vr53311js.fsf@alter.siamese.dyndns.org","threadId":"28503","inReplyTo":"7vzkhr142r.fsf@alter.siamese.dyndns.org","subject":"Re: git apply/am whitespace errors","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2011-09-26T20:39:03Z","receivedAt":"2011-09-26T20:39:03Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Subject: apply --whitespace=error: correctly report new blank lines at end\n\nEarlier 77b15bb (apply --whitespace=warn/error: diagnose blank at EOF,\n2009-09-03) cheated by reporting the line number of the hunk that contains\nthe offending line that adds new blank lines at the end of the file. All\nother types of whitespace errors are reported with the line number in the\npatch file that has the actual offending text.\n\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n\n * This is an interim workaround. fragment->linenr was added for the\n   specific purpose of reporting this type of error in the quoted patch,\n   and the field is not used for any other purpose, so it may be a better\n   fix to either rename it to hunk_linenr and use it directly without\n   introducing a new local variable in apply_one_fragment(), or pass\n   \"linenr\" as a parameter to parse_fragment() and pass it down the\n   callchain all the way through, or something like that.\n\n builtin/apply.c |   11 +++++++++--\n 1 files changed, 9 insertions(+), 2 deletions(-)\n\ndiff --git a/builtin/apply.c b/builtin/apply.c\nindex f2edc52..092429a 100644\n--- a/builtin/apply.c\n+++ b/builtin/apply.c\n@@ -2447,6 +2447,8 @@ static int apply_one_fragment(struct image *img, struct fragment *frag,\n \tchar *old, *oldlines;\n \tstruct strbuf newlines;\n \tint new_blank_lines_at_end = 0;\n+\tint found_new_blank_lines_at_end = 0;\n+\tint hunk_linenr = frag->linenr;\n \tunsigned long leading, trailing;\n \tint pos, applied_pos;\n \tstruct image preimage;\n@@ -2540,14 +2542,18 @@ static int apply_one_fragment(struct image *img, struct fragment *frag,\n \t\t\t\terror(\"invalid start of line: '%c'\", first);\n \t\t\treturn -1;\n \t\t}\n-\t\tif (added_blank_line)\n+\t\tif (added_blank_line) {\n+\t\t\tif (!new_blank_lines_at_end)\n+\t\t\t\tfound_new_blank_lines_at_end = hunk_linenr;\n \t\t\tnew_blank_lines_at_end++;\n+\t\t}\n \t\telse if (is_blank_context)\n \t\t\t;\n \t\telse\n \t\t\tnew_blank_lines_at_end = 0;\n \t\tpatch += len;\n \t\tsize -= len;\n+\t\thunk_linenr++;\n \t}\n \tif (inaccurate_eof &&\n \t    old > oldlines && old[-1] == '\\n' &&\n@@ -2629,7 +2635,8 @@ static int apply_one_fragment(struct image *img, struct fragment *frag,\n \t\t    preimage.nr + applied_pos >= img->nr &&\n \t\t    (ws_rule & WS_BLANK_AT_EOF) &&\n \t\t    ws_error_action != nowarn_ws_error) {\n-\t\t\trecord_ws_error(WS_BLANK_AT_EOF, \"+\", 1, frag->linenr);\n+\t\t\trecord_ws_error(WS_BLANK_AT_EOF, \"+\", 1,\n+\t\t\t\t\tfound_new_blank_lines_at_end);\n \t\t\tif (ws_error_action == correct_ws_error) {\n \t\t\t\twhile (new_blank_lines_at_end--)\n \t\t\t\t\tremove_last_line(&postimage);\n-- \n1.7.7.rc3\n"}]}