From: NeilBrown Date: Wed, 13 Feb 2013 23:45:57 +0000 (+1100) Subject: merge: remove useless context from the end of a conflict. X-Git-Tag: v1.0~63 X-Git-Url: http://git.neil.brown.name/?a=commitdiff_plain;h=11da12692c1244203ce9634fa96c2e455cc6d9ef;p=wiggle.git merge: remove useless context from the end of a conflict. If we are close to the end-of-file, then don't expect too many unchanged lines. And allow zero lines of context in the merge if it is unchanged out side the merge. Update various tests to match - all clear improvements. Signed-off-by: NeilBrown --- diff --git a/merge2.c b/merge2.c index b2cc4cf..9f97c65 100644 --- a/merge2.c +++ b/merge2.c @@ -256,7 +256,7 @@ int isolate_conflicts(struct file af, struct file bf, struct file cf, int firstk = -1; for (k = 0 ; k < m[j].al ; k++) if (ends_line(af.list[m[j].a+k])) { - if (firstk <= 0) + if (firstk < 0) firstk = k; newlines++; if (newlines >= 3) { @@ -264,6 +264,11 @@ int isolate_conflicts(struct file af, struct file bf, struct file cf, break; } } + if (newlines < 3 && + m[j+1].type == End) + /* Hit end of file, pretend we found 3 newlines. */ + k = firstk; + if (firstk >= 0 && m[j+1].type == Unmatched) { /* If this Unmatched exceeds 3 lines, just stop here */ diff --git a/tests/linux/raid5build/merge b/tests/linux/raid5build/merge index 0fe41cd..eaff4ce 100644 --- a/tests/linux/raid5build/merge +++ b/tests/linux/raid5build/merge @@ -27,12 +27,10 @@ static void raid5_build_block (struct stripe_head *sh, int i) bh->b_size = sh->size; bh->b_list = BUF_LOCKED; return bh; -} ||||||| bh->b_size = sh->size; return bh; -} ======= dev->sector = compute_blocknr(sh, i); -} >>>>>>> +} diff --git a/tests/simple/all-different/merge b/tests/simple/all-different/merge index 28ee454..ab83c87 100644 --- a/tests/simple/all-different/merge +++ b/tests/simple/all-different/merge @@ -9,7 +9,6 @@ 8 9 0 -yes ||||||| a b @@ -21,7 +20,6 @@ g h i j -yes ======= A B @@ -33,5 +31,5 @@ G H I J -yes >>>>>>> +yes diff --git a/tests/simple/conflict/merge b/tests/simple/conflict/merge index fb97f49..4afaeff 100644 --- a/tests/simple/conflict/merge +++ b/tests/simple/conflict/merge @@ -2,11 +2,9 @@ this is a file with the word <<<<<<< two which is -misspelt ||||||| to which is -misspelt ======= too which is -misspelt >>>>>>> +misspelt diff --git a/tests/simple/conflictmixed/merge b/tests/simple/conflictmixed/merge index 5af8ed0..bb4d03c 100644 --- a/tests/simple/conflictmixed/merge +++ b/tests/simple/conflictmixed/merge @@ -2,11 +2,9 @@ this is a file with the word <<<<<<< two which is -misspelt ||||||| to which is -misspelt ======= too which was -misspelt >>>>>>> +misspelt diff --git a/tests/simple/multiple-add/merge b/tests/simple/multiple-add/merge index 312609f..f2a4151 100644 --- a/tests/simple/multiple-add/merge +++ b/tests/simple/multiple-add/merge @@ -7,11 +7,9 @@ of the <<<<<<< file. - ||||||| file - ======= file that has changed - >>>>>>> + diff --git a/tests/simple/show-wiggle-1/Wmerge b/tests/simple/show-wiggle-1/Wmerge index 805a091..2bb7d41 100644 --- a/tests/simple/show-wiggle-1/Wmerge +++ b/tests/simple/show-wiggle-1/Wmerge @@ -1,17 +1,14 @@ <<<<<<< This is one line of the file - ||||||| This is 1 line of the file - ======= This is 1 line of the document - &&&&&&& This is one line of the document - >>>>>>> + I think this is another line So is this