rugged 1.5.0.1 → 1.7.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (250) hide show
  1. checksums.yaml +4 -4
  2. data/ext/rugged/extconf.rb +2 -2
  3. data/ext/rugged/rugged_allocator.c +0 -54
  4. data/ext/rugged/rugged_blame.c +2 -0
  5. data/ext/rugged/rugged_blob.c +3 -0
  6. data/ext/rugged/rugged_commit.c +1 -0
  7. data/ext/rugged/rugged_config.c +2 -0
  8. data/ext/rugged/rugged_diff.c +1 -0
  9. data/ext/rugged/rugged_index.c +2 -0
  10. data/ext/rugged/rugged_patch.c +1 -0
  11. data/ext/rugged/rugged_rebase.c +1 -0
  12. data/ext/rugged/rugged_reference.c +1 -0
  13. data/ext/rugged/rugged_remote.c +1 -0
  14. data/ext/rugged/rugged_repo.c +5 -2
  15. data/ext/rugged/rugged_revwalk.c +5 -1
  16. data/ext/rugged/rugged_submodule.c +1 -0
  17. data/ext/rugged/rugged_tag.c +1 -0
  18. data/ext/rugged/rugged_tree.c +4 -0
  19. data/lib/rugged/index.rb +1 -1
  20. data/lib/rugged/tree.rb +1 -1
  21. data/lib/rugged/version.rb +1 -1
  22. data/vendor/libgit2/CMakeLists.txt +7 -8
  23. data/vendor/libgit2/COPYING +30 -0
  24. data/vendor/libgit2/cmake/CheckPrototypeDefinitionSafe.cmake +16 -0
  25. data/vendor/libgit2/cmake/ExperimentalFeatures.cmake +23 -0
  26. data/vendor/libgit2/cmake/SelectGSSAPI.cmake +3 -3
  27. data/vendor/libgit2/cmake/SelectHTTPSBackend.cmake +21 -2
  28. data/vendor/libgit2/cmake/SelectHashes.cmake +4 -0
  29. data/vendor/libgit2/cmake/SelectXdiff.cmake +9 -0
  30. data/vendor/libgit2/deps/ntlmclient/CMakeLists.txt +2 -0
  31. data/vendor/libgit2/deps/pcre/LICENCE +5 -5
  32. data/vendor/libgit2/deps/pcre/pcre.h +2 -2
  33. data/vendor/libgit2/deps/pcre/pcre_compile.c +6 -3
  34. data/vendor/libgit2/deps/pcre/pcre_exec.c +2 -2
  35. data/vendor/libgit2/deps/xdiff/CMakeLists.txt +28 -0
  36. data/vendor/libgit2/{src/libgit2 → deps}/xdiff/git-xdiff.h +4 -1
  37. data/vendor/libgit2/{src/libgit2 → deps}/xdiff/xdiffi.c +19 -18
  38. data/vendor/libgit2/{src/libgit2 → deps}/xdiff/xdiffi.h +2 -4
  39. data/vendor/libgit2/{src/libgit2 → deps}/xdiff/xemit.c +3 -3
  40. data/vendor/libgit2/{src/libgit2 → deps}/xdiff/xhistogram.c +7 -18
  41. data/vendor/libgit2/{src/libgit2 → deps}/xdiff/xmacros.h +18 -1
  42. data/vendor/libgit2/{src/libgit2 → deps}/xdiff/xmerge.c +24 -22
  43. data/vendor/libgit2/{src/libgit2 → deps}/xdiff/xpatience.c +21 -30
  44. data/vendor/libgit2/{src/libgit2 → deps}/xdiff/xprepare.c +13 -30
  45. data/vendor/libgit2/{src/libgit2 → deps}/xdiff/xutils.c +18 -1
  46. data/vendor/libgit2/{src/libgit2 → deps}/xdiff/xutils.h +2 -1
  47. data/vendor/libgit2/include/git2/common.h +38 -6
  48. data/vendor/libgit2/include/git2/deprecated.h +6 -0
  49. data/vendor/libgit2/include/git2/diff.h +42 -4
  50. data/vendor/libgit2/include/git2/errors.h +4 -2
  51. data/vendor/libgit2/include/git2/experimental.h +20 -0
  52. data/vendor/libgit2/include/git2/index.h +9 -0
  53. data/vendor/libgit2/include/git2/indexer.h +29 -0
  54. data/vendor/libgit2/include/git2/object.h +28 -2
  55. data/vendor/libgit2/include/git2/odb.h +58 -7
  56. data/vendor/libgit2/include/git2/odb_backend.h +106 -18
  57. data/vendor/libgit2/include/git2/oid.h +116 -16
  58. data/vendor/libgit2/include/git2/remote.h +18 -0
  59. data/vendor/libgit2/include/git2/repository.h +32 -3
  60. data/vendor/libgit2/include/git2/stash.h +60 -6
  61. data/vendor/libgit2/include/git2/strarray.h +0 -13
  62. data/vendor/libgit2/include/git2/sys/alloc.h +0 -34
  63. data/vendor/libgit2/include/git2/sys/commit_graph.h +12 -2
  64. data/vendor/libgit2/include/git2/sys/midx.h +5 -1
  65. data/vendor/libgit2/include/git2/sys/odb_backend.h +1 -1
  66. data/vendor/libgit2/include/git2/sys/stream.h +16 -2
  67. data/vendor/libgit2/include/git2/sys/transport.h +32 -2
  68. data/vendor/libgit2/include/git2/version.h +4 -4
  69. data/vendor/libgit2/include/git2/worktree.h +3 -1
  70. data/vendor/libgit2/include/git2.h +1 -0
  71. data/vendor/libgit2/src/CMakeLists.txt +34 -17
  72. data/vendor/libgit2/src/cli/CMakeLists.txt +5 -2
  73. data/vendor/libgit2/src/cli/cmd_clone.c +22 -6
  74. data/vendor/libgit2/src/cli/cmd_hash_object.c +27 -8
  75. data/vendor/libgit2/src/cli/opt.c +1 -1
  76. data/vendor/libgit2/src/cli/progress.c +9 -8
  77. data/vendor/libgit2/src/cli/progress.h +4 -4
  78. data/vendor/libgit2/src/libgit2/CMakeLists.txt +25 -34
  79. data/vendor/libgit2/src/libgit2/annotated_commit.c +2 -2
  80. data/vendor/libgit2/src/libgit2/annotated_commit.h +1 -1
  81. data/vendor/libgit2/src/libgit2/apply.c +4 -3
  82. data/vendor/libgit2/src/libgit2/attr_file.c +1 -1
  83. data/vendor/libgit2/src/libgit2/attrcache.c +1 -1
  84. data/vendor/libgit2/src/libgit2/blame.c +23 -14
  85. data/vendor/libgit2/src/libgit2/blame_git.c +0 -1
  86. data/vendor/libgit2/src/libgit2/blob.c +4 -2
  87. data/vendor/libgit2/src/libgit2/blob.h +2 -2
  88. data/vendor/libgit2/src/libgit2/branch.c +2 -2
  89. data/vendor/libgit2/src/libgit2/cherrypick.c +3 -3
  90. data/vendor/libgit2/src/libgit2/clone.c +34 -3
  91. data/vendor/libgit2/src/libgit2/commit.c +78 -21
  92. data/vendor/libgit2/src/libgit2/commit.h +25 -7
  93. data/vendor/libgit2/src/libgit2/commit_graph.c +129 -47
  94. data/vendor/libgit2/src/libgit2/commit_graph.h +23 -4
  95. data/vendor/libgit2/src/libgit2/commit_list.c +16 -5
  96. data/vendor/libgit2/src/libgit2/commit_list.h +1 -0
  97. data/vendor/libgit2/src/libgit2/config.c +6 -3
  98. data/vendor/libgit2/src/libgit2/config_file.c +16 -10
  99. data/vendor/libgit2/src/libgit2/describe.c +11 -8
  100. data/vendor/libgit2/src/libgit2/diff.c +19 -6
  101. data/vendor/libgit2/src/libgit2/diff.h +6 -6
  102. data/vendor/libgit2/src/libgit2/diff_file.c +16 -7
  103. data/vendor/libgit2/src/libgit2/diff_generate.c +37 -11
  104. data/vendor/libgit2/src/libgit2/diff_parse.c +20 -4
  105. data/vendor/libgit2/src/libgit2/diff_print.c +26 -7
  106. data/vendor/libgit2/src/libgit2/diff_tform.c +4 -0
  107. data/vendor/libgit2/src/libgit2/diff_xdiff.h +1 -1
  108. data/vendor/libgit2/src/libgit2/email.c +4 -3
  109. data/vendor/libgit2/src/libgit2/errors.c +73 -18
  110. data/vendor/libgit2/src/libgit2/experimental.h.in +13 -0
  111. data/vendor/libgit2/src/libgit2/fetch.c +38 -13
  112. data/vendor/libgit2/src/libgit2/fetch.h +0 -2
  113. data/vendor/libgit2/src/libgit2/fetchhead.c +11 -9
  114. data/vendor/libgit2/src/libgit2/grafts.c +272 -0
  115. data/vendor/libgit2/src/libgit2/grafts.h +36 -0
  116. data/vendor/libgit2/src/libgit2/ident.c +3 -3
  117. data/vendor/libgit2/src/libgit2/index.c +327 -123
  118. data/vendor/libgit2/src/libgit2/index.h +14 -1
  119. data/vendor/libgit2/src/libgit2/indexer.c +116 -46
  120. data/vendor/libgit2/src/libgit2/iterator.c +21 -4
  121. data/vendor/libgit2/src/libgit2/iterator.h +3 -0
  122. data/vendor/libgit2/src/libgit2/libgit2.c +58 -0
  123. data/vendor/libgit2/src/libgit2/merge.c +14 -9
  124. data/vendor/libgit2/src/libgit2/merge_file.c +0 -2
  125. data/vendor/libgit2/src/libgit2/midx.c +68 -38
  126. data/vendor/libgit2/src/libgit2/midx.h +13 -3
  127. data/vendor/libgit2/src/libgit2/mwindow.c +5 -2
  128. data/vendor/libgit2/src/libgit2/mwindow.h +4 -1
  129. data/vendor/libgit2/src/libgit2/notes.c +9 -8
  130. data/vendor/libgit2/src/libgit2/object.c +118 -29
  131. data/vendor/libgit2/src/libgit2/object.h +17 -2
  132. data/vendor/libgit2/src/libgit2/odb.c +224 -55
  133. data/vendor/libgit2/src/libgit2/odb.h +43 -4
  134. data/vendor/libgit2/src/libgit2/odb_loose.c +128 -70
  135. data/vendor/libgit2/src/libgit2/odb_pack.c +111 -46
  136. data/vendor/libgit2/src/libgit2/oid.c +141 -77
  137. data/vendor/libgit2/src/libgit2/oid.h +183 -9
  138. data/vendor/libgit2/src/libgit2/oidarray.c +49 -3
  139. data/vendor/libgit2/src/libgit2/oidarray.h +5 -1
  140. data/vendor/libgit2/src/libgit2/pack-objects.c +31 -13
  141. data/vendor/libgit2/src/libgit2/pack-objects.h +5 -2
  142. data/vendor/libgit2/src/libgit2/pack.c +93 -70
  143. data/vendor/libgit2/src/libgit2/pack.h +29 -15
  144. data/vendor/libgit2/src/libgit2/parse.c +8 -4
  145. data/vendor/libgit2/src/libgit2/parse.h +1 -1
  146. data/vendor/libgit2/src/libgit2/patch.h +7 -1
  147. data/vendor/libgit2/src/libgit2/patch_generate.c +24 -5
  148. data/vendor/libgit2/src/libgit2/patch_parse.c +16 -8
  149. data/vendor/libgit2/src/libgit2/push.c +13 -3
  150. data/vendor/libgit2/src/libgit2/reader.c +1 -1
  151. data/vendor/libgit2/src/libgit2/rebase.c +72 -83
  152. data/vendor/libgit2/src/libgit2/refdb_fs.c +92 -52
  153. data/vendor/libgit2/src/libgit2/reflog.c +7 -5
  154. data/vendor/libgit2/src/libgit2/reflog.h +1 -2
  155. data/vendor/libgit2/src/libgit2/refs.c +9 -0
  156. data/vendor/libgit2/src/libgit2/remote.c +47 -37
  157. data/vendor/libgit2/src/libgit2/remote.h +41 -0
  158. data/vendor/libgit2/src/libgit2/repository.c +784 -329
  159. data/vendor/libgit2/src/libgit2/repository.h +26 -2
  160. data/vendor/libgit2/src/libgit2/reset.c +2 -2
  161. data/vendor/libgit2/src/libgit2/revert.c +8 -11
  162. data/vendor/libgit2/src/libgit2/revparse.c +23 -7
  163. data/vendor/libgit2/src/libgit2/revwalk.c +31 -5
  164. data/vendor/libgit2/src/libgit2/stash.c +209 -33
  165. data/vendor/libgit2/src/libgit2/strarray.c +1 -0
  166. data/vendor/libgit2/src/libgit2/strarray.h +25 -0
  167. data/vendor/libgit2/src/libgit2/streams/mbedtls.c +0 -1
  168. data/vendor/libgit2/src/libgit2/streams/openssl.c +9 -17
  169. data/vendor/libgit2/src/libgit2/streams/openssl_dynamic.c +7 -3
  170. data/vendor/libgit2/src/libgit2/streams/schannel.c +715 -0
  171. data/vendor/libgit2/src/libgit2/streams/schannel.h +28 -0
  172. data/vendor/libgit2/src/libgit2/streams/socket.c +240 -51
  173. data/vendor/libgit2/src/libgit2/streams/socket.h +3 -1
  174. data/vendor/libgit2/src/libgit2/streams/stransport.c +40 -12
  175. data/vendor/libgit2/src/libgit2/streams/tls.c +5 -0
  176. data/vendor/libgit2/src/libgit2/submodule.c +6 -2
  177. data/vendor/libgit2/src/libgit2/submodule.h +3 -3
  178. data/vendor/libgit2/src/libgit2/sysdir.c +294 -7
  179. data/vendor/libgit2/src/libgit2/sysdir.h +41 -9
  180. data/vendor/libgit2/src/libgit2/tag.c +29 -10
  181. data/vendor/libgit2/src/libgit2/tag.h +2 -2
  182. data/vendor/libgit2/src/libgit2/threadstate.c +15 -2
  183. data/vendor/libgit2/src/libgit2/threadstate.h +1 -3
  184. data/vendor/libgit2/src/libgit2/transports/auth.h +1 -2
  185. data/vendor/libgit2/src/libgit2/transports/{auth_negotiate.c → auth_gssapi.c} +32 -32
  186. data/vendor/libgit2/src/libgit2/transports/auth_negotiate.h +1 -1
  187. data/vendor/libgit2/src/libgit2/transports/auth_ntlm.h +1 -1
  188. data/vendor/libgit2/src/libgit2/transports/{auth_ntlm.c → auth_ntlmclient.c} +12 -12
  189. data/vendor/libgit2/src/libgit2/transports/auth_sspi.c +341 -0
  190. data/vendor/libgit2/src/libgit2/transports/git.c +7 -8
  191. data/vendor/libgit2/src/libgit2/transports/http.c +15 -9
  192. data/vendor/libgit2/src/libgit2/transports/httpclient.c +14 -0
  193. data/vendor/libgit2/src/libgit2/transports/httpclient.h +10 -0
  194. data/vendor/libgit2/src/libgit2/transports/local.c +27 -4
  195. data/vendor/libgit2/src/libgit2/transports/smart.c +68 -27
  196. data/vendor/libgit2/src/libgit2/transports/smart.h +33 -9
  197. data/vendor/libgit2/src/libgit2/transports/smart_pkt.c +281 -49
  198. data/vendor/libgit2/src/libgit2/transports/smart_protocol.c +192 -55
  199. data/vendor/libgit2/src/libgit2/transports/ssh.c +334 -102
  200. data/vendor/libgit2/src/libgit2/transports/winhttp.c +22 -18
  201. data/vendor/libgit2/src/libgit2/tree-cache.c +26 -16
  202. data/vendor/libgit2/src/libgit2/tree-cache.h +5 -3
  203. data/vendor/libgit2/src/libgit2/tree.c +23 -17
  204. data/vendor/libgit2/src/libgit2/tree.h +2 -2
  205. data/vendor/libgit2/src/libgit2/worktree.c +30 -10
  206. data/vendor/libgit2/src/util/CMakeLists.txt +6 -1
  207. data/vendor/libgit2/src/util/alloc.c +65 -6
  208. data/vendor/libgit2/src/util/alloc.h +34 -9
  209. data/vendor/libgit2/src/util/allocators/failalloc.c +0 -60
  210. data/vendor/libgit2/src/util/allocators/failalloc.h +0 -6
  211. data/vendor/libgit2/src/util/allocators/stdalloc.c +2 -105
  212. data/vendor/libgit2/src/util/allocators/win32_leakcheck.c +0 -68
  213. data/vendor/libgit2/src/util/array.h +6 -1
  214. data/vendor/libgit2/src/util/cc-compat.h +2 -0
  215. data/vendor/libgit2/src/util/filebuf.c +6 -1
  216. data/vendor/libgit2/src/util/filebuf.h +19 -6
  217. data/vendor/libgit2/src/util/fs_path.c +2 -2
  218. data/vendor/libgit2/src/util/futils.c +8 -8
  219. data/vendor/libgit2/src/{features.h.in → util/git2_features.h.in} +9 -3
  220. data/vendor/libgit2/src/util/git2_util.h +2 -2
  221. data/vendor/libgit2/src/util/hash/openssl.c +4 -3
  222. data/vendor/libgit2/src/util/hash/rfc6234/sha.h +0 -112
  223. data/vendor/libgit2/src/util/hash.h +13 -0
  224. data/vendor/libgit2/src/util/net.c +492 -87
  225. data/vendor/libgit2/src/util/net.h +32 -0
  226. data/vendor/libgit2/src/util/posix.c +54 -0
  227. data/vendor/libgit2/src/util/posix.h +24 -0
  228. data/vendor/libgit2/src/util/rand.c +10 -4
  229. data/vendor/libgit2/src/util/regexp.c +3 -3
  230. data/vendor/libgit2/src/util/staticstr.h +66 -0
  231. data/vendor/libgit2/src/util/thread.h +20 -19
  232. data/vendor/libgit2/src/util/util.c +15 -10
  233. data/vendor/libgit2/src/util/util.h +25 -16
  234. data/vendor/libgit2/src/util/win32/error.c +1 -1
  235. data/vendor/libgit2/src/util/win32/path_w32.c +8 -8
  236. data/vendor/libgit2/src/util/win32/posix_w32.c +1 -1
  237. data/vendor/libgit2/src/util/win32/utf-conv.c +73 -75
  238. data/vendor/libgit2/src/util/win32/utf-conv.h +81 -14
  239. data/vendor/libgit2/src/util/win32/w32_util.c +1 -1
  240. metadata +34 -26
  241. data/vendor/libgit2/cmake/SelectWinHTTP.cmake +0 -17
  242. data/vendor/libgit2/src/libgit2/netops.c +0 -124
  243. data/vendor/libgit2/src/libgit2/netops.h +0 -68
  244. data/vendor/libgit2/src/util/win32/findfile.c +0 -286
  245. data/vendor/libgit2/src/util/win32/findfile.h +0 -22
  246. /data/vendor/libgit2/{src/libgit2 → deps}/xdiff/xdiff.h +0 -0
  247. /data/vendor/libgit2/{src/libgit2 → deps}/xdiff/xemit.h +0 -0
  248. /data/vendor/libgit2/{src/libgit2 → deps}/xdiff/xinclude.h +0 -0
  249. /data/vendor/libgit2/{src/libgit2 → deps}/xdiff/xprepare.h +0 -0
  250. /data/vendor/libgit2/{src/libgit2 → deps}/xdiff/xtypes.h +0 -0
@@ -14,13 +14,13 @@
14
14
  #include <limits.h>
15
15
 
16
16
  const git_oid git_oid__empty_blob_sha1 =
17
- {{ 0xe6, 0x9d, 0xe2, 0x9b, 0xb2, 0xd1, 0xd6, 0x43, 0x4b, 0x8b,
18
- 0x29, 0xae, 0x77, 0x5a, 0xd8, 0xc2, 0xe4, 0x8c, 0x53, 0x91 }};
17
+ GIT_OID_INIT(GIT_OID_SHA1,
18
+ { 0xe6, 0x9d, 0xe2, 0x9b, 0xb2, 0xd1, 0xd6, 0x43, 0x4b, 0x8b,
19
+ 0x29, 0xae, 0x77, 0x5a, 0xd8, 0xc2, 0xe4, 0x8c, 0x53, 0x91 });
19
20
  const git_oid git_oid__empty_tree_sha1 =
20
- {{ 0x4b, 0x82, 0x5d, 0xc6, 0x42, 0xcb, 0x6e, 0xb9, 0xa0, 0x60,
21
- 0xe5, 0x4b, 0xf8, 0xd6, 0x92, 0x88, 0xfb, 0xee, 0x49, 0x04 }};
22
-
23
- static char to_hex[] = "0123456789abcdef";
21
+ GIT_OID_INIT(GIT_OID_SHA1,
22
+ { 0x4b, 0x82, 0x5d, 0xc6, 0x42, 0xcb, 0x6e, 0xb9, 0xa0, 0x60,
23
+ 0xe5, 0x4b, 0xf8, 0xd6, 0x92, 0x88, 0xfb, 0xee, 0x49, 0x04 });
24
24
 
25
25
  static int oid_error_invalid(const char *msg)
26
26
  {
@@ -28,21 +28,31 @@ static int oid_error_invalid(const char *msg)
28
28
  return -1;
29
29
  }
30
30
 
31
- int git_oid_fromstrn(git_oid *out, const char *str, size_t length)
31
+ int git_oid__fromstrn(
32
+ git_oid *out,
33
+ const char *str,
34
+ size_t length,
35
+ git_oid_t type)
32
36
  {
33
- size_t p;
37
+ size_t size, p;
34
38
  int v;
35
39
 
36
40
  GIT_ASSERT_ARG(out);
37
41
  GIT_ASSERT_ARG(str);
38
42
 
43
+ if (!(size = git_oid_size(type)))
44
+ return oid_error_invalid("unknown type");
45
+
39
46
  if (!length)
40
47
  return oid_error_invalid("too short");
41
48
 
42
- if (length > GIT_OID_HEXSZ)
49
+ if (length > git_oid_hexsize(type))
43
50
  return oid_error_invalid("too long");
44
51
 
45
- memset(out->id, 0, GIT_OID_RAWSZ);
52
+ #ifdef GIT_EXPERIMENTAL_SHA256
53
+ out->type = type;
54
+ #endif
55
+ memset(out->id, 0, size);
46
56
 
47
57
  for (p = 0; p < length; p++) {
48
58
  v = git__fromhex(str[p]);
@@ -55,87 +65,134 @@ int git_oid_fromstrn(git_oid *out, const char *str, size_t length)
55
65
  return 0;
56
66
  }
57
67
 
58
- int git_oid_fromstrp(git_oid *out, const char *str)
68
+ int git_oid__fromstrp(git_oid *out, const char *str, git_oid_t type)
59
69
  {
60
- return git_oid_fromstrn(out, str, strlen(str));
70
+ return git_oid__fromstrn(out, str, strlen(str), type);
61
71
  }
62
72
 
63
- int git_oid_fromstr(git_oid *out, const char *str)
73
+ int git_oid__fromstr(git_oid *out, const char *str, git_oid_t type)
64
74
  {
65
- return git_oid_fromstrn(out, str, GIT_OID_HEXSZ);
75
+ return git_oid__fromstrn(out, str, git_oid_hexsize(type), type);
66
76
  }
67
77
 
68
- GIT_INLINE(char) *fmt_one(char *str, unsigned int val)
78
+ #ifdef GIT_EXPERIMENTAL_SHA256
79
+ int git_oid_fromstrn(
80
+ git_oid *out,
81
+ const char *str,
82
+ size_t length,
83
+ git_oid_t type)
69
84
  {
70
- *str++ = to_hex[val >> 4];
71
- *str++ = to_hex[val & 0xf];
72
- return str;
85
+ return git_oid__fromstrn(out, str, length, type);
86
+ }
87
+
88
+ int git_oid_fromstrp(git_oid *out, const char *str, git_oid_t type)
89
+ {
90
+ return git_oid_fromstrn(out, str, strlen(str), type);
91
+ }
92
+
93
+ int git_oid_fromstr(git_oid *out, const char *str, git_oid_t type)
94
+ {
95
+ return git_oid_fromstrn(out, str, git_oid_hexsize(type), type);
96
+ }
97
+ #else
98
+ int git_oid_fromstrn(
99
+ git_oid *out,
100
+ const char *str,
101
+ size_t length)
102
+ {
103
+ return git_oid__fromstrn(out, str, length, GIT_OID_SHA1);
104
+ }
105
+
106
+ int git_oid_fromstrp(git_oid *out, const char *str)
107
+ {
108
+ return git_oid__fromstrn(out, str, strlen(str), GIT_OID_SHA1);
109
+ }
110
+
111
+ int git_oid_fromstr(git_oid *out, const char *str)
112
+ {
113
+ return git_oid__fromstrn(out, str, GIT_OID_SHA1_HEXSIZE, GIT_OID_SHA1);
73
114
  }
115
+ #endif
74
116
 
75
117
  int git_oid_nfmt(char *str, size_t n, const git_oid *oid)
76
118
  {
77
- size_t i, max_i;
119
+ size_t hex_size;
78
120
 
79
121
  if (!oid) {
80
122
  memset(str, 0, n);
81
123
  return 0;
82
124
  }
83
- if (n > GIT_OID_HEXSZ) {
84
- memset(&str[GIT_OID_HEXSZ], 0, n - GIT_OID_HEXSZ);
85
- n = GIT_OID_HEXSZ;
86
- }
87
-
88
- max_i = n / 2;
89
125
 
90
- for (i = 0; i < max_i; i++)
91
- str = fmt_one(str, oid->id[i]);
126
+ if (!(hex_size = git_oid_hexsize(git_oid_type(oid))))
127
+ return oid_error_invalid("unknown type");
92
128
 
93
- if (n & 1)
94
- *str++ = to_hex[oid->id[i] >> 4];
129
+ if (n > hex_size) {
130
+ memset(&str[hex_size], 0, n - hex_size);
131
+ n = hex_size;
132
+ }
95
133
 
134
+ git_oid_fmt_substr(str, oid, 0, n);
96
135
  return 0;
97
136
  }
98
137
 
99
138
  int git_oid_fmt(char *str, const git_oid *oid)
100
139
  {
101
- return git_oid_nfmt(str, GIT_OID_HEXSZ, oid);
140
+ return git_oid_nfmt(str, git_oid_hexsize(git_oid_type(oid)), oid);
102
141
  }
103
142
 
104
143
  int git_oid_pathfmt(char *str, const git_oid *oid)
105
144
  {
106
- size_t i;
145
+ size_t hex_size;
107
146
 
108
- str = fmt_one(str, oid->id[0]);
109
- *str++ = '/';
110
- for (i = 1; i < sizeof(oid->id); i++)
111
- str = fmt_one(str, oid->id[i]);
147
+ if (!(hex_size = git_oid_hexsize(git_oid_type(oid))))
148
+ return oid_error_invalid("unknown type");
112
149
 
150
+ git_oid_fmt_substr(str, oid, 0, 2);
151
+ str[2] = '/';
152
+ git_oid_fmt_substr(&str[3], oid, 2, (hex_size - 2));
113
153
  return 0;
114
154
  }
115
155
 
116
156
  char *git_oid_tostr_s(const git_oid *oid)
117
157
  {
118
- char *str = GIT_THREADSTATE->oid_fmt;
119
- git_oid_nfmt(str, GIT_OID_HEXSZ + 1, oid);
158
+ git_threadstate *threadstate = git_threadstate_get();
159
+ char *str;
160
+
161
+ if (!threadstate)
162
+ return NULL;
163
+
164
+ str = threadstate->oid_fmt;
165
+ git_oid_nfmt(str, git_oid_hexsize(git_oid_type(oid)) + 1, oid);
120
166
  return str;
121
167
  }
122
168
 
123
169
  char *git_oid_allocfmt(const git_oid *oid)
124
170
  {
125
- char *str = git__malloc(GIT_OID_HEXSZ + 1);
126
- if (!str)
171
+ size_t hex_size = git_oid_hexsize(git_oid_type(oid));
172
+ char *str = git__malloc(hex_size + 1);
173
+
174
+ if (!hex_size || !str)
127
175
  return NULL;
128
- git_oid_nfmt(str, GIT_OID_HEXSZ + 1, oid);
176
+
177
+ if (git_oid_nfmt(str, hex_size + 1, oid) < 0) {
178
+ git__free(str);
179
+ return NULL;
180
+ }
181
+
129
182
  return str;
130
183
  }
131
184
 
132
185
  char *git_oid_tostr(char *out, size_t n, const git_oid *oid)
133
186
  {
187
+ size_t hex_size;
188
+
134
189
  if (!out || n == 0)
135
190
  return "";
136
191
 
137
- if (n > GIT_OID_HEXSZ + 1)
138
- n = GIT_OID_HEXSZ + 1;
192
+ hex_size = oid ? git_oid_hexsize(git_oid_type(oid)) : 0;
193
+
194
+ if (n > hex_size + 1)
195
+ n = hex_size + 1;
139
196
 
140
197
  git_oid_nfmt(out, n - 1, oid); /* allow room for terminating NUL */
141
198
  out[n - 1] = '\0';
@@ -143,51 +200,44 @@ char *git_oid_tostr(char *out, size_t n, const git_oid *oid)
143
200
  return out;
144
201
  }
145
202
 
146
- int git_oid__parse(
147
- git_oid *oid, const char **buffer_out,
148
- const char *buffer_end, const char *header)
203
+ int git_oid__fromraw(git_oid *out, const unsigned char *raw, git_oid_t type)
149
204
  {
150
- const size_t sha_len = GIT_OID_HEXSZ;
151
- const size_t header_len = strlen(header);
152
-
153
- const char *buffer = *buffer_out;
154
-
155
- if (buffer + (header_len + sha_len + 1) > buffer_end)
156
- return -1;
157
-
158
- if (memcmp(buffer, header, header_len) != 0)
159
- return -1;
160
-
161
- if (buffer[header_len + sha_len] != '\n')
162
- return -1;
163
-
164
- if (git_oid_fromstr(oid, buffer + header_len) < 0)
165
- return -1;
205
+ size_t size;
166
206
 
167
- *buffer_out = buffer + (header_len + sha_len + 1);
207
+ if (!(size = git_oid_size(type)))
208
+ return oid_error_invalid("unknown type");
168
209
 
210
+ #ifdef GIT_EXPERIMENTAL_SHA256
211
+ out->type = type;
212
+ #endif
213
+ memcpy(out->id, raw, size);
169
214
  return 0;
170
215
  }
171
216
 
172
- void git_oid__writebuf(git_str *buf, const char *header, const git_oid *oid)
217
+ #ifdef GIT_EXPERIMENTAL_SHA256
218
+ int git_oid_fromraw(git_oid *out, const unsigned char *raw, git_oid_t type)
173
219
  {
174
- char hex_oid[GIT_OID_HEXSZ];
175
-
176
- git_oid_fmt(hex_oid, oid);
177
- git_str_puts(buf, header);
178
- git_str_put(buf, hex_oid, GIT_OID_HEXSZ);
179
- git_str_putc(buf, '\n');
220
+ return git_oid__fromraw(out, raw, type);
180
221
  }
181
-
222
+ #else
182
223
  int git_oid_fromraw(git_oid *out, const unsigned char *raw)
183
224
  {
184
- memcpy(out->id, raw, sizeof(out->id));
185
- return 0;
225
+ return git_oid__fromraw(out, raw, GIT_OID_SHA1);
186
226
  }
227
+ #endif
187
228
 
188
229
  int git_oid_cpy(git_oid *out, const git_oid *src)
189
230
  {
190
- return git_oid_raw_cpy(out->id, src->id);
231
+ size_t size;
232
+
233
+ if (!(size = git_oid_size(git_oid_type(src))))
234
+ return oid_error_invalid("unknown type");
235
+
236
+ #ifdef GIT_EXPERIMENTAL_SHA256
237
+ out->type = src->type;
238
+ #endif
239
+
240
+ return git_oid_raw_cpy(out->id, src->id, size);
191
241
  }
192
242
 
193
243
  int git_oid_cmp(const git_oid *a, const git_oid *b)
@@ -202,6 +252,11 @@ int git_oid_equal(const git_oid *a, const git_oid *b)
202
252
 
203
253
  int git_oid_ncmp(const git_oid *oid_a, const git_oid *oid_b, size_t len)
204
254
  {
255
+ #ifdef GIT_EXPERIMENTAL_SHA256
256
+ if (oid_a->type != oid_b->type)
257
+ return oid_a->type - oid_b->type;
258
+ #endif
259
+
205
260
  return git_oid_raw_ncmp(oid_a->id, oid_b->id, len);
206
261
  }
207
262
 
@@ -209,9 +264,10 @@ int git_oid_strcmp(const git_oid *oid_a, const char *str)
209
264
  {
210
265
  const unsigned char *a;
211
266
  unsigned char strval;
267
+ long size = (long)git_oid_size(git_oid_type(oid_a));
212
268
  int hexval;
213
269
 
214
- for (a = oid_a->id; *str && (a - oid_a->id) < GIT_OID_RAWSZ; ++a) {
270
+ for (a = oid_a->id; *str && (a - oid_a->id) < size; ++a) {
215
271
  if ((hexval = git__fromhex(*str++)) < 0)
216
272
  return -1;
217
273
  strval = (unsigned char)(hexval << 4);
@@ -235,8 +291,16 @@ int git_oid_streq(const git_oid *oid_a, const char *str)
235
291
  int git_oid_is_zero(const git_oid *oid_a)
236
292
  {
237
293
  const unsigned char *a = oid_a->id;
238
- unsigned int i;
239
- for (i = 0; i < GIT_OID_RAWSZ; ++i, ++a)
294
+ size_t size = git_oid_size(git_oid_type(oid_a)), i;
295
+
296
+ #ifdef GIT_EXPERIMENTAL_SHA256
297
+ if (!oid_a->type)
298
+ return 1;
299
+ else if (!size)
300
+ return 0;
301
+ #endif
302
+
303
+ for (i = 0; i < size; ++i, ++a)
240
304
  if (*a != 0)
241
305
  return 0;
242
306
  return 1;
@@ -393,7 +457,7 @@ int git_oid_shorten_add(git_oid_shorten *os, const char *text_oid)
393
457
  idx = 0;
394
458
  is_leaf = false;
395
459
 
396
- for (i = 0; i < GIT_OID_HEXSZ; ++i) {
460
+ for (i = 0; i < GIT_OID_SHA1_HEXSIZE; ++i) {
397
461
  int c = git__fromhex(text_oid[i]);
398
462
  trie_node *node;
399
463
 
@@ -9,11 +9,120 @@
9
9
 
10
10
  #include "common.h"
11
11
 
12
+ #include "git2/experimental.h"
12
13
  #include "git2/oid.h"
14
+ #include "hash.h"
15
+
16
+ #ifdef GIT_EXPERIMENTAL_SHA256
17
+ # define GIT_OID_NONE { 0, { 0 } }
18
+ # define GIT_OID_INIT(type, ...) { type, __VA_ARGS__ }
19
+ #else
20
+ # define GIT_OID_NONE { { 0 } }
21
+ # define GIT_OID_INIT(type, ...) { __VA_ARGS__ }
22
+ #endif
13
23
 
14
24
  extern const git_oid git_oid__empty_blob_sha1;
15
25
  extern const git_oid git_oid__empty_tree_sha1;
16
26
 
27
+ GIT_INLINE(git_oid_t) git_oid_type(const git_oid *oid)
28
+ {
29
+ #ifdef GIT_EXPERIMENTAL_SHA256
30
+ return oid->type;
31
+ #else
32
+ GIT_UNUSED(oid);
33
+ return GIT_OID_SHA1;
34
+ #endif
35
+ }
36
+
37
+ GIT_INLINE(size_t) git_oid_size(git_oid_t type)
38
+ {
39
+ switch (type) {
40
+ case GIT_OID_SHA1:
41
+ return GIT_OID_SHA1_SIZE;
42
+
43
+ #ifdef GIT_EXPERIMENTAL_SHA256
44
+ case GIT_OID_SHA256:
45
+ return GIT_OID_SHA256_SIZE;
46
+ #endif
47
+
48
+ }
49
+
50
+ return 0;
51
+ }
52
+
53
+ GIT_INLINE(size_t) git_oid_hexsize(git_oid_t type)
54
+ {
55
+ switch (type) {
56
+ case GIT_OID_SHA1:
57
+ return GIT_OID_SHA1_HEXSIZE;
58
+
59
+ #ifdef GIT_EXPERIMENTAL_SHA256
60
+ case GIT_OID_SHA256:
61
+ return GIT_OID_SHA256_HEXSIZE;
62
+ #endif
63
+
64
+ }
65
+
66
+ return 0;
67
+ }
68
+
69
+ GIT_INLINE(const char *) git_oid_type_name(git_oid_t type)
70
+ {
71
+ switch (type) {
72
+ case GIT_OID_SHA1:
73
+ return "sha1";
74
+
75
+ #ifdef GIT_EXPERIMENTAL_SHA256
76
+ case GIT_OID_SHA256:
77
+ return "sha256";
78
+ #endif
79
+ }
80
+
81
+ return "unknown";
82
+ }
83
+
84
+ GIT_INLINE(git_oid_t) git_oid_type_fromstr(const char *name)
85
+ {
86
+ if (strcmp(name, "sha1") == 0)
87
+ return GIT_OID_SHA1;
88
+
89
+ #ifdef GIT_EXPERIMENTAL_SHA256
90
+ if (strcmp(name, "sha256") == 0)
91
+ return GIT_OID_SHA256;
92
+ #endif
93
+
94
+ return 0;
95
+ }
96
+
97
+ GIT_INLINE(git_oid_t) git_oid_type_fromstrn(const char *name, size_t len)
98
+ {
99
+ if (len == CONST_STRLEN("sha1") && strncmp(name, "sha1", len) == 0)
100
+ return GIT_OID_SHA1;
101
+
102
+ #ifdef GIT_EXPERIMENTAL_SHA256
103
+ if (len == CONST_STRLEN("sha256") && strncmp(name, "sha256", len) == 0)
104
+ return GIT_OID_SHA256;
105
+ #endif
106
+
107
+ return 0;
108
+ }
109
+
110
+ GIT_INLINE(git_hash_algorithm_t) git_oid_algorithm(git_oid_t type)
111
+ {
112
+ switch (type) {
113
+ case GIT_OID_SHA1:
114
+ return GIT_HASH_ALGORITHM_SHA1;
115
+
116
+ #ifdef GIT_EXPERIMENTAL_SHA256
117
+ case GIT_OID_SHA256:
118
+ return GIT_HASH_ALGORITHM_SHA256;
119
+ #endif
120
+
121
+ }
122
+
123
+ return 0;
124
+ }
125
+
17
126
  /**
18
127
  * Format a git_oid into a newly allocated c-string.
19
128
  *
@@ -25,13 +134,42 @@ extern const git_oid git_oid__empty_tree_sha1;
25
134
  */
26
135
  char *git_oid_allocfmt(const git_oid *id);
27
136
 
137
+ /**
138
+ * Format the requested nibbles of an object id.
139
+ *
140
+ * @param str the string to write into
141
+ * @param oid the oid structure to format
142
+ * @param start the starting number of nibbles
143
+ * @param count the number of nibbles to format
144
+ */
145
+ GIT_INLINE(void) git_oid_fmt_substr(
146
+ char *str,
147
+ const git_oid *oid,
148
+ size_t start,
149
+ size_t count)
150
+ {
151
+ static char hex[] = "0123456789abcdef";
152
+ size_t i, end = start + count, min = start / 2, max = end / 2;
153
+
154
+ if (start & 1)
155
+ *str++ = hex[oid->id[min++] & 0x0f];
156
+
157
+ for (i = min; i < max; i++) {
158
+ *str++ = hex[oid->id[i] >> 4];
159
+ *str++ = hex[oid->id[i] & 0x0f];
160
+ }
161
+
162
+ if (end & 1)
163
+ *str++ = hex[oid->id[i] >> 4];
164
+ }
165
+
28
166
  GIT_INLINE(int) git_oid_raw_ncmp(
29
167
  const unsigned char *sha1,
30
168
  const unsigned char *sha2,
31
169
  size_t len)
32
170
  {
33
- if (len > GIT_OID_HEXSZ)
34
- len = GIT_OID_HEXSZ;
171
+ if (len > GIT_OID_MAX_HEXSIZE)
172
+ len = GIT_OID_MAX_HEXSIZE;
35
173
 
36
174
  while (len > 1) {
37
175
  if (*sha1 != *sha2)
@@ -50,16 +188,18 @@ GIT_INLINE(int) git_oid_raw_ncmp(
50
188
 
51
189
  GIT_INLINE(int) git_oid_raw_cmp(
52
190
  const unsigned char *sha1,
53
- const unsigned char *sha2)
191
+ const unsigned char *sha2,
192
+ size_t size)
54
193
  {
55
- return memcmp(sha1, sha2, GIT_OID_RAWSZ);
194
+ return memcmp(sha1, sha2, size);
56
195
  }
57
196
 
58
197
  GIT_INLINE(int) git_oid_raw_cpy(
59
198
  unsigned char *dst,
60
- const unsigned char *src)
199
+ const unsigned char *src,
200
+ size_t size)
61
201
  {
62
- memcpy(dst, src, GIT_OID_RAWSZ);
202
+ memcpy(dst, src, size);
63
203
  return 0;
64
204
  }
65
205
 
@@ -72,19 +212,30 @@ GIT_INLINE(int) git_oid_raw_cpy(
72
212
  */
73
213
  GIT_INLINE(int) git_oid__cmp(const git_oid *a, const git_oid *b)
74
214
  {
75
- return git_oid_raw_cmp(a->id, b->id);
215
+ #ifdef GIT_EXPERIMENTAL_SHA256
216
+ if (a->type != b->type)
217
+ return a->type - b->type;
218
+
219
+ return git_oid_raw_cmp(a->id, b->id, git_oid_size(a->type));
220
+ #else
221
+ return git_oid_raw_cmp(a->id, b->id, git_oid_size(GIT_OID_SHA1));
222
+ #endif
76
223
  }
77
224
 
78
225
  GIT_INLINE(void) git_oid__cpy_prefix(
79
226
  git_oid *out, const git_oid *id, size_t len)
80
227
  {
228
+ #ifdef GIT_EXPERIMENTAL_SHA256
229
+ out->type = id->type;
230
+ #endif
231
+
81
232
  memcpy(&out->id, id->id, (len + 1) / 2);
82
233
 
83
234
  if (len & 1)
84
235
  out->id[len / 2] &= 0xF0;
85
236
  }
86
237
 
87
- GIT_INLINE(bool) git_oid__is_hexstr(const char *str)
238
+ GIT_INLINE(bool) git_oid__is_hexstr(const char *str, git_oid_t type)
88
239
  {
89
240
  size_t i;
90
241
 
@@ -93,7 +244,30 @@ GIT_INLINE(bool) git_oid__is_hexstr(const char *str)
93
244
  return false;
94
245
  }
95
246
 
96
- return (i == GIT_OID_HEXSZ);
247
+ return (i == git_oid_hexsize(type));
97
248
  }
98
249
 
250
+ GIT_INLINE(void) git_oid_clear(git_oid *out, git_oid_t type)
251
+ {
252
+ memset(out->id, 0, git_oid_size(type));
253
+
254
+ #ifdef GIT_EXPERIMENTAL_SHA256
255
+ out->type = type;
256
+ #endif
257
+ }
258
+
259
+ /* SHA256 support */
260
+
261
+ int git_oid__fromstr(git_oid *out, const char *str, git_oid_t type);
262
+
263
+ int git_oid__fromstrp(git_oid *out, const char *str, git_oid_t type);
264
+
265
+ int git_oid__fromstrn(
266
+ git_oid *out,
267
+ const char *str,
268
+ size_t length,
269
+ git_oid_t type);
270
+
271
+ int git_oid__fromraw(git_oid *out, const unsigned char *raw, git_oid_t type);
272
+
99
273
  #endif
@@ -15,10 +15,17 @@ void git_oidarray_dispose(git_oidarray *arr)
15
15
  git__free(arr->ids);
16
16
  }
17
17
 
18
- void git_oidarray__from_array(git_oidarray *arr, git_array_oid_t *array)
18
+ void git_oidarray__from_array(git_oidarray *out, const git_array_oid_t *array)
19
19
  {
20
- arr->count = array->size;
21
- arr->ids = array->ptr;
20
+ out->count = array->size;
21
+ out->ids = array->ptr;
22
+ }
23
+
24
+ void git_oidarray__to_array(git_array_oid_t *out, const git_oidarray *array)
25
+ {
26
+ out->ptr = array->ids;
27
+ out->size = array->count;
28
+ out->asize = array->count;
22
29
  }
23
30
 
24
31
  void git_oidarray__reverse(git_oidarray *arr)
@@ -33,6 +40,45 @@ void git_oidarray__reverse(git_oidarray *arr)
33
40
  }
34
41
  }
35
42
 
43
+ int git_oidarray__add(git_array_oid_t *arr, git_oid *id)
44
+ {
45
+ git_oid *add, *iter;
46
+ size_t i;
47
+
48
+ git_array_foreach(*arr, i, iter) {
49
+ if (git_oid_cmp(iter, id) == 0)
50
+ return 0;
51
+ }
52
+
53
+ if ((add = git_array_alloc(*arr)) == NULL)
54
+ return -1;
55
+
56
+ git_oid_cpy(add, id);
57
+ return 0;
58
+ }
59
+
60
+ bool git_oidarray__remove(git_array_oid_t *arr, git_oid *id)
61
+ {
62
+ bool found = false;
63
+ size_t remain, i;
64
+ git_oid *iter;
65
+
66
+ git_array_foreach(*arr, i, iter) {
67
+ if (git_oid_cmp(iter, id) == 0) {
68
+ arr->size--;
69
+ remain = arr->size - i;
70
+
71
+ if (remain > 0)
72
+ memmove(&arr->ptr[i], &arr->ptr[i+1], remain * sizeof(git_oid));
73
+
74
+ found = true;
75
+ break;
76
+ }
77
+ }
78
+
79
+ return found;
80
+ }
81
+
36
82
  #ifndef GIT_DEPRECATE_HARD
37
83
 
38
84
  void git_oidarray_free(git_oidarray *arr)
@@ -15,6 +15,10 @@
15
15
  typedef git_array_t(git_oid) git_array_oid_t;
16
16
 
17
17
  extern void git_oidarray__reverse(git_oidarray *arr);
18
- extern void git_oidarray__from_array(git_oidarray *arr, git_array_oid_t *array);
18
+ extern void git_oidarray__from_array(git_oidarray *out, const git_array_oid_t *array);
19
+ extern void git_oidarray__to_array(git_array_oid_t *out, const git_oidarray *array);
20
+
21
+ int git_oidarray__add(git_array_oid_t *arr, git_oid *id);
22
+ bool git_oidarray__remove(git_array_oid_t *arr, git_oid *id);
19
23
 
20
24
  #endif