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

git-blame: handling of revisions and filenames

From
Alex Riesen <fork0@t-online.de>
Date
Nov 15, 2006, 21:52 UTC
Message-ID
<20061115215225.GA4595@steel.home>
I noticed that there is no safe way to give a revision to git-blame:
it can always be interpreted as an existing file:
 - "git blame rev -- file.txt" can fail if "rev" is a file
 - "git blame rev^0 -- file.txt" can file there is a "rev^0" file
   (happens if you type too fast with a tool not designed for keyboard)
 - "git blame file.txt rev" is ambiguos too, for the same reasons.

I did the simple patch (below) to resolve at least the very first one, just because that is how git-rev-list does it. But if all forms of git-blame command line are expected to live, a more serious surgery of the argv[] handling code needed. And I afraid the patch has a small chance of crashing: I don't check if there is enough space in argv (don't actually even know how to), so Junio, please do not apply it (it passes blame tests, though). I also suspect git-blame is not the only command using revision machinery which has the same problem, so this message is more like a discussion starter.

diff --git a/builtin-blame.c b/builtin-blame.c
index 066dee7..83c8905 100644
--- a/builtin-blame.c
+++ b/builtin-blame.c
@@ -1787,6 +1787,7 @@ int cmd_blame(int argc, const char **arg
        /* Now we got rev and path.  We do not want the path pruning
         * but we may want "bottom" processing.
         */
+       argv[unk++] = "--";
        argv[unk] = NULL;
 
        init_revisions(&revs, NULL);
Next: Junio C Hamano
Message 1 of 2 in “git-blame: handling of revisions and filenames”
  1. Alex RiesenNov 15, 2006
  2. Junio C HamanoNov 29, 2006

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.