MCPcopy Create free account
hub / github.com/libgit2/pygit2 / Reference_set_target

Function Reference_set_target

src/reference.c:338–388  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

336 " Message to use for the reflog.\n");
337
338PyObject *
339Reference_set_target(Reference *self, PyObject *args, PyObject *kwds)
340{
341 git_oid oid;
342 int err;
343 git_reference *new_ref;
344 PyObject *py_target = NULL;
345 const char *message = NULL;
346 char *keywords[] = {"target", "message", NULL};
347
348 CHECK_REFERENCE(self);
349
350 if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|s", keywords,
351 &py_target, &message))
352 return NULL;
353
354 /* Case 1: Direct */
355 if (GIT_REF_OID == git_reference_type(self->reference)) {
356 err = py_oid_to_git_oid_expand(self->repo->repo, py_target, &oid);
357 if (err < 0)
358 goto error;
359
360 err = git_reference_set_target(&new_ref, self->reference, &oid, message);
361 if (err < 0)
362 goto error;
363
364 git_reference_free(self->reference);
365 self->reference = new_ref;
366 Py_RETURN_NONE;
367 }
368
369 /* Case 2: Symbolic */
370 PyObject *tvalue;
371 char *c_name = pgit_borrow_fsdefault(py_target, &tvalue);
372 if (c_name == NULL)
373 return NULL;
374
375 err = git_reference_symbolic_set_target(&new_ref, self->reference, c_name, message);
376 Py_DECREF(tvalue);
377 if (err < 0)
378 goto error;
379
380 git_reference_free(self->reference);
381 self->reference = new_ref;
382
383 Py_RETURN_NONE;
384
385error:
386 Error_set(err);
387 return NULL;
388}
389
390
391PyDoc_STRVAR(Reference_name__doc__, "The full name of the reference.");

Callers

nothing calls this directly

Calls 3

py_oid_to_git_oid_expandFunction · 0.85
pgit_borrow_fsdefaultFunction · 0.85
Error_setFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…