@@ -693,11 +693,77 @@ static VALUE rb_git_commit_extract_signature(int argc, VALUE *argv, VALUE self)
693
693
return ret ;
694
694
}
695
695
696
+ /*
697
+ * call-seq:
698
+ * Commit.create_to_s(repository, data = {}) -> str
699
+ *
700
+ * Create a string with the contents of the commit, created with the
701
+ * given +data+ arguments, passed as a +Hash+:
702
+ *
703
+ * - +:message+: a string with the full text for the commit's message
704
+ * - +:committer+ (optional): a hash with the signature for the committer,
705
+ * defaults to the signature from the configuration
706
+ * - +:author+ (optional): a hash with the signature for the author,
707
+ * defaults to the signature from the configuration
708
+ * - +:parents+: an +Array+ with zero or more parents for this commit,
709
+ * represented as <tt>Rugged::Commit</tt> instances, or OID +String+.
710
+ * - +:tree+: the tree for this commit, represented as a <tt>Rugged::Tree</tt>
711
+ * instance or an OID +String+.
712
+ *
713
+ * author = {:email=>"[email protected] ", :time=>Time.now, :name=>"Vicent Mart\303\255"}
714
+ *
715
+ * Rugged::Commit.create(r,
716
+ * :author => author,
717
+ * :message => "Hello world\n\n",
718
+ * :committer => author,
719
+ * :parents => ["2cb831a8aea28b2c1b9c63385585b864e4d3bad1"],
720
+ * :tree => some_tree) #=> "tree some_tree\nparent 2cb831...."
721
+ */
722
+ static VALUE rb_git_commit_create_to_s (VALUE self , VALUE rb_repo , VALUE rb_data )
723
+ {
724
+ int error = 0 ;
725
+ struct commit_data commit_data = { Qnil };
726
+ git_repository * repo ;
727
+ git_buf buf = { 0 };
728
+
729
+ Check_Type (rb_data , T_HASH );
730
+
731
+ rugged_check_repo (rb_repo );
732
+ Data_Get_Struct (rb_repo , git_repository , repo );
733
+
734
+ if ((error = parse_commit_options (& commit_data , repo , rb_data )) < 0 )
735
+ goto cleanup ;
736
+
737
+ error = git_commit_create_buffer (
738
+ & buf ,
739
+ repo ,
740
+ commit_data .author ,
741
+ commit_data .committer ,
742
+ NULL ,
743
+ commit_data .message ,
744
+ commit_data .tree ,
745
+ commit_data .parent_count ,
746
+ commit_data .parents );
747
+
748
+ cleanup :
749
+ free_commit_options (& commit_data );
750
+ if (!NIL_P (commit_data .rb_err_obj ))
751
+ rb_exc_raise (commit_data .rb_err_obj );
752
+
753
+ rugged_exception_check (error );
754
+
755
+ VALUE ret = rb_str_new_utf8 (buf .ptr );
756
+ git_buf_free (& buf );
757
+
758
+ return ret ;
759
+ }
760
+
696
761
void Init_rugged_commit (void )
697
762
{
698
763
rb_cRuggedCommit = rb_define_class_under (rb_mRugged , "Commit" , rb_cRuggedObject );
699
764
700
765
rb_define_singleton_method (rb_cRuggedCommit , "create" , rb_git_commit_create , 2 );
766
+ rb_define_singleton_method (rb_cRuggedCommit , "create_to_s" , rb_git_commit_create_to_s , 2 );
701
767
rb_define_singleton_method (rb_cRuggedCommit , "extract_signature" , rb_git_commit_extract_signature , -1 );
702
768
703
769
rb_define_method (rb_cRuggedCommit , "message" , rb_git_commit_message_GET , 0 );
0 commit comments