summaryrefslogtreecommitdiff
path: root/range-diff.c
diff options
context:
space:
mode:
authorLibravatar Thomas Gummerer <t.gummerer@gmail.com>2019-07-11 17:08:49 +0100
committerLibravatar Junio C Hamano <gitster@pobox.com>2019-07-11 14:29:27 -0700
commitb66885a30cb84fc61986bc4eea805a31fdbea79a (patch)
tree6c1194f1200b9d363752115aa6a091fdc05bbe86 /range-diff.c
parentrange-diff: suppress line count in outer diff (diff)
downloadtgif-b66885a30cb84fc61986bc4eea805a31fdbea79a.tar.xz
range-diff: add section header instead of diff header
Currently range-diff keeps the diff header of the inner diff intact (apart from stripping lines starting with index). This diff header is somewhat useful, especially when files get different names in different ranges. However there is no real need to keep the whole diff header for that. The main reason we currently do that is probably because it is easy to do. Introduce a new range diff hunk header, that's enclosed by "##", similar to how line numbers in diff hunks are enclosed by "@@", and give human readable information of what exactly happened to the file, including the file name. This improves the readability of the range-diff by giving more concise information to the users. For example if a file was renamed in one iteration, but not in another, the diff of the headers would be quite noisy. However the diff of a single line is concise and should be easier to understand. Additionally, this allows us to add these range diff section headers to the outer diffs hunk headers using a custom userdiff pattern, which should help making the range-diff more readable. Signed-off-by: Thomas Gummerer <t.gummerer@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'range-diff.c')
-rw-r--r--range-diff.c34
1 files changed, 27 insertions, 7 deletions
diff --git a/range-diff.c b/range-diff.c
index f4a90b33b8..5f64380fe4 100644
--- a/range-diff.c
+++ b/range-diff.c
@@ -10,6 +10,7 @@
#include "commit.h"
#include "pretty.h"
#include "userdiff.h"
+#include "apply.h"
struct patch_util {
/* For the search for an exact match */
@@ -101,12 +102,35 @@ static int read_patches(const char *range, struct string_list *list)
}
if (starts_with(line, "diff --git")) {
+ struct patch patch = { 0 };
+ struct strbuf root = STRBUF_INIT;
+ int linenr = 0;
+
in_header = 0;
strbuf_addch(&buf, '\n');
if (!util->diff_offset)
util->diff_offset = buf.len;
- strbuf_addch(&buf, ' ');
- strbuf_addstr(&buf, line);
+ line[len - 1] = '\n';
+ len = parse_git_diff_header(&root, &linenr, 1, line,
+ len, size, &patch);
+ if (len < 0)
+ die(_("could not parse git header '%.*s'"), (int)len, line);
+ strbuf_addstr(&buf, " ## ");
+ if (patch.is_new > 0)
+ strbuf_addf(&buf, "%s (new)", patch.new_name);
+ else if (patch.is_delete > 0)
+ strbuf_addf(&buf, "%s (deleted)", patch.old_name);
+ else if (patch.is_rename)
+ strbuf_addf(&buf, "%s => %s", patch.old_name, patch.new_name);
+ else
+ strbuf_addstr(&buf, patch.new_name);
+
+ if (patch.new_mode && patch.old_mode &&
+ patch.old_mode != patch.new_mode)
+ strbuf_addf(&buf, " (mode change %06o => %06o)",
+ patch.old_mode, patch.new_mode);
+
+ strbuf_addstr(&buf, " ##");
} else if (in_header) {
if (starts_with(line, "Author: ")) {
strbuf_addstr(&buf, line);
@@ -122,17 +146,13 @@ static int read_patches(const char *range, struct string_list *list)
} else if (skip_prefix(line, "@@ ", &p)) {
p = strstr(p, "@@");
strbuf_addstr(&buf, p ? p : "@@");
- } else if (!line[0] || starts_with(line, "index "))
+ } else if (!line[0])
/*
* A completely blank (not ' \n', which is context)
* line is not valid in a diff. We skip it
* silently, because this neatly handles the blank
* separator line between commits in git-log
* output.
- *
- * We also want to ignore the diff's `index` lines
- * because they contain exact blob hashes in which
- * we are not interested.
*/
continue;
else if (line[0] == '>') {