rugged 1.5.1 → 1.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (154) hide show
  1. checksums.yaml +4 -4
  2. data/ext/rugged/extconf.rb +2 -2
  3. data/ext/rugged/rugged_blame.c +2 -0
  4. data/ext/rugged/rugged_blob.c +3 -0
  5. data/ext/rugged/rugged_commit.c +1 -0
  6. data/ext/rugged/rugged_config.c +2 -0
  7. data/ext/rugged/rugged_diff.c +1 -0
  8. data/ext/rugged/rugged_index.c +2 -0
  9. data/ext/rugged/rugged_patch.c +1 -0
  10. data/ext/rugged/rugged_rebase.c +1 -0
  11. data/ext/rugged/rugged_reference.c +1 -0
  12. data/ext/rugged/rugged_remote.c +1 -0
  13. data/ext/rugged/rugged_repo.c +5 -2
  14. data/ext/rugged/rugged_revwalk.c +5 -1
  15. data/ext/rugged/rugged_submodule.c +1 -0
  16. data/ext/rugged/rugged_tag.c +1 -0
  17. data/ext/rugged/rugged_tree.c +4 -0
  18. data/lib/rugged/index.rb +1 -1
  19. data/lib/rugged/tree.rb +1 -1
  20. data/lib/rugged/version.rb +1 -1
  21. data/vendor/libgit2/CMakeLists.txt +5 -1
  22. data/vendor/libgit2/COPYING +30 -0
  23. data/vendor/libgit2/cmake/ExperimentalFeatures.cmake +23 -0
  24. data/vendor/libgit2/deps/ntlmclient/CMakeLists.txt +2 -0
  25. data/vendor/libgit2/include/git2/common.h +13 -6
  26. data/vendor/libgit2/include/git2/deprecated.h +6 -0
  27. data/vendor/libgit2/include/git2/diff.h +1 -1
  28. data/vendor/libgit2/include/git2/experimental.h +20 -0
  29. data/vendor/libgit2/include/git2/indexer.h +29 -0
  30. data/vendor/libgit2/include/git2/object.h +28 -2
  31. data/vendor/libgit2/include/git2/odb.h +58 -7
  32. data/vendor/libgit2/include/git2/odb_backend.h +106 -18
  33. data/vendor/libgit2/include/git2/oid.h +115 -15
  34. data/vendor/libgit2/include/git2/repository.h +20 -1
  35. data/vendor/libgit2/include/git2/stash.h +60 -6
  36. data/vendor/libgit2/include/git2/strarray.h +0 -13
  37. data/vendor/libgit2/include/git2/sys/odb_backend.h +1 -1
  38. data/vendor/libgit2/include/git2/sys/transport.h +12 -0
  39. data/vendor/libgit2/include/git2/version.h +4 -4
  40. data/vendor/libgit2/include/git2.h +1 -0
  41. data/vendor/libgit2/src/CMakeLists.txt +0 -6
  42. data/vendor/libgit2/src/cli/CMakeLists.txt +6 -2
  43. data/vendor/libgit2/src/cli/cmd_hash_object.c +27 -8
  44. data/vendor/libgit2/src/cli/opt.c +1 -1
  45. data/vendor/libgit2/src/libgit2/CMakeLists.txt +25 -15
  46. data/vendor/libgit2/src/libgit2/annotated_commit.c +1 -1
  47. data/vendor/libgit2/src/libgit2/annotated_commit.h +1 -1
  48. data/vendor/libgit2/src/libgit2/attr_file.c +1 -1
  49. data/vendor/libgit2/src/libgit2/attrcache.c +1 -1
  50. data/vendor/libgit2/src/libgit2/blame.c +2 -0
  51. data/vendor/libgit2/src/libgit2/blob.c +4 -2
  52. data/vendor/libgit2/src/libgit2/blob.h +2 -2
  53. data/vendor/libgit2/src/libgit2/branch.c +2 -2
  54. data/vendor/libgit2/src/libgit2/cherrypick.c +3 -3
  55. data/vendor/libgit2/src/libgit2/clone.c +31 -2
  56. data/vendor/libgit2/src/libgit2/commit.c +52 -17
  57. data/vendor/libgit2/src/libgit2/commit.h +25 -7
  58. data/vendor/libgit2/src/libgit2/commit_graph.c +47 -32
  59. data/vendor/libgit2/src/libgit2/commit_graph.h +3 -0
  60. data/vendor/libgit2/src/libgit2/commit_list.c +6 -2
  61. data/vendor/libgit2/src/libgit2/config.c +1 -1
  62. data/vendor/libgit2/src/libgit2/config_file.c +2 -2
  63. data/vendor/libgit2/src/libgit2/describe.c +8 -8
  64. data/vendor/libgit2/src/libgit2/diff.c +5 -1
  65. data/vendor/libgit2/src/libgit2/diff_file.c +15 -6
  66. data/vendor/libgit2/src/libgit2/diff_generate.c +17 -12
  67. data/vendor/libgit2/src/libgit2/diff_print.c +5 -5
  68. data/vendor/libgit2/src/libgit2/diff_tform.c +4 -0
  69. data/vendor/libgit2/src/libgit2/email.c +2 -2
  70. data/vendor/libgit2/src/libgit2/experimental.h.in +13 -0
  71. data/vendor/libgit2/src/libgit2/fetch.c +3 -6
  72. data/vendor/libgit2/src/libgit2/fetchhead.c +4 -4
  73. data/vendor/libgit2/src/libgit2/ident.c +3 -3
  74. data/vendor/libgit2/src/libgit2/index.c +11 -9
  75. data/vendor/libgit2/src/libgit2/indexer.c +107 -44
  76. data/vendor/libgit2/src/libgit2/iterator.c +4 -2
  77. data/vendor/libgit2/src/libgit2/libgit2.c +19 -0
  78. data/vendor/libgit2/src/libgit2/merge.c +3 -3
  79. data/vendor/libgit2/src/libgit2/midx.c +16 -15
  80. data/vendor/libgit2/src/libgit2/mwindow.c +5 -2
  81. data/vendor/libgit2/src/libgit2/mwindow.h +4 -1
  82. data/vendor/libgit2/src/libgit2/notes.c +5 -5
  83. data/vendor/libgit2/src/libgit2/object.c +89 -25
  84. data/vendor/libgit2/src/libgit2/object.h +12 -3
  85. data/vendor/libgit2/src/libgit2/odb.c +194 -50
  86. data/vendor/libgit2/src/libgit2/odb.h +43 -4
  87. data/vendor/libgit2/src/libgit2/odb_loose.c +128 -70
  88. data/vendor/libgit2/src/libgit2/odb_pack.c +96 -44
  89. data/vendor/libgit2/src/libgit2/oid.c +134 -76
  90. data/vendor/libgit2/src/libgit2/oid.h +183 -9
  91. data/vendor/libgit2/src/libgit2/pack-objects.c +15 -4
  92. data/vendor/libgit2/src/libgit2/pack.c +90 -66
  93. data/vendor/libgit2/src/libgit2/pack.h +29 -15
  94. data/vendor/libgit2/src/libgit2/parse.c +4 -3
  95. data/vendor/libgit2/src/libgit2/patch_parse.c +5 -5
  96. data/vendor/libgit2/src/libgit2/push.c +13 -3
  97. data/vendor/libgit2/src/libgit2/reader.c +1 -1
  98. data/vendor/libgit2/src/libgit2/rebase.c +19 -18
  99. data/vendor/libgit2/src/libgit2/refdb_fs.c +70 -39
  100. data/vendor/libgit2/src/libgit2/reflog.c +7 -5
  101. data/vendor/libgit2/src/libgit2/reflog.h +1 -2
  102. data/vendor/libgit2/src/libgit2/refs.c +2 -0
  103. data/vendor/libgit2/src/libgit2/remote.c +38 -37
  104. data/vendor/libgit2/src/libgit2/remote.h +40 -0
  105. data/vendor/libgit2/src/libgit2/repository.c +212 -36
  106. data/vendor/libgit2/src/libgit2/repository.h +9 -0
  107. data/vendor/libgit2/src/libgit2/reset.c +2 -2
  108. data/vendor/libgit2/src/libgit2/revert.c +4 -4
  109. data/vendor/libgit2/src/libgit2/revparse.c +23 -7
  110. data/vendor/libgit2/src/libgit2/revwalk.c +5 -1
  111. data/vendor/libgit2/src/libgit2/stash.c +201 -26
  112. data/vendor/libgit2/src/libgit2/strarray.c +1 -0
  113. data/vendor/libgit2/src/libgit2/strarray.h +25 -0
  114. data/vendor/libgit2/src/libgit2/streams/openssl.c +1 -1
  115. data/vendor/libgit2/src/libgit2/streams/openssl_dynamic.c +7 -3
  116. data/vendor/libgit2/src/libgit2/streams/socket.c +4 -1
  117. data/vendor/libgit2/src/libgit2/submodule.c +6 -2
  118. data/vendor/libgit2/src/libgit2/sysdir.c +294 -7
  119. data/vendor/libgit2/src/libgit2/sysdir.h +39 -9
  120. data/vendor/libgit2/src/libgit2/tag.c +29 -10
  121. data/vendor/libgit2/src/libgit2/tag.h +2 -2
  122. data/vendor/libgit2/src/libgit2/threadstate.h +1 -1
  123. data/vendor/libgit2/src/libgit2/transports/http.c +8 -7
  124. data/vendor/libgit2/src/libgit2/transports/httpclient.c +9 -0
  125. data/vendor/libgit2/src/libgit2/transports/httpclient.h +10 -0
  126. data/vendor/libgit2/src/libgit2/transports/local.c +14 -0
  127. data/vendor/libgit2/src/libgit2/transports/smart.c +35 -0
  128. data/vendor/libgit2/src/libgit2/transports/smart.h +10 -1
  129. data/vendor/libgit2/src/libgit2/transports/smart_pkt.c +153 -41
  130. data/vendor/libgit2/src/libgit2/transports/smart_protocol.c +42 -12
  131. data/vendor/libgit2/src/libgit2/transports/ssh.c +62 -65
  132. data/vendor/libgit2/src/libgit2/transports/winhttp.c +9 -4
  133. data/vendor/libgit2/src/libgit2/tree-cache.c +4 -4
  134. data/vendor/libgit2/src/libgit2/tree.c +22 -16
  135. data/vendor/libgit2/src/libgit2/tree.h +2 -2
  136. data/vendor/libgit2/src/libgit2/worktree.c +5 -0
  137. data/vendor/libgit2/src/util/CMakeLists.txt +7 -1
  138. data/vendor/libgit2/src/util/fs_path.c +1 -1
  139. data/vendor/libgit2/src/util/futils.c +0 -3
  140. data/vendor/libgit2/src/util/git2_util.h +2 -2
  141. data/vendor/libgit2/src/util/hash/openssl.c +4 -3
  142. data/vendor/libgit2/src/util/hash/rfc6234/sha.h +0 -112
  143. data/vendor/libgit2/src/util/hash.h +13 -0
  144. data/vendor/libgit2/src/util/net.c +338 -84
  145. data/vendor/libgit2/src/util/net.h +7 -0
  146. data/vendor/libgit2/src/util/posix.h +2 -0
  147. data/vendor/libgit2/src/util/rand.c +4 -0
  148. data/vendor/libgit2/src/util/regexp.c +3 -3
  149. data/vendor/libgit2/src/util/thread.h +20 -19
  150. data/vendor/libgit2/src/util/util.h +1 -0
  151. metadata +7 -5
  152. data/vendor/libgit2/src/util/win32/findfile.c +0 -286
  153. data/vendor/libgit2/src/util/win32/findfile.h +0 -22
  154. /data/vendor/libgit2/src/{features.h.in → util/git2_features.h.in} +0 -0
@@ -181,7 +181,8 @@ GIT_INLINE(int) rebase_readoid(
181
181
  if ((error = rebase_readfile(str_out, state_path, filename)) < 0)
182
182
  return error;
183
183
 
184
- if (str_out->size != GIT_OID_HEXSZ || git_oid_fromstr(out, str_out->ptr) < 0) {
184
+ if (str_out->size != GIT_OID_SHA1_HEXSIZE ||
185
+ git_oid__fromstr(out, str_out->ptr, GIT_OID_SHA1) < 0) {
185
186
  git_error_set(GIT_ERROR_REBASE, "the file '%s' contains an invalid object ID", filename);
186
187
  return -1;
187
188
  }
@@ -363,7 +364,7 @@ int git_rebase_open(
363
364
 
364
365
  git_str_rtrim(&orig_head_id);
365
366
 
366
- if ((error = git_oid_fromstr(&rebase->orig_head_id, orig_head_id.ptr)) < 0)
367
+ if ((error = git_oid__fromstr(&rebase->orig_head_id, orig_head_id.ptr, GIT_OID_SHA1)) < 0)
367
368
  goto done;
368
369
 
369
370
  git_str_truncate(&path, state_path_len);
@@ -374,7 +375,7 @@ int git_rebase_open(
374
375
 
375
376
  git_str_rtrim(&onto_id);
376
377
 
377
- if ((error = git_oid_fromstr(&rebase->onto_id, onto_id.ptr)) < 0)
378
+ if ((error = git_oid__fromstr(&rebase->onto_id, onto_id.ptr, GIT_OID_SHA1)) < 0)
378
379
  goto done;
379
380
 
380
381
  if (!rebase->head_detached)
@@ -452,7 +453,7 @@ static const char *rebase_onto_name(const git_annotated_commit *onto)
452
453
  static int rebase_setupfiles_merge(git_rebase *rebase)
453
454
  {
454
455
  git_str commit_filename = GIT_STR_INIT;
455
- char id_str[GIT_OID_HEXSZ];
456
+ char id_str[GIT_OID_SHA1_HEXSIZE];
456
457
  git_rebase_operation *operation;
457
458
  size_t i;
458
459
  int error = 0;
@@ -470,7 +471,7 @@ static int rebase_setupfiles_merge(git_rebase *rebase)
470
471
  git_oid_fmt(id_str, &operation->id);
471
472
 
472
473
  if ((error = rebase_setupfile(rebase, commit_filename.ptr, 0,
473
- "%.*s\n", GIT_OID_HEXSZ, id_str)) < 0)
474
+ "%.*s\n", GIT_OID_SHA1_HEXSIZE, id_str)) < 0)
474
475
  goto done;
475
476
  }
476
477
 
@@ -481,7 +482,7 @@ done:
481
482
 
482
483
  static int rebase_setupfiles(git_rebase *rebase)
483
484
  {
484
- char onto[GIT_OID_HEXSZ], orig_head[GIT_OID_HEXSZ];
485
+ char onto[GIT_OID_SHA1_HEXSIZE], orig_head[GIT_OID_SHA1_HEXSIZE];
485
486
  const char *orig_head_name;
486
487
 
487
488
  git_oid_fmt(onto, &rebase->onto_id);
@@ -497,8 +498,8 @@ static int rebase_setupfiles(git_rebase *rebase)
497
498
 
498
499
  if (git_repository__set_orig_head(rebase->repo, &rebase->orig_head_id) < 0 ||
499
500
  rebase_setupfile(rebase, HEAD_NAME_FILE, 0, "%s\n", orig_head_name) < 0 ||
500
- rebase_setupfile(rebase, ONTO_FILE, 0, "%.*s\n", GIT_OID_HEXSZ, onto) < 0 ||
501
- rebase_setupfile(rebase, ORIG_HEAD_FILE, 0, "%.*s\n", GIT_OID_HEXSZ, orig_head) < 0 ||
501
+ rebase_setupfile(rebase, ONTO_FILE, 0, "%.*s\n", GIT_OID_SHA1_HEXSIZE, onto) < 0 ||
502
+ rebase_setupfile(rebase, ORIG_HEAD_FILE, 0, "%.*s\n", GIT_OID_SHA1_HEXSIZE, orig_head) < 0 ||
502
503
  rebase_setupfile(rebase, QUIET_FILE, 0, rebase->quiet ? "t\n" : "\n") < 0)
503
504
  return -1;
504
505
 
@@ -813,7 +814,7 @@ static int rebase_next_merge(
813
814
  git_indexwriter indexwriter = GIT_INDEXWRITER_INIT;
814
815
  git_rebase_operation *operation;
815
816
  git_checkout_options checkout_opts;
816
- char current_idstr[GIT_OID_HEXSZ];
817
+ char current_idstr[GIT_OID_SHA1_HEXSIZE];
817
818
  unsigned int parent_count;
818
819
  int error;
819
820
 
@@ -842,7 +843,7 @@ static int rebase_next_merge(
842
843
 
843
844
  if ((error = git_indexwriter_init_for_operation(&indexwriter, rebase->repo, &checkout_opts.checkout_strategy)) < 0 ||
844
845
  (error = rebase_setupfile(rebase, MSGNUM_FILE, 0, "%" PRIuZ "\n", rebase->current+1)) < 0 ||
845
- (error = rebase_setupfile(rebase, CURRENT_FILE, 0, "%.*s\n", GIT_OID_HEXSZ, current_idstr)) < 0 ||
846
+ (error = rebase_setupfile(rebase, CURRENT_FILE, 0, "%.*s\n", GIT_OID_SHA1_HEXSIZE, current_idstr)) < 0 ||
846
847
  (error = git_merge_trees(&index, rebase->repo, parent_tree, head_tree, current_tree, &rebase->options.merge_options)) < 0 ||
847
848
  (error = git_merge__check_result(rebase->repo, index)) < 0 ||
848
849
  (error = git_checkout_index(rebase->repo, index, &checkout_opts)) < 0 ||
@@ -1102,7 +1103,7 @@ static int rebase_commit_merge(
1102
1103
  git_reference *head = NULL;
1103
1104
  git_commit *head_commit = NULL, *commit = NULL;
1104
1105
  git_index *index = NULL;
1105
- char old_idstr[GIT_OID_HEXSZ], new_idstr[GIT_OID_HEXSZ];
1106
+ char old_idstr[GIT_OID_SHA1_HEXSIZE], new_idstr[GIT_OID_SHA1_HEXSIZE];
1106
1107
  int error;
1107
1108
 
1108
1109
  operation = git_array_get(rebase->operations, rebase->current);
@@ -1122,7 +1123,7 @@ static int rebase_commit_merge(
1122
1123
  git_oid_fmt(new_idstr, git_commit_id(commit));
1123
1124
 
1124
1125
  if ((error = rebase_setupfile(rebase, REWRITTEN_FILE, O_CREAT|O_WRONLY|O_APPEND,
1125
- "%.*s %.*s\n", GIT_OID_HEXSZ, old_idstr, GIT_OID_HEXSZ, new_idstr)) < 0)
1126
+ "%.*s %.*s\n", GIT_OID_SHA1_HEXSIZE, old_idstr, GIT_OID_SHA1_HEXSIZE, new_idstr)) < 0)
1126
1127
  goto done;
1127
1128
 
1128
1129
  git_oid_cpy(commit_id, git_commit_id(commit));
@@ -1341,10 +1342,10 @@ static int rebase_copy_notes(
1341
1342
  tostr = end+1;
1342
1343
  *end = '\0';
1343
1344
 
1344
- if (strlen(fromstr) != GIT_OID_HEXSZ ||
1345
- strlen(tostr) != GIT_OID_HEXSZ ||
1346
- git_oid_fromstr(&from, fromstr) < 0 ||
1347
- git_oid_fromstr(&to, tostr) < 0)
1345
+ if (strlen(fromstr) != GIT_OID_SHA1_HEXSIZE ||
1346
+ strlen(tostr) != GIT_OID_SHA1_HEXSIZE ||
1347
+ git_oid__fromstr(&from, fromstr, GIT_OID_SHA1) < 0 ||
1348
+ git_oid__fromstr(&to, tostr, GIT_OID_SHA1) < 0)
1348
1349
  goto on_error;
1349
1350
 
1350
1351
  if ((error = rebase_copy_note(rebase, notes_ref.ptr, &from, &to, committer)) < 0)
@@ -1372,14 +1373,14 @@ static int return_to_orig_head(git_rebase *rebase)
1372
1373
  git_reference *terminal_ref = NULL, *branch_ref = NULL, *head_ref = NULL;
1373
1374
  git_commit *terminal_commit = NULL;
1374
1375
  git_str branch_msg = GIT_STR_INIT, head_msg = GIT_STR_INIT;
1375
- char onto[GIT_OID_HEXSZ];
1376
+ char onto[GIT_OID_SHA1_HEXSIZE];
1376
1377
  int error = 0;
1377
1378
 
1378
1379
  git_oid_fmt(onto, &rebase->onto_id);
1379
1380
 
1380
1381
  if ((error = git_str_printf(&branch_msg,
1381
1382
  "rebase finished: %s onto %.*s",
1382
- rebase->orig_head_name, GIT_OID_HEXSZ, onto)) == 0 &&
1383
+ rebase->orig_head_name, GIT_OID_SHA1_HEXSIZE, onto)) == 0 &&
1383
1384
  (error = git_str_printf(&head_msg,
1384
1385
  "rebase finished: returning to %s",
1385
1386
  rebase->orig_head_name)) == 0 &&
@@ -60,15 +60,17 @@ typedef struct refdb_fs_backend {
60
60
  /* path to common objects' directory */
61
61
  char *commonpath;
62
62
 
63
- git_sortedcache *refcache;
63
+ git_oid_t oid_type;
64
+
65
+ int fsync : 1,
66
+ sorted : 1;
64
67
  int peeling_mode;
65
68
  git_iterator_flag_t iterator_flags;
66
69
  uint32_t direach_flags;
67
- int fsync;
70
+ git_sortedcache *refcache;
68
71
  git_map packed_refs_map;
69
72
  git_mutex prlock; /* protect packed_refs_map */
70
73
  git_futils_filestamp packed_refs_stamp;
71
- bool sorted;
72
74
  } refdb_fs_backend;
73
75
 
74
76
  static int refdb_reflog_fs__delete(git_refdb_backend *_backend, const char *name);
@@ -113,6 +115,7 @@ static int packed_reload(refdb_fs_backend *backend)
113
115
  {
114
116
  int error;
115
117
  git_str packedrefs = GIT_STR_INIT;
118
+ size_t oid_hexsize = git_oid_hexsize(backend->oid_type);
116
119
  char *scan, *eof, *eol;
117
120
 
118
121
  if (!backend->gitpath)
@@ -158,9 +161,9 @@ static int packed_reload(refdb_fs_backend *backend)
158
161
 
159
162
  /* parse "<OID> <refname>\n" */
160
163
 
161
- if (git_oid_fromstr(&oid, scan) < 0)
164
+ if (git_oid__fromstr(&oid, scan, backend->oid_type) < 0)
162
165
  goto parse_failed;
163
- scan += GIT_OID_HEXSZ;
166
+ scan += oid_hexsize;
164
167
 
165
168
  if (*scan++ != ' ')
166
169
  goto parse_failed;
@@ -179,9 +182,9 @@ static int packed_reload(refdb_fs_backend *backend)
179
182
  /* look for optional "^<OID>\n" */
180
183
 
181
184
  if (*scan == '^') {
182
- if (git_oid_fromstr(&oid, scan + 1) < 0)
185
+ if (git_oid__fromstr(&oid, scan + 1, backend->oid_type) < 0)
183
186
  goto parse_failed;
184
- scan += GIT_OID_HEXSZ + 1;
187
+ scan += oid_hexsize + 1;
185
188
 
186
189
  if (scan < eof) {
187
190
  if (!(eol = strchr(scan, '\n')))
@@ -214,19 +217,23 @@ parse_failed:
214
217
  }
215
218
 
216
219
  static int loose_parse_oid(
217
- git_oid *oid, const char *filename, git_str *file_content)
220
+ git_oid *oid,
221
+ const char *filename,
222
+ git_str *file_content,
223
+ git_oid_t oid_type)
218
224
  {
219
225
  const char *str = git_str_cstr(file_content);
226
+ size_t oid_hexsize = git_oid_hexsize(oid_type);
220
227
 
221
- if (git_str_len(file_content) < GIT_OID_HEXSZ)
228
+ if (git_str_len(file_content) < oid_hexsize)
222
229
  goto corrupted;
223
230
 
224
231
  /* we need to get 40 OID characters from the file */
225
- if (git_oid_fromstr(oid, str) < 0)
232
+ if (git_oid__fromstr(oid, str, oid_type) < 0)
226
233
  goto corrupted;
227
234
 
228
235
  /* If the file is longer than 40 chars, the 41st must be a space */
229
- str += GIT_OID_HEXSZ;
236
+ str += oid_hexsize;
230
237
  if (*str == '\0' || git__isspace(*str))
231
238
  return 0;
232
239
 
@@ -266,7 +273,7 @@ static int loose_lookup_to_packfile(refdb_fs_backend *backend, const char *name)
266
273
  goto done;
267
274
 
268
275
  /* parse OID from file */
269
- if ((error = loose_parse_oid(&oid, name, &ref_file)) < 0)
276
+ if ((error = loose_parse_oid(&oid, name, &ref_file, backend->oid_type)) < 0)
270
277
  goto done;
271
278
 
272
279
  if ((error = git_sortedcache_wlock(backend->refcache)) < 0)
@@ -437,7 +444,7 @@ static int loose_lookup(
437
444
  } else {
438
445
  git_oid oid;
439
446
 
440
- if (!(error = loose_parse_oid(&oid, ref_name, &ref_file)) &&
447
+ if (!(error = loose_parse_oid(&oid, ref_name, &ref_file, backend->oid_type)) &&
441
448
  out != NULL)
442
449
  *out = git_reference__alloc(ref_name, &oid, NULL);
443
450
  }
@@ -615,19 +622,24 @@ static const char *end_of_record(const char *p, const char *end)
615
622
  return p;
616
623
  }
617
624
 
618
- static int
619
- cmp_record_to_refname(const char *rec, size_t data_end, const char *ref_name)
625
+ static int cmp_record_to_refname(
626
+ const char *rec,
627
+ size_t data_end,
628
+ const char *ref_name,
629
+ git_oid_t oid_type)
620
630
  {
621
631
  const size_t ref_len = strlen(ref_name);
622
632
  int cmp_val;
623
633
  const char *end;
634
+ size_t oid_hexsize = git_oid_hexsize(oid_type);
624
635
 
625
- rec += GIT_OID_HEXSZ + 1; /* <oid> + space */
626
- if (data_end < GIT_OID_HEXSZ + 3) {
627
- /* an incomplete (corrupt) record is treated as less than ref_name */
636
+ rec += oid_hexsize + 1; /* <oid> + space */
637
+
638
+ /* an incomplete (corrupt) record is treated as less than ref_name */
639
+ if (data_end < oid_hexsize + 3)
628
640
  return -1;
629
- }
630
- data_end -= GIT_OID_HEXSZ + 1;
641
+
642
+ data_end -= oid_hexsize + 1;
631
643
 
632
644
  end = memchr(rec, '\n', data_end);
633
645
  if (end)
@@ -675,6 +687,7 @@ static int packed_lookup(
675
687
  {
676
688
  int error = 0;
677
689
  const char *left, *right, *data_end;
690
+ size_t oid_hexsize = git_oid_hexsize(backend->oid_type);
678
691
 
679
692
  if ((error = packed_map_check(backend)) < 0)
680
693
  return error;
@@ -698,7 +711,7 @@ static int packed_lookup(
698
711
 
699
712
  mid = left + (right - left) / 2;
700
713
  rec = start_of_record(left, mid);
701
- compare = cmp_record_to_refname(rec, data_end - rec, ref_name);
714
+ compare = cmp_record_to_refname(rec, data_end - rec, ref_name, backend->oid_type);
702
715
 
703
716
  if (compare < 0) {
704
717
  left = end_of_record(mid, right);
@@ -708,11 +721,11 @@ static int packed_lookup(
708
721
  const char *eol;
709
722
  git_oid oid, peel, *peel_ptr = NULL;
710
723
 
711
- if (data_end - rec < GIT_OID_HEXSZ ||
712
- git_oid_fromstr(&oid, rec) < 0) {
724
+ if (data_end - rec < (long)oid_hexsize ||
725
+ git_oid__fromstr(&oid, rec, backend->oid_type) < 0) {
713
726
  goto parse_failed;
714
727
  }
715
- rec += GIT_OID_HEXSZ + 1;
728
+ rec += oid_hexsize + 1;
716
729
  if (!(eol = memchr(rec, '\n', data_end - rec))) {
717
730
  goto parse_failed;
718
731
  }
@@ -724,8 +737,8 @@ static int packed_lookup(
724
737
 
725
738
  if (*rec == '^') {
726
739
  rec++;
727
- if (data_end - rec < GIT_OID_HEXSZ ||
728
- git_oid_fromstr(&peel, rec) < 0) {
740
+ if (data_end - rec < (long)oid_hexsize ||
741
+ git_oid__fromstr(&peel, rec, backend->oid_type) < 0) {
729
742
  goto parse_failed;
730
743
  }
731
744
  peel_ptr = &peel;
@@ -1108,7 +1121,7 @@ static int loose_commit(git_filebuf *file, const git_reference *ref)
1108
1121
  GIT_ASSERT_ARG(ref);
1109
1122
 
1110
1123
  if (ref->type == GIT_REFERENCE_DIRECT) {
1111
- char oid[GIT_OID_HEXSZ + 1];
1124
+ char oid[GIT_OID_MAX_HEXSIZE + 1];
1112
1125
  git_oid_nfmt(oid, sizeof(oid), &ref->target.oid);
1113
1126
 
1114
1127
  git_filebuf_printf(file, "%s\n", oid);
@@ -1224,7 +1237,7 @@ static int packed_find_peel(refdb_fs_backend *backend, struct packref *ref)
1224
1237
  */
1225
1238
  static int packed_write_ref(struct packref *ref, git_filebuf *file)
1226
1239
  {
1227
- char oid[GIT_OID_HEXSZ + 1];
1240
+ char oid[GIT_OID_MAX_HEXSIZE + 1];
1228
1241
  git_oid_nfmt(oid, sizeof(oid), &ref->oid);
1229
1242
 
1230
1243
  /*
@@ -1238,7 +1251,7 @@ static int packed_write_ref(struct packref *ref, git_filebuf *file)
1238
1251
  * The required peels have already been loaded into `ref->peel_target`.
1239
1252
  */
1240
1253
  if (ref->flags & PACKREF_HAS_PEEL) {
1241
- char peel[GIT_OID_HEXSZ + 1];
1254
+ char peel[GIT_OID_MAX_HEXSIZE + 1];
1242
1255
  git_oid_nfmt(peel, sizeof(peel), &ref->peel);
1243
1256
 
1244
1257
  if (git_filebuf_printf(file, "%s %s\n^%s\n", oid, ref->name, peel) < 0)
@@ -1302,7 +1315,7 @@ static int packed_remove_loose(refdb_fs_backend *backend)
1302
1315
  continue;
1303
1316
 
1304
1317
  /* Figure out the current id; if we find a bad ref file, skip it so we can do the rest */
1305
- if (loose_parse_oid(&current_id, lock.path_original, &ref_content) < 0)
1318
+ if (loose_parse_oid(&current_id, lock.path_original, &ref_content, backend->oid_type) < 0)
1306
1319
  continue;
1307
1320
 
1308
1321
  /* If the ref moved since we packed it, we must not delete it */
@@ -1891,7 +1904,10 @@ done:
1891
1904
  return out;
1892
1905
  }
1893
1906
 
1894
- static int reflog_alloc(git_reflog **reflog, const char *name)
1907
+ static int reflog_alloc(
1908
+ git_reflog **reflog,
1909
+ const char *name,
1910
+ git_oid_t oid_type)
1895
1911
  {
1896
1912
  git_reflog *log;
1897
1913
 
@@ -1903,6 +1919,8 @@ static int reflog_alloc(git_reflog **reflog, const char *name)
1903
1919
  log->ref_name = git__strdup(name);
1904
1920
  GIT_ERROR_CHECK_ALLOC(log->ref_name);
1905
1921
 
1922
+ log->oid_type = oid_type;
1923
+
1906
1924
  if (git_vector_init(&log->entries, 0, NULL) < 0) {
1907
1925
  git__free(log->ref_name);
1908
1926
  git__free(log);
@@ -2032,7 +2050,10 @@ static int refdb_reflog_fs__has_log(git_refdb_backend *_backend, const char *nam
2032
2050
  return has_reflog(backend->repo, name);
2033
2051
  }
2034
2052
 
2035
- static int refdb_reflog_fs__read(git_reflog **out, git_refdb_backend *_backend, const char *name)
2053
+ static int refdb_reflog_fs__read(
2054
+ git_reflog **out,
2055
+ git_refdb_backend *_backend,
2056
+ const char *name)
2036
2057
  {
2037
2058
  int error = -1;
2038
2059
  git_str log_path = GIT_STR_INIT;
@@ -2048,7 +2069,7 @@ static int refdb_reflog_fs__read(git_reflog **out, git_refdb_backend *_backend,
2048
2069
  backend = GIT_CONTAINER_OF(_backend, refdb_fs_backend, parent);
2049
2070
  repo = backend->repo;
2050
2071
 
2051
- if (reflog_alloc(&log, name) < 0)
2072
+ if (reflog_alloc(&log, name, backend->oid_type) < 0)
2052
2073
  return -1;
2053
2074
 
2054
2075
  if (reflog_path(&log_path, repo, name) < 0)
@@ -2086,11 +2107,11 @@ static int serialize_reflog_entry(
2086
2107
  const git_signature *committer,
2087
2108
  const char *msg)
2088
2109
  {
2089
- char raw_old[GIT_OID_HEXSZ+1];
2090
- char raw_new[GIT_OID_HEXSZ+1];
2110
+ char raw_old[GIT_OID_MAX_HEXSIZE + 1];
2111
+ char raw_new[GIT_OID_MAX_HEXSIZE + 1];
2091
2112
 
2092
- git_oid_tostr(raw_old, GIT_OID_HEXSZ+1, oid_old);
2093
- git_oid_tostr(raw_new, GIT_OID_HEXSZ+1, oid_new);
2113
+ git_oid_tostr(raw_old, GIT_OID_MAX_HEXSIZE + 1, oid_old);
2114
+ git_oid_tostr(raw_new, GIT_OID_MAX_HEXSIZE + 1, oid_new);
2094
2115
 
2095
2116
  git_str_clear(buf);
2096
2117
 
@@ -2189,10 +2210,16 @@ success:
2189
2210
  }
2190
2211
 
2191
2212
  /* Append to the reflog, must be called under reference lock */
2192
- static int reflog_append(refdb_fs_backend *backend, const git_reference *ref, const git_oid *old, const git_oid *new, const git_signature *who, const char *message)
2213
+ static int reflog_append(
2214
+ refdb_fs_backend *backend,
2215
+ const git_reference *ref,
2216
+ const git_oid *old,
2217
+ const git_oid *new,
2218
+ const git_signature *who,
2219
+ const char *message)
2193
2220
  {
2194
2221
  int error, is_symbolic, open_flags;
2195
- git_oid old_id = {{0}}, new_id = {{0}};
2222
+ git_oid old_id, new_id;
2196
2223
  git_str buf = GIT_STR_INIT, path = GIT_STR_INIT;
2197
2224
  git_repository *repo = backend->repo;
2198
2225
 
@@ -2206,6 +2233,9 @@ static int reflog_append(refdb_fs_backend *backend, const git_reference *ref, co
2206
2233
 
2207
2234
  /* From here on is_symbolic also means that it's HEAD */
2208
2235
 
2236
+ git_oid_clear(&old_id, backend->oid_type);
2237
+ git_oid_clear(&new_id, backend->oid_type);
2238
+
2209
2239
  if (old) {
2210
2240
  git_oid_cpy(&old_id, old);
2211
2241
  } else {
@@ -2402,6 +2432,7 @@ int git_refdb_backend_fs(
2402
2432
  goto fail;
2403
2433
 
2404
2434
  backend->repo = repository;
2435
+ backend->oid_type = repository->oid_type;
2405
2436
 
2406
2437
  if (repository->gitdir) {
2407
2438
  backend->gitpath = setup_namespace(repository, repository->gitdir);
@@ -71,7 +71,11 @@ int git_reflog_write(git_reflog *reflog)
71
71
  return db->backend->reflog_write(db->backend, reflog);
72
72
  }
73
73
 
74
- int git_reflog_append(git_reflog *reflog, const git_oid *new_oid, const git_signature *committer, const char *msg)
74
+ int git_reflog_append(
75
+ git_reflog *reflog,
76
+ const git_oid *new_oid,
77
+ const git_signature *committer,
78
+ const char *msg)
75
79
  {
76
80
  const git_reflog_entry *previous;
77
81
  git_reflog_entry *entry;
@@ -104,7 +108,7 @@ int git_reflog_append(git_reflog *reflog, const git_oid *new_oid, const git_sign
104
108
  previous = git_reflog_entry_byindex(reflog, 0);
105
109
 
106
110
  if (previous == NULL)
107
- git_oid_fromstr(&entry->oid_old, GIT_OID_HEX_ZERO);
111
+ git_oid_clear(&entry->oid_old, reflog->oid_type);
108
112
  else
109
113
  git_oid_cpy(&entry->oid_old, &previous->oid_cur);
110
114
 
@@ -219,9 +223,7 @@ int git_reflog_drop(git_reflog *reflog, size_t idx, int rewrite_previous_entry)
219
223
  /* If the oldest entry has just been removed... */
220
224
  if (idx == entrycount - 1) {
221
225
  /* ...clear the oid_old member of the "new" oldest entry */
222
- if (git_oid_fromstr(&entry->oid_old, GIT_OID_HEX_ZERO) < 0)
223
- return -1;
224
-
226
+ git_oid_clear(&entry->oid_old, reflog->oid_type);
225
227
  return 0;
226
228
  }
227
229
 
@@ -16,8 +16,6 @@
16
16
  #define GIT_REFLOG_DIR_MODE 0777
17
17
  #define GIT_REFLOG_FILE_MODE 0666
18
18
 
19
- #define GIT_REFLOG_SIZE_MIN (2*GIT_OID_HEXSZ+2+17)
20
-
21
19
  struct git_reflog_entry {
22
20
  git_oid oid_old;
23
21
  git_oid oid_cur;
@@ -30,6 +28,7 @@ struct git_reflog_entry {
30
28
  struct git_reflog {
31
29
  git_refdb *db;
32
30
  char *ref_name;
31
+ git_oid_t oid_type;
33
32
  git_vector entries;
34
33
  };
35
34
 
@@ -86,6 +86,8 @@ git_reference *git_reference__alloc(
86
86
 
87
87
  if (peel != NULL)
88
88
  git_oid_cpy(&ref->peel, peel);
89
+ else
90
+ git_oid_clear(&ref->peel, GIT_OID_SHA1);
89
91
 
90
92
  return ref;
91
93
  }
@@ -17,6 +17,7 @@
17
17
  #include "fetchhead.h"
18
18
  #include "push.h"
19
19
  #include "proxy.h"
20
+ #include "strarray.h"
20
21
 
21
22
  #include "git2/config.h"
22
23
  #include "git2/types.h"
@@ -1026,6 +1027,24 @@ int git_remote_capabilities(unsigned int *out, git_remote *remote)
1026
1027
  return remote->transport->capabilities(out, remote->transport);
1027
1028
  }
1028
1029
 
1030
+ int git_remote_oid_type(git_oid_t *out, git_remote *remote)
1031
+ {
1032
+ GIT_ASSERT_ARG(remote);
1033
+
1034
+ if (!remote->transport) {
1035
+ git_error_set(GIT_ERROR_NET, "this remote has never connected");
1036
+ *out = 0;
1037
+ return -1;
1038
+ }
1039
+
1040
+ #ifdef GIT_EXPERIMENTAL_SHA256
1041
+ return remote->transport->oid_type(out, remote->transport);
1042
+ #else
1043
+ *out = GIT_OID_SHA1;
1044
+ return 0;
1045
+ #endif
1046
+ }
1047
+
1029
1048
  static int lookup_config(char **out, git_config *cfg, const char *name)
1030
1049
  {
1031
1050
  git_config_entry *ce = NULL;
@@ -1225,24 +1244,6 @@ static int ls_to_vector(git_vector *out, git_remote *remote)
1225
1244
  return 0;
1226
1245
  }
1227
1246
 
1228
- #define copy_opts(out, in) \
1229
- if (in) { \
1230
- (out)->callbacks = (in)->callbacks; \
1231
- (out)->proxy_opts = (in)->proxy_opts; \
1232
- (out)->custom_headers = (in)->custom_headers; \
1233
- (out)->follow_redirects = (in)->follow_redirects; \
1234
- }
1235
-
1236
- GIT_INLINE(int) connect_opts_from_fetch_opts(
1237
- git_remote_connect_options *out,
1238
- git_remote *remote,
1239
- const git_fetch_options *fetch_opts)
1240
- {
1241
- git_remote_connect_options tmp = GIT_REMOTE_CONNECT_OPTIONS_INIT;
1242
- copy_opts(&tmp, fetch_opts);
1243
- return git_remote_connect_options_normalize(out, remote->repo, &tmp);
1244
- }
1245
-
1246
1247
  static int connect_or_reset_options(
1247
1248
  git_remote *remote,
1248
1249
  int direction,
@@ -1330,7 +1331,8 @@ int git_remote_download(
1330
1331
  return -1;
1331
1332
  }
1332
1333
 
1333
- if (connect_opts_from_fetch_opts(&connect_opts, remote, opts) < 0)
1334
+ if (git_remote_connect_options__from_fetch_opts(&connect_opts,
1335
+ remote, opts) < 0)
1334
1336
  return -1;
1335
1337
 
1336
1338
  if ((error = connect_or_reset_options(remote, GIT_DIRECTION_FETCH, &connect_opts)) < 0)
@@ -1350,6 +1352,8 @@ int git_remote_fetch(
1350
1352
  bool prune = false;
1351
1353
  git_str reflog_msg_buf = GIT_STR_INIT;
1352
1354
  git_remote_connect_options connect_opts = GIT_REMOTE_CONNECT_OPTIONS_INIT;
1355
+ unsigned int capabilities;
1356
+ git_oid_t oid_type;
1353
1357
 
1354
1358
  GIT_ASSERT_ARG(remote);
1355
1359
 
@@ -1358,7 +1362,8 @@ int git_remote_fetch(
1358
1362
  return -1;
1359
1363
  }
1360
1364
 
1361
- if (connect_opts_from_fetch_opts(&connect_opts, remote, opts) < 0)
1365
+ if (git_remote_connect_options__from_fetch_opts(&connect_opts,
1366
+ remote, opts) < 0)
1362
1367
  return -1;
1363
1368
 
1364
1369
  if ((error = connect_or_reset_options(remote, GIT_DIRECTION_FETCH, &connect_opts)) < 0)
@@ -1369,6 +1374,10 @@ int git_remote_fetch(
1369
1374
  tagopt = opts->download_tags;
1370
1375
  }
1371
1376
 
1377
+ if ((error = git_remote_capabilities(&capabilities, remote)) < 0 ||
1378
+ (error = git_remote_oid_type(&oid_type, remote)) < 0)
1379
+ return error;
1380
+
1372
1381
  /* Connect and download everything */
1373
1382
  error = git_remote__download(remote, refspecs, opts);
1374
1383
 
@@ -1622,7 +1631,7 @@ int git_remote_prune(git_remote *remote, const git_remote_callbacks *callbacks)
1622
1631
  const git_refspec *spec;
1623
1632
  const char *refname;
1624
1633
  int error;
1625
- git_oid zero_id = {{ 0 }};
1634
+ git_oid zero_id = GIT_OID_SHA1_ZERO;
1626
1635
 
1627
1636
  if (callbacks)
1628
1637
  GIT_ERROR_CHECK_VERSION(callbacks, GIT_REMOTE_CALLBACKS_VERSION, "git_remote_callbacks");
@@ -1724,7 +1733,7 @@ static int update_ref(
1724
1733
  const git_remote_callbacks *callbacks)
1725
1734
  {
1726
1735
  git_reference *ref;
1727
- git_oid old_id;
1736
+ git_oid old_id = GIT_OID_SHA1_ZERO;
1728
1737
  int error;
1729
1738
 
1730
1739
  error = git_reference_name_to_id(&old_id, remote->repo, ref_name);
@@ -1830,7 +1839,7 @@ static int update_one_tip(
1830
1839
  }
1831
1840
 
1832
1841
  if (error == GIT_ENOTFOUND) {
1833
- memset(&old, 0, sizeof(git_oid));
1842
+ git_oid_clear(&old, GIT_OID_SHA1);
1834
1843
  error = 0;
1835
1844
 
1836
1845
  if (autotag && (error = git_vector_insert(update_heads, head)) < 0)
@@ -1892,10 +1901,10 @@ static int update_tips_for_spec(
1892
1901
  }
1893
1902
 
1894
1903
  /* Handle specified oid sources */
1895
- if (git_oid__is_hexstr(spec->src)) {
1904
+ if (git_oid__is_hexstr(spec->src, GIT_OID_SHA1)) {
1896
1905
  git_oid id;
1897
1906
 
1898
- if ((error = git_oid_fromstr(&id, spec->src)) < 0)
1907
+ if ((error = git_oid__fromstr(&id, spec->src, GIT_OID_SHA1)) < 0)
1899
1908
  goto on_error;
1900
1909
 
1901
1910
  if (spec->dst &&
@@ -2896,16 +2905,6 @@ done:
2896
2905
  return error;
2897
2906
  }
2898
2907
 
2899
- GIT_INLINE(int) connect_opts_from_push_opts(
2900
- git_remote_connect_options *out,
2901
- git_remote *remote,
2902
- const git_push_options *push_opts)
2903
- {
2904
- git_remote_connect_options tmp = GIT_REMOTE_CONNECT_OPTIONS_INIT;
2905
- copy_opts(&tmp, push_opts);
2906
- return git_remote_connect_options_normalize(out, remote->repo, &tmp);
2907
- }
2908
-
2909
2908
  int git_remote_upload(
2910
2909
  git_remote *remote,
2911
2910
  const git_strarray *refspecs,
@@ -2924,7 +2923,8 @@ int git_remote_upload(
2924
2923
  return -1;
2925
2924
  }
2926
2925
 
2927
- if ((error = connect_opts_from_push_opts(&connect_opts, remote, opts)) < 0)
2926
+ if ((error = git_remote_connect_options__from_push_opts(
2927
+ &connect_opts, remote, opts)) < 0)
2928
2928
  goto cleanup;
2929
2929
 
2930
2930
  if ((error = connect_or_reset_options(remote, GIT_DIRECTION_PUSH, &connect_opts)) < 0)
@@ -2985,7 +2985,8 @@ int git_remote_push(
2985
2985
  return -1;
2986
2986
  }
2987
2987
 
2988
- if (connect_opts_from_push_opts(&connect_opts, remote, opts) < 0)
2988
+ if (git_remote_connect_options__from_push_opts(&connect_opts,
2989
+ remote, opts) < 0)
2989
2990
  return -1;
2990
2991
 
2991
2992
  if ((error = git_remote_upload(remote, refspecs, opts)) < 0)