Skip to content

Commit 53dc463

Browse files
Fredrik KuivinenJunio C Hamano
authored andcommitted
blame: Fix git-blame <directory>
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 88a8b79 commit 53dc463

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

blame.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,11 +180,13 @@ static int get_blob_sha1_internal(unsigned char *sha1, const char *base,
180180
unsigned mode, int stage);
181181

182182
static unsigned char blob_sha1[20];
183+
static const char* blame_file;
183184
static int get_blob_sha1(struct tree *t, const char *pathname,
184185
unsigned char *sha1)
185186
{
186187
int i;
187188
const char *pathspec[2];
189+
blame_file = pathname;
188190
pathspec[0] = pathname;
189191
pathspec[1] = NULL;
190192
memset(blob_sha1, 0, sizeof(blob_sha1));
@@ -209,6 +211,10 @@ static int get_blob_sha1_internal(unsigned char *sha1, const char *base,
209211
if (S_ISDIR(mode))
210212
return READ_TREE_RECURSIVE;
211213

214+
if (strncmp(blame_file, base, baselen) ||
215+
strcmp(blame_file + baselen, pathname))
216+
return -1;
217+
212218
memcpy(blob_sha1, sha1, 20);
213219
return -1;
214220
}

0 commit comments

Comments
 (0)