public inbox for git@vger.kernel.org 
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox•com>
To: Noam Postavsky <npostavs@users•sourceforge.net>
Cc: git@vger•kernel.org
Subject: Re: [BUG] git diff --(src|dst)-prefix=// causes spurious "(new|deleted) file mode"
Date: Wed, 28 May 2014 10:29:22 -0700	[thread overview]
Message-ID: <xmqq38fterrh.fsf@gitster.dls.corp.google.com> (raw)
In-Reply-To: <CAM-tV-9vQPPj+TemYnzjRMTjaHqwo3qq=WWJ89VnRMAeYXHZZw@mail.gmail.com> (Noam Postavsky's message of "Tue, 27 May 2014 21:55:29 -0400")

Noam Postavsky <npostavs@users•sourceforge.net> writes:

> % git init
> Initialized empty Git repository in /home/npostavs/tmp/scratch/.git/
> % echo foo > x
> % git add x
> % git commit -m x
> [master (root-commit) 41be1f2] x
>  1 file changed, 1 insertion(+)
>  create mode 100644 x
> % echo bar > x
> % git diff  | head -3
> diff --git i/x w/x
> index 257cc56..5716ca5 100644
> --- i/x
> % git diff --dst-prefix=// | head -3
> diff --git i/x //x

The feature these options implement was never designed to accept
anything other than "foo/bar/" (i.e. a relative path-looking thing
that ends with "/" and no funnies such as duplicated slashes, in
order to replace the standard "a/" and "b/").  I think the command
line parsing code of src/dst-prefix trusts the user too much not to
feed nonsense like the above.  They may want to be tightened.

> Background: trying to find a prefix that can't show up in file names
> in order to make parsing easier.
> https://github.com/magit/magit/pull/1379
> https://github.com/magit/magit/pull/1383

It may be worth studying how "git apply" finds what the paths are
and use the same rule for consistency.  IIRC, the rules are roughly:

 - In a renaming/copying patch, you will have "rename/copy from/to"
   header separately.  There is no need to parse the "diff --git"
   line at all;

 - Otherwise, you will have "a/SOMETHING b/SOMETHING" (SOMETHING are
   repeated because there is no rename involved).

      reply	other threads:[~2014-05-28 17:29 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-28  1:55 [BUG] git diff --(src|dst)-prefix=// causes spurious "(new|deleted) file mode" Noam Postavsky
2014-05-28 17:29 ` 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=xmqq38fterrh.fsf@gitster.dls.corp.google.com \
    --to=gitster@pobox$(echo .)com \
    --cc=git@vger$(echo .)kernel.org \
    --cc=npostavs@users$(echo .)sourceforge.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
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