Re: [PATCH v2] diff: support anchoring line(s)
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Nov 28, 2017, 01:38 UTC
- Message-ID
- <xmqq1skj9o7r.fsf@gitster.mtv.corp.google.com>
- In-Reply-To
- <20171127194747.118254-1-jonathantanmy@google.com>
Jonathan Tan <jonathantanmy@google.com> writes:
Show 13 quoted lines
> - else if (!strcmp(arg, "--patience"))
> + else if (!strcmp(arg, "--patience")) {
> + int i;
> options->xdl_opts = DIFF_WITH_ALG(options, PATIENCE_DIFF);
> - else if (!strcmp(arg, "--histogram"))
> + /*
> + * Both --patience and --anchored use PATIENCE_DIFF
> + * internally, so remove any anchors previously
> + * specified.
> + */
> + for (i = 0; i < options->anchors_nr; i++)
> + free(options->anchors[i]);
> + options->anchors_nr = 0;This makes sense, but "--diff-algorithm=patience" would want to do the same, I suspect, so the loop would want to become a little helper function "clear_patience_anchors(options)" or something like that.
Show 15 quoted lines
> diff --git a/t/t4064-diff-anchored.sh b/t/t4064-diff-anchored.sh > new file mode 100755 > index 000000000..b3f510f04 > --- /dev/null > +++ b/t/t4064-diff-anchored.sh > @@ -0,0 +1,94 @@ > +#!/bin/sh > + > +test_description='anchored diff algorithm' > + > +. ./test-lib.sh > + > +test_expect_success '--anchored' ' > + printf "a\nb\nc\n" >pre && > + printf "c\na\nb\n" >post &&
This may be too little to matter, but I'd find
printf "%s\n" a b c >pre
vastly easier to read. Or perhaps just use
test_write_lines a b c >pre