@matheusbsbs / matheus-bagliano / commits / 88a8b79556
Fork 0

blame: Nicer output

As pointed out by Junio, it may be dangerous to cut off people's names after 15 bytes. If the name is encoded in an encoding which uses more than one byte per code point we may end up with outputting garbage. Instead of trying to do something smart, just output the entire name. We don't gain much screen space by chopping it off anyway. Furthermore, only output the file name if we actually found any renames. 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 88a8b7955666ed8fa5924fadbb3bb58984eaa6af
1 file changed +30 -5
blame.c
+30 -5
@@ -742,6 +742,8 @@ int main(int argc, const char **argv)
742 struct commit_info ci;
743 const char *buf;
744 int max_digits;
745 + size_t longest_file, longest_author;
746 + int found_rename;
747
748 const char* prefix = setup_git_directory();
749
@@ -818,6 +820,25 @@ int main(int argc, const char **argv)
820 for (max_digits = 1, i = 10; i <= num_blame_lines + 1; max_digits++)
821 i *= 10;
822
823 + longest_file = 0;
824 + longest_author = 0;
825 + found_rename = 0;
826 + for (i = 0; i < num_blame_lines; i++) {
827 + struct commit *c = blame_lines[i];
828 + struct util_info* u;
829 + if (!c)
830 + c = initial;
831 + u = c->object.util;
832 +
833 + if (!found_rename && strcmp(filename, u->pathname))
834 + found_rename = 1;
835 + if (longest_file < strlen(u->pathname))
836 + longest_file = strlen(u->pathname);
837 + get_commit_info(c, &ci);
838 + if (longest_author < strlen(ci.author))
839 + longest_author = strlen(ci.author);
840 + }
841 +
842 for (i = 0; i < num_blame_lines; i++) {
843 struct commit *c = blame_lines[i];
844 struct util_info* u;
@@ -828,14 +849,18 @@ int main(int argc, const char **argv)
849 u = c->object.util;
850 get_commit_info(c, &ci);
851 fwrite(sha1_to_hex(c->object.sha1), sha1_len, 1, stdout);
831 - if(compability)
852 + if(compability) {
853 printf("\t(%10s\t%10s\t%d)", ci.author,
854 format_time(ci.author_time, ci.author_tz), i+1);
834 - else
835 - printf(" %s (%-15.15s %10s %*d) ", u->pathname,
836 - ci.author, format_time(ci.author_time,
837 - ci.author_tz),
855 + } else {
856 + if (found_rename)
857 + printf(" %-*.*s", longest_file, longest_file,
858 + u->pathname);
859 + printf(" (%-*.*s %10s %*d) ",
860 + longest_author, longest_author, ci.author,
861 + format_time(ci.author_time, ci.author_tz),
862 max_digits, i+1);
863 + }
864
865 if(i == num_blame_lines - 1) {
866 fwrite(buf, blame_len - (buf - blame_contents),