diff: add option to show context between close hunks
PATCH v2 1/1 diff: add option to show context between close hunks
Merge two hunks if there is only the specified number of otherwise unshown context between them. For --inter-hunk-context=1, the resulting patch has the same number of lines but shows uninterrupted context instead of a context header line in between.
Patches generated with this option are easier to read but are also more likely to conflict if the file to be patched contains other changes.
This patch keeps the default for this option at 0. It is intended to just make the feature available in order to see its advantages and downsides.
Signed-off-by Rene Scharfe <[email protected]>
---
Changes: s/chunk/hunk/g, bash completion, redone test script.
Documentation/diff-options.txt | 4 ++ contrib/completion/git-completion.bash | 2 + diff.c | 4 ++ diff.h | 1 + t/t4032-diff-inter-hunk-context.sh | 92 ++++++++++++++++++++++++++++++++ xdiff/xdiff.h | 1 + xdiff/xemit.c | 3 +- 7 files changed, 106 insertions(+), 1 deletions(-) create mode 100755 t/t4032-diff-inter-hunk-context.sh
Documentation/diff-options.txt +4 -0
@@ -215,6 +215,10 @@ endif::git-format-patch[] -w:: Shorthand for "--ignore-all-space". +--inter-hunk-context=<lines>:: + Show the context between diff hunks, up to the specified number + of lines, thereby fusing hunks that are close to each other. + --exit-code:: Make the program exit with codes similar to diff(1). That is, it exits with 1 if there were differences and
contrib/completion/git-completion.bash +2 -0
@@ -776,6 +776,7 @@ _git_diff () --no-ext-diff --no-prefix --src-prefix= --dst-prefix= --base --ours --theirs + --inter-hunk-context= " return ;;
@@ -967,6 +968,7 @@ _git_log () --color-words --walk-reflogs --parents --children --full-history --merge + --inter-hunk-context= " return ;;
diff.c +4 -0
@@ -1469,6 +1469,7 @@ static void builtin_diff(const char *name_a, ecbdata.file = o->file; xpp.flags =XDF_NEED_MINIMAL | o->xdl_opts; xecfg.ctxlen = o->context; + xecfg.interhunkctxlen = o->interhunkcontext; xecfg.flags =XDL_EMIT_FUNCNAMES ;if (pe)xdiff_set_find_func (&xecfg, pe->pattern, pe->cflags);
@@ -2538,6 +2539,9 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac) options->b_prefix = arg +13 ; else if (!strcmp(arg, "--no-prefix")) options->a_prefix = options->b_prefix ="" ; + else if (opt_arg(arg, '\0', "inter-hunk-context", + &options->interhunkcontext)) + ; else if (!prefixcmp(arg, "--output=")) { options->file =fopen (arg +strlen ("--output=" ),"w" ); options->close_file =1 ;
diff.h +1 -0
@@ -78,6 +78,7 @@ struct diff_options {const char *a_prefix, *b_prefix;unsigned flags;int context; +int interhunkcontext;int break_opt;int detect_rename;int skip_stat_unmatch;
t/t4032-diff-inter-hunk-context.sh new file +92 -0
92 lines not on this page · raw message
xdiff/xdiff.h +1 -0
@@ -84,6 +84,7 @@ typedef long (*find_func_t)(const char *line, long line_len, char *buffer, long typedef struct s_xdemitconf { long ctxlen; + long interhunkctxlen; unsigned long flags; find_func_t find_func; void *find_func_priv;
xdiff/xemit.c +2 -1
@@ -59,9 +59,10 @@ static int xdl_emit_record(xdfile_t *xdf, long ri, char const *pre, xdemitcb_t **/ xdchange_t *xdl_get_hunk (xdchange_t *xscr,xdemitconf_t const *xecfg) {xdchange_t *xch, *xchp; +long max_common =2 * xecfg->ctxlen + xecfg->interhunkctxlen;for (xchp = xscr, xch = xscr->next; xch; xchp = xch, xch = xch->next) -if (xch->i1 - (xchp->i1 + xchp->chg1) >2 * xecfg->ctxlen) +if (xch->i1 - (xchp->i1 + xchp->chg1) > max_common)break ;return xchp;
Signature · 1 line
1.6.1
Thanks; will queue.