@@ -657,28 +657,37 @@ static VALUE rb_git_diff_sorted_icase_p(VALUE self)
657
657
return git_diff_is_sorted_icase (diff ) ? Qtrue : Qfalse ;
658
658
}
659
659
660
- static VALUE rb_git_diff_from_string (VALUE contents )
660
+ /*
661
+ * call-seq: Diff.from_buffer(buffer) -> Rugged::Diff object
662
+ *
663
+ * Where +buffer+ is a +String+.
664
+ * Returns A Rugged::Diff object
665
+ */
666
+ static VALUE rb_git_diff_from_buffer (VALUE self , VALUE rb_buffer )
661
667
{
662
- git_diff * diff ;
663
- const char * buffer ;
668
+ git_diff * diff = NULL ;
669
+ const char * buffer ;
670
+ // const char *buffer = "diff --git a/file b/file\nnew file mode 100644\nindex 0000000..d5f7fc3\n--- /dev/null\n+++ b/file\n@@ -0,0 +1 @@\n+added\n" ;
664
671
size_t len ;
665
672
VALUE rb_diff ;
673
+ int error ;
666
674
667
- buffer = StringValuePtr (contents );
668
- len = strlen (buffer );
669
-
670
- git_diff_from_buffer (& diff , buffer , len );
671
-
672
- Data_Wrap_Struct (rb_cRuggedDiff , NULL , git_diff_free , diff );
675
+ Check_Type (rb_buffer , T_STRING );
676
+ buffer = RSTRING_PTR (rb_buffer );
677
+ len = RSTRING_LEN (rb_buffer );
673
678
674
- return rb_diff ;
679
+ error = git_diff_from_buffer (& diff , buffer , len );
680
+ rugged_exception_check (error );
681
+
682
+ rb_diff = Data_Wrap_Struct (rb_cRuggedDiff , NULL , git_diff_free , diff );
683
+ return rb_diff ;
675
684
}
676
685
677
686
void Init_rugged_diff (void )
678
687
{
679
688
rb_cRuggedDiff = rb_define_class_under (rb_mRugged , "Diff" , rb_cObject );
680
689
681
- rb_define_singleton_method (rb_cRuggedDiff , "new_from_string " , rb_git_diff_from_string , 1 );
690
+ rb_define_singleton_method (rb_cRuggedDiff , "from_buffer " , rb_git_diff_from_buffer , 1 );
682
691
683
692
rb_define_method (rb_cRuggedDiff , "patch" , rb_git_diff_patch , -1 );
684
693
rb_define_method (rb_cRuggedDiff , "write_patch" , rb_git_diff_write_patch , -1 );
0 commit comments