blame.c: move code to output metainfo into a separate function.
This does not change any behaviour, but just separates out the code to emit the initial part of the output of each line into a separate function, since I'll be mucking with it further. Signed-off-by: Junio C Hamano <junkio@cox.net>
Junio C Hamano committed
Oct 5, 2006 at 14:06 UTC
c137f40f8a9dfe05ee002cf5f23bf562c1f13100
1 file changed
+45
-31
blame.c
+45
-31
@@ -750,6 +750,42 @@ static int find_orig_linenum(struct util_info *u, int lineno)
750
return 0;
751
}
752
753
+static void emit_meta(struct commit *c, int lno,
754
+ int sha1_len, int compatibility,
755
+ int show_name, int show_number, int show_raw_time,
756
+ int longest_file, int longest_author,
757
+ int max_digits, int max_orig_digits)
758
+{
759
+ struct util_info *u;
760
+ int lineno;
761
+ struct commit_info ci;
762
+
763
+ u = c->util;
764
+ lineno = find_orig_linenum(u, lno);
765
+
766
+ get_commit_info(c, &ci);
767
+ fwrite(sha1_to_hex(c->object.sha1), sha1_len, 1, stdout);
768
+ if (compatibility) {
769
+ printf("\t(%10s\t%10s\t%d)", ci.author,
770
+ format_time(ci.author_time, ci.author_tz,
771
+ show_raw_time),
772
+ lno + 1);
773
+ }
774
+ else {
775
+ if (show_name)
776
+ printf(" %-*.*s", longest_file, longest_file,
777
+ u->pathname);
778
+ if (show_number)
779
+ printf(" %*d", max_orig_digits,
780
+ lineno);
781
+ printf(" (%-*.*s %10s %*d) ",
782
+ longest_author, longest_author, ci.author,
783
+ format_time(ci.author_time, ci.author_tz,
784
+ show_raw_time),
785
+ max_digits, lno + 1);
786
+ }
787
+}
788
+
789
int main(int argc, const char **argv)
790
{
791
int i;
@@ -877,6 +913,10 @@ int main(int argc, const char **argv)
913
prepare_revision_walk(&rev);
914
process_commits(&rev, filename, &initial);
915
916
+ for (i = 0; i < num_blame_lines; i++)
917
+ if (!blame_lines[i])
918
+ blame_lines[i] = initial;
919
+
920
buf = blame_contents;
921
max_digits = lineno_width(num_blame_lines);
922
@@ -886,8 +926,6 @@ int main(int argc, const char **argv)
926
for (i = 0; i < num_blame_lines; i++) {
927
struct commit *c = blame_lines[i];
928
struct util_info *u;
889
- if (!c)
890
- c = initial;
929
u = c->util;
930
931
if (!show_name && strcmp(filename, u->pathname))
@@ -904,35 +942,11 @@ int main(int argc, const char **argv)
942
max_orig_digits = lineno_width(longest_file_lines);
943
944
for (i = 0; i < num_blame_lines; i++) {
907
- struct commit *c = blame_lines[i];
908
- struct util_info *u;
909
- int lineno;
910
- if (!c)
911
- c = initial;
912
- u = c->util;
913
- lineno = find_orig_linenum(u, i);
914
-
915
- get_commit_info(c, &ci);
916
- fwrite(sha1_to_hex(c->object.sha1), sha1_len, 1, stdout);
917
- if (compatibility) {
918
- printf("\t(%10s\t%10s\t%d)", ci.author,
919
- format_time(ci.author_time, ci.author_tz,
920
- show_raw_time),
921
- i+1);
922
- }
923
- else {
924
- if (show_name)
925
- printf(" %-*.*s", longest_file, longest_file,
926
- u->pathname);
927
- if (show_number)
928
- printf(" %*d", max_orig_digits,
929
- lineno);
930
- printf(" (%-*.*s %10s %*d) ",
931
- longest_author, longest_author, ci.author,
932
- format_time(ci.author_time, ci.author_tz,
933
- show_raw_time),
934
- max_digits, i+1);
935
- }
945
+ emit_meta(blame_lines[i], i,
946
+ sha1_len, compatibility,
947
+ show_name, show_number, show_raw_time,
948
+ longest_file, longest_author,
949
+ max_digits, max_orig_digits);
950
951
if (i == num_blame_lines - 1) {
952
fwrite(buf, blame_len - (buf - blame_contents),