]>
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
);
68 void cgit_print_log(const char *tip
, int ofs
, int cnt
, char *grep
, char *pattern
,
69 char *path
, int pager
)
72 struct commit
*commit
;
73 const char *argv
[] = {NULL
, tip
, NULL
, NULL
, NULL
};
78 argv
[1] = ctx
.qry
.head
;
80 if (grep
&& pattern
&& (!strcmp(grep
, "grep") ||
81 !strcmp(grep
, "author") ||
82 !strcmp(grep
, "committer")))
83 argv
[argc
++] = fmt("--%s=%s", grep
, pattern
);
89 init_revisions(&rev
, NULL
);
90 rev
.abbrev
= DEFAULT_ABBREV
;
91 rev
.commit_format
= CMIT_FMT_DEFAULT
;
92 rev
.verbose_header
= 1;
93 rev
.show_root_diff
= 0;
94 setup_revisions(argc
, argv
, &rev
, NULL
);
95 rev
.grep_filter
.regflags
|= REG_ICASE
;
96 compile_grep_patterns(&rev
.grep_filter
);
97 prepare_revision_walk(&rev
);
100 html("<table class='list nowrap'>");
102 html("<tr class='nohover'><th class='left'>Age</th>"
103 "<th class='left'>Commit message</th>"
104 "<th class='left'>Author</th>");
105 if (ctx
.repo
->enable_log_filecount
) {
106 html("<th class='left'>Files</th>");
108 if (ctx
.repo
->enable_log_linecount
) {
109 html("<th class='left'>Lines</th>");
118 for (i
= 0; i
< ofs
&& (commit
= get_revision(&rev
)) != NULL
; i
++) {
119 free(commit
->buffer
);
120 commit
->buffer
= NULL
;
121 free_commit_list(commit
->parents
);
122 commit
->parents
= NULL
;
125 for (i
= 0; i
< cnt
&& (commit
= get_revision(&rev
)) != NULL
; i
++) {
126 print_commit(commit
);
127 free(commit
->buffer
);
128 commit
->buffer
= NULL
;
129 free_commit_list(commit
->parents
);
130 commit
->parents
= NULL
;
133 htmlf("</table><div class='pager'>",
136 cgit_log_link("[prev]", NULL
, NULL
, ctx
.qry
.head
,
137 ctx
.qry
.sha1
, ctx
.qry
.path
,
138 ofs
- cnt
, ctx
.qry
.grep
,
142 if ((commit
= get_revision(&rev
)) != NULL
) {
143 cgit_log_link("[next]", NULL
, NULL
, ctx
.qry
.head
,
144 ctx
.qry
.sha1
, ctx
.qry
.path
,
145 ofs
+ cnt
, ctx
.qry
.grep
,
149 } else if ((commit
= get_revision(&rev
)) != NULL
) {
150 html("<tr class='nohover'><td colspan='3'>");
151 cgit_log_link("[...]", NULL
, NULL
, ctx
.qry
.head
, NULL
, NULL
, 0,
153 html("</td></tr>\n");