Blame


1 404c43c4 2018-06-21 stsp /*
2 5aa81393 2020-01-06 stsp * Copyright (c) 2018, 2019, 2020 Stefan Sperling <stsp@openbsd.org>
3 404c43c4 2018-06-21 stsp *
4 404c43c4 2018-06-21 stsp * Permission to use, copy, modify, and distribute this software for any
5 404c43c4 2018-06-21 stsp * purpose with or without fee is hereby granted, provided that the above
6 404c43c4 2018-06-21 stsp * copyright notice and this permission notice appear in all copies.
7 404c43c4 2018-06-21 stsp *
8 404c43c4 2018-06-21 stsp * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 404c43c4 2018-06-21 stsp * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 404c43c4 2018-06-21 stsp * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 404c43c4 2018-06-21 stsp * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 404c43c4 2018-06-21 stsp * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 404c43c4 2018-06-21 stsp * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 404c43c4 2018-06-21 stsp * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 404c43c4 2018-06-21 stsp */
16 404c43c4 2018-06-21 stsp
17 404c43c4 2018-06-21 stsp #include <sys/queue.h>
18 fe621944 2020-11-10 stsp #include <sys/mman.h>
19 404c43c4 2018-06-21 stsp #include <sys/stat.h>
20 404c43c4 2018-06-21 stsp
21 404c43c4 2018-06-21 stsp #include <sha1.h>
22 404c43c4 2018-06-21 stsp #include <string.h>
23 fe621944 2020-11-10 stsp #include <stdbool.h>
24 404c43c4 2018-06-21 stsp #include <stdio.h>
25 404c43c4 2018-06-21 stsp #include <stdlib.h>
26 404c43c4 2018-06-21 stsp #include <time.h>
27 56e0773d 2019-11-28 stsp #include <limits.h>
28 404c43c4 2018-06-21 stsp #include <util.h>
29 404c43c4 2018-06-21 stsp #include <zlib.h>
30 404c43c4 2018-06-21 stsp
31 404c43c4 2018-06-21 stsp #include "got_error.h"
32 404c43c4 2018-06-21 stsp #include "got_object.h"
33 6fb7cd11 2019-08-22 stsp #include "got_cancel.h"
34 404c43c4 2018-06-21 stsp #include "got_blame.h"
35 6fb7cd11 2019-08-22 stsp #include "got_commit_graph.h"
36 404c43c4 2018-06-21 stsp #include "got_opentemp.h"
37 404c43c4 2018-06-21 stsp
38 63581804 2018-07-09 stsp #include "got_lib_inflate.h"
39 404c43c4 2018-06-21 stsp #include "got_lib_delta.h"
40 404c43c4 2018-06-21 stsp #include "got_lib_object.h"
41 404c43c4 2018-06-21 stsp #include "got_lib_diff.h"
42 404c43c4 2018-06-21 stsp
43 fe621944 2020-11-10 stsp #ifndef MAX
44 fe621944 2020-11-10 stsp #define MAX(_a,_b) ((_a) > (_b) ? (_a) : (_b))
45 fe621944 2020-11-10 stsp #endif
46 fe621944 2020-11-10 stsp
47 404c43c4 2018-06-21 stsp struct got_blame_line {
48 404c43c4 2018-06-21 stsp int annotated;
49 9b94757a 2018-06-21 stsp struct got_object_id id;
50 404c43c4 2018-06-21 stsp };
51 404c43c4 2018-06-21 stsp
52 404c43c4 2018-06-21 stsp struct got_blame {
53 404c43c4 2018-06-21 stsp FILE *f;
54 fe621944 2020-11-10 stsp char *map;
55 fe621944 2020-11-10 stsp struct diff_data left_data;
56 fe621944 2020-11-10 stsp struct diff_data right_data;
57 fe621944 2020-11-10 stsp const struct diff_config *cfg;
58 6c4c42e0 2019-06-24 stsp size_t filesize;
59 6fcac457 2018-11-19 stsp int nlines;
60 06ca4d09 2018-11-19 stsp int nannotated;
61 404c43c4 2018-06-21 stsp struct got_blame_line *lines; /* one per line */
62 6c4c42e0 2019-06-24 stsp off_t *line_offsets; /* one per line */
63 c35a7943 2018-07-12 stsp int ncommits;
64 404c43c4 2018-06-21 stsp };
65 404c43c4 2018-06-21 stsp
66 404c43c4 2018-06-21 stsp static const struct got_error *
67 84451b3e 2018-07-10 stsp annotate_line(struct got_blame *blame, int lineno, struct got_object_id *id,
68 84451b3e 2018-07-10 stsp const struct got_error *(*cb)(void *, int, int, struct got_object_id *),
69 84451b3e 2018-07-10 stsp void *arg)
70 404c43c4 2018-06-21 stsp {
71 404c43c4 2018-06-21 stsp const struct got_error *err = NULL;
72 404c43c4 2018-06-21 stsp struct got_blame_line *line;
73 404c43c4 2018-06-21 stsp
74 404c43c4 2018-06-21 stsp if (lineno < 1 || lineno > blame->nlines)
75 f2e233d8 2018-11-19 stsp return NULL;
76 3168e5da 2020-09-10 stsp
77 404c43c4 2018-06-21 stsp line = &blame->lines[lineno - 1];
78 404c43c4 2018-06-21 stsp if (line->annotated)
79 84451b3e 2018-07-10 stsp return NULL;
80 404c43c4 2018-06-21 stsp
81 404c43c4 2018-06-21 stsp memcpy(&line->id, id, sizeof(line->id));
82 404c43c4 2018-06-21 stsp line->annotated = 1;
83 06ca4d09 2018-11-19 stsp blame->nannotated++;
84 84451b3e 2018-07-10 stsp if (cb)
85 84451b3e 2018-07-10 stsp err = cb(arg, blame->nlines, lineno, id);
86 84451b3e 2018-07-10 stsp return err;
87 404c43c4 2018-06-21 stsp }
88 404c43c4 2018-06-21 stsp
89 404c43c4 2018-06-21 stsp static const struct got_error *
90 fe621944 2020-11-10 stsp blame_changes(struct got_blame *blame, struct diff_result *diff_result,
91 c35a7943 2018-07-12 stsp struct got_object_id *commit_id,
92 c35a7943 2018-07-12 stsp const struct got_error *(*cb)(void *, int, int, struct got_object_id *),
93 c35a7943 2018-07-12 stsp void *arg)
94 c35a7943 2018-07-12 stsp {
95 c35a7943 2018-07-12 stsp const struct got_error *err = NULL;
96 fe621944 2020-11-10 stsp int i;
97 c35a7943 2018-07-12 stsp
98 fe621944 2020-11-10 stsp for (i = 0; i < diff_result->chunks.len; i++) {
99 fe621944 2020-11-10 stsp struct diff_chunk *c = diff_chunk_get(diff_result, i);
100 fe621944 2020-11-10 stsp unsigned int right_start, right_count;
101 fe621944 2020-11-10 stsp int lineno, len;
102 c35a7943 2018-07-12 stsp int ln;
103 c35a7943 2018-07-12 stsp
104 fe621944 2020-11-10 stsp if (diff_chunk_get_left_count(c) != 0)
105 fe621944 2020-11-10 stsp continue;
106 fe621944 2020-11-10 stsp
107 fe621944 2020-11-10 stsp len = diff_chunk_get_right_count(c);
108 fe621944 2020-11-10 stsp if (len == 0)
109 fe621944 2020-11-10 stsp continue;
110 fe621944 2020-11-10 stsp
111 fe621944 2020-11-10 stsp right_start = diff_chunk_get_right_start(c, diff_result, 0);
112 fe621944 2020-11-10 stsp right_count = diff_chunk_get_right_count(c);
113 fe621944 2020-11-10 stsp
114 fe621944 2020-11-10 stsp lineno = right_start + 1;
115 fe621944 2020-11-10 stsp len = right_count;
116 fe621944 2020-11-10 stsp for (ln = lineno; ln < lineno + len; ln++) {
117 4c9641fd 2019-08-21 stsp err = annotate_line(blame, ln, commit_id, cb, arg);
118 c35a7943 2018-07-12 stsp if (err)
119 c35a7943 2018-07-12 stsp return err;
120 06ca4d09 2018-11-19 stsp if (blame->nlines == blame->nannotated)
121 4c9641fd 2019-08-21 stsp break;
122 c35a7943 2018-07-12 stsp }
123 c35a7943 2018-07-12 stsp }
124 c35a7943 2018-07-12 stsp
125 c35a7943 2018-07-12 stsp return NULL;
126 c35a7943 2018-07-12 stsp }
127 c35a7943 2018-07-12 stsp
128 c35a7943 2018-07-12 stsp static const struct got_error *
129 4c9641fd 2019-08-21 stsp blame_commit(struct got_blame *blame, struct got_object_id *parent_id,
130 4c9641fd 2019-08-21 stsp struct got_object_id *id, const char *path, struct got_repository *repo,
131 84451b3e 2018-07-10 stsp const struct got_error *(*cb)(void *, int, int, struct got_object_id *),
132 84451b3e 2018-07-10 stsp void *arg)
133 404c43c4 2018-06-21 stsp {
134 404c43c4 2018-06-21 stsp const struct got_error *err = NULL;
135 d0275cf7 2019-08-21 stsp struct got_object *obj = NULL;
136 4c9641fd 2019-08-21 stsp struct got_object_id *obj_id = NULL;
137 8d725ae1 2019-08-18 stsp struct got_commit_object *commit = NULL;
138 4c9641fd 2019-08-21 stsp struct got_blob_object *blob = NULL;
139 fe621944 2020-11-10 stsp struct got_diffreg_result *diffreg_result = NULL;
140 404c43c4 2018-06-21 stsp
141 4c9641fd 2019-08-21 stsp err = got_object_open_as_commit(&commit, repo, parent_id);
142 8d725ae1 2019-08-18 stsp if (err)
143 8d725ae1 2019-08-18 stsp return err;
144 8d725ae1 2019-08-18 stsp
145 4c9641fd 2019-08-21 stsp err = got_object_id_by_path(&obj_id, repo, parent_id, path);
146 4c9641fd 2019-08-21 stsp if (err) {
147 4c9641fd 2019-08-21 stsp if (err->code == GOT_ERR_NO_TREE_ENTRY)
148 4c9641fd 2019-08-21 stsp err = NULL;
149 404c43c4 2018-06-21 stsp goto done;
150 4c9641fd 2019-08-21 stsp }
151 27d434c2 2018-09-15 stsp
152 27d434c2 2018-09-15 stsp err = got_object_open(&obj, repo, obj_id);
153 27d434c2 2018-09-15 stsp if (err)
154 27d434c2 2018-09-15 stsp goto done;
155 27d434c2 2018-09-15 stsp
156 15a94983 2018-12-23 stsp if (obj->type != GOT_OBJ_TYPE_BLOB) {
157 2c2d5c5f 2020-06-07 stsp err = got_error_path(path, GOT_ERR_OBJ_TYPE);
158 404c43c4 2018-06-21 stsp goto done;
159 404c43c4 2018-06-21 stsp }
160 404c43c4 2018-06-21 stsp
161 404c43c4 2018-06-21 stsp err = got_object_blob_open(&blob, repo, obj, 8192);
162 404c43c4 2018-06-21 stsp if (err)
163 404c43c4 2018-06-21 stsp goto done;
164 404c43c4 2018-06-21 stsp
165 4c9641fd 2019-08-21 stsp if (fseek(blame->f, 0L, SEEK_SET) == -1) {
166 4c9641fd 2019-08-21 stsp err = got_ferror(blame->f, GOT_ERR_IO);
167 4c9641fd 2019-08-21 stsp goto done;
168 4c9641fd 2019-08-21 stsp }
169 4c9641fd 2019-08-21 stsp
170 fe621944 2020-11-10 stsp diff_data_free(&blame->left_data);
171 fe621944 2020-11-10 stsp memset(&blame->left_data, 0, sizeof(blame->left_data));
172 fe621944 2020-11-10 stsp err = got_diff_blob_prepared_file(&diffreg_result, &blame->left_data,
173 fe621944 2020-11-10 stsp blob, &blame->right_data, blame->f, blame->map, blame->filesize,
174 fe621944 2020-11-10 stsp blame->cfg, 0);
175 404c43c4 2018-06-21 stsp if (err)
176 404c43c4 2018-06-21 stsp goto done;
177 404c43c4 2018-06-21 stsp
178 fe621944 2020-11-10 stsp if (diffreg_result->result->chunks.len > 0) {
179 fe621944 2020-11-10 stsp err = blame_changes(blame, diffreg_result->result, id, cb, arg);
180 d68a0a7d 2018-07-10 stsp } else if (cb)
181 3bf198ba 2018-07-10 stsp err = cb(arg, blame->nlines, -1, id);
182 404c43c4 2018-06-21 stsp done:
183 fe621944 2020-11-10 stsp if (diffreg_result) {
184 fe621944 2020-11-10 stsp const struct got_error *free_err;
185 fe621944 2020-11-10 stsp free_err = got_diffreg_result_free_left(diffreg_result);
186 fe621944 2020-11-10 stsp if (free_err && err == NULL)
187 fe621944 2020-11-10 stsp err = free_err;
188 fe621944 2020-11-10 stsp }
189 8d725ae1 2019-08-18 stsp if (commit)
190 8d725ae1 2019-08-18 stsp got_object_commit_close(commit);
191 27d434c2 2018-09-15 stsp free(obj_id);
192 404c43c4 2018-06-21 stsp if (obj)
193 404c43c4 2018-06-21 stsp got_object_close(obj);
194 404c43c4 2018-06-21 stsp if (blob)
195 404c43c4 2018-06-21 stsp got_object_blob_close(blob);
196 404c43c4 2018-06-21 stsp return err;
197 404c43c4 2018-06-21 stsp }
198 404c43c4 2018-06-21 stsp
199 fb43ecf1 2019-02-11 stsp static const struct got_error *
200 404c43c4 2018-06-21 stsp blame_close(struct got_blame *blame)
201 404c43c4 2018-06-21 stsp {
202 fb43ecf1 2019-02-11 stsp const struct got_error *err = NULL;
203 c35a7943 2018-07-12 stsp
204 fe621944 2020-11-10 stsp diff_data_free(&blame->left_data);
205 fe621944 2020-11-10 stsp diff_data_free(&blame->right_data);
206 fe621944 2020-11-10 stsp if (blame->map && munmap(blame->map, blame->filesize) == -1)
207 fe621944 2020-11-10 stsp err = got_error_from_errno("munmap");
208 fe621944 2020-11-10 stsp if (blame->f && fclose(blame->f) != 0 && err == NULL)
209 638f9024 2019-05-13 stsp err = got_error_from_errno("fclose");
210 404c43c4 2018-06-21 stsp free(blame->lines);
211 404c43c4 2018-06-21 stsp free(blame);
212 fb43ecf1 2019-02-11 stsp return err;
213 404c43c4 2018-06-21 stsp }
214 404c43c4 2018-06-21 stsp
215 404c43c4 2018-06-21 stsp static const struct got_error *
216 404c43c4 2018-06-21 stsp blame_open(struct got_blame **blamep, const char *path,
217 84451b3e 2018-07-10 stsp struct got_object_id *start_commit_id, struct got_repository *repo,
218 84451b3e 2018-07-10 stsp const struct got_error *(*cb)(void *, int, int, struct got_object_id *),
219 6fb7cd11 2019-08-22 stsp void *arg, got_cancel_cb cancel_cb, void *cancel_arg)
220 404c43c4 2018-06-21 stsp {
221 404c43c4 2018-06-21 stsp const struct got_error *err = NULL;
222 404c43c4 2018-06-21 stsp struct got_object *obj = NULL;
223 27d434c2 2018-09-15 stsp struct got_object_id *obj_id = NULL;
224 404c43c4 2018-06-21 stsp struct got_blob_object *blob = NULL;
225 404c43c4 2018-06-21 stsp struct got_blame *blame = NULL;
226 4c9641fd 2019-08-21 stsp struct got_object_id *id = NULL, *pid = NULL;
227 fe621944 2020-11-10 stsp int lineno, created;
228 fe621944 2020-11-10 stsp size_t size;
229 293f6400 2018-09-20 stsp struct got_commit_graph *graph = NULL;
230 404c43c4 2018-06-21 stsp
231 404c43c4 2018-06-21 stsp *blamep = NULL;
232 404c43c4 2018-06-21 stsp
233 27d434c2 2018-09-15 stsp err = got_object_id_by_path(&obj_id, repo, start_commit_id, path);
234 404c43c4 2018-06-21 stsp if (err)
235 404c43c4 2018-06-21 stsp return err;
236 27d434c2 2018-09-15 stsp
237 27d434c2 2018-09-15 stsp err = got_object_open(&obj, repo, obj_id);
238 27d434c2 2018-09-15 stsp if (err)
239 27d434c2 2018-09-15 stsp goto done;
240 27d434c2 2018-09-15 stsp
241 15a94983 2018-12-23 stsp if (obj->type != GOT_OBJ_TYPE_BLOB) {
242 2c2d5c5f 2020-06-07 stsp err = got_error_path(path, GOT_ERR_OBJ_TYPE);
243 404c43c4 2018-06-21 stsp goto done;
244 404c43c4 2018-06-21 stsp }
245 404c43c4 2018-06-21 stsp
246 404c43c4 2018-06-21 stsp err = got_object_blob_open(&blob, repo, obj, 8192);
247 404c43c4 2018-06-21 stsp if (err)
248 404c43c4 2018-06-21 stsp goto done;
249 404c43c4 2018-06-21 stsp
250 404c43c4 2018-06-21 stsp blame = calloc(1, sizeof(*blame));
251 404c43c4 2018-06-21 stsp if (blame == NULL)
252 638f9024 2019-05-13 stsp return got_error_from_errno("calloc");
253 404c43c4 2018-06-21 stsp
254 404c43c4 2018-06-21 stsp blame->f = got_opentemp();
255 404c43c4 2018-06-21 stsp if (blame->f == NULL) {
256 638f9024 2019-05-13 stsp err = got_error_from_errno("got_opentemp");
257 404c43c4 2018-06-21 stsp goto done;
258 404c43c4 2018-06-21 stsp }
259 6c4c42e0 2019-06-24 stsp err = got_object_blob_dump_to_file(&blame->filesize, &blame->nlines,
260 62d463ca 2020-10-20 naddy &blame->line_offsets, blame->f, blob);
261 b02560ec 2019-08-19 stsp if (err || blame->nlines == 0)
262 404c43c4 2018-06-21 stsp goto done;
263 b02560ec 2019-08-19 stsp
264 fe621944 2020-11-10 stsp blame->cfg = got_diff_get_config(GOT_DIFF_ALGORITHM_PATIENCE),
265 fe621944 2020-11-10 stsp err = got_diff_prepare_file(&blame->f, &blame->map, &created, &size,
266 fe621944 2020-11-10 stsp &blame->right_data, blame->cfg, 0);
267 fe621944 2020-11-10 stsp if (err)
268 fe621944 2020-11-10 stsp goto done;
269 fe621944 2020-11-10 stsp
270 b02560ec 2019-08-19 stsp /* Don't include \n at EOF in the blame line count. */
271 b02560ec 2019-08-19 stsp if (blame->line_offsets[blame->nlines - 1] == blame->filesize)
272 b02560ec 2019-08-19 stsp blame->nlines--;
273 404c43c4 2018-06-21 stsp
274 404c43c4 2018-06-21 stsp blame->lines = calloc(blame->nlines, sizeof(*blame->lines));
275 404c43c4 2018-06-21 stsp if (blame->lines == NULL) {
276 638f9024 2019-05-13 stsp err = got_error_from_errno("calloc");
277 404c43c4 2018-06-21 stsp goto done;
278 404c43c4 2018-06-21 stsp }
279 404c43c4 2018-06-21 stsp
280 3d509237 2020-01-04 stsp err = got_commit_graph_open(&graph, path, 1);
281 404c43c4 2018-06-21 stsp if (err)
282 293f6400 2018-09-20 stsp return err;
283 6fb7cd11 2019-08-22 stsp err = got_commit_graph_iter_start(graph, start_commit_id, repo,
284 6fb7cd11 2019-08-22 stsp cancel_cb, cancel_arg);
285 293f6400 2018-09-20 stsp if (err)
286 404c43c4 2018-06-21 stsp goto done;
287 4c9641fd 2019-08-21 stsp id = start_commit_id;
288 656b1f76 2019-05-11 jcs for (;;) {
289 ee780d5c 2020-01-04 stsp err = got_commit_graph_iter_next(&pid, graph, repo,
290 ee780d5c 2020-01-04 stsp cancel_cb, cancel_arg);
291 404c43c4 2018-06-21 stsp if (err) {
292 ee780d5c 2020-01-04 stsp if (err->code == GOT_ERR_ITER_COMPLETED)
293 4c9641fd 2019-08-21 stsp err = NULL;
294 ee780d5c 2020-01-04 stsp break;
295 293f6400 2018-09-20 stsp }
296 4c9641fd 2019-08-21 stsp if (pid) {
297 4c9641fd 2019-08-21 stsp err = blame_commit(blame, pid, id, path, repo, cb, arg);
298 293f6400 2018-09-20 stsp if (err) {
299 293f6400 2018-09-20 stsp if (err->code == GOT_ERR_ITER_COMPLETED)
300 293f6400 2018-09-20 stsp err = NULL;
301 293f6400 2018-09-20 stsp break;
302 293f6400 2018-09-20 stsp }
303 06ca4d09 2018-11-19 stsp if (blame->nannotated == blame->nlines)
304 06ca4d09 2018-11-19 stsp break;
305 404c43c4 2018-06-21 stsp }
306 4c9641fd 2019-08-21 stsp id = pid;
307 293f6400 2018-09-20 stsp }
308 ed77f2ae 2018-06-21 stsp
309 06ca4d09 2018-11-19 stsp if (id && blame->nannotated < blame->nlines) {
310 293f6400 2018-09-20 stsp /* Annotate remaining non-annotated lines with last commit. */
311 293f6400 2018-09-20 stsp for (lineno = 1; lineno <= blame->nlines; lineno++) {
312 293f6400 2018-09-20 stsp err = annotate_line(blame, lineno, id, cb, arg);
313 293f6400 2018-09-20 stsp if (err)
314 293f6400 2018-09-20 stsp goto done;
315 404c43c4 2018-06-21 stsp }
316 404c43c4 2018-06-21 stsp }
317 404c43c4 2018-06-21 stsp
318 404c43c4 2018-06-21 stsp done:
319 293f6400 2018-09-20 stsp if (graph)
320 293f6400 2018-09-20 stsp got_commit_graph_close(graph);
321 27d434c2 2018-09-15 stsp free(obj_id);
322 404c43c4 2018-06-21 stsp if (obj)
323 404c43c4 2018-06-21 stsp got_object_close(obj);
324 404c43c4 2018-06-21 stsp if (blob)
325 404c43c4 2018-06-21 stsp got_object_blob_close(blob);
326 1828273a 2018-07-09 stsp if (err) {
327 1828273a 2018-07-09 stsp if (blame)
328 1828273a 2018-07-09 stsp blame_close(blame);
329 1828273a 2018-07-09 stsp } else
330 404c43c4 2018-06-21 stsp *blamep = blame;
331 404c43c4 2018-06-21 stsp
332 404c43c4 2018-06-21 stsp return err;
333 404c43c4 2018-06-21 stsp }
334 84451b3e 2018-07-10 stsp
335 84451b3e 2018-07-10 stsp const struct got_error *
336 0d8ff7d5 2019-08-14 stsp got_blame(const char *path, struct got_object_id *commit_id,
337 84451b3e 2018-07-10 stsp struct got_repository *repo,
338 84451b3e 2018-07-10 stsp const struct got_error *(*cb)(void *, int, int, struct got_object_id *),
339 6fb7cd11 2019-08-22 stsp void *arg, got_cancel_cb cancel_cb, void* cancel_arg)
340 84451b3e 2018-07-10 stsp {
341 fb43ecf1 2019-02-11 stsp const struct got_error *err = NULL, *close_err = NULL;
342 84451b3e 2018-07-10 stsp struct got_blame *blame;
343 84451b3e 2018-07-10 stsp char *abspath;
344 84451b3e 2018-07-10 stsp
345 84451b3e 2018-07-10 stsp if (asprintf(&abspath, "%s%s", path[0] == '/' ? "" : "/", path) == -1)
346 638f9024 2019-05-13 stsp return got_error_from_errno2("asprintf", path);
347 84451b3e 2018-07-10 stsp
348 6fb7cd11 2019-08-22 stsp err = blame_open(&blame, abspath, commit_id, repo, cb, arg,
349 6fb7cd11 2019-08-22 stsp cancel_cb, cancel_arg);
350 84451b3e 2018-07-10 stsp free(abspath);
351 26206841 2018-07-12 stsp if (blame)
352 fb43ecf1 2019-02-11 stsp close_err = blame_close(blame);
353 fb43ecf1 2019-02-11 stsp return err ? err : close_err;
354 84451b3e 2018-07-10 stsp }