{"thread":{"id":"3658","subject":"[PATCH 1/2] blame: Nicer output","startedAt":"2006-03-17T21:49:28Z","lastAt":"2006-03-17T21:49:31Z","messageCount":2,"participants":["Fredrik Kuivinen"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"17625","messageId":"20060317214928.23075.76032.stgit@c165","threadId":"3658","inReplyTo":null,"subject":"[PATCH 1/2] blame: Nicer output","fromName":"Fredrik Kuivinen","fromEmail":"freku045@student.liu.se","sentAt":"2006-03-17T21:49:28Z","receivedAt":"2006-03-17T21:49:28Z","isPatch":true,"sender":{"key":"frekui@gmail.com","avatar":"https://avatars.githubusercontent.com/u/13770967?v=4"},"body":"\nAs pointed out by Junio, it may be dangerous to cut off people's names\nafter 15 bytes. If the name is encoded in an encoding which uses more\nthan one byte per code point we may end up with outputting garbage.\nInstead of trying to do something smart, just output the entire name.\nWe don't gain much screen space by chopping it off anyway.\n\nFurthermore, only output the file name if we actually found any\nrenames.\n\nSigned-off-by: Fredrik Kuivinen <freku045@student.liu.se>\n\n---\n\n blame.c |   35 ++++++++++++++++++++++++++++++-----\n 1 files changed, 30 insertions(+), 5 deletions(-)\n\ndiff --git a/blame.c b/blame.c\nindex 1fb5070..8af4b54 100644\n--- a/blame.c\n+++ b/blame.c\n@@ -742,6 +742,8 @@ int main(int argc, const char **argv)\n \tstruct commit_info ci;\n \tconst char *buf;\n \tint max_digits;\n+\tsize_t longest_file, longest_author;\n+\tint found_rename;\n \n \tconst char* prefix = setup_git_directory();\n \n@@ -818,6 +820,25 @@ int main(int argc, const char **argv)\n \tfor (max_digits = 1, i = 10; i <= num_blame_lines + 1; max_digits++)\n \t\ti *= 10;\n \n+\tlongest_file = 0;\n+\tlongest_author = 0;\n+\tfound_rename = 0;\n+\tfor (i = 0; i < num_blame_lines; i++) {\n+\t\tstruct commit *c = blame_lines[i];\n+\t\tstruct util_info* u;\n+\t\tif (!c)\n+\t\t\tc = initial;\n+\t\tu = c->object.util;\n+\n+\t\tif (!found_rename && strcmp(filename, u->pathname))\n+\t\t\tfound_rename = 1;\n+\t\tif (longest_file < strlen(u->pathname))\n+\t\t\tlongest_file = strlen(u->pathname);\n+\t\tget_commit_info(c, &ci);\n+\t\tif (longest_author < strlen(ci.author))\n+\t\t\tlongest_author = strlen(ci.author);\n+\t}\n+\n \tfor (i = 0; i < num_blame_lines; i++) {\n \t\tstruct commit *c = blame_lines[i];\n \t\tstruct util_info* u;\n@@ -828,14 +849,18 @@ int main(int argc, const char **argv)\n \t\tu = c->object.util;\n \t\tget_commit_info(c, &ci);\n \t\tfwrite(sha1_to_hex(c->object.sha1), sha1_len, 1, stdout);\n-\t\tif(compability)\n+\t\tif(compability) {\n \t\t\tprintf(\"\\t(%10s\\t%10s\\t%d)\", ci.author,\n \t\t\t       format_time(ci.author_time, ci.author_tz), i+1);\n-\t\telse\n-\t\t\tprintf(\" %s (%-15.15s %10s %*d) \", u->pathname,\n-\t\t\t       ci.author, format_time(ci.author_time,\n-\t\t\t\t\t\t      ci.author_tz),\n+\t\t} else {\n+\t\t\tif (found_rename)\n+\t\t\t\tprintf(\" %-*.*s\", longest_file, longest_file,\n+\t\t\t\t       u->pathname);\n+\t\t\tprintf(\" (%-*.*s %10s %*d) \",\n+\t\t\t       longest_author, longest_author, ci.author,\n+\t\t\t       format_time(ci.author_time, ci.author_tz),\n \t\t\t       max_digits, i+1);\n+\t\t}\n \n \t\tif(i == num_blame_lines - 1) {\n \t\t\tfwrite(buf, blame_len - (buf - blame_contents),\n"},{"id":"17626","messageId":"20060317214931.23075.14431.stgit@c165","threadId":"3658","inReplyTo":"20060317214928.23075.76032.stgit@c165","subject":"[PATCH 2/2] blame: Fix git-blame <directory>","fromName":"Fredrik Kuivinen","fromEmail":"freku045@student.liu.se","sentAt":"2006-03-17T21:49:31Z","receivedAt":"2006-03-17T21:49:31Z","isPatch":true,"sender":{"key":"frekui@gmail.com","avatar":"https://avatars.githubusercontent.com/u/13770967?v=4"},"body":"\nBefore this patch git-blame <directory> gave non-sensible output. (It\nassigned blame to some random file in <directory>) Abort with an error\nmessage instead.\n\nSigned-off-by: Fredrik Kuivinen <freku045@student.liu.se>\n\n---\n\n blame.c |    6 ++++++\n 1 files changed, 6 insertions(+), 0 deletions(-)\n\ndiff --git a/blame.c b/blame.c\nindex 8af4b54..9c97aec 100644\n--- a/blame.c\n+++ b/blame.c\n@@ -180,11 +180,13 @@ static int get_blob_sha1_internal(unsign\n \t\t\t\t  unsigned mode, int stage);\n \n static unsigned char blob_sha1[20];\n+static const char* blame_file;\n static int get_blob_sha1(struct tree *t, const char *pathname,\n \t\t\t unsigned char *sha1)\n {\n \tint i;\n \tconst char *pathspec[2];\n+\tblame_file = pathname;\n \tpathspec[0] = pathname;\n \tpathspec[1] = NULL;\n \tmemset(blob_sha1, 0, sizeof(blob_sha1));\n@@ -209,6 +211,10 @@ static int get_blob_sha1_internal(unsign\n \tif (S_ISDIR(mode))\n \t\treturn READ_TREE_RECURSIVE;\n \n+\tif (strncmp(blame_file, base, baselen) ||\n+\t    strcmp(blame_file + baselen, pathname))\n+\t\treturn -1;\n+\n \tmemcpy(blob_sha1, sha1, 20);\n \treturn -1;\n }\n"}]}