commit 7ef28ff8dd61cbf38f88784ea8c11e373757985f from: Stefan Sperling date: Wed Aug 14 21:10:00 2019 UTC make 'got blame' show line numbers commit - e27a7222faaa171dcb086ea0b566dc7bebb74a0b commit + 7ef28ff8dd61cbf38f88784ea8c11e373757985f blob - 892916e7b1e35425bc8bd687190937dfbe0c047c blob + 6aaab256399b6996c57b843dcf33ab27058b640b --- got/got.c +++ got/got.c @@ -2162,6 +2162,7 @@ struct blame_line { struct blame_cb_args { struct blame_line *lines; int nlines; + int nlines_prec; int lineno_cur; off_t *line_offsets; FILE *f; @@ -2212,7 +2213,8 @@ blame_cb(void *arg, int nlines, int lineno, struct got nl = strchr(line, '\n'); if (nl) *nl = '\0'; - printf("%.8s %s\n", bline->id_str, line); + printf("%.*d) %.8s %s\n", a->nlines_prec, a->lineno_cur, + bline->id_str, line); a->lineno_cur++; bline = &a->lines[a->lineno_cur - 1]; @@ -2363,7 +2365,7 @@ cmd_blame(int argc, char *argv[]) } error = got_object_blob_dump_to_file(NULL, &bca.nlines, &bca.line_offsets, bca.f, blob); - if (error) + if (error || bca.nlines == 0) goto done; bca.lines = calloc(bca.nlines, sizeof(*bca.lines)); @@ -2374,6 +2376,13 @@ cmd_blame(int argc, char *argv[]) bca.lineno_cur = 1; + bca.nlines_prec = 0; + i = bca.nlines; + while (i > 0) { + i /= 10; + bca.nlines_prec++; + } + error = got_blame_incremental(in_repo_path, commit_id, repo, blame_cb, &bca); if (error) blob - bd295cf08b277cac199f4c1fc887139d66aecd2f blob + b3f34a68bb9a7524660dc7ba0f73911918e96c8b --- regress/cmdline/blame.sh +++ regress/cmdline/blame.sh @@ -44,9 +44,9 @@ function test_blame_basic { local short_commit2=`trim_obj_id 32 $commit2` local short_commit3=`trim_obj_id 32 $commit3` - echo "$short_commit1 1" > $testroot/stdout.expected - echo "$short_commit2 2" >> $testroot/stdout.expected - echo "$short_commit3 3" >> $testroot/stdout.expected + echo "1) $short_commit1 1" > $testroot/stdout.expected + echo "2) $short_commit2 2" >> $testroot/stdout.expected + echo "3) $short_commit3 3" >> $testroot/stdout.expected cmp -s $testroot/stdout.expected $testroot/stdout ret="$?" @@ -86,8 +86,8 @@ function test_blame_tag { local short_commit1=`trim_obj_id 32 $commit1` local short_commit2=`trim_obj_id 32 $commit2` - echo "$short_commit1 1" > $testroot/stdout.expected - echo "$short_commit2 2" >> $testroot/stdout.expected + echo "1) $short_commit1 1" > $testroot/stdout.expected + echo "2) $short_commit2 2" >> $testroot/stdout.expected cmp -s $testroot/stdout.expected $testroot/stdout ret="$?" @@ -115,7 +115,7 @@ function test_blame_file_single_line { local short_commit1=`trim_obj_id 32 $commit1` - echo "$short_commit1 1" > $testroot/stdout.expected + echo "1) $short_commit1 1" > $testroot/stdout.expected cmp -s $testroot/stdout.expected $testroot/stdout ret="$?" @@ -143,7 +143,7 @@ function test_blame_file_single_line_no_newline { local short_commit1=`trim_obj_id 32 $commit1` - echo "$short_commit1 1" > $testroot/stdout.expected + echo "1) $short_commit1 1" > $testroot/stdout.expected cmp -s $testroot/stdout.expected $testroot/stdout ret="$?"