treebuilder: set the attributes before sorting and inserting

We need to set the attributes before we try to insert it into the
vector, as the comparison function needs to know whether the entry is a
tree or not.
Merge pull request #2494 from libgit2/cmn/treebuilder-set-attribute

treebuilder: set the attributes before sorting and inserting