* [PATCH] merge-recursive: fix parsing of "diff-algorithm" option
@ 2013-09-26 20:02 John Keeping
2013-09-26 20:47 ` Jonathan Nieder
0 siblings, 1 reply; 3+ messages in thread
From: John Keeping @ 2013-09-26 20:02 UTC (permalink / raw)
To: git; +Cc: Luke Noel-Storr, Michal Privoznik, John Keeping
The "diff-algorithm" option to the recursive merge strategy takes the
name of the algorithm as an option, but it uses strcmp on the option
string to check if it starts with "diff-algorithm=", meaning that this
options cannot actually be used.
Fix this by switching to prefixcmp. At the same time, clarify the
following line by using strlen instead of a hard-coded length, which
also makes it consistent with nearby code.
Reported-by: Luke Noel-Storr <luke.noel-storr@integrate.co.uk>
Signed-off-by: John Keeping <john@keeping.me.uk>
---
merge-recursive.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/merge-recursive.c b/merge-recursive.c
index 40eb840..dbb7104 100644
--- a/merge-recursive.c
+++ b/merge-recursive.c
@@ -2069,8 +2069,8 @@ int parse_merge_opt(struct merge_options *o, const char *s)
o->xdl_opts = DIFF_WITH_ALG(o, PATIENCE_DIFF);
else if (!strcmp(s, "histogram"))
o->xdl_opts = DIFF_WITH_ALG(o, HISTOGRAM_DIFF);
- else if (!strcmp(s, "diff-algorithm=")) {
- long value = parse_algorithm_value(s+15);
+ else if (!prefixcmp(s, "diff-algorithm=")) {
+ long value = parse_algorithm_value(s + strlen("diff-algorithm="));
if (value < 0)
return -1;
/* clear out previous settings */
--
1.8.4.566.g73d370b
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] merge-recursive: fix parsing of "diff-algorithm" option
2013-09-26 20:02 [PATCH] merge-recursive: fix parsing of "diff-algorithm" option John Keeping
@ 2013-09-26 20:47 ` Jonathan Nieder
2013-09-26 21:13 ` John Keeping
0 siblings, 1 reply; 3+ messages in thread
From: Jonathan Nieder @ 2013-09-26 20:47 UTC (permalink / raw)
To: John Keeping; +Cc: git, Luke Noel-Storr, Michal Privoznik
John Keeping wrote:
> The "diff-algorithm" option to the recursive merge strategy takes the
> name of the algorithm as an option, but it uses strcmp on the option
> string to check if it starts with "diff-algorithm=", meaning that this
> options cannot actually be used.
>
> Fix this by switching to prefixcmp. At the same time, clarify the
> following line by using strlen instead of a hard-coded length, which
> also makes it consistent with nearby code.
>
> Reported-by: Luke Noel-Storr <luke.noel-storr@integrate.co.uk>
> Signed-off-by: John Keeping <john@keeping.me.uk>
Thanks, both.
[...]
> --- a/merge-recursive.c
> +++ b/merge-recursive.c
> @@ -2069,8 +2069,8 @@ int parse_merge_opt(struct merge_options *o, const char *s)
> o->xdl_opts = DIFF_WITH_ALG(o, PATIENCE_DIFF);
> else if (!strcmp(s, "histogram"))
> o->xdl_opts = DIFF_WITH_ALG(o, HISTOGRAM_DIFF);
> - else if (!strcmp(s, "diff-algorithm=")) {
> - long value = parse_algorithm_value(s+15);
> + else if (!prefixcmp(s, "diff-algorithm=")) {
> + long value = parse_algorithm_value(s + strlen("diff-algorithm="));
> if (value < 0)
> return -1;
While we're here:
Part of the problem is that there are no tests for this option (or for
'git diff --diff-algorithm', or for the '[diff] algorithm'
configuration), so we didn't notice it didn't work until someone
actually tried it.
Do you have any examples of a diff or merge that works better with
some particular diff algorithm, that could be used in tests?
Ciao,
Jonathan
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] merge-recursive: fix parsing of "diff-algorithm" option
2013-09-26 20:47 ` Jonathan Nieder
@ 2013-09-26 21:13 ` John Keeping
0 siblings, 0 replies; 3+ messages in thread
From: John Keeping @ 2013-09-26 21:13 UTC (permalink / raw)
To: Jonathan Nieder; +Cc: git, Luke Noel-Storr, Michal Privoznik
On Thu, Sep 26, 2013 at 01:47:20PM -0700, Jonathan Nieder wrote:
> John Keeping wrote:
>
> > The "diff-algorithm" option to the recursive merge strategy takes the
> > name of the algorithm as an option, but it uses strcmp on the option
> > string to check if it starts with "diff-algorithm=", meaning that this
> > options cannot actually be used.
> >
> > Fix this by switching to prefixcmp. At the same time, clarify the
> > following line by using strlen instead of a hard-coded length, which
> > also makes it consistent with nearby code.
> >
> > Reported-by: Luke Noel-Storr <luke.noel-storr@integrate.co.uk>
> > Signed-off-by: John Keeping <john@keeping.me.uk>
>
> Thanks, both.
>
> [...]
> > --- a/merge-recursive.c
> > +++ b/merge-recursive.c
> > @@ -2069,8 +2069,8 @@ int parse_merge_opt(struct merge_options *o, const char *s)
> > o->xdl_opts = DIFF_WITH_ALG(o, PATIENCE_DIFF);
> > else if (!strcmp(s, "histogram"))
> > o->xdl_opts = DIFF_WITH_ALG(o, HISTOGRAM_DIFF);
> > - else if (!strcmp(s, "diff-algorithm=")) {
> > - long value = parse_algorithm_value(s+15);
> > + else if (!prefixcmp(s, "diff-algorithm=")) {
> > + long value = parse_algorithm_value(s + strlen("diff-algorithm="));
> > if (value < 0)
> > return -1;
>
> While we're here:
>
> Part of the problem is that there are no tests for this option (or for
> 'git diff --diff-algorithm', or for the '[diff] algorithm'
> configuration), so we didn't notice it didn't work until someone
> actually tried it.
>
> Do you have any examples of a diff or merge that works better with
> some particular diff algorithm, that could be used in tests?
The following is the same diff, but the first time using histogram and
then with myers.
I'm not sure whether we should encode specific diff output into general
tests though - I assume there's a reason why there aren't already tests
for this, but perhaps it's just that no one's written them yet.
-- >8 --
diff --git a/test.c b/test.c
index f3eae9e..55f0c37 100644
--- a/test.c
+++ b/test.c
@@ -1,9 +1,9 @@
-void bye(void)
-{
- printf("goodbye\n");
-}
-
void hello(void)
{
printf("hello\n");
}
+
+void bye(void)
+{
+ printf("goodbye\n");
+}
diff --git a/test.c b/test.c
index f3eae9e..55f0c37 100644
--- a/test.c
+++ b/test.c
@@ -1,9 +1,9 @@
-void bye(void)
+void hello(void)
{
- printf("goodbye\n");
+ printf("hello\n");
}
-void hello(void)
+void bye(void)
{
- printf("hello\n");
+ printf("goodbye\n");
}
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2013-09-26 21:13 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-09-26 20:02 [PATCH] merge-recursive: fix parsing of "diff-algorithm" option John Keeping
2013-09-26 20:47 ` Jonathan Nieder
2013-09-26 21:13 ` John Keeping
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).