rugged 0.25.0b2 → 0.25.0b3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (99) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +1 -1
  3. data/ext/rugged/extconf.rb +3 -1
  4. data/ext/rugged/rugged.c +1 -1
  5. data/ext/rugged/rugged.h +1 -1
  6. data/ext/rugged/rugged_blob.c +29 -38
  7. data/ext/rugged/rugged_commit.c +215 -78
  8. data/ext/rugged/rugged_rebase.c +18 -11
  9. data/ext/rugged/rugged_remote.c +2 -2
  10. data/ext/rugged/rugged_tree.c +132 -0
  11. data/lib/rugged/version.rb +1 -1
  12. data/vendor/libgit2/CMakeLists.txt +11 -3
  13. data/vendor/libgit2/include/git2.h +1 -0
  14. data/vendor/libgit2/include/git2/blob.h +39 -28
  15. data/vendor/libgit2/include/git2/commit.h +30 -0
  16. data/vendor/libgit2/include/git2/common.h +16 -1
  17. data/vendor/libgit2/include/git2/merge.h +10 -1
  18. data/vendor/libgit2/include/git2/proxy.h +92 -0
  19. data/vendor/libgit2/include/git2/refs.h +11 -0
  20. data/vendor/libgit2/include/git2/remote.h +17 -4
  21. data/vendor/libgit2/include/git2/signature.h +13 -0
  22. data/vendor/libgit2/include/git2/sys/merge.h +177 -0
  23. data/vendor/libgit2/include/git2/sys/remote.h +16 -0
  24. data/vendor/libgit2/include/git2/sys/stream.h +2 -1
  25. data/vendor/libgit2/include/git2/sys/transport.h +3 -1
  26. data/vendor/libgit2/include/git2/tag.h +9 -0
  27. data/vendor/libgit2/include/git2/tree.h +55 -0
  28. data/vendor/libgit2/src/annotated_commit.c +99 -80
  29. data/vendor/libgit2/src/annotated_commit.h +5 -2
  30. data/vendor/libgit2/src/array.h +40 -0
  31. data/vendor/libgit2/src/blame.c +8 -3
  32. data/vendor/libgit2/src/blame_git.c +2 -1
  33. data/vendor/libgit2/src/blob.c +71 -39
  34. data/vendor/libgit2/src/branch.c +2 -1
  35. data/vendor/libgit2/src/checkout.c +66 -42
  36. data/vendor/libgit2/src/commit.c +67 -3
  37. data/vendor/libgit2/src/config_cache.c +2 -1
  38. data/vendor/libgit2/src/config_file.c +32 -27
  39. data/vendor/libgit2/src/curl_stream.c +89 -6
  40. data/vendor/libgit2/src/delta-apply.c +36 -5
  41. data/vendor/libgit2/src/delta-apply.h +12 -0
  42. data/vendor/libgit2/src/describe.c +3 -2
  43. data/vendor/libgit2/src/diff.c +13 -20
  44. data/vendor/libgit2/src/diff_tform.c +5 -3
  45. data/vendor/libgit2/src/filebuf.c +12 -2
  46. data/vendor/libgit2/src/filebuf.h +1 -0
  47. data/vendor/libgit2/src/fnmatch.c +18 -5
  48. data/vendor/libgit2/src/global.c +18 -0
  49. data/vendor/libgit2/src/global.h +1 -0
  50. data/vendor/libgit2/src/ignore.c +11 -3
  51. data/vendor/libgit2/src/index.c +11 -5
  52. data/vendor/libgit2/src/indexer.c +11 -7
  53. data/vendor/libgit2/src/iterator.c +1575 -1468
  54. data/vendor/libgit2/src/iterator.h +52 -69
  55. data/vendor/libgit2/src/merge.c +160 -63
  56. data/vendor/libgit2/src/merge.h +61 -2
  57. data/vendor/libgit2/src/merge_driver.c +397 -0
  58. data/vendor/libgit2/src/merge_driver.h +60 -0
  59. data/vendor/libgit2/src/merge_file.c +11 -49
  60. data/vendor/libgit2/src/netops.c +12 -10
  61. data/vendor/libgit2/src/object.c +3 -6
  62. data/vendor/libgit2/src/object_api.c +19 -1
  63. data/vendor/libgit2/src/odb_loose.c +1 -1
  64. data/vendor/libgit2/src/openssl_stream.c +16 -3
  65. data/vendor/libgit2/src/pack-objects.c +3 -1
  66. data/vendor/libgit2/src/pack.c +5 -9
  67. data/vendor/libgit2/src/path.c +14 -0
  68. data/vendor/libgit2/src/path.h +12 -0
  69. data/vendor/libgit2/src/pathspec.c +1 -1
  70. data/vendor/libgit2/src/posix.c +7 -0
  71. data/vendor/libgit2/src/posix.h +1 -0
  72. data/vendor/libgit2/src/proxy.c +32 -0
  73. data/vendor/libgit2/src/proxy.h +14 -0
  74. data/vendor/libgit2/src/push.c +7 -7
  75. data/vendor/libgit2/src/rebase.c +61 -31
  76. data/vendor/libgit2/src/refdb_fs.c +1 -0
  77. data/vendor/libgit2/src/refs.c +16 -1
  78. data/vendor/libgit2/src/remote.c +20 -6
  79. data/vendor/libgit2/src/repository.c +1 -1
  80. data/vendor/libgit2/src/reset.c +1 -1
  81. data/vendor/libgit2/src/settings.c +23 -1
  82. data/vendor/libgit2/src/signature.c +26 -1
  83. data/vendor/libgit2/src/stransport_stream.c +5 -2
  84. data/vendor/libgit2/src/stream.h +2 -2
  85. data/vendor/libgit2/src/submodule.c +3 -2
  86. data/vendor/libgit2/src/tag.c +8 -2
  87. data/vendor/libgit2/src/transports/http.c +32 -9
  88. data/vendor/libgit2/src/transports/local.c +4 -1
  89. data/vendor/libgit2/src/transports/smart.c +6 -0
  90. data/vendor/libgit2/src/transports/smart.h +1 -0
  91. data/vendor/libgit2/src/transports/smart_protocol.c +61 -17
  92. data/vendor/libgit2/src/transports/winhttp.c +130 -11
  93. data/vendor/libgit2/src/tree.c +329 -98
  94. data/vendor/libgit2/src/tree.h +4 -5
  95. data/vendor/libgit2/src/unix/map.c +5 -0
  96. data/vendor/libgit2/src/win32/map.c +24 -5
  97. data/vendor/libgit2/src/xdiff/xprepare.c +2 -1
  98. metadata +10 -4
  99. data/vendor/libgit2/Makefile.embed +0 -60
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4f92aa719b09c0bc6b851086d77eaceaee7d652c
4
- data.tar.gz: e87ded2043f332eae518cdfd4405f7e05cf40413
3
+ metadata.gz: decef5bc39de7103a2e879463898551989f0356f
4
+ data.tar.gz: 0011b10ea74d9092eaa562c635a1fbfc9aa8603d
5
5
  SHA512:
6
- metadata.gz: 3bcc955d28541daed191f26bc4ae37a336bd0cb2a701da8a31990255920e1b87f2d0d20081bf41cda7ec4af1094acab9b08ca4c531e94dba74cc8f84a6cedb45
7
- data.tar.gz: 79d06e428b8d9b03a3d132530e88e7b85e3c4865959ce553c5751a23c10cacca27308edb43b655a7982dbd296d107b6deba0dcfebb9ffe94cfa3a9b09e0d87c0
6
+ metadata.gz: a72e1a7f4f0053397c15a3f995ed11b4fa3255202ff738a148652f4813ce619d62481423084b471659905a023d3c2ed42d83d182c86f0a66cfdb50ab18fe2aef
7
+ data.tar.gz: b45c43553374f7eb2ea44728f9fb9e15e2eb8bee4f70261c6336f38d9d8345d7b87b567289e040663426a2a3a0216a46197130ef0b3e386fe0d19cdb40388ba2
data/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License
2
2
 
3
- Copyright (c) 2015 GitHub, Inc
3
+ Copyright (c) 2016 GitHub, Inc
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -67,7 +67,9 @@ else
67
67
  Dir.mkdir("build") if !Dir.exists?("build")
68
68
 
69
69
  Dir.chdir("build") do
70
- sys("cmake .. -DBUILD_CLAR=OFF -DTHREADSAFE=ON -DBUILD_SHARED_LIBS=OFF -DCMAKE_C_FLAGS=-fPIC -DCMAKE_BUILD_TYPE=RelWithDebInfo -G \"Unix Makefiles\"")
70
+ # On Windows, Ruby-DevKit is MSYS-based, so ensure to use MSYS Makefiles.
71
+ generator = "-G \"MSYS Makefiles\"" if windows?
72
+ sys("cmake .. -DBUILD_CLAR=OFF -DTHREADSAFE=ON -DBUILD_SHARED_LIBS=OFF -DCMAKE_C_FLAGS=-fPIC -DCMAKE_BUILD_TYPE=RelWithDebInfo #{generator}")
71
73
  sys(MAKE)
72
74
 
73
75
  # "normal" libraries (and libgit2 builds) get all these when they build but we're doing it
data/ext/rugged/rugged.c CHANGED
@@ -181,7 +181,7 @@ static VALUE rb_git_raw_to_hex(VALUE self, VALUE raw)
181
181
  git_oid_fromraw(&oid, (const unsigned char *)RSTRING_PTR(raw));
182
182
  git_oid_fmt(out, &oid);
183
183
 
184
- return rb_str_new(out, 40);
184
+ return rb_usascii_str_new(out, 40);
185
185
  }
186
186
 
187
187
  /*
data/ext/rugged/rugged.h CHANGED
@@ -176,7 +176,7 @@ static inline VALUE rugged_create_oid(const git_oid *oid)
176
176
  {
177
177
  char out[40];
178
178
  git_oid_fmt(out, oid);
179
- return rb_str_new(out, 40);
179
+ return rb_usascii_str_new(out, 40);
180
180
  }
181
181
 
182
182
 
@@ -231,30 +231,6 @@ static VALUE rb_read_check(VALUE pointer) {
231
231
  return rb_buffer;
232
232
  }
233
233
 
234
- static int cb_blob__get__chunk(char *content, size_t max_length, void *data)
235
- {
236
- VALUE rb_buffer, rb_args[2];
237
- size_t str_len, safe_len;
238
- struct rugged_cb_payload *payload = data;
239
-
240
- rb_args[0] = payload->rb_data;
241
- rb_args[1] = INT2FIX(max_length);
242
-
243
- rb_buffer = rb_protect(rb_read_check, (VALUE)rb_args, &payload->exception);
244
-
245
- if (payload->exception)
246
- return GIT_ERROR;
247
-
248
- if (NIL_P(rb_buffer))
249
- return 0;
250
-
251
- str_len = (size_t)RSTRING_LEN(rb_buffer);
252
- safe_len = str_len > max_length ? max_length : str_len;
253
- memcpy(content, StringValuePtr(rb_buffer), safe_len);
254
-
255
- return (int)safe_len;
256
- }
257
-
258
234
  /*
259
235
  * call-seq:
260
236
  * Blob.from_io(repository, io [, hint_path]) -> oid
@@ -282,11 +258,10 @@ static int cb_blob__get__chunk(char *content, size_t max_length, void *data)
282
258
  */
283
259
  static VALUE rb_git_blob_from_io(int argc, VALUE *argv, VALUE klass)
284
260
  {
285
- VALUE rb_repo, rb_io, rb_hint_path;
286
- struct rugged_cb_payload payload;
261
+ VALUE rb_repo, rb_io, rb_hint_path, rb_buffer, rb_read_args[2];
287
262
  const char * hint_path = NULL;
288
-
289
- int error;
263
+ git_writestream *stream;
264
+ int error = 0, exception = 0, max_length = 4096;
290
265
  git_oid oid;
291
266
  git_repository *repo;
292
267
 
@@ -300,18 +275,34 @@ static VALUE rb_git_blob_from_io(int argc, VALUE *argv, VALUE klass)
300
275
  hint_path = StringValueCStr(rb_hint_path);
301
276
  }
302
277
 
303
- payload.exception = 0;
304
- payload.rb_data = rb_io;
278
+ error = git_blob_create_fromstream(&stream, repo, hint_path);
279
+ if (error)
280
+ goto cleanup;
281
+
282
+ rb_read_args[0] = rb_io;
283
+ rb_read_args[1] = INT2FIX(max_length);
284
+
285
+ do {
286
+ rb_buffer = rb_protect(rb_read_check, (VALUE)rb_read_args, &exception);
287
+
288
+ if (exception)
289
+ goto cleanup;
290
+
291
+ if (NIL_P(rb_buffer))
292
+ break;
293
+
294
+ error = stream->write(stream, RSTRING_PTR(rb_buffer), RSTRING_LEN(rb_buffer));
295
+ if (error)
296
+ goto cleanup;
297
+ } while (RSTRING_LEN(rb_buffer) == max_length);
298
+
299
+ error = git_blob_create_fromstream_commit(&oid, stream);
300
+
301
+ cleanup:
305
302
 
306
- error = git_blob_create_fromchunks(
307
- &oid,
308
- repo,
309
- hint_path,
310
- cb_blob__get__chunk,
311
- (void *)&payload);
303
+ if (exception)
304
+ rb_jump_tag(exception);
312
305
 
313
- if (payload.exception)
314
- rb_jump_tag(payload.exception);
315
306
  rugged_exception_check(error);
316
307
 
317
308
  return rugged_create_oid(&oid);
@@ -338,69 +338,44 @@ static VALUE rb_git_commit_amend(VALUE self, VALUE rb_data)
338
338
  return rugged_create_oid(&commit_oid);
339
339
  }
340
340
 
341
- /*
342
- * call-seq:
343
- * Commit.create(repository, data = {}) -> oid
344
- *
345
- * Write a new +Commit+ object to +repository+, with the given +data+
346
- * arguments, passed as a +Hash+:
347
- *
348
- * - +:message+: a string with the full text for the commit's message
349
- * - +:committer+ (optional): a hash with the signature for the committer,
350
- * defaults to the signature from the configuration
351
- * - +:author+ (optional): a hash with the signature for the author,
352
- * defaults to the signature from the configuration
353
- * - +:parents+: an +Array+ with zero or more parents for this commit,
354
- * represented as <tt>Rugged::Commit</tt> instances, or OID +String+.
355
- * - +:tree+: the tree for this commit, represented as a <tt>Rugged::Tree</tt>
356
- * instance or an OID +String+.
357
- * - +:update_ref+ (optional): a +String+ with the name of a reference in the
358
- * repository which should be updated to point to this commit (e.g. "HEAD")
359
- *
360
- * When the commit is successfully written to disk, its +oid+ will be
361
- * returned as a hex +String+.
362
- *
363
- * author = {:email=>"tanoku@gmail.com", :time=>Time.now, :name=>"Vicent Mart\303\255"}
341
+ struct commit_data {
342
+ VALUE rb_err_obj;
343
+
344
+ const char *update_ref;
345
+ const char *message;
346
+ git_tree *tree;
347
+ git_signature *author;
348
+ git_signature *committer;
349
+ int parent_count;
350
+ const git_commit **parents;
351
+ };
352
+
353
+ /**
354
+ * Parse the commit options into something we can re-use
364
355
  *
365
- * Rugged::Commit.create(r,
366
- * :author => author,
367
- * :message => "Hello world\n\n",
368
- * :committer => author,
369
- * :parents => ["2cb831a8aea28b2c1b9c63385585b864e4d3bad1"],
370
- * :tree => some_tree) #=> "f148106ca58764adc93ad4e2d6b1d168422b9796"
356
+ * Note that parents may be set even when the function errors, so make
357
+ * sure to free this data.
371
358
  */
372
- static VALUE rb_git_commit_create(VALUE self, VALUE rb_repo, VALUE rb_data)
359
+ static VALUE parse_commit_options(struct commit_data *out, git_repository *repo, VALUE rb_data)
373
360
  {
374
361
  VALUE rb_message, rb_tree, rb_parents, rb_ref;
375
- VALUE rb_err_obj = Qnil;
376
- int parent_count, i, error = 0;
377
- const git_commit **parents = NULL;
378
- git_commit **free_list = NULL;
379
- git_tree *tree;
380
- git_signature *author, *committer;
381
- git_oid commit_oid;
382
- git_repository *repo;
383
- const char *update_ref = NULL;
384
-
385
- Check_Type(rb_data, T_HASH);
386
-
387
- rugged_check_repo(rb_repo);
388
- Data_Get_Struct(rb_repo, git_repository, repo);
362
+ int error = 0, parent_count, i;
389
363
 
390
364
  rb_ref = rb_hash_aref(rb_data, CSTR2SYM("update_ref"));
391
365
  if (!NIL_P(rb_ref)) {
392
366
  Check_Type(rb_ref, T_STRING);
393
- update_ref = StringValueCStr(rb_ref);
367
+ out->update_ref = StringValueCStr(rb_ref);
394
368
  }
395
369
 
396
370
  rb_message = rb_hash_aref(rb_data, CSTR2SYM("message"));
397
371
  Check_Type(rb_message, T_STRING);
372
+ out->message = StringValueCStr(rb_message);
398
373
 
399
- committer = rugged_signature_get(
374
+ out->committer = rugged_signature_get(
400
375
  rb_hash_aref(rb_data, CSTR2SYM("committer")), repo
401
376
  );
402
377
 
403
- author = rugged_signature_get(
378
+ out->author = rugged_signature_get(
404
379
  rb_hash_aref(rb_data, CSTR2SYM("author")), repo
405
380
  );
406
381
 
@@ -408,16 +383,15 @@ static VALUE rb_git_commit_create(VALUE self, VALUE rb_repo, VALUE rb_data)
408
383
  Check_Type(rb_parents, T_ARRAY);
409
384
 
410
385
  rb_tree = rb_hash_aref(rb_data, CSTR2SYM("tree"));
411
- tree = (git_tree *)rugged_object_get(repo, rb_tree, GIT_OBJ_TREE);
386
+ out->tree = (git_tree *)rugged_object_get(repo, rb_tree, GIT_OBJ_TREE);
412
387
 
413
- parents = alloca(RARRAY_LEN(rb_parents) * sizeof(void *));
414
- free_list = alloca(RARRAY_LEN(rb_parents) * sizeof(void *));
388
+ out->parents = xcalloc(RARRAY_LEN(rb_parents), sizeof(void *));
415
389
  parent_count = 0;
416
390
 
417
391
  for (i = 0; i < (int)RARRAY_LEN(rb_parents); ++i) {
418
392
  VALUE p = rb_ary_entry(rb_parents, i);
419
393
  git_commit *parent = NULL;
420
- git_commit *free_ptr = NULL;
394
+ git_commit *tmp = NULL;
421
395
 
422
396
  if (NIL_P(p))
423
397
  continue;
@@ -427,49 +401,106 @@ static VALUE rb_git_commit_create(VALUE self, VALUE rb_repo, VALUE rb_data)
427
401
 
428
402
  error = git_oid_fromstr(&oid, StringValueCStr(p));
429
403
  if (error < GIT_OK)
430
- goto cleanup;
404
+ goto out;
431
405
 
432
406
  error = git_commit_lookup(&parent, repo, &oid);
433
407
  if (error < GIT_OK)
434
- goto cleanup;
435
-
436
- free_ptr = parent;
437
-
408
+ goto out;
438
409
  } else if (rb_obj_is_kind_of(p, rb_cRuggedCommit)) {
439
- Data_Get_Struct(p, git_commit, parent);
410
+ Data_Get_Struct(p, git_commit, tmp);
411
+ if ((error = git_object_dup((git_object **) &parent, (git_object *) tmp)) < 0)
412
+ goto out;
440
413
  } else {
441
- rb_err_obj = rb_exc_new2(rb_eTypeError, "Invalid type for parent object");
442
- goto cleanup;
414
+ out->rb_err_obj = rb_exc_new2(rb_eTypeError, "Invalid type for parent object");
415
+ error = -1;
416
+ goto out;
443
417
  }
444
418
 
445
- parents[parent_count] = parent;
446
- free_list[parent_count] = free_ptr;
419
+ out->parents[parent_count] = parent;
447
420
  parent_count++;
448
421
  }
449
422
 
423
+ out:
424
+ out->parent_count = parent_count;
425
+ return error;
426
+ }
427
+
428
+ static void free_commit_options(struct commit_data *commit_data)
429
+ {
430
+ int i;
431
+
432
+ git_signature_free(commit_data->author);
433
+ git_signature_free(commit_data->committer);
434
+
435
+ git_object_free((git_object *)commit_data->tree);
436
+
437
+ for (i = 0; i < commit_data->parent_count; ++i)
438
+ git_object_free((git_object *) commit_data->parents[i]);
439
+ xfree(commit_data->parents);
440
+ }
441
+
442
+ /*
443
+ * call-seq:
444
+ * Commit.create(repository, data = {}) -> oid
445
+ *
446
+ * Write a new +Commit+ object to +repository+, with the given +data+
447
+ * arguments, passed as a +Hash+:
448
+ *
449
+ * - +:message+: a string with the full text for the commit's message
450
+ * - +:committer+ (optional): a hash with the signature for the committer,
451
+ * defaults to the signature from the configuration
452
+ * - +:author+ (optional): a hash with the signature for the author,
453
+ * defaults to the signature from the configuration
454
+ * - +:parents+: an +Array+ with zero or more parents for this commit,
455
+ * represented as <tt>Rugged::Commit</tt> instances, or OID +String+.
456
+ * - +:tree+: the tree for this commit, represented as a <tt>Rugged::Tree</tt>
457
+ * instance or an OID +String+.
458
+ * - +:update_ref+ (optional): a +String+ with the name of a reference in the
459
+ * repository which should be updated to point to this commit (e.g. "HEAD")
460
+ *
461
+ * When the commit is successfully written to disk, its +oid+ will be
462
+ * returned as a hex +String+.
463
+ *
464
+ * author = {:email=>"tanoku@gmail.com", :time=>Time.now, :name=>"Vicent Mart\303\255"}
465
+ *
466
+ * Rugged::Commit.create(r,
467
+ * :author => author,
468
+ * :message => "Hello world\n\n",
469
+ * :committer => author,
470
+ * :parents => ["2cb831a8aea28b2c1b9c63385585b864e4d3bad1"],
471
+ * :tree => some_tree) #=> "f148106ca58764adc93ad4e2d6b1d168422b9796"
472
+ */
473
+ static VALUE rb_git_commit_create(VALUE self, VALUE rb_repo, VALUE rb_data)
474
+ {
475
+ int error = 0;
476
+ struct commit_data commit_data = { Qnil };
477
+ git_oid commit_oid;
478
+ git_repository *repo;
479
+
480
+ Check_Type(rb_data, T_HASH);
481
+
482
+ rugged_check_repo(rb_repo);
483
+ Data_Get_Struct(rb_repo, git_repository, repo);
484
+
485
+ if ((error = parse_commit_options(&commit_data, repo, rb_data)) < 0)
486
+ goto cleanup;
487
+
450
488
  error = git_commit_create(
451
489
  &commit_oid,
452
490
  repo,
453
- update_ref,
454
- author,
455
- committer,
491
+ commit_data.update_ref,
492
+ commit_data.author,
493
+ commit_data.committer,
456
494
  NULL,
457
- StringValueCStr(rb_message),
458
- tree,
459
- parent_count,
460
- parents);
495
+ commit_data.message,
496
+ commit_data.tree,
497
+ commit_data.parent_count,
498
+ commit_data.parents);
461
499
 
462
500
  cleanup:
463
- git_signature_free(author);
464
- git_signature_free(committer);
465
-
466
- git_object_free((git_object *)tree);
467
-
468
- for (i = 0; i < parent_count; ++i)
469
- git_object_free((git_object *)free_list[i]);
470
-
471
- if (!NIL_P(rb_err_obj))
472
- rb_exc_raise(rb_err_obj);
501
+ free_commit_options(&commit_data);
502
+ if (!NIL_P(commit_data.rb_err_obj))
503
+ rb_exc_raise(commit_data.rb_err_obj);
473
504
 
474
505
  rugged_exception_check(error);
475
506
 
@@ -662,11 +693,117 @@ static VALUE rb_git_commit_extract_signature(int argc, VALUE *argv, VALUE self)
662
693
  return ret;
663
694
  }
664
695
 
696
+ /*
697
+ * call-seq:
698
+ * Commit.create_to_s(repository, data = {}) -> str
699
+ *
700
+ * Create a string with the contents of the commit, created with the
701
+ * given +data+ arguments, passed as a +Hash+:
702
+ *
703
+ * - +:message+: a string with the full text for the commit's message
704
+ * - +:committer+ (optional): a hash with the signature for the committer,
705
+ * defaults to the signature from the configuration
706
+ * - +:author+ (optional): a hash with the signature for the author,
707
+ * defaults to the signature from the configuration
708
+ * - +:parents+: an +Array+ with zero or more parents for this commit,
709
+ * represented as <tt>Rugged::Commit</tt> instances, or OID +String+.
710
+ * - +:tree+: the tree for this commit, represented as a <tt>Rugged::Tree</tt>
711
+ * instance or an OID +String+.
712
+ *
713
+ * author = {:email=>"tanoku@gmail.com", :time=>Time.now, :name=>"Vicent Mart\303\255"}
714
+ *
715
+ * Rugged::Commit.create(r,
716
+ * :author => author,
717
+ * :message => "Hello world\n\n",
718
+ * :committer => author,
719
+ * :parents => ["2cb831a8aea28b2c1b9c63385585b864e4d3bad1"],
720
+ * :tree => some_tree) #=> "tree some_tree\nparent 2cb831...."
721
+ */
722
+ static VALUE rb_git_commit_create_to_s(VALUE self, VALUE rb_repo, VALUE rb_data)
723
+ {
724
+ int error = 0;
725
+ struct commit_data commit_data = { Qnil };
726
+ git_repository *repo;
727
+ git_buf buf = { 0 };
728
+ VALUE ret;
729
+
730
+ Check_Type(rb_data, T_HASH);
731
+
732
+ rugged_check_repo(rb_repo);
733
+ Data_Get_Struct(rb_repo, git_repository, repo);
734
+
735
+ if ((error = parse_commit_options(&commit_data, repo, rb_data)) < 0)
736
+ goto cleanup;
737
+
738
+ error = git_commit_create_buffer(
739
+ &buf,
740
+ repo,
741
+ commit_data.author,
742
+ commit_data.committer,
743
+ NULL,
744
+ commit_data.message,
745
+ commit_data.tree,
746
+ commit_data.parent_count,
747
+ commit_data.parents);
748
+
749
+ cleanup:
750
+ free_commit_options(&commit_data);
751
+ if (!NIL_P(commit_data.rb_err_obj))
752
+ rb_exc_raise(commit_data.rb_err_obj);
753
+
754
+ rugged_exception_check(error);
755
+
756
+ ret = rb_str_new_utf8(buf.ptr);
757
+ git_buf_free(&buf);
758
+
759
+ return ret;
760
+ }
761
+
762
+ /*
763
+ * call-seq:
764
+ * Rugged::Commit.create_with_signature(repo, content, signature, field_name = "gpgsig") -> oid
765
+ *
766
+ * Create a commit from the +content+ string and the +signature+,
767
+ * adding this data to the +field_name+ header field in the resulting
768
+ * commit.
769
+ *
770
+ * Returns the new commit's object id.
771
+ *
772
+ */
773
+ static VALUE rb_git_commit_create_with_signature(int argc, VALUE *argv, VALUE self)
774
+ {
775
+ int error;
776
+ git_oid id;
777
+ const char *field = NULL;
778
+ git_repository *repo;
779
+ VALUE rb_repo, rb_content, rb_signature, rb_field = Qnil;
780
+
781
+ rb_scan_args(argc, argv, "31", &rb_repo, &rb_content, &rb_signature, &rb_field);
782
+
783
+ rugged_check_repo(rb_repo);
784
+ Data_Get_Struct(rb_repo, git_repository, repo);
785
+
786
+ Check_Type(rb_content, T_STRING);
787
+ Check_Type(rb_signature, T_STRING);
788
+
789
+ if (!NIL_P(rb_field)) {
790
+ Check_Type(rb_field, T_STRING);
791
+ field = StringValueCStr(rb_field);
792
+ }
793
+
794
+ error = git_commit_create_with_signature(&id, repo, StringValueCStr(rb_content), StringValueCStr(rb_signature), field);
795
+ rugged_exception_check(error);
796
+
797
+ return rugged_create_oid(&id);
798
+ }
799
+
665
800
  void Init_rugged_commit(void)
666
801
  {
667
802
  rb_cRuggedCommit = rb_define_class_under(rb_mRugged, "Commit", rb_cRuggedObject);
668
803
 
669
804
  rb_define_singleton_method(rb_cRuggedCommit, "create", rb_git_commit_create, 2);
805
+ rb_define_singleton_method(rb_cRuggedCommit, "create_to_s", rb_git_commit_create_to_s, 2);
806
+ rb_define_singleton_method(rb_cRuggedCommit, "create_with_signature", rb_git_commit_create_with_signature, -1);
670
807
  rb_define_singleton_method(rb_cRuggedCommit, "extract_signature", rb_git_commit_extract_signature, -1);
671
808
 
672
809
  rb_define_method(rb_cRuggedCommit, "message", rb_git_commit_message_GET, 0);