anchor.diff:  
   
   stem(Trees, Limit) ->
  -    % flatten each branch in a tree into a tree path
  -    Paths = get_all_leafs_full(Trees),
  -
  -    Paths2 = [{Pos, lists:sublist(Path, Limit)} || {Pos, Path} <- Paths],
  +    % flatten each branch in a tree into a tree path, sort by starting rev #
  +    Paths = lists:sort(lists:map(fun({Pos, Path}) ->
  +        StemmedPath = lists:sublist(Path, Limit),
  +        {Pos + 1 - length(StemmedPath), StemmedPath}
  +    end, get_all_leafs_full(Trees))),
   
       % convert paths back to trees
       lists:foldl(
  -        fun({PathPos, Path},TreeAcc) ->
  +        fun({StartPos, Path},TreeAcc) ->
               [SingleTree] = lists:foldl(
                   fun({K,V},NewTreeAcc) -> [{K,V,NewTreeAcc}] end, [], Path),
  -            {NewTrees, _} = merge(TreeAcc, {PathPos + 1 - length(Path), SingleTree}),
  +            {NewTrees, _} = merge(TreeAcc, {StartPos, SingleTree}),
               NewTrees
  -        end, [], Paths2).
  +        end, [], Paths).
  +
  +
  +value_pref(Tuple, _) when is_tuple(Tuple),
  +        (tuple_size(Tuple) == 3 orelse tuple_size(Tuple) == 4) ->
  +    Tuple;
  +value_pref(_, Tuple) when is_tuple(Tuple),
  +        (tuple_size(Tuple) == 3 orelse tuple_size(Tuple) == 4) ->
  +    Tuple;
  +value_pref(?REV_MISSING, Other) ->
  +    Other;
  +value_pref(Other, ?REV_MISSING) ->
  +    Other;
  +value_pref(Last, _) ->
  +    Last.
  +
   
   % Tests moved to test/etap/06?-*.t
   
  
positive.code:     {B, false};
  merge_simple(A, []) ->
      {A, false};
  merge_simple([{Key, Value, SubA} | NextA], [{Key, _, SubB} | NextB]) ->
      {MergedSubTree, Conflict1} = merge_simple(SubA, SubB),
      {MergedNextTree, Conflict2} = merge_simple(NextA, NextB),
      {[{Key, Value, MergedSubTree} | MergedNextTree], Conflict1 or Conflict2};
  merge_simple([{A, _, _} = Tree | Next], [{B, _, _} | _] = Insert) when A < B ->
      {Merged, Conflict} = merge_simple(Next, Insert),
  
negative.code:     % filter out any that are in the keys list.
      {FilteredPaths, RemovedKeys} = filter_leafs(Paths, Keys, [], []),
  
      SortedPaths = lists:sort(
          [{Pos + 1 - length(Path), Path} || {Pos, Path} <- FilteredPaths]
      ),
  
      % convert paths back to trees
      NewTree = lists:foldl(
          fun({StartPos, Path},TreeAcc) ->
              [SingleTree] = lists:foldl(
                  fun({K,V},NewTreeAcc) -> [{K,V,NewTreeAcc}] end, [], Path),
              {NewTrees, _} = merge(TreeAcc, {StartPos, SingleTree}),
              NewTrees
          end, [], SortedPaths),
      {NewTree, RemovedKeys}.
  
  
  