rugged 1.6.5 → 1.7.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (182) hide show
  1. checksums.yaml +4 -4
  2. data/ext/rugged/rugged_allocator.c +0 -54
  3. data/lib/rugged/version.rb +1 -1
  4. data/vendor/libgit2/CMakeLists.txt +3 -8
  5. data/vendor/libgit2/cmake/CheckPrototypeDefinitionSafe.cmake +16 -0
  6. data/vendor/libgit2/cmake/SelectGSSAPI.cmake +3 -3
  7. data/vendor/libgit2/cmake/SelectHTTPSBackend.cmake +21 -2
  8. data/vendor/libgit2/cmake/SelectHashes.cmake +4 -0
  9. data/vendor/libgit2/cmake/SelectXdiff.cmake +9 -0
  10. data/vendor/libgit2/deps/pcre/LICENCE +5 -5
  11. data/vendor/libgit2/deps/pcre/pcre.h +2 -2
  12. data/vendor/libgit2/deps/pcre/pcre_compile.c +6 -3
  13. data/vendor/libgit2/deps/pcre/pcre_exec.c +2 -2
  14. data/vendor/libgit2/deps/xdiff/CMakeLists.txt +28 -0
  15. data/vendor/libgit2/{src/libgit2 → deps}/xdiff/git-xdiff.h +4 -1
  16. data/vendor/libgit2/{src/libgit2 → deps}/xdiff/xdiffi.c +19 -18
  17. data/vendor/libgit2/{src/libgit2 → deps}/xdiff/xdiffi.h +2 -4
  18. data/vendor/libgit2/{src/libgit2 → deps}/xdiff/xemit.c +3 -3
  19. data/vendor/libgit2/{src/libgit2 → deps}/xdiff/xhistogram.c +7 -18
  20. data/vendor/libgit2/{src/libgit2 → deps}/xdiff/xmacros.h +18 -1
  21. data/vendor/libgit2/{src/libgit2 → deps}/xdiff/xmerge.c +24 -22
  22. data/vendor/libgit2/{src/libgit2 → deps}/xdiff/xpatience.c +21 -30
  23. data/vendor/libgit2/{src/libgit2 → deps}/xdiff/xprepare.c +13 -30
  24. data/vendor/libgit2/{src/libgit2 → deps}/xdiff/xutils.c +18 -1
  25. data/vendor/libgit2/{src/libgit2 → deps}/xdiff/xutils.h +2 -1
  26. data/vendor/libgit2/include/git2/common.h +26 -1
  27. data/vendor/libgit2/include/git2/diff.h +41 -3
  28. data/vendor/libgit2/include/git2/errors.h +4 -2
  29. data/vendor/libgit2/include/git2/index.h +9 -0
  30. data/vendor/libgit2/include/git2/oid.h +1 -1
  31. data/vendor/libgit2/include/git2/remote.h +18 -0
  32. data/vendor/libgit2/include/git2/repository.h +12 -2
  33. data/vendor/libgit2/include/git2/sys/alloc.h +0 -34
  34. data/vendor/libgit2/include/git2/sys/commit_graph.h +12 -2
  35. data/vendor/libgit2/include/git2/sys/midx.h +5 -1
  36. data/vendor/libgit2/include/git2/sys/stream.h +16 -2
  37. data/vendor/libgit2/include/git2/sys/transport.h +20 -2
  38. data/vendor/libgit2/include/git2/version.h +4 -4
  39. data/vendor/libgit2/include/git2/worktree.h +3 -1
  40. data/vendor/libgit2/src/CMakeLists.txt +34 -11
  41. data/vendor/libgit2/src/cli/cmd_clone.c +22 -6
  42. data/vendor/libgit2/src/cli/progress.c +9 -8
  43. data/vendor/libgit2/src/cli/progress.h +4 -4
  44. data/vendor/libgit2/src/libgit2/CMakeLists.txt +1 -19
  45. data/vendor/libgit2/src/libgit2/annotated_commit.c +2 -2
  46. data/vendor/libgit2/src/libgit2/annotated_commit.h +1 -1
  47. data/vendor/libgit2/src/libgit2/apply.c +4 -3
  48. data/vendor/libgit2/src/libgit2/blame.c +23 -16
  49. data/vendor/libgit2/src/libgit2/blame_git.c +0 -1
  50. data/vendor/libgit2/src/libgit2/branch.c +2 -2
  51. data/vendor/libgit2/src/libgit2/cherrypick.c +3 -3
  52. data/vendor/libgit2/src/libgit2/clone.c +3 -1
  53. data/vendor/libgit2/src/libgit2/commit.c +31 -9
  54. data/vendor/libgit2/src/libgit2/commit_graph.c +110 -43
  55. data/vendor/libgit2/src/libgit2/commit_graph.h +20 -4
  56. data/vendor/libgit2/src/libgit2/commit_list.c +12 -5
  57. data/vendor/libgit2/src/libgit2/commit_list.h +1 -0
  58. data/vendor/libgit2/src/libgit2/config_file.c +14 -8
  59. data/vendor/libgit2/src/libgit2/describe.c +10 -7
  60. data/vendor/libgit2/src/libgit2/diff.c +16 -7
  61. data/vendor/libgit2/src/libgit2/diff.h +6 -6
  62. data/vendor/libgit2/src/libgit2/diff_file.c +7 -7
  63. data/vendor/libgit2/src/libgit2/diff_generate.c +36 -15
  64. data/vendor/libgit2/src/libgit2/diff_parse.c +20 -4
  65. data/vendor/libgit2/src/libgit2/diff_print.c +26 -7
  66. data/vendor/libgit2/src/libgit2/diff_tform.c +4 -4
  67. data/vendor/libgit2/src/libgit2/diff_xdiff.h +1 -1
  68. data/vendor/libgit2/src/libgit2/email.c +4 -3
  69. data/vendor/libgit2/src/libgit2/errors.c +73 -18
  70. data/vendor/libgit2/src/libgit2/fetch.c +37 -9
  71. data/vendor/libgit2/src/libgit2/fetch.h +0 -2
  72. data/vendor/libgit2/src/libgit2/fetchhead.c +11 -9
  73. data/vendor/libgit2/src/libgit2/grafts.c +272 -0
  74. data/vendor/libgit2/src/libgit2/grafts.h +36 -0
  75. data/vendor/libgit2/src/libgit2/ident.c +3 -3
  76. data/vendor/libgit2/src/libgit2/index.c +325 -125
  77. data/vendor/libgit2/src/libgit2/index.h +14 -1
  78. data/vendor/libgit2/src/libgit2/indexer.c +10 -3
  79. data/vendor/libgit2/src/libgit2/iterator.c +20 -5
  80. data/vendor/libgit2/src/libgit2/iterator.h +3 -0
  81. data/vendor/libgit2/src/libgit2/libgit2.c +39 -0
  82. data/vendor/libgit2/src/libgit2/merge.c +14 -9
  83. data/vendor/libgit2/src/libgit2/merge_file.c +0 -2
  84. data/vendor/libgit2/src/libgit2/midx.c +66 -37
  85. data/vendor/libgit2/src/libgit2/midx.h +13 -3
  86. data/vendor/libgit2/src/libgit2/notes.c +9 -8
  87. data/vendor/libgit2/src/libgit2/object.c +40 -15
  88. data/vendor/libgit2/src/libgit2/object.h +6 -0
  89. data/vendor/libgit2/src/libgit2/odb.c +11 -5
  90. data/vendor/libgit2/src/libgit2/odb_pack.c +16 -3
  91. data/vendor/libgit2/src/libgit2/oid.c +7 -1
  92. data/vendor/libgit2/src/libgit2/oidarray.c +49 -3
  93. data/vendor/libgit2/src/libgit2/oidarray.h +5 -1
  94. data/vendor/libgit2/src/libgit2/pack-objects.c +19 -12
  95. data/vendor/libgit2/src/libgit2/pack-objects.h +5 -2
  96. data/vendor/libgit2/src/libgit2/pack.c +3 -3
  97. data/vendor/libgit2/src/libgit2/parse.c +7 -4
  98. data/vendor/libgit2/src/libgit2/parse.h +1 -1
  99. data/vendor/libgit2/src/libgit2/patch.h +7 -1
  100. data/vendor/libgit2/src/libgit2/patch_generate.c +24 -5
  101. data/vendor/libgit2/src/libgit2/patch_parse.c +16 -8
  102. data/vendor/libgit2/src/libgit2/push.c +2 -2
  103. data/vendor/libgit2/src/libgit2/reader.c +1 -1
  104. data/vendor/libgit2/src/libgit2/rebase.c +72 -84
  105. data/vendor/libgit2/src/libgit2/refdb_fs.c +22 -13
  106. data/vendor/libgit2/src/libgit2/refs.c +8 -1
  107. data/vendor/libgit2/src/libgit2/remote.c +15 -6
  108. data/vendor/libgit2/src/libgit2/remote.h +1 -0
  109. data/vendor/libgit2/src/libgit2/repository.c +580 -301
  110. data/vendor/libgit2/src/libgit2/repository.h +17 -2
  111. data/vendor/libgit2/src/libgit2/reset.c +2 -2
  112. data/vendor/libgit2/src/libgit2/revert.c +8 -11
  113. data/vendor/libgit2/src/libgit2/revparse.c +1 -4
  114. data/vendor/libgit2/src/libgit2/revwalk.c +26 -4
  115. data/vendor/libgit2/src/libgit2/stash.c +9 -8
  116. data/vendor/libgit2/src/libgit2/streams/mbedtls.c +0 -1
  117. data/vendor/libgit2/src/libgit2/streams/openssl.c +8 -16
  118. data/vendor/libgit2/src/libgit2/streams/schannel.c +715 -0
  119. data/vendor/libgit2/src/libgit2/streams/schannel.h +28 -0
  120. data/vendor/libgit2/src/libgit2/streams/socket.c +237 -51
  121. data/vendor/libgit2/src/libgit2/streams/socket.h +3 -1
  122. data/vendor/libgit2/src/libgit2/streams/stransport.c +40 -12
  123. data/vendor/libgit2/src/libgit2/streams/tls.c +5 -0
  124. data/vendor/libgit2/src/libgit2/submodule.h +3 -3
  125. data/vendor/libgit2/src/libgit2/threadstate.c +15 -2
  126. data/vendor/libgit2/src/libgit2/threadstate.h +1 -3
  127. data/vendor/libgit2/src/libgit2/transports/auth.h +1 -2
  128. data/vendor/libgit2/src/libgit2/transports/{auth_negotiate.c → auth_gssapi.c} +32 -32
  129. data/vendor/libgit2/src/libgit2/transports/auth_negotiate.h +1 -1
  130. data/vendor/libgit2/src/libgit2/transports/auth_ntlm.h +1 -1
  131. data/vendor/libgit2/src/libgit2/transports/{auth_ntlm.c → auth_ntlmclient.c} +12 -12
  132. data/vendor/libgit2/src/libgit2/transports/auth_sspi.c +341 -0
  133. data/vendor/libgit2/src/libgit2/transports/git.c +7 -8
  134. data/vendor/libgit2/src/libgit2/transports/http.c +7 -2
  135. data/vendor/libgit2/src/libgit2/transports/httpclient.c +5 -0
  136. data/vendor/libgit2/src/libgit2/transports/local.c +13 -4
  137. data/vendor/libgit2/src/libgit2/transports/smart.c +33 -27
  138. data/vendor/libgit2/src/libgit2/transports/smart.h +23 -8
  139. data/vendor/libgit2/src/libgit2/transports/smart_pkt.c +136 -17
  140. data/vendor/libgit2/src/libgit2/transports/smart_protocol.c +154 -47
  141. data/vendor/libgit2/src/libgit2/transports/ssh.c +3 -3
  142. data/vendor/libgit2/src/libgit2/transports/winhttp.c +14 -15
  143. data/vendor/libgit2/src/libgit2/tree-cache.c +26 -16
  144. data/vendor/libgit2/src/libgit2/tree-cache.h +5 -3
  145. data/vendor/libgit2/src/libgit2/tree.c +1 -1
  146. data/vendor/libgit2/src/libgit2/worktree.c +25 -10
  147. data/vendor/libgit2/src/util/alloc.c +65 -6
  148. data/vendor/libgit2/src/util/alloc.h +34 -9
  149. data/vendor/libgit2/src/util/allocators/failalloc.c +0 -60
  150. data/vendor/libgit2/src/util/allocators/failalloc.h +0 -6
  151. data/vendor/libgit2/src/util/allocators/stdalloc.c +2 -105
  152. data/vendor/libgit2/src/util/allocators/win32_leakcheck.c +0 -68
  153. data/vendor/libgit2/src/util/array.h +6 -1
  154. data/vendor/libgit2/src/util/cc-compat.h +2 -0
  155. data/vendor/libgit2/src/util/filebuf.c +6 -1
  156. data/vendor/libgit2/src/util/filebuf.h +19 -6
  157. data/vendor/libgit2/src/util/fs_path.c +1 -1
  158. data/vendor/libgit2/src/util/futils.c +8 -5
  159. data/vendor/libgit2/src/util/git2_features.h.in +9 -3
  160. data/vendor/libgit2/src/util/net.c +308 -157
  161. data/vendor/libgit2/src/util/net.h +25 -0
  162. data/vendor/libgit2/src/util/posix.c +54 -0
  163. data/vendor/libgit2/src/util/posix.h +22 -0
  164. data/vendor/libgit2/src/util/rand.c +6 -4
  165. data/vendor/libgit2/src/util/staticstr.h +66 -0
  166. data/vendor/libgit2/src/util/util.c +15 -10
  167. data/vendor/libgit2/src/util/util.h +24 -16
  168. data/vendor/libgit2/src/util/win32/error.c +1 -1
  169. data/vendor/libgit2/src/util/win32/path_w32.c +8 -8
  170. data/vendor/libgit2/src/util/win32/posix_w32.c +1 -1
  171. data/vendor/libgit2/src/util/win32/utf-conv.c +73 -75
  172. data/vendor/libgit2/src/util/win32/utf-conv.h +81 -14
  173. data/vendor/libgit2/src/util/win32/w32_util.c +1 -1
  174. metadata +29 -23
  175. data/vendor/libgit2/cmake/SelectWinHTTP.cmake +0 -17
  176. data/vendor/libgit2/src/libgit2/netops.c +0 -124
  177. data/vendor/libgit2/src/libgit2/netops.h +0 -68
  178. /data/vendor/libgit2/{src/libgit2 → deps}/xdiff/xdiff.h +0 -0
  179. /data/vendor/libgit2/{src/libgit2 → deps}/xdiff/xemit.h +0 -0
  180. /data/vendor/libgit2/{src/libgit2 → deps}/xdiff/xinclude.h +0 -0
  181. /data/vendor/libgit2/{src/libgit2 → deps}/xdiff/xprepare.h +0 -0
  182. /data/vendor/libgit2/{src/libgit2 → deps}/xdiff/xtypes.h +0 -0
@@ -30,15 +30,15 @@ typedef enum {
30
30
  } git_diff_origin_t;
31
31
 
32
32
  struct git_diff {
33
- git_refcount rc;
33
+ git_refcount rc;
34
34
  git_repository *repo;
35
- git_attr_session attrsession;
35
+ git_attr_session attrsession;
36
36
  git_diff_origin_t type;
37
- git_diff_options opts;
38
- git_vector deltas; /* vector of git_diff_delta */
37
+ git_diff_options opts;
38
+ git_vector deltas; /* vector of git_diff_delta */
39
39
  git_pool pool;
40
- git_iterator_t old_src;
41
- git_iterator_t new_src;
40
+ git_iterator_t old_src;
41
+ git_iterator_t new_src;
42
42
  git_diff_perfdata perf;
43
43
 
44
44
  int (*strcomp)(const char *, const char *);
@@ -112,7 +112,7 @@ int git_diff_file_content__init_from_diff(
112
112
  case GIT_DELTA_DELETED:
113
113
  has_data = use_old; break;
114
114
  case GIT_DELTA_UNTRACKED:
115
- has_data = !use_old &&
115
+ has_data = (use_old == (diff->opts.flags & GIT_DIFF_REVERSE)) &&
116
116
  (diff->opts.flags & GIT_DIFF_SHOW_UNTRACKED_CONTENT) != 0;
117
117
  break;
118
118
  case GIT_DELTA_UNREADABLE:
@@ -144,7 +144,7 @@ int git_diff_file_content__init_from_src(
144
144
 
145
145
  if (!src->blob && !src->buf) {
146
146
  fc->flags |= GIT_DIFF_FLAG__NO_DATA;
147
- git_oid_clear(&fc->file->id, GIT_OID_SHA1);
147
+ git_oid_clear(&fc->file->id, opts->oid_type);
148
148
  } else {
149
149
  fc->flags |= GIT_DIFF_FLAG__LOADED;
150
150
  fc->file->flags |= GIT_DIFF_FLAG_VALID_ID;
@@ -154,7 +154,7 @@ int git_diff_file_content__init_from_src(
154
154
  git_blob_dup((git_blob **)&fc->blob, (git_blob *) src->blob);
155
155
  fc->file->size = git_blob_rawsize(src->blob);
156
156
  git_oid_cpy(&fc->file->id, git_blob_id(src->blob));
157
- fc->file->id_abbrev = GIT_OID_SHA1_HEXSIZE;
157
+ fc->file->id_abbrev = (uint16_t)git_oid_hexsize(repo->oid_type);
158
158
 
159
159
  fc->map.len = (size_t)fc->file->size;
160
160
  fc->map.data = (char *)git_blob_rawcontent(src->blob);
@@ -162,10 +162,10 @@ int git_diff_file_content__init_from_src(
162
162
  fc->flags |= GIT_DIFF_FLAG__FREE_BLOB;
163
163
  } else {
164
164
  int error;
165
- if ((error = git_odb__hash(&fc->file->id, src->buf, src->buflen, GIT_OBJECT_BLOB, GIT_OID_SHA1)) < 0)
165
+ if ((error = git_odb__hash(&fc->file->id, src->buf, src->buflen, GIT_OBJECT_BLOB, opts->oid_type)) < 0)
166
166
  return error;
167
167
  fc->file->size = src->buflen;
168
- fc->file->id_abbrev = GIT_OID_SHA1_HEXSIZE;
168
+ fc->file->id_abbrev = (uint16_t)git_oid_hexsize(opts->oid_type);
169
169
 
170
170
  fc->map.len = src->buflen;
171
171
  fc->map.data = (char *)src->buf;
@@ -178,7 +178,7 @@ int git_diff_file_content__init_from_src(
178
178
  static int diff_file_content_commit_to_str(
179
179
  git_diff_file_content *fc, bool check_status)
180
180
  {
181
- char oid[GIT_OID_SHA1_HEXSIZE+1];
181
+ char oid[GIT_OID_MAX_HEXSIZE+1];
182
182
  git_str content = GIT_STR_INIT;
183
183
  const char *status = "";
184
184
 
@@ -420,7 +420,7 @@ static int diff_file_content_load_workdir(
420
420
  if (!error && (fc->file->flags & GIT_DIFF_FLAG_VALID_ID) == 0) {
421
421
  error = git_odb__hash(
422
422
  &fc->file->id, fc->map.data, fc->map.len,
423
- GIT_OBJECT_BLOB, GIT_OID_SHA1);
423
+ GIT_OBJECT_BLOB, diff_opts->oid_type);
424
424
  fc->file->flags |= GIT_DIFF_FLAG_VALID_ID;
425
425
  }
426
426
 
@@ -61,8 +61,8 @@ static git_diff_delta *diff_delta__alloc(
61
61
  }
62
62
  delta->status = status;
63
63
 
64
- git_oid_clear(&delta->old_file.id, GIT_OID_SHA1);
65
- git_oid_clear(&delta->new_file.id, GIT_OID_SHA1);
64
+ git_oid_clear(&delta->old_file.id, diff->base.opts.oid_type);
65
+ git_oid_clear(&delta->new_file.id, diff->base.opts.oid_type);
66
66
 
67
67
  return delta;
68
68
  }
@@ -149,10 +149,13 @@ static int diff_delta__from_one(
149
149
  const git_index_entry *entry = nitem;
150
150
  bool has_old = false;
151
151
  git_diff_delta *delta;
152
+ git_oid_t oid_type;
152
153
  const char *matched_pathspec;
153
154
 
154
155
  GIT_ASSERT_ARG((oitem != NULL) ^ (nitem != NULL));
155
156
 
157
+ oid_type = diff->base.opts.oid_type;
158
+
156
159
  if (oitem) {
157
160
  entry = oitem;
158
161
  has_old = true;
@@ -186,20 +189,23 @@ static int diff_delta__from_one(
186
189
  GIT_ASSERT(status != GIT_DELTA_MODIFIED);
187
190
  delta->nfiles = 1;
188
191
 
192
+ git_oid_clear(&delta->old_file.id, diff->base.opts.oid_type);
193
+ git_oid_clear(&delta->new_file.id, diff->base.opts.oid_type);
194
+
189
195
  if (has_old) {
190
196
  delta->old_file.mode = entry->mode;
191
197
  delta->old_file.size = entry->file_size;
192
198
  delta->old_file.flags |= GIT_DIFF_FLAG_EXISTS;
193
199
  git_oid_cpy(&delta->old_file.id, &entry->id);
194
- git_oid_clear(&delta->new_file.id, GIT_OID_SHA1);
195
- delta->old_file.id_abbrev = GIT_OID_SHA1_HEXSIZE;
200
+ git_oid_clear(&delta->new_file.id, oid_type);
201
+ delta->old_file.id_abbrev = (uint16_t)git_oid_hexsize(oid_type);
196
202
  } else /* ADDED, IGNORED, UNTRACKED */ {
197
203
  delta->new_file.mode = entry->mode;
198
204
  delta->new_file.size = entry->file_size;
199
205
  delta->new_file.flags |= GIT_DIFF_FLAG_EXISTS;
200
- git_oid_clear(&delta->old_file.id, GIT_OID_SHA1);
206
+ git_oid_clear(&delta->old_file.id, oid_type);
201
207
  git_oid_cpy(&delta->new_file.id, &entry->id);
202
- delta->new_file.id_abbrev = GIT_OID_SHA1_HEXSIZE;
208
+ delta->new_file.id_abbrev = (uint16_t)git_oid_hexsize(oid_type);
203
209
  }
204
210
 
205
211
  delta->old_file.flags |= GIT_DIFF_FLAG_VALID_ID;
@@ -225,6 +231,9 @@ static int diff_delta__from_two(
225
231
  const git_oid *old_id = &old_entry->id;
226
232
  git_diff_delta *delta;
227
233
  const char *canonical_path = old_entry->path;
234
+ git_oid_t oid_type;
235
+
236
+ oid_type = diff->base.opts.oid_type;
228
237
 
229
238
  if (status == GIT_DELTA_UNMODIFIED &&
230
239
  DIFF_FLAG_ISNT_SET(diff, GIT_DIFF_INCLUDE_UNMODIFIED))
@@ -254,14 +263,14 @@ static int diff_delta__from_two(
254
263
  delta->old_file.size = old_entry->file_size;
255
264
  delta->old_file.mode = old_mode;
256
265
  git_oid_cpy(&delta->old_file.id, old_id);
257
- delta->old_file.id_abbrev = GIT_OID_SHA1_HEXSIZE;
266
+ delta->old_file.id_abbrev = (uint16_t)git_oid_hexsize(oid_type);
258
267
  delta->old_file.flags |= GIT_DIFF_FLAG_VALID_ID |
259
268
  GIT_DIFF_FLAG_EXISTS;
260
269
  }
261
270
 
262
271
  if (!git_index_entry_is_conflict(new_entry)) {
263
272
  git_oid_cpy(&delta->new_file.id, new_id);
264
- delta->new_file.id_abbrev = GIT_OID_SHA1_HEXSIZE;
273
+ delta->new_file.id_abbrev = (uint16_t)git_oid_hexsize(oid_type);
265
274
  delta->new_file.size = new_entry->file_size;
266
275
  delta->new_file.mode = new_mode;
267
276
  delta->old_file.flags |= GIT_DIFF_FLAG_EXISTS;
@@ -490,6 +499,14 @@ static int diff_generated_apply_options(
490
499
  return -1;
491
500
  }
492
501
 
502
+ if (!diff->base.opts.oid_type) {
503
+ diff->base.opts.oid_type = repo->oid_type;
504
+ } else if (diff->base.opts.oid_type != repo->oid_type) {
505
+ git_error_set(GIT_ERROR_INVALID,
506
+ "specified object ID type does not match repository object ID type");
507
+ return -1;
508
+ }
509
+
493
510
  /* flag INCLUDE_TYPECHANGE_TREES implies INCLUDE_TYPECHANGE */
494
511
  if (DIFF_FLAG_IS_SET(diff, GIT_DIFF_INCLUDE_TYPECHANGE_TREES))
495
512
  diff->base.opts.flags |= GIT_DIFF_INCLUDE_TYPECHANGE;
@@ -603,7 +620,7 @@ int git_diff__oid_for_file(
603
620
  entry.mode = mode;
604
621
  entry.file_size = (uint32_t)size;
605
622
  entry.path = (char *)path;
606
- git_oid_clear(&entry.id, GIT_OID_SHA1);
623
+ git_oid_clear(&entry.id, diff->opts.oid_type);
607
624
 
608
625
  return git_diff__oid_for_entry(out, diff, &entry, mode, NULL);
609
626
  }
@@ -624,7 +641,7 @@ int git_diff__oid_for_entry(
624
641
  GIT_ASSERT(d->type == GIT_DIFF_TYPE_GENERATED);
625
642
  diff = (git_diff_generated *)d;
626
643
 
627
- git_oid_clear(out, GIT_OID_SHA1);
644
+ git_oid_clear(out, diff->base.opts.oid_type);
628
645
 
629
646
  if (git_repository_workdir_path(&full_path, diff->base.repo, entry.path) < 0)
630
647
  return -1;
@@ -660,7 +677,8 @@ int git_diff__oid_for_entry(
660
677
  git_error_clear();
661
678
  }
662
679
  } else if (S_ISLNK(mode)) {
663
- error = git_odb__hashlink(out, full_path.ptr, GIT_OID_SHA1);
680
+ error = git_odb__hashlink(out, full_path.ptr,
681
+ diff->base.opts.oid_type);
664
682
  diff->base.perf.oid_calculations++;
665
683
  } else if (!git__is_sizet(entry.file_size)) {
666
684
  git_error_set(GIT_ERROR_NOMEMORY, "file size overflow (for 32-bits) on '%s'",
@@ -676,7 +694,8 @@ int git_diff__oid_for_entry(
676
694
  else {
677
695
  error = git_odb__hashfd_filtered(
678
696
  out, fd, (size_t)entry.file_size,
679
- GIT_OBJECT_BLOB, GIT_OID_SHA1, fl);
697
+ GIT_OBJECT_BLOB, diff->base.opts.oid_type,
698
+ fl);
680
699
  p_close(fd);
681
700
  diff->base.perf.oid_calculations++;
682
701
  }
@@ -785,7 +804,7 @@ static int maybe_modified(
785
804
  git_diff_generated *diff,
786
805
  diff_in_progress *info)
787
806
  {
788
- git_oid noid = GIT_OID_SHA1_ZERO;
807
+ git_oid noid;
789
808
  git_delta_t status = GIT_DELTA_MODIFIED;
790
809
  const git_index_entry *oitem = info->oitem;
791
810
  const git_index_entry *nitem = info->nitem;
@@ -796,6 +815,8 @@ static int maybe_modified(
796
815
  const char *matched_pathspec;
797
816
  int error = 0;
798
817
 
818
+ git_oid_clear(&noid, diff->base.opts.oid_type);
819
+
799
820
  if (!diff_pathspec_match(&matched_pathspec, diff, oitem))
800
821
  return 0;
801
822
 
@@ -1700,11 +1721,11 @@ int git_diff__commit(
1700
1721
  *out = NULL;
1701
1722
 
1702
1723
  if ((parents = git_commit_parentcount(commit)) > 1) {
1703
- char commit_oidstr[GIT_OID_SHA1_HEXSIZE + 1];
1724
+ char commit_oidstr[GIT_OID_MAX_HEXSIZE + 1];
1704
1725
 
1705
1726
  error = -1;
1706
1727
  git_error_set(GIT_ERROR_INVALID, "commit %s is a merge commit",
1707
- git_oid_tostr(commit_oidstr, GIT_OID_SHA1_HEXSIZE + 1, git_commit_id(commit)));
1728
+ git_oid_tostr(commit_oidstr, GIT_OID_MAX_HEXSIZE + 1, git_commit_id(commit)));
1708
1729
  goto on_error;
1709
1730
  }
1710
1731
 
@@ -29,7 +29,7 @@ static void diff_parsed_free(git_diff *d)
29
29
  git__free(diff);
30
30
  }
31
31
 
32
- static git_diff_parsed *diff_parsed_alloc(void)
32
+ static git_diff_parsed *diff_parsed_alloc(git_oid_t oid_type)
33
33
  {
34
34
  git_diff_parsed *diff;
35
35
 
@@ -51,6 +51,7 @@ static git_diff_parsed *diff_parsed_alloc(void)
51
51
  }
52
52
 
53
53
  diff->base.opts.flags &= ~GIT_DIFF_IGNORE_CASE;
54
+ diff->base.opts.oid_type = oid_type;
54
55
 
55
56
  if (git_pool_init(&diff->base.pool, 1) < 0 ||
56
57
  git_vector_init(&diff->patches, 0, NULL) < 0 ||
@@ -67,19 +68,34 @@ static git_diff_parsed *diff_parsed_alloc(void)
67
68
  int git_diff_from_buffer(
68
69
  git_diff **out,
69
70
  const char *content,
70
- size_t content_len)
71
+ size_t content_len
72
+ #ifdef GIT_EXPERIMENTAL_SHA256
73
+ , git_diff_parse_options *opts
74
+ #endif
75
+ )
71
76
  {
72
77
  git_diff_parsed *diff;
73
78
  git_patch *patch;
74
79
  git_patch_parse_ctx *ctx = NULL;
80
+ git_patch_options patch_opts = GIT_PATCH_OPTIONS_INIT;
81
+ git_oid_t oid_type;
75
82
  int error = 0;
76
83
 
77
84
  *out = NULL;
78
85
 
79
- diff = diff_parsed_alloc();
86
+ #ifdef GIT_EXPERIMENTAL_SHA256
87
+ oid_type = (opts && opts->oid_type) ? opts->oid_type :
88
+ GIT_OID_DEFAULT;
89
+ #else
90
+ oid_type = GIT_OID_DEFAULT;
91
+ #endif
92
+
93
+ patch_opts.oid_type = oid_type;
94
+
95
+ diff = diff_parsed_alloc(oid_type);
80
96
  GIT_ERROR_CHECK_ALLOC(diff);
81
97
 
82
- ctx = git_patch_parse_ctx_init(content, content_len, NULL);
98
+ ctx = git_patch_parse_ctx_init(content, content_len, &patch_opts);
83
99
  GIT_ERROR_CHECK_ALLOC(ctx);
84
100
 
85
101
  while (ctx->parse_ctx.remain_len) {
@@ -29,6 +29,7 @@ typedef struct {
29
29
  const char *new_prefix;
30
30
  uint32_t flags;
31
31
  int id_strlen;
32
+ git_oid_t oid_type;
32
33
 
33
34
  int (*strcomp)(const char *, const char *);
34
35
  } diff_print_info;
@@ -46,6 +47,8 @@ static int diff_print_info_init__common(
46
47
  pi->payload = payload;
47
48
  pi->buf = out;
48
49
 
50
+ GIT_ASSERT(pi->oid_type);
51
+
49
52
  if (!pi->id_strlen) {
50
53
  if (!repo)
51
54
  pi->id_strlen = GIT_ABBREV_DEFAULT;
@@ -53,8 +56,9 @@ static int diff_print_info_init__common(
53
56
  return -1;
54
57
  }
55
58
 
56
- if (pi->id_strlen > GIT_OID_SHA1_HEXSIZE)
57
- pi->id_strlen = GIT_OID_SHA1_HEXSIZE;
59
+ if (pi->id_strlen > 0 &&
60
+ (size_t)pi->id_strlen > git_oid_hexsize(pi->oid_type))
61
+ pi->id_strlen = (int)git_oid_hexsize(pi->oid_type);
58
62
 
59
63
  memset(&pi->line, 0, sizeof(pi->line));
60
64
  pi->line.old_lineno = -1;
@@ -78,6 +82,7 @@ static int diff_print_info_init_fromdiff(
78
82
 
79
83
  if (diff) {
80
84
  pi->flags = diff->opts.flags;
85
+ pi->oid_type = diff->opts.oid_type;
81
86
  pi->id_strlen = diff->opts.id_abbrev;
82
87
  pi->old_prefix = diff->opts.old_prefix;
83
88
  pi->new_prefix = diff->opts.new_prefix;
@@ -101,6 +106,7 @@ static int diff_print_info_init_frompatch(
101
106
  memset(pi, 0, sizeof(diff_print_info));
102
107
 
103
108
  pi->flags = patch->diff_opts.flags;
109
+ pi->oid_type = patch->diff_opts.oid_type;
104
110
  pi->id_strlen = patch->diff_opts.id_abbrev;
105
111
  pi->old_prefix = patch->diff_opts.old_prefix;
106
112
  pi->new_prefix = patch->diff_opts.new_prefix;
@@ -212,7 +218,10 @@ static int diff_print_one_raw(
212
218
  git_str *out = pi->buf;
213
219
  int id_abbrev;
214
220
  char code = git_diff_status_char(delta->status);
215
- char start_oid[GIT_OID_SHA1_HEXSIZE+1], end_oid[GIT_OID_SHA1_HEXSIZE+1];
221
+ char start_oid[GIT_OID_MAX_HEXSIZE + 1],
222
+ end_oid[GIT_OID_MAX_HEXSIZE + 1];
223
+ size_t oid_hexsize;
224
+ bool id_is_abbrev;
216
225
 
217
226
  GIT_UNUSED(progress);
218
227
 
@@ -231,12 +240,21 @@ static int diff_print_one_raw(
231
240
  return -1;
232
241
  }
233
242
 
243
+ #ifdef GIT_EXPERIMENTAL_SHA256
244
+ GIT_ASSERT(delta->old_file.id.type == delta->new_file.id.type);
245
+ oid_hexsize = git_oid_hexsize(delta->old_file.id.type);
246
+ #else
247
+ oid_hexsize = GIT_OID_SHA1_HEXSIZE;
248
+ #endif
249
+
250
+ id_is_abbrev = (pi->id_strlen > 0 &&
251
+ (size_t)pi->id_strlen <= oid_hexsize);
252
+
234
253
  git_oid_tostr(start_oid, pi->id_strlen + 1, &delta->old_file.id);
235
254
  git_oid_tostr(end_oid, pi->id_strlen + 1, &delta->new_file.id);
236
255
 
237
- git_str_printf(
238
- out, (pi->id_strlen <= GIT_OID_SHA1_HEXSIZE) ?
239
- ":%06o %06o %s... %s... %c" : ":%06o %06o %s %s %c",
256
+ git_str_printf(out,
257
+ id_is_abbrev ? ":%06o %06o %s... %s... %c" : ":%06o %06o %s %s %c",
240
258
  delta->old_file.mode, delta->new_file.mode, start_oid, end_oid, code);
241
259
 
242
260
  if (delta->similarity > 0)
@@ -273,7 +291,8 @@ static int diff_print_oid_range(
273
291
  git_str *out, const git_diff_delta *delta, int id_strlen,
274
292
  bool print_index)
275
293
  {
276
- char start_oid[GIT_OID_SHA1_HEXSIZE+1], end_oid[GIT_OID_SHA1_HEXSIZE+1];
294
+ char start_oid[GIT_OID_MAX_HEXSIZE + 1],
295
+ end_oid[GIT_OID_MAX_HEXSIZE + 1];
277
296
 
278
297
  if (delta->old_file.mode &&
279
298
  id_strlen > delta->old_file.id_abbrev) {
@@ -364,7 +364,7 @@ static int insert_delete_side_of_split(
364
364
  memset(&deleted->new_file, 0, sizeof(deleted->new_file));
365
365
  deleted->new_file.path = deleted->old_file.path;
366
366
  deleted->new_file.flags |= GIT_DIFF_FLAG_VALID_ID;
367
- git_oid_clear(&deleted->new_file.id, GIT_OID_SHA1);
367
+ git_oid_clear(&deleted->new_file.id, diff->opts.oid_type);
368
368
 
369
369
  return git_vector_insert(onto, deleted);
370
370
  }
@@ -398,7 +398,7 @@ static int apply_splits_and_deletes(
398
398
  memset(&delta->old_file, 0, sizeof(delta->old_file));
399
399
  delta->old_file.path = delta->new_file.path;
400
400
  delta->old_file.flags |= GIT_DIFF_FLAG_VALID_ID;
401
- git_oid_clear(&delta->old_file.id, GIT_OID_SHA1);
401
+ git_oid_clear(&delta->old_file.id, diff->opts.oid_type);
402
402
  }
403
403
 
404
404
  /* clean up delta before inserting into new list */
@@ -997,7 +997,7 @@ find_best_matches:
997
997
  memset(&src->new_file, 0, sizeof(src->new_file));
998
998
  src->new_file.path = src->old_file.path;
999
999
  src->new_file.flags |= GIT_DIFF_FLAG_VALID_ID;
1000
- git_oid_clear(&src->new_file.id, GIT_OID_SHA1);
1000
+ git_oid_clear(&src->new_file.id, diff->opts.oid_type);
1001
1001
 
1002
1002
  num_updates++;
1003
1003
 
@@ -1023,7 +1023,7 @@ find_best_matches:
1023
1023
  memset(&src->old_file, 0, sizeof(src->old_file));
1024
1024
  src->old_file.path = src->new_file.path;
1025
1025
  src->old_file.flags |= GIT_DIFF_FLAG_VALID_ID;
1026
- git_oid_clear(&src->old_file.id, GIT_OID_SHA1);
1026
+ git_oid_clear(&src->old_file.id, diff->opts.oid_type);
1027
1027
 
1028
1028
  src->flags &= ~GIT_DIFF_FLAG__TO_SPLIT;
1029
1029
  num_rewrites--;
@@ -10,7 +10,7 @@
10
10
  #include "common.h"
11
11
 
12
12
  #include "diff.h"
13
- #include "xdiff/xdiff.h"
13
+ #include "xdiff.h"
14
14
  #include "patch_generate.h"
15
15
 
16
16
  /* xdiff cannot cope with large files. these files should not be passed to
@@ -130,11 +130,12 @@ static int append_header(
130
130
  const git_signature *author,
131
131
  git_email_create_options *opts)
132
132
  {
133
- char id[GIT_OID_SHA1_HEXSIZE];
133
+ char id[GIT_OID_MAX_HEXSIZE + 1];
134
134
  int error;
135
135
 
136
- if ((error = git_oid_fmt(id, commit_id)) < 0 ||
137
- (error = git_str_printf(out, "From %.*s %s\n", GIT_OID_SHA1_HEXSIZE, id, EMAIL_TIMESTAMP)) < 0 ||
136
+ git_oid_tostr(id, GIT_OID_MAX_HEXSIZE + 1, commit_id);
137
+
138
+ if ((error = git_str_printf(out, "From %s %s\n", id, EMAIL_TIMESTAMP)) < 0 ||
138
139
  (error = git_str_printf(out, "From: %s <%s>\n", author->name, author->email)) < 0 ||
139
140
  (error = append_date(out, &author->when)) < 0 ||
140
141
  (error = append_subject(out, patch_idx, patch_count, summary, opts)) < 0)
@@ -16,32 +16,51 @@
16
16
  * New error handling
17
17
  ********************************************/
18
18
 
19
- static git_error g_git_oom_error = {
19
+ static git_error oom_error = {
20
20
  "Out of memory",
21
21
  GIT_ERROR_NOMEMORY
22
22
  };
23
23
 
24
- static git_error g_git_uninitialized_error = {
24
+ static git_error uninitialized_error = {
25
25
  "libgit2 has not been initialized; you must call git_libgit2_init",
26
26
  GIT_ERROR_INVALID
27
27
  };
28
28
 
29
+ static git_error tlsdata_error = {
30
+ "thread-local data initialization failure",
31
+ GIT_ERROR
32
+ };
33
+
29
34
  static void set_error_from_buffer(int error_class)
30
35
  {
31
- git_error *error = &GIT_THREADSTATE->error_t;
32
- git_str *buf = &GIT_THREADSTATE->error_buf;
36
+ git_threadstate *threadstate = git_threadstate_get();
37
+ git_error *error;
38
+ git_str *buf;
39
+
40
+ if (!threadstate)
41
+ return;
42
+
43
+ error = &threadstate->error_t;
44
+ buf = &threadstate->error_buf;
33
45
 
34
46
  error->message = buf->ptr;
35
47
  error->klass = error_class;
36
48
 
37
- GIT_THREADSTATE->last_error = error;
49
+ threadstate->last_error = error;
38
50
  }
39
51
 
40
52
  static void set_error(int error_class, char *string)
41
53
  {
42
- git_str *buf = &GIT_THREADSTATE->error_buf;
54
+ git_threadstate *threadstate = git_threadstate_get();
55
+ git_str *buf;
56
+
57
+ if (!threadstate)
58
+ return;
59
+
60
+ buf = &threadstate->error_buf;
43
61
 
44
62
  git_str_clear(buf);
63
+
45
64
  if (string) {
46
65
  git_str_puts(buf, string);
47
66
  git__free(string);
@@ -52,7 +71,12 @@ static void set_error(int error_class, char *string)
52
71
 
53
72
  void git_error_set_oom(void)
54
73
  {
55
- GIT_THREADSTATE->last_error = &g_git_oom_error;
74
+ git_threadstate *threadstate = git_threadstate_get();
75
+
76
+ if (!threadstate)
77
+ return;
78
+
79
+ threadstate->last_error = &oom_error;
56
80
  }
57
81
 
58
82
  void git_error_set(int error_class, const char *fmt, ...)
@@ -69,10 +93,18 @@ void git_error_vset(int error_class, const char *fmt, va_list ap)
69
93
  #ifdef GIT_WIN32
70
94
  DWORD win32_error_code = (error_class == GIT_ERROR_OS) ? GetLastError() : 0;
71
95
  #endif
96
+
97
+ git_threadstate *threadstate = git_threadstate_get();
72
98
  int error_code = (error_class == GIT_ERROR_OS) ? errno : 0;
73
- git_str *buf = &GIT_THREADSTATE->error_buf;
99
+ git_str *buf;
100
+
101
+ if (!threadstate)
102
+ return;
103
+
104
+ buf = &threadstate->error_buf;
74
105
 
75
106
  git_str_clear(buf);
107
+
76
108
  if (fmt) {
77
109
  git_str_vprintf(buf, fmt, ap);
78
110
  if (error_class == GIT_ERROR_OS)
@@ -81,7 +113,7 @@ void git_error_vset(int error_class, const char *fmt, va_list ap)
81
113
 
82
114
  if (error_class == GIT_ERROR_OS) {
83
115
  #ifdef GIT_WIN32
84
- char * win32_error = git_win32_get_error_message(win32_error_code);
116
+ char *win32_error = git_win32_get_error_message(win32_error_code);
85
117
  if (win32_error) {
86
118
  git_str_puts(buf, win32_error);
87
119
  git__free(win32_error);
@@ -103,10 +135,16 @@ void git_error_vset(int error_class, const char *fmt, va_list ap)
103
135
 
104
136
  int git_error_set_str(int error_class, const char *string)
105
137
  {
106
- git_str *buf = &GIT_THREADSTATE->error_buf;
138
+ git_threadstate *threadstate = git_threadstate_get();
139
+ git_str *buf;
107
140
 
108
141
  GIT_ASSERT_ARG(string);
109
142
 
143
+ if (!threadstate)
144
+ return -1;
145
+
146
+ buf = &threadstate->error_buf;
147
+
110
148
  git_str_clear(buf);
111
149
  git_str_puts(buf, string);
112
150
 
@@ -119,9 +157,14 @@ int git_error_set_str(int error_class, const char *string)
119
157
 
120
158
  void git_error_clear(void)
121
159
  {
122
- if (GIT_THREADSTATE->last_error != NULL) {
160
+ git_threadstate *threadstate = git_threadstate_get();
161
+
162
+ if (!threadstate)
163
+ return;
164
+
165
+ if (threadstate->last_error != NULL) {
123
166
  set_error(0, NULL);
124
- GIT_THREADSTATE->last_error = NULL;
167
+ threadstate->last_error = NULL;
125
168
  }
126
169
 
127
170
  errno = 0;
@@ -132,17 +175,29 @@ void git_error_clear(void)
132
175
 
133
176
  const git_error *git_error_last(void)
134
177
  {
178
+ git_threadstate *threadstate;
179
+
135
180
  /* If the library is not initialized, return a static error. */
136
181
  if (!git_libgit2_init_count())
137
- return &g_git_uninitialized_error;
182
+ return &uninitialized_error;
183
+
184
+ if ((threadstate = git_threadstate_get()) == NULL)
185
+ return &tlsdata_error;
138
186
 
139
- return GIT_THREADSTATE->last_error;
187
+ return threadstate->last_error;
140
188
  }
141
189
 
142
190
  int git_error_state_capture(git_error_state *state, int error_code)
143
191
  {
144
- git_error *error = GIT_THREADSTATE->last_error;
145
- git_str *error_buf = &GIT_THREADSTATE->error_buf;
192
+ git_threadstate *threadstate = git_threadstate_get();
193
+ git_error *error;
194
+ git_str *error_buf;
195
+
196
+ if (!threadstate)
197
+ return -1;
198
+
199
+ error = threadstate->last_error;
200
+ error_buf = &threadstate->error_buf;
146
201
 
147
202
  memset(state, 0, sizeof(git_error_state));
148
203
 
@@ -150,13 +205,13 @@ int git_error_state_capture(git_error_state *state, int error_code)
150
205
  return 0;
151
206
 
152
207
  state->error_code = error_code;
153
- state->oom = (error == &g_git_oom_error);
208
+ state->oom = (error == &oom_error);
154
209
 
155
210
  if (error) {
156
211
  state->error_msg.klass = error->klass;
157
212
 
158
213
  if (state->oom)
159
- state->error_msg.message = g_git_oom_error.message;
214
+ state->error_msg.message = oom_error.message;
160
215
  else
161
216
  state->error_msg.message = git_str_detach(error_buf);
162
217
  }