Method: Rugged::Commit#header_field

Defined in:
ext/rugged/rugged_commit.c

#header_field(field_name) ⇒ String

Returns commit‘s header field value.

Returns:

  • (String)


666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
# File 'ext/rugged/rugged_commit.c', line 666

static VALUE rb_git_commit_header_field(VALUE self, VALUE rb_field)
{
  git_buf header_field = { 0 };
  git_commit *commit = NULL;

  const char *encoding_name;
  rb_encoding *encoding = rb_utf8_encoding();
  VALUE rb_result;

  int error;

  Check_Type(rb_field, T_STRING);
  TypedData_Get_Struct(self, git_commit, &rugged_object_type, commit);

  error = git_commit_header_field(&header_field, commit, StringValueCStr(rb_field));

  if (error < 0) {
    git_buf_dispose(&header_field);
    if (error == GIT_ENOTFOUND)
      return Qnil;
    rugged_exception_check(error);
  }

  encoding_name = git_commit_message_encoding(commit);
  if (encoding_name != NULL)
    encoding = rb_enc_find(encoding_name);

  rb_result = rb_enc_str_new(header_field.ptr, header_field.size, encoding);
  git_buf_dispose(&header_field);
  return rb_result;
}