git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeff King <peff@peff.net>
To: Junio C Hamano <gitster@pobox.com>
Cc: Daniel Lyubomirov <daniel@digitalus.bg>, git@vger.kernel.org
Subject: Re: Bug: problem with file named with dash character
Date: Wed, 27 Jun 2012 15:52:05 -0400	[thread overview]
Message-ID: <20120627195205.GA11700@sigill.intra.peff.net> (raw)
In-Reply-To: <7vk3ys8v96.fsf@alter.siamese.dyndns.org>

On Wed, Jun 27, 2012 at 11:28:21AM -0700, Junio C Hamano wrote:

> Thanks for a report.  I think the "diff" callchain should be
> refactored so that the caller can mark the special "stdin" token in
> a saner way, but until it happens, the following one-liner should
> do.

Yeah, I assume this is there at all to support "diff --no-index -", so the
special marking should happen at that layer.

> diff --git a/diff.c b/diff.c
> index 1a594df..caa2309 100644
> --- a/diff.c
> +++ b/diff.c
> @@ -2589,6 +2589,14 @@ static int reuse_worktree_file(const char *name, const unsigned char *sha1, int
>  	if (!FAST_WORKING_DIRECTORY && !want_file && has_sha1_pack(sha1))
>  		return 0;
>  
> +	/*
> +	 * And asking to read "-" from the working tree triggers stdin
> +	 * input (which needs to be fixed separately by refactoring the
> +	 * callchain), forbid "reuse" for now.
> +	 */
> +	if (!strcmp(name, "-"))
> +		return 0;
> +

Unfortunately this is not enough. The problematic code path is the call
to populate_from_stdin in diff_populate_filespec. And we follow that
conditional if reuse_worktree_file is true, _or_ if the sha1_valid flag
on the filespec is not set. We hit the latter due to the --no-index
case, but we can also hit it if we are comparing a working tree file in
the repo that is stat-dirty.

So without your patch, this reads from stdin:

  git init repo &&
  cd repo &&
  echo foo >- &&
  git add - &&
  git commit -m foo

when the commit command tries to generate the diff summary. Your patch
fixes it, but remains broken if you then do:

  echo changes >>- &&
  git diff

I think you'd want to do just do something like:

diff --git a/diff.c b/diff.c
index 1a594df..aac72b7 100644
--- a/diff.c
+++ b/diff.c
@@ -2684,9 +2684,6 @@ int diff_populate_filespec(struct diff_filespec *s, int size_only)
 		struct stat st;
 		int fd;
 
-		if (!strcmp(s->path, "-"))
-			return populate_from_stdin(s);
-
 		if (lstat(s->path, &st) < 0) {
 			if (errno == ENOENT) {
 			err_empty:

to temporarily fix it. That breaks

  echo content | git diff --no-index - some-file

but that code path should be fixed properly (with a use_stdin flag in
the filespec).

-Peff

  reply	other threads:[~2012-06-27 19:52 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <52ae7682-3e9a-4b52-bec1-08ba3aadffc0@office.digitalus.nl>
2012-06-27  7:32 ` Bug: problem with file named with dash character Daniel Lyubomirov -|- Digitalus Bulgaria
2012-06-27  9:57   ` faux
2012-06-27 18:28   ` Junio C Hamano
2012-06-27 19:52     ` Jeff King [this message]
2012-06-27 20:25       ` Jeff King
2012-06-27 20:27       ` Junio C Hamano
2012-06-27 20:33         ` Junio C Hamano
2012-06-27 20:35           ` Junio C Hamano
2012-06-27 20:39             ` Junio C Hamano
2012-06-27 20:48               ` Junio C Hamano
2012-06-27 21:00                 ` Jeff King
2012-06-27 22:17                   ` Junio C Hamano
2012-06-27 22:41                     ` Jeff King

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=20120627195205.GA11700@sigill.intra.peff.net \
    --to=peff@peff.net \
    --cc=daniel@digitalus.bg \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.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).