rugged 1.1.1 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (277) 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 +17 -5
  16. data/vendor/libgit2/deps/ntlmclient/crypt.h +14 -9
  17. data/vendor/libgit2/deps/ntlmclient/crypt_commoncrypto.c +20 -20
  18. data/vendor/libgit2/deps/ntlmclient/crypt_commoncrypto.h +3 -3
  19. data/vendor/libgit2/deps/ntlmclient/crypt_mbedtls.c +37 -36
  20. data/vendor/libgit2/deps/ntlmclient/crypt_mbedtls.h +4 -3
  21. data/vendor/libgit2/deps/ntlmclient/crypt_openssl.c +178 -51
  22. data/vendor/libgit2/deps/ntlmclient/crypt_openssl.h +74 -5
  23. data/vendor/libgit2/deps/ntlmclient/ntlm.c +150 -118
  24. data/vendor/libgit2/deps/ntlmclient/ntlm.h +13 -9
  25. data/vendor/libgit2/deps/ntlmclient/ntlmclient.h +16 -3
  26. data/vendor/libgit2/deps/ntlmclient/unicode.h +10 -4
  27. data/vendor/libgit2/deps/ntlmclient/unicode_builtin.c +16 -27
  28. data/vendor/libgit2/deps/ntlmclient/unicode_builtin.h +20 -0
  29. data/vendor/libgit2/deps/ntlmclient/unicode_iconv.c +28 -52
  30. data/vendor/libgit2/deps/ntlmclient/unicode_iconv.h +22 -0
  31. data/vendor/libgit2/include/git2/attr.h +89 -0
  32. data/vendor/libgit2/include/git2/blame.h +93 -42
  33. data/vendor/libgit2/include/git2/blob.h +14 -2
  34. data/vendor/libgit2/include/git2/branch.h +25 -0
  35. data/vendor/libgit2/include/git2/cert.h +42 -5
  36. data/vendor/libgit2/include/git2/checkout.h +28 -12
  37. data/vendor/libgit2/include/git2/commit.h +35 -19
  38. data/vendor/libgit2/include/git2/common.h +14 -4
  39. data/vendor/libgit2/include/git2/deprecated.h +206 -6
  40. data/vendor/libgit2/include/git2/diff.h +34 -19
  41. data/vendor/libgit2/include/git2/errors.h +6 -6
  42. data/vendor/libgit2/include/git2/filter.h +57 -17
  43. data/vendor/libgit2/include/git2/graph.h +20 -2
  44. data/vendor/libgit2/include/git2/index.h +2 -2
  45. data/vendor/libgit2/include/git2/odb.h +29 -0
  46. data/vendor/libgit2/include/git2/patch.h +8 -0
  47. data/vendor/libgit2/include/git2/rebase.h +25 -1
  48. data/vendor/libgit2/include/git2/refs.h +6 -2
  49. data/vendor/libgit2/include/git2/remote.h +59 -6
  50. data/vendor/libgit2/include/git2/revparse.h +5 -5
  51. data/vendor/libgit2/include/git2/status.h +115 -59
  52. data/vendor/libgit2/include/git2/submodule.h +9 -0
  53. data/vendor/libgit2/include/git2/sys/commit_graph.h +174 -0
  54. data/vendor/libgit2/include/git2/sys/filter.h +49 -28
  55. data/vendor/libgit2/include/git2/sys/midx.h +74 -0
  56. data/vendor/libgit2/include/git2/sys/odb_backend.h +7 -0
  57. data/vendor/libgit2/include/git2/sys/transport.h +1 -0
  58. data/vendor/libgit2/include/git2/tag.h +12 -0
  59. data/vendor/libgit2/include/git2/tree.h +0 -14
  60. data/vendor/libgit2/include/git2/types.h +9 -0
  61. data/vendor/libgit2/include/git2/version.h +4 -4
  62. data/vendor/libgit2/include/git2/worktree.h +1 -0
  63. data/vendor/libgit2/src/CMakeLists.txt +25 -4
  64. data/vendor/libgit2/src/alloc.c +21 -8
  65. data/vendor/libgit2/src/allocators/failalloc.c +92 -0
  66. data/vendor/libgit2/src/allocators/failalloc.h +23 -0
  67. data/vendor/libgit2/src/allocators/stdalloc.c +41 -10
  68. data/vendor/libgit2/src/allocators/win32_leakcheck.c +118 -0
  69. data/vendor/libgit2/src/allocators/{win32_crtdbg.h → win32_leakcheck.h} +3 -3
  70. data/vendor/libgit2/src/annotated_commit.c +21 -9
  71. data/vendor/libgit2/src/apply.c +16 -7
  72. data/vendor/libgit2/src/array.h +11 -11
  73. data/vendor/libgit2/src/attr.c +181 -74
  74. data/vendor/libgit2/src/attr_file.c +84 -39
  75. data/vendor/libgit2/src/attr_file.h +32 -11
  76. data/vendor/libgit2/src/attrcache.c +42 -37
  77. data/vendor/libgit2/src/attrcache.h +4 -5
  78. data/vendor/libgit2/src/blame.c +11 -5
  79. data/vendor/libgit2/src/blob.c +35 -24
  80. data/vendor/libgit2/src/branch.c +69 -17
  81. data/vendor/libgit2/src/buffer.c +334 -25
  82. data/vendor/libgit2/src/buffer.h +153 -2
  83. data/vendor/libgit2/src/cache.c +2 -2
  84. data/vendor/libgit2/src/cache.h +7 -7
  85. data/vendor/libgit2/src/cc-compat.h +10 -2
  86. data/vendor/libgit2/src/checkout.c +48 -26
  87. data/vendor/libgit2/src/cherrypick.c +6 -2
  88. data/vendor/libgit2/src/clone.c +41 -47
  89. data/vendor/libgit2/src/commit.c +41 -28
  90. data/vendor/libgit2/src/commit_graph.c +1209 -0
  91. data/vendor/libgit2/src/commit_graph.h +162 -0
  92. data/vendor/libgit2/src/commit_list.c +46 -0
  93. data/vendor/libgit2/src/commit_list.h +2 -0
  94. data/vendor/libgit2/src/common.h +25 -2
  95. data/vendor/libgit2/src/config.c +37 -15
  96. data/vendor/libgit2/src/config_cache.c +5 -3
  97. data/vendor/libgit2/src/config_file.c +16 -8
  98. data/vendor/libgit2/src/config_parse.c +4 -6
  99. data/vendor/libgit2/src/crlf.c +16 -6
  100. data/vendor/libgit2/src/date.c +4 -3
  101. data/vendor/libgit2/src/delta.c +1 -1
  102. data/vendor/libgit2/src/describe.c +6 -3
  103. data/vendor/libgit2/src/diff.c +11 -8
  104. data/vendor/libgit2/src/diff_driver.c +21 -17
  105. data/vendor/libgit2/src/diff_file.c +2 -6
  106. data/vendor/libgit2/src/diff_generate.c +46 -17
  107. data/vendor/libgit2/src/diff_print.c +19 -6
  108. data/vendor/libgit2/src/diff_stats.c +7 -5
  109. data/vendor/libgit2/src/diff_tform.c +9 -8
  110. data/vendor/libgit2/src/diff_xdiff.c +4 -2
  111. data/vendor/libgit2/src/diff_xdiff.h +1 -1
  112. data/vendor/libgit2/src/errors.c +24 -19
  113. data/vendor/libgit2/src/features.h.in +5 -1
  114. data/vendor/libgit2/src/fetch.c +5 -2
  115. data/vendor/libgit2/src/fetchhead.c +8 -4
  116. data/vendor/libgit2/src/filebuf.c +9 -7
  117. data/vendor/libgit2/src/filter.c +206 -110
  118. data/vendor/libgit2/src/filter.h +24 -5
  119. data/vendor/libgit2/src/futils.c +5 -5
  120. data/vendor/libgit2/src/futils.h +1 -1
  121. data/vendor/libgit2/src/graph.c +64 -9
  122. data/vendor/libgit2/src/hash/sha1/collisiondetect.c +3 -3
  123. data/vendor/libgit2/src/hash/sha1/common_crypto.c +3 -3
  124. data/vendor/libgit2/src/hash/sha1/generic.h +1 -1
  125. data/vendor/libgit2/src/hash/sha1/mbedtls.c +12 -12
  126. data/vendor/libgit2/src/hash/sha1/openssl.c +3 -3
  127. data/vendor/libgit2/src/hash/sha1/sha1dc/sha1.c +0 -2
  128. data/vendor/libgit2/src/hash/sha1/win32.c +15 -11
  129. data/vendor/libgit2/src/hash.c +16 -13
  130. data/vendor/libgit2/src/hash.h +1 -1
  131. data/vendor/libgit2/src/hashsig.c +23 -10
  132. data/vendor/libgit2/src/ident.c +13 -3
  133. data/vendor/libgit2/src/ignore.c +35 -19
  134. data/vendor/libgit2/src/index.c +106 -70
  135. data/vendor/libgit2/src/index.h +1 -1
  136. data/vendor/libgit2/src/indexer.c +31 -29
  137. data/vendor/libgit2/src/integer.h +64 -2
  138. data/vendor/libgit2/src/iterator.c +36 -24
  139. data/vendor/libgit2/src/iterator.h +1 -1
  140. data/vendor/libgit2/src/khash.h +2 -11
  141. data/vendor/libgit2/src/{settings.c → libgit2.c} +117 -50
  142. data/vendor/libgit2/src/libgit2.h +15 -0
  143. data/vendor/libgit2/src/mailmap.c +23 -10
  144. data/vendor/libgit2/src/map.h +3 -3
  145. data/vendor/libgit2/src/merge.c +70 -30
  146. data/vendor/libgit2/src/merge.h +2 -1
  147. data/vendor/libgit2/src/merge_driver.c +19 -13
  148. data/vendor/libgit2/src/merge_file.c +11 -3
  149. data/vendor/libgit2/src/message.c +3 -1
  150. data/vendor/libgit2/src/midx.c +471 -10
  151. data/vendor/libgit2/src/midx.h +28 -1
  152. data/vendor/libgit2/src/mwindow.c +103 -59
  153. data/vendor/libgit2/src/mwindow.h +3 -3
  154. data/vendor/libgit2/src/net.c +127 -3
  155. data/vendor/libgit2/src/net.h +16 -2
  156. data/vendor/libgit2/src/netops.c +6 -4
  157. data/vendor/libgit2/src/netops.h +2 -2
  158. data/vendor/libgit2/src/notes.c +10 -10
  159. data/vendor/libgit2/src/object.c +22 -14
  160. data/vendor/libgit2/src/odb.c +285 -48
  161. data/vendor/libgit2/src/odb.h +16 -2
  162. data/vendor/libgit2/src/odb_loose.c +28 -18
  163. data/vendor/libgit2/src/odb_mempack.c +1 -1
  164. data/vendor/libgit2/src/odb_pack.c +391 -114
  165. data/vendor/libgit2/src/oid.c +5 -4
  166. data/vendor/libgit2/src/pack-objects.c +54 -48
  167. data/vendor/libgit2/src/pack.c +329 -119
  168. data/vendor/libgit2/src/pack.h +25 -7
  169. data/vendor/libgit2/src/patch.c +14 -7
  170. data/vendor/libgit2/src/patch_generate.c +2 -2
  171. data/vendor/libgit2/src/patch_parse.c +2 -1
  172. data/vendor/libgit2/src/path.c +98 -53
  173. data/vendor/libgit2/src/path.h +79 -6
  174. data/vendor/libgit2/src/pathspec.c +8 -8
  175. data/vendor/libgit2/src/pool.c +13 -7
  176. data/vendor/libgit2/src/posix.c +11 -3
  177. data/vendor/libgit2/src/reader.c +10 -6
  178. data/vendor/libgit2/src/rebase.c +93 -49
  179. data/vendor/libgit2/src/refdb.c +30 -13
  180. data/vendor/libgit2/src/refdb_fs.c +121 -69
  181. data/vendor/libgit2/src/reflog.c +19 -14
  182. data/vendor/libgit2/src/refs.c +76 -41
  183. data/vendor/libgit2/src/refspec.c +32 -12
  184. data/vendor/libgit2/src/remote.c +272 -102
  185. data/vendor/libgit2/src/remote.h +2 -1
  186. data/vendor/libgit2/src/repository.c +176 -103
  187. data/vendor/libgit2/src/repository.h +12 -1
  188. data/vendor/libgit2/src/reset.c +7 -6
  189. data/vendor/libgit2/src/revert.c +6 -2
  190. data/vendor/libgit2/src/revparse.c +14 -9
  191. data/vendor/libgit2/src/revwalk.c +32 -15
  192. data/vendor/libgit2/src/runtime.c +162 -0
  193. data/vendor/libgit2/src/runtime.h +62 -0
  194. data/vendor/libgit2/src/settings.h +11 -0
  195. data/vendor/libgit2/src/signature.c +6 -5
  196. data/vendor/libgit2/src/sortedcache.h +10 -8
  197. data/vendor/libgit2/src/stash.c +3 -1
  198. data/vendor/libgit2/src/status.c +7 -4
  199. data/vendor/libgit2/src/strarray.c +2 -1
  200. data/vendor/libgit2/src/streams/mbedtls.c +14 -17
  201. data/vendor/libgit2/src/streams/mbedtls.h +1 -1
  202. data/vendor/libgit2/src/streams/openssl.c +101 -201
  203. data/vendor/libgit2/src/streams/openssl.h +9 -1
  204. data/vendor/libgit2/src/streams/openssl_dynamic.c +309 -0
  205. data/vendor/libgit2/src/streams/openssl_dynamic.h +348 -0
  206. data/vendor/libgit2/src/streams/openssl_legacy.c +203 -0
  207. data/vendor/libgit2/src/streams/openssl_legacy.h +63 -0
  208. data/vendor/libgit2/src/streams/registry.c +5 -6
  209. data/vendor/libgit2/src/streams/socket.c +6 -2
  210. data/vendor/libgit2/src/streams/stransport.c +6 -3
  211. data/vendor/libgit2/src/streams/tls.c +5 -3
  212. data/vendor/libgit2/src/submodule.c +128 -62
  213. data/vendor/libgit2/src/submodule.h +9 -9
  214. data/vendor/libgit2/src/sysdir.c +4 -6
  215. data/vendor/libgit2/src/tag.c +47 -11
  216. data/vendor/libgit2/src/thread.c +140 -0
  217. data/vendor/libgit2/src/thread.h +479 -0
  218. data/vendor/libgit2/src/threadstate.c +83 -0
  219. data/vendor/libgit2/src/threadstate.h +24 -0
  220. data/vendor/libgit2/src/trace.c +2 -2
  221. data/vendor/libgit2/src/trace.h +17 -13
  222. data/vendor/libgit2/src/transaction.c +19 -8
  223. data/vendor/libgit2/src/transport.c +3 -3
  224. data/vendor/libgit2/src/transports/auth.c +1 -1
  225. data/vendor/libgit2/src/transports/auth_negotiate.c +11 -4
  226. data/vendor/libgit2/src/transports/auth_ntlm.c +10 -6
  227. data/vendor/libgit2/src/transports/credential.c +15 -7
  228. data/vendor/libgit2/src/transports/git.c +1 -3
  229. data/vendor/libgit2/src/transports/http.c +19 -17
  230. data/vendor/libgit2/src/transports/http.h +1 -0
  231. data/vendor/libgit2/src/transports/httpclient.c +53 -26
  232. data/vendor/libgit2/src/transports/httpclient.h +1 -1
  233. data/vendor/libgit2/src/transports/local.c +3 -3
  234. data/vendor/libgit2/src/transports/smart.c +12 -7
  235. data/vendor/libgit2/src/transports/smart.h +1 -1
  236. data/vendor/libgit2/src/transports/smart_protocol.c +11 -5
  237. data/vendor/libgit2/src/transports/ssh.c +51 -17
  238. data/vendor/libgit2/src/transports/winhttp.c +41 -31
  239. data/vendor/libgit2/src/tree.c +100 -77
  240. data/vendor/libgit2/src/tree.h +1 -0
  241. data/vendor/libgit2/src/tsort.c +0 -2
  242. data/vendor/libgit2/src/unix/map.c +3 -1
  243. data/vendor/libgit2/src/unix/pthread.h +2 -1
  244. data/vendor/libgit2/src/utf8.c +150 -0
  245. data/vendor/libgit2/src/utf8.h +52 -0
  246. data/vendor/libgit2/src/util.c +53 -129
  247. data/vendor/libgit2/src/util.h +33 -39
  248. data/vendor/libgit2/src/vector.c +23 -19
  249. data/vendor/libgit2/src/vector.h +4 -2
  250. data/vendor/libgit2/src/win32/findfile.c +4 -2
  251. data/vendor/libgit2/src/win32/map.c +1 -1
  252. data/vendor/libgit2/src/win32/msvc-compat.h +9 -1
  253. data/vendor/libgit2/src/win32/path_w32.c +22 -24
  254. data/vendor/libgit2/src/win32/path_w32.h +0 -1
  255. data/vendor/libgit2/src/win32/posix_w32.c +7 -1
  256. data/vendor/libgit2/src/win32/precompiled.h +0 -1
  257. data/vendor/libgit2/src/win32/reparse.h +4 -4
  258. data/vendor/libgit2/src/win32/thread.c +24 -15
  259. data/vendor/libgit2/src/win32/thread.h +1 -1
  260. data/vendor/libgit2/src/win32/w32_buffer.c +3 -3
  261. data/vendor/libgit2/src/win32/w32_common.h +18 -9
  262. data/vendor/libgit2/src/win32/{w32_crtdbg_stacktrace.c → w32_leakcheck.c} +269 -33
  263. data/vendor/libgit2/src/win32/w32_leakcheck.h +222 -0
  264. data/vendor/libgit2/src/win32/w32_util.h +6 -6
  265. data/vendor/libgit2/src/worktree.c +27 -16
  266. data/vendor/libgit2/src/zstream.c +1 -1
  267. metadata +32 -16
  268. data/vendor/libgit2/src/allocators/win32_crtdbg.c +0 -118
  269. data/vendor/libgit2/src/buf_text.c +0 -316
  270. data/vendor/libgit2/src/buf_text.h +0 -122
  271. data/vendor/libgit2/src/global.c +0 -363
  272. data/vendor/libgit2/src/global.h +0 -41
  273. data/vendor/libgit2/src/thread-utils.c +0 -58
  274. data/vendor/libgit2/src/thread-utils.h +0 -369
  275. data/vendor/libgit2/src/win32/w32_crtdbg_stacktrace.h +0 -127
  276. data/vendor/libgit2/src/win32/w32_stack.c +0 -188
  277. data/vendor/libgit2/src/win32/w32_stack.h +0 -140
@@ -17,12 +17,34 @@
17
17
  * } git_buf;
18
18
  */
19
19
 
20
+ typedef enum {
21
+ GIT_BUF_BOM_NONE = 0,
22
+ GIT_BUF_BOM_UTF8 = 1,
23
+ GIT_BUF_BOM_UTF16_LE = 2,
24
+ GIT_BUF_BOM_UTF16_BE = 3,
25
+ GIT_BUF_BOM_UTF32_LE = 4,
26
+ GIT_BUF_BOM_UTF32_BE = 5
27
+ } git_buf_bom_t;
28
+
29
+ typedef struct {
30
+ git_buf_bom_t bom; /* BOM found at head of text */
31
+ unsigned int nul, cr, lf, crlf; /* NUL, CR, LF and CRLF counts */
32
+ unsigned int printable, nonprintable; /* These are just approximations! */
33
+ } git_buf_text_stats;
34
+
20
35
  extern char git_buf__initbuf[];
21
36
  extern char git_buf__oom[];
22
37
 
23
38
  /* Use to initialize buffer structure when git_buf is on stack */
24
39
  #define GIT_BUF_INIT { git_buf__initbuf, 0, 0 }
25
40
 
41
+ /**
42
+ * Static initializer for git_buf from static buffer
43
+ */
44
+ #ifdef GIT_DEPRECATE_HARD
45
+ # define GIT_BUF_INIT_CONST(STR,LEN) { (char *)(STR), 0, (size_t)(LEN) }
46
+ #endif
47
+
26
48
  GIT_INLINE(bool) git_buf_is_allocated(const git_buf *buf)
27
49
  {
28
50
  return (buf->ptr != NULL && buf->asize > 0);
@@ -36,6 +58,33 @@ GIT_INLINE(bool) git_buf_is_allocated(const git_buf *buf)
36
58
  */
37
59
  extern int git_buf_init(git_buf *buf, size_t initial_size);
38
60
 
61
+ #ifdef GIT_DEPRECATE_HARD
62
+
63
+ /**
64
+ * Resize the buffer allocation to make more space.
65
+ *
66
+ * This will attempt to grow the buffer to accommodate the target size.
67
+ *
68
+ * If the buffer refers to memory that was not allocated by libgit2 (i.e.
69
+ * the `asize` field is zero), then `ptr` will be replaced with a newly
70
+ * allocated block of data. Be careful so that memory allocated by the
71
+ * caller is not lost. As a special variant, if you pass `target_size` as
72
+ * 0 and the memory is not allocated by libgit2, this will allocate a new
73
+ * buffer of size `size` and copy the external data into it.
74
+ *
75
+ * Currently, this will never shrink a buffer, only expand it.
76
+ *
77
+ * If the allocation fails, this will return an error and the buffer will be
78
+ * marked as invalid for future operations, invaliding the contents.
79
+ *
80
+ * @param buffer The buffer to be resized; may or may not be allocated yet
81
+ * @param target_size The desired available size
82
+ * @return 0 on success, -1 on allocation failure
83
+ */
84
+ int git_buf_grow(git_buf *buffer, size_t target_size);
85
+
86
+ #endif
87
+
39
88
  /**
40
89
  * Resize the buffer allocation to make more space.
41
90
  *
@@ -69,7 +118,7 @@ extern int git_buf_try_grow(
69
118
  * git_buf__initbuf. If a buffer with a non-NULL ptr is passed in, this method
70
119
  * assures that the buffer is '\0'-terminated.
71
120
  */
72
- extern void git_buf_sanitize(git_buf *buf);
121
+ extern int git_buf_sanitize(git_buf *buf);
73
122
 
74
123
  extern void git_buf_swap(git_buf *buf_a, git_buf *buf_b);
75
124
  extern char *git_buf_detach(git_buf *buf);
@@ -105,6 +154,11 @@ GIT_INLINE(bool) git_buf_oom(const git_buf *buf)
105
154
  * return code of these functions and call them in a series then just call
106
155
  * git_buf_oom at the end.
107
156
  */
157
+
158
+ #ifdef GIT_DEPRECATE_HARD
159
+ int git_buf_set(git_buf *buffer, const void *data, size_t datalen);
160
+ #endif
161
+
108
162
  int git_buf_sets(git_buf *buf, const char *string);
109
163
  int git_buf_putc(git_buf *buf, char c);
110
164
  int git_buf_putcn(git_buf *buf, char c, size_t len);
@@ -145,7 +199,7 @@ GIT_INLINE(size_t) git_buf_len(const git_buf *buf)
145
199
  return buf->size;
146
200
  }
147
201
 
148
- void git_buf_copy_cstr(char *data, size_t datasize, const git_buf *buf);
202
+ int git_buf_copy_cstr(char *data, size_t datasize, const git_buf *buf);
149
203
 
150
204
  #define git_buf_PUTS(buf, str) git_buf_put(buf, str, sizeof(str) - 1)
151
205
 
@@ -219,4 +273,101 @@ int git_buf_splice(
219
273
  const char *data,
220
274
  size_t nb_to_insert);
221
275
 
276
+ /**
277
+ * Append string to buffer, prefixing each character from `esc_chars` with
278
+ * `esc_with` string.
279
+ *
280
+ * @param buf Buffer to append data to
281
+ * @param string String to escape and append
282
+ * @param esc_chars Characters to be escaped
283
+ * @param esc_with String to insert in from of each found character
284
+ * @return 0 on success, <0 on failure (probably allocation problem)
285
+ */
286
+ extern int git_buf_puts_escaped(
287
+ git_buf *buf,
288
+ const char *string,
289
+ const char *esc_chars,
290
+ const char *esc_with);
291
+
292
+ /**
293
+ * Append string escaping characters that are regex special
294
+ */
295
+ GIT_INLINE(int) git_buf_puts_escape_regex(git_buf *buf, const char *string)
296
+ {
297
+ return git_buf_puts_escaped(buf, string, "^.[]$()|*+?{}\\", "\\");
298
+ }
299
+
300
+ /**
301
+ * Unescape all characters in a buffer in place
302
+ *
303
+ * I.e. remove backslashes
304
+ */
305
+ extern void git_buf_unescape(git_buf *buf);
306
+
307
+ /**
308
+ * Replace all \r\n with \n.
309
+ *
310
+ * @return 0 on success, -1 on memory error
311
+ */
312
+ extern int git_buf_crlf_to_lf(git_buf *tgt, const git_buf *src);
313
+
314
+ /**
315
+ * Replace all \n with \r\n. Does not modify existing \r\n.
316
+ *
317
+ * @return 0 on success, -1 on memory error
318
+ */
319
+ extern int git_buf_lf_to_crlf(git_buf *tgt, const git_buf *src);
320
+
321
+ /**
322
+ * Fill buffer with the common prefix of a array of strings
323
+ *
324
+ * Buffer will be set to empty if there is no common prefix
325
+ */
326
+ extern int git_buf_common_prefix(git_buf *buf, const git_strarray *strs);
327
+
328
+ /**
329
+ * Check if a buffer begins with a UTF BOM
330
+ *
331
+ * @param bom Set to the type of BOM detected or GIT_BOM_NONE
332
+ * @param buf Buffer in which to check the first bytes for a BOM
333
+ * @return Number of bytes of BOM data (or 0 if no BOM found)
334
+ */
335
+ extern int git_buf_detect_bom(git_buf_bom_t *bom, const git_buf *buf);
336
+
337
+ /**
338
+ * Gather stats for a piece of text
339
+ *
340
+ * Fill the `stats` structure with counts of unreadable characters, carriage
341
+ * returns, etc, so it can be used in heuristics. This automatically skips
342
+ * a trailing EOF (\032 character). Also it will look for a BOM at the
343
+ * start of the text and can be told to skip that as well.
344
+ *
345
+ * @param stats Structure to be filled in
346
+ * @param buf Text to process
347
+ * @param skip_bom Exclude leading BOM from stats if true
348
+ * @return Does the buffer heuristically look like binary data
349
+ */
350
+ extern bool git_buf_gather_text_stats(
351
+ git_buf_text_stats *stats, const git_buf *buf, bool skip_bom);
352
+
353
+ #ifdef GIT_DEPRECATE_HARD
354
+
355
+ /**
356
+ * Check quickly if buffer looks like it contains binary data
357
+ *
358
+ * @param buf Buffer to check
359
+ * @return 1 if buffer looks like non-text data
360
+ */
361
+ int git_buf_is_binary(const git_buf *buf);
362
+
363
+ /**
364
+ * Check quickly if buffer contains a NUL byte
365
+ *
366
+ * @param buf Buffer to check
367
+ * @return 1 if buffer contains a NUL byte
368
+ */
369
+ int git_buf_contains_nul(const git_buf *buf);
370
+
371
+ #endif
372
+
222
373
  #endif
@@ -9,7 +9,7 @@
9
9
 
10
10
  #include "repository.h"
11
11
  #include "commit.h"
12
- #include "thread-utils.h"
12
+ #include "thread.h"
13
13
  #include "util.h"
14
14
  #include "odb.h"
15
15
  #include "object.h"
@@ -235,7 +235,7 @@ void git_cached_obj_decref(void *_obj)
235
235
  {
236
236
  git_cached_obj *obj = _obj;
237
237
 
238
- if (git_atomic_dec(&obj->refcount) == 0) {
238
+ if (git_atomic32_dec(&obj->refcount) == 0) {
239
239
  switch (obj->flags) {
240
240
  case GIT_CACHE_STORE_RAW:
241
241
  git_odb_object__free(_obj);
@@ -13,7 +13,7 @@
13
13
  #include "git2/oid.h"
14
14
  #include "git2/odb.h"
15
15
 
16
- #include "thread-utils.h"
16
+ #include "thread.h"
17
17
  #include "oidmap.h"
18
18
 
19
19
  enum {
@@ -23,11 +23,11 @@ enum {
23
23
  };
24
24
 
25
25
  typedef struct {
26
- git_oid oid;
27
- int16_t type; /* git_object_t value */
28
- uint16_t flags; /* GIT_CACHE_STORE value */
29
- size_t size;
30
- git_atomic refcount;
26
+ git_oid oid;
27
+ int16_t type; /* git_object_t value */
28
+ uint16_t flags; /* GIT_CACHE_STORE value */
29
+ size_t size;
30
+ git_atomic32 refcount;
31
31
  } git_cached_obj;
32
32
 
33
33
  typedef struct {
@@ -61,7 +61,7 @@ GIT_INLINE(size_t) git_cache_size(git_cache *cache)
61
61
  GIT_INLINE(void) git_cached_obj_incref(void *_obj)
62
62
  {
63
63
  git_cached_obj *obj = _obj;
64
- git_atomic_inc(&obj->refcount);
64
+ git_atomic32_inc(&obj->refcount);
65
65
  }
66
66
 
67
67
  void git_cached_obj_decref(void *_obj);
@@ -43,9 +43,17 @@
43
43
  # define GIT_ALIGN(x,size) x
44
44
  #endif
45
45
 
46
- #define GIT_UNUSED(x) ((void)(x))
46
+ #if defined(__GNUC__)
47
+ # define GIT_UNUSED(x) \
48
+ do { \
49
+ typeof(x) _unused __attribute__((unused)); \
50
+ _unused = (x); \
51
+ } while (0)
52
+ #else
53
+ # define GIT_UNUSED(x) ((void)(x))
54
+ #endif
47
55
 
48
- /* Define the printf format specifer to use for size_t output */
56
+ /* Define the printf format specifier to use for size_t output */
49
57
  #if defined(_MSC_VER) || defined(__MINGW32__)
50
58
 
51
59
  /* Visual Studio 2012 and prior lack PRId64 entirely */
@@ -26,7 +26,6 @@
26
26
  #include "diff.h"
27
27
  #include "diff_generate.h"
28
28
  #include "pathspec.h"
29
- #include "buf_text.h"
30
29
  #include "diff_xdiff.h"
31
30
  #include "path.h"
32
31
  #include "attr.h"
@@ -329,6 +328,9 @@ static int checkout_target_fullpath(
329
328
  if (path && git_buf_puts(&data->target_path, path) < 0)
330
329
  return -1;
331
330
 
331
+ if (git_path_validate_workdir_buf(data->repo, &data->target_path) < 0)
332
+ return -1;
333
+
332
334
  *out = &data->target_path;
333
335
 
334
336
  return 0;
@@ -1243,7 +1245,7 @@ static int checkout_conflict_append_remove(
1243
1245
  checkout_data *data = payload;
1244
1246
  const char *name;
1245
1247
 
1246
- assert(ancestor || ours || theirs);
1248
+ GIT_ASSERT_ARG(ancestor || ours || theirs);
1247
1249
 
1248
1250
  if (ancestor)
1249
1251
  name = git__strdup(ancestor->path);
@@ -1278,14 +1280,14 @@ static int checkout_verify_paths(
1278
1280
  unsigned int flags = GIT_PATH_REJECT_WORKDIR_DEFAULTS;
1279
1281
 
1280
1282
  if (action & CHECKOUT_ACTION__REMOVE) {
1281
- if (!git_path_isvalid(repo, delta->old_file.path, delta->old_file.mode, flags)) {
1283
+ if (!git_path_validate(repo, delta->old_file.path, delta->old_file.mode, flags)) {
1282
1284
  git_error_set(GIT_ERROR_CHECKOUT, "cannot remove invalid path '%s'", delta->old_file.path);
1283
1285
  return -1;
1284
1286
  }
1285
1287
  }
1286
1288
 
1287
1289
  if (action & ~CHECKOUT_ACTION__REMOVE) {
1288
- if (!git_path_isvalid(repo, delta->new_file.path, delta->new_file.mode, flags)) {
1290
+ if (!git_path_validate(repo, delta->new_file.path, delta->new_file.mode, flags)) {
1289
1291
  git_error_set(GIT_ERROR_CHECKOUT, "cannot checkout to invalid path '%s'", delta->new_file.path);
1290
1292
  return -1;
1291
1293
  }
@@ -1487,7 +1489,9 @@ static int checkout_stream_write(
1487
1489
  static int checkout_stream_close(git_writestream *s)
1488
1490
  {
1489
1491
  struct checkout_stream *stream = (struct checkout_stream *)s;
1490
- assert(stream && stream->open);
1492
+
1493
+ GIT_ASSERT_ARG(stream);
1494
+ GIT_ASSERT_ARG(stream->open);
1491
1495
 
1492
1496
  stream->open = 0;
1493
1497
  return p_close(stream->fd);
@@ -1509,7 +1513,7 @@ static int blob_content_to_file(
1509
1513
  int flags = data->opts.file_open_flags;
1510
1514
  mode_t file_mode = data->opts.file_mode ?
1511
1515
  data->opts.file_mode : entry_filemode;
1512
- git_filter_options filter_opts = GIT_FILTER_OPTIONS_INIT;
1516
+ git_filter_session filter_session = GIT_FILTER_SESSION_INIT;
1513
1517
  struct checkout_stream writer;
1514
1518
  mode_t mode;
1515
1519
  git_filter_list *fl = NULL;
@@ -1532,13 +1536,13 @@ static int blob_content_to_file(
1532
1536
  return fd;
1533
1537
  }
1534
1538
 
1535
- filter_opts.attr_session = &data->attr_session;
1536
- filter_opts.temp_buf = &data->tmp;
1539
+ filter_session.attr_session = &data->attr_session;
1540
+ filter_session.temp_buf = &data->tmp;
1537
1541
 
1538
1542
  if (!data->opts.disable_filters &&
1539
- (error = git_filter_list__load_ext(
1543
+ (error = git_filter_list__load(
1540
1544
  &fl, data->repo, blob, hint_path,
1541
- GIT_FILTER_TO_WORKTREE, &filter_opts))) {
1545
+ GIT_FILTER_TO_WORKTREE, &filter_session))) {
1542
1546
  p_close(fd);
1543
1547
  return error;
1544
1548
  }
@@ -1554,7 +1558,7 @@ static int blob_content_to_file(
1554
1558
 
1555
1559
  error = git_filter_list_stream_blob(fl, blob, &writer.base);
1556
1560
 
1557
- assert(writer.open == 0);
1561
+ GIT_ASSERT(writer.open == 0);
1558
1562
 
1559
1563
  git_filter_list_free(fl);
1560
1564
 
@@ -1976,7 +1980,7 @@ static int checkout_write_entry(
1976
1980
  struct stat st;
1977
1981
  int error;
1978
1982
 
1979
- assert (side == conflict->ours || side == conflict->theirs);
1983
+ GIT_ASSERT(side == conflict->ours || side == conflict->theirs);
1980
1984
 
1981
1985
  if (checkout_target_fullpath(&fullpath, data, side->path) < 0)
1982
1986
  return -1;
@@ -2030,7 +2034,8 @@ static int checkout_merge_path(
2030
2034
  const char *our_label_raw, *their_label_raw, *suffix;
2031
2035
  int error = 0;
2032
2036
 
2033
- if ((error = git_buf_joinpath(out, git_repository_workdir(data->repo), result->path)) < 0)
2037
+ if ((error = git_buf_joinpath(out, data->opts.target_directory, result->path)) < 0 ||
2038
+ (error = git_path_validate_workdir_buf(data->repo, out)) < 0)
2034
2039
  return error;
2035
2040
 
2036
2041
  /* Most conflicts simply use the filename in the index */
@@ -2059,7 +2064,7 @@ static int checkout_write_merge(
2059
2064
  git_merge_file_result result = {0};
2060
2065
  git_filebuf output = GIT_FILEBUF_INIT;
2061
2066
  git_filter_list *fl = NULL;
2062
- git_filter_options filter_opts = GIT_FILTER_OPTIONS_INIT;
2067
+ git_filter_session filter_session = GIT_FILTER_SESSION_INIT;
2063
2068
  int error = 0;
2064
2069
 
2065
2070
  if (data->opts.checkout_strategy & GIT_CHECKOUT_CONFLICT_STYLE_DIFF3)
@@ -2109,13 +2114,13 @@ static int checkout_write_merge(
2109
2114
  in_data.ptr = (char *)result.ptr;
2110
2115
  in_data.size = result.len;
2111
2116
 
2112
- filter_opts.attr_session = &data->attr_session;
2113
- filter_opts.temp_buf = &data->tmp;
2117
+ filter_session.attr_session = &data->attr_session;
2118
+ filter_session.temp_buf = &data->tmp;
2114
2119
 
2115
- if ((error = git_filter_list__load_ext(
2120
+ if ((error = git_filter_list__load(
2116
2121
  &fl, data->repo, NULL, git_buf_cstr(&path_workdir),
2117
- GIT_FILTER_TO_WORKTREE, &filter_opts)) < 0 ||
2118
- (error = git_filter_list_apply_to_data(&out_data, fl, &in_data)) < 0)
2122
+ GIT_FILTER_TO_WORKTREE, &filter_session)) < 0 ||
2123
+ (error = git_filter_list__convert_buf(&out_data, fl, &in_data)) < 0)
2119
2124
  goto done;
2120
2125
  } else {
2121
2126
  out_data.ptr = (char *)result.ptr;
@@ -2329,6 +2334,22 @@ static void checkout_data_clear(checkout_data *data)
2329
2334
  git_attr_session__free(&data->attr_session);
2330
2335
  }
2331
2336
 
2337
+ static int validate_target_directory(checkout_data *data)
2338
+ {
2339
+ int error;
2340
+
2341
+ if ((error = git_path_validate_workdir(data->repo, data->opts.target_directory)) < 0)
2342
+ return error;
2343
+
2344
+ if (git_path_isdir(data->opts.target_directory))
2345
+ return 0;
2346
+
2347
+ error = checkout_mkdir(data, data->opts.target_directory, NULL,
2348
+ GIT_DIR_MODE, GIT_MKDIR_VERIFY_DIR);
2349
+
2350
+ return error;
2351
+ }
2352
+
2332
2353
  static int checkout_data_init(
2333
2354
  checkout_data *data,
2334
2355
  git_iterator *target,
@@ -2361,10 +2382,7 @@ static int checkout_data_init(
2361
2382
 
2362
2383
  if (!data->opts.target_directory)
2363
2384
  data->opts.target_directory = git_repository_workdir(repo);
2364
- else if (!git_path_isdir(data->opts.target_directory) &&
2365
- (error = checkout_mkdir(data,
2366
- data->opts.target_directory, NULL,
2367
- GIT_DIR_MODE, GIT_MKDIR_VERIFY_DIR)) < 0)
2385
+ else if ((error = validate_target_directory(data)) < 0)
2368
2386
  goto cleanup;
2369
2387
 
2370
2388
  if ((error = git_repository_index(&data->index, data->repo)) < 0)
@@ -2588,7 +2606,7 @@ int git_checkout_iterator(
2588
2606
  }
2589
2607
 
2590
2608
  /* Should not have case insensitivity mismatch */
2591
- assert(git_iterator_ignore_case(workdir) == git_iterator_ignore_case(baseline));
2609
+ GIT_ASSERT(git_iterator_ignore_case(workdir) == git_iterator_ignore_case(baseline));
2592
2610
 
2593
2611
  /* Generate baseline-to-target diff which will include an entry for
2594
2612
  * every possible update that might need to be made.
@@ -2604,6 +2622,9 @@ int git_checkout_iterator(
2604
2622
  if ((error = checkout_get_actions(&actions, &counts, &data, workdir)) != 0)
2605
2623
  goto cleanup;
2606
2624
 
2625
+ if (data.strategy & GIT_CHECKOUT_DRY_RUN)
2626
+ goto cleanup;
2627
+
2607
2628
  data.total_steps = counts[CHECKOUT_ACTION__REMOVE] +
2608
2629
  counts[CHECKOUT_ACTION__REMOVE_CONFLICT] +
2609
2630
  counts[CHECKOUT_ACTION__UPDATE_BLOB] +
@@ -2639,7 +2660,7 @@ int git_checkout_iterator(
2639
2660
  (error = checkout_extensions_update_index(&data)) < 0)
2640
2661
  goto cleanup;
2641
2662
 
2642
- assert(data.completed_steps == data.total_steps);
2663
+ GIT_ASSERT(data.completed_steps == data.total_steps);
2643
2664
 
2644
2665
  if (data.opts.perfdata_cb)
2645
2666
  data.opts.perfdata_cb(&data.perfdata, data.opts.perfdata_payload);
@@ -2767,7 +2788,8 @@ int git_checkout_head(
2767
2788
  git_repository *repo,
2768
2789
  const git_checkout_options *opts)
2769
2790
  {
2770
- assert(repo);
2791
+ GIT_ASSERT_ARG(repo);
2792
+
2771
2793
  return git_checkout_tree(repo, NULL, opts);
2772
2794
  }
2773
2795