summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Koutcher <thomas.koutcher@online.fr>2024-03-10 19:17:09 +0100
committerThomas Koutcher <thomas.koutcher@online.fr>2024-03-26 19:06:20 +0100
commit683fdc86374da5ce03ddabc271157e601a8fda0b (patch)
treeba9c1fb5a4d6e3c7a04b379e66f1c302f61508e8
parent3c2cdb438a42a03d3ea06c522854829db459a993 (diff)
Improve the blob view experience
* Fix opening the blob view for the same file from a different commit. * Set %(file) rather than %(file_old) in the blame view to allow the blob view to open properly. * Allow faster access to the blob view when using `tig <file>`.
-rw-r--r--NEWS.adoc1
-rw-r--r--src/blame.c6
-rw-r--r--src/blob.c14
-rw-r--r--src/grep.c1
-rw-r--r--src/log.c1
-rw-r--r--src/main.c1
-rw-r--r--src/refs.c1
-rw-r--r--src/stash.c1
-rw-r--r--src/status.c4
9 files changed, 23 insertions, 7 deletions
diff --git a/NEWS.adoc b/NEWS.adoc
index a018b855..0295d973 100644
--- a/NEWS.adoc
+++ b/NEWS.adoc
@@ -15,6 +15,7 @@ Improvements:
- Add new "prefetch" reference type for refs created by `git maintenance`
(hidden in default config). (#1318)
- Show the selected commit in the blame view title window.
+ - Improve the blob view experience.
Bug fixes:
diff --git a/src/blame.c b/src/blame.c
index df4c9fef..c8211669 100644
--- a/src/blame.c
+++ b/src/blame.c
@@ -482,13 +482,11 @@ blame_select(struct view *view, struct line *line)
string_format(view->ref, "%s changed %s", commit->id, 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';
+ string_ncopy(view->env->file, commit->filename, strlen(commit->filename));
view->env->lineno = view->pos.lineno + 1;
string_ncopy(view->env->text, text, strlen(text));
+ view->env->blob[0] = 0;
}
static struct view_ops blame_ops = {
diff --git a/src/blob.c b/src/blob.c
index a0055c97..0df5293e 100644
--- a/src/blob.c
+++ b/src/blob.c
@@ -31,9 +31,19 @@ open_blob_view(struct view *prev, enum open_flags flags)
{
struct view *view = &blob_view;
bool in_blob_view = prev == view;
- bool has_blob_selection = view->env->blob[0] || view->env->file[0];
- if (!in_blob_view && (view->lines || has_blob_selection)) {
+ if (!view->env->file[0] && opt_file_args && !opt_file_args[1]) {
+ const char *ls_tree_argv[] = {
+ "git", "ls-tree", "-d", "-z", view->env->commit, opt_file_args[0], NULL
+ };
+ char buf[SIZEOF_STR] = "";
+
+ /* Check that opt_file_args[0] is not a directory */
+ if (!io_run_buf(ls_tree_argv, buf, sizeof(buf), NULL, false))
+ string_concat_path(view->env->file, repo.prefix, opt_file_args[0]);
+ }
+
+ if (!in_blob_view && (view->lines || view->env->blob[0] || view->env->file[0])) {
if (view->env->goto_lineno > 0)
flags |= OPEN_RELOAD;
open_view(prev, view, flags);
diff --git a/src/grep.c b/src/grep.c
index e4201d69..59e8521e 100644
--- a/src/grep.c
+++ b/src/grep.c
@@ -86,6 +86,7 @@ grep_select(struct view *view, struct line *line)
string_ncopy(view->ref, grep->file, strlen(grep->file));
view->env->lineno = grep->lineno + 1;
string_ncopy(view->env->text, text, strlen(text));
+ view->env->blob[0] = 0;
}
static const char *grep_args[] = {
diff --git a/src/log.c b/src/log.c
index dee3c8b6..c24cd241 100644
--- a/src/log.c
+++ b/src/log.c
@@ -37,6 +37,7 @@ log_copy_rev(struct view *view, struct line *line)
size_t offset = get_graph_indent(text);
string_copy_rev_from_commit_line(view->ref, text + offset);
+ view->env->blob[0] = 0;
}
static void
diff --git a/src/main.c b/src/main.c
index 9533356e..e1f252af 100644
--- a/src/main.c
+++ b/src/main.c
@@ -634,6 +634,7 @@ main_select(struct view *view, struct line *line)
view->env->tag[0] = view->env->remote[0] = view->env->branch[0] = view->env->refname[0] = 0;
}
string_copy_rev(view->env->commit, commit->id);
+ view->env->blob[0] = 0;
}
static struct view_ops main_ops = {
diff --git a/src/refs.c b/src/refs.c
index c4b94014..dab556a2 100644
--- a/src/refs.c
+++ b/src/refs.c
@@ -241,6 +241,7 @@ refs_select(struct view *view, struct line *line)
string_copy_rev(view->env->head, reference->ref->id);
string_ncopy(view->env->ref, reference->ref->name, strlen(reference->ref->name));
ref_update_env(view->env, reference->ref, false);
+ view->env->blob[0] = 0;
}
static struct view_ops refs_ops = {
diff --git a/src/stash.c b/src/stash.c
index 75a1b169..ac7b9290 100644
--- a/src/stash.c
+++ b/src/stash.c
@@ -62,6 +62,7 @@ stash_select(struct view *view, struct line *line)
string_ncopy(view->env->stash, state->reflog[line->lineno - 1] + STRING_SIZE("refs/"),
strlen(state->reflog[line->lineno - 1]) - STRING_SIZE("refs/"));
string_copy(view->ref, view->env->stash);
+ view->env->blob[0] = 0;
}
static enum request
diff --git a/src/status.c b/src/status.c
index 7391426f..8c83c7fe 100644
--- a/src/status.c
+++ b/src/status.c
@@ -856,8 +856,10 @@ status_select(struct view *view, struct line *line)
string_format(view->ref, text, key, file);
status_stage_info(view->env->status, line->type, status);
- if (status)
+ if (status) {
string_copy(view->env->file, status->new.name);
+ view->env->blob[0] = 0;
+ }
}
static struct view_ops status_ops = {