23
23
*/
24
24
25
25
#include "rugged.h"
26
+ #include "git2/commit.h"
26
27
27
28
extern VALUE rb_mRugged ;
28
29
extern VALUE rb_cRuggedObject ;
@@ -556,6 +557,51 @@ static VALUE rb_git_commit_to_mbox(int argc, VALUE *argv, VALUE self)
556
557
return rb_email_patch ;
557
558
}
558
559
560
+ /*
561
+ * call-seq:
562
+ * commit.header_field(field_name) -> str
563
+ *
564
+ * Returns +commit+'s header field value.
565
+ */
566
+ static VALUE rb_git_commit_header_field (VALUE self , VALUE rb_field ) {
567
+ git_buf header_field = { 0 };
568
+ VALUE rb_result ;
569
+ git_commit * commit ;
570
+
571
+ Check_Type (rb_field , T_STRING );
572
+
573
+ Data_Get_Struct (self , git_commit , commit );
574
+
575
+ rugged_exception_check (
576
+ git_commit_header_field (& header_field , commit , StringValueCStr (rb_field ))
577
+ );
578
+
579
+ rb_result = rb_enc_str_new (header_field .ptr , header_field .size , rb_utf8_encoding ());
580
+
581
+ git_buf_free (& header_field );
582
+
583
+ return rb_result ;
584
+ }
585
+
586
+ /*
587
+ * call-seq:
588
+ * commit.header -> str
589
+ *
590
+ * Returns +commit+'s entire raw header.
591
+ */
592
+ static VALUE rb_git_commit_header (VALUE self ) {
593
+ VALUE rb_result ;
594
+ git_commit * commit ;
595
+ const char * raw_header ;
596
+
597
+ Data_Get_Struct (self , git_commit , commit );
598
+
599
+ raw_header = git_commit_raw_header (commit );
600
+
601
+ rb_result = rb_enc_str_new (raw_header , strlen (raw_header ), rb_utf8_encoding ());
602
+
603
+ return rb_result ;
604
+ }
559
605
560
606
void Init_rugged_commit (void )
561
607
{
@@ -579,4 +625,7 @@ void Init_rugged_commit(void)
579
625
rb_define_method (rb_cRuggedCommit , "amend" , rb_git_commit_amend , 1 );
580
626
581
627
rb_define_method (rb_cRuggedCommit , "to_mbox" , rb_git_commit_to_mbox , -1 );
628
+
629
+ rb_define_method (rb_cRuggedCommit , "header_field" , rb_git_commit_header_field , 1 );
630
+ rb_define_method (rb_cRuggedCommit , "header" , rb_git_commit_header , 0 );
582
631
}
0 commit comments