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
@@ -71,12 +71,16 @@ const git_tree_cache *git_tree_cache_get(const git_tree_cache *tree, const char
71
71
  }
72
72
  }
73
73
 
74
- static int read_tree_internal(git_tree_cache **out,
75
- const char **buffer_in, const char *buffer_end,
76
- git_pool *pool)
74
+ static int read_tree_internal(
75
+ git_tree_cache **out,
76
+ const char **buffer_in,
77
+ const char *buffer_end,
78
+ git_oid_t oid_type,
79
+ git_pool *pool)
77
80
  {
78
81
  git_tree_cache *tree = NULL;
79
82
  const char *name_start, *buffer;
83
+ size_t oid_size = git_oid_size(oid_type);
80
84
  int count;
81
85
 
82
86
  buffer = name_start = *buffer_in;
@@ -87,7 +91,7 @@ static int read_tree_internal(git_tree_cache **out,
87
91
  if (++buffer >= buffer_end)
88
92
  goto corrupted;
89
93
 
90
- if (git_tree_cache_new(&tree, name_start, pool) < 0)
94
+ if (git_tree_cache_new(&tree, name_start, oid_type, pool) < 0)
91
95
  return -1;
92
96
 
93
97
  /* Blank-terminated ASCII decimal number of entries in this tree */
@@ -108,14 +112,14 @@ static int read_tree_internal(git_tree_cache **out,
108
112
  if (*buffer != '\n' || ++buffer > buffer_end)
109
113
  goto corrupted;
110
114
 
111
- /* The SHA1 is only there if it's not invalidated */
115
+ /* The OID is only there if it's not invalidated */
112
116
  if (tree->entry_count >= 0) {
113
117
  /* 160-bit SHA-1 for this tree and it's children */
114
- if (buffer + GIT_OID_RAWSZ > buffer_end)
118
+ if (buffer + oid_size > buffer_end)
115
119
  goto corrupted;
116
120
 
117
- git_oid_fromraw(&tree->oid, (const unsigned char *)buffer);
118
- buffer += GIT_OID_RAWSZ;
121
+ git_oid__fromraw(&tree->oid, (const unsigned char *)buffer, oid_type);
122
+ buffer += oid_size;
119
123
  }
120
124
 
121
125
  /* Parse children: */
@@ -130,7 +134,7 @@ static int read_tree_internal(git_tree_cache **out,
130
134
  memset(tree->children, 0x0, bufsize);
131
135
 
132
136
  for (i = 0; i < tree->children_count; ++i) {
133
- if (read_tree_internal(&tree->children[i], &buffer, buffer_end, pool) < 0)
137
+ if (read_tree_internal(&tree->children[i], &buffer, buffer_end, oid_type, pool) < 0)
134
138
  goto corrupted;
135
139
  }
136
140
  }
@@ -144,11 +148,16 @@ static int read_tree_internal(git_tree_cache **out,
144
148
  return -1;
145
149
  }
146
150
 
147
- int git_tree_cache_read(git_tree_cache **tree, const char *buffer, size_t buffer_size, git_pool *pool)
151
+ int git_tree_cache_read(
152
+ git_tree_cache **tree,
153
+ const char *buffer,
154
+ size_t buffer_size,
155
+ git_oid_t oid_type,
156
+ git_pool *pool)
148
157
  {
149
158
  const char *buffer_end = buffer + buffer_size;
150
159
 
151
- if (read_tree_internal(tree, &buffer, buffer_end, pool) < 0)
160
+ if (read_tree_internal(tree, &buffer, buffer_end, oid_type, pool) < 0)
152
161
  return -1;
153
162
 
154
163
  if (buffer < buffer_end) {
@@ -201,7 +210,7 @@ static int read_tree_recursive(git_tree_cache *cache, const git_tree *tree, git_
201
210
  continue;
202
211
  }
203
212
 
204
- if ((error = git_tree_cache_new(&cache->children[j], git_tree_entry_name(entry), pool)) < 0)
213
+ if ((error = git_tree_cache_new(&cache->children[j], git_tree_entry_name(entry), cache->oid_type, pool)) < 0)
205
214
  return error;
206
215
 
207
216
  if ((error = git_tree_lookup(&subtree, repo, git_tree_entry_id(entry))) < 0)
@@ -219,12 +228,12 @@ static int read_tree_recursive(git_tree_cache *cache, const git_tree *tree, git_
219
228
  return 0;
220
229
  }
221
230
 
222
- int git_tree_cache_read_tree(git_tree_cache **out, const git_tree *tree, git_pool *pool)
231
+ int git_tree_cache_read_tree(git_tree_cache **out, const git_tree *tree, git_oid_t oid_type, git_pool *pool)
223
232
  {
224
233
  int error;
225
234
  git_tree_cache *cache;
226
235
 
227
- if ((error = git_tree_cache_new(&cache, "", pool)) < 0)
236
+ if ((error = git_tree_cache_new(&cache, "", oid_type, pool)) < 0)
228
237
  return error;
229
238
 
230
239
  if ((error = read_tree_recursive(cache, tree, pool)) < 0)
@@ -234,7 +243,7 @@ int git_tree_cache_read_tree(git_tree_cache **out, const git_tree *tree, git_poo
234
243
  return 0;
235
244
  }
236
245
 
237
- int git_tree_cache_new(git_tree_cache **out, const char *name, git_pool *pool)
246
+ int git_tree_cache_new(git_tree_cache **out, const char *name, git_oid_t oid_type, git_pool *pool)
238
247
  {
239
248
  size_t name_len, alloc_size;
240
249
  git_tree_cache *tree;
@@ -248,6 +257,7 @@ int git_tree_cache_new(git_tree_cache **out, const char *name, git_pool *pool)
248
257
 
249
258
  memset(tree, 0x0, sizeof(git_tree_cache));
250
259
  /* NUL-terminated tree name */
260
+ tree->oid_type = oid_type;
251
261
  tree->namelen = name_len;
252
262
  memcpy(tree->name, name, name_len);
253
263
  tree->name[name_len] = '\0';
@@ -263,7 +273,7 @@ static void write_tree(git_str *out, git_tree_cache *tree)
263
273
  git_str_printf(out, "%s%c%"PRIdZ" %"PRIuZ"\n", tree->name, 0, tree->entry_count, tree->children_count);
264
274
 
265
275
  if (tree->entry_count != -1)
266
- git_str_put(out, (char *)&tree->oid.id, GIT_OID_RAWSZ);
276
+ git_str_put(out, (char *)&tree->oid.id, git_oid_size(tree->oid_type));
267
277
 
268
278
  for (i = 0; i < tree->children_count; i++)
269
279
  write_tree(out, tree->children[i]);
@@ -18,6 +18,8 @@ typedef struct git_tree_cache {
18
18
  struct git_tree_cache **children;
19
19
  size_t children_count;
20
20
 
21
+ git_oid_t oid_type;
22
+
21
23
  ssize_t entry_count;
22
24
  git_oid oid;
23
25
  size_t namelen;
@@ -25,14 +27,14 @@ typedef struct git_tree_cache {
25
27
  } git_tree_cache;
26
28
 
27
29
  int git_tree_cache_write(git_str *out, git_tree_cache *tree);
28
- int git_tree_cache_read(git_tree_cache **tree, const char *buffer, size_t buffer_size, git_pool *pool);
30
+ int git_tree_cache_read(git_tree_cache **tree, const char *buffer, size_t buffer_size, git_oid_t oid_type, git_pool *pool);
29
31
  void git_tree_cache_invalidate_path(git_tree_cache *tree, const char *path);
30
32
  const git_tree_cache *git_tree_cache_get(const git_tree_cache *tree, const char *path);
31
- int git_tree_cache_new(git_tree_cache **out, const char *name, git_pool *pool);
33
+ int git_tree_cache_new(git_tree_cache **out, const char *name, git_oid_t oid_type, git_pool *pool);
32
34
  /**
33
35
  * Read a tree as the root of the tree cache (like for `git read-tree`)
34
36
  */
35
- int git_tree_cache_read_tree(git_tree_cache **out, const git_tree *tree, git_pool *pool);
37
+ int git_tree_cache_read_tree(git_tree_cache **out, const git_tree *tree, git_oid_t oid_type, git_pool *pool);
36
38
  void git_tree_cache_free(git_tree_cache *tree);
37
39
 
38
40
  #endif
@@ -85,11 +85,17 @@ static git_tree_entry *alloc_entry(const char *filename, size_t filename_len, co
85
85
  char *filename_ptr;
86
86
  size_t tree_len;
87
87
 
88
+ #ifdef GIT_EXPERIMENTAL_SHA256
89
+ size_t oid_size = git_oid_size(id->type);
90
+ #else
91
+ size_t oid_size = GIT_OID_SHA1_SIZE;
92
+ #endif
93
+
88
94
  TREE_ENTRY_CHECK_NAMELEN(filename_len);
89
95
 
90
96
  if (GIT_ADD_SIZET_OVERFLOW(&tree_len, sizeof(git_tree_entry), filename_len) ||
91
97
  GIT_ADD_SIZET_OVERFLOW(&tree_len, tree_len, 1) ||
92
- GIT_ADD_SIZET_OVERFLOW(&tree_len, tree_len, GIT_OID_RAWSZ))
98
+ GIT_ADD_SIZET_OVERFLOW(&tree_len, tree_len, oid_size))
93
99
  return NULL;
94
100
 
95
101
  entry = git__calloc(1, tree_len);
@@ -383,11 +389,12 @@ static int parse_mode(uint16_t *mode_out, const char *buffer, size_t buffer_len,
383
389
  return 0;
384
390
  }
385
391
 
386
- int git_tree__parse_raw(void *_tree, const char *data, size_t size)
392
+ int git_tree__parse_raw(void *_tree, const char *data, size_t size, git_oid_t oid_type)
387
393
  {
388
394
  git_tree *tree = _tree;
389
395
  const char *buffer;
390
396
  const char *buffer_end;
397
+ const long oid_size = (long)git_oid_size(oid_type);
391
398
 
392
399
  buffer = data;
393
400
  buffer_end = buffer + size;
@@ -414,35 +421,33 @@ int git_tree__parse_raw(void *_tree, const char *data, size_t size)
414
421
  if ((filename_len = nul - buffer) == 0 || filename_len > UINT16_MAX)
415
422
  return tree_parse_error("failed to parse tree: can't parse filename", NULL);
416
423
 
417
- if ((buffer_end - (nul + 1)) < GIT_OID_RAWSZ)
424
+ if ((buffer_end - (nul + 1)) < (long)oid_size)
418
425
  return tree_parse_error("failed to parse tree: can't parse OID", NULL);
419
426
 
420
427
  /* Allocate the entry */
421
- {
422
- entry = git_array_alloc(tree->entries);
423
- GIT_ERROR_CHECK_ALLOC(entry);
424
-
425
- entry->attr = attr;
426
- entry->filename_len = (uint16_t)filename_len;
427
- entry->filename = buffer;
428
- git_oid_fromraw(&entry->oid, ((unsigned char *) buffer + filename_len + 1));
429
- }
428
+ entry = git_array_alloc(tree->entries);
429
+ GIT_ERROR_CHECK_ALLOC(entry);
430
430
 
431
+ entry->attr = attr;
432
+ entry->filename_len = (uint16_t)filename_len;
433
+ entry->filename = buffer;
431
434
  buffer += filename_len + 1;
432
- buffer += GIT_OID_RAWSZ;
435
+
436
+ git_oid__fromraw(&entry->oid, (unsigned char *)buffer, oid_type);
437
+ buffer += oid_size;
433
438
  }
434
439
 
435
440
  return 0;
436
441
  }
437
442
 
438
- int git_tree__parse(void *_tree, git_odb_object *odb_obj)
443
+ int git_tree__parse(void *_tree, git_odb_object *odb_obj, git_oid_t oid_type)
439
444
  {
440
445
  git_tree *tree = _tree;
441
446
  const char *data = git_odb_object_data(odb_obj);
442
447
  size_t size = git_odb_object_size(odb_obj);
443
448
  int error;
444
449
 
445
- if ((error = git_tree__parse_raw(tree, data, size)) < 0 ||
450
+ if ((error = git_tree__parse_raw(tree, data, size, oid_type)) < 0 ||
446
451
  (error = git_odb_object_dup(&tree->odb_obj, odb_obj)) < 0)
447
452
  return error;
448
453
 
@@ -506,6 +511,7 @@ static int git_treebuilder__write_with_buffer(
506
511
  git_odb *odb;
507
512
  git_tree_entry *entry;
508
513
  git_vector entries = GIT_VECTOR_INIT;
514
+ size_t oid_size = git_oid_size(bld->repo->oid_type);
509
515
 
510
516
  git_str_clear(buf);
511
517
 
@@ -529,7 +535,7 @@ static int git_treebuilder__write_with_buffer(
529
535
 
530
536
  git_str_printf(buf, "%o ", entry->attr);
531
537
  git_str_put(buf, entry->filename, entry->filename_len + 1);
532
- git_str_put(buf, (char *)entry->oid.id, GIT_OID_RAWSZ);
538
+ git_str_put(buf, (char *)entry->oid.id, oid_size);
533
539
 
534
540
  if (git_str_oom(buf)) {
535
541
  error = -1;
@@ -725,7 +731,7 @@ int git_tree__write_index(
725
731
  return ret;
726
732
 
727
733
  /* Read the tree cache into the index */
728
- ret = git_tree_cache_read_tree(&index->tree, tree, &index->tree_pool);
734
+ ret = git_tree_cache_read_tree(&index->tree, tree, index->oid_type, &index->tree_pool);
729
735
  git_tree_free(tree);
730
736
 
731
737
  return ret;
@@ -41,8 +41,8 @@ GIT_INLINE(bool) git_tree_entry__is_tree(const struct git_tree_entry *e)
41
41
  }
42
42
 
43
43
  void git_tree__free(void *tree);
44
- int git_tree__parse(void *tree, git_odb_object *obj);
45
- int git_tree__parse_raw(void *_tree, const char *data, size_t size);
44
+ int git_tree__parse(void *tree, git_odb_object *obj, git_oid_t oid_type);
45
+ int git_tree__parse_raw(void *_tree, const char *data, size_t size, git_oid_t oid_type);
46
46
 
47
47
  /**
48
48
  * Write a tree to the given repository
@@ -187,6 +187,11 @@ int git_worktree_lookup(git_worktree **out, git_repository *repo, const char *na
187
187
  if ((error = git_str_join3(&path, '/', repo->commondir, "worktrees", name)) < 0)
188
188
  goto out;
189
189
 
190
+ if (!git_fs_path_isdir(path.ptr)) {
191
+ error = GIT_ENOTFOUND;
192
+ goto out;
193
+ }
194
+
190
195
  if ((error = (open_worktree_dir(out, git_repository_workdir(repo), path.ptr, name))) < 0)
191
196
  goto out;
192
197
 
@@ -560,6 +565,8 @@ int git_worktree_is_prunable(git_worktree *wt,
560
565
  git_worktree_prune_options *opts)
561
566
  {
562
567
  git_worktree_prune_options popts = GIT_WORKTREE_PRUNE_OPTIONS_INIT;
568
+ git_str path = GIT_STR_INIT;
569
+ int ret = 0;
563
570
 
564
571
  GIT_ERROR_CHECK_VERSION(
565
572
  opts, GIT_WORKTREE_PRUNE_OPTIONS_VERSION,
@@ -570,27 +577,40 @@ int git_worktree_is_prunable(git_worktree *wt,
570
577
 
571
578
  if ((popts.flags & GIT_WORKTREE_PRUNE_LOCKED) == 0) {
572
579
  git_str reason = GIT_STR_INIT;
573
- int error;
574
580
 
575
- if ((error = git_worktree__is_locked(&reason, wt)) < 0)
576
- return error;
581
+ if ((ret = git_worktree__is_locked(&reason, wt)) < 0)
582
+ goto out;
583
+
584
+ if (ret) {
585
+ git_error_set(GIT_ERROR_WORKTREE,
586
+ "not pruning locked working tree: '%s'",
587
+ reason.size ? reason.ptr : "is locked");
577
588
 
578
- if (error) {
579
- if (!reason.size)
580
- git_str_attach_notowned(&reason, "no reason given", 15);
581
- git_error_set(GIT_ERROR_WORKTREE, "not pruning locked working tree: '%s'", reason.ptr);
582
589
  git_str_dispose(&reason);
583
- return 0;
590
+ ret = 0;
591
+ goto out;
584
592
  }
585
593
  }
586
594
 
587
595
  if ((popts.flags & GIT_WORKTREE_PRUNE_VALID) == 0 &&
588
596
  git_worktree_validate(wt) == 0) {
589
597
  git_error_set(GIT_ERROR_WORKTREE, "not pruning valid working tree");
590
- return 0;
598
+ goto out;
591
599
  }
592
600
 
593
- return 1;
601
+ if ((ret = git_str_printf(&path, "%s/worktrees/%s", wt->commondir_path, wt->name) < 0))
602
+ goto out;
603
+
604
+ if (!git_fs_path_exists(path.ptr)) {
605
+ git_error_set(GIT_ERROR_WORKTREE, "worktree gitdir ('%s') does not exist", path.ptr);
606
+ goto out;
607
+ }
608
+
609
+ ret = 1;
610
+
611
+ out:
612
+ git_str_dispose(&path);
613
+ return ret;
594
614
  }
595
615
 
596
616
  int git_worktree_prune(git_worktree *wt,
@@ -4,8 +4,11 @@ add_library(util OBJECT)
4
4
  set_target_properties(util PROPERTIES C_STANDARD 90)
5
5
  set_target_properties(util PROPERTIES C_EXTENSIONS OFF)
6
6
 
7
+ configure_file(git2_features.h.in git2_features.h)
8
+
7
9
  set(UTIL_INCLUDES
8
- "${PROJECT_BINARY_DIR}/src"
10
+ "${PROJECT_BINARY_DIR}/src/util"
11
+ "${PROJECT_BINARY_DIR}/include"
9
12
  "${PROJECT_SOURCE_DIR}/src/util"
10
13
  "${PROJECT_SOURCE_DIR}/include")
11
14
 
@@ -34,6 +37,7 @@ if(USE_SHA1 STREQUAL "CollisionDetection")
34
37
  target_compile_definitions(util PRIVATE SHA1DC_CUSTOM_INCLUDE_SHA1_C=\"git2_util.h\")
35
38
  target_compile_definitions(util PRIVATE SHA1DC_CUSTOM_INCLUDE_UBC_CHECK_C=\"git2_util.h\")
36
39
  elseif(USE_SHA1 STREQUAL "OpenSSL" OR USE_SHA1 STREQUAL "OpenSSL-Dynamic")
40
+ add_definitions(-DOPENSSL_API_COMPAT=0x10100000L)
37
41
  file(GLOB UTIL_SRC_SHA1 hash/openssl.*)
38
42
  elseif(USE_SHA1 STREQUAL "CommonCrypto")
39
43
  file(GLOB UTIL_SRC_SHA1 hash/common_crypto.*)
@@ -50,6 +54,7 @@ list(SORT UTIL_SRC_SHA1)
50
54
  if(USE_SHA256 STREQUAL "Builtin")
51
55
  file(GLOB UTIL_SRC_SHA256 hash/builtin.* hash/rfc6234/*)
52
56
  elseif(USE_SHA256 STREQUAL "OpenSSL" OR USE_SHA256 STREQUAL "OpenSSL-Dynamic")
57
+ add_definitions(-DOPENSSL_API_COMPAT=0x10100000L)
53
58
  file(GLOB UTIL_SRC_SHA256 hash/openssl.*)
54
59
  elseif(USE_SHA256 STREQUAL "CommonCrypto")
55
60
  file(GLOB UTIL_SRC_SHA256 hash/common_crypto.*)
@@ -15,16 +15,75 @@
15
15
  /* Fail any allocation until git_libgit2_init is called. */
16
16
  git_allocator git__allocator = {
17
17
  git_failalloc_malloc,
18
- git_failalloc_calloc,
19
- git_failalloc_strdup,
20
- git_failalloc_strndup,
21
- git_failalloc_substrdup,
22
18
  git_failalloc_realloc,
23
- git_failalloc_reallocarray,
24
- git_failalloc_mallocarray,
25
19
  git_failalloc_free
26
20
  };
27
21
 
22
+ void *git__calloc(size_t nelem, size_t elsize)
23
+ {
24
+ size_t newsize;
25
+ void *ptr;
26
+
27
+ if (GIT_MULTIPLY_SIZET_OVERFLOW(&newsize, nelem, elsize))
28
+ return NULL;
29
+
30
+ if ((ptr = git__malloc(newsize)))
31
+ memset(ptr, 0, newsize);
32
+
33
+ return ptr;
34
+ }
35
+
36
+ void *git__reallocarray(void *ptr, size_t nelem, size_t elsize)
37
+ {
38
+ size_t newsize;
39
+
40
+ if (GIT_MULTIPLY_SIZET_OVERFLOW(&newsize, nelem, elsize))
41
+ return NULL;
42
+
43
+ return git__realloc(ptr, newsize);
44
+ }
45
+
46
+ void *git__mallocarray(size_t nelem, size_t elsize)
47
+ {
48
+ return git__reallocarray(NULL, nelem, elsize);
49
+ }
50
+
51
+ char *git__strdup(const char *str)
52
+ {
53
+ size_t len = strlen(str) + 1;
54
+ void *ptr = git__malloc(len);
55
+
56
+ if (ptr)
57
+ memcpy(ptr, str, len);
58
+
59
+ return ptr;
60
+ }
61
+
62
+ char *git__strndup(const char *str, size_t n)
63
+ {
64
+ size_t len = p_strnlen(str, n);
65
+ char *ptr = git__malloc(len + 1);
66
+
67
+ if (ptr) {
68
+ memcpy(ptr, str, len);
69
+ ptr[len] = '\0';
70
+ }
71
+
72
+ return ptr;
73
+ }
74
+
75
+ char *git__substrdup(const char *str, size_t n)
76
+ {
77
+ char *ptr = git__malloc(n + 1);
78
+
79
+ if (ptr) {
80
+ memcpy(ptr, str, n);
81
+ ptr[n] = '\0';
82
+ }
83
+
84
+ return ptr;
85
+ }
86
+
28
87
  static int setup_default_allocator(void)
29
88
  {
30
89
  #if defined(GIT_WIN32_LEAKCHECK)
@@ -10,17 +10,42 @@
10
10
 
11
11
  #include "git2/sys/alloc.h"
12
12
 
13
+ #include "git2_util.h"
14
+
13
15
  extern git_allocator git__allocator;
14
16
 
15
- #define git__malloc(len) git__allocator.gmalloc(len, __FILE__, __LINE__)
16
- #define git__calloc(nelem, elsize) git__allocator.gcalloc(nelem, elsize, __FILE__, __LINE__)
17
- #define git__strdup(str) git__allocator.gstrdup(str, __FILE__, __LINE__)
18
- #define git__strndup(str, n) git__allocator.gstrndup(str, n, __FILE__, __LINE__)
19
- #define git__substrdup(str, n) git__allocator.gsubstrdup(str, n, __FILE__, __LINE__)
20
- #define git__realloc(ptr, size) git__allocator.grealloc(ptr, size, __FILE__, __LINE__)
21
- #define git__reallocarray(ptr, nelem, elsize) git__allocator.greallocarray(ptr, nelem, elsize, __FILE__, __LINE__)
22
- #define git__mallocarray(nelem, elsize) git__allocator.gmallocarray(nelem, elsize, __FILE__, __LINE__)
23
- #define git__free git__allocator.gfree
17
+ GIT_INLINE(void *) git__malloc(size_t len)
18
+ {
19
+ void *p = git__allocator.gmalloc(len, __FILE__, __LINE__);
20
+
21
+ if (!p)
22
+ git_error_set_oom();
23
+
24
+ return p;
25
+ }
26
+
27
+ GIT_INLINE(void *) git__realloc(void *ptr, size_t size)
28
+ {
29
+ void *p = git__allocator.grealloc(ptr, size, __FILE__, __LINE__);
30
+
31
+ if (!p)
32
+ git_error_set_oom();
33
+
34
+ return p;
35
+ }
36
+
37
+ GIT_INLINE(void) git__free(void *ptr)
38
+ {
39
+ git__allocator.gfree(ptr);
40
+ }
41
+
42
+ extern void *git__calloc(size_t nelem, size_t elsize);
43
+ extern void *git__mallocarray(size_t nelem, size_t elsize);
44
+ extern void *git__reallocarray(void *ptr, size_t nelem, size_t elsize);
45
+
46
+ extern char *git__strdup(const char *str);
47
+ extern char *git__strndup(const char *str, size_t n);
48
+ extern char *git__substrdup(const char *str, size_t n);
24
49
 
25
50
  /**
26
51
  * This function is being called by our global setup routines to
@@ -16,45 +16,6 @@ void *git_failalloc_malloc(size_t len, const char *file, int line)
16
16
  return NULL;
17
17
  }
18
18
 
19
- void *git_failalloc_calloc(size_t nelem, size_t elsize, const char *file, int line)
20
- {
21
- GIT_UNUSED(nelem);
22
- GIT_UNUSED(elsize);
23
- GIT_UNUSED(file);
24
- GIT_UNUSED(line);
25
-
26
- return NULL;
27
- }
28
-
29
- char *git_failalloc_strdup(const char *str, const char *file, int line)
30
- {
31
- GIT_UNUSED(str);
32
- GIT_UNUSED(file);
33
- GIT_UNUSED(line);
34
-
35
- return NULL;
36
- }
37
-
38
- char *git_failalloc_strndup(const char *str, size_t n, const char *file, int line)
39
- {
40
- GIT_UNUSED(str);
41
- GIT_UNUSED(n);
42
- GIT_UNUSED(file);
43
- GIT_UNUSED(line);
44
-
45
- return NULL;
46
- }
47
-
48
- char *git_failalloc_substrdup(const char *start, size_t n, const char *file, int line)
49
- {
50
- GIT_UNUSED(start);
51
- GIT_UNUSED(n);
52
- GIT_UNUSED(file);
53
- GIT_UNUSED(line);
54
-
55
- return NULL;
56
- }
57
-
58
19
  void *git_failalloc_realloc(void *ptr, size_t size, const char *file, int line)
59
20
  {
60
21
  GIT_UNUSED(ptr);
@@ -65,27 +26,6 @@ void *git_failalloc_realloc(void *ptr, size_t size, const char *file, int line)
65
26
  return NULL;
66
27
  }
67
28
 
68
- void *git_failalloc_reallocarray(void *ptr, size_t nelem, size_t elsize, const char *file, int line)
69
- {
70
- GIT_UNUSED(ptr);
71
- GIT_UNUSED(nelem);
72
- GIT_UNUSED(elsize);
73
- GIT_UNUSED(file);
74
- GIT_UNUSED(line);
75
-
76
- return NULL;
77
- }
78
-
79
- void *git_failalloc_mallocarray(size_t nelem, size_t elsize, const char *file, int line)
80
- {
81
- GIT_UNUSED(nelem);
82
- GIT_UNUSED(elsize);
83
- GIT_UNUSED(file);
84
- GIT_UNUSED(line);
85
-
86
- return NULL;
87
- }
88
-
89
29
  void git_failalloc_free(void *ptr)
90
30
  {
91
31
  GIT_UNUSED(ptr);
@@ -11,13 +11,7 @@
11
11
  #include "git2_util.h"
12
12
 
13
13
  extern void *git_failalloc_malloc(size_t len, const char *file, int line);
14
- extern void *git_failalloc_calloc(size_t nelem, size_t elsize, const char *file, int line);
15
- extern char *git_failalloc_strdup(const char *str, const char *file, int line);
16
- extern char *git_failalloc_strndup(const char *str, size_t n, const char *file, int line);
17
- extern char *git_failalloc_substrdup(const char *start, size_t n, const char *file, int line);
18
14
  extern void *git_failalloc_realloc(void *ptr, size_t size, const char *file, int line);
19
- extern void *git_failalloc_reallocarray(void *ptr, size_t nelem, size_t elsize, const char *file, int line);
20
- extern void *git_failalloc_mallocarray(size_t nelem, size_t elsize, const char *file, int line);
21
15
  extern void git_failalloc_free(void *ptr);
22
16
 
23
17
  #endif