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
@@ -66,7 +66,7 @@ struct pack_chain_elem {
66
66
  git_off_t base_key;
67
67
  git_off_t offset;
68
68
  size_t size;
69
- git_otype type;
69
+ git_object_t type;
70
70
  };
71
71
 
72
72
  typedef git_array_t(struct pack_chain_elem) git_dependency_chain;
@@ -123,20 +123,20 @@ typedef struct git_packfile_stream {
123
123
  git_mwindow *mw;
124
124
  } git_packfile_stream;
125
125
 
126
- size_t git_packfile__object_header(unsigned char *hdr, size_t size, git_otype type);
126
+ size_t git_packfile__object_header(unsigned char *hdr, size_t size, git_object_t type);
127
127
 
128
128
  int git_packfile__name(char **out, const char *path);
129
129
 
130
130
  int git_packfile_unpack_header(
131
131
  size_t *size_p,
132
- git_otype *type_p,
132
+ git_object_t *type_p,
133
133
  git_mwindow_file *mwf,
134
134
  git_mwindow **w_curs,
135
135
  git_off_t *curpos);
136
136
 
137
137
  int git_packfile_resolve_header(
138
138
  size_t *size_p,
139
- git_otype *type_p,
139
+ git_object_t *type_p,
140
140
  struct git_pack_file *p,
141
141
  git_off_t offset);
142
142
 
@@ -144,10 +144,10 @@ int git_packfile_unpack(git_rawobj *obj, struct git_pack_file *p, git_off_t *obj
144
144
 
145
145
  int git_packfile_stream_open(git_packfile_stream *obj, struct git_pack_file *p, git_off_t curpos);
146
146
  ssize_t git_packfile_stream_read(git_packfile_stream *obj, void *buffer, size_t len);
147
- void git_packfile_stream_free(git_packfile_stream *obj);
147
+ void git_packfile_stream_dispose(git_packfile_stream *obj);
148
148
 
149
149
  git_off_t get_delta_base(struct git_pack_file *p, git_mwindow **w_curs,
150
- git_off_t *curpos, git_otype type,
150
+ git_off_t *curpos, git_object_t type,
151
151
  git_off_t delta_obj_offset);
152
152
 
153
153
  void git_packfile_close(struct git_pack_file *p, bool unlink_packfile);
@@ -27,7 +27,7 @@ int git_parse_ctx_init(git_parse_ctx *ctx, const char *content, size_t content_l
27
27
  void git_parse_ctx_clear(git_parse_ctx *ctx);
28
28
 
29
29
  #define git_parse_err(...) \
30
- ( giterr_set(GITERR_PATCH, __VA_ARGS__), -1 )
30
+ ( git_error_set(GIT_ERROR_PATCH, __VA_ARGS__), -1 )
31
31
 
32
32
  #define git_parse_ctx_contains_s(ctx, str) \
33
33
  git_parse_ctx_contains(ctx, str, sizeof(str) - 1)
@@ -80,11 +80,11 @@ size_t git_patch_size(
80
80
 
81
81
  if (git_diff_delta__format_file_header(
82
82
  &file_header, patch->delta, NULL, NULL, 0) < 0)
83
- giterr_clear();
83
+ git_error_clear();
84
84
  else
85
85
  out += git_buf_len(&file_header);
86
86
 
87
- git_buf_free(&file_header);
87
+ git_buf_dispose(&file_header);
88
88
  }
89
89
 
90
90
  return out;
@@ -141,7 +141,7 @@ size_t git_patch_num_hunks(const git_patch *patch)
141
141
 
142
142
  static int patch_error_outofrange(const char *thing)
143
143
  {
144
- giterr_set(GITERR_INVALID, "patch %s index out of range", thing);
144
+ git_error_set(GIT_ERROR_INVALID, "patch %s index out of range", thing);
145
145
  return GIT_ENOTFOUND;
146
146
  }
147
147
 
@@ -84,7 +84,7 @@ static int patch_generated_normalize_options(
84
84
  const git_diff_options *opts)
85
85
  {
86
86
  if (opts) {
87
- GITERR_CHECK_VERSION(opts, GIT_DIFF_OPTIONS_VERSION, "git_diff_options");
87
+ GIT_ERROR_CHECK_VERSION(opts, GIT_DIFF_OPTIONS_VERSION, "git_diff_options");
88
88
  memcpy(out, opts, sizeof(git_diff_options));
89
89
  } else {
90
90
  git_diff_options default_opts = GIT_DIFF_OPTIONS_INIT;
@@ -99,8 +99,8 @@ static int patch_generated_normalize_options(
99
99
  git__strdup(opts->new_prefix) :
100
100
  git__strdup(DIFF_NEW_PREFIX_DEFAULT);
101
101
 
102
- GITERR_CHECK_ALLOC(out->old_prefix);
103
- GITERR_CHECK_ALLOC(out->new_prefix);
102
+ GIT_ERROR_CHECK_ALLOC(out->old_prefix);
103
+ GIT_ERROR_CHECK_ALLOC(out->new_prefix);
104
104
 
105
105
  return 0;
106
106
  }
@@ -135,7 +135,7 @@ static int patch_generated_alloc_from_diff(
135
135
  {
136
136
  int error;
137
137
  git_patch_generated *patch = git__calloc(1, sizeof(git_patch_generated));
138
- GITERR_CHECK_ALLOC(patch);
138
+ GIT_ERROR_CHECK_ALLOC(patch);
139
139
 
140
140
  if (!(error = patch_generated_init(patch, diff, delta_index))) {
141
141
  patch->flags |= GIT_PATCH_GENERATED_ALLOCATED;
@@ -248,7 +248,7 @@ static int patch_generated_invoke_file_callback(
248
248
  if (!output->file_cb)
249
249
  return 0;
250
250
 
251
- return giterr_set_after_callback_function(
251
+ return git_error_set_after_callback_function(
252
252
  output->file_cb(patch->base.delta, progress, output->payload),
253
253
  "git_patch");
254
254
  }
@@ -314,8 +314,8 @@ static int create_binary(
314
314
  }
315
315
 
316
316
  done:
317
- git_buf_free(&deflate);
318
- git_buf_free(&delta);
317
+ git_buf_dispose(&deflate);
318
+ git_buf_dispose(&delta);
319
319
 
320
320
  return error;
321
321
  }
@@ -350,7 +350,7 @@ static int diff_binary(git_patch_generated_output *output, git_patch_generated *
350
350
  return error;
351
351
  }
352
352
 
353
- error = giterr_set_after_callback_function(
353
+ error = git_error_set_after_callback_function(
354
354
  output->binary_cb(patch->base.delta, &binary, output->payload),
355
355
  "git_patch");
356
356
 
@@ -397,7 +397,7 @@ static int diff_required(git_diff *diff, const char *action)
397
397
  {
398
398
  if (diff)
399
399
  return 0;
400
- giterr_set(GITERR_INVALID, "must provide valid diff to %s", action);
400
+ git_error_set(GIT_ERROR_INVALID, "must provide valid diff to %s", action);
401
401
  return -1;
402
402
  }
403
403
 
@@ -501,12 +501,12 @@ static int patch_generated_with_delta_alloc(
501
501
  size_t new_len = *new_path ? strlen(*new_path) : 0;
502
502
  size_t alloc_len;
503
503
 
504
- GITERR_CHECK_ALLOC_ADD(&alloc_len, sizeof(*pd), old_len);
505
- GITERR_CHECK_ALLOC_ADD(&alloc_len, alloc_len, new_len);
506
- GITERR_CHECK_ALLOC_ADD(&alloc_len, alloc_len, 2);
504
+ GIT_ERROR_CHECK_ALLOC_ADD(&alloc_len, sizeof(*pd), old_len);
505
+ GIT_ERROR_CHECK_ALLOC_ADD(&alloc_len, alloc_len, new_len);
506
+ GIT_ERROR_CHECK_ALLOC_ADD(&alloc_len, alloc_len, 2);
507
507
 
508
508
  *out = pd = git__calloc(1, alloc_len);
509
- GITERR_CHECK_ALLOC(pd);
509
+ GIT_ERROR_CHECK_ALLOC(pd);
510
510
 
511
511
  pd->patch.flags = GIT_PATCH_GENERATED_ALLOCATED;
512
512
 
@@ -708,7 +708,7 @@ int git_patch_generated_from_diff(
708
708
 
709
709
  delta = git_vector_get(&diff->deltas, idx);
710
710
  if (!delta) {
711
- giterr_set(GITERR_INVALID, "index out of range for delta in diff");
711
+ git_error_set(GIT_ERROR_INVALID, "index out of range for delta in diff");
712
712
  return GIT_ENOTFOUND;
713
713
  }
714
714
 
@@ -788,7 +788,7 @@ static int patch_generated_binary_cb(
788
788
 
789
789
  if (binary->old_file.data) {
790
790
  patch->binary.old_file.data = git__malloc(binary->old_file.datalen);
791
- GITERR_CHECK_ALLOC(patch->binary.old_file.data);
791
+ GIT_ERROR_CHECK_ALLOC(patch->binary.old_file.data);
792
792
 
793
793
  memcpy((char *)patch->binary.old_file.data,
794
794
  binary->old_file.data, binary->old_file.datalen);
@@ -796,7 +796,7 @@ static int patch_generated_binary_cb(
796
796
 
797
797
  if (binary->new_file.data) {
798
798
  patch->binary.new_file.data = git__malloc(binary->new_file.datalen);
799
- GITERR_CHECK_ALLOC(patch->binary.new_file.data);
799
+ GIT_ERROR_CHECK_ALLOC(patch->binary.new_file.data);
800
800
 
801
801
  memcpy((char *)patch->binary.new_file.data,
802
802
  binary->new_file.data, binary->new_file.datalen);
@@ -816,7 +816,7 @@ static int git_patch_hunk_cb(
816
816
  GIT_UNUSED(delta);
817
817
 
818
818
  hunk = git_array_alloc(patch->base.hunks);
819
- GITERR_CHECK_ALLOC(hunk);
819
+ GIT_ERROR_CHECK_ALLOC(hunk);
820
820
 
821
821
  memcpy(&hunk->hunk, hunk_, sizeof(hunk->hunk));
822
822
 
@@ -845,7 +845,7 @@ static int patch_generated_line_cb(
845
845
  assert(hunk); /* programmer error if no hunk is available */
846
846
 
847
847
  line = git_array_alloc(patch->base.lines);
848
- GITERR_CHECK_ALLOC(line);
848
+ GIT_ERROR_CHECK_ALLOC(line);
849
849
 
850
850
  memcpy(line, line_, sizeof(*line));
851
851
 
@@ -98,7 +98,7 @@ static int parse_header_git_oldpath(
98
98
  patch->old_path = git_buf_detach(&old_path);
99
99
 
100
100
  out:
101
- git_buf_free(&old_path);
101
+ git_buf_dispose(&old_path);
102
102
  return error;
103
103
  }
104
104
 
@@ -114,7 +114,7 @@ static int parse_header_git_newpath(
114
114
  patch->new_path = git_buf_detach(&new_path);
115
115
 
116
116
  out:
117
- git_buf_free(&new_path);
117
+ git_buf_dispose(&new_path);
118
118
  return error;
119
119
  }
120
120
 
@@ -282,7 +282,7 @@ static int parse_header_percent(uint16_t *out, git_patch_parse_ctx *ctx)
282
282
  if (val < 0 || val > 100)
283
283
  return -1;
284
284
 
285
- *out = val;
285
+ *out = (uint16_t)val;
286
286
  return 0;
287
287
  }
288
288
 
@@ -518,7 +518,7 @@ static int parse_hunk_header(
518
518
  return 0;
519
519
 
520
520
  fail:
521
- giterr_set(GITERR_PATCH, "invalid patch hunk header at line %"PRIuZ,
521
+ git_error_set(GIT_ERROR_PATCH, "invalid patch hunk header at line %"PRIuZ,
522
522
  ctx->parse_ctx.line_num);
523
523
  return -1;
524
524
  }
@@ -583,7 +583,7 @@ static int parse_hunk_body(
583
583
  }
584
584
 
585
585
  line = git_array_alloc(patch->base.lines);
586
- GITERR_CHECK_ALLOC(line);
586
+ GIT_ERROR_CHECK_ALLOC(line);
587
587
 
588
588
  memset(line, 0x0, sizeof(git_diff_line));
589
589
 
@@ -650,7 +650,7 @@ static int parse_patch_header(
650
650
  * noise, continue.
651
651
  */
652
652
  if (parse_hunk_header(&hunk, ctx) < 0) {
653
- giterr_clear();
653
+ git_error_clear();
654
654
  continue;
655
655
  }
656
656
 
@@ -673,7 +673,7 @@ static int parse_patch_header(
673
673
  continue;
674
674
  }
675
675
 
676
- giterr_set(GITERR_PATCH, "no patch found");
676
+ git_error_set(GIT_ERROR_PATCH, "no patch found");
677
677
  error = GIT_ENOTFOUND;
678
678
 
679
679
  done:
@@ -757,8 +757,8 @@ static int parse_patch_binary_side(
757
757
  binary->data = git_buf_detach(&decoded);
758
758
 
759
759
  done:
760
- git_buf_free(&base85);
761
- git_buf_free(&decoded);
760
+ git_buf_dispose(&base85);
761
+ git_buf_dispose(&decoded);
762
762
  return error;
763
763
  }
764
764
 
@@ -821,7 +821,7 @@ static int parse_patch_hunks(
821
821
 
822
822
  while (git_parse_ctx_contains_s(&ctx->parse_ctx, "@@ -")) {
823
823
  hunk = git_array_alloc(patch->base.hunks);
824
- GITERR_CHECK_ALLOC(hunk);
824
+ GIT_ERROR_CHECK_ALLOC(hunk);
825
825
 
826
826
  memset(hunk, 0, sizeof(git_patch_hunk));
827
827
 
@@ -1079,7 +1079,7 @@ int git_patch_parse(
1079
1079
  *out = NULL;
1080
1080
 
1081
1081
  patch = git__calloc(1, sizeof(git_patch_parsed));
1082
- GITERR_CHECK_ALLOC(patch);
1082
+ GIT_ERROR_CHECK_ALLOC(patch);
1083
1083
 
1084
1084
  patch->ctx = ctx;
1085
1085
  GIT_REFCOUNT_INC(patch->ctx);
@@ -1087,7 +1087,7 @@ int git_patch_parse(
1087
1087
  patch->base.free_fn = patch_parsed__free;
1088
1088
 
1089
1089
  patch->base.delta = git__calloc(1, sizeof(git_diff_delta));
1090
- GITERR_CHECK_ALLOC(patch->base.delta);
1090
+ GIT_ERROR_CHECK_ALLOC(patch->base.delta);
1091
1091
 
1092
1092
  patch->base.delta->status = GIT_DELTA_MODIFIED;
1093
1093
  patch->base.delta->nfiles = 2;
@@ -1126,7 +1126,7 @@ int git_patch_from_buffer(
1126
1126
  int error;
1127
1127
 
1128
1128
  ctx = git_patch_parse_ctx_init(content, content_len, opts);
1129
- GITERR_CHECK_ALLOC(ctx);
1129
+ GIT_ERROR_CHECK_ALLOC(ctx);
1130
1130
 
1131
1131
  error = git_patch_parse(out, ctx);
1132
1132
 
@@ -14,36 +14,13 @@
14
14
  #include "win32/w32_buffer.h"
15
15
  #include "win32/w32_util.h"
16
16
  #include "win32/version.h"
17
- #include <AclAPI.h>
18
17
  #else
19
18
  #include <dirent.h>
20
19
  #endif
21
20
  #include <stdio.h>
22
21
  #include <ctype.h>
23
22
 
24
- static int dos_drive_prefix_length(const char *path)
25
- {
26
- int i;
27
-
28
- /*
29
- * Does it start with an ASCII letter (i.e. highest bit not set),
30
- * followed by a colon?
31
- */
32
- if (!(0x80 & (unsigned char)*path))
33
- return *path && path[1] == ':' ? 2 : 0;
34
-
35
- /*
36
- * While drive letters must be letters of the English alphabet, it is
37
- * possible to assign virtually _any_ Unicode character via `subst` as
38
- * a drive letter to "virtual drives". Even `1`, or `ä`. Or fun stuff
39
- * like this:
40
- *
41
- * subst ֍: %USERPROFILE%\Desktop
42
- */
43
- for (i = 1; i < 4 && (0x80 & (unsigned char)path[i]); i++)
44
- ; /* skip first UTF-8 character */
45
- return path[i] == ':' ? i + 1 : 0;
46
- }
23
+ #define LOOKS_LIKE_DRIVE_PREFIX(S) (git__isalpha((S)[0]) && (S)[1] == ':')
47
24
 
48
25
  #ifdef GIT_WIN32
49
26
  static bool looks_like_network_computer_name(const char *path, int pos)
@@ -145,11 +122,11 @@ static int win32_prefix_length(const char *path, int len)
145
122
  GIT_UNUSED(len);
146
123
  #else
147
124
  /*
148
- * Mimic unix behavior where '/.git' returns '/': 'C:/.git'
149
- * will return 'C:/' here
125
+ * Mimic unix behavior where '/.git' returns '/': 'C:/.git' will return
126
+ * 'C:/' here
150
127
  */
151
- if (dos_drive_prefix_length(path) == len)
152
- return len;
128
+ if (len == 2 && LOOKS_LIKE_DRIVE_PREFIX(path))
129
+ return 2;
153
130
 
154
131
  /*
155
132
  * Similarly checks if we're dealing with a network computer name
@@ -230,7 +207,7 @@ char *git_path_dirname(const char *path)
230
207
 
231
208
  git_path_dirname_r(&buf, path);
232
209
  dirname = git_buf_detach(&buf);
233
- git_buf_free(&buf); /* avoid memleak if error occurs */
210
+ git_buf_dispose(&buf); /* avoid memleak if error occurs */
234
211
 
235
212
  return dirname;
236
213
  }
@@ -242,7 +219,7 @@ char *git_path_basename(const char *path)
242
219
 
243
220
  git_path_basename_r(&buf, path);
244
221
  basename = git_buf_detach(&buf);
245
- git_buf_free(&buf); /* avoid memleak if error occurs */
222
+ git_buf_dispose(&buf); /* avoid memleak if error occurs */
246
223
 
247
224
  return basename;
248
225
  }
@@ -282,11 +259,11 @@ const char *git_path_topdir(const char *path)
282
259
 
283
260
  int git_path_root(const char *path)
284
261
  {
285
- int offset = 0, prefix_len;
262
+ int offset = 0;
286
263
 
287
264
  /* Does the root of the path look like a windows drive ? */
288
- if ((prefix_len = dos_drive_prefix_length(path)))
289
- offset += prefix_len;
265
+ if (LOOKS_LIKE_DRIVE_PREFIX(path))
266
+ offset += 2;
290
267
 
291
268
  #ifdef GIT_WIN32
292
269
  /* Are we dealing with a windows network path? */
@@ -384,9 +361,9 @@ int git_path_prettify(git_buf *path_out, const char *path, const char *base)
384
361
  }
385
362
 
386
363
  if (p_realpath(path, buf) == NULL) {
387
- /* giterr_set resets the errno when dealing with a GITERR_OS kind of error */
364
+ /* git_error_set resets the errno when dealing with a GIT_ERROR_OS kind of error */
388
365
  int error = (errno == ENOENT || errno == ENOTDIR) ? GIT_ENOTFOUND : -1;
389
- giterr_set(GITERR_OS, "failed to resolve path '%s'", path);
366
+ git_error_set(GIT_ERROR_OS, "failed to resolve path '%s'", path);
390
367
 
391
368
  git_buf_clear(path_out);
392
369
 
@@ -459,7 +436,7 @@ append:
459
436
 
460
437
  static int error_invalid_local_file_uri(const char *uri)
461
438
  {
462
- giterr_set(GITERR_CONFIG, "'%s' is not a valid local file URI", uri);
439
+ git_error_set(GIT_ERROR_CONFIG, "'%s' is not a valid local file URI", uri);
463
440
  return -1;
464
441
  }
465
442
 
@@ -525,7 +502,7 @@ int git_path_walk_up(
525
502
  if (!scan) {
526
503
  error = cb(data, "");
527
504
  if (error)
528
- giterr_set_after_callback(error);
505
+ git_error_set_after_callback(error);
529
506
  return error;
530
507
  }
531
508
 
@@ -538,7 +515,7 @@ int git_path_walk_up(
538
515
  iter.ptr[scan] = oldc;
539
516
 
540
517
  if (error) {
541
- giterr_set_after_callback(error);
518
+ git_error_set_after_callback(error);
542
519
  break;
543
520
  }
544
521
 
@@ -558,7 +535,7 @@ int git_path_walk_up(
558
535
  if (!error && stop == 0 && iter.ptr[0] != '/') {
559
536
  error = cb(data, "");
560
537
  if (error)
561
- giterr_set_after_callback(error);
538
+ git_error_set_after_callback(error);
562
539
  }
563
540
 
564
541
  return error;
@@ -661,11 +638,11 @@ bool git_path_is_empty_dir(const char *path)
661
638
  return false;
662
639
 
663
640
  if ((error = git_buf_sets(&dir, path)) != 0)
664
- giterr_clear();
641
+ git_error_clear();
665
642
  else
666
643
  error = git_path_direach(&dir, 0, path_found_entry, NULL);
667
644
 
668
- git_buf_free(&dir);
645
+ git_buf_dispose(&dir);
669
646
 
670
647
  return !error;
671
648
  }
@@ -677,24 +654,24 @@ int git_path_set_error(int errno_value, const char *path, const char *action)
677
654
  switch (errno_value) {
678
655
  case ENOENT:
679
656
  case ENOTDIR:
680
- giterr_set(GITERR_OS, "could not find '%s' to %s", path, action);
657
+ git_error_set(GIT_ERROR_OS, "could not find '%s' to %s", path, action);
681
658
  return GIT_ENOTFOUND;
682
659
 
683
660
  case EINVAL:
684
661
  case ENAMETOOLONG:
685
- giterr_set(GITERR_OS, "invalid path for filesystem '%s'", path);
662
+ git_error_set(GIT_ERROR_OS, "invalid path for filesystem '%s'", path);
686
663
  return GIT_EINVALIDSPEC;
687
664
 
688
665
  case EEXIST:
689
- giterr_set(GITERR_OS, "failed %s - '%s' already exists", action, path);
666
+ git_error_set(GIT_ERROR_OS, "failed %s - '%s' already exists", action, path);
690
667
  return GIT_EEXISTS;
691
668
 
692
669
  case EACCES:
693
- giterr_set(GITERR_OS, "failed %s - '%s' is locked", action, path);
670
+ git_error_set(GIT_ERROR_OS, "failed %s - '%s' is locked", action, path);
694
671
  return GIT_ELOCKED;
695
672
 
696
673
  default:
697
- giterr_set(GITERR_OS, "could not %s '%s'", action, path);
674
+ git_error_set(GIT_ERROR_OS, "could not %s '%s'", action, path);
698
675
  return -1;
699
676
  }
700
677
  }
@@ -774,7 +751,7 @@ int git_path_resolve_relative(git_buf *path, size_t ceiling)
774
751
  char *base, *to, *from, *next;
775
752
  size_t len;
776
753
 
777
- GITERR_CHECK_ALLOC_BUF(path);
754
+ GIT_ERROR_CHECK_ALLOC_BUF(path);
778
755
 
779
756
  if (ceiling > path->size)
780
757
  ceiling = path->size;
@@ -803,7 +780,7 @@ int git_path_resolve_relative(git_buf *path, size_t ceiling)
803
780
  else if (len == 2 && from[0] == '.' && from[1] == '.') {
804
781
  /* error out if trying to up one from a hard base */
805
782
  if (to == base && ceiling != 0) {
806
- giterr_set(GITERR_INVALID,
783
+ git_error_set(GIT_ERROR_INVALID,
807
784
  "cannot strip root component off url");
808
785
  return -1;
809
786
  }
@@ -910,7 +887,7 @@ int git_path_make_relative(git_buf *path, const char *parent)
910
887
  /* need at least 1 common path segment */
911
888
  if ((p_dirsep == path->ptr || q_dirsep == parent) &&
912
889
  (*p_dirsep != '/' || *q_dirsep != '/')) {
913
- giterr_set(GITERR_INVALID,
890
+ git_error_set(GIT_ERROR_INVALID,
914
891
  "%s is not a parent of %s", parent, path->ptr);
915
892
  return GIT_ENOTFOUND;
916
893
  }
@@ -934,10 +911,10 @@ int git_path_make_relative(git_buf *path, const char *parent)
934
911
  for (; (q = strchr(q, '/')) && *(q + 1); q++)
935
912
  depth++;
936
913
 
937
- GITERR_CHECK_ALLOC_MULTIPLY(&newlen, depth, 3);
938
- GITERR_CHECK_ALLOC_ADD(&newlen, newlen, plen);
914
+ GIT_ERROR_CHECK_ALLOC_MULTIPLY(&newlen, depth, 3);
915
+ GIT_ERROR_CHECK_ALLOC_ADD(&newlen, newlen, plen);
939
916
 
940
- GITERR_CHECK_ALLOC_ADD(&alloclen, newlen, 1);
917
+ GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, newlen, 1);
941
918
 
942
919
  /* save the offset as we might realllocate the pointer */
943
920
  offset = p - path->ptr;
@@ -979,7 +956,7 @@ void git_path_iconv_clear(git_path_iconv_t *ic)
979
956
  if (ic) {
980
957
  if (ic->map != (iconv_t)-1)
981
958
  iconv_close(ic->map);
982
- git_buf_free(&ic->buf);
959
+ git_buf_dispose(&ic->buf);
983
960
  }
984
961
  }
985
962
 
@@ -996,7 +973,7 @@ int git_path_iconv(git_path_iconv_t *ic, const char **in, size_t *inlen)
996
973
  git_buf_clear(&ic->buf);
997
974
 
998
975
  while (1) {
999
- GITERR_CHECK_ALLOC_ADD(&alloclen, wantlen, 1);
976
+ GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, wantlen, 1);
1000
977
  if (git_buf_grow(&ic->buf, alloclen) < 0)
1001
978
  return -1;
1002
979
 
@@ -1033,7 +1010,7 @@ int git_path_iconv(git_path_iconv_t *ic, const char **in, size_t *inlen)
1033
1010
  return 0;
1034
1011
 
1035
1012
  fail:
1036
- giterr_set(GITERR_OS, "unable to convert unicode path data");
1013
+ git_error_set(GIT_ERROR_OS, "unable to convert unicode path data");
1037
1014
  return -1;
1038
1015
  }
1039
1016
 
@@ -1083,7 +1060,7 @@ bool git_path_does_fs_decompose_unicode(const char *root)
1083
1060
  (void)p_unlink(path.ptr);
1084
1061
 
1085
1062
  done:
1086
- git_buf_free(&path);
1063
+ git_buf_dispose(&path);
1087
1064
  return found_decomposed;
1088
1065
  }
1089
1066
 
@@ -1126,7 +1103,7 @@ int git_path_direach(
1126
1103
  wd_len = git_buf_len(path);
1127
1104
 
1128
1105
  if ((dir = opendir(path->ptr)) == NULL) {
1129
- giterr_set(GITERR_OS, "failed to open directory '%s'", path->ptr);
1106
+ git_error_set(GIT_ERROR_OS, "failed to open directory '%s'", path->ptr);
1130
1107
  if (errno == ENOENT)
1131
1108
  return GIT_ENOTFOUND;
1132
1109
 
@@ -1153,15 +1130,15 @@ int git_path_direach(
1153
1130
  if ((error = git_buf_put(path, de_path, de_len)) < 0)
1154
1131
  break;
1155
1132
 
1156
- giterr_clear();
1133
+ git_error_clear();
1157
1134
  error = fn(arg, path);
1158
1135
 
1159
1136
  git_buf_truncate(path, wd_len); /* restore path */
1160
1137
 
1161
1138
  /* Only set our own error if the callback did not set one already */
1162
1139
  if (error != 0) {
1163
- if (!giterr_last())
1164
- giterr_set_after_callback(error);
1140
+ if (!git_error_last())
1141
+ git_error_set_after_callback(error);
1165
1142
 
1166
1143
  break;
1167
1144
  }
@@ -1207,13 +1184,13 @@ int git_path_diriter_init(
1207
1184
  git_path_trim_slashes(&diriter->path_utf8);
1208
1185
 
1209
1186
  if (diriter->path_utf8.size == 0) {
1210
- giterr_set(GITERR_FILESYSTEM, "could not open directory '%s'", path);
1187
+ git_error_set(GIT_ERROR_FILESYSTEM, "could not open directory '%s'", path);
1211
1188
  return -1;
1212
1189
  }
1213
1190
 
1214
1191
  if ((diriter->parent_len = git_win32_path_from_utf8(diriter->path, diriter->path_utf8.ptr)) < 0 ||
1215
1192
  !git_win32__findfirstfile_filter(path_filter, diriter->path_utf8.ptr)) {
1216
- giterr_set(GITERR_OS, "could not parse the directory path '%s'", path);
1193
+ git_error_set(GIT_ERROR_OS, "could not parse the directory path '%s'", path);
1217
1194
  return -1;
1218
1195
  }
1219
1196
 
@@ -1226,7 +1203,7 @@ int git_path_diriter_init(
1226
1203
  is_win7_or_later ? FIND_FIRST_EX_LARGE_FETCH : 0);
1227
1204
 
1228
1205
  if (diriter->handle == INVALID_HANDLE_VALUE) {
1229
- giterr_set(GITERR_OS, "could not open directory '%s'", path);
1206
+ git_error_set(GIT_ERROR_OS, "could not open directory '%s'", path);
1230
1207
  return -1;
1231
1208
  }
1232
1209
 
@@ -1246,7 +1223,7 @@ static int diriter_update_paths(git_path_diriter *diriter)
1246
1223
  return -1;
1247
1224
 
1248
1225
  if (path_len > GIT_WIN_PATH_UTF16) {
1249
- giterr_set(GITERR_FILESYSTEM,
1226
+ git_error_set(GIT_ERROR_FILESYSTEM,
1250
1227
  "invalid path '%.*ls\\%ls' (path too long)",
1251
1228
  diriter->parent_len, diriter->path, diriter->current.cFileName);
1252
1229
  return -1;
@@ -1331,7 +1308,7 @@ void git_path_diriter_free(git_path_diriter *diriter)
1331
1308
  if (diriter == NULL)
1332
1309
  return;
1333
1310
 
1334
- git_buf_free(&diriter->path_utf8);
1311
+ git_buf_dispose(&diriter->path_utf8);
1335
1312
 
1336
1313
  if (diriter->handle != INVALID_HANDLE_VALUE) {
1337
1314
  FindClose(diriter->handle);
@@ -1356,14 +1333,14 @@ int git_path_diriter_init(
1356
1333
  git_path_trim_slashes(&diriter->path);
1357
1334
 
1358
1335
  if (diriter->path.size == 0) {
1359
- giterr_set(GITERR_FILESYSTEM, "could not open directory '%s'", path);
1336
+ git_error_set(GIT_ERROR_FILESYSTEM, "could not open directory '%s'", path);
1360
1337
  return -1;
1361
1338
  }
1362
1339
 
1363
1340
  if ((diriter->dir = opendir(diriter->path.ptr)) == NULL) {
1364
- git_buf_free(&diriter->path);
1341
+ git_buf_dispose(&diriter->path);
1365
1342
 
1366
- giterr_set(GITERR_OS, "failed to open directory '%s'", path);
1343
+ git_error_set(GIT_ERROR_OS, "failed to open directory '%s'", path);
1367
1344
  return -1;
1368
1345
  }
1369
1346
 
@@ -1395,7 +1372,7 @@ int git_path_diriter_next(git_path_diriter *diriter)
1395
1372
  if (!errno)
1396
1373
  return GIT_ITEROVER;
1397
1374
 
1398
- giterr_set(GITERR_OS,
1375
+ git_error_set(GIT_ERROR_OS,
1399
1376
  "could not read directory '%s'", diriter->path.ptr);
1400
1377
  return -1;
1401
1378
  }
@@ -1471,7 +1448,7 @@ void git_path_diriter_free(git_path_diriter *diriter)
1471
1448
  git_path_iconv_clear(&diriter->ic);
1472
1449
  #endif
1473
1450
 
1474
- git_buf_free(&diriter->path);
1451
+ git_buf_dispose(&diriter->path);
1475
1452
  }
1476
1453
 
1477
1454
  #endif
@@ -1500,7 +1477,7 @@ int git_path_dirload(
1500
1477
  assert(name_len > prefix_len);
1501
1478
 
1502
1479
  dup = git__strndup(name + prefix_len, name_len - prefix_len);
1503
- GITERR_CHECK_ALLOC(dup);
1480
+ GIT_ERROR_CHECK_ALLOC(dup);
1504
1481
 
1505
1482
  if ((error = git_vector_insert(contents, dup)) < 0)
1506
1483
  break;
@@ -1631,12 +1608,8 @@ GIT_INLINE(bool) verify_dotgit_ntfs(git_repository *repo, const char *path, size
1631
1608
  if (!start)
1632
1609
  return true;
1633
1610
 
1634
- /*
1635
- * Reject paths that start with Windows-style directory separators
1636
- * (".git\") or NTFS alternate streams (".git:") and could be used
1637
- * to write to the ".git" directory on Windows platforms.
1638
- */
1639
- if (path[start] == '\\' || path[start] == ':')
1611
+ /* Reject paths like ".git\" */
1612
+ if (path[start] == '\\')
1640
1613
  return false;
1641
1614
 
1642
1615
  /* Reject paths like '.git ' or '.git.' */
@@ -1648,21 +1621,12 @@ GIT_INLINE(bool) verify_dotgit_ntfs(git_repository *repo, const char *path, size
1648
1621
  return false;
1649
1622
  }
1650
1623
 
1651
- /*
1652
- * Windows paths that end with spaces and/or dots are elided to the
1653
- * path without them for backward compatibility. That is to say
1654
- * that opening file "foo ", "foo." or even "foo . . ." will all
1655
- * map to a filename of "foo". This function identifies spaces and
1656
- * dots at the end of a filename, whether the proper end of the
1657
- * filename (end of string) or a colon (which would indicate a
1658
- * Windows alternate data stream.)
1659
- */
1660
- GIT_INLINE(bool) ntfs_end_of_filename(const char *path)
1624
+ GIT_INLINE(bool) only_spaces_and_dots(const char *path)
1661
1625
  {
1662
1626
  const char *c = path;
1663
1627
 
1664
1628
  for (;; c++) {
1665
- if (*c == '\0' || *c == ':')
1629
+ if (*c == '\0')
1666
1630
  return true;
1667
1631
  if (*c != ' ' && *c != '.')
1668
1632
  return false;
@@ -1677,13 +1641,13 @@ GIT_INLINE(bool) verify_dotgit_ntfs_generic(const char *name, size_t len, const
1677
1641
 
1678
1642
  if (name[0] == '.' && len >= dotgit_len &&
1679
1643
  !strncasecmp(name + 1, dotgit_name, dotgit_len)) {
1680
- return !ntfs_end_of_filename(name + dotgit_len + 1);
1644
+ return !only_spaces_and_dots(name + dotgit_len + 1);
1681
1645
  }
1682
1646
 
1683
1647
  /* Detect the basic NTFS shortname with the first six chars */
1684
1648
  if (!strncasecmp(name, dotgit_name, 6) && name[6] == '~' &&
1685
1649
  name[7] >= '1' && name[7] <= '4')
1686
- return !ntfs_end_of_filename(name + 8);
1650
+ return !only_spaces_and_dots(name + 8);
1687
1651
 
1688
1652
  /* Catch fallback names */
1689
1653
  for (i = 0, saw_tilde = 0; i < 8; i++) {
@@ -1698,14 +1662,14 @@ GIT_INLINE(bool) verify_dotgit_ntfs_generic(const char *name, size_t len, const
1698
1662
  saw_tilde = 1;
1699
1663
  } else if (i >= 6) {
1700
1664
  return true;
1701
- } else if (name[i] < 0) {
1665
+ } else if ((unsigned char)name[i] > 127) {
1702
1666
  return true;
1703
1667
  } else if (git__tolower(name[i]) != shortname_pfix[i]) {
1704
1668
  return true;
1705
1669
  }
1706
1670
  }
1707
1671
 
1708
- return !ntfs_end_of_filename(name + i);
1672
+ return !only_spaces_and_dots(name + i);
1709
1673
  }
1710
1674
 
1711
1675
  GIT_INLINE(bool) verify_char(unsigned char c, unsigned int flags)
@@ -1802,14 +1766,14 @@ static bool verify_component(
1802
1766
  if (flags & GIT_PATH_REJECT_DOT_GIT_HFS) {
1803
1767
  if (!verify_dotgit_hfs(component, len))
1804
1768
  return false;
1805
- if (S_ISLNK(mode) && git_path_is_hfs_dotgit_modules(component, len))
1769
+ if (S_ISLNK(mode) && git_path_is_gitfile(component, len, GIT_PATH_GITFILE_GITMODULES, GIT_PATH_FS_HFS))
1806
1770
  return false;
1807
1771
  }
1808
1772
 
1809
1773
  if (flags & GIT_PATH_REJECT_DOT_GIT_NTFS) {
1810
1774
  if (!verify_dotgit_ntfs(repo, component, len))
1811
1775
  return false;
1812
- if (S_ISLNK(mode) && git_path_is_ntfs_dotgit_modules(component, len))
1776
+ if (S_ISLNK(mode) && git_path_is_gitfile(component, len, GIT_PATH_GITFILE_GITMODULES, GIT_PATH_FS_NTFS))
1813
1777
  return false;
1814
1778
  }
1815
1779
 
@@ -1839,7 +1803,7 @@ GIT_INLINE(unsigned int) dotgit_flags(
1839
1803
  git_repository *repo,
1840
1804
  unsigned int flags)
1841
1805
  {
1842
- int protectHFS = 0, protectNTFS = 1;
1806
+ int protectHFS = 0, protectNTFS = 0;
1843
1807
  int error = 0;
1844
1808
 
1845
1809
  flags |= GIT_PATH_REJECT_DOT_GIT_LITERAL;
@@ -1848,12 +1812,16 @@ GIT_INLINE(unsigned int) dotgit_flags(
1848
1812
  protectHFS = 1;
1849
1813
  #endif
1850
1814
 
1815
+ #ifdef GIT_WIN32
1816
+ protectNTFS = 1;
1817
+ #endif
1818
+
1851
1819
  if (repo && !protectHFS)
1852
1820
  error = git_repository__cvar(&protectHFS, repo, GIT_CVAR_PROTECTHFS);
1853
1821
  if (!error && protectHFS)
1854
1822
  flags |= GIT_PATH_REJECT_DOT_GIT_HFS;
1855
1823
 
1856
- if (repo)
1824
+ if (repo && !protectNTFS)
1857
1825
  error = git_repository__cvar(&protectNTFS, repo, GIT_CVAR_PROTECTNTFS);
1858
1826
  if (!error && protectNTFS)
1859
1827
  flags |= GIT_PATH_REJECT_DOT_GIT_NTFS;
@@ -1904,140 +1872,40 @@ int git_path_normalize_slashes(git_buf *out, const char *path)
1904
1872
  return 0;
1905
1873
  }
1906
1874
 
1907
- static int verify_dotgit_generic(const char *name, size_t len, const char *dotgit_name, size_t dotgit_len, const char *shortname_pfix)
1908
- {
1909
- if (!verify_dotgit_ntfs_generic(name, len, dotgit_name, dotgit_len, shortname_pfix))
1910
- return false;
1911
-
1912
- return verify_dotgit_hfs_generic(name, len, dotgit_name, dotgit_len);
1913
- }
1914
-
1915
- int git_path_is_ntfs_dotgit_modules(const char *name, size_t len)
1916
- {
1917
- return !verify_dotgit_ntfs_generic(name, len, "gitmodules", CONST_STRLEN("gitmodules"), "gi7eba");
1918
- }
1919
-
1920
- int git_path_is_hfs_dotgit_modules(const char *name, size_t len)
1921
- {
1922
- return !verify_dotgit_hfs_generic(name, len, "gitmodules", CONST_STRLEN("gitmodules"));
1923
- }
1875
+ static const struct {
1876
+ const char *file;
1877
+ const char *hash;
1878
+ size_t filelen;
1879
+ } gitfiles[] = {
1880
+ { "gitignore", "gi250a", CONST_STRLEN("gitignore") },
1881
+ { "gitmodules", "gi7eba", CONST_STRLEN("gitmodules") },
1882
+ { "gitattributes", "gi7d29", CONST_STRLEN("gitattributes") }
1883
+ };
1924
1884
 
1925
- int git_path_is_dotgit_modules(const char *name, size_t len)
1885
+ extern int git_path_is_gitfile(const char *path, size_t pathlen, git_path_gitfile gitfile, git_path_fs fs)
1926
1886
  {
1927
- if (git_path_is_hfs_dotgit_modules(name, len))
1928
- return 1;
1887
+ const char *file, *hash;
1888
+ size_t filelen;
1929
1889
 
1930
- return git_path_is_ntfs_dotgit_modules(name, len);
1931
- }
1932
-
1933
- int git_path_is_ntfs_dotgit_ignore(const char *name, size_t len)
1934
- {
1935
- return !verify_dotgit_ntfs_generic(name, len, "gitignore", CONST_STRLEN("gitignore"), "gi250a");
1936
- }
1937
-
1938
- int git_path_is_hfs_dotgit_ignore(const char *name, size_t len)
1939
- {
1940
- return !verify_dotgit_hfs_generic(name, len, "gitignore", CONST_STRLEN("gitignore"));
1941
- }
1942
-
1943
- int git_path_is_dotgit_ignore(const char *name, size_t len)
1944
- {
1945
- if (git_path_is_hfs_dotgit_ignore(name, len))
1946
- return 1;
1947
-
1948
- return git_path_is_ntfs_dotgit_ignore(name, len);
1949
- }
1950
-
1951
- int git_path_is_hfs_dotgit_attributes(const char *name, size_t len)
1952
- {
1953
- return !verify_dotgit_hfs_generic(name, len, "gitattributes", CONST_STRLEN("gitattributes"));
1954
- }
1955
-
1956
- int git_path_is_ntfs_dotgit_attributes(const char *name, size_t len)
1957
- {
1958
- return !verify_dotgit_ntfs_generic(name, len, "gitattributes", CONST_STRLEN("gitattributes"), "gi7d29");
1959
- }
1960
-
1961
- int git_path_is_dotgit_attributes(const char *name, size_t len)
1962
- {
1963
- if (git_path_is_hfs_dotgit_attributes(name, len))
1964
- return 1;
1965
-
1966
- return git_path_is_ntfs_dotgit_attributes(name, len);
1967
- }
1968
-
1969
- int git_path_validate_system_file_ownership(const char *path)
1970
- {
1971
- #ifndef GIT_WIN32
1972
- GIT_UNUSED(path);
1973
- return GIT_OK;
1974
- #else
1975
- git_win32_path buf;
1976
- PSID owner_sid;
1977
- PSECURITY_DESCRIPTOR descriptor = NULL;
1978
- HANDLE token;
1979
- TOKEN_USER *info = NULL;
1980
- DWORD err, len;
1981
- int ret;
1982
-
1983
- if (git_win32_path_from_utf8(buf, path) < 0)
1890
+ if (!(gitfile >= GIT_PATH_GITFILE_GITIGNORE && gitfile < ARRAY_SIZE(gitfiles))) {
1891
+ git_error_set(GIT_ERROR_OS, "invalid gitfile for path validation");
1984
1892
  return -1;
1985
-
1986
- err = GetNamedSecurityInfoW(buf, SE_FILE_OBJECT,
1987
- OWNER_SECURITY_INFORMATION |
1988
- DACL_SECURITY_INFORMATION,
1989
- &owner_sid, NULL, NULL, NULL, &descriptor);
1990
-
1991
- if (err == ERROR_FILE_NOT_FOUND || err == ERROR_PATH_NOT_FOUND) {
1992
- ret = GIT_ENOTFOUND;
1993
- goto cleanup;
1994
- }
1995
-
1996
- if (err != ERROR_SUCCESS) {
1997
- giterr_set(GITERR_OS, "failed to get security information");
1998
- ret = GIT_ERROR;
1999
- goto cleanup;
2000
- }
2001
-
2002
- if (!IsValidSid(owner_sid)) {
2003
- giterr_set(GITERR_INVALID, "programdata configuration file owner is unknown");
2004
- ret = GIT_ERROR;
2005
- goto cleanup;
2006
- }
2007
-
2008
- if (IsWellKnownSid(owner_sid, WinBuiltinAdministratorsSid) ||
2009
- IsWellKnownSid(owner_sid, WinLocalSystemSid)) {
2010
- ret = GIT_OK;
2011
- goto cleanup;
2012
- }
2013
-
2014
- /* Obtain current user's SID */
2015
- if (OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &token) &&
2016
- !GetTokenInformation(token, TokenUser, NULL, 0, &len)) {
2017
- info = git__malloc(len);
2018
- GITERR_CHECK_ALLOC(info);
2019
- if (!GetTokenInformation(token, TokenUser, info, len, &len)) {
2020
- git__free(info);
2021
- info = NULL;
2022
- }
2023
1893
  }
2024
1894
 
2025
- /*
2026
- * If the file is owned by the same account that is running the current
2027
- * process, it's okay to read from that file.
2028
- */
2029
- if (info && EqualSid(owner_sid, info->User.Sid))
2030
- ret = GIT_OK;
2031
- else {
2032
- giterr_set(GITERR_INVALID, "programdata configuration file owner is not valid");
2033
- ret = GIT_ERROR;
1895
+ file = gitfiles[gitfile].file;
1896
+ filelen = gitfiles[gitfile].filelen;
1897
+ hash = gitfiles[gitfile].hash;
1898
+
1899
+ switch (fs) {
1900
+ case GIT_PATH_FS_GENERIC:
1901
+ return !verify_dotgit_ntfs_generic(path, pathlen, file, filelen, hash) ||
1902
+ !verify_dotgit_hfs_generic(path, pathlen, file, filelen);
1903
+ case GIT_PATH_FS_NTFS:
1904
+ return !verify_dotgit_ntfs_generic(path, pathlen, file, filelen, hash);
1905
+ case GIT_PATH_FS_HFS:
1906
+ return !verify_dotgit_hfs_generic(path, pathlen, file, filelen);
1907
+ default:
1908
+ git_error_set(GIT_ERROR_OS, "invalid filesystem for path validation");
1909
+ return -1;
2034
1910
  }
2035
- free(info);
2036
-
2037
- cleanup:
2038
- if (descriptor)
2039
- LocalFree(descriptor);
2040
-
2041
- return ret;
2042
- #endif
2043
1911
  }