

A -- latest revision on branch A
B -- latest revision on branch B
WD -- a project tree on both A and B


B_mergept (A) is a0,b0  (at revision a0, A added b0, but no other
			 patches from B since then)

A_mergept (B) is b1,a1	(at revision b0, B added a0, but no other
			 patches from A since then)

A_lvl (WD) is ax
B_lvl (WD) is bx

A_lvl (B) is a1
B_lvl (A) is b0

Presume that A and B have been mutually merged, but only in 
cumulative ways.  Thus, either:

	(a0 < a1) and (b0 < b1)		OR 	(a1 < a0) and (b0 < b1)


Assume without loss of generality that:

	(a0 < a1) and (b0 < b1)

	a0 is earlier than a1, b0 earlier than b1

	so: A has been merged into B more recently than B into A

Assume WITH loss of generality that:

	((ax = A) && (bx = b0))  or ((bx = B) && (ax = a1))

because, those states are the expected case...WD is checked out from either
A or B.   

WD may have local mods.

p-merge perm(WD, A, B)

	should form a working dir that is up-to-date with A, B, and includes local changes
	in WD.  The permutation determines precedence, e.g.:

		p-merge A WD B

	means, start with A, add the local changes from WD, add the changes from B


Two normal cases for which tree is WD up-to-date with:

	ax = A, bx = b0
	bx = B, ax = a1


Times six permutations:

	WD A B
	WD B A
	A WD B
	A B WD
	B A WD
	B WD A

Twelve normal cases total:

    ax = A, bx = b0

	cached tree:
		A

	A WD B
	WD A B				WD B
	WD B A
	  WD := delta(a1, B)[WD]

		delta (a1, B) is:

		delta (b1, B) o delta (a1, b1)
			delta (b1, B) is a computable combination
			of patch sets

			delta (a1, b1) can be cheaply computed and
			stored when b1 is committed


	A B WD
	  tmp := delta (a1, B)[A]
	  WD := delta (A, WD)[tmp]

	B A WD				B WD
	B WD A

	  WD := delta (a1, WD) [B]

		delta (a1, WD)
		== delta (A, WD) o delta (a1, A)
		   delta (a1, A) is a computable combination of 
			patch sets

		   deleta (A, WD) is computable from project tree

		   delta (A, WD) o delta (a1, A) is computable
			combination of patch sets


    ax = a1, bx = B

	cached tree:
		B

	B WD A
	WD B A
	WD A B
	   delta (a1, A)[WD]

			computable delta

	B A WD
	   tmp := delta (a1, A)[B]
	   WD := delta (B, WD)[tmp]

	A B WD
	A WD B

	  WD := delta (a1, WD) [A]   (update! or,
					delta(a1,WD) = delta (B, WD) o delta (a1, B) (see above)


Are There Four Special Cases?

	b0 = <none>, ax = A, bx = <none>, a1 != <none>
	a1 = <none>, ax = <none>, bx = B, b0 != <none>

Times six permutations:

	WD A B
	WD B A
	A WD B
	A B WD
	B A WD
	B WD A

Twelve Special Cases

	b0 = <none>, ax = A, bx = <none>, a1 != <none>

		WD A B
		A WD B
		WD B A
			delta (a1, B) [WD]


		A B WD
			tmp := delta (a1, B)[A]
			WD := delta (A, WD)[tmp]

		B A WD
		B WD A

		  	WD := delta (a1, WD) [B]

	   same as ordinary ax = A cases!



	a1 = <none>, ax = <none>, bx = B, b0 != <none>

		This case violates the assumption that (a0 < a1):
		swap A and B, then it reduces to the previous case.



One More Special Case

	b0 = <none>, a1 = <none>, ax = A, bx = <none>
		(ax = A w/out loss of generality)

	but that is not a star topology: neither A nor B is a branch
	of the other.

	if the two trees are branches of branches .... 
	user's can figure out how to use `join'


# tag: Tom Lord Sat Jan  5 13:45:59 2002 (manual/=merges)
#
