The sound distributed version control system

#928 Questions about order conflict

Opened by hardy7cc on April 6, 2024
hardy7cc on April 6, 2024

Order conflict questions

I was reading through this blog post and did fiddle with order conflicts. Which lead me to some questions about them.

See the shell script at the end to setup an example repo which I will base this discuss on. The scenario is simple there is a file (conflict.txt) with some text and then in parallel alice and bob add a new line at the same spot(using their own channels). Then both of these changes are pulled into the main channel resulting in an order conflict.

  • The order in what I pull in the changes do determine how they are presented. e.g. If I pull alice and then bob the resulting conflict does show alice's line first and bob's line second. If I pull the other way around the shown order is the other way around.
    • This seems reasonable to me. However there is one thing I can not make up my mind. Is it possible that this could lead to a different outcome after resolving this? I would expect no, isn't this the whole point behind pijul.
  • Now the difficult part solving the conflict. The expected outcome is a new change which does solve the conflict. However there are various reasonable solutions so lets first go over all the reasonable scenarios and then do some discussion based on that.
    1. None of the new lines are required. While this seems unreasonable for this particular example in real world there could be changes in other files.
    2. alice's and bob's line are required. And they are already in the correct order so only the conflict markers have to be removed.
    3. bob's and alice's line are required. And they are in the wrong order so when removing the conflict markers adjust the hunk order.
    4. A combination of both lines. So basically combine the meaning of alice's and bob's line.
  • Below I added the output of “pijul diff” for all scenarios. Questions:
    • Scenario 2 and 3 contain a hunk “Solving an order conflict”. However whats about 1 and 4? Is this due to the fact that 1 and 4 basically removed the lines and therefore there is no conflict anymore which would require conflict resolution?
    • Why does scenario 3 does contain the addition and removal of the same line as of bob's change? I basically wonder why does scenario 2 only require the information that we solved the order conflict but 3 also that extra hunks? This seems especially confusing if I look back where I stated that the order of pulling first alice's and then bob's changes or vice versa should not change anything.

Conflict resolution scenarios

Diff output scenario 1

>pijul diff
message = ''
timestamp = '2024-04-06T12:02:03.964989080Z'
authors = []

# Dependencies
[2] SBBT3VQVPAMBJNUEETXX4J5ZLMGX3R4TDBISJ5LWPVINBQCS47EAC # Alice change
[3] AXFO4RLKX3C6N4BIKRRJNXFCAD5JNBL62YFI5TEADUZ2ZUFTMZ7AC # Bob change
[4]+HH5IX3PGVYMTMDQ6GS762J2STARGUNMPIDNJ7KIMQZ6656REPFSQC # Base setup
[*] HH5IX3PGVYMTMDQ6GS762J2STARGUNMPIDNJ7KIMQZ6656REPFSQC # Base setup

# Hunks

1. Edit in "conflict.txt":2 4.1 "UTF-8"
B:BD 4.23 -> 2.1:19/2, B:BD 4.23 -> 3.1:17/3
- new line by alice
- new line by bob

Diff output scenario 2

>pijul diff
message = ''
timestamp = '2024-04-06T12:02:10.455050181Z'
authors = []

# Dependencies
[2] SBBT3VQVPAMBJNUEETXX4J5ZLMGX3R4TDBISJ5LWPVINBQCS47EAC # Alice change
[3] AXFO4RLKX3C6N4BIKRRJNXFCAD5JNBL62YFI5TEADUZ2ZUFTMZ7AC # Bob change
[4]+HH5IX3PGVYMTMDQ6GS762J2STARGUNMPIDNJ7KIMQZ6656REPFSQC # Base setup

# Hunks

1. Solving an order conflict in "conflict.txt":3 4.1 "UTF-8"
  up 2.19, new 2:2, down 3.1

Diff output scenario 3

>pijul diff
message = ''
timestamp = '2024-04-06T12:02:15.633334331Z'
authors = []

# Dependencies
[2] SBBT3VQVPAMBJNUEETXX4J5ZLMGX3R4TDBISJ5LWPVINBQCS47EAC # Alice change
[3] AXFO4RLKX3C6N4BIKRRJNXFCAD5JNBL62YFI5TEADUZ2ZUFTMZ7AC # Bob change
[4]+HH5IX3PGVYMTMDQ6GS762J2STARGUNMPIDNJ7KIMQZ6656REPFSQC # Base setup
[*] HH5IX3PGVYMTMDQ6GS762J2STARGUNMPIDNJ7KIMQZ6656REPFSQC # Base setup

# Hunks

1. Edit in "conflict.txt":2 4.1 "UTF-8"
  up 4.23, new 1:17, down 2.1
+ new line by bob

2. Edit in "conflict.txt":4 4.1 "UTF-8"
B:BD 4.23 -> 3.1:17/3
- new line by bob

3. Solving an order conflict in "conflict.txt":4 4.1 "UTF-8"
  up 2.19, new 19:19, down 4.23

Diff output scenario 4

>pijul diff
message = ''
timestamp = '2024-04-06T12:03:51.920903210Z'
authors = []

# Dependencies
[2] SBBT3VQVPAMBJNUEETXX4J5ZLMGX3R4TDBISJ5LWPVINBQCS47EAC # Alice change
[3] AXFO4RLKX3C6N4BIKRRJNXFCAD5JNBL62YFI5TEADUZ2ZUFTMZ7AC # Bob change
[4]+HH5IX3PGVYMTMDQ6GS762J2STARGUNMPIDNJ7KIMQZ6656REPFSQC # Base setup
[*] HH5IX3PGVYMTMDQ6GS762J2STARGUNMPIDNJ7KIMQZ6656REPFSQC # Base setup

# Hunks

1. Replacement in "conflict.txt":2 4.1 "UTF-8"
B:BD 4.23 -> 2.1:19/2, B:BD 4.23 -> 3.1:17/3
  up 4.23, new 1:27, down 4.23
- new line by alice
- new line by bob
+ new line by bob and alice

Setup example repository script

#!/bin/sh

#provide repo name as first param or default to "repo"
repo_path="${1:-repo}"

pijul init "$repo_path"
(
    cd "$repo_path" || exit

    # Create the initial file and record it.
    cat > conflict.txt << EOF
Line before conflict
Line after conflict
EOF

    pijul add conflict.txt
    pijul record -a -m "Base setup"

    # create two channels to record a conflicting change onto them.
    pijul fork --channel main alice
    pijul fork --channel main bob

    # alice change file content and record
    cat > conflict.txt << EOF
Line before conflict
new line by alice
Line after conflict
EOF
    pijul record --channel alice -a -m "Alice change"

    # bob change file content and record
    cat > conflict.txt << EOF
Line before conflict
new line by bob
Line after conflict
EOF
    pijul record --channel bob -a -m "Bob change"

    # reset working copy
    pijul reset .

    # pull both alice and bobs changes back into main
    pijul pull . -a --from-channel alice
    pijul pull . -a --from-channel bob

    # the pull order of the changes do have impact
    #pijul pull . -a --from-channel bob
    #pijul pull . -a --from-channel alice

)

I hope the questions above are reasonable and we can find an answer to them.

tankf33der on April 6, 2024

There is my output of test run.

$ ./928.sh 
Repository created at repo
Tracked 1 path(s)
Hash: 2GRYAON3N7FQKCPOTGXDE35A4YO24VF4XE654XMCGUJ5P43Y2GMAC
Hash: ABEDC3CBR666JLT3C5PEDSHPOW5M4LASACYL2QHVMJICXVGXORGAC
Hash: ELD7YFZX6ONVSGCX3KR3NCN5NY7NPP4QR3QYMY25TPLD2X4SSCJQC
Outputting repository... done!
Reset given paths to last recorded change
Downloading changes  [==================================================] 1/1 [00:00:00]
Applying changes     [==================================================] 1/1 [00:00:00]
Downloading changes  [==================================================] 1/1 [00:00:00]
Completing changes... done!
Outputting repository... done!
Downloading changes  [==================================================] 1/1 [00:00:00]
Applying changes     [==================================================] 1/1 [00:00:00]
Downloading changes  [==================================================] 1/1 [00:00:00]
Completing changes... done!
Outputting repository..                                                                                                                                                           
There were conflicts:

  - Order conflict in "conflict.txt" starting on line 2
Outputting repository... done!