@@ -563,77 +563,53 @@ static VALUE rb_git_commit_to_mbox(int argc, VALUE *argv, VALUE self)
563
563
*
564
564
* Returns +commit+'s header field value.
565
565
*/
566
- static VALUE rb_git_commit_header_field (VALUE self , VALUE rb_field ) {
566
+ static VALUE rb_git_commit_header_field (VALUE self , VALUE rb_field )
567
+ {
567
568
git_buf header_field = { 0 };
569
+ git_commit * commit = NULL ;
570
+
571
+ const char * encoding_name ;
572
+ rb_encoding * encoding = rb_utf8_encoding ();
568
573
VALUE rb_result ;
569
- git_commit * commit ;
574
+
570
575
int error ;
571
576
572
577
Check_Type (rb_field , T_STRING );
573
-
574
578
Data_Get_Struct (self , git_commit , commit );
575
579
576
580
error = git_commit_header_field (& header_field , commit , StringValueCStr (rb_field ));
577
581
578
- if (error == GIT_ENOTFOUND ) {
582
+ if (error < 0 ) {
579
583
git_buf_free (& header_field );
580
- return Qnil ;
584
+ if (error == GIT_ENOTFOUND )
585
+ return Qnil ;
586
+ rugged_exception_check (error );
581
587
}
582
588
583
- rugged_exception_check ( error );
584
-
585
- rb_result = rb_enc_str_new ( header_field . ptr , header_field . size , rb_utf8_encoding () );
589
+ encoding_name = git_commit_message_encoding ( commit );
590
+ if ( encoding_name != NULL )
591
+ encoding = rb_enc_find ( encoding_name );
586
592
593
+ rb_result = rb_enc_str_new (header_field .ptr , header_field .size , encoding );
587
594
git_buf_free (& header_field );
588
-
589
595
return rb_result ;
590
596
}
591
597
592
- /*
593
- * call-seq:
594
- * commit.header_field?(field_name) -> bool
595
- *
596
- * Returns true if header field is present, false otherwise.
597
- */
598
- static VALUE rb_git_commit_header_field_present (VALUE self , VALUE rb_field ) {
599
- git_buf header_field = { 0 };
600
- git_commit * commit ;
601
- int error ;
602
-
603
- Check_Type (rb_field , T_STRING );
604
-
605
- Data_Get_Struct (self , git_commit , commit );
606
-
607
- error = git_commit_header_field (& header_field , commit , StringValueCStr (rb_field ));
608
-
609
- git_buf_free (& header_field );
610
-
611
- if (error == GIT_ENOTFOUND )
612
- return Qfalse ;
613
-
614
- rugged_exception_check (error );
615
-
616
- return Qtrue ;
617
- }
618
-
619
598
/*
620
599
* call-seq:
621
600
* commit.header -> str
622
601
*
623
602
* Returns +commit+'s entire raw header.
624
603
*/
625
- static VALUE rb_git_commit_header (VALUE self ) {
626
- VALUE rb_result ;
604
+ static VALUE rb_git_commit_header (VALUE self )
605
+ {
627
606
git_commit * commit ;
628
607
const char * raw_header ;
629
608
630
609
Data_Get_Struct (self , git_commit , commit );
631
610
632
611
raw_header = git_commit_raw_header (commit );
633
-
634
- rb_result = rb_enc_str_new (raw_header , strlen (raw_header ), rb_utf8_encoding ());
635
-
636
- return rb_result ;
612
+ return rb_str_new_utf8 (raw_header );
637
613
}
638
614
639
615
void Init_rugged_commit (void )
@@ -660,6 +636,5 @@ void Init_rugged_commit(void)
660
636
rb_define_method (rb_cRuggedCommit , "to_mbox" , rb_git_commit_to_mbox , -1 );
661
637
662
638
rb_define_method (rb_cRuggedCommit , "header_field" , rb_git_commit_header_field , 1 );
663
- rb_define_method (rb_cRuggedCommit , "header_field?" , rb_git_commit_header_field_present , 1 );
664
639
rb_define_method (rb_cRuggedCommit , "header" , rb_git_commit_header , 0 );
665
640
}
0 commit comments