allow moving to parent directory in 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
diff --git a/tog/tog.1 b/tog/tog.1
index 91f55cb..4e27b78 100644
--- a/tog/tog.1
+++ b/tog/tog.1
@@ -106,6 +106,8 @@ updated when the other switches to a different commit.
Switch to the
.Cm tree
view showing the tree for the currently selected commit.
+.It Cm Backspace
+Show log entries for the parent directory of the currently selected path.
.El
.Pp
The options for
diff --git a/tog/tog.c b/tog/tog.c
index 2c93b3c..78fbabb 100644
--- a/tog/tog.c
+++ b/tog/tog.c
@@ -34,6 +34,7 @@
#include <wchar.h>
#include <time.h>
#include <pthread.h>
+#include <libgen.h>
#include "got_error.h"
#include "got_object.h"
@@ -117,6 +118,7 @@ struct tog_log_view_state {
int selected;
char *in_repo_path;
struct got_repository *repo;
+ struct got_object_id *start_id;
};
struct tog_blame_cb_args {
@@ -1136,6 +1138,11 @@ open_log_view(struct tog_view *view, struct got_object_id *start_id,
s->first_displayed_entry = TAILQ_FIRST(&s->commits.head);
s->selected_entry = s->first_displayed_entry;
s->repo = repo;
+ s->start_id = got_object_id_dup(start_id);
+ if (s->start_id == NULL) {
+ err = got_error_from_errno();
+ goto done;
+ }
view->show = show_log_view;
view->input = input_log_view;
@@ -1154,6 +1161,7 @@ close_log_view(struct tog_view *view)
got_commit_graph_close(s->graph);
free_commits(&s->commits);
free(s->in_repo_path);
+ free(s->start_id);
return NULL;
}
@@ -1223,6 +1231,7 @@ 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;
switch (ch) {
case 'k':
@@ -1295,6 +1304,22 @@ input_log_view(struct tog_view **new_view, struct tog_view **dead_view,
err = browse_commit(new_view, view, s->selected_entry,
s->repo);
break;
+ case KEY_BACKSPACE:
+ if (strcmp(s->in_repo_path, "/") == 0)
+ break;
+ parent_path = dirname(s->in_repo_path);
+ if (parent_path && strcmp(parent_path, ".") != 0) {
+ struct tog_view *lv;
+ lv = view_open(0, 0, 0, 0, NULL, TOG_VIEW_LOG);
+ if (lv == NULL)
+ return got_error_from_errno();
+ err = open_log_view(lv, s->start_id, s->repo,
+ parent_path);
+ if (err)
+ break;
+ *new_view = lv;
+ }
+ break;
default:
break;
}