Skip to content

Commit

Permalink
Fix reopening the blame view from the main view
Browse files Browse the repository at this point in the history
* Update %(ref) when opening the blame view from the main view.

* Rework 683fdc8 to set %(file) only
  when opening the blob view and bring back %(file_old).
  • Loading branch information
koutcher committed Apr 10, 2024
1 parent 2560393 commit 663a69b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
1 change: 1 addition & 0 deletions NEWS.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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
---------
Expand Down
11 changes: 9 additions & 2 deletions src/blame.c
Original file line number Diff line number Diff line change
Expand Up @@ -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] = "";

Expand Down Expand Up @@ -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;
}
Expand All @@ -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));
Expand Down
8 changes: 8 additions & 0 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 663a69b

Please sign in to comment.