From ded9393b173853d2e960f9b176aeb0bc4ed35be2 Mon Sep 17 00:00:00 2001 From: Lars Hjemli Date: Fri, 11 May 2007 12:12:48 +0200 Subject: [PATCH 01/16] Add submodule links in tree listing When a submodule occurs in a tree, generate a link to show the module/commit. The link is specified as a sprintf string in /etc/cgitrc, using parameters 'module-link' and 'repo.module-link'. This should probably be extended with repo.module-link.$path. Signed-off-by: Lars Hjemli --- cgit.css | 2 +- cgit.h | 2 ++ cgitrc | 7 ++++++- html.c | 3 ++- shared.c | 6 ++++++ ui-tree.c | 19 ++++++++++--------- 6 files changed, 27 insertions(+), 12 deletions(-) diff --git a/cgit.css b/cgit.css index 640bbc9..ef4bc62 100644 --- a/cgit.css +++ b/cgit.css @@ -141,7 +141,7 @@ div.error { margin: 1em 2em; } -div.ls-blob, div.ls-dir { +td.ls-blob, td.ls-dir, td.ls-mod { font-family: monospace; } diff --git a/cgit.h b/cgit.h index 292e488..b7f8827 100644 --- a/cgit.h +++ b/cgit.h @@ -33,6 +33,7 @@ struct repoinfo { char *path; char *desc; char *owner; + char *module_link; int snapshots; }; @@ -70,6 +71,7 @@ extern char *cgit_root_title; extern char *cgit_css; extern char *cgit_logo; extern char *cgit_logo_link; +extern char *cgit_module_link; extern char *cgit_virtual_root; extern char *cgit_cache_root; diff --git a/cgitrc b/cgitrc index 3bae642..f217b39 100644 --- a/cgitrc +++ b/cgitrc @@ -47,6 +47,10 @@ #logo-link=http://www.kernel.org/pub/software/scm/git/docs/ +## Url loaded when clicking a submodule link +#module-link=./?repo=%s&page=commit&id=%s + + ## Number of chars shown of commit subject message (in log view) #max-message-length=60 @@ -81,4 +85,5 @@ #repo.desc=the caching cgi for git #repo.path=/pub/git/cgit #repo.owner=Lars Hjemli -#repo.snapshots=1 # override a sitewide snapshot-setting +#repo.snapshots=1 # override a sitewide snapshot-setting +#repo.module-link=/git/%s/commit/?id=%s # override the standard module-link diff --git a/html.c b/html.c index c0b2ed4..175b4b6 100644 --- a/html.c +++ b/html.c @@ -158,10 +158,11 @@ void html_filemode(unsigned short mode) html("d"); else if (S_ISLNK(mode)) html("l"); + else if (S_ISDIRLNK(mode)) + html("m"); else html("-"); html_fileperm(mode >> 6); html_fileperm(mode >> 3); html_fileperm(mode); } - diff --git a/shared.c b/shared.c index 531d8c0..19d2df0 100644 --- a/shared.c +++ b/shared.c @@ -15,6 +15,7 @@ char *cgit_root_title = "Git repository browser"; char *cgit_css = "/cgit.css"; char *cgit_logo = "/git-logo.png"; char *cgit_logo_link = "http://www.kernel.org/pub/software/scm/git/docs/"; +char *cgit_module_link = "./?repo=%s&page=commit&id=%s"; char *cgit_virtual_root = NULL; char *cgit_cache_root = "/var/cache/cgit"; @@ -85,6 +86,7 @@ struct repoinfo *add_repo(const char *url) ret->desc = NULL; ret->owner = NULL; ret->snapshots = cgit_snapshots; + ret->module_link = cgit_module_link; return ret; } @@ -98,6 +100,8 @@ void cgit_global_config_cb(const char *name, const char *value) cgit_logo = xstrdup(value); else if (!strcmp(name, "logo-link")) cgit_logo_link = xstrdup(value); + else if (!strcmp(name, "module-link")) + cgit_module_link = xstrdup(value); else if (!strcmp(name, "virtual-root")) cgit_virtual_root = xstrdup(value); else if (!strcmp(name, "nocache")) @@ -128,6 +132,8 @@ void cgit_global_config_cb(const char *name, const char *value) cgit_repo->owner = xstrdup(value); else if (cgit_repo && !strcmp(name, "repo.snapshots")) cgit_repo->snapshots = atoi(value); + else if (cgit_repo && !strcmp(name, "repo.module-link")) + cgit_repo->module_link= xstrdup(value); } void cgit_repo_config_cb(const char *name, const char *value) diff --git a/ui-tree.c b/ui-tree.c index 60f7560..dee8309 100644 --- a/ui-tree.c +++ b/ui-tree.c @@ -15,11 +15,11 @@ static int print_entry(const unsigned char *sha1, const char *base, { char *name; enum object_type type; - unsigned long size; + unsigned long size = 0; name = xstrdup(pathname); type = sha1_object_info(sha1, &size); - if (type == OBJ_BAD) { + if (type == OBJ_BAD && !S_ISDIRLNK(mode)) { htmlf("Bad object: %s %s", name, sha1_to_hex(sha1)); @@ -27,26 +27,27 @@ static int print_entry(const unsigned char *sha1, const char *base, } html(""); html_filemode(mode); - html(""); + html("%s => submodule", name); + htmlf("class='ls-mod'>%s", name); } else { - html("", name); } - html(""); + htmlf("'>%s", name); htmlf("%li", size); html("\n"); free(name); -- 2.50.1 From 5a217ed3e04a6ef7b066ded446582c0dd0fc5d3e Mon Sep 17 00:00:00 2001 From: Lars Hjemli Date: Fri, 11 May 2007 12:13:15 +0200 Subject: [PATCH 02/16] Update README with submodule build info Signed-off-by: Lars Hjemli --- README | 52 +++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 39 insertions(+), 13 deletions(-) diff --git a/README b/README index a14418e..6d661d8 100644 --- a/README +++ b/README @@ -8,19 +8,35 @@ builtin cache to decrease server io-pressure. Installation - $ make gitsrc= + $ make $ su - $ make prefix= install + $ make install +This will install cgit.cgi and cgit.css into "/var/www/htdocs/cgit". -Default value for gitsrc is "../git", and this directory should contain the -git sources. +Note: The initial "make" will create a submodule 'git' and clone the git +repository at git://git.kernel.org/pub/scm/git/git.git in it. If you +already have a local git git repository that you want to use as origin +for the submodule, run -Default value for prefix is "/var/www/htdocs/cgit". This directory will -contain "cgit.cgi" and "cgit.css" after 'make install'. + $ git clone -s git + $ ./submodules.sh -u -After installation, httpd.conf probably must be updated with a Directory- -section for cgit, possibly something like this: +before running "make". + + +Dependencies + + -git (1.5.2-rc0 or newer, due to git submodule) installed + -zip lib + -crypto lib + -openssl lib + + +Apache configuration + +A new Directory-section must probably be added for cgit, possibly something +like this: AllowOverride None @@ -33,23 +49,33 @@ section for cgit, possibly something like this: Runtime configuration The file /etc/cgitrc is read by cgit before handling a request. In addition -to runtime parameters, this file also contains a list of the repositories +to runtime parameters, this file also contains a list of the repositories displayed by cgit. A template cgitrc is shipped with the sources, and all parameters and default -values are documented in this file. +values are documented in this file. The cache -When cgit is invoked it looks for a cachefile matching the request and -returns it to the client. If no such cachefile exist (or if it has expired), +When cgit is invoked it looks for a cachefile matching the request and +returns it to the client. If no such cachefile exist (or if it has expired), the content for the request is written into the proper cachefile before the file is returned. -If the cachefile has expired but cgit is unable to obtain a lock for it, the +If the cachefile has expired but cgit is unable to obtain a lock for it, the stale cachefile is returned to the client. This is done to favour page throughput over page freshness. The generated content contains the complete response to the client, including the http-headers "Modified" and "Expires". + + +The mis(sing) features + +Submodule links in the directory listing page have a fixed format per +repository. This should probably be extended to a generic map between +submodule path and url. + + +The end. -- 2.50.1 From dad80d1ff8e065002cdf4e37252164a7f8517a5b Mon Sep 17 00:00:00 2001 From: Lars Hjemli Date: Fri, 11 May 2007 12:15:44 +0200 Subject: [PATCH 03/16] Tag release v0.3 Signed-off-by: Lars Hjemli --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 138f261..86b2a70 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -CGIT_VERSION = 0.2 +CGIT_VERSION = 0.3 prefix = /var/www/htdocs/cgit -- 2.50.1 From f596d10d7391ed72b73019e037a7f7eec7a50d02 Mon Sep 17 00:00:00 2001 From: Lars Hjemli Date: Fri, 11 May 2007 20:41:14 +0200 Subject: [PATCH 04/16] Makefile: add support for building w.o. preinstalled git Signed-off-by: Lars Hjemli --- Makefile | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 86b2a70..ccc7582 100644 --- a/Makefile +++ b/Makefile @@ -19,6 +19,18 @@ endif CFLAGS += -Igit -DSHA1_HEADER='$(SHA1_HEADER)' +# +# If make is run on a nongit platform, we need to get the git sources as a tarball. +# But there is currently no recent enough tarball available on kernel.org, so download +# a zipfile from hjemli.net instead +# +GITVER = $(shell git version 2>/dev/null || echo nogit) +ifeq ($(GITVER),nogit) +GITURL = http://hjemli.net/git/git/snapshot/?id=v1.5.2-rc2 +INITGIT = test -e git/git.c || (curl "$(GITURL)" > tmp.zip && unzip tmp.zip) +else +INITGIT = ./submodules.sh -i +endif # @@ -33,7 +45,7 @@ cgit: cgit.c cgit.h $(OBJECTS) $(OBJECTS): cgit.h git/libgit.a git/libgit.a: - ./submodules.sh -i + $(INITGIT) $(MAKE) -C git # -- 2.50.1 From 9f48df63f6d8d9a8abcc02cd2f08293da7081520 Mon Sep 17 00:00:00 2001 From: Lars Hjemli Date: Fri, 11 May 2007 23:44:42 +0200 Subject: [PATCH 05/16] Add links to enable downloading of tagged blobs All tags below refs/archives are shown on the repo summary page as download links. The links referes to the tagged objects, using the tag name as filename for download. This can be used to add shortcuts for release tarballs, documentation and other blobs stored in the object database, especially blobs that are not reachable during cloning. Signed-off-by: Lars Hjemli --- cgit.css | 20 ++++++++++++++ ui-summary.c | 74 +++++++++++++++++++++++++++++++++++++++++++++------- 2 files changed, 85 insertions(+), 9 deletions(-) diff --git a/cgit.css b/cgit.css index ef4bc62..49cf2d1 100644 --- a/cgit.css +++ b/cgit.css @@ -10,6 +10,7 @@ body { h2 { font-size: 120%; font-weight: bold; + margin-top: 0em; margin-bottom: 0.25em; } @@ -127,6 +128,25 @@ td#search input { background-color: #fff; } +td#summary { + vertical-align: top; + padding-bottom: 1em; +} + +td#archivelist { + padding-bottom: 1em; +} + +td#archivelist table { + float: right; + border-collapse: collapse; + border: solid 1px #777; +} + +td#archivelist table th { + background-color: #ccc; +} + td#content { padding: 1em 0.5em; } diff --git a/ui-summary.c b/ui-summary.c index 0a7869b..9388f5f 100644 --- a/ui-summary.c +++ b/ui-summary.c @@ -8,6 +8,8 @@ #include "cgit.h" +int items = 0; + static int cgit_print_branch_cb(const char *refname, const unsigned char *sha1, int flags, void *cb_data) { @@ -83,6 +85,13 @@ static int cgit_print_tag_cb(const char *refname, const unsigned char *sha1, tag = lookup_tag(sha1); if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag))) return 2; + if (!items) { + html("Tag" + "Created" + "Author" + "Reference\n"); + } + items++; html(""); url = cgit_pageurl(cgit_query_repo, "view", fmt("id=%s", sha1_to_hex(sha1))); @@ -108,6 +117,44 @@ static int cgit_print_tag_cb(const char *refname, const unsigned char *sha1, return 0; } +static int cgit_print_archive_cb(const char *refname, const unsigned char *sha1, + int flags, void *cb_data) +{ + struct tag *tag; + struct taginfo *info; + struct object *obj; + char buf[256], *url; + + if (prefixcmp(refname, "refs/archives")) + return 0; + strncpy(buf, refname+14, sizeof(buf)); + obj = parse_object(sha1); + if (!obj) + return 1; + if (obj->type == OBJ_TAG) { + tag = lookup_tag(sha1); + if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag))) + return 0; + hashcpy(sha1, tag->tagged->sha1); + } else if (obj->type != OBJ_BLOB) { + return 0; + } + if (!items) { + html(""); + html(""); + } + items++; + html(""); + return 0; +} + static void cgit_print_branches() { html("" @@ -119,21 +166,30 @@ static void cgit_print_branches() static void cgit_print_tags() { - html("" - "" - "" - "\n"); + items = 0; for_each_tag_ref(cgit_print_tag_cb, NULL); } +static void cgit_print_archives() +{ + items = 0; + for_each_ref(cgit_print_archive_cb, NULL); + if (items) + html("
Downloads
"); + url = cgit_pageurl(cgit_query_repo, "blob", + fmt("id=%s&path=%s", sha1_to_hex(sha1), + buf)); + html_link_open(url, NULL, NULL); + html_txt(buf); + html_link_close(); + html("
Branch
TagCreatedAuthorReference
"); +} + void cgit_print_summary() { - html("

"); - html(cgit_repo->name); - html("

"); - html(cgit_repo->desc); - html("

"); html(""); + html(""); cgit_print_branches(); html(""); cgit_print_tags(); -- 2.50.1 From f5af0beb6ab569d64950ca55a52a07923917ce81 Mon Sep 17 00:00:00 2001 From: Lars Hjemli Date: Sat, 12 May 2007 00:29:37 +0200 Subject: [PATCH 06/16] css: fix bad rendering in Internet Explorer The layout-tables used border-collapse:separate, which maked all pages look really bad in IE. Fix it. Signed-off-by: Lars Hjemli --- cgit.css | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/cgit.css b/cgit.css index 49cf2d1..cded981 100644 --- a/cgit.css +++ b/cgit.css @@ -2,10 +2,16 @@ body { font-family: arial; font-size: 11pt; background: white; +} + +body, table { padding: 0em; margin: 0em; } +table { + border-collapse: collapse; +} h2 { font-size: 120%; @@ -64,8 +70,7 @@ img { table#layout { width: 100%; - border-collapse: separate; - border-spacing: 0px; + border-collapse: collapse; margin: 0px; } -- 2.50.1 From 1b49de3c2c52e29c78f870826b6334abdadc0295 Mon Sep 17 00:00:00 2001 From: Lars Hjemli Date: Sun, 13 May 2007 11:24:23 +0200 Subject: [PATCH 07/16] Add shared diff-handling functions This adds a standard interface for tree diffing. Signed-off-by: Lars Hjemli --- cgit.h | 5 +++++ shared.c | 47 +++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 50 insertions(+), 2 deletions(-) diff --git a/cgit.h b/cgit.h index b7f8827..24b02d7 100644 --- a/cgit.h +++ b/cgit.h @@ -19,6 +19,7 @@ typedef void (*configfn)(const char *name, const char *value); +typedef void (*filepair_fn)(struct diff_filepair *pair); struct cacheitem { char *name; @@ -116,6 +117,10 @@ extern int chk_positive(int result, char *msg); extern int hextoint(char c); extern void *cgit_free_commitinfo(struct commitinfo *info); +extern void cgit_diff_tree(const unsigned char *old_sha1, + const unsigned char *new_sha1, + filepair_fn fn); +extern void cgit_diff_commit(struct commit *commit, filepair_fn fn); extern char *fmt(const char *format,...); diff --git a/shared.c b/shared.c index 19d2df0..f8a17b6 100644 --- a/shared.c +++ b/shared.c @@ -74,8 +74,8 @@ struct repoinfo *add_repo(const char *url) cgit_repolist.length = 8; else cgit_repolist.length *= 2; - cgit_repolist.repos = xrealloc(cgit_repolist.repos, - cgit_repolist.length * + cgit_repolist.repos = xrealloc(cgit_repolist.repos, + cgit_repolist.length * sizeof(struct repoinfo)); } @@ -195,3 +195,46 @@ int hextoint(char c) return -1; } +void cgit_diff_tree_cb(struct diff_queue_struct *q, + struct diff_options *options, void *data) +{ + int i; + + for (i = 0; i < q->nr; i++) { + if (q->queue[i]->status == 'U') + continue; + ((filepair_fn)data)(q->queue[i]); + } +} + +void cgit_diff_tree(const unsigned char *old_sha1, + const unsigned char *new_sha1, + filepair_fn fn) +{ + struct diff_options opt; + int ret; + + diff_setup(&opt); + opt.output_format = DIFF_FORMAT_CALLBACK; + opt.detect_rename = 1; + opt.recursive = 1; + opt.format_callback = cgit_diff_tree_cb; + opt.format_callback_data = fn; + diff_setup_done(&opt); + + if (old_sha1) + ret = diff_tree_sha1(old_sha1, new_sha1, "", &opt); + else + ret = diff_root_tree_sha1(new_sha1, "", &opt); + diffcore_std(&opt); + diff_flush(&opt); +} + +void cgit_diff_commit(struct commit *commit, filepair_fn fn) +{ + unsigned char *old_sha1 = NULL; + + if (commit->parents) + old_sha1 = commit->parents->item->object.sha1; + cgit_diff_tree(old_sha1, commit->object.sha1, fn); +} -- 2.50.1 From ae4c1ee11379e353f2a94201181a3a9dab75b646 Mon Sep 17 00:00:00 2001 From: Lars Hjemli Date: Sun, 13 May 2007 11:26:23 +0200 Subject: [PATCH 08/16] Use standard tree-diff function when showing diffstat for single commit Remove unneeded code from ui-commit.c and replace with call to standard diff-functions. Also fix some whitespace issues. Signed-off-by: Lars Hjemli --- ui-commit.c | 66 ++++++++++++----------------------------------------- 1 file changed, 15 insertions(+), 51 deletions(-) diff --git a/ui-commit.c b/ui-commit.c index 3618800..f1a22d3 100644 --- a/ui-commit.c +++ b/ui-commit.c @@ -14,7 +14,7 @@ void print_filepair(struct diff_filepair *pair) { char *query; char *class; - + switch (pair->status) { case DIFF_STATUS_ADDED: class = "add"; @@ -52,25 +52,25 @@ void print_filepair(struct diff_filepair *pair) html_filemode(pair->two->mode); } - if (pair->one->mode != pair->two->mode && - !is_null_sha1(pair->one->sha1) && + if (pair->one->mode != pair->two->mode && + !is_null_sha1(pair->one->sha1) && !is_null_sha1(pair->two->sha1)) { html("["); html_filemode(pair->one->mode); html("]"); } htmlf("\n"); - files++; -} - -void diff_format_cb(struct diff_queue_struct *q, - struct diff_options *options, void *data) -{ - int i; - - for (i = 0; i < q->nr; i++) { - if (q->queue[i]->status == 'U') - continue; - print_filepair(q->queue[i]); - } -} - -void cgit_diffstat(struct commit *commit) -{ - struct diff_options opt; - int ret; - - diff_setup(&opt); - opt.output_format = DIFF_FORMAT_CALLBACK; - opt.detect_rename = 1; - opt.recursive = 1; - opt.format_callback = diff_format_cb; - diff_setup_done(&opt); - - if (commit->parents) - ret = diff_tree_sha1(commit->parents->item->object.sha1, - commit->object.sha1, - "", &opt); - else - ret = diff_root_tree_sha1(commit->object.sha1, "", &opt); - diffcore_std(&opt); - diff_flush(&opt); + html("\n"); + files++; } void cgit_print_commit(const char *hex) @@ -166,17 +131,16 @@ void cgit_print_commit(const char *hex) "%s\n", + htmlf("'>%s\n", sha1_to_hex(p->item->object.sha1)); } if (cgit_repo->snapshots) { htmlf("", filename); } - html("
"); + html("

"); + html_txt(cgit_repo->name); + html(" - "); + html_txt(cgit_repo->desc); + html("

"); + html("
"); + cgit_print_archives(); + html("
 
", class); - query = fmt("id=%s&id2=%s", sha1_to_hex(pair->one->sha1), - sha1_to_hex(pair->two->sha1)); - html_link_open(cgit_pageurl(cgit_query_repo, "diff", query), + query = fmt("id=%s&id2=%s", sha1_to_hex(pair->one->sha1), + sha1_to_hex(pair->two->sha1)); + html_link_open(cgit_pageurl(cgit_query_repo, "diff", query), NULL, NULL); - if (pair->status == DIFF_STATUS_COPIED || + if (pair->status == DIFF_STATUS_COPIED || pair->status == DIFF_STATUS_RENAMED) { html_txt(pair->two->path); - htmlf(" (%s from ", pair->status == DIFF_STATUS_COPIED ? + htmlf(" (%s from ", pair->status == DIFF_STATUS_COPIED ? "copied" : "renamed"); - query = fmt("id=%s", sha1_to_hex(pair->one->sha1)); - html_link_open(cgit_pageurl(cgit_query_repo, "view", query), + query = fmt("id=%s", sha1_to_hex(pair->one->sha1)); + html_link_open(cgit_pageurl(cgit_query_repo, "view", query), NULL, NULL); html_txt(pair->one->path); html(")"); @@ -81,44 +81,9 @@ void print_filepair(struct diff_filepair *pair) html(""); //TODO: diffstat graph - - html("
download%s
\n"); html("
"); html_txt(info->subject); @@ -186,7 +150,7 @@ void cgit_print_commit(const char *hex) html("
"); html(""); html("\n"); - cgit_diffstat(commit); + cgit_diff_commit(commit, print_filepair); htmlf("\n", files, files > 1 ? "s" : ""); html("
Affected files
" "%d file%s changed
"); -- 2.50.1 From 48dc00342effe3ba530ff6cbb79e5d0d5fc740fd Mon Sep 17 00:00:00 2001 From: Lars Hjemli Date: Sun, 13 May 2007 11:27:46 +0200 Subject: [PATCH 09/16] Show number of changed files in log view This uses the new tree-diff functions to calculate number of files changed per commit. Also fix some whitespace issues. Signed-off-by: Lars Hjemli --- ui-log.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/ui-log.c b/ui-log.c index 159393a..b930bb2 100644 --- a/ui-log.c +++ b/ui-log.c @@ -8,6 +8,13 @@ #include "cgit.h" +int files, lines; + +void inspect_files(struct diff_filepair *pair) +{ + files++; +} + void print_commit(struct commit *commit) { char buf[32]; @@ -17,7 +24,7 @@ void print_commit(struct commit *commit) info = cgit_parse_commit(commit); time = gmtime(&commit->date); html(""); - strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", time); + strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M", time); html_txt(buf); html(""); char *qry = fmt("id=%s", sha1_to_hex(commit->object.sha1)); @@ -25,6 +32,11 @@ void print_commit(struct commit *commit) html_link_open(url, NULL, NULL); html_ntxt(cgit_max_msg_len, info->subject); html_link_close(); + html(""); + files = 0; + lines = 0; + cgit_diff_commit(commit, inspect_files); + htmlf("%d", files); html(""); html_txt(info->author); html("\n"); @@ -39,7 +51,7 @@ void cgit_print_log(const char *tip, int ofs, int cnt, char *grep) const char *argv[3] = {NULL, tip, NULL}; int argc = 2; int i; - + if (grep) argv[argc++] = fmt("--grep=%s", grep); init_revisions(&rev, NULL); @@ -57,6 +69,7 @@ void cgit_print_log(const char *tip, int ofs, int cnt, char *grep) html(""); html("" "" + "" "\n"); if (ofs<0) -- 2.50.1 From c4ef667961ef4668c9449124f97d55b9ac46c059 Mon Sep 17 00:00:00 2001 From: Lars Hjemli Date: Sun, 13 May 2007 14:21:19 +0200 Subject: [PATCH 10/16] Add standard interface for file diff functions Signed-off-by: Lars Hjemli --- cgit.h | 7 +++++ shared.c | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+) diff --git a/cgit.h b/cgit.h index 24b02d7..43de375 100644 --- a/cgit.h +++ b/cgit.h @@ -20,6 +20,7 @@ typedef void (*configfn)(const char *name, const char *value); typedef void (*filepair_fn)(struct diff_filepair *pair); +typedef void (*linediff_fn)(char *line, int len); struct cacheitem { char *name; @@ -117,9 +118,15 @@ extern int chk_positive(int result, char *msg); extern int hextoint(char c); extern void *cgit_free_commitinfo(struct commitinfo *info); + +extern int cgit_diff_files(const unsigned char *old_sha1, + const unsigned char *new_sha1, + linediff_fn fn); + extern void cgit_diff_tree(const unsigned char *old_sha1, const unsigned char *new_sha1, filepair_fn fn); + extern void cgit_diff_commit(struct commit *commit, filepair_fn fn); extern char *fmt(const char *format,...); diff --git a/shared.c b/shared.c index f8a17b6..801f68d 100644 --- a/shared.c +++ b/shared.c @@ -207,6 +207,85 @@ void cgit_diff_tree_cb(struct diff_queue_struct *q, } } +static int load_mmfile(mmfile_t *file, const unsigned char *sha1) +{ + 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); + } + return 1; +} + +/* + * Receive diff-buffers from xdiff and concatenate them as + * needed across multiple callbacks. + * + * This is basically a copy of xdiff-interface.c/xdiff_outf(), + * ripped from git and modified to use globals instead of + * a special callback-struct. + */ +char *diffbuf = NULL; +int buflen = 0; + +int filediff_cb(void *priv, mmbuffer_t *mb, int nbuf) +{ + int i; + + for (i = 0; i < nbuf; i++) { + if (mb[i].ptr[mb[i].size-1] != '\n') { + /* Incomplete line */ + diffbuf = xrealloc(diffbuf, buflen + mb[i].size); + memcpy(diffbuf + buflen, mb[i].ptr, mb[i].size); + buflen += mb[i].size; + continue; + } + + /* we have a complete line */ + if (!diffbuf) { + ((linediff_fn)priv)(mb[i].ptr, mb[i].size); + continue; + } + diffbuf = xrealloc(diffbuf, buflen + mb[i].size); + memcpy(diffbuf + buflen, mb[i].ptr, mb[i].size); + ((linediff_fn)priv)(diffbuf, buflen + mb[i].size); + free(diffbuf); + diffbuf = NULL; + buflen = 0; + } + if (diffbuf) { + ((linediff_fn)priv)(diffbuf, buflen); + free(diffbuf); + diffbuf = NULL; + buflen = 0; + } + return 0; +} + +int cgit_diff_files(const unsigned char *old_sha1, + const unsigned char *new_sha1, + linediff_fn fn) +{ + mmfile_t file1, file2; + xpparam_t diff_params; + xdemitconf_t emit_params; + xdemitcb_t emit_cb; + + if (!load_mmfile(&file1, old_sha1) || !load_mmfile(&file2, new_sha1)) + return 1; + + diff_params.flags = XDF_NEED_MINIMAL; + emit_params.ctxlen = 3; + emit_params.flags = XDL_EMIT_FUNCNAMES; + emit_cb.outf = filediff_cb; + emit_cb.priv = fn; + xdl_diff(&file1, &file2, &diff_params, &emit_params, &emit_cb); + return 0; +} + void cgit_diff_tree(const unsigned char *old_sha1, const unsigned char *new_sha1, filepair_fn fn) -- 2.50.1 From 38a0f9cd89c4c5a97bd5b38e7b56da809a00fccb Mon Sep 17 00:00:00 2001 From: Lars Hjemli Date: Sun, 13 May 2007 14:21:46 +0200 Subject: [PATCH 11/16] Simplify ui-diff.c using the new file-level diff interface Signed-off-by: Lars Hjemli --- ui-diff.c | 88 ++----------------------------------------------------- 1 file changed, 2 insertions(+), 86 deletions(-) diff --git a/ui-diff.c b/ui-diff.c index 0ad9faf..96106af 100644 --- a/ui-diff.c +++ b/ui-diff.c @@ -8,9 +8,6 @@ #include "cgit.h" -char *diff_buffer; -int diff_buffer_size; - /* * print a single line returned from xdiff @@ -34,88 +31,6 @@ static void print_line(char *line, int len) line[len-1] = c; } -/* - * Receive diff-buffers from xdiff and concatenate them as - * needed across multiple callbacks. - * - * This is basically a copy of xdiff-interface.c/xdiff_outf(), - * ripped from git and modified to use globals instead of - * a special callback-struct. - */ -int diff_cb(void *priv_, mmbuffer_t *mb, int nbuf) -{ - int i; - - for (i = 0; i < nbuf; i++) { - if (mb[i].ptr[mb[i].size-1] != '\n') { - /* Incomplete line */ - diff_buffer = xrealloc(diff_buffer, - diff_buffer_size + mb[i].size); - memcpy(diff_buffer + diff_buffer_size, - mb[i].ptr, mb[i].size); - diff_buffer_size += mb[i].size; - continue; - } - - /* we have a complete line */ - if (!diff_buffer) { - print_line(mb[i].ptr, mb[i].size); - continue; - } - diff_buffer = xrealloc(diff_buffer, - diff_buffer_size + mb[i].size); - memcpy(diff_buffer + diff_buffer_size, mb[i].ptr, mb[i].size); - print_line(diff_buffer, diff_buffer_size + mb[i].size); - free(diff_buffer); - diff_buffer = NULL; - diff_buffer_size = 0; - } - if (diff_buffer) { - print_line(diff_buffer, diff_buffer_size); - free(diff_buffer); - diff_buffer = NULL; - diff_buffer_size = 0; - } - return 0; -} - -static int load_mmfile(mmfile_t *file, const unsigned char *sha1) -{ - 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); - } - return 1; -} - -static void run_diff(const unsigned char *sha1, const unsigned char *sha2) -{ - mmfile_t file1, file2; - xpparam_t diff_params; - xdemitconf_t emit_params; - xdemitcb_t emit_cb; - - if (!load_mmfile(&file1, sha1) || !load_mmfile(&file2, sha2)) { - cgit_print_error("Unable to load files for diff"); - return; - } - - diff_params.flags = XDF_NEED_MINIMAL; - - emit_params.ctxlen = 3; - emit_params.flags = XDL_EMIT_FUNCNAMES; - - emit_cb.outf = diff_cb; - - xdl_diff(&file1, &file2, &diff_params, &emit_params, &emit_cb); -} - - - void cgit_print_diff(const char *old_hex, const char *new_hex) { unsigned char sha1[20], sha2[20]; @@ -124,6 +39,7 @@ void cgit_print_diff(const char *old_hex, const char *new_hex) get_sha1(new_hex, sha2); html("
DateMessageFilesAuthor
"); - run_diff(sha1, sha2); + if (cgit_diff_files(sha1, sha2, print_line)) + cgit_print_error("Error running diff"); html("
"); } -- 2.50.1 From 80e577c3ef2a73becabff7e9c9c242f317a87de9 Mon Sep 17 00:00:00 2001 From: Lars Hjemli Date: Sun, 13 May 2007 17:03:27 +0200 Subject: [PATCH 12/16] Show number of changed lines in log view Use the new file-diff interface to calculate number of changed lines per commit. Signed-off-by: Lars Hjemli --- ui-log.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/ui-log.c b/ui-log.c index b930bb2..7d1985e 100644 --- a/ui-log.c +++ b/ui-log.c @@ -10,9 +10,16 @@ int files, lines; +void count_lines(char *line, int size) +{ + if (size>0 && (line[0] == '+' || line[0] == '-')) + lines++; +} + void inspect_files(struct diff_filepair *pair) { files++; + cgit_diff_files(pair->one->sha1, pair->two->sha1, count_lines); } void print_commit(struct commit *commit) @@ -32,11 +39,13 @@ void print_commit(struct commit *commit) html_link_open(url, NULL, NULL); html_ntxt(cgit_max_msg_len, info->subject); html_link_close(); - html(""); files = 0; lines = 0; cgit_diff_commit(commit, inspect_files); + html(""); htmlf("%d", files); + html(""); + htmlf("%d", lines); html(""); html_txt(info->author); html("\n"); @@ -70,6 +79,7 @@ void cgit_print_log(const char *tip, int ofs, int cnt, char *grep) html("Date" "Message" "Files" + "Lines" "Author\n"); if (ofs<0) -- 2.50.1 From c6cf3a424a0860d69b290254d9b19d35527b2d27 Mon Sep 17 00:00:00 2001 From: Lars Hjemli Date: Sun, 13 May 2007 17:15:06 +0200 Subject: [PATCH 13/16] Add max-commit-count parameter to cgitrc This enabled customizing number of commits shown per page in log view. It also changes the default from 100 to 50, mainly due to the more cpu intensive log pages (number of files/lines changed) but also since 100 log messages requires excessive scrolling. Signed-off-by: Lars Hjemli --- cgit.c | 4 ++-- cgit.h | 1 + cgitrc | 4 ++++ shared.c | 3 +++ 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/cgit.c b/cgit.c index 28bab8d..aee7ba3 100644 --- a/cgit.c +++ b/cgit.c @@ -107,8 +107,8 @@ static void cgit_print_repo_page(struct cacheitem *item) cgit_print_pageheader(cgit_query_page, show_search); if (!strcmp(cgit_query_page, "log")) { - cgit_print_log(cgit_query_head, cgit_query_ofs, 100, - cgit_query_search); + cgit_print_log(cgit_query_head, cgit_query_ofs, + cgit_max_commit_count, cgit_query_search); } else if (!strcmp(cgit_query_page, "tree")) { cgit_print_tree(cgit_query_sha1, cgit_query_path); } else if (!strcmp(cgit_query_page, "commit")) { diff --git a/cgit.h b/cgit.h index 43de375..46f3173 100644 --- a/cgit.h +++ b/cgit.h @@ -87,6 +87,7 @@ extern int cgit_cache_static_ttl; extern int cgit_cache_max_create_time; extern int cgit_max_msg_len; +extern int cgit_max_commit_count; extern char *cgit_repo_name; extern char *cgit_repo_desc; diff --git a/cgitrc b/cgitrc index f217b39..019781e 100644 --- a/cgitrc +++ b/cgitrc @@ -55,6 +55,10 @@ #max-message-length=60 +## Number of commits per page in log view +#max-commit-count=50 + + ## Root of cached output #cache-root=/var/cache/cgit diff --git a/shared.c b/shared.c index 801f68d..ffecac8 100644 --- a/shared.c +++ b/shared.c @@ -30,6 +30,7 @@ int cgit_cache_static_ttl = -1; int cgit_cache_max_create_time = 5; int cgit_max_msg_len = 60; +int cgit_max_commit_count = 50; char *cgit_repo_name = NULL; char *cgit_repo_desc = NULL; @@ -120,6 +121,8 @@ void cgit_global_config_cb(const char *name, const char *value) cgit_cache_dynamic_ttl = atoi(value); else if (!strcmp(name, "max-message-length")) cgit_max_msg_len = atoi(value); + else if (!strcmp(name, "max-commit-count")) + cgit_max_commit_count = atoi(value); else if (!strcmp(name, "repo.url")) cgit_repo = add_repo(value); else if (!strcmp(name, "repo.name")) -- 2.50.1 From 8a3685bcf2612206fc24a2421acb53dd83aeab85 Mon Sep 17 00:00:00 2001 From: Lars Hjemli Date: Sun, 13 May 2007 22:25:14 +0200 Subject: [PATCH 14/16] Add graphical diffstat to commit view The diffstat is calculated against the leftmost parent of the commit. This gives nice information for "normal" merges while octopus merges are less than optimal, so the diffstat isn't calculated for those merges. Signed-off-by: Lars Hjemli --- Makefile | 1 + add.png | Bin 0 -> 168 bytes cgit.css | 30 +++++++++++- del.png | Bin 0 -> 168 bytes ui-commit.c | 132 ++++++++++++++++++++++++++++++++++++++++------------ 5 files changed, 130 insertions(+), 33 deletions(-) create mode 100644 add.png create mode 100644 del.png diff --git a/Makefile b/Makefile index ccc7582..ea4d818 100644 --- a/Makefile +++ b/Makefile @@ -55,6 +55,7 @@ install: all clean-cache mkdir -p $(prefix) install cgit $(prefix)/cgit.cgi install cgit.css $(prefix)/cgit.css + install add.png del.png $(prefix)/ clean-cgit: rm -f cgit *.o diff --git a/add.png b/add.png new file mode 100644 index 0000000000000000000000000000000000000000..c550388694dca3178807e6bdaf6901df0761adac GIT binary patch literal 168 zcmeAS@N?(olHy`uVBq!ia0y~yU|lDxO@5ryiZZhV_;z5@pN$v;kce`urHg3fvJnpCD-~*4+8@O NgQu&X%Q~loCIGR*D+mAp literal 0 HcmV?d00001 diff --git a/cgit.css b/cgit.css index cded981..b736b19 100644 --- a/cgit.css +++ b/cgit.css @@ -26,6 +26,13 @@ h3 { font-weight: normal; } +h4 { + margin-top: 1.5em; + margin-bottom: 0.1em; + font-size: 100%; + font-weight: bold; +} + a { color: blue; text-decoration: none; @@ -227,6 +234,12 @@ div.commit-msg { table.diffstat { border-collapse: collapse; margin-top: 1.5em; + width: 100%; + border: solid 1px #aaa; +} + +table.diffstat tr:hover { + background-color: #eee; } table.diffstat th { @@ -238,8 +251,11 @@ table.diffstat th { } table.diffstat td { - padding: 0.1em 1em 0.1em 0.1em; + padding: 0.2em 0.2em 0.1em 0.1em; font-size: 100%; + border: none; + border-top: solid 1px #aaa; + border-bottom: solid 1px #aaa; } table.diffstat td span.modechange { @@ -259,7 +275,17 @@ table.diffstat td.upd a { color: blue; } -table.diffstat td.summary { +table.diffstat td.graph { + width: 75%; + vertical-align: center; +} + +table.diffstat td.graph img { + border: none; + height: 11pt; +} + +div.diffstat-summary { color: #888; padding-top: 0.5em; } diff --git a/del.png b/del.png new file mode 100644 index 0000000000000000000000000000000000000000..5c73e8248a6ad318eed8afaebf27fa1ec50dd2d4 GIT binary patch literal 168 zcmeAS@N?(olHy`uVBq!ia0y~yU|lDxO@5ryiZZhV_;z5@pN$v;kcf>BRhwOf!T!7#b?4EkXsl$ MUHx3vIVCg!0Hi7^kpKVy literal 0 HcmV?d00001 diff --git a/ui-commit.c b/ui-commit.c index f1a22d3..ce33cf9 100644 --- a/ui-commit.c +++ b/ui-commit.c @@ -8,14 +8,30 @@ #include "cgit.h" -int files = 0; +int files = 0, slots = 0; +int total_adds = 0, total_rems = 0, max_changes = 0; +int lines_added, lines_removed; -void print_filepair(struct diff_filepair *pair) +struct fileinfo { + char status; + unsigned char old_sha1[20]; + unsigned char new_sha1[20]; + unsigned short old_mode; + unsigned short new_mode; + char *old_path; + char *new_path; + unsigned int added; + unsigned int removed; +} *items; + + +void print_fileinfo(struct fileinfo *info) { - char *query; + char *query, *query2; char *class; + double width; - switch (pair->status) { + switch (info->status) { case DIFF_STATUS_ADDED: class = "add"; break; @@ -41,51 +57,98 @@ void print_filepair(struct diff_filepair *pair) class = "stg"; break; default: - die("bug: unhandled diff status %c", pair->status); + die("bug: unhandled diff status %c", info->status); } html(""); htmlf(""); - if (is_null_sha1(pair->two->sha1)) { - html_filemode(pair->one->mode); + if (is_null_sha1(info->new_sha1)) { + html_filemode(info->old_mode); } else { - html_filemode(pair->two->mode); + html_filemode(info->new_mode); } - if (pair->one->mode != pair->two->mode && - !is_null_sha1(pair->one->sha1) && - !is_null_sha1(pair->two->sha1)) { + if (info->old_mode != info->new_mode && + !is_null_sha1(info->old_sha1) && + !is_null_sha1(info->new_sha1)) { html("["); - html_filemode(pair->one->mode); + html_filemode(info->old_mode); html("]"); } htmlf("", class); - query = fmt("id=%s&id2=%s", sha1_to_hex(pair->one->sha1), - sha1_to_hex(pair->two->sha1)); + query = fmt("id=%s&id2=%s", sha1_to_hex(info->old_sha1), + sha1_to_hex(info->new_sha1)); html_link_open(cgit_pageurl(cgit_query_repo, "diff", query), NULL, NULL); - if (pair->status == DIFF_STATUS_COPIED || - pair->status == DIFF_STATUS_RENAMED) { - html_txt(pair->two->path); - htmlf(" (%s from ", pair->status == DIFF_STATUS_COPIED ? + if (info->status == DIFF_STATUS_COPIED || + info->status == DIFF_STATUS_RENAMED) { + html_txt(info->new_path); + htmlf(" (%s from ", info->status == DIFF_STATUS_COPIED ? "copied" : "renamed"); - query = fmt("id=%s", sha1_to_hex(pair->one->sha1)); - html_link_open(cgit_pageurl(cgit_query_repo, "view", query), + query2 = fmt("id=%s", sha1_to_hex(info->old_sha1)); + html_link_open(cgit_pageurl(cgit_query_repo, "view", query2), NULL, NULL); - html_txt(pair->one->path); + html_txt(info->old_path); html(")"); } else { - html_txt(pair->two->path); + html_txt(info->new_path); html(""); } - html(""); + html(""); + htmlf("%d", info->added + info->removed); - //TODO: diffstat graph + html(""); + width = (info->added + info->removed) * 100.0 / max_changes; + if (width < 0.1) + width = 0.1; + html_link_open(cgit_pageurl(cgit_query_repo, "diff", query), + NULL, NULL); + htmlf("", + info->added * width / (info->added + info->removed)); + htmlf("", + info->removed * width / (info->added + info->removed)); + html("\n"); +} - html("\n"); +void cgit_count_diff_lines(char *line, int len) +{ + if (line && (len > 0)) { + if (line[0] == '+') + lines_added++; + else if (line[0] == '-') + lines_removed++; + } +} + +void inspect_filepair(struct diff_filepair *pair) +{ files++; + lines_added = 0; + lines_removed = 0; + cgit_diff_files(pair->one->sha1, pair->two->sha1, cgit_count_diff_lines); + if (files >= slots) { + if (slots == 0) + slots = 4; + else + slots = slots * 2; + items = xrealloc(items, slots * sizeof(struct fileinfo)); + } + items[files-1].status = pair->status; + hashcpy(items[files-1].old_sha1, pair->one->sha1); + hashcpy(items[files-1].new_sha1, pair->two->sha1); + items[files-1].old_mode = pair->one->mode; + items[files-1].new_mode = pair->two->mode; + items[files-1].old_path = xstrdup(pair->one->path); + items[files-1].new_path = xstrdup(pair->two->path); + items[files-1].added = lines_added; + items[files-1].removed = lines_removed; + if (lines_added + lines_removed > max_changes) + max_changes = lines_added + lines_removed; + total_adds += lines_added; + total_rems += lines_removed; } + void cgit_print_commit(const char *hex) { struct commit *commit; @@ -94,6 +157,7 @@ void cgit_print_commit(const char *hex) unsigned char sha1[20]; char *query; char *filename; + int i; if (get_sha1(hex, sha1)) { cgit_print_error(fmt("Bad object id: %s", hex)); @@ -148,11 +212,17 @@ void cgit_print_commit(const char *hex) html("
"); html_txt(info->msg); html("
"); - html(""); - html("\n"); - cgit_diff_commit(commit, print_filepair); - htmlf("\n", files, files > 1 ? "s" : ""); - html("
Affected files
" - "%d file%s changed
"); + if (!(commit->parents && commit->parents->next && commit->parents->next->next)) { + html(""); + max_changes = 0; + cgit_diff_commit(commit, inspect_filepair); + for(i = 0; i"); + html("
"); + htmlf("%d files changed, %d insertions, %d deletions\n", + files, total_adds, total_rems); + html("
"); + } cgit_free_commitinfo(info); } -- 2.50.1 From 6a8749d3bd1570faa3dc07e80efc8fcef5953aa0 Mon Sep 17 00:00:00 2001 From: Lars Hjemli Date: Sun, 13 May 2007 23:13:12 +0200 Subject: [PATCH 15/16] Add commitdiff between commit and each of it's parent A link is added next to each parent of a commit, leading to the new diff-functionality in ui-diff.c. Also added support for a path-parameter to filelevel diffs accessed via the diffstat. Signed-off-by: Lars Hjemli --- cgit.c | 2 +- cgit.css | 5 +++++ cgit.h | 2 +- ui-commit.c | 19 +++++++++++++++---- ui-diff.c | 45 +++++++++++++++++++++++++++++++++++++++++---- 5 files changed, 63 insertions(+), 10 deletions(-) diff --git a/cgit.c b/cgit.c index aee7ba3..3d85a08 100644 --- a/cgit.c +++ b/cgit.c @@ -116,7 +116,7 @@ static void cgit_print_repo_page(struct cacheitem *item) } else if (!strcmp(cgit_query_page, "view")) { cgit_print_view(cgit_query_sha1, cgit_query_path); } else if (!strcmp(cgit_query_page, "diff")) { - cgit_print_diff(cgit_query_sha1, cgit_query_sha2); + cgit_print_diff(cgit_query_sha1, cgit_query_sha2, cgit_query_path); } else { cgit_print_error("Invalid request"); } diff --git a/cgit.css b/cgit.css index b736b19..fe0ba50 100644 --- a/cgit.css +++ b/cgit.css @@ -290,6 +290,11 @@ div.diffstat-summary { padding-top: 0.5em; } +table.diff th { + padding: 1em 0em 0.1em 0.1em; + text-align: left; +} + table.diff td { border: solid 1px black; font-family: monospace; diff --git a/cgit.h b/cgit.h index 46f3173..93699b5 100644 --- a/cgit.h +++ b/cgit.h @@ -174,7 +174,7 @@ extern void cgit_print_view(const char *hex, char *path); extern void cgit_print_blob(struct cacheitem *item, const char *hex, char *path); extern void cgit_print_tree(const char *hex, char *path); extern void cgit_print_commit(const char *hex); -extern void cgit_print_diff(const char *old_hex, const char *new_hex); +extern void cgit_print_diff(const char *old_hex, const char *new_hex, char *path); extern void cgit_print_snapshot(struct cacheitem *item, const char *hex, const char *format, const char *prefix, const char *filename); diff --git a/ui-commit.c b/ui-commit.c index ce33cf9..b3d1c28 100644 --- a/ui-commit.c +++ b/ui-commit.c @@ -76,8 +76,8 @@ void print_fileinfo(struct fileinfo *info) html("]"); } htmlf("
\n", sha1_to_hex(commit->tree->object.sha1)); for (p = commit->parents; p ; p = p->next) { + parent = lookup_commit_reference(p->item->object.sha1); + if (!parent) { + html(""); + continue; + } html("" "\n", + htmlf("'>%s (diff)"); } if (cgit_repo->snapshots) { htmlf("
", class); - query = fmt("id=%s&id2=%s", sha1_to_hex(info->old_sha1), - sha1_to_hex(info->new_sha1)); + query = fmt("id=%s&id2=%s&path=%s", sha1_to_hex(info->old_sha1), + sha1_to_hex(info->new_sha1), info->new_path); html_link_open(cgit_pageurl(cgit_query_repo, "diff", query), NULL, NULL); if (info->status == DIFF_STATUS_COPIED || @@ -151,7 +151,7 @@ void inspect_filepair(struct diff_filepair *pair) void cgit_print_commit(const char *hex) { - struct commit *commit; + struct commit *commit, *parent; struct commitinfo *info; struct commit_list *p; unsigned char sha1[20]; @@ -190,13 +190,24 @@ void cgit_print_commit(const char *hex) html_attr(cgit_pageurl(cgit_query_repo, "tree", query)); htmlf("'>%s
"); + cgit_print_error("Error reading parent commit"); + html("
parent" "%s
download
"); - if (cgit_diff_files(sha1, sha2, print_line)) - cgit_print_error("Error running diff"); + type = sha1_object_info(sha1, &size); + if (type == OBJ_BAD) { + type = sha1_object_info(sha2, &size); + if (type == OBJ_BAD) { + cgit_print_error(fmt("Bad object names: %s, %s", old_hex, new_hex)); + return; + } + } + + html(""); + switch(type) { + case OBJ_BLOB: + if (path) + htmlf("", path); + html(""); + break; + case OBJ_TREE: + cgit_diff_tree(sha1, sha2, filepair_cb); + break; + default: + cgit_print_error(fmt("Unhandled object type: %s", + typename(type))); + break; + } html("
%s
"); + if (cgit_diff_files(sha1, sha2, print_line)) + cgit_print_error("Error running diff"); + html("
"); } -- 2.50.1 From 4fdf571c888fd38ae362684c429a3bdf24240ef7 Mon Sep 17 00:00:00 2001 From: Lars Hjemli Date: Sun, 13 May 2007 23:28:19 +0200 Subject: [PATCH 16/16] cgit v0.4 Signed-off-by: Lars Hjemli --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index ea4d818..a36eede 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -CGIT_VERSION = 0.3 +CGIT_VERSION = 0.4 prefix = /var/www/htdocs/cgit -- 2.50.1