rugged 0.25.0b6 → 0.25.0b7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ext/rugged/rugged_patch.c +110 -25
- data/lib/rugged/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bc3490bf1a853d0f30e8c825dca468582cb12e2f
|
4
|
+
data.tar.gz: 9799cb94e85aaacd3aac5be5e2381acd65a1239a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 756066193b6fce22cd1a2af4818a58c785dbbee0026d1adb07082ba9af3772cead576bf7a5029ba8394d409d8cfdd25da5524ad173dfb6508ed943df3889dd68
|
7
|
+
data.tar.gz: 7ead1eb36914cf7c49decee943477ead775dc03927b3532e6436adbb544848eafa5ba38bddfc2489b60e37fc52087dcae9ead8151005415dacd9eba5d21a8ede
|
data/ext/rugged/rugged_patch.c
CHANGED
@@ -173,6 +173,13 @@ static VALUE rb_git_diff_patch_stat(VALUE self)
|
|
173
173
|
return rb_ary_new3(2, INT2FIX(additions), INT2FIX(deletions));
|
174
174
|
}
|
175
175
|
|
176
|
+
enum {
|
177
|
+
EXCLUDE_CONTEXT = (1u << 0),
|
178
|
+
EXCLUDE_ADDITIONS = (1u << 1),
|
179
|
+
EXCLUDE_DELETIONS = (1u << 2),
|
180
|
+
EXCLUDE_EOFNL = (1u << 3)
|
181
|
+
};
|
182
|
+
|
176
183
|
/*
|
177
184
|
* call-seq:
|
178
185
|
* patch.lines(options = {}) -> int
|
@@ -191,42 +198,84 @@ static VALUE rb_git_diff_patch_stat(VALUE self)
|
|
191
198
|
* Boolean value specifying that deletion line counts should be excluded from
|
192
199
|
* the returned total.
|
193
200
|
*
|
201
|
+
* :exclude_eofnl ::
|
202
|
+
* Boolean value specifying that end-of-file newline change lines should
|
203
|
+
* be excluded from the returned total.
|
204
|
+
*
|
194
205
|
* Returns the total number of lines in the patch, depending on the options
|
195
206
|
* specified.
|
196
207
|
*/
|
197
208
|
static VALUE rb_git_diff_patch_lines(int argc, VALUE *argv, VALUE self)
|
198
209
|
{
|
199
210
|
git_patch *patch;
|
200
|
-
size_t
|
201
|
-
size_t total_out;
|
211
|
+
size_t lines = 0;
|
202
212
|
VALUE rb_options;
|
203
213
|
Data_Get_Struct(self, git_patch, patch);
|
204
214
|
|
205
|
-
|
206
|
-
additions = 0;
|
207
|
-
deletions = 0;
|
208
|
-
|
209
|
-
git_patch_line_stats(&context_lines, &additions, &deletions, patch);
|
210
|
-
|
211
|
-
total_out = context_lines + additions + deletions;
|
215
|
+
int options = 0;
|
212
216
|
|
213
217
|
rb_scan_args(argc, argv, "0:", &rb_options);
|
214
218
|
if (!NIL_P(rb_options)) {
|
215
219
|
if (RTEST(rb_hash_aref(rb_options, CSTR2SYM("exclude_context")))) {
|
216
|
-
|
220
|
+
options |= EXCLUDE_CONTEXT;
|
217
221
|
}
|
218
222
|
|
219
223
|
if (RTEST(rb_hash_aref(rb_options, CSTR2SYM("exclude_additions")))) {
|
220
|
-
|
224
|
+
options |= EXCLUDE_ADDITIONS;
|
221
225
|
}
|
222
226
|
|
223
227
|
if (RTEST(rb_hash_aref(rb_options, CSTR2SYM("exclude_deletions")))) {
|
224
|
-
|
228
|
+
options |= EXCLUDE_DELETIONS;
|
229
|
+
}
|
230
|
+
|
231
|
+
if (RTEST(rb_hash_aref(rb_options, CSTR2SYM("exclude_eofnl")))) {
|
232
|
+
options |= EXCLUDE_EOFNL;
|
225
233
|
}
|
226
234
|
}
|
227
235
|
|
228
|
-
|
236
|
+
if (options == 0) {
|
237
|
+
size_t i = 0, hunks_count = git_patch_num_hunks(patch);
|
238
|
+
for (i = 0; i < hunks_count; ++i) {
|
239
|
+
lines += git_patch_num_lines_in_hunk(patch, i);
|
240
|
+
}
|
241
|
+
} else {
|
242
|
+
size_t i = 0, hunks_count = git_patch_num_hunks(patch);
|
243
|
+
for (i = 0; i < hunks_count; ++i) {
|
244
|
+
size_t lines_in_hunk = git_patch_num_lines_in_hunk(patch, i), l = 0;
|
245
|
+
|
246
|
+
for (l = 0; l < lines_in_hunk; ++l) {
|
247
|
+
const git_diff_line *line;
|
248
|
+
rugged_exception_check(
|
249
|
+
git_patch_get_line_in_hunk(&line, patch, i, l)
|
250
|
+
);
|
251
|
+
|
252
|
+
switch (line->origin) {
|
253
|
+
case GIT_DIFF_LINE_CONTEXT:
|
254
|
+
if (options & EXCLUDE_CONTEXT) continue;
|
255
|
+
break;
|
256
|
+
|
257
|
+
case GIT_DIFF_LINE_ADDITION:
|
258
|
+
if (options & EXCLUDE_ADDITIONS) continue;
|
259
|
+
break;
|
260
|
+
|
261
|
+
case GIT_DIFF_LINE_DELETION:
|
262
|
+
if (options & EXCLUDE_DELETIONS) continue;
|
263
|
+
break;
|
264
|
+
|
265
|
+
case GIT_DIFF_LINE_ADD_EOFNL:
|
266
|
+
case GIT_DIFF_LINE_DEL_EOFNL:
|
267
|
+
if (options & EXCLUDE_EOFNL) continue;
|
268
|
+
break;
|
269
|
+
}
|
270
|
+
|
271
|
+
lines += 1;
|
272
|
+
}
|
273
|
+
}
|
274
|
+
}
|
275
|
+
|
276
|
+
return INT2FIX(lines);
|
229
277
|
}
|
278
|
+
|
230
279
|
/*
|
231
280
|
* call-seq:
|
232
281
|
* patch.bytesize(options = {}) -> int
|
@@ -256,21 +305,19 @@ static VALUE rb_git_diff_patch_bytesize(int argc, VALUE *argv, VALUE self)
|
|
256
305
|
int include_context, include_hunk_headers, include_file_headers;
|
257
306
|
Data_Get_Struct(self, git_patch, patch);
|
258
307
|
|
259
|
-
include_context = 1;
|
260
|
-
include_hunk_headers = 1;
|
261
|
-
include_file_headers = 1;
|
308
|
+
include_context = include_hunk_headers = include_file_headers = 1;
|
262
309
|
|
263
310
|
rb_scan_args(argc, argv, "0:", &rb_options);
|
264
311
|
if (!NIL_P(rb_options)) {
|
265
|
-
if (rb_hash_aref(rb_options, CSTR2SYM("
|
312
|
+
if (RTEST(rb_hash_aref(rb_options, CSTR2SYM("exclude_context")))) {
|
266
313
|
include_context = 0;
|
267
314
|
}
|
268
315
|
|
269
|
-
if (rb_hash_aref(rb_options, CSTR2SYM("
|
316
|
+
if (RTEST(rb_hash_aref(rb_options, CSTR2SYM("exclude_hunk_headers")))) {
|
270
317
|
include_hunk_headers = 0;
|
271
318
|
}
|
272
319
|
|
273
|
-
if (rb_hash_aref(rb_options, CSTR2SYM("
|
320
|
+
if (RTEST(rb_hash_aref(rb_options, CSTR2SYM("exclude_file_headers")))) {
|
274
321
|
include_file_headers = 0;
|
275
322
|
}
|
276
323
|
}
|
@@ -286,20 +333,36 @@ static int patch_print_cb(
|
|
286
333
|
const git_diff_line *line,
|
287
334
|
void *payload)
|
288
335
|
{
|
289
|
-
VALUE
|
336
|
+
VALUE rb_buffer = (VALUE)payload;
|
290
337
|
|
291
338
|
switch (line->origin) {
|
292
339
|
case GIT_DIFF_LINE_CONTEXT:
|
293
340
|
case GIT_DIFF_LINE_ADDITION:
|
294
341
|
case GIT_DIFF_LINE_DELETION:
|
295
|
-
|
342
|
+
rb_ary_push(rb_buffer, rb_str_new(&line->origin, 1));
|
296
343
|
}
|
297
344
|
|
298
|
-
|
345
|
+
rb_ary_push(rb_buffer, rb_str_new(line->content, line->content_len));
|
299
346
|
|
300
347
|
return GIT_OK;
|
301
348
|
}
|
302
349
|
|
350
|
+
static int patch_print_header_cb(
|
351
|
+
const git_diff_delta *delta,
|
352
|
+
const git_diff_hunk *hunk,
|
353
|
+
const git_diff_line *line,
|
354
|
+
void *payload)
|
355
|
+
{
|
356
|
+
VALUE rb_buffer = (VALUE)payload;
|
357
|
+
|
358
|
+
if (line->origin == GIT_DIFF_LINE_FILE_HDR) {
|
359
|
+
rb_ary_push(rb_buffer, rb_str_new(line->content, line->content_len));
|
360
|
+
return GIT_OK;
|
361
|
+
} else {
|
362
|
+
return GIT_ITEROVER;
|
363
|
+
}
|
364
|
+
}
|
365
|
+
|
303
366
|
/*
|
304
367
|
* call-seq:
|
305
368
|
* patch.to_s -> str
|
@@ -309,14 +372,35 @@ static int patch_print_cb(
|
|
309
372
|
static VALUE rb_git_diff_patch_to_s(VALUE self)
|
310
373
|
{
|
311
374
|
git_patch *patch;
|
312
|
-
VALUE
|
375
|
+
VALUE rb_buffer = rb_ary_new();
|
313
376
|
Data_Get_Struct(self, git_patch, patch);
|
314
377
|
|
315
|
-
rugged_exception_check(git_patch_print(patch, patch_print_cb, (void*)
|
378
|
+
rugged_exception_check(git_patch_print(patch, patch_print_cb, (void*)rb_buffer));
|
316
379
|
|
317
|
-
return
|
380
|
+
return rb_ary_join(rb_buffer, Qnil);
|
318
381
|
}
|
319
382
|
|
383
|
+
/*
|
384
|
+
* call-seq:
|
385
|
+
* patch.header -> str
|
386
|
+
*
|
387
|
+
* Returns only the header of the patch as a string.
|
388
|
+
*/
|
389
|
+
static VALUE rb_git_diff_patch_header(VALUE self)
|
390
|
+
{
|
391
|
+
git_patch *patch;
|
392
|
+
int error = 0;
|
393
|
+
VALUE rb_buffer = rb_ary_new();
|
394
|
+
Data_Get_Struct(self, git_patch, patch);
|
395
|
+
|
396
|
+
error = git_patch_print(patch, patch_print_header_cb, (void*)rb_buffer);
|
397
|
+
if (error && error != GIT_ITEROVER)
|
398
|
+
rugged_exception_check(error);
|
399
|
+
|
400
|
+
return rb_ary_join(rb_buffer, Qnil);
|
401
|
+
}
|
402
|
+
|
403
|
+
|
320
404
|
void Init_rugged_patch(void)
|
321
405
|
{
|
322
406
|
rb_cRuggedPatch = rb_define_class_under(rb_mRugged, "Patch", rb_cObject);
|
@@ -329,6 +413,7 @@ void Init_rugged_patch(void)
|
|
329
413
|
|
330
414
|
rb_define_method(rb_cRuggedPatch, "delta", rb_git_diff_patch_delta, 0);
|
331
415
|
|
416
|
+
rb_define_method(rb_cRuggedPatch, "header", rb_git_diff_patch_header, 0);
|
332
417
|
rb_define_method(rb_cRuggedPatch, "to_s", rb_git_diff_patch_to_s, 0);
|
333
418
|
|
334
419
|
rb_define_method(rb_cRuggedPatch, "each_hunk", rb_git_diff_patch_each_hunk, 0);
|
data/lib/rugged/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rugged
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.25.
|
4
|
+
version: 0.25.0b7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Scott Chacon
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2016-08-
|
12
|
+
date: 2016-08-26 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake-compiler
|