Skip to content

Commit cb2b0f2

Browse files
committed
bring in master
2 parents 92409b5 + d909d3f commit cb2b0f2

17 files changed

+35
-98
lines changed

.travis.yml

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ cache: bundler
33

44
os:
55
- linux
6+
- osx
67

78
rvm:
8-
- 2.0.0
9-
- 2.1.8
109
- 2.2.5
1110
- 2.3.3
1211
- 2.4.0
12+
- 2.5.0
1313
- ruby-head
1414
- rbx-2
1515

@@ -28,21 +28,13 @@ matrix:
2828
allow_failures:
2929
- rvm: rbx-2
3030
- rvm: ruby-head
31-
include:
32-
- os: osx
33-
rvm: 2.0.0
34-
- os: osx
35-
rvm: 2.1.5
36-
- os: osx
37-
rvm: 2.2.2
38-
- os: osx
39-
rvm: rbx-2
4031

4132
git:
4233
submodules: false
4334

4435
before_install:
4536
- git submodule update --init
37+
- gem update --system
4638
- if [ "$TRAVIS_OS_NAME" = "osx" ]; then ./vendor/libgit2/script/install-deps-osx.sh; fi
4739

4840
script: script/travisbuild

ext/rugged/rugged_blame.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,11 @@ static VALUE rb_git_blame_count(VALUE self)
188188
return UINT2NUM(git_blame_get_hunk_count(blame));
189189
}
190190

191+
static VALUE rugged_blame_enum_size(VALUE rb_blame, VALUE rb_args, VALUE rb_eobj)
192+
{
193+
return rb_git_blame_count(rb_blame);
194+
}
195+
191196
/*
192197
* call-seq:
193198
* blame[index] -> hunk
@@ -242,9 +247,7 @@ static VALUE rb_git_blame_each(VALUE self)
242247
git_blame *blame;
243248
uint32_t i, blame_count;
244249

245-
if (!rb_block_given_p()) {
246-
return rb_funcall(self, rb_intern("to_enum"), 1, CSTR2SYM("each"), self);
247-
}
250+
RETURN_SIZED_ENUMERATOR(self, 0, 0, rugged_blame_enum_size);
248251

249252
Data_Get_Struct(self, git_blame, blame);
250253

ext/rugged/rugged_branch_collection.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -178,19 +178,16 @@ static VALUE rb_git_branch_collection_aref(VALUE self, VALUE rb_name) {
178178

179179
static VALUE each_branch(int argc, VALUE *argv, VALUE self, int branch_names_only)
180180
{
181-
VALUE rb_repo = rugged_owner(self), rb_filter;
181+
VALUE rb_repo, rb_filter;
182182
git_repository *repo;
183183
git_branch_iterator *iter;
184184
int error, exception = 0;
185185
git_branch_t filter = (GIT_BRANCH_LOCAL | GIT_BRANCH_REMOTE), branch_type;
186186

187+
RETURN_ENUMERATOR(self, argc, argv);
187188
rb_scan_args(argc, argv, "01", &rb_filter);
188189

189-
if (!rb_block_given_p()) {
190-
VALUE symbol = branch_names_only ? CSTR2SYM("each_name") : CSTR2SYM("each");
191-
return rb_funcall(self, rb_intern("to_enum"), 2, symbol, rb_filter);
192-
}
193-
190+
rb_repo = rugged_owner(self);
194191
rugged_check_repo(rb_repo);
195192

196193
if (!NIL_P(rb_filter))

ext/rugged/rugged_config.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ static int cb_config__to_hash(const git_config_entry *entry, void *opaque)
198198
/*
199199
* call-seq:
200200
* cfg.each_key { |key| block }
201-
* cfg.each_key -> enumarator
201+
* cfg.each_key -> enumerator
202202
*
203203
* Call the given block once for each key in the config file. If no block
204204
* is given, an enumerator is returned.
@@ -212,11 +212,9 @@ static VALUE rb_git_config_each_key(VALUE self)
212212
git_config *config;
213213
int error;
214214

215+
RETURN_ENUMERATOR(self, 0, 0);
215216
Data_Get_Struct(self, git_config, config);
216217

217-
if (!rb_block_given_p())
218-
return rb_funcall(self, rb_intern("to_enum"), 1, CSTR2SYM("each_key"));
219-
220218
error = git_config_foreach(config, &cb_config__each_key, (void *)rb_block_proc());
221219
rugged_exception_check(error);
222220
return Qnil;
@@ -240,12 +238,10 @@ static VALUE rb_git_config_each_pair(VALUE self)
240238
{
241239
git_config *config;
242240
int error;
243-
241+
242+
RETURN_ENUMERATOR(self, 0, 0);
244243
Data_Get_Struct(self, git_config, config);
245244

246-
if (!rb_block_given_p())
247-
return rb_funcall(self, rb_intern("to_enum"), 1, CSTR2SYM("each_pair"));
248-
249245
error = git_config_foreach(config, &cb_config__each_pair, (void *)rb_block_proc());
250246
rugged_exception_check(error);
251247
return Qnil;

ext/rugged/rugged_diff.c

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -447,10 +447,7 @@ static VALUE rb_git_diff_each_patch(VALUE self)
447447
int error = 0;
448448
size_t d, delta_count;
449449

450-
if (!rb_block_given_p()) {
451-
return rb_funcall(self, rb_intern("to_enum"), 1, CSTR2SYM("each_patch"), self);
452-
}
453-
450+
RETURN_ENUMERATOR(self, 0, 0);
454451
Data_Get_Struct(self, git_diff, diff);
455452

456453
delta_count = git_diff_num_deltas(diff);
@@ -481,13 +478,9 @@ static VALUE rb_git_diff_each_delta(VALUE self)
481478
{
482479
git_diff *diff;
483480
const git_diff_delta *delta;
484-
int error = 0;
485481
size_t d, delta_count;
486482

487-
if (!rb_block_given_p()) {
488-
return rb_funcall(self, rb_intern("to_enum"), 1, CSTR2SYM("each_delta"), self);
489-
}
490-
483+
RETURN_ENUMERATOR(self, 0, 0);
491484
Data_Get_Struct(self, git_diff, diff);
492485

493486
delta_count = git_diff_num_deltas(diff);
@@ -496,8 +489,6 @@ static VALUE rb_git_diff_each_delta(VALUE self)
496489
rb_yield(rugged_diff_delta_new(self, delta));
497490
}
498491

499-
rugged_exception_check(error);
500-
501492
return self;
502493
}
503494

@@ -524,6 +515,7 @@ static VALUE rb_git_diff_each_line(int argc, VALUE *argv, VALUE self)
524515
git_diff_format_t format;
525516
int exception = 0, error;
526517

518+
RETURN_ENUMERATOR(self, argc, argv);
527519
Data_Get_Struct(self, git_diff, diff);
528520

529521
if (rb_scan_args(argc, argv, "01", &rb_format) == 1) {
@@ -532,9 +524,6 @@ static VALUE rb_git_diff_each_line(int argc, VALUE *argv, VALUE self)
532524
rb_format = CSTR2SYM("patch");
533525
}
534526

535-
if (!rb_block_given_p())
536-
return rb_funcall(self, rb_intern("to_enum"), 2, CSTR2SYM("each_line"), rb_format);
537-
538527
if (SYM2ID(rb_format) == rb_intern("patch")) {
539528
format = GIT_DIFF_FORMAT_PATCH;
540529
} else if (SYM2ID(rb_format) == rb_intern("patch_header")) {

ext/rugged/rugged_diff_hunk.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,7 @@ static VALUE rb_git_diff_hunk_each_line(VALUE self)
4242
git_patch *patch;
4343
int error = 0, l, lines_count, hunk_idx;
4444

45-
if (!rb_block_given_p()) {
46-
return rb_funcall(self, rb_intern("to_enum"), 1, CSTR2SYM("each_line"), self);
47-
}
45+
RETURN_ENUMERATOR(self, 0, 0);
4846

4947
Data_Get_Struct(rugged_owner(self), git_patch, patch);
5048

ext/rugged/rugged_index.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,11 +190,9 @@ static VALUE rb_git_index_each(VALUE self)
190190
git_index *index;
191191
unsigned int i, count;
192192

193+
RETURN_ENUMERATOR(self, 0, 0);
193194
Data_Get_Struct(self, git_index, index);
194195

195-
if (!rb_block_given_p())
196-
return rb_funcall(self, rb_intern("to_enum"), 0);
197-
198196
count = (unsigned int)git_index_entrycount(index);
199197
for (i = 0; i < count; ++i) {
200198
const git_index_entry *entry = git_index_get_byindex(index, i);

ext/rugged/rugged_note.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -297,12 +297,9 @@ static VALUE rb_git_note_each(int argc, VALUE *argv, VALUE self)
297297
struct rugged_cb_payload payload = { self, 0 };
298298
VALUE rb_notes_ref;
299299

300+
RETURN_ENUMERATOR(self, argc, argv);
300301
rb_scan_args(argc, argv, "01", &rb_notes_ref);
301302

302-
if (!rb_block_given_p()) {
303-
return rb_funcall(self, rb_intern("to_enum"), 3, CSTR2SYM("each_note"), self, rb_notes_ref);
304-
}
305-
306303
if (!NIL_P(rb_notes_ref)) {
307304
Check_Type(rb_notes_ref, T_STRING);
308305
notes_ref = StringValueCStr(rb_notes_ref);

ext/rugged/rugged_patch.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,7 @@ static VALUE rb_git_diff_patch_each_hunk(VALUE self)
9393
int error = 0;
9494
size_t hunks_count, h;
9595

96-
if (!rb_block_given_p()) {
97-
return rb_funcall(self, rb_intern("to_enum"), 1, CSTR2SYM("each_hunk"), self);
98-
}
99-
96+
RETURN_ENUMERATOR(self, 0, 0);
10097
Data_Get_Struct(self, git_patch, patch);
10198

10299
hunks_count = git_patch_num_hunks(patch);

ext/rugged/rugged_reference_collection.c

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -114,15 +114,9 @@ static VALUE rb_git_reference_collection__each(int argc, VALUE *argv, VALUE self
114114
git_reference_iterator *iter;
115115
int error, exception = 0;
116116

117+
RETURN_ENUMERATOR(self, argc, argv);
117118
rb_scan_args(argc, argv, "01", &rb_glob);
118119

119-
if (!rb_block_given_p()) {
120-
return rb_funcall(self,
121-
rb_intern("to_enum"), 2,
122-
only_names ? CSTR2SYM("each_name") : CSTR2SYM("each"),
123-
rb_glob);
124-
}
125-
126120
rugged_check_repo(rb_repo);
127121

128122
Data_Get_Struct(rb_repo, git_repository, repo);

0 commit comments

Comments
 (0)