rugged 0.27.10.1 → 0.28.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (297) hide show
  1. checksums.yaml +4 -4
  2. data/ext/rugged/extconf.rb +23 -2
  3. data/ext/rugged/rugged.c +48 -2
  4. data/ext/rugged/rugged.h +5 -0
  5. data/ext/rugged/rugged_allocator.c +89 -0
  6. data/ext/rugged/rugged_blob.c +3 -3
  7. data/ext/rugged/rugged_branch.c +1 -1
  8. data/ext/rugged/rugged_commit.c +8 -8
  9. data/ext/rugged/rugged_config.c +1 -1
  10. data/ext/rugged/rugged_diff.c +24 -4
  11. data/ext/rugged/rugged_note.c +1 -1
  12. data/ext/rugged/rugged_repo.c +10 -10
  13. data/ext/rugged/rugged_settings.c +1 -1
  14. data/lib/rugged/version.rb +1 -1
  15. data/vendor/libgit2/CMakeLists.txt +69 -47
  16. data/vendor/libgit2/cmake/Modules/AddCFlagIfSupported.cmake +15 -1
  17. data/vendor/libgit2/cmake/Modules/EnableWarnings.cmake +5 -8
  18. data/vendor/libgit2/cmake/Modules/FindmbedTLS.cmake +93 -0
  19. data/vendor/libgit2/deps/http-parser/CMakeLists.txt +2 -0
  20. data/vendor/libgit2/deps/http-parser/{LICENSE-MIT → COPYING} +0 -0
  21. data/vendor/libgit2/deps/regex/COPYING +502 -0
  22. data/vendor/libgit2/deps/winhttp/COPYING.GPL +993 -0
  23. data/vendor/libgit2/deps/winhttp/COPYING.LGPL +502 -0
  24. data/vendor/libgit2/deps/zlib/CMakeLists.txt +1 -0
  25. data/vendor/libgit2/deps/zlib/COPYING +27 -0
  26. data/vendor/libgit2/include/git2.h +3 -0
  27. data/vendor/libgit2/include/git2/annotated_commit.h +9 -0
  28. data/vendor/libgit2/include/git2/apply.h +129 -0
  29. data/vendor/libgit2/include/git2/attr.h +19 -8
  30. data/vendor/libgit2/include/git2/blame.h +41 -24
  31. data/vendor/libgit2/include/git2/blob.h +1 -1
  32. data/vendor/libgit2/include/git2/branch.h +1 -1
  33. data/vendor/libgit2/include/git2/buffer.h +2 -2
  34. data/vendor/libgit2/include/git2/checkout.h +20 -19
  35. data/vendor/libgit2/include/git2/cherrypick.h +6 -4
  36. data/vendor/libgit2/include/git2/clone.h +11 -9
  37. data/vendor/libgit2/include/git2/commit.h +30 -2
  38. data/vendor/libgit2/include/git2/common.h +54 -4
  39. data/vendor/libgit2/include/git2/config.h +18 -7
  40. data/vendor/libgit2/include/git2/deprecated.h +253 -0
  41. data/vendor/libgit2/include/git2/describe.h +30 -7
  42. data/vendor/libgit2/include/git2/diff.h +193 -143
  43. data/vendor/libgit2/include/git2/errors.h +54 -46
  44. data/vendor/libgit2/include/git2/ignore.h +2 -2
  45. data/vendor/libgit2/include/git2/index.h +72 -51
  46. data/vendor/libgit2/include/git2/indexer.h +30 -4
  47. data/vendor/libgit2/include/git2/mailmap.h +115 -0
  48. data/vendor/libgit2/include/git2/merge.h +29 -8
  49. data/vendor/libgit2/include/git2/net.h +1 -1
  50. data/vendor/libgit2/include/git2/notes.h +1 -1
  51. data/vendor/libgit2/include/git2/object.h +16 -16
  52. data/vendor/libgit2/include/git2/odb.h +10 -10
  53. data/vendor/libgit2/include/git2/odb_backend.h +7 -7
  54. data/vendor/libgit2/include/git2/oid.h +1 -1
  55. data/vendor/libgit2/include/git2/pack.h +2 -2
  56. data/vendor/libgit2/include/git2/proxy.h +9 -5
  57. data/vendor/libgit2/include/git2/rebase.h +7 -4
  58. data/vendor/libgit2/include/git2/refs.h +14 -15
  59. data/vendor/libgit2/include/git2/refspec.h +17 -0
  60. data/vendor/libgit2/include/git2/remote.h +92 -16
  61. data/vendor/libgit2/include/git2/repository.h +52 -37
  62. data/vendor/libgit2/include/git2/revert.h +5 -3
  63. data/vendor/libgit2/include/git2/revwalk.h +7 -7
  64. data/vendor/libgit2/include/git2/signature.h +2 -2
  65. data/vendor/libgit2/include/git2/stash.h +13 -10
  66. data/vendor/libgit2/include/git2/status.h +8 -4
  67. data/vendor/libgit2/include/git2/submodule.h +11 -10
  68. data/vendor/libgit2/include/git2/sys/alloc.h +101 -0
  69. data/vendor/libgit2/include/git2/sys/commit.h +1 -1
  70. data/vendor/libgit2/include/git2/sys/config.h +13 -13
  71. data/vendor/libgit2/include/git2/sys/filter.h +6 -6
  72. data/vendor/libgit2/include/git2/sys/index.h +3 -0
  73. data/vendor/libgit2/include/git2/sys/mempack.h +35 -35
  74. data/vendor/libgit2/include/git2/sys/merge.h +9 -4
  75. data/vendor/libgit2/include/git2/sys/odb_backend.h +19 -19
  76. data/vendor/libgit2/include/git2/sys/path.h +64 -0
  77. data/vendor/libgit2/include/git2/sys/refdb_backend.h +19 -19
  78. data/vendor/libgit2/include/git2/sys/stream.h +92 -12
  79. data/vendor/libgit2/include/git2/sys/transport.h +127 -81
  80. data/vendor/libgit2/include/git2/tag.h +2 -2
  81. data/vendor/libgit2/include/git2/trace.h +1 -1
  82. data/vendor/libgit2/include/git2/transaction.h +1 -0
  83. data/vendor/libgit2/include/git2/transport.h +47 -18
  84. data/vendor/libgit2/include/git2/tree.h +3 -3
  85. data/vendor/libgit2/include/git2/types.h +35 -28
  86. data/vendor/libgit2/include/git2/version.h +4 -4
  87. data/vendor/libgit2/include/git2/worktree.h +47 -12
  88. data/vendor/libgit2/src/CMakeLists.txt +87 -26
  89. data/vendor/libgit2/src/alloc.c +55 -0
  90. data/vendor/libgit2/src/alloc.h +40 -0
  91. data/vendor/libgit2/src/annotated_commit.c +15 -8
  92. data/vendor/libgit2/src/apply.c +490 -14
  93. data/vendor/libgit2/src/apply.h +3 -1
  94. data/vendor/libgit2/src/array.h +2 -2
  95. data/vendor/libgit2/src/attr.c +11 -11
  96. data/vendor/libgit2/src/attr_file.c +20 -15
  97. data/vendor/libgit2/src/attrcache.c +11 -11
  98. data/vendor/libgit2/src/blame.c +30 -15
  99. data/vendor/libgit2/src/blame.h +1 -0
  100. data/vendor/libgit2/src/blame_git.c +16 -13
  101. data/vendor/libgit2/src/blob.c +50 -28
  102. data/vendor/libgit2/src/blob.h +18 -1
  103. data/vendor/libgit2/src/branch.c +38 -38
  104. data/vendor/libgit2/src/buf_text.c +7 -6
  105. data/vendor/libgit2/src/buffer.c +55 -50
  106. data/vendor/libgit2/src/buffer.h +1 -1
  107. data/vendor/libgit2/src/cache.c +16 -16
  108. data/vendor/libgit2/src/cache.h +2 -2
  109. data/vendor/libgit2/src/cc-compat.h +15 -3
  110. data/vendor/libgit2/src/checkout.c +83 -74
  111. data/vendor/libgit2/src/cherrypick.c +6 -6
  112. data/vendor/libgit2/src/clone.c +20 -20
  113. data/vendor/libgit2/src/commit.c +53 -33
  114. data/vendor/libgit2/src/commit.h +1 -0
  115. data/vendor/libgit2/src/commit_list.c +6 -10
  116. data/vendor/libgit2/src/common.h +32 -30
  117. data/vendor/libgit2/src/config.c +167 -147
  118. data/vendor/libgit2/src/config.h +1 -14
  119. data/vendor/libgit2/src/config_backend.h +84 -0
  120. data/vendor/libgit2/src/config_cache.c +7 -1
  121. data/vendor/libgit2/src/config_entries.c +259 -0
  122. data/vendor/libgit2/src/config_entries.h +23 -0
  123. data/vendor/libgit2/src/config_file.c +167 -439
  124. data/vendor/libgit2/src/config_mem.c +224 -0
  125. data/vendor/libgit2/src/config_parse.c +69 -38
  126. data/vendor/libgit2/src/config_parse.h +4 -4
  127. data/vendor/libgit2/src/crlf.c +215 -186
  128. data/vendor/libgit2/src/delta.c +25 -18
  129. data/vendor/libgit2/src/describe.c +23 -23
  130. data/vendor/libgit2/src/diff.c +12 -12
  131. data/vendor/libgit2/src/diff_driver.c +14 -15
  132. data/vendor/libgit2/src/diff_file.c +10 -10
  133. data/vendor/libgit2/src/diff_generate.c +29 -23
  134. data/vendor/libgit2/src/diff_generate.h +1 -1
  135. data/vendor/libgit2/src/diff_parse.c +3 -3
  136. data/vendor/libgit2/src/diff_print.c +17 -17
  137. data/vendor/libgit2/src/diff_stats.c +22 -7
  138. data/vendor/libgit2/src/diff_tform.c +12 -12
  139. data/vendor/libgit2/src/diff_xdiff.c +15 -3
  140. data/vendor/libgit2/src/errors.c +42 -20
  141. data/vendor/libgit2/src/features.h.in +2 -1
  142. data/vendor/libgit2/src/fetch.c +3 -3
  143. data/vendor/libgit2/src/fetchhead.c +16 -16
  144. data/vendor/libgit2/src/filebuf.c +28 -28
  145. data/vendor/libgit2/src/fileops.c +54 -54
  146. data/vendor/libgit2/src/fileops.h +1 -1
  147. data/vendor/libgit2/src/filter.c +30 -30
  148. data/vendor/libgit2/src/filter.h +0 -10
  149. data/vendor/libgit2/src/global.c +36 -23
  150. data/vendor/libgit2/src/hash.h +4 -1
  151. data/vendor/libgit2/src/hash/hash_collisiondetect.h +6 -2
  152. data/vendor/libgit2/src/hash/hash_common_crypto.h +5 -1
  153. data/vendor/libgit2/src/hash/hash_generic.h +5 -1
  154. data/vendor/libgit2/src/hash/hash_mbedtls.c +38 -0
  155. data/vendor/libgit2/src/hash/hash_mbedtls.h +24 -0
  156. data/vendor/libgit2/src/hash/hash_openssl.h +8 -4
  157. data/vendor/libgit2/src/hash/hash_win32.c +13 -13
  158. data/vendor/libgit2/src/hashsig.c +4 -4
  159. data/vendor/libgit2/src/idxmap.c +25 -5
  160. data/vendor/libgit2/src/idxmap.h +4 -18
  161. data/vendor/libgit2/src/ignore.c +9 -9
  162. data/vendor/libgit2/src/index.c +280 -198
  163. data/vendor/libgit2/src/index.h +16 -0
  164. data/vendor/libgit2/src/indexer.c +311 -139
  165. data/vendor/libgit2/src/integer.h +32 -22
  166. data/vendor/libgit2/src/iterator.c +116 -49
  167. data/vendor/libgit2/src/iterator.h +15 -0
  168. data/vendor/libgit2/src/khash.h +3 -1
  169. data/vendor/libgit2/src/mailmap.c +485 -0
  170. data/vendor/libgit2/src/mailmap.h +35 -0
  171. data/vendor/libgit2/src/merge.c +89 -59
  172. data/vendor/libgit2/src/merge_driver.c +7 -7
  173. data/vendor/libgit2/src/merge_file.c +1 -1
  174. data/vendor/libgit2/src/mwindow.c +8 -8
  175. data/vendor/libgit2/src/netops.c +22 -13
  176. data/vendor/libgit2/src/netops.h +2 -0
  177. data/vendor/libgit2/src/notes.c +15 -10
  178. data/vendor/libgit2/src/object.c +118 -67
  179. data/vendor/libgit2/src/object.h +20 -9
  180. data/vendor/libgit2/src/object_api.c +8 -8
  181. data/vendor/libgit2/src/odb.c +72 -72
  182. data/vendor/libgit2/src/odb.h +7 -7
  183. data/vendor/libgit2/src/odb_loose.c +46 -46
  184. data/vendor/libgit2/src/odb_mempack.c +14 -14
  185. data/vendor/libgit2/src/odb_pack.c +14 -10
  186. data/vendor/libgit2/src/offmap.c +30 -0
  187. data/vendor/libgit2/src/offmap.h +20 -11
  188. data/vendor/libgit2/src/oid.c +6 -6
  189. data/vendor/libgit2/src/oidmap.c +20 -0
  190. data/vendor/libgit2/src/oidmap.h +9 -12
  191. data/vendor/libgit2/src/pack-objects.c +71 -63
  192. data/vendor/libgit2/src/pack-objects.h +1 -7
  193. data/vendor/libgit2/src/pack.c +58 -58
  194. data/vendor/libgit2/src/pack.h +6 -6
  195. data/vendor/libgit2/src/parse.h +1 -1
  196. data/vendor/libgit2/src/patch.c +3 -3
  197. data/vendor/libgit2/src/patch_generate.c +18 -18
  198. data/vendor/libgit2/src/patch_parse.c +13 -13
  199. data/vendor/libgit2/src/path.c +93 -225
  200. data/vendor/libgit2/src/path.h +2 -84
  201. data/vendor/libgit2/src/pathspec.c +6 -6
  202. data/vendor/libgit2/src/posix.c +3 -3
  203. data/vendor/libgit2/src/proxy.c +1 -1
  204. data/vendor/libgit2/src/push.c +27 -26
  205. data/vendor/libgit2/src/push.h +2 -1
  206. data/vendor/libgit2/src/reader.c +265 -0
  207. data/vendor/libgit2/src/reader.h +107 -0
  208. data/vendor/libgit2/src/rebase.c +49 -52
  209. data/vendor/libgit2/src/refdb.c +3 -3
  210. data/vendor/libgit2/src/refdb_fs.c +181 -103
  211. data/vendor/libgit2/src/reflog.c +3 -3
  212. data/vendor/libgit2/src/refs.c +98 -74
  213. data/vendor/libgit2/src/refs.h +5 -3
  214. data/vendor/libgit2/src/refspec.c +47 -21
  215. data/vendor/libgit2/src/refspec.h +1 -1
  216. data/vendor/libgit2/src/remote.c +219 -166
  217. data/vendor/libgit2/src/remote.h +9 -0
  218. data/vendor/libgit2/src/repository.c +173 -133
  219. data/vendor/libgit2/src/repository.h +6 -3
  220. data/vendor/libgit2/src/reset.c +8 -8
  221. data/vendor/libgit2/src/revert.c +6 -6
  222. data/vendor/libgit2/src/revparse.c +30 -30
  223. data/vendor/libgit2/src/revwalk.c +60 -30
  224. data/vendor/libgit2/src/revwalk.h +2 -1
  225. data/vendor/libgit2/src/settings.c +42 -10
  226. data/vendor/libgit2/src/signature.c +11 -11
  227. data/vendor/libgit2/src/sortedcache.c +13 -13
  228. data/vendor/libgit2/src/stash.c +91 -45
  229. data/vendor/libgit2/src/status.c +13 -13
  230. data/vendor/libgit2/src/stdalloc.c +120 -0
  231. data/vendor/libgit2/src/{streams/curl.h → stdalloc.h} +6 -6
  232. data/vendor/libgit2/src/stream.h +17 -2
  233. data/vendor/libgit2/src/streams/mbedtls.c +483 -0
  234. data/vendor/libgit2/src/streams/mbedtls.h +23 -0
  235. data/vendor/libgit2/src/streams/openssl.c +204 -114
  236. data/vendor/libgit2/src/streams/openssl.h +4 -108
  237. data/vendor/libgit2/src/streams/registry.c +118 -0
  238. data/vendor/libgit2/src/streams/registry.h +19 -0
  239. data/vendor/libgit2/src/streams/socket.c +54 -29
  240. data/vendor/libgit2/src/streams/stransport.c +57 -32
  241. data/vendor/libgit2/src/streams/stransport.h +5 -0
  242. data/vendor/libgit2/src/streams/tls.c +50 -19
  243. data/vendor/libgit2/src/streams/tls.h +12 -4
  244. data/vendor/libgit2/src/strmap.c +22 -2
  245. data/vendor/libgit2/src/strmap.h +18 -15
  246. data/vendor/libgit2/src/submodule.c +179 -155
  247. data/vendor/libgit2/src/sysdir.c +18 -18
  248. data/vendor/libgit2/src/tag.c +31 -26
  249. data/vendor/libgit2/src/tag.h +2 -1
  250. data/vendor/libgit2/src/trace.c +1 -1
  251. data/vendor/libgit2/src/trace.h +1 -1
  252. data/vendor/libgit2/src/trailer.c +6 -6
  253. data/vendor/libgit2/src/transaction.c +23 -23
  254. data/vendor/libgit2/src/transport.c +5 -5
  255. data/vendor/libgit2/src/transports/auth.c +7 -4
  256. data/vendor/libgit2/src/transports/auth.h +1 -1
  257. data/vendor/libgit2/src/transports/auth_negotiate.c +12 -11
  258. data/vendor/libgit2/src/transports/cred.c +18 -18
  259. data/vendor/libgit2/src/transports/git.c +15 -15
  260. data/vendor/libgit2/src/transports/http.c +606 -216
  261. data/vendor/libgit2/src/transports/http.h +2 -0
  262. data/vendor/libgit2/src/transports/local.c +26 -26
  263. data/vendor/libgit2/src/transports/smart.c +54 -31
  264. data/vendor/libgit2/src/transports/smart.h +1 -2
  265. data/vendor/libgit2/src/transports/smart_pkt.c +43 -40
  266. data/vendor/libgit2/src/transports/smart_protocol.c +61 -57
  267. data/vendor/libgit2/src/transports/ssh.c +34 -33
  268. data/vendor/libgit2/src/transports/winhttp.c +99 -119
  269. data/vendor/libgit2/src/tree-cache.c +5 -5
  270. data/vendor/libgit2/src/tree.c +96 -121
  271. data/vendor/libgit2/src/tree.h +1 -12
  272. data/vendor/libgit2/src/unix/map.c +2 -2
  273. data/vendor/libgit2/src/util.c +22 -6
  274. data/vendor/libgit2/src/util.h +12 -135
  275. data/vendor/libgit2/src/vector.c +4 -4
  276. data/vendor/libgit2/src/win32/dir.c +3 -3
  277. data/vendor/libgit2/src/win32/findfile.c +3 -3
  278. data/vendor/libgit2/src/win32/map.c +6 -6
  279. data/vendor/libgit2/src/win32/msvc-compat.h +6 -0
  280. data/vendor/libgit2/src/win32/path_w32.c +101 -7
  281. data/vendor/libgit2/src/win32/path_w32.h +18 -0
  282. data/vendor/libgit2/src/win32/posix_w32.c +24 -43
  283. data/vendor/libgit2/src/win32/w32_buffer.c +2 -2
  284. data/vendor/libgit2/src/win32/w32_crtdbg_stacktrace.c +96 -2
  285. data/vendor/libgit2/src/win32/w32_crtdbg_stacktrace.h +28 -75
  286. data/vendor/libgit2/src/win32/w32_stack.c +2 -2
  287. data/vendor/libgit2/src/win32/w32_util.c +1 -69
  288. data/vendor/libgit2/src/win32/w32_util.h +1 -19
  289. data/vendor/libgit2/src/worktree.c +75 -54
  290. data/vendor/libgit2/src/worktree.h +2 -0
  291. data/vendor/libgit2/src/xdiff/xdiffi.c +7 -5
  292. data/vendor/libgit2/src/xdiff/xhistogram.c +1 -1
  293. data/vendor/libgit2/src/xdiff/xmerge.c +15 -15
  294. data/vendor/libgit2/src/zstream.c +4 -4
  295. metadata +33 -7
  296. data/vendor/libgit2/src/config_file.h +0 -73
  297. data/vendor/libgit2/src/streams/curl.c +0 -385
@@ -42,34 +42,44 @@ GIT_INLINE(int) git__is_int(long long p)
42
42
  return p == (long long)r;
43
43
  }
44
44
 
45
- /**
46
- * Sets `one + two` into `out`, unless the arithmetic would overflow.
47
- * @return true if the result fits in a `uint64_t`, false on overflow.
48
- */
49
- GIT_INLINE(bool) git__add_uint64_overflow(uint64_t *out, uint64_t one, uint64_t two)
50
- {
51
- if (UINT64_MAX - one < two)
52
- return true;
53
- *out = one + two;
54
- return false;
55
- }
56
-
57
45
  /* Use clang/gcc compiler intrinsics whenever possible */
58
- #if (SIZE_MAX == ULONG_MAX) && __has_builtin(__builtin_uaddl_overflow)
59
- # define git__add_sizet_overflow(out, one, two) \
60
- __builtin_uaddl_overflow(one, two, out)
61
- # define git__multiply_sizet_overflow(out, one, two) \
62
- __builtin_umull_overflow(one, two, out)
63
- #elif (SIZE_MAX == UINT_MAX) && __has_builtin(__builtin_uadd_overflow)
46
+ #if (__has_builtin(__builtin_add_overflow) || \
47
+ (defined(__GNUC__) && (__GNUC__ >= 5)))
48
+
49
+ # if (SIZE_MAX == UINT_MAX)
50
+ # define git__add_sizet_overflow(out, one, two) \
51
+ __builtin_uadd_overflow(one, two, out)
52
+ # define git__multiply_sizet_overflow(out, one, two) \
53
+ __builtin_umul_overflow(one, two, out)
54
+ # elif (SIZE_MAX == ULONG_MAX)
55
+ # define git__add_sizet_overflow(out, one, two) \
56
+ __builtin_uaddl_overflow(one, two, out)
57
+ # define git__multiply_sizet_overflow(out, one, two) \
58
+ __builtin_umull_overflow(one, two, out)
59
+ # elif (SIZE_MAX == ULLONG_MAX)
60
+ # define git__add_sizet_overflow(out, one, two) \
61
+ __builtin_uaddll_overflow(one, two, out)
62
+ # define git__multiply_sizet_overflow(out, one, two) \
63
+ __builtin_umulll_overflow(one, two, out)
64
+ # else
65
+ # error compiler has add with overflow intrinsics but SIZE_MAX is unknown
66
+ # endif
67
+
68
+ /* Use Microsoft's safe integer handling functions where available */
69
+ #elif defined(_MSC_VER)
70
+
71
+ # include <intsafe.h>
72
+
64
73
  # define git__add_sizet_overflow(out, one, two) \
65
- __builtin_uadd_overflow(one, two, out)
74
+ (SizeTAdd(one, two, out) != S_OK)
66
75
  # define git__multiply_sizet_overflow(out, one, two) \
67
- __builtin_umul_overflow(one, two, out)
76
+ (SizeTMult(one, two, out) != S_OK)
77
+
68
78
  #else
69
79
 
70
80
  /**
71
81
  * Sets `one + two` into `out`, unless the arithmetic would overflow.
72
- * @return true if the result fits in a `size_t`, false on overflow.
82
+ * @return false if the result fits in a `size_t`, true on overflow.
73
83
  */
74
84
  GIT_INLINE(bool) git__add_sizet_overflow(size_t *out, size_t one, size_t two)
75
85
  {
@@ -81,7 +91,7 @@ GIT_INLINE(bool) git__add_sizet_overflow(size_t *out, size_t one, size_t two)
81
91
 
82
92
  /**
83
93
  * Sets `one * two` into `out`, unless the arithmetic would overflow.
84
- * @return true if the result fits in a `size_t`, false on overflow.
94
+ * @return false if the result fits in a `size_t`, true on overflow.
85
95
  */
86
96
  GIT_INLINE(bool) git__multiply_sizet_overflow(size_t *out, size_t one, size_t two)
87
97
  {
@@ -46,14 +46,14 @@ static int iterator_range_init(
46
46
  {
47
47
  if (start && *start) {
48
48
  iter->start = git__strdup(start);
49
- GITERR_CHECK_ALLOC(iter->start);
49
+ GIT_ERROR_CHECK_ALLOC(iter->start);
50
50
 
51
51
  iter->start_len = strlen(iter->start);
52
52
  }
53
53
 
54
54
  if (end && *end) {
55
55
  iter->end = git__strdup(end);
56
- GITERR_CHECK_ALLOC(iter->end);
56
+ GIT_ERROR_CHECK_ALLOC(iter->end);
57
57
 
58
58
  iter->end_len = strlen(iter->end);
59
59
  }
@@ -146,7 +146,7 @@ static int iterator_init_common(
146
146
  (iter->flags & GIT_ITERATOR_DONT_PRECOMPOSE_UNICODE) == 0) {
147
147
 
148
148
  if (git_repository__cvar(&precompose, repo, GIT_CVAR_PRECOMPOSE) < 0)
149
- giterr_clear();
149
+ git_error_clear();
150
150
  else if (precompose)
151
151
  iter->flags |= GIT_ITERATOR_PRECOMPOSE_UNICODE;
152
152
  }
@@ -403,7 +403,7 @@ int git_iterator_for_nothing(
403
403
  *out = NULL;
404
404
 
405
405
  iter = git__calloc(1, sizeof(empty_iterator));
406
- GITERR_CHECK_ALLOC(iter);
406
+ GIT_ERROR_CHECK_ALLOC(iter);
407
407
 
408
408
  iter->base.type = GIT_ITERATOR_TYPE_EMPTY;
409
409
  iter->base.cb = &callbacks;
@@ -478,14 +478,6 @@ GIT_INLINE(int) tree_entry_cmp(
478
478
  icase ? git__strncasecmp : git__strncmp);
479
479
  }
480
480
 
481
- GIT_INLINE(int) tree_iterator_entry_cmp(const void *ptr_a, const void *ptr_b)
482
- {
483
- const tree_iterator_entry *a = (const tree_iterator_entry *)ptr_a;
484
- const tree_iterator_entry *b = (const tree_iterator_entry *)ptr_b;
485
-
486
- return tree_entry_cmp(a->tree_entry, b->tree_entry, false);
487
- }
488
-
489
481
  GIT_INLINE(int) tree_iterator_entry_cmp_icase(
490
482
  const void *ptr_a, const void *ptr_b)
491
483
  {
@@ -549,7 +541,7 @@ static int tree_iterator_frame_init(
549
541
  int error = 0;
550
542
 
551
543
  new_frame = git_array_alloc(iter->frames);
552
- GITERR_CHECK_ALLOC(new_frame);
544
+ GIT_ERROR_CHECK_ALLOC(new_frame);
553
545
 
554
546
  memset(new_frame, 0, sizeof(tree_iterator_frame));
555
547
 
@@ -572,7 +564,7 @@ static int tree_iterator_frame_init(
572
564
 
573
565
  git_array_foreach(dup->entries, i, tree_entry) {
574
566
  new_entry = git_pool_malloc(&iter->entry_pool, 1);
575
- GITERR_CHECK_ALLOC(new_entry);
567
+ GIT_ERROR_CHECK_ALLOC(new_entry);
576
568
 
577
569
  new_entry->tree_entry = tree_entry;
578
570
  new_entry->parent_path = new_frame->path.ptr;
@@ -626,20 +618,20 @@ GIT_INLINE(int) tree_iterator_frame_push_neighbors(
626
618
  break;
627
619
 
628
620
  path = git_array_alloc(parent_frame->similar_paths);
629
- GITERR_CHECK_ALLOC(path);
621
+ GIT_ERROR_CHECK_ALLOC(path);
630
622
 
631
623
  memset(path, 0, sizeof(git_buf));
632
624
 
633
625
  if ((error = tree_iterator_compute_path(path, entry)) < 0)
634
626
  break;
635
627
 
636
- GITERR_CHECK_ALLOC_ADD(&new_size,
628
+ GIT_ERROR_CHECK_ALLOC_ADD(&new_size,
637
629
  frame->entries.length, tree->entries.size);
638
630
  git_vector_size_hint(&frame->entries, new_size);
639
631
 
640
632
  git_array_foreach(tree->entries, i, tree_entry) {
641
633
  new_entry = git_pool_malloc(&iter->entry_pool, 1);
642
- GITERR_CHECK_ALLOC(new_entry);
634
+ GIT_ERROR_CHECK_ALLOC(new_entry);
643
635
 
644
636
  new_entry->tree_entry = tree_entry;
645
637
  new_entry->parent_path = path->ptr;
@@ -701,7 +693,7 @@ static void tree_iterator_frame_pop(tree_iterator *iter)
701
693
 
702
694
  do {
703
695
  buf = git_array_pop(frame->similar_paths);
704
- git_buf_free(buf);
696
+ git_buf_dispose(buf);
705
697
  } while (buf != NULL);
706
698
 
707
699
  git_array_clear(frame->similar_paths);
@@ -711,7 +703,7 @@ static void tree_iterator_frame_pop(tree_iterator *iter)
711
703
 
712
704
  git_vector_free(&frame->similar_trees);
713
705
 
714
- git_buf_free(&frame->path);
706
+ git_buf_dispose(&frame->path);
715
707
  }
716
708
 
717
709
  static int tree_iterator_current(
@@ -929,7 +921,7 @@ static void tree_iterator_free(git_iterator *i)
929
921
  tree_iterator_clear(iter);
930
922
 
931
923
  git_tree_free(iter->root);
932
- git_buf_free(&iter->entry_path);
924
+ git_buf_dispose(&iter->entry_path);
933
925
  }
934
926
 
935
927
  int git_iterator_for_tree(
@@ -955,7 +947,7 @@ int git_iterator_for_tree(
955
947
  return git_iterator_for_nothing(out, options);
956
948
 
957
949
  iter = git__calloc(1, sizeof(tree_iterator));
958
- GITERR_CHECK_ALLOC(iter);
950
+ GIT_ERROR_CHECK_ALLOC(iter);
959
951
 
960
952
  iter->base.type = GIT_ITERATOR_TYPE_TREE;
961
953
  iter->base.cb = &callbacks;
@@ -1015,6 +1007,7 @@ typedef struct {
1015
1007
  struct stat st;
1016
1008
  size_t path_len;
1017
1009
  iterator_pathlist_search_t match;
1010
+ git_oid id;
1018
1011
  char path[GIT_FLEX_ARRAY];
1019
1012
  } filesystem_iterator_entry;
1020
1013
 
@@ -1150,7 +1143,7 @@ static void filesystem_iterator_frame_push_ignores(
1150
1143
 
1151
1144
  if (git_ignore__lookup(&new_frame->is_ignored,
1152
1145
  &iter->ignores, path, GIT_DIR_FLAG_TRUE) < 0) {
1153
- giterr_clear();
1146
+ git_error_clear();
1154
1147
  new_frame->is_ignored = GIT_IGNORE_NOTFOUND;
1155
1148
  }
1156
1149
 
@@ -1265,7 +1258,32 @@ GIT_INLINE(bool) filesystem_iterator_is_dot_git(
1265
1258
  return (len == 4 || path[len - 5] == '/');
1266
1259
  }
1267
1260
 
1268
- static filesystem_iterator_entry *filesystem_iterator_entry_init(
1261
+ static int filesystem_iterator_entry_hash(
1262
+ filesystem_iterator *iter,
1263
+ filesystem_iterator_entry *entry)
1264
+ {
1265
+ git_buf fullpath = GIT_BUF_INIT;
1266
+ int error;
1267
+
1268
+ if (S_ISDIR(entry->st.st_mode)) {
1269
+ memset(&entry->id, 0, GIT_OID_RAWSZ);
1270
+ return 0;
1271
+ }
1272
+
1273
+ if (iter->base.type == GIT_ITERATOR_TYPE_WORKDIR)
1274
+ return git_repository_hashfile(&entry->id,
1275
+ iter->base.repo, entry->path, GIT_OBJECT_BLOB, NULL);
1276
+
1277
+ if (!(error = git_buf_joinpath(&fullpath, iter->root, entry->path)))
1278
+ error = git_odb_hashfile(&entry->id, fullpath.ptr, GIT_OBJECT_BLOB);
1279
+
1280
+ git_buf_dispose(&fullpath);
1281
+ return error;
1282
+ }
1283
+
1284
+ static int filesystem_iterator_entry_init(
1285
+ filesystem_iterator_entry **out,
1286
+ filesystem_iterator *iter,
1269
1287
  filesystem_iterator_frame *frame,
1270
1288
  const char *path,
1271
1289
  size_t path_len,
@@ -1274,15 +1292,19 @@ static filesystem_iterator_entry *filesystem_iterator_entry_init(
1274
1292
  {
1275
1293
  filesystem_iterator_entry *entry;
1276
1294
  size_t entry_size;
1295
+ int error = 0;
1296
+
1297
+ *out = NULL;
1277
1298
 
1278
1299
  /* Make sure to append two bytes, one for the path's null
1279
1300
  * termination, one for a possible trailing '/' for folders.
1280
1301
  */
1281
- if (GIT_ADD_SIZET_OVERFLOW(&entry_size,
1282
- sizeof(filesystem_iterator_entry), path_len) ||
1283
- GIT_ADD_SIZET_OVERFLOW(&entry_size, entry_size, 2) ||
1284
- (entry = git_pool_malloc(&frame->entry_pool, entry_size)) == NULL)
1285
- return NULL;
1302
+ GIT_ERROR_CHECK_ALLOC_ADD(&entry_size,
1303
+ sizeof(filesystem_iterator_entry), path_len);
1304
+ GIT_ERROR_CHECK_ALLOC_ADD(&entry_size, entry_size, 2);
1305
+
1306
+ entry = git_pool_malloc(&frame->entry_pool, entry_size);
1307
+ GIT_ERROR_CHECK_ALLOC(entry);
1286
1308
 
1287
1309
  entry->path_len = path_len;
1288
1310
  entry->match = pathlist_match;
@@ -1295,7 +1317,13 @@ static filesystem_iterator_entry *filesystem_iterator_entry_init(
1295
1317
 
1296
1318
  entry->path[entry->path_len] = '\0';
1297
1319
 
1298
- return entry;
1320
+ if (iter->base.flags & GIT_ITERATOR_INCLUDE_HASH)
1321
+ error = filesystem_iterator_entry_hash(iter, entry);
1322
+
1323
+ if (!error)
1324
+ *out = entry;
1325
+
1326
+ return error;
1299
1327
  }
1300
1328
 
1301
1329
  static int filesystem_iterator_frame_push(
@@ -1312,13 +1340,13 @@ static int filesystem_iterator_frame_push(
1312
1340
  int error;
1313
1341
 
1314
1342
  if (iter->frames.size == FILESYSTEM_MAX_DEPTH) {
1315
- giterr_set(GITERR_REPOSITORY,
1343
+ git_error_set(GIT_ERROR_REPOSITORY,
1316
1344
  "directory nesting too deep (%"PRIuZ")", iter->frames.size);
1317
1345
  return -1;
1318
1346
  }
1319
1347
 
1320
1348
  new_frame = git_array_alloc(iter->frames);
1321
- GITERR_CHECK_ALLOC(new_frame);
1349
+ GIT_ERROR_CHECK_ALLOC(new_frame);
1322
1350
 
1323
1351
  memset(new_frame, 0, sizeof(filesystem_iterator_frame));
1324
1352
 
@@ -1418,9 +1446,9 @@ static int filesystem_iterator_frame_push(
1418
1446
  else if (dir_expected)
1419
1447
  continue;
1420
1448
 
1421
- entry = filesystem_iterator_entry_init(new_frame,
1422
- path, path_len, &statbuf, pathlist_match);
1423
- GITERR_CHECK_ALLOC(entry);
1449
+ if ((error = filesystem_iterator_entry_init(&entry,
1450
+ iter, new_frame, path, path_len, &statbuf, pathlist_match)) < 0)
1451
+ goto done;
1424
1452
 
1425
1453
  git_vector_insert(&new_frame->entries, entry);
1426
1454
  }
@@ -1435,7 +1463,7 @@ done:
1435
1463
  if (error < 0)
1436
1464
  git_array_pop(iter->frames);
1437
1465
 
1438
- git_buf_free(&root);
1466
+ git_buf_dispose(&root);
1439
1467
  git_path_diriter_free(&diriter);
1440
1468
  return error;
1441
1469
  }
@@ -1457,10 +1485,17 @@ static void filesystem_iterator_set_current(
1457
1485
  filesystem_iterator *iter,
1458
1486
  filesystem_iterator_entry *entry)
1459
1487
  {
1460
- iter->entry.ctime.seconds = entry->st.st_ctime;
1461
- iter->entry.mtime.seconds = entry->st.st_mtime;
1488
+ /*
1489
+ * Index entries are limited to 32 bit timestamps. We can safely
1490
+ * cast this since workdir times are only used in the cache; any
1491
+ * mismatch will cause a hash recomputation which is unfortunate
1492
+ * but affects only people who set their filetimes to 2038.
1493
+ * (Same with the file size.)
1494
+ */
1495
+ iter->entry.ctime.seconds = (int32_t)entry->st.st_ctime;
1496
+ iter->entry.mtime.seconds = (int32_t)entry->st.st_mtime;
1462
1497
 
1463
- #if defined(GIT_USE_NSEC)
1498
+ #if defined(GIT_USE_NSEC)
1464
1499
  iter->entry.ctime.nanoseconds = entry->st.st_ctime_nsec;
1465
1500
  iter->entry.mtime.nanoseconds = entry->st.st_mtime_nsec;
1466
1501
  #else
@@ -1473,7 +1508,10 @@ static void filesystem_iterator_set_current(
1473
1508
  iter->entry.mode = git_futils_canonical_mode(entry->st.st_mode);
1474
1509
  iter->entry.uid = entry->st.st_uid;
1475
1510
  iter->entry.gid = entry->st.st_gid;
1476
- iter->entry.file_size = entry->st.st_size;
1511
+ iter->entry.file_size = (uint32_t)entry->st.st_size;
1512
+
1513
+ if (iter->base.flags & GIT_ITERATOR_INCLUDE_HASH)
1514
+ git_oid_cpy(&iter->entry.id, &entry->id);
1477
1515
 
1478
1516
  iter->entry.path = entry->path;
1479
1517
 
@@ -1523,7 +1561,7 @@ static int filesystem_iterator_is_dir(
1523
1561
  *is_dir = S_ISDIR(st.st_mode);
1524
1562
 
1525
1563
  done:
1526
- git_buf_free(&fullpath);
1564
+ git_buf_dispose(&fullpath);
1527
1565
  return error;
1528
1566
  }
1529
1567
 
@@ -1664,7 +1702,7 @@ static void filesystem_iterator_update_ignored(filesystem_iterator *iter)
1664
1702
 
1665
1703
  if (git_ignore__lookup(&iter->current_is_ignored,
1666
1704
  &iter->ignores, iter->entry.path, dir_flag) < 0) {
1667
- giterr_clear();
1705
+ git_error_clear();
1668
1706
  iter->current_is_ignored = GIT_IGNORE_NOTFOUND;
1669
1707
  }
1670
1708
 
@@ -1804,7 +1842,7 @@ static void filesystem_iterator_clear(filesystem_iterator *iter)
1804
1842
  git_array_clear(iter->frames);
1805
1843
  git_ignore__free(&iter->ignores);
1806
1844
 
1807
- git_buf_free(&iter->tmp_buf);
1845
+ git_buf_dispose(&iter->tmp_buf);
1808
1846
 
1809
1847
  iterator_clear(&iter->base);
1810
1848
  }
@@ -1838,7 +1876,7 @@ static void filesystem_iterator_free(git_iterator *i)
1838
1876
  {
1839
1877
  filesystem_iterator *iter = (filesystem_iterator *)i;
1840
1878
  git__free(iter->root);
1841
- git_buf_free(&iter->current_path);
1879
+ git_buf_dispose(&iter->current_path);
1842
1880
  git_tree_free(iter->tree);
1843
1881
  if (iter->index)
1844
1882
  git_index_snapshot_release(&iter->index_snapshot, iter->index);
@@ -1873,7 +1911,7 @@ static int iterator_for_filesystem(
1873
1911
  return git_iterator_for_nothing(out, options);
1874
1912
 
1875
1913
  iter = git__calloc(1, sizeof(filesystem_iterator));
1876
- GITERR_CHECK_ALLOC(iter);
1914
+ GIT_ERROR_CHECK_ALLOC(iter);
1877
1915
 
1878
1916
  iter->base.type = type;
1879
1917
  iter->base.cb = &callbacks;
@@ -1881,7 +1919,7 @@ static int iterator_for_filesystem(
1881
1919
  root_len = strlen(root);
1882
1920
 
1883
1921
  iter->root = git__malloc(root_len+2);
1884
- GITERR_CHECK_ALLOC(iter->root);
1922
+ GIT_ERROR_CHECK_ALLOC(iter->root);
1885
1923
 
1886
1924
  memcpy(iter->root, root, root_len);
1887
1925
 
@@ -2176,7 +2214,7 @@ static void index_iterator_free(git_iterator *i)
2176
2214
  index_iterator *iter = (index_iterator *)i;
2177
2215
 
2178
2216
  git_index_snapshot_release(&iter->entries, iter->base.index);
2179
- git_buf_free(&iter->tree_buf);
2217
+ git_buf_dispose(&iter->tree_buf);
2180
2218
  }
2181
2219
 
2182
2220
  int git_iterator_for_index(
@@ -2203,7 +2241,7 @@ int git_iterator_for_index(
2203
2241
  return git_iterator_for_nothing(out, options);
2204
2242
 
2205
2243
  iter = git__calloc(1, sizeof(index_iterator));
2206
- GITERR_CHECK_ALLOC(iter);
2244
+ GIT_ERROR_CHECK_ALLOC(iter);
2207
2245
 
2208
2246
  iter->base.type = GIT_ITERATOR_TYPE_INDEX;
2209
2247
  iter->base.cb = &callbacks;
@@ -2259,6 +2297,35 @@ void git_iterator_free(git_iterator *iter)
2259
2297
  git__free(iter);
2260
2298
  }
2261
2299
 
2300
+ int git_iterator_foreach(
2301
+ git_iterator *iterator,
2302
+ git_iterator_foreach_cb cb,
2303
+ void *data)
2304
+ {
2305
+ const git_index_entry *iterator_item;
2306
+ int error = 0;
2307
+
2308
+ if ((error = git_iterator_current(&iterator_item, iterator)) < 0)
2309
+ goto done;
2310
+
2311
+ if ((error = cb(iterator_item, data)) != 0)
2312
+ goto done;
2313
+
2314
+ while (true) {
2315
+ if ((error = git_iterator_advance(&iterator_item, iterator)) < 0)
2316
+ goto done;
2317
+
2318
+ if ((error = cb(iterator_item, data)) != 0)
2319
+ goto done;
2320
+ }
2321
+
2322
+ done:
2323
+ if (error == GIT_ITEROVER)
2324
+ error = 0;
2325
+
2326
+ return error;
2327
+ }
2328
+
2262
2329
  int git_iterator_walk(
2263
2330
  git_iterator **iterators,
2264
2331
  size_t cnt,
@@ -2274,8 +2341,8 @@ int git_iterator_walk(
2274
2341
  iterator_item = git__calloc(cnt, sizeof(git_index_entry *));
2275
2342
  cur_items = git__calloc(cnt, sizeof(git_index_entry *));
2276
2343
 
2277
- GITERR_CHECK_ALLOC(iterator_item);
2278
- GITERR_CHECK_ALLOC(cur_items);
2344
+ GIT_ERROR_CHECK_ALLOC(iterator_item);
2345
+ GIT_ERROR_CHECK_ALLOC(cur_items);
2279
2346
 
2280
2347
  /* Set up the iterators */
2281
2348
  for (i = 0; i < cnt; i++) {