rugged 0.22.0b1 → 0.22.0b2

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: 0aa39e21ccc3e603f31e60c998ccc0c71980ba60
4
- data.tar.gz: fff10f16bf3d155d9851ea92cbfa49b2f30e8dda
3
+ metadata.gz: a1fcbe10398bb6a72a8b366a061a86dc86a22d86
4
+ data.tar.gz: 6d0ab2ee6aa49b3d0d6e7f9c2f5c7ee18f01e820
5
5
  SHA512:
6
- metadata.gz: 0e4bb2074cfea2e6cef066c7bc23b28c07d2dee537ebae03697328bde5dfa8ed012b8c4bab5ad3f52ad2a43781e9230937c9778f40e32a55baf5fd125fc8eede
7
- data.tar.gz: cb09bd34a103015ad61d197989e31c7fa28df5e1199c10bf5b41e423a224d11b2b9f5e6063c07380d6617c1655ef266d3a8a3c4fbca8567ab0cc168b876f3a42
6
+ metadata.gz: 47f0d46dbfb6a493678c7c0fffc12d25ffadabc3b8210920a2f509556e2504b48de4223db27488e70a78da1d2bbf6d440dfe15b3992ff7a2ded9bdebf5219d3b
7
+ data.tar.gz: 2c83e8937a0bda990da855f793901299269ea2cf174c2e7f7501795c7f3a7377b37b60fe555a453963206d93c4c035fe24c9ee02afcd084d101e484426b35030
@@ -32,6 +32,7 @@ extern VALUE rb_cRuggedRepo;
32
32
  static ID id_read;
33
33
 
34
34
  VALUE rb_cRuggedBlob;
35
+ VALUE rb_cRuggedBlobLoader;
35
36
  VALUE rb_cRuggedBlobSig;
36
37
 
37
38
  /*
@@ -479,46 +480,75 @@ static VALUE rb_git_blob_diff(int argc, VALUE *argv, VALUE self)
479
480
  return rugged_patch_new(self, patch);
480
481
  }
481
482
 
482
- static VALUE rb_git_blob_to_buffer(int argc, VALUE *argv, VALUE self)
483
+ /*
484
+ * call-seq:
485
+ * Rugged::Blob::Loader.new(repository, max_size) -> Blob::Loader instance
486
+ *
487
+ * Create a Blob Loader instance that allows you to bring several blobs
488
+ * from the object database with no extra memory cost by reusing the same
489
+ * underlying storage.
490
+ *
491
+ * repository - the repo where the blobs will be loaded from
492
+ * max_size - the maximum size for the underlying storage; blobs larger than
493
+ * that size will be truncated
494
+ *
495
+ * Example:
496
+ *
497
+ * loader = loader = Rugged::Blob::Loader.new(@repo, 4 * 1024)
498
+ * #=> Blob::Loader instance
499
+ *
500
+ * loader.load("d70d245ed97ed2aa596dd1af6536e4bfdb047b69")
501
+ * #=> [contents, real_size]
502
+ */
503
+ static VALUE rb_git_blob_loader_new(VALUE self, VALUE rb_repo, VALUE rb_max_bytes)
483
504
  {
484
- VALUE rb_repo, rb_sha1, rb_max_bytes;
485
- VALUE rb_ret;
505
+ long max_bytes;
506
+
507
+ rugged_check_repo(rb_repo);
508
+ Check_Type(rb_max_bytes, T_FIXNUM);
509
+
510
+ /* extra byte for NULL-termination */
511
+ max_bytes = (long)FIX2INT(rb_max_bytes) + 1;
512
+
513
+ rb_iv_set(self, "@repository", rb_repo);
514
+ rb_iv_set(self, "buffer", rb_str_buf_new(max_bytes));
515
+ return Qnil;
516
+ }
517
+
518
+ static VALUE rb_git_blob_loader_load(VALUE self, VALUE rb_sha1)
519
+ {
520
+ VALUE rb_ret, rb_repo, rb_buffer;
486
521
 
487
522
  git_repository *repo = NULL;
488
523
  git_blob *blob = NULL;
489
524
 
490
- size_t size;
525
+ size_t size, capacity;
491
526
  const char *content;
492
527
 
493
- rb_scan_args(argc, argv, "21", &rb_repo, &rb_sha1, &rb_max_bytes);
528
+ rb_repo = rb_iv_get(self, "@repository");
529
+ rb_buffer = rb_iv_get(self, "buffer");
494
530
 
531
+ Check_Type(rb_buffer, T_STRING);
495
532
  rugged_check_repo(rb_repo);
496
533
  Data_Get_Struct(rb_repo, git_repository, repo);
497
534
 
498
535
  blob = (git_blob *)rugged_object_get(repo, rb_sha1, GIT_OBJ_BLOB);
499
536
 
500
537
  content = git_blob_rawcontent(blob);
501
- size = git_blob_rawsize(blob);
538
+ size = (long)git_blob_rawsize(blob);
539
+ capacity = rb_str_capacity(rb_buffer);
502
540
 
503
- if (!NIL_P(rb_max_bytes)) {
504
- int maxbytes;
541
+ if (size > capacity - 1)
542
+ size = capacity - 1;
505
543
 
506
- Check_Type(rb_max_bytes, T_FIXNUM);
507
- maxbytes = FIX2INT(rb_max_bytes);
508
-
509
- if (maxbytes >= 0 && (size_t)maxbytes < size)
510
- size = (size_t)maxbytes;
511
- }
544
+ memcpy(RSTRING_PTR(rb_buffer), content, size);
545
+ rb_str_set_len(rb_buffer, size);
512
546
 
513
547
  rb_ret = rb_ary_new();
514
-
515
- rb_ary_push(rb_ret, rb_str_new(content, size));
548
+ rb_ary_push(rb_ret, rb_buffer);
516
549
  rb_ary_push(rb_ret, INT2FIX(git_blob_rawsize(blob)));
517
550
 
518
551
  git_object_free((git_object*)blob);
519
-
520
- /* TODO: LOC */
521
-
522
552
  return rb_ret;
523
553
  }
524
554
 
@@ -591,9 +621,11 @@ void Init_rugged_blob(void)
591
621
  rb_define_singleton_method(rb_cRuggedBlob, "from_disk", rb_git_blob_from_disk, 2);
592
622
  rb_define_singleton_method(rb_cRuggedBlob, "from_io", rb_git_blob_from_io, -1);
593
623
 
594
- rb_define_singleton_method(rb_cRuggedBlob, "to_buffer", rb_git_blob_to_buffer, -1);
595
-
596
624
  rb_cRuggedBlobSig = rb_define_class_under(rb_cRuggedBlob, "HashSignature", rb_cObject);
597
625
  rb_define_singleton_method(rb_cRuggedBlobSig, "new", rb_git_blob_sig_new, -1);
598
626
  rb_define_singleton_method(rb_cRuggedBlobSig, "compare", rb_git_blob_sig_compare, 2);
627
+
628
+ rb_cRuggedBlobLoader = rb_define_class_under(rb_cRuggedBlob, "Loader", rb_cObject);
629
+ rb_define_method(rb_cRuggedBlobLoader, "initialize", rb_git_blob_loader_new, 2);
630
+ rb_define_method(rb_cRuggedBlobLoader, "load", rb_git_blob_loader_load, 1);
599
631
  }
@@ -1,3 +1,3 @@
1
1
  module Rugged
2
- Version = VERSION = '0.22.0b1'
2
+ Version = VERSION = '0.22.0b2'
3
3
  end
@@ -14,6 +14,7 @@
14
14
  #include "indexer.h"
15
15
  #include "strarray.h"
16
16
  #include "transport.h"
17
+ #include "push.h"
17
18
 
18
19
  /**
19
20
  * @file git2/remote.h
@@ -280,14 +281,19 @@ GIT_EXTERN(const git_refspec *)git_remote_get_refspec(const git_remote *remote,
280
281
  GIT_EXTERN(int) git_remote_connect(git_remote *remote, git_direction direction);
281
282
 
282
283
  /**
283
- * Get a list of refs at the remote
284
+ * Get the remote repository's reference advertisement list
284
285
  *
285
- * The remote (or more exactly its transport) must be connected. The
286
- * memory belongs to the remote.
286
+ * Get the list of references with which the server responds to a new
287
+ * connection.
287
288
  *
288
- * The array will stay valid as long as the remote object exists and
289
- * its transport isn't changed, but a copy is recommended for usage of
290
- * the data.
289
+ * The remote (or more exactly its transport) must have connected to
290
+ * the remote repository. This list is available as soon as the
291
+ * connection to the remote is initiated and it remains available
292
+ * after disconnecting.
293
+ *
294
+ * The memory belongs to the remote. The pointer will be valid as long
295
+ * as a new connection is not initiated, but it is recommended that
296
+ * you make a copy in order to make use of the data.
291
297
  *
292
298
  * @param out pointer to the array
293
299
  * @param size the number of remote heads
@@ -337,8 +343,7 @@ GIT_EXTERN(void) git_remote_stop(git_remote *remote);
337
343
  /**
338
344
  * Disconnect from the remote
339
345
  *
340
- * Close the connection to the remote and free the underlying
341
- * transport.
346
+ * Close the connection to the remote.
342
347
  *
343
348
  * @param remote the remote to disconnect from
344
349
  */
@@ -389,6 +394,23 @@ GIT_EXTERN(int) git_remote_fetch(
389
394
  const git_signature *signature,
390
395
  const char *reflog_message);
391
396
 
397
+ /**
398
+ * Perform a push
399
+ *
400
+ * Peform all the steps from a push.
401
+ *
402
+ * @param remote the remote to push to
403
+ * @param refspecs the refspecs to use for pushing. If none are
404
+ * passed, the configured refspecs will be used
405
+ * @param opts the options
406
+ * @param signature signature to use for the reflog of updated references
407
+ * @param reflog_message message to use for the reflog of upated references
408
+ */
409
+ GIT_EXTERN(int) git_remote_push(git_remote *remote,
410
+ git_strarray *refspecs,
411
+ const git_push_options *opts,
412
+ const git_signature *signature, const char *reflog_message);
413
+
392
414
  /**
393
415
  * Get a list of the configured remotes for a repo
394
416
  *
@@ -461,6 +483,28 @@ struct git_remote_callbacks {
461
483
  */
462
484
  int (*update_tips)(const char *refname, const git_oid *a, const git_oid *b, void *data);
463
485
 
486
+ /**
487
+ * Function to call with progress information during pack
488
+ * building. Be aware that this is called inline with pack
489
+ * building operations, so performance may be affected.
490
+ */
491
+ git_packbuilder_progress pack_progress;
492
+
493
+ /**
494
+ * Function to call with progress information during the
495
+ * upload portion of a push. Be aware that this is called
496
+ * inline with pack building operations, so performance may be
497
+ * affected.
498
+ */
499
+ git_push_transfer_progress push_transfer_progress;
500
+
501
+ /**
502
+ * Called for each updated reference on push. If `status` is
503
+ * not `NULL`, the update was rejected by the remote server
504
+ * and `status` contains the reason given.
505
+ */
506
+ int (*push_update_reference)(const char *refname, const char *status, void *data);
507
+
464
508
  /**
465
509
  * This will be passed to each of the callbacks in this struct
466
510
  * as the last parameter.
@@ -762,12 +762,12 @@ static int hardcoded_objects(git_rawobj *raw, const git_oid *id)
762
762
  if (!git_oid_cmp(id, &empty_blob)) {
763
763
  raw->type = GIT_OBJ_BLOB;
764
764
  raw->len = 0;
765
- raw->data = NULL;
765
+ raw->data = git__calloc(1, sizeof(uint8_t));
766
766
  return 0;
767
767
  } else if (!git_oid_cmp(id, &empty_tree)) {
768
768
  raw->type = GIT_OBJ_TREE;
769
769
  raw->len = 0;
770
- raw->data = NULL;
770
+ raw->data = git__calloc(1, sizeof(uint8_t));
771
771
  return 0;
772
772
  } else {
773
773
  return GIT_ENOTFOUND;
@@ -333,7 +333,8 @@ static int revwalk(git_vector *commits, git_push *push)
333
333
  continue;
334
334
 
335
335
  if (!git_odb_exists(push->repo->_odb, &spec->roid)) {
336
- giterr_set(GITERR_REFERENCE, "Cannot push missing reference");
336
+ giterr_set(GITERR_REFERENCE,
337
+ "Cannot push because a reference that you are trying to update on the remote contains commits that are not present locally.");
337
338
  error = GIT_ENONFASTFORWARD;
338
339
  goto on_error;
339
340
  }
@@ -706,7 +706,7 @@ int git_remote_ls(const git_remote_head ***out, size_t *size, git_remote *remote
706
706
  assert(remote);
707
707
 
708
708
  if (!remote->transport) {
709
- giterr_set(GITERR_NET, "No transport bound to this remote");
709
+ giterr_set(GITERR_NET, "this remote has never connected");
710
710
  return -1;
711
711
  }
712
712
 
@@ -2115,3 +2115,63 @@ int git_remote_default_branch(git_buf *out, git_remote *remote)
2115
2115
 
2116
2116
  return git_buf_puts(out, guess->name);
2117
2117
  }
2118
+
2119
+ int git_remote_push(git_remote *remote, git_strarray *refspecs, const git_push_options *opts,
2120
+ const git_signature *signature, const char *reflog_message)
2121
+ {
2122
+ int error;
2123
+ size_t i;
2124
+ git_push *push = NULL;
2125
+ git_remote_callbacks *cbs;
2126
+ git_refspec *spec;
2127
+
2128
+ assert(remote && refspecs);
2129
+
2130
+ if ((error = git_remote_connect(remote, GIT_DIRECTION_PUSH)) < 0)
2131
+ return error;
2132
+
2133
+ if ((error = git_push_new(&push, remote)) < 0)
2134
+ goto cleanup;
2135
+
2136
+ if (opts && (error = git_push_set_options(push, opts)) < 0)
2137
+ goto cleanup;
2138
+
2139
+ if (refspecs && refspecs->count > 0) {
2140
+ for (i = 0; i < refspecs->count; i++) {
2141
+ if ((error = git_push_add_refspec(push, refspecs->strings[i])) < 0)
2142
+ goto cleanup;
2143
+ }
2144
+ } else {
2145
+ git_vector_foreach(&remote->refspecs, i, spec) {
2146
+ if (!spec->push)
2147
+ continue;
2148
+ if ((error = git_push_add_refspec(push, spec->string)) < 0)
2149
+ goto cleanup;
2150
+ }
2151
+ }
2152
+
2153
+ cbs = &remote->callbacks;
2154
+ if ((error = git_push_set_callbacks(push,
2155
+ cbs->pack_progress, cbs->payload,
2156
+ cbs->push_transfer_progress, cbs->payload)) < 0)
2157
+ goto cleanup;
2158
+
2159
+ if ((error = git_push_finish(push)) < 0)
2160
+ goto cleanup;
2161
+
2162
+ if (!git_push_unpack_ok(push)) {
2163
+ error = -1;
2164
+ giterr_set(GITERR_NET, "error in the remote while trying to unpack");
2165
+ goto cleanup;
2166
+ }
2167
+
2168
+ if ((error = git_push_status_foreach(push, cbs->push_update_reference, cbs->payload)) < 0)
2169
+ goto cleanup;
2170
+
2171
+ error = git_push_update_tips(push, signature, reflog_message);
2172
+
2173
+ cleanup:
2174
+ git_remote_disconnect(remote);
2175
+ git_push_free(push);
2176
+ return error;
2177
+ }
@@ -1009,6 +1009,7 @@ static int http_close(git_smart_subtransport *subtransport)
1009
1009
  git_vector_clear(&t->auth_contexts);
1010
1010
 
1011
1011
  gitno_connection_data_free_ptrs(&t->connection_data);
1012
+ memset(&t->connection_data, 0x0, sizeof(gitno_connection_data));
1012
1013
 
1013
1014
  return 0;
1014
1015
  }
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.22.0b1
4
+ version: 0.22.0b2
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: 2014-11-18 00:00:00.000000000 Z
12
+ date: 2014-11-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake-compiler