|
diff --git a/shared.c b/shared.c index 6e8f0ce..58837dc 100644 --- a/ shared.c+++ b/ shared.c |
|
@@ -38,48 +38,49 @@ struct cgit_repo *cgit_add_repo(const char *url) |
38 | |
38 | |
39 | if (++cgit_repolist.count > cgit_repolist.length) { |
39 | if (++cgit_repolist.count > cgit_repolist.length) { |
40 | if (cgit_repolist.length == 0) |
40 | if (cgit_repolist.length == 0) |
41 | cgit_repolist.length = 8; |
41 | cgit_repolist.length = 8; |
42 | else |
42 | else |
43 | cgit_repolist.length *= 2; |
43 | cgit_repolist.length *= 2; |
44 | cgit_repolist.repos = xrealloc(cgit_repolist.repos, |
44 | cgit_repolist.repos = xrealloc(cgit_repolist.repos, |
45 | cgit_repolist.length * |
45 | cgit_repolist.length * |
46 | sizeof(struct cgit_repo)); |
46 | sizeof(struct cgit_repo)); |
47 | } |
47 | } |
48 | |
48 | |
49 | ret = &cgit_repolist.repos[cgit_repolist.count-1]; |
49 | ret = &cgit_repolist.repos[cgit_repolist.count-1]; |
50 | memset(ret, 0, sizeof(struct cgit_repo)); |
50 | memset(ret, 0, sizeof(struct cgit_repo)); |
51 | ret->url = trim_end(url, '/'); |
51 | ret->url = trim_end(url, '/'); |
52 | ret->name = ret->url; |
52 | ret->name = ret->url; |
53 | ret->path = NULL; |
53 | ret->path = NULL; |
54 | ret->desc = "[no description]"; |
54 | ret->desc = "[no description]"; |
55 | ret->owner = NULL; |
55 | ret->owner = NULL; |
56 | ret->section = ctx.cfg.section; |
56 | ret->section = ctx.cfg.section; |
57 | ret->defbranch = "master"; |
57 | ret->defbranch = "master"; |
58 | ret->snapshots = ctx.cfg.snapshots; |
58 | ret->snapshots = ctx.cfg.snapshots; |
59 | ret->enable_log_filecount = ctx.cfg.enable_log_filecount; |
59 | ret->enable_log_filecount = ctx.cfg.enable_log_filecount; |
60 | ret->enable_log_linecount = ctx.cfg.enable_log_linecount; |
60 | ret->enable_log_linecount = ctx.cfg.enable_log_linecount; |
61 | ret->enable_remote_branches = ctx.cfg.enable_remote_branches; |
61 | ret->enable_remote_branches = ctx.cfg.enable_remote_branches; |
| |
62 | ret->enable_subject_links = ctx.cfg.enable_subject_links; |
62 | ret->max_stats = ctx.cfg.max_stats; |
63 | ret->max_stats = ctx.cfg.max_stats; |
63 | ret->module_link = ctx.cfg.module_link; |
64 | ret->module_link = ctx.cfg.module_link; |
64 | ret->readme = NULL; |
65 | ret->readme = NULL; |
65 | ret->mtime = -1; |
66 | ret->mtime = -1; |
66 | ret->about_filter = ctx.cfg.about_filter; |
67 | ret->about_filter = ctx.cfg.about_filter; |
67 | ret->commit_filter = ctx.cfg.commit_filter; |
68 | ret->commit_filter = ctx.cfg.commit_filter; |
68 | ret->source_filter = ctx.cfg.source_filter; |
69 | ret->source_filter = ctx.cfg.source_filter; |
69 | return ret; |
70 | return ret; |
70 | } |
71 | } |
71 | |
72 | |
72 | struct cgit_repo *cgit_get_repoinfo(const char *url) |
73 | struct cgit_repo *cgit_get_repoinfo(const char *url) |
73 | { |
74 | { |
74 | int i; |
75 | int i; |
75 | struct cgit_repo *repo; |
76 | struct cgit_repo *repo; |
76 | |
77 | |
77 | for (i=0; i<cgit_repolist.count; i++) { |
78 | for (i=0; i<cgit_repolist.count; i++) { |
78 | repo = &cgit_repolist.repos[i]; |
79 | repo = &cgit_repolist.repos[i]; |
79 | if (!strcmp(repo->url, url)) |
80 | if (!strcmp(repo->url, url)) |
80 | return repo; |
81 | return repo; |
81 | } |
82 | } |
82 | return NULL; |
83 | return NULL; |
83 | } |
84 | } |
84 | |
85 | |
85 | void *cgit_free_commitinfo(struct commitinfo *info) |
86 | void *cgit_free_commitinfo(struct commitinfo *info) |
@@ -257,60 +258,68 @@ int filediff_cb(void *priv, mmbuffer_t *mb, int nbuf) |
257 | diffbuf = NULL; |
258 | diffbuf = NULL; |
258 | buflen = 0; |
259 | buflen = 0; |
259 | } |
260 | } |
260 | return 0; |
261 | return 0; |
261 | } |
262 | } |
262 | |
263 | |
263 | int cgit_diff_files(const unsigned char *old_sha1, |
264 | int cgit_diff_files(const unsigned char *old_sha1, |
264 | const unsigned char *new_sha1, unsigned long *old_size, |
265 | const unsigned char *new_sha1, unsigned long *old_size, |
265 | unsigned long *new_size, int *binary, linediff_fn fn) |
266 | unsigned long *new_size, int *binary, linediff_fn fn) |
266 | { |
267 | { |
267 | mmfile_t file1, file2; |
268 | mmfile_t file1, file2; |
268 | xpparam_t diff_params; |
269 | xpparam_t diff_params; |
269 | xdemitconf_t emit_params; |
270 | xdemitconf_t emit_params; |
270 | xdemitcb_t emit_cb; |
271 | xdemitcb_t emit_cb; |
271 | |
272 | |
272 | if (!load_mmfile(&file1, old_sha1) || !load_mmfile(&file2, new_sha1)) |
273 | if (!load_mmfile(&file1, old_sha1) || !load_mmfile(&file2, new_sha1)) |
273 | return 1; |
274 | return 1; |
274 | |
275 | |
275 | *old_size = file1.size; |
276 | *old_size = file1.size; |
276 | *new_size = file2.size; |
277 | *new_size = file2.size; |
277 | |
278 | |
278 | if ((file1.ptr && buffer_is_binary(file1.ptr, file1.size)) || |
279 | if ((file1.ptr && buffer_is_binary(file1.ptr, file1.size)) || |
279 | (file2.ptr && buffer_is_binary(file2.ptr, file2.size))) { |
280 | (file2.ptr && buffer_is_binary(file2.ptr, file2.size))) { |
280 | *binary = 1; |
281 | *binary = 1; |
| |
282 | if (file1.size) |
| |
283 | free(file1.ptr); |
| |
284 | if (file2.size) |
| |
285 | free(file2.ptr); |
281 | return 0; |
286 | return 0; |
282 | } |
287 | } |
283 | |
288 | |
284 | memset(&diff_params, 0, sizeof(diff_params)); |
289 | memset(&diff_params, 0, sizeof(diff_params)); |
285 | memset(&emit_params, 0, sizeof(emit_params)); |
290 | memset(&emit_params, 0, sizeof(emit_params)); |
286 | memset(&emit_cb, 0, sizeof(emit_cb)); |
291 | memset(&emit_cb, 0, sizeof(emit_cb)); |
287 | diff_params.flags = XDF_NEED_MINIMAL; |
292 | diff_params.flags = XDF_NEED_MINIMAL; |
288 | emit_params.ctxlen = 3; |
293 | emit_params.ctxlen = 3; |
289 | emit_params.flags = XDL_EMIT_FUNCNAMES; |
294 | emit_params.flags = XDL_EMIT_FUNCNAMES; |
290 | emit_cb.outf = filediff_cb; |
295 | emit_cb.outf = filediff_cb; |
291 | emit_cb.priv = fn; |
296 | emit_cb.priv = fn; |
292 | xdl_diff(&file1, &file2, &diff_params, &emit_params, &emit_cb); |
297 | xdl_diff(&file1, &file2, &diff_params, &emit_params, &emit_cb); |
| |
298 | if (file1.size) |
| |
299 | free(file1.ptr); |
| |
300 | if (file2.size) |
| |
301 | free(file2.ptr); |
293 | return 0; |
302 | return 0; |
294 | } |
303 | } |
295 | |
304 | |
296 | void cgit_diff_tree(const unsigned char *old_sha1, |
305 | void cgit_diff_tree(const unsigned char *old_sha1, |
297 | const unsigned char *new_sha1, |
306 | const unsigned char *new_sha1, |
298 | filepair_fn fn, const char *prefix) |
307 | filepair_fn fn, const char *prefix) |
299 | { |
308 | { |
300 | struct diff_options opt; |
309 | struct diff_options opt; |
301 | int ret; |
310 | int ret; |
302 | int prefixlen; |
311 | int prefixlen; |
303 | |
312 | |
304 | diff_setup(&opt); |
313 | diff_setup(&opt); |
305 | opt.output_format = DIFF_FORMAT_CALLBACK; |
314 | opt.output_format = DIFF_FORMAT_CALLBACK; |
306 | opt.detect_rename = 1; |
315 | opt.detect_rename = 1; |
307 | opt.rename_limit = ctx.cfg.renamelimit; |
316 | opt.rename_limit = ctx.cfg.renamelimit; |
308 | DIFF_OPT_SET(&opt, RECURSIVE); |
317 | DIFF_OPT_SET(&opt, RECURSIVE); |
309 | opt.format_callback = cgit_diff_tree_cb; |
318 | opt.format_callback = cgit_diff_tree_cb; |
310 | opt.format_callback_data = fn; |
319 | opt.format_callback_data = fn; |
311 | if (prefix) { |
320 | if (prefix) { |
312 | opt.nr_paths = 1; |
321 | opt.nr_paths = 1; |
313 | opt.paths = &prefix; |
322 | opt.paths = &prefix; |
314 | prefixlen = strlen(prefix); |
323 | prefixlen = strlen(prefix); |
315 | opt.pathlens = &prefixlen; |
324 | opt.pathlens = &prefixlen; |
316 | } |
325 | } |
|