Git Mailing List Archive on lore.kernel.org
 help / color / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
Cc: git@vger.kernel.org
Subject: Re: Getting clean diff data from git-mailinfo
Date: Sat, 22 Feb 2020 08:47:42 -0800
Message-ID: <xmqqk14e7emp.fsf@gitster-ct.c.googlers.com> (raw)
In-Reply-To: <20200221171312.xyzsrvebuwiw6pgj@chatter.i7.local> (Konstantin Ryabitsev's message of "Fri, 21 Feb 2020 12:14:01 -0500")

Konstantin Ryabitsev <konstantin@linuxfoundation.org> writes:

> Is there a git-native command to further clean up the "patch" file to 
> get just diff contents (i.e. as returned by "git diff" after this patch 
> is applied)?

There isn't one, as Git did not need one ;-)

The "git am" toolchain is tasked to take a reasonably formatted
e-mailed patch generated by tools other people use.  When fed a
piece of e-mail, after it was split out of a mailbox by the "git
mailsplit" program, the "git mailinfo" program is asked to

 (1) gather metainfo for author identity
 (2) gather commit log message material
 (3) collect the input for "git apply"

The e-mail header is parsed for (1) and the first line of (2), and
then the e-mail body is scanned to find the boundary between (2) and
(3), and this is done in order to avoid cruft at the end of (2) as
much as possible, because (2) is something a human user has to clean
up while applying, as opposed to (3) that is mechanically processed.
For that, the line between (2) and (3) is drawn:

 (a) at "---\n" line, for output by "git format-patch";

 (b) at "Index: " line, that often comes from CVS repository;

 (c) at "diff -" line, that can catch handmade patch e-mail using
     GNU and BSD diff.

And that is why we throw the diffstat and commentary to maintainer
that are written after the "---\n" line but before the diff in (3).

Now, if "git apply" were less smart and required a pure diff without
anything else wround it as its input, then we may have had split (3)
into three pieces:

 (3a) material before the pure diff (e.g. diffstat, etc.)
 (3b) pure diff
 (3c) trailing junk (e.g. base-commit info, e-mail signature, etc.)

But "git apply" was designed to be usable on the whole of plain text
e-mail, roughly as a "GNU diff" replacement, it does not require (3a)
and (3c) cleansed out from its input.

So, because there is no such need so far, there is no tool in the
Git toolbox to split (3) into three pieces.

You're welcome to write one, but the current toolset does not need
it.

Thanks.

  reply index

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-21 17:14 Konstantin Ryabitsev
2020-02-22 16:47 ` Junio C Hamano [this message]
2020-02-22 16:56   ` Junio C Hamano
2020-02-22 18:00     ` Andreas Schwab

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=xmqqk14e7emp.fsf@gitster-ct.c.googlers.com \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=konstantin@linuxfoundation.org \
    /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

Git Mailing List Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/git/0 git/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 git git/ https://lore.kernel.org/git \
		git@vger.kernel.org
	public-inbox-index git

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.git


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git