rugged 0.24.0b12 → 0.24.0b13

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4bd70b6169b13b2a50eff47a4d3b01e333388f12
4
- data.tar.gz: cfb572bc347939bab52487dff98b4c75650bea53
3
+ metadata.gz: a2c13da3a882d071568aadfd4cbc7930e5d07beb
4
+ data.tar.gz: 1f237b49dbcef1a6fca8a1e8bbd73cfb92c93ce9
5
5
  SHA512:
6
- metadata.gz: f43d9d0c6618f4a2d490bfc7e39a810bc1753741e93671d427c38f4d9dd235061ec37f4f6430c553bb9d9ad1aa1fc331cc27aee7ea659e3ba479ceb7ae2b98ed
7
- data.tar.gz: 2700a84afcd1c5647917597154ff348c7884657d4df03a040dc8e322e536d7086548d5b92a22acd8bb91b6f3ca58e2a32be10be681af8b49ecbd2f36bc137510
6
+ metadata.gz: 51a3a2e6980689febe708c5d5d9863f3b99d95ae327dd490e302db92efb31618059ec04cd1eaf0686c49258a1b01f238fa47fbf62f6d2ccfca0670853802a102
7
+ data.tar.gz: 3d46a7fbdcef781e6e0c1becf48f932707cba5f5b31340fc57f360a19da807e649ffb2c40310651a9b843a8797afa41358b01a2aa16e037e4be6e6a31b7c115a
data/ext/rugged/rugged.c CHANGED
@@ -487,6 +487,7 @@ void Init_rugged(void)
487
487
  Init_rugged_blame();
488
488
  Init_rugged_cred();
489
489
  Init_rugged_backend();
490
+ Init_rugged_rebase();
490
491
 
491
492
  /*
492
493
  * Sort the repository contents in no particular ordering;
data/ext/rugged/rugged.h CHANGED
@@ -75,6 +75,7 @@ void Init_rugged_diff_line(void);
75
75
  void Init_rugged_blame(void);
76
76
  void Init_rugged_cred(void);
77
77
  void Init_rugged_backend(void);
78
+ void Init_rugged_rebase(void);
78
79
 
79
80
  VALUE rb_git_object_init(git_otype type, int argc, VALUE *argv, VALUE self);
80
81
 
@@ -98,6 +99,7 @@ VALUE rb_git_delta_file_fromC(const git_diff_file *file);
98
99
 
99
100
  void rugged_parse_diff_options(git_diff_options *opts, VALUE rb_options);
100
101
  void rugged_parse_merge_options(git_merge_options *opts, VALUE rb_options);
102
+ void rugged_parse_checkout_options(git_checkout_options *opts, VALUE rb_options);
101
103
 
102
104
  void rugged_cred_extract(git_cred **cred, int allowed_types, VALUE rb_credential);
103
105
 
@@ -107,6 +109,7 @@ git_otype rugged_otype_get(VALUE rb_type);
107
109
  git_signature *rugged_signature_get(VALUE rb_person, git_repository *repo);
108
110
  git_object *rugged_object_get(git_repository *repo, VALUE object_value, git_otype type);
109
111
  int rugged_oid_get(git_oid *oid, git_repository *repo, VALUE p);
112
+ const char * rugged_refname_from_string_or_ref(VALUE rb_name_or_ref);
110
113
 
111
114
  void rugged_rb_ary_to_strarray(VALUE rb_array, git_strarray *str_array);
112
115
  VALUE rugged_strarray_to_rb_ary(git_strarray *str_array);
@@ -563,23 +563,35 @@ static VALUE rb_git_commit_to_mbox(int argc, VALUE *argv, VALUE self)
563
563
  *
564
564
  * Returns +commit+'s header field value.
565
565
  */
566
- static VALUE rb_git_commit_header_field(VALUE self, VALUE rb_field) {
566
+ static VALUE rb_git_commit_header_field(VALUE self, VALUE rb_field)
567
+ {
567
568
  git_buf header_field = { 0 };
569
+ git_commit *commit = NULL;
570
+
571
+ const char *encoding_name;
572
+ rb_encoding *encoding = rb_utf8_encoding();
568
573
  VALUE rb_result;
569
- git_commit *commit;
570
574
 
571
- Check_Type(rb_field, T_STRING);
575
+ int error;
572
576
 
577
+ Check_Type(rb_field, T_STRING);
573
578
  Data_Get_Struct(self, git_commit, commit);
574
579
 
575
- rugged_exception_check(
576
- git_commit_header_field(&header_field, commit, StringValueCStr(rb_field))
577
- );
580
+ error = git_commit_header_field(&header_field, commit, StringValueCStr(rb_field));
581
+
582
+ if (error < 0) {
583
+ git_buf_free(&header_field);
584
+ if (error == GIT_ENOTFOUND)
585
+ return Qnil;
586
+ rugged_exception_check(error);
587
+ }
578
588
 
579
- rb_result = rb_enc_str_new(header_field.ptr, header_field.size, rb_utf8_encoding());
589
+ encoding_name = git_commit_message_encoding(commit);
590
+ if (encoding_name != NULL)
591
+ encoding = rb_enc_find(encoding_name);
580
592
 
593
+ rb_result = rb_enc_str_new(header_field.ptr, header_field.size, encoding);
581
594
  git_buf_free(&header_field);
582
-
583
595
  return rb_result;
584
596
  }
585
597
 
@@ -589,18 +601,65 @@ static VALUE rb_git_commit_header_field(VALUE self, VALUE rb_field) {
589
601
  *
590
602
  * Returns +commit+'s entire raw header.
591
603
  */
592
- static VALUE rb_git_commit_header(VALUE self) {
593
- VALUE rb_result;
604
+ static VALUE rb_git_commit_header(VALUE self)
605
+ {
594
606
  git_commit *commit;
595
607
  const char *raw_header;
596
608
 
597
609
  Data_Get_Struct(self, git_commit, commit);
598
610
 
599
611
  raw_header = git_commit_raw_header(commit);
612
+ return rb_str_new_utf8(raw_header);
613
+ }
600
614
 
601
- rb_result = rb_enc_str_new(raw_header, strlen(raw_header), rb_utf8_encoding());
615
+ /*
616
+ * call-seq:
617
+ * Rugged::Commit.extract_signature(repo, commit, field_name) -> [str, str]
618
+ *
619
+ * Returns +commit+'s signature in 'field' and the signed data
620
+ *
621
+ * The signature is done over the contents of the commit without the
622
+ * signature block in the header, which is the data in the second
623
+ * element in the return array.
624
+ */
625
+ static VALUE rb_git_commit_extract_signature(int argc, VALUE *argv, VALUE self)
626
+ {
627
+ int error;
628
+ VALUE ret_arr;
629
+ git_oid commit_id;
630
+ const char *field;
631
+ git_repository *repo;
632
+ git_buf signature = {0}, signed_data = {0};
633
+ VALUE rb_repo, rb_commit, rb_field = Qnil;
602
634
 
603
- return rb_result;
635
+ rb_scan_args(argc, argv, "21", &rb_repo, &rb_commit, &rb_field);
636
+
637
+ rugged_check_repo(rb_repo);
638
+ Data_Get_Struct(rb_repo, git_repository, repo);
639
+
640
+ error = git_oid_fromstr(&commit_id, StringValueCStr(rb_commit));
641
+ rugged_exception_check(error);
642
+
643
+ field = NIL_P(rb_field) ? NULL : StringValueCStr(rb_field);
644
+ error = git_commit_extract_signature(&signature, &signed_data, repo, &commit_id, field);
645
+ if (error < 0) {
646
+ git_buf_free(&signature);
647
+ git_buf_free(&signed_data);
648
+ }
649
+
650
+ if (error == GIT_ENOTFOUND) {
651
+ ret_arr = rb_ary_new3(2, Qnil, Qnil);
652
+ } else {
653
+ rugged_exception_check(error);
654
+
655
+ ret_arr = rb_ary_new3(2, rb_str_new(signature.ptr, signature.size),
656
+ rb_str_new(signed_data.ptr, signed_data.size));
657
+ }
658
+
659
+ git_buf_free(&signature);
660
+ git_buf_free(&signed_data);
661
+
662
+ return ret_arr;
604
663
  }
605
664
 
606
665
  void Init_rugged_commit(void)
@@ -608,6 +667,7 @@ void Init_rugged_commit(void)
608
667
  rb_cRuggedCommit = rb_define_class_under(rb_mRugged, "Commit", rb_cRuggedObject);
609
668
 
610
669
  rb_define_singleton_method(rb_cRuggedCommit, "create", rb_git_commit_create, 2);
670
+ rb_define_singleton_method(rb_cRuggedCommit, "extract_signature", rb_git_commit_extract_signature, -1);
611
671
 
612
672
  rb_define_method(rb_cRuggedCommit, "message", rb_git_commit_message_GET, 0);
613
673
  rb_define_method(rb_cRuggedCommit, "epoch_time", rb_git_commit_epoch_time_GET, 0);
@@ -0,0 +1,355 @@
1
+ /*
2
+ * The MIT License
3
+ *
4
+ * Copyright (c) 2016 GitHub, Inc
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in
14
+ * all copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
+ * THE SOFTWARE.
23
+ */
24
+
25
+ #include "rugged.h"
26
+
27
+ extern VALUE rb_mRugged;
28
+ extern VALUE rb_cRuggedIndex;
29
+ extern VALUE rb_cRuggedRepo;
30
+
31
+ VALUE rb_cRuggedRebase;
32
+
33
+ static VALUE rebase_operation_type(git_rebase_operation *operation);
34
+
35
+ static void parse_rebase_options(git_rebase_options *ret, VALUE rb_options)
36
+ {
37
+ VALUE val;
38
+
39
+ if (NIL_P(rb_options))
40
+ return;
41
+
42
+ val = rb_hash_aref(rb_options, CSTR2SYM("quiet"));
43
+ ret->quiet = RTEST(val);
44
+
45
+ val = rb_hash_aref(rb_options, CSTR2SYM("inmemory"));
46
+ ret->inmemory = RTEST(val);
47
+
48
+ val = rb_hash_aref(rb_options, CSTR2SYM("rewrite_notes_ref"));
49
+ if (!NIL_P(val)) {
50
+ Check_Type(val, T_STRING);
51
+ ret->rewrite_notes_ref = StringValueCStr(val);
52
+ }
53
+
54
+ rugged_parse_checkout_options(&ret->checkout_options, rb_options);
55
+ rugged_parse_merge_options(&ret->merge_options, rb_options);
56
+ }
57
+
58
+ void rb_git_rebase__free(git_rebase *rebase)
59
+ {
60
+ git_rebase_free(rebase);
61
+ }
62
+
63
+ VALUE rugged_rebase_new(VALUE klass, VALUE owner, git_rebase *rebase)
64
+ {
65
+ VALUE rb_rebase = Data_Wrap_Struct(klass, NULL, &rb_git_rebase__free, rebase);
66
+ rugged_set_owner(rb_rebase, owner);
67
+ return rb_rebase;
68
+ }
69
+
70
+ /*
71
+ * call-seq:
72
+ * Rebase.new(repo, branch, upstream[, onto][, options]) -> Rebase
73
+ *
74
+ * Initialize a new rebase operation. This will put +repo+ in a
75
+ * rebase state.
76
+ *
77
+ * +branch+ is the branch to be rebased, and +upstream+ is the branch
78
+ * which is to be the new base. If +onto+ is specified, this will be
79
+ * the one base, and +upstream+ is used to determine which commits
80
+ * from +branch+ to use for the rebase.
81
+ *
82
+ * You can pass merge and checkout options for the options hash, plus
83
+ * a few rebase-specific ones:
84
+ *
85
+ * :quiet ::
86
+ * If true, a flag will be set to ask tools to activate quiet
87
+ * mode. This does not do anything for libgit2/rugged but can be
88
+ * used to interact with other implementations.
89
+ *
90
+ * :inmemory ::
91
+ * Do not put the repository in a rebase state but perform all the
92
+ * operations in-memory. In case of conflicts, the RebaseOperation
93
+ * returned by #next will contain the index which can be used to
94
+ * resolve conflicts.
95
+ *
96
+ * :rewrite_notes_ref ::
97
+ * Name of the notes reference used to rewrite notes for rebased
98
+ * commits when finishing the rebase. If +nil+, it will be taken
99
+ * from the configuration.
100
+ */
101
+ static VALUE rb_git_rebase_new(int argc, VALUE* argv, VALUE klass)
102
+ {
103
+ int error;
104
+ const char* str_branch = NULL, *str_upstream = NULL, *str_onto = NULL;
105
+ git_rebase *rebase;
106
+ git_repository *repo;
107
+ git_annotated_commit *branch = NULL, *upstream = NULL, *onto = NULL;
108
+ VALUE rb_repo, rb_branch, rb_upstream, rb_onto, rb_options;
109
+ git_rebase_options options = GIT_REBASE_OPTIONS_INIT;
110
+
111
+ rb_scan_args(argc, argv, "31:", &rb_repo, &rb_branch, &rb_upstream, &rb_onto, &rb_options);
112
+ Data_Get_Struct(rb_repo, git_repository, repo);
113
+ str_branch = rugged_refname_from_string_or_ref(rb_branch);
114
+ str_upstream = rugged_refname_from_string_or_ref(rb_upstream);
115
+ Check_Type(rb_branch, T_STRING);
116
+ Check_Type(rb_upstream, T_STRING);
117
+ if (!NIL_P(rb_onto))
118
+ str_onto = rugged_refname_from_string_or_ref(rb_onto);
119
+
120
+ parse_rebase_options(&options, rb_options);
121
+
122
+ if ((error = git_annotated_commit_from_revspec(&branch, repo, str_branch)) < 0 ||
123
+ (error = git_annotated_commit_from_revspec(&upstream, repo, str_upstream)) < 0)
124
+ goto cleanup;
125
+
126
+ if (!NIL_P(rb_onto)) {
127
+ if ((error = git_annotated_commit_from_revspec(&onto, repo, str_onto)) < 0)
128
+ goto cleanup;
129
+ }
130
+
131
+ error = git_rebase_init(&rebase, repo, branch, upstream, onto, &options);
132
+
133
+ cleanup:
134
+ git_annotated_commit_free(branch);
135
+ git_annotated_commit_free(upstream);
136
+ git_annotated_commit_free(onto);
137
+
138
+ rugged_exception_check(error);
139
+
140
+ return rugged_rebase_new(klass, rb_repo, rebase);
141
+ }
142
+
143
+ /*
144
+ * call-seq:
145
+ * Rebase.next() -> operation or nil
146
+ *
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
+ * :exec ::
160
+ * If the operatin is +:exec+ this is what the user asked to be
161
+ * executed.
162
+ */
163
+ static VALUE rb_git_rebase_next(VALUE self)
164
+ {
165
+ int error;
166
+ git_rebase *rebase;
167
+ git_rebase_operation *operation;
168
+ VALUE hash, val;
169
+
170
+ Data_Get_Struct(self, git_rebase, rebase);
171
+ error = git_rebase_next(&operation, rebase);
172
+ if (error == GIT_ITEROVER)
173
+ return Qnil;
174
+
175
+ rugged_exception_check(error);
176
+
177
+ /* Create the operation hash out of the relevant details */
178
+ hash = rb_hash_new();
179
+
180
+ val = rebase_operation_type(operation);
181
+ rb_hash_aset(hash, CSTR2SYM("type"), val);
182
+
183
+ if (operation->type != GIT_REBASE_OPERATION_EXEC) {
184
+ val = rugged_create_oid(&operation->id);
185
+ rb_hash_aset(hash, CSTR2SYM("id"), val);
186
+ }
187
+
188
+ if (operation->exec) {
189
+ val = rb_str_new_utf8(operation->exec);
190
+ rb_hash_aset(hash, CSTR2SYM("exec"), val);
191
+ }
192
+
193
+ return hash;
194
+ }
195
+ /*
196
+ * call-seq:
197
+ * Rebase.inmemory_index -> Index
198
+ *
199
+ * Gets the index produced by the last operation, which is the result
200
+ * of +next+ and which will be committed by the next invocation of
201
+ * +commit+. This is useful for resolving conflicts in an in-memory
202
+ * rebase before committing them.
203
+ *
204
+ * This is only applicable for in-memory rebases; for rebases within
205
+ * a working directory, the changes were applied to the repository's
206
+ * index.
207
+ */
208
+ static VALUE rb_git_rebase_inmemory_index(VALUE self)
209
+ {
210
+ git_rebase *rebase;
211
+ git_index *index;
212
+
213
+ Data_Get_Struct(self, git_rebase, rebase);
214
+ rugged_exception_check(git_rebase_inmemory_index(&index, rebase));
215
+
216
+ return rugged_index_new(rb_cRuggedIndex, self, index);
217
+ }
218
+
219
+ /*
220
+ * call-seq:
221
+ * Rebase.commit(author = nil, committer, message = nil)
222
+ *
223
+ * Commit the current patch. Any conflicts must have been resolved.
224
+ *
225
+ * If +author+ is +nil+, the existing author for the commit will be
226
+ * used. If +message+ is +nil+, the existing message will be used.
227
+ */
228
+ static VALUE rb_git_rebase_commit(int argc, VALUE *argv, VALUE self)
229
+ {
230
+ int error;
231
+ git_oid id;
232
+ git_rebase *rebase;
233
+ git_signature *author = NULL, *committer;
234
+ const char *message = NULL;
235
+ VALUE rb_options, rb_author, rb_committer, rb_message;
236
+
237
+ Data_Get_Struct(self, git_rebase, rebase);
238
+ rb_scan_args(argc, argv, ":", &rb_options);
239
+
240
+ rb_author = rb_hash_aref(rb_options, CSTR2SYM("author"));
241
+ rb_committer = rb_hash_aref(rb_options, CSTR2SYM("committer"));
242
+ rb_message = rb_hash_aref(rb_options, CSTR2SYM("message"));
243
+
244
+ if (!NIL_P(rb_message)) {
245
+ Check_Type(rb_message, T_STRING);
246
+ message = StringValueCStr(rb_message);
247
+ }
248
+
249
+ if (NIL_P(rb_committer))
250
+ rb_raise(rb_eArgError, "Expected non-nil committer");
251
+ else
252
+ committer = rugged_signature_get(rb_committer, NULL);
253
+
254
+ if (!NIL_P(rb_author))
255
+ author = rugged_signature_get(rb_author, NULL);
256
+
257
+ error = git_rebase_commit(&id, rebase, author, committer, NULL, message);
258
+ git_signature_free(author);
259
+ git_signature_free(committer);
260
+
261
+ rugged_exception_check(error);
262
+
263
+ return rugged_create_oid(&id);
264
+ }
265
+
266
+ /*
267
+ * call-seq:
268
+ * Rebase.abort()
269
+ *
270
+ * Abort the rebase currently in process, resetting the repository
271
+ * and working directory to their state before the rebase began.
272
+ */
273
+ static VALUE rb_git_rebase_abort(VALUE self)
274
+ {
275
+ git_rebase *rebase;
276
+
277
+ Data_Get_Struct(self, git_rebase, rebase);
278
+ rugged_exception_check(git_rebase_abort(rebase));
279
+
280
+ return Qnil;
281
+ }
282
+
283
+ /*
284
+ * call-seq:
285
+ * Rebase.finish()
286
+ *
287
+ * Finish the rebase currently in progress once all patches have been
288
+ * applied.
289
+ */
290
+ static VALUE rb_git_rebase_finish(VALUE self, VALUE rb_sig)
291
+ {
292
+ git_rebase *rebase;
293
+ git_signature *sig;
294
+ int error;
295
+
296
+ Data_Get_Struct(self, git_rebase, rebase);
297
+ sig = rugged_signature_get(rb_sig, NULL);
298
+ error = git_rebase_finish(rebase, sig);
299
+ git_signature_free(sig);
300
+
301
+ rugged_exception_check(error);
302
+
303
+ return Qnil;
304
+ }
305
+
306
+ static VALUE rebase_operation_type(git_rebase_operation *operation)
307
+ {
308
+ VALUE rb_type;
309
+
310
+ switch (operation->type) {
311
+ case GIT_REBASE_OPERATION_PICK:
312
+ rb_type = CSTR2SYM("pick");
313
+ break;
314
+ case GIT_REBASE_OPERATION_REWORD:
315
+ rb_type = CSTR2SYM("reword");
316
+ break;
317
+ case GIT_REBASE_OPERATION_EDIT:
318
+ rb_type = CSTR2SYM("edit");
319
+ break;
320
+ case GIT_REBASE_OPERATION_SQUASH:
321
+ rb_type = CSTR2SYM("squash");
322
+ break;
323
+ case GIT_REBASE_OPERATION_FIXUP:
324
+ rb_type = CSTR2SYM("fixup");
325
+ break;
326
+ case GIT_REBASE_OPERATION_EXEC:
327
+ rb_type = CSTR2SYM("exec");
328
+ break;
329
+ default:
330
+ rb_raise(rb_eTypeError, "Invalid rebase operation type found");
331
+ break;
332
+ }
333
+
334
+ return rb_type;
335
+ }
336
+
337
+ void Init_rugged_rebase(void)
338
+ {
339
+ rb_cRuggedRebase = rb_define_class_under(rb_mRugged, "Rebase", rb_cObject);
340
+
341
+ rb_define_singleton_method(rb_cRuggedRebase, "new", rb_git_rebase_new, -1);
342
+ rb_define_method(rb_cRuggedRebase, "next", rb_git_rebase_next, 0);
343
+ rb_define_method(rb_cRuggedRebase, "inmemory_index", rb_git_rebase_inmemory_index, 0);
344
+ rb_define_method(rb_cRuggedRebase, "commit", rb_git_rebase_commit, -1);
345
+ rb_define_method(rb_cRuggedRebase, "abort", rb_git_rebase_abort, 0);
346
+ rb_define_method(rb_cRuggedRebase, "finish", rb_git_rebase_finish, 1);
347
+ }
348
+
349
+
350
+
351
+
352
+
353
+
354
+
355
+