2 5aa81393 2020-01-06 stsp * Copyright (c) 2018, 2019, 2020 Stefan Sperling <stsp@openbsd.org>
4 9f7d7167 2018-04-29 stsp * Permission to use, copy, modify, and distribute this software for any
5 9f7d7167 2018-04-29 stsp * purpose with or without fee is hereby granted, provided that the above
6 9f7d7167 2018-04-29 stsp * copyright notice and this permission notice appear in all copies.
8 9f7d7167 2018-04-29 stsp * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 9f7d7167 2018-04-29 stsp * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 9f7d7167 2018-04-29 stsp * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 9f7d7167 2018-04-29 stsp * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 9f7d7167 2018-04-29 stsp * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 9f7d7167 2018-04-29 stsp * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 9f7d7167 2018-04-29 stsp * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 80ddbec8 2018-04-29 stsp #include <sys/queue.h>
18 ffd1d5e5 2018-06-23 stsp #include <sys/stat.h>
19 25791caa 2018-10-24 stsp #include <sys/ioctl.h>
21 0d6c6ee3 2020-05-20 stsp #include <ctype.h>
22 31120ada 2018-04-30 stsp #include <errno.h>
23 6062e8ea 2021-09-21 stsp #define _XOPEN_SOURCE_EXTENDED /* for ncurses wide-character functions */
24 9f7d7167 2018-04-29 stsp #include <curses.h>
25 9f7d7167 2018-04-29 stsp #include <panel.h>
26 9f7d7167 2018-04-29 stsp #include <locale.h>
27 d7b5a0e8 2022-04-20 stsp #include <sha1.h>
28 61266923 2020-01-14 stsp #include <signal.h>
29 9f7d7167 2018-04-29 stsp #include <stdlib.h>
30 ee85c5e8 2020-02-29 stsp #include <stdarg.h>
31 26ed57b2 2018-05-19 stsp #include <stdio.h>
32 9f7d7167 2018-04-29 stsp #include <getopt.h>
33 9f7d7167 2018-04-29 stsp #include <string.h>
34 9f7d7167 2018-04-29 stsp #include <err.h>
35 80ddbec8 2018-04-29 stsp #include <unistd.h>
36 26ed57b2 2018-05-19 stsp #include <limits.h>
37 61e69b96 2018-05-20 stsp #include <wchar.h>
38 788c352e 2018-06-16 stsp #include <time.h>
39 84451b3e 2018-07-10 stsp #include <pthread.h>
40 5036bf37 2018-09-24 stsp #include <libgen.h>
41 60493ae3 2019-06-20 stsp #include <regex.h>
42 3da8ef85 2021-09-21 stsp #include <sched.h>
44 53ccebc2 2019-07-30 stsp #include "got_version.h"
45 9f7d7167 2018-04-29 stsp #include "got_error.h"
46 80ddbec8 2018-04-29 stsp #include "got_object.h"
47 80ddbec8 2018-04-29 stsp #include "got_reference.h"
48 80ddbec8 2018-04-29 stsp #include "got_repository.h"
49 80ddbec8 2018-04-29 stsp #include "got_diff.h"
50 511a516b 2018-05-19 stsp #include "got_opentemp.h"
51 00dfcb92 2018-06-11 stsp #include "got_utf8.h"
52 6fb7cd11 2019-08-22 stsp #include "got_cancel.h"
53 6fb7cd11 2019-08-22 stsp #include "got_commit_graph.h"
54 a70480e0 2018-06-23 stsp #include "got_blame.h"
55 c2db6724 2019-01-04 stsp #include "got_privsep.h"
56 1dd54920 2019-05-11 stsp #include "got_path.h"
57 b7165be3 2019-02-05 stsp #include "got_worktree.h"
60 881b2d3e 2018-04-30 stsp #define MIN(_a,_b) ((_a) < (_b) ? (_a) : (_b))
64 2bd27830 2018-10-22 stsp #define MAX(_a,_b) ((_a) > (_b) ? (_a) : (_b))
67 a4292ac5 2019-05-12 jcs #define CTRL(x) ((x) & 0x1f)
69 9f7d7167 2018-04-29 stsp #ifndef nitems
70 9f7d7167 2018-04-29 stsp #define nitems(_a) (sizeof((_a)) / sizeof((_a)[0]))
73 9f7d7167 2018-04-29 stsp struct tog_cmd {
74 c2301be8 2018-04-30 stsp const char *name;
75 9f7d7167 2018-04-29 stsp const struct got_error *(*cmd_main)(int, char *[]);
76 9f7d7167 2018-04-29 stsp void (*cmd_usage)(void);
79 6879ba42 2020-10-01 naddy __dead static void usage(int, int);
80 4ed7e80c 2018-05-20 stsp __dead static void usage_log(void);
81 4ed7e80c 2018-05-20 stsp __dead static void usage_diff(void);
82 4ed7e80c 2018-05-20 stsp __dead static void usage_blame(void);
83 ffd1d5e5 2018-06-23 stsp __dead static void usage_tree(void);
84 6458efa5 2020-11-24 stsp __dead static void usage_ref(void);
86 4ed7e80c 2018-05-20 stsp static const struct got_error* cmd_log(int, char *[]);
87 4ed7e80c 2018-05-20 stsp static const struct got_error* cmd_diff(int, char *[]);
88 4ed7e80c 2018-05-20 stsp static const struct got_error* cmd_blame(int, char *[]);
89 ffd1d5e5 2018-06-23 stsp static const struct got_error* cmd_tree(int, char *[]);
90 6458efa5 2020-11-24 stsp static const struct got_error* cmd_ref(int, char *[]);
92 3e166534 2022-02-16 naddy static const struct tog_cmd tog_commands[] = {
93 5e070240 2019-06-22 stsp { "log", cmd_log, usage_log },
94 5e070240 2019-06-22 stsp { "diff", cmd_diff, usage_diff },
95 5e070240 2019-06-22 stsp { "blame", cmd_blame, usage_blame },
96 5e070240 2019-06-22 stsp { "tree", cmd_tree, usage_tree },
97 6458efa5 2020-11-24 stsp { "ref", cmd_ref, usage_ref },
100 d6b05b5b 2018-08-04 stsp enum tog_view_type {
101 d6b05b5b 2018-08-04 stsp TOG_VIEW_DIFF,
102 d6b05b5b 2018-08-04 stsp TOG_VIEW_LOG,
103 ad80ab7b 2018-08-04 stsp TOG_VIEW_BLAME,
104 6458efa5 2020-11-24 stsp TOG_VIEW_TREE,
105 6458efa5 2020-11-24 stsp TOG_VIEW_REF,
106 ec2a9698 2022-09-15 mark TOG_VIEW_HELP
109 ec2a9698 2022-09-15 mark /* Match _DIFF to _HELP with enum tog_view_type TOG_VIEW_* counterparts. */
110 ec2a9698 2022-09-15 mark enum tog_keymap_type {
111 ec2a9698 2022-09-15 mark TOG_KEYMAP_KEYS = -2,
112 ec2a9698 2022-09-15 mark TOG_KEYMAP_GLOBAL,
113 ec2a9698 2022-09-15 mark TOG_KEYMAP_DIFF,
114 ec2a9698 2022-09-15 mark TOG_KEYMAP_LOG,
115 ec2a9698 2022-09-15 mark TOG_KEYMAP_BLAME,
116 ec2a9698 2022-09-15 mark TOG_KEYMAP_TREE,
117 ec2a9698 2022-09-15 mark TOG_KEYMAP_REF,
118 ec2a9698 2022-09-15 mark TOG_KEYMAP_HELP
121 9b058f45 2022-06-30 mark enum tog_view_mode {
122 9b058f45 2022-06-30 mark TOG_VIEW_SPLIT_NONE,
123 9b058f45 2022-06-30 mark TOG_VIEW_SPLIT_VERT,
124 9b058f45 2022-06-30 mark TOG_VIEW_SPLIT_HRZN
127 9b058f45 2022-06-30 mark #define HSPLIT_SCALE 0.3 /* default horizontal split scale */
129 c3e9aa98 2019-05-13 jcs #define TOG_EOF_STRING "(END)"
131 ba4f502b 2018-08-04 stsp struct commit_queue_entry {
132 ba4f502b 2018-08-04 stsp TAILQ_ENTRY(commit_queue_entry) entry;
133 ba4f502b 2018-08-04 stsp struct got_object_id *id;
134 ba4f502b 2018-08-04 stsp struct got_commit_object *commit;
137 ba4f502b 2018-08-04 stsp TAILQ_HEAD(commit_queue_head, commit_queue_entry);
138 ba4f502b 2018-08-04 stsp struct commit_queue {
139 ba4f502b 2018-08-04 stsp int ncommits;
140 ba4f502b 2018-08-04 stsp struct commit_queue_head head;
143 f26dddb7 2019-11-08 stsp struct tog_color {
144 dbdddfee 2021-06-23 naddy STAILQ_ENTRY(tog_color) entry;
145 6d17833f 2019-11-08 stsp regex_t regex;
146 6d17833f 2019-11-08 stsp short colorpair;
148 dbdddfee 2021-06-23 naddy STAILQ_HEAD(tog_colors, tog_color);
150 d9dff0e5 2020-12-26 stsp static struct got_reflist_head tog_refs = TAILQ_HEAD_INITIALIZER(tog_refs);
151 51a10b52 2020-12-26 stsp static struct got_reflist_object_id_map *tog_refs_idmap;
152 917d79a7 2022-07-01 stsp static enum got_diff_algorithm tog_diff_algo = GOT_DIFF_ALGORITHM_MYERS;
154 cc488aa7 2022-01-23 stsp static const struct got_error *
155 cc488aa7 2022-01-23 stsp tog_ref_cmp_by_name(void *arg, int *cmp, struct got_reference *re1,
156 cc488aa7 2022-01-23 stsp struct got_reference* re2)
158 cc488aa7 2022-01-23 stsp const char *name1 = got_ref_get_name(re1);
159 cc488aa7 2022-01-23 stsp const char *name2 = got_ref_get_name(re2);
160 cc488aa7 2022-01-23 stsp int isbackup1, isbackup2;
162 cc488aa7 2022-01-23 stsp /* Sort backup refs towards the bottom of the list. */
163 cc488aa7 2022-01-23 stsp isbackup1 = strncmp(name1, "refs/got/backup/", 16) == 0;
164 cc488aa7 2022-01-23 stsp isbackup2 = strncmp(name2, "refs/got/backup/", 16) == 0;
165 cc488aa7 2022-01-23 stsp if (!isbackup1 && isbackup2) {
167 cc488aa7 2022-01-23 stsp return NULL;
168 cc488aa7 2022-01-23 stsp } else if (isbackup1 && !isbackup2) {
170 cc488aa7 2022-01-23 stsp return NULL;
173 cc488aa7 2022-01-23 stsp *cmp = got_path_cmp(name1, name2, strlen(name1), strlen(name2));
174 cc488aa7 2022-01-23 stsp return NULL;
177 11b20872 2019-11-08 stsp static const struct got_error *
178 7f66531d 2021-11-16 stsp tog_load_refs(struct got_repository *repo, int sort_by_date)
180 51a10b52 2020-12-26 stsp const struct got_error *err;
182 7f66531d 2021-11-16 stsp err = got_ref_list(&tog_refs, repo, NULL, sort_by_date ?
183 cc488aa7 2022-01-23 stsp got_ref_cmp_by_commit_timestamp_descending : tog_ref_cmp_by_name,
186 51a10b52 2020-12-26 stsp return err;
188 51a10b52 2020-12-26 stsp return got_reflist_object_id_map_create(&tog_refs_idmap, &tog_refs,
192 51a10b52 2020-12-26 stsp static void
193 51a10b52 2020-12-26 stsp tog_free_refs(void)
195 51a10b52 2020-12-26 stsp if (tog_refs_idmap) {
196 f193b038 2020-12-26 stsp got_reflist_object_id_map_free(tog_refs_idmap);
197 51a10b52 2020-12-26 stsp tog_refs_idmap = NULL;
199 51a10b52 2020-12-26 stsp got_ref_list_free(&tog_refs);
202 51a10b52 2020-12-26 stsp static const struct got_error *
203 11b20872 2019-11-08 stsp add_color(struct tog_colors *colors, const char *pattern,
204 11b20872 2019-11-08 stsp int idx, short color)
206 11b20872 2019-11-08 stsp const struct got_error *err = NULL;
207 11b20872 2019-11-08 stsp struct tog_color *tc;
208 11b20872 2019-11-08 stsp int regerr = 0;
210 11b20872 2019-11-08 stsp if (idx < 1 || idx > COLOR_PAIRS - 1)
211 11b20872 2019-11-08 stsp return NULL;
213 11b20872 2019-11-08 stsp init_pair(idx, color, -1);
215 11b20872 2019-11-08 stsp tc = calloc(1, sizeof(*tc));
216 11b20872 2019-11-08 stsp if (tc == NULL)
217 11b20872 2019-11-08 stsp return got_error_from_errno("calloc");
218 11b20872 2019-11-08 stsp regerr = regcomp(&tc->regex, pattern,
219 11b20872 2019-11-08 stsp REG_EXTENDED | REG_NOSUB | REG_NEWLINE);
220 11b20872 2019-11-08 stsp if (regerr) {
221 11b20872 2019-11-08 stsp static char regerr_msg[512];
222 11b20872 2019-11-08 stsp static char err_msg[512];
223 11b20872 2019-11-08 stsp regerror(regerr, &tc->regex, regerr_msg,
224 11b20872 2019-11-08 stsp sizeof(regerr_msg));
225 11b20872 2019-11-08 stsp snprintf(err_msg, sizeof(err_msg), "regcomp: %s",
226 11b20872 2019-11-08 stsp regerr_msg);
227 11b20872 2019-11-08 stsp err = got_error_msg(GOT_ERR_REGEX, err_msg);
229 11b20872 2019-11-08 stsp return err;
231 11b20872 2019-11-08 stsp tc->colorpair = idx;
232 dbdddfee 2021-06-23 naddy STAILQ_INSERT_HEAD(colors, tc, entry);
233 11b20872 2019-11-08 stsp return NULL;
236 11b20872 2019-11-08 stsp static void
237 11b20872 2019-11-08 stsp free_colors(struct tog_colors *colors)
239 11b20872 2019-11-08 stsp struct tog_color *tc;
241 dbdddfee 2021-06-23 naddy while (!STAILQ_EMPTY(colors)) {
242 dbdddfee 2021-06-23 naddy tc = STAILQ_FIRST(colors);
243 dbdddfee 2021-06-23 naddy STAILQ_REMOVE_HEAD(colors, entry);
244 11b20872 2019-11-08 stsp regfree(&tc->regex);
249 336075a4 2022-06-25 op static struct tog_color *
250 11b20872 2019-11-08 stsp get_color(struct tog_colors *colors, int colorpair)
252 11b20872 2019-11-08 stsp struct tog_color *tc = NULL;
254 dbdddfee 2021-06-23 naddy STAILQ_FOREACH(tc, colors, entry) {
255 11b20872 2019-11-08 stsp if (tc->colorpair == colorpair)
259 11b20872 2019-11-08 stsp return NULL;
263 11b20872 2019-11-08 stsp default_color_value(const char *envvar)
265 11b20872 2019-11-08 stsp if (strcmp(envvar, "TOG_COLOR_DIFF_MINUS") == 0)
266 11b20872 2019-11-08 stsp return COLOR_MAGENTA;
267 11b20872 2019-11-08 stsp if (strcmp(envvar, "TOG_COLOR_DIFF_PLUS") == 0)
268 11b20872 2019-11-08 stsp return COLOR_CYAN;
269 11b20872 2019-11-08 stsp if (strcmp(envvar, "TOG_COLOR_DIFF_CHUNK_HEADER") == 0)
270 11b20872 2019-11-08 stsp return COLOR_YELLOW;
271 11b20872 2019-11-08 stsp if (strcmp(envvar, "TOG_COLOR_DIFF_META") == 0)
272 11b20872 2019-11-08 stsp return COLOR_GREEN;
273 11b20872 2019-11-08 stsp if (strcmp(envvar, "TOG_COLOR_TREE_SUBMODULE") == 0)
274 11b20872 2019-11-08 stsp return COLOR_MAGENTA;
275 11b20872 2019-11-08 stsp if (strcmp(envvar, "TOG_COLOR_TREE_SYMLINK") == 0)
276 91b8c405 2020-01-25 stsp return COLOR_MAGENTA;
277 11b20872 2019-11-08 stsp if (strcmp(envvar, "TOG_COLOR_TREE_DIRECTORY") == 0)
278 91b8c405 2020-01-25 stsp return COLOR_CYAN;
279 11b20872 2019-11-08 stsp if (strcmp(envvar, "TOG_COLOR_TREE_EXECUTABLE") == 0)
280 11b20872 2019-11-08 stsp return COLOR_GREEN;
281 11b20872 2019-11-08 stsp if (strcmp(envvar, "TOG_COLOR_COMMIT") == 0)
282 11b20872 2019-11-08 stsp return COLOR_GREEN;
283 11b20872 2019-11-08 stsp if (strcmp(envvar, "TOG_COLOR_AUTHOR") == 0)
284 11b20872 2019-11-08 stsp return COLOR_CYAN;
285 11b20872 2019-11-08 stsp if (strcmp(envvar, "TOG_COLOR_DATE") == 0)
286 11b20872 2019-11-08 stsp return COLOR_YELLOW;
287 6458efa5 2020-11-24 stsp if (strcmp(envvar, "TOG_COLOR_REFS_HEADS") == 0)
288 6458efa5 2020-11-24 stsp return COLOR_GREEN;
289 6458efa5 2020-11-24 stsp if (strcmp(envvar, "TOG_COLOR_REFS_TAGS") == 0)
290 6458efa5 2020-11-24 stsp return COLOR_MAGENTA;
291 6458efa5 2020-11-24 stsp if (strcmp(envvar, "TOG_COLOR_REFS_REMOTES") == 0)
292 6458efa5 2020-11-24 stsp return COLOR_YELLOW;
293 cc488aa7 2022-01-23 stsp if (strcmp(envvar, "TOG_COLOR_REFS_BACKUP") == 0)
294 cc488aa7 2022-01-23 stsp return COLOR_CYAN;
300 11b20872 2019-11-08 stsp get_color_value(const char *envvar)
302 11b20872 2019-11-08 stsp const char *val = getenv(envvar);
304 11b20872 2019-11-08 stsp if (val == NULL)
305 11b20872 2019-11-08 stsp return default_color_value(envvar);
307 11b20872 2019-11-08 stsp if (strcasecmp(val, "black") == 0)
308 11b20872 2019-11-08 stsp return COLOR_BLACK;
309 11b20872 2019-11-08 stsp if (strcasecmp(val, "red") == 0)
310 11b20872 2019-11-08 stsp return COLOR_RED;
311 11b20872 2019-11-08 stsp if (strcasecmp(val, "green") == 0)
312 11b20872 2019-11-08 stsp return COLOR_GREEN;
313 11b20872 2019-11-08 stsp if (strcasecmp(val, "yellow") == 0)
314 11b20872 2019-11-08 stsp return COLOR_YELLOW;
315 11b20872 2019-11-08 stsp if (strcasecmp(val, "blue") == 0)
316 11b20872 2019-11-08 stsp return COLOR_BLUE;
317 11b20872 2019-11-08 stsp if (strcasecmp(val, "magenta") == 0)
318 11b20872 2019-11-08 stsp return COLOR_MAGENTA;
319 11b20872 2019-11-08 stsp if (strcasecmp(val, "cyan") == 0)
320 11b20872 2019-11-08 stsp return COLOR_CYAN;
321 11b20872 2019-11-08 stsp if (strcasecmp(val, "white") == 0)
322 11b20872 2019-11-08 stsp return COLOR_WHITE;
323 11b20872 2019-11-08 stsp if (strcasecmp(val, "default") == 0)
326 11b20872 2019-11-08 stsp return default_color_value(envvar);
329 15a087fe 2019-02-21 stsp struct tog_diff_view_state {
330 15a087fe 2019-02-21 stsp struct got_object_id *id1, *id2;
331 3dbaef42 2020-11-24 stsp const char *label1, *label2;
332 b72706c3 2022-06-01 stsp FILE *f, *f1, *f2;
333 f9d37699 2022-06-28 stsp int fd1, fd2;
334 c7d5c43c 2022-08-04 mark int lineno;
335 15a087fe 2019-02-21 stsp int first_displayed_line;
336 15a087fe 2019-02-21 stsp int last_displayed_line;
338 15a087fe 2019-02-21 stsp int diff_context;
339 3dbaef42 2020-11-24 stsp int ignore_whitespace;
340 64453f7e 2020-11-21 stsp int force_text_diff;
341 15a087fe 2019-02-21 stsp struct got_repository *repo;
342 c7d5c43c 2022-08-04 mark struct got_diff_line *lines;
343 fe621944 2020-11-10 stsp size_t nlines;
344 f44b1f58 2020-02-02 tracey int matched_line;
345 f44b1f58 2020-02-02 tracey int selected_line;
347 c0f61fa4 2022-07-11 mark /* passed from log or blame view; may be NULL */
348 c0f61fa4 2022-07-11 mark struct tog_view *parent_view;
351 1a76625f 2018-10-22 stsp pthread_mutex_t tog_mutex = PTHREAD_MUTEX_INITIALIZER;
352 5629093a 2022-07-11 stsp static volatile sig_atomic_t tog_thread_error;
354 1a76625f 2018-10-22 stsp struct tog_log_thread_args {
355 1a76625f 2018-10-22 stsp pthread_cond_t need_commits;
356 7c1452c1 2020-03-26 stsp pthread_cond_t commit_loaded;
357 1a76625f 2018-10-22 stsp int commits_needed;
358 fb280deb 2021-08-30 stsp int load_all;
359 b01e7d3b 2018-08-04 stsp struct got_commit_graph *graph;
360 568eae95 2022-09-11 mark struct commit_queue *real_commits;
361 1a76625f 2018-10-22 stsp const char *in_repo_path;
362 1a76625f 2018-10-22 stsp struct got_object_id *start_id;
363 1a76625f 2018-10-22 stsp struct got_repository *repo;
364 74467cc8 2022-06-15 stsp int *pack_fds;
365 1a76625f 2018-10-22 stsp int log_complete;
366 1a76625f 2018-10-22 stsp sig_atomic_t *quit;
367 1a76625f 2018-10-22 stsp struct commit_queue_entry **first_displayed_entry;
368 1a76625f 2018-10-22 stsp struct commit_queue_entry **selected_entry;
369 13add988 2019-10-15 stsp int *searching;
370 13add988 2019-10-15 stsp int *search_next_done;
371 13add988 2019-10-15 stsp regex_t *regex;
372 568eae95 2022-09-11 mark int *limiting;
373 568eae95 2022-09-11 mark int limit_match;
374 568eae95 2022-09-11 mark regex_t *limit_regex;
375 568eae95 2022-09-11 mark struct commit_queue *limit_commits;
378 1a76625f 2018-10-22 stsp struct tog_log_view_state {
379 568eae95 2022-09-11 mark struct commit_queue *commits;
380 b01e7d3b 2018-08-04 stsp struct commit_queue_entry *first_displayed_entry;
381 b01e7d3b 2018-08-04 stsp struct commit_queue_entry *last_displayed_entry;
382 b01e7d3b 2018-08-04 stsp struct commit_queue_entry *selected_entry;
383 568eae95 2022-09-11 mark struct commit_queue real_commits;
384 b01e7d3b 2018-08-04 stsp int selected;
385 b01e7d3b 2018-08-04 stsp char *in_repo_path;
386 9cd7cbd1 2020-12-07 stsp char *head_ref_name;
387 b672a97a 2020-01-27 stsp int log_branches;
388 b01e7d3b 2018-08-04 stsp struct got_repository *repo;
389 5036bf37 2018-09-24 stsp struct got_object_id *start_id;
390 1a76625f 2018-10-22 stsp sig_atomic_t quit;
391 1a76625f 2018-10-22 stsp pthread_t thread;
392 1a76625f 2018-10-22 stsp struct tog_log_thread_args thread_args;
393 60493ae3 2019-06-20 stsp struct commit_queue_entry *matched_entry;
394 96e2b566 2019-07-08 stsp struct commit_queue_entry *search_entry;
395 11b20872 2019-11-08 stsp struct tog_colors colors;
396 10aab77f 2022-07-19 op int use_committer;
397 568eae95 2022-09-11 mark int limit_view;
398 568eae95 2022-09-11 mark regex_t limit_regex;
399 568eae95 2022-09-11 mark struct commit_queue limit_commits;
402 11b20872 2019-11-08 stsp #define TOG_COLOR_DIFF_MINUS 1
403 11b20872 2019-11-08 stsp #define TOG_COLOR_DIFF_PLUS 2
404 11b20872 2019-11-08 stsp #define TOG_COLOR_DIFF_CHUNK_HEADER 3
405 11b20872 2019-11-08 stsp #define TOG_COLOR_DIFF_META 4
406 11b20872 2019-11-08 stsp #define TOG_COLOR_TREE_SUBMODULE 5
407 11b20872 2019-11-08 stsp #define TOG_COLOR_TREE_SYMLINK 6
408 11b20872 2019-11-08 stsp #define TOG_COLOR_TREE_DIRECTORY 7
409 11b20872 2019-11-08 stsp #define TOG_COLOR_TREE_EXECUTABLE 8
410 11b20872 2019-11-08 stsp #define TOG_COLOR_COMMIT 9
411 11b20872 2019-11-08 stsp #define TOG_COLOR_AUTHOR 10
412 bf30f154 2020-12-07 naddy #define TOG_COLOR_DATE 11
413 6458efa5 2020-11-24 stsp #define TOG_COLOR_REFS_HEADS 12
414 6458efa5 2020-11-24 stsp #define TOG_COLOR_REFS_TAGS 13
415 6458efa5 2020-11-24 stsp #define TOG_COLOR_REFS_REMOTES 14
416 cc488aa7 2022-01-23 stsp #define TOG_COLOR_REFS_BACKUP 15
418 e9424729 2018-08-04 stsp struct tog_blame_cb_args {
419 e9424729 2018-08-04 stsp struct tog_blame_line *lines; /* one per line */
420 e9424729 2018-08-04 stsp int nlines;
422 e9424729 2018-08-04 stsp struct tog_view *view;
423 e9424729 2018-08-04 stsp struct got_object_id *commit_id;
427 e9424729 2018-08-04 stsp struct tog_blame_thread_args {
428 e9424729 2018-08-04 stsp const char *path;
429 e9424729 2018-08-04 stsp struct got_repository *repo;
430 e9424729 2018-08-04 stsp struct tog_blame_cb_args *cb_args;
431 e9424729 2018-08-04 stsp int *complete;
432 fc06ba56 2019-08-22 stsp got_cancel_cb cancel_cb;
433 fc06ba56 2019-08-22 stsp void *cancel_arg;
436 e9424729 2018-08-04 stsp struct tog_blame {
438 be659d10 2020-11-18 stsp off_t filesize;
439 e9424729 2018-08-04 stsp struct tog_blame_line *lines;
440 6fcac457 2018-11-19 stsp int nlines;
441 6c4c42e0 2019-06-24 stsp off_t *line_offsets;
442 e9424729 2018-08-04 stsp pthread_t thread;
443 e9424729 2018-08-04 stsp struct tog_blame_thread_args thread_args;
444 e9424729 2018-08-04 stsp struct tog_blame_cb_args cb_args;
445 e9424729 2018-08-04 stsp const char *path;
446 0ae84acc 2022-06-15 tracey int *pack_fds;
449 7cbe629d 2018-08-04 stsp struct tog_blame_view_state {
450 7cbe629d 2018-08-04 stsp int first_displayed_line;
451 7cbe629d 2018-08-04 stsp int last_displayed_line;
452 7cbe629d 2018-08-04 stsp int selected_line;
453 c0f61fa4 2022-07-11 mark int last_diffed_line;
454 7cbe629d 2018-08-04 stsp int blame_complete;
457 7cbe629d 2018-08-04 stsp struct got_object_id_queue blamed_commits;
458 7cbe629d 2018-08-04 stsp struct got_object_qid *blamed_commit;
459 e5a0f69f 2018-08-18 stsp char *path;
460 7cbe629d 2018-08-04 stsp struct got_repository *repo;
461 ad80ab7b 2018-08-04 stsp struct got_object_id *commit_id;
462 136e2bd4 2022-07-23 mark struct got_object_id *id_to_log;
463 e9424729 2018-08-04 stsp struct tog_blame blame;
464 6c4c42e0 2019-06-24 stsp int matched_line;
465 11b20872 2019-11-08 stsp struct tog_colors colors;
468 ad80ab7b 2018-08-04 stsp struct tog_parent_tree {
469 ad80ab7b 2018-08-04 stsp TAILQ_ENTRY(tog_parent_tree) entry;
470 ad80ab7b 2018-08-04 stsp struct got_tree_object *tree;
471 ad80ab7b 2018-08-04 stsp struct got_tree_entry *first_displayed_entry;
472 ad80ab7b 2018-08-04 stsp struct got_tree_entry *selected_entry;
473 ad80ab7b 2018-08-04 stsp int selected;
476 ad80ab7b 2018-08-04 stsp TAILQ_HEAD(tog_parent_trees, tog_parent_tree);
478 ad80ab7b 2018-08-04 stsp struct tog_tree_view_state {
479 ad80ab7b 2018-08-04 stsp char *tree_label;
480 bc573f3b 2021-07-10 stsp struct got_object_id *commit_id;/* commit which this tree belongs to */
481 bc573f3b 2021-07-10 stsp struct got_tree_object *root; /* the commit's root tree entry */
482 bc573f3b 2021-07-10 stsp struct got_tree_object *tree; /* currently displayed (sub-)tree */
483 ad80ab7b 2018-08-04 stsp struct got_tree_entry *first_displayed_entry;
484 ad80ab7b 2018-08-04 stsp struct got_tree_entry *last_displayed_entry;
485 ad80ab7b 2018-08-04 stsp struct got_tree_entry *selected_entry;
486 416a95c5 2019-01-24 stsp int ndisplayed, selected, show_ids;
487 bc573f3b 2021-07-10 stsp struct tog_parent_trees parents; /* parent trees of current sub-tree */
488 9cd7cbd1 2020-12-07 stsp char *head_ref_name;
489 ad80ab7b 2018-08-04 stsp struct got_repository *repo;
490 7c32bd05 2019-06-22 stsp struct got_tree_entry *matched_entry;
491 6458efa5 2020-11-24 stsp struct tog_colors colors;
494 6458efa5 2020-11-24 stsp struct tog_reflist_entry {
495 6458efa5 2020-11-24 stsp TAILQ_ENTRY(tog_reflist_entry) entry;
496 6458efa5 2020-11-24 stsp struct got_reference *ref;
500 6458efa5 2020-11-24 stsp TAILQ_HEAD(tog_reflist_head, tog_reflist_entry);
502 6458efa5 2020-11-24 stsp struct tog_ref_view_state {
503 dae613fa 2020-12-26 stsp struct tog_reflist_head refs;
504 6458efa5 2020-11-24 stsp struct tog_reflist_entry *first_displayed_entry;
505 6458efa5 2020-11-24 stsp struct tog_reflist_entry *last_displayed_entry;
506 6458efa5 2020-11-24 stsp struct tog_reflist_entry *selected_entry;
507 b4996bee 2022-06-16 stsp int nrefs, ndisplayed, selected, show_date, show_ids, sort_by_date;
508 6458efa5 2020-11-24 stsp struct got_repository *repo;
509 6458efa5 2020-11-24 stsp struct tog_reflist_entry *matched_entry;
510 bddb1296 2019-11-08 stsp struct tog_colors colors;
513 ec2a9698 2022-09-15 mark struct tog_help_view_state {
515 ec2a9698 2022-09-15 mark off_t *line_offsets;
516 ec2a9698 2022-09-15 mark size_t nlines;
517 ec2a9698 2022-09-15 mark int lineno;
518 ec2a9698 2022-09-15 mark int first_displayed_line;
519 ec2a9698 2022-09-15 mark int last_displayed_line;
521 ec2a9698 2022-09-15 mark int matched_line;
522 ec2a9698 2022-09-15 mark int selected_line;
524 ec2a9698 2022-09-15 mark enum tog_keymap_type type;
527 ec2a9698 2022-09-15 mark #define GENERATE_HELP \
528 ec2a9698 2022-09-15 mark KEYMAP_("Global", TOG_KEYMAP_GLOBAL), \
529 ec2a9698 2022-09-15 mark KEY_("H F1", "Open view-specific help (double tap for all help)"), \
530 ec2a9698 2022-09-15 mark KEY_("k C-p Up", "Move cursor or page up one line"), \
531 ec2a9698 2022-09-15 mark KEY_("j C-n Down", "Move cursor or page down one line"), \
532 ec2a9698 2022-09-15 mark KEY_("C-b b PgUp", "Scroll the view up one page"), \
533 ec2a9698 2022-09-15 mark KEY_("C-f f PgDn Space", "Scroll the view down one page"), \
534 ec2a9698 2022-09-15 mark KEY_("C-u u", "Scroll the view up one half page"), \
535 ec2a9698 2022-09-15 mark KEY_("C-d d", "Scroll the view down one half page"), \
536 ec2a9698 2022-09-15 mark KEY_("g Home", "Go to line N (default: first line)"), \
537 ec2a9698 2022-09-15 mark KEY_("G End", "Go to line N (default: last line)"), \
538 ec2a9698 2022-09-15 mark KEY_("l Right", "Scroll the view right"), \
539 ec2a9698 2022-09-15 mark KEY_("h Left", "Scroll the view left"), \
540 ec2a9698 2022-09-15 mark KEY_("$", "Scroll view to the rightmost position"), \
541 ec2a9698 2022-09-15 mark KEY_("0", "Scroll view to the leftmost position"), \
542 ec2a9698 2022-09-15 mark KEY_("-", "Decrease size of the focussed split"), \
543 ec2a9698 2022-09-15 mark KEY_("+", "Increase size of the focussed split"), \
544 ec2a9698 2022-09-15 mark KEY_("Tab", "Switch focus between views"), \
545 ec2a9698 2022-09-15 mark KEY_("F", "Toggle fullscreen mode"), \
546 ec2a9698 2022-09-15 mark KEY_("/", "Open prompt to enter search term"), \
547 ec2a9698 2022-09-15 mark KEY_("n", "Find next line/token matching the current search term"), \
548 ec2a9698 2022-09-15 mark KEY_("N", "Find previous line/token matching the current search term"),\
549 16a2d4f0 2022-09-19 stsp KEY_("q", "Quit the focussed view; Quit help screen"), \
550 ec2a9698 2022-09-15 mark KEY_("Q", "Quit tog"), \
552 fd6badaa 2022-09-23 stsp KEYMAP_("Log view", TOG_KEYMAP_LOG), \
553 ec2a9698 2022-09-15 mark KEY_("< ,", "Move cursor up one commit"), \
554 ec2a9698 2022-09-15 mark KEY_("> .", "Move cursor down one commit"), \
555 ec2a9698 2022-09-15 mark KEY_("Enter", "Open diff view of the selected commit"), \
556 ec2a9698 2022-09-15 mark KEY_("B", "Reload the log view and toggle display of merged commits"), \
557 ec2a9698 2022-09-15 mark KEY_("R", "Open ref view of all repository references"), \
558 ec2a9698 2022-09-15 mark KEY_("T", "Display tree view of the repository from the selected" \
559 ec2a9698 2022-09-15 mark " commit"), \
560 ec2a9698 2022-09-15 mark KEY_("@", "Toggle between displaying author and committer name"), \
561 ec2a9698 2022-09-15 mark KEY_("&", "Open prompt to enter term to limit commits displayed"), \
562 ec2a9698 2022-09-15 mark KEY_("C-g Backspace", "Cancel current search or log operation"), \
563 ec2a9698 2022-09-15 mark KEY_("C-l", "Reload the log view with new commits in the repository"), \
565 fd6badaa 2022-09-23 stsp KEYMAP_("Diff view", TOG_KEYMAP_DIFF), \
566 ec2a9698 2022-09-15 mark KEY_("K < ,", "Display diff of next line in the file/log entry"), \
567 ec2a9698 2022-09-15 mark KEY_("J > .", "Display diff of previous line in the file/log entry"), \
568 ec2a9698 2022-09-15 mark KEY_("A", "Toggle between Myers and Patience diff algorithm"), \
569 ec2a9698 2022-09-15 mark KEY_("a", "Toggle treatment of file as ASCII irrespective of binary" \
570 ec2a9698 2022-09-15 mark " data"), \
571 ec2a9698 2022-09-15 mark KEY_("(", "Go to the previous file in the diff"), \
572 ec2a9698 2022-09-15 mark KEY_(")", "Go to the next file in the diff"), \
573 ec2a9698 2022-09-15 mark KEY_("{", "Go to the previous hunk in the diff"), \
574 ec2a9698 2022-09-15 mark KEY_("}", "Go to the next hunk in the diff"), \
575 ec2a9698 2022-09-15 mark KEY_("[", "Decrease the number of context lines"), \
576 ec2a9698 2022-09-15 mark KEY_("]", "Increase the number of context lines"), \
577 ec2a9698 2022-09-15 mark KEY_("w", "Toggle ignore whitespace-only changes in the diff"), \
579 fd6badaa 2022-09-23 stsp KEYMAP_("Blame view", TOG_KEYMAP_BLAME), \
580 ec2a9698 2022-09-15 mark KEY_("Enter", "Display diff view of the selected line's commit"), \
581 ec2a9698 2022-09-15 mark KEY_("A", "Toggle diff algorithm between Myers and Patience"), \
582 ec2a9698 2022-09-15 mark KEY_("L", "Open log view for the currently selected annotated line"), \
583 ec2a9698 2022-09-15 mark KEY_("C", "Reload view with the previously blamed commit"), \
584 ec2a9698 2022-09-15 mark KEY_("c", "Reload view with the version of the file found in the" \
585 ec2a9698 2022-09-15 mark " selected line's commit"), \
586 ec2a9698 2022-09-15 mark KEY_("p", "Reload view with the version of the file found in the" \
587 ec2a9698 2022-09-15 mark " selected line's parent commit"), \
589 fd6badaa 2022-09-23 stsp KEYMAP_("Tree view", TOG_KEYMAP_TREE), \
590 ec2a9698 2022-09-15 mark KEY_("Enter", "Enter selected directory or open blame view of the" \
591 ec2a9698 2022-09-15 mark " selected file"), \
592 ec2a9698 2022-09-15 mark KEY_("L", "Open log view for the selected entry"), \
593 ec2a9698 2022-09-15 mark KEY_("R", "Open ref view of all repository references"), \
594 ec2a9698 2022-09-15 mark KEY_("i", "Show object IDs for all tree entries"), \
595 ec2a9698 2022-09-15 mark KEY_("Backspace", "Return to the parent directory"), \
597 fd6badaa 2022-09-23 stsp KEYMAP_("Ref view", TOG_KEYMAP_REF), \
598 ec2a9698 2022-09-15 mark KEY_("Enter", "Display log view of the selected reference"), \
599 ec2a9698 2022-09-15 mark KEY_("T", "Display tree view of the selected reference"), \
600 ec2a9698 2022-09-15 mark KEY_("i", "Toggle display of IDs for all non-symbolic references"), \
601 ec2a9698 2022-09-15 mark KEY_("m", "Toggle display of last modified date for each reference"), \
602 ec2a9698 2022-09-15 mark KEY_("o", "Toggle reference sort order (name -> timestamp)"), \
603 ec2a9698 2022-09-15 mark KEY_("C-l", "Reload view with all repository references")
605 ec2a9698 2022-09-15 mark struct tog_key_map {
606 ec2a9698 2022-09-15 mark const char *keys;
607 ec2a9698 2022-09-15 mark const char *info;
608 ec2a9698 2022-09-15 mark enum tog_keymap_type type;
612 669b5ffa 2018-10-07 stsp * We implement two types of views: parent views and child views.
614 e78dc838 2020-12-04 stsp * The 'Tab' key switches focus between a parent view and its child view.
615 669b5ffa 2018-10-07 stsp * Child views are shown side-by-side to their parent view, provided
616 669b5ffa 2018-10-07 stsp * there is enough screen estate.
618 669b5ffa 2018-10-07 stsp * When a new view is opened from within a parent view, this new view
619 669b5ffa 2018-10-07 stsp * becomes a child view of the parent view, replacing any existing child.
621 669b5ffa 2018-10-07 stsp * When a new view is opened from within a child view, this new view
622 669b5ffa 2018-10-07 stsp * becomes a parent view which will obscure the views below until the
623 669b5ffa 2018-10-07 stsp * user quits the new parent view by typing 'q'.
625 669b5ffa 2018-10-07 stsp * This list of views contains parent views only.
626 669b5ffa 2018-10-07 stsp * Child views are only pointed to by their parent view.
628 bcbd79e2 2018-08-19 stsp TAILQ_HEAD(tog_view_list_head, tog_view);
630 cc3c9aac 2018-08-01 stsp struct tog_view {
631 e5a0f69f 2018-08-18 stsp TAILQ_ENTRY(tog_view) entry;
632 26ed57b2 2018-05-19 stsp WINDOW *window;
633 26ed57b2 2018-05-19 stsp PANEL *panel;
634 9b058f45 2022-06-30 mark int nlines, ncols, begin_y, begin_x; /* based on split height/width */
635 3c1dfe12 2022-07-08 mark int resized_y, resized_x; /* begin_y/x based on user resizing */
636 145b6838 2022-06-16 stsp int maxx, x; /* max column and current start column */
637 f7d12f7e 2018-08-01 stsp int lines, cols; /* copies of LINES and COLS */
638 9b058f45 2022-06-30 mark int nscrolled, offset; /* lines scrolled and hsplit line offset */
639 94b80cfa 2022-08-01 mark int gline, hiline; /* navigate to and highlight this nG line */
640 640cd7ff 2022-06-22 mark int ch, count; /* current keymap and count prefix */
641 571ccd73 2022-07-19 mark int resized; /* set when in a resize event */
642 e78dc838 2020-12-04 stsp int focussed; /* Only set on one parent or child view at a time. */
644 669b5ffa 2018-10-07 stsp struct tog_view *parent;
645 669b5ffa 2018-10-07 stsp struct tog_view *child;
648 e78dc838 2020-12-04 stsp * This flag is initially set on parent views when a new child view
649 e78dc838 2020-12-04 stsp * is created. It gets toggled when the 'Tab' key switches focus
650 e78dc838 2020-12-04 stsp * between parent and child.
651 e78dc838 2020-12-04 stsp * The flag indicates whether focus should be passed on to our child
652 e78dc838 2020-12-04 stsp * view if this parent view gets picked for focus after another parent
653 e78dc838 2020-12-04 stsp * view was closed. This prevents child views from losing focus in such
654 e78dc838 2020-12-04 stsp * situations.
656 e78dc838 2020-12-04 stsp int focus_child;
658 9b058f45 2022-06-30 mark enum tog_view_mode mode;
659 5dc9f4bc 2018-08-04 stsp /* type-specific state */
660 d6b05b5b 2018-08-04 stsp enum tog_view_type type;
662 b01e7d3b 2018-08-04 stsp struct tog_diff_view_state diff;
663 b01e7d3b 2018-08-04 stsp struct tog_log_view_state log;
664 7cbe629d 2018-08-04 stsp struct tog_blame_view_state blame;
665 ad80ab7b 2018-08-04 stsp struct tog_tree_view_state tree;
666 6458efa5 2020-11-24 stsp struct tog_ref_view_state ref;
667 ec2a9698 2022-09-15 mark struct tog_help_view_state help;
670 e5a0f69f 2018-08-18 stsp const struct got_error *(*show)(struct tog_view *);
671 e5a0f69f 2018-08-18 stsp const struct got_error *(*input)(struct tog_view **,
672 e78dc838 2020-12-04 stsp struct tog_view *, int);
673 917d79a7 2022-07-01 stsp const struct got_error *(*reset)(struct tog_view *);
674 571ccd73 2022-07-19 mark const struct got_error *(*resize)(struct tog_view *, int);
675 e5a0f69f 2018-08-18 stsp const struct got_error *(*close)(struct tog_view *);
677 60493ae3 2019-06-20 stsp const struct got_error *(*search_start)(struct tog_view *);
678 60493ae3 2019-06-20 stsp const struct got_error *(*search_next)(struct tog_view *);
679 eaf2c13e 2022-09-17 mark void (*search_setup)(struct tog_view *, FILE **, off_t **, size_t *,
680 eaf2c13e 2022-09-17 mark int **, int **, int **, int **);
681 c0c4acc8 2021-01-24 stsp int search_started;
682 60493ae3 2019-06-20 stsp int searching;
683 b1bf1435 2019-06-21 stsp #define TOG_SEARCH_FORWARD 1
684 b1bf1435 2019-06-21 stsp #define TOG_SEARCH_BACKWARD 2
685 60493ae3 2019-06-20 stsp int search_next_done;
686 8f4ed634 2020-03-26 stsp #define TOG_SEARCH_HAVE_MORE 1
687 8f4ed634 2020-03-26 stsp #define TOG_SEARCH_NO_MORE 2
688 f9967bca 2020-03-27 stsp #define TOG_SEARCH_HAVE_NONE 3
689 1803e47f 2019-06-22 stsp regex_t regex;
690 41605754 2020-11-12 stsp regmatch_t regmatch;
693 ba4f502b 2018-08-04 stsp static const struct got_error *open_diff_view(struct tog_view *,
694 3dbaef42 2020-11-24 stsp struct got_object_id *, struct got_object_id *,
695 3dbaef42 2020-11-24 stsp const char *, const char *, int, int, int, struct tog_view *,
696 78756c87 2020-11-24 stsp struct got_repository *);
697 5dc9f4bc 2018-08-04 stsp static const struct got_error *show_diff_view(struct tog_view *);
698 e5a0f69f 2018-08-18 stsp static const struct got_error *input_diff_view(struct tog_view **,
699 e78dc838 2020-12-04 stsp struct tog_view *, int);
700 917d79a7 2022-07-01 stsp static const struct got_error *reset_diff_view(struct tog_view *);
701 e5a0f69f 2018-08-18 stsp static const struct got_error* close_diff_view(struct tog_view *);
702 f44b1f58 2020-02-02 tracey static const struct got_error *search_start_diff_view(struct tog_view *);
703 eaf2c13e 2022-09-17 mark static void search_setup_diff_view(struct tog_view *, FILE **, off_t **,
704 eaf2c13e 2022-09-17 mark size_t *, int **, int **, int **, int **);
705 ec2a9698 2022-09-15 mark static const struct got_error *search_next_view_match(struct tog_view *);
707 ba4f502b 2018-08-04 stsp static const struct got_error *open_log_view(struct tog_view *,
708 78756c87 2020-11-24 stsp struct got_object_id *, struct got_repository *,
709 78756c87 2020-11-24 stsp const char *, const char *, int);
710 ba4f502b 2018-08-04 stsp static const struct got_error * show_log_view(struct tog_view *);
711 e5a0f69f 2018-08-18 stsp static const struct got_error *input_log_view(struct tog_view **,
712 e78dc838 2020-12-04 stsp struct tog_view *, int);
713 571ccd73 2022-07-19 mark static const struct got_error *resize_log_view(struct tog_view *, int);
714 e5a0f69f 2018-08-18 stsp static const struct got_error *close_log_view(struct tog_view *);
715 60493ae3 2019-06-20 stsp static const struct got_error *search_start_log_view(struct tog_view *);
716 60493ae3 2019-06-20 stsp static const struct got_error *search_next_log_view(struct tog_view *);
718 e5a0f69f 2018-08-18 stsp static const struct got_error *open_blame_view(struct tog_view *, char *,
719 78756c87 2020-11-24 stsp struct got_object_id *, struct got_repository *);
720 7cbe629d 2018-08-04 stsp static const struct got_error *show_blame_view(struct tog_view *);
721 e5a0f69f 2018-08-18 stsp static const struct got_error *input_blame_view(struct tog_view **,
722 e78dc838 2020-12-04 stsp struct tog_view *, int);
723 917d79a7 2022-07-01 stsp static const struct got_error *reset_blame_view(struct tog_view *);
724 e5a0f69f 2018-08-18 stsp static const struct got_error *close_blame_view(struct tog_view *);
725 6c4c42e0 2019-06-24 stsp static const struct got_error *search_start_blame_view(struct tog_view *);
726 eaf2c13e 2022-09-17 mark static void search_setup_blame_view(struct tog_view *, FILE **, off_t **,
727 eaf2c13e 2022-09-17 mark size_t *, int **, int **, int **, int **);
729 ad80ab7b 2018-08-04 stsp static const struct got_error *open_tree_view(struct tog_view *,
730 bc573f3b 2021-07-10 stsp struct got_object_id *, const char *, struct got_repository *);
731 ad80ab7b 2018-08-04 stsp static const struct got_error *show_tree_view(struct tog_view *);
732 e5a0f69f 2018-08-18 stsp static const struct got_error *input_tree_view(struct tog_view **,
733 e78dc838 2020-12-04 stsp struct tog_view *, int);
734 e5a0f69f 2018-08-18 stsp static const struct got_error *close_tree_view(struct tog_view *);
735 7c32bd05 2019-06-22 stsp static const struct got_error *search_start_tree_view(struct tog_view *);
736 7c32bd05 2019-06-22 stsp static const struct got_error *search_next_tree_view(struct tog_view *);
738 6458efa5 2020-11-24 stsp static const struct got_error *open_ref_view(struct tog_view *,
739 6458efa5 2020-11-24 stsp struct got_repository *);
740 6458efa5 2020-11-24 stsp static const struct got_error *show_ref_view(struct tog_view *);
741 6458efa5 2020-11-24 stsp static const struct got_error *input_ref_view(struct tog_view **,
742 e78dc838 2020-12-04 stsp struct tog_view *, int);
743 6458efa5 2020-11-24 stsp static const struct got_error *close_ref_view(struct tog_view *);
744 6458efa5 2020-11-24 stsp static const struct got_error *search_start_ref_view(struct tog_view *);
745 6458efa5 2020-11-24 stsp static const struct got_error *search_next_ref_view(struct tog_view *);
747 eaf2c13e 2022-09-17 mark static const struct got_error *open_help_view(struct tog_view *,
748 eaf2c13e 2022-09-17 mark struct tog_view *);
749 eaf2c13e 2022-09-17 mark static const struct got_error *show_help_view(struct tog_view *);
750 eaf2c13e 2022-09-17 mark static const struct got_error *input_help_view(struct tog_view **,
751 eaf2c13e 2022-09-17 mark struct tog_view *, int);
752 eaf2c13e 2022-09-17 mark static const struct got_error *reset_help_view(struct tog_view *);
753 eaf2c13e 2022-09-17 mark static const struct got_error* close_help_view(struct tog_view *);
754 eaf2c13e 2022-09-17 mark static const struct got_error *search_start_help_view(struct tog_view *);
755 eaf2c13e 2022-09-17 mark static void search_setup_help_view(struct tog_view *, FILE **, off_t **,
756 eaf2c13e 2022-09-17 mark size_t *, int **, int **, int **, int **);
758 25791caa 2018-10-24 stsp static volatile sig_atomic_t tog_sigwinch_received;
759 83baff54 2019-08-12 stsp static volatile sig_atomic_t tog_sigpipe_received;
760 61266923 2020-01-14 stsp static volatile sig_atomic_t tog_sigcont_received;
761 2497f032 2022-05-31 stsp static volatile sig_atomic_t tog_sigint_received;
762 2497f032 2022-05-31 stsp static volatile sig_atomic_t tog_sigterm_received;
764 25791caa 2018-10-24 stsp static void
765 25791caa 2018-10-24 stsp tog_sigwinch(int signo)
767 25791caa 2018-10-24 stsp tog_sigwinch_received = 1;
770 83baff54 2019-08-12 stsp static void
771 83baff54 2019-08-12 stsp tog_sigpipe(int signo)
773 83baff54 2019-08-12 stsp tog_sigpipe_received = 1;
776 61266923 2020-01-14 stsp static void
777 61266923 2020-01-14 stsp tog_sigcont(int signo)
779 61266923 2020-01-14 stsp tog_sigcont_received = 1;
782 2497f032 2022-05-31 stsp static void
783 2497f032 2022-05-31 stsp tog_sigint(int signo)
785 2497f032 2022-05-31 stsp tog_sigint_received = 1;
788 2497f032 2022-05-31 stsp static void
789 2497f032 2022-05-31 stsp tog_sigterm(int signo)
791 2497f032 2022-05-31 stsp tog_sigterm_received = 1;
795 dd6e31d7 2022-06-17 stsp tog_fatal_signal_received(void)
797 2497f032 2022-05-31 stsp return (tog_sigpipe_received ||
798 f044c841 2022-10-24 stsp tog_sigint_received || tog_sigterm_received);
801 e5a0f69f 2018-08-18 stsp static const struct got_error *
802 96a765a8 2018-08-04 stsp view_close(struct tog_view *view)
804 5629093a 2022-07-11 stsp const struct got_error *err = NULL, *child_err = NULL;
806 669b5ffa 2018-10-07 stsp if (view->child) {
807 5629093a 2022-07-11 stsp child_err = view_close(view->child);
808 669b5ffa 2018-10-07 stsp view->child = NULL;
810 e5a0f69f 2018-08-18 stsp if (view->close)
811 e5a0f69f 2018-08-18 stsp err = view->close(view);
812 ea5e7bb5 2018-08-01 stsp if (view->panel)
813 ea5e7bb5 2018-08-01 stsp del_panel(view->panel);
814 ea5e7bb5 2018-08-01 stsp if (view->window)
815 ea5e7bb5 2018-08-01 stsp delwin(view->window);
816 ea5e7bb5 2018-08-01 stsp free(view);
817 5629093a 2022-07-11 stsp return err ? err : child_err;
820 ea5e7bb5 2018-08-01 stsp static struct tog_view *
821 b3665f43 2018-08-04 stsp view_open(int nlines, int ncols, int begin_y, int begin_x,
822 0cf4efb1 2018-09-29 stsp enum tog_view_type type)
824 ad80ab7b 2018-08-04 stsp struct tog_view *view = calloc(1, sizeof(*view));
826 ea5e7bb5 2018-08-01 stsp if (view == NULL)
827 ea5e7bb5 2018-08-01 stsp return NULL;
829 d6b05b5b 2018-08-04 stsp view->type = type;
830 f7d12f7e 2018-08-01 stsp view->lines = LINES;
831 f7d12f7e 2018-08-01 stsp view->cols = COLS;
832 207b9029 2018-08-01 stsp view->nlines = nlines ? nlines : LINES - begin_y;
833 207b9029 2018-08-01 stsp view->ncols = ncols ? ncols : COLS - begin_x;
834 97ddc146 2018-08-01 stsp view->begin_y = begin_y;
835 97ddc146 2018-08-01 stsp view->begin_x = begin_x;
836 842167bf 2018-08-01 stsp view->window = newwin(nlines, ncols, begin_y, begin_x);
837 ea5e7bb5 2018-08-01 stsp if (view->window == NULL) {
838 96a765a8 2018-08-04 stsp view_close(view);
839 ea5e7bb5 2018-08-01 stsp return NULL;
841 ea5e7bb5 2018-08-01 stsp view->panel = new_panel(view->window);
842 0cf4efb1 2018-09-29 stsp if (view->panel == NULL ||
843 0cf4efb1 2018-09-29 stsp set_panel_userptr(view->panel, view) != OK) {
844 96a765a8 2018-08-04 stsp view_close(view);
845 ea5e7bb5 2018-08-01 stsp return NULL;
848 ea5e7bb5 2018-08-01 stsp keypad(view->window, TRUE);
849 ea5e7bb5 2018-08-01 stsp return view;
853 0cf4efb1 2018-09-29 stsp view_split_begin_x(int begin_x)
855 2bd27830 2018-10-22 stsp if (begin_x > 0 || COLS < 120)
857 2bd27830 2018-10-22 stsp return (COLS - MAX(COLS / 2, 80));
860 9b058f45 2022-06-30 mark /* XXX Stub till we decide what to do. */
862 9b058f45 2022-06-30 mark view_split_begin_y(int lines)
864 9b058f45 2022-06-30 mark return lines * HSPLIT_SCALE;
867 5c60c32a 2018-10-18 stsp static const struct got_error *view_resize(struct tog_view *);
869 5c60c32a 2018-10-18 stsp static const struct got_error *
870 5c60c32a 2018-10-18 stsp view_splitscreen(struct tog_view *view)
872 5c60c32a 2018-10-18 stsp const struct got_error *err = NULL;
874 571ccd73 2022-07-19 mark if (!view->resized && view->mode == TOG_VIEW_SPLIT_HRZN) {
875 3c1dfe12 2022-07-08 mark if (view->resized_y && view->resized_y < view->lines)
876 3c1dfe12 2022-07-08 mark view->begin_y = view->resized_y;
878 3c1dfe12 2022-07-08 mark view->begin_y = view_split_begin_y(view->nlines);
879 9b058f45 2022-06-30 mark view->begin_x = 0;
880 571ccd73 2022-07-19 mark } else if (!view->resized) {
881 3c1dfe12 2022-07-08 mark if (view->resized_x && view->resized_x < view->cols - 1 &&
882 3c1dfe12 2022-07-08 mark view->cols > 119)
883 3c1dfe12 2022-07-08 mark view->begin_x = view->resized_x;
885 3c1dfe12 2022-07-08 mark view->begin_x = view_split_begin_x(0);
886 9b058f45 2022-06-30 mark view->begin_y = 0;
888 9b058f45 2022-06-30 mark view->nlines = LINES - view->begin_y;
889 5c60c32a 2018-10-18 stsp view->ncols = COLS - view->begin_x;
890 5c60c32a 2018-10-18 stsp view->lines = LINES;
891 5c60c32a 2018-10-18 stsp view->cols = COLS;
892 5c60c32a 2018-10-18 stsp err = view_resize(view);
894 5c60c32a 2018-10-18 stsp return err;
896 9b058f45 2022-06-30 mark if (view->parent && view->mode == TOG_VIEW_SPLIT_HRZN)
897 9b058f45 2022-06-30 mark view->parent->nlines = view->begin_y;
899 5c60c32a 2018-10-18 stsp if (mvwin(view->window, view->begin_y, view->begin_x) == ERR)
900 638f9024 2019-05-13 stsp return got_error_from_errno("mvwin");
902 5c60c32a 2018-10-18 stsp return NULL;
905 5c60c32a 2018-10-18 stsp static const struct got_error *
906 5c60c32a 2018-10-18 stsp view_fullscreen(struct tog_view *view)
908 5c60c32a 2018-10-18 stsp const struct got_error *err = NULL;
910 5c60c32a 2018-10-18 stsp view->begin_x = 0;
911 571ccd73 2022-07-19 mark view->begin_y = view->resized ? view->begin_y : 0;
912 571ccd73 2022-07-19 mark view->nlines = view->resized ? view->nlines : LINES;
913 5c60c32a 2018-10-18 stsp view->ncols = COLS;
914 5c60c32a 2018-10-18 stsp view->lines = LINES;
915 5c60c32a 2018-10-18 stsp view->cols = COLS;
916 5c60c32a 2018-10-18 stsp err = view_resize(view);
918 5c60c32a 2018-10-18 stsp return err;
920 5c60c32a 2018-10-18 stsp if (mvwin(view->window, view->begin_y, view->begin_x) == ERR)
921 638f9024 2019-05-13 stsp return got_error_from_errno("mvwin");
923 5c60c32a 2018-10-18 stsp return NULL;
927 5c60c32a 2018-10-18 stsp view_is_parent_view(struct tog_view *view)
929 5c60c32a 2018-10-18 stsp return view->parent == NULL;
933 6131ff18 2022-06-20 mark view_is_splitscreen(struct tog_view *view)
935 9b058f45 2022-06-30 mark return view->begin_x > 0 || view->begin_y > 0;
939 24b9cfdc 2022-06-30 stsp view_is_fullscreen(struct tog_view *view)
941 24b9cfdc 2022-06-30 stsp return view->nlines == LINES && view->ncols == COLS;
945 49b24ee5 2022-07-03 mark view_is_hsplit_top(struct tog_view *view)
947 49b24ee5 2022-07-03 mark return view->mode == TOG_VIEW_SPLIT_HRZN && view->child &&
948 49b24ee5 2022-07-03 mark view_is_splitscreen(view->child);
951 9b058f45 2022-06-30 mark static void
952 9b058f45 2022-06-30 mark view_border(struct tog_view *view)
954 9b058f45 2022-06-30 mark PANEL *panel;
955 9b058f45 2022-06-30 mark const struct tog_view *view_above;
957 9b058f45 2022-06-30 mark if (view->parent)
958 9b058f45 2022-06-30 mark return view_border(view->parent);
960 9b058f45 2022-06-30 mark panel = panel_above(view->panel);
961 9b058f45 2022-06-30 mark if (panel == NULL)
964 9b058f45 2022-06-30 mark view_above = panel_userptr(panel);
965 9b058f45 2022-06-30 mark if (view->mode == TOG_VIEW_SPLIT_HRZN)
966 9b058f45 2022-06-30 mark mvwhline(view->window, view_above->begin_y - 1,
967 9b058f45 2022-06-30 mark view->begin_x, got_locale_is_utf8() ?
968 9b058f45 2022-06-30 mark ACS_HLINE : '-', view->ncols);
970 9b058f45 2022-06-30 mark mvwvline(view->window, view->begin_y, view_above->begin_x - 1,
971 9b058f45 2022-06-30 mark got_locale_is_utf8() ? ACS_VLINE : '|', view->nlines);
974 3c1dfe12 2022-07-08 mark static const struct got_error *view_init_hsplit(struct tog_view *, int);
975 9b058f45 2022-06-30 mark static const struct got_error *request_log_commits(struct tog_view *);
976 9b058f45 2022-06-30 mark static const struct got_error *offset_selection_down(struct tog_view *);
977 9b058f45 2022-06-30 mark static void offset_selection_up(struct tog_view *);
978 3c1dfe12 2022-07-08 mark static void view_get_split(struct tog_view *, int *, int *);
980 4d8c2215 2018-08-19 stsp static const struct got_error *
981 f7d12f7e 2018-08-01 stsp view_resize(struct tog_view *view)
983 9b058f45 2022-06-30 mark const struct got_error *err = NULL;
984 9b058f45 2022-06-30 mark int dif, nlines, ncols;
986 9b058f45 2022-06-30 mark dif = LINES - view->lines; /* line difference */
988 0cf4efb1 2018-09-29 stsp if (view->lines > LINES)
989 0cf4efb1 2018-09-29 stsp nlines = view->nlines - (view->lines - LINES);
991 0cf4efb1 2018-09-29 stsp nlines = view->nlines + (LINES - view->lines);
992 0cf4efb1 2018-09-29 stsp if (view->cols > COLS)
993 0cf4efb1 2018-09-29 stsp ncols = view->ncols - (view->cols - COLS);
995 0cf4efb1 2018-09-29 stsp ncols = view->ncols + (COLS - view->cols);
997 4dd27a72 2022-06-29 stsp if (view->child) {
998 9b058f45 2022-06-30 mark int hs = view->child->begin_y;
1000 24b9cfdc 2022-06-30 stsp if (!view_is_fullscreen(view))
1001 c71ed39a 2022-06-29 stsp view->child->begin_x = view_split_begin_x(view->begin_x);
1002 9b058f45 2022-06-30 mark if (view->mode == TOG_VIEW_SPLIT_HRZN ||
1003 9b058f45 2022-06-30 mark view->child->begin_x == 0) {
1004 0dbbbe90 2022-06-17 op ncols = COLS;
1006 5c60c32a 2018-10-18 stsp view_fullscreen(view->child);
1007 5c60c32a 2018-10-18 stsp if (view->child->focussed)
1008 5c60c32a 2018-10-18 stsp show_panel(view->child->panel);
1010 5c60c32a 2018-10-18 stsp show_panel(view->panel);
1012 0dbbbe90 2022-06-17 op ncols = view->child->begin_x;
1014 5c60c32a 2018-10-18 stsp view_splitscreen(view->child);
1015 5c60c32a 2018-10-18 stsp show_panel(view->child->panel);
1018 9b058f45 2022-06-30 mark * XXX This is ugly and needs to be moved into the above
1019 9b058f45 2022-06-30 mark * logic but "works" for now and my attempts at moving it
1020 9b058f45 2022-06-30 mark * break either 'tab' or 'F' key maps in horizontal splits.
1023 9b058f45 2022-06-30 mark err = view_splitscreen(view->child);
1025 9b058f45 2022-06-30 mark return err;
1026 9b058f45 2022-06-30 mark if (dif < 0) { /* top split decreased */
1027 9b058f45 2022-06-30 mark err = offset_selection_down(view);
1029 9b058f45 2022-06-30 mark return err;
1031 9b058f45 2022-06-30 mark view_border(view);
1032 9b058f45 2022-06-30 mark update_panels();
1033 9b058f45 2022-06-30 mark doupdate();
1034 9b058f45 2022-06-30 mark show_panel(view->child->panel);
1035 9b058f45 2022-06-30 mark nlines = view->nlines;
1037 0dbbbe90 2022-06-17 op } else if (view->parent == NULL)
1038 0dbbbe90 2022-06-17 op ncols = COLS;
1040 571ccd73 2022-07-19 mark if (view->resize && dif > 0) {
1041 571ccd73 2022-07-19 mark err = view->resize(view, dif);
1043 571ccd73 2022-07-19 mark return err;
1046 0dbbbe90 2022-06-17 op if (wresize(view->window, nlines, ncols) == ERR)
1047 0dbbbe90 2022-06-17 op return got_error_from_errno("wresize");
1048 0dbbbe90 2022-06-17 op if (replace_panel(view->panel, view->window) == ERR)
1049 0dbbbe90 2022-06-17 op return got_error_from_errno("replace_panel");
1050 0dbbbe90 2022-06-17 op wclear(view->window);
1052 0dbbbe90 2022-06-17 op view->nlines = nlines;
1053 0dbbbe90 2022-06-17 op view->ncols = ncols;
1054 0dbbbe90 2022-06-17 op view->lines = LINES;
1055 0dbbbe90 2022-06-17 op view->cols = COLS;
1057 5c60c32a 2018-10-18 stsp return NULL;
1060 571ccd73 2022-07-19 mark static const struct got_error *
1061 571ccd73 2022-07-19 mark resize_log_view(struct tog_view *view, int increase)
1063 6fe51fee 2022-07-22 mark struct tog_log_view_state *s = &view->state.log;
1064 6fe51fee 2022-07-22 mark const struct got_error *err = NULL;
1065 6fe51fee 2022-07-22 mark int n = 0;
1067 6fe51fee 2022-07-22 mark if (s->selected_entry)
1068 6fe51fee 2022-07-22 mark n = s->selected_entry->idx + view->lines - s->selected;
1071 571ccd73 2022-07-19 mark * Request commits to account for the increased
1072 571ccd73 2022-07-19 mark * height so we have enough to populate the view.
1074 568eae95 2022-09-11 mark if (s->commits->ncommits < n) {
1075 568eae95 2022-09-11 mark view->nscrolled = n - s->commits->ncommits + increase + 1;
1076 571ccd73 2022-07-19 mark err = request_log_commits(view);
1079 571ccd73 2022-07-19 mark return err;
1082 d9a7ab53 2022-07-11 mark static void
1083 d9a7ab53 2022-07-11 mark view_adjust_offset(struct tog_view *view, int n)
1085 d9a7ab53 2022-07-11 mark if (n == 0)
1088 d9a7ab53 2022-07-11 mark if (view->parent && view->parent->offset) {
1089 d9a7ab53 2022-07-11 mark if (view->parent->offset + n >= 0)
1090 d9a7ab53 2022-07-11 mark view->parent->offset += n;
1092 d9a7ab53 2022-07-11 mark view->parent->offset = 0;
1093 d9a7ab53 2022-07-11 mark } else if (view->offset) {
1094 d9a7ab53 2022-07-11 mark if (view->offset - n >= 0)
1095 d9a7ab53 2022-07-11 mark view->offset -= n;
1097 d9a7ab53 2022-07-11 mark view->offset = 0;
1101 3c1dfe12 2022-07-08 mark static const struct got_error *
1102 3c1dfe12 2022-07-08 mark view_resize_split(struct tog_view *view, int resize)
1104 3c1dfe12 2022-07-08 mark const struct got_error *err = NULL;
1105 3c1dfe12 2022-07-08 mark struct tog_view *v = NULL;
1107 3c1dfe12 2022-07-08 mark if (view->parent)
1108 3c1dfe12 2022-07-08 mark v = view->parent;
1112 3c1dfe12 2022-07-08 mark if (!v->child || !view_is_splitscreen(v->child))
1113 3c1dfe12 2022-07-08 mark return NULL;
1115 571ccd73 2022-07-19 mark v->resized = v->child->resized = resize; /* lock for resize event */
1117 3c1dfe12 2022-07-08 mark if (view->mode == TOG_VIEW_SPLIT_HRZN) {
1118 3c1dfe12 2022-07-08 mark if (v->child->resized_y)
1119 3c1dfe12 2022-07-08 mark v->child->begin_y = v->child->resized_y;
1120 3c1dfe12 2022-07-08 mark if (view->parent)
1121 3c1dfe12 2022-07-08 mark v->child->begin_y -= resize;
1123 3c1dfe12 2022-07-08 mark v->child->begin_y += resize;
1124 3c1dfe12 2022-07-08 mark if (v->child->begin_y < 3) {
1125 3c1dfe12 2022-07-08 mark view->count = 0;
1126 3c1dfe12 2022-07-08 mark v->child->begin_y = 3;
1127 3c1dfe12 2022-07-08 mark } else if (v->child->begin_y > LINES - 1) {
1128 3c1dfe12 2022-07-08 mark view->count = 0;
1129 3c1dfe12 2022-07-08 mark v->child->begin_y = LINES - 1;
1131 3c1dfe12 2022-07-08 mark v->ncols = COLS;
1132 3c1dfe12 2022-07-08 mark v->child->ncols = COLS;
1133 d9a7ab53 2022-07-11 mark view_adjust_offset(view, resize);
1134 3c1dfe12 2022-07-08 mark err = view_init_hsplit(v, v->child->begin_y);
1136 3c1dfe12 2022-07-08 mark return err;
1137 3c1dfe12 2022-07-08 mark v->child->resized_y = v->child->begin_y;
1139 3c1dfe12 2022-07-08 mark if (v->child->resized_x)
1140 3c1dfe12 2022-07-08 mark v->child->begin_x = v->child->resized_x;
1141 3c1dfe12 2022-07-08 mark if (view->parent)
1142 3c1dfe12 2022-07-08 mark v->child->begin_x -= resize;
1144 3c1dfe12 2022-07-08 mark v->child->begin_x += resize;
1145 3c1dfe12 2022-07-08 mark if (v->child->begin_x < 11) {
1146 3c1dfe12 2022-07-08 mark view->count = 0;
1147 3c1dfe12 2022-07-08 mark v->child->begin_x = 11;
1148 3c1dfe12 2022-07-08 mark } else if (v->child->begin_x > COLS - 1) {
1149 3c1dfe12 2022-07-08 mark view->count = 0;
1150 3c1dfe12 2022-07-08 mark v->child->begin_x = COLS - 1;
1152 3c1dfe12 2022-07-08 mark v->child->resized_x = v->child->begin_x;
1155 3c1dfe12 2022-07-08 mark v->child->mode = v->mode;
1156 3c1dfe12 2022-07-08 mark v->child->nlines = v->lines - v->child->begin_y;
1157 3c1dfe12 2022-07-08 mark v->child->ncols = v->cols - v->child->begin_x;
1158 3c1dfe12 2022-07-08 mark v->focus_child = 1;
1160 3c1dfe12 2022-07-08 mark err = view_fullscreen(v);
1162 3c1dfe12 2022-07-08 mark return err;
1163 3c1dfe12 2022-07-08 mark err = view_splitscreen(v->child);
1165 3c1dfe12 2022-07-08 mark return err;
1167 3c1dfe12 2022-07-08 mark if (v->mode == TOG_VIEW_SPLIT_HRZN) {
1168 3c1dfe12 2022-07-08 mark err = offset_selection_down(v->child);
1170 3c1dfe12 2022-07-08 mark return err;
1173 6fe51fee 2022-07-22 mark if (v->resize)
1174 6fe51fee 2022-07-22 mark err = v->resize(v, 0);
1175 6fe51fee 2022-07-22 mark else if (v->child->resize)
1176 6fe51fee 2022-07-22 mark err = v->child->resize(v->child, 0);
1178 571ccd73 2022-07-19 mark v->resized = v->child->resized = 0;
1180 3c1dfe12 2022-07-08 mark return err;
1183 3c1dfe12 2022-07-08 mark static void
1184 3c1dfe12 2022-07-08 mark view_transfer_size(struct tog_view *dst, struct tog_view *src)
1186 3c1dfe12 2022-07-08 mark struct tog_view *v = src->child ? src->child : src;
1188 3c1dfe12 2022-07-08 mark dst->resized_x = v->resized_x;
1189 3c1dfe12 2022-07-08 mark dst->resized_y = v->resized_y;
1192 669b5ffa 2018-10-07 stsp static const struct got_error *
1193 669b5ffa 2018-10-07 stsp view_close_child(struct tog_view *view)
1195 1a76625f 2018-10-22 stsp const struct got_error *err = NULL;
1197 669b5ffa 2018-10-07 stsp if (view->child == NULL)
1198 669b5ffa 2018-10-07 stsp return NULL;
1200 669b5ffa 2018-10-07 stsp err = view_close(view->child);
1201 669b5ffa 2018-10-07 stsp view->child = NULL;
1202 669b5ffa 2018-10-07 stsp return err;
1205 0dbbbe90 2022-06-17 op static const struct got_error *
1206 669b5ffa 2018-10-07 stsp view_set_child(struct tog_view *view, struct tog_view *child)
1208 3c1dfe12 2022-07-08 mark const struct got_error *err = NULL;
1210 669b5ffa 2018-10-07 stsp view->child = child;
1211 669b5ffa 2018-10-07 stsp child->parent = view;
1213 3c1dfe12 2022-07-08 mark err = view_resize(view);
1215 3c1dfe12 2022-07-08 mark return err;
1217 3c1dfe12 2022-07-08 mark if (view->child->resized_x || view->child->resized_y)
1218 3c1dfe12 2022-07-08 mark err = view_resize_split(view, 0);
1220 3c1dfe12 2022-07-08 mark return err;
1223 136e2bd4 2022-07-23 mark static const struct got_error *view_dispatch_request(struct tog_view **,
1224 136e2bd4 2022-07-23 mark struct tog_view *, enum tog_view_type, int, int);
1226 136e2bd4 2022-07-23 mark static const struct got_error *
1227 136e2bd4 2022-07-23 mark view_request_new(struct tog_view **requested, struct tog_view *view,
1228 136e2bd4 2022-07-23 mark enum tog_view_type request)
1230 136e2bd4 2022-07-23 mark struct tog_view *new_view = NULL;
1231 136e2bd4 2022-07-23 mark const struct got_error *err;
1232 136e2bd4 2022-07-23 mark int y = 0, x = 0;
1234 136e2bd4 2022-07-23 mark *requested = NULL;
1236 94274a8f 2022-09-19 mark if (view_is_parent_view(view) && request != TOG_VIEW_HELP)
1237 136e2bd4 2022-07-23 mark view_get_split(view, &y, &x);
1239 136e2bd4 2022-07-23 mark err = view_dispatch_request(&new_view, view, request, y, x);
1241 136e2bd4 2022-07-23 mark return err;
1243 94274a8f 2022-09-19 mark if (view_is_parent_view(view) && view->mode == TOG_VIEW_SPLIT_HRZN &&
1244 94274a8f 2022-09-19 mark request != TOG_VIEW_HELP) {
1245 136e2bd4 2022-07-23 mark err = view_init_hsplit(view, y);
1247 136e2bd4 2022-07-23 mark return err;
1250 136e2bd4 2022-07-23 mark view->focussed = 0;
1251 136e2bd4 2022-07-23 mark new_view->focussed = 1;
1252 136e2bd4 2022-07-23 mark new_view->mode = view->mode;
1253 94274a8f 2022-09-19 mark new_view->nlines = request == TOG_VIEW_HELP ?
1254 94274a8f 2022-09-19 mark view->lines : view->lines - y;
1256 94274a8f 2022-09-19 mark if (view_is_parent_view(view) && request != TOG_VIEW_HELP) {
1257 136e2bd4 2022-07-23 mark view_transfer_size(new_view, view);
1258 136e2bd4 2022-07-23 mark err = view_close_child(view);
1260 136e2bd4 2022-07-23 mark return err;
1261 136e2bd4 2022-07-23 mark err = view_set_child(view, new_view);
1263 136e2bd4 2022-07-23 mark return err;
1264 136e2bd4 2022-07-23 mark view->focus_child = 1;
1266 136e2bd4 2022-07-23 mark *requested = new_view;
1268 136e2bd4 2022-07-23 mark return NULL;
1271 34bc9ec9 2019-02-22 stsp static void
1272 79fcf3e4 2018-11-04 stsp tog_resizeterm(void)
1274 25791caa 2018-10-24 stsp int cols, lines;
1275 25791caa 2018-10-24 stsp struct winsize size;
1277 25791caa 2018-10-24 stsp if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &size) < 0) {
1278 25791caa 2018-10-24 stsp cols = 80; /* Default */
1279 25791caa 2018-10-24 stsp lines = 24;
1281 25791caa 2018-10-24 stsp cols = size.ws_col;
1282 25791caa 2018-10-24 stsp lines = size.ws_row;
1284 25791caa 2018-10-24 stsp resize_term(lines, cols);
1287 2b49a8ae 2019-06-22 stsp static const struct got_error *
1288 2b49a8ae 2019-06-22 stsp view_search_start(struct tog_view *view)
1290 7c32bd05 2019-06-22 stsp const struct got_error *err = NULL;
1291 9b058f45 2022-06-30 mark struct tog_view *v = view;
1292 2b49a8ae 2019-06-22 stsp char pattern[1024];
1295 c0c4acc8 2021-01-24 stsp if (view->search_started) {
1296 c0c4acc8 2021-01-24 stsp regfree(&view->regex);
1297 c0c4acc8 2021-01-24 stsp view->searching = 0;
1298 c0c4acc8 2021-01-24 stsp memset(&view->regmatch, 0, sizeof(view->regmatch));
1300 c0c4acc8 2021-01-24 stsp view->search_started = 0;
1302 2b49a8ae 2019-06-22 stsp if (view->nlines < 1)
1303 2b49a8ae 2019-06-22 stsp return NULL;
1305 49b24ee5 2022-07-03 mark if (view_is_hsplit_top(view))
1306 9b058f45 2022-06-30 mark v = view->child;
1308 9b058f45 2022-06-30 mark mvwaddstr(v->window, v->nlines - 1, 0, "/");
1309 9b058f45 2022-06-30 mark wclrtoeol(v->window);
1311 a6d37fac 2022-07-03 mark nodelay(view->window, FALSE); /* block for search term input */
1312 2b49a8ae 2019-06-22 stsp nocbreak();
1314 9b058f45 2022-06-30 mark ret = wgetnstr(v->window, pattern, sizeof(pattern));
1315 9b058f45 2022-06-30 mark wrefresh(v->window);
1318 a6d37fac 2022-07-03 mark nodelay(view->window, TRUE);
1319 2b49a8ae 2019-06-22 stsp if (ret == ERR)
1320 2b49a8ae 2019-06-22 stsp return NULL;
1322 41605754 2020-11-12 stsp if (regcomp(&view->regex, pattern, REG_EXTENDED | REG_NEWLINE) == 0) {
1323 7c32bd05 2019-06-22 stsp err = view->search_start(view);
1324 7c32bd05 2019-06-22 stsp if (err) {
1325 7c32bd05 2019-06-22 stsp regfree(&view->regex);
1326 7c32bd05 2019-06-22 stsp return err;
1328 c0c4acc8 2021-01-24 stsp view->search_started = 1;
1329 2b49a8ae 2019-06-22 stsp view->searching = TOG_SEARCH_FORWARD;
1330 2b49a8ae 2019-06-22 stsp view->search_next_done = 0;
1331 2b49a8ae 2019-06-22 stsp view->search_next(view);
1334 2b49a8ae 2019-06-22 stsp return NULL;
1337 7532ccda 2022-07-11 mark /* Switch split mode. If view is a parent or child, draw the new splitscreen. */
1338 d2366e29 2022-07-07 mark static const struct got_error *
1339 d2366e29 2022-07-07 mark switch_split(struct tog_view *view)
1341 d2366e29 2022-07-07 mark const struct got_error *err = NULL;
1342 d2366e29 2022-07-07 mark struct tog_view *v = NULL;
1344 d2366e29 2022-07-07 mark if (view->parent)
1345 d2366e29 2022-07-07 mark v = view->parent;
1349 7532ccda 2022-07-11 mark if (v->mode == TOG_VIEW_SPLIT_HRZN)
1350 7532ccda 2022-07-11 mark v->mode = TOG_VIEW_SPLIT_VERT;
1352 d2366e29 2022-07-07 mark v->mode = TOG_VIEW_SPLIT_HRZN;
1354 7532ccda 2022-07-11 mark if (!v->child)
1355 7532ccda 2022-07-11 mark return NULL;
1356 7532ccda 2022-07-11 mark else if (v->mode == TOG_VIEW_SPLIT_VERT && v->cols < 120)
1357 7532ccda 2022-07-11 mark v->mode = TOG_VIEW_SPLIT_NONE;
1359 d2366e29 2022-07-07 mark view_get_split(v, &v->child->begin_y, &v->child->begin_x);
1360 3c1dfe12 2022-07-08 mark if (v->mode == TOG_VIEW_SPLIT_HRZN && v->child->resized_y)
1361 3c1dfe12 2022-07-08 mark v->child->begin_y = v->child->resized_y;
1362 7532ccda 2022-07-11 mark else if (v->mode == TOG_VIEW_SPLIT_VERT && v->child->resized_x)
1363 3c1dfe12 2022-07-08 mark v->child->begin_x = v->child->resized_x;
1366 d2366e29 2022-07-07 mark if (v->mode == TOG_VIEW_SPLIT_HRZN) {
1367 d2366e29 2022-07-07 mark v->ncols = COLS;
1368 d2366e29 2022-07-07 mark v->child->ncols = COLS;
1369 7532ccda 2022-07-11 mark v->child->nscrolled = LINES - v->child->nlines;
1371 d2366e29 2022-07-07 mark err = view_init_hsplit(v, v->child->begin_y);
1373 d2366e29 2022-07-07 mark return err;
1375 d2366e29 2022-07-07 mark v->child->mode = v->mode;
1376 d2366e29 2022-07-07 mark v->child->nlines = v->lines - v->child->begin_y;
1377 d2366e29 2022-07-07 mark v->focus_child = 1;
1379 d2366e29 2022-07-07 mark err = view_fullscreen(v);
1381 d2366e29 2022-07-07 mark return err;
1382 d2366e29 2022-07-07 mark err = view_splitscreen(v->child);
1384 d2366e29 2022-07-07 mark return err;
1386 7532ccda 2022-07-11 mark if (v->mode == TOG_VIEW_SPLIT_NONE)
1387 7532ccda 2022-07-11 mark v->mode = TOG_VIEW_SPLIT_VERT;
1388 7532ccda 2022-07-11 mark if (v->mode == TOG_VIEW_SPLIT_HRZN) {
1389 7532ccda 2022-07-11 mark err = offset_selection_down(v);
1391 279d2047 2022-07-29 stsp return err;
1392 d2366e29 2022-07-07 mark err = offset_selection_down(v->child);
1394 279d2047 2022-07-29 stsp return err;
1396 7532ccda 2022-07-11 mark offset_selection_up(v);
1397 7532ccda 2022-07-11 mark offset_selection_up(v->child);
1399 dff91825 2022-07-22 mark if (v->resize)
1400 dff91825 2022-07-22 mark err = v->resize(v, 0);
1401 dff91825 2022-07-22 mark else if (v->child->resize)
1402 dff91825 2022-07-22 mark err = v->child->resize(v->child, 0);
1404 d2366e29 2022-07-07 mark return err;
1408 f0032ce6 2022-07-02 mark * Compute view->count from numeric input. Assign total to view->count and
1409 f0032ce6 2022-07-02 mark * return first non-numeric key entered.
1411 640cd7ff 2022-06-22 mark static int
1412 640cd7ff 2022-06-22 mark get_compound_key(struct tog_view *view, int c)
1414 9b058f45 2022-06-30 mark struct tog_view *v = view;
1415 9b058f45 2022-06-30 mark int x, n = 0;
1417 49b24ee5 2022-07-03 mark if (view_is_hsplit_top(view))
1418 9b058f45 2022-06-30 mark v = view->child;
1419 9b058f45 2022-06-30 mark else if (view->mode == TOG_VIEW_SPLIT_VERT && view->parent)
1420 9b058f45 2022-06-30 mark v = view->parent;
1422 640cd7ff 2022-06-22 mark view->count = 0;
1423 f0032ce6 2022-07-02 mark cbreak(); /* block for input */
1424 94b80cfa 2022-08-01 mark nodelay(view->window, FALSE);
1425 9b058f45 2022-06-30 mark wmove(v->window, v->nlines - 1, 0);
1426 9b058f45 2022-06-30 mark wclrtoeol(v->window);
1427 9b058f45 2022-06-30 mark waddch(v->window, ':');
1430 9b058f45 2022-06-30 mark x = getcurx(v->window);
1431 9b058f45 2022-06-30 mark if (x != ERR && x < view->ncols) {
1432 9b058f45 2022-06-30 mark waddch(v->window, c);
1433 9b058f45 2022-06-30 mark wrefresh(v->window);
1437 640cd7ff 2022-06-22 mark * Don't overflow. Max valid request should be the greatest
1438 640cd7ff 2022-06-22 mark * between the longest and total lines; cap at 10 million.
1440 640cd7ff 2022-06-22 mark if (n >= 9999999)
1441 640cd7ff 2022-06-22 mark n = 9999999;
1443 640cd7ff 2022-06-22 mark n = n * 10 + (c - '0');
1444 640cd7ff 2022-06-22 mark } while (((c = wgetch(view->window))) >= '0' && c <= '9' && c != ERR);
1446 94b80cfa 2022-08-01 mark if (c == 'G' || c == 'g') { /* nG key map */
1447 94b80cfa 2022-08-01 mark view->gline = view->hiline = n;
1452 640cd7ff 2022-06-22 mark /* Massage excessive or inapplicable values at the input handler. */
1453 640cd7ff 2022-06-22 mark view->count = n;
1458 0cf4efb1 2018-09-29 stsp static const struct got_error *
1459 e78dc838 2020-12-04 stsp view_input(struct tog_view **new, int *done, struct tog_view *view,
1460 e78dc838 2020-12-04 stsp struct tog_view_list_head *views)
1462 e5a0f69f 2018-08-18 stsp const struct got_error *err = NULL;
1463 669b5ffa 2018-10-07 stsp struct tog_view *v;
1464 1a76625f 2018-10-22 stsp int ch, errcode;
1466 e5a0f69f 2018-08-18 stsp *new = NULL;
1468 f9967bca 2020-03-27 stsp /* Clear "no matches" indicator. */
1469 f9967bca 2020-03-27 stsp if (view->search_next_done == TOG_SEARCH_NO_MORE ||
1470 640cd7ff 2022-06-22 mark view->search_next_done == TOG_SEARCH_HAVE_NONE) {
1471 8f4ed634 2020-03-26 stsp view->search_next_done = TOG_SEARCH_HAVE_MORE;
1472 640cd7ff 2022-06-22 mark view->count = 0;
1475 60493ae3 2019-06-20 stsp if (view->searching && !view->search_next_done) {
1476 82954512 2020-02-03 stsp errcode = pthread_mutex_unlock(&tog_mutex);
1477 82954512 2020-02-03 stsp if (errcode)
1478 82954512 2020-02-03 stsp return got_error_set_errno(errcode,
1479 82954512 2020-02-03 stsp "pthread_mutex_unlock");
1480 3da8ef85 2021-09-21 stsp sched_yield();
1481 82954512 2020-02-03 stsp errcode = pthread_mutex_lock(&tog_mutex);
1482 82954512 2020-02-03 stsp if (errcode)
1483 82954512 2020-02-03 stsp return got_error_set_errno(errcode,
1484 82954512 2020-02-03 stsp "pthread_mutex_lock");
1485 60493ae3 2019-06-20 stsp view->search_next(view);
1486 60493ae3 2019-06-20 stsp return NULL;
1489 1a76625f 2018-10-22 stsp /* Allow threads to make progress while we are waiting for input. */
1490 1a76625f 2018-10-22 stsp errcode = pthread_mutex_unlock(&tog_mutex);
1491 1a76625f 2018-10-22 stsp if (errcode)
1492 2af4a041 2019-05-11 jcs return got_error_set_errno(errcode, "pthread_mutex_unlock");
1493 a6d37fac 2022-07-03 mark /* If we have an unfinished count, let C-g or backspace abort. */
1494 a6d37fac 2022-07-03 mark if (view->count && --view->count) {
1496 a6d37fac 2022-07-03 mark nodelay(view->window, TRUE);
1497 640cd7ff 2022-06-22 mark ch = wgetch(view->window);
1498 a6d37fac 2022-07-03 mark if (ch == CTRL('g') || ch == KEY_BACKSPACE)
1499 a6d37fac 2022-07-03 mark view->count = 0;
1501 a6d37fac 2022-07-03 mark ch = view->ch;
1503 a6d37fac 2022-07-03 mark ch = wgetch(view->window);
1504 640cd7ff 2022-06-22 mark if (ch >= '1' && ch <= '9')
1505 640cd7ff 2022-06-22 mark view->ch = ch = get_compound_key(view, ch);
1507 94b80cfa 2022-08-01 mark if (view->hiline && ch != ERR && ch != 0)
1508 94b80cfa 2022-08-01 mark view->hiline = 0; /* key pressed, clear line highlight */
1509 94b80cfa 2022-08-01 mark nodelay(view->window, TRUE);
1510 1a76625f 2018-10-22 stsp errcode = pthread_mutex_lock(&tog_mutex);
1511 1a76625f 2018-10-22 stsp if (errcode)
1512 2af4a041 2019-05-11 jcs return got_error_set_errno(errcode, "pthread_mutex_lock");
1514 61266923 2020-01-14 stsp if (tog_sigwinch_received || tog_sigcont_received) {
1515 25791caa 2018-10-24 stsp tog_resizeterm();
1516 25791caa 2018-10-24 stsp tog_sigwinch_received = 0;
1517 61266923 2020-01-14 stsp tog_sigcont_received = 0;
1518 25791caa 2018-10-24 stsp TAILQ_FOREACH(v, views, entry) {
1519 25791caa 2018-10-24 stsp err = view_resize(v);
1521 25791caa 2018-10-24 stsp return err;
1522 e78dc838 2020-12-04 stsp err = v->input(new, v, KEY_RESIZE);
1524 25791caa 2018-10-24 stsp return err;
1525 cdfcfb03 2020-12-06 stsp if (v->child) {
1526 cdfcfb03 2020-12-06 stsp err = view_resize(v->child);
1528 cdfcfb03 2020-12-06 stsp return err;
1529 cdfcfb03 2020-12-06 stsp err = v->child->input(new, v->child,
1530 cdfcfb03 2020-12-06 stsp KEY_RESIZE);
1532 cdfcfb03 2020-12-06 stsp return err;
1533 3c1dfe12 2022-07-08 mark if (v->child->resized_x || v->child->resized_y) {
1534 3c1dfe12 2022-07-08 mark err = view_resize_split(v, 0);
1536 3c1dfe12 2022-07-08 mark return err;
1542 e5a0f69f 2018-08-18 stsp switch (ch) {
1545 ec2a9698 2022-09-15 mark case KEY_F(1):
1546 ec2a9698 2022-09-15 mark if (view->type == TOG_VIEW_HELP)
1547 ec2a9698 2022-09-15 mark err = view->reset(view);
1549 ec2a9698 2022-09-15 mark err = view_request_new(new, view, TOG_VIEW_HELP);
1552 640cd7ff 2022-06-22 mark view->count = 0;
1553 1e37a5c2 2019-05-12 jcs if (view->child) {
1554 e78dc838 2020-12-04 stsp view->focussed = 0;
1555 e78dc838 2020-12-04 stsp view->child->focussed = 1;
1556 e78dc838 2020-12-04 stsp view->focus_child = 1;
1557 1e37a5c2 2019-05-12 jcs } else if (view->parent) {
1558 e78dc838 2020-12-04 stsp view->focussed = 0;
1559 e78dc838 2020-12-04 stsp view->parent->focussed = 1;
1560 e78dc838 2020-12-04 stsp view->parent->focus_child = 0;
1561 9b058f45 2022-06-30 mark if (!view_is_splitscreen(view)) {
1562 6fe51fee 2022-07-22 mark if (view->parent->resize) {
1563 6fe51fee 2022-07-22 mark err = view->parent->resize(view->parent,
1566 9b058f45 2022-06-30 mark return err;
1568 9b058f45 2022-06-30 mark offset_selection_up(view->parent);
1569 6131ff18 2022-06-20 mark err = view_fullscreen(view->parent);
1571 9b058f45 2022-06-30 mark return err;
1576 9b058f45 2022-06-30 mark if (view->parent && view->mode == TOG_VIEW_SPLIT_HRZN) {
1577 6fe51fee 2022-07-22 mark if (view->parent->resize) {
1578 9b058f45 2022-06-30 mark /* might need more commits to fill fullscreen */
1579 6fe51fee 2022-07-22 mark err = view->parent->resize(view->parent, 0);
1583 9b058f45 2022-06-30 mark offset_selection_up(view->parent);
1585 e78dc838 2020-12-04 stsp err = view->input(new, view, ch);
1586 9970f7fc 2020-12-03 stsp view->dying = 1;
1592 640cd7ff 2022-06-22 mark view->count = 0;
1593 1e37a5c2 2019-05-12 jcs if (view_is_parent_view(view)) {
1594 1e37a5c2 2019-05-12 jcs if (view->child == NULL)
1596 1e37a5c2 2019-05-12 jcs if (view_is_splitscreen(view->child)) {
1597 e78dc838 2020-12-04 stsp view->focussed = 0;
1598 e78dc838 2020-12-04 stsp view->child->focussed = 1;
1599 1e37a5c2 2019-05-12 jcs err = view_fullscreen(view->child);
1601 1e37a5c2 2019-05-12 jcs err = view_splitscreen(view->child);
1603 3c1dfe12 2022-07-08 mark err = view_resize_split(view, 0);
1607 e78dc838 2020-12-04 stsp err = view->child->input(new, view->child,
1608 9970f7fc 2020-12-03 stsp KEY_RESIZE);
1610 1e37a5c2 2019-05-12 jcs if (view_is_splitscreen(view)) {
1611 e78dc838 2020-12-04 stsp view->parent->focussed = 0;
1612 e78dc838 2020-12-04 stsp view->focussed = 1;
1613 1e37a5c2 2019-05-12 jcs err = view_fullscreen(view);
1615 1e37a5c2 2019-05-12 jcs err = view_splitscreen(view);
1616 9b058f45 2022-06-30 mark if (!err && view->mode != TOG_VIEW_SPLIT_HRZN)
1617 6131ff18 2022-06-20 mark err = view_resize(view->parent);
1619 3c1dfe12 2022-07-08 mark err = view_resize_split(view, 0);
1623 e78dc838 2020-12-04 stsp err = view->input(new, view, KEY_RESIZE);
1627 6fe51fee 2022-07-22 mark if (view->resize) {
1628 6fe51fee 2022-07-22 mark err = view->resize(view, 0);
1632 9b058f45 2022-06-30 mark if (view->parent)
1633 9b058f45 2022-06-30 mark err = offset_selection_down(view->parent);
1635 9b058f45 2022-06-30 mark err = offset_selection_down(view);
1638 3c1dfe12 2022-07-08 mark view->count = 0;
1639 d2366e29 2022-07-07 mark err = switch_split(view);
1642 3c1dfe12 2022-07-08 mark err = view_resize_split(view, -1);
1645 3c1dfe12 2022-07-08 mark err = view_resize_split(view, 1);
1647 1e37a5c2 2019-05-12 jcs case KEY_RESIZE:
1650 640cd7ff 2022-06-22 mark view->count = 0;
1651 60493ae3 2019-06-20 stsp if (view->search_start)
1652 2b49a8ae 2019-06-22 stsp view_search_start(view);
1654 e78dc838 2020-12-04 stsp err = view->input(new, view, ch);
1658 c0c4acc8 2021-01-24 stsp if (view->search_started && view->search_next) {
1659 b1bf1435 2019-06-21 stsp view->searching = (ch == 'n' ?
1660 b1bf1435 2019-06-21 stsp TOG_SEARCH_FORWARD : TOG_SEARCH_BACKWARD);
1661 60493ae3 2019-06-20 stsp view->search_next_done = 0;
1662 60493ae3 2019-06-20 stsp view->search_next(view);
1664 e78dc838 2020-12-04 stsp err = view->input(new, view, ch);
1667 917d79a7 2022-07-01 stsp if (tog_diff_algo == GOT_DIFF_ALGORITHM_MYERS)
1668 917d79a7 2022-07-01 stsp tog_diff_algo = GOT_DIFF_ALGORITHM_PATIENCE;
1670 917d79a7 2022-07-01 stsp tog_diff_algo = GOT_DIFF_ALGORITHM_MYERS;
1671 917d79a7 2022-07-01 stsp TAILQ_FOREACH(v, views, entry) {
1672 917d79a7 2022-07-01 stsp if (v->reset) {
1673 917d79a7 2022-07-01 stsp err = v->reset(v);
1675 917d79a7 2022-07-01 stsp return err;
1677 917d79a7 2022-07-01 stsp if (v->child && v->child->reset) {
1678 917d79a7 2022-07-01 stsp err = v->child->reset(v->child);
1680 917d79a7 2022-07-01 stsp return err;
1685 e78dc838 2020-12-04 stsp err = view->input(new, view, ch);
1689 e5a0f69f 2018-08-18 stsp return err;
1693 a3404814 2018-09-02 stsp view_needs_focus_indication(struct tog_view *view)
1695 669b5ffa 2018-10-07 stsp if (view_is_parent_view(view)) {
1696 acdafe9c 2020-12-03 stsp if (view->child == NULL || view->child->focussed)
1698 669b5ffa 2018-10-07 stsp if (!view_is_splitscreen(view->child))
1700 669b5ffa 2018-10-07 stsp } else if (!view_is_splitscreen(view))
1703 669b5ffa 2018-10-07 stsp return view->focussed;
1706 bcbd79e2 2018-08-19 stsp static const struct got_error *
1707 e5a0f69f 2018-08-18 stsp view_loop(struct tog_view *view)
1709 e5a0f69f 2018-08-18 stsp const struct got_error *err = NULL;
1710 e5a0f69f 2018-08-18 stsp struct tog_view_list_head views;
1711 fb59748f 2020-12-05 stsp struct tog_view *new_view;
1712 d2366e29 2022-07-07 mark char *mode;
1713 fd823528 2018-10-22 stsp int fast_refresh = 10;
1714 1a76625f 2018-10-22 stsp int done = 0, errcode;
1716 d2366e29 2022-07-07 mark mode = getenv("TOG_VIEW_SPLIT_MODE");
1717 d2366e29 2022-07-07 mark if (!mode || !(*mode == 'h' || *mode == 'H'))
1718 d2366e29 2022-07-07 mark view->mode = TOG_VIEW_SPLIT_VERT;
1720 d2366e29 2022-07-07 mark view->mode = TOG_VIEW_SPLIT_HRZN;
1722 1a76625f 2018-10-22 stsp errcode = pthread_mutex_lock(&tog_mutex);
1723 1a76625f 2018-10-22 stsp if (errcode)
1724 2af4a041 2019-05-11 jcs return got_error_set_errno(errcode, "pthread_mutex_lock");
1726 e5a0f69f 2018-08-18 stsp TAILQ_INIT(&views);
1727 e5a0f69f 2018-08-18 stsp TAILQ_INSERT_HEAD(&views, view, entry);
1729 1004088d 2018-09-29 stsp view->focussed = 1;
1730 878940b7 2018-09-29 stsp err = view->show(view);
1732 0cf4efb1 2018-09-29 stsp return err;
1733 0cf4efb1 2018-09-29 stsp update_panels();
1734 0cf4efb1 2018-09-29 stsp doupdate();
1735 5629093a 2022-07-11 stsp while (!TAILQ_EMPTY(&views) && !done && !tog_thread_error &&
1736 5629093a 2022-07-11 stsp !tog_fatal_signal_received()) {
1737 fd823528 2018-10-22 stsp /* Refresh fast during initialization, then become slower. */
1738 fd823528 2018-10-22 stsp if (fast_refresh && fast_refresh-- == 0)
1739 fd823528 2018-10-22 stsp halfdelay(10); /* switch to once per second */
1741 e78dc838 2020-12-04 stsp err = view_input(&new_view, &done, view, &views);
1744 9970f7fc 2020-12-03 stsp if (view->dying) {
1745 e78dc838 2020-12-04 stsp struct tog_view *v, *prev = NULL;
1747 9970f7fc 2020-12-03 stsp if (view_is_parent_view(view))
1748 9970f7fc 2020-12-03 stsp prev = TAILQ_PREV(view, tog_view_list_head,
1750 e78dc838 2020-12-04 stsp else if (view->parent)
1751 669b5ffa 2018-10-07 stsp prev = view->parent;
1753 e78dc838 2020-12-04 stsp if (view->parent) {
1754 9970f7fc 2020-12-03 stsp view->parent->child = NULL;
1755 e78dc838 2020-12-04 stsp view->parent->focus_child = 0;
1756 9b058f45 2022-06-30 mark /* Restore fullscreen line height. */
1757 9b058f45 2022-06-30 mark view->parent->nlines = view->parent->lines;
1758 0dbbbe90 2022-06-17 op err = view_resize(view->parent);
1761 3c1dfe12 2022-07-08 mark /* Make resized splits persist. */
1762 3c1dfe12 2022-07-08 mark view_transfer_size(view->parent, view);
1764 9970f7fc 2020-12-03 stsp TAILQ_REMOVE(&views, view, entry);
1766 9970f7fc 2020-12-03 stsp err = view_close(view);
1768 e5a0f69f 2018-08-18 stsp goto done;
1770 e78dc838 2020-12-04 stsp view = NULL;
1771 e78dc838 2020-12-04 stsp TAILQ_FOREACH(v, &views, entry) {
1772 e78dc838 2020-12-04 stsp if (v->focussed)
1775 e78dc838 2020-12-04 stsp if (view == NULL && new_view == NULL) {
1776 e78dc838 2020-12-04 stsp /* No view has focus. Try to pick one. */
1778 e78dc838 2020-12-04 stsp view = prev;
1779 e78dc838 2020-12-04 stsp else if (!TAILQ_EMPTY(&views)) {
1780 e78dc838 2020-12-04 stsp view = TAILQ_LAST(&views,
1781 e78dc838 2020-12-04 stsp tog_view_list_head);
1783 e78dc838 2020-12-04 stsp if (view) {
1784 e78dc838 2020-12-04 stsp if (view->focus_child) {
1785 e78dc838 2020-12-04 stsp view->child->focussed = 1;
1786 e78dc838 2020-12-04 stsp view = view->child;
1788 e78dc838 2020-12-04 stsp view->focussed = 1;
1792 bcbd79e2 2018-08-19 stsp if (new_view) {
1793 86c66b02 2018-10-18 stsp struct tog_view *v, *t;
1794 86c66b02 2018-10-18 stsp /* Only allow one parent view per type. */
1795 86c66b02 2018-10-18 stsp TAILQ_FOREACH_SAFE(v, &views, entry, t) {
1796 86c66b02 2018-10-18 stsp if (v->type != new_view->type)
1798 86c66b02 2018-10-18 stsp TAILQ_REMOVE(&views, v, entry);
1799 86c66b02 2018-10-18 stsp err = view_close(v);
1801 86c66b02 2018-10-18 stsp goto done;
1804 bcbd79e2 2018-08-19 stsp TAILQ_INSERT_TAIL(&views, new_view, entry);
1805 fed7eaa8 2018-10-24 stsp view = new_view;
1807 669b5ffa 2018-10-07 stsp if (view) {
1808 e78dc838 2020-12-04 stsp if (view_is_parent_view(view)) {
1809 e78dc838 2020-12-04 stsp if (view->child && view->child->focussed)
1810 e78dc838 2020-12-04 stsp view = view->child;
1812 e78dc838 2020-12-04 stsp if (view->parent && view->parent->focussed)
1813 e78dc838 2020-12-04 stsp view = view->parent;
1815 e78dc838 2020-12-04 stsp show_panel(view->panel);
1816 e78dc838 2020-12-04 stsp if (view->child && view_is_splitscreen(view->child))
1817 e78dc838 2020-12-04 stsp show_panel(view->child->panel);
1818 e78dc838 2020-12-04 stsp if (view->parent && view_is_splitscreen(view)) {
1819 669b5ffa 2018-10-07 stsp err = view->parent->show(view->parent);
1821 1a76625f 2018-10-22 stsp goto done;
1823 669b5ffa 2018-10-07 stsp err = view->show(view);
1825 1a76625f 2018-10-22 stsp goto done;
1826 669b5ffa 2018-10-07 stsp if (view->child) {
1827 669b5ffa 2018-10-07 stsp err = view->child->show(view->child);
1829 1a76625f 2018-10-22 stsp goto done;
1831 1a76625f 2018-10-22 stsp update_panels();
1832 1a76625f 2018-10-22 stsp doupdate();
1836 e5a0f69f 2018-08-18 stsp while (!TAILQ_EMPTY(&views)) {
1837 5629093a 2022-07-11 stsp const struct got_error *close_err;
1838 e5a0f69f 2018-08-18 stsp view = TAILQ_FIRST(&views);
1839 e5a0f69f 2018-08-18 stsp TAILQ_REMOVE(&views, view, entry);
1840 5629093a 2022-07-11 stsp close_err = view_close(view);
1841 5629093a 2022-07-11 stsp if (close_err && err == NULL)
1842 5629093a 2022-07-11 stsp err = close_err;
1845 1a76625f 2018-10-22 stsp errcode = pthread_mutex_unlock(&tog_mutex);
1846 963ecf2a 2019-08-12 stsp if (errcode && err == NULL)
1847 963ecf2a 2019-08-12 stsp err = got_error_set_errno(errcode, "pthread_mutex_unlock");
1849 e5a0f69f 2018-08-18 stsp return err;
1852 4ed7e80c 2018-05-20 stsp __dead static void
1853 9f7d7167 2018-04-29 stsp usage_log(void)
1856 c70c5802 2018-08-01 stsp fprintf(stderr,
1857 b672a97a 2020-01-27 stsp "usage: %s log [-b] [-c commit] [-r repository-path] [path]\n",
1858 9f7d7167 2018-04-29 stsp getprogname());
1862 963b370f 2018-05-20 stsp /* Create newly allocated wide-character string equivalent to a byte string. */
1863 80ddbec8 2018-04-29 stsp static const struct got_error *
1864 963b370f 2018-05-20 stsp mbs2ws(wchar_t **ws, size_t *wlen, const char *s)
1866 00dfcb92 2018-06-11 stsp char *vis = NULL;
1867 963b370f 2018-05-20 stsp const struct got_error *err = NULL;
1869 963b370f 2018-05-20 stsp *ws = NULL;
1870 963b370f 2018-05-20 stsp *wlen = mbstowcs(NULL, s, 0);
1871 00dfcb92 2018-06-11 stsp if (*wlen == (size_t)-1) {
1872 00dfcb92 2018-06-11 stsp int vislen;
1873 00dfcb92 2018-06-11 stsp if (errno != EILSEQ)
1874 638f9024 2019-05-13 stsp return got_error_from_errno("mbstowcs");
1876 00dfcb92 2018-06-11 stsp /* byte string invalid in current encoding; try to "fix" it */
1877 00dfcb92 2018-06-11 stsp err = got_mbsavis(&vis, &vislen, s);
1879 00dfcb92 2018-06-11 stsp return err;
1880 00dfcb92 2018-06-11 stsp *wlen = mbstowcs(NULL, vis, 0);
1881 a7f50699 2018-06-11 stsp if (*wlen == (size_t)-1) {
1882 638f9024 2019-05-13 stsp err = got_error_from_errno("mbstowcs"); /* give up */
1883 a7f50699 2018-06-11 stsp goto done;
1887 fd9f4a2d 2019-08-28 hiltjo *ws = calloc(*wlen + 1, sizeof(**ws));
1888 a7f50699 2018-06-11 stsp if (*ws == NULL) {
1889 638f9024 2019-05-13 stsp err = got_error_from_errno("calloc");
1890 a7f50699 2018-06-11 stsp goto done;
1893 00dfcb92 2018-06-11 stsp if (mbstowcs(*ws, vis ? vis : s, *wlen) != *wlen)
1894 638f9024 2019-05-13 stsp err = got_error_from_errno("mbstowcs");
1896 00dfcb92 2018-06-11 stsp free(vis);
1897 963b370f 2018-05-20 stsp if (err) {
1898 963b370f 2018-05-20 stsp free(*ws);
1899 963b370f 2018-05-20 stsp *ws = NULL;
1900 963b370f 2018-05-20 stsp *wlen = 0;
1902 963b370f 2018-05-20 stsp return err;
1905 145b6838 2022-06-16 stsp static const struct got_error *
1906 145b6838 2022-06-16 stsp expand_tab(char **ptr, const char *src)
1908 145b6838 2022-06-16 stsp char *dst;
1909 145b6838 2022-06-16 stsp size_t len, n, idx = 0, sz = 0;
1911 145b6838 2022-06-16 stsp *ptr = NULL;
1912 145b6838 2022-06-16 stsp n = len = strlen(src);
1913 6e1c41ad 2022-06-16 mark dst = malloc(n + 1);
1914 145b6838 2022-06-16 stsp if (dst == NULL)
1915 145b6838 2022-06-16 stsp return got_error_from_errno("malloc");
1917 145b6838 2022-06-16 stsp while (idx < len && src[idx]) {
1918 145b6838 2022-06-16 stsp const char c = src[idx];
1920 145b6838 2022-06-16 stsp if (c == '\t') {
1921 145b6838 2022-06-16 stsp size_t nb = TABSIZE - sz % TABSIZE;
1924 367ddf28 2022-06-16 mark p = realloc(dst, n + nb);
1925 6e1c41ad 2022-06-16 mark if (p == NULL) {
1926 6e1c41ad 2022-06-16 mark free(dst);
1927 6e1c41ad 2022-06-16 mark return got_error_from_errno("realloc");
1932 6e1c41ad 2022-06-16 mark memset(dst + sz, ' ', nb);
1935 145b6838 2022-06-16 stsp dst[sz++] = src[idx];
1939 145b6838 2022-06-16 stsp dst[sz] = '\0';
1940 145b6838 2022-06-16 stsp *ptr = dst;
1941 145b6838 2022-06-16 stsp return NULL;
1945 4e4a9ac8 2022-06-17 op * Advance at most n columns from wline starting at offset off.
1946 4e4a9ac8 2022-06-17 op * Return the index to the first character after the span operation.
1947 4e4a9ac8 2022-06-17 op * Return the combined column width of all spanned wide character in
1951 4e4a9ac8 2022-06-17 op span_wline(int *rcol, int off, wchar_t *wline, int n, int col_tab_align)
1953 4e4a9ac8 2022-06-17 op int width, i, cols = 0;
1955 4e4a9ac8 2022-06-17 op if (n == 0) {
1956 4e4a9ac8 2022-06-17 op *rcol = cols;
1960 4e4a9ac8 2022-06-17 op for (i = off; wline[i] != L'\0'; ++i) {
1961 4e4a9ac8 2022-06-17 op if (wline[i] == L'\t')
1962 4e4a9ac8 2022-06-17 op width = TABSIZE - ((cols + col_tab_align) % TABSIZE);
1964 4e4a9ac8 2022-06-17 op width = wcwidth(wline[i]);
1966 4e4a9ac8 2022-06-17 op if (width == -1) {
1968 4e4a9ac8 2022-06-17 op wline[i] = L'.';
1971 4e4a9ac8 2022-06-17 op if (cols + width > n)
1973 4e4a9ac8 2022-06-17 op cols += width;
1976 4e4a9ac8 2022-06-17 op *rcol = cols;
1981 ccda2f4d 2022-06-16 stsp * Format a line for display, ensuring that it won't overflow a width limit.
1982 ccda2f4d 2022-06-16 stsp * With scrolling, the width returned refers to the scrolled version of the
1983 ccda2f4d 2022-06-16 stsp * line, which starts at (*wlinep)[*scrollxp]. The caller must free *wlinep.
1985 ccda2f4d 2022-06-16 stsp static const struct got_error *
1986 ccda2f4d 2022-06-16 stsp format_line(wchar_t **wlinep, int *widthp, int *scrollxp,
1987 ccda2f4d 2022-06-16 stsp const char *line, int nscroll, int wlimit, int col_tab_align, int expand)
1989 963b370f 2018-05-20 stsp const struct got_error *err = NULL;
1991 963b370f 2018-05-20 stsp wchar_t *wline = NULL;
1992 145b6838 2022-06-16 stsp char *exstr = NULL;
1993 963b370f 2018-05-20 stsp size_t wlen;
1994 4e4a9ac8 2022-06-17 op int i, scrollx;
1996 963b370f 2018-05-20 stsp *wlinep = NULL;
1997 b700b5d6 2018-07-10 stsp *widthp = 0;
1999 145b6838 2022-06-16 stsp if (expand) {
2000 145b6838 2022-06-16 stsp err = expand_tab(&exstr, line);
2002 145b6838 2022-06-16 stsp return err;
2005 145b6838 2022-06-16 stsp err = mbs2ws(&wline, &wlen, expand ? exstr : line);
2006 145b6838 2022-06-16 stsp free(exstr);
2008 963b370f 2018-05-20 stsp return err;
2010 4e4a9ac8 2022-06-17 op scrollx = span_wline(&cols, 0, wline, nscroll, col_tab_align);
2012 3f670bfb 2020-12-10 stsp if (wlen > 0 && wline[wlen - 1] == L'\n') {
2013 3f670bfb 2020-12-10 stsp wline[wlen - 1] = L'\0';
2016 3f670bfb 2020-12-10 stsp if (wlen > 0 && wline[wlen - 1] == L'\r') {
2017 3f670bfb 2020-12-10 stsp wline[wlen - 1] = L'\0';
2021 4e4a9ac8 2022-06-17 op i = span_wline(&cols, scrollx, wline, wlimit, col_tab_align);
2022 4e4a9ac8 2022-06-17 op wline[i] = L'\0';
2024 b700b5d6 2018-07-10 stsp if (widthp)
2025 b700b5d6 2018-07-10 stsp *widthp = cols;
2026 ccda2f4d 2022-06-16 stsp if (scrollxp)
2027 ccda2f4d 2022-06-16 stsp *scrollxp = scrollx;
2029 963b370f 2018-05-20 stsp free(wline);
2031 963b370f 2018-05-20 stsp *wlinep = wline;
2032 963b370f 2018-05-20 stsp return err;
2035 8b473291 2019-02-21 stsp static const struct got_error*
2036 8b473291 2019-02-21 stsp build_refs_str(char **refs_str, struct got_reflist_head *refs,
2037 52b5abe1 2019-08-13 stsp struct got_object_id *id, struct got_repository *repo)
2039 8b473291 2019-02-21 stsp static const struct got_error *err = NULL;
2040 8b473291 2019-02-21 stsp struct got_reflist_entry *re;
2042 8b473291 2019-02-21 stsp const char *name;
2044 8b473291 2019-02-21 stsp *refs_str = NULL;
2046 d9dff0e5 2020-12-26 stsp TAILQ_FOREACH(re, refs, entry) {
2047 52b5abe1 2019-08-13 stsp struct got_tag_object *tag = NULL;
2048 48cae60d 2020-09-22 stsp struct got_object_id *ref_id;
2051 8b473291 2019-02-21 stsp name = got_ref_get_name(re->ref);
2052 8b473291 2019-02-21 stsp if (strcmp(name, GOT_REF_HEAD) == 0)
2054 8b473291 2019-02-21 stsp if (strncmp(name, "refs/", 5) == 0)
2055 8b473291 2019-02-21 stsp name += 5;
2056 cc488aa7 2022-01-23 stsp if (strncmp(name, "got/", 4) == 0 &&
2057 cc488aa7 2022-01-23 stsp strncmp(name, "got/backup/", 11) != 0)
2059 8b473291 2019-02-21 stsp if (strncmp(name, "heads/", 6) == 0)
2060 8b473291 2019-02-21 stsp name += 6;
2061 79cc719f 2020-04-24 stsp if (strncmp(name, "remotes/", 8) == 0) {
2062 8b473291 2019-02-21 stsp name += 8;
2063 79cc719f 2020-04-24 stsp s = strstr(name, "/" GOT_REF_HEAD);
2064 79cc719f 2020-04-24 stsp if (s != NULL && s[strlen(s)] == '\0')
2067 48cae60d 2020-09-22 stsp err = got_ref_resolve(&ref_id, repo, re->ref);
2070 52b5abe1 2019-08-13 stsp if (strncmp(name, "tags/", 5) == 0) {
2071 48cae60d 2020-09-22 stsp err = got_object_open_as_tag(&tag, repo, ref_id);
2072 5d844a1e 2019-08-13 stsp if (err) {
2073 48cae60d 2020-09-22 stsp if (err->code != GOT_ERR_OBJ_TYPE) {
2074 48cae60d 2020-09-22 stsp free(ref_id);
2077 5d844a1e 2019-08-13 stsp /* Ref points at something other than a tag. */
2078 5d844a1e 2019-08-13 stsp err = NULL;
2079 5d844a1e 2019-08-13 stsp tag = NULL;
2082 52b5abe1 2019-08-13 stsp cmp = got_object_id_cmp(tag ?
2083 48cae60d 2020-09-22 stsp got_object_tag_get_object_id(tag) : ref_id, id);
2084 48cae60d 2020-09-22 stsp free(ref_id);
2086 52b5abe1 2019-08-13 stsp got_object_tag_close(tag);
2087 52b5abe1 2019-08-13 stsp if (cmp != 0)
2089 8b473291 2019-02-21 stsp s = *refs_str;
2090 8b473291 2019-02-21 stsp if (asprintf(refs_str, "%s%s%s", s ? s : "",
2091 8b473291 2019-02-21 stsp s ? ", " : "", name) == -1) {
2092 638f9024 2019-05-13 stsp err = got_error_from_errno("asprintf");
2094 8b473291 2019-02-21 stsp *refs_str = NULL;
2100 8b473291 2019-02-21 stsp return err;
2103 963b370f 2018-05-20 stsp static const struct got_error *
2104 27a741e5 2019-09-11 stsp format_author(wchar_t **wauthor, int *author_width, char *author, int limit,
2105 27a741e5 2019-09-11 stsp int col_tab_align)
2107 e6b8b890 2020-12-29 naddy char *smallerthan;
2109 5813d178 2019-03-09 stsp smallerthan = strchr(author, '<');
2110 5813d178 2019-03-09 stsp if (smallerthan && smallerthan[1] != '\0')
2111 5813d178 2019-03-09 stsp author = smallerthan + 1;
2112 e6b8b890 2020-12-29 naddy author[strcspn(author, "@>")] = '\0';
2113 ccda2f4d 2022-06-16 stsp return format_line(wauthor, author_width, NULL, author, 0, limit,
2114 ccda2f4d 2022-06-16 stsp col_tab_align, 0);
2117 5813d178 2019-03-09 stsp static const struct got_error *
2118 2814baeb 2018-08-01 stsp draw_commit(struct tog_view *view, struct got_commit_object *commit,
2119 8fdc79fe 2020-12-01 naddy struct got_object_id *id, const size_t date_display_cols,
2120 8fdc79fe 2020-12-01 naddy int author_display_cols)
2122 8fdc79fe 2020-12-01 naddy struct tog_log_view_state *s = &view->state.log;
2123 80ddbec8 2018-04-29 stsp const struct got_error *err = NULL;
2124 6db9f7f6 2019-12-10 stsp char datebuf[12]; /* YYYY-MM-DD + SPACE + NUL */
2125 80ddbec8 2018-04-29 stsp char *logmsg0 = NULL, *logmsg = NULL;
2126 5813d178 2019-03-09 stsp char *author = NULL;
2127 ccda2f4d 2022-06-16 stsp wchar_t *wlogmsg = NULL, *wauthor = NULL;
2128 bb737323 2018-05-20 stsp int author_width, logmsg_width;
2129 5813d178 2019-03-09 stsp char *newline, *line = NULL;
2130 ccda2f4d 2022-06-16 stsp int col, limit, scrollx;
2131 f7d12f7e 2018-08-01 stsp const int avail = view->ncols;
2132 ccb26ccd 2018-11-05 stsp struct tm tm;
2133 45d799e2 2018-12-23 stsp time_t committer_time;
2134 11b20872 2019-11-08 stsp struct tog_color *tc;
2136 45d799e2 2018-12-23 stsp committer_time = got_object_commit_get_committer_time(commit);
2137 e385fc42 2021-08-30 stsp if (gmtime_r(&committer_time, &tm) == NULL)
2138 e385fc42 2021-08-30 stsp return got_error_from_errno("gmtime_r");
2139 ec6d1a36 2021-03-21 jrick if (strftime(datebuf, sizeof(datebuf), "%G-%m-%d ", &tm) == 0)
2140 b39d25c7 2018-07-10 stsp return got_error(GOT_ERR_NO_SPACE);
2142 27a741e5 2019-09-11 stsp if (avail <= date_display_cols)
2143 b39d25c7 2018-07-10 stsp limit = MIN(sizeof(datebuf) - 1, avail);
2145 b39d25c7 2018-07-10 stsp limit = MIN(date_display_cols, sizeof(datebuf) - 1);
2146 8fdc79fe 2020-12-01 naddy tc = get_color(&s->colors, TOG_COLOR_DATE);
2148 11b20872 2019-11-08 stsp wattr_on(view->window,
2149 11b20872 2019-11-08 stsp COLOR_PAIR(tc->colorpair), NULL);
2150 2814baeb 2018-08-01 stsp waddnstr(view->window, datebuf, limit);
2152 11b20872 2019-11-08 stsp wattr_off(view->window,
2153 11b20872 2019-11-08 stsp COLOR_PAIR(tc->colorpair), NULL);
2154 27a741e5 2019-09-11 stsp col = limit;
2155 b39d25c7 2018-07-10 stsp if (col > avail)
2156 b39d25c7 2018-07-10 stsp goto done;
2158 6570a66d 2019-11-08 stsp if (avail >= 120) {
2159 6570a66d 2019-11-08 stsp char *id_str;
2160 6570a66d 2019-11-08 stsp err = got_object_id_str(&id_str, id);
2162 6570a66d 2019-11-08 stsp goto done;
2163 8fdc79fe 2020-12-01 naddy tc = get_color(&s->colors, TOG_COLOR_COMMIT);
2165 11b20872 2019-11-08 stsp wattr_on(view->window,
2166 11b20872 2019-11-08 stsp COLOR_PAIR(tc->colorpair), NULL);
2167 6570a66d 2019-11-08 stsp wprintw(view->window, "%.8s ", id_str);
2169 11b20872 2019-11-08 stsp wattr_off(view->window,
2170 11b20872 2019-11-08 stsp COLOR_PAIR(tc->colorpair), NULL);
2171 6570a66d 2019-11-08 stsp free(id_str);
2173 6570a66d 2019-11-08 stsp if (col > avail)
2174 6570a66d 2019-11-08 stsp goto done;
2177 10aab77f 2022-07-19 op if (s->use_committer)
2178 10aab77f 2022-07-19 op author = strdup(got_object_commit_get_committer(commit));
2180 10aab77f 2022-07-19 op author = strdup(got_object_commit_get_author(commit));
2181 5813d178 2019-03-09 stsp if (author == NULL) {
2182 638f9024 2019-05-13 stsp err = got_error_from_errno("strdup");
2183 80ddbec8 2018-04-29 stsp goto done;
2185 27a741e5 2019-09-11 stsp err = format_author(&wauthor, &author_width, author, avail - col, col);
2187 bb737323 2018-05-20 stsp goto done;
2188 8fdc79fe 2020-12-01 naddy tc = get_color(&s->colors, TOG_COLOR_AUTHOR);
2190 11b20872 2019-11-08 stsp wattr_on(view->window,
2191 11b20872 2019-11-08 stsp COLOR_PAIR(tc->colorpair), NULL);
2192 2814baeb 2018-08-01 stsp waddwstr(view->window, wauthor);
2193 bb737323 2018-05-20 stsp col += author_width;
2194 27a741e5 2019-09-11 stsp while (col < avail && author_width < author_display_cols + 2) {
2195 2814baeb 2018-08-01 stsp waddch(view->window, ' ');
2197 bb737323 2018-05-20 stsp author_width++;
2200 f0f62654 2022-09-08 mark wattr_off(view->window,
2201 f0f62654 2022-09-08 mark COLOR_PAIR(tc->colorpair), NULL);
2202 9c2eaf34 2018-05-20 stsp if (col > avail)
2203 9c2eaf34 2018-05-20 stsp goto done;
2205 5943eee2 2019-08-13 stsp err = got_object_commit_get_logmsg(&logmsg0, commit);
2207 6d9fbc00 2018-04-29 stsp goto done;
2208 bb737323 2018-05-20 stsp logmsg = logmsg0;
2209 bb737323 2018-05-20 stsp while (*logmsg == '\n')
2211 bb737323 2018-05-20 stsp newline = strchr(logmsg, '\n');
2212 bb737323 2018-05-20 stsp if (newline)
2213 bb737323 2018-05-20 stsp *newline = '\0';
2214 ccda2f4d 2022-06-16 stsp limit = avail - col;
2215 49b24ee5 2022-07-03 mark if (view->child && !view_is_hsplit_top(view) && limit > 0)
2216 4d1f6af3 2022-06-17 op limit--; /* for the border */
2217 ccda2f4d 2022-06-16 stsp err = format_line(&wlogmsg, &logmsg_width, &scrollx, logmsg, view->x,
2218 ccda2f4d 2022-06-16 stsp limit, col, 1);
2220 29688b02 2022-06-16 stsp goto done;
2221 ccda2f4d 2022-06-16 stsp waddwstr(view->window, &wlogmsg[scrollx]);
2222 29688b02 2022-06-16 stsp col += MAX(logmsg_width, 0);
2223 27a741e5 2019-09-11 stsp while (col < avail) {
2224 2814baeb 2018-08-01 stsp waddch(view->window, ' ');
2228 80ddbec8 2018-04-29 stsp free(logmsg0);
2229 bb737323 2018-05-20 stsp free(wlogmsg);
2230 5813d178 2019-03-09 stsp free(author);
2231 bb737323 2018-05-20 stsp free(wauthor);
2232 80ddbec8 2018-04-29 stsp free(line);
2233 80ddbec8 2018-04-29 stsp return err;
2236 899d86c2 2018-05-10 stsp static struct commit_queue_entry *
2237 899d86c2 2018-05-10 stsp alloc_commit_queue_entry(struct got_commit_object *commit,
2238 899d86c2 2018-05-10 stsp struct got_object_id *id)
2240 80ddbec8 2018-04-29 stsp struct commit_queue_entry *entry;
2241 e15c42de 2022-09-05 op struct got_object_id *dup;
2243 80ddbec8 2018-04-29 stsp entry = calloc(1, sizeof(*entry));
2244 80ddbec8 2018-04-29 stsp if (entry == NULL)
2245 899d86c2 2018-05-10 stsp return NULL;
2247 e15c42de 2022-09-05 op dup = got_object_id_dup(id);
2248 e15c42de 2022-09-05 op if (dup == NULL) {
2249 e15c42de 2022-09-05 op free(entry);
2250 e15c42de 2022-09-05 op return NULL;
2253 e15c42de 2022-09-05 op entry->id = dup;
2254 99db9666 2018-05-07 stsp entry->commit = commit;
2255 899d86c2 2018-05-10 stsp return entry;
2258 99db9666 2018-05-07 stsp static void
2259 99db9666 2018-05-07 stsp pop_commit(struct commit_queue *commits)
2261 99db9666 2018-05-07 stsp struct commit_queue_entry *entry;
2263 ecb28ae0 2018-07-16 stsp entry = TAILQ_FIRST(&commits->head);
2264 ecb28ae0 2018-07-16 stsp TAILQ_REMOVE(&commits->head, entry, entry);
2265 99db9666 2018-05-07 stsp got_object_commit_close(entry->commit);
2266 ecb28ae0 2018-07-16 stsp commits->ncommits--;
2267 e15c42de 2022-09-05 op free(entry->id);
2268 99db9666 2018-05-07 stsp free(entry);
2271 99db9666 2018-05-07 stsp static void
2272 99db9666 2018-05-07 stsp free_commits(struct commit_queue *commits)
2274 ecb28ae0 2018-07-16 stsp while (!TAILQ_EMPTY(&commits->head))
2275 99db9666 2018-05-07 stsp pop_commit(commits);
2278 c4972b91 2018-05-07 stsp static const struct got_error *
2279 13add988 2019-10-15 stsp match_commit(int *have_match, struct got_object_id *id,
2280 13add988 2019-10-15 stsp struct got_commit_object *commit, regex_t *regex)
2282 13add988 2019-10-15 stsp const struct got_error *err = NULL;
2283 13add988 2019-10-15 stsp regmatch_t regmatch;
2284 13add988 2019-10-15 stsp char *id_str = NULL, *logmsg = NULL;
2286 13add988 2019-10-15 stsp *have_match = 0;
2288 13add988 2019-10-15 stsp err = got_object_id_str(&id_str, id);
2290 13add988 2019-10-15 stsp return err;
2292 13add988 2019-10-15 stsp err = got_object_commit_get_logmsg(&logmsg, commit);
2294 13add988 2019-10-15 stsp goto done;
2296 13add988 2019-10-15 stsp if (regexec(regex, got_object_commit_get_author(commit), 1,
2297 13add988 2019-10-15 stsp ®match, 0) == 0 ||
2298 13add988 2019-10-15 stsp regexec(regex, got_object_commit_get_committer(commit), 1,
2299 13add988 2019-10-15 stsp ®match, 0) == 0 ||
2300 13add988 2019-10-15 stsp regexec(regex, id_str, 1, ®match, 0) == 0 ||
2301 13add988 2019-10-15 stsp regexec(regex, logmsg, 1, ®match, 0) == 0)
2302 13add988 2019-10-15 stsp *have_match = 1;
2304 13add988 2019-10-15 stsp free(id_str);
2305 13add988 2019-10-15 stsp free(logmsg);
2306 13add988 2019-10-15 stsp return err;
2309 13add988 2019-10-15 stsp static const struct got_error *
2310 4e0d2870 2020-12-07 naddy queue_commits(struct tog_log_thread_args *a)
2312 899d86c2 2018-05-10 stsp const struct got_error *err = NULL;
2315 1a76625f 2018-10-22 stsp * We keep all commits open throughout the lifetime of the log
2316 1a76625f 2018-10-22 stsp * view in order to avoid having to re-fetch commits from disk
2317 1a76625f 2018-10-22 stsp * while updating the display.
2320 d9787ed8 2022-09-10 op struct got_object_id id;
2321 9ba79e04 2018-06-11 stsp struct got_commit_object *commit;
2322 93e45b7c 2018-09-24 stsp struct commit_queue_entry *entry;
2323 568eae95 2022-09-11 mark int limit_match = 0;
2324 1a76625f 2018-10-22 stsp int errcode;
2326 4e0d2870 2020-12-07 naddy err = got_commit_graph_iter_next(&id, a->graph, a->repo,
2327 4e0d2870 2020-12-07 naddy NULL, NULL);
2331 d9787ed8 2022-09-10 op err = got_object_open_as_commit(&commit, a->repo, &id);
2334 d9787ed8 2022-09-10 op entry = alloc_commit_queue_entry(commit, &id);
2335 9ba79e04 2018-06-11 stsp if (entry == NULL) {
2336 638f9024 2019-05-13 stsp err = got_error_from_errno("alloc_commit_queue_entry");
2340 1a76625f 2018-10-22 stsp errcode = pthread_mutex_lock(&tog_mutex);
2341 1a76625f 2018-10-22 stsp if (errcode) {
2342 13add988 2019-10-15 stsp err = got_error_set_errno(errcode,
2343 13add988 2019-10-15 stsp "pthread_mutex_lock");
2347 568eae95 2022-09-11 mark entry->idx = a->real_commits->ncommits;
2348 568eae95 2022-09-11 mark TAILQ_INSERT_TAIL(&a->real_commits->head, entry, entry);
2349 568eae95 2022-09-11 mark a->real_commits->ncommits++;
2351 568eae95 2022-09-11 mark if (*a->limiting) {
2352 568eae95 2022-09-11 mark err = match_commit(&limit_match, &id, commit,
2353 568eae95 2022-09-11 mark a->limit_regex);
2357 568eae95 2022-09-11 mark if (limit_match) {
2358 568eae95 2022-09-11 mark struct commit_queue_entry *matched;
2360 568eae95 2022-09-11 mark matched = alloc_commit_queue_entry(
2361 568eae95 2022-09-11 mark entry->commit, entry->id);
2362 568eae95 2022-09-11 mark if (matched == NULL) {
2363 568eae95 2022-09-11 mark err = got_error_from_errno(
2364 568eae95 2022-09-11 mark "alloc_commit_queue_entry");
2367 34a842a4 2022-09-18 mark matched->commit = entry->commit;
2368 34a842a4 2022-09-18 mark got_object_commit_retain(entry->commit);
2370 568eae95 2022-09-11 mark matched->idx = a->limit_commits->ncommits;
2371 568eae95 2022-09-11 mark TAILQ_INSERT_TAIL(&a->limit_commits->head,
2372 568eae95 2022-09-11 mark matched, entry);
2373 568eae95 2022-09-11 mark a->limit_commits->ncommits++;
2377 568eae95 2022-09-11 mark * This is how we signal log_thread() that we
2378 568eae95 2022-09-11 mark * have found a match, and that it should be
2379 568eae95 2022-09-11 mark * counted as a new entry for the view.
2381 568eae95 2022-09-11 mark a->limit_match = limit_match;
2384 4e0d2870 2020-12-07 naddy if (*a->searching == TOG_SEARCH_FORWARD &&
2385 4e0d2870 2020-12-07 naddy !*a->search_next_done) {
2386 7c1452c1 2020-03-26 stsp int have_match;
2387 d9787ed8 2022-09-10 op err = match_commit(&have_match, &id, commit, a->regex);
2391 568eae95 2022-09-11 mark if (*a->limiting) {
2392 568eae95 2022-09-11 mark if (limit_match && have_match)
2393 568eae95 2022-09-11 mark *a->search_next_done =
2394 568eae95 2022-09-11 mark TOG_SEARCH_HAVE_MORE;
2395 568eae95 2022-09-11 mark } else if (have_match)
2396 4e0d2870 2020-12-07 naddy *a->search_next_done = TOG_SEARCH_HAVE_MORE;
2399 1a76625f 2018-10-22 stsp errcode = pthread_mutex_unlock(&tog_mutex);
2400 1a76625f 2018-10-22 stsp if (errcode && err == NULL)
2401 2af4a041 2019-05-11 jcs err = got_error_set_errno(errcode,
2402 2af4a041 2019-05-11 jcs "pthread_mutex_unlock");
2405 4e0d2870 2020-12-07 naddy } while (*a->searching == TOG_SEARCH_FORWARD && !*a->search_next_done);
2407 9ba79e04 2018-06-11 stsp return err;
2410 2b779855 2020-12-05 naddy static void
2411 2b779855 2020-12-05 naddy select_commit(struct tog_log_view_state *s)
2413 2b779855 2020-12-05 naddy struct commit_queue_entry *entry;
2414 2b779855 2020-12-05 naddy int ncommits = 0;
2416 2b779855 2020-12-05 naddy entry = s->first_displayed_entry;
2417 2b779855 2020-12-05 naddy while (entry) {
2418 2b779855 2020-12-05 naddy if (ncommits == s->selected) {
2419 2b779855 2020-12-05 naddy s->selected_entry = entry;
2422 2b779855 2020-12-05 naddy entry = TAILQ_NEXT(entry, entry);
2423 2b779855 2020-12-05 naddy ncommits++;
2427 0553a4e3 2018-04-30 stsp static const struct got_error *
2428 8fdc79fe 2020-12-01 naddy draw_commits(struct tog_view *view)
2430 0553a4e3 2018-04-30 stsp const struct got_error *err = NULL;
2431 52b5abe1 2019-08-13 stsp struct tog_log_view_state *s = &view->state.log;
2432 2b779855 2020-12-05 naddy struct commit_queue_entry *entry = s->selected_entry;
2433 cbb0c8d7 2022-08-12 mark int limit = view->nlines;
2434 60493ae3 2019-06-20 stsp int width;
2435 52e88aae 2019-11-08 stsp int ncommits, author_cols = 4;
2436 1a76625f 2018-10-22 stsp char *id_str = NULL, *header = NULL, *ncommits_str = NULL;
2437 8b473291 2019-02-21 stsp char *refs_str = NULL;
2438 ecb28ae0 2018-07-16 stsp wchar_t *wline;
2439 11b20872 2019-11-08 stsp struct tog_color *tc;
2440 6db9f7f6 2019-12-10 stsp static const size_t date_display_cols = 12;
2442 cbb0c8d7 2022-08-12 mark if (view_is_hsplit_top(view))
2443 cbb0c8d7 2022-08-12 mark --limit; /* account for border */
2445 8fdc79fe 2020-12-01 naddy if (s->selected_entry &&
2446 8fdc79fe 2020-12-01 naddy !(view->searching && view->search_next_done == 0)) {
2447 d2075bf3 2020-12-25 stsp struct got_reflist_head *refs;
2448 8fdc79fe 2020-12-01 naddy err = got_object_id_str(&id_str, s->selected_entry->id);
2450 ecb28ae0 2018-07-16 stsp return err;
2451 51a10b52 2020-12-26 stsp refs = got_reflist_object_id_map_lookup(tog_refs_idmap,
2452 d2075bf3 2020-12-25 stsp s->selected_entry->id);
2453 d2075bf3 2020-12-25 stsp if (refs) {
2454 d2075bf3 2020-12-25 stsp err = build_refs_str(&refs_str, refs,
2455 d2075bf3 2020-12-25 stsp s->selected_entry->id, s->repo);
2457 d2075bf3 2020-12-25 stsp goto done;
2461 8fdc79fe 2020-12-01 naddy if (s->thread_args.commits_needed == 0)
2462 359bfafd 2019-02-22 stsp halfdelay(10); /* disable fast refresh */
2464 fb280deb 2021-08-30 stsp if (s->thread_args.commits_needed > 0 || s->thread_args.load_all) {
2465 8f4ed634 2020-03-26 stsp if (asprintf(&ncommits_str, " [%d/%d] %s",
2466 568eae95 2022-09-11 mark entry ? entry->idx + 1 : 0, s->commits->ncommits,
2467 38d166d8 2022-09-23 stsp (view->searching && !view->search_next_done) ?
2468 38d166d8 2022-09-23 stsp "searching..." : "loading...") == -1) {
2469 8f4ed634 2020-03-26 stsp err = got_error_from_errno("asprintf");
2470 8f4ed634 2020-03-26 stsp goto done;
2473 f9686aa5 2020-03-27 stsp const char *search_str = NULL;
2474 568eae95 2022-09-11 mark const char *limit_str = NULL;
2476 f9686aa5 2020-03-27 stsp if (view->searching) {
2477 f9686aa5 2020-03-27 stsp if (view->search_next_done == TOG_SEARCH_NO_MORE)
2478 f9686aa5 2020-03-27 stsp search_str = "no more matches";
2479 f9686aa5 2020-03-27 stsp else if (view->search_next_done == TOG_SEARCH_HAVE_NONE)
2480 f9686aa5 2020-03-27 stsp search_str = "no matches found";
2481 f9686aa5 2020-03-27 stsp else if (!view->search_next_done)
2482 f9686aa5 2020-03-27 stsp search_str = "searching...";
2485 568eae95 2022-09-11 mark if (s->limit_view && s->commits->ncommits == 0)
2486 568eae95 2022-09-11 mark limit_str = "no matches found";
2488 568eae95 2022-09-11 mark if (asprintf(&ncommits_str, " [%d/%d] %s %s",
2489 568eae95 2022-09-11 mark entry ? entry->idx + 1 : 0, s->commits->ncommits,
2490 568eae95 2022-09-11 mark search_str ? search_str : (refs_str ? refs_str : ""),
2491 568eae95 2022-09-11 mark limit_str ? limit_str : "") == -1) {
2492 8f4ed634 2020-03-26 stsp err = got_error_from_errno("asprintf");
2493 8f4ed634 2020-03-26 stsp goto done;
2497 8fdc79fe 2020-12-01 naddy if (s->in_repo_path && strcmp(s->in_repo_path, "/") != 0) {
2498 87411fa9 2022-06-16 stsp if (asprintf(&header, "commit %s %s%s", id_str ? id_str :
2499 87411fa9 2022-06-16 stsp "........................................",
2500 8fdc79fe 2020-12-01 naddy s->in_repo_path, ncommits_str) == -1) {
2501 638f9024 2019-05-13 stsp err = got_error_from_errno("asprintf");
2502 1a76625f 2018-10-22 stsp header = NULL;
2503 1a76625f 2018-10-22 stsp goto done;
2505 c1124f18 2018-12-23 stsp } else if (asprintf(&header, "commit %s%s",
2506 1a76625f 2018-10-22 stsp id_str ? id_str : "........................................",
2507 1a76625f 2018-10-22 stsp ncommits_str) == -1) {
2508 638f9024 2019-05-13 stsp err = got_error_from_errno("asprintf");
2509 1a76625f 2018-10-22 stsp header = NULL;
2510 1a76625f 2018-10-22 stsp goto done;
2512 ccda2f4d 2022-06-16 stsp err = format_line(&wline, &width, NULL, header, 0, view->ncols, 0, 0);
2514 1a76625f 2018-10-22 stsp goto done;
2516 2814baeb 2018-08-01 stsp werase(view->window);
2518 a3404814 2018-09-02 stsp if (view_needs_focus_indication(view))
2519 a3404814 2018-09-02 stsp wstandout(view->window);
2520 8fdc79fe 2020-12-01 naddy tc = get_color(&s->colors, TOG_COLOR_COMMIT);
2522 0c6ad1bc 2022-09-09 mark wattr_on(view->window, COLOR_PAIR(tc->colorpair), NULL);
2523 2814baeb 2018-08-01 stsp waddwstr(view->window, wline);
2524 1a76625f 2018-10-22 stsp while (width < view->ncols) {
2525 1a76625f 2018-10-22 stsp waddch(view->window, ' ');
2529 0c6ad1bc 2022-09-09 mark wattr_off(view->window, COLOR_PAIR(tc->colorpair), NULL);
2530 a3404814 2018-09-02 stsp if (view_needs_focus_indication(view))
2531 a3404814 2018-09-02 stsp wstandend(view->window);
2532 ecb28ae0 2018-07-16 stsp free(wline);
2533 ecb28ae0 2018-07-16 stsp if (limit <= 1)
2534 1a76625f 2018-10-22 stsp goto done;
2536 29688b02 2022-06-16 stsp /* Grow author column size if necessary, and set view->maxx. */
2537 8fdc79fe 2020-12-01 naddy entry = s->first_displayed_entry;
2538 5813d178 2019-03-09 stsp ncommits = 0;
2539 145b6838 2022-06-16 stsp view->maxx = 0;
2540 5813d178 2019-03-09 stsp while (entry) {
2541 10aab77f 2022-07-19 op struct got_commit_object *c = entry->commit;
2542 145b6838 2022-06-16 stsp char *author, *eol, *msg, *msg0;
2543 29688b02 2022-06-16 stsp wchar_t *wauthor, *wmsg;
2544 5813d178 2019-03-09 stsp int width;
2545 5813d178 2019-03-09 stsp if (ncommits >= limit - 1)
2547 10aab77f 2022-07-19 op if (s->use_committer)
2548 10aab77f 2022-07-19 op author = strdup(got_object_commit_get_committer(c));
2550 10aab77f 2022-07-19 op author = strdup(got_object_commit_get_author(c));
2551 5813d178 2019-03-09 stsp if (author == NULL) {
2552 638f9024 2019-05-13 stsp err = got_error_from_errno("strdup");
2553 5813d178 2019-03-09 stsp goto done;
2555 27a741e5 2019-09-11 stsp err = format_author(&wauthor, &width, author, COLS,
2556 27a741e5 2019-09-11 stsp date_display_cols);
2557 5813d178 2019-03-09 stsp if (author_cols < width)
2558 5813d178 2019-03-09 stsp author_cols = width;
2559 5813d178 2019-03-09 stsp free(wauthor);
2560 5813d178 2019-03-09 stsp free(author);
2561 a310d9c3 2022-07-21 florian if (err)
2562 a310d9c3 2022-07-21 florian goto done;
2563 10aab77f 2022-07-19 op err = got_object_commit_get_logmsg(&msg0, c);
2565 145b6838 2022-06-16 stsp goto done;
2566 145b6838 2022-06-16 stsp msg = msg0;
2567 145b6838 2022-06-16 stsp while (*msg == '\n')
2569 145b6838 2022-06-16 stsp if ((eol = strchr(msg, '\n')))
2570 29688b02 2022-06-16 stsp *eol = '\0';
2571 ccda2f4d 2022-06-16 stsp err = format_line(&wmsg, &width, NULL, msg, 0, INT_MAX,
2572 29688b02 2022-06-16 stsp date_display_cols + author_cols, 0);
2574 29688b02 2022-06-16 stsp goto done;
2575 29688b02 2022-06-16 stsp view->maxx = MAX(view->maxx, width);
2576 145b6838 2022-06-16 stsp free(msg0);
2577 29688b02 2022-06-16 stsp free(wmsg);
2578 7ca04879 2019-10-19 stsp ncommits++;
2579 5813d178 2019-03-09 stsp entry = TAILQ_NEXT(entry, entry);
2582 8fdc79fe 2020-12-01 naddy entry = s->first_displayed_entry;
2583 8fdc79fe 2020-12-01 naddy s->last_displayed_entry = s->first_displayed_entry;
2584 867c6645 2018-07-10 stsp ncommits = 0;
2585 899d86c2 2018-05-10 stsp while (entry) {
2586 ecb28ae0 2018-07-16 stsp if (ncommits >= limit - 1)
2588 8fdc79fe 2020-12-01 naddy if (ncommits == s->selected)
2589 2814baeb 2018-08-01 stsp wstandout(view->window);
2590 8fdc79fe 2020-12-01 naddy err = draw_commit(view, entry->commit, entry->id,
2591 8fdc79fe 2020-12-01 naddy date_display_cols, author_cols);
2592 8fdc79fe 2020-12-01 naddy if (ncommits == s->selected)
2593 2814baeb 2018-08-01 stsp wstandend(view->window);
2595 60493ae3 2019-06-20 stsp goto done;
2596 0553a4e3 2018-04-30 stsp ncommits++;
2597 8fdc79fe 2020-12-01 naddy s->last_displayed_entry = entry;
2598 899d86c2 2018-05-10 stsp entry = TAILQ_NEXT(entry, entry);
2601 9b058f45 2022-06-30 mark view_border(view);
2603 1a76625f 2018-10-22 stsp free(id_str);
2604 8b473291 2019-02-21 stsp free(refs_str);
2605 1a76625f 2018-10-22 stsp free(ncommits_str);
2606 1a76625f 2018-10-22 stsp free(header);
2607 80ddbec8 2018-04-29 stsp return err;
2610 07b55e75 2018-05-10 stsp static void
2611 3e135950 2020-12-01 naddy log_scroll_up(struct tog_log_view_state *s, int maxscroll)
2613 07b55e75 2018-05-10 stsp struct commit_queue_entry *entry;
2614 07b55e75 2018-05-10 stsp int nscrolled = 0;
2616 568eae95 2022-09-11 mark entry = TAILQ_FIRST(&s->commits->head);
2617 ffe38506 2020-12-01 naddy if (s->first_displayed_entry == entry)
2620 ffe38506 2020-12-01 naddy entry = s->first_displayed_entry;
2621 16482c3b 2018-05-20 stsp while (entry && nscrolled < maxscroll) {
2622 ecb28ae0 2018-07-16 stsp entry = TAILQ_PREV(entry, commit_queue_head, entry);
2623 07b55e75 2018-05-10 stsp if (entry) {
2624 ffe38506 2020-12-01 naddy s->first_displayed_entry = entry;
2625 07b55e75 2018-05-10 stsp nscrolled++;
2630 aa075928 2018-05-10 stsp static const struct got_error *
2631 ffe38506 2020-12-01 naddy trigger_log_thread(struct tog_view *view, int wait)
2633 ffe38506 2020-12-01 naddy struct tog_log_thread_args *ta = &view->state.log.thread_args;
2634 5e224a3e 2019-02-22 stsp int errcode;
2636 8a42fca8 2019-02-22 stsp halfdelay(1); /* fast refresh while loading commits */
2638 5629093a 2022-07-11 stsp while (!ta->log_complete && !tog_thread_error &&
2639 5629093a 2022-07-11 stsp (ta->commits_needed > 0 || ta->load_all)) {
2640 5e224a3e 2019-02-22 stsp /* Wake the log thread. */
2641 ffe38506 2020-12-01 naddy errcode = pthread_cond_signal(&ta->need_commits);
2642 7aafa0d1 2019-02-22 stsp if (errcode)
2643 2af4a041 2019-05-11 jcs return got_error_set_errno(errcode,
2644 2af4a041 2019-05-11 jcs "pthread_cond_signal");
2647 7c1452c1 2020-03-26 stsp * The mutex will be released while the view loop waits
2648 7c1452c1 2020-03-26 stsp * in wgetch(), at which time the log thread will run.
2650 7c1452c1 2020-03-26 stsp if (!wait)
2653 7c1452c1 2020-03-26 stsp /* Display progress update in log view. */
2654 ffe38506 2020-12-01 naddy show_log_view(view);
2655 7c1452c1 2020-03-26 stsp update_panels();
2656 7c1452c1 2020-03-26 stsp doupdate();
2658 7c1452c1 2020-03-26 stsp /* Wait right here while next commit is being loaded. */
2659 ffe38506 2020-12-01 naddy errcode = pthread_cond_wait(&ta->commit_loaded, &tog_mutex);
2660 82954512 2020-02-03 stsp if (errcode)
2661 82954512 2020-02-03 stsp return got_error_set_errno(errcode,
2662 7c1452c1 2020-03-26 stsp "pthread_cond_wait");
2664 7c1452c1 2020-03-26 stsp /* Display progress update in log view. */
2665 ffe38506 2020-12-01 naddy show_log_view(view);
2666 7c1452c1 2020-03-26 stsp update_panels();
2667 7c1452c1 2020-03-26 stsp doupdate();
2670 5e224a3e 2019-02-22 stsp return NULL;
2673 5e224a3e 2019-02-22 stsp static const struct got_error *
2674 9b058f45 2022-06-30 mark request_log_commits(struct tog_view *view)
2676 9b058f45 2022-06-30 mark struct tog_log_view_state *state = &view->state.log;
2677 9b058f45 2022-06-30 mark const struct got_error *err = NULL;
2679 2525dccb 2022-07-13 mark if (state->thread_args.log_complete)
2680 2525dccb 2022-07-13 mark return NULL;
2682 27187d45 2022-07-11 mark state->thread_args.commits_needed += view->nscrolled;
2683 9b058f45 2022-06-30 mark err = trigger_log_thread(view, 1);
2684 9b058f45 2022-06-30 mark view->nscrolled = 0;
2686 9b058f45 2022-06-30 mark return err;
2689 9b058f45 2022-06-30 mark static const struct got_error *
2690 ffe38506 2020-12-01 naddy log_scroll_down(struct tog_view *view, int maxscroll)
2692 ffe38506 2020-12-01 naddy struct tog_log_view_state *s = &view->state.log;
2693 5e224a3e 2019-02-22 stsp const struct got_error *err = NULL;
2694 5e224a3e 2019-02-22 stsp struct commit_queue_entry *pentry;
2695 7c1452c1 2020-03-26 stsp int nscrolled = 0, ncommits_needed;
2697 ffe38506 2020-12-01 naddy if (s->last_displayed_entry == NULL)
2698 5e224a3e 2019-02-22 stsp return NULL;
2700 bf30f154 2020-12-07 naddy ncommits_needed = s->last_displayed_entry->idx + 1 + maxscroll;
2701 568eae95 2022-09-11 mark if (s->commits->ncommits < ncommits_needed &&
2702 ffe38506 2020-12-01 naddy !s->thread_args.log_complete) {
2704 7c1452c1 2020-03-26 stsp * Ask the log thread for required amount of commits.
2706 94b80cfa 2022-08-01 mark s->thread_args.commits_needed +=
2707 568eae95 2022-09-11 mark ncommits_needed - s->commits->ncommits;
2708 ffe38506 2020-12-01 naddy err = trigger_log_thread(view, 1);
2710 5e224a3e 2019-02-22 stsp return err;
2714 ffe38506 2020-12-01 naddy pentry = TAILQ_NEXT(s->last_displayed_entry, entry);
2715 9b058f45 2022-06-30 mark if (pentry == NULL && view->mode != TOG_VIEW_SPLIT_HRZN)
2718 9b058f45 2022-06-30 mark s->last_displayed_entry = pentry ?
2719 9b058f45 2022-06-30 mark pentry : s->last_displayed_entry;;
2721 ffe38506 2020-12-01 naddy pentry = TAILQ_NEXT(s->first_displayed_entry, entry);
2722 dd0a52c1 2018-05-20 stsp if (pentry == NULL)
2724 ffe38506 2020-12-01 naddy s->first_displayed_entry = pentry;
2725 16482c3b 2018-05-20 stsp } while (++nscrolled < maxscroll);
2727 2525dccb 2022-07-13 mark if (view->mode == TOG_VIEW_SPLIT_HRZN && !s->thread_args.log_complete)
2728 9b058f45 2022-06-30 mark view->nscrolled += nscrolled;
2730 9b058f45 2022-06-30 mark view->nscrolled = 0;
2732 dd0a52c1 2018-05-20 stsp return err;
2735 cd0acaa7 2018-05-20 stsp static const struct got_error *
2736 9b058f45 2022-06-30 mark open_diff_view_for_commit(struct tog_view **new_view, int begin_y, int begin_x,
2737 fb872ab2 2019-02-21 stsp struct got_commit_object *commit, struct got_object_id *commit_id,
2738 78756c87 2020-11-24 stsp struct tog_view *log_view, struct got_repository *repo)
2740 cd0acaa7 2018-05-20 stsp const struct got_error *err;
2741 9ba79e04 2018-06-11 stsp struct got_object_qid *parent_id;
2742 e5a0f69f 2018-08-18 stsp struct tog_view *diff_view;
2744 9b058f45 2022-06-30 mark diff_view = view_open(0, 0, begin_y, begin_x, TOG_VIEW_DIFF);
2745 15a94983 2018-12-23 stsp if (diff_view == NULL)
2746 638f9024 2019-05-13 stsp return got_error_from_errno("view_open");
2748 dbdddfee 2021-06-23 naddy parent_id = STAILQ_FIRST(got_object_commit_get_parent_ids(commit));
2749 d7b5a0e8 2022-04-20 stsp err = open_diff_view(diff_view, parent_id ? &parent_id->id : NULL,
2750 78756c87 2020-11-24 stsp commit_id, NULL, NULL, 3, 0, 0, log_view, repo);
2751 e5a0f69f 2018-08-18 stsp if (err == NULL)
2752 e5a0f69f 2018-08-18 stsp *new_view = diff_view;
2753 cd0acaa7 2018-05-20 stsp return err;
2756 80ddbec8 2018-04-29 stsp static const struct got_error *
2757 42a2230c 2020-12-01 naddy tree_view_visit_subtree(struct tog_tree_view_state *s,
2758 42a2230c 2020-12-01 naddy struct got_tree_object *subtree)
2760 941e9f74 2019-05-21 stsp struct tog_parent_tree *parent;
2762 941e9f74 2019-05-21 stsp parent = calloc(1, sizeof(*parent));
2763 941e9f74 2019-05-21 stsp if (parent == NULL)
2764 941e9f74 2019-05-21 stsp return got_error_from_errno("calloc");
2766 941e9f74 2019-05-21 stsp parent->tree = s->tree;
2767 941e9f74 2019-05-21 stsp parent->first_displayed_entry = s->first_displayed_entry;
2768 941e9f74 2019-05-21 stsp parent->selected_entry = s->selected_entry;
2769 941e9f74 2019-05-21 stsp parent->selected = s->selected;
2770 941e9f74 2019-05-21 stsp TAILQ_INSERT_HEAD(&s->parents, parent, entry);
2771 941e9f74 2019-05-21 stsp s->tree = subtree;
2772 941e9f74 2019-05-21 stsp s->selected = 0;
2773 941e9f74 2019-05-21 stsp s->first_displayed_entry = NULL;
2774 941e9f74 2019-05-21 stsp return NULL;
2777 941e9f74 2019-05-21 stsp static const struct got_error *
2778 55cccc34 2020-02-20 stsp tree_view_walk_path(struct tog_tree_view_state *s,
2779 a44927cc 2022-04-07 stsp struct got_commit_object *commit, const char *path)
2781 9343a5fb 2018-06-23 stsp const struct got_error *err = NULL;
2782 55cccc34 2020-02-20 stsp struct got_tree_object *tree = NULL;
2783 941e9f74 2019-05-21 stsp const char *p;
2784 55cccc34 2020-02-20 stsp char *slash, *subpath = NULL;
2786 941e9f74 2019-05-21 stsp /* Walk the path and open corresponding tree objects. */
2788 941e9f74 2019-05-21 stsp while (*p) {
2789 56e0773d 2019-11-28 stsp struct got_tree_entry *te;
2790 941e9f74 2019-05-21 stsp struct got_object_id *tree_id;
2791 56e0773d 2019-11-28 stsp char *te_name;
2793 33cbf02b 2020-01-12 stsp while (p[0] == '/')
2796 941e9f74 2019-05-21 stsp /* Ensure the correct subtree entry is selected. */
2797 941e9f74 2019-05-21 stsp slash = strchr(p, '/');
2798 941e9f74 2019-05-21 stsp if (slash == NULL)
2799 33cbf02b 2020-01-12 stsp te_name = strdup(p);
2801 33cbf02b 2020-01-12 stsp te_name = strndup(p, slash - p);
2802 56e0773d 2019-11-28 stsp if (te_name == NULL) {
2803 56e0773d 2019-11-28 stsp err = got_error_from_errno("strndup");
2806 56e0773d 2019-11-28 stsp te = got_object_tree_find_entry(s->tree, te_name);
2807 56e0773d 2019-11-28 stsp if (te == NULL) {
2808 56e0773d 2019-11-28 stsp err = got_error_path(te_name, GOT_ERR_NO_TREE_ENTRY);
2809 56e0773d 2019-11-28 stsp free(te_name);
2812 56e0773d 2019-11-28 stsp free(te_name);
2813 9a1d5146 2020-11-27 naddy s->first_displayed_entry = s->selected_entry = te;
2815 9a1d5146 2020-11-27 naddy if (!S_ISDIR(got_tree_entry_get_mode(s->selected_entry)))
2816 9a1d5146 2020-11-27 naddy break; /* jump to this file's entry */
2818 941e9f74 2019-05-21 stsp slash = strchr(p, '/');
2819 941e9f74 2019-05-21 stsp if (slash)
2820 941e9f74 2019-05-21 stsp subpath = strndup(path, slash - path);
2822 941e9f74 2019-05-21 stsp subpath = strdup(path);
2823 941e9f74 2019-05-21 stsp if (subpath == NULL) {
2824 941e9f74 2019-05-21 stsp err = got_error_from_errno("strdup");
2828 a44927cc 2022-04-07 stsp err = got_object_id_by_path(&tree_id, s->repo, commit,
2833 d91faf3b 2020-12-01 naddy err = got_object_open_as_tree(&tree, s->repo, tree_id);
2834 941e9f74 2019-05-21 stsp free(tree_id);
2838 42a2230c 2020-12-01 naddy err = tree_view_visit_subtree(s, tree);
2839 941e9f74 2019-05-21 stsp if (err) {
2840 941e9f74 2019-05-21 stsp got_object_tree_close(tree);
2843 941e9f74 2019-05-21 stsp if (slash == NULL)
2845 941e9f74 2019-05-21 stsp free(subpath);
2846 941e9f74 2019-05-21 stsp subpath = NULL;
2847 941e9f74 2019-05-21 stsp p = slash;
2850 941e9f74 2019-05-21 stsp free(subpath);
2851 1a76625f 2018-10-22 stsp return err;
2854 61266923 2020-01-14 stsp static const struct got_error *
2855 49b24ee5 2022-07-03 mark browse_commit_tree(struct tog_view **new_view, int begin_y, int begin_x,
2856 55cccc34 2020-02-20 stsp struct commit_queue_entry *entry, const char *path,
2857 4e97c21c 2020-12-06 stsp const char *head_ref_name, struct got_repository *repo)
2859 55cccc34 2020-02-20 stsp const struct got_error *err = NULL;
2860 55cccc34 2020-02-20 stsp struct tog_tree_view_state *s;
2861 55cccc34 2020-02-20 stsp struct tog_view *tree_view;
2863 49b24ee5 2022-07-03 mark tree_view = view_open(0, 0, begin_y, begin_x, TOG_VIEW_TREE);
2864 55cccc34 2020-02-20 stsp if (tree_view == NULL)
2865 55cccc34 2020-02-20 stsp return got_error_from_errno("view_open");
2867 bc573f3b 2021-07-10 stsp err = open_tree_view(tree_view, entry->id, head_ref_name, repo);
2869 55cccc34 2020-02-20 stsp return err;
2870 55cccc34 2020-02-20 stsp s = &tree_view->state.tree;
2872 55cccc34 2020-02-20 stsp *new_view = tree_view;
2874 55cccc34 2020-02-20 stsp if (got_path_is_root_dir(path))
2875 55cccc34 2020-02-20 stsp return NULL;
2877 a44927cc 2022-04-07 stsp return tree_view_walk_path(s, entry->commit, path);
2880 55cccc34 2020-02-20 stsp static const struct got_error *
2881 61266923 2020-01-14 stsp block_signals_used_by_main_thread(void)
2883 61266923 2020-01-14 stsp sigset_t sigset;
2884 61266923 2020-01-14 stsp int errcode;
2886 61266923 2020-01-14 stsp if (sigemptyset(&sigset) == -1)
2887 61266923 2020-01-14 stsp return got_error_from_errno("sigemptyset");
2889 2497f032 2022-05-31 stsp /* tog handles SIGWINCH, SIGCONT, SIGINT, SIGTERM */
2890 61266923 2020-01-14 stsp if (sigaddset(&sigset, SIGWINCH) == -1)
2891 61266923 2020-01-14 stsp return got_error_from_errno("sigaddset");
2892 61266923 2020-01-14 stsp if (sigaddset(&sigset, SIGCONT) == -1)
2893 2497f032 2022-05-31 stsp return got_error_from_errno("sigaddset");
2894 2497f032 2022-05-31 stsp if (sigaddset(&sigset, SIGINT) == -1)
2895 61266923 2020-01-14 stsp return got_error_from_errno("sigaddset");
2896 2497f032 2022-05-31 stsp if (sigaddset(&sigset, SIGTERM) == -1)
2897 2497f032 2022-05-31 stsp return got_error_from_errno("sigaddset");
2899 61266923 2020-01-14 stsp /* ncurses handles SIGTSTP */
2900 61266923 2020-01-14 stsp if (sigaddset(&sigset, SIGTSTP) == -1)
2901 61266923 2020-01-14 stsp return got_error_from_errno("sigaddset");
2903 61266923 2020-01-14 stsp errcode = pthread_sigmask(SIG_BLOCK, &sigset, NULL);
2904 61266923 2020-01-14 stsp if (errcode)
2905 61266923 2020-01-14 stsp return got_error_set_errno(errcode, "pthread_sigmask");
2907 61266923 2020-01-14 stsp return NULL;
2910 1a76625f 2018-10-22 stsp static void *
2911 1a76625f 2018-10-22 stsp log_thread(void *arg)
2913 1a76625f 2018-10-22 stsp const struct got_error *err = NULL;
2914 1a76625f 2018-10-22 stsp int errcode = 0;
2915 1a76625f 2018-10-22 stsp struct tog_log_thread_args *a = arg;
2916 1a76625f 2018-10-22 stsp int done = 0;
2919 5629093a 2022-07-11 stsp * Sync startup with main thread such that we begin our
2920 5629093a 2022-07-11 stsp * work once view_input() has released the mutex.
2922 5629093a 2022-07-11 stsp errcode = pthread_mutex_lock(&tog_mutex);
2923 5629093a 2022-07-11 stsp if (errcode) {
2924 5629093a 2022-07-11 stsp err = got_error_set_errno(errcode, "pthread_mutex_lock");
2925 61266923 2020-01-14 stsp return (void *)err;
2928 5629093a 2022-07-11 stsp err = block_signals_used_by_main_thread();
2929 5629093a 2022-07-11 stsp if (err) {
2930 5629093a 2022-07-11 stsp pthread_mutex_unlock(&tog_mutex);
2931 5629093a 2022-07-11 stsp goto done;
2934 2497f032 2022-05-31 stsp while (!done && !err && !tog_fatal_signal_received()) {
2935 5629093a 2022-07-11 stsp errcode = pthread_mutex_unlock(&tog_mutex);
2936 5629093a 2022-07-11 stsp if (errcode) {
2937 5629093a 2022-07-11 stsp err = got_error_set_errno(errcode,
2938 5629093a 2022-07-11 stsp "pthread_mutex_unlock");
2939 5629093a 2022-07-11 stsp goto done;
2941 4e0d2870 2020-12-07 naddy err = queue_commits(a);
2942 1a76625f 2018-10-22 stsp if (err) {
2943 1a76625f 2018-10-22 stsp if (err->code != GOT_ERR_ITER_COMPLETED)
2944 5629093a 2022-07-11 stsp goto done;
2945 1a76625f 2018-10-22 stsp err = NULL;
2947 568eae95 2022-09-11 mark } else if (a->commits_needed > 0 && !a->load_all) {
2948 568eae95 2022-09-11 mark if (*a->limiting) {
2949 568eae95 2022-09-11 mark if (a->limit_match)
2950 568eae95 2022-09-11 mark a->commits_needed--;
2952 568eae95 2022-09-11 mark a->commits_needed--;
2955 1a76625f 2018-10-22 stsp errcode = pthread_mutex_lock(&tog_mutex);
2956 3abe8080 2019-04-10 stsp if (errcode) {
2957 2af4a041 2019-05-11 jcs err = got_error_set_errno(errcode,
2958 2af4a041 2019-05-11 jcs "pthread_mutex_lock");
2959 5629093a 2022-07-11 stsp goto done;
2960 3abe8080 2019-04-10 stsp } else if (*a->quit)
2962 568eae95 2022-09-11 mark else if (*a->limiting && *a->first_displayed_entry == NULL) {
2963 1a76625f 2018-10-22 stsp *a->first_displayed_entry =
2964 568eae95 2022-09-11 mark TAILQ_FIRST(&a->limit_commits->head);
2965 1a76625f 2018-10-22 stsp *a->selected_entry = *a->first_displayed_entry;
2966 568eae95 2022-09-11 mark } else if (*a->first_displayed_entry == NULL) {
2967 568eae95 2022-09-11 mark *a->first_displayed_entry =
2968 568eae95 2022-09-11 mark TAILQ_FIRST(&a->real_commits->head);
2969 568eae95 2022-09-11 mark *a->selected_entry = *a->first_displayed_entry;
2972 7c1452c1 2020-03-26 stsp errcode = pthread_cond_signal(&a->commit_loaded);
2973 7c1452c1 2020-03-26 stsp if (errcode) {
2974 7c1452c1 2020-03-26 stsp err = got_error_set_errno(errcode,
2975 7c1452c1 2020-03-26 stsp "pthread_cond_signal");
2976 7c1452c1 2020-03-26 stsp pthread_mutex_unlock(&tog_mutex);
2977 5629093a 2022-07-11 stsp goto done;
2981 1a76625f 2018-10-22 stsp a->commits_needed = 0;
2983 fb280deb 2021-08-30 stsp if (a->commits_needed == 0 && !a->load_all) {
2984 7c1452c1 2020-03-26 stsp errcode = pthread_cond_wait(&a->need_commits,
2985 7c1452c1 2020-03-26 stsp &tog_mutex);
2986 5629093a 2022-07-11 stsp if (errcode) {
2987 7c1452c1 2020-03-26 stsp err = got_error_set_errno(errcode,
2988 7c1452c1 2020-03-26 stsp "pthread_cond_wait");
2989 5629093a 2022-07-11 stsp pthread_mutex_unlock(&tog_mutex);
2990 5629093a 2022-07-11 stsp goto done;
2992 21355643 2020-12-06 stsp if (*a->quit)
2997 3abe8080 2019-04-10 stsp a->log_complete = 1;
2998 5629093a 2022-07-11 stsp errcode = pthread_mutex_unlock(&tog_mutex);
2999 5629093a 2022-07-11 stsp if (errcode)
3000 5629093a 2022-07-11 stsp err = got_error_set_errno(errcode, "pthread_mutex_unlock");
3002 5629093a 2022-07-11 stsp if (err) {
3003 5629093a 2022-07-11 stsp tog_thread_error = 1;
3004 5629093a 2022-07-11 stsp pthread_cond_signal(&a->commit_loaded);
3006 1a76625f 2018-10-22 stsp return (void *)err;
3009 1a76625f 2018-10-22 stsp static const struct got_error *
3010 1a76625f 2018-10-22 stsp stop_log_thread(struct tog_log_view_state *s)
3012 5629093a 2022-07-11 stsp const struct got_error *err = NULL, *thread_err = NULL;
3013 1a76625f 2018-10-22 stsp int errcode;
3015 1a76625f 2018-10-22 stsp if (s->thread) {
3016 1a76625f 2018-10-22 stsp s->quit = 1;
3017 1a76625f 2018-10-22 stsp errcode = pthread_cond_signal(&s->thread_args.need_commits);
3018 1a76625f 2018-10-22 stsp if (errcode)
3019 2af4a041 2019-05-11 jcs return got_error_set_errno(errcode,
3020 2af4a041 2019-05-11 jcs "pthread_cond_signal");
3021 1a76625f 2018-10-22 stsp errcode = pthread_mutex_unlock(&tog_mutex);
3022 1a76625f 2018-10-22 stsp if (errcode)
3023 2af4a041 2019-05-11 jcs return got_error_set_errno(errcode,
3024 2af4a041 2019-05-11 jcs "pthread_mutex_unlock");
3025 5629093a 2022-07-11 stsp errcode = pthread_join(s->thread, (void **)&thread_err);
3026 1a76625f 2018-10-22 stsp if (errcode)
3027 2af4a041 2019-05-11 jcs return got_error_set_errno(errcode, "pthread_join");
3028 1a76625f 2018-10-22 stsp errcode = pthread_mutex_lock(&tog_mutex);
3029 1a76625f 2018-10-22 stsp if (errcode)
3030 2af4a041 2019-05-11 jcs return got_error_set_errno(errcode,
3031 2af4a041 2019-05-11 jcs "pthread_mutex_lock");
3032 1a76625f 2018-10-22 stsp s->thread = NULL;
3035 1a76625f 2018-10-22 stsp if (s->thread_args.repo) {
3036 1d0f4054 2021-06-17 stsp err = got_repo_close(s->thread_args.repo);
3037 1a76625f 2018-10-22 stsp s->thread_args.repo = NULL;
3040 74467cc8 2022-06-15 stsp if (s->thread_args.pack_fds) {
3041 74467cc8 2022-06-15 stsp const struct got_error *pack_err =
3042 74467cc8 2022-06-15 stsp got_repo_pack_fds_close(s->thread_args.pack_fds);
3043 74467cc8 2022-06-15 stsp if (err == NULL)
3044 74467cc8 2022-06-15 stsp err = pack_err;
3045 74467cc8 2022-06-15 stsp s->thread_args.pack_fds = NULL;
3048 1a76625f 2018-10-22 stsp if (s->thread_args.graph) {
3049 1a76625f 2018-10-22 stsp got_commit_graph_close(s->thread_args.graph);
3050 1a76625f 2018-10-22 stsp s->thread_args.graph = NULL;
3053 5629093a 2022-07-11 stsp return err ? err : thread_err;
3056 9343a5fb 2018-06-23 stsp static const struct got_error *
3057 1a76625f 2018-10-22 stsp close_log_view(struct tog_view *view)
3059 1a76625f 2018-10-22 stsp const struct got_error *err = NULL;
3060 1a76625f 2018-10-22 stsp struct tog_log_view_state *s = &view->state.log;
3061 276b94a1 2020-11-13 naddy int errcode;
3063 1a76625f 2018-10-22 stsp err = stop_log_thread(s);
3065 276b94a1 2020-11-13 naddy errcode = pthread_cond_destroy(&s->thread_args.need_commits);
3066 276b94a1 2020-11-13 naddy if (errcode && err == NULL)
3067 276b94a1 2020-11-13 naddy err = got_error_set_errno(errcode, "pthread_cond_destroy");
3069 276b94a1 2020-11-13 naddy errcode = pthread_cond_destroy(&s->thread_args.commit_loaded);
3070 276b94a1 2020-11-13 naddy if (errcode && err == NULL)
3071 276b94a1 2020-11-13 naddy err = got_error_set_errno(errcode, "pthread_cond_destroy");
3073 568eae95 2022-09-11 mark free_commits(&s->limit_commits);
3074 568eae95 2022-09-11 mark free_commits(&s->real_commits);
3075 1a76625f 2018-10-22 stsp free(s->in_repo_path);
3076 797bc7b9 2018-10-22 stsp s->in_repo_path = NULL;
3077 1a76625f 2018-10-22 stsp free(s->start_id);
3078 797bc7b9 2018-10-22 stsp s->start_id = NULL;
3079 9cd7cbd1 2020-12-07 stsp free(s->head_ref_name);
3080 9cd7cbd1 2020-12-07 stsp s->head_ref_name = NULL;