Skip to content

Commit

Permalink
Use %(diffargs) in the stage view commands
Browse files Browse the repository at this point in the history
Fixes #545
  • Loading branch information
jonas committed Nov 26, 2016
1 parent e63ebc9 commit 3e4e15a
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 20 deletions.
5 changes: 5 additions & 0 deletions NEWS.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ Release notes
master
------

Improvements:

- Use `diff-options` when preparing the diff in the stage view to make the diff
state configurable. (GH #545)

Bug fixes:

- Add workaround for detecting failure to start the diff-highlight process.
Expand Down
2 changes: 1 addition & 1 deletion doc/manual.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ following variables.
|%(fileargs) |The file arguments passed on the command line.
|%(cmdlineargs) |All other options passed on the command line.
|%(diffargs) |Options from 'diff-options' or 'TIG_DIFF_OPTS' used
used by the diff view.
used by the diff and stage view.
|%(blameargs) |Options from 'blame-options' used by the blame view.
|%(logargs) |Options from 'log-options' used by the log view.
|%(mainargs) |Options from 'main-options' used by the main view.
Expand Down
2 changes: 1 addition & 1 deletion doc/tigrc.5.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@ following variable names, which are substituted before commands are run:
|%(fileargs) |The file arguments passed on the command line.
|%(cmdlineargs) |All other options passed on the command line.
|%(diffargs) |Options from 'diff-options' or 'TIG_DIFF_OPTS' used
used by the diff view.
used by the diff and stage view.
|%(blameargs) |Options from 'blame-options' used by the blame view.
|%(logargs) |Options from 'log-options' used by the log view.
|%(mainargs) |Options from 'main-options' used by the main view.
Expand Down
1 change: 1 addition & 0 deletions include/tig/argv.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
*/

#define SIZEOF_ARG 32 /* Default argument array size. */
#define DIFF_ARGS "%(diffargs)"

bool argv_to_string(const char *argv[], char *buf, size_t buflen, const char *sep);
char *argv_to_string_alloc(const char *argv[], const char *sep);
Expand Down
4 changes: 2 additions & 2 deletions include/tig/git.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@

#define GIT_DIFF_STAGED(encoding_arg, context_arg, space_arg, old_name, new_name) \
"git", "diff-index", (encoding_arg), "--root", "--patch-with-stat", "-C", "-M", \
"--cached", "--diff-filter=ACDMRTXB", (context_arg), (space_arg), "HEAD", \
"--cached", "--diff-filter=ACDMRTXB", DIFF_ARGS, (context_arg), (space_arg), "HEAD", \
"--", (old_name), (new_name), NULL

#define GIT_DIFF_UNSTAGED(encoding_arg, context_arg, space_arg, old_name, new_name) \
"git", "diff-files", (encoding_arg), "--root", "--patch-with-stat", "-C", "-M", \
(context_arg), (space_arg), "--", (old_name), (new_name), NULL
DIFF_ARGS, (context_arg), (space_arg), "--", (old_name), (new_name), NULL

/* Don't show staged unmerged entries. */
#define GIT_DIFF_STAGED_FILES(output_arg) \
Expand Down
2 changes: 1 addition & 1 deletion src/argv.c
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ argv_format(struct argv_env *argv_env, const char ***dst_argv, const char *src_a
if (file_filter && !argv_append_array(dst_argv, opt_file_args))
break;

} else if (!strcmp(arg, "%(diffargs)")) {
} else if (!strcmp(arg, DIFF_ARGS)) {
if (!format_append_argv(&format, dst_argv, opt_diff_options))
break;

Expand Down
2 changes: 1 addition & 1 deletion src/diff.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ diff_open(struct view *view, enum open_flags flags)
"git", "show", encoding_arg, "--pretty=fuller", "--root",
"--patch-with-stat", use_mailmap_arg(),
show_notes_arg(), diff_context_arg(), ignore_space_arg(),
"%(diffargs)", "%(cmdlineargs)", "--no-color", "%(commit)",
DIFF_ARGS, "%(cmdlineargs)", "--no-color", "%(commit)",
"--", "%(fileargs)", NULL
};
enum status_code code;
Expand Down
22 changes: 9 additions & 13 deletions src/stage.c
Original file line number Diff line number Diff line change
Expand Up @@ -496,12 +496,13 @@ stage_open(struct view *view, enum open_flags flags)
* path, so leave out the new path. */
const char *files_unmerged_argv[] = {
"git", "diff-files", encoding_arg, "--root", "--patch-with-stat",
diff_context_arg(), ignore_space_arg(), "--",
DIFF_ARGS, diff_context_arg(), ignore_space_arg(), "--",
stage_status.old.name, NULL
};
static const char *file_argv[] = { repo.cdup, stage_status.new.name, NULL };
const char **argv = NULL;
struct stage_state *state = view->private;
enum status_code code;

if (!stage_line_type)
return error("No stage content, press %s to open the status view and choose file",
Expand Down Expand Up @@ -536,26 +537,21 @@ stage_open(struct view *view, enum open_flags flags)
die("line type %d not handled in switch", stage_line_type);
}

if (!status_stage_info(view->ref, stage_line_type, &stage_status)
|| !argv_copy(&view->argv, argv))
if (!status_stage_info(view->ref, stage_line_type, &stage_status))
return error("Failed to open staged view");

if (stage_line_type != LINE_STAT_UNTRACKED)
diff_save_line(view, &state->diff, flags);

view->vid[0] = 0;
view->dir = repo.cdup;
{
enum status_code ok = begin_update(view, NULL, NULL, flags);
code = begin_update(view, repo.cdup, argv, flags);
if (code == SUCCESS && stage_line_type != LINE_STAT_UNTRACKED) {
struct stage_state *state = view->private;

if (ok == SUCCESS && stage_line_type != LINE_STAT_UNTRACKED) {
struct stage_state *state = view->private;

return diff_init_highlight(view, &state->diff);
}

return ok;
return diff_init_highlight(view, &state->diff);
}

return code;
}

static bool
Expand Down
2 changes: 1 addition & 1 deletion src/stash.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ stash_request(struct view *view, enum request request, struct line *line)
"git", "stash", "show", encoding_arg, "--pretty=fuller",
"--root", "--patch-with-stat", use_mailmap_arg(),
show_notes_arg(), diff_context_arg(),
ignore_space_arg(), "%(diffargs)",
ignore_space_arg(), DIFF_ARGS,
"--no-color", "%(stash)", NULL
};

Expand Down

0 comments on commit 3e4e15a

Please sign in to comment.