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

[PATCH 2/2] blame: Fix git-blame <directory>

From
Fredrik Kuivinen <freku045@student.liu.se>
Date
Mar 17, 2006, 21:49 UTC
Message-ID
<20060317214931.23075.14431.stgit@c165>
In-Reply-To
<20060317214928.23075.76032.stgit@c165>

Before this patch git-blame <directory> gave non-sensible output. (It assigned blame to some random file in <directory>) Abort with an error message instead.

Signed-off-by: Fredrik Kuivinen <freku045@student.liu.se>
---
 blame.c |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)
diff --git a/blame.c b/blame.c
index 8af4b54..9c97aec 100644
--- a/blame.c
+++ b/blame.c
@@ -180,11 +180,13 @@ static int get_blob_sha1_internal(unsign
 				  unsigned mode, int stage);
 
 static unsigned char blob_sha1[20];
+static const char* blame_file;
 static int get_blob_sha1(struct tree *t, const char *pathname,
 			 unsigned char *sha1)
 {
 	int i;
 	const char *pathspec[2];
+	blame_file = pathname;
 	pathspec[0] = pathname;
 	pathspec[1] = NULL;
 	memset(blob_sha1, 0, sizeof(blob_sha1));
@@ -209,6 +211,10 @@ static int get_blob_sha1_internal(unsign
 	if (S_ISDIR(mode))
 		return READ_TREE_RECURSIVE;
 
+	if (strncmp(blame_file, base, baselen) ||
+	    strcmp(blame_file + baselen, pathname))
+		return -1;
+
 	memcpy(blob_sha1, sha1, 20);
 	return -1;
 }
Previous: Fredrik Kuivinen
Message 2 of 2 in “blame: Nicer output”
  1. 1/2 blame: Nicer outputFredrik Kuivinen, Mar 17, 2006
  2. 2/2 blame: Fix git-blame <directory>Fredrik Kuivinen, Mar 17, 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.