From 663a69bedea38ddd9ceef0571cca8831f688244e Mon Sep 17 00:00:00 2001 From: Thomas Koutcher Date: Wed, 10 Apr 2024 20:51:42 +0200 Subject: [PATCH] Fix reopening the blame view from the main view * Update %(ref) when opening the blame view from the main view. * Rework 683fdc86374da5ce03ddabc271157e601a8fda0b to set %(file) only when opening the blob view and bring back %(file_old). --- NEWS.adoc | 1 + src/blame.c | 11 +++++++++-- src/main.c | 8 ++++++++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/NEWS.adoc b/NEWS.adoc index 62201bfc2..aac472fc9 100644 --- a/NEWS.adoc +++ b/NEWS.adoc @@ -9,6 +9,7 @@ Bug fixes: - Fix `stat-*` coloring file names in `tig status` instead of just markers (regression in 2.5.9). (#1326) - Fix keybinding with +[cmd] not triggering view refreshing. (#1324) + - Fix reopening the blame view from the main view. tig-2.5.9 --------- diff --git a/src/blame.c b/src/blame.c index c8211669a..a665c18cc 100644 --- a/src/blame.c +++ b/src/blame.c @@ -128,7 +128,7 @@ blame_open(struct view *view, enum open_flags flags) if (!view->env->file[0] && opt_file_args && !opt_file_args[1]) { const char *ls_tree_argv[] = { - "git", "ls-tree", "-d", "-z", *view->env->ref ? view->env->ref : view->env->commit, opt_file_args[0], NULL + "git", "ls-tree", "-d", "-z", *view->env->ref ? view->env->ref : "HEAD", opt_file_args[0], NULL }; char buf[SIZEOF_STR] = ""; @@ -457,6 +457,10 @@ blame_request(struct view *view, enum request request, struct line *line) open_main_view(view, OPEN_RELOAD); break; + case REQ_VIEW_BLOB: + string_ncopy(view->env->file, blame->commit->filename, strlen(blame->commit->filename)); + return request; + default: return request; } @@ -482,7 +486,10 @@ blame_select(struct view *view, struct line *line) string_format(view->ref, "%s changed %s", commit->id, commit->filename); } - string_ncopy(view->env->file, commit->filename, strlen(commit->filename)); + if (strcmp(commit->filename, view->env->file)) + string_format(view->env->file_old, "%s", commit->filename); + else + view->env->file_old[0] = '\0'; view->env->lineno = view->pos.lineno + 1; string_ncopy(view->env->text, text, strlen(text)); diff --git a/src/main.c b/src/main.c index e1f252af8..912505706 100644 --- a/src/main.c +++ b/src/main.c @@ -548,6 +548,7 @@ main_request(struct view *view, enum request request, struct line *line) line->type == LINE_STAT_STAGED || line->type == LINE_STAT_UNTRACKED)) ? OPEN_SPLIT : OPEN_DEFAULT; + struct commit *commit = line->data; switch (request) { case REQ_VIEW_DIFF: @@ -576,6 +577,13 @@ main_request(struct view *view, enum request request, struct line *line) return request; break; + case REQ_VIEW_BLAME: + if (string_rev_is_null(commit->id)) + view->env->ref[0] = 0; + else + string_copy_rev(view->env->ref, commit->id); + return request; + case REQ_REFRESH: load_refs(true); refresh_view(view);