@@ -346,6 +346,22 @@ static int patch_print_cb(
346
346
return GIT_OK ;
347
347
}
348
348
349
+ static int patch_print_header_cb (
350
+ const git_diff_delta * delta ,
351
+ const git_diff_hunk * hunk ,
352
+ const git_diff_line * line ,
353
+ void * payload )
354
+ {
355
+ VALUE rb_str = (VALUE )payload ;
356
+
357
+ if (line -> origin == GIT_DIFF_LINE_FILE_HDR ) {
358
+ rb_str_cat (rb_str , line -> content , line -> content_len );
359
+ }
360
+
361
+ return GIT_OK ;
362
+ }
363
+
364
+
349
365
/*
350
366
* call-seq:
351
367
* patch.to_s -> str
@@ -363,6 +379,24 @@ static VALUE rb_git_diff_patch_to_s(VALUE self)
363
379
return rb_str ;
364
380
}
365
381
382
+ /*
383
+ * call-seq:
384
+ * patch.header -> str
385
+ *
386
+ * Returns only the header of the patch as a string.
387
+ */
388
+ static VALUE rb_git_diff_patch_header (VALUE self )
389
+ {
390
+ git_patch * patch ;
391
+ VALUE rb_str = rb_str_new (NULL , 0 );
392
+ Data_Get_Struct (self , git_patch , patch );
393
+
394
+ rugged_exception_check (git_patch_print (patch , patch_print_header_cb , (void * )rb_str ));
395
+
396
+ return rb_str ;
397
+ }
398
+
399
+
366
400
void Init_rugged_patch (void )
367
401
{
368
402
rb_cRuggedPatch = rb_define_class_under (rb_mRugged , "Patch" , rb_cObject );
@@ -375,6 +409,7 @@ void Init_rugged_patch(void)
375
409
376
410
rb_define_method (rb_cRuggedPatch , "delta" , rb_git_diff_patch_delta , 0 );
377
411
412
+ rb_define_method (rb_cRuggedPatch , "header" , rb_git_diff_patch_header , 0 );
378
413
rb_define_method (rb_cRuggedPatch , "to_s" , rb_git_diff_patch_to_s , 0 );
379
414
380
415
rb_define_method (rb_cRuggedPatch , "each_hunk" , rb_git_diff_patch_each_hunk , 0 );
0 commit comments