rugged 0.24.0b0 → 0.24.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: 9cbd379f155df87669ec3b453094bf4883ab30e5
4
- data.tar.gz: 05db49343e6d30304224ac60e4c12ca3feea853f
3
+ metadata.gz: cb4fe7da10d53dd706d2d8c31e63145f752483e1
4
+ data.tar.gz: 8373c3e1414d5557cfec7f5970286278b97e1daa
5
5
  SHA512:
6
- metadata.gz: 3eca55c77bfdab68087f3ce9883485755f80968c77693828c9bb12c9bd54f0cd4544a62536e64b3bd16ac98640b37113194f693f08afcc7c8a5375987d4fddcf
7
- data.tar.gz: 49e8e55c6cd7593e671f123099b8330076767eef59edde22a134262d1d594e137819c5917e500e5f843b90943f0af210998f7ea99b71d970a6a643c9ab4427fa
6
+ metadata.gz: 8779a103e14c2eeff09294d32b9d38b215903295502bf5d8619375f22fb714fa1263538b04ddc876fc3c6b5d0f23cfe6ce2cc8972caa791b859aaa3f7abe2d52
7
+ data.tar.gz: 7fded5b859f54137656ebeab2b8cdd3b3b498f5e4a3bebd1bfe49da9eef0fdc20b224bf8429c88d9cf42e675decd8913feb0ff5f89f6c9e1072896af21ad2c59
data/ext/rugged/rugged.c CHANGED
@@ -26,30 +26,36 @@
26
26
 
27
27
  const char *RUGGED_ERROR_NAMES[] = {
28
28
  "None", /* GITERR_NONE */
29
- "NoMemError", /* GITERR_NOMEMORY, */
30
- "OSError", /* GITERR_OS, */
31
- "InvalidError", /* GITERR_INVALID, */
32
- "ReferenceError", /* GITERR_REFERENCE, */
33
- "ZlibError", /* GITERR_ZLIB, */
34
- "RepositoryError", /* GITERR_REPOSITORY, */
35
- "ConfigError", /* GITERR_CONFIG, */
36
- "RegexError", /* GITERR_REGEX, */
37
- "OdbError", /* GITERR_ODB, */
38
- "IndexError", /* GITERR_INDEX, */
39
- "ObjectError", /* GITERR_OBJECT, */
40
- "NetworkError", /* GITERR_NET, */
41
- "TagError", /* GITERR_TAG, */
42
- "TreeError", /* GITERR_TREE, */
43
- "IndexerError", /* GITERR_INDEXER, */
44
- "SslError", /* GITERR_SSL, */
45
- "SubmoduleError", /* GITERR_SUBMODULE, */
46
- "ThreadError", /* GITERR_THREAD, */
47
- "StashError", /* GITERR_STASH, */
48
- "CheckoutError", /* GITERR_CHECKOUT, */
49
- "FetchheadError", /* GITERR_FETCHHEAD, */
50
- "MergeError", /* GITERR_MERGE, */
51
- "SshError", /* GITERR_SSH, */
52
- "FilterError" /* GITERR_FILTER, */
29
+ "NoMemError", /* GITERR_NOMEMORY */
30
+ "OSError", /* GITERR_OS */
31
+ "InvalidError", /* GITERR_INVALID */
32
+ "ReferenceError", /* GITERR_REFERENCE */
33
+ "ZlibError", /* GITERR_ZLIB */
34
+ "RepositoryError", /* GITERR_REPOSITORY */
35
+ "ConfigError", /* GITERR_CONFIG */
36
+ "RegexError", /* GITERR_REGEX */
37
+ "OdbError", /* GITERR_ODB */
38
+ "IndexError", /* GITERR_INDEX */
39
+ "ObjectError", /* GITERR_OBJECT */
40
+ "NetworkError", /* GITERR_NET */
41
+ "TagError", /* GITERR_TAG */
42
+ "TreeError", /* GITERR_TREE */
43
+ "IndexerError", /* GITERR_INDEXER */
44
+ "SslError", /* GITERR_SSL */
45
+ "SubmoduleError", /* GITERR_SUBMODULE */
46
+ "ThreadError", /* GITERR_THREAD */
47
+ "StashError", /* GITERR_STASH */
48
+ "CheckoutError", /* GITERR_CHECKOUT */
49
+ "FetchheadError", /* GITERR_FETCHHEAD */
50
+ "MergeError", /* GITERR_MERGE */
51
+ "SshError", /* GITERR_SSH */
52
+ "FilterError", /* GITERR_FILTER */
53
+ "RevertError", /* GITERR_REVERT */
54
+ "CallbackError", /* GITERR_CALLBACK */
55
+ "CherrypickError", /* GITERR_CHERRYPICK */
56
+ "DescribeError", /* GITERR_DESCRIBE */
57
+ "RebaseError", /* GITERR_REBASE */
58
+ "FilesystemError", /* GITERR_FILESYSTEM */
53
59
  };
54
60
 
55
61
  #define RUGGED_ERROR_COUNT (int)((sizeof(RUGGED_ERROR_NAMES)/sizeof(RUGGED_ERROR_NAMES[0])))
@@ -50,21 +50,27 @@ VALUE rugged_config_new(VALUE klass, VALUE owner, git_config *cfg)
50
50
  static VALUE rb_git_config_new(VALUE klass, VALUE rb_path)
51
51
  {
52
52
  git_config *config = NULL;
53
- int error, i;
54
53
 
55
54
  if (TYPE(rb_path) == T_ARRAY) {
55
+ int error, i;
56
+
56
57
  error = git_config_new(&config);
57
58
  rugged_exception_check(error);
58
59
 
59
- for (i = 0; i < RARRAY_LEN(rb_path); ++i) {
60
+ for (i = 0; i < RARRAY_LEN(rb_path) && !error; ++i) {
60
61
  VALUE f = rb_ary_entry(rb_path, i);
61
62
  Check_Type(f, T_STRING);
62
63
  error = git_config_add_file_ondisk(config, StringValueCStr(f), i + 1, 1);
64
+ }
65
+
66
+ if (error) {
67
+ git_config_free(config);
63
68
  rugged_exception_check(error);
64
69
  }
65
70
  } else if (TYPE(rb_path) == T_STRING) {
66
- error = git_config_open_ondisk(&config, StringValueCStr(rb_path));
67
- rugged_exception_check(error);
71
+ rugged_exception_check(
72
+ git_config_open_ondisk(&config, StringValueCStr(rb_path))
73
+ );
68
74
  } else {
69
75
  rb_raise(rb_eTypeError, "Expecting a filename or an array of filenames");
70
76
  }
@@ -181,6 +181,15 @@ void rugged_remote_init_callbacks_and_payload_from_options(
181
181
  }
182
182
  }
183
183
 
184
+ static void init_custom_headers(VALUE rb_options, git_strarray *custom_headers)
185
+ {
186
+ if (!NIL_P(rb_options))
187
+ {
188
+ VALUE rb_headers = rb_hash_aref(rb_options, CSTR2SYM("headers"));
189
+ rugged_rb_ary_to_strarray(rb_headers, custom_headers);
190
+ }
191
+ }
192
+
184
193
  static int parse_prune_type(VALUE rb_prune_type)
185
194
  {
186
195
  if (rb_prune_type == Qtrue) {
@@ -254,11 +263,15 @@ static VALUE rugged_rhead_new(const git_remote_head *head)
254
263
  * of the Rugged::Credentials types, or a proc returning one of the former.
255
264
  * The proc will be called with the +url+, the +username+ from the url (if applicable) and
256
265
  * a list of applicable credential types.
266
+ *
267
+ * :headers ::
268
+ * Extra HTTP headers to include with the request (only applies to http:// or https:// remotes)
257
269
  */
258
270
  static VALUE rb_git_remote_ls(int argc, VALUE *argv, VALUE self)
259
271
  {
260
272
  git_remote *remote;
261
273
  git_remote_callbacks callbacks = GIT_REMOTE_CALLBACKS_INIT;
274
+ git_strarray custom_headers = {0};
262
275
  const git_remote_head **heads;
263
276
 
264
277
  struct rugged_remote_cb_payload payload = { Qnil, Qnil, Qnil, Qnil, Qnil, Qnil, 0 };
@@ -276,8 +289,9 @@ static VALUE rb_git_remote_ls(int argc, VALUE *argv, VALUE self)
276
289
  return rb_funcall(self, rb_intern("to_enum"), 2, CSTR2SYM("ls"), rb_options);
277
290
 
278
291
  rugged_remote_init_callbacks_and_payload_from_options(rb_options, &callbacks, &payload);
292
+ init_custom_headers(rb_options, &custom_headers);
279
293
 
280
- if ((error = git_remote_connect(remote, GIT_DIRECTION_FETCH, &callbacks, NULL)) ||
294
+ if ((error = git_remote_connect(remote, GIT_DIRECTION_FETCH, &callbacks, &custom_headers)) ||
281
295
  (error = git_remote_ls(&heads, &heads_len, remote)))
282
296
  goto cleanup;
283
297
 
@@ -287,6 +301,7 @@ static VALUE rb_git_remote_ls(int argc, VALUE *argv, VALUE self)
287
301
  cleanup:
288
302
 
289
303
  git_remote_disconnect(remote);
304
+ git_strarray_free(&custom_headers);
290
305
 
291
306
  if (payload.exception)
292
307
  rb_jump_tag(payload.exception);
@@ -442,6 +457,9 @@ static VALUE rb_git_remote_push_refspecs(VALUE self)
442
457
  * The proc will be called with the +url+, the +username+ from the url (if
443
458
  * applicable) and a list of applicable credential types.
444
459
  *
460
+ * :headers ::
461
+ * Extra HTTP headers to include with the request (only applies to http:// or https:// remotes)
462
+ *
445
463
  * Example:
446
464
  *
447
465
  * remote = repo.remotes["origin"]
@@ -452,6 +470,7 @@ static VALUE rb_git_remote_check_connection(int argc, VALUE *argv, VALUE self)
452
470
  {
453
471
  git_remote *remote;
454
472
  git_remote_callbacks callbacks = GIT_REMOTE_CALLBACKS_INIT;
473
+ git_strarray custom_headers = {0};
455
474
  struct rugged_remote_cb_payload payload = { Qnil, Qnil, Qnil, Qnil, Qnil, Qnil, 0 };
456
475
  VALUE rb_direction, rb_options;
457
476
  ID id_direction;
@@ -470,10 +489,13 @@ static VALUE rb_git_remote_check_connection(int argc, VALUE *argv, VALUE self)
470
489
  rb_raise(rb_eTypeError, "Invalid direction. Expected :fetch or :push");
471
490
 
472
491
  rugged_remote_init_callbacks_and_payload_from_options(rb_options, &callbacks, &payload);
492
+ init_custom_headers(rb_options, &custom_headers);
473
493
 
474
- error = git_remote_connect(remote, direction, &callbacks, NULL);
494
+ error = git_remote_connect(remote, direction, &callbacks, &custom_headers);
475
495
  git_remote_disconnect(remote);
476
496
 
497
+ git_strarray_free(&custom_headers);
498
+
477
499
  if (payload.exception)
478
500
  rb_jump_tag(payload.exception);
479
501
 
@@ -499,6 +521,9 @@ static VALUE rb_git_remote_check_connection(int argc, VALUE *argv, VALUE self)
499
521
  * The proc will be called with the +url+, the +username+ from the url (if applicable) and
500
522
  * a list of applicable credential types.
501
523
  *
524
+ * :headers ::
525
+ * Extra HTTP headers to include with the request (only applies to http:// or https:// remotes)
526
+ *
502
527
  * :progress ::
503
528
  * A callback that will be executed with the textual progress received from the remote.
504
529
  * This is the text send over the progress side-band (ie. the "counting objects" output).
@@ -548,19 +573,23 @@ static VALUE rb_git_remote_fetch(int argc, VALUE *argv, VALUE self)
548
573
  Data_Get_Struct(self, git_remote, remote);
549
574
 
550
575
  rugged_remote_init_callbacks_and_payload_from_options(rb_options, &opts.callbacks, &payload);
576
+ init_custom_headers(rb_options, &opts.custom_headers);
551
577
 
552
578
  if (!NIL_P(rb_options)) {
579
+ VALUE rb_prune_type;
553
580
  VALUE rb_val = rb_hash_aref(rb_options, CSTR2SYM("message"));
581
+
554
582
  if (!NIL_P(rb_val))
555
583
  log_message = StringValueCStr(rb_val);
556
584
 
557
- VALUE rb_prune_type = rb_hash_aref(rb_options, CSTR2SYM("prune"));
585
+ rb_prune_type = rb_hash_aref(rb_options, CSTR2SYM("prune"));
558
586
  opts.prune = parse_prune_type(rb_prune_type);
559
587
  }
560
588
 
561
589
  error = git_remote_fetch(remote, &refspecs, &opts, log_message);
562
590
 
563
591
  xfree(refspecs.strings);
592
+ git_strarray_free(&opts.custom_headers);
564
593
 
565
594
  if (payload.exception)
566
595
  rb_jump_tag(payload.exception);
@@ -603,6 +632,9 @@ static VALUE rb_git_remote_fetch(int argc, VALUE *argv, VALUE self)
603
632
  * A callback that will be executed each time a reference is updated remotely. It will be
604
633
  * passed the +refname+, +old_oid+ and +new_oid+.
605
634
  *
635
+ * :headers ::
636
+ * Extra HTTP headers to include with the push (only applies to http:// or https:// remotes)
637
+ *
606
638
  * Example:
607
639
  *
608
640
  * remote = Rugged::Remote.lookup(@repo, 'origin')
@@ -627,10 +659,12 @@ static VALUE rb_git_remote_push(int argc, VALUE *argv, VALUE self)
627
659
  Data_Get_Struct(self, git_remote, remote);
628
660
 
629
661
  rugged_remote_init_callbacks_and_payload_from_options(rb_options, &opts.callbacks, &payload);
662
+ init_custom_headers(rb_options, &opts.custom_headers);
630
663
 
631
664
  error = git_remote_push(remote, &refspecs, &opts);
632
665
 
633
666
  xfree(refspecs.strings);
667
+ git_strarray_free(&opts.custom_headers);
634
668
 
635
669
  if (payload.exception)
636
670
  rb_jump_tag(payload.exception);
@@ -1,3 +1,3 @@
1
1
  module Rugged
2
- Version = VERSION = '0.24.0b0'
2
+ Version = VERSION = '0.24.0b2'
3
3
  end
@@ -591,7 +591,12 @@ INSTALL(FILES include/git2.h DESTINATION ${INCLUDE_INSTALL_DIR} )
591
591
 
592
592
  # Tests
593
593
  IF (BUILD_CLAR)
594
- FIND_PACKAGE(PythonInterp REQUIRED)
594
+ FIND_PACKAGE(PythonInterp)
595
+
596
+ IF(NOT PYTHONINTERP_FOUND)
597
+ MESSAGE(FATAL_ERROR "Could not find a python interpeter, which is needed to build the tests. "
598
+ "Make sure python is available, or pass -DBUILD_CLAR=OFF to skip building the tests")
599
+ ENDIF()
595
600
 
596
601
  SET(CLAR_FIXTURES "${CMAKE_CURRENT_SOURCE_DIR}/tests/resources/")
597
602
  SET(CLAR_PATH "${CMAKE_CURRENT_SOURCE_DIR}/tests")
@@ -374,10 +374,14 @@ static int backend_sort_cmp(const void *a, const void *b)
374
374
  const backend_internal *backend_a = (const backend_internal *)(a);
375
375
  const backend_internal *backend_b = (const backend_internal *)(b);
376
376
 
377
- if (backend_a->is_alternate == backend_b->is_alternate)
378
- return (backend_b->priority - backend_a->priority);
379
-
380
- return backend_a->is_alternate ? 1 : -1;
377
+ if (backend_b->priority == backend_a->priority) {
378
+ if (backend_a->is_alternate)
379
+ return -1;
380
+ if (backend_b->is_alternate)
381
+ return 1;
382
+ return 0;
383
+ }
384
+ return (backend_b->priority - backend_a->priority);
381
385
  }
382
386
 
383
387
  int git_odb_new(git_odb **out)
@@ -620,23 +624,18 @@ void git_odb_free(git_odb *db)
620
624
  GIT_REFCOUNT_DEC(db, odb_free);
621
625
  }
622
626
 
623
- int git_odb_exists(git_odb *db, const git_oid *id)
627
+ static int odb_exists_1(git_odb *db, const git_oid *id, bool only_refreshed)
624
628
  {
625
- git_odb_object *object;
626
629
  size_t i;
627
630
  bool found = false;
628
631
 
629
- assert(db && id);
630
-
631
- if ((object = git_cache_get_raw(odb_cache(db), id)) != NULL) {
632
- git_odb_object_free(object);
633
- return (int)true;
634
- }
635
-
636
632
  for (i = 0; i < db->backends.length && !found; ++i) {
637
633
  backend_internal *internal = git_vector_get(&db->backends, i);
638
634
  git_odb_backend *b = internal->backend;
639
635
 
636
+ if (only_refreshed && !b->refresh)
637
+ continue;
638
+
640
639
  if (b->exists != NULL)
641
640
  found = (bool)b->exists(b, id);
642
641
  }
@@ -644,43 +643,45 @@ int git_odb_exists(git_odb *db, const git_oid *id)
644
643
  return (int)found;
645
644
  }
646
645
 
647
- int git_odb_exists_prefix(
648
- git_oid *out, git_odb *db, const git_oid *short_id, size_t len)
646
+ int git_odb_exists(git_odb *db, const git_oid *id)
649
647
  {
650
- int error = GIT_ENOTFOUND, num_found = 0;
651
- size_t i;
652
- git_oid key = {{0}}, last_found = {{0}}, found;
653
-
654
- assert(db && short_id);
648
+ git_odb_object *object;
655
649
 
656
- if (len < GIT_OID_MINPREFIXLEN)
657
- return git_odb__error_ambiguous("prefix length too short");
658
- if (len > GIT_OID_HEXSZ)
659
- len = GIT_OID_HEXSZ;
650
+ assert(db && id);
660
651
 
661
- if (len == GIT_OID_HEXSZ) {
662
- if (git_odb_exists(db, short_id)) {
663
- if (out)
664
- git_oid_cpy(out, short_id);
665
- return 0;
666
- } else {
667
- return git_odb__error_notfound("no match for id prefix", short_id);
668
- }
652
+ if ((object = git_cache_get_raw(odb_cache(db), id)) != NULL) {
653
+ git_odb_object_free(object);
654
+ return (int)true;
669
655
  }
670
656
 
671
- /* just copy valid part of short_id */
672
- memcpy(&key.id, short_id->id, (len + 1) / 2);
673
- if (len & 1)
674
- key.id[len / 2] &= 0xF0;
657
+ if (odb_exists_1(db, id, false))
658
+ return 1;
659
+
660
+ if (!git_odb_refresh(db))
661
+ return odb_exists_1(db, id, true);
662
+
663
+ /* Failed to refresh, hence not found */
664
+ return 0;
665
+ }
666
+
667
+ static int odb_exists_prefix_1(git_oid *out, git_odb *db,
668
+ const git_oid *key, size_t len, bool only_refreshed)
669
+ {
670
+ size_t i;
671
+ int error = GIT_ENOTFOUND, num_found = 0;
672
+ git_oid last_found = {{0}}, found;
675
673
 
676
674
  for (i = 0; i < db->backends.length; ++i) {
677
675
  backend_internal *internal = git_vector_get(&db->backends, i);
678
676
  git_odb_backend *b = internal->backend;
679
677
 
678
+ if (only_refreshed && !b->refresh)
679
+ continue;
680
+
680
681
  if (!b->exists_prefix)
681
682
  continue;
682
683
 
683
- error = b->exists_prefix(&found, b, &key, len);
684
+ error = b->exists_prefix(&found, b, key, len);
684
685
  if (error == GIT_ENOTFOUND || error == GIT_PASSTHROUGH)
685
686
  continue;
686
687
  if (error)
@@ -697,13 +698,53 @@ int git_odb_exists_prefix(
697
698
  }
698
699
 
699
700
  if (!num_found)
700
- return git_odb__error_notfound("no match for id prefix", &key);
701
+ return GIT_ENOTFOUND;
702
+
701
703
  if (out)
702
704
  git_oid_cpy(out, &last_found);
703
705
 
704
706
  return 0;
705
707
  }
706
708
 
709
+ int git_odb_exists_prefix(
710
+ git_oid *out, git_odb *db, const git_oid *short_id, size_t len)
711
+ {
712
+ int error;
713
+ git_oid key = {{0}};
714
+
715
+ assert(db && short_id);
716
+
717
+ if (len < GIT_OID_MINPREFIXLEN)
718
+ return git_odb__error_ambiguous("prefix length too short");
719
+ if (len > GIT_OID_HEXSZ)
720
+ len = GIT_OID_HEXSZ;
721
+
722
+ if (len == GIT_OID_HEXSZ) {
723
+ if (git_odb_exists(db, short_id)) {
724
+ if (out)
725
+ git_oid_cpy(out, short_id);
726
+ return 0;
727
+ } else {
728
+ return git_odb__error_notfound("no match for id prefix", short_id);
729
+ }
730
+ }
731
+
732
+ /* just copy valid part of short_id */
733
+ memcpy(&key.id, short_id->id, (len + 1) / 2);
734
+ if (len & 1)
735
+ key.id[len / 2] &= 0xF0;
736
+
737
+ error = odb_exists_prefix_1(out, db, &key, len, false);
738
+
739
+ if (error == GIT_ENOTFOUND && !git_odb_refresh(db))
740
+ error = odb_exists_prefix_1(out, db, &key, len, true);
741
+
742
+ if (error == GIT_ENOTFOUND)
743
+ return git_odb__error_notfound("no match for id prefix", &key);
744
+
745
+ return error;
746
+ }
747
+
707
748
  int git_odb_read_header(size_t *len_p, git_otype *type_p, git_odb *db, const git_oid *id)
708
749
  {
709
750
  int error;
@@ -783,36 +824,38 @@ static int hardcoded_objects(git_rawobj *raw, const git_oid *id)
783
824
  }
784
825
  }
785
826
 
786
- int git_odb_read(git_odb_object **out, git_odb *db, const git_oid *id)
827
+ static int odb_read_1(git_odb_object **out, git_odb *db, const git_oid *id,
828
+ bool only_refreshed)
787
829
  {
788
- size_t i, reads = 0;
789
- int error;
830
+ size_t i;
790
831
  git_rawobj raw;
791
832
  git_odb_object *object;
833
+ bool found = false;
792
834
 
793
- assert(out && db && id);
794
-
795
- *out = git_cache_get_raw(odb_cache(db), id);
796
- if (*out != NULL)
797
- return 0;
798
-
799
- error = hardcoded_objects(&raw, id);
835
+ if (!hardcoded_objects(&raw, id))
836
+ found = true;
800
837
 
801
- for (i = 0; i < db->backends.length && error < 0; ++i) {
838
+ for (i = 0; i < db->backends.length && !found; ++i) {
802
839
  backend_internal *internal = git_vector_get(&db->backends, i);
803
840
  git_odb_backend *b = internal->backend;
804
841
 
842
+ if (only_refreshed && !b->refresh)
843
+ continue;
844
+
805
845
  if (b->read != NULL) {
806
- ++reads;
807
- error = b->read(&raw.data, &raw.len, &raw.type, b, id);
846
+ int error = b->read(&raw.data, &raw.len, &raw.type, b, id);
847
+ if (error == GIT_PASSTHROUGH || error == GIT_ENOTFOUND)
848
+ continue;
849
+
850
+ if (error < 0)
851
+ return error;
852
+
853
+ found = true;
808
854
  }
809
855
  }
810
856
 
811
- if (error && error != GIT_PASSTHROUGH) {
812
- if (!reads)
813
- return git_odb__error_notfound("no match for id", id);
814
- return error;
815
- }
857
+ if (!found)
858
+ return GIT_ENOTFOUND;
816
859
 
817
860
  giterr_clear();
818
861
  if ((object = odb_object__alloc(id, &raw)) == NULL)
@@ -822,42 +865,48 @@ int git_odb_read(git_odb_object **out, git_odb *db, const git_oid *id)
822
865
  return 0;
823
866
  }
824
867
 
825
- int git_odb_read_prefix(
826
- git_odb_object **out, git_odb *db, const git_oid *short_id, size_t len)
868
+ int git_odb_read(git_odb_object **out, git_odb *db, const git_oid *id)
869
+ {
870
+ int error;
871
+
872
+ assert(out && db && id);
873
+
874
+ *out = git_cache_get_raw(odb_cache(db), id);
875
+ if (*out != NULL)
876
+ return 0;
877
+
878
+ error = odb_read_1(out, db, id, false);
879
+
880
+ if (error == GIT_ENOTFOUND && !git_odb_refresh(db))
881
+ error = odb_read_1(out, db, id, true);
882
+
883
+ if (error == GIT_ENOTFOUND)
884
+ return git_odb__error_notfound("no match for id", id);
885
+
886
+ return error;
887
+ }
888
+
889
+ static int read_prefix_1(git_odb_object **out, git_odb *db,
890
+ const git_oid *key, size_t len, bool only_refreshed)
827
891
  {
828
892
  size_t i;
829
893
  int error = GIT_ENOTFOUND;
830
- git_oid key = {{0}}, found_full_oid = {{0}};
894
+ git_oid found_full_oid = {{0}};
831
895
  git_rawobj raw;
832
896
  void *data = NULL;
833
897
  bool found = false;
834
898
  git_odb_object *object;
835
899
 
836
- assert(out && db);
837
-
838
- if (len < GIT_OID_MINPREFIXLEN)
839
- return git_odb__error_ambiguous("prefix length too short");
840
- if (len > GIT_OID_HEXSZ)
841
- len = GIT_OID_HEXSZ;
842
-
843
- if (len == GIT_OID_HEXSZ) {
844
- *out = git_cache_get_raw(odb_cache(db), short_id);
845
- if (*out != NULL)
846
- return 0;
847
- }
848
-
849
- /* just copy valid part of short_id */
850
- memcpy(&key.id, short_id->id, (len + 1) / 2);
851
- if (len & 1)
852
- key.id[len / 2] &= 0xF0;
853
-
854
900
  for (i = 0; i < db->backends.length; ++i) {
855
901
  backend_internal *internal = git_vector_get(&db->backends, i);
856
902
  git_odb_backend *b = internal->backend;
857
903
 
904
+ if (only_refreshed && !b->refresh)
905
+ continue;
906
+
858
907
  if (b->read_prefix != NULL) {
859
908
  git_oid full_oid;
860
- error = b->read_prefix(&full_oid, &raw.data, &raw.len, &raw.type, b, &key, len);
909
+ error = b->read_prefix(&full_oid, &raw.data, &raw.len, &raw.type, b, key, len);
861
910
  if (error == GIT_ENOTFOUND || error == GIT_PASSTHROUGH)
862
911
  continue;
863
912
 
@@ -878,7 +927,7 @@ int git_odb_read_prefix(
878
927
  }
879
928
 
880
929
  if (!found)
881
- return git_odb__error_notfound("no match for prefix", &key);
930
+ return GIT_ENOTFOUND;
882
931
 
883
932
  if ((object = odb_object__alloc(&found_full_oid, &raw)) == NULL)
884
933
  return -1;
@@ -887,6 +936,42 @@ int git_odb_read_prefix(
887
936
  return 0;
888
937
  }
889
938
 
939
+ int git_odb_read_prefix(
940
+ git_odb_object **out, git_odb *db, const git_oid *short_id, size_t len)
941
+ {
942
+ git_oid key = {{0}};
943
+ int error;
944
+
945
+ assert(out && db);
946
+
947
+ if (len < GIT_OID_MINPREFIXLEN)
948
+ return git_odb__error_ambiguous("prefix length too short");
949
+
950
+ if (len > GIT_OID_HEXSZ)
951
+ len = GIT_OID_HEXSZ;
952
+
953
+ if (len == GIT_OID_HEXSZ) {
954
+ *out = git_cache_get_raw(odb_cache(db), short_id);
955
+ if (*out != NULL)
956
+ return 0;
957
+ }
958
+
959
+ /* just copy valid part of short_id */
960
+ memcpy(&key.id, short_id->id, (len + 1) / 2);
961
+ if (len & 1)
962
+ key.id[len / 2] &= 0xF0;
963
+
964
+ error = read_prefix_1(out, db, &key, len, false);
965
+
966
+ if (error == GIT_ENOTFOUND && !git_odb_refresh(db))
967
+ error = read_prefix_1(out, db, &key, len, true);
968
+
969
+ if (error == GIT_ENOTFOUND)
970
+ return git_odb__error_notfound("no match for prefix", &key);
971
+
972
+ return error;
973
+ }
974
+
890
975
  int git_odb_foreach(git_odb *db, git_odb_foreach_cb cb, void *payload)
891
976
  {
892
977
  unsigned int i;
@@ -346,7 +346,7 @@ static int pack_backend__refresh(git_odb_backend *backend_)
346
346
  return error;
347
347
  }
348
348
 
349
- static int pack_backend__read_header_internal(
349
+ static int pack_backend__read_header(
350
350
  size_t *len_p, git_otype *type_p,
351
351
  struct git_odb_backend *backend, const git_oid *oid)
352
352
  {
@@ -361,24 +361,7 @@ static int pack_backend__read_header_internal(
361
361
  return git_packfile_resolve_header(len_p, type_p, e.p, e.offset);
362
362
  }
363
363
 
364
- static int pack_backend__read_header(
365
- size_t *len_p, git_otype *type_p,
366
- struct git_odb_backend *backend, const git_oid *oid)
367
- {
368
- int error;
369
-
370
- error = pack_backend__read_header_internal(len_p, type_p, backend, oid);
371
-
372
- if (error != GIT_ENOTFOUND)
373
- return error;
374
-
375
- if ((error = pack_backend__refresh(backend)) < 0)
376
- return error;
377
-
378
- return pack_backend__read_header_internal(len_p, type_p, backend, oid);
379
- }
380
-
381
- static int pack_backend__read_internal(
364
+ static int pack_backend__read(
382
365
  void **buffer_p, size_t *len_p, git_otype *type_p,
383
366
  git_odb_backend *backend, const git_oid *oid)
384
367
  {
@@ -397,24 +380,7 @@ static int pack_backend__read_internal(
397
380
  return 0;
398
381
  }
399
382
 
400
- static int pack_backend__read(
401
- void **buffer_p, size_t *len_p, git_otype *type_p,
402
- git_odb_backend *backend, const git_oid *oid)
403
- {
404
- int error;
405
-
406
- error = pack_backend__read_internal(buffer_p, len_p, type_p, backend, oid);
407
-
408
- if (error != GIT_ENOTFOUND)
409
- return error;
410
-
411
- if ((error = pack_backend__refresh(backend)) < 0)
412
- return error;
413
-
414
- return pack_backend__read_internal(buffer_p, len_p, type_p, backend, oid);
415
- }
416
-
417
- static int pack_backend__read_prefix_internal(
383
+ static int pack_backend__read_prefix(
418
384
  git_oid *out_oid,
419
385
  void **buffer_p,
420
386
  size_t *len_p,
@@ -451,45 +417,9 @@ static int pack_backend__read_prefix_internal(
451
417
  return error;
452
418
  }
453
419
 
454
- static int pack_backend__read_prefix(
455
- git_oid *out_oid,
456
- void **buffer_p,
457
- size_t *len_p,
458
- git_otype *type_p,
459
- git_odb_backend *backend,
460
- const git_oid *short_oid,
461
- size_t len)
462
- {
463
- int error;
464
-
465
- error = pack_backend__read_prefix_internal(
466
- out_oid, buffer_p, len_p, type_p, backend, short_oid, len);
467
-
468
- if (error != GIT_ENOTFOUND)
469
- return error;
470
-
471
- if ((error = pack_backend__refresh(backend)) < 0)
472
- return error;
473
-
474
- return pack_backend__read_prefix_internal(
475
- out_oid, buffer_p, len_p, type_p, backend, short_oid, len);
476
- }
477
-
478
420
  static int pack_backend__exists(git_odb_backend *backend, const git_oid *oid)
479
421
  {
480
422
  struct git_pack_entry e;
481
- int error;
482
-
483
- error = pack_entry_find(&e, (struct pack_backend *)backend, oid);
484
-
485
- if (error != GIT_ENOTFOUND)
486
- return error == 0;
487
-
488
- if ((error = pack_backend__refresh(backend)) < 0) {
489
- giterr_clear();
490
- return (int)false;
491
- }
492
-
493
423
  return pack_entry_find(&e, (struct pack_backend *)backend, oid) == 0;
494
424
  }
495
425
 
@@ -501,12 +431,7 @@ static int pack_backend__exists_prefix(
501
431
  struct git_pack_entry e = {0};
502
432
 
503
433
  error = pack_entry_find_prefix(&e, pb, short_id, len);
504
-
505
- if (error == GIT_ENOTFOUND && !(error = pack_backend__refresh(backend)))
506
- error = pack_entry_find_prefix(&e, pb, short_id, len);
507
-
508
434
  git_oid_cpy(out, &e.sha1);
509
-
510
435
  return error;
511
436
  }
512
437
 
@@ -674,7 +599,6 @@ int git_odb_backend_pack(git_odb_backend **backend_out, const char *objects_dir)
674
599
  git_path_isdir(git_buf_cstr(&path)))
675
600
  {
676
601
  backend->pack_folder = git_buf_detach(&path);
677
-
678
602
  error = pack_backend__refresh((git_odb_backend *)backend);
679
603
  }
680
604
 
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.24.0b0
4
+ version: 0.24.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: 2015-10-06 00:00:00.000000000 Z
12
+ date: 2015-10-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake-compiler