@@ -175,19 +175,56 @@ static VALUE rb_git_diff_patch_stat(VALUE self)
175
175
176
176
/*
177
177
* call-seq:
178
- * patch.lines -> int
178
+ * patch.lines(options = {}) -> int
179
+ *
180
+ * The following options can be passed in the +options+ Hash:
181
+ *
182
+ * :exclude_context ::
183
+ * Boolean value specifying that context line counts should be excluded from
184
+ * the returned total.
185
+ *
186
+ * :exclude_additions ::
187
+ * Boolean value specifying that addition line counts should be excluded from
188
+ * the returned total.
189
+ *
190
+ * :exclude_deletions ::
191
+ * Boolean value specifying that deletion line counts should be excluded from
192
+ * the returned total.
179
193
*
180
194
* Returns the total number of lines in the patch.
181
195
*/
182
- static VALUE rb_git_diff_patch_lines (VALUE self )
196
+ static VALUE rb_git_diff_patch_lines (int argc , VALUE * argv , VALUE self )
183
197
{
184
198
git_patch * patch ;
185
- size_t context , adds , dels ;
199
+ size_t context_lines , additions , deletions ;
200
+ size_t total_out ;
201
+ VALUE rb_options ;
186
202
Data_Get_Struct (self , git_patch , patch );
187
203
188
- git_patch_line_stats (& context , & adds , & dels , patch );
204
+ context_lines = 0 ;
205
+ additions = 0 ;
206
+ deletions = 0 ;
207
+
208
+ git_patch_line_stats (& context_lines , & additions , & deletions , patch );
209
+
210
+ total_out = context_lines + additions + deletions ;
211
+
212
+ rb_scan_args (argc , argv , "0:" , & rb_options );
213
+ if (!NIL_P (rb_options )) {
214
+ if (RTEST (rb_hash_aref (rb_options , CSTR2SYM ("exclude_context" )))) {
215
+ total_out -= context_lines ;
216
+ }
217
+
218
+ if (RTEST (rb_hash_aref (rb_options , CSTR2SYM ("exclude_additions" )))) {
219
+ total_out -= additions ;
220
+ }
221
+
222
+ if (RTEST (rb_hash_aref (rb_options , CSTR2SYM ("exclude_deletions" )))) {
223
+ total_out -= deletions ;
224
+ }
225
+ }
189
226
190
- return INT2FIX (context + adds + dels );
227
+ return INT2FIX (total_out );
191
228
}
192
229
193
230
static VALUE rb_git_diff_patch_bytesize (int argc , VALUE * argv , VALUE self )
@@ -264,7 +301,7 @@ void Init_rugged_patch(void)
264
301
rb_define_singleton_method (rb_cRuggedPatch , "from_strings" , rb_git_patch_from_strings , -1 );
265
302
266
303
rb_define_method (rb_cRuggedPatch , "stat" , rb_git_diff_patch_stat , 0 );
267
- rb_define_method (rb_cRuggedPatch , "lines" , rb_git_diff_patch_lines , 0 );
304
+ rb_define_method (rb_cRuggedPatch , "lines" , rb_git_diff_patch_lines , -1 );
268
305
rb_define_method (rb_cRuggedPatch , "bytesize" , rb_git_diff_patch_bytesize , -1 );
269
306
270
307
rb_define_method (rb_cRuggedPatch , "delta" , rb_git_diff_patch_delta , 0 );
0 commit comments