]> gitweb.ps.run Git - ps-cgit/blobdiff - shared.c
Use reflist to print branch info
[ps-cgit] / shared.c
index 077934f7ad7a51359d64d92407647232e83904f2..d815cb1c5b9e47522e160926f80f9b23b7b54bce 100644 (file)
--- a/shared.c
+++ b/shared.c
@@ -23,7 +23,7 @@ char *cgit_module_link  = "./?repo=%s&page=commit&id=%s";
 char *cgit_agefile      = "info/web/last-modified";
 char *cgit_virtual_root = NULL;
 char *cgit_script_name  = CGIT_SCRIPT_NAME;
-char *cgit_cache_root   = "/var/cache/cgit";
+char *cgit_cache_root   = CGIT_CACHE_ROOT;
 char *cgit_repo_group   = NULL;
 
 int cgit_nocache               =  0;
@@ -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"))
@@ -288,6 +291,47 @@ char *trim_end(const char *str, char c)
        return s;
 }
 
+void cgit_add_ref(struct reflist *list, struct refinfo *ref)
+{
+       size_t size;
+
+       if (list->count >= list->alloc) {
+               list->alloc += (list->alloc ? list->alloc : 4);
+               size = list->alloc * sizeof(struct refinfo *);
+               list->refs = xrealloc(list->refs, size);
+       }
+       list->refs[list->count++] = ref;
+}
+
+struct refinfo *cgit_mk_refinfo(const char *refname, const unsigned char *sha1)
+{
+       struct refinfo *ref;
+
+       ref = xmalloc(sizeof (struct refinfo));
+       ref->refname = xstrdup(refname);
+       ref->object = parse_object(sha1);
+       switch (ref->object->type) {
+       case OBJ_TAG:
+               ref->tag = cgit_parse_tag((struct tag *)ref->object);
+               break;
+       case OBJ_COMMIT:
+               ref->commit = cgit_parse_commit((struct commit *)ref->object);
+               break;
+       }
+       return ref;
+}
+
+int cgit_refs_cb(const char *refname, const unsigned char *sha1, int flags,
+                 void *cb_data)
+{
+       struct reflist *list = (struct reflist *)cb_data;
+       struct refinfo *info = cgit_mk_refinfo(refname, sha1);
+
+       if (info)
+               cgit_add_ref(list, info);
+       return 0;
+}
+
 void cgit_diff_tree_cb(struct diff_queue_struct *q,
                       struct diff_options *options, void *data)
 {
@@ -308,7 +352,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;
 }
@@ -373,6 +418,7 @@ int cgit_diff_files(const unsigned char *old_sha1,
        diff_params.flags = XDF_NEED_MINIMAL;
        emit_params.ctxlen = 3;
        emit_params.flags = XDL_EMIT_FUNCNAMES;
+       emit_params.find_func = NULL;
        emit_cb.outf = filediff_cb;
        emit_cb.priv = fn;
        xdl_diff(&file1, &file2, &diff_params, &emit_params, &emit_cb);
@@ -381,17 +427,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))
@@ -408,5 +462,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);
 }