: <<COMMENT
file1 - =head(p1,m), *tail(p1,m)
o		r5 (1 2x 3y z 1 2x 3y)	p1:r3-r5: =1..5, *6..7;			p2:r4-r5: =1..3,+4..7
|\
| o		r4 (1 2x 3y)
o |		r3 (1 2x 3y z 1 2 3)		<---- in r5, head is unchanged, tail is merged with r4
| |		
o |		r2 (a b c z 1 2 3)
| o		r1 (1 2x 3)
|/
o		r0 (1 2 3)

file1bis - r3 without 123 tail, so that tail(p1,m) comes as 'added', not 'changed'
file5 below is r3 completely different than r5, i.e. *head(p1,m), +tail(p1,m)
file4 below is similar to r5 but =tail(p1,m)

file2 - similar to file1, but diff(base-p1) aka diff(r0-r3) gives incorrect map (shall map 123 to abc)
o		r5 (1 2x 3y a 2x 3y)	p1:r3-r5: =1..4, *5..6;			p2:r4-r5: =1..3,+4..6
|\
| o		r4 (1 2x 3y)
o |		r3 (1 2x 3y a b c)
| |		
o |		r2 (1 2 3 a b c)		<---- abc correspond to initial 123 lines
| |
o |		r1 (a b c)
|/
o		r0 (1 2 3)


      - =head(p1,m), *tail(p1,m)
file3 - shorter version of file2. Here I question which (sub)sequence of *(p1,m) shall I look for existence in p2 - (2x) and then (c1) or (2x c1)
o		r4 (1 2x 3y a 2x c1)		p1:r2-r4: =1..4, *5..6;		p2:r3-r4: =1..3,+4..6
|\
| o		r3 (1 2x 3y)
o |		r2 (1 2x 3y a b c)
| |
o |		r1 (a b c)
|/
o		r0 (1 2 3)
? file3bis with reversed line order in the tail: r4 (1 2x 3y a 3y 2x)



file4 - *head(p1,m), =tail(p1,m)
o		r5 (1 2x 3y z 1 2x 3y)		p1:r3-r5: =1..1,*2..3,=4..7		p2:r4-r5: =1..3, +4..7
|\
| o		r4 (1 2x 3y)
o |		r3 (1 2 3 z 1 2x 3y)		<---- in r5, head is merged with r4, tail goes into r5 unchaned
| |		
o |		r2 (a b 3 z 1 2 3)			<---- ab3z inserted in front of original lines (need 3z1 to match same in r3)
| o		r1 (1 2x 3)
|/
o		r0 (1 2 3)

my annotate with diff(p1->base-p2) strategy.   'hg annotate'
  3: 1											0: 1
  1: 2x											1: 2x
  4: 3y											4: 3y
  2: z											2: z
  0: 1											0: 1
  3: 2x											3: 2x
  3: 3y											

file5 - *head(p1,m), +tail(p1,m)
o		r5 (1 2x 3y z 1 2x 3y)		p1:r3-r5: *1..3, =4, +5..7;			p2:r4-r5: =1..3, +4..7
|\
| o		r4 (1 2x 3y)
o |		r3 (a b c z)				<---- intention: can't map to lines of base revision (lines of base revision gone)
| |		
o |		r2 (a b c z 1 2 3)
| o		r1 (1 2x 3)
|/
o		r0 (1 2 3)
? file5bis when I *can* map lines in r3 to lines in 'base'


file6
o		r4 (a b c 1 2x 3y)		p1:r2-r4: =1..4, *5..6;			p2:r3-r4: =1..3,+4..6 || +1..3,=4..6
|\
| o		r3 (1 2x 3y a b c)
o |		r2 (a b c 1 2 3)
| o		r1 (1 2x 3y)
|/
o		r0 (1 2 3)


?
o		r5 (1 2x 3y z 1 2x 3y)			p1:r3-r5: =1..4, ~5..7(5..8);			p2:r4-r5: =1..3,+4..7
|\
| o		r4 (1 2x 3y)					<---- diff(base,p2) =1(1), ~2..3
o |		r3 (1 2x 3y z 2 3  2  3)		<---- diff(p1,base) =1(1), +2..6, =7..8(2..3)
| |		
o |		r2 (a b c z 1 2 3)
| o		r1 (1 2x 3)
|/
o		r0 (1 2 3)

COMMENT

hg init

#r0
echo -e "1\n2\n3" > file1
echo -e "1\n2\n3" > file4
echo -e "1\n2\n3" > file5
hg add file1 file4 file5
hg ci -m "r0"

#r1
echo -e "1\n2x\n3" > file1
echo -e "1\n2x\n3" > file4
echo -e "1\n2x\n3" > file5
hg ci -m "r1"

#r2
hg up -r 0 -C
echo -e "a\nb\nc\nz\n1\n2\n3" > file1
echo -e "a\nb\n3\nz\n1\n2\n3" > file4
echo -e "a\nb\nc\nz\n1\n2\n3" > file5
hg ci -m "r2"

#r3
echo -e "1\n2x\n3y\nz\n1\n2\n3" > file1
echo -e "1\n2\n3\nz\n1\n2x\n3y" > file4
echo -e "a\nb\nc\nz" > file5
hg ci -m "r3"

#r4
hg up -r 1 -C
echo -e "1\n2x\n3y" > file1
echo -e "1\n2x\n3y" > file4
echo -e "1\n2x\n3y" > file5
hg ci -m "r4"

#r5
hg up -r 3 -C
hg merge -r 4 --tool internal:merge
echo -e "1\n2x\n3y\nz\n1\n2x\n3y" > file1
echo -e "1\n2x\n3y\nz\n1\n2x\n3y" > file4
echo -e "1\n2x\n3y\nz\n1\n2x\n3y" > file5
hg resolve -m
hg ci -m "r5"

