Theory/Example

Notes:

  • Below each modification is a table showing the tree before and after the change. These tables are not the point of this example. They are mostly irrelevant, and exist only to help you follow the example better.
  • Due to limitations in wiki syntax, newlines are represented as in these tables
  • Patch names strategically chosen to reflect when they were made and where they were originally made, but are otherwise meaningless.
  • Sequential composition of patches is here written in the old style — the rightmost patch is applied first.

initial record (patch lA)

repoLeft: initial record

[lA
author**20050424225158] {
addfile ./file
hunk ./file 1
+red
+blue
+green
}
before after history
red
blue
green
lA

repoRight modifications

repoRight: pull patch A from repoLeft, then change first line

[rD
author**20050424225453] {
hunk ./file 1
-red
+exRed
}
before after history
red
blue
green
exRed
blue
green
rD lA

repoRight: add pink at beginning

[rE
author**20050424225640] {
hunk ./file 1
+pink
}
before after history

exRed
blue
green
pink
exRed
blue
green
rE rD lA
  • observe that patches rE and rD are independent of each other

repoLeft modifications (patches lB, lC)

repoLeft: change second line

[lB
author**20050424225332] {
hunk ./file 2
-blue
+exBlue
}
before after history
red
blue
green
red
exBlue
green
lB lA

repoLeft: add line to end of file

[lC
author**20050424225356] {
hunk ./file 4
+cyan
}
before after history
red
exBlue
green
red
exBlue
green
cyan
lC lB lA
  • observe that patch lC is actually independent of patch lB

repoRight pull from repoLeft (commuting!)

repoRight: pull patch lB and lC from repoLeft, darcs commutes the patches lB and lC (??? with rE and rD? – FIXME, clarify) and changes the lines numbers

[lB
author**20050424225332] {
hunk ./file 3
-blue
+exBlue
}
[lC
author**20050424225356] {
hunk ./file 5
+cyan
}
before after history
pink
exRed
blue
green
pink
exRed
exBlue
green
cyan
lC’ lB’ rE rD lA

repoLeft pull from repoRight

repoLeft: pull patch rD and rE from repoRight, darcs just adds the patches rD and rE since no changes are needed (??? but this is deduced somehow (by commutation?); if not, why is it obvious that no changes are needed? – FIXME, clarify)

repoLeft contains lA lB lC rD rE now, repoRight contains lA rD rE lB’ lC’ where lB’ and lC’ produce the same result in a different context as their counterparts lB and lC produce in the original context. RepoLeft and repoRight can now exchange patches without conflicts.

repoLeft ||before||after||history|| ||redexBluegreencyan||pinkexRedexBluegreencyan||rE rD lC lB lA||

before after history
red
exBlue
green
cyan<br/
pink
exRed
exBlue
green
cyan
rE’rD’ lC lB lA

repoLeft make a new change

repoLeft: record patch changing line 2

[lF
author**20050424232202] {
hunk ./file 2
-exRed
+newRed
}
before after history
pink
exRed
exBlue
green
cyan
pink
newRed
exBlue
green
cyan
lF rE’rD’ lC lB lA

repoRight: can pull this patch without conflicts

See also Motivation and Questions