libgit2/libgit2 — pull request #743 by yorah (2012-06-04 20:57:44+00:00)
Title: Allow note creation in an already fanned out tree

Hello,

**Standard disclaimer**: this is my first PR on libgit2, and my C skills are very rusty, so please try to bear with me as much as you can ;)

While I was implementing support for notes in libgit2/libgit2sharp#140, I noticed a small bug during notes creations:
- when the first note was created on a new namespace, it was inserted in a fanned out tree (a first level fanout)
- then, the next notes added on this namespace would be inserted at the root of the tree
- however, when creating a note on a target whose SHA was starting with the same two characters than the first note, then some previously inserted notes were "disappearing"

After looking more thoroughly at it, I noticed that what was happening was that the fanned out tree created during the first note creation was replacing the root tree. Basically, it meant that creating notes in already fanned out trees was not working.

The behaviour introduced by this PR is:
- to be able to insert a new note in an already fanned out tree
- to be able to insert a note in the root tree if there is no already fanned out tree (it means I didn't implement native fanout creation in libgit2. Do we need it?)
- to be able to retrieve a note from a fanned out tree (created by git.git for instance)
- I also tried to refactor some code, mostly related to error handling.

I'm sure there is still work to do on the code side, but I wanted to share it with you before going further.

Could you please give me some feedback on this? Tell me if I'm going in the right direction, or if I'm totally mistaken?