@matheusbsbs / matheus-bagliano / commits / b19ee24b22
Fork 0

blame: Add --time to produce raw timestamps

fix the usage string and clean up the docs while we are at it Signed-off-by: Fredrik Kuivinen <freku045@student.liu.se> Signed-off-by: Junio C Hamano <junkio@cox.net>

Fredrik Kuivinen committed Jun 13, 2006 at 08:08 UTC b19ee24b22b3c1d08f06e8f868f11d9e8639fd30
2 files changed +24 -5
Documentation/git-blame.txt
+4 -1
@@ -20,7 +20,10 @@ OPTIONS
20 Use the same output mode as git-annotate (Default: off).
21
22 -l, --long::
23 - Show long rev (Defaults off).
23 + Show long rev (Default: off).
24 +
25 +-t, --time::
26 + Show raw timestamp (Default: off).
27
28 -S, --rev-file <revs-file>::
29 Use revs from revs-file instead of calling git-rev-list.
blame.c
+20 -4
@@ -20,9 +20,11 @@
20
21 #define DEBUG 0
22
23 -static const char blame_usage[] = "[-c] [-l] [--] file [commit]\n"
23 +static const char blame_usage[] = "[-c] [-l] [-t] [-S <revs-file>] [--] file [commit]\n"
24 " -c, --compability Use the same output mode as git-annotate (Default: off)\n"
25 " -l, --long Show long commit SHA1 (Default: off)\n"
26 + " -t, --time Show raw timestamp (Default: off)\n"
27 + " -S, --revs-file Use revisions from revs-file instead of calling git-rev-list\n"
28 " -h, --help This message";
29
30 static struct commit **blame_lines;
@@ -680,13 +682,19 @@ static void get_commit_info(struct commit* commit, struct commit_info* ret)
682 *tmp = 0;
683 }
684
683 -static const char* format_time(unsigned long time, const char* tz_str)
685 +static const char* format_time(unsigned long time, const char* tz_str,
686 + int show_raw_time)
687 {
688 static char time_buf[128];
689 time_t t = time;
690 int minutes, tz;
691 struct tm *tm;
692
693 + if (show_raw_time) {
694 + sprintf(time_buf, "%lu %s", time, tz_str);
695 + return time_buf;
696 + }
697 +
698 tz = atoi(tz_str);
699 minutes = tz < 0 ? -tz : tz;
700 minutes = (minutes / 100)*60 + (minutes % 100);
@@ -740,6 +748,7 @@ int main(int argc, const char **argv)
748 char filename_buf[256];
749 int sha1_len = 8;
750 int compability = 0;
751 + int show_raw_time = 0;
752 int options = 1;
753 struct commit* start_commit;
754
@@ -768,6 +777,10 @@ int main(int argc, const char **argv)
777 !strcmp(argv[i], "--compability")) {
778 compability = 1;
779 continue;
780 + } else if(!strcmp(argv[i], "-t") ||
781 + !strcmp(argv[i], "--time")) {
782 + show_raw_time = 1;
783 + continue;
784 } else if(!strcmp(argv[i], "-S")) {
785 if (i + 1 < argc &&
786 !read_ancestry(argv[i + 1], &sha1_p)) {
@@ -873,14 +886,17 @@ int main(int argc, const char **argv)
886 fwrite(sha1_to_hex(c->object.sha1), sha1_len, 1, stdout);
887 if(compability) {
888 printf("\t(%10s\t%10s\t%d)", ci.author,
876 - format_time(ci.author_time, ci.author_tz), i+1);
889 + format_time(ci.author_time, ci.author_tz,
890 + show_raw_time),
891 + i+1);
892 } else {
893 if (found_rename)
894 printf(" %-*.*s", longest_file, longest_file,
895 u->pathname);
896 printf(" (%-*.*s %10s %*d) ",
897 longest_author, longest_author, ci.author,
883 - format_time(ci.author_time, ci.author_tz),
898 + format_time(ci.author_time, ci.author_tz,
899 + show_raw_time),
900 max_digits, i+1);
901 }
902