blame.c: whitespace and formatting clean-up.
Signed-off-by: Junio C Hamano <junkio@cox.net>
Junio C Hamano committed
Oct 5, 2006 at 14:00 UTC
506e49ff9ff2b5be34b2bdf15c88038b00d3ef66
1 file changed
+100
-100
blame.c
+100
-100
@@ -20,16 +20,17 @@
20
21
#define DEBUG 0
22
23
-static const char blame_usage[] = "git-blame [-c] [-l] [-t] [-S <revs-file>] [--] file [commit]\n"
24
- " -c, --compatibility 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";
23
+static const char blame_usage[] =
24
+"git-blame [-c] [-l] [-t] [-S <revs-file>] [--] file [commit]\n"
25
+" -c, --compatibility Use the same output mode as git-annotate (Default: off)\n"
26
+" -l, --long Show long commit SHA1 (Default: off)\n"
27
+" -t, --time Show raw timestamp (Default: off)\n"
28
+" -S, --revs-file Use revisions from revs-file instead of calling git-rev-list\n"
29
+" -h, --help This message";
30
31
static struct commit **blame_lines;
32
static int num_blame_lines;
32
-static char* blame_contents;
33
+static char *blame_contents;
34
static int blame_len;
35
36
struct util_info {
@@ -38,9 +39,9 @@ struct util_info {
39
char *buf;
40
unsigned long size;
41
int num_lines;
41
- const char* pathname;
42
+ const char *pathname;
43
43
- void* topo_data;
44
+ void *topo_data;
45
};
46
47
struct chunk {
@@ -156,11 +157,10 @@ static int get_blob_sha1_internal(const unsigned char *sha1, const char *base,
157
unsigned mode, int stage);
158
159
static unsigned char blob_sha1[20];
159
-static const char* blame_file;
160
+static const char *blame_file;
161
static int get_blob_sha1(struct tree *t, const char *pathname,
162
unsigned char *sha1)
163
{
163
- int i;
164
const char *pathspec[2];
165
blame_file = pathname;
166
pathspec[0] = pathname;
@@ -168,12 +168,7 @@ static int get_blob_sha1(struct tree *t, const char *pathname,
168
hashclr(blob_sha1);
169
read_tree_recursive(t, "", 0, 0, pathspec, get_blob_sha1_internal);
170
171
- for (i = 0; i < 20; i++) {
172
- if (blob_sha1[i] != 0)
173
- break;
174
- }
175
-
176
- if (i == 20)
171
+ if (is_null_sha1(blob_sha1))
172
return -1;
173
174
hashcpy(sha1, blob_sha1);
@@ -239,7 +234,8 @@ static void print_map(struct commit *cmit, struct commit *other)
234
if (i < util->num_lines) {
235
num = util->line_map[i];
236
printf("%d\t", num);
242
- } else
237
+ }
238
+ else
239
printf("\t");
240
241
if (i < util2->num_lines) {
@@ -247,7 +243,8 @@ static void print_map(struct commit *cmit, struct commit *other)
243
printf("%d\t", num2);
244
if (num != -1 && num2 != num)
245
printf("---");
250
- } else
246
+ }
247
+ else
248
printf("\t");
249
250
printf("\n");
@@ -266,12 +263,12 @@ static void fill_line_map(struct commit *commit, struct commit *other,
263
int cur_chunk = 0;
264
int i1, i2;
265
269
- if (p->num && DEBUG)
270
- print_patch(p);
271
-
272
- if (DEBUG)
266
+ if (DEBUG) {
267
+ if (p->num)
268
+ print_patch(p);
269
printf("num lines 1: %d num lines 2: %d\n", util->num_lines,
270
util2->num_lines);
271
+ }
272
273
for (i1 = 0, i2 = 0; i1 < util->num_lines; i1++, i2++) {
274
struct chunk *chunk = NULL;
@@ -293,7 +290,8 @@ static void fill_line_map(struct commit *commit, struct commit *other,
290
i2 += chunk->len2;
291
292
cur_chunk++;
296
- } else {
293
+ }
294
+ else {
295
if (i2 >= util2->num_lines)
296
break;
297
@@ -327,7 +325,7 @@ static int map_line(struct commit *commit, int line)
325
return info->line_map[line];
326
}
327
330
-static struct util_info* get_util(struct commit *commit)
328
+static struct util_info *get_util(struct commit *commit)
329
{
330
struct util_info *util = commit->util;
331
@@ -369,7 +367,7 @@ static void alloc_line_map(struct commit *commit)
367
if (util->buf[i] == '\n')
368
util->num_lines++;
369
}
372
- if(util->buf[util->size - 1] != '\n')
370
+ if (util->buf[util->size - 1] != '\n')
371
util->num_lines++;
372
373
util->line_map = xmalloc(sizeof(int) * util->num_lines);
@@ -378,9 +376,9 @@ static void alloc_line_map(struct commit *commit)
376
util->line_map[i] = -1;
377
}
378
381
-static void init_first_commit(struct commit* commit, const char* filename)
379
+static void init_first_commit(struct commit *commit, const char *filename)
380
{
383
- struct util_info* util = commit->util;
381
+ struct util_info *util = commit->util;
382
int i;
383
384
util->pathname = filename;
@@ -395,18 +393,17 @@ static void init_first_commit(struct commit* commit, const char* filename)
393
util->line_map[i] = i;
394
}
395
398
-
396
static void process_commits(struct rev_info *rev, const char *path,
400
- struct commit** initial)
397
+ struct commit **initial)
398
{
399
int i;
403
- struct util_info* util;
400
+ struct util_info *util;
401
int lines_left;
402
int *blame_p;
403
int *new_lines;
404
int new_lines_len;
405
409
- struct commit* commit = get_revision(rev);
406
+ struct commit *commit = get_revision(rev);
407
assert(commit);
408
init_first_commit(commit, path);
409
@@ -442,7 +439,7 @@ static void process_commits(struct rev_info *rev, const char *path,
439
parents != NULL; parents = parents->next)
440
num_parents++;
441
445
- if(num_parents == 0)
442
+ if (num_parents == 0)
443
*initial = commit;
444
445
if (fill_util_info(commit))
@@ -503,13 +500,12 @@ static void process_commits(struct rev_info *rev, const char *path,
500
} while ((commit = get_revision(rev)) != NULL);
501
}
502
506
-
507
-static int compare_tree_path(struct rev_info* revs,
508
- struct commit* c1, struct commit* c2)
503
+static int compare_tree_path(struct rev_info *revs,
504
+ struct commit *c1, struct commit *c2)
505
{
506
int ret;
511
- const char* paths[2];
512
- struct util_info* util = c2->util;
507
+ const char *paths[2];
508
+ struct util_info *util = c2->util;
509
paths[0] = util->pathname;
510
paths[1] = NULL;
511
@@ -520,12 +516,11 @@ static int compare_tree_path(struct rev_info* revs,
516
return ret;
517
}
518
523
-
524
-static int same_tree_as_empty_path(struct rev_info *revs, struct tree* t1,
525
- const char* path)
519
+static int same_tree_as_empty_path(struct rev_info *revs, struct tree *t1,
520
+ const char *path)
521
{
522
int ret;
528
- const char* paths[2];
523
+ const char *paths[2];
524
paths[0] = path;
525
paths[1] = NULL;
526
@@ -536,9 +531,9 @@ static int same_tree_as_empty_path(struct rev_info *revs, struct tree* t1,
531
return ret;
532
}
533
539
-static const char* find_rename(struct commit* commit, struct commit* parent)
534
+static const char *find_rename(struct commit *commit, struct commit *parent)
535
{
541
- struct util_info* cutil = commit->util;
536
+ struct util_info *cutil = commit->util;
537
struct diff_options diff_opts;
538
const char *paths[1];
539
int i;
@@ -564,9 +559,11 @@ static const char* find_rename(struct commit* commit, struct commit* parent)
559
for (i = 0; i < diff_queued_diff.nr; i++) {
560
struct diff_filepair *p = diff_queued_diff.queue[i];
561
567
- if (p->status == 'R' && !strcmp(p->one->path, cutil->pathname)) {
562
+ if (p->status == 'R' &&
563
+ !strcmp(p->one->path, cutil->pathname)) {
564
if (DEBUG)
569
- printf("rename %s -> %s\n", p->one->path, p->two->path);
565
+ printf("rename %s -> %s\n",
566
+ p->one->path, p->two->path);
567
return p->two->path;
568
}
569
}
@@ -582,7 +579,7 @@ static void simplify_commit(struct rev_info *revs, struct commit *commit)
579
return;
580
581
if (!commit->parents) {
585
- struct util_info* util = commit->util;
582
+ struct util_info *util = commit->util;
583
if (!same_tree_as_empty_path(revs, commit->tree,
584
util->pathname))
585
commit->object.flags |= TREECHANGE;
@@ -608,17 +605,17 @@ static void simplify_commit(struct rev_info *revs, struct commit *commit)
605
606
case REV_TREE_NEW:
607
{
611
-
612
- struct util_info* util = commit->util;
608
+ struct util_info *util = commit->util;
609
if (revs->remove_empty_trees &&
610
same_tree_as_empty_path(revs, p->tree,
611
util->pathname)) {
616
- const char* new_name = find_rename(commit, p);
612
+ const char *new_name = find_rename(commit, p);
613
if (new_name) {
618
- struct util_info* putil = get_util(p);
614
+ struct util_info *putil = get_util(p);
615
if (!putil->pathname)
616
putil->pathname = xstrdup(new_name);
621
- } else {
617
+ }
618
+ else {
619
*pp = parent->next;
620
continue;
621
}
@@ -639,19 +636,18 @@ static void simplify_commit(struct rev_info *revs, struct commit *commit)
636
commit->object.flags |= TREECHANGE;
637
}
638
642
-
639
struct commit_info
640
{
645
- char* author;
646
- char* author_mail;
641
+ char *author;
642
+ char *author_mail;
643
unsigned long author_time;
648
- char* author_tz;
644
+ char *author_tz;
645
};
646
651
-static void get_commit_info(struct commit* commit, struct commit_info* ret)
647
+static void get_commit_info(struct commit *commit, struct commit_info *ret)
648
{
649
int len;
654
- char* tmp;
650
+ char *tmp;
651
static char author_buf[1024];
652
653
tmp = strstr(commit->buffer, "\nauthor ") + 8;
@@ -662,24 +658,24 @@ static void get_commit_info(struct commit* commit, struct commit_info* ret)
658
tmp = ret->author;
659
tmp += len;
660
*tmp = 0;
665
- while(*tmp != ' ')
661
+ while (*tmp != ' ')
662
tmp--;
663
ret->author_tz = tmp+1;
664
665
*tmp = 0;
670
- while(*tmp != ' ')
666
+ while (*tmp != ' ')
667
tmp--;
668
ret->author_time = strtoul(tmp, NULL, 10);
669
670
*tmp = 0;
675
- while(*tmp != ' ')
671
+ while (*tmp != ' ')
672
tmp--;
673
ret->author_mail = tmp + 1;
674
675
*tmp = 0;
676
}
677
682
-static const char* format_time(unsigned long time, const char* tz_str,
678
+static const char *format_time(unsigned long time, const char *tz_str,
679
int show_raw_time)
680
{
681
static char time_buf[128];
@@ -704,15 +700,15 @@ static const char* format_time(unsigned long time, const char* tz_str,
700
return time_buf;
701
}
702
707
-static void topo_setter(struct commit* c, void* data)
703
+static void topo_setter(struct commit *c, void *data)
704
{
709
- struct util_info* util = c->util;
705
+ struct util_info *util = c->util;
706
util->topo_data = data;
707
}
708
713
-static void* topo_getter(struct commit* c)
709
+static void *topo_getter(struct commit *c)
710
{
715
- struct util_info* util = c->util;
711
+ struct util_info *util = c->util;
712
return util->topo_data;
713
}
714
@@ -747,9 +743,9 @@ int main(int argc, const char **argv)
743
int compatibility = 0;
744
int show_raw_time = 0;
745
int options = 1;
750
- struct commit* start_commit;
746
+ struct commit *start_commit;
747
752
- const char* args[10];
748
+ const char *args[10];
749
struct rev_info rev;
750
751
struct commit_info ci;
@@ -758,27 +754,30 @@ int main(int argc, const char **argv)
754
int longest_file, longest_author;
755
int found_rename;
756
761
- const char* prefix = setup_git_directory();
757
+ const char *prefix = setup_git_directory();
758
git_config(git_default_config);
759
764
- for(i = 1; i < argc; i++) {
765
- if(options) {
766
- if(!strcmp(argv[i], "-h") ||
760
+ for (i = 1; i < argc; i++) {
761
+ if (options) {
762
+ if (!strcmp(argv[i], "-h") ||
763
!strcmp(argv[i], "--help"))
764
usage(blame_usage);
769
- else if(!strcmp(argv[i], "-l") ||
770
- !strcmp(argv[i], "--long")) {
765
+ if (!strcmp(argv[i], "-l") ||
766
+ !strcmp(argv[i], "--long")) {
767
sha1_len = 40;
768
continue;
773
- } else if(!strcmp(argv[i], "-c") ||
774
- !strcmp(argv[i], "--compatibility")) {
769
+ }
770
+ if (!strcmp(argv[i], "-c") ||
771
+ !strcmp(argv[i], "--compatibility")) {
772
compatibility = 1;
773
continue;
777
- } else if(!strcmp(argv[i], "-t") ||
778
- !strcmp(argv[i], "--time")) {
774
+ }
775
+ if (!strcmp(argv[i], "-t") ||
776
+ !strcmp(argv[i], "--time")) {
777
show_raw_time = 1;
778
continue;
781
- } else if(!strcmp(argv[i], "-S")) {
779
+ }
780
+ if (!strcmp(argv[i], "-S")) {
781
if (i + 1 < argc &&
782
!read_ancestry(argv[i + 1], &sha1_p)) {
783
compatibility = 1;
@@ -786,33 +785,34 @@ int main(int argc, const char **argv)
785
continue;
786
}
787
usage(blame_usage);
789
- } else if(!strcmp(argv[i], "--")) {
788
+ }
789
+ if (!strcmp(argv[i], "--")) {
790
options = 0;
791
continue;
792
- } else if(argv[i][0] == '-')
792
+ }
793
+ if (argv[i][0] == '-')
794
usage(blame_usage);
794
- else
795
- options = 0;
795
+ options = 0;
796
}
797
798
- if(!options) {
799
- if(!filename)
798
+ if (!options) {
799
+ if (!filename)
800
filename = argv[i];
801
- else if(!commit)
801
+ else if (!commit)
802
commit = argv[i];
803
else
804
usage(blame_usage);
805
}
806
}
807
808
- if(!filename)
808
+ if (!filename)
809
usage(blame_usage);
810
if (commit && sha1_p)
811
usage(blame_usage);
812
- else if(!commit)
812
+ else if (!commit)
813
commit = "HEAD";
814
815
- if(prefix)
815
+ if (prefix)
816
sprintf(filename_buf, "%s%s", prefix, filename);
817
else
818
strcpy(filename_buf, filename);
@@ -830,7 +830,6 @@ int main(int argc, const char **argv)
830
return 1;
831
}
832
833
-
833
init_revisions(&rev, setup_git_directory());
834
rev.remove_empty_trees = 1;
835
rev.topo_order = 1;
@@ -857,7 +856,7 @@ int main(int argc, const char **argv)
856
found_rename = 0;
857
for (i = 0; i < num_blame_lines; i++) {
858
struct commit *c = blame_lines[i];
860
- struct util_info* u;
859
+ struct util_info *u;
860
if (!c)
861
c = initial;
862
u = c->util;
@@ -873,20 +872,20 @@ int main(int argc, const char **argv)
872
873
for (i = 0; i < num_blame_lines; i++) {
874
struct commit *c = blame_lines[i];
876
- struct util_info* u;
877
-
875
+ struct util_info *u;
876
if (!c)
877
c = initial;
880
-
878
u = c->util;
879
+
880
get_commit_info(c, &ci);
881
fwrite(sha1_to_hex(c->object.sha1), sha1_len, 1, stdout);
884
- if(compatibility) {
882
+ if (compatibility) {
883
printf("\t(%10s\t%10s\t%d)", ci.author,
884
format_time(ci.author_time, ci.author_tz,
885
show_raw_time),
886
i+1);
889
- } else {
887
+ }
888
+ else {
889
if (found_rename)
890
printf(" %-*.*s", longest_file, longest_file,
891
u->pathname);
@@ -897,13 +896,14 @@ int main(int argc, const char **argv)
896
max_digits, i+1);
897
}
898
900
- if(i == num_blame_lines - 1) {
899
+ if (i == num_blame_lines - 1) {
900
fwrite(buf, blame_len - (buf - blame_contents),
901
1, stdout);
903
- if(blame_contents[blame_len-1] != '\n')
902
+ if (blame_contents[blame_len-1] != '\n')
903
putc('\n', stdout);
905
- } else {
906
- char* next_buf = strchr(buf, '\n') + 1;
904
+ }
905
+ else {
906
+ char *next_buf = strchr(buf, '\n') + 1;
907
fwrite(buf, next_buf - buf, 1, stdout);
908
buf = next_buf;
909
}