rugged 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (288) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +1 -0
  3. data/README.md +1 -1
  4. data/ext/rugged/rugged.c +7 -4
  5. data/ext/rugged/rugged_object.c +1 -1
  6. data/ext/rugged/rugged_repo.c +3 -3
  7. data/lib/rugged/repository.rb +2 -2
  8. data/lib/rugged/version.rb +1 -1
  9. data/vendor/libgit2/CMakeLists.txt +11 -6
  10. data/vendor/libgit2/COPYING +109 -1
  11. data/vendor/libgit2/cmake/Findfutimens.cmake +14 -0
  12. data/vendor/libgit2/cmake/SelectHTTPSBackend.cmake +4 -0
  13. data/vendor/libgit2/cmake/SelectHashes.cmake +1 -0
  14. data/vendor/libgit2/deps/chromium-zlib/CMakeLists.txt +101 -0
  15. data/vendor/libgit2/deps/ntlmclient/CMakeLists.txt +18 -5
  16. data/vendor/libgit2/deps/ntlmclient/compat.h +0 -34
  17. data/vendor/libgit2/deps/ntlmclient/crypt.h +14 -9
  18. data/vendor/libgit2/deps/ntlmclient/crypt_commoncrypto.c +20 -20
  19. data/vendor/libgit2/deps/ntlmclient/crypt_commoncrypto.h +3 -3
  20. data/vendor/libgit2/deps/ntlmclient/crypt_mbedtls.c +37 -36
  21. data/vendor/libgit2/deps/ntlmclient/crypt_mbedtls.h +4 -3
  22. data/vendor/libgit2/deps/ntlmclient/crypt_openssl.c +178 -51
  23. data/vendor/libgit2/deps/ntlmclient/crypt_openssl.h +74 -5
  24. data/vendor/libgit2/deps/ntlmclient/ntlm.c +156 -124
  25. data/vendor/libgit2/deps/ntlmclient/ntlm.h +13 -9
  26. data/vendor/libgit2/deps/ntlmclient/ntlmclient.h +16 -3
  27. data/vendor/libgit2/deps/ntlmclient/unicode.h +10 -4
  28. data/vendor/libgit2/deps/ntlmclient/unicode_builtin.c +16 -27
  29. data/vendor/libgit2/deps/ntlmclient/unicode_builtin.h +20 -0
  30. data/vendor/libgit2/deps/ntlmclient/unicode_iconv.c +28 -52
  31. data/vendor/libgit2/deps/ntlmclient/unicode_iconv.h +22 -0
  32. data/vendor/libgit2/deps/ntlmclient/util.c +15 -1
  33. data/vendor/libgit2/deps/ntlmclient/util.h +2 -1
  34. data/vendor/libgit2/include/git2/apply.h +2 -0
  35. data/vendor/libgit2/include/git2/attr.h +89 -0
  36. data/vendor/libgit2/include/git2/blame.h +93 -42
  37. data/vendor/libgit2/include/git2/blob.h +31 -3
  38. data/vendor/libgit2/include/git2/branch.h +25 -0
  39. data/vendor/libgit2/include/git2/cert.h +42 -5
  40. data/vendor/libgit2/include/git2/checkout.h +28 -12
  41. data/vendor/libgit2/include/git2/commit.h +35 -19
  42. data/vendor/libgit2/include/git2/common.h +19 -4
  43. data/vendor/libgit2/include/git2/config.h +1 -1
  44. data/vendor/libgit2/include/git2/deprecated.h +206 -6
  45. data/vendor/libgit2/include/git2/diff.h +35 -20
  46. data/vendor/libgit2/include/git2/errors.h +6 -6
  47. data/vendor/libgit2/include/git2/filter.h +57 -17
  48. data/vendor/libgit2/include/git2/graph.h +20 -2
  49. data/vendor/libgit2/include/git2/index.h +3 -3
  50. data/vendor/libgit2/include/git2/indexer.h +2 -1
  51. data/vendor/libgit2/include/git2/odb.h +44 -20
  52. data/vendor/libgit2/include/git2/patch.h +8 -0
  53. data/vendor/libgit2/include/git2/rebase.h +25 -1
  54. data/vendor/libgit2/include/git2/refs.h +9 -5
  55. data/vendor/libgit2/include/git2/remote.h +59 -6
  56. data/vendor/libgit2/include/git2/repository.h +95 -52
  57. data/vendor/libgit2/include/git2/revparse.h +5 -5
  58. data/vendor/libgit2/include/git2/status.h +115 -59
  59. data/vendor/libgit2/include/git2/submodule.h +9 -0
  60. data/vendor/libgit2/include/git2/sys/commit_graph.h +174 -0
  61. data/vendor/libgit2/include/git2/sys/filter.h +49 -28
  62. data/vendor/libgit2/include/git2/sys/midx.h +74 -0
  63. data/vendor/libgit2/include/git2/sys/odb_backend.h +7 -0
  64. data/vendor/libgit2/include/git2/sys/transport.h +1 -0
  65. data/vendor/libgit2/include/git2/tag.h +12 -0
  66. data/vendor/libgit2/include/git2/transport.h +1 -1
  67. data/vendor/libgit2/include/git2/tree.h +2 -14
  68. data/vendor/libgit2/include/git2/types.h +9 -0
  69. data/vendor/libgit2/include/git2/version.h +3 -3
  70. data/vendor/libgit2/include/git2/worktree.h +1 -0
  71. data/vendor/libgit2/src/CMakeLists.txt +25 -4
  72. data/vendor/libgit2/src/alloc.c +21 -8
  73. data/vendor/libgit2/src/allocators/failalloc.c +92 -0
  74. data/vendor/libgit2/src/allocators/failalloc.h +23 -0
  75. data/vendor/libgit2/src/allocators/stdalloc.c +41 -10
  76. data/vendor/libgit2/src/allocators/win32_leakcheck.c +118 -0
  77. data/vendor/libgit2/src/allocators/{win32_crtdbg.h → win32_leakcheck.h} +3 -3
  78. data/vendor/libgit2/src/annotated_commit.c +21 -9
  79. data/vendor/libgit2/src/apply.c +16 -7
  80. data/vendor/libgit2/src/array.h +11 -11
  81. data/vendor/libgit2/src/attr.c +181 -74
  82. data/vendor/libgit2/src/attr_file.c +84 -39
  83. data/vendor/libgit2/src/attr_file.h +32 -11
  84. data/vendor/libgit2/src/attrcache.c +42 -37
  85. data/vendor/libgit2/src/attrcache.h +4 -5
  86. data/vendor/libgit2/src/blame.c +26 -15
  87. data/vendor/libgit2/src/blob.c +44 -24
  88. data/vendor/libgit2/src/branch.c +69 -17
  89. data/vendor/libgit2/src/buffer.c +334 -25
  90. data/vendor/libgit2/src/buffer.h +153 -2
  91. data/vendor/libgit2/src/cache.c +2 -2
  92. data/vendor/libgit2/src/cache.h +7 -7
  93. data/vendor/libgit2/src/cc-compat.h +10 -2
  94. data/vendor/libgit2/src/checkout.c +48 -26
  95. data/vendor/libgit2/src/cherrypick.c +6 -2
  96. data/vendor/libgit2/src/clone.c +26 -11
  97. data/vendor/libgit2/src/commit.c +41 -28
  98. data/vendor/libgit2/src/commit_graph.c +1209 -0
  99. data/vendor/libgit2/src/commit_graph.h +162 -0
  100. data/vendor/libgit2/src/commit_list.c +46 -0
  101. data/vendor/libgit2/src/commit_list.h +2 -0
  102. data/vendor/libgit2/src/common.h +25 -2
  103. data/vendor/libgit2/src/config.c +37 -15
  104. data/vendor/libgit2/src/config_cache.c +9 -4
  105. data/vendor/libgit2/src/config_file.c +16 -8
  106. data/vendor/libgit2/src/config_parse.c +4 -6
  107. data/vendor/libgit2/src/crlf.c +16 -6
  108. data/vendor/libgit2/src/date.c +4 -3
  109. data/vendor/libgit2/src/delta.c +1 -1
  110. data/vendor/libgit2/src/describe.c +6 -3
  111. data/vendor/libgit2/src/diff.c +11 -8
  112. data/vendor/libgit2/src/diff_driver.c +21 -17
  113. data/vendor/libgit2/src/diff_file.c +2 -6
  114. data/vendor/libgit2/src/diff_generate.c +46 -17
  115. data/vendor/libgit2/src/diff_print.c +19 -6
  116. data/vendor/libgit2/src/diff_stats.c +7 -5
  117. data/vendor/libgit2/src/diff_tform.c +11 -10
  118. data/vendor/libgit2/src/diff_xdiff.c +4 -2
  119. data/vendor/libgit2/src/diff_xdiff.h +1 -1
  120. data/vendor/libgit2/src/errors.c +24 -19
  121. data/vendor/libgit2/src/features.h.in +5 -1
  122. data/vendor/libgit2/src/fetch.c +5 -2
  123. data/vendor/libgit2/src/fetchhead.c +8 -4
  124. data/vendor/libgit2/src/filebuf.c +9 -7
  125. data/vendor/libgit2/src/filter.c +206 -110
  126. data/vendor/libgit2/src/filter.h +24 -5
  127. data/vendor/libgit2/src/futils.c +5 -5
  128. data/vendor/libgit2/src/futils.h +1 -1
  129. data/vendor/libgit2/src/graph.c +64 -9
  130. data/vendor/libgit2/src/hash/sha1/collisiondetect.c +3 -3
  131. data/vendor/libgit2/src/hash/sha1/common_crypto.c +3 -3
  132. data/vendor/libgit2/src/hash/sha1/generic.h +1 -1
  133. data/vendor/libgit2/src/hash/sha1/mbedtls.c +12 -12
  134. data/vendor/libgit2/src/hash/sha1/openssl.c +3 -3
  135. data/vendor/libgit2/src/hash/sha1/sha1dc/sha1.c +0 -2
  136. data/vendor/libgit2/src/hash/sha1/win32.c +15 -11
  137. data/vendor/libgit2/src/hash.c +16 -13
  138. data/vendor/libgit2/src/hash.h +1 -1
  139. data/vendor/libgit2/src/hashsig.c +23 -10
  140. data/vendor/libgit2/src/ident.c +13 -3
  141. data/vendor/libgit2/src/ignore.c +35 -19
  142. data/vendor/libgit2/src/index.c +112 -75
  143. data/vendor/libgit2/src/index.h +1 -1
  144. data/vendor/libgit2/src/indexer.c +50 -32
  145. data/vendor/libgit2/src/integer.h +79 -2
  146. data/vendor/libgit2/src/iterator.c +36 -24
  147. data/vendor/libgit2/src/iterator.h +1 -1
  148. data/vendor/libgit2/src/khash.h +2 -11
  149. data/vendor/libgit2/src/{settings.c → libgit2.c} +117 -50
  150. data/vendor/libgit2/src/libgit2.h +15 -0
  151. data/vendor/libgit2/src/mailmap.c +23 -10
  152. data/vendor/libgit2/src/map.h +3 -3
  153. data/vendor/libgit2/src/merge.c +75 -32
  154. data/vendor/libgit2/src/merge.h +2 -1
  155. data/vendor/libgit2/src/merge_driver.c +19 -13
  156. data/vendor/libgit2/src/merge_file.c +11 -3
  157. data/vendor/libgit2/src/message.c +3 -1
  158. data/vendor/libgit2/src/midx.c +471 -10
  159. data/vendor/libgit2/src/midx.h +28 -1
  160. data/vendor/libgit2/src/mwindow.c +106 -60
  161. data/vendor/libgit2/src/mwindow.h +3 -3
  162. data/vendor/libgit2/src/net.c +127 -3
  163. data/vendor/libgit2/src/net.h +16 -2
  164. data/vendor/libgit2/src/netops.c +6 -4
  165. data/vendor/libgit2/src/netops.h +2 -2
  166. data/vendor/libgit2/src/notes.c +10 -10
  167. data/vendor/libgit2/src/object.c +22 -14
  168. data/vendor/libgit2/src/odb.c +289 -51
  169. data/vendor/libgit2/src/odb.h +16 -2
  170. data/vendor/libgit2/src/odb_loose.c +28 -18
  171. data/vendor/libgit2/src/odb_mempack.c +1 -1
  172. data/vendor/libgit2/src/odb_pack.c +391 -114
  173. data/vendor/libgit2/src/oid.c +5 -4
  174. data/vendor/libgit2/src/pack-objects.c +54 -48
  175. data/vendor/libgit2/src/pack.c +339 -125
  176. data/vendor/libgit2/src/pack.h +25 -7
  177. data/vendor/libgit2/src/patch.c +14 -7
  178. data/vendor/libgit2/src/patch_generate.c +2 -2
  179. data/vendor/libgit2/src/patch_parse.c +2 -1
  180. data/vendor/libgit2/src/path.c +98 -53
  181. data/vendor/libgit2/src/path.h +79 -6
  182. data/vendor/libgit2/src/pathspec.c +8 -8
  183. data/vendor/libgit2/src/pool.c +13 -7
  184. data/vendor/libgit2/src/posix.c +43 -12
  185. data/vendor/libgit2/src/posix.h +9 -0
  186. data/vendor/libgit2/src/reader.c +10 -6
  187. data/vendor/libgit2/src/rebase.c +93 -49
  188. data/vendor/libgit2/src/refdb.c +30 -13
  189. data/vendor/libgit2/src/refdb_fs.c +125 -71
  190. data/vendor/libgit2/src/reflog.c +19 -14
  191. data/vendor/libgit2/src/refs.c +91 -43
  192. data/vendor/libgit2/src/refs.h +1 -1
  193. data/vendor/libgit2/src/refspec.c +80 -44
  194. data/vendor/libgit2/src/remote.c +281 -105
  195. data/vendor/libgit2/src/remote.h +2 -1
  196. data/vendor/libgit2/src/repository.c +191 -118
  197. data/vendor/libgit2/src/repository.h +13 -2
  198. data/vendor/libgit2/src/reset.c +7 -6
  199. data/vendor/libgit2/src/revert.c +6 -2
  200. data/vendor/libgit2/src/revparse.c +14 -9
  201. data/vendor/libgit2/src/revwalk.c +32 -15
  202. data/vendor/libgit2/src/runtime.c +162 -0
  203. data/vendor/libgit2/src/runtime.h +62 -0
  204. data/vendor/libgit2/src/settings.h +11 -0
  205. data/vendor/libgit2/src/signature.c +6 -5
  206. data/vendor/libgit2/src/sortedcache.h +10 -8
  207. data/vendor/libgit2/src/stash.c +3 -1
  208. data/vendor/libgit2/src/status.c +7 -4
  209. data/vendor/libgit2/src/strarray.c +2 -1
  210. data/vendor/libgit2/src/streams/mbedtls.c +14 -17
  211. data/vendor/libgit2/src/streams/mbedtls.h +1 -1
  212. data/vendor/libgit2/src/streams/openssl.c +101 -201
  213. data/vendor/libgit2/src/streams/openssl.h +9 -1
  214. data/vendor/libgit2/src/streams/openssl_dynamic.c +309 -0
  215. data/vendor/libgit2/src/streams/openssl_dynamic.h +348 -0
  216. data/vendor/libgit2/src/streams/openssl_legacy.c +203 -0
  217. data/vendor/libgit2/src/streams/openssl_legacy.h +63 -0
  218. data/vendor/libgit2/src/streams/registry.c +5 -6
  219. data/vendor/libgit2/src/streams/socket.c +6 -2
  220. data/vendor/libgit2/src/streams/stransport.c +6 -3
  221. data/vendor/libgit2/src/streams/tls.c +5 -3
  222. data/vendor/libgit2/src/submodule.c +128 -62
  223. data/vendor/libgit2/src/submodule.h +9 -9
  224. data/vendor/libgit2/src/sysdir.c +4 -6
  225. data/vendor/libgit2/src/tag.c +47 -11
  226. data/vendor/libgit2/src/thread.c +140 -0
  227. data/vendor/libgit2/src/thread.h +479 -0
  228. data/vendor/libgit2/src/threadstate.c +83 -0
  229. data/vendor/libgit2/src/threadstate.h +24 -0
  230. data/vendor/libgit2/src/trace.c +2 -2
  231. data/vendor/libgit2/src/trace.h +17 -13
  232. data/vendor/libgit2/src/transaction.c +19 -8
  233. data/vendor/libgit2/src/transport.c +3 -3
  234. data/vendor/libgit2/src/transports/auth.c +1 -1
  235. data/vendor/libgit2/src/transports/auth_negotiate.c +11 -4
  236. data/vendor/libgit2/src/transports/auth_ntlm.c +10 -6
  237. data/vendor/libgit2/src/transports/credential.c +15 -7
  238. data/vendor/libgit2/src/transports/git.c +1 -3
  239. data/vendor/libgit2/src/transports/http.c +19 -17
  240. data/vendor/libgit2/src/transports/http.h +1 -0
  241. data/vendor/libgit2/src/transports/httpclient.c +62 -30
  242. data/vendor/libgit2/src/transports/httpclient.h +1 -1
  243. data/vendor/libgit2/src/transports/local.c +3 -3
  244. data/vendor/libgit2/src/transports/smart.c +12 -7
  245. data/vendor/libgit2/src/transports/smart.h +1 -1
  246. data/vendor/libgit2/src/transports/smart_protocol.c +11 -5
  247. data/vendor/libgit2/src/transports/ssh.c +51 -17
  248. data/vendor/libgit2/src/transports/winhttp.c +138 -81
  249. data/vendor/libgit2/src/tree.c +100 -77
  250. data/vendor/libgit2/src/tree.h +1 -0
  251. data/vendor/libgit2/src/tsort.c +0 -2
  252. data/vendor/libgit2/src/unix/map.c +3 -1
  253. data/vendor/libgit2/src/unix/posix.h +3 -0
  254. data/vendor/libgit2/src/unix/pthread.h +2 -1
  255. data/vendor/libgit2/src/utf8.c +150 -0
  256. data/vendor/libgit2/src/utf8.h +52 -0
  257. data/vendor/libgit2/src/util.c +53 -129
  258. data/vendor/libgit2/src/util.h +33 -39
  259. data/vendor/libgit2/src/vector.c +23 -19
  260. data/vendor/libgit2/src/vector.h +4 -2
  261. data/vendor/libgit2/src/win32/findfile.c +4 -2
  262. data/vendor/libgit2/src/win32/map.c +1 -1
  263. data/vendor/libgit2/src/win32/msvc-compat.h +9 -1
  264. data/vendor/libgit2/src/win32/path_w32.c +22 -24
  265. data/vendor/libgit2/src/win32/path_w32.h +0 -1
  266. data/vendor/libgit2/src/win32/posix_w32.c +77 -1
  267. data/vendor/libgit2/src/win32/precompiled.h +0 -1
  268. data/vendor/libgit2/src/win32/reparse.h +4 -4
  269. data/vendor/libgit2/src/win32/thread.c +24 -15
  270. data/vendor/libgit2/src/win32/thread.h +1 -1
  271. data/vendor/libgit2/src/win32/w32_buffer.c +3 -3
  272. data/vendor/libgit2/src/win32/w32_common.h +18 -9
  273. data/vendor/libgit2/src/win32/{w32_crtdbg_stacktrace.c → w32_leakcheck.c} +269 -33
  274. data/vendor/libgit2/src/win32/w32_leakcheck.h +222 -0
  275. data/vendor/libgit2/src/win32/w32_util.h +6 -6
  276. data/vendor/libgit2/src/worktree.c +32 -14
  277. data/vendor/libgit2/src/zstream.c +1 -1
  278. metadata +32 -16
  279. data/vendor/libgit2/src/allocators/win32_crtdbg.c +0 -118
  280. data/vendor/libgit2/src/buf_text.c +0 -316
  281. data/vendor/libgit2/src/buf_text.h +0 -122
  282. data/vendor/libgit2/src/global.c +0 -363
  283. data/vendor/libgit2/src/global.h +0 -41
  284. data/vendor/libgit2/src/thread-utils.c +0 -58
  285. data/vendor/libgit2/src/thread-utils.h +0 -364
  286. data/vendor/libgit2/src/win32/w32_crtdbg_stacktrace.h +0 -127
  287. data/vendor/libgit2/src/win32/w32_stack.c +0 -188
  288. data/vendor/libgit2/src/win32/w32_stack.h +0 -140
@@ -24,8 +24,6 @@
24
24
  #include "zstream.h"
25
25
  #include "object.h"
26
26
 
27
- extern git_mutex git__mwindow_mutex;
28
-
29
27
  size_t git_indexer__max_objects = UINT32_MAX;
30
28
 
31
29
  #define UINT31_MAX (0x7FFFFFFF)
@@ -239,7 +237,8 @@ static int hash_object_stream(git_indexer*idx, git_packfile_stream *stream)
239
237
  {
240
238
  ssize_t read;
241
239
 
242
- assert(idx && stream);
240
+ GIT_ASSERT_ARG(idx);
241
+ GIT_ASSERT_ARG(stream);
243
242
 
244
243
  do {
245
244
  if ((read = git_packfile_stream_read(stream, idx->objbuf, sizeof(idx->objbuf))) < 0)
@@ -262,7 +261,7 @@ static int advance_delta_offset(git_indexer *idx, git_object_t type)
262
261
  {
263
262
  git_mwindow *w = NULL;
264
263
 
265
- assert(type == GIT_OBJECT_REF_DELTA || type == GIT_OBJECT_OFS_DELTA);
264
+ GIT_ASSERT_ARG(type == GIT_OBJECT_REF_DELTA || type == GIT_OBJECT_OFS_DELTA);
266
265
 
267
266
  if (type == GIT_OBJECT_REF_DELTA) {
268
267
  idx->off += GIT_OID_RAWSZ;
@@ -282,7 +281,7 @@ static int read_object_stream(git_indexer *idx, git_packfile_stream *stream)
282
281
  {
283
282
  ssize_t read;
284
283
 
285
- assert(stream);
284
+ GIT_ASSERT_ARG(stream);
286
285
 
287
286
  do {
288
287
  read = git_packfile_stream_read(stream, idx->objbuf, sizeof(idx->objbuf));
@@ -604,6 +603,23 @@ static void hash_partially(git_indexer *idx, const uint8_t *data, size_t size)
604
603
 
605
604
  static int write_at(git_indexer *idx, const void *data, off64_t offset, size_t size)
606
605
  {
606
+ #ifdef NO_MMAP
607
+ size_t remaining_size = size;
608
+ const char *ptr = (const char *)data;
609
+
610
+ /* Handle data size larger that ssize_t */
611
+ while (remaining_size > 0) {
612
+ ssize_t nb;
613
+ HANDLE_EINTR(nb, p_pwrite(idx->pack->mwf.fd, (void *)ptr,
614
+ remaining_size, offset));
615
+ if (nb <= 0)
616
+ return -1;
617
+
618
+ ptr += nb;
619
+ offset += nb;
620
+ remaining_size -= nb;
621
+ }
622
+ #else
607
623
  git_file fd = idx->pack->mwf.fd;
608
624
  size_t mmap_alignment;
609
625
  size_t page_offset;
@@ -612,7 +628,8 @@ static int write_at(git_indexer *idx, const void *data, off64_t offset, size_t s
612
628
  git_map map;
613
629
  int error;
614
630
 
615
- assert(data && size);
631
+ GIT_ASSERT_ARG(data);
632
+ GIT_ASSERT_ARG(size);
616
633
 
617
634
  if ((error = git__mmap_alignment(&mmap_alignment)) < 0)
618
635
  return error;
@@ -627,6 +644,7 @@ static int write_at(git_indexer *idx, const void *data, off64_t offset, size_t s
627
644
  map_data = (unsigned char *)map.data;
628
645
  memcpy(map_data + page_offset, data, size);
629
646
  p_munmap(&map);
647
+ #endif
630
648
 
631
649
  return 0;
632
650
  }
@@ -638,7 +656,6 @@ static int append_to_pack(git_indexer *idx, const void *data, size_t size)
638
656
  size_t page_offset;
639
657
  off64_t page_start;
640
658
  off64_t current_size = idx->pack->mwf.size;
641
- int fd = idx->pack->mwf.fd;
642
659
  int error;
643
660
 
644
661
  if (!size)
@@ -655,8 +672,7 @@ static int append_to_pack(git_indexer *idx, const void *data, size_t size)
655
672
  page_offset = new_size % mmap_alignment;
656
673
  page_start = new_size - page_offset;
657
674
 
658
- if (p_lseek(fd, page_start + mmap_alignment - 1, SEEK_SET) < 0 ||
659
- p_write(idx->pack->mwf.fd, data, 1) < 0) {
675
+ if (p_pwrite(idx->pack->mwf.fd, data, 1, page_start + mmap_alignment - 1) < 0) {
660
676
  git_error_set(GIT_ERROR_OS, "cannot extend packfile '%s'", idx->pack->pack_name);
661
677
  return -1;
662
678
  }
@@ -677,7 +693,7 @@ static int read_stream_object(git_indexer *idx, git_indexer_progress *stats)
677
693
  return GIT_EBUFS;
678
694
 
679
695
  if (!idx->have_stream) {
680
- error = git_packfile_unpack_header(&entry_size, &type, &idx->pack->mwf, &w, &idx->off);
696
+ error = git_packfile_unpack_header(&entry_size, &type, idx->pack, &w, &idx->off);
681
697
  if (error == GIT_EBUFS) {
682
698
  idx->off = entry_start;
683
699
  return error;
@@ -759,7 +775,9 @@ int git_indexer_append(git_indexer *idx, const void *data, size_t size, git_inde
759
775
  struct git_pack_header *hdr = &idx->hdr;
760
776
  git_mwindow_file *mwf = &idx->pack->mwf;
761
777
 
762
- assert(idx && data && stats);
778
+ GIT_ASSERT_ARG(idx);
779
+ GIT_ASSERT_ARG(data);
780
+ GIT_ASSERT_ARG(stats);
763
781
 
764
782
  if ((error = append_to_pack(idx, data, size)) < 0)
765
783
  return error;
@@ -813,7 +831,8 @@ int git_indexer_append(git_indexer *idx, const void *data, size_t size, git_inde
813
831
  /* Now that we have data in the pack, let's try to parse it */
814
832
 
815
833
  /* As the file grows any windows we try to use will be out of date */
816
- git_mwindow_free_all(mwf);
834
+ if ((error = git_mwindow_free_all(mwf)) < 0)
835
+ goto on_error;
817
836
 
818
837
  while (stats->indexed_objects < idx->nr_objects) {
819
838
  if ((error = read_stream_object(idx, stats)) != 0) {
@@ -857,16 +876,16 @@ static int index_path(git_buf *path, git_indexer *idx, const char *suffix)
857
876
  * Rewind the packfile by the trailer, as we might need to fix the
858
877
  * packfile by injecting objects at the tail and must overwrite it.
859
878
  */
860
- static void seek_back_trailer(git_indexer *idx)
879
+ static int seek_back_trailer(git_indexer *idx)
861
880
  {
862
881
  idx->pack->mwf.size -= GIT_OID_RAWSZ;
863
- git_mwindow_free_all(&idx->pack->mwf);
882
+ return git_mwindow_free_all(&idx->pack->mwf);
864
883
  }
865
884
 
866
885
  static int inject_object(git_indexer *idx, git_oid *id)
867
886
  {
868
- git_odb_object *obj;
869
- struct entry *entry;
887
+ git_odb_object *obj = NULL;
888
+ struct entry *entry = NULL;
870
889
  struct git_pack_entry *pentry = NULL;
871
890
  git_oid foo = {{0}};
872
891
  unsigned char hdr[64];
@@ -876,12 +895,14 @@ static int inject_object(git_indexer *idx, git_oid *id)
876
895
  size_t len, hdr_len;
877
896
  int error;
878
897
 
879
- seek_back_trailer(idx);
898
+ if ((error = seek_back_trailer(idx)) < 0)
899
+ goto cleanup;
900
+
880
901
  entry_start = idx->pack->mwf.size;
881
902
 
882
- if (git_odb_read(&obj, idx->odb, id) < 0) {
903
+ if ((error = git_odb_read(&obj, idx->odb, id)) < 0) {
883
904
  git_error_set(GIT_ERROR_INDEXER, "missing delta bases");
884
- return -1;
905
+ goto cleanup;
885
906
  }
886
907
 
887
908
  data = git_odb_object_data(obj);
@@ -893,8 +914,8 @@ static int inject_object(git_indexer *idx, git_oid *id)
893
914
  entry->crc = crc32(0L, Z_NULL, 0);
894
915
 
895
916
  /* Write out the object header */
896
- hdr_len = git_packfile__object_header(hdr, len, git_odb_object_type(obj));
897
- if ((error = append_to_pack(idx, hdr, hdr_len)) < 0)
917
+ if ((error = git_packfile__object_header(&hdr_len, hdr, len, git_odb_object_type(obj))) < 0 ||
918
+ (error = append_to_pack(idx, hdr, hdr_len)) < 0)
898
919
  goto cleanup;
899
920
 
900
921
  idx->pack->mwf.size += hdr_len;
@@ -950,7 +971,7 @@ static int fix_thin_pack(git_indexer *idx, git_indexer_progress *stats)
950
971
  unsigned int left = 0;
951
972
  git_oid base;
952
973
 
953
- assert(git_vector_length(&idx->deltas) > 0);
974
+ GIT_ASSERT(git_vector_length(&idx->deltas) > 0);
954
975
 
955
976
  if (idx->odb == NULL) {
956
977
  git_error_set(GIT_ERROR_INDEXER, "cannot fix a thin pack without an ODB");
@@ -963,7 +984,7 @@ static int fix_thin_pack(git_indexer *idx, git_indexer_progress *stats)
963
984
  continue;
964
985
 
965
986
  curpos = delta->delta_off;
966
- error = git_packfile_unpack_header(&size, &type, &idx->pack->mwf, &w, &curpos);
987
+ error = git_packfile_unpack_header(&size, &type, idx->pack, &w, &curpos);
967
988
  if (error < 0)
968
989
  return error;
969
990
 
@@ -1081,7 +1102,9 @@ static int update_header_and_rehash(git_indexer *idx, git_indexer_progress *stat
1081
1102
  * hash_partially() keep the existing trailer out of the
1082
1103
  * calculation.
1083
1104
  */
1084
- git_mwindow_free_all(mwf);
1105
+ if (git_mwindow_free_all(mwf) < 0)
1106
+ return -1;
1107
+
1085
1108
  idx->inbuf_len = 0;
1086
1109
  while (hashed < mwf->size) {
1087
1110
  ptr = git_mwindow_open(mwf, &w, hashed, chunk, &left);
@@ -1253,7 +1276,8 @@ int git_indexer_commit(git_indexer *idx, git_indexer_progress *stats)
1253
1276
  if (git_filebuf_commit_at(&index_file, filename.ptr) < 0)
1254
1277
  goto on_error;
1255
1278
 
1256
- git_mwindow_free_all(&idx->pack->mwf);
1279
+ if (git_mwindow_free_all(&idx->pack->mwf) < 0)
1280
+ goto on_error;
1257
1281
 
1258
1282
  /* Truncate file to undo rounding up to next page_size in append_to_pack */
1259
1283
  if (p_ftruncate(idx->pack->mwf.fd, idx->pack->mwf.size) < 0) {
@@ -1323,13 +1347,7 @@ void git_indexer_free(git_indexer *idx)
1323
1347
 
1324
1348
  git_vector_free_deep(&idx->deltas);
1325
1349
 
1326
- if (!git_mutex_lock(&git__mwindow_mutex)) {
1327
- if (!idx->pack_committed)
1328
- git_packfile_close(idx->pack, true);
1329
-
1330
- git_packfile_free(idx->pack);
1331
- git_mutex_unlock(&git__mwindow_mutex);
1332
- }
1350
+ git_packfile_free(idx->pack, !idx->pack_committed);
1333
1351
 
1334
1352
  iter = 0;
1335
1353
  while (git_oidmap_iterate((void **) &value, idx->expected_oids, &iter, &key) == 0)
@@ -43,10 +43,10 @@ GIT_INLINE(int) git__is_ulong(int64_t p)
43
43
  }
44
44
 
45
45
  /** @return true if p fits into the range of an int */
46
- GIT_INLINE(int) git__is_int(long long p)
46
+ GIT_INLINE(int) git__is_int(int64_t p)
47
47
  {
48
48
  int r = (int)p;
49
- return p == (long long)r;
49
+ return p == (int64_t)r;
50
50
  }
51
51
 
52
52
  /* Use clang/gcc compiler intrinsics whenever possible */
@@ -77,6 +77,15 @@ GIT_INLINE(int) git__is_int(long long p)
77
77
  # define git__sub_int_overflow(out, one, two) \
78
78
  __builtin_ssub_overflow(one, two, out)
79
79
 
80
+ # define git__add_int64_overflow(out, one, two) \
81
+ __builtin_add_overflow(one, two, out)
82
+
83
+ /* clang on 32-bit systems produces an undefined reference to `__mulodi4`. */
84
+ # if !defined(__clang__) || !defined(GIT_ARCH_32)
85
+ # define git__multiply_int64_overflow(out, one, two) \
86
+ __builtin_mul_overflow(one, two, out)
87
+ # endif
88
+
80
89
  /* Use Microsoft's safe integer handling functions where available */
81
90
  #elif defined(_MSC_VER)
82
91
 
@@ -87,11 +96,17 @@ GIT_INLINE(int) git__is_int(long long p)
87
96
  (SizeTAdd(one, two, out) != S_OK)
88
97
  # define git__multiply_sizet_overflow(out, one, two) \
89
98
  (SizeTMult(one, two, out) != S_OK)
99
+
90
100
  #define git__add_int_overflow(out, one, two) \
91
101
  (IntAdd(one, two, out) != S_OK)
92
102
  #define git__sub_int_overflow(out, one, two) \
93
103
  (IntSub(one, two, out) != S_OK)
94
104
 
105
+ #define git__add_int64_overflow(out, one, two) \
106
+ (LongLongAdd(one, two, out) != S_OK)
107
+ #define git__multiply_int64_overflow(out, one, two) \
108
+ (LongLongMult(one, two, out) != S_OK)
109
+
95
110
  #else
96
111
 
97
112
  /**
@@ -136,6 +151,68 @@ GIT_INLINE(bool) git__sub_int_overflow(int *out, int one, int two)
136
151
  return false;
137
152
  }
138
153
 
154
+ GIT_INLINE(bool) git__add_int64_overflow(int64_t *out, int64_t one, int64_t two)
155
+ {
156
+ if ((two > 0 && one > (INT64_MAX - two)) ||
157
+ (two < 0 && one < (INT64_MIN - two)))
158
+ return true;
159
+ *out = one + two;
160
+ return false;
161
+ }
162
+
163
+ #endif
164
+
165
+ /* If we could not provide an intrinsic implementation for this, provide a (slow) fallback. */
166
+ #if !defined(git__multiply_int64_overflow)
167
+ GIT_INLINE(bool) git__multiply_int64_overflow(int64_t *out, int64_t one, int64_t two)
168
+ {
169
+ /*
170
+ * Detects whether `INT64_MAX < (one * two) || INT64_MIN > (one * two)`,
171
+ * without incurring in undefined behavior. That is done by performing the
172
+ * comparison with a division instead of a multiplication, which translates
173
+ * to `INT64_MAX / one < two || INT64_MIN / one > two`. Some caveats:
174
+ *
175
+ * - The comparison sign is inverted when both sides of the inequality are
176
+ * multiplied/divided by a negative number, so if `one < 0` the comparison
177
+ * needs to be flipped.
178
+ * - `INT64_MAX / -1` itself overflows (or traps), so that case should be
179
+ * avoided.
180
+ * - Since the overflow flag is defined as the discrepance between the result
181
+ * of performing the multiplication in a signed integer at twice the width
182
+ * of the operands, and the truncated+sign-extended version of that same
183
+ * result, there are four cases where the result is the opposite of what
184
+ * would be expected:
185
+ * * `INT64_MIN * -1` / `-1 * INT64_MIN`
186
+ * * `INT64_MIN * 1 / `1 * INT64_MIN`
187
+ */
188
+ if (one && two) {
189
+ if (one > 0 && two > 0) {
190
+ if (INT64_MAX / one < two)
191
+ return true;
192
+ } else if (one < 0 && two < 0) {
193
+ if ((one == -1 && two == INT64_MIN) ||
194
+ (two == -1 && one == INT64_MIN)) {
195
+ *out = INT64_MIN;
196
+ return false;
197
+ }
198
+ if (INT64_MAX / one > two)
199
+ return true;
200
+ } else if (one > 0 && two < 0) {
201
+ if ((one == 1 && two == INT64_MIN) ||
202
+ (INT64_MIN / one > two))
203
+ return true;
204
+ } else if (one == -1) {
205
+ if (INT64_MIN / two > one)
206
+ return true;
207
+ } else {
208
+ if ((one == INT64_MIN && two == 1) ||
209
+ (INT64_MIN / one < two))
210
+ return true;
211
+ }
212
+ }
213
+ *out = one * two;
214
+ return false;
215
+ }
139
216
  #endif
140
217
 
141
218
  #endif
@@ -330,7 +330,7 @@ static iterator_pathlist_search_t iterator_pathlist_search(
330
330
  break;
331
331
 
332
332
  /* an exact match would have been matched by the bsearch above */
333
- assert(p[path_len]);
333
+ GIT_ASSERT_WITH_RETVAL(p[path_len], ITERATOR_PATHLIST_NONE);
334
334
 
335
335
  /* is this a literal directory entry (eg `foo/`) or a file beneath */
336
336
  if (p[path_len] == '/') {
@@ -678,14 +678,14 @@ done:
678
678
  return error;
679
679
  }
680
680
 
681
- static void tree_iterator_frame_pop(tree_iterator *iter)
681
+ static int tree_iterator_frame_pop(tree_iterator *iter)
682
682
  {
683
683
  tree_iterator_frame *frame;
684
684
  git_buf *buf = NULL;
685
685
  git_tree *tree;
686
686
  size_t i;
687
687
 
688
- assert(iter->frames.size);
688
+ GIT_ASSERT(iter->frames.size);
689
689
 
690
690
  frame = git_array_pop(iter->frames);
691
691
 
@@ -705,6 +705,8 @@ static void tree_iterator_frame_pop(tree_iterator *iter)
705
705
  git_vector_free(&frame->similar_trees);
706
706
 
707
707
  git_buf_dispose(&frame->path);
708
+
709
+ return 0;
708
710
  }
709
711
 
710
712
  static int tree_iterator_current(
@@ -760,7 +762,9 @@ static int tree_iterator_advance(const git_index_entry **out, git_iterator *i)
760
762
 
761
763
  /* no more entries in this frame. pop the frame out */
762
764
  if (frame->next_idx == frame->entries.length) {
763
- tree_iterator_frame_pop(iter);
765
+ if ((error = tree_iterator_frame_pop(iter)) < 0)
766
+ break;
767
+
764
768
  continue;
765
769
  }
766
770
 
@@ -838,7 +842,7 @@ static int tree_iterator_advance_into(
838
842
  const git_index_entry **out, git_iterator *i)
839
843
  {
840
844
  tree_iterator *iter = (tree_iterator *)i;
841
- tree_iterator_frame *frame;
845
+ tree_iterator_frame *frame;
842
846
  tree_iterator_entry *prev_entry;
843
847
  int error;
844
848
 
@@ -855,7 +859,7 @@ static int tree_iterator_advance_into(
855
859
  * we will have pushed a new (empty) frame on to the stack for this
856
860
  * new directory. since it's empty, its current_entry should be null.
857
861
  */
858
- assert(iterator__do_autoexpand(i) ^ (prev_entry != NULL));
862
+ GIT_ASSERT(iterator__do_autoexpand(i) ^ (prev_entry != NULL));
859
863
 
860
864
  if (prev_entry) {
861
865
  if (!git_tree_entry__is_tree(prev_entry->tree_entry))
@@ -973,7 +977,7 @@ int git_iterator_current_tree_entry(
973
977
  tree_iterator_frame *frame;
974
978
  tree_iterator_entry *entry;
975
979
 
976
- assert(i->type == GIT_ITERATOR_TREE);
980
+ GIT_ASSERT(i->type == GIT_ITERATOR_TREE);
977
981
 
978
982
  iter = (tree_iterator *)i;
979
983
 
@@ -990,11 +994,11 @@ int git_iterator_current_parent_tree(
990
994
  tree_iterator *iter;
991
995
  tree_iterator_frame *frame;
992
996
 
993
- assert(i->type == GIT_ITERATOR_TREE);
997
+ GIT_ASSERT(i->type == GIT_ITERATOR_TREE);
994
998
 
995
999
  iter = (tree_iterator *)i;
996
1000
 
997
- assert(depth < iter->frames.size);
1001
+ GIT_ASSERT(depth < iter->frames.size);
998
1002
  frame = &iter->frames.ptr[iter->frames.size-depth-1];
999
1003
 
1000
1004
  *parent_tree = frame->tree;
@@ -1274,7 +1278,8 @@ static int filesystem_iterator_entry_hash(
1274
1278
  return git_repository_hashfile(&entry->id,
1275
1279
  iter->base.repo, entry->path, GIT_OBJECT_BLOB, NULL);
1276
1280
 
1277
- if (!(error = git_buf_joinpath(&fullpath, iter->root, entry->path)))
1281
+ if (!(error = git_buf_joinpath(&fullpath, iter->root, entry->path)) &&
1282
+ !(error = git_path_validate_workdir_buf(iter->base.repo, &fullpath)))
1278
1283
  error = git_odb_hashfile(&entry->id, fullpath.ptr, GIT_OBJECT_BLOB);
1279
1284
 
1280
1285
  git_buf_dispose(&fullpath);
@@ -1355,7 +1360,8 @@ static int filesystem_iterator_frame_push(
1355
1360
  else
1356
1361
  git_buf_puts(&root, iter->root);
1357
1362
 
1358
- if (git_buf_oom(&root)) {
1363
+ if (git_buf_oom(&root) ||
1364
+ git_path_validate_workdir_buf(iter->base.repo, &root) < 0) {
1359
1365
  error = -1;
1360
1366
  goto done;
1361
1367
  }
@@ -1385,10 +1391,11 @@ static int filesystem_iterator_frame_push(
1385
1391
  iterator_pathlist_search_t pathlist_match = ITERATOR_PATHLIST_FULL;
1386
1392
  bool dir_expected = false;
1387
1393
 
1388
- if ((error = git_path_diriter_fullpath(&path, &path_len, &diriter)) < 0)
1394
+ if ((error = git_path_diriter_fullpath(&path, &path_len, &diriter)) < 0 ||
1395
+ (error = git_path_validate_workdir_with_len(iter->base.repo, path, path_len)) < 0)
1389
1396
  goto done;
1390
1397
 
1391
- assert(path_len > iter->root_len);
1398
+ GIT_ASSERT(path_len > iter->root_len);
1392
1399
 
1393
1400
  /* remove the prefix if requested */
1394
1401
  path += iter->root_len;
@@ -1469,17 +1476,19 @@ done:
1469
1476
  return error;
1470
1477
  }
1471
1478
 
1472
- GIT_INLINE(void) filesystem_iterator_frame_pop(filesystem_iterator *iter)
1479
+ GIT_INLINE(int) filesystem_iterator_frame_pop(filesystem_iterator *iter)
1473
1480
  {
1474
1481
  filesystem_iterator_frame *frame;
1475
1482
 
1476
- assert(iter->frames.size);
1483
+ GIT_ASSERT(iter->frames.size);
1477
1484
 
1478
1485
  frame = git_array_pop(iter->frames);
1479
1486
  filesystem_iterator_frame_pop_ignores(iter);
1480
1487
 
1481
1488
  git_pool_clear(&frame->entry_pool);
1482
1489
  git_vector_free(&frame->entries);
1490
+
1491
+ return 0;
1483
1492
  }
1484
1493
 
1485
1494
  static void filesystem_iterator_set_current(
@@ -1556,7 +1565,8 @@ static int filesystem_iterator_is_dir(
1556
1565
  }
1557
1566
 
1558
1567
  if ((error = git_buf_joinpath(&fullpath, iter->root, entry->path)) < 0 ||
1559
- (error = p_stat(fullpath.ptr, &st)) < 0)
1568
+ (error = git_path_validate_workdir_buf(iter->base.repo, &fullpath)) < 0 ||
1569
+ (error = p_stat(fullpath.ptr, &st)) < 0)
1560
1570
  goto done;
1561
1571
 
1562
1572
  *is_dir = S_ISDIR(st.st_mode);
@@ -1646,7 +1656,7 @@ static int filesystem_iterator_advance_into(
1646
1656
  * we will have pushed a new (empty) frame on to the stack for this
1647
1657
  * new directory. since it's empty, its current_entry should be null.
1648
1658
  */
1649
- assert(iterator__do_autoexpand(i) ^ (prev_entry != NULL));
1659
+ GIT_ASSERT(iterator__do_autoexpand(i) ^ (prev_entry != NULL));
1650
1660
 
1651
1661
  if (prev_entry) {
1652
1662
  if (prev_entry->st.st_mode != GIT_FILEMODE_COMMIT &&
@@ -1762,12 +1772,13 @@ static int filesystem_iterator_advance_over(
1762
1772
  *out = NULL;
1763
1773
  *status = GIT_ITERATOR_STATUS_NORMAL;
1764
1774
 
1765
- assert(iterator__has_been_accessed(i));
1775
+ GIT_ASSERT(iterator__has_been_accessed(i));
1766
1776
 
1767
1777
  current_frame = filesystem_iterator_current_frame(iter);
1768
- assert(current_frame);
1778
+ GIT_ASSERT(current_frame);
1779
+
1769
1780
  current_entry = filesystem_iterator_current_entry(current_frame);
1770
- assert(current_entry);
1781
+ GIT_ASSERT(current_entry);
1771
1782
 
1772
1783
  if ((error = git_iterator_current(&entry, i)) < 0)
1773
1784
  return error;
@@ -2065,8 +2076,8 @@ static bool index_iterator_create_pseudotree(
2065
2076
 
2066
2077
  static int index_iterator_skip_pseudotree(index_iterator *iter)
2067
2078
  {
2068
- assert(iterator__has_been_accessed(&iter->base));
2069
- assert(S_ISDIR(iter->entry->mode));
2079
+ GIT_ASSERT(iterator__has_been_accessed(&iter->base));
2080
+ GIT_ASSERT(S_ISDIR(iter->entry->mode));
2070
2081
 
2071
2082
  while (true) {
2072
2083
  const git_index_entry *next_entry = NULL;
@@ -2280,10 +2291,11 @@ int git_iterator_reset_range(
2280
2291
  return i->cb->reset(i);
2281
2292
  }
2282
2293
 
2283
- void git_iterator_set_ignore_case(git_iterator *i, bool ignore_case)
2294
+ int git_iterator_set_ignore_case(git_iterator *i, bool ignore_case)
2284
2295
  {
2285
- assert(!iterator__has_been_accessed(i));
2296
+ GIT_ASSERT(!iterator__has_been_accessed(i));
2286
2297
  iterator_set_ignore_case(i, ignore_case);
2298
+ return 0;
2287
2299
  }
2288
2300
 
2289
2301
  void git_iterator_free(git_iterator *iter)
@@ -263,7 +263,7 @@ GIT_INLINE(bool) git_iterator_ignore_case(git_iterator *iter)
263
263
  return ((iter->flags & GIT_ITERATOR_IGNORE_CASE) != 0);
264
264
  }
265
265
 
266
- extern void git_iterator_set_ignore_case(
266
+ extern int git_iterator_set_ignore_case(
267
267
  git_iterator *iter, bool ignore_case);
268
268
 
269
269
  extern int git_iterator_current_tree_entry(
@@ -131,17 +131,8 @@ int main() {
131
131
 
132
132
  /* compiler specific configuration */
133
133
 
134
- #if UINT_MAX == 0xffffffffu
135
- typedef unsigned int khint32_t;
136
- #elif ULONG_MAX == 0xffffffffu
137
- typedef unsigned long khint32_t;
138
- #endif
139
-
140
- #if ULONG_MAX == ULLONG_MAX
141
- typedef unsigned long khint64_t;
142
- #else
143
- typedef unsigned long long khint64_t;
144
- #endif
134
+ typedef uint32_t khint32_t;
135
+ typedef uint64_t khint64_t;
145
136
 
146
137
  #ifndef kh_inline
147
138
  #ifdef _MSC_VER