Commit 997c65b
committed
Fix the refdb backend rename callback
pygit2_refdb_backend_rename() had an inverted success check on
build_signature(): it returned an error precisely when the signature
was built successfully, and fell through with a NULL signature when
it failed, so the callback could never work. It also decref'd the
signature object twice (it is stolen into the argument tuple by
Py_BuildValue()'s N format), passed a borrowed reference to the
Py_True/Py_False singleton with N, and leaked the callback result
when it was not a Reference.
Two more bugs kept the function from working once the check was
fixed. The Python Signature takes ownership of the git_signature it
wraps, but _who belongs to libgit2 and is freed again on return;
pass a git_signature_dup() copy instead. And git_reference_dup()
cannot be used on the returned reference, because its db field is
only set by git_refdb_rename() after the callback returns; transfer
the pointer directly, as pygit2_refdb_backend_lookup() already does.
Also accept None for the message argument of RefdbBackend.rename():
libgit2 passes NULL when no log message is given (pygit2's
Reference.rename() always does), Py_BuildValue() maps that to None,
and the Python-side method must round-trip it back to NULL. This
matches the z format already used by write() and delete().
Add test_rename_callback, the first test to drive a custom refdb
backend through libgit2: assigning repo.backend only sets a Python
attribute, so the existing tests never exercised the C callbacks.
Fixes #1474
Assisted-by: Kimi Code1 parent eb512d2 commit 997c65b
3 files changed
Lines changed: 59 additions & 14 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
599 | 599 | | |
600 | 600 | | |
601 | 601 | | |
602 | | - | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
603 | 608 | | |
604 | 609 | | |
605 | 610 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
249 | 249 | | |
250 | 250 | | |
251 | 251 | | |
252 | | - | |
253 | | - | |
254 | 252 | | |
255 | 253 | | |
256 | | - | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
257 | 264 | | |
258 | | - | |
259 | | - | |
260 | | - | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
261 | 272 | | |
262 | 273 | | |
| 274 | + | |
263 | 275 | | |
264 | | - | |
265 | 276 | | |
266 | 277 | | |
267 | | - | |
| 278 | + | |
| 279 | + | |
268 | 280 | | |
| 281 | + | |
269 | 282 | | |
270 | 283 | | |
271 | 284 | | |
| 285 | + | |
272 | 286 | | |
273 | 287 | | |
274 | 288 | | |
275 | | - | |
276 | | - | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
277 | 293 | | |
278 | 294 | | |
279 | 295 | | |
| |||
625 | 641 | | |
626 | 642 | | |
627 | 643 | | |
628 | | - | |
| 644 | + | |
629 | 645 | | |
630 | 646 | | |
631 | 647 | | |
| |||
643 | 659 | | |
644 | 660 | | |
645 | 661 | | |
646 | | - | |
| 662 | + | |
647 | 663 | | |
648 | 664 | | |
649 | 665 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
| 44 | + | |
44 | 45 | | |
45 | 46 | | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
46 | 53 | | |
47 | 54 | | |
48 | 55 | | |
| |||
61 | 68 | | |
62 | 69 | | |
63 | 70 | | |
64 | | - | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
65 | 77 | | |
66 | 78 | | |
67 | 79 | | |
| |||
112 | 124 | | |
113 | 125 | | |
114 | 126 | | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
115 | 139 | | |
116 | 140 | | |
117 | 141 | | |
| |||
0 commit comments