@@ -29,9 +29,8 @@ extern VALUE rb_cRuggedIndex;
29
29
extern VALUE rb_cRuggedRepo ;
30
30
31
31
VALUE rb_cRuggedRebase ;
32
- VALUE rb_cRuggedRebaseOperation ;
33
32
34
- VALUE ruged_rebase_operation_new (git_rebase_operation * operation , VALUE owner );
33
+ static VALUE rebase_operation_type (git_rebase_operation * operation );
35
34
36
35
static void parse_rebase_options (git_rebase_options * ret , VALUE rb_options )
37
36
{
@@ -143,16 +142,35 @@ static VALUE rb_git_rebase_new(int argc, VALUE* argv, VALUE klass)
143
142
144
143
/*
145
144
* call-seq:
146
- * Rebase.next() -> RebaseOperation
145
+ * Rebase.next() -> operation or nil
147
146
*
148
- * Perform the next step in the rebase. The returned operation gives
149
- * its details.
147
+ * Perform the next step in the rebase. The returned operation is a
148
+ * Hash with its details or nil if there are no more operations to
149
+ * perform. The Hash contains some of the following entries:
150
+ *
151
+ * :type ::
152
+ * The type of operation being done. Can be one of +:pick+,
153
+ * +:reword+, +:edit+, +:squash+, +:fixup+ or +:exec+.
154
+ *
155
+ * :id ::
156
+ * The id of the commit being cherry-picked. Exists for all but
157
+ * +:exec+ operations.
158
+ *
159
+ * :index ::
160
+ * If the rebase is +:inmemory+ this is in the resulting merge
161
+ * index. It can be used to resolve merge conflicts during the
162
+ * rebase.
163
+ *
164
+ * :exec ::
165
+ * If the operatin is +:exec+ this is what the user asked to be
166
+ * executed.
150
167
*/
151
168
static VALUE rb_git_rebase_next (VALUE self )
152
169
{
153
170
int error ;
154
171
git_rebase * rebase ;
155
172
git_rebase_operation * operation ;
173
+ VALUE hash , val ;
156
174
157
175
Data_Get_Struct (self , git_rebase , rebase );
158
176
error = git_rebase_next (& operation , rebase );
@@ -161,7 +179,29 @@ static VALUE rb_git_rebase_next(VALUE self)
161
179
162
180
rugged_exception_check (error );
163
181
164
- return ruged_rebase_operation_new (operation , self );
182
+ /* Create the operation hash out of the relevant details */
183
+ hash = rb_hash_new ();
184
+
185
+ val = rebase_operation_type (operation );
186
+ rb_hash_aset (hash , CSTR2SYM ("type" ), val );
187
+
188
+ if (operation -> type != GIT_REBASE_OPERATION_EXEC ) {
189
+ val = rugged_create_oid (& operation -> id );
190
+ rb_hash_aset (hash , CSTR2SYM ("id" ), val );
191
+ }
192
+
193
+ if (operation -> index ) {
194
+ val = Data_Wrap_Struct (rb_cRuggedIndex , NULL , NULL , operation -> index );
195
+ rugged_set_owner (val , self );
196
+ rb_hash_aset (hash , CSTR2SYM ("index" ), val );
197
+ }
198
+
199
+ if (operation -> exec ) {
200
+ val = rb_str_new_utf8 (operation -> exec );
201
+ rb_hash_aset (hash , CSTR2SYM ("exec" ), val );
202
+ }
203
+
204
+ return hash ;
165
205
}
166
206
167
207
/*
@@ -251,27 +291,9 @@ static VALUE rb_git_rebase_finish(VALUE self, VALUE rb_sig)
251
291
return Qnil ;
252
292
}
253
293
254
- VALUE ruged_rebase_operation_new (git_rebase_operation * operation , VALUE owner )
255
- {
256
- VALUE rb_rebase = Data_Wrap_Struct (rb_cRuggedRebaseOperation , NULL , NULL , operation );
257
- rugged_set_owner (rb_rebase , owner );
258
-
259
- return rb_rebase ;
260
- }
261
-
262
- /*
263
- * call-seq:
264
- * RebaseOperation.type -> symbol
265
- *
266
- * The type of operation being done. Can be one of +:pick+,
267
- * +:reword+, +:edit+, +:squash+, +:fixup+ or +:exec+.
268
- *
269
- */ static VALUE rb_git_rebase_operation_type (VALUE self )
294
+ static VALUE rebase_operation_type (git_rebase_operation * operation )
270
295
{
271
296
VALUE rb_type ;
272
- git_rebase_operation * operation ;
273
-
274
- Data_Get_Struct (self , git_rebase_operation , operation );
275
297
276
298
switch (operation -> type ) {
277
299
case GIT_REBASE_OPERATION_PICK :
@@ -300,58 +322,6 @@ VALUE ruged_rebase_operation_new(git_rebase_operation *operation, VALUE owner)
300
322
return rb_type ;
301
323
}
302
324
303
- /*
304
- * call-seq:
305
- * RebaseOperation.id -> oid
306
- *
307
- * The id of the commit being cherry-picked. Exists for all but
308
- * +:exec+ operations.
309
- */
310
- static VALUE rb_git_rebase_operation_id (VALUE self )
311
- {
312
- git_rebase_operation * operation ;
313
-
314
- Data_Get_Struct (self , git_rebase_operation , operation );
315
-
316
- return rugged_create_oid (& operation -> id );
317
- }
318
-
319
- /*
320
- * call-seq:
321
- * RebaseOperation.index -> Index
322
- *
323
- * The index that is the result of an opration. Only valid for
324
- * +:inmemory+ rebases.
325
- */
326
- static VALUE rb_git_rebase_operation_index (VALUE self )
327
- {
328
- git_rebase_operation * operation ;
329
- VALUE rb_index ;
330
-
331
- Data_Get_Struct (self , git_rebase_operation , operation );
332
-
333
- rb_index = Data_Wrap_Struct (rb_cRuggedIndex , NULL , NULL , operation -> index );
334
- rugged_set_owner (rb_index , self );
335
-
336
- return rb_index ;
337
- }
338
-
339
- /*
340
- * call-seq:
341
- * RebaseOperation.exec -> str
342
- *
343
- * The executable the user has requested to run. Only exists for
344
- * +:exec+ operations.
345
- */
346
- static VALUE rb_git_rebase_operation_exec (VALUE self )
347
- {
348
- git_rebase_operation * operation ;
349
-
350
- Data_Get_Struct (self , git_rebase_operation , operation );
351
-
352
- return rb_str_new_utf8 (operation -> exec ? operation -> exec : "" );
353
- }
354
-
355
325
void Init_rugged_rebase (void )
356
326
{
357
327
rb_cRuggedRebase = rb_define_class_under (rb_mRugged , "Rebase" , rb_cObject );
@@ -361,12 +331,6 @@ void Init_rugged_rebase(void)
361
331
rb_define_method (rb_cRuggedRebase , "commit" , rb_git_rebase_commit , -1 );
362
332
rb_define_method (rb_cRuggedRebase , "abort" , rb_git_rebase_abort , 0 );
363
333
rb_define_method (rb_cRuggedRebase , "finish" , rb_git_rebase_finish , 1 );
364
-
365
- rb_cRuggedRebaseOperation = rb_define_class_under (rb_mRugged , "RebaseOperation" , rb_cObject );
366
- rb_define_method (rb_cRuggedRebaseOperation , "type" , rb_git_rebase_operation_type , 0 );
367
- rb_define_method (rb_cRuggedRebaseOperation , "id" , rb_git_rebase_operation_id , 0 );
368
- rb_define_method (rb_cRuggedRebaseOperation , "index" , rb_git_rebase_operation_index , 0 );
369
- rb_define_method (rb_cRuggedRebaseOperation , "exec" , rb_git_rebase_operation_exec , 0 );
370
334
}
371
335
372
336
0 commit comments