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
@@ -36,8 +36,8 @@ int git_pool_global_init(void)
36
36
 
37
37
  int git_pool_init(git_pool *pool, size_t item_size)
38
38
  {
39
- assert(pool);
40
- assert(item_size >= 1);
39
+ GIT_ASSERT_ARG(pool);
40
+ GIT_ASSERT_ARG(item_size >= 1);
41
41
 
42
42
  memset(pool, 0, sizeof(git_pool));
43
43
  pool->item_size = item_size;
@@ -131,8 +131,8 @@ static int git_pool__ptr_cmp(const void * a, const void * b)
131
131
 
132
132
  int git_pool_init(git_pool *pool, size_t item_size)
133
133
  {
134
- assert(pool);
135
- assert(item_size >= 1);
134
+ GIT_ASSERT_ARG(pool);
135
+ GIT_ASSERT_ARG(item_size >= 1);
136
136
 
137
137
  memset(pool, 0, sizeof(git_pool));
138
138
  pool->item_size = item_size;
@@ -205,7 +205,9 @@ char *git_pool_strndup(git_pool *pool, const char *str, size_t n)
205
205
  {
206
206
  char *ptr = NULL;
207
207
 
208
- assert(pool && str && pool->item_size == sizeof(char));
208
+ GIT_ASSERT_ARG_WITH_RETVAL(pool, NULL);
209
+ GIT_ASSERT_ARG_WITH_RETVAL(str, NULL);
210
+ GIT_ASSERT_ARG_WITH_RETVAL(pool->item_size == sizeof(char), NULL);
209
211
 
210
212
  if (n == SIZE_MAX)
211
213
  return NULL;
@@ -220,7 +222,10 @@ char *git_pool_strndup(git_pool *pool, const char *str, size_t n)
220
222
 
221
223
  char *git_pool_strdup(git_pool *pool, const char *str)
222
224
  {
223
- assert(pool && str && pool->item_size == sizeof(char));
225
+ GIT_ASSERT_ARG_WITH_RETVAL(pool, NULL);
226
+ GIT_ASSERT_ARG_WITH_RETVAL(str, NULL);
227
+ GIT_ASSERT_ARG_WITH_RETVAL(pool->item_size == sizeof(char), NULL);
228
+
224
229
  return git_pool_strndup(pool, str, strlen(str));
225
230
  }
226
231
 
@@ -234,7 +239,8 @@ char *git_pool_strcat(git_pool *pool, const char *a, const char *b)
234
239
  void *ptr;
235
240
  size_t len_a, len_b, total;
236
241
 
237
- assert(pool && pool->item_size == sizeof(char));
242
+ GIT_ASSERT_ARG_WITH_RETVAL(pool, NULL);
243
+ GIT_ASSERT_ARG_WITH_RETVAL(pool->item_size == sizeof(char), NULL);
238
244
 
239
245
  len_a = a ? strlen(a) : 0;
240
246
  len_b = b ? strlen(b) : 0;
@@ -109,6 +109,13 @@ int p_open(const char *path, volatile int flags, ...)
109
109
  {
110
110
  mode_t mode = 0;
111
111
 
112
+ #ifdef GIT_DEBUG_STRICT_OPEN
113
+ if (strstr(path, "//") != NULL) {
114
+ errno = EACCES;
115
+ return -1;
116
+ }
117
+ #endif
118
+
112
119
  if (flags & O_CREAT) {
113
120
  va_list arg_list;
114
121
 
@@ -129,7 +136,8 @@ int p_getcwd(char *buffer_out, size_t size)
129
136
  {
130
137
  char *cwd_buffer;
131
138
 
132
- assert(buffer_out && size > 0);
139
+ GIT_ASSERT_ARG(buffer_out);
140
+ GIT_ASSERT_ARG(size > 0);
133
141
 
134
142
  cwd_buffer = getcwd(buffer_out, size);
135
143
 
@@ -196,7 +204,7 @@ int p_write(git_file fd, const void *buf, size_t cnt)
196
204
  while (cnt) {
197
205
  ssize_t r;
198
206
  #ifdef GIT_WIN32
199
- assert((size_t)((unsigned int)cnt) == cnt);
207
+ GIT_ASSERT((size_t)((unsigned int)cnt) == cnt);
200
208
  r = write(fd, b, (unsigned int)cnt);
201
209
  #else
202
210
  r = write(fd, b, cnt);
@@ -237,24 +245,43 @@ int git__mmap_alignment(size_t *alignment)
237
245
 
238
246
  int p_mmap(git_map *out, size_t len, int prot, int flags, int fd, off64_t offset)
239
247
  {
248
+ const char *ptr;
249
+ size_t remaining_len;
250
+
240
251
  GIT_MMAP_VALIDATE(out, len, prot, flags);
241
252
 
242
- out->data = NULL;
243
- out->len = 0;
253
+ /* writes cannot be emulated without handling pagefaults since write happens by
254
+ * writing to mapped memory */
255
+ if (prot & GIT_PROT_WRITE) {
256
+ git_error_set(GIT_ERROR_OS, "trying to map %s-writeable",
257
+ ((flags & GIT_MAP_TYPE) == GIT_MAP_SHARED) ? "shared": "private");
258
+ return -1;
259
+ }
244
260
 
245
- if ((prot & GIT_PROT_WRITE) && ((flags & GIT_MAP_TYPE) == GIT_MAP_SHARED)) {
246
- git_error_set(GIT_ERROR_OS, "trying to map shared-writeable");
261
+ if (!git__is_ssizet(len)) {
262
+ errno = EINVAL;
247
263
  return -1;
248
264
  }
249
265
 
266
+ out->len = 0;
250
267
  out->data = git__malloc(len);
251
268
  GIT_ERROR_CHECK_ALLOC(out->data);
252
269
 
253
- if (!git__is_ssizet(len) ||
254
- (p_lseek(fd, offset, SEEK_SET) < 0) ||
255
- (p_read(fd, out->data, len) != (ssize_t)len)) {
256
- git_error_set(GIT_ERROR_OS, "mmap emulation failed");
257
- return -1;
270
+ remaining_len = len;
271
+ ptr = (const char *)out->data;
272
+ while (remaining_len > 0) {
273
+ ssize_t nb;
274
+ HANDLE_EINTR(nb, p_pread(fd, (void *)ptr, remaining_len, offset));
275
+ if (nb <= 0) {
276
+ git_error_set(GIT_ERROR_OS, "mmap emulation failed");
277
+ git__free(out->data);
278
+ out->data = NULL;
279
+ return -1;
280
+ }
281
+
282
+ ptr += nb;
283
+ offset += nb;
284
+ remaining_len -= nb;
258
285
  }
259
286
 
260
287
  out->len = len;
@@ -263,9 +290,13 @@ int p_mmap(git_map *out, size_t len, int prot, int flags, int fd, off64_t offset
263
290
 
264
291
  int p_munmap(git_map *map)
265
292
  {
266
- assert(map != NULL);
293
+ GIT_ASSERT_ARG(map);
267
294
  git__free(map->data);
268
295
 
296
+ /* Initializing will help debug use-after-free */
297
+ map->len = 0;
298
+ map->data = NULL;
299
+
269
300
  return 0;
270
301
  }
271
302
 
@@ -89,6 +89,12 @@
89
89
  #define EAFNOSUPPORT (INT_MAX-1)
90
90
  #endif
91
91
 
92
+ /* Compiler independent macro to handle signal interrpted system calls */
93
+ #define HANDLE_EINTR(result, x) do { \
94
+ result = (x); \
95
+ } while (result == -1 && errno == EINTR);
96
+
97
+
92
98
  /* Provide a 64-bit size for offsets. */
93
99
 
94
100
  #if defined(_MSC_VER)
@@ -119,6 +125,9 @@ typedef int git_file;
119
125
  extern ssize_t p_read(git_file fd, void *buf, size_t cnt);
120
126
  extern int p_write(git_file fd, const void *buf, size_t cnt);
121
127
 
128
+ extern ssize_t p_pread(int fd, void *data, size_t size, off64_t offset);
129
+ extern ssize_t p_pwrite(int fd, const void *data, size_t size, off64_t offset);
130
+
122
131
  #define p_close(fd) close(fd)
123
132
  #define p_umask(m) umask(m)
124
133
 
@@ -61,7 +61,8 @@ int git_reader_for_tree(git_reader **out, git_tree *tree)
61
61
  {
62
62
  tree_reader *reader;
63
63
 
64
- assert(out && tree);
64
+ GIT_ASSERT_ARG(out);
65
+ GIT_ASSERT_ARG(tree);
65
66
 
66
67
  reader = git__calloc(1, sizeof(tree_reader));
67
68
  GIT_ERROR_CHECK_ALLOC(reader);
@@ -97,8 +98,7 @@ static int workdir_reader_read(
97
98
  git_oid id;
98
99
  int error;
99
100
 
100
- if ((error = git_buf_joinpath(&path,
101
- git_repository_workdir(reader->repo), filename)) < 0)
101
+ if ((error = git_repository_workdir_path(&path, reader->repo, filename)) < 0)
102
102
  goto done;
103
103
 
104
104
  if ((error = p_lstat(path.ptr, &st)) < 0) {
@@ -158,7 +158,8 @@ int git_reader_for_workdir(
158
158
  workdir_reader *reader;
159
159
  int error;
160
160
 
161
- assert(out && repo);
161
+ GIT_ASSERT_ARG(out);
162
+ GIT_ASSERT_ARG(repo);
162
163
 
163
164
  reader = git__calloc(1, sizeof(workdir_reader));
164
165
  GIT_ERROR_CHECK_ALLOC(reader);
@@ -223,7 +224,8 @@ int git_reader_for_index(
223
224
  index_reader *reader;
224
225
  int error;
225
226
 
226
- assert(out && repo);
227
+ GIT_ASSERT_ARG(out);
228
+ GIT_ASSERT_ARG(repo);
227
229
 
228
230
  reader = git__calloc(1, sizeof(index_reader));
229
231
  GIT_ERROR_CHECK_ALLOC(reader);
@@ -251,7 +253,9 @@ int git_reader_read(
251
253
  git_reader *reader,
252
254
  const char *filename)
253
255
  {
254
- assert(out && reader && filename);
256
+ GIT_ASSERT_ARG(out);
257
+ GIT_ASSERT_ARG(reader);
258
+ GIT_ASSERT_ARG(filename);
255
259
 
256
260
  return reader->read(out, out_id, out_filemode, reader, filename);
257
261
  }
@@ -186,8 +186,8 @@ static git_rebase_operation *rebase_operation_alloc(
186
186
  {
187
187
  git_rebase_operation *operation;
188
188
 
189
- assert((type == GIT_REBASE_OPERATION_EXEC) == !id);
190
- assert((type == GIT_REBASE_OPERATION_EXEC) == !!exec);
189
+ GIT_ASSERT_WITH_RETVAL((type == GIT_REBASE_OPERATION_EXEC) == !id, NULL);
190
+ GIT_ASSERT_WITH_RETVAL((type == GIT_REBASE_OPERATION_EXEC) == !!exec, NULL);
191
191
 
192
192
  if ((operation = git_array_alloc(rebase->operations)) == NULL)
193
193
  return NULL;
@@ -301,7 +301,7 @@ int git_rebase_open(
301
301
  size_t state_path_len;
302
302
  int error;
303
303
 
304
- assert(repo);
304
+ GIT_ASSERT_ARG(repo);
305
305
 
306
306
  if ((error = rebase_check_versions(given_opts)) < 0)
307
307
  return error;
@@ -701,7 +701,8 @@ int git_rebase_init(
701
701
  bool inmemory = (given_opts && given_opts->inmemory);
702
702
  int error;
703
703
 
704
- assert(repo && (upstream || onto));
704
+ GIT_ASSERT_ARG(repo);
705
+ GIT_ASSERT_ARG(upstream || onto);
705
706
 
706
707
  *out = NULL;
707
708
 
@@ -912,7 +913,8 @@ int git_rebase_next(
912
913
  {
913
914
  int error;
914
915
 
915
- assert(out && rebase);
916
+ GIT_ASSERT_ARG(out);
917
+ GIT_ASSERT_ARG(rebase);
916
918
 
917
919
  if ((error = rebase_movenext(rebase)) < 0)
918
920
  return error;
@@ -931,7 +933,9 @@ int git_rebase_inmemory_index(
931
933
  git_index **out,
932
934
  git_rebase *rebase)
933
935
  {
934
- assert(out && rebase && rebase->index);
936
+ GIT_ASSERT_ARG(out);
937
+ GIT_ASSERT_ARG(rebase);
938
+ GIT_ASSERT_ARG(rebase->index);
935
939
 
936
940
  GIT_REFCOUNT_INC(rebase->index);
937
941
  *out = rebase->index;
@@ -939,6 +943,54 @@ int git_rebase_inmemory_index(
939
943
  return 0;
940
944
  }
941
945
 
946
+ #ifndef GIT_DEPRECATE_HARD
947
+ static int create_signed(
948
+ git_oid *out,
949
+ git_rebase *rebase,
950
+ const git_signature *author,
951
+ const git_signature *committer,
952
+ const char *message_encoding,
953
+ const char *message,
954
+ git_tree *tree,
955
+ size_t parent_count,
956
+ const git_commit **parents)
957
+ {
958
+ git_buf commit_content = GIT_BUF_INIT,
959
+ commit_signature = GIT_BUF_INIT,
960
+ signature_field = GIT_BUF_INIT;
961
+ int error;
962
+
963
+ git_error_clear();
964
+
965
+ if ((error = git_commit_create_buffer(&commit_content,
966
+ rebase->repo, author, committer, message_encoding,
967
+ message, tree, parent_count, parents)) < 0)
968
+ goto done;
969
+
970
+ error = rebase->options.signing_cb(&commit_signature,
971
+ &signature_field, commit_content.ptr,
972
+ rebase->options.payload);
973
+
974
+ if (error) {
975
+ if (error != GIT_PASSTHROUGH)
976
+ git_error_set_after_callback_function(error, "signing_cb");
977
+
978
+ goto done;
979
+ }
980
+
981
+ error = git_commit_create_with_signature(out, rebase->repo,
982
+ commit_content.ptr,
983
+ commit_signature.size > 0 ? commit_signature.ptr : NULL,
984
+ signature_field.size > 0 ? signature_field.ptr : NULL);
985
+
986
+ done:
987
+ git_buf_dispose(&commit_signature);
988
+ git_buf_dispose(&signature_field);
989
+ git_buf_dispose(&commit_content);
990
+ return error;
991
+ }
992
+ #endif
993
+
942
994
  static int rebase_commit__create(
943
995
  git_commit **out,
944
996
  git_rebase *rebase,
@@ -953,10 +1005,6 @@ static int rebase_commit__create(
953
1005
  git_commit *current_commit = NULL, *commit = NULL;
954
1006
  git_tree *parent_tree = NULL, *tree = NULL;
955
1007
  git_oid tree_id, commit_id;
956
- git_buf commit_content = GIT_BUF_INIT, commit_signature = GIT_BUF_INIT,
957
- signature_field = GIT_BUF_INIT;
958
- const char *signature_field_string = NULL,
959
- *commit_signature_string = NULL;
960
1008
  int error;
961
1009
 
962
1010
  operation = git_array_get(rebase->operations, rebase->current);
@@ -987,37 +1035,32 @@ static int rebase_commit__create(
987
1035
  message = git_commit_message(current_commit);
988
1036
  }
989
1037
 
990
- if ((error = git_commit_create_buffer(&commit_content, rebase->repo, author, committer,
991
- message_encoding, message, tree, 1, (const git_commit **)&parent_commit)) < 0)
992
- goto done;
1038
+ git_error_clear();
1039
+ error = GIT_PASSTHROUGH;
993
1040
 
994
- if (rebase->options.signing_cb) {
995
- git_error_clear();
996
- error = git_error_set_after_callback_function(rebase->options.signing_cb(
997
- &commit_signature, &signature_field, git_buf_cstr(&commit_content),
998
- rebase->options.payload), "commit signing_cb failed");
999
- if (error == GIT_PASSTHROUGH) {
1000
- git_buf_dispose(&commit_signature);
1001
- git_buf_dispose(&signature_field);
1002
- git_error_clear();
1003
- error = GIT_OK;
1004
- } else if (error < 0)
1005
- goto done;
1006
- }
1041
+ if (rebase->options.commit_create_cb) {
1042
+ error = rebase->options.commit_create_cb(&commit_id,
1043
+ author, committer, message_encoding, message,
1044
+ tree, 1, (const git_commit **)&parent_commit,
1045
+ rebase->options.payload);
1007
1046
 
1008
- if (git_buf_is_allocated(&commit_signature)) {
1009
- assert(git_buf_contains_nul(&commit_signature));
1010
- commit_signature_string = git_buf_cstr(&commit_signature);
1047
+ git_error_set_after_callback_function(error,
1048
+ "commit_create_cb");
1011
1049
  }
1012
-
1013
- if (git_buf_is_allocated(&signature_field)) {
1014
- assert(git_buf_contains_nul(&signature_field));
1015
- signature_field_string = git_buf_cstr(&signature_field);
1050
+ #ifndef GIT_DEPRECATE_HARD
1051
+ else if (rebase->options.signing_cb) {
1052
+ error = create_signed(&commit_id, rebase, author,
1053
+ committer, message_encoding, message, tree,
1054
+ 1, (const git_commit **)&parent_commit);
1016
1055
  }
1056
+ #endif
1017
1057
 
1018
- if ((error = git_commit_create_with_signature(&commit_id, rebase->repo,
1019
- git_buf_cstr(&commit_content), commit_signature_string,
1020
- signature_field_string)))
1058
+ if (error == GIT_PASSTHROUGH)
1059
+ error = git_commit_create(&commit_id, rebase->repo, NULL,
1060
+ author, committer, message_encoding, message,
1061
+ tree, 1, (const git_commit **)&parent_commit);
1062
+
1063
+ if (error)
1021
1064
  goto done;
1022
1065
 
1023
1066
  if ((error = git_commit_lookup(&commit, rebase->repo, &commit_id)) < 0)
@@ -1029,9 +1072,6 @@ done:
1029
1072
  if (error < 0)
1030
1073
  git_commit_free(commit);
1031
1074
 
1032
- git_buf_dispose(&commit_signature);
1033
- git_buf_dispose(&signature_field);
1034
- git_buf_dispose(&commit_content);
1035
1075
  git_commit_free(current_commit);
1036
1076
  git_tree_free(parent_tree);
1037
1077
  git_tree_free(tree);
@@ -1055,7 +1095,7 @@ static int rebase_commit_merge(
1055
1095
  int error;
1056
1096
 
1057
1097
  operation = git_array_get(rebase->operations, rebase->current);
1058
- assert(operation);
1098
+ GIT_ASSERT(operation);
1059
1099
 
1060
1100
  if ((error = rebase_ensure_not_dirty(rebase->repo, false, true, GIT_EUNMERGED)) < 0 ||
1061
1101
  (error = git_repository_head(&head, rebase->repo)) < 0 ||
@@ -1095,9 +1135,9 @@ static int rebase_commit_inmemory(
1095
1135
  git_commit *commit = NULL;
1096
1136
  int error = 0;
1097
1137
 
1098
- assert(rebase->index);
1099
- assert(rebase->last_commit);
1100
- assert(rebase->current < rebase->operations.size);
1138
+ GIT_ASSERT_ARG(rebase->index);
1139
+ GIT_ASSERT_ARG(rebase->last_commit);
1140
+ GIT_ASSERT_ARG(rebase->current < rebase->operations.size);
1101
1141
 
1102
1142
  if ((error = rebase_commit__create(&commit, rebase, rebase->index,
1103
1143
  rebase->last_commit, author, committer, message_encoding, message)) < 0)
@@ -1125,7 +1165,8 @@ int git_rebase_commit(
1125
1165
  {
1126
1166
  int error;
1127
1167
 
1128
- assert(rebase && committer);
1168
+ GIT_ASSERT_ARG(rebase);
1169
+ GIT_ASSERT_ARG(committer);
1129
1170
 
1130
1171
  if (rebase->inmemory)
1131
1172
  error = rebase_commit_inmemory(
@@ -1145,7 +1186,7 @@ int git_rebase_abort(git_rebase *rebase)
1145
1186
  git_commit *orig_head_commit = NULL;
1146
1187
  int error;
1147
1188
 
1148
- assert(rebase);
1189
+ GIT_ASSERT_ARG(rebase);
1149
1190
 
1150
1191
  if (rebase->inmemory)
1151
1192
  return 0;
@@ -1358,7 +1399,7 @@ int git_rebase_finish(
1358
1399
  {
1359
1400
  int error = 0;
1360
1401
 
1361
- assert(rebase);
1402
+ GIT_ASSERT_ARG(rebase);
1362
1403
 
1363
1404
  if (rebase->inmemory)
1364
1405
  return 0;
@@ -1373,14 +1414,17 @@ int git_rebase_finish(
1373
1414
  }
1374
1415
 
1375
1416
  const char *git_rebase_orig_head_name(git_rebase *rebase) {
1417
+ GIT_ASSERT_ARG_WITH_RETVAL(rebase, NULL);
1376
1418
  return rebase->orig_head_name;
1377
1419
  }
1378
1420
 
1379
1421
  const git_oid *git_rebase_orig_head_id(git_rebase *rebase) {
1422
+ GIT_ASSERT_ARG_WITH_RETVAL(rebase, NULL);
1380
1423
  return &rebase->orig_head_id;
1381
1424
  }
1382
1425
 
1383
1426
  const char *git_rebase_onto_name(git_rebase *rebase) {
1427
+ GIT_ASSERT_ARG_WITH_RETVAL(rebase, NULL);
1384
1428
  return rebase->onto_name;
1385
1429
  }
1386
1430
 
@@ -1390,21 +1434,21 @@ const git_oid *git_rebase_onto_id(git_rebase *rebase) {
1390
1434
 
1391
1435
  size_t git_rebase_operation_entrycount(git_rebase *rebase)
1392
1436
  {
1393
- assert(rebase);
1437
+ GIT_ASSERT_ARG_WITH_RETVAL(rebase, 0);
1394
1438
 
1395
1439
  return git_array_size(rebase->operations);
1396
1440
  }
1397
1441
 
1398
1442
  size_t git_rebase_operation_current(git_rebase *rebase)
1399
1443
  {
1400
- assert(rebase);
1444
+ GIT_ASSERT_ARG_WITH_RETVAL(rebase, 0);
1401
1445
 
1402
1446
  return rebase->started ? rebase->current : GIT_REBASE_NO_OPERATION;
1403
1447
  }
1404
1448
 
1405
1449
  git_rebase_operation *git_rebase_operation_byindex(git_rebase *rebase, size_t idx)
1406
1450
  {
1407
- assert(rebase);
1451
+ GIT_ASSERT_ARG_WITH_RETVAL(rebase, NULL);
1408
1452
 
1409
1453
  return git_array_get(rebase->operations, idx);
1410
1454
  }
@@ -24,7 +24,8 @@ int git_refdb_new(git_refdb **out, git_repository *repo)
24
24
  {
25
25
  git_refdb *db;
26
26
 
27
- assert(out && repo);
27
+ GIT_ASSERT_ARG(out);
28
+ GIT_ASSERT_ARG(repo);
28
29
 
29
30
  db = git__calloc(1, sizeof(*db));
30
31
  GIT_ERROR_CHECK_ALLOC(db);
@@ -41,7 +42,8 @@ int git_refdb_open(git_refdb **out, git_repository *repo)
41
42
  git_refdb *db;
42
43
  git_refdb_backend *dir;
43
44
 
44
- assert(out && repo);
45
+ GIT_ASSERT_ARG(out);
46
+ GIT_ASSERT_ARG(repo);
45
47
 
46
48
  *out = NULL;
47
49
 
@@ -89,7 +91,7 @@ int git_refdb_set_backend(git_refdb *db, git_refdb_backend *backend)
89
91
 
90
92
  int git_refdb_compress(git_refdb *db)
91
93
  {
92
- assert(db);
94
+ GIT_ASSERT_ARG(db);
93
95
 
94
96
  if (db->backend->compress)
95
97
  return db->backend->compress(db->backend);
@@ -114,7 +116,9 @@ void git_refdb_free(git_refdb *db)
114
116
 
115
117
  int git_refdb_exists(int *exists, git_refdb *refdb, const char *ref_name)
116
118
  {
117
- assert(exists && refdb && refdb->backend);
119
+ GIT_ASSERT_ARG(exists);
120
+ GIT_ASSERT_ARG(refdb);
121
+ GIT_ASSERT_ARG(refdb->backend);
118
122
 
119
123
  return refdb->backend->exists(exists, refdb->backend, ref_name);
120
124
  }
@@ -124,7 +128,10 @@ int git_refdb_lookup(git_reference **out, git_refdb *db, const char *ref_name)
124
128
  git_reference *ref;
125
129
  int error;
126
130
 
127
- assert(db && db->backend && out && ref_name);
131
+ GIT_ASSERT_ARG(db);
132
+ GIT_ASSERT_ARG(db->backend);
133
+ GIT_ASSERT_ARG(out);
134
+ GIT_ASSERT_ARG(ref_name);
128
135
 
129
136
  error = db->backend->lookup(&ref, db->backend, ref_name);
130
137
  if (error < 0)
@@ -234,7 +241,8 @@ void git_refdb_iterator_free(git_reference_iterator *iter)
234
241
 
235
242
  int git_refdb_write(git_refdb *db, git_reference *ref, int force, const git_signature *who, const char *message, const git_oid *old_id, const char *old_target)
236
243
  {
237
- assert(db && db->backend);
244
+ GIT_ASSERT_ARG(db);
245
+ GIT_ASSERT_ARG(db->backend);
238
246
 
239
247
  GIT_REFCOUNT_INC(db);
240
248
  ref->db = db;
@@ -253,7 +261,9 @@ int git_refdb_rename(
253
261
  {
254
262
  int error;
255
263
 
256
- assert(db && db->backend);
264
+ GIT_ASSERT_ARG(db);
265
+ GIT_ASSERT_ARG(db->backend);
266
+
257
267
  error = db->backend->rename(out, db->backend, old_name, new_name, force, who, message);
258
268
  if (error < 0)
259
269
  return error;
@@ -268,7 +278,9 @@ int git_refdb_rename(
268
278
 
269
279
  int git_refdb_delete(struct git_refdb *db, const char *ref_name, const git_oid *old_id, const char *old_target)
270
280
  {
271
- assert(db && db->backend);
281
+ GIT_ASSERT_ARG(db);
282
+ GIT_ASSERT_ARG(db->backend);
283
+
272
284
  return db->backend->del(db->backend, ref_name, old_id, old_target);
273
285
  }
274
286
 
@@ -276,7 +288,8 @@ int git_refdb_reflog_read(git_reflog **out, git_refdb *db, const char *name)
276
288
  {
277
289
  int error;
278
290
 
279
- assert(db && db->backend);
291
+ GIT_ASSERT_ARG(db);
292
+ GIT_ASSERT_ARG(db->backend);
280
293
 
281
294
  if ((error = db->backend->reflog_read(out, db->backend, name)) < 0)
282
295
  return error;
@@ -368,14 +381,16 @@ out:
368
381
 
369
382
  int git_refdb_has_log(git_refdb *db, const char *refname)
370
383
  {
371
- assert(db && refname);
384
+ GIT_ASSERT_ARG(db);
385
+ GIT_ASSERT_ARG(refname);
372
386
 
373
387
  return db->backend->has_log(db->backend, refname);
374
388
  }
375
389
 
376
390
  int git_refdb_ensure_log(git_refdb *db, const char *refname)
377
391
  {
378
- assert(db && refname);
392
+ GIT_ASSERT_ARG(db);
393
+ GIT_ASSERT_ARG(refname);
379
394
 
380
395
  return db->backend->ensure_log(db->backend, refname);
381
396
  }
@@ -389,7 +404,9 @@ int git_refdb_init_backend(git_refdb_backend *backend, unsigned int version)
389
404
 
390
405
  int git_refdb_lock(void **payload, git_refdb *db, const char *refname)
391
406
  {
392
- assert(payload && db && refname);
407
+ GIT_ASSERT_ARG(payload);
408
+ GIT_ASSERT_ARG(db);
409
+ GIT_ASSERT_ARG(refname);
393
410
 
394
411
  if (!db->backend->lock) {
395
412
  git_error_set(GIT_ERROR_REFERENCE, "backend does not support locking");
@@ -401,7 +418,7 @@ int git_refdb_lock(void **payload, git_refdb *db, const char *refname)
401
418
 
402
419
  int git_refdb_unlock(git_refdb *db, void *payload, int success, int update_reflog, const git_reference *ref, const git_signature *sig, const char *message)
403
420
  {
404
- assert(db);
421
+ GIT_ASSERT_ARG(db);
405
422
 
406
423
  return db->backend->unlock(db->backend, payload, success, update_reflog, ref, sig, message);
407
424
  }