git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
MCMarco Costalba <mcostalba@gmail.com>
Date
May 22, 2007, 11:13 UTC
Message-ID
<e5bfff550705220413v261e1543s220d97ce4b9da07b@mail.gmail.com>
In-Reply-To
<7vbqgdbq5j.fsf@assigned-by-dhcp.cox.net>
On 5/22/07, Junio C Hamano <junkio@cox.net> wrote:
Show 18 quoted lines
> "Marco Costalba" <mcostalba@gmail.com> writes:
>
> > On 5/21/07, Junio C Hamano <junkio@cox.net> wrote:
> >> Junio C Hamano <junkio@cox.net> writes:
> >>
> >>
> >> We somehow end up removing one LF too many, like this:
> >>
> >>     diff --git a/contrib/emacs/.gitignore b/contrib/emacs/.gitignore
> >>     index c531d98..016d3b1 100644
> >>     --- a/contrib/emacs/.gitignore
> >>     +++ b/contrib/emacs/.gitignore
> >>     @@ -1 +1 @@
> >>     -*.elc
> >>     +*.elc
> >>     \ No newline at end of file
> >>
> >
The final, and correct version is:
       if (new_whitespace == strip_whitespace && trailing_added_lines)  {
	int n = 0;
	for (   ; n  <= trailing_added_lines; n++)  { /* counting trailing '\n' */
		if (newsize == n)  {
			n++;
			break;
		}
		if (new[newsize - 1 - n] != '\n')
			break;
	}
             trailing_added_lines = (n>0) ? --n : 0;
      }  else
	trailing_added_lines = 0;

but I understand is ugly as hell. The fact is, it is far easier to count '\n' *while* they are created then after at the end.

So no problem for me if you drop my patch.
  Marco
Previous: Junio C Hamano
Message 16 of 16 in “Teach 'git-apply --whitespace=strip' to remove empty lines at the end of file”
  1. Teach 'git-apply --whitespace=strip' to remove empty lines at the end of fileMarco Costalba, May 20, 2007
  2. Junio C HamanoMay 20, 2007
  3. Marco CostalbaMay 20, 2007
  4. Junio C HamanoMay 20, 2007
  5. Marco CostalbaMay 20, 2007
  6. Junio C HamanoMay 20, 2007
  7. Marco CostalbaMay 20, 2007
  8. Junio C HamanoMay 20, 2007
  9. Marco CostalbaMay 20, 2007
  10. Frank LichtenheldMay 20, 2007
  11. Marco CostalbaMay 20, 2007
  12. Josef WeidendorferMay 21, 2007
  13. Junio C HamanoMay 21, 2007
  14. Marco CostalbaMay 21, 2007
  15. Junio C HamanoMay 22, 2007
  16. Marco CostalbaMay 22, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.