make 'got blame' show committer names
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
diff --git a/got/got.c b/got/got.c
index 6aaab25..0a9f047 100644
--- a/got/got.c
+++ b/got/got.c
@@ -2157,6 +2157,7 @@ usage_blame(void)
struct blame_line {
int annotated;
char *id_str;
+ char *committer;
};
struct blame_cb_args {
@@ -2166,6 +2167,7 @@ struct blame_cb_args {
int lineno_cur;
off_t *line_offsets;
FILE *f;
+ struct got_repository *repo;
};
static const struct got_error *
@@ -2174,8 +2176,9 @@ blame_cb(void *arg, int nlines, int lineno, struct got_object_id *id)
const struct got_error *err = NULL;
struct blame_cb_args *a = arg;
struct blame_line *bline;
- char *line = NULL, *nl;
+ char *line = NULL;
size_t linesize = 0;
+ struct got_commit_object *commit = NULL;
off_t offset;
if (nlines != a->nlines ||
@@ -2192,34 +2195,62 @@ blame_cb(void *arg, int nlines, int lineno, struct got_object_id *id)
err = got_object_id_str(&bline->id_str, id);
if (err)
return err;
+
+ err = got_object_open_as_commit(&commit, a->repo, id);
+ if (err)
+ goto done;
+
+ bline->committer = strdup(got_object_commit_get_committer(commit));
+ if (bline->committer == NULL) {
+ err = got_error_from_errno("strdup");
+ goto done;
+ }
bline->annotated = 1;
/* Print lines annotated so far. */
bline = &a->lines[a->lineno_cur - 1];
if (!bline->annotated)
- return NULL;
+ goto done;
offset = a->line_offsets[a->lineno_cur - 1];
- if (fseeko(a->f, offset, SEEK_SET) == -1)
- return got_error_from_errno("fseeko");
+ if (fseeko(a->f, offset, SEEK_SET) == -1) {
+ err = got_error_from_errno("fseeko");
+ goto done;
+ }
while (bline->annotated) {
+ char *smallerthan, *at, *nl, *committer;
+ size_t len;
+
if (getline(&line, &linesize, a->f) == (ssize_t)-1) {
if (ferror(a->f))
err = got_error_from_errno("getline");
break;
}
+ committer = bline->committer;
+ smallerthan = strchr(committer, '<');
+ if (smallerthan && smallerthan[1] != '\0')
+ committer = smallerthan + 1;
+ at = strchr(committer, '@');
+ if (at)
+ *at = '\0';
+ len = strlen(committer);
+ if (len >= 9)
+ committer[8] = '\0';
+
nl = strchr(line, '\n');
if (nl)
*nl = '\0';
- printf("%.*d) %.8s %s\n", a->nlines_prec, a->lineno_cur,
- bline->id_str, line);
+ printf("%.*d) %.8s %-8s %s\n", a->nlines_prec, a->lineno_cur,
+ bline->id_str, committer, line);
a->lineno_cur++;
bline = &a->lines[a->lineno_cur - 1];
}
-
+done:
+ if (commit)
+ got_object_commit_close(commit);
free(line);
return err;
}
@@ -2373,15 +2404,14 @@ cmd_blame(int argc, char *argv[])
error = got_error_from_errno("calloc");
goto done;
}
-
bca.lineno_cur = 1;
-
bca.nlines_prec = 0;
i = bca.nlines;
while (i > 0) {
i /= 10;
bca.nlines_prec++;
}
+ bca.repo = repo;
error = got_blame_incremental(in_repo_path, commit_id, repo,
blame_cb, &bca);
@@ -2406,6 +2436,7 @@ done:
for (i = 0; i < bca.nlines; i++) {
struct blame_line *bline = &bca.lines[i];
free(bline->id_str);
+ free(bline->committer);
}
free(bca.lines);
free(bca.line_offsets);
diff --git a/regress/cmdline/blame.sh b/regress/cmdline/blame.sh
index b3f34a6..ffd9450 100755
--- a/regress/cmdline/blame.sh
+++ b/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 "1) $short_commit1 1" > $testroot/stdout.expected
- echo "2) $short_commit2 2" >> $testroot/stdout.expected
- echo "3) $short_commit3 3" >> $testroot/stdout.expected
+ echo "1) $short_commit1 $GOT_AUTHOR_8 1" > $testroot/stdout.expected
+ echo "2) $short_commit2 $GOT_AUTHOR_8 2" >> $testroot/stdout.expected
+ echo "3) $short_commit3 $GOT_AUTHOR_8 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 "1) $short_commit1 1" > $testroot/stdout.expected
- echo "2) $short_commit2 2" >> $testroot/stdout.expected
+ echo "1) $short_commit1 $GOT_AUTHOR_8 1" > $testroot/stdout.expected
+ echo "2) $short_commit2 $GOT_AUTHOR_8 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 "1) $short_commit1 1" > $testroot/stdout.expected
+ echo "1) $short_commit1 $GOT_AUTHOR_8 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 "1) $short_commit1 1" > $testroot/stdout.expected
+ echo "1) $short_commit1 $GOT_AUTHOR_8 1" > $testroot/stdout.expected
cmp -s $testroot/stdout.expected $testroot/stdout
ret="$?"
diff --git a/regress/cmdline/common.sh b/regress/cmdline/common.sh
index 7554600..296735a 100644
--- a/regress/cmdline/common.sh
+++ b/regress/cmdline/common.sh
@@ -15,6 +15,7 @@
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
export GOT_AUTHOR="Flan Hacker <flan_hacker@openbsd.org>"
+export GOT_AUTHOR_8="flan_hac"
export GOT_LOG_DEFAULT_LIMIT=0
export MALLOC_OPTIONS=S