Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[GH #91] Allow to open blob related with added content in a diff

  • Loading branch information...
commit 6ffb71c3ae8978066af22484d6cf08e7a3409da5 1 parent 690c03d
@jonas jonas authored
Showing with 23 additions and 7 deletions.
  1. +1 −0  NEWS
  2. +22 −7 tig.c
View
1  NEWS
@@ -46,6 +46,7 @@ Improvements:
and diff view, e.g. `tig --no-walk --stdin < cherry-picks.txt`.
- Add option to disable focusing of the child view when it's opened.
Disable using: `set focus-child = no`. (GH #83)
+ - Allow to open blob related with added content in a diff. (GH #91)
Bug fixes:
View
29 tig.c
@@ -4540,15 +4540,16 @@ diff_request(struct view *view, enum request request, struct line *line)
static void
diff_select(struct view *view, struct line *line)
{
- const char *s;
-
if (line->type == LINE_DIFF_STAT) {
- s = get_view_key(view, REQ_ENTER);
- string_format(view->ref, "Press '%s' to jump to file diff", s);
+ string_format(view->ref, "Press '%s' to jump to file diff",
+ get_view_key(view, REQ_ENTER));
} else {
- s = diff_get_pathname(view, line);
- if (s) {
- string_format(view->ref, "Changes to '%s'", s);
+ const char *file = diff_get_pathname(view, line);
+
+ if (file) {
+ string_format(view->ref, "Changes to '%s'", file);
+ string_format(opt_file, "%s", file);
+ ref_blob[0] = 0;
} else {
string_ncopy(view->ref, view->id, strlen(view->id));
pager_select(view, line);
@@ -5210,6 +5211,20 @@ blob_open(struct view *view, enum open_flags flags)
"git", "cat-file", "blob", "%(blob)", NULL
};
+ if (!ref_blob[0] && opt_file[0]) {
+ const char *commit = ref_commit[0] ? ref_commit : "HEAD";
+ char blob_spec[SIZEOF_STR];
+ const char *rev_parse_argv[] = {
+ "git", "rev-parse", blob_spec, NULL
+ };
+
+ if (!string_format(blob_spec, "%s:%s", commit, opt_file) ||
+ !io_run_buf(rev_parse_argv, ref_blob, sizeof(ref_blob))) {
+ report("Failed to resolve blob from file name");
+ return FALSE;
+ }
+ }
+
if (!ref_blob[0]) {
report("No file chosen, press %s to open tree view",
get_view_key(view, REQ_VIEW_TREE));
Please sign in to comment.
Something went wrong with that request. Please try again.