From: Lars Hjemli Date: Mon, 3 Sep 2007 21:00:06 +0000 (+0200) Subject: Merge branch 'jo/dirlink' X-Git-Url: https://gitweb.ps.run/ps-cgit/commitdiff_plain/ff13396926f3352d9e29c0663154918297dc5af7?hp=-c Merge branch 'jo/dirlink' * jo/dirlink: Rename dirlink to gitlink. Conflicts: ui-tree.c Signed-off-by: Lars Hjemli --- ff13396926f3352d9e29c0663154918297dc5af7 diff --combined ui-diff.c index a76a234,4695e3a..0be845f --- a/ui-diff.c +++ b/ui-diff.c @@@ -37,7 -37,7 +37,7 @@@ static void header(unsigned char *sha1 char *abbrev1, *abbrev2; int subproject; - subproject = (S_ISDIRLNK(mode1) || S_ISDIRLNK(mode2)); + subproject = (S_ISGITLINK(mode1) || S_ISGITLINK(mode2)); html("
"); html("diff --git a/"); html_txt(path1); @@@ -78,10 -78,10 +78,10 @@@ static void filepair_cb(struct diff_fil { header(pair->one->sha1, pair->one->path, pair->one->mode, pair->two->sha1, pair->two->path, pair->two->mode); - if (S_ISDIRLNK(pair->one->mode) || S_ISDIRLNK(pair->two->mode)) { - if (S_ISDIRLNK(pair->one->mode)) + if (S_ISGITLINK(pair->one->mode) || S_ISGITLINK(pair->two->mode)) { + if (S_ISGITLINK(pair->one->mode)) print_line(fmt("-Subproject %s", sha1_to_hex(pair->one->sha1)), 52); - if (S_ISDIRLNK(pair->two->mode)) + if (S_ISGITLINK(pair->two->mode)) print_line(fmt("+Subproject %s", sha1_to_hex(pair->two->sha1)), 52); return; } @@@ -89,52 -89,54 +89,52 @@@ cgit_print_error("Error running diff"); } -void cgit_print_diff(const char *head, const char *old_hex, const char *new_hex, char *path) +void cgit_print_diff(const char *new_rev, const char *old_rev) { unsigned char sha1[20], sha2[20]; enum object_type type; unsigned long size; - struct commit *commit; - - if (head && !old_hex && !new_hex) { - get_sha1(head, sha1); - commit = lookup_commit_reference(sha1); - if (commit && !parse_commit(commit)) { - html(""); - html(""); - html("
"); - cgit_diff_commit(commit, filepair_cb); - html("
"); - } + struct commit *commit, *commit2; + + if (!new_rev) + new_rev = cgit_query_head; + get_sha1(new_rev, sha1); + type = sha1_object_info(sha1, &size); + if (type == OBJ_BAD) { + cgit_print_error(fmt("Bad object name: %s", new_rev)); + return; + } + if (type != OBJ_COMMIT) { + cgit_print_error(fmt("Unhandled object type: %s", + typename(type))); return; } - get_sha1(old_hex, sha1); - get_sha1(new_hex, sha2); + commit = lookup_commit_reference(sha1); + if (!commit || parse_commit(commit)) + cgit_print_error(fmt("Bad commit: %s", sha1_to_hex(sha1))); - type = sha1_object_info(sha1, &size); - if (type == OBJ_BAD) { + if (old_rev) + get_sha1(old_rev, sha2); + else if (commit->parents && commit->parents->item) + hashcpy(sha2, commit->parents->item->object.sha1); + else + hashclr(sha2); + + if (!is_null_sha1(sha2)) { type = sha1_object_info(sha2, &size); if (type == OBJ_BAD) { - cgit_print_error(fmt("Bad object names: %s, %s", old_hex, new_hex)); + cgit_print_error(fmt("Bad object name: %s", sha1_to_hex(sha2))); return; } + commit2 = lookup_commit_reference(sha2); + if (!commit2 || parse_commit(commit2)) + cgit_print_error(fmt("Bad commit: %s", sha1_to_hex(sha2))); } html(""); - switch(type) { - case OBJ_BLOB: - 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(""); html("
"); - header(sha1, path, 0644, sha2, path, 0644); - if (cgit_diff_files(sha1, sha2, print_line)) - cgit_print_error("Error running diff"); - html("
"); + cgit_diff_tree(sha2, sha1, filepair_cb); + html("
"); } diff --combined ui-tree.c index 634132f,21dd533..1cb09f7 --- a/ui-tree.c +++ b/ui-tree.c @@@ -9,205 -9,96 +9,205 @@@ #include "cgit.h" char *curr_rev; +char *match_path; +int header = 0; -static int print_entry(const unsigned char *sha1, const char *base, - int baselen, const char *pathname, unsigned int mode, - int stage) +static void print_object(const unsigned char *sha1, char *path) +{ + enum object_type type; + unsigned char *buf; + unsigned long size, lineno, start, idx; + + type = sha1_object_info(sha1, &size); + if (type == OBJ_BAD) { + cgit_print_error(fmt("Bad object name: %s", + sha1_to_hex(sha1))); + return; + } + + buf = read_sha1_file(sha1, &type, &size); + if (!buf) { + cgit_print_error(fmt("Error reading object %s", + sha1_to_hex(sha1))); + return; + } + + html(" blob: %s",sha1_to_hex(sha1)); + + html("\n"); + idx = 0; + start = 0; + lineno = 0; + while(idx < size) { + if (buf[idx] == '\n') { + buf[idx] = '\0'; + htmlf("\n"); + start = idx + 1; + } + idx++; + } + html("
%1$d", + ++lineno); + html_txt(buf + start); + html("
\n"); +} + + +static int ls_item(const unsigned char *sha1, const char *base, int baselen, + const char *pathname, unsigned int mode, int stage) { char *name; + char *fullpath; enum object_type type; unsigned long size = 0; name = xstrdup(pathname); + fullpath = fmt("%s%s%s", cgit_query_path ? cgit_query_path : "", + cgit_query_path ? "/" : "", name); + type = sha1_object_info(sha1, &size); - if (type == OBJ_BAD && !S_ISDIRLNK(mode)) { + if (type == OBJ_BAD && !S_ISGITLINK(mode)) { htmlf("Bad object: %s %s", name, sha1_to_hex(sha1)); return 0; } - html(""); + + html(""); html_filemode(mode); - html(""); - if (S_ISDIRLNK(mode)) { + if (S_ISGITLINK(mode)) { - htmlf("class='ls-mod'>"); + html_txt(name); + html(""); } else if (S_ISDIR(mode)) { - html("class='ls-dir'>%s", name); - htmlf("%li", size); - - html("history"); - html("\n"); + htmlf("%li", size); + + html(""); + cgit_log_link("log", NULL, "button", cgit_query_head, curr_rev, + fullpath, 0); + html("\n"); free(name); return 0; } -void cgit_print_tree(const char *rev, const char *hex, char *path) +static void ls_head() +{ + html("\n"); + html(""); + html(""); + html(""); + html(""); + html("\n"); + header = 1; +} + +static void ls_tail() +{ + if (!header) + return; + html("
ModeNameSize"); + html("
\n"); + header = 0; +} + +static void ls_tree(const unsigned char *sha1, char *path) { struct tree *tree; + + tree = parse_tree_indirect(sha1); + if (!tree) { + cgit_print_error(fmt("Not a tree object: %s", + sha1_to_hex(sha1))); + return; + } + + ls_head(); + read_tree_recursive(tree, "", 0, 1, NULL, ls_item); + ls_tail(); +} + + +static int walk_tree(const unsigned char *sha1, const char *base, int baselen, + const char *pathname, unsigned mode, int stage) +{ + static int state; + static char buffer[PATH_MAX]; + char *url; + + if (state == 0) { + memcpy(buffer, base, baselen); + strcpy(buffer+baselen, pathname); + url = cgit_pageurl(cgit_query_repo, "tree", + fmt("h=%s&path=%s", curr_rev, buffer)); + html("/"); + cgit_tree_link(xstrdup(pathname), NULL, NULL, cgit_query_head, + curr_rev, buffer); + + if (strcmp(match_path, buffer)) + return READ_TREE_RECURSIVE; + + if (S_ISDIR(mode)) { + state = 1; + ls_head(); + return READ_TREE_RECURSIVE; + } else { + print_object(sha1, buffer); + return 0; + } + } + ls_item(sha1, base, baselen, pathname, mode, stage); + return 0; +} + + +/* + * Show a tree or a blob + * rev: the commit pointing at the root tree object + * path: path to tree or blob + */ +void cgit_print_tree(const char *rev, char *path) +{ unsigned char sha1[20]; struct commit *commit; + const char *paths[] = {path, NULL}; + + if (!rev) + rev = cgit_query_head; curr_rev = xstrdup(rev); - get_sha1(rev, sha1); + if (get_sha1(rev, sha1)) { + cgit_print_error(fmt("Invalid revision name: %s", rev)); + return; + } commit = lookup_commit_reference(sha1); if (!commit || parse_commit(commit)) { - cgit_print_error(fmt("Invalid head: %s", rev)); + cgit_print_error(fmt("Invalid commit reference: %s", rev)); return; } - if (!hex) - hex = sha1_to_hex(commit->tree->object.sha1); - if (get_sha1_hex(hex, sha1)) { - cgit_print_error(fmt("Invalid object id: %s", hex)); - return; - } - tree = parse_tree_indirect(sha1); - if (!tree) { - cgit_print_error(fmt("Not a tree object: %s", hex)); + html("path: root"); + + if (path == NULL) { + ls_tree(commit->tree->object.sha1, NULL); return; } - html_txt(path); - html("\n"); - html(""); - html(""); - html(""); - html(""); - html("\n"); - read_tree_recursive(tree, "", 0, 1, NULL, print_entry); - html("
ModeNameSize"); - html("
\n"); + match_path = path; + read_tree_recursive(commit->tree, NULL, 0, 0, paths, walk_tree); + ls_tail(); }