Skip to content

Commit b0f77a7

Browse files
committed
Allow to hide +/- signs in the diff view
Use `:toggle diff-indicator` to show or hide the +/- signs in the diff view. Closes #855, closes #901
1 parent 80fc430 commit b0f77a7

File tree

7 files changed

+30
-16
lines changed

7 files changed

+30
-16
lines changed

doc/tigrc.5.adoc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,10 @@ The following variables can be set:
290290
regions are governed by `color diff-add-highlight` and
291291
`color diff-del-highlight`.
292292
293+
'diff-indicator' (bool)::
294+
295+
Show +/- signs in the diff view. On by default.
296+
293297
'ignore-space' (mixed) [no|all|some|at-eol|<bool>]::
294298
295299
Ignore space changes in diff view. By default no space changes are
@@ -301,7 +305,7 @@ The following variables can be set:
301305
the *status-update* and *status-revert* may fail when updating or
302306
reverting chunks containing lines with space changes. Similarly,
303307
*stage-update-line* may fail when updating a line adjacent to a line
304-
with space changes
308+
with space changes.
305309
306310
'commit-order' (enum) [auto|default|topo|date|author-date|reverse]::
307311

include/tig/diff.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ struct diff_state {
2424
bool combined_diff;
2525
bool adding_describe_ref;
2626
bool highlight;
27+
bool stage;
28+
unsigned int parents;
2729
const char *file;
2830
unsigned int lineno;
2931
struct position pos;

include/tig/options.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ typedef struct view_column *view_settings;
3636
_(blob_view, view_settings, VIEW_NO_FLAGS) \
3737
_(commit_order, enum commit_order, VIEW_LOG_LIKE) \
3838
_(diff_context, int, VIEW_DIFF_LIKE) \
39+
_(diff_indicator, bool, VIEW_DIFF_LIKE) \
3940
_(diff_noprefix, bool, VIEW_NO_FLAGS) \
4041
_(diff_options, const char **, VIEW_DIFF_LIKE) \
4142
_(diff_highlight, const char *, VIEW_DIFF_LIKE) \

include/tig/parse.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,10 @@ size_t parse_size(const char *text);
6363
const char *get_path(const char *path);
6464
struct ident *get_author(const char *name, const char *email);
6565

66-
static inline int
66+
static inline unsigned int
6767
chunk_header_marker_length(const char *data)
6868
{
69-
int len = 0;
69+
unsigned int len = 0;
7070
for (; *data == '@'; data++)
7171
len++;
7272
return len;

src/diff.c

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ diff_common_read(struct view *view, const char *data, struct diff_state *state)
347347
state->reading_diff_chunk = false;
348348

349349
} else if (type == LINE_DIFF_CHUNK) {
350-
const int len = chunk_header_marker_length(data);
350+
const unsigned int len = chunk_header_marker_length(data);
351351
const char *context = strstr(data + len, "@@");
352352
struct line *line =
353353
context ? add_line_text_at(view, view->lines, data, LINE_DIFF_CHUNK, len)
@@ -362,20 +362,26 @@ diff_common_read(struct view *view, const char *data, struct diff_state *state)
362362
box->cell[1].length = strlen(context + len);
363363
box->cell[box->cells++].type = LINE_DIFF_STAT;
364364
state->combined_diff = (len > 2);
365+
state->parents = len - 1;
365366
state->reading_diff_chunk = true;
366367
return true;
367368

368369
} else if (type == LINE_COMMIT) {
369370
state->reading_diff_chunk = false;
370371

371-
} else if (state->highlight && strchr(data, 0x1b)) {
372-
return diff_common_highlight(view, data, type);
372+
}
373373

374-
} else if (opt_word_diff && state->reading_diff_chunk &&
375-
/* combined diff format is not using word diff */
376-
!state->combined_diff) {
374+
if (opt_word_diff && state->reading_diff_chunk &&
375+
/* combined diff format is not using word diff */
376+
!state->combined_diff)
377377
return diff_common_read_diff_wdiff(view, data);
378-
}
378+
379+
if (!opt_diff_indicator && state->reading_diff_chunk &&
380+
!state->stage)
381+
data += state->parents;
382+
383+
if (state->highlight && strchr(data, 0x1b))
384+
return diff_common_highlight(view, data, type);
379385

380386
return pager_common_read(view, data, type, NULL);
381387
}

src/stage.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -769,18 +769,17 @@ stage_open(struct view *view, enum open_flags flags)
769769
}
770770

771771
if (!status_stage_info(view->ref, stage_line_type, &stage_status))
772-
return error("Failed to open staged view");
772+
return error("Failed to open stage view");
773+
774+
state->diff.stage = true;
773775

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

777779
view->vid[0] = 0;
778780
code = begin_update(view, repo.exec_dir, argv, flags | OPEN_WITH_STDERR);
779-
if (code == SUCCESS && stage_line_type != LINE_STAT_UNTRACKED) {
780-
struct stage_state *state = view->private;
781-
781+
if (code == SUCCESS && stage_line_type != LINE_STAT_UNTRACKED)
782782
return diff_init_highlight(view, &state->diff);
783-
}
784783

785784
return code;
786785
}

tigrc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,9 @@ set show-notes = yes # When non-bool passed as `--show-notes=...` (diff)
122122
#set diff-context = 3 # Number of lines to show around diff changes (diff)
123123
#set word-diff = yes # Show a word diff? (diff)
124124
#set diff-options = -C # User-defined options for `tig show` (git-diff)
125-
#set diff-highlight = true # String (or bool): Path to diff-highlight script,
125+
#set diff-highlight = yes # String (or bool): Path to diff-highlight script,
126126
# defaults to `diff-highlight`.
127+
set diff-indicator = yes # Show diff +/- signs?
127128
#set blame-options = -C -C -C # User-defined options for `tig blame` (git-blame)
128129
set log-options = --cc --stat # User-defined options for `tig log` (git-log)
129130
#set main-options = -n 1000 # User-defined options for `tig` (git-log)
@@ -326,6 +327,7 @@ bind generic $ :toggle commit-title-overflow
326327
# Toggle display of file in untracked directories
327328
# bind generic ??? :toggle vertical-split # Toggle vertical split
328329
# bind generic ??? :toggle word-diff # Toggle word diff
330+
# bind generic ??? :toggle diff-indicator # Toggle display of diff +/- signs
329331
bind generic % :toggle file-filter # Toggle filtering by pathspecs in file-args
330332
bind generic ^ :toggle rev-filter # Toggle filtering by revisions in rev-args
331333

0 commit comments

Comments
 (0)