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.
15 #include "tig/options.h"
16 #include "tig/parse.h"
17 #include "tig/display.h"
28 const struct ident
*author
; /* Author of the last commit. */
29 struct time time
; /* Date of the last activity. */
30 char title
[128]; /* First line of the commit message. */
31 const struct ref
*ref
; /* Name and commit ID information. */
34 static const struct ref
*refs_all
;
35 #define REFS_ALL_NAME "All references"
36 #define refs_is_all(reference) ((reference)->ref == refs_all)
39 refs_get_column_data(struct view
*view
, const struct line
*line
, struct view_column_data
*column_data
)
41 const struct reference
*reference
= line
->data
;
43 column_data
->author
= reference
->author
;
44 column_data
->date
= &reference
->time
;
45 column_data
->id
= reference
->ref
->id
;
46 column_data
->ref
= reference
->ref
;
47 column_data
->commit_title
= reference
->title
;
53 refs_request(struct view
*view
, enum request request
, struct line
*line
)
55 struct reference
*reference
= line
->data
;
65 const struct ref
*ref
= reference
->ref
;
66 const char *all_references_argv
[] = {
67 GIT_MAIN_LOG_CUSTOM(encoding_arg
, commit_order_arg(), "",
68 refs_is_all(reference
) ? "--all" : ref
->name
, "")
71 open_argv(view
, &main_view
, all_references_argv
, NULL
, OPEN_SPLIT
);
80 refs_read(struct view
*view
, struct buffer
*buf
)
82 struct reference
template = {};
93 author
= io_memchr(buf
, buf
->data
, 0);
94 title
= io_memchr(buf
, author
, 0);
97 parse_author_line(author
, &template.author
, &template.time
);
99 for (i
= 0; i
< view
->lines
; i
++) {
100 struct reference
*reference
= view
->line
[i
].data
;
102 if (strcmp(reference
->ref
->id
, buf
->data
))
105 reference
->author
= template.author
;
106 reference
->time
= template.time
;
109 string_expand(reference
->title
, sizeof(reference
->title
), title
, 1);
111 view
->line
[i
].dirty
= TRUE
;
112 view_column_info_update(view
, &view
->line
[i
]);
119 refs_open_visitor(void *data
, const struct ref
*ref
)
121 struct view
*view
= data
;
122 struct reference
*reference
;
123 bool is_all
= ref
== refs_all
;
126 line
= add_line_alloc(view
, &reference
, LINE_DEFAULT
, 0, is_all
);
130 reference
->ref
= ref
;
131 view_column_info_update(view
, line
);
137 refs_open(struct view
*view
, enum open_flags flags
)
139 const char *refs_log
[] = {
140 "git", "log", encoding_arg
, "--no-color", "--date=raw",
141 "--pretty=format:%H%x00%an <%ae> %ad%x00%s",
142 "--all", "--simplify-by-decoration", NULL
146 struct ref
*ref
= calloc(1, sizeof(*refs_all
) + strlen(REFS_ALL_NAME
));
149 strncpy(ref
->name
, REFS_ALL_NAME
, strlen(REFS_ALL_NAME
));
154 if (!refs_all
|| !begin_update(view
, NULL
, refs_log
, OPEN_RELOAD
)) {
155 report("Failed to load reference data");
159 refs_open_visitor(view
, refs_all
);
160 foreach_ref(refs_open_visitor
, view
);
162 watch_register(&view
->watch
, WATCH_HEAD
| WATCH_REFS
);
168 refs_select(struct view
*view
, struct line
*line
)
170 struct reference
*reference
= line
->data
;
172 if (refs_is_all(reference
)) {
173 string_copy(view
->ref
, REFS_ALL_NAME
);
176 string_copy_rev(view
->ref
, reference
->ref
->id
);
177 string_copy_rev(view
->env
->head
, reference
->ref
->id
);
178 string_ncopy(view
->env
->ref
, reference
->ref
->name
, strlen(reference
->ref
->name
));
179 ref_update_env(view
->env
, reference
->ref
, TRUE
);
182 static struct view_ops refs_ops
= {
185 VIEW_REFRESH
| VIEW_SORTABLE
,
194 view_column_bit(AUTHOR
) | view_column_bit(COMMIT_TITLE
) |
195 view_column_bit(DATE
) | view_column_bit(ID
) |
196 view_column_bit(LINE_NUMBER
) | view_column_bit(REF
),
197 refs_get_column_data
,
202 /* vim: set ts=8 sw=8 noexpandtab: */