[sync] Fix performance problem with GitModelCache#getChildren
The problem was that it returned a child for each changed file, instead
of only the direct children. So e.g. with changes in "dir/a", "dir/b"
and "dir/c", it returned a node for "dir" three times. When the number
of changes is significant, this resulted in many children returned, each
of which also has children which will be processed by the calling code.
The code in GitModelCommit for tree construction did it right. To fix
this, this change consolidates the two tree construction implementations
into one which should be correct.
It also takes care that the final tree nodes use as little memory as
possible by using arrays.
Bug: 396209
Change-Id: I0f139cf7747affb06b32cee584355cf60b46fb76