[Bug 6174] New: merge could probably be smarter and produce more correct results in some obscure cases
mercurial-bugs at mercurial-scm.org
mercurial-bugs at mercurial-scm.org
Thu Jul 18 15:10:12 UTC 2019
https://bz.mercurial-scm.org/show_bug.cgi?id=6174
Bug ID: 6174
Summary: merge could probably be smarter and produce more
correct results in some obscure cases
Product: Mercurial
Version: stable branch
Hardware: All
OS: All
Status: UNCONFIRMED
Severity: feature
Priority: wish
Component: Mercurial
Assignee: bugzilla at mercurial-scm.org
Reporter: durin42 at gmail.com
CC: mercurial-devel at mercurial-scm.org
Consider the below as a .t-test:
Test case taken from
https://tahoe-lafs.org/~zooko/badmerge/concrete-good-semantics.html
$ hg init badmerge
$ cd badmerge
$ cat >main.c <<EOF
> int square(int x) {
> int y = x;
> /* Update y to equal the result. */
> /* Question: what is the order of magnitude of this algorithm with
respect to x? */
> for (int i = 0; i < x; i++) y += x;
> return y;
> }
> EOF
$ hg addr
adding main.c
$ hg ci -m a
$ cat > main.c <<EOF
> int very_slow_square(int x) {
> int y = 0;
> /* Update y to equal the result. */
> /* Question: what is the order of magnitude of this algorithm with
respect to x? */
> for (int i = 0; i < x; i++)
> for (int j = 0; j < x; j++)
> y += 1;
> return y;
> }
>
> int square(int x) {
> int y = x;
> /* Update y to equal the result. */
> /* Question: what is the order of magnitude of this algorithm with
respect to x? */
> for (int i = 0; i < x; i++) y += x;
> return y;
> }
> EOF
$ hg ci -m b1
$ cat > main.c <<EOF
> int square(int x) {
> int y = x;
> /* Update y to equal the result. */
> /* Question: what is the order of magnitude of this algorithm with
respect to x? */
> return y * x;
> }
>
> int very_slow_square(int x) {
> int y = 0;
> /* Update y to equal the result. */
> /* Question: what is the order of magnitude of this algorithm with
respect to x? */
> for (int i = 0; i < x; i++)
> for (int j = 0; j < x; j++)
> y += 1;
> return y;
> }
>
> int slow_square(int x) {
> int y = x;
> /* Update y to equal the result. */
> /* Question: what is the order of magnitude of this algorithm with
respect to x? */
> for (int i = 0; i < x; i++) y += x;
> return y;
> }
> EOF
$ hg ci -m b2
$ hg co 0
1 files updated, 0 files merged, 0 files removed, 0 files unresolved
$ cat > main.c <<EOF
> int square(int x) {
> int y = 0;
> /* Update y to equal the result. */
> /* Question: what is the order of magnitude of this algorithm with
respect to x? */
> for (int i = 0; i < x; i++) y += x;
> return y;
> }
> EOF
$ hg ci -m c1
created new head
$ hg merge
merging main.c
0 files updated, 1 files merged, 0 files removed, 0 files unresolved
(branch merge, don't forget to commit)
$ hg ci -m merge
$ cat > main.c <<EOF
> int square(int x) {
> int y = x;
> /* Update y to equal the result. */
> /* Question: what is the order of magnitude of this algorithm with
respect to x? */
> return y * x;
> }
>
> int very_slow_square(int x) {
> int y = 0;
> /* Update y to equal the result. */
> /* Question: what is the order of magnitude of this algorithm with
respect to x? */
> for (int i = 0; i < x; i++)
> for (int j = 0; j < x; j++)
> y += 1;
> return y;
> }
>
> int slow_square(int x) {
> int y = 0;
> /* Update y to equal the result. */
> /* Question: what is the order of magnitude of this algorithm with
respect to x? */
> for (int i = 0; i < x; i++) y += x;
> return y;
> }
> EOF
BUG: `hg diff` should be empty here, but we resolve the merge "wrong":
$ hg diff
diff -r 0a91f3f63b84 main.c
--- a/main.c Thu Jan 01 00:00:00 1970 +0000
+++ b/main.c Thu Jan 01 00:00:00 1970 +0000
@@ -1,5 +1,5 @@
int square(int x) {
- int y = 0;
+ int y = x;
/* Update y to equal the result. */
/* Question: what is the order of magnitude of this algorithm with
respect to x? */
return y * x;
@@ -16,7 +16,7 @@
}
int slow_square(int x) {
- int y = x;
+ int y = 0;
/* Update y to equal the result. */
/* Question: what is the order of magnitude of this algorithm with
respect to x? */
for (int i = 0; i < x; i++) y += x;
It's pretty clear that the merged text as produced by hg is wrong (cat it if
you don't see the bug in the resulting .c file). zooko's doc claims we should
be able to do better, and I don't really have any reason to disagree. Filing
this mostly as a way to hang on to the test case, as I wrote it mostly to see
if we'd fixed this or not.
--
You are receiving this mail because:
You are on the CC list for the bug.
More information about the Mercurial-devel
mailing list