author | Lars Hjemli <hjemli@gmail.com> | 2007-02-04 21:55:19 (UTC) |
---|---|---|
committer | Lars Hjemli <hjemli@gmail.com> | 2007-02-04 21:55:19 (UTC) |
commit | 8fb2f056961e577a039ae185d89ab8e2d2840b9e (patch) (side-by-side diff) | |
tree | a009aca3c52dd134faa48181daede79bd930f9a4 | |
parent | ce1c7336e5b3e3ebe8f8c9029c405aedec98c208 (diff) | |
download | cgit-8fb2f056961e577a039ae185d89ab8e2d2840b9e.zip cgit-8fb2f056961e577a039ae185d89ab8e2d2840b9e.tar.gz cgit-8fb2f056961e577a039ae185d89ab8e2d2840b9e.tar.bz2 |
Add support for lightweight tags
There is nothing bad about a tag that has no tag-object, but the old code
didn't handle such tags correctly. Fix it.
Signed-off-by: Lars Hjemli <hjemli@gmail.com>
-rw-r--r-- | git.h | 4 | ||||
-rw-r--r-- | ui-summary.c | 52 |
2 files changed, 37 insertions, 19 deletions
@@ -185,192 +185,196 @@ enum grep_pat_token { }; 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); diff --git a/ui-summary.c b/ui-summary.c index 5518d01..ff3ed4d 100644 --- a/ui-summary.c +++ b/ui-summary.c @@ -1,125 +1,139 @@ /* ui-summary.c: functions for generating repo summary page * * Copyright (C) 2006 Lars Hjemli * * Licensed under GNU General Public License v2 * (see COPYING for full license text) */ #include "cgit.h" static int cgit_print_branch_cb(const char *refname, const unsigned char *sha1, int flags, void *cb_data) { struct commit *commit; struct commitinfo *info; char buf[256], *url; strncpy(buf, refname, sizeof(buf)); commit = lookup_commit(sha1); if (commit && !parse_commit(commit)){ info = cgit_parse_commit(commit); html("<tr><td>"); url = cgit_pageurl(cgit_query_repo, "log", fmt("h=%s", refname)); html_link_open(url, NULL, NULL); html_txt(buf); html_link_close(); html("</td><td>"); cgit_print_date(commit->date); html("</td><td>"); html_txt(info->author); html("</td><td>"); url = cgit_pageurl(cgit_query_repo, "commit", fmt("id=%s", sha1_to_hex(sha1))); html_link_open(url, NULL, NULL); html_ntxt(cgit_max_msg_len, info->subject); html_link_close(); html("</td></tr>\n"); cgit_free_commitinfo(info); } else { html("<tr><td>"); html_txt(buf); html("</td><td colspan='3'>"); htmlf("*** bad ref %s ***", sha1_to_hex(sha1)); html("</td></tr>\n"); } return 0; } + +static void cgit_print_object_ref(struct object *obj) +{ + char *page, *url; + + if (obj->type == OBJ_COMMIT) + page = "commit"; + else if (obj->type == OBJ_TREE) + page = "tree"; + else + page = "view"; + + 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], + sha1_to_hex(obj->sha1)); + html_link_close(); +} + static int cgit_print_tag_cb(const char *refname, const unsigned char *sha1, int flags, void *cb_data) { struct tag *tag; struct taginfo *info; - char buf[256], *page, *url; - + struct object *obj; + char buf[256], *url; + strncpy(buf, refname, sizeof(buf)); - tag = lookup_tag(sha1); - if (tag && !parse_tag(tag) && (info = cgit_parse_tag(tag))){ + 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 2; html("<tr><td>"); url = cgit_pageurl(cgit_query_repo, "view", fmt("id=%s", sha1_to_hex(sha1))); html_link_open(url, NULL, NULL); html_txt(buf); html_link_close(); html("</td><td>"); if (info->tagger_date > 0) cgit_print_date(info->tagger_date); html("</td><td>"); if (info->tagger) html(info->tagger); html("</td><td>"); - if (tag->tagged->type == OBJ_COMMIT) - page = "commit"; - else if (tag->tagged->type == OBJ_TREE) - page = "tree"; - else - page = "view"; - - url = cgit_pageurl(cgit_query_repo, page, - fmt("id=%s", sha1_to_hex(tag->tagged->sha1))); - html_link_open(url, NULL, NULL); - htmlf("%s %s", type_names[tag->tagged->type], - sha1_to_hex(tag->tagged->sha1)); - html_link_close(); + cgit_print_object_ref(tag->tagged); html("</td></tr>\n"); } else { html("<tr><td>"); html_txt(buf); - html("</td><td colspan='3'>"); - htmlf("*** bad ref %s ***", sha1_to_hex(sha1)); + html("</td><td colspan='2'/><td>"); + cgit_print_object_ref(obj); html("</td></tr>\n"); } return 0; } static void cgit_print_branches() { html("<tr class='nohover'><th class='left'>Branch</th>" "<th class='left'>Updated</th>" "<th class='left'>Author</th>" "<th class='left'>Head commit</th></tr>\n"); for_each_branch_ref(cgit_print_branch_cb, NULL); } static void cgit_print_tags() { html("<tr class='nohover'><th class='left'>Tag</th>" "<th class='left'>Created</th>" "<th class='left'>Author</th>" "<th class='left'>Reference</th></tr>\n"); for_each_tag_ref(cgit_print_tag_cb, NULL); } void cgit_print_summary() { html("<h2>"); html_txt("Repo summary page"); html("</h2>"); html("<table class='list nowrap'>"); cgit_print_branches(); html("<tr class='nohover'><td colspan='4'> </td></tr>"); cgit_print_tags(); html("</table>"); } |