1 /* Copyright (c) 2006-2014 Jonas Fonseca <jonas.fonseca@gmail.com>
3 * This program is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU General Public License as
5 * published by the Free Software Foundation; either version 2 of
6 * the License, or (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
14 #include "tig/refdb.h"
15 #include "tig/display.h"
19 #include "tig/pager.h"
22 /* Used for tracking when we need to recalculate the previous
23 * commit, for example when the user scrolls up or uses the page
24 * up/down in the log view. */
26 enum line_type last_type
;
27 bool commit_title_read
;
28 bool after_commit_header
;
29 bool reading_diff_stat
;
33 log_select(struct view
*view
, struct line
*line
)
35 struct log_state
*state
= view
->private;
36 int last_lineno
= state
->last_lineno
;
38 if (!last_lineno
|| abs(last_lineno
- line
->lineno
) > 1
39 || (state
->last_type
== LINE_COMMIT
&& last_lineno
> line
->lineno
)) {
40 const struct line
*commit_line
= find_prev_line_by_type(view
, line
, LINE_COMMIT
);
43 string_copy_rev_from_commit_line(view
->ref
, commit_line
->data
);
46 if (line
->type
== LINE_COMMIT
&& !view_has_flags(view
, VIEW_NO_REF
)) {
47 string_copy_rev_from_commit_line(view
->ref
, (char *)line
->data
);
49 string_copy_rev(view
->env
->commit
, view
->ref
);
50 state
->last_lineno
= line
->lineno
;
51 state
->last_type
= line
->type
;
55 log_open(struct view
*view
, enum open_flags flags
)
57 const char *log_argv
[] = {
58 "git", "log", encoding_arg
, commit_order_arg(), "--cc",
59 "--stat", "%(cmdlineargs)", "%(revargs)", "--no-color",
60 "--", "%(fileargs)", NULL
63 if (!pager_column_init(view
))
65 return begin_update(view
, NULL
, log_argv
, flags
);
69 log_request(struct view
*view
, enum request request
, struct line
*line
)
78 if (!display
[1] || strcmp(display
[1]->vid
, view
->ref
))
79 open_diff_view(view
, OPEN_SPLIT
);
88 log_read(struct view
*view
, char *data
)
91 struct log_state
*state
= view
->private;
97 type
= get_line_type(data
);
100 if (type
== LINE_COMMIT
)
101 state
->commit_title_read
= TRUE
;
102 else if (state
->commit_title_read
&& len
< 1) {
103 state
->commit_title_read
= FALSE
;
104 state
->after_commit_header
= TRUE
;
105 } else if (state
->after_commit_header
&& len
< 1) {
106 state
->after_commit_header
= FALSE
;
107 state
->reading_diff_stat
= TRUE
;
108 } else if (state
->reading_diff_stat
) {
109 if (diff_common_add_diff_stat(view
, data
))
111 state
->reading_diff_stat
= FALSE
;
114 return pager_common_read(view
, data
, type
);
118 log_draw(struct view
*view
, struct line
*line
, unsigned int lineno
)
120 char *text
= line
->data
;
121 enum line_type type
= line
->type
;
122 struct view_column
*column
= get_view_column(view
, VIEW_COLUMN_LINE_NUMBER
);
124 if (column
&& (type
== LINE_DIFF_STAT
) && draw_lineno(view
, column
, lineno
))
127 if (type
== LINE_DIFF_STAT
) {
128 diff_common_draw_diff_stat(view
, &type
, &text
);
129 draw_text(view
, type
, text
);
133 return view_column_draw(view
, line
, lineno
);
136 static struct view_ops log_ops
= {
139 VIEW_ADD_PAGER_REFS
| VIEW_OPEN_DIFF
| VIEW_SEND_CHILD_ENTER
| VIEW_LOG_LIKE
| VIEW_REFRESH
,
140 sizeof(struct log_state
),
148 pager_get_column_data
,
153 /* vim: set ts=8 sw=8 noexpandtab: */