]> git.cameronkatri.com Git - cgit.git/blobdiff - shared.c
Add prefix parameter to cgit_diff_tree()
[cgit.git] / shared.c
index 1cd60a2d6b00b97f292b6ee306256358287f95ab..3d4feeac2e415db10405f7f81eac3658f1d17b5b 100644 (file)
--- a/shared.c
+++ b/shared.c
@@ -38,6 +38,7 @@ int cgit_cache_dynamic_ttl     =  5;
 int cgit_cache_static_ttl      = -1;
 int cgit_cache_max_create_time =  5;
 int cgit_summary_log           =  0;
+int cgit_renamelimit           = -1;
 
 int cgit_max_msg_len = 60;
 int cgit_max_repodesc_len = 60;
@@ -108,7 +109,7 @@ struct repoinfo *add_repo(const char *url)
        }
 
        ret = &cgit_repolist.repos[cgit_repolist.count-1];
-       ret->url = xstrdup(url);
+       ret->url = trim_end(url, '/');
        ret->name = ret->url;
        ret->path = NULL;
        ret->desc = NULL;
@@ -151,7 +152,7 @@ void cgit_global_config_cb(const char *name, const char *value)
        else if (!strcmp(name, "module-link"))
                cgit_module_link = xstrdup(value);
        else if (!strcmp(name, "virtual-root"))
-               cgit_virtual_root = xstrdup(value);
+               cgit_virtual_root = trim_end(value, '/');
        else if (!strcmp(name, "nocache"))
                cgit_nocache = atoi(value);
        else if (!strcmp(name, "snapshots"))
@@ -182,6 +183,8 @@ void cgit_global_config_cb(const char *name, const char *value)
                cgit_summary_log = atoi(value);
        else if (!strcmp(name, "agefile"))
                cgit_agefile = xstrdup(value);
+       else if (!strcmp(name, "renamelimit"))
+               cgit_renamelimit = atoi(value);
        else if (!strcmp(name, "repo.group"))
                cgit_repo_group = xstrdup(value);
        else if (!strcmp(name, "repo.url"))
@@ -189,7 +192,7 @@ void cgit_global_config_cb(const char *name, const char *value)
        else if (!strcmp(name, "repo.name"))
                cgit_repo->name = xstrdup(value);
        else if (cgit_repo && !strcmp(name, "repo.path"))
-               cgit_repo->path = xstrdup(value);
+               cgit_repo->path = trim_end(value, '/');
        else if (cgit_repo && !strcmp(name, "repo.desc"))
                cgit_repo->desc = xstrdup(value);
        else if (cgit_repo && !strcmp(name, "repo.owner"))
@@ -308,7 +311,8 @@ static int load_mmfile(mmfile_t *file, const unsigned char *sha1)
                file->ptr = (char *)"";
                file->size = 0;
        } else {
-               file->ptr = read_sha1_file(sha1, &type, &file->size);
+               file->ptr = read_sha1_file(sha1, &type, 
+                                          (unsigned long *)&file->size);
        }
        return 1;
 }
@@ -382,17 +386,25 @@ int cgit_diff_files(const unsigned char *old_sha1,
 
 void cgit_diff_tree(const unsigned char *old_sha1,
                    const unsigned char *new_sha1,
-                   filepair_fn fn)
+                   filepair_fn fn, const char *prefix)
 {
        struct diff_options opt;
        int ret;
+       int prefixlen;
 
        diff_setup(&opt);
        opt.output_format = DIFF_FORMAT_CALLBACK;
        opt.detect_rename = 1;
+       opt.rename_limit = cgit_renamelimit;
        opt.recursive = 1;
        opt.format_callback = cgit_diff_tree_cb;
        opt.format_callback_data = fn;
+       if (prefix) {
+               opt.nr_paths = 1;
+               opt.paths = &prefix;
+               prefixlen = strlen(prefix);
+               opt.pathlens = &prefixlen;
+       }
        diff_setup_done(&opt);
 
        if (old_sha1 && !is_null_sha1(old_sha1))
@@ -409,5 +421,5 @@ void cgit_diff_commit(struct commit *commit, filepair_fn fn)
 
        if (commit->parents)
                old_sha1 = commit->parents->item->object.sha1;
-       cgit_diff_tree(old_sha1, commit->object.sha1, fn);
+       cgit_diff_tree(old_sha1, commit->object.sha1, fn, NULL);
 }