]>
git.cameronkatri.com Git - cgit.git/blob - ui-log.c
1 /* ui-log.c: functions for log output
3 * Copyright (C) 2006 Lars Hjemli
5 * Licensed under GNU General Public License v2
6 * (see COPYING for full license text)
11 #include "ui-shared.h"
13 int files
, add_lines
, rem_lines
;
15 void count_lines(char *line
, int size
)
23 else if (line
[0] == '-')
27 void inspect_files(struct diff_filepair
*pair
)
30 if (ctx
.repo
->enable_log_linecount
)
31 cgit_diff_files(pair
->one
->sha1
, pair
->two
->sha1
, count_lines
);
34 void print_commit(struct commit
*commit
)
36 struct commitinfo
*info
;
39 info
= cgit_parse_commit(commit
);
41 tmp
= fmt("id=%s", sha1_to_hex(commit
->object
.sha1
));
42 tmp
= cgit_pageurl(ctx
.repo
->url
, "commit", tmp
);
43 html_link_open(tmp
, NULL
, NULL
);
44 cgit_print_age(commit
->date
, TM_WEEK
* 2, FMT_SHORTDATE
);
47 cgit_commit_link(info
->subject
, NULL
, NULL
, ctx
.qry
.head
,
48 sha1_to_hex(commit
->object
.sha1
));
50 html_txt(info
->author
);
51 if (ctx
.repo
->enable_log_filecount
) {
55 cgit_diff_commit(commit
, inspect_files
);
58 if (ctx
.repo
->enable_log_linecount
) {
60 htmlf("-%d/+%d", rem_lines
, add_lines
);
64 cgit_free_commitinfo(info
);
67 static const char *disambiguate_ref(const char *ref
)
69 unsigned char sha1
[20];
72 longref
= fmt("refs/heads/%s", ref
);
73 if (get_sha1(longref
, sha1
) == 0)
79 void cgit_print_log(const char *tip
, int ofs
, int cnt
, char *grep
, char *pattern
,
80 char *path
, int pager
)
83 struct commit
*commit
;
84 const char *argv
[] = {NULL
, NULL
, NULL
, NULL
, NULL
};
91 argv
[1] = disambiguate_ref(tip
);
93 if (grep
&& pattern
&& (!strcmp(grep
, "grep") ||
94 !strcmp(grep
, "author") ||
95 !strcmp(grep
, "committer")))
96 argv
[argc
++] = fmt("--%s=%s", grep
, pattern
);
102 init_revisions(&rev
, NULL
);
103 rev
.abbrev
= DEFAULT_ABBREV
;
104 rev
.commit_format
= CMIT_FMT_DEFAULT
;
105 rev
.verbose_header
= 1;
106 rev
.show_root_diff
= 0;
107 setup_revisions(argc
, argv
, &rev
, NULL
);
108 rev
.grep_filter
.regflags
|= REG_ICASE
;
109 compile_grep_patterns(&rev
.grep_filter
);
110 prepare_revision_walk(&rev
);
113 html("<table class='list nowrap'>");
115 html("<tr class='nohover'><th class='left'>Age</th>"
116 "<th class='left'>Commit message</th>"
117 "<th class='left'>Author</th>");
118 if (ctx
.repo
->enable_log_filecount
) {
119 html("<th class='left'>Files</th>");
121 if (ctx
.repo
->enable_log_linecount
) {
122 html("<th class='left'>Lines</th>");
131 for (i
= 0; i
< ofs
&& (commit
= get_revision(&rev
)) != NULL
; i
++) {
132 free(commit
->buffer
);
133 commit
->buffer
= NULL
;
134 free_commit_list(commit
->parents
);
135 commit
->parents
= NULL
;
138 for (i
= 0; i
< cnt
&& (commit
= get_revision(&rev
)) != NULL
; i
++) {
139 print_commit(commit
);
140 free(commit
->buffer
);
141 commit
->buffer
= NULL
;
142 free_commit_list(commit
->parents
);
143 commit
->parents
= NULL
;
146 htmlf("</table><div class='pager'>",
149 cgit_log_link("[prev]", NULL
, NULL
, ctx
.qry
.head
,
150 ctx
.qry
.sha1
, ctx
.qry
.path
,
151 ofs
- cnt
, ctx
.qry
.grep
,
155 if ((commit
= get_revision(&rev
)) != NULL
) {
156 cgit_log_link("[next]", NULL
, NULL
, ctx
.qry
.head
,
157 ctx
.qry
.sha1
, ctx
.qry
.path
,
158 ofs
+ cnt
, ctx
.qry
.grep
,
162 } else if ((commit
= get_revision(&rev
)) != NULL
) {
163 html("<tr class='nohover'><td colspan='3'>");
164 cgit_log_link("[...]", NULL
, NULL
, ctx
.qry
.head
, NULL
, NULL
, 0,
166 html("</td></tr>\n");