git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <junkio@cox.net>
To: "Marco Costalba" <mcostalba@gmail.com>
Cc: "Git Mailing List" <git@vger.kernel.org>
Subject: Re: [PATCH] Teach 'git-apply --whitespace=strip' to remove empty lines at end of file
Date: Sat, 19 May 2007 16:18:00 -0700	[thread overview]
Message-ID: <7vabw0tnbr.fsf@assigned-by-dhcp.cox.net> (raw)
In-Reply-To: <7vsl9stnzp.fsf@assigned-by-dhcp.cox.net> (Junio C. Hamano's message of "Sat, 19 May 2007 16:03:38 -0700")

Junio C Hamano <junkio@cox.net> writes:

> ... these may or may not be at the end of the file, so
> inspecting what blank lines they have at the end is not
> sufficient.  If "new" does not introduce new blank lines at its
> end, then you can be sure that you are not adding trailing blank
> lines, but even if "new" does introduce a new blank line at the
> end, you do not know if that is adding it to the end of the
> file, or in the middle.
>
> You do not know where the hunk is applied until you do the loop
> that follows the part your patch we are discussing.

If I were doing this, I would probably do it this way:

 (1) Inside apply_one_fragment(), where "case '+':" appears, count
     the blank (not just '\n', but matches /^\s*$/) lines at the
     end of "new" side.  As soon as you fall into "case ' ':" or
     "case '-':" or non-blank line in "case '+':", you reset the
     counter to zero, so that what you are counting is the
     number of blank lines that would have get added, if the
     hunk were to be applied at the end of the file.  Keep that
     number ofter you separated the fragment into new and old.

 (2) In the same function, inside the big "for (;;)" loop that
     figures out where to apply that "old" => "new" change, use
     the number you gathered in the step (1) to trim what is
     applied, where the real application happens, which is the
     part that has memmove()/memcpy(), only when you know you
     are applying the hunk at the end of the file.  That is the
     only place in the function that knows where the hunk is
     being applied.

      reply	other threads:[~2007-05-19 23:18 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-05-19 13:12 [PATCH] Teach 'git-apply --whitespace=strip' to remove empty lines at end of file Marco Costalba
2007-05-19 20:39 ` Junio C Hamano
2007-05-19 21:58   ` Marco Costalba
2007-05-19 23:03     ` Junio C Hamano
2007-05-19 23:18       ` Junio C Hamano [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7vabw0tnbr.fsf@assigned-by-dhcp.cox.net \
    --to=junkio@cox.net \
    --cc=git@vger.kernel.org \
    --cc=mcostalba@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).