As above, the magic is supposed to be a SV, so this should be:

```
tmp = xs_object_magic_get_struct(aTHX_ SvRV(self));
ref = GIT_SV_TO_PTR(Reference, tmp);
```

where `tmp` is `SV *`.