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
@@ -83,4 +83,22 @@ extern char *git_win32_path_8dot3_name(const char *path);
83
83
 
84
84
  extern int git_win32_path_readlink_w(git_win32_path dest, const git_win32_path path);
85
85
 
86
+ /**
87
+ * Removes any trailing backslashes from a path, except in the case of a drive
88
+ * letter path (C:\, D:\, etc.). This function cannot fail.
89
+ *
90
+ * @param path The path which should be trimmed.
91
+ * @return The length of the modified string (<= the input length)
92
+ */
93
+ size_t git_win32_path_trim_end(wchar_t *str, size_t len);
94
+
95
+ /**
96
+ * Removes any of the following namespace prefixes from a path,
97
+ * if found: "\??\", "\\?\", "\\?\UNC\". This function cannot fail.
98
+ *
99
+ * @param path The path which should be converted.
100
+ * @return The length of the modified string (<= the input length)
101
+ */
102
+ size_t git_win32_path_remove_namespace(wchar_t *str, size_t len);
103
+
86
104
  #endif
@@ -29,15 +29,16 @@
29
29
  #define IO_REPARSE_TAG_SYMLINK (0xA000000CL)
30
30
  #endif
31
31
 
32
+ #ifndef SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE
33
+ # define SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE 0x02
34
+ #endif
35
+
32
36
  /* Allowable mode bits on Win32. Using mode bits that are not supported on
33
37
  * Win32 (eg S_IRWXU) is generally ignored, but Wine warns loudly about it
34
38
  * so we simply remove them.
35
39
  */
36
40
  #define WIN32_MODE_MASK (_S_IREAD | _S_IWRITE)
37
41
 
38
- /* GetFinalPathNameByHandleW signature */
39
- typedef DWORD(WINAPI *PFGetFinalPathNameByHandleW)(HANDLE, LPWSTR, DWORD, DWORD);
40
-
41
42
  unsigned long git_win32__createfile_sharemode =
42
43
  FILE_SHARE_READ | FILE_SHARE_WRITE;
43
44
  int git_win32__retries = 10;
@@ -354,7 +355,7 @@ static int do_lstat(const char *path, struct stat *buf, bool posixly_correct)
354
355
  if ((len = git_win32_path_from_utf8(path_w, path)) < 0)
355
356
  return -1;
356
357
 
357
- git_win32__path_trim_end(path_w, len);
358
+ git_win32_path_trim_end(path_w, len);
358
359
 
359
360
  return lstat_w(path_w, buf, posixly_correct);
360
361
  }
@@ -393,12 +394,19 @@ int p_readlink(const char *path, char *buf, size_t bufsiz)
393
394
  return (int)bufsiz;
394
395
  }
395
396
 
396
- int p_symlink(const char *old, const char *new)
397
+ int p_symlink(const char *target, const char *path)
397
398
  {
398
- /* Real symlinks on NTFS require admin privileges. Until this changes,
399
- * libgit2 just creates a text file with the link target in the contents.
400
- */
401
- return git_futils_fake_symlink(old, new);
399
+ git_win32_path target_w, path_w;
400
+
401
+ if (git_win32_path_from_utf8(path_w, path) < 0 ||
402
+ git__utf8_to_16(target_w, MAX_PATH, target) < 0)
403
+ return -1;
404
+
405
+ if (!CreateSymbolicLinkW(path_w, target_w,
406
+ SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE))
407
+ return -1;
408
+
409
+ return 0;
402
410
  }
403
411
 
404
412
  struct open_opts {
@@ -524,7 +532,7 @@ int p_utimes(const char *path, const struct p_timeval times[2])
524
532
  attrs_new = attrs_orig & ~FILE_ATTRIBUTE_READONLY;
525
533
 
526
534
  if (!SetFileAttributesW(wpath, attrs_new)) {
527
- giterr_set(GITERR_OS, "failed to set attributes");
535
+ git_error_set(GIT_ERROR_OS, "failed to set attributes");
528
536
  return -1;
529
537
  }
530
538
  }
@@ -598,40 +606,13 @@ int p_getcwd(char *buffer_out, size_t size)
598
606
  return 0;
599
607
  }
600
608
 
601
- /*
602
- * Returns the address of the GetFinalPathNameByHandleW function.
603
- * This function is available on Windows Vista and higher.
604
- */
605
- static PFGetFinalPathNameByHandleW get_fpnbyhandle(void)
606
- {
607
- static PFGetFinalPathNameByHandleW pFunc = NULL;
608
- PFGetFinalPathNameByHandleW toReturn = pFunc;
609
-
610
- if (!toReturn) {
611
- HMODULE hModule = GetModuleHandleW(L"kernel32");
612
-
613
- if (hModule)
614
- toReturn = (PFGetFinalPathNameByHandleW)GetProcAddress(hModule, "GetFinalPathNameByHandleW");
615
-
616
- pFunc = toReturn;
617
- }
618
-
619
- assert(toReturn);
620
-
621
- return toReturn;
622
- }
623
-
624
609
  static int getfinalpath_w(
625
610
  git_win32_path dest,
626
611
  const wchar_t *path)
627
612
  {
628
- PFGetFinalPathNameByHandleW pgfp = get_fpnbyhandle();
629
613
  HANDLE hFile;
630
614
  DWORD dwChars;
631
615
 
632
- if (!pgfp)
633
- return -1;
634
-
635
616
  /* Use FILE_FLAG_BACKUP_SEMANTICS so we can open a directory. Do not
636
617
  * specify FILE_FLAG_OPEN_REPARSE_POINT; we want to open a handle to the
637
618
  * target of the link. */
@@ -642,14 +623,14 @@ static int getfinalpath_w(
642
623
  return -1;
643
624
 
644
625
  /* Call GetFinalPathNameByHandle */
645
- dwChars = pgfp(hFile, dest, GIT_WIN_PATH_UTF16, FILE_NAME_NORMALIZED);
626
+ dwChars = GetFinalPathNameByHandleW(hFile, dest, GIT_WIN_PATH_UTF16, FILE_NAME_NORMALIZED);
646
627
  CloseHandle(hFile);
647
628
 
648
629
  if (!dwChars || dwChars >= GIT_WIN_PATH_UTF16)
649
630
  return -1;
650
631
 
651
- /* The path may be delivered to us with a prefix; canonicalize */
652
- return (int)git_win32__canonicalize_path(dest, dwChars);
632
+ /* The path may be delivered to us with a namespace prefix; remove */
633
+ return (int)git_win32_path_remove_namespace(dest, dwChars);
653
634
  }
654
635
 
655
636
  static int follow_and_lstat_link(git_win32_path path, struct stat* buf)
@@ -832,7 +813,7 @@ int p_mkstemp(char *tmp_path)
832
813
  return -1;
833
814
  #endif
834
815
 
835
- return p_open(tmp_path, O_RDWR | O_CREAT | O_EXCL, 0744); //-V536
816
+ return p_open(tmp_path, O_RDWR | O_CREAT | O_EXCL, 0744); /* -V536 */
836
817
  }
837
818
 
838
819
  int p_access(const char* path, mode_t mode)
@@ -871,7 +852,7 @@ int p_rename(const char *from, const char *to)
871
852
  int p_recv(GIT_SOCKET socket, void *buffer, size_t length, int flags)
872
853
  {
873
854
  if ((size_t)((int)length) != length)
874
- return -1; /* giterr_set will be done by caller */
855
+ return -1; /* git_error_set will be done by caller */
875
856
 
876
857
  return recv(socket, buffer, (int)length, flags);
877
858
  }
@@ -879,7 +860,7 @@ int p_recv(GIT_SOCKET socket, void *buffer, size_t length, int flags)
879
860
  int p_send(GIT_SOCKET socket, const void *buffer, size_t length, int flags)
880
861
  {
881
862
  if ((size_t)((int)length) != length)
882
- return -1; /* giterr_set will be done by caller */
863
+ return -1; /* git_error_set will be done by caller */
883
864
 
884
865
  return send(socket, buffer, (int)length, flags);
885
866
  }
@@ -36,8 +36,8 @@ int git_buf_put_w(git_buf *buf, const wchar_t *string_w, size_t len_w)
36
36
 
37
37
  assert(utf8_len > 0);
38
38
 
39
- GITERR_CHECK_ALLOC_ADD(&new_size, buf->size, (size_t)utf8_len);
40
- GITERR_CHECK_ALLOC_ADD(&new_size, new_size, 1);
39
+ GIT_ERROR_CHECK_ALLOC_ADD(&new_size, buf->size, (size_t)utf8_len);
40
+ GIT_ERROR_CHECK_ALLOC_ADD(&new_size, new_size, 1);
41
41
 
42
42
  if (git_buf_grow(buf, new_size) < 0)
43
43
  return -1;
@@ -71,6 +71,99 @@ static bool g_limit_reached = false; /* had allocs after we filled row table */
71
71
  static unsigned int g_checkpoint_id = 0; /* to better label leak checkpoints */
72
72
  static bool g_transient_leaks_since_mark = false; /* payload for hook */
73
73
 
74
+ static void *crtdbg__malloc(size_t len, const char *file, int line)
75
+ {
76
+ void *ptr = _malloc_dbg(len, _NORMAL_BLOCK, git_win32__crtdbg_stacktrace(1,file), line);
77
+ if (!ptr) git_error_set_oom();
78
+ return ptr;
79
+ }
80
+
81
+ static void *crtdbg__calloc(size_t nelem, size_t elsize, const char *file, int line)
82
+ {
83
+ void *ptr = _calloc_dbg(nelem, elsize, _NORMAL_BLOCK, git_win32__crtdbg_stacktrace(1,file), line);
84
+ if (!ptr) git_error_set_oom();
85
+ return ptr;
86
+ }
87
+
88
+ static char *crtdbg__strdup(const char *str, const char *file, int line)
89
+ {
90
+ char *ptr = _strdup_dbg(str, _NORMAL_BLOCK, git_win32__crtdbg_stacktrace(1,file), line);
91
+ if (!ptr) git_error_set_oom();
92
+ return ptr;
93
+ }
94
+
95
+ static char *crtdbg__strndup(const char *str, size_t n, const char *file, int line)
96
+ {
97
+ size_t length = 0, alloclength;
98
+ char *ptr;
99
+
100
+ length = p_strnlen(str, n);
101
+
102
+ if (GIT_ADD_SIZET_OVERFLOW(&alloclength, length, 1) ||
103
+ !(ptr = crtdbg__malloc(alloclength, file, line)))
104
+ return NULL;
105
+
106
+ if (length)
107
+ memcpy(ptr, str, length);
108
+
109
+ ptr[length] = '\0';
110
+
111
+ return ptr;
112
+ }
113
+
114
+ static char *crtdbg__substrdup(const char *start, size_t n, const char *file, int line)
115
+ {
116
+ char *ptr;
117
+ size_t alloclen;
118
+
119
+ if (GIT_ADD_SIZET_OVERFLOW(&alloclen, n, 1) ||
120
+ !(ptr = crtdbg__malloc(alloclen, file, line)))
121
+ return NULL;
122
+
123
+ memcpy(ptr, start, n);
124
+ ptr[n] = '\0';
125
+ return ptr;
126
+ }
127
+
128
+ static void *crtdbg__realloc(void *ptr, size_t size, const char *file, int line)
129
+ {
130
+ void *new_ptr = _realloc_dbg(ptr, size, _NORMAL_BLOCK, git_win32__crtdbg_stacktrace(1,file), line);
131
+ if (!new_ptr) git_error_set_oom();
132
+ return new_ptr;
133
+ }
134
+
135
+ static void *crtdbg__reallocarray(void *ptr, size_t nelem, size_t elsize, const char *file, int line)
136
+ {
137
+ size_t newsize;
138
+
139
+ return GIT_MULTIPLY_SIZET_OVERFLOW(&newsize, nelem, elsize) ?
140
+ NULL : _realloc_dbg(ptr, newsize, _NORMAL_BLOCK, git_win32__crtdbg_stacktrace(1,file), line);
141
+ }
142
+
143
+ static void *crtdbg__mallocarray(size_t nelem, size_t elsize, const char *file, int line)
144
+ {
145
+ return crtdbg__reallocarray(NULL, nelem, elsize, file, line);
146
+ }
147
+
148
+ static void crtdbg__free(void *ptr)
149
+ {
150
+ free(ptr);
151
+ }
152
+
153
+ int git_win32_crtdbg_init_allocator(git_allocator *allocator)
154
+ {
155
+ allocator->gmalloc = crtdbg__malloc;
156
+ allocator->gcalloc = crtdbg__calloc;
157
+ allocator->gstrdup = crtdbg__strdup;
158
+ allocator->gstrndup = crtdbg__strndup;
159
+ allocator->gsubstrdup = crtdbg__substrdup;
160
+ allocator->grealloc = crtdbg__realloc;
161
+ allocator->greallocarray = crtdbg__reallocarray;
162
+ allocator->gmallocarray = crtdbg__mallocarray;
163
+ allocator->gfree = crtdbg__free;
164
+ return 0;
165
+ }
166
+
74
167
  /**
75
168
  * Compare function for bsearch on g_cs_index table.
76
169
  */
@@ -254,11 +347,11 @@ int git_win32__crtdbg_stacktrace__dump(
254
347
  bool b_quiet = IS_BIT_SET(opt, GIT_WIN32__CRTDBG_STACKTRACE__QUIET);
255
348
 
256
349
  if (b_leaks_since_mark && b_leaks_total) {
257
- giterr_set(GITERR_INVALID, "cannot combine LEAKS_SINCE_MARK and LEAKS_TOTAL.");
350
+ git_error_set(GIT_ERROR_INVALID, "cannot combine LEAKS_SINCE_MARK and LEAKS_TOTAL.");
258
351
  return GIT_ERROR;
259
352
  }
260
353
  if (!b_set_mark && !b_leaks_since_mark && !b_leaks_total) {
261
- giterr_set(GITERR_INVALID, "nothing to do.");
354
+ git_error_set(GIT_ERROR_INVALID, "nothing to do.");
262
355
  return GIT_ERROR;
263
356
  }
264
357
 
@@ -341,4 +434,5 @@ const char *git_win32__crtdbg_stacktrace(int skip, const char *file)
341
434
 
342
435
  return result;
343
436
  }
437
+
344
438
  #endif
@@ -17,6 +17,34 @@
17
17
  #include "git2/errors.h"
18
18
  #include "strnlen.h"
19
19
 
20
+ /* MSVC CRTDBG memory leak reporting.
21
+ *
22
+ * We DO NOT use the "_CRTDBG_MAP_ALLOC" macro described in the MSVC
23
+ * documentation because all allocs/frees in libgit2 already go through
24
+ * the "git__" routines defined in this file. Simply using the normal
25
+ * reporting mechanism causes all leaks to be attributed to a routine
26
+ * here in util.h (ie, the actual call to calloc()) rather than the
27
+ * caller of git__calloc().
28
+ *
29
+ * Therefore, we declare a set of "git__crtdbg__" routines to replace
30
+ * the corresponding "git__" routines and re-define the "git__" symbols
31
+ * as macros. This allows us to get and report the file:line info of
32
+ * the real caller.
33
+ *
34
+ * We DO NOT replace the "git__free" routine because it needs to remain
35
+ * a function pointer because it is used as a function argument when
36
+ * setting up various structure "destructors".
37
+ *
38
+ * We also DO NOT use the "_CRTDBG_MAP_ALLOC" macro because it causes
39
+ * "free" to be remapped to "_free_dbg" and this causes problems for
40
+ * structures which define a field named "free".
41
+ *
42
+ * Finally, CRTDBG must be explicitly enabled and configured at program
43
+ * startup. See tests/main.c for an example.
44
+ */
45
+
46
+ int git_win32_crtdbg_init_allocator(git_allocator *allocator);
47
+
20
48
  /**
21
49
  * Initialize our memory leak tracking and de-dup data structures.
22
50
  * This should ONLY be called by git_libgit2_init().
@@ -97,80 +125,5 @@ GIT_EXTERN(int) git_win32__crtdbg_stacktrace__dump(
97
125
  */
98
126
  const char *git_win32__crtdbg_stacktrace(int skip, const char *file);
99
127
 
100
- GIT_INLINE(void *) git__crtdbg__malloc(size_t len, const char *file, int line)
101
- {
102
- void *ptr = _malloc_dbg(len, _NORMAL_BLOCK, git_win32__crtdbg_stacktrace(1,file), line);
103
- if (!ptr) giterr_set_oom();
104
- return ptr;
105
- }
106
-
107
- GIT_INLINE(void *) git__crtdbg__calloc(size_t nelem, size_t elsize, const char *file, int line)
108
- {
109
- void *ptr = _calloc_dbg(nelem, elsize, _NORMAL_BLOCK, git_win32__crtdbg_stacktrace(1,file), line);
110
- if (!ptr) giterr_set_oom();
111
- return ptr;
112
- }
113
-
114
- GIT_INLINE(char *) git__crtdbg__strdup(const char *str, const char *file, int line)
115
- {
116
- char *ptr = _strdup_dbg(str, _NORMAL_BLOCK, git_win32__crtdbg_stacktrace(1,file), line);
117
- if (!ptr) giterr_set_oom();
118
- return ptr;
119
- }
120
-
121
- GIT_INLINE(char *) git__crtdbg__strndup(const char *str, size_t n, const char *file, int line)
122
- {
123
- size_t length = 0, alloclength;
124
- char *ptr;
125
-
126
- length = p_strnlen(str, n);
127
-
128
- if (GIT_ADD_SIZET_OVERFLOW(&alloclength, length, 1) ||
129
- !(ptr = git__crtdbg__malloc(alloclength, file, line)))
130
- return NULL;
131
-
132
- if (length)
133
- memcpy(ptr, str, length);
134
-
135
- ptr[length] = '\0';
136
-
137
- return ptr;
138
- }
139
-
140
- GIT_INLINE(char *) git__crtdbg__substrdup(const char *start, size_t n, const char *file, int line)
141
- {
142
- char *ptr;
143
- size_t alloclen;
144
-
145
- if (GIT_ADD_SIZET_OVERFLOW(&alloclen, n, 1) ||
146
- !(ptr = git__crtdbg__malloc(alloclen, file, line)))
147
- return NULL;
148
-
149
- memcpy(ptr, start, n);
150
- ptr[n] = '\0';
151
- return ptr;
152
- }
153
-
154
- GIT_INLINE(void *) git__crtdbg__realloc(void *ptr, size_t size, const char *file, int line)
155
- {
156
- void *new_ptr = _realloc_dbg(ptr, size, _NORMAL_BLOCK, git_win32__crtdbg_stacktrace(1,file), line);
157
- if (!new_ptr) giterr_set_oom();
158
- return new_ptr;
159
- }
160
-
161
- GIT_INLINE(void *) git__crtdbg__reallocarray(void *ptr, size_t nelem, size_t elsize, const char *file, int line)
162
- {
163
- size_t newsize;
164
-
165
- return GIT_MULTIPLY_SIZET_OVERFLOW(&newsize, nelem, elsize) ?
166
- NULL : _realloc_dbg(ptr, newsize, _NORMAL_BLOCK, git_win32__crtdbg_stacktrace(1,file), line);
167
- }
168
-
169
- GIT_INLINE(void *) git__crtdbg__mallocarray(size_t nelem, size_t elsize, const char *file, int line)
170
- {
171
- return git__crtdbg__reallocarray(NULL, nelem, elsize, file, line);
172
- }
173
-
174
-
175
128
  #endif
176
129
  #endif
@@ -55,7 +55,7 @@ void git_win32__stack_cleanup(void)
55
55
  int git_win32__stack_capture(git_win32__stack__raw_data *pdata, int skip)
56
56
  {
57
57
  if (!g_win32_stack_initialized) {
58
- giterr_set(GITERR_INVALID, "git_win32_stack not initialized.");
58
+ git_error_set(GIT_ERROR_INVALID, "git_win32_stack not initialized.");
59
59
  return GIT_ERROR;
60
60
  }
61
61
 
@@ -102,7 +102,7 @@ int git_win32__stack_format(
102
102
  int detail_len;
103
103
 
104
104
  if (!g_win32_stack_initialized) {
105
- giterr_set(GITERR_INVALID, "git_win32_stack not initialized.");
105
+ git_error_set(GIT_ERROR_INVALID, "git_win32_stack not initialized.");
106
106
  return GIT_ERROR;
107
107
  }
108
108
 
@@ -68,7 +68,7 @@ int git_win32__set_hidden(const char *path, bool hidden)
68
68
  newattrs = attrs & ~FILE_ATTRIBUTE_HIDDEN;
69
69
 
70
70
  if (attrs != newattrs && !SetFileAttributesW(buf, newattrs)) {
71
- giterr_set(GITERR_OS, "failed to %s hidden bit for '%s'",
71
+ git_error_set(GIT_ERROR_OS, "failed to %s hidden bit for '%s'",
72
72
  hidden ? "set" : "unset", path);
73
73
  return -1;
74
74
  }
@@ -93,71 +93,3 @@ int git_win32__hidden(bool *out, const char *path)
93
93
  *out = (attrs & FILE_ATTRIBUTE_HIDDEN) ? true : false;
94
94
  return 0;
95
95
  }
96
-
97
- /**
98
- * Removes any trailing backslashes from a path, except in the case of a drive
99
- * letter path (C:\, D:\, etc.). This function cannot fail.
100
- *
101
- * @param path The path which should be trimmed.
102
- * @return The length of the modified string (<= the input length)
103
- */
104
- size_t git_win32__path_trim_end(wchar_t *str, size_t len)
105
- {
106
- while (1) {
107
- if (!len || str[len - 1] != L'\\')
108
- break;
109
-
110
- /* Don't trim backslashes from drive letter paths, which
111
- * are 3 characters long and of the form C:\, D:\, etc. */
112
- if (len == 3 && git_win32__isalpha(str[0]) && str[1] == ':')
113
- break;
114
-
115
- len--;
116
- }
117
-
118
- str[len] = L'\0';
119
-
120
- return len;
121
- }
122
-
123
- /**
124
- * Removes any of the following namespace prefixes from a path,
125
- * if found: "\??\", "\\?\", "\\?\UNC\". This function cannot fail.
126
- *
127
- * @param path The path which should be converted.
128
- * @return The length of the modified string (<= the input length)
129
- */
130
- size_t git_win32__canonicalize_path(wchar_t *str, size_t len)
131
- {
132
- static const wchar_t dosdevices_prefix[] = L"\\\?\?\\";
133
- static const wchar_t nt_prefix[] = L"\\\\?\\";
134
- static const wchar_t unc_prefix[] = L"UNC\\";
135
- size_t to_advance = 0;
136
-
137
- /* "\??\" -- DOS Devices prefix */
138
- if (len >= CONST_STRLEN(dosdevices_prefix) &&
139
- !wcsncmp(str, dosdevices_prefix, CONST_STRLEN(dosdevices_prefix))) {
140
- to_advance += CONST_STRLEN(dosdevices_prefix);
141
- len -= CONST_STRLEN(dosdevices_prefix);
142
- }
143
- /* "\\?\" -- NT namespace prefix */
144
- else if (len >= CONST_STRLEN(nt_prefix) &&
145
- !wcsncmp(str, nt_prefix, CONST_STRLEN(nt_prefix))) {
146
- to_advance += CONST_STRLEN(nt_prefix);
147
- len -= CONST_STRLEN(nt_prefix);
148
- }
149
-
150
- /* "\??\UNC\", "\\?\UNC\" -- UNC prefix */
151
- if (to_advance && len >= CONST_STRLEN(unc_prefix) &&
152
- !wcsncmp(str + to_advance, unc_prefix, CONST_STRLEN(unc_prefix))) {
153
- to_advance += CONST_STRLEN(unc_prefix);
154
- len -= CONST_STRLEN(unc_prefix);
155
- }
156
-
157
- if (to_advance) {
158
- memmove(str, str + to_advance, len * sizeof(wchar_t));
159
- str[len] = L'\0';
160
- }
161
-
162
- return git_win32__path_trim_end(str, len);
163
- }