author | Lars Hjemli <hjemli@gmail.com> | 2008-12-03 16:34:23 (UTC) |
---|---|---|
committer | Lars Hjemli <hjemli@gmail.com> | 2008-12-03 16:34:23 (UTC) |
commit | a1b01b2513510f8f93f7f8ca39969002cd496a19 (patch) (unidiff) | |
tree | 143e569416a89b31de6f96e8e79f8841c24dd935 | |
parent | c7d1402b177f4cf835e81f962e2faa3c9e28c549 (diff) | |
download | cgit-a1b01b2513510f8f93f7f8ca39969002cd496a19.zip cgit-a1b01b2513510f8f93f7f8ca39969002cd496a19.tar.gz cgit-a1b01b2513510f8f93f7f8ca39969002cd496a19.tar.bz2 |
ui-log: try to disambiguate ref names
The 'h' querystring parameter in cgit is normally used to specify
a branch (i.e. a ref below refs/heads/), but if a repository contains
a tag with the same name as a branch the output from ui-log would use
the tag as start-revision.
This patch tries to fix the issue by checking if the specified ref is
valid as a branch name; if so, the full refname is used in the call
to setup_revisions().
Noticed-by: Takamori Yamaguchi <akschar@gmail.com>
Signed-off-by: Lars Hjemli <hjemli@gmail.com>
-rw-r--r-- | ui-log.c | 17 |
1 files changed, 15 insertions, 2 deletions
@@ -1,155 +1,168 @@ | |||
1 | /* ui-log.c: functions for log output | 1 | /* ui-log.c: functions for log output |
2 | * | 2 | * |
3 | * Copyright (C) 2006 Lars Hjemli | 3 | * Copyright (C) 2006 Lars Hjemli |
4 | * | 4 | * |
5 | * Licensed under GNU General Public License v2 | 5 | * Licensed under GNU General Public License v2 |
6 | * (see COPYING for full license text) | 6 | * (see COPYING for full license text) |
7 | */ | 7 | */ |
8 | 8 | ||
9 | #include "cgit.h" | 9 | #include "cgit.h" |
10 | #include "html.h" | 10 | #include "html.h" |
11 | #include "ui-shared.h" | 11 | #include "ui-shared.h" |
12 | 12 | ||
13 | int files, add_lines, rem_lines; | 13 | int files, add_lines, rem_lines; |
14 | 14 | ||
15 | void count_lines(char *line, int size) | 15 | void count_lines(char *line, int size) |
16 | { | 16 | { |
17 | if (size <= 0) | 17 | if (size <= 0) |
18 | return; | 18 | return; |
19 | 19 | ||
20 | if (line[0] == '+') | 20 | if (line[0] == '+') |
21 | add_lines++; | 21 | add_lines++; |
22 | 22 | ||
23 | else if (line[0] == '-') | 23 | else if (line[0] == '-') |
24 | rem_lines++; | 24 | rem_lines++; |
25 | } | 25 | } |
26 | 26 | ||
27 | void inspect_files(struct diff_filepair *pair) | 27 | void inspect_files(struct diff_filepair *pair) |
28 | { | 28 | { |
29 | files++; | 29 | files++; |
30 | if (ctx.repo->enable_log_linecount) | 30 | if (ctx.repo->enable_log_linecount) |
31 | cgit_diff_files(pair->one->sha1, pair->two->sha1, count_lines); | 31 | cgit_diff_files(pair->one->sha1, pair->two->sha1, count_lines); |
32 | } | 32 | } |
33 | 33 | ||
34 | void print_commit(struct commit *commit) | 34 | void print_commit(struct commit *commit) |
35 | { | 35 | { |
36 | struct commitinfo *info; | 36 | struct commitinfo *info; |
37 | char *tmp; | 37 | char *tmp; |
38 | 38 | ||
39 | info = cgit_parse_commit(commit); | 39 | info = cgit_parse_commit(commit); |
40 | html("<tr><td>"); | 40 | html("<tr><td>"); |
41 | tmp = fmt("id=%s", sha1_to_hex(commit->object.sha1)); | 41 | tmp = fmt("id=%s", sha1_to_hex(commit->object.sha1)); |
42 | tmp = cgit_pageurl(ctx.repo->url, "commit", tmp); | 42 | tmp = cgit_pageurl(ctx.repo->url, "commit", tmp); |
43 | html_link_open(tmp, NULL, NULL); | 43 | html_link_open(tmp, NULL, NULL); |
44 | cgit_print_age(commit->date, TM_WEEK * 2, FMT_SHORTDATE); | 44 | cgit_print_age(commit->date, TM_WEEK * 2, FMT_SHORTDATE); |
45 | html_link_close(); | 45 | html_link_close(); |
46 | html("</td><td>"); | 46 | html("</td><td>"); |
47 | cgit_commit_link(info->subject, NULL, NULL, ctx.qry.head, | 47 | cgit_commit_link(info->subject, NULL, NULL, ctx.qry.head, |
48 | sha1_to_hex(commit->object.sha1)); | 48 | sha1_to_hex(commit->object.sha1)); |
49 | html("</td><td>"); | 49 | html("</td><td>"); |
50 | html_txt(info->author); | 50 | html_txt(info->author); |
51 | if (ctx.repo->enable_log_filecount) { | 51 | if (ctx.repo->enable_log_filecount) { |
52 | files = 0; | 52 | files = 0; |
53 | add_lines = 0; | 53 | add_lines = 0; |
54 | rem_lines = 0; | 54 | rem_lines = 0; |
55 | cgit_diff_commit(commit, inspect_files); | 55 | cgit_diff_commit(commit, inspect_files); |
56 | html("</td><td>"); | 56 | html("</td><td>"); |
57 | htmlf("%d", files); | 57 | htmlf("%d", files); |
58 | if (ctx.repo->enable_log_linecount) { | 58 | if (ctx.repo->enable_log_linecount) { |
59 | html("</td><td>"); | 59 | html("</td><td>"); |
60 | htmlf("-%d/+%d", rem_lines, add_lines); | 60 | htmlf("-%d/+%d", rem_lines, add_lines); |
61 | } | 61 | } |
62 | } | 62 | } |
63 | html("</td></tr>\n"); | 63 | html("</td></tr>\n"); |
64 | cgit_free_commitinfo(info); | 64 | cgit_free_commitinfo(info); |
65 | } | 65 | } |
66 | 66 | ||
67 | static const char *disambiguate_ref(const char *ref) | ||
68 | { | ||
69 | unsigned char sha1[20]; | ||
70 | const char *longref; | ||
71 | |||
72 | longref = fmt("refs/heads/%s", ref); | ||
73 | if (get_sha1(longref, sha1) == 0) | ||
74 | return longref; | ||
75 | |||
76 | return ref; | ||
77 | } | ||
67 | 78 | ||
68 | void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern, | 79 | void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern, |
69 | char *path, int pager) | 80 | char *path, int pager) |
70 | { | 81 | { |
71 | struct rev_info rev; | 82 | struct rev_info rev; |
72 | struct commit *commit; | 83 | struct commit *commit; |
73 | const char *argv[] = {NULL, tip, NULL, NULL, NULL}; | 84 | const char *argv[] = {NULL, NULL, NULL, NULL, NULL}; |
74 | int argc = 2; | 85 | int argc = 2; |
75 | int i, columns = 3; | 86 | int i, columns = 3; |
76 | 87 | ||
77 | if (!tip) | 88 | if (!tip) |
78 | argv[1] = ctx.qry.head; | 89 | tip = ctx.qry.head; |
90 | |||
91 | argv[1] = disambiguate_ref(tip); | ||
79 | 92 | ||
80 | if (grep && pattern && (!strcmp(grep, "grep") || | 93 | if (grep && pattern && (!strcmp(grep, "grep") || |
81 | !strcmp(grep, "author") || | 94 | !strcmp(grep, "author") || |
82 | !strcmp(grep, "committer"))) | 95 | !strcmp(grep, "committer"))) |
83 | argv[argc++] = fmt("--%s=%s", grep, pattern); | 96 | argv[argc++] = fmt("--%s=%s", grep, pattern); |
84 | 97 | ||
85 | if (path) { | 98 | if (path) { |
86 | argv[argc++] = "--"; | 99 | argv[argc++] = "--"; |
87 | argv[argc++] = path; | 100 | argv[argc++] = path; |
88 | } | 101 | } |
89 | init_revisions(&rev, NULL); | 102 | init_revisions(&rev, NULL); |
90 | rev.abbrev = DEFAULT_ABBREV; | 103 | rev.abbrev = DEFAULT_ABBREV; |
91 | rev.commit_format = CMIT_FMT_DEFAULT; | 104 | rev.commit_format = CMIT_FMT_DEFAULT; |
92 | rev.verbose_header = 1; | 105 | rev.verbose_header = 1; |
93 | rev.show_root_diff = 0; | 106 | rev.show_root_diff = 0; |
94 | setup_revisions(argc, argv, &rev, NULL); | 107 | setup_revisions(argc, argv, &rev, NULL); |
95 | rev.grep_filter.regflags |= REG_ICASE; | 108 | rev.grep_filter.regflags |= REG_ICASE; |
96 | compile_grep_patterns(&rev.grep_filter); | 109 | compile_grep_patterns(&rev.grep_filter); |
97 | prepare_revision_walk(&rev); | 110 | prepare_revision_walk(&rev); |
98 | 111 | ||
99 | if (pager) | 112 | if (pager) |
100 | html("<table class='list nowrap'>"); | 113 | html("<table class='list nowrap'>"); |
101 | 114 | ||
102 | html("<tr class='nohover'><th class='left'>Age</th>" | 115 | html("<tr class='nohover'><th class='left'>Age</th>" |
103 | "<th class='left'>Commit message</th>" | 116 | "<th class='left'>Commit message</th>" |
104 | "<th class='left'>Author</th>"); | 117 | "<th class='left'>Author</th>"); |
105 | if (ctx.repo->enable_log_filecount) { | 118 | if (ctx.repo->enable_log_filecount) { |
106 | html("<th class='left'>Files</th>"); | 119 | html("<th class='left'>Files</th>"); |
107 | columns++; | 120 | columns++; |
108 | if (ctx.repo->enable_log_linecount) { | 121 | if (ctx.repo->enable_log_linecount) { |
109 | html("<th class='left'>Lines</th>"); | 122 | html("<th class='left'>Lines</th>"); |
110 | columns++; | 123 | columns++; |
111 | } | 124 | } |
112 | } | 125 | } |
113 | html("</tr>\n"); | 126 | html("</tr>\n"); |
114 | 127 | ||
115 | if (ofs<0) | 128 | if (ofs<0) |
116 | ofs = 0; | 129 | ofs = 0; |
117 | 130 | ||
118 | for (i = 0; i < ofs && (commit = get_revision(&rev)) != NULL; i++) { | 131 | for (i = 0; i < ofs && (commit = get_revision(&rev)) != NULL; i++) { |
119 | free(commit->buffer); | 132 | free(commit->buffer); |
120 | commit->buffer = NULL; | 133 | commit->buffer = NULL; |
121 | free_commit_list(commit->parents); | 134 | free_commit_list(commit->parents); |
122 | commit->parents = NULL; | 135 | commit->parents = NULL; |
123 | } | 136 | } |
124 | 137 | ||
125 | for (i = 0; i < cnt && (commit = get_revision(&rev)) != NULL; i++) { | 138 | for (i = 0; i < cnt && (commit = get_revision(&rev)) != NULL; i++) { |
126 | print_commit(commit); | 139 | print_commit(commit); |
127 | free(commit->buffer); | 140 | free(commit->buffer); |
128 | commit->buffer = NULL; | 141 | commit->buffer = NULL; |
129 | free_commit_list(commit->parents); | 142 | free_commit_list(commit->parents); |
130 | commit->parents = NULL; | 143 | commit->parents = NULL; |
131 | } | 144 | } |
132 | if (pager) { | 145 | if (pager) { |
133 | htmlf("</table><div class='pager'>", | 146 | htmlf("</table><div class='pager'>", |
134 | columns); | 147 | columns); |
135 | if (ofs > 0) { | 148 | if (ofs > 0) { |
136 | cgit_log_link("[prev]", NULL, NULL, ctx.qry.head, | 149 | cgit_log_link("[prev]", NULL, NULL, ctx.qry.head, |
137 | ctx.qry.sha1, ctx.qry.path, | 150 | ctx.qry.sha1, ctx.qry.path, |
138 | ofs - cnt, ctx.qry.grep, | 151 | ofs - cnt, ctx.qry.grep, |
139 | ctx.qry.search); | 152 | ctx.qry.search); |
140 | html(" "); | 153 | html(" "); |
141 | } | 154 | } |
142 | if ((commit = get_revision(&rev)) != NULL) { | 155 | if ((commit = get_revision(&rev)) != NULL) { |
143 | cgit_log_link("[next]", NULL, NULL, ctx.qry.head, | 156 | cgit_log_link("[next]", NULL, NULL, ctx.qry.head, |
144 | ctx.qry.sha1, ctx.qry.path, | 157 | ctx.qry.sha1, ctx.qry.path, |
145 | ofs + cnt, ctx.qry.grep, | 158 | ofs + cnt, ctx.qry.grep, |
146 | ctx.qry.search); | 159 | ctx.qry.search); |
147 | } | 160 | } |
148 | html("</div>"); | 161 | html("</div>"); |
149 | } else if ((commit = get_revision(&rev)) != NULL) { | 162 | } else if ((commit = get_revision(&rev)) != NULL) { |
150 | html("<tr class='nohover'><td colspan='3'>"); | 163 | html("<tr class='nohover'><td colspan='3'>"); |
151 | cgit_log_link("[...]", NULL, NULL, ctx.qry.head, NULL, NULL, 0, | 164 | cgit_log_link("[...]", NULL, NULL, ctx.qry.head, NULL, NULL, 0, |
152 | NULL, NULL); | 165 | NULL, NULL); |
153 | html("</td></tr>\n"); | 166 | html("</td></tr>\n"); |
154 | } | 167 | } |
155 | } | 168 | } |