Skip to content

Commit

Permalink
Open the blob corresponding to the diff line
Browse files Browse the repository at this point in the history
Fixes #1334
  • Loading branch information
koutcher committed May 28, 2024
1 parent 587a59a commit 2a8ef0f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
7 changes: 7 additions & 0 deletions NEWS.adoc
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
Release notes
=============

master
------

Improvements:

- Open the blob corresponding to the diff line. (#1334)

tig-2.5.10
----------
Expand Down
20 changes: 7 additions & 13 deletions src/diff.c
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@ diff_get_lineno(struct view *view, struct line *line, bool old)
}

static enum request
diff_trace_origin(struct view *view, struct line *line)
diff_trace_origin(struct view *view, enum request request, struct line *line)
{
struct line *commit_line = find_prev_line_by_type(view, line, LINE_COMMIT);
char id[SIZEOF_REV];
Expand All @@ -652,16 +652,9 @@ diff_trace_origin(struct view *view, struct line *line)
return REQ_NONE;
}

for (; diff < line && !file; diff++) {
const char *data = box_text(diff);
file = diff_get_pathname(view, line, line->type == LINE_DIFF_DEL);

if (!prefixcmp(data, "--- a/")) {
file = data + STRING_SIZE("--- a/");
break;
}
}

if (diff == line || !file) {
if (!file) {
report("Failed to read the file name");
return REQ_NONE;
}
Expand Down Expand Up @@ -704,10 +697,10 @@ diff_trace_origin(struct view *view, struct line *line)
}

string_ncopy(view->env->file, commit.filename, strlen(commit.filename));
string_copy(view->env->ref, header.id);
string_copy(request == REQ_VIEW_BLAME ? view->env->ref : view->env->commit, header.id);
view->env->goto_lineno = header.orig_lineno - 1;

return REQ_VIEW_BLAME;
return request;
}

const char *
Expand Down Expand Up @@ -782,7 +775,8 @@ diff_request(struct view *view, enum request request, struct line *line)
{
switch (request) {
case REQ_VIEW_BLAME:
return diff_trace_origin(view, line);
case REQ_VIEW_BLOB:
return diff_trace_origin(view, request, line);

case REQ_EDIT:
return diff_common_edit(view, request, line);
Expand Down

0 comments on commit 2a8ef0f

Please sign in to comment.