Adjust to libgit2's immutable refs

Reference objects are immutable now, which means that any operation
that affects the values returns a new object.

Accessing data from a deleted ref is also permissible now, as libgit2
doesn't free the memory.