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

Re: [BUG/RFC] Raw diff output format (git-diff-tree) and --relative[=<path>] option

From
Jakub Narebski <jnareb@gmail.com>
Date
Jul 8, 2010, 14:56 UTC
Message-ID
<201007081656.23474.jnareb@gmail.com>
In-Reply-To
<20100708142341.GA9991@coredump.intra.peff.net>
On Thu, 8 Jul 2010, Jeff King wrote:
Show 23 quoted lines
> On Thu, Jul 08, 2010 at 02:19:42PM +0200, Jakub Narebski wrote:
> 
> > Nevertheless for the patch output format both "git diff --relative=sub"
> > and "git diff --relative=sub/" give the same output, without 'b//quux'.
> > The same IMHO should be done for raw output format, so we don't have
> > '/quux' but 'quux'.
> 
> Hmm. That is because the diff output properly eliminates the double "/".
> But AFAICT, all of the following do what I would expect:
> 
>   git diff --relative=sub
>   git diff --relative=sub/ ;# same as above
>   git diff --relative=foo- ;# yields "a/10" for file "foo-10"
> 
> Doing
> 
>   git diff --relative=sub --stat
> 
> shows the same issue as your --raw version, as does --name-only. I think
> the right solution is to clean up a leading "/" for those cases. That
> leaves the possibility for non-directory prefixes, but should do what
> the user wants in the directory case (since a leading "/" is
> nonsensical).
Perhaps this would be enough:
-- >8 --
diff --git i/diff.c w/diff.c
index 3aa695d..3a4696e 100644
--- i/diff.c
+++ w/diff.c
@@ -2705,10 +2705,16 @@ static void diff_fill_sha1_info(struct diff_filespec *one)
 static void strip_prefix(int prefix_length, const char **namep, const char **otherp)
 {
 	/* Strip the prefix but do not molest /dev/null and absolute paths */
-	if (*namep && **namep != '/')
+	if (*namep && **namep != '/') {
 		*namep += prefix_length;
-	if (*otherp && **otherp != '/')
+		if (**namep == '/')
+			++*namep;
+	}
+	if (*otherp && **otherp != '/') {
 		*otherp += prefix_length;
+		if (**otherp == '/')
+			++*otherp;
+	}
 }
 
 static void run_diff(struct diff_filepair *p, struct diff_options *o)
-- 8< --

> 
> Or was that what you had in mind the whole time? My impression was that
> you wanted --relative=foo to always be equivalent to --relative=foo/.
> The subtle difference is that I want the "/" removed only if it is the
> next character (or another way of thinking about it is to append "/" to
> the prefix only if it is an actual directory).

What I wanted is for "git diff-tree A B --relative=sub" to behave as
"git diff-tree A:sub B:sub".  Currently without -r / -t (without turning
on recursive mode) it produces no output; well at least no output if
'sub' is really subdirectory.

What's more I wanted for "git diff --raw" in any combination to behave
the same... although I guess here point is moot, as "git diff" is
automatically recursive regardless of output format, and you can't turn
it off.

Stil I'd like for "git diff-tree <commit>" to behave appropriately
with --relative or --relative=<path>.
-- 
Jakub Narebski
Poland
Previous: Jeff KingNext: Jeff King
Message 8 of 10 in “[BUG] Spurious leading '/' in filename in "git diff --raw --relative=<subdirectory>"”
  1. Jakub NarebskiJul 5, 2010
  2. Jakub NarebskiJul 5, 2010
  3. [BUG/RFC] Raw diff output format (git-diff-tree) and --relative[=<path>] optionJakub Narebski, Jul 8, 2010
  4. Jeff KingJul 8, 2010
  5. Jakub NarebskiJul 8, 2010
  6. Jakub NarebskiJul 8, 2010
  7. Jeff KingJul 8, 2010
  8. Jakub NarebskiJul 8, 2010
  9. Jeff KingAug 9, 2010
  10. Jeff KingAug 9, 2010

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.