@matheusbsbs / matheus-bagliano / commits / 53dc463627
Fork 0

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 <freku045@student.liu.se> Signed-off-by: Junio C Hamano <junkio@cox.net>

Fredrik Kuivinen committed Mar 17, 2006 at 22:49 UTC 53dc4636275c966bb0781709fd0dded1cced4458
1 file changed +6
blame.c
+6
@@ -180,11 +180,13 @@ static int get_blob_sha1_internal(unsigned char *sha1, const char *base,
180 unsigned mode, int stage);
181
182 static unsigned char blob_sha1[20];
183 +static const char* blame_file;
184 static int get_blob_sha1(struct tree *t, const char *pathname,
185 unsigned char *sha1)
186 {
187 int i;
188 const char *pathspec[2];
189 + blame_file = pathname;
190 pathspec[0] = pathname;
191 pathspec[1] = NULL;
192 memset(blob_sha1, 0, sizeof(blob_sha1));
@@ -209,6 +211,10 @@ static int get_blob_sha1_internal(unsigned char *sha1, const char *base,
211 if (S_ISDIR(mode))
212 return READ_TREE_RECURSIVE;
213
214 + if (strncmp(blame_file, base, baselen) ||
215 + strcmp(blame_file + baselen, pathname))
216 + return -1;
217 +
218 memcpy(blob_sha1, sha1, 20);
219 return -1;
220 }