From 65093b11cf295b7057bb0c01339b2976ee4feccf Mon Sep 17 00:00:00 2001 From: Gabriel Date: Wed, 22 May 2024 14:19:54 -0700 Subject: [PATCH 1/4] change diff parsing naive fix#1336 --- src/diff.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/diff.c b/src/diff.c index 23746b41b..862b36460 100644 --- a/src/diff.c +++ b/src/diff.c @@ -654,10 +654,13 @@ diff_trace_origin(struct view *view, struct line *line) for (; diff < line && !file; diff++) { const char *data = box_text(diff); - - if (!prefixcmp(data, "--- a/")) { - file = data + STRING_SIZE("--- a/"); - break; + if (!prefixcmp(data, "--- ")) { + const char *data_n1 = box_text(diff+1); + const char *data_n2 = box_text(diff+2); + if(!prefixcmp(data_n1, "+++ ") && prefixcmp(data_n2, "@@ ")){ + file = data + STRING_SIZE("--- "); + break; + } } } From 7d05ccff1c11eb666c3fa83dba8779c5eed6bd71 Mon Sep 17 00:00:00 2001 From: Gabriel Date: Wed, 22 May 2024 15:22:18 -0700 Subject: [PATCH 2/4] typo --- src/diff.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/diff.c b/src/diff.c index 862b36460..f3ed11f78 100644 --- a/src/diff.c +++ b/src/diff.c @@ -657,7 +657,7 @@ diff_trace_origin(struct view *view, struct line *line) if (!prefixcmp(data, "--- ")) { const char *data_n1 = box_text(diff+1); const char *data_n2 = box_text(diff+2); - if(!prefixcmp(data_n1, "+++ ") && prefixcmp(data_n2, "@@ ")){ + if(!prefixcmp(data_n1, "+++ ") && !prefixcmp(data_n2, "@@ ")){ file = data + STRING_SIZE("--- "); break; } From 31b8c118a0219f82d06a53ccce2e81996f82609e Mon Sep 17 00:00:00 2001 From: Thomas Koutcher Date: Thu, 23 May 2024 18:34:20 +0200 Subject: [PATCH 3/4] fix original use case --- src/diff.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/diff.c b/src/diff.c index f3ed11f78..c520ba2f5 100644 --- a/src/diff.c +++ b/src/diff.c @@ -654,13 +654,10 @@ diff_trace_origin(struct view *view, struct line *line) for (; diff < line && !file; diff++) { const char *data = box_text(diff); + if (!prefixcmp(data, "--- ")) { - const char *data_n1 = box_text(diff+1); - const char *data_n2 = box_text(diff+2); - if(!prefixcmp(data_n1, "+++ ") && !prefixcmp(data_n2, "@@ ")){ - file = data + STRING_SIZE("--- "); - break; - } + file = data + (opt_diff_noprefix ? STRING_SIZE("--- ") : STRING_SIZE("--- a/")); + break; } } From 39dca0b16403f1006c89bc047bfbeb7d94cd1e0e Mon Sep 17 00:00:00 2001 From: gcb <56283+gcb@users.noreply.github.com> Date: Thu, 30 May 2024 16:32:29 -0300 Subject: [PATCH 4/4] TODO: TODO --- include/tig/options.h | 2 ++ src/diff.c | 2 ++ src/options.c | 4 ++++ 3 files changed, 8 insertions(+) diff --git a/include/tig/options.h b/include/tig/options.h index a17456a0c..55d684c89 100644 --- a/include/tig/options.h +++ b/include/tig/options.h @@ -37,6 +37,8 @@ typedef struct view_column *view_settings; _(commit_order, enum commit_order, VIEW_LOG_LIKE) \ _(diff_context, int, VIEW_DIFF_LIKE) \ _(diff_noprefix, bool, VIEW_NO_FLAGS) \ + // TODO: _(diff_dstprefix, + // TODO: _(diff_srcprefix, _(diff_options, const char **, VIEW_DIFF_LIKE) \ _(diff_highlight, const char *, VIEW_DIFF_LIKE) \ _(word_diff, bool, VIEW_DIFF_LIKE) \ diff --git a/src/diff.c b/src/diff.c index c520ba2f5..96793ccce 100644 --- a/src/diff.c +++ b/src/diff.c @@ -655,6 +655,7 @@ diff_trace_origin(struct view *view, struct line *line) for (; diff < line && !file; diff++) { const char *data = box_text(diff); + // TODO: make a diff file name parser generic if (!prefixcmp(data, "--- ")) { file = data + (opt_diff_noprefix ? STRING_SIZE("--- ") : STRING_SIZE("--- a/")); break; @@ -735,6 +736,7 @@ diff_get_pathname(struct view *view, struct line *line, bool old) if (!header) return NULL; + // TODO: make a diff file name parser generic name = box_text(header); if (old ? !prefixcmp(name, "--- ") : !prefixcmp(name, "+++ ")) name += STRING_SIZE("+++ "); diff --git a/src/options.c b/src/options.c index 0bd0c0f7f..7d1a5b7ce 100644 --- a/src/options.c +++ b/src/options.c @@ -1534,6 +1534,10 @@ read_repo_config_option(char *name, size_t namelen, char *value, size_t valuelen else if (!strcmp(name, "diff.noprefix")) parse_bool(&opt_diff_noprefix, value); + // TODO: else if (!strcmp(name, "diff.dstprefix")) and store it somewhere + + // TODO: else if (!strcmp(name, "diff.srcprefix")) and store it somewhere + else if (!strcmp(name, "status.showuntrackedfiles")) opt_status_show_untracked_files = !!strcmp(value, "no"), opt_status_show_untracked_dirs = !strcmp(value, "all");