add 'r' command to tog log view
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
diff --git a/TODO b/TODO
index d5065f1..7aaa8ea 100644
--- a/TODO
+++ b/TODO
@@ -11,7 +11,6 @@ lib:
(e.g. diffing between versions of sys/dev/pci/pcidevs is too slow)
tog:
-- allow loading new commits in 'tog log' after startup (e.g. via Ctrl-L, 'r')
- implement horizonal scrolling in all views
- implement horizonal split view mode
- implement search feature for diff view
diff --git a/tog/tog.1 b/tog/tog.1
index 55b3318..8911577 100644
--- a/tog/tog.1
+++ b/tog/tog.1
@@ -114,6 +114,8 @@ Regular expression syntax is documented in
Find the next commit which matches the current search pattern.
.It Cm N
Find the previous commit which matches the current search pattern.
+.It Cm r
+Reload the log view with new commits found in the repository.
.El
.Pp
The options for
diff --git a/tog/tog.c b/tog/tog.c
index 77bc11a..2c60e90 100644
--- a/tog/tog.c
+++ b/tog/tog.c
@@ -148,6 +148,7 @@ struct tog_log_view_state {
struct commit_queue_entry *selected_entry;
int selected;
char *in_repo_path;
+ const char *head_ref_name;
struct got_repository *repo;
struct got_reflist_head *refs;
struct got_object_id *start_id;
@@ -291,7 +292,7 @@ static const struct got_error* close_diff_view(struct tog_view *);
static const struct got_error *open_log_view(struct tog_view *,
struct got_object_id *, struct got_reflist_head *,
- struct got_repository *, const char *, int);
+ struct got_repository *, const char *, const char *, int);
static const struct got_error * show_log_view(struct tog_view *);
static const struct got_error *input_log_view(struct tog_view **,
struct tog_view **, struct tog_view **, struct tog_view *, int);
@@ -768,7 +769,7 @@ view_loop(struct tog_view *view)
TAILQ_REMOVE(&views, dead_view, entry);
err = view_close(dead_view);
- if (err || dead_view == main_view)
+ if (err || (dead_view == main_view && new_view == NULL))
goto done;
if (view == dead_view) {
@@ -1809,7 +1810,7 @@ search_next_log_view(struct tog_view *view)
static const struct got_error *
open_log_view(struct tog_view *view, struct got_object_id *start_id,
struct got_reflist_head *refs, struct got_repository *repo,
- const char *path, int check_disk)
+ const char *head_ref_name, const char *path, int check_disk)
{
const struct got_error *err = NULL;
struct tog_log_view_state *s = &view->state.log;
@@ -1827,6 +1828,7 @@ open_log_view(struct tog_view *view, struct got_object_id *start_id,
s->refs = refs;
s->repo = repo;
+ s->head_ref_name = head_ref_name;
s->start_id = got_object_id_dup(start_id);
if (s->start_id == NULL) {
err = got_error_from_errno("got_object_id_dup");
@@ -1894,9 +1896,10 @@ input_log_view(struct tog_view **new_view, struct tog_view **dead_view,
{
const struct got_error *err = NULL;
struct tog_log_view_state *s = &view->state.log;
- char *parent_path;
- struct tog_view *diff_view = NULL, *tree_view = NULL;
+ char *parent_path, *in_repo_path = NULL;
+ struct tog_view *diff_view = NULL, *tree_view = NULL, *lv = NULL;
int begin_x = 0;
+ struct got_object_id *start_id;
switch (ch) {
case 'q':
@@ -2024,7 +2027,6 @@ input_log_view(struct tog_view **new_view, struct tog_view **dead_view,
break;
parent_path = dirname(s->in_repo_path);
if (parent_path && strcmp(parent_path, ".") != 0) {
- struct tog_view *lv;
err = stop_log_thread(s);
if (err)
return err;
@@ -2034,7 +2036,7 @@ input_log_view(struct tog_view **new_view, struct tog_view **dead_view,
return got_error_from_errno(
"view_open");
err = open_log_view(lv, s->start_id, s->refs,
- s->repo, parent_path, 0);
+ s->repo, s->head_ref_name, parent_path, 0);
if (err)
return err;;
if (view_is_parent_view(view))
@@ -2046,6 +2048,30 @@ input_log_view(struct tog_view **new_view, struct tog_view **dead_view,
return NULL;
}
break;
+ case 'r':
+ err = stop_log_thread(s);
+ if (err)
+ return err;
+ lv = view_open(view->nlines, view->ncols,
+ view->begin_y, view->begin_x, TOG_VIEW_LOG);
+ if (lv == NULL)
+ return got_error_from_errno("view_open");
+ err = get_head_commit_id(&start_id, s->head_ref_name ?
+ s->head_ref_name : GOT_REF_HEAD, s->repo);
+ if (err)
+ return err;
+ in_repo_path = strdup(s->in_repo_path);
+ if (in_repo_path == NULL) {
+ free(start_id);
+ return got_error_from_errno("strdup");
+ }
+ err = open_log_view(lv, start_id, s->refs, s->repo,
+ s->head_ref_name, in_repo_path, 0);
+ if (err)
+ return err;;
+ *dead_view = view;
+ *new_view = lv;
+ break;
default:
break;
}
@@ -2200,7 +2226,8 @@ cmd_log(int argc, char *argv[])
error = got_error_from_errno("view_open");
goto done;
}
- error = open_log_view(view, start_id, &refs, repo, path, 1);
+ error = open_log_view(view, start_id, &refs, repo, worktree ?
+ got_worktree_get_head_ref_name(worktree) : NULL, path, 1);
if (error)
goto done;
error = view_loop(view);
@@ -3934,7 +3961,7 @@ log_tree_entry(struct tog_view **new_view, int begin_x,
if (err)
return err;
- err = open_log_view(log_view, commit_id, refs, repo, path, 0);
+ err = open_log_view(log_view, commit_id, refs, repo, NULL, path, 0);
if (err)
view_close(log_view);
else