@@ -190,6 +190,36 @@ static VALUE rb_git_diff_patch_lines(VALUE self)
190
190
return INT2FIX (context + adds + dels );
191
191
}
192
192
193
+ static VALUE rb_git_diff_patch_bytesize (int argc , VALUE * argv , VALUE self )
194
+ {
195
+ git_patch * patch ;
196
+ size_t bytesize ;
197
+ VALUE rb_options ;
198
+ int options [3 ];
199
+ Data_Get_Struct (self , git_patch , patch );
200
+
201
+ memset (options , 0 , sizeof (options ));
202
+
203
+ rb_scan_args (argc , argv , "0:" , & rb_options );
204
+ if (!NIL_P (rb_options )) {
205
+ if (RTEST (rb_hash_aref (rb_options , CSTR2SYM ("include_context" )))) {
206
+ options [0 ] = 1 ;
207
+ }
208
+
209
+ if (RTEST (rb_hash_aref (rb_options , CSTR2SYM ("include_hunk_headers" )))) {
210
+ options [1 ] = 1 ;
211
+ }
212
+
213
+ if (RTEST (rb_hash_aref (rb_options , CSTR2SYM ("include_file_headers" )))) {
214
+ options [2 ] = 1 ;
215
+ }
216
+ }
217
+
218
+ bytesize = git_patch_size (patch , options [0 ], options [1 ], options [2 ]);
219
+
220
+ return INT2FIX (bytesize );
221
+ }
222
+
193
223
static int patch_print_cb (
194
224
const git_diff_delta * delta ,
195
225
const git_diff_hunk * hunk ,
@@ -235,6 +265,7 @@ void Init_rugged_patch(void)
235
265
236
266
rb_define_method (rb_cRuggedPatch , "stat" , rb_git_diff_patch_stat , 0 );
237
267
rb_define_method (rb_cRuggedPatch , "lines" , rb_git_diff_patch_lines , 0 );
268
+ rb_define_method (rb_cRuggedPatch , "bytesize" , rb_git_diff_patch_bytesize , -1 );
238
269
239
270
rb_define_method (rb_cRuggedPatch , "delta" , rb_git_diff_patch_delta , 0 );
240
271
0 commit comments