Method: Rugged::Reference#peel

Defined in:
ext/rugged/rugged_reference.c

#peelObject

Peels tag objects to the sha that they point at. Replicates git show-ref –dereference.



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'ext/rugged/rugged_reference.c', line 68

static VALUE rb_git_ref_peel(VALUE self)
{
  /* Leave room for \0 */
  git_reference *ref;
  git_object *object;
  char oid[GIT_OID_HEXSZ + 1];
  int error;

  Data_Get_Struct(self, git_reference, ref);

  error = git_reference_peel(&object, ref, GIT_OBJ_ANY);
  if (error == GIT_ENOTFOUND)
    return Qnil;
  else
    rugged_exception_check(error);

  if (git_reference_type(ref) == GIT_REF_OID &&
      !git_oid_cmp(git_object_id(object), git_reference_target(ref))) {
    git_object_free(object);
    return Qnil;
  } else {
    git_oid_tostr(oid, sizeof(oid), git_object_id(object));
    git_object_free(object);
    return rb_str_new_utf8(oid);
  }
}