int chk_non_negative(int result, char *msg)
{
- if (result < 0)
- die("%s: %s",msg, strerror(errno));
+ if (result < 0)
+ die("%s: %s", msg, strerror(errno));
return result;
}
+char *cgit_default_repo_desc = "[no description]";
struct cgit_repo *cgit_add_repo(const char *url)
{
struct cgit_repo *ret;
ret->url = trim_end(url, '/');
ret->name = ret->url;
ret->path = NULL;
- ret->desc = "[no description]";
+ ret->desc = cgit_default_repo_desc;
ret->owner = NULL;
ret->section = ctx.cfg.section;
ret->snapshots = ctx.cfg.snapshots;
ret->enable_remote_branches = ctx.cfg.enable_remote_branches;
ret->enable_subject_links = ctx.cfg.enable_subject_links;
ret->max_stats = ctx.cfg.max_stats;
+ ret->commit_sort = ctx.cfg.commit_sort;
ret->module_link = ctx.cfg.module_link;
ret->readme = ctx.cfg.readme;
ret->mtime = -1;
int i;
struct cgit_repo *repo;
- for (i=0; i<cgit_repolist.count; i++) {
+ for (i = 0; i < cgit_repolist.count; i++) {
repo = &cgit_repolist.repos[i];
if (!strcmp(repo->url, url))
return repo;
if (str == NULL)
return NULL;
len = strlen(str);
- while(len > 0 && str[len - 1] == c)
+ while (len > 0 && str[len - 1] == c)
len--;
if (len == 0)
return NULL;
return xstrndup(str, len);
}
+char *ensure_end(const char *str, char c)
+{
+ size_t len = strlen(str);
+ char *result;
+
+ if (len && str[len - 1] == c)
+ return xstrndup(str, len);
+
+ result = xmalloc(len + 2);
+ memcpy(result, str, len);
+ result[len] = '/';
+ result[len + 1] = '\0';
+ return result;
+}
+
+void strbuf_ensure_end(struct strbuf *sb, char c)
+{
+ if (!sb->len || sb->buf[sb->len - 1] != c)
+ strbuf_addch(sb, c);
+}
+
char *strlpart(char *txt, int maxlen)
{
char *result;
list->refs[list->count++] = ref;
}
-struct refinfo *cgit_mk_refinfo(const char *refname, const unsigned char *sha1)
+static struct refinfo *cgit_mk_refinfo(const char *refname, const unsigned char *sha1)
{
struct refinfo *ref;
return ref;
}
+static void cgit_free_taginfo(struct taginfo *tag)
+{
+ if (tag->tagger)
+ free(tag->tagger);
+ if (tag->tagger_email)
+ free(tag->tagger_email);
+ if (tag->msg)
+ free(tag->msg);
+ free(tag);
+}
+
+static void cgit_free_refinfo(struct refinfo *ref)
+{
+ if (ref->refname)
+ free((char *)ref->refname);
+ switch (ref->object->type) {
+ case OBJ_TAG:
+ cgit_free_taginfo(ref->tag);
+ break;
+ case OBJ_COMMIT:
+ cgit_free_commitinfo(ref->commit);
+ break;
+ }
+ free(ref);
+}
+
+void cgit_free_reflist_inner(struct reflist *list)
+{
+ int i;
+
+ for (i = 0; i < list->count; i++) {
+ cgit_free_refinfo(list->refs[i]);
+ }
+ free(list->refs);
+}
+
int cgit_refs_cb(const char *refname, const unsigned char *sha1, int flags,
void *cb_data)
{
return 0;
}
-void cgit_diff_tree_cb(struct diff_queue_struct *q,
- struct diff_options *options, void *data)
+static void cgit_diff_tree_cb(struct diff_queue_struct *q,
+ struct diff_options *options, void *data)
{
int i;
file->ptr = (char *)"";
file->size = 0;
} else {
- file->ptr = read_sha1_file(sha1, &type,
+ file->ptr = read_sha1_file(sha1, &type,
(unsigned long *)&file->size);
}
return 1;
char *diffbuf = NULL;
int buflen = 0;
-int filediff_cb(void *priv, mmbuffer_t *mb, int nbuf)
+static int filediff_cb(void *priv, mmbuffer_t *mb, int nbuf)
{
int i;
filepair_fn fn, const char *prefix, int ignorews)
{
struct diff_options opt;
- int prefixlen;
+ struct pathspec_item item;
diff_setup(&opt);
opt.output_format = DIFF_FORMAT_CALLBACK;
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;
+ item.match = prefix;
+ item.len = strlen(prefix);
+ opt.pathspec.nr = 1;
+ opt.pathspec.items = &item;
}
diff_setup_done(&opt);
int tl, sl, rv = 0;
/* favor legacy setting */
- if(atoi(str))
+ if (atoi(str))
return 1;
- for(;;) {
- str += strspn(str,delim);
- tl = strcspn(str,delim);
+ for (;;) {
+ str += strspn(str, delim);
+ tl = strcspn(str, delim);
if (!tl)
break;
for (f = cgit_snapshot_formats; f->suffix; f++) {
sl = strlen(f->suffix);
- if((tl == sl && !strncmp(f->suffix, str, tl)) ||
- (tl == sl-1 && !strncmp(f->suffix+1, str, tl-1))) {
+ if ((tl == sl && !strncmp(f->suffix, str, tl)) ||
+ (tl == sl - 1 && !strncmp(f->suffix + 1, str, tl - 1))) {
rv |= f->bit;
break;
}
return (*size == st.st_size ? 0 : e);
}
-int is_token_char(char c)
+static int is_token_char(char c)
{
return isalnum(c) || c == '_';
}
/* Replace name with getenv(name), return pointer to zero-terminating char
*/
-char *expand_macro(char *name, int maxlength)
+static char *expand_macro(char *name, int maxlength)
{
char *value;
int len;