diff options
Diffstat (limited to '')
-rw-r--r-- | Makefile | 12 | ||||
-rw-r--r-- | cgit.h | 20 | ||||
-rw-r--r-- | git.h | 699 | ||||
-rw-r--r-- | parsing.c | 6 | ||||
-rw-r--r-- | ui-diff.c | 5 | ||||
-rw-r--r-- | ui-summary.c | 2 | ||||
-rw-r--r-- | ui-tree.c | 24 | ||||
-rw-r--r-- | ui-view.c | 14 | ||||
-rw-r--r-- | xdiff.h | 105 |
9 files changed, 50 insertions, 837 deletions
diff --git a/Makefile b/Makefile index b1c3a4e..24c3963 100644 --- a/Makefile +++ b/Makefile @@ -3,10 +3,12 @@ CGIT_VERSION = 0.2 prefix = /var/www/htdocs/cgit gitsrc = ../git +SHA1_HEADER = <openssl/sha.h> + CACHE_ROOT = /var/cache/cgit EXTLIBS = $(gitsrc)/libgit.a $(gitsrc)/xdiff/lib.a -lz -lcrypto OBJECTS = shared.o cache.o parsing.o html.o ui-shared.o ui-repolist.o \ - ui-summary.o ui-log.o ui-view.c ui-tree.c ui-commit.c ui-diff.o \ + ui-summary.o ui-log.o ui-view.o ui-tree.o ui-commit.o ui-diff.o \ ui-snapshot.o CFLAGS += -Wall @@ -15,6 +17,8 @@ ifdef DEBUG CFLAGS += -g endif +CFLAGS += -I$(gitsrc) -DSHA1_HEADER='$(SHA1_HEADER)' + all: cgit install: all clean-cache @@ -22,13 +26,11 @@ install: all clean-cache install cgit $(prefix)/cgit.cgi install cgit.css $(prefix)/cgit.css -cgit: cgit.c cgit.h git.h $(OBJECTS) $(gitsrc)/libgit.a +cgit: cgit.c cgit.h $(OBJECTS) $(gitsrc)/libgit.a $(CC) $(CFLAGS) -DCGIT_VERSION='"$(CGIT_VERSION)"' cgit.c -o cgit \ $(OBJECTS) $(EXTLIBS) -$(OBJECTS): cgit.h git.h - -ui-diff.o: xdiff.h +$(OBJECTS): cgit.h $(gitsrc)/libgit.a: $(MAKE) -C $(gitsrc) diff --git a/cgit.h b/cgit.h index 6e95673..222c9c2 100644 --- a/cgit.h +++ b/cgit.h @@ -1,10 +1,22 @@ #ifndef CGIT_H #define CGIT_H -#include "git.h" -#include <openssl/sha.h> -#include <ctype.h> -#include <sched.h> + +#include <git-compat-util.h> +#include <cache.h> +#include <grep.h> +#include <object.h> +#include <tree.h> +#include <commit.h> +#include <tag.h> +#include <diff.h> +#include <diffcore.h> +#include <refs.h> +#include <revision.h> +#include <log-tree.h> +#include <archive.h> +#include <xdiff/xdiff.h> + typedef void (*configfn)(const char *name, const char *value); diff --git a/git.h b/git.h deleted file mode 100644 index a1d1c4b..0000000 --- a/git.h +++ /dev/null @@ -1,699 +0,0 @@ -#ifndef GIT_H -#define GIT_H - - -/* - * from git:git-compat-util.h - */ - - -#ifndef FLEX_ARRAY -#if defined(__GNUC__) && (__GNUC__ < 3) -#define FLEX_ARRAY 0 -#else -#define FLEX_ARRAY /* empty */ -#endif -#endif - - -#include <unistd.h> -#include <stdio.h> -#include <sys/stat.h> -#include <fcntl.h> -#include <stddef.h> -#include <stdlib.h> -#include <stdarg.h> -#include <string.h> -#include <errno.h> -#include <limits.h> -#include <sys/param.h> -#include <netinet/in.h> -#include <sys/types.h> -#include <dirent.h> -#include <time.h> -#include <regex.h> - -/* On most systems <limits.h> would have given us this, but - * not on some systems (e.g. GNU/Hurd). - */ -#ifndef PATH_MAX -#define PATH_MAX 4096 -#endif - -#ifdef __GNUC__ -#define NORETURN __attribute__((__noreturn__)) -#else -#define NORETURN -#ifndef __attribute__ -#define __attribute__(x) -#endif -#endif - - -extern void die(const char *err, ...) NORETURN __attribute__((format (printf, 1, 2))); - - -static inline char* xstrdup(const char *str) -{ - char *ret = strdup(str); - if (!ret) - die("Out of memory, strdup failed"); - return ret; -} - -static inline void *xmalloc(size_t size) -{ - void *ret = malloc(size); - if (!ret && !size) - ret = malloc(1); - if (!ret) - die("Out of memory, malloc failed"); -#ifdef XMALLOC_POISON - memset(ret, 0xA5, size); -#endif - return ret; -} - -static inline void *xrealloc(void *ptr, size_t size) -{ - void *ret = realloc(ptr, size); - if (!ret && !size) - ret = realloc(ptr, 1); - if (!ret) - die("Out of memory, realloc failed"); - return ret; -} - -static inline void *xcalloc(size_t nmemb, size_t size) -{ - void *ret = calloc(nmemb, size); - if (!ret && (!nmemb || !size)) - ret = calloc(1, 1); - if (!ret) - die("Out of memory, calloc failed"); - return ret; -} - -static inline ssize_t xread(int fd, void *buf, size_t len) -{ - ssize_t nr; - while (1) { - nr = read(fd, buf, len); - if ((nr < 0) && (errno == EAGAIN || errno == EINTR)) - continue; - return nr; - } -} - -static inline ssize_t xwrite(int fd, const void *buf, size_t len) -{ - ssize_t nr; - while (1) { - nr = write(fd, buf, len); - if ((nr < 0) && (errno == EAGAIN || errno == EINTR)) - continue; - return nr; - } -} - - - - -/* - * from git:cache.h - */ - - -enum object_type { - OBJ_NONE = 0, - OBJ_COMMIT = 1, - OBJ_TREE = 2, - OBJ_BLOB = 3, - OBJ_TAG = 4, - /* 5 for future expansion */ - OBJ_OFS_DELTA = 6, - OBJ_REF_DELTA = 7, - OBJ_BAD, -}; - - -/* Convert to/from hex/sha1 representation */ -#define MINIMUM_ABBREV 4 -#define DEFAULT_ABBREV 7 - -extern const unsigned char null_sha1[20]; - -extern int sha1_object_info(const unsigned char *, char *, unsigned long *); - -extern void * read_sha1_file(const unsigned char *sha1, char *type, unsigned long *size); - -extern int get_sha1(const char *str, unsigned char *sha1); -extern int get_sha1_hex(const char *hex, unsigned char *sha1); -extern char *sha1_to_hex(const unsigned char *sha1); /* static buffer result! */ - -static inline int is_null_sha1(const unsigned char *sha1) -{ - return !memcmp(sha1, null_sha1, 20); -} -static inline int hashcmp(const unsigned char *sha1, const unsigned char *sha2) -{ - return memcmp(sha1, sha2, 20); -} -static inline void hashcpy(unsigned char *sha_dst, const unsigned char *sha_src) -{ - memcpy(sha_dst, sha_src, 20); -} -static inline void hashclr(unsigned char *hash) -{ - memset(hash, 0, 20); -} - - -/* - * from git:grep.h - */ - -enum grep_pat_token { - GREP_PATTERN, - GREP_PATTERN_HEAD, - GREP_PATTERN_BODY, - GREP_AND, - GREP_OPEN_PAREN, - GREP_CLOSE_PAREN, - GREP_NOT, - GREP_OR, -}; - -enum grep_context { - GREP_CONTEXT_HEAD, - GREP_CONTEXT_BODY, -}; - -struct grep_pat { - struct grep_pat *next; - const char *origin; - int no; - enum grep_pat_token token; - const char *pattern; - regex_t regexp; -}; - -enum grep_expr_node { - GREP_NODE_ATOM, - GREP_NODE_NOT, - GREP_NODE_AND, - GREP_NODE_OR, -}; - -struct grep_opt { - struct grep_pat *pattern_list; - struct grep_pat **pattern_tail; - struct grep_expr *pattern_expression; - int prefix_length; - regex_t regexp; - unsigned linenum:1; - unsigned invert:1; - unsigned status_only:1; - unsigned name_only:1; - unsigned unmatch_name_only:1; - unsigned count:1; - unsigned word_regexp:1; - unsigned fixed:1; - unsigned all_match:1; -#define GREP_BINARY_DEFAULT 0 -#define GREP_BINARY_NOMATCH 1 -#define GREP_BINARY_TEXT 2 - unsigned binary:2; - unsigned extended:1; - unsigned relative:1; - unsigned pathname:1; - int regflags; - unsigned pre_context; - unsigned post_context; -}; - - -extern void compile_grep_patterns(struct grep_opt *opt); -extern void free_grep_patterns(struct grep_opt *opt); - - -/* - * from git:object.h - */ - -extern const char *type_names[9]; - -struct object_list { - struct object *item; - struct object_list *next; -}; - -struct object_refs { - unsigned count; - struct object *base; - struct object *ref[FLEX_ARRAY]; /* more */ -}; - -struct object_array { - unsigned int nr; - unsigned int alloc; - struct object_array_entry { - struct object *item; - const char *name; - } *objects; -}; - -#define TYPE_BITS 3 -#define FLAG_BITS 27 - -/* - * The object type is stored in 3 bits. - */ -struct object { - unsigned parsed : 1; - unsigned used : 1; - unsigned type : TYPE_BITS; - unsigned flags : FLAG_BITS; - unsigned char sha1[20]; -}; - - -/** Returns the object, having parsed it to find out what it is. **/ -struct object *parse_object(const unsigned char *sha1); - - -/* - * from git:tree.h - */ - -struct tree { - struct object object; - void *buffer; - unsigned long size; -}; - - -struct tree *lookup_tree(const unsigned char *sha1); -int parse_tree_buffer(struct tree *item, void *buffer, unsigned long size); -int parse_tree(struct tree *tree); -struct tree *parse_tree_indirect(const unsigned char *sha1); - -typedef int (*read_tree_fn_t)(const unsigned char *, const char *, int, const char *, unsigned int, int); - -extern int read_tree_recursive(struct tree *tree, - const char *base, int baselen, - int stage, const char **match, - read_tree_fn_t fn); - -extern int read_tree(struct tree *tree, int stage, const char **paths); - - -/* from git:commit.h */ - -struct commit_list { - struct commit *item; - struct commit_list *next; -}; - -struct commit { - struct object object; - void *util; - unsigned long date; - struct commit_list *parents; - struct tree *tree; - char *buffer; -}; - - -struct commit *lookup_commit(const unsigned char *sha1); -struct commit *lookup_commit_reference(const unsigned char *sha1); -struct commit *lookup_commit_reference_gently(const unsigned char *sha1, - int quiet); - -int parse_commit_buffer(struct commit *item, void *buffer, unsigned long size); -int parse_commit(struct commit *item); - -struct commit_list * commit_list_insert(struct commit *item, struct commit_list **list_p); -struct commit_list * insert_by_date(struct commit *item, struct commit_list **list); - -void free_commit_list(struct commit_list *list); - -void sort_by_date(struct commit_list **list); - -/* Commit formats */ -enum cmit_fmt { - CMIT_FMT_RAW, - CMIT_FMT_MEDIUM, - CMIT_FMT_DEFAULT = CMIT_FMT_MEDIUM, - CMIT_FMT_SHORT, - CMIT_FMT_FULL, - CMIT_FMT_FULLER, - CMIT_FMT_ONELINE, - CMIT_FMT_EMAIL, - - CMIT_FMT_UNSPECIFIED, -}; - -extern unsigned long pretty_print_commit(enum cmit_fmt fmt, const struct commit *, unsigned long len, char *buf, unsigned long space, int abbrev, const char *subject, const char *after_subject, int relative_date); - - -typedef void (*topo_sort_set_fn_t)(struct commit*, void *data); -typedef void* (*topo_sort_get_fn_t)(struct commit*); - - - -/* - * from git:tag.h - */ - -extern const char *tag_type; - -struct tag { - struct object object; - struct object *tagged; - char *tag; - char *signature; /* not actually implemented */ -}; - -extern struct tag *lookup_tag(const unsigned char *sha1); -extern int parse_tag_buffer(struct tag *item, void *data, unsigned long size); -extern int parse_tag(struct tag *item); -extern struct object *deref_tag(struct object *, const char *, int); - - -/* - * from git:diffcore.h - */ - -struct diff_filespec { - unsigned char sha1[20]; - char *path; - void *data; - void *cnt_data; - unsigned long size; - int xfrm_flags; /* for use by the xfrm */ - unsigned short mode; /* file mode */ - unsigned sha1_valid : 1; /* if true, use sha1 and trust mode; - * if false, use the name and read from - * the filesystem. - */ -#define DIFF_FILE_VALID(spec) (((spec)->mode) != 0) - unsigned should_free : 1; /* data should be free()'ed */ - unsigned should_munmap : 1; /* data should be munmap()'ed */ -}; - -struct diff_filepair { - struct diff_filespec *one; - struct diff_filespec *two; - unsigned short int score; - char status; /* M C R N D U (see Documentation/diff-format.txt) */ - unsigned source_stays : 1; /* all of R/C are copies */ - unsigned broken_pair : 1; - unsigned renamed_pair : 1; -}; - -#define DIFF_PAIR_UNMERGED(p) \ - (!DIFF_FILE_VALID((p)->one) && !DIFF_FILE_VALID((p)->two)) - -#define DIFF_PAIR_RENAME(p) ((p)->renamed_pair) - -#define DIFF_PAIR_BROKEN(p) \ - ( (!DIFF_FILE_VALID((p)->one) != !DIFF_FILE_VALID((p)->two)) && \ - ((p)->broken_pair != 0) ) - -#define DIFF_PAIR_TYPE_CHANGED(p) \ - ((S_IFMT & (p)->one->mode) != (S_IFMT & (p)->two->mode)) - -#define DIFF_PAIR_MODE_CHANGED(p) ((p)->one->mode != (p)->two->mode) - -extern void diff_free_filepair(struct diff_filepair *); - -extern int diff_unmodified_pair(struct diff_filepair *); - -struct diff_queue_struct { - struct diff_filepair **queue; - int alloc; - int nr; -}; - - -/* - * from git:diff.h - */ - - -struct rev_info; -struct diff_options; -struct diff_queue_struct; - -typedef void (*change_fn_t)(struct diff_options *options, - unsigned old_mode, unsigned new_mode, - const unsigned char *old_sha1, - const unsigned char *new_sha1, - const char *base, const char *path); - -typedef void (*add_remove_fn_t)(struct diff_options *options, - int addremove, unsigned mode, - const unsigned char *sha1, - const char *base, const char *path); - -typedef void (*diff_format_fn_t)(struct diff_queue_struct *q, - struct diff_options *options, void *data); - -#define DIFF_FORMAT_RAW 0x0001 -#define DIFF_FORMAT_DIFFSTAT 0x0002 -#define DIFF_FORMAT_NUMSTAT 0x0004 -#define DIFF_FORMAT_SUMMARY 0x0008 -#define DIFF_FORMAT_PATCH 0x0010 - -/* These override all above */ -#define DIFF_FORMAT_NAME 0x0100 -#define DIFF_FORMAT_NAME_STATUS 0x0200 -#define DIFF_FORMAT_CHECKDIFF 0x0400 - -/* Same as output_format = 0 but we know that -s flag was given - * and we should not give default value to output_format. - */ -#define DIFF_FORMAT_NO_OUTPUT 0x0800 - -#define DIFF_FORMAT_CALLBACK 0x1000 - -struct diff_options { - const char *filter; - const char *orderfile; - const char *pickaxe; - const char *single_follow; - unsigned recursive:1, - tree_in_recursive:1, - binary:1, - text:1, - full_index:1, - silent_on_remove:1, - find_copies_harder:1, - color_diff:1, - color_diff_words:1; - int context; - int break_opt; - int detect_rename; - int line_termination; - int output_format; - int pickaxe_opts; - int rename_score; - int reverse_diff; - int rename_limit; - int setup; - int abbrev; - const char *msg_sep; - const char *stat_sep; - long xdl_opts; - - int stat_width; - int stat_name_width; - - int nr_paths; - const char **paths; - int *pathlens; - change_fn_t change; - add_remove_fn_t add_remove; - diff_format_fn_t format_callback; - void *format_callback_data; -}; - -enum color_diff { - DIFF_RESET = 0, - DIFF_PLAIN = 1, - DIFF_METAINFO = 2, - DIFF_FRAGINFO = 3, - DIFF_FILE_OLD = 4, - DIFF_FILE_NEW = 5, - DIFF_COMMIT = 6, - DIFF_WHITESPACE = 7, -}; - - -extern int diff_tree_sha1(const unsigned char *old, const unsigned char *new, - const char *base, struct diff_options *opt); - -extern int diff_root_tree_sha1(const unsigned char *new, const char *base, - struct diff_options *opt); - -extern int git_diff_ui_config(const char *var, const char *value); -extern void diff_setup(struct diff_options *); -extern int diff_opt_parse(struct diff_options *, const char **, int); -extern int diff_setup_done(struct diff_options *); - - -extern void diffcore_std(struct diff_options *); -extern void diff_flush(struct diff_options*); - - -/* diff-raw status letters */ -#define DIFF_STATUS_ADDED 'A' -#define DIFF_STATUS_COPIED 'C' -#define DIFF_STATUS_DELETED 'D' -#define DIFF_STATUS_MODIFIED 'M' -#define DIFF_STATUS_RENAMED 'R' -#define DIFF_STATUS_TYPE_CHANGED 'T' -#define DIFF_STATUS_UNKNOWN 'X' -#define DIFF_STATUS_UNMERGED 'U' - - - -/* - * from git:refs.g - */ - -typedef int each_ref_fn(const char *refname, const unsigned char *sha1, int flags, void *cb_data); -extern int head_ref(each_ref_fn, void *); -extern int for_each_ref(each_ref_fn, void *); -extern int for_each_tag_ref(each_ref_fn, void *); -extern int for_each_branch_ref(each_ref_fn, void *); -extern int for_each_remote_ref(each_ref_fn, void *); - - - -/* - * from git:revision.h - */ - -struct rev_info; -struct log_info; - -typedef void (prune_fn_t)(struct rev_info *revs, struct commit *commit); - -struct rev_info { - /* Starting list */ - struct commit_list *commits; - struct object_array pending; - - /* Basic information */ - const char *prefix; - void *prune_data; - prune_fn_t *prune_fn; - - /* Traversal flags */ - unsigned int dense:1, - no_merges:1, - no_walk:1, - remove_empty_trees:1, - simplify_history:1, - lifo:1, - topo_order:1, - tag_objects:1, - tree_objects:1, - blob_objects:1, - edge_hint:1, - limited:1, - unpacked:1, /* see also ignore_packed below */ - boundary:1, - parents:1; - - /* Diff flags */ - unsigned int diff:1, - full_diff:1, - show_root_diff:1, - no_commit_id:1, - verbose_header:1, - ignore_merges:1, - combine_merges:1, - dense_combined_merges:1, - always_show_header:1; - - /* Format info */ - unsigned int shown_one:1, - abbrev_commit:1, - relative_date:1; - - const char **ignore_packed; /* pretend objects in these are unpacked */ - int num_ignore_packed; - - unsigned int abbrev; - enum cmit_fmt commit_format; - struct log_info *loginfo; - int nr, total; - const char *mime_boundary; - const char *message_id; - const char *ref_message_id; - const char *add_signoff; - const char *extra_headers; - - /* Filter by commit log message */ - struct grep_opt *grep_filter; - - /* special limits */ - int max_count; - unsigned long max_age; - unsigned long min_age; - - /* diff info for patches and for paths limiting */ - struct diff_options diffopt; - struct diff_options pruning; - - topo_sort_set_fn_t topo_setter; - topo_sort_get_fn_t topo_getter; -}; - - -extern void init_revisions(struct rev_info *revs, const char *prefix); -extern int setup_revisions(int argc, const char **argv, struct rev_info *revs, const char *def); -extern int handle_revision_arg(const char *arg, struct rev_info *revs,int flags,int cant_be_filename); - -extern void prepare_revision_walk(struct rev_info *revs); -extern struct commit *get_revision(struct rev_info *revs); - - - -/* from git:log-tree.h */ - -int log_tree_commit(struct rev_info *, struct commit *); - - - -/* from git:archive.h */ - -struct archiver_args { - const char *base; - struct tree *tree; - const unsigned char *commit_sha1; - time_t time; - const char **pathspec; - unsigned int verbose : 1; - void *extra; -}; - -typedef int (*write_archive_fn_t)(struct archiver_args *); - -typedef void *(*parse_extra_args_fn_t)(int argc, const char **argv); - -struct archiver { - const char *name; - struct archiver_args args; - write_archive_fn_t write_archive; - parse_extra_args_fn_t parse_extra; -}; - -extern int write_tar_archive(struct archiver_args *); -extern int write_zip_archive(struct archiver_args *); -extern void *parse_extra_zip_args(int argc, const char **argv); - -#endif /* GIT_H */ diff --git a/parsing.c b/parsing.c index 1013dad..332d61c 100644 --- a/parsing.c +++ b/parsing.c @@ -201,13 +201,13 @@ struct commitinfo *cgit_parse_commit(struct commit *commit) struct taginfo *cgit_parse_tag(struct tag *tag) { void *data; - char type[20]; + enum object_type type; unsigned long size; char *p, *t; struct taginfo *ret; - data = read_sha1_file(tag->object.sha1, type, &size); - if (!data || strcmp(type, tag_type)) { + data = read_sha1_file(tag->object.sha1, &type, &size); + if (!data || type != OBJ_TAG) { free(data); return 0; } diff --git a/ui-diff.c b/ui-diff.c index b6486f1..0ad9faf 100644 --- a/ui-diff.c +++ b/ui-diff.c @@ -7,7 +7,6 @@ */ #include "cgit.h" -#include "xdiff.h" char *diff_buffer; int diff_buffer_size; @@ -82,13 +81,13 @@ int diff_cb(void *priv_, mmbuffer_t *mb, int nbuf) static int load_mmfile(mmfile_t *file, const unsigned char *sha1) { - char type[20]; + enum object_type type; if (is_null_sha1(sha1)) { file->ptr = (char *)""; file->size = 0; } else { - file->ptr = read_sha1_file(sha1, type, &file->size); + file->ptr = read_sha1_file(sha1, &type, &file->size); } return 1; } diff --git a/ui-summary.c b/ui-summary.c index 42f4300..0a7869b 100644 --- a/ui-summary.c +++ b/ui-summary.c @@ -62,7 +62,7 @@ static void cgit_print_object_ref(struct object *obj) url = cgit_pageurl(cgit_query_repo, page, fmt("id=%s", sha1_to_hex(obj->sha1))); html_link_open(url, NULL, NULL); - htmlf("%s %s", type_names[obj->type], + htmlf("%s %s", typename(obj->type), sha1_to_hex(obj->sha1)); html_link_close(); } diff --git a/ui-tree.c b/ui-tree.c index b00670e..60f7560 100644 --- a/ui-tree.c +++ b/ui-tree.c @@ -14,37 +14,39 @@ static int print_entry(const unsigned char *sha1, const char *base, int stage) { char *name; - char type[20]; + enum object_type type; unsigned long size; - if (sha1_object_info(sha1, type, &size)) { - cgit_print_error(fmt("Bad object name: %s", - sha1_to_hex(sha1))); + name = xstrdup(pathname); + type = sha1_object_info(sha1, &size); + if (type == OBJ_BAD) { + htmlf("<tr><td colspan='3'>Bad object: %s %s</td></tr>", + name, + sha1_to_hex(sha1)); return 0; } - name = xstrdup(pathname); html("<tr><td class='filemode'>"); html_filemode(mode); html("</td><td>"); - if (S_ISDIR(mode)) { + if (S_ISDIRLNK(mode)) { + htmlf("<div class='ls-dirlnk'>%s => submodule</div>", name); + } else if (S_ISDIR(mode)) { html("<div class='ls-dir'><a href='"); html_attr(cgit_pageurl(cgit_query_repo, "tree", fmt("id=%s&path=%s%s/", sha1_to_hex(sha1), cgit_query_path ? cgit_query_path : "", pathname))); + htmlf("'>%s</a></div>", name); } else { html("<div class='ls-blob'><a href='"); html_attr(cgit_pageurl(cgit_query_repo, "view", fmt("id=%s&path=%s%s", sha1_to_hex(sha1), cgit_query_path ? cgit_query_path : "", pathname))); + htmlf("'>%s</a></div>", name); } - html("'>"); - html_txt(name); - if (S_ISDIR(mode)) - html("/"); - html("</a></div></td>"); + html("</div></td>"); htmlf("<td class='filesize'>%li</td>", size); html("</tr>\n"); free(name); diff --git a/ui-view.c b/ui-view.c index 85e223c..9d23c45 100644 --- a/ui-view.c +++ b/ui-view.c @@ -11,7 +11,7 @@ void cgit_print_view(const char *hex) { unsigned char sha1[20]; - char type[20]; + enum object_type type; unsigned char *buf; unsigned long size; @@ -20,20 +20,22 @@ void cgit_print_view(const char *hex) return; } - if (sha1_object_info(sha1, type, &size)){ - cgit_print_error("Bad object name"); + type = sha1_object_info(sha1, &size); + if (type == OBJ_BAD) { + cgit_print_error(fmt("Bad object name: %s", hex)); return; } - buf = read_sha1_file(sha1, type, &size); + buf = read_sha1_file(sha1, &type, &size); if (!buf) { - cgit_print_error("Error reading object"); + cgit_print_error(fmt("Error reading object %s", hex)); return; } buf[size] = '\0'; html("<table class='list'>\n"); - htmlf("<tr class='nohover'><th class='left'>%s %s, %li bytes</th></tr>\n", type, hex, size); + htmlf("<tr class='nohover'><th class='left'>%s %s, %li bytes</th></tr>\n", + typename(type), hex, size); html("<tr><td class='blob'>\n"); html_txt(buf); html("\n</td></tr>\n"); diff --git a/xdiff.h b/xdiff.h deleted file mode 100644 index fa409d5..0000000 --- a/xdiff.h +++ /dev/null @@ -1,105 +0,0 @@ -/* - * LibXDiff by Davide Libenzi ( File Differential Library ) - * Copyright (C) 2003 Davide Libenzi - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * Davide Libenzi <davidel@xmailserver.org> - * - */ - -#if !defined(XDIFF_H) -#define XDIFF_H - -#ifdef __cplusplus -extern "C" { -#endif /* #ifdef __cplusplus */ - - -#define XDF_NEED_MINIMAL (1 << 1) -#define XDF_IGNORE_WHITESPACE (1 << 2) -#define XDF_IGNORE_WHITESPACE_CHANGE (1 << 3) -#define XDF_WHITESPACE_FLAGS (XDF_IGNORE_WHITESPACE | XDF_IGNORE_WHITESPACE_CHANGE) - -#define XDL_PATCH_NORMAL '-' -#define XDL_PATCH_REVERSE '+' -#define XDL_PATCH_MODEMASK ((1 << 8) - 1) -#define XDL_PATCH_IGNOREBSPACE (1 << 8) - -#define XDL_EMIT_FUNCNAMES (1 << 0) -#define XDL_EMIT_COMMON (1 << 1) - -#define XDL_MMB_READONLY (1 << 0) - -#define XDL_MMF_ATOMIC (1 << 0) - -#define XDL_BDOP_INS 1 -#define XDL_BDOP_CPY 2 -#define XDL_BDOP_INSB 3 - -#define XDL_MERGE_MINIMAL 0 -#define XDL_MERGE_EAGER 1 -#define XDL_MERGE_ZEALOUS 2 - -typedef struct s_mmfile { - char *ptr; - long size; -} mmfile_t; - -typedef struct s_mmbuffer { - char *ptr; - long size; -} mmbuffer_t; - -typedef struct s_xpparam { - unsigned long flags; -} xpparam_t; - -typedef struct s_xdemitcb { - void *priv; - int (*outf)(void *, mmbuffer_t *, int); -} xdemitcb_t; - -typedef struct s_xdemitconf { - long ctxlen; - unsigned long flags; -} xdemitconf_t; - -typedef struct s_bdiffparam { - long bsize; -} bdiffparam_t; - - -#define xdl_malloc(x) malloc(x) -#define xdl_free(ptr) free(ptr) -#define xdl_realloc(ptr,x) realloc(ptr,x) - -void *xdl_mmfile_first(mmfile_t *mmf, long *size); -void *xdl_mmfile_next(mmfile_t *mmf, long *size); -long xdl_mmfile_size(mmfile_t *mmf); - -int xdl_diff(mmfile_t *mf1, mmfile_t *mf2, xpparam_t const *xpp, - xdemitconf_t const *xecfg, xdemitcb_t *ecb); - -int xdl_merge(mmfile_t *orig, mmfile_t *mf1, const char *name1, - mmfile_t *mf2, const char *name2, - xpparam_t const *xpp, int level, mmbuffer_t *result); - -#ifdef __cplusplus -} -#endif /* #ifdef __cplusplus */ - -#endif /* #if !defined(XDIFF_H) */ - |