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 5822e79e 2023-02-23 op #include <sha2.h>
29 61266923 2020-01-14 stsp #include <signal.h>
30 9f7d7167 2018-04-29 stsp #include <stdlib.h>
31 ee85c5e8 2020-02-29 stsp #include <stdarg.h>
32 26ed57b2 2018-05-19 stsp #include <stdio.h>
33 9f7d7167 2018-04-29 stsp #include <getopt.h>
34 9f7d7167 2018-04-29 stsp #include <string.h>
35 9f7d7167 2018-04-29 stsp #include <err.h>
36 80ddbec8 2018-04-29 stsp #include <unistd.h>
37 26ed57b2 2018-05-19 stsp #include <limits.h>
38 61e69b96 2018-05-20 stsp #include <wchar.h>
39 788c352e 2018-06-16 stsp #include <time.h>
40 84451b3e 2018-07-10 stsp #include <pthread.h>
41 5036bf37 2018-09-24 stsp #include <libgen.h>
42 60493ae3 2019-06-20 stsp #include <regex.h>
43 3da8ef85 2021-09-21 stsp #include <sched.h>
45 53ccebc2 2019-07-30 stsp #include "got_version.h"
46 9f7d7167 2018-04-29 stsp #include "got_error.h"
47 80ddbec8 2018-04-29 stsp #include "got_object.h"
48 80ddbec8 2018-04-29 stsp #include "got_reference.h"
49 80ddbec8 2018-04-29 stsp #include "got_repository.h"
50 80ddbec8 2018-04-29 stsp #include "got_diff.h"
51 511a516b 2018-05-19 stsp #include "got_opentemp.h"
52 00dfcb92 2018-06-11 stsp #include "got_utf8.h"
53 6fb7cd11 2019-08-22 stsp #include "got_cancel.h"
54 6fb7cd11 2019-08-22 stsp #include "got_commit_graph.h"
55 a70480e0 2018-06-23 stsp #include "got_blame.h"
56 c2db6724 2019-01-04 stsp #include "got_privsep.h"
57 1dd54920 2019-05-11 stsp #include "got_path.h"
58 b7165be3 2019-02-05 stsp #include "got_worktree.h"
59 c4df265e 2023-07-19 mark #include "got_keyword.h"
62 881b2d3e 2018-04-30 stsp #define MIN(_a,_b) ((_a) < (_b) ? (_a) : (_b))
66 2bd27830 2018-10-22 stsp #define MAX(_a,_b) ((_a) > (_b) ? (_a) : (_b))
69 a4292ac5 2019-05-12 jcs #define CTRL(x) ((x) & 0x1f)
71 9f7d7167 2018-04-29 stsp #ifndef nitems
72 9f7d7167 2018-04-29 stsp #define nitems(_a) (sizeof((_a)) / sizeof((_a)[0]))
75 9f7d7167 2018-04-29 stsp struct tog_cmd {
76 c2301be8 2018-04-30 stsp const char *name;
77 9f7d7167 2018-04-29 stsp const struct got_error *(*cmd_main)(int, char *[]);
78 9f7d7167 2018-04-29 stsp void (*cmd_usage)(void);
81 6879ba42 2020-10-01 naddy __dead static void usage(int, int);
82 4ed7e80c 2018-05-20 stsp __dead static void usage_log(void);
83 4ed7e80c 2018-05-20 stsp __dead static void usage_diff(void);
84 4ed7e80c 2018-05-20 stsp __dead static void usage_blame(void);
85 ffd1d5e5 2018-06-23 stsp __dead static void usage_tree(void);
86 6458efa5 2020-11-24 stsp __dead static void usage_ref(void);
88 4ed7e80c 2018-05-20 stsp static const struct got_error* cmd_log(int, char *[]);
89 4ed7e80c 2018-05-20 stsp static const struct got_error* cmd_diff(int, char *[]);
90 4ed7e80c 2018-05-20 stsp static const struct got_error* cmd_blame(int, char *[]);
91 ffd1d5e5 2018-06-23 stsp static const struct got_error* cmd_tree(int, char *[]);
92 6458efa5 2020-11-24 stsp static const struct got_error* cmd_ref(int, char *[]);
94 3e166534 2022-02-16 naddy static const struct tog_cmd tog_commands[] = {
95 5e070240 2019-06-22 stsp { "log", cmd_log, usage_log },
96 5e070240 2019-06-22 stsp { "diff", cmd_diff, usage_diff },
97 5e070240 2019-06-22 stsp { "blame", cmd_blame, usage_blame },
98 5e070240 2019-06-22 stsp { "tree", cmd_tree, usage_tree },
99 6458efa5 2020-11-24 stsp { "ref", cmd_ref, usage_ref },
102 d6b05b5b 2018-08-04 stsp enum tog_view_type {
103 d6b05b5b 2018-08-04 stsp TOG_VIEW_DIFF,
104 d6b05b5b 2018-08-04 stsp TOG_VIEW_LOG,
105 ad80ab7b 2018-08-04 stsp TOG_VIEW_BLAME,
106 6458efa5 2020-11-24 stsp TOG_VIEW_TREE,
107 6458efa5 2020-11-24 stsp TOG_VIEW_REF,
108 ec2a9698 2022-09-15 mark TOG_VIEW_HELP
111 ec2a9698 2022-09-15 mark /* Match _DIFF to _HELP with enum tog_view_type TOG_VIEW_* counterparts. */
112 ec2a9698 2022-09-15 mark enum tog_keymap_type {
113 ec2a9698 2022-09-15 mark TOG_KEYMAP_KEYS = -2,
114 ec2a9698 2022-09-15 mark TOG_KEYMAP_GLOBAL,
115 ec2a9698 2022-09-15 mark TOG_KEYMAP_DIFF,
116 ec2a9698 2022-09-15 mark TOG_KEYMAP_LOG,
117 ec2a9698 2022-09-15 mark TOG_KEYMAP_BLAME,
118 ec2a9698 2022-09-15 mark TOG_KEYMAP_TREE,
119 ec2a9698 2022-09-15 mark TOG_KEYMAP_REF,
120 ec2a9698 2022-09-15 mark TOG_KEYMAP_HELP
123 9b058f45 2022-06-30 mark enum tog_view_mode {
124 9b058f45 2022-06-30 mark TOG_VIEW_SPLIT_NONE,
125 9b058f45 2022-06-30 mark TOG_VIEW_SPLIT_VERT,
126 9b058f45 2022-06-30 mark TOG_VIEW_SPLIT_HRZN
129 91db2202 2023-04-22 op #define HSPLIT_SCALE 0.3f /* default horizontal split scale */
131 c3e9aa98 2019-05-13 jcs #define TOG_EOF_STRING "(END)"
133 ba4f502b 2018-08-04 stsp struct commit_queue_entry {
134 ba4f502b 2018-08-04 stsp TAILQ_ENTRY(commit_queue_entry) entry;
135 ba4f502b 2018-08-04 stsp struct got_object_id *id;
136 ba4f502b 2018-08-04 stsp struct got_commit_object *commit;
139 ba4f502b 2018-08-04 stsp TAILQ_HEAD(commit_queue_head, commit_queue_entry);
140 ba4f502b 2018-08-04 stsp struct commit_queue {
141 ba4f502b 2018-08-04 stsp int ncommits;
142 ba4f502b 2018-08-04 stsp struct commit_queue_head head;
145 f26dddb7 2019-11-08 stsp struct tog_color {
146 dbdddfee 2021-06-23 naddy STAILQ_ENTRY(tog_color) entry;
147 6d17833f 2019-11-08 stsp regex_t regex;
148 6d17833f 2019-11-08 stsp short colorpair;
150 dbdddfee 2021-06-23 naddy STAILQ_HEAD(tog_colors, tog_color);
152 d9dff0e5 2020-12-26 stsp static struct got_reflist_head tog_refs = TAILQ_HEAD_INITIALIZER(tog_refs);
153 51a10b52 2020-12-26 stsp static struct got_reflist_object_id_map *tog_refs_idmap;
154 c935fd51 2023-07-23 mark static struct {
155 c935fd51 2023-07-23 mark struct got_object_id *id;
157 c935fd51 2023-07-23 mark char marker;
158 c935fd51 2023-07-23 mark } tog_base_commit;
159 2e2450f5 2023-10-04 mark static enum got_diff_algorithm tog_diff_algo = GOT_DIFF_ALGORITHM_PATIENCE;
161 cc488aa7 2022-01-23 stsp static const struct got_error *
162 cc488aa7 2022-01-23 stsp tog_ref_cmp_by_name(void *arg, int *cmp, struct got_reference *re1,
163 cc488aa7 2022-01-23 stsp struct got_reference* re2)
165 cc488aa7 2022-01-23 stsp const char *name1 = got_ref_get_name(re1);
166 cc488aa7 2022-01-23 stsp const char *name2 = got_ref_get_name(re2);
167 cc488aa7 2022-01-23 stsp int isbackup1, isbackup2;
169 cc488aa7 2022-01-23 stsp /* Sort backup refs towards the bottom of the list. */
170 cc488aa7 2022-01-23 stsp isbackup1 = strncmp(name1, "refs/got/backup/", 16) == 0;
171 cc488aa7 2022-01-23 stsp isbackup2 = strncmp(name2, "refs/got/backup/", 16) == 0;
172 cc488aa7 2022-01-23 stsp if (!isbackup1 && isbackup2) {
174 cc488aa7 2022-01-23 stsp return NULL;
175 cc488aa7 2022-01-23 stsp } else if (isbackup1 && !isbackup2) {
177 cc488aa7 2022-01-23 stsp return NULL;
180 cc488aa7 2022-01-23 stsp *cmp = got_path_cmp(name1, name2, strlen(name1), strlen(name2));
181 cc488aa7 2022-01-23 stsp return NULL;
184 11b20872 2019-11-08 stsp static const struct got_error *
185 7f66531d 2021-11-16 stsp tog_load_refs(struct got_repository *repo, int sort_by_date)
187 51a10b52 2020-12-26 stsp const struct got_error *err;
189 7f66531d 2021-11-16 stsp err = got_ref_list(&tog_refs, repo, NULL, sort_by_date ?
190 cc488aa7 2022-01-23 stsp got_ref_cmp_by_commit_timestamp_descending : tog_ref_cmp_by_name,
193 51a10b52 2020-12-26 stsp return err;
195 51a10b52 2020-12-26 stsp return got_reflist_object_id_map_create(&tog_refs_idmap, &tog_refs,
199 51a10b52 2020-12-26 stsp static void
200 51a10b52 2020-12-26 stsp tog_free_refs(void)
202 51a10b52 2020-12-26 stsp if (tog_refs_idmap) {
203 f193b038 2020-12-26 stsp got_reflist_object_id_map_free(tog_refs_idmap);
204 51a10b52 2020-12-26 stsp tog_refs_idmap = NULL;
206 51a10b52 2020-12-26 stsp got_ref_list_free(&tog_refs);
209 51a10b52 2020-12-26 stsp static const struct got_error *
210 11b20872 2019-11-08 stsp add_color(struct tog_colors *colors, const char *pattern,
211 11b20872 2019-11-08 stsp int idx, short color)
213 11b20872 2019-11-08 stsp const struct got_error *err = NULL;
214 11b20872 2019-11-08 stsp struct tog_color *tc;
215 11b20872 2019-11-08 stsp int regerr = 0;
217 11b20872 2019-11-08 stsp if (idx < 1 || idx > COLOR_PAIRS - 1)
218 11b20872 2019-11-08 stsp return NULL;
220 11b20872 2019-11-08 stsp init_pair(idx, color, -1);
222 11b20872 2019-11-08 stsp tc = calloc(1, sizeof(*tc));
223 11b20872 2019-11-08 stsp if (tc == NULL)
224 11b20872 2019-11-08 stsp return got_error_from_errno("calloc");
225 11b20872 2019-11-08 stsp regerr = regcomp(&tc->regex, pattern,
226 11b20872 2019-11-08 stsp REG_EXTENDED | REG_NOSUB | REG_NEWLINE);
227 11b20872 2019-11-08 stsp if (regerr) {
228 11b20872 2019-11-08 stsp static char regerr_msg[512];
229 11b20872 2019-11-08 stsp static char err_msg[512];
230 11b20872 2019-11-08 stsp regerror(regerr, &tc->regex, regerr_msg,
231 11b20872 2019-11-08 stsp sizeof(regerr_msg));
232 11b20872 2019-11-08 stsp snprintf(err_msg, sizeof(err_msg), "regcomp: %s",
233 11b20872 2019-11-08 stsp regerr_msg);
234 11b20872 2019-11-08 stsp err = got_error_msg(GOT_ERR_REGEX, err_msg);
236 11b20872 2019-11-08 stsp return err;
238 11b20872 2019-11-08 stsp tc->colorpair = idx;
239 dbdddfee 2021-06-23 naddy STAILQ_INSERT_HEAD(colors, tc, entry);
240 11b20872 2019-11-08 stsp return NULL;
243 11b20872 2019-11-08 stsp static void
244 11b20872 2019-11-08 stsp free_colors(struct tog_colors *colors)
246 11b20872 2019-11-08 stsp struct tog_color *tc;
248 dbdddfee 2021-06-23 naddy while (!STAILQ_EMPTY(colors)) {
249 dbdddfee 2021-06-23 naddy tc = STAILQ_FIRST(colors);
250 dbdddfee 2021-06-23 naddy STAILQ_REMOVE_HEAD(colors, entry);
251 11b20872 2019-11-08 stsp regfree(&tc->regex);
256 336075a4 2022-06-25 op static struct tog_color *
257 11b20872 2019-11-08 stsp get_color(struct tog_colors *colors, int colorpair)
259 11b20872 2019-11-08 stsp struct tog_color *tc = NULL;
261 dbdddfee 2021-06-23 naddy STAILQ_FOREACH(tc, colors, entry) {
262 11b20872 2019-11-08 stsp if (tc->colorpair == colorpair)
266 11b20872 2019-11-08 stsp return NULL;
270 11b20872 2019-11-08 stsp default_color_value(const char *envvar)
272 11b20872 2019-11-08 stsp if (strcmp(envvar, "TOG_COLOR_DIFF_MINUS") == 0)
273 11b20872 2019-11-08 stsp return COLOR_MAGENTA;
274 11b20872 2019-11-08 stsp if (strcmp(envvar, "TOG_COLOR_DIFF_PLUS") == 0)
275 11b20872 2019-11-08 stsp return COLOR_CYAN;
276 11b20872 2019-11-08 stsp if (strcmp(envvar, "TOG_COLOR_DIFF_CHUNK_HEADER") == 0)
277 11b20872 2019-11-08 stsp return COLOR_YELLOW;
278 11b20872 2019-11-08 stsp if (strcmp(envvar, "TOG_COLOR_DIFF_META") == 0)
279 11b20872 2019-11-08 stsp return COLOR_GREEN;
280 11b20872 2019-11-08 stsp if (strcmp(envvar, "TOG_COLOR_TREE_SUBMODULE") == 0)
281 11b20872 2019-11-08 stsp return COLOR_MAGENTA;
282 11b20872 2019-11-08 stsp if (strcmp(envvar, "TOG_COLOR_TREE_SYMLINK") == 0)
283 91b8c405 2020-01-25 stsp return COLOR_MAGENTA;
284 11b20872 2019-11-08 stsp if (strcmp(envvar, "TOG_COLOR_TREE_DIRECTORY") == 0)
285 91b8c405 2020-01-25 stsp return COLOR_CYAN;
286 11b20872 2019-11-08 stsp if (strcmp(envvar, "TOG_COLOR_TREE_EXECUTABLE") == 0)
287 11b20872 2019-11-08 stsp return COLOR_GREEN;
288 11b20872 2019-11-08 stsp if (strcmp(envvar, "TOG_COLOR_COMMIT") == 0)
289 11b20872 2019-11-08 stsp return COLOR_GREEN;
290 11b20872 2019-11-08 stsp if (strcmp(envvar, "TOG_COLOR_AUTHOR") == 0)
291 11b20872 2019-11-08 stsp return COLOR_CYAN;
292 11b20872 2019-11-08 stsp if (strcmp(envvar, "TOG_COLOR_DATE") == 0)
293 11b20872 2019-11-08 stsp return COLOR_YELLOW;
294 6458efa5 2020-11-24 stsp if (strcmp(envvar, "TOG_COLOR_REFS_HEADS") == 0)
295 6458efa5 2020-11-24 stsp return COLOR_GREEN;
296 6458efa5 2020-11-24 stsp if (strcmp(envvar, "TOG_COLOR_REFS_TAGS") == 0)
297 6458efa5 2020-11-24 stsp return COLOR_MAGENTA;
298 6458efa5 2020-11-24 stsp if (strcmp(envvar, "TOG_COLOR_REFS_REMOTES") == 0)
299 6458efa5 2020-11-24 stsp return COLOR_YELLOW;
300 cc488aa7 2022-01-23 stsp if (strcmp(envvar, "TOG_COLOR_REFS_BACKUP") == 0)
301 cc488aa7 2022-01-23 stsp return COLOR_CYAN;
307 11b20872 2019-11-08 stsp get_color_value(const char *envvar)
309 11b20872 2019-11-08 stsp const char *val = getenv(envvar);
311 11b20872 2019-11-08 stsp if (val == NULL)
312 11b20872 2019-11-08 stsp return default_color_value(envvar);
314 11b20872 2019-11-08 stsp if (strcasecmp(val, "black") == 0)
315 11b20872 2019-11-08 stsp return COLOR_BLACK;
316 11b20872 2019-11-08 stsp if (strcasecmp(val, "red") == 0)
317 11b20872 2019-11-08 stsp return COLOR_RED;
318 11b20872 2019-11-08 stsp if (strcasecmp(val, "green") == 0)
319 11b20872 2019-11-08 stsp return COLOR_GREEN;
320 11b20872 2019-11-08 stsp if (strcasecmp(val, "yellow") == 0)
321 11b20872 2019-11-08 stsp return COLOR_YELLOW;
322 11b20872 2019-11-08 stsp if (strcasecmp(val, "blue") == 0)
323 11b20872 2019-11-08 stsp return COLOR_BLUE;
324 11b20872 2019-11-08 stsp if (strcasecmp(val, "magenta") == 0)
325 11b20872 2019-11-08 stsp return COLOR_MAGENTA;
326 11b20872 2019-11-08 stsp if (strcasecmp(val, "cyan") == 0)
327 11b20872 2019-11-08 stsp return COLOR_CYAN;
328 11b20872 2019-11-08 stsp if (strcasecmp(val, "white") == 0)
329 11b20872 2019-11-08 stsp return COLOR_WHITE;
330 11b20872 2019-11-08 stsp if (strcasecmp(val, "default") == 0)
333 11b20872 2019-11-08 stsp return default_color_value(envvar);
336 15a087fe 2019-02-21 stsp struct tog_diff_view_state {
337 15a087fe 2019-02-21 stsp struct got_object_id *id1, *id2;
338 3dbaef42 2020-11-24 stsp const char *label1, *label2;
339 b72706c3 2022-06-01 stsp FILE *f, *f1, *f2;
340 f9d37699 2022-06-28 stsp int fd1, fd2;
341 c7d5c43c 2022-08-04 mark int lineno;
342 15a087fe 2019-02-21 stsp int first_displayed_line;
343 15a087fe 2019-02-21 stsp int last_displayed_line;
345 15a087fe 2019-02-21 stsp int diff_context;
346 3dbaef42 2020-11-24 stsp int ignore_whitespace;
347 64453f7e 2020-11-21 stsp int force_text_diff;
348 15a087fe 2019-02-21 stsp struct got_repository *repo;
349 c7d5c43c 2022-08-04 mark struct got_diff_line *lines;
350 fe621944 2020-11-10 stsp size_t nlines;
351 f44b1f58 2020-02-02 tracey int matched_line;
352 f44b1f58 2020-02-02 tracey int selected_line;
354 c0f61fa4 2022-07-11 mark /* passed from log or blame view; may be NULL */
355 c0f61fa4 2022-07-11 mark struct tog_view *parent_view;
358 1a76625f 2018-10-22 stsp pthread_mutex_t tog_mutex = PTHREAD_MUTEX_INITIALIZER;
359 5629093a 2022-07-11 stsp static volatile sig_atomic_t tog_thread_error;
361 1a76625f 2018-10-22 stsp struct tog_log_thread_args {
362 1a76625f 2018-10-22 stsp pthread_cond_t need_commits;
363 7c1452c1 2020-03-26 stsp pthread_cond_t commit_loaded;
364 1a76625f 2018-10-22 stsp int commits_needed;
365 fb280deb 2021-08-30 stsp int load_all;
366 b01e7d3b 2018-08-04 stsp struct got_commit_graph *graph;
367 568eae95 2022-09-11 mark struct commit_queue *real_commits;
368 1a76625f 2018-10-22 stsp const char *in_repo_path;
369 1a76625f 2018-10-22 stsp struct got_object_id *start_id;
370 1a76625f 2018-10-22 stsp struct got_repository *repo;
371 74467cc8 2022-06-15 stsp int *pack_fds;
372 1a76625f 2018-10-22 stsp int log_complete;
373 99301cec 2023-07-24 stsp pthread_cond_t log_loaded;
374 1a76625f 2018-10-22 stsp sig_atomic_t *quit;
375 1a76625f 2018-10-22 stsp struct commit_queue_entry **first_displayed_entry;
376 1a76625f 2018-10-22 stsp struct commit_queue_entry **selected_entry;
377 13add988 2019-10-15 stsp int *searching;
378 13add988 2019-10-15 stsp int *search_next_done;
379 13add988 2019-10-15 stsp regex_t *regex;
380 568eae95 2022-09-11 mark int *limiting;
381 568eae95 2022-09-11 mark int limit_match;
382 568eae95 2022-09-11 mark regex_t *limit_regex;
383 568eae95 2022-09-11 mark struct commit_queue *limit_commits;
384 99301cec 2023-07-24 stsp struct got_worktree *worktree;
385 99301cec 2023-07-24 stsp int need_commit_marker;
388 1a76625f 2018-10-22 stsp struct tog_log_view_state {
389 568eae95 2022-09-11 mark struct commit_queue *commits;
390 b01e7d3b 2018-08-04 stsp struct commit_queue_entry *first_displayed_entry;
391 b01e7d3b 2018-08-04 stsp struct commit_queue_entry *last_displayed_entry;
392 b01e7d3b 2018-08-04 stsp struct commit_queue_entry *selected_entry;
393 568eae95 2022-09-11 mark struct commit_queue real_commits;
394 b01e7d3b 2018-08-04 stsp int selected;
395 b01e7d3b 2018-08-04 stsp char *in_repo_path;
396 9cd7cbd1 2020-12-07 stsp char *head_ref_name;
397 b672a97a 2020-01-27 stsp int log_branches;
398 b01e7d3b 2018-08-04 stsp struct got_repository *repo;
399 5036bf37 2018-09-24 stsp struct got_object_id *start_id;
400 1a76625f 2018-10-22 stsp sig_atomic_t quit;
401 1a76625f 2018-10-22 stsp pthread_t thread;
402 1a76625f 2018-10-22 stsp struct tog_log_thread_args thread_args;
403 60493ae3 2019-06-20 stsp struct commit_queue_entry *matched_entry;
404 96e2b566 2019-07-08 stsp struct commit_queue_entry *search_entry;
405 11b20872 2019-11-08 stsp struct tog_colors colors;
406 10aab77f 2022-07-19 op int use_committer;
407 568eae95 2022-09-11 mark int limit_view;
408 568eae95 2022-09-11 mark regex_t limit_regex;
409 568eae95 2022-09-11 mark struct commit_queue limit_commits;
412 11b20872 2019-11-08 stsp #define TOG_COLOR_DIFF_MINUS 1
413 11b20872 2019-11-08 stsp #define TOG_COLOR_DIFF_PLUS 2
414 11b20872 2019-11-08 stsp #define TOG_COLOR_DIFF_CHUNK_HEADER 3
415 11b20872 2019-11-08 stsp #define TOG_COLOR_DIFF_META 4
416 11b20872 2019-11-08 stsp #define TOG_COLOR_TREE_SUBMODULE 5
417 11b20872 2019-11-08 stsp #define TOG_COLOR_TREE_SYMLINK 6
418 11b20872 2019-11-08 stsp #define TOG_COLOR_TREE_DIRECTORY 7
419 11b20872 2019-11-08 stsp #define TOG_COLOR_TREE_EXECUTABLE 8
420 11b20872 2019-11-08 stsp #define TOG_COLOR_COMMIT 9
421 11b20872 2019-11-08 stsp #define TOG_COLOR_AUTHOR 10
422 bf30f154 2020-12-07 naddy #define TOG_COLOR_DATE 11
423 6458efa5 2020-11-24 stsp #define TOG_COLOR_REFS_HEADS 12
424 6458efa5 2020-11-24 stsp #define TOG_COLOR_REFS_TAGS 13
425 6458efa5 2020-11-24 stsp #define TOG_COLOR_REFS_REMOTES 14
426 cc488aa7 2022-01-23 stsp #define TOG_COLOR_REFS_BACKUP 15
428 e9424729 2018-08-04 stsp struct tog_blame_cb_args {
429 e9424729 2018-08-04 stsp struct tog_blame_line *lines; /* one per line */
430 e9424729 2018-08-04 stsp int nlines;
432 e9424729 2018-08-04 stsp struct tog_view *view;
433 e9424729 2018-08-04 stsp struct got_object_id *commit_id;
437 e9424729 2018-08-04 stsp struct tog_blame_thread_args {
438 e9424729 2018-08-04 stsp const char *path;
439 e9424729 2018-08-04 stsp struct got_repository *repo;
440 e9424729 2018-08-04 stsp struct tog_blame_cb_args *cb_args;
441 e9424729 2018-08-04 stsp int *complete;
442 fc06ba56 2019-08-22 stsp got_cancel_cb cancel_cb;
443 fc06ba56 2019-08-22 stsp void *cancel_arg;
444 8496bf63 2023-04-20 mark pthread_cond_t blame_complete;
447 e9424729 2018-08-04 stsp struct tog_blame {
449 be659d10 2020-11-18 stsp off_t filesize;
450 e9424729 2018-08-04 stsp struct tog_blame_line *lines;
451 6fcac457 2018-11-19 stsp int nlines;
452 6c4c42e0 2019-06-24 stsp off_t *line_offsets;
453 e9424729 2018-08-04 stsp pthread_t thread;
454 e9424729 2018-08-04 stsp struct tog_blame_thread_args thread_args;
455 e9424729 2018-08-04 stsp struct tog_blame_cb_args cb_args;
456 e9424729 2018-08-04 stsp const char *path;
457 0ae84acc 2022-06-15 tracey int *pack_fds;
460 7cbe629d 2018-08-04 stsp struct tog_blame_view_state {
461 7cbe629d 2018-08-04 stsp int first_displayed_line;
462 7cbe629d 2018-08-04 stsp int last_displayed_line;
463 7cbe629d 2018-08-04 stsp int selected_line;
464 c0f61fa4 2022-07-11 mark int last_diffed_line;
465 7cbe629d 2018-08-04 stsp int blame_complete;
468 7cbe629d 2018-08-04 stsp struct got_object_id_queue blamed_commits;
469 7cbe629d 2018-08-04 stsp struct got_object_qid *blamed_commit;
470 e5a0f69f 2018-08-18 stsp char *path;
471 7cbe629d 2018-08-04 stsp struct got_repository *repo;
472 ad80ab7b 2018-08-04 stsp struct got_object_id *commit_id;
473 136e2bd4 2022-07-23 mark struct got_object_id *id_to_log;
474 e9424729 2018-08-04 stsp struct tog_blame blame;
475 6c4c42e0 2019-06-24 stsp int matched_line;
476 11b20872 2019-11-08 stsp struct tog_colors colors;
479 ad80ab7b 2018-08-04 stsp struct tog_parent_tree {
480 ad80ab7b 2018-08-04 stsp TAILQ_ENTRY(tog_parent_tree) entry;
481 ad80ab7b 2018-08-04 stsp struct got_tree_object *tree;
482 ad80ab7b 2018-08-04 stsp struct got_tree_entry *first_displayed_entry;
483 ad80ab7b 2018-08-04 stsp struct got_tree_entry *selected_entry;
484 ad80ab7b 2018-08-04 stsp int selected;
487 ad80ab7b 2018-08-04 stsp TAILQ_HEAD(tog_parent_trees, tog_parent_tree);
489 ad80ab7b 2018-08-04 stsp struct tog_tree_view_state {
490 ad80ab7b 2018-08-04 stsp char *tree_label;
491 bc573f3b 2021-07-10 stsp struct got_object_id *commit_id;/* commit which this tree belongs to */
492 bc573f3b 2021-07-10 stsp struct got_tree_object *root; /* the commit's root tree entry */
493 bc573f3b 2021-07-10 stsp struct got_tree_object *tree; /* currently displayed (sub-)tree */
494 ad80ab7b 2018-08-04 stsp struct got_tree_entry *first_displayed_entry;
495 ad80ab7b 2018-08-04 stsp struct got_tree_entry *last_displayed_entry;
496 ad80ab7b 2018-08-04 stsp struct got_tree_entry *selected_entry;
497 416a95c5 2019-01-24 stsp int ndisplayed, selected, show_ids;
498 bc573f3b 2021-07-10 stsp struct tog_parent_trees parents; /* parent trees of current sub-tree */
499 9cd7cbd1 2020-12-07 stsp char *head_ref_name;
500 ad80ab7b 2018-08-04 stsp struct got_repository *repo;
501 7c32bd05 2019-06-22 stsp struct got_tree_entry *matched_entry;
502 6458efa5 2020-11-24 stsp struct tog_colors colors;
505 6458efa5 2020-11-24 stsp struct tog_reflist_entry {
506 6458efa5 2020-11-24 stsp TAILQ_ENTRY(tog_reflist_entry) entry;
507 6458efa5 2020-11-24 stsp struct got_reference *ref;
511 6458efa5 2020-11-24 stsp TAILQ_HEAD(tog_reflist_head, tog_reflist_entry);
513 6458efa5 2020-11-24 stsp struct tog_ref_view_state {
514 dae613fa 2020-12-26 stsp struct tog_reflist_head refs;
515 6458efa5 2020-11-24 stsp struct tog_reflist_entry *first_displayed_entry;
516 6458efa5 2020-11-24 stsp struct tog_reflist_entry *last_displayed_entry;
517 6458efa5 2020-11-24 stsp struct tog_reflist_entry *selected_entry;
518 b4996bee 2022-06-16 stsp int nrefs, ndisplayed, selected, show_date, show_ids, sort_by_date;
519 6458efa5 2020-11-24 stsp struct got_repository *repo;
520 6458efa5 2020-11-24 stsp struct tog_reflist_entry *matched_entry;
521 bddb1296 2019-11-08 stsp struct tog_colors colors;
524 ec2a9698 2022-09-15 mark struct tog_help_view_state {
526 ec2a9698 2022-09-15 mark off_t *line_offsets;
527 ec2a9698 2022-09-15 mark size_t nlines;
528 ec2a9698 2022-09-15 mark int lineno;
529 ec2a9698 2022-09-15 mark int first_displayed_line;
530 ec2a9698 2022-09-15 mark int last_displayed_line;
532 ec2a9698 2022-09-15 mark int matched_line;
533 ec2a9698 2022-09-15 mark int selected_line;
535 ec2a9698 2022-09-15 mark enum tog_keymap_type type;
538 ec2a9698 2022-09-15 mark #define GENERATE_HELP \
539 ec2a9698 2022-09-15 mark KEYMAP_("Global", TOG_KEYMAP_GLOBAL), \
540 ec2a9698 2022-09-15 mark KEY_("H F1", "Open view-specific help (double tap for all help)"), \
541 ec2a9698 2022-09-15 mark KEY_("k C-p Up", "Move cursor or page up one line"), \
542 ec2a9698 2022-09-15 mark KEY_("j C-n Down", "Move cursor or page down one line"), \
543 ec2a9698 2022-09-15 mark KEY_("C-b b PgUp", "Scroll the view up one page"), \
544 ec2a9698 2022-09-15 mark KEY_("C-f f PgDn Space", "Scroll the view down one page"), \
545 ec2a9698 2022-09-15 mark KEY_("C-u u", "Scroll the view up one half page"), \
546 ec2a9698 2022-09-15 mark KEY_("C-d d", "Scroll the view down one half page"), \
547 0b3f028d 2023-01-09 mark KEY_("g", "Go to line N (default: first line)"), \
548 0b3f028d 2023-01-09 mark KEY_("Home =", "Go to the first line"), \
549 0b3f028d 2023-01-09 mark KEY_("G", "Go to line N (default: last line)"), \
550 0b3f028d 2023-01-09 mark KEY_("End *", "Go to the last line"), \
551 ec2a9698 2022-09-15 mark KEY_("l Right", "Scroll the view right"), \
552 ec2a9698 2022-09-15 mark KEY_("h Left", "Scroll the view left"), \
553 ec2a9698 2022-09-15 mark KEY_("$", "Scroll view to the rightmost position"), \
554 ec2a9698 2022-09-15 mark KEY_("0", "Scroll view to the leftmost position"), \
555 ec2a9698 2022-09-15 mark KEY_("-", "Decrease size of the focussed split"), \
556 ec2a9698 2022-09-15 mark KEY_("+", "Increase size of the focussed split"), \
557 ec2a9698 2022-09-15 mark KEY_("Tab", "Switch focus between views"), \
558 ec2a9698 2022-09-15 mark KEY_("F", "Toggle fullscreen mode"), \
559 132d5247 2023-04-14 stsp KEY_("S", "Switch split-screen layout"), \
560 ec2a9698 2022-09-15 mark KEY_("/", "Open prompt to enter search term"), \
561 ec2a9698 2022-09-15 mark KEY_("n", "Find next line/token matching the current search term"), \
562 ec2a9698 2022-09-15 mark KEY_("N", "Find previous line/token matching the current search term"),\
563 16a2d4f0 2022-09-19 stsp KEY_("q", "Quit the focussed view; Quit help screen"), \
564 ec2a9698 2022-09-15 mark KEY_("Q", "Quit tog"), \
566 fd6badaa 2022-09-23 stsp KEYMAP_("Log view", TOG_KEYMAP_LOG), \
567 ec2a9698 2022-09-15 mark KEY_("< ,", "Move cursor up one commit"), \
568 ec2a9698 2022-09-15 mark KEY_("> .", "Move cursor down one commit"), \
569 ec2a9698 2022-09-15 mark KEY_("Enter", "Open diff view of the selected commit"), \
570 ec2a9698 2022-09-15 mark KEY_("B", "Reload the log view and toggle display of merged commits"), \
571 ec2a9698 2022-09-15 mark KEY_("R", "Open ref view of all repository references"), \
572 ec2a9698 2022-09-15 mark KEY_("T", "Display tree view of the repository from the selected" \
573 ec2a9698 2022-09-15 mark " commit"), \
574 ec2a9698 2022-09-15 mark KEY_("@", "Toggle between displaying author and committer name"), \
575 ec2a9698 2022-09-15 mark KEY_("&", "Open prompt to enter term to limit commits displayed"), \
576 ec2a9698 2022-09-15 mark KEY_("C-g Backspace", "Cancel current search or log operation"), \
577 ec2a9698 2022-09-15 mark KEY_("C-l", "Reload the log view with new commits in the repository"), \
579 fd6badaa 2022-09-23 stsp KEYMAP_("Diff view", TOG_KEYMAP_DIFF), \
580 ec2a9698 2022-09-15 mark KEY_("K < ,", "Display diff of next line in the file/log entry"), \
581 ec2a9698 2022-09-15 mark KEY_("J > .", "Display diff of previous line in the file/log entry"), \
582 ec2a9698 2022-09-15 mark KEY_("A", "Toggle between Myers and Patience diff algorithm"), \
583 ec2a9698 2022-09-15 mark KEY_("a", "Toggle treatment of file as ASCII irrespective of binary" \
584 ec2a9698 2022-09-15 mark " data"), \
585 ec2a9698 2022-09-15 mark KEY_("(", "Go to the previous file in the diff"), \
586 ec2a9698 2022-09-15 mark KEY_(")", "Go to the next file in the diff"), \
587 ec2a9698 2022-09-15 mark KEY_("{", "Go to the previous hunk in the diff"), \
588 ec2a9698 2022-09-15 mark KEY_("}", "Go to the next hunk in the diff"), \
589 ec2a9698 2022-09-15 mark KEY_("[", "Decrease the number of context lines"), \
590 ec2a9698 2022-09-15 mark KEY_("]", "Increase the number of context lines"), \
591 ec2a9698 2022-09-15 mark KEY_("w", "Toggle ignore whitespace-only changes in the diff"), \
593 fd6badaa 2022-09-23 stsp KEYMAP_("Blame view", TOG_KEYMAP_BLAME), \
594 ec2a9698 2022-09-15 mark KEY_("Enter", "Display diff view of the selected line's commit"), \
595 ec2a9698 2022-09-15 mark KEY_("A", "Toggle diff algorithm between Myers and Patience"), \
596 ec2a9698 2022-09-15 mark KEY_("L", "Open log view for the currently selected annotated line"), \
597 ec2a9698 2022-09-15 mark KEY_("C", "Reload view with the previously blamed commit"), \
598 ec2a9698 2022-09-15 mark KEY_("c", "Reload view with the version of the file found in the" \
599 ec2a9698 2022-09-15 mark " selected line's commit"), \
600 ec2a9698 2022-09-15 mark KEY_("p", "Reload view with the version of the file found in the" \
601 ec2a9698 2022-09-15 mark " selected line's parent commit"), \
603 fd6badaa 2022-09-23 stsp KEYMAP_("Tree view", TOG_KEYMAP_TREE), \
604 ec2a9698 2022-09-15 mark KEY_("Enter", "Enter selected directory or open blame view of the" \
605 ec2a9698 2022-09-15 mark " selected file"), \
606 ec2a9698 2022-09-15 mark KEY_("L", "Open log view for the selected entry"), \
607 ec2a9698 2022-09-15 mark KEY_("R", "Open ref view of all repository references"), \
608 ec2a9698 2022-09-15 mark KEY_("i", "Show object IDs for all tree entries"), \
609 ec2a9698 2022-09-15 mark KEY_("Backspace", "Return to the parent directory"), \
611 fd6badaa 2022-09-23 stsp KEYMAP_("Ref view", TOG_KEYMAP_REF), \
612 ec2a9698 2022-09-15 mark KEY_("Enter", "Display log view of the selected reference"), \
613 ec2a9698 2022-09-15 mark KEY_("T", "Display tree view of the selected reference"), \
614 ec2a9698 2022-09-15 mark KEY_("i", "Toggle display of IDs for all non-symbolic references"), \
615 ec2a9698 2022-09-15 mark KEY_("m", "Toggle display of last modified date for each reference"), \
616 ec2a9698 2022-09-15 mark KEY_("o", "Toggle reference sort order (name -> timestamp)"), \
617 ec2a9698 2022-09-15 mark KEY_("C-l", "Reload view with all repository references")
619 ec2a9698 2022-09-15 mark struct tog_key_map {
620 ec2a9698 2022-09-15 mark const char *keys;
621 ec2a9698 2022-09-15 mark const char *info;
622 ec2a9698 2022-09-15 mark enum tog_keymap_type type;
625 af21bb7e 2023-04-12 mark /* curses io for tog regress */
626 af21bb7e 2023-04-12 mark struct tog_io {
628 af21bb7e 2023-04-12 mark FILE *cout;
631 f641a707 2023-09-05 mark char *input_str;
632 8d212112 2023-04-16 mark int wait_for_ui;
634 098596c5 2023-04-14 stsp static int using_mock_io;
636 81641b41 2023-04-20 mark #define TOG_KEY_SCRDUMP SHRT_MIN
639 669b5ffa 2018-10-07 stsp * We implement two types of views: parent views and child views.
641 e78dc838 2020-12-04 stsp * The 'Tab' key switches focus between a parent view and its child view.
642 669b5ffa 2018-10-07 stsp * Child views are shown side-by-side to their parent view, provided
643 669b5ffa 2018-10-07 stsp * there is enough screen estate.
645 669b5ffa 2018-10-07 stsp * When a new view is opened from within a parent view, this new view
646 669b5ffa 2018-10-07 stsp * becomes a child view of the parent view, replacing any existing child.
648 669b5ffa 2018-10-07 stsp * When a new view is opened from within a child view, this new view
649 669b5ffa 2018-10-07 stsp * becomes a parent view which will obscure the views below until the
650 669b5ffa 2018-10-07 stsp * user quits the new parent view by typing 'q'.
652 669b5ffa 2018-10-07 stsp * This list of views contains parent views only.
653 669b5ffa 2018-10-07 stsp * Child views are only pointed to by their parent view.
655 bcbd79e2 2018-08-19 stsp TAILQ_HEAD(tog_view_list_head, tog_view);
657 cc3c9aac 2018-08-01 stsp struct tog_view {
658 e5a0f69f 2018-08-18 stsp TAILQ_ENTRY(tog_view) entry;
659 26ed57b2 2018-05-19 stsp WINDOW *window;
660 26ed57b2 2018-05-19 stsp PANEL *panel;
661 9b058f45 2022-06-30 mark int nlines, ncols, begin_y, begin_x; /* based on split height/width */
662 3c1dfe12 2022-07-08 mark int resized_y, resized_x; /* begin_y/x based on user resizing */
663 145b6838 2022-06-16 stsp int maxx, x; /* max column and current start column */
664 f7d12f7e 2018-08-01 stsp int lines, cols; /* copies of LINES and COLS */
665 9b058f45 2022-06-30 mark int nscrolled, offset; /* lines scrolled and hsplit line offset */
666 94b80cfa 2022-08-01 mark int gline, hiline; /* navigate to and highlight this nG line */
667 640cd7ff 2022-06-22 mark int ch, count; /* current keymap and count prefix */
668 571ccd73 2022-07-19 mark int resized; /* set when in a resize event */
669 e78dc838 2020-12-04 stsp int focussed; /* Only set on one parent or child view at a time. */
671 669b5ffa 2018-10-07 stsp struct tog_view *parent;
672 669b5ffa 2018-10-07 stsp struct tog_view *child;
675 e78dc838 2020-12-04 stsp * This flag is initially set on parent views when a new child view
676 e78dc838 2020-12-04 stsp * is created. It gets toggled when the 'Tab' key switches focus
677 e78dc838 2020-12-04 stsp * between parent and child.
678 e78dc838 2020-12-04 stsp * The flag indicates whether focus should be passed on to our child
679 e78dc838 2020-12-04 stsp * view if this parent view gets picked for focus after another parent
680 e78dc838 2020-12-04 stsp * view was closed. This prevents child views from losing focus in such
681 e78dc838 2020-12-04 stsp * situations.
683 e78dc838 2020-12-04 stsp int focus_child;
685 9b058f45 2022-06-30 mark enum tog_view_mode mode;
686 5dc9f4bc 2018-08-04 stsp /* type-specific state */
687 d6b05b5b 2018-08-04 stsp enum tog_view_type type;
689 b01e7d3b 2018-08-04 stsp struct tog_diff_view_state diff;
690 b01e7d3b 2018-08-04 stsp struct tog_log_view_state log;
691 7cbe629d 2018-08-04 stsp struct tog_blame_view_state blame;
692 ad80ab7b 2018-08-04 stsp struct tog_tree_view_state tree;
693 6458efa5 2020-11-24 stsp struct tog_ref_view_state ref;
694 ec2a9698 2022-09-15 mark struct tog_help_view_state help;
697 e5a0f69f 2018-08-18 stsp const struct got_error *(*show)(struct tog_view *);
698 e5a0f69f 2018-08-18 stsp const struct got_error *(*input)(struct tog_view **,
699 e78dc838 2020-12-04 stsp struct tog_view *, int);
700 917d79a7 2022-07-01 stsp const struct got_error *(*reset)(struct tog_view *);
701 571ccd73 2022-07-19 mark const struct got_error *(*resize)(struct tog_view *, int);
702 e5a0f69f 2018-08-18 stsp const struct got_error *(*close)(struct tog_view *);
704 60493ae3 2019-06-20 stsp const struct got_error *(*search_start)(struct tog_view *);
705 60493ae3 2019-06-20 stsp const struct got_error *(*search_next)(struct tog_view *);
706 eaf2c13e 2022-09-17 mark void (*search_setup)(struct tog_view *, FILE **, off_t **, size_t *,
707 eaf2c13e 2022-09-17 mark int **, int **, int **, int **);
708 c0c4acc8 2021-01-24 stsp int search_started;
709 60493ae3 2019-06-20 stsp int searching;
710 b1bf1435 2019-06-21 stsp #define TOG_SEARCH_FORWARD 1
711 b1bf1435 2019-06-21 stsp #define TOG_SEARCH_BACKWARD 2
712 60493ae3 2019-06-20 stsp int search_next_done;
713 8f4ed634 2020-03-26 stsp #define TOG_SEARCH_HAVE_MORE 1
714 8f4ed634 2020-03-26 stsp #define TOG_SEARCH_NO_MORE 2
715 f9967bca 2020-03-27 stsp #define TOG_SEARCH_HAVE_NONE 3
716 1803e47f 2019-06-22 stsp regex_t regex;
717 41605754 2020-11-12 stsp regmatch_t regmatch;
718 3f6c6614 2023-01-23 mark const char *action;
721 ba4f502b 2018-08-04 stsp static const struct got_error *open_diff_view(struct tog_view *,
722 3dbaef42 2020-11-24 stsp struct got_object_id *, struct got_object_id *,
723 3dbaef42 2020-11-24 stsp const char *, const char *, int, int, int, struct tog_view *,
724 78756c87 2020-11-24 stsp struct got_repository *);
725 5dc9f4bc 2018-08-04 stsp static const struct got_error *show_diff_view(struct tog_view *);
726 e5a0f69f 2018-08-18 stsp static const struct got_error *input_diff_view(struct tog_view **,
727 e78dc838 2020-12-04 stsp struct tog_view *, int);
728 917d79a7 2022-07-01 stsp static const struct got_error *reset_diff_view(struct tog_view *);
729 e5a0f69f 2018-08-18 stsp static const struct got_error* close_diff_view(struct tog_view *);
730 f44b1f58 2020-02-02 tracey static const struct got_error *search_start_diff_view(struct tog_view *);
731 eaf2c13e 2022-09-17 mark static void search_setup_diff_view(struct tog_view *, FILE **, off_t **,
732 eaf2c13e 2022-09-17 mark size_t *, int **, int **, int **, int **);
733 ec2a9698 2022-09-15 mark static const struct got_error *search_next_view_match(struct tog_view *);
735 ba4f502b 2018-08-04 stsp static const struct got_error *open_log_view(struct tog_view *,
736 78756c87 2020-11-24 stsp struct got_object_id *, struct got_repository *,
737 99301cec 2023-07-24 stsp const char *, const char *, int, struct got_worktree *);
738 ba4f502b 2018-08-04 stsp static const struct got_error * show_log_view(struct tog_view *);
739 e5a0f69f 2018-08-18 stsp static const struct got_error *input_log_view(struct tog_view **,
740 e78dc838 2020-12-04 stsp struct tog_view *, int);
741 571ccd73 2022-07-19 mark static const struct got_error *resize_log_view(struct tog_view *, int);
742 e5a0f69f 2018-08-18 stsp static const struct got_error *close_log_view(struct tog_view *);
743 60493ae3 2019-06-20 stsp static const struct got_error *search_start_log_view(struct tog_view *);
744 60493ae3 2019-06-20 stsp static const struct got_error *search_next_log_view(struct tog_view *);
746 e5a0f69f 2018-08-18 stsp static const struct got_error *open_blame_view(struct tog_view *, char *,
747 78756c87 2020-11-24 stsp struct got_object_id *, struct got_repository *);
748 7cbe629d 2018-08-04 stsp static const struct got_error *show_blame_view(struct tog_view *);
749 e5a0f69f 2018-08-18 stsp static const struct got_error *input_blame_view(struct tog_view **,
750 e78dc838 2020-12-04 stsp struct tog_view *, int);
751 917d79a7 2022-07-01 stsp static const struct got_error *reset_blame_view(struct tog_view *);
752 e5a0f69f 2018-08-18 stsp static const struct got_error *close_blame_view(struct tog_view *);
753 6c4c42e0 2019-06-24 stsp static const struct got_error *search_start_blame_view(struct tog_view *);
754 eaf2c13e 2022-09-17 mark static void search_setup_blame_view(struct tog_view *, FILE **, off_t **,
755 eaf2c13e 2022-09-17 mark size_t *, int **, int **, int **, int **);
757 ad80ab7b 2018-08-04 stsp static const struct got_error *open_tree_view(struct tog_view *,
758 bc573f3b 2021-07-10 stsp struct got_object_id *, const char *, struct got_repository *);
759 ad80ab7b 2018-08-04 stsp static const struct got_error *show_tree_view(struct tog_view *);
760 e5a0f69f 2018-08-18 stsp static const struct got_error *input_tree_view(struct tog_view **,
761 e78dc838 2020-12-04 stsp struct tog_view *, int);
762 e5a0f69f 2018-08-18 stsp static const struct got_error *close_tree_view(struct tog_view *);
763 7c32bd05 2019-06-22 stsp static const struct got_error *search_start_tree_view(struct tog_view *);
764 7c32bd05 2019-06-22 stsp static const struct got_error *search_next_tree_view(struct tog_view *);
766 6458efa5 2020-11-24 stsp static const struct got_error *open_ref_view(struct tog_view *,
767 6458efa5 2020-11-24 stsp struct got_repository *);
768 6458efa5 2020-11-24 stsp static const struct got_error *show_ref_view(struct tog_view *);
769 6458efa5 2020-11-24 stsp static const struct got_error *input_ref_view(struct tog_view **,
770 e78dc838 2020-12-04 stsp struct tog_view *, int);
771 6458efa5 2020-11-24 stsp static const struct got_error *close_ref_view(struct tog_view *);
772 6458efa5 2020-11-24 stsp static const struct got_error *search_start_ref_view(struct tog_view *);
773 6458efa5 2020-11-24 stsp static const struct got_error *search_next_ref_view(struct tog_view *);
775 eaf2c13e 2022-09-17 mark static const struct got_error *open_help_view(struct tog_view *,
776 eaf2c13e 2022-09-17 mark struct tog_view *);
777 eaf2c13e 2022-09-17 mark static const struct got_error *show_help_view(struct tog_view *);
778 eaf2c13e 2022-09-17 mark static const struct got_error *input_help_view(struct tog_view **,
779 eaf2c13e 2022-09-17 mark struct tog_view *, int);
780 eaf2c13e 2022-09-17 mark static const struct got_error *reset_help_view(struct tog_view *);
781 eaf2c13e 2022-09-17 mark static const struct got_error* close_help_view(struct tog_view *);
782 eaf2c13e 2022-09-17 mark static const struct got_error *search_start_help_view(struct tog_view *);
783 eaf2c13e 2022-09-17 mark static void search_setup_help_view(struct tog_view *, FILE **, off_t **,
784 eaf2c13e 2022-09-17 mark size_t *, int **, int **, int **, int **);
786 25791caa 2018-10-24 stsp static volatile sig_atomic_t tog_sigwinch_received;
787 83baff54 2019-08-12 stsp static volatile sig_atomic_t tog_sigpipe_received;
788 61266923 2020-01-14 stsp static volatile sig_atomic_t tog_sigcont_received;
789 2497f032 2022-05-31 stsp static volatile sig_atomic_t tog_sigint_received;
790 2497f032 2022-05-31 stsp static volatile sig_atomic_t tog_sigterm_received;
792 25791caa 2018-10-24 stsp static void
793 25791caa 2018-10-24 stsp tog_sigwinch(int signo)
795 25791caa 2018-10-24 stsp tog_sigwinch_received = 1;
798 83baff54 2019-08-12 stsp static void
799 83baff54 2019-08-12 stsp tog_sigpipe(int signo)
801 83baff54 2019-08-12 stsp tog_sigpipe_received = 1;
804 61266923 2020-01-14 stsp static void
805 61266923 2020-01-14 stsp tog_sigcont(int signo)
807 61266923 2020-01-14 stsp tog_sigcont_received = 1;
810 2497f032 2022-05-31 stsp static void
811 2497f032 2022-05-31 stsp tog_sigint(int signo)
813 2497f032 2022-05-31 stsp tog_sigint_received = 1;
816 2497f032 2022-05-31 stsp static void
817 2497f032 2022-05-31 stsp tog_sigterm(int signo)
819 2497f032 2022-05-31 stsp tog_sigterm_received = 1;
823 dd6e31d7 2022-06-17 stsp tog_fatal_signal_received(void)
825 2497f032 2022-05-31 stsp return (tog_sigpipe_received ||
826 f044c841 2022-10-24 stsp tog_sigint_received || tog_sigterm_received);
829 e5a0f69f 2018-08-18 stsp static const struct got_error *
830 96a765a8 2018-08-04 stsp view_close(struct tog_view *view)
832 5629093a 2022-07-11 stsp const struct got_error *err = NULL, *child_err = NULL;
834 669b5ffa 2018-10-07 stsp if (view->child) {
835 5629093a 2022-07-11 stsp child_err = view_close(view->child);
836 669b5ffa 2018-10-07 stsp view->child = NULL;
838 e5a0f69f 2018-08-18 stsp if (view->close)
839 e5a0f69f 2018-08-18 stsp err = view->close(view);
840 ea5e7bb5 2018-08-01 stsp if (view->panel)
841 ea5e7bb5 2018-08-01 stsp del_panel(view->panel);
842 ea5e7bb5 2018-08-01 stsp if (view->window)
843 ea5e7bb5 2018-08-01 stsp delwin(view->window);
844 ea5e7bb5 2018-08-01 stsp free(view);
845 5629093a 2022-07-11 stsp return err ? err : child_err;
848 ea5e7bb5 2018-08-01 stsp static struct tog_view *
849 b3665f43 2018-08-04 stsp view_open(int nlines, int ncols, int begin_y, int begin_x,
850 0cf4efb1 2018-09-29 stsp enum tog_view_type type)
852 ad80ab7b 2018-08-04 stsp struct tog_view *view = calloc(1, sizeof(*view));
854 ea5e7bb5 2018-08-01 stsp if (view == NULL)
855 ea5e7bb5 2018-08-01 stsp return NULL;
857 d6b05b5b 2018-08-04 stsp view->type = type;
858 f7d12f7e 2018-08-01 stsp view->lines = LINES;
859 f7d12f7e 2018-08-01 stsp view->cols = COLS;
860 207b9029 2018-08-01 stsp view->nlines = nlines ? nlines : LINES - begin_y;
861 207b9029 2018-08-01 stsp view->ncols = ncols ? ncols : COLS - begin_x;
862 97ddc146 2018-08-01 stsp view->begin_y = begin_y;
863 97ddc146 2018-08-01 stsp view->begin_x = begin_x;
864 842167bf 2018-08-01 stsp view->window = newwin(nlines, ncols, begin_y, begin_x);
865 ea5e7bb5 2018-08-01 stsp if (view->window == NULL) {
866 96a765a8 2018-08-04 stsp view_close(view);
867 ea5e7bb5 2018-08-01 stsp return NULL;
869 ea5e7bb5 2018-08-01 stsp view->panel = new_panel(view->window);
870 0cf4efb1 2018-09-29 stsp if (view->panel == NULL ||
871 0cf4efb1 2018-09-29 stsp set_panel_userptr(view->panel, view) != OK) {
872 96a765a8 2018-08-04 stsp view_close(view);
873 ea5e7bb5 2018-08-01 stsp return NULL;
876 ea5e7bb5 2018-08-01 stsp keypad(view->window, TRUE);
877 ea5e7bb5 2018-08-01 stsp return view;
881 0cf4efb1 2018-09-29 stsp view_split_begin_x(int begin_x)
883 2bd27830 2018-10-22 stsp if (begin_x > 0 || COLS < 120)
885 2bd27830 2018-10-22 stsp return (COLS - MAX(COLS / 2, 80));
888 9b058f45 2022-06-30 mark /* XXX Stub till we decide what to do. */
890 9b058f45 2022-06-30 mark view_split_begin_y(int lines)
892 9b058f45 2022-06-30 mark return lines * HSPLIT_SCALE;
895 5c60c32a 2018-10-18 stsp static const struct got_error *view_resize(struct tog_view *);
897 5c60c32a 2018-10-18 stsp static const struct got_error *
898 5c60c32a 2018-10-18 stsp view_splitscreen(struct tog_view *view)
900 5c60c32a 2018-10-18 stsp const struct got_error *err = NULL;
902 571ccd73 2022-07-19 mark if (!view->resized && view->mode == TOG_VIEW_SPLIT_HRZN) {
903 3c1dfe12 2022-07-08 mark if (view->resized_y && view->resized_y < view->lines)
904 3c1dfe12 2022-07-08 mark view->begin_y = view->resized_y;
906 3c1dfe12 2022-07-08 mark view->begin_y = view_split_begin_y(view->nlines);
907 9b058f45 2022-06-30 mark view->begin_x = 0;
908 571ccd73 2022-07-19 mark } else if (!view->resized) {
909 3c1dfe12 2022-07-08 mark if (view->resized_x && view->resized_x < view->cols - 1 &&
910 3c1dfe12 2022-07-08 mark view->cols > 119)
911 3c1dfe12 2022-07-08 mark view->begin_x = view->resized_x;
913 3c1dfe12 2022-07-08 mark view->begin_x = view_split_begin_x(0);
914 9b058f45 2022-06-30 mark view->begin_y = 0;
916 9b058f45 2022-06-30 mark view->nlines = LINES - view->begin_y;
917 5c60c32a 2018-10-18 stsp view->ncols = COLS - view->begin_x;
918 5c60c32a 2018-10-18 stsp view->lines = LINES;
919 5c60c32a 2018-10-18 stsp view->cols = COLS;
920 5c60c32a 2018-10-18 stsp err = view_resize(view);
922 5c60c32a 2018-10-18 stsp return err;
924 9b058f45 2022-06-30 mark if (view->parent && view->mode == TOG_VIEW_SPLIT_HRZN)
925 9b058f45 2022-06-30 mark view->parent->nlines = view->begin_y;
927 5c60c32a 2018-10-18 stsp if (mvwin(view->window, view->begin_y, view->begin_x) == ERR)
928 638f9024 2019-05-13 stsp return got_error_from_errno("mvwin");
930 5c60c32a 2018-10-18 stsp return NULL;
933 5c60c32a 2018-10-18 stsp static const struct got_error *
934 5c60c32a 2018-10-18 stsp view_fullscreen(struct tog_view *view)
936 5c60c32a 2018-10-18 stsp const struct got_error *err = NULL;
938 5c60c32a 2018-10-18 stsp view->begin_x = 0;
939 571ccd73 2022-07-19 mark view->begin_y = view->resized ? view->begin_y : 0;
940 571ccd73 2022-07-19 mark view->nlines = view->resized ? view->nlines : LINES;
941 5c60c32a 2018-10-18 stsp view->ncols = COLS;
942 5c60c32a 2018-10-18 stsp view->lines = LINES;
943 5c60c32a 2018-10-18 stsp view->cols = COLS;
944 5c60c32a 2018-10-18 stsp err = view_resize(view);
946 5c60c32a 2018-10-18 stsp return err;
948 5c60c32a 2018-10-18 stsp if (mvwin(view->window, view->begin_y, view->begin_x) == ERR)
949 638f9024 2019-05-13 stsp return got_error_from_errno("mvwin");
951 5c60c32a 2018-10-18 stsp return NULL;
955 5c60c32a 2018-10-18 stsp view_is_parent_view(struct tog_view *view)
957 5c60c32a 2018-10-18 stsp return view->parent == NULL;
961 6131ff18 2022-06-20 mark view_is_splitscreen(struct tog_view *view)
963 9b058f45 2022-06-30 mark return view->begin_x > 0 || view->begin_y > 0;
967 24b9cfdc 2022-06-30 stsp view_is_fullscreen(struct tog_view *view)
969 24b9cfdc 2022-06-30 stsp return view->nlines == LINES && view->ncols == COLS;
973 49b24ee5 2022-07-03 mark view_is_hsplit_top(struct tog_view *view)
975 49b24ee5 2022-07-03 mark return view->mode == TOG_VIEW_SPLIT_HRZN && view->child &&
976 49b24ee5 2022-07-03 mark view_is_splitscreen(view->child);
979 9b058f45 2022-06-30 mark static void
980 9b058f45 2022-06-30 mark view_border(struct tog_view *view)
982 9b058f45 2022-06-30 mark PANEL *panel;
983 9b058f45 2022-06-30 mark const struct tog_view *view_above;
985 9b058f45 2022-06-30 mark if (view->parent)
986 9b058f45 2022-06-30 mark return view_border(view->parent);
988 9b058f45 2022-06-30 mark panel = panel_above(view->panel);
989 9b058f45 2022-06-30 mark if (panel == NULL)
992 9b058f45 2022-06-30 mark view_above = panel_userptr(panel);
993 9b058f45 2022-06-30 mark if (view->mode == TOG_VIEW_SPLIT_HRZN)
994 9b058f45 2022-06-30 mark mvwhline(view->window, view_above->begin_y - 1,
995 c62d44e7 2023-04-20 naddy view->begin_x, ACS_HLINE, view->ncols);
997 9b058f45 2022-06-30 mark mvwvline(view->window, view->begin_y, view_above->begin_x - 1,
998 c62d44e7 2023-04-20 naddy ACS_VLINE, view->nlines);
1001 3c1dfe12 2022-07-08 mark static const struct got_error *view_init_hsplit(struct tog_view *, int);
1002 9b058f45 2022-06-30 mark static const struct got_error *request_log_commits(struct tog_view *);
1003 9b058f45 2022-06-30 mark static const struct got_error *offset_selection_down(struct tog_view *);
1004 9b058f45 2022-06-30 mark static void offset_selection_up(struct tog_view *);
1005 3c1dfe12 2022-07-08 mark static void view_get_split(struct tog_view *, int *, int *);
1007 4d8c2215 2018-08-19 stsp static const struct got_error *
1008 f7d12f7e 2018-08-01 stsp view_resize(struct tog_view *view)
1010 9b058f45 2022-06-30 mark const struct got_error *err = NULL;
1011 9b058f45 2022-06-30 mark int dif, nlines, ncols;
1013 9b058f45 2022-06-30 mark dif = LINES - view->lines; /* line difference */
1015 0cf4efb1 2018-09-29 stsp if (view->lines > LINES)
1016 0cf4efb1 2018-09-29 stsp nlines = view->nlines - (view->lines - LINES);
1018 0cf4efb1 2018-09-29 stsp nlines = view->nlines + (LINES - view->lines);
1019 0cf4efb1 2018-09-29 stsp if (view->cols > COLS)
1020 0cf4efb1 2018-09-29 stsp ncols = view->ncols - (view->cols - COLS);
1022 0cf4efb1 2018-09-29 stsp ncols = view->ncols + (COLS - view->cols);
1024 4dd27a72 2022-06-29 stsp if (view->child) {
1025 9b058f45 2022-06-30 mark int hs = view->child->begin_y;
1027 24b9cfdc 2022-06-30 stsp if (!view_is_fullscreen(view))
1028 c71ed39a 2022-06-29 stsp view->child->begin_x = view_split_begin_x(view->begin_x);
1029 9b058f45 2022-06-30 mark if (view->mode == TOG_VIEW_SPLIT_HRZN ||
1030 9b058f45 2022-06-30 mark view->child->begin_x == 0) {
1031 0dbbbe90 2022-06-17 op ncols = COLS;
1033 5c60c32a 2018-10-18 stsp view_fullscreen(view->child);
1034 5c60c32a 2018-10-18 stsp if (view->child->focussed)
1035 5c60c32a 2018-10-18 stsp show_panel(view->child->panel);
1037 5c60c32a 2018-10-18 stsp show_panel(view->panel);
1039 0dbbbe90 2022-06-17 op ncols = view->child->begin_x;
1041 5c60c32a 2018-10-18 stsp view_splitscreen(view->child);
1042 5c60c32a 2018-10-18 stsp show_panel(view->child->panel);
1045 9b058f45 2022-06-30 mark * XXX This is ugly and needs to be moved into the above
1046 9b058f45 2022-06-30 mark * logic but "works" for now and my attempts at moving it
1047 9b058f45 2022-06-30 mark * break either 'tab' or 'F' key maps in horizontal splits.
1050 9b058f45 2022-06-30 mark err = view_splitscreen(view->child);
1052 9b058f45 2022-06-30 mark return err;
1053 9b058f45 2022-06-30 mark if (dif < 0) { /* top split decreased */
1054 9b058f45 2022-06-30 mark err = offset_selection_down(view);
1056 9b058f45 2022-06-30 mark return err;
1058 9b058f45 2022-06-30 mark view_border(view);
1059 9b058f45 2022-06-30 mark update_panels();
1060 9b058f45 2022-06-30 mark doupdate();
1061 9b058f45 2022-06-30 mark show_panel(view->child->panel);
1062 9b058f45 2022-06-30 mark nlines = view->nlines;
1064 0dbbbe90 2022-06-17 op } else if (view->parent == NULL)
1065 0dbbbe90 2022-06-17 op ncols = COLS;
1067 571ccd73 2022-07-19 mark if (view->resize && dif > 0) {
1068 571ccd73 2022-07-19 mark err = view->resize(view, dif);
1070 571ccd73 2022-07-19 mark return err;
1073 0dbbbe90 2022-06-17 op if (wresize(view->window, nlines, ncols) == ERR)
1074 0dbbbe90 2022-06-17 op return got_error_from_errno("wresize");
1075 0dbbbe90 2022-06-17 op if (replace_panel(view->panel, view->window) == ERR)
1076 0dbbbe90 2022-06-17 op return got_error_from_errno("replace_panel");
1077 0dbbbe90 2022-06-17 op wclear(view->window);
1079 0dbbbe90 2022-06-17 op view->nlines = nlines;
1080 0dbbbe90 2022-06-17 op view->ncols = ncols;
1081 0dbbbe90 2022-06-17 op view->lines = LINES;
1082 0dbbbe90 2022-06-17 op view->cols = COLS;
1084 5c60c32a 2018-10-18 stsp return NULL;
1087 571ccd73 2022-07-19 mark static const struct got_error *
1088 571ccd73 2022-07-19 mark resize_log_view(struct tog_view *view, int increase)
1090 6fe51fee 2022-07-22 mark struct tog_log_view_state *s = &view->state.log;
1091 6fe51fee 2022-07-22 mark const struct got_error *err = NULL;
1092 6fe51fee 2022-07-22 mark int n = 0;
1094 6fe51fee 2022-07-22 mark if (s->selected_entry)
1095 6fe51fee 2022-07-22 mark n = s->selected_entry->idx + view->lines - s->selected;
1098 571ccd73 2022-07-19 mark * Request commits to account for the increased
1099 571ccd73 2022-07-19 mark * height so we have enough to populate the view.
1101 568eae95 2022-09-11 mark if (s->commits->ncommits < n) {
1102 568eae95 2022-09-11 mark view->nscrolled = n - s->commits->ncommits + increase + 1;
1103 571ccd73 2022-07-19 mark err = request_log_commits(view);
1106 571ccd73 2022-07-19 mark return err;
1109 d9a7ab53 2022-07-11 mark static void
1110 d9a7ab53 2022-07-11 mark view_adjust_offset(struct tog_view *view, int n)
1112 d9a7ab53 2022-07-11 mark if (n == 0)
1115 d9a7ab53 2022-07-11 mark if (view->parent && view->parent->offset) {
1116 d9a7ab53 2022-07-11 mark if (view->parent->offset + n >= 0)
1117 d9a7ab53 2022-07-11 mark view->parent->offset += n;
1119 d9a7ab53 2022-07-11 mark view->parent->offset = 0;
1120 d9a7ab53 2022-07-11 mark } else if (view->offset) {
1121 d9a7ab53 2022-07-11 mark if (view->offset - n >= 0)
1122 d9a7ab53 2022-07-11 mark view->offset -= n;
1124 d9a7ab53 2022-07-11 mark view->offset = 0;
1128 3c1dfe12 2022-07-08 mark static const struct got_error *
1129 3c1dfe12 2022-07-08 mark view_resize_split(struct tog_view *view, int resize)
1131 3c1dfe12 2022-07-08 mark const struct got_error *err = NULL;
1132 3c1dfe12 2022-07-08 mark struct tog_view *v = NULL;
1134 3c1dfe12 2022-07-08 mark if (view->parent)
1135 3c1dfe12 2022-07-08 mark v = view->parent;
1139 3c1dfe12 2022-07-08 mark if (!v->child || !view_is_splitscreen(v->child))
1140 3c1dfe12 2022-07-08 mark return NULL;
1142 571ccd73 2022-07-19 mark v->resized = v->child->resized = resize; /* lock for resize event */
1144 3c1dfe12 2022-07-08 mark if (view->mode == TOG_VIEW_SPLIT_HRZN) {
1145 3c1dfe12 2022-07-08 mark if (v->child->resized_y)
1146 3c1dfe12 2022-07-08 mark v->child->begin_y = v->child->resized_y;
1147 3c1dfe12 2022-07-08 mark if (view->parent)
1148 3c1dfe12 2022-07-08 mark v->child->begin_y -= resize;
1150 3c1dfe12 2022-07-08 mark v->child->begin_y += resize;
1151 3c1dfe12 2022-07-08 mark if (v->child->begin_y < 3) {
1152 3c1dfe12 2022-07-08 mark view->count = 0;
1153 3c1dfe12 2022-07-08 mark v->child->begin_y = 3;
1154 3c1dfe12 2022-07-08 mark } else if (v->child->begin_y > LINES - 1) {
1155 3c1dfe12 2022-07-08 mark view->count = 0;
1156 3c1dfe12 2022-07-08 mark v->child->begin_y = LINES - 1;
1158 3c1dfe12 2022-07-08 mark v->ncols = COLS;
1159 3c1dfe12 2022-07-08 mark v->child->ncols = COLS;
1160 d9a7ab53 2022-07-11 mark view_adjust_offset(view, resize);
1161 3c1dfe12 2022-07-08 mark err = view_init_hsplit(v, v->child->begin_y);
1163 3c1dfe12 2022-07-08 mark return err;
1164 3c1dfe12 2022-07-08 mark v->child->resized_y = v->child->begin_y;
1166 3c1dfe12 2022-07-08 mark if (v->child->resized_x)
1167 3c1dfe12 2022-07-08 mark v->child->begin_x = v->child->resized_x;
1168 3c1dfe12 2022-07-08 mark if (view->parent)
1169 3c1dfe12 2022-07-08 mark v->child->begin_x -= resize;
1171 3c1dfe12 2022-07-08 mark v->child->begin_x += resize;
1172 3c1dfe12 2022-07-08 mark if (v->child->begin_x < 11) {
1173 3c1dfe12 2022-07-08 mark view->count = 0;
1174 3c1dfe12 2022-07-08 mark v->child->begin_x = 11;
1175 3c1dfe12 2022-07-08 mark } else if (v->child->begin_x > COLS - 1) {
1176 3c1dfe12 2022-07-08 mark view->count = 0;
1177 3c1dfe12 2022-07-08 mark v->child->begin_x = COLS - 1;
1179 3c1dfe12 2022-07-08 mark v->child->resized_x = v->child->begin_x;
1182 3c1dfe12 2022-07-08 mark v->child->mode = v->mode;
1183 3c1dfe12 2022-07-08 mark v->child->nlines = v->lines - v->child->begin_y;
1184 3c1dfe12 2022-07-08 mark v->child->ncols = v->cols - v->child->begin_x;
1185 3c1dfe12 2022-07-08 mark v->focus_child = 1;
1187 3c1dfe12 2022-07-08 mark err = view_fullscreen(v);
1189 3c1dfe12 2022-07-08 mark return err;
1190 3c1dfe12 2022-07-08 mark err = view_splitscreen(v->child);
1192 3c1dfe12 2022-07-08 mark return err;
1194 3c1dfe12 2022-07-08 mark if (v->mode == TOG_VIEW_SPLIT_HRZN) {
1195 3c1dfe12 2022-07-08 mark err = offset_selection_down(v->child);
1197 3c1dfe12 2022-07-08 mark return err;
1200 6fe51fee 2022-07-22 mark if (v->resize)
1201 6fe51fee 2022-07-22 mark err = v->resize(v, 0);
1202 6fe51fee 2022-07-22 mark else if (v->child->resize)
1203 6fe51fee 2022-07-22 mark err = v->child->resize(v->child, 0);
1205 571ccd73 2022-07-19 mark v->resized = v->child->resized = 0;
1207 3c1dfe12 2022-07-08 mark return err;
1210 3c1dfe12 2022-07-08 mark static void
1211 3c1dfe12 2022-07-08 mark view_transfer_size(struct tog_view *dst, struct tog_view *src)
1213 3c1dfe12 2022-07-08 mark struct tog_view *v = src->child ? src->child : src;
1215 3c1dfe12 2022-07-08 mark dst->resized_x = v->resized_x;
1216 3c1dfe12 2022-07-08 mark dst->resized_y = v->resized_y;
1219 669b5ffa 2018-10-07 stsp static const struct got_error *
1220 669b5ffa 2018-10-07 stsp view_close_child(struct tog_view *view)
1222 1a76625f 2018-10-22 stsp const struct got_error *err = NULL;
1224 669b5ffa 2018-10-07 stsp if (view->child == NULL)
1225 669b5ffa 2018-10-07 stsp return NULL;
1227 669b5ffa 2018-10-07 stsp err = view_close(view->child);
1228 669b5ffa 2018-10-07 stsp view->child = NULL;
1229 669b5ffa 2018-10-07 stsp return err;
1232 0dbbbe90 2022-06-17 op static const struct got_error *
1233 669b5ffa 2018-10-07 stsp view_set_child(struct tog_view *view, struct tog_view *child)
1235 3c1dfe12 2022-07-08 mark const struct got_error *err = NULL;
1237 669b5ffa 2018-10-07 stsp view->child = child;
1238 669b5ffa 2018-10-07 stsp child->parent = view;
1240 3c1dfe12 2022-07-08 mark err = view_resize(view);
1242 3c1dfe12 2022-07-08 mark return err;
1244 3c1dfe12 2022-07-08 mark if (view->child->resized_x || view->child->resized_y)
1245 3c1dfe12 2022-07-08 mark err = view_resize_split(view, 0);
1247 3c1dfe12 2022-07-08 mark return err;
1250 136e2bd4 2022-07-23 mark static const struct got_error *view_dispatch_request(struct tog_view **,
1251 136e2bd4 2022-07-23 mark struct tog_view *, enum tog_view_type, int, int);
1253 136e2bd4 2022-07-23 mark static const struct got_error *
1254 136e2bd4 2022-07-23 mark view_request_new(struct tog_view **requested, struct tog_view *view,
1255 136e2bd4 2022-07-23 mark enum tog_view_type request)
1257 136e2bd4 2022-07-23 mark struct tog_view *new_view = NULL;
1258 136e2bd4 2022-07-23 mark const struct got_error *err;
1259 136e2bd4 2022-07-23 mark int y = 0, x = 0;
1261 136e2bd4 2022-07-23 mark *requested = NULL;
1263 94274a8f 2022-09-19 mark if (view_is_parent_view(view) && request != TOG_VIEW_HELP)
1264 136e2bd4 2022-07-23 mark view_get_split(view, &y, &x);
1266 136e2bd4 2022-07-23 mark err = view_dispatch_request(&new_view, view, request, y, x);
1268 136e2bd4 2022-07-23 mark return err;
1270 94274a8f 2022-09-19 mark if (view_is_parent_view(view) && view->mode == TOG_VIEW_SPLIT_HRZN &&
1271 94274a8f 2022-09-19 mark request != TOG_VIEW_HELP) {
1272 136e2bd4 2022-07-23 mark err = view_init_hsplit(view, y);
1274 136e2bd4 2022-07-23 mark return err;
1277 136e2bd4 2022-07-23 mark view->focussed = 0;
1278 136e2bd4 2022-07-23 mark new_view->focussed = 1;
1279 136e2bd4 2022-07-23 mark new_view->mode = view->mode;
1280 94274a8f 2022-09-19 mark new_view->nlines = request == TOG_VIEW_HELP ?
1281 94274a8f 2022-09-19 mark view->lines : view->lines - y;
1283 94274a8f 2022-09-19 mark if (view_is_parent_view(view) && request != TOG_VIEW_HELP) {
1284 136e2bd4 2022-07-23 mark view_transfer_size(new_view, view);
1285 136e2bd4 2022-07-23 mark err = view_close_child(view);
1287 136e2bd4 2022-07-23 mark return err;
1288 136e2bd4 2022-07-23 mark err = view_set_child(view, new_view);
1290 136e2bd4 2022-07-23 mark return err;
1291 136e2bd4 2022-07-23 mark view->focus_child = 1;
1293 136e2bd4 2022-07-23 mark *requested = new_view;
1295 136e2bd4 2022-07-23 mark return NULL;
1298 34bc9ec9 2019-02-22 stsp static void
1299 79fcf3e4 2018-11-04 stsp tog_resizeterm(void)
1301 25791caa 2018-10-24 stsp int cols, lines;
1302 25791caa 2018-10-24 stsp struct winsize size;
1304 25791caa 2018-10-24 stsp if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &size) < 0) {
1305 25791caa 2018-10-24 stsp cols = 80; /* Default */
1306 25791caa 2018-10-24 stsp lines = 24;
1308 25791caa 2018-10-24 stsp cols = size.ws_col;
1309 25791caa 2018-10-24 stsp lines = size.ws_row;
1311 25791caa 2018-10-24 stsp resize_term(lines, cols);
1314 2b49a8ae 2019-06-22 stsp static const struct got_error *
1315 602eda79 2023-02-09 mark view_search_start(struct tog_view *view, int fast_refresh)
1317 7c32bd05 2019-06-22 stsp const struct got_error *err = NULL;
1318 9b058f45 2022-06-30 mark struct tog_view *v = view;
1319 2b49a8ae 2019-06-22 stsp char pattern[1024];
1322 c0c4acc8 2021-01-24 stsp if (view->search_started) {
1323 c0c4acc8 2021-01-24 stsp regfree(&view->regex);
1324 c0c4acc8 2021-01-24 stsp view->searching = 0;
1325 c0c4acc8 2021-01-24 stsp memset(&view->regmatch, 0, sizeof(view->regmatch));
1327 c0c4acc8 2021-01-24 stsp view->search_started = 0;
1329 2b49a8ae 2019-06-22 stsp if (view->nlines < 1)
1330 2b49a8ae 2019-06-22 stsp return NULL;
1332 49b24ee5 2022-07-03 mark if (view_is_hsplit_top(view))
1333 9b058f45 2022-06-30 mark v = view->child;
1334 9d0feb8b 2022-12-27 mark else if (view->mode == TOG_VIEW_SPLIT_VERT && view->parent)
1335 9d0feb8b 2022-12-27 mark v = view->parent;
1337 f641a707 2023-09-05 mark if (tog_io.input_str != NULL) {
1338 f641a707 2023-09-05 mark if (strlcpy(pattern, tog_io.input_str, sizeof(pattern)) >=
1339 f641a707 2023-09-05 mark sizeof(pattern))
1340 f641a707 2023-09-05 mark return got_error(GOT_ERR_NO_SPACE);
1342 f641a707 2023-09-05 mark mvwaddstr(v->window, v->nlines - 1, 0, "/");
1343 f641a707 2023-09-05 mark wclrtoeol(v->window);
1344 f641a707 2023-09-05 mark nodelay(v->window, FALSE); /* block for search term input */
1345 f641a707 2023-09-05 mark nocbreak();
1347 f641a707 2023-09-05 mark ret = wgetnstr(v->window, pattern, sizeof(pattern));
1348 f641a707 2023-09-05 mark wrefresh(v->window);
1351 f641a707 2023-09-05 mark nodelay(v->window, TRUE);
1352 f641a707 2023-09-05 mark if (!fast_refresh && !using_mock_io)
1353 f641a707 2023-09-05 mark halfdelay(10);
1354 f641a707 2023-09-05 mark if (ret == ERR)
1355 f641a707 2023-09-05 mark return NULL;
1358 41605754 2020-11-12 stsp if (regcomp(&view->regex, pattern, REG_EXTENDED | REG_NEWLINE) == 0) {
1359 7c32bd05 2019-06-22 stsp err = view->search_start(view);
1360 7c32bd05 2019-06-22 stsp if (err) {
1361 7c32bd05 2019-06-22 stsp regfree(&view->regex);
1362 7c32bd05 2019-06-22 stsp return err;
1364 c0c4acc8 2021-01-24 stsp view->search_started = 1;
1365 2b49a8ae 2019-06-22 stsp view->searching = TOG_SEARCH_FORWARD;
1366 2b49a8ae 2019-06-22 stsp view->search_next_done = 0;
1367 2b49a8ae 2019-06-22 stsp view->search_next(view);
1370 2b49a8ae 2019-06-22 stsp return NULL;
1373 7532ccda 2022-07-11 mark /* Switch split mode. If view is a parent or child, draw the new splitscreen. */
1374 d2366e29 2022-07-07 mark static const struct got_error *
1375 d2366e29 2022-07-07 mark switch_split(struct tog_view *view)
1377 d2366e29 2022-07-07 mark const struct got_error *err = NULL;
1378 d2366e29 2022-07-07 mark struct tog_view *v = NULL;
1380 d2366e29 2022-07-07 mark if (view->parent)
1381 d2366e29 2022-07-07 mark v = view->parent;
1385 7532ccda 2022-07-11 mark if (v->mode == TOG_VIEW_SPLIT_HRZN)
1386 7532ccda 2022-07-11 mark v->mode = TOG_VIEW_SPLIT_VERT;
1388 d2366e29 2022-07-07 mark v->mode = TOG_VIEW_SPLIT_HRZN;
1390 7532ccda 2022-07-11 mark if (!v->child)
1391 7532ccda 2022-07-11 mark return NULL;
1392 7532ccda 2022-07-11 mark else if (v->mode == TOG_VIEW_SPLIT_VERT && v->cols < 120)
1393 7532ccda 2022-07-11 mark v->mode = TOG_VIEW_SPLIT_NONE;
1395 d2366e29 2022-07-07 mark view_get_split(v, &v->child->begin_y, &v->child->begin_x);
1396 3c1dfe12 2022-07-08 mark if (v->mode == TOG_VIEW_SPLIT_HRZN && v->child->resized_y)
1397 3c1dfe12 2022-07-08 mark v->child->begin_y = v->child->resized_y;
1398 7532ccda 2022-07-11 mark else if (v->mode == TOG_VIEW_SPLIT_VERT && v->child->resized_x)
1399 3c1dfe12 2022-07-08 mark v->child->begin_x = v->child->resized_x;
1402 d2366e29 2022-07-07 mark if (v->mode == TOG_VIEW_SPLIT_HRZN) {
1403 d2366e29 2022-07-07 mark v->ncols = COLS;
1404 d2366e29 2022-07-07 mark v->child->ncols = COLS;
1405 7532ccda 2022-07-11 mark v->child->nscrolled = LINES - v->child->nlines;
1407 d2366e29 2022-07-07 mark err = view_init_hsplit(v, v->child->begin_y);
1409 d2366e29 2022-07-07 mark return err;
1411 d2366e29 2022-07-07 mark v->child->mode = v->mode;
1412 d2366e29 2022-07-07 mark v->child->nlines = v->lines - v->child->begin_y;
1413 d2366e29 2022-07-07 mark v->focus_child = 1;
1415 d2366e29 2022-07-07 mark err = view_fullscreen(v);
1417 d2366e29 2022-07-07 mark return err;
1418 d2366e29 2022-07-07 mark err = view_splitscreen(v->child);
1420 d2366e29 2022-07-07 mark return err;
1422 7532ccda 2022-07-11 mark if (v->mode == TOG_VIEW_SPLIT_NONE)
1423 7532ccda 2022-07-11 mark v->mode = TOG_VIEW_SPLIT_VERT;
1424 7532ccda 2022-07-11 mark if (v->mode == TOG_VIEW_SPLIT_HRZN) {
1425 7532ccda 2022-07-11 mark err = offset_selection_down(v);
1427 279d2047 2022-07-29 stsp return err;
1428 d2366e29 2022-07-07 mark err = offset_selection_down(v->child);
1430 279d2047 2022-07-29 stsp return err;
1432 7532ccda 2022-07-11 mark offset_selection_up(v);
1433 7532ccda 2022-07-11 mark offset_selection_up(v->child);
1435 dff91825 2022-07-22 mark if (v->resize)
1436 dff91825 2022-07-22 mark err = v->resize(v, 0);
1437 dff91825 2022-07-22 mark else if (v->child->resize)
1438 dff91825 2022-07-22 mark err = v->child->resize(v->child, 0);
1440 d2366e29 2022-07-07 mark return err;
1444 af21bb7e 2023-04-12 mark * Strip trailing whitespace from str starting at byte *n;
1445 af21bb7e 2023-04-12 mark * if *n < 0, use strlen(str). Return new str length in *n.
1447 af21bb7e 2023-04-12 mark static void
1448 af21bb7e 2023-04-12 mark strip_trailing_ws(char *str, int *n)
1450 af21bb7e 2023-04-12 mark size_t x = *n;
1452 af21bb7e 2023-04-12 mark if (str == NULL || *str == '\0')
1455 af21bb7e 2023-04-12 mark if (x < 0)
1456 af21bb7e 2023-04-12 mark x = strlen(str);
1458 af21bb7e 2023-04-12 mark while (x-- > 0 && isspace((unsigned char)str[x]))
1459 af21bb7e 2023-04-12 mark str[x] = '\0';
1461 af21bb7e 2023-04-12 mark *n = x + 1;
1465 af21bb7e 2023-04-12 mark * Extract visible substring of line y from the curses screen
1466 81641b41 2023-04-20 mark * and strip trailing whitespace. If vline is set, overwrite
1467 81641b41 2023-04-20 mark * line[vline] with '|' because the ACS_VLINE character is
1468 81641b41 2023-04-20 mark * written out as 'x'. Write the line to file f.
1470 af21bb7e 2023-04-12 mark static const struct got_error *
1471 af21bb7e 2023-04-12 mark view_write_line(FILE *f, int y, int vline)
1473 af21bb7e 2023-04-12 mark char line[COLS * MB_LEN_MAX]; /* allow for multibyte chars */
1476 af21bb7e 2023-04-12 mark r = mvwinnstr(curscr, y, 0, line, sizeof(line));
1477 af21bb7e 2023-04-12 mark if (r == ERR)
1478 af21bb7e 2023-04-12 mark return got_error_fmt(GOT_ERR_RANGE,
1479 af21bb7e 2023-04-12 mark "failed to extract line %d", y);
1482 af21bb7e 2023-04-12 mark * In some views, lines are padded with blanks to COLS width.
1483 af21bb7e 2023-04-12 mark * Strip them so we can diff without the -b flag when testing.
1485 af21bb7e 2023-04-12 mark strip_trailing_ws(line, &r);
1487 81641b41 2023-04-20 mark if (vline > 0)
1488 af21bb7e 2023-04-12 mark line[vline] = '|';
1490 af21bb7e 2023-04-12 mark w = fprintf(f, "%s\n", line);
1491 af21bb7e 2023-04-12 mark if (w != r + 1) /* \n */
1492 af21bb7e 2023-04-12 mark return got_ferror(f, GOT_ERR_IO);
1494 af21bb7e 2023-04-12 mark return NULL;
1498 af21bb7e 2023-04-12 mark * Capture the visible curses screen by writing each line to the
1499 af21bb7e 2023-04-12 mark * file at the path set via the TOG_SCR_DUMP environment variable.
1501 af21bb7e 2023-04-12 mark static const struct got_error *
1502 af21bb7e 2023-04-12 mark screendump(struct tog_view *view)
1504 af21bb7e 2023-04-12 mark const struct got_error *err;
1507 3aa652ef 2023-04-21 op err = got_opentemp_truncate(tog_io.sdump);
1511 af21bb7e 2023-04-12 mark if ((view->child && view->child->begin_x) ||
1512 af21bb7e 2023-04-12 mark (view->parent && view->begin_x)) {
1513 af21bb7e 2023-04-12 mark int ncols = view->child ? view->ncols : view->parent->ncols;
1515 af21bb7e 2023-04-12 mark /* vertical splitscreen */
1516 af21bb7e 2023-04-12 mark for (i = 0; i < view->nlines; ++i) {
1517 3aa652ef 2023-04-21 op err = view_write_line(tog_io.sdump, i, ncols - 1);
1519 af21bb7e 2023-04-12 mark goto done;
1522 af21bb7e 2023-04-12 mark int hline = 0;
1524 af21bb7e 2023-04-12 mark /* fullscreen or horizontal splitscreen */
1525 af21bb7e 2023-04-12 mark if ((view->child && view->child->begin_y) ||
1526 af21bb7e 2023-04-12 mark (view->parent && view->begin_y)) /* hsplit */
1527 af21bb7e 2023-04-12 mark hline = view->child ?
1528 af21bb7e 2023-04-12 mark view->child->begin_y : view->begin_y;
1530 af21bb7e 2023-04-12 mark for (i = 0; i < view->lines; i++) {
1531 81641b41 2023-04-20 mark if (hline && i == hline - 1) {
1534 af21bb7e 2023-04-12 mark /* ACS_HLINE writes out as 'q', overwrite it */
1535 af21bb7e 2023-04-12 mark for (c = 0; c < view->cols; ++c)
1536 3aa652ef 2023-04-21 op fputc('-', tog_io.sdump);
1537 3aa652ef 2023-04-21 op fputc('\n', tog_io.sdump);
1541 3aa652ef 2023-04-21 op err = view_write_line(tog_io.sdump, i, 0);
1543 af21bb7e 2023-04-12 mark goto done;
1548 af21bb7e 2023-04-12 mark return err;
1552 f0032ce6 2022-07-02 mark * Compute view->count from numeric input. Assign total to view->count and
1553 f0032ce6 2022-07-02 mark * return first non-numeric key entered.
1555 640cd7ff 2022-06-22 mark static int
1556 640cd7ff 2022-06-22 mark get_compound_key(struct tog_view *view, int c)
1558 9b058f45 2022-06-30 mark struct tog_view *v = view;
1559 9b058f45 2022-06-30 mark int x, n = 0;
1561 49b24ee5 2022-07-03 mark if (view_is_hsplit_top(view))
1562 9b058f45 2022-06-30 mark v = view->child;
1563 9b058f45 2022-06-30 mark else if (view->mode == TOG_VIEW_SPLIT_VERT && view->parent)
1564 9b058f45 2022-06-30 mark v = view->parent;
1566 640cd7ff 2022-06-22 mark view->count = 0;
1567 f0032ce6 2022-07-02 mark cbreak(); /* block for input */
1568 94b80cfa 2022-08-01 mark nodelay(view->window, FALSE);
1569 9b058f45 2022-06-30 mark wmove(v->window, v->nlines - 1, 0);
1570 9b058f45 2022-06-30 mark wclrtoeol(v->window);
1571 9b058f45 2022-06-30 mark waddch(v->window, ':');
1574 9b058f45 2022-06-30 mark x = getcurx(v->window);
1575 9b058f45 2022-06-30 mark if (x != ERR && x < view->ncols) {
1576 9b058f45 2022-06-30 mark waddch(v->window, c);
1577 9b058f45 2022-06-30 mark wrefresh(v->window);
1581 640cd7ff 2022-06-22 mark * Don't overflow. Max valid request should be the greatest
1582 640cd7ff 2022-06-22 mark * between the longest and total lines; cap at 10 million.
1584 640cd7ff 2022-06-22 mark if (n >= 9999999)
1585 640cd7ff 2022-06-22 mark n = 9999999;
1587 640cd7ff 2022-06-22 mark n = n * 10 + (c - '0');
1588 640cd7ff 2022-06-22 mark } while (((c = wgetch(view->window))) >= '0' && c <= '9' && c != ERR);
1590 94b80cfa 2022-08-01 mark if (c == 'G' || c == 'g') { /* nG key map */
1591 94b80cfa 2022-08-01 mark view->gline = view->hiline = n;
1596 640cd7ff 2022-06-22 mark /* Massage excessive or inapplicable values at the input handler. */
1597 640cd7ff 2022-06-22 mark view->count = n;
1602 3f6c6614 2023-01-23 mark static void
1603 3f6c6614 2023-01-23 mark action_report(struct tog_view *view)
1605 3f6c6614 2023-01-23 mark struct tog_view *v = view;
1607 3f6c6614 2023-01-23 mark if (view_is_hsplit_top(view))
1608 3f6c6614 2023-01-23 mark v = view->child;
1609 3f6c6614 2023-01-23 mark else if (view->mode == TOG_VIEW_SPLIT_VERT && view->parent)
1610 3f6c6614 2023-01-23 mark v = view->parent;
1612 3f6c6614 2023-01-23 mark wmove(v->window, v->nlines - 1, 0);
1613 3f6c6614 2023-01-23 mark wclrtoeol(v->window);
1614 3f6c6614 2023-01-23 mark wprintw(v->window, ":%s", view->action);
1615 3f6c6614 2023-01-23 mark wrefresh(v->window);
1618 3f6c6614 2023-01-23 mark * Clear action status report. Only clear in blame view
1619 3f6c6614 2023-01-23 mark * once annotating is complete, otherwise it's too fast.
1621 3f6c6614 2023-01-23 mark if (view->type == TOG_VIEW_BLAME) {
1622 3f6c6614 2023-01-23 mark if (view->state.blame.blame_complete)
1623 3f6c6614 2023-01-23 mark view->action = NULL;
1625 3f6c6614 2023-01-23 mark view->action = NULL;
1629 af21bb7e 2023-04-12 mark * Read the next line from the test script and assign
1630 af21bb7e 2023-04-12 mark * key instruction to *ch. If at EOF, set the *done flag.
1632 0cf4efb1 2018-09-29 stsp static const struct got_error *
1633 d9bb8469 2023-04-20 mark tog_read_script_key(FILE *script, struct tog_view *view, int *ch, int *done)
1635 af21bb7e 2023-04-12 mark const struct got_error *err = NULL;
1636 af21bb7e 2023-04-12 mark char *line = NULL;
1637 af21bb7e 2023-04-12 mark size_t linesz = 0;
1638 f641a707 2023-09-05 mark ssize_t n;
1641 d9bb8469 2023-04-20 mark if (view->count && --view->count) {
1642 d9bb8469 2023-04-20 mark *ch = view->ch;
1643 d9bb8469 2023-04-20 mark return NULL;
1647 f641a707 2023-09-05 mark if ((n = getline(&line, &linesz, script)) == -1) {
1648 af21bb7e 2023-04-12 mark if (feof(script)) {
1649 af21bb7e 2023-04-12 mark *done = 1;
1650 af21bb7e 2023-04-12 mark goto done;
1652 af21bb7e 2023-04-12 mark err = got_ferror(script, GOT_ERR_IO);
1653 af21bb7e 2023-04-12 mark goto done;
1657 8d212112 2023-04-16 mark if (strncasecmp(line, "WAIT_FOR_UI", 11) == 0)
1658 8d212112 2023-04-16 mark tog_io.wait_for_ui = 1;
1659 8d212112 2023-04-16 mark else if (strncasecmp(line, "KEY_ENTER", 9) == 0)
1660 af21bb7e 2023-04-12 mark *ch = KEY_ENTER;
1661 af21bb7e 2023-04-12 mark else if (strncasecmp(line, "KEY_RIGHT", 9) == 0)
1662 af21bb7e 2023-04-12 mark *ch = KEY_RIGHT;
1663 af21bb7e 2023-04-12 mark else if (strncasecmp(line, "KEY_LEFT", 8) == 0)
1664 af21bb7e 2023-04-12 mark *ch = KEY_LEFT;
1665 af21bb7e 2023-04-12 mark else if (strncasecmp(line, "KEY_DOWN", 8) == 0)
1666 af21bb7e 2023-04-12 mark *ch = KEY_DOWN;
1667 af21bb7e 2023-04-12 mark else if (strncasecmp(line, "KEY_UP", 6) == 0)
1668 af21bb7e 2023-04-12 mark *ch = KEY_UP;
1669 c671dc65 2023-04-24 mark else if (strncasecmp(line, "TAB", 3) == 0)
1670 c671dc65 2023-04-24 mark *ch = '\t';
1671 81641b41 2023-04-20 mark else if (strncasecmp(line, "SCREENDUMP", 10) == 0)
1672 af21bb7e 2023-04-12 mark *ch = TOG_KEY_SCRDUMP;
1673 d9bb8469 2023-04-20 mark else if (isdigit((unsigned char)*line)) {
1674 d9bb8469 2023-04-20 mark char *t = line;
1676 d9bb8469 2023-04-20 mark while (isdigit((unsigned char)*t))
1678 d9bb8469 2023-04-20 mark view->ch = *ch = *t;
1679 d9bb8469 2023-04-20 mark *t = '\0';
1680 d9bb8469 2023-04-20 mark /* ignore error, view->count is 0 if instruction is invalid */
1681 d9bb8469 2023-04-20 mark view->count = strtonum(line, 0, INT_MAX, NULL);
1683 af21bb7e 2023-04-12 mark *ch = *line;
1684 f641a707 2023-09-05 mark if (n > 2 && (*ch == '/' || *ch == '&')) {
1685 f641a707 2023-09-05 mark /* skip leading keymap and trim trailing newline */
1686 f641a707 2023-09-05 mark tog_io.input_str = strndup(line + 1, n - 2);
1687 f641a707 2023-09-05 mark if (tog_io.input_str == NULL) {
1688 f641a707 2023-09-05 mark err = got_error_from_errno("strndup");
1689 f641a707 2023-09-05 mark goto done;
1695 af21bb7e 2023-04-12 mark free(line);
1696 af21bb7e 2023-04-12 mark return err;
1699 af21bb7e 2023-04-12 mark static const struct got_error *
1700 e78dc838 2020-12-04 stsp view_input(struct tog_view **new, int *done, struct tog_view *view,
1701 098596c5 2023-04-14 stsp struct tog_view_list_head *views, int fast_refresh)
1703 e5a0f69f 2018-08-18 stsp const struct got_error *err = NULL;
1704 669b5ffa 2018-10-07 stsp struct tog_view *v;
1705 1a76625f 2018-10-22 stsp int ch, errcode;
1707 e5a0f69f 2018-08-18 stsp *new = NULL;
1709 3f6c6614 2023-01-23 mark if (view->action)
1710 3f6c6614 2023-01-23 mark action_report(view);
1712 f9967bca 2020-03-27 stsp /* Clear "no matches" indicator. */
1713 f9967bca 2020-03-27 stsp if (view->search_next_done == TOG_SEARCH_NO_MORE ||
1714 640cd7ff 2022-06-22 mark view->search_next_done == TOG_SEARCH_HAVE_NONE) {
1715 8f4ed634 2020-03-26 stsp view->search_next_done = TOG_SEARCH_HAVE_MORE;
1716 640cd7ff 2022-06-22 mark view->count = 0;
1719 60493ae3 2019-06-20 stsp if (view->searching && !view->search_next_done) {
1720 82954512 2020-02-03 stsp errcode = pthread_mutex_unlock(&tog_mutex);
1721 82954512 2020-02-03 stsp if (errcode)
1722 82954512 2020-02-03 stsp return got_error_set_errno(errcode,
1723 82954512 2020-02-03 stsp "pthread_mutex_unlock");
1724 3da8ef85 2021-09-21 stsp sched_yield();
1725 82954512 2020-02-03 stsp errcode = pthread_mutex_lock(&tog_mutex);
1726 82954512 2020-02-03 stsp if (errcode)
1727 82954512 2020-02-03 stsp return got_error_set_errno(errcode,
1728 82954512 2020-02-03 stsp "pthread_mutex_lock");
1729 60493ae3 2019-06-20 stsp view->search_next(view);
1730 60493ae3 2019-06-20 stsp return NULL;
1733 1a76625f 2018-10-22 stsp /* Allow threads to make progress while we are waiting for input. */
1734 1a76625f 2018-10-22 stsp errcode = pthread_mutex_unlock(&tog_mutex);
1735 1a76625f 2018-10-22 stsp if (errcode)
1736 2af4a041 2019-05-11 jcs return got_error_set_errno(errcode, "pthread_mutex_unlock");
1738 098596c5 2023-04-14 stsp if (using_mock_io) {
1739 d9bb8469 2023-04-20 mark err = tog_read_script_key(tog_io.f, view, &ch, done);
1740 c736b84a 2023-04-16 mark if (err) {
1741 c736b84a 2023-04-16 mark errcode = pthread_mutex_lock(&tog_mutex);
1742 af21bb7e 2023-04-12 mark return err;
1744 af21bb7e 2023-04-12 mark } else if (view->count && --view->count) {
1746 a6d37fac 2022-07-03 mark nodelay(view->window, TRUE);
1747 640cd7ff 2022-06-22 mark ch = wgetch(view->window);
1748 af21bb7e 2023-04-12 mark /* let C-g or backspace abort unfinished count */
1749 a6d37fac 2022-07-03 mark if (ch == CTRL('g') || ch == KEY_BACKSPACE)
1750 a6d37fac 2022-07-03 mark view->count = 0;
1752 a6d37fac 2022-07-03 mark ch = view->ch;
1754 a6d37fac 2022-07-03 mark ch = wgetch(view->window);
1755 640cd7ff 2022-06-22 mark if (ch >= '1' && ch <= '9')
1756 640cd7ff 2022-06-22 mark view->ch = ch = get_compound_key(view, ch);
1758 94b80cfa 2022-08-01 mark if (view->hiline && ch != ERR && ch != 0)
1759 94b80cfa 2022-08-01 mark view->hiline = 0; /* key pressed, clear line highlight */
1760 94b80cfa 2022-08-01 mark nodelay(view->window, TRUE);
1761 1a76625f 2018-10-22 stsp errcode = pthread_mutex_lock(&tog_mutex);
1762 1a76625f 2018-10-22 stsp if (errcode)
1763 2af4a041 2019-05-11 jcs return got_error_set_errno(errcode, "pthread_mutex_lock");
1765 61266923 2020-01-14 stsp if (tog_sigwinch_received || tog_sigcont_received) {
1766 25791caa 2018-10-24 stsp tog_resizeterm();
1767 25791caa 2018-10-24 stsp tog_sigwinch_received = 0;
1768 61266923 2020-01-14 stsp tog_sigcont_received = 0;
1769 25791caa 2018-10-24 stsp TAILQ_FOREACH(v, views, entry) {
1770 25791caa 2018-10-24 stsp err = view_resize(v);
1772 25791caa 2018-10-24 stsp return err;
1773 e78dc838 2020-12-04 stsp err = v->input(new, v, KEY_RESIZE);
1775 25791caa 2018-10-24 stsp return err;
1776 cdfcfb03 2020-12-06 stsp if (v->child) {
1777 cdfcfb03 2020-12-06 stsp err = view_resize(v->child);
1779 cdfcfb03 2020-12-06 stsp return err;
1780 cdfcfb03 2020-12-06 stsp err = v->child->input(new, v->child,
1781 cdfcfb03 2020-12-06 stsp KEY_RESIZE);
1783 cdfcfb03 2020-12-06 stsp return err;
1784 3c1dfe12 2022-07-08 mark if (v->child->resized_x || v->child->resized_y) {
1785 3c1dfe12 2022-07-08 mark err = view_resize_split(v, 0);
1787 3c1dfe12 2022-07-08 mark return err;
1793 e5a0f69f 2018-08-18 stsp switch (ch) {
1796 ec2a9698 2022-09-15 mark case KEY_F(1):
1797 ec2a9698 2022-09-15 mark if (view->type == TOG_VIEW_HELP)
1798 ec2a9698 2022-09-15 mark err = view->reset(view);
1800 ec2a9698 2022-09-15 mark err = view_request_new(new, view, TOG_VIEW_HELP);
1803 640cd7ff 2022-06-22 mark view->count = 0;
1804 1e37a5c2 2019-05-12 jcs if (view->child) {
1805 e78dc838 2020-12-04 stsp view->focussed = 0;
1806 e78dc838 2020-12-04 stsp view->child->focussed = 1;
1807 e78dc838 2020-12-04 stsp view->focus_child = 1;
1808 1e37a5c2 2019-05-12 jcs } else if (view->parent) {
1809 e78dc838 2020-12-04 stsp view->focussed = 0;
1810 e78dc838 2020-12-04 stsp view->parent->focussed = 1;
1811 e78dc838 2020-12-04 stsp view->parent->focus_child = 0;
1812 9b058f45 2022-06-30 mark if (!view_is_splitscreen(view)) {
1813 6fe51fee 2022-07-22 mark if (view->parent->resize) {
1814 6fe51fee 2022-07-22 mark err = view->parent->resize(view->parent,
1817 9b058f45 2022-06-30 mark return err;
1819 9b058f45 2022-06-30 mark offset_selection_up(view->parent);
1820 6131ff18 2022-06-20 mark err = view_fullscreen(view->parent);
1822 9b058f45 2022-06-30 mark return err;
1827 9b058f45 2022-06-30 mark if (view->parent && view->mode == TOG_VIEW_SPLIT_HRZN) {
1828 6fe51fee 2022-07-22 mark if (view->parent->resize) {
1829 9b058f45 2022-06-30 mark /* might need more commits to fill fullscreen */
1830 6fe51fee 2022-07-22 mark err = view->parent->resize(view->parent, 0);
1834 9b058f45 2022-06-30 mark offset_selection_up(view->parent);
1836 e78dc838 2020-12-04 stsp err = view->input(new, view, ch);
1837 9970f7fc 2020-12-03 stsp view->dying = 1;
1843 640cd7ff 2022-06-22 mark view->count = 0;
1844 1e37a5c2 2019-05-12 jcs if (view_is_parent_view(view)) {
1845 1e37a5c2 2019-05-12 jcs if (view->child == NULL)
1847 1e37a5c2 2019-05-12 jcs if (view_is_splitscreen(view->child)) {
1848 e78dc838 2020-12-04 stsp view->focussed = 0;
1849 e78dc838 2020-12-04 stsp view->child->focussed = 1;
1850 1e37a5c2 2019-05-12 jcs err = view_fullscreen(view->child);
1852 1e37a5c2 2019-05-12 jcs err = view_splitscreen(view->child);
1854 3c1dfe12 2022-07-08 mark err = view_resize_split(view, 0);
1858 e78dc838 2020-12-04 stsp err = view->child->input(new, view->child,
1859 9970f7fc 2020-12-03 stsp KEY_RESIZE);
1861 1e37a5c2 2019-05-12 jcs if (view_is_splitscreen(view)) {
1862 e78dc838 2020-12-04 stsp view->parent->focussed = 0;
1863 e78dc838 2020-12-04 stsp view->focussed = 1;
1864 1e37a5c2 2019-05-12 jcs err = view_fullscreen(view);
1866 1e37a5c2 2019-05-12 jcs err = view_splitscreen(view);
1867 9b058f45 2022-06-30 mark if (!err && view->mode != TOG_VIEW_SPLIT_HRZN)
1868 6131ff18 2022-06-20 mark err = view_resize(view->parent);
1870 3c1dfe12 2022-07-08 mark err = view_resize_split(view, 0);
1874 e78dc838 2020-12-04 stsp err = view->input(new, view, KEY_RESIZE);
1878 6fe51fee 2022-07-22 mark if (view->resize) {
1879 6fe51fee 2022-07-22 mark err = view->resize(view, 0);
1883 e56a1796 2023-04-24 mark if (view->parent) {
1884 e56a1796 2023-04-24 mark if (view->parent->resize) {
1885 e56a1796 2023-04-24 mark err = view->parent->resize(view->parent, 0);
1886 e56a1796 2023-04-24 mark if (err != NULL)
1889 9b058f45 2022-06-30 mark err = offset_selection_down(view->parent);
1890 e56a1796 2023-04-24 mark if (err != NULL)
1893 e56a1796 2023-04-24 mark err = offset_selection_down(view);
1896 3c1dfe12 2022-07-08 mark view->count = 0;
1897 d2366e29 2022-07-07 mark err = switch_split(view);
1900 3c1dfe12 2022-07-08 mark err = view_resize_split(view, -1);
1903 3c1dfe12 2022-07-08 mark err = view_resize_split(view, 1);
1905 1e37a5c2 2019-05-12 jcs case KEY_RESIZE:
1908 640cd7ff 2022-06-22 mark view->count = 0;
1909 60493ae3 2019-06-20 stsp if (view->search_start)
1910 602eda79 2023-02-09 mark view_search_start(view, fast_refresh);
1912 e78dc838 2020-12-04 stsp err = view->input(new, view, ch);
1916 c0c4acc8 2021-01-24 stsp if (view->search_started && view->search_next) {
1917 b1bf1435 2019-06-21 stsp view->searching = (ch == 'n' ?
1918 b1bf1435 2019-06-21 stsp TOG_SEARCH_FORWARD : TOG_SEARCH_BACKWARD);
1919 60493ae3 2019-06-20 stsp view->search_next_done = 0;
1920 60493ae3 2019-06-20 stsp view->search_next(view);
1922 e78dc838 2020-12-04 stsp err = view->input(new, view, ch);
1925 3f6c6614 2023-01-23 mark if (tog_diff_algo == GOT_DIFF_ALGORITHM_MYERS) {
1926 917d79a7 2022-07-01 stsp tog_diff_algo = GOT_DIFF_ALGORITHM_PATIENCE;
1927 3f6c6614 2023-01-23 mark view->action = "Patience diff algorithm";
1929 917d79a7 2022-07-01 stsp tog_diff_algo = GOT_DIFF_ALGORITHM_MYERS;
1930 3f6c6614 2023-01-23 mark view->action = "Myers diff algorithm";
1932 917d79a7 2022-07-01 stsp TAILQ_FOREACH(v, views, entry) {
1933 917d79a7 2022-07-01 stsp if (v->reset) {
1934 917d79a7 2022-07-01 stsp err = v->reset(v);
1936 917d79a7 2022-07-01 stsp return err;
1938 917d79a7 2022-07-01 stsp if (v->child && v->child->reset) {
1939 917d79a7 2022-07-01 stsp err = v->child->reset(v->child);
1941 917d79a7 2022-07-01 stsp return err;
1945 af21bb7e 2023-04-12 mark case TOG_KEY_SCRDUMP:
1946 af21bb7e 2023-04-12 mark err = screendump(view);
1949 e78dc838 2020-12-04 stsp err = view->input(new, view, ch);
1953 e5a0f69f 2018-08-18 stsp return err;
1957 a3404814 2018-09-02 stsp view_needs_focus_indication(struct tog_view *view)
1959 669b5ffa 2018-10-07 stsp if (view_is_parent_view(view)) {
1960 acdafe9c 2020-12-03 stsp if (view->child == NULL || view->child->focussed)
1962 669b5ffa 2018-10-07 stsp if (!view_is_splitscreen(view->child))
1964 669b5ffa 2018-10-07 stsp } else if (!view_is_splitscreen(view))
1967 669b5ffa 2018-10-07 stsp return view->focussed;
1970 bcbd79e2 2018-08-19 stsp static const struct got_error *
1971 098596c5 2023-04-14 stsp tog_io_close(void)
1973 e5a0f69f 2018-08-18 stsp const struct got_error *err = NULL;
1975 098596c5 2023-04-14 stsp if (tog_io.cin && fclose(tog_io.cin) == EOF)
1976 098596c5 2023-04-14 stsp err = got_ferror(tog_io.cin, GOT_ERR_IO);
1977 098596c5 2023-04-14 stsp if (tog_io.cout && fclose(tog_io.cout) == EOF && err == NULL)
1978 098596c5 2023-04-14 stsp err = got_ferror(tog_io.cout, GOT_ERR_IO);
1979 098596c5 2023-04-14 stsp if (tog_io.f && fclose(tog_io.f) == EOF && err == NULL)
1980 098596c5 2023-04-14 stsp err = got_ferror(tog_io.f, GOT_ERR_IO);
1981 3aa652ef 2023-04-21 op if (tog_io.sdump && fclose(tog_io.sdump) == EOF && err == NULL)
1982 3aa652ef 2023-04-21 op err = got_ferror(tog_io.sdump, GOT_ERR_IO);
1983 f641a707 2023-09-05 mark if (tog_io.input_str != NULL)
1984 f641a707 2023-09-05 mark free(tog_io.input_str);
1986 af21bb7e 2023-04-12 mark return err;
1989 af21bb7e 2023-04-12 mark static const struct got_error *
1990 098596c5 2023-04-14 stsp view_loop(struct tog_view *view)
1992 af21bb7e 2023-04-12 mark const struct got_error *err = NULL;
1993 e5a0f69f 2018-08-18 stsp struct tog_view_list_head views;
1994 fb59748f 2020-12-05 stsp struct tog_view *new_view;
1995 d2366e29 2022-07-07 mark char *mode;
1996 fd823528 2018-10-22 stsp int fast_refresh = 10;
1997 1a76625f 2018-10-22 stsp int done = 0, errcode;
1999 d2366e29 2022-07-07 mark mode = getenv("TOG_VIEW_SPLIT_MODE");
2000 d2366e29 2022-07-07 mark if (!mode || !(*mode == 'h' || *mode == 'H'))
2001 d2366e29 2022-07-07 mark view->mode = TOG_VIEW_SPLIT_VERT;
2003 d2366e29 2022-07-07 mark view->mode = TOG_VIEW_SPLIT_HRZN;
2005 1a76625f 2018-10-22 stsp errcode = pthread_mutex_lock(&tog_mutex);
2006 1a76625f 2018-10-22 stsp if (errcode)
2007 2af4a041 2019-05-11 jcs return got_error_set_errno(errcode, "pthread_mutex_lock");
2009 e5a0f69f 2018-08-18 stsp TAILQ_INIT(&views);
2010 e5a0f69f 2018-08-18 stsp TAILQ_INSERT_HEAD(&views, view, entry);
2012 1004088d 2018-09-29 stsp view->focussed = 1;
2013 878940b7 2018-09-29 stsp err = view->show(view);
2015 0cf4efb1 2018-09-29 stsp return err;
2016 0cf4efb1 2018-09-29 stsp update_panels();
2017 0cf4efb1 2018-09-29 stsp doupdate();
2018 5629093a 2022-07-11 stsp while (!TAILQ_EMPTY(&views) && !done && !tog_thread_error &&
2019 5629093a 2022-07-11 stsp !tog_fatal_signal_received()) {
2020 fd823528 2018-10-22 stsp /* Refresh fast during initialization, then become slower. */
2021 098596c5 2023-04-14 stsp if (fast_refresh && --fast_refresh == 0 && !using_mock_io)
2022 fd823528 2018-10-22 stsp halfdelay(10); /* switch to once per second */
2024 098596c5 2023-04-14 stsp err = view_input(&new_view, &done, view, &views, fast_refresh);
2028 dc2c3344 2023-01-23 mark if (view->dying && view == TAILQ_FIRST(&views) &&
2029 dc2c3344 2023-01-23 mark TAILQ_NEXT(view, entry) == NULL)
2031 dc2c3344 2023-01-23 mark if (done) {
2032 dc2c3344 2023-01-23 mark struct tog_view *v;
2035 dc2c3344 2023-01-23 mark * When we quit, scroll the screen up a single line
2036 dc2c3344 2023-01-23 mark * so we don't lose any information.
2038 dc2c3344 2023-01-23 mark TAILQ_FOREACH(v, &views, entry) {
2039 dc2c3344 2023-01-23 mark wmove(v->window, 0, 0);
2040 dc2c3344 2023-01-23 mark wdeleteln(v->window);
2041 dc2c3344 2023-01-23 mark wnoutrefresh(v->window);
2042 dc2c3344 2023-01-23 mark if (v->child && !view_is_fullscreen(v)) {
2043 dc2c3344 2023-01-23 mark wmove(v->child->window, 0, 0);
2044 dc2c3344 2023-01-23 mark wdeleteln(v->child->window);
2045 dc2c3344 2023-01-23 mark wnoutrefresh(v->child->window);
2048 dc2c3344 2023-01-23 mark doupdate();
2051 9970f7fc 2020-12-03 stsp if (view->dying) {
2052 e78dc838 2020-12-04 stsp struct tog_view *v, *prev = NULL;
2054 9970f7fc 2020-12-03 stsp if (view_is_parent_view(view))
2055 9970f7fc 2020-12-03 stsp prev = TAILQ_PREV(view, tog_view_list_head,
2057 e78dc838 2020-12-04 stsp else if (view->parent)
2058 669b5ffa 2018-10-07 stsp prev = view->parent;
2060 e78dc838 2020-12-04 stsp if (view->parent) {
2061 9970f7fc 2020-12-03 stsp view->parent->child = NULL;
2062 e78dc838 2020-12-04 stsp view->parent->focus_child = 0;
2063 9b058f45 2022-06-30 mark /* Restore fullscreen line height. */
2064 9b058f45 2022-06-30 mark view->parent->nlines = view->parent->lines;
2065 0dbbbe90 2022-06-17 op err = view_resize(view->parent);
2068 3c1dfe12 2022-07-08 mark /* Make resized splits persist. */
2069 3c1dfe12 2022-07-08 mark view_transfer_size(view->parent, view);
2071 9970f7fc 2020-12-03 stsp TAILQ_REMOVE(&views, view, entry);
2073 9970f7fc 2020-12-03 stsp err = view_close(view);
2075 e5a0f69f 2018-08-18 stsp goto done;
2077 e78dc838 2020-12-04 stsp view = NULL;
2078 e78dc838 2020-12-04 stsp TAILQ_FOREACH(v, &views, entry) {
2079 e78dc838 2020-12-04 stsp if (v->focussed)
2082 e78dc838 2020-12-04 stsp if (view == NULL && new_view == NULL) {
2083 e78dc838 2020-12-04 stsp /* No view has focus. Try to pick one. */
2085 e78dc838 2020-12-04 stsp view = prev;
2086 e78dc838 2020-12-04 stsp else if (!TAILQ_EMPTY(&views)) {
2087 e78dc838 2020-12-04 stsp view = TAILQ_LAST(&views,
2088 e78dc838 2020-12-04 stsp tog_view_list_head);
2090 e78dc838 2020-12-04 stsp if (view) {
2091 e78dc838 2020-12-04 stsp if (view->focus_child) {
2092 e78dc838 2020-12-04 stsp view->child->focussed = 1;
2093 e78dc838 2020-12-04 stsp view = view->child;
2095 e78dc838 2020-12-04 stsp view->focussed = 1;
2099 bcbd79e2 2018-08-19 stsp if (new_view) {
2100 86c66b02 2018-10-18 stsp struct tog_view *v, *t;
2101 86c66b02 2018-10-18 stsp /* Only allow one parent view per type. */
2102 86c66b02 2018-10-18 stsp TAILQ_FOREACH_SAFE(v, &views, entry, t) {
2103 86c66b02 2018-10-18 stsp if (v->type != new_view->type)
2105 86c66b02 2018-10-18 stsp TAILQ_REMOVE(&views, v, entry);
2106 86c66b02 2018-10-18 stsp err = view_close(v);
2108 86c66b02 2018-10-18 stsp goto done;
2111 bcbd79e2 2018-08-19 stsp TAILQ_INSERT_TAIL(&views, new_view, entry);
2112 fed7eaa8 2018-10-24 stsp view = new_view;
2114 dc2c3344 2023-01-23 mark if (view && !done) {
2115 e78dc838 2020-12-04 stsp if (view_is_parent_view(view)) {
2116 e78dc838 2020-12-04 stsp if (view->child && view->child->focussed)
2117 e78dc838 2020-12-04 stsp view = view->child;
2119 e78dc838 2020-12-04 stsp if (view->parent && view->parent->focussed)
2120 e78dc838 2020-12-04 stsp view = view->parent;
2122 e78dc838 2020-12-04 stsp show_panel(view->panel);
2123 e78dc838 2020-12-04 stsp if (view->child && view_is_splitscreen(view->child))
2124 e78dc838 2020-12-04 stsp show_panel(view->child->panel);
2125 e78dc838 2020-12-04 stsp if (view->parent && view_is_splitscreen(view)) {
2126 669b5ffa 2018-10-07 stsp err = view->parent->show(view->parent);
2128 1a76625f 2018-10-22 stsp goto done;
2130 669b5ffa 2018-10-07 stsp err = view->show(view);
2132 1a76625f 2018-10-22 stsp goto done;
2133 669b5ffa 2018-10-07 stsp if (view->child) {
2134 669b5ffa 2018-10-07 stsp err = view->child->show(view->child);
2136 1a76625f 2018-10-22 stsp goto done;
2138 1a76625f 2018-10-22 stsp update_panels();
2139 1a76625f 2018-10-22 stsp doupdate();
2143 e5a0f69f 2018-08-18 stsp while (!TAILQ_EMPTY(&views)) {
2144 5629093a 2022-07-11 stsp const struct got_error *close_err;
2145 e5a0f69f 2018-08-18 stsp view = TAILQ_FIRST(&views);
2146 e5a0f69f 2018-08-18 stsp TAILQ_REMOVE(&views, view, entry);
2147 5629093a 2022-07-11 stsp close_err = view_close(view);
2148 5629093a 2022-07-11 stsp if (close_err && err == NULL)
2149 5629093a 2022-07-11 stsp err = close_err;
2152 1a76625f 2018-10-22 stsp errcode = pthread_mutex_unlock(&tog_mutex);
2153 963ecf2a 2019-08-12 stsp if (errcode && err == NULL)
2154 963ecf2a 2019-08-12 stsp err = got_error_set_errno(errcode, "pthread_mutex_unlock");
2156 e5a0f69f 2018-08-18 stsp return err;
2159 4ed7e80c 2018-05-20 stsp __dead static void
2160 9f7d7167 2018-04-29 stsp usage_log(void)
2163 c70c5802 2018-08-01 stsp fprintf(stderr,
2164 b672a97a 2020-01-27 stsp "usage: %s log [-b] [-c commit] [-r repository-path] [path]\n",
2165 9f7d7167 2018-04-29 stsp getprogname());
2169 963b370f 2018-05-20 stsp /* Create newly allocated wide-character string equivalent to a byte string. */
2170 80ddbec8 2018-04-29 stsp static const struct got_error *
2171 963b370f 2018-05-20 stsp mbs2ws(wchar_t **ws, size_t *wlen, const char *s)
2173 00dfcb92 2018-06-11 stsp char *vis = NULL;
2174 963b370f 2018-05-20 stsp const struct got_error *err = NULL;
2176 963b370f 2018-05-20 stsp *ws = NULL;
2177 963b370f 2018-05-20 stsp *wlen = mbstowcs(NULL, s, 0);
2178 00dfcb92 2018-06-11 stsp if (*wlen == (size_t)-1) {
2179 00dfcb92 2018-06-11 stsp int vislen;
2180 00dfcb92 2018-06-11 stsp if (errno != EILSEQ)
2181 638f9024 2019-05-13 stsp return got_error_from_errno("mbstowcs");
2183 00dfcb92 2018-06-11 stsp /* byte string invalid in current encoding; try to "fix" it */
2184 00dfcb92 2018-06-11 stsp err = got_mbsavis(&vis, &vislen, s);
2186 00dfcb92 2018-06-11 stsp return err;
2187 00dfcb92 2018-06-11 stsp *wlen = mbstowcs(NULL, vis, 0);
2188 a7f50699 2018-06-11 stsp if (*wlen == (size_t)-1) {
2189 638f9024 2019-05-13 stsp err = got_error_from_errno("mbstowcs"); /* give up */
2190 a7f50699 2018-06-11 stsp goto done;
2194 fd9f4a2d 2019-08-28 hiltjo *ws = calloc(*wlen + 1, sizeof(**ws));
2195 a7f50699 2018-06-11 stsp if (*ws == NULL) {
2196 638f9024 2019-05-13 stsp err = got_error_from_errno("calloc");
2197 a7f50699 2018-06-11 stsp goto done;
2200 00dfcb92 2018-06-11 stsp if (mbstowcs(*ws, vis ? vis : s, *wlen) != *wlen)
2201 638f9024 2019-05-13 stsp err = got_error_from_errno("mbstowcs");
2203 00dfcb92 2018-06-11 stsp free(vis);
2204 963b370f 2018-05-20 stsp if (err) {
2205 963b370f 2018-05-20 stsp free(*ws);
2206 963b370f 2018-05-20 stsp *ws = NULL;
2207 963b370f 2018-05-20 stsp *wlen = 0;
2209 963b370f 2018-05-20 stsp return err;
2212 145b6838 2022-06-16 stsp static const struct got_error *
2213 145b6838 2022-06-16 stsp expand_tab(char **ptr, const char *src)
2215 145b6838 2022-06-16 stsp char *dst;
2216 145b6838 2022-06-16 stsp size_t len, n, idx = 0, sz = 0;
2218 145b6838 2022-06-16 stsp *ptr = NULL;
2219 145b6838 2022-06-16 stsp n = len = strlen(src);
2220 6e1c41ad 2022-06-16 mark dst = malloc(n + 1);
2221 145b6838 2022-06-16 stsp if (dst == NULL)
2222 145b6838 2022-06-16 stsp return got_error_from_errno("malloc");
2224 145b6838 2022-06-16 stsp while (idx < len && src[idx]) {
2225 145b6838 2022-06-16 stsp const char c = src[idx];
2227 145b6838 2022-06-16 stsp if (c == '\t') {
2228 145b6838 2022-06-16 stsp size_t nb = TABSIZE - sz % TABSIZE;
2231 367ddf28 2022-06-16 mark p = realloc(dst, n + nb);
2232 6e1c41ad 2022-06-16 mark if (p == NULL) {
2233 6e1c41ad 2022-06-16 mark free(dst);
2234 6e1c41ad 2022-06-16 mark return got_error_from_errno("realloc");
2239 6e1c41ad 2022-06-16 mark memset(dst + sz, ' ', nb);
2242 145b6838 2022-06-16 stsp dst[sz++] = src[idx];
2246 145b6838 2022-06-16 stsp dst[sz] = '\0';
2247 145b6838 2022-06-16 stsp *ptr = dst;
2248 145b6838 2022-06-16 stsp return NULL;
2252 4e4a9ac8 2022-06-17 op * Advance at most n columns from wline starting at offset off.
2253 4e4a9ac8 2022-06-17 op * Return the index to the first character after the span operation.
2254 6046ddd5 2023-05-29 op * Return the combined column width of all spanned wide characters in
2258 4e4a9ac8 2022-06-17 op span_wline(int *rcol, int off, wchar_t *wline, int n, int col_tab_align)
2260 4e4a9ac8 2022-06-17 op int width, i, cols = 0;
2262 4e4a9ac8 2022-06-17 op if (n == 0) {
2263 4e4a9ac8 2022-06-17 op *rcol = cols;
2267 4e4a9ac8 2022-06-17 op for (i = off; wline[i] != L'\0'; ++i) {
2268 4e4a9ac8 2022-06-17 op if (wline[i] == L'\t')
2269 4e4a9ac8 2022-06-17 op width = TABSIZE - ((cols + col_tab_align) % TABSIZE);
2271 4e4a9ac8 2022-06-17 op width = wcwidth(wline[i]);
2273 4e4a9ac8 2022-06-17 op if (width == -1) {
2275 4e4a9ac8 2022-06-17 op wline[i] = L'.';
2278 4e4a9ac8 2022-06-17 op if (cols + width > n)
2280 4e4a9ac8 2022-06-17 op cols += width;
2283 4e4a9ac8 2022-06-17 op *rcol = cols;
2288 ccda2f4d 2022-06-16 stsp * Format a line for display, ensuring that it won't overflow a width limit.
2289 ccda2f4d 2022-06-16 stsp * With scrolling, the width returned refers to the scrolled version of the
2290 ccda2f4d 2022-06-16 stsp * line, which starts at (*wlinep)[*scrollxp]. The caller must free *wlinep.
2292 ccda2f4d 2022-06-16 stsp static const struct got_error *
2293 ccda2f4d 2022-06-16 stsp format_line(wchar_t **wlinep, int *widthp, int *scrollxp,
2294 ccda2f4d 2022-06-16 stsp const char *line, int nscroll, int wlimit, int col_tab_align, int expand)
2296 963b370f 2018-05-20 stsp const struct got_error *err = NULL;
2298 963b370f 2018-05-20 stsp wchar_t *wline = NULL;
2299 145b6838 2022-06-16 stsp char *exstr = NULL;
2300 963b370f 2018-05-20 stsp size_t wlen;
2301 4e4a9ac8 2022-06-17 op int i, scrollx;
2303 963b370f 2018-05-20 stsp *wlinep = NULL;
2304 b700b5d6 2018-07-10 stsp *widthp = 0;
2306 145b6838 2022-06-16 stsp if (expand) {
2307 145b6838 2022-06-16 stsp err = expand_tab(&exstr, line);
2309 145b6838 2022-06-16 stsp return err;
2312 145b6838 2022-06-16 stsp err = mbs2ws(&wline, &wlen, expand ? exstr : line);
2313 145b6838 2022-06-16 stsp free(exstr);
2315 963b370f 2018-05-20 stsp return err;
2317 4e4a9ac8 2022-06-17 op scrollx = span_wline(&cols, 0, wline, nscroll, col_tab_align);
2319 3f670bfb 2020-12-10 stsp if (wlen > 0 && wline[wlen - 1] == L'\n') {
2320 3f670bfb 2020-12-10 stsp wline[wlen - 1] = L'\0';
2323 3f670bfb 2020-12-10 stsp if (wlen > 0 && wline[wlen - 1] == L'\r') {
2324 3f670bfb 2020-12-10 stsp wline[wlen - 1] = L'\0';
2328 4e4a9ac8 2022-06-17 op i = span_wline(&cols, scrollx, wline, wlimit, col_tab_align);
2329 4e4a9ac8 2022-06-17 op wline[i] = L'\0';
2331 b700b5d6 2018-07-10 stsp if (widthp)
2332 b700b5d6 2018-07-10 stsp *widthp = cols;
2333 ccda2f4d 2022-06-16 stsp if (scrollxp)
2334 ccda2f4d 2022-06-16 stsp *scrollxp = scrollx;
2336 963b370f 2018-05-20 stsp free(wline);
2338 963b370f 2018-05-20 stsp *wlinep = wline;
2339 963b370f 2018-05-20 stsp return err;
2342 8b473291 2019-02-21 stsp static const struct got_error*
2343 8b473291 2019-02-21 stsp build_refs_str(char **refs_str, struct got_reflist_head *refs,
2344 52b5abe1 2019-08-13 stsp struct got_object_id *id, struct got_repository *repo)
2346 8b473291 2019-02-21 stsp static const struct got_error *err = NULL;
2347 8b473291 2019-02-21 stsp struct got_reflist_entry *re;
2349 8b473291 2019-02-21 stsp const char *name;
2351 8b473291 2019-02-21 stsp *refs_str = NULL;
2353 9cd447eb 2023-05-17 op if (refs == NULL)
2354 9cd447eb 2023-05-17 op return NULL;
2356 d9dff0e5 2020-12-26 stsp TAILQ_FOREACH(re, refs, entry) {
2357 52b5abe1 2019-08-13 stsp struct got_tag_object *tag = NULL;
2358 48cae60d 2020-09-22 stsp struct got_object_id *ref_id;
2361 8b473291 2019-02-21 stsp name = got_ref_get_name(re->ref);
2362 8b473291 2019-02-21 stsp if (strcmp(name, GOT_REF_HEAD) == 0)
2364 8b473291 2019-02-21 stsp if (strncmp(name, "refs/", 5) == 0)
2365 8b473291 2019-02-21 stsp name += 5;
2366 675a8e0a 2023-05-28 stsp if (strncmp(name, "got/", 4) == 0)
2368 8b473291 2019-02-21 stsp if (strncmp(name, "heads/", 6) == 0)
2369 8b473291 2019-02-21 stsp name += 6;
2370 79cc719f 2020-04-24 stsp if (strncmp(name, "remotes/", 8) == 0) {
2371 8b473291 2019-02-21 stsp name += 8;
2372 79cc719f 2020-04-24 stsp s = strstr(name, "/" GOT_REF_HEAD);
2373 563ffc1b 2023-06-14 op if (s != NULL && strcmp(s, "/" GOT_REF_HEAD) == 0)
2376 48cae60d 2020-09-22 stsp err = got_ref_resolve(&ref_id, repo, re->ref);
2379 52b5abe1 2019-08-13 stsp if (strncmp(name, "tags/", 5) == 0) {
2380 48cae60d 2020-09-22 stsp err = got_object_open_as_tag(&tag, repo, ref_id);
2381 5d844a1e 2019-08-13 stsp if (err) {
2382 48cae60d 2020-09-22 stsp if (err->code != GOT_ERR_OBJ_TYPE) {
2383 48cae60d 2020-09-22 stsp free(ref_id);
2386 5d844a1e 2019-08-13 stsp /* Ref points at something other than a tag. */
2387 5d844a1e 2019-08-13 stsp err = NULL;
2388 5d844a1e 2019-08-13 stsp tag = NULL;
2391 52b5abe1 2019-08-13 stsp cmp = got_object_id_cmp(tag ?
2392 48cae60d 2020-09-22 stsp got_object_tag_get_object_id(tag) : ref_id, id);
2393 48cae60d 2020-09-22 stsp free(ref_id);
2395 52b5abe1 2019-08-13 stsp got_object_tag_close(tag);
2396 52b5abe1 2019-08-13 stsp if (cmp != 0)
2398 8b473291 2019-02-21 stsp s = *refs_str;
2399 8b473291 2019-02-21 stsp if (asprintf(refs_str, "%s%s%s", s ? s : "",
2400 8b473291 2019-02-21 stsp s ? ", " : "", name) == -1) {
2401 638f9024 2019-05-13 stsp err = got_error_from_errno("asprintf");
2403 8b473291 2019-02-21 stsp *refs_str = NULL;
2409 8b473291 2019-02-21 stsp return err;
2412 963b370f 2018-05-20 stsp static const struct got_error *
2413 27a741e5 2019-09-11 stsp format_author(wchar_t **wauthor, int *author_width, char *author, int limit,
2414 27a741e5 2019-09-11 stsp int col_tab_align)
2416 e6b8b890 2020-12-29 naddy char *smallerthan;
2418 5813d178 2019-03-09 stsp smallerthan = strchr(author, '<');
2419 5813d178 2019-03-09 stsp if (smallerthan && smallerthan[1] != '\0')
2420 5813d178 2019-03-09 stsp author = smallerthan + 1;
2421 e6b8b890 2020-12-29 naddy author[strcspn(author, "@>")] = '\0';
2422 ccda2f4d 2022-06-16 stsp return format_line(wauthor, author_width, NULL, author, 0, limit,
2423 ccda2f4d 2022-06-16 stsp col_tab_align, 0);
2426 5813d178 2019-03-09 stsp static const struct got_error *
2427 c935fd51 2023-07-23 mark draw_commit(struct tog_view *view, struct commit_queue_entry *entry,
2428 c935fd51 2023-07-23 mark const size_t date_display_cols, int author_display_cols)
2430 8fdc79fe 2020-12-01 naddy struct tog_log_view_state *s = &view->state.log;
2431 80ddbec8 2018-04-29 stsp const struct got_error *err = NULL;
2432 c935fd51 2023-07-23 mark struct got_commit_object *commit = entry->commit;
2433 c935fd51 2023-07-23 mark struct got_object_id *id = entry->id;
2434 6db9f7f6 2019-12-10 stsp char datebuf[12]; /* YYYY-MM-DD + SPACE + NUL */
2435 0b570e72 2023-05-16 op char *refs_str = NULL;
2436 80ddbec8 2018-04-29 stsp char *logmsg0 = NULL, *logmsg = NULL;
2437 5813d178 2019-03-09 stsp char *author = NULL;
2438 cc3ce059 2023-05-29 stsp wchar_t *wrefstr = NULL, *wlogmsg = NULL, *wauthor = NULL;
2439 cc3ce059 2023-05-29 stsp int author_width, refstr_width, logmsg_width;
2440 5813d178 2019-03-09 stsp char *newline, *line = NULL;
2441 cc3ce059 2023-05-29 stsp int col, limit, scrollx, logmsg_x;
2442 c935fd51 2023-07-23 mark const int avail = view->ncols, marker_column = author_display_cols + 1;
2443 ccb26ccd 2018-11-05 stsp struct tm tm;
2444 45d799e2 2018-12-23 stsp time_t committer_time;
2445 11b20872 2019-11-08 stsp struct tog_color *tc;
2446 689555c9 2023-05-15 stsp struct got_reflist_head *refs;
2448 99301cec 2023-07-24 stsp if (tog_base_commit.id != NULL && tog_base_commit.idx == -1 &&
2449 99301cec 2023-07-24 stsp got_object_id_cmp(id, tog_base_commit.id) == 0)
2450 99301cec 2023-07-24 stsp tog_base_commit.idx = entry->idx;
2451 7c67cf56 2023-07-25 stsp if (tog_io.wait_for_ui && s->thread_args.need_commit_marker) {
2454 7c67cf56 2023-07-25 stsp rc = pthread_cond_wait(&s->thread_args.log_loaded, &tog_mutex);
2456 7c67cf56 2023-07-25 stsp return got_error_set_errno(rc, "pthread_cond_wait");
2459 45d799e2 2018-12-23 stsp committer_time = got_object_commit_get_committer_time(commit);
2460 e385fc42 2021-08-30 stsp if (gmtime_r(&committer_time, &tm) == NULL)
2461 e385fc42 2021-08-30 stsp return got_error_from_errno("gmtime_r");
2462 283939fb 2024-04-23 op if (strftime(datebuf, sizeof(datebuf), "%F ", &tm) == 0)
2463 b39d25c7 2018-07-10 stsp return got_error(GOT_ERR_NO_SPACE);
2465 27a741e5 2019-09-11 stsp if (avail <= date_display_cols)
2466 b39d25c7 2018-07-10 stsp limit = MIN(sizeof(datebuf) - 1, avail);
2468 b39d25c7 2018-07-10 stsp limit = MIN(date_display_cols, sizeof(datebuf) - 1);
2469 8fdc79fe 2020-12-01 naddy tc = get_color(&s->colors, TOG_COLOR_DATE);
2471 11b20872 2019-11-08 stsp wattr_on(view->window,
2472 11b20872 2019-11-08 stsp COLOR_PAIR(tc->colorpair), NULL);
2473 2814baeb 2018-08-01 stsp waddnstr(view->window, datebuf, limit);
2475 11b20872 2019-11-08 stsp wattr_off(view->window,
2476 11b20872 2019-11-08 stsp COLOR_PAIR(tc->colorpair), NULL);
2477 27a741e5 2019-09-11 stsp col = limit;
2478 b39d25c7 2018-07-10 stsp if (col > avail)
2479 b39d25c7 2018-07-10 stsp goto done;
2481 6570a66d 2019-11-08 stsp if (avail >= 120) {
2482 6570a66d 2019-11-08 stsp char *id_str;
2483 6570a66d 2019-11-08 stsp err = got_object_id_str(&id_str, id);
2485 6570a66d 2019-11-08 stsp goto done;
2486 8fdc79fe 2020-12-01 naddy tc = get_color(&s->colors, TOG_COLOR_COMMIT);
2488 11b20872 2019-11-08 stsp wattr_on(view->window,
2489 11b20872 2019-11-08 stsp COLOR_PAIR(tc->colorpair), NULL);
2490 6570a66d 2019-11-08 stsp wprintw(view->window, "%.8s ", id_str);
2492 11b20872 2019-11-08 stsp wattr_off(view->window,
2493 11b20872 2019-11-08 stsp COLOR_PAIR(tc->colorpair), NULL);
2494 6570a66d 2019-11-08 stsp free(id_str);
2496 6570a66d 2019-11-08 stsp if (col > avail)
2497 6570a66d 2019-11-08 stsp goto done;
2500 10aab77f 2022-07-19 op if (s->use_committer)
2501 10aab77f 2022-07-19 op author = strdup(got_object_commit_get_committer(commit));
2503 10aab77f 2022-07-19 op author = strdup(got_object_commit_get_author(commit));
2504 5813d178 2019-03-09 stsp if (author == NULL) {
2505 638f9024 2019-05-13 stsp err = got_error_from_errno("strdup");
2506 80ddbec8 2018-04-29 stsp goto done;
2508 27a741e5 2019-09-11 stsp err = format_author(&wauthor, &author_width, author, avail - col, col);
2510 bb737323 2018-05-20 stsp goto done;
2511 8fdc79fe 2020-12-01 naddy tc = get_color(&s->colors, TOG_COLOR_AUTHOR);
2513 11b20872 2019-11-08 stsp wattr_on(view->window,
2514 11b20872 2019-11-08 stsp COLOR_PAIR(tc->colorpair), NULL);
2515 2814baeb 2018-08-01 stsp waddwstr(view->window, wauthor);
2516 bb737323 2018-05-20 stsp col += author_width;
2517 27a741e5 2019-09-11 stsp while (col < avail && author_width < author_display_cols + 2) {
2518 99301cec 2023-07-24 stsp if (tog_base_commit.marker != GOT_WORKTREE_STATE_UNKNOWN &&
2519 c935fd51 2023-07-23 mark author_width == marker_column &&
2520 e31c89e9 2023-08-22 mark entry->idx == tog_base_commit.idx && !s->limit_view) {
2521 9e0b5624 2023-07-23 mark tc = get_color(&s->colors, TOG_COLOR_COMMIT);
2523 9e0b5624 2023-07-23 mark wattr_on(view->window,
2524 9e0b5624 2023-07-23 mark COLOR_PAIR(tc->colorpair), NULL);
2525 c935fd51 2023-07-23 mark waddch(view->window, tog_base_commit.marker);
2527 9e0b5624 2023-07-23 mark wattr_off(view->window,
2528 9e0b5624 2023-07-23 mark COLOR_PAIR(tc->colorpair), NULL);
2530 c935fd51 2023-07-23 mark waddch(view->window, ' ');
2532 bb737323 2018-05-20 stsp author_width++;
2535 f0f62654 2022-09-08 mark wattr_off(view->window,
2536 f0f62654 2022-09-08 mark COLOR_PAIR(tc->colorpair), NULL);
2537 9c2eaf34 2018-05-20 stsp if (col > avail)
2538 9c2eaf34 2018-05-20 stsp goto done;
2540 5943eee2 2019-08-13 stsp err = got_object_commit_get_logmsg(&logmsg0, commit);
2542 6d9fbc00 2018-04-29 stsp goto done;
2543 bb737323 2018-05-20 stsp logmsg = logmsg0;
2544 bb737323 2018-05-20 stsp while (*logmsg == '\n')
2546 bb737323 2018-05-20 stsp newline = strchr(logmsg, '\n');
2547 bb737323 2018-05-20 stsp if (newline)
2548 bb737323 2018-05-20 stsp *newline = '\0';
2550 cc3ce059 2023-05-29 stsp limit = avail - col;
2551 cc3ce059 2023-05-29 stsp if (view->child && !view_is_hsplit_top(view) && limit > 0)
2552 cc3ce059 2023-05-29 stsp limit--; /* for the border */
2554 689555c9 2023-05-15 stsp /* Prepend reference labels to log message if possible .*/
2555 689555c9 2023-05-15 stsp refs = got_reflist_object_id_map_lookup(tog_refs_idmap, id);
2556 9cd447eb 2023-05-17 op err = build_refs_str(&refs_str, refs, id, s->repo);
2559 0b570e72 2023-05-16 op if (refs_str) {
2562 cc3ce059 2023-05-29 stsp if (asprintf(&rs, "[%s]", refs_str) == -1) {
2563 689555c9 2023-05-15 stsp err = got_error_from_errno("asprintf");
2564 689555c9 2023-05-15 stsp goto done;
2566 cc3ce059 2023-05-29 stsp err = format_line(&wrefstr, &refstr_width,
2567 cc3ce059 2023-05-29 stsp &scrollx, rs, view->x, limit, col, 1);
2570 cc3ce059 2023-05-29 stsp goto done;
2571 689555c9 2023-05-15 stsp tc = get_color(&s->colors, TOG_COLOR_COMMIT);
2573 689555c9 2023-05-15 stsp wattr_on(view->window,
2574 689555c9 2023-05-15 stsp COLOR_PAIR(tc->colorpair), NULL);
2575 cc3ce059 2023-05-29 stsp waddwstr(view->window, &wrefstr[scrollx]);
2577 689555c9 2023-05-15 stsp wattr_off(view->window,
2578 689555c9 2023-05-15 stsp COLOR_PAIR(tc->colorpair), NULL);
2579 cc3ce059 2023-05-29 stsp col += MAX(refstr_width, 0);
2580 cc3ce059 2023-05-29 stsp if (col > avail)
2581 cc3ce059 2023-05-29 stsp goto done;
2583 cc3ce059 2023-05-29 stsp if (col < avail) {
2584 cc3ce059 2023-05-29 stsp waddch(view->window, ' ');
2588 cc3ce059 2023-05-29 stsp if (refstr_width > 0)
2589 cc3ce059 2023-05-29 stsp logmsg_x = 0;
2591 cc3ce059 2023-05-29 stsp int unscrolled_refstr_width;
2592 cc3ce059 2023-05-29 stsp size_t len = wcslen(wrefstr);
2595 cc3ce059 2023-05-29 stsp * No need to check for -1 return value here since
2596 cc3ce059 2023-05-29 stsp * unprintables have been replaced by span_wline().
2598 cc3ce059 2023-05-29 stsp unscrolled_refstr_width = wcswidth(wrefstr, len);
2599 cc3ce059 2023-05-29 stsp unscrolled_refstr_width += 1; /* trailing space */
2600 cc3ce059 2023-05-29 stsp logmsg_x = view->x - unscrolled_refstr_width;
2603 cc3ce059 2023-05-29 stsp limit = avail - col;
2604 cc3ce059 2023-05-29 stsp if (view->child && !view_is_hsplit_top(view) && limit > 0)
2605 cc3ce059 2023-05-29 stsp limit--; /* for the border */
2607 cc3ce059 2023-05-29 stsp logmsg_x = view->x;
2609 cc3ce059 2023-05-29 stsp err = format_line(&wlogmsg, &logmsg_width, &scrollx, logmsg, logmsg_x,
2610 cc3ce059 2023-05-29 stsp limit, col, 1);
2612 cc3ce059 2023-05-29 stsp goto done;
2613 cc3ce059 2023-05-29 stsp waddwstr(view->window, &wlogmsg[scrollx]);
2614 29688b02 2022-06-16 stsp col += MAX(logmsg_width, 0);
2615 27a741e5 2019-09-11 stsp while (col < avail) {
2616 2814baeb 2018-08-01 stsp waddch(view->window, ' ');
2620 80ddbec8 2018-04-29 stsp free(logmsg0);
2621 bb737323 2018-05-20 stsp free(wlogmsg);
2622 cc3ce059 2023-05-29 stsp free(wrefstr);
2623 0b570e72 2023-05-16 op free(refs_str);
2624 5813d178 2019-03-09 stsp free(author);
2625 bb737323 2018-05-20 stsp free(wauthor);
2626 80ddbec8 2018-04-29 stsp free(line);
2627 80ddbec8 2018-04-29 stsp return err;
2630 899d86c2 2018-05-10 stsp static struct commit_queue_entry *
2631 899d86c2 2018-05-10 stsp alloc_commit_queue_entry(struct got_commit_object *commit,
2632 899d86c2 2018-05-10 stsp struct got_object_id *id)
2634 80ddbec8 2018-04-29 stsp struct commit_queue_entry *entry;
2635 e15c42de 2022-09-05 op struct got_object_id *dup;
2637 80ddbec8 2018-04-29 stsp entry = calloc(1, sizeof(*entry));
2638 80ddbec8 2018-04-29 stsp if (entry == NULL)
2639 899d86c2 2018-05-10 stsp return NULL;
2641 e15c42de 2022-09-05 op dup = got_object_id_dup(id);
2642 e15c42de 2022-09-05 op if (dup == NULL) {
2643 e15c42de 2022-09-05 op free(entry);
2644 e15c42de 2022-09-05 op return NULL;
2647 e15c42de 2022-09-05 op entry->id = dup;
2648 99db9666 2018-05-07 stsp entry->commit = commit;
2649 899d86c2 2018-05-10 stsp return entry;
2652 99db9666 2018-05-07 stsp static void
2653 99db9666 2018-05-07 stsp pop_commit(struct commit_queue *commits)
2655 99db9666 2018-05-07 stsp struct commit_queue_entry *entry;
2657 ecb28ae0 2018-07-16 stsp entry = TAILQ_FIRST(&commits->head);
2658 ecb28ae0 2018-07-16 stsp TAILQ_REMOVE(&commits->head, entry, entry);
2659 99db9666 2018-05-07 stsp got_object_commit_close(entry->commit);
2660 ecb28ae0 2018-07-16 stsp commits->ncommits--;
2661 e15c42de 2022-09-05 op free(entry->id);
2662 99db9666 2018-05-07 stsp free(entry);
2665 99db9666 2018-05-07 stsp static void
2666 99db9666 2018-05-07 stsp free_commits(struct commit_queue *commits)
2668 ecb28ae0 2018-07-16 stsp while (!TAILQ_EMPTY(&commits->head))
2669 99db9666 2018-05-07 stsp pop_commit(commits);
2672 c4972b91 2018-05-07 stsp static const struct got_error *
2673 13add988 2019-10-15 stsp match_commit(int *have_match, struct got_object_id *id,
2674 13add988 2019-10-15 stsp struct got_commit_object *commit, regex_t *regex)
2676 13add988 2019-10-15 stsp const struct got_error *err = NULL;
2677 13add988 2019-10-15 stsp regmatch_t regmatch;
2678 13add988 2019-10-15 stsp char *id_str = NULL, *logmsg = NULL;
2680 13add988 2019-10-15 stsp *have_match = 0;
2682 13add988 2019-10-15 stsp err = got_object_id_str(&id_str, id);
2684 13add988 2019-10-15 stsp return err;
2686 13add988 2019-10-15 stsp err = got_object_commit_get_logmsg(&logmsg, commit);
2688 13add988 2019-10-15 stsp goto done;
2690 13add988 2019-10-15 stsp if (regexec(regex, got_object_commit_get_author(commit), 1,
2691 13add988 2019-10-15 stsp ®match, 0) == 0 ||
2692 13add988 2019-10-15 stsp regexec(regex, got_object_commit_get_committer(commit), 1,
2693 13add988 2019-10-15 stsp ®match, 0) == 0 ||
2694 13add988 2019-10-15 stsp regexec(regex, id_str, 1, ®match, 0) == 0 ||
2695 13add988 2019-10-15 stsp regexec(regex, logmsg, 1, ®match, 0) == 0)
2696 13add988 2019-10-15 stsp *have_match = 1;
2698 13add988 2019-10-15 stsp free(id_str);
2699 13add988 2019-10-15 stsp free(logmsg);
2700 13add988 2019-10-15 stsp return err;
2703 13add988 2019-10-15 stsp static const struct got_error *
2704 4e0d2870 2020-12-07 naddy queue_commits(struct tog_log_thread_args *a)
2706 899d86c2 2018-05-10 stsp const struct got_error *err = NULL;
2709 1a76625f 2018-10-22 stsp * We keep all commits open throughout the lifetime of the log
2710 1a76625f 2018-10-22 stsp * view in order to avoid having to re-fetch commits from disk
2711 1a76625f 2018-10-22 stsp * while updating the display.
2714 d9787ed8 2022-09-10 op struct got_object_id id;
2715 9ba79e04 2018-06-11 stsp struct got_commit_object *commit;
2716 93e45b7c 2018-09-24 stsp struct commit_queue_entry *entry;
2717 568eae95 2022-09-11 mark int limit_match = 0;
2718 1a76625f 2018-10-22 stsp int errcode;
2720 4e0d2870 2020-12-07 naddy err = got_commit_graph_iter_next(&id, a->graph, a->repo,
2721 4e0d2870 2020-12-07 naddy NULL, NULL);
2725 d9787ed8 2022-09-10 op err = got_object_open_as_commit(&commit, a->repo, &id);
2728 d9787ed8 2022-09-10 op entry = alloc_commit_queue_entry(commit, &id);
2729 9ba79e04 2018-06-11 stsp if (entry == NULL) {
2730 638f9024 2019-05-13 stsp err = got_error_from_errno("alloc_commit_queue_entry");
2734 1a76625f 2018-10-22 stsp errcode = pthread_mutex_lock(&tog_mutex);
2735 1a76625f 2018-10-22 stsp if (errcode) {
2736 13add988 2019-10-15 stsp err = got_error_set_errno(errcode,
2737 13add988 2019-10-15 stsp "pthread_mutex_lock");
2741 568eae95 2022-09-11 mark entry->idx = a->real_commits->ncommits;
2742 568eae95 2022-09-11 mark TAILQ_INSERT_TAIL(&a->real_commits->head, entry, entry);
2743 568eae95 2022-09-11 mark a->real_commits->ncommits++;
2745 568eae95 2022-09-11 mark if (*a->limiting) {
2746 568eae95 2022-09-11 mark err = match_commit(&limit_match, &id, commit,
2747 568eae95 2022-09-11 mark a->limit_regex);
2751 568eae95 2022-09-11 mark if (limit_match) {
2752 568eae95 2022-09-11 mark struct commit_queue_entry *matched;
2754 568eae95 2022-09-11 mark matched = alloc_commit_queue_entry(
2755 568eae95 2022-09-11 mark entry->commit, entry->id);
2756 568eae95 2022-09-11 mark if (matched == NULL) {
2757 568eae95 2022-09-11 mark err = got_error_from_errno(
2758 568eae95 2022-09-11 mark "alloc_commit_queue_entry");
2761 34a842a4 2022-09-18 mark matched->commit = entry->commit;
2762 34a842a4 2022-09-18 mark got_object_commit_retain(entry->commit);
2764 568eae95 2022-09-11 mark matched->idx = a->limit_commits->ncommits;
2765 568eae95 2022-09-11 mark TAILQ_INSERT_TAIL(&a->limit_commits->head,
2766 568eae95 2022-09-11 mark matched, entry);
2767 568eae95 2022-09-11 mark a->limit_commits->ncommits++;
2771 568eae95 2022-09-11 mark * This is how we signal log_thread() that we
2772 568eae95 2022-09-11 mark * have found a match, and that it should be
2773 568eae95 2022-09-11 mark * counted as a new entry for the view.
2775 568eae95 2022-09-11 mark a->limit_match = limit_match;
2778 4e0d2870 2020-12-07 naddy if (*a->searching == TOG_SEARCH_FORWARD &&
2779 4e0d2870 2020-12-07 naddy !*a->search_next_done) {
2780 7c1452c1 2020-03-26 stsp int have_match;
2781 d9787ed8 2022-09-10 op err = match_commit(&have_match, &id, commit, a->regex);
2785 568eae95 2022-09-11 mark if (*a->limiting) {
2786 568eae95 2022-09-11 mark if (limit_match && have_match)
2787 568eae95 2022-09-11 mark *a->search_next_done =
2788 568eae95 2022-09-11 mark TOG_SEARCH_HAVE_MORE;
2789 568eae95 2022-09-11 mark } else if (have_match)
2790 4e0d2870 2020-12-07 naddy *a->search_next_done = TOG_SEARCH_HAVE_MORE;
2793 1a76625f 2018-10-22 stsp errcode = pthread_mutex_unlock(&tog_mutex);
2794 1a76625f 2018-10-22 stsp if (errcode && err == NULL)
2795 2af4a041 2019-05-11 jcs err = got_error_set_errno(errcode,
2796 2af4a041 2019-05-11 jcs "pthread_mutex_unlock");
2799 4e0d2870 2020-12-07 naddy } while (*a->searching == TOG_SEARCH_FORWARD && !*a->search_next_done);
2801 9ba79e04 2018-06-11 stsp return err;
2804 2b779855 2020-12-05 naddy static void
2805 2b779855 2020-12-05 naddy select_commit(struct tog_log_view_state *s)
2807 2b779855 2020-12-05 naddy struct commit_queue_entry *entry;
2808 2b779855 2020-12-05 naddy int ncommits = 0;
2810 2b779855 2020-12-05 naddy entry = s->first_displayed_entry;
2811 2b779855 2020-12-05 naddy while (entry) {
2812 2b779855 2020-12-05 naddy if (ncommits == s->selected) {
2813 2b779855 2020-12-05 naddy s->selected_entry = entry;
2816 2b779855 2020-12-05 naddy entry = TAILQ_NEXT(entry, entry);
2817 2b779855 2020-12-05 naddy ncommits++;
2821 0553a4e3 2018-04-30 stsp static const struct got_error *
2822 8fdc79fe 2020-12-01 naddy draw_commits(struct tog_view *view)
2824 0553a4e3 2018-04-30 stsp const struct got_error *err = NULL;
2825 52b5abe1 2019-08-13 stsp struct tog_log_view_state *s = &view->state.log;
2826 2b779855 2020-12-05 naddy struct commit_queue_entry *entry = s->selected_entry;
2827 cbb0c8d7 2022-08-12 mark int limit = view->nlines;
2828 60493ae3 2019-06-20 stsp int width;
2829 cc3ce059 2023-05-29 stsp int ncommits, author_cols = 4, refstr_cols;
2830 1a76625f 2018-10-22 stsp char *id_str = NULL, *header = NULL, *ncommits_str = NULL;
2831 8b473291 2019-02-21 stsp char *refs_str = NULL;
2832 ecb28ae0 2018-07-16 stsp wchar_t *wline;
2833 11b20872 2019-11-08 stsp struct tog_color *tc;
2834 6db9f7f6 2019-12-10 stsp static const size_t date_display_cols = 12;
2835 cc3ce059 2023-05-29 stsp struct got_reflist_head *refs;
2837 cbb0c8d7 2022-08-12 mark if (view_is_hsplit_top(view))
2838 cbb0c8d7 2022-08-12 mark --limit; /* account for border */
2840 8fdc79fe 2020-12-01 naddy if (s->selected_entry &&
2841 8fdc79fe 2020-12-01 naddy !(view->searching && view->search_next_done == 0)) {
2842 8fdc79fe 2020-12-01 naddy err = got_object_id_str(&id_str, s->selected_entry->id);
2844 ecb28ae0 2018-07-16 stsp return err;
2845 51a10b52 2020-12-26 stsp refs = got_reflist_object_id_map_lookup(tog_refs_idmap,
2846 d2075bf3 2020-12-25 stsp s->selected_entry->id);
2847 9cd447eb 2023-05-17 op err = build_refs_str(&refs_str, refs, s->selected_entry->id,
2853 098596c5 2023-04-14 stsp if (s->thread_args.commits_needed == 0 && !using_mock_io)
2854 359bfafd 2019-02-22 stsp halfdelay(10); /* disable fast refresh */
2856 fb280deb 2021-08-30 stsp if (s->thread_args.commits_needed > 0 || s->thread_args.load_all) {
2857 8f4ed634 2020-03-26 stsp if (asprintf(&ncommits_str, " [%d/%d] %s",
2858 568eae95 2022-09-11 mark entry ? entry->idx + 1 : 0, s->commits->ncommits,
2859 38d166d8 2022-09-23 stsp (view->searching && !view->search_next_done) ?
2860 38d166d8 2022-09-23 stsp "searching..." : "loading...") == -1) {
2861 8f4ed634 2020-03-26 stsp err = got_error_from_errno("asprintf");
2862 8f4ed634 2020-03-26 stsp goto done;
2865 f9686aa5 2020-03-27 stsp const char *search_str = NULL;
2866 568eae95 2022-09-11 mark const char *limit_str = NULL;
2868 f9686aa5 2020-03-27 stsp if (view->searching) {
2869 f9686aa5 2020-03-27 stsp if (view->search_next_done == TOG_SEARCH_NO_MORE)
2870 f9686aa5 2020-03-27 stsp search_str = "no more matches";
2871 f9686aa5 2020-03-27 stsp else if (view->search_next_done == TOG_SEARCH_HAVE_NONE)
2872 f9686aa5 2020-03-27 stsp search_str = "no matches found";
2873 f9686aa5 2020-03-27 stsp else if (!view->search_next_done)
2874 f9686aa5 2020-03-27 stsp search_str = "searching...";
2877 568eae95 2022-09-11 mark if (s->limit_view && s->commits->ncommits == 0)
2878 568eae95 2022-09-11 mark limit_str = "no matches found";
2880 568eae95 2022-09-11 mark if (asprintf(&ncommits_str, " [%d/%d] %s %s",
2881 568eae95 2022-09-11 mark entry ? entry->idx + 1 : 0, s->commits->ncommits,
2882 568eae95 2022-09-11 mark search_str ? search_str : (refs_str ? refs_str : ""),
2883 568eae95 2022-09-11 mark limit_str ? limit_str : "") == -1) {
2884 8f4ed634 2020-03-26 stsp err = got_error_from_errno("asprintf");
2885 8f4ed634 2020-03-26 stsp goto done;
2889 6c685612 2023-05-29 stsp free(refs_str);
2890 6c685612 2023-05-29 stsp refs_str = NULL;
2892 8fdc79fe 2020-12-01 naddy if (s->in_repo_path && strcmp(s->in_repo_path, "/") != 0) {
2893 87411fa9 2022-06-16 stsp if (asprintf(&header, "commit %s %s%s", id_str ? id_str :
2894 87411fa9 2022-06-16 stsp "........................................",
2895 8fdc79fe 2020-12-01 naddy s->in_repo_path, ncommits_str) == -1) {
2896 638f9024 2019-05-13 stsp err = got_error_from_errno("asprintf");
2897 1a76625f 2018-10-22 stsp header = NULL;
2898 1a76625f 2018-10-22 stsp goto done;
2900 c1124f18 2018-12-23 stsp } else if (asprintf(&header, "commit %s%s",
2901 1a76625f 2018-10-22 stsp id_str ? id_str : "........................................",
2902 1a76625f 2018-10-22 stsp ncommits_str) == -1) {
2903 638f9024 2019-05-13 stsp err = got_error_from_errno("asprintf");
2904 1a76625f 2018-10-22 stsp header = NULL;
2905 1a76625f 2018-10-22 stsp goto done;
2907 ccda2f4d 2022-06-16 stsp err = format_line(&wline, &width, NULL, header, 0, view->ncols, 0, 0);
2909 1a76625f 2018-10-22 stsp goto done;
2911 2814baeb 2018-08-01 stsp werase(view->window);
2913 a3404814 2018-09-02 stsp if (view_needs_focus_indication(view))
2914 a3404814 2018-09-02 stsp wstandout(view->window);
2915 8fdc79fe 2020-12-01 naddy tc = get_color(&s->colors, TOG_COLOR_COMMIT);
2917 0c6ad1bc 2022-09-09 mark wattr_on(view->window, COLOR_PAIR(tc->colorpair), NULL);
2918 2814baeb 2018-08-01 stsp waddwstr(view->window, wline);
2919 1a76625f 2018-10-22 stsp while (width < view->ncols) {
2920 1a76625f 2018-10-22 stsp waddch(view->window, ' ');
2924 0c6ad1bc 2022-09-09 mark wattr_off(view->window, COLOR_PAIR(tc->colorpair), NULL);
2925 a3404814 2018-09-02 stsp if (view_needs_focus_indication(view))
2926 a3404814 2018-09-02 stsp wstandend(view->window);
2927 ecb28ae0 2018-07-16 stsp free(wline);
2928 ecb28ae0 2018-07-16 stsp if (limit <= 1)
2929 1a76625f 2018-10-22 stsp goto done;
2931 29688b02 2022-06-16 stsp /* Grow author column size if necessary, and set view->maxx. */
2932 8fdc79fe 2020-12-01 naddy entry = s->first_displayed_entry;
2933 5813d178 2019-03-09 stsp ncommits = 0;
2934 145b6838 2022-06-16 stsp view->maxx = 0;
2935 5813d178 2019-03-09 stsp while (entry) {
2936 10aab77f 2022-07-19 op struct got_commit_object *c = entry->commit;
2937 145b6838 2022-06-16 stsp char *author, *eol, *msg, *msg0;
2938 29688b02 2022-06-16 stsp wchar_t *wauthor, *wmsg;
2939 5813d178 2019-03-09 stsp int width;
2940 5813d178 2019-03-09 stsp if (ncommits >= limit - 1)
2942 10aab77f 2022-07-19 op if (s->use_committer)
2943 10aab77f 2022-07-19 op author = strdup(got_object_commit_get_committer(c));
2945 10aab77f 2022-07-19 op author = strdup(got_object_commit_get_author(c));
2946 5813d178 2019-03-09 stsp if (author == NULL) {
2947 638f9024 2019-05-13 stsp err = got_error_from_errno("strdup");
2948 5813d178 2019-03-09 stsp goto done;
2950 27a741e5 2019-09-11 stsp err = format_author(&wauthor, &width, author, COLS,
2951 27a741e5 2019-09-11 stsp date_display_cols);
2952 5813d178 2019-03-09 stsp if (author_cols < width)
2953 5813d178 2019-03-09 stsp author_cols = width;
2954 5813d178 2019-03-09 stsp free(wauthor);
2955 5813d178 2019-03-09 stsp free(author);
2956 a310d9c3 2022-07-21 florian if (err)
2957 a310d9c3 2022-07-21 florian goto done;
2958 cc3ce059 2023-05-29 stsp refs = got_reflist_object_id_map_lookup(tog_refs_idmap,
2959 cc3ce059 2023-05-29 stsp entry->id);
2960 cc3ce059 2023-05-29 stsp err = build_refs_str(&refs_str, refs, entry->id, s->repo);
2962 cc3ce059 2023-05-29 stsp goto done;
2963 cc3ce059 2023-05-29 stsp if (refs_str) {
2964 cc3ce059 2023-05-29 stsp wchar_t *ws;
2965 cc3ce059 2023-05-29 stsp err = format_line(&ws, &width, NULL, refs_str,
2966 cc3ce059 2023-05-29 stsp 0, INT_MAX, date_display_cols + author_cols, 0);
2968 6c685612 2023-05-29 stsp free(refs_str);
2969 6c685612 2023-05-29 stsp refs_str = NULL;
2971 cc3ce059 2023-05-29 stsp goto done;
2972 cc3ce059 2023-05-29 stsp refstr_cols = width + 3; /* account for [ ] + space */
2974 cc3ce059 2023-05-29 stsp refstr_cols = 0;
2975 10aab77f 2022-07-19 op err = got_object_commit_get_logmsg(&msg0, c);
2977 145b6838 2022-06-16 stsp goto done;
2978 145b6838 2022-06-16 stsp msg = msg0;
2979 145b6838 2022-06-16 stsp while (*msg == '\n')
2981 145b6838 2022-06-16 stsp if ((eol = strchr(msg, '\n')))
2982 29688b02 2022-06-16 stsp *eol = '\0';
2983 ccda2f4d 2022-06-16 stsp err = format_line(&wmsg, &width, NULL, msg, 0, INT_MAX,
2984 cc3ce059 2023-05-29 stsp date_display_cols + author_cols + refstr_cols, 0);
2986 29688b02 2022-06-16 stsp goto done;
2987 cc3ce059 2023-05-29 stsp view->maxx = MAX(view->maxx, width + refstr_cols);
2988 145b6838 2022-06-16 stsp free(msg0);
2989 29688b02 2022-06-16 stsp free(wmsg);
2990 7ca04879 2019-10-19 stsp ncommits++;
2991 5813d178 2019-03-09 stsp entry = TAILQ_NEXT(entry, entry);
2994 8fdc79fe 2020-12-01 naddy entry = s->first_displayed_entry;
2995 8fdc79fe 2020-12-01 naddy s->last_displayed_entry = s->first_displayed_entry;
2996 867c6645 2018-07-10 stsp ncommits = 0;
2997 899d86c2 2018-05-10 stsp while (entry) {
2998 ecb28ae0 2018-07-16 stsp if (ncommits >= limit - 1)
3000 8fdc79fe 2020-12-01 naddy if (ncommits == s->selected)
3001 2814baeb 2018-08-01 stsp wstandout(view->window);
3002 c935fd51 2023-07-23 mark err = draw_commit(view, entry, date_display_cols, author_cols);
3003 8fdc79fe 2020-12-01 naddy if (ncommits == s->selected)
3004 2814baeb 2018-08-01 stsp wstandend(view->window);
3006 60493ae3 2019-06-20 stsp goto done;
3007 0553a4e3 2018-04-30 stsp ncommits++;
3008 8fdc79fe 2020-12-01 naddy s->last_displayed_entry = entry;
3009 899d86c2 2018-05-10 stsp entry = TAILQ_NEXT(entry, entry);
3012 9b058f45 2022-06-30 mark view_border(view);
3014 1a76625f 2018-10-22 stsp free(id_str);
3015 8b473291 2019-02-21 stsp free(refs_str);
3016 1a76625f 2018-10-22 stsp free(ncommits_str);
3017 1a76625f 2018-10-22 stsp free(header);
3018 80ddbec8 2018-04-29 stsp return err;
3021 07b55e75 2018-05-10 stsp static void
3022 3e135950 2020-12-01 naddy log_scroll_up(struct tog_log_view_state *s, int maxscroll)
3024 07b55e75 2018-05-10 stsp struct commit_queue_entry *entry;
3025 07b55e75 2018-05-10 stsp int nscrolled = 0;
3027 568eae95 2022-09-11 mark entry = TAILQ_FIRST(&s->commits->head);
3028 ffe38506 2020-12-01 naddy if (s->first_displayed_entry == entry)
3031 ffe38506 2020-12-01 naddy entry = s->first_displayed_entry;
3032 16482c3b 2018-05-20 stsp while (entry && nscrolled < maxscroll) {
3033 ecb28ae0 2018-07-16 stsp entry = TAILQ_PREV(entry, commit_queue_head, entry);
3034 07b55e75 2018-05-10 stsp if (entry) {
3035 ffe38506 2020-12-01 naddy s->first_displayed_entry = entry;
3036 07b55e75 2018-05-10 stsp nscrolled++;
3041 aa075928 2018-05-10 stsp static const struct got_error *
3042 ffe38506 2020-12-01 naddy trigger_log_thread(struct tog_view *view, int wait)
3044 ffe38506 2020-12-01 naddy struct tog_log_thread_args *ta = &view->state.log.thread_args;
3045 5e224a3e 2019-02-22 stsp int errcode;
3047 098596c5 2023-04-14 stsp if (!using_mock_io)
3048 098596c5 2023-04-14 stsp halfdelay(1); /* fast refresh while loading commits */
3050 5629093a 2022-07-11 stsp while (!ta->log_complete && !tog_thread_error &&
3051 5629093a 2022-07-11 stsp (ta->commits_needed > 0 || ta->load_all)) {
3052 5e224a3e 2019-02-22 stsp /* Wake the log thread. */
3053 ffe38506 2020-12-01 naddy errcode = pthread_cond_signal(&ta->need_commits);
3054 7aafa0d1 2019-02-22 stsp if (errcode)
3055 2af4a041 2019-05-11 jcs return got_error_set_errno(errcode,
3056 2af4a041 2019-05-11 jcs "pthread_cond_signal");
3059 7c1452c1 2020-03-26 stsp * The mutex will be released while the view loop waits
3060 7c1452c1 2020-03-26 stsp * in wgetch(), at which time the log thread will run.
3062 7c1452c1 2020-03-26 stsp if (!wait)
3065 7c1452c1 2020-03-26 stsp /* Display progress update in log view. */
3066 ffe38506 2020-12-01 naddy show_log_view(view);
3067 7c1452c1 2020-03-26 stsp update_panels();
3068 7c1452c1 2020-03-26 stsp doupdate();
3070 7c1452c1 2020-03-26 stsp /* Wait right here while next commit is being loaded. */