pass an already open commit object to the blame callback ok op@
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 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244
diff --git a/got/got.c b/got/got.c
index 5cb9d72..d75debc 100644
--- a/got/got.c
+++ b/got/got.c
@@ -4876,14 +4876,14 @@ struct blame_cb_args {
};
static const struct got_error *
-blame_cb(void *arg, int nlines, int lineno, struct got_object_id *id)
+blame_cb(void *arg, int nlines, int lineno,
+ struct got_commit_object *commit, struct got_object_id *id)
{
const struct got_error *err = NULL;
struct blame_cb_args *a = arg;
struct blame_line *bline;
char *line = NULL;
size_t linesize = 0;
- struct got_commit_object *commit = NULL;
off_t offset;
struct tm tm;
time_t committer_time;
@@ -4906,10 +4906,6 @@ blame_cb(void *arg, int nlines, int lineno, struct got_object_id *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");
@@ -4968,8 +4964,6 @@ blame_cb(void *arg, int nlines, int lineno, struct got_object_id *id)
bline = &a->lines[a->lineno_cur - 1];
}
done:
- if (commit)
- got_object_commit_close(commit);
free(line);
return err;
}
diff --git a/gotweb/gotweb.c b/gotweb/gotweb.c
index 70b31ef..7107881 100644
--- a/gotweb/gotweb.c
+++ b/gotweb/gotweb.c
@@ -214,6 +214,7 @@ static const struct got_error *gw_get_commit(struct gw_trans *,
struct got_object_id *);
static const struct got_error *gw_apply_unveil(const char *);
static const struct got_error *gw_blame_cb(void *, int, int,
+ struct got_commit_object *,
struct got_object_id *);
static const struct got_error *gw_load_got_paths(struct gw_trans *);
static const struct got_error *gw_load_got_path(struct gw_trans *,
@@ -3862,14 +3863,14 @@ struct gw_blame_cb_args {
};
static const struct got_error *
-gw_blame_cb(void *arg, int nlines, int lineno, struct got_object_id *id)
+gw_blame_cb(void *arg, int nlines, int lineno,
+ struct got_commit_object *commit, struct got_object_id *id)
{
const struct got_error *err = NULL;
struct gw_blame_cb_args *a = arg;
struct blame_line *bline;
char *line = NULL;
size_t linesize = 0;
- struct got_commit_object *commit = NULL;
off_t offset;
struct tm tm;
time_t committer_time;
@@ -3890,10 +3891,6 @@ gw_blame_cb(void *arg, int nlines, int lineno, struct got_object_id *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");
@@ -4030,8 +4027,6 @@ err:
free(href_diff);
}
done:
- if (commit)
- got_object_commit_close(commit);
free(line);
if (err == NULL && kerr != KCGI_OK)
err = gw_kcgi_error(kerr);
diff --git a/include/got_blame.h b/include/got_blame.h
index c4c15ba..e360955 100644
--- a/include/got_blame.h
+++ b/include/got_blame.h
@@ -14,6 +14,9 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+typedef const struct got_error *(*got_blame_cb)(void *, int, int,
+ struct got_commit_object *, struct got_object_id *);
+
/*
* Blame the blob at the specified path in the specified commit and invoke
* a callback whenever an annotation has been computed for a line.
@@ -33,5 +36,4 @@
*/
const struct got_error *got_blame(const char *,
struct got_object_id *, struct got_repository *,
- const struct got_error *(*cb)(void *, int, int, struct got_object_id *),
- void *, got_cancel_cb, void *);
+ got_blame_cb, void *, got_cancel_cb, void *);
diff --git a/lib/blame.c b/lib/blame.c
index 4fb57b6..19208f0 100644
--- a/lib/blame.c
+++ b/lib/blame.c
@@ -89,9 +89,9 @@ struct got_blame {
};
static const struct got_error *
-annotate_line(struct got_blame *blame, int lineno, struct got_object_id *id,
- const struct got_error *(*cb)(void *, int, int, struct got_object_id *),
- void *arg)
+annotate_line(struct got_blame *blame, int lineno,
+ struct got_commit_object *commit, struct got_object_id *id,
+ got_blame_cb cb, void *arg)
{
const struct got_error *err = NULL;
struct got_blame_line *line;
@@ -107,15 +107,14 @@ annotate_line(struct got_blame *blame, int lineno, struct got_object_id *id,
line->annotated = 1;
blame->nannotated++;
if (cb)
- err = cb(arg, blame->nlines, lineno + 1, id);
+ err = cb(arg, blame->nlines, lineno + 1, commit, id);
return err;
}
static const struct got_error *
blame_changes(struct got_blame *blame, struct diff_result *diff_result,
- struct got_object_id *commit_id,
- const struct got_error *(*cb)(void *, int, int, struct got_object_id *),
- void *arg)
+ struct got_commit_object *commit, struct got_object_id *commit_id,
+ got_blame_cb cb, void *arg)
{
const struct got_error *err = NULL;
int i;
@@ -153,7 +152,8 @@ blame_changes(struct got_blame *blame, struct diff_result *diff_result,
for (j = 0; j < right_count; j++) {
int ln = blame->linemap2[idx2++];
- err = annotate_line(blame, ln, commit_id, cb, arg);
+ err = annotate_line(blame, ln, commit, commit_id,
+ cb, arg);
if (err)
return err;
if (blame->nlines == blame->nannotated)
@@ -196,8 +196,7 @@ blame_prepare_file(FILE *f, unsigned char **p, off_t *size,
static const struct got_error *
blame_commit(struct got_blame *blame, struct got_object_id *id,
const char *path, struct got_repository *repo,
- const struct got_error *(*cb)(void *, int, int, struct got_object_id *),
- void *arg)
+ got_blame_cb cb, void *arg)
{
const struct got_error *err = NULL;
struct got_commit_object *commit = NULL, *pcommit = NULL;
@@ -261,11 +260,11 @@ blame_commit(struct got_blame *blame, struct got_object_id *id,
goto done;
}
}
- err = blame_changes(blame, diff_result, id, cb, arg);
+ err = blame_changes(blame, diff_result, commit, id, cb, arg);
if (err)
goto done;
} else if (cb)
- err = cb(arg, blame->nlines, -1, id);
+ err = cb(arg, blame->nlines, -1, commit, id);
done:
if (diff_result)
diff_result_free(diff_result);
@@ -500,11 +499,10 @@ close_file2_and_reuse_file1(struct got_blame *blame)
static const struct got_error *
blame_open(struct got_blame **blamep, const char *path,
struct got_object_id *start_commit_id, struct got_repository *repo,
- const struct got_error *(*cb)(void *, int, int, struct got_object_id *),
- void *arg, got_cancel_cb cancel_cb, void *cancel_arg)
+ got_blame_cb cb, void *arg, got_cancel_cb cancel_cb, void *cancel_arg)
{
const struct got_error *err = NULL;
- struct got_commit_object *start_commit = NULL;
+ struct got_commit_object *start_commit = NULL, *last_commit = NULL;
struct got_object_id *obj_id = NULL;
struct got_blob_object *blob = NULL;
struct got_blame *blame = NULL;
@@ -619,8 +617,12 @@ blame_open(struct got_blame **blamep, const char *path,
if (id && blame->nannotated < blame->nlines) {
/* Annotate remaining non-annotated lines with last commit. */
+ err = got_object_open_as_commit(&last_commit, repo, id);
+ if (err)
+ goto done;
for (lineno = 0; lineno < blame->nlines; lineno++) {
- err = annotate_line(blame, lineno, id, cb, arg);
+ err = annotate_line(blame, lineno, last_commit, id,
+ cb, arg);
if (err)
goto done;
}
@@ -634,6 +636,8 @@ done:
got_object_blob_close(blob);
if (start_commit)
got_object_commit_close(start_commit);
+ if (last_commit)
+ got_object_commit_close(last_commit);
if (err) {
if (blame)
blame_close(blame);
@@ -645,9 +649,8 @@ done:
const struct got_error *
got_blame(const char *path, struct got_object_id *commit_id,
- struct got_repository *repo,
- const struct got_error *(*cb)(void *, int, int, struct got_object_id *),
- void *arg, got_cancel_cb cancel_cb, void* cancel_arg)
+ struct got_repository *repo, got_blame_cb cb, void *arg,
+ got_cancel_cb cancel_cb, void* cancel_arg)
{
const struct got_error *err = NULL, *close_err = NULL;
struct got_blame *blame;
diff --git a/tog/tog.c b/tog/tog.c
index cf64000..1235f3d 100644
--- a/tog/tog.c
+++ b/tog/tog.c
@@ -4162,7 +4162,8 @@ draw_blame(struct tog_view *view)
}
static const struct got_error *
-blame_cb(void *arg, int nlines, int lineno, struct got_object_id *id)
+blame_cb(void *arg, int nlines, int lineno,
+ struct got_commit_object *commit, struct got_object_id *id)
{
const struct got_error *err = NULL;
struct tog_blame_cb_args *a = arg;