pijul_org / pijul

#405 Not so painless "cherry-picking"

Opened by MarvinHannott, on June 20, 2019
Open
MarvinHannott commented on June 20, 2019

I came across an issue which directly goes against the promise of painles "cherry-picking". I would have liked to upload the repo to the nest but I just couldn't get it working. But probably I was doing something wrong. I am using pijul 0.11 on windows.\r + \r + This is a very simple example using just one javascript file:\r + \r + On the master branch I recorded a simple function with a bug:\r +

function add(a, b) {\r                                                                                                                                                                                                                                                                                                                                                                             +
    a - b; // intentional bug\r                                                                                                                                                                                                                                                                                                                                                                    +
}\r                                                                                                                                                                                                                                                                                                                                                                                                +
```\r                                                                                                                                                                                                                                                                                                                                                                                              +
On the other branch I added another simple function to the file without a bug:\r                                                                                                                                                                                                                                                                                                                   +
```\r                                                                                                                                                                                                                                                                                                                                                                                              +
function add(a, b) {\r                                                                                                                                                                                                                                                                                                                                                                             +
    a - b;\r                                                                                                                                                                                                                                                                                                                                                                                       +
}\r                                                                                                                                                                                                                                                                                                                                                                                                +
\r                                                                                                                                                                                                                                                                                                                                                                                                 +
function sub(a, b) {\r                                                                                                                                                                                                                                                                                                                                                                             +
    a - b;\r                                                                                                                                                                                                                                                                                                                                                                                       +
}\r                                                                                                                                                                                                                                                                                                                                                                                                +
```\r                                                                                                                                                                                                                                                                                                                                                                                              +
Then I switched back to the master branch and fixed the error:\r                                                                                                                                                                                                                                                                                                                                   +
```\r                                                                                                                                                                                                                                                                                                                                                                                              +
function add(a, b) {\r                                                                                                                                                                                                                                                                                                                                                                             +
    a + b; // fix!\r                                                                                                                                                                                                                                                                                                                                                                               +
}\r                                                                                                                                                                                                                                                                                                                                                                                                +
```\r                                                                                                                                                                                                                                                                                                                                                                                              +
Then I switched back again to the other branch to apply the patch with the fix. This is what I got:\r                                                                                                                                                                                                                                                                                              +
```\r                                                                                                                                                                                                                                                                                                                                                                                              +
function add(a, b) {\r                                                                                                                                                                                                                                                                                                                                                                             +
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> \r                                                                                                                                                                                                                                                                                                                                                                +
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\r                                                                                                                                                                                                                                                                                                                                                                 +
    a - b;\r                                                                                                                                                                                                                                                                                                                                                                                       +
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< \r                                                                                                                                                                                                                                                                                                                                                                +
}\r                                                                                                                                                                                                                                                                                                                                                                                                +
\r                                                                                                                                                                                                                                                                                                                                                                                                 +
function sub(a, b) {\r                                                                                                                                                                                                                                                                                                                                                                             +
    a - b;\r                                                                                                                                                                                                                                                                                                                                                                                       +
================================ \r                                                                                                                                                                                                                                                                                                                                                                +
    a + b;\r                                                                                                                                                                                                                                                                                                                                                                                       +
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\r                                                                                                                                                                                                                                                                                                                                                                 +
}\r                                                                                                                                                                                                                                                                                                                                                                                                +
```\r                                                                                                                                                                                                                                                                                                                                                                                              +
I was very much surprised by this because the patch only changed one line. I did the same experiment with git and got a similar result. But the promise of pijul was that it produces correct merges. I understand that doesn't mean merge conflicts would never occur but if that were a more complex example a correct merge would be very difficult to achieve. Am I doing something wrong here?
pmeunier commented on June 21, 2019

Pijul 0.11 had all sorts of problems related to conflicts, and some problems related to branches. Can you try again on Pijul 0.12?

MarvinHannott commented on June 25, 2019

I have tried to get Pijul 0.12 to work but it always fails at compiling Nettle: \r + \r + failed to run custom build command for nettle-sys v1.0.1\r + process didn't exit successfully: /home/marvin/Desktop/pijul-0.12.0/target/release/build/nettle-sys-c11944b7ae12ed22/build-script-build (exit code: 101)\r + --- stderr\r + thread 'main' panicked at 'called Result::unwrap() on an Err value: Failure { command: ""pkg-config" "--libs" "--cflags" "nettle hogweed"", output: Output { status: ExitStatus(ExitStatus(256)), stdout: "", stderr: "Package nettle was not found in the pkg-config search path.\nPerhaps you should add the directory containing nettle.pc\'\nto the PKG_CONFIG_PATH environment variable\nNo package \'nettle\' found\nPackage hogweed was not found in the pkg-config search path.\nPerhaps you should add the directory containing hogweed.pc'\nto the PKG_CONFIG_PATH environment variable\nNo package 'hogweed' found\n" } }', src/libcore/result.rs:997:5\r+ \r + I am by no means a Rust expert so I don't really know what to do.

pmeunier commented on June 26, 2019

The following doesn't seem related to Rust:\r + \r + > Package nettle was not found in the pkg-config search path\r + \r + How about installing nettle? Sometimes clang is required as well.

krixano commented on July 12, 2019

He's on Windows... I couldn't even find any way to install nettle on Windows (unless I used msys or WSL)... so maybe you all should actually be testing on other platforms more? Also, this topic has been brought up multiple times on the discourse by different people.

cbmcday commented on July 18, 2019

Playing around with various test cases, looks like you are tickling a corner case common to most non-semantic diff functions.\r + \r + If you included your annotations -- "// intentional bug" in the base and branch file and "// fix!" on cherry pick -- then I would have expected the cherry pick to work.\r + \r + Here's a demo to show the subtlety:\r + \r + # make a repository\r + mkdir demo\r + cd demo \r + pijul init\r + \r + # add two files, which start out the same\r + cat <<EOF > first \r + function add(a, b) {\r + a - b;\r + } \r + EOF\r + cp first second\r + pijul add first second\r + pijul record -a -m 'baseline'\r + \r + # append the new function to those files.\r + cat <<EOF >> first\r + \r + function sub(a, b) {\r + a - b;\r + }\r + EOF\r + # second also gets a new first line inserted\r + echo "// Comments Here" | cat - first > second\r + \r + # Compute impact of changes\r + pijul diff first\r + pijul diff second\r + \r + What I'm seeing with version 0.12:\r + \r + $ pijul diff first\r + first\r + From line 1\r + \r + + a - b;\r + + }\r + + \r + + function sub(a, b) {\r + \r + $ pijul diff second\r + second\r + + // Comments Here\r + \r + From line 4\r + \r + +\r + + function sub(a, b) {\r + + a - b;\r + + }\r + \r + You can see the first diff thinks the new work is spliced inside of the original function leading to the results you see in the cherry pick. Simply adding in a first line takes a different path through diff code, and winds up blocking the lines for the new function. Try adding a new line at the start of the file on the branch and see what happens?\r+

cbmcday commented on July 18, 2019

EDIT: changed add to sub in the code above which appends the files.\r+ \r + If you grabbed my original code, you won't see the results I posted.