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

Re: Bug: problem with file named with dash character

From
Junio C Hamano <gitster@pobox.com>
Date
Jun 27, 2012, 20:35 UTC
Message-ID
<7v4npw8pdo.fsf@alter.siamese.dyndns.org>
In-Reply-To
<7vbok48pfu.fsf@alter.siamese.dyndns.org>
Junio C Hamano <gitster@pobox.com> writes:
Show 12 quoted lines
> Junio C Hamano <gitster@pobox.com> writes:
>
>> Jeff King <peff@peff.net> writes:
>>
>>> but that code path should be fixed properly (with a use_stdin flag in
>>> the filespec).
>>
>> Yes, just as I said; I am finding more and more issues with the
>> no-index hack that I have been fixing a bit by bit since I send the
>> message you responded to.
>
> It is not ready yet, but here are a few patches WIP.
And this is the second clean-up
-- >8 --
Subject: [PATCH 2/?] diff-index.c: unify handling of command line paths

Regardless of where in the directory hierarchy you are, "-" on the command line means the standard input. The old code knew too much about how the low level machinery uses paths to read from the working tree and did not bother to have the same check for "-" when the command is run from the top-level.

Unify the codepaths for subdirectory case and toplevel case into one and make it clearer.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 diff-no-index.c | 27 +++++++++++----------------
 1 file changed, 11 insertions(+), 16 deletions(-)
diff --git a/diff-no-index.c b/diff-no-index.c
index ca875da..a5c1e3e 100644
--- a/diff-no-index.c
+++ b/diff-no-index.c
@@ -172,7 +172,7 @@ void diff_no_index(struct rev_info *revs,
 		   int argc, const char **argv,
 		   int nongit, const char *prefix)
 {
-	int i;
+	int i, prefixlen;
 	int no_index = 0;
 	unsigned options = 0;
 	const char *paths[2];
@@ -232,23 +232,18 @@ void diff_no_index(struct rev_info *revs,
 	if (!DIFF_OPT_TST(&revs->diffopt, EXIT_WITH_STATUS))
 		setup_pager();
 
-	if (prefix) {
-		int len = strlen(prefix);
-
-		for (i = 0; i < 2; i++) {
-			const char *p = argv[argc - 2 + i];
+	prefixlen = prefix ? strlen(prefix) : 0;
+	for (i = 0; i < 2; i++) {
+		const char *p = argv[argc - 2 + i];
+		if (!strcmp(p, "-"))
 			/*
-			 * stdin should be spelled as '-'; if you have
-			 * path that is '-', spell it as ./-.
+			 * stdin should be spelled as "-"; if you have
+			 * path that is "-", spell it as "./-".
 			 */
-			p = (strcmp(p, "-")
-			     ? xstrdup(prefix_filename(prefix, len, p))
-			     : p);
-			paths[i] = p;
-		}
-	} else {
-		for (i = 0; i < 2; i++)
-			paths[i] = argv[argc - 2 + i];
+			p = p;
+		else if (prefixlen)
+			p = xstrdup(prefix_filename(prefix, prefixlen, p));
+		paths[i] = p;
 	}
 	revs->diffopt.skip_stat_unmatch = 1;
 	if (!revs->diffopt.output_format)
-- 
1.7.11.1.184.g3ee8f69
Previous: Junio C HamanoNext: Junio C Hamano
Message 8 of 13 in “Bug: problem with file named with dash character”
  1. Daniel Lyubomirov -|- Digitalus BulgariaJun 27, 2012
  2. faux@goeswhere.comJun 27, 2012
  3. Junio C HamanoJun 27, 2012
  4. Jeff KingJun 27, 2012
  5. Jeff KingJun 27, 2012
  6. Junio C HamanoJun 27, 2012
  7. Junio C HamanoJun 27, 2012
  8. Junio C HamanoJun 27, 2012
  9. Junio C HamanoJun 27, 2012
  10. Junio C HamanoJun 27, 2012
  11. Jeff KingJun 27, 2012
  12. Junio C HamanoJun 27, 2012
  13. Jeff KingJun 27, 2012

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.