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
@@ -35,5 +35,6 @@ struct git_commit {
35
35
 
36
36
  void git_commit__free(void *commit);
37
37
  int git_commit__parse(void *commit, git_odb_object *obj);
38
+ int git_commit__parse_raw(void *commit, const char *data, size_t size);
38
39
 
39
40
  #endif
@@ -61,7 +61,7 @@ static int commit_error(git_commit_list_node *commit, const char *msg)
61
61
  git_oid_fmt(commit_oid, &commit->oid);
62
62
  commit_oid[GIT_OID_HEXSZ] = '\0';
63
63
 
64
- giterr_set(GITERR_ODB, "failed to parse commit %s - %s", commit_oid, msg);
64
+ git_error_set(GIT_ERROR_ODB, "failed to parse commit %s - %s", commit_oid, msg);
65
65
 
66
66
  return -1;
67
67
  }
@@ -69,15 +69,11 @@ static int commit_error(git_commit_list_node *commit, const char *msg)
69
69
  static git_commit_list_node **alloc_parents(
70
70
  git_revwalk *walk, git_commit_list_node *commit, size_t n_parents)
71
71
  {
72
- size_t bytes;
73
-
74
72
  if (n_parents <= PARENTS_PER_COMMIT)
75
73
  return (git_commit_list_node **)((char *)commit + sizeof(git_commit_list_node));
76
74
 
77
- if (git__multiply_sizet_overflow(&bytes, n_parents, sizeof(git_commit_list_node *)))
78
- return NULL;
79
-
80
- return (git_commit_list_node **)git_pool_malloc(&walk->commit_pool, bytes);
75
+ return (git_commit_list_node **)git_pool_malloc(
76
+ &walk->commit_pool, (uint32_t)(n_parents * sizeof(git_commit_list_node *)));
81
77
  }
82
78
 
83
79
 
@@ -130,7 +126,7 @@ static int commit_quick_parse(
130
126
  }
131
127
 
132
128
  commit->parents = alloc_parents(walk, commit, parents);
133
- GITERR_CHECK_ALLOC(commit->parents);
129
+ GIT_ERROR_CHECK_ALLOC(commit->parents);
134
130
 
135
131
  buffer = parents_start;
136
132
  for (i = 0; i < parents; ++i) {
@@ -196,8 +192,8 @@ int git_commit_list_parse(git_revwalk *walk, git_commit_list_node *commit)
196
192
  if ((error = git_odb_read(&obj, walk->odb, &commit->oid)) < 0)
197
193
  return error;
198
194
 
199
- if (obj->cached.type != GIT_OBJ_COMMIT) {
200
- giterr_set(GITERR_INVALID, "object is no commit object");
195
+ if (obj->cached.type != GIT_OBJECT_COMMIT) {
196
+ git_error_set(GIT_ERROR_INVALID, "object is no commit object");
201
197
  error = -1;
202
198
  } else
203
199
  error = commit_quick_parse(
@@ -17,8 +17,10 @@
17
17
  /** Declare a function as always inlined. */
18
18
  #if defined(_MSC_VER)
19
19
  # define GIT_INLINE(type) static __inline type
20
+ #elif defined(__GNUC__)
21
+ # define GIT_INLINE(type) static __inline__ type
20
22
  #else
21
- # define GIT_INLINE(type) static inline type
23
+ # define GIT_INLINE(type) static type
22
24
  #endif
23
25
 
24
26
  /** Support for gcc/clang __has_builtin intrinsic */
@@ -87,30 +89,30 @@
87
89
  /**
88
90
  * Check a pointer allocation result, returning -1 if it failed.
89
91
  */
90
- #define GITERR_CHECK_ALLOC(ptr) if (ptr == NULL) { return -1; }
92
+ #define GIT_ERROR_CHECK_ALLOC(ptr) if (ptr == NULL) { return -1; }
91
93
 
92
94
  /**
93
95
  * Check a buffer allocation result, returning -1 if it failed.
94
96
  */
95
- #define GITERR_CHECK_ALLOC_BUF(buf) if ((void *)(buf) == NULL || git_buf_oom(buf)) { return -1; }
97
+ #define GIT_ERROR_CHECK_ALLOC_BUF(buf) if ((void *)(buf) == NULL || git_buf_oom(buf)) { return -1; }
96
98
 
97
99
  /**
98
100
  * Check a return value and propagate result if non-zero.
99
101
  */
100
- #define GITERR_CHECK_ERROR(code) \
102
+ #define GIT_ERROR_CHECK_ERROR(code) \
101
103
  do { int _err = (code); if (_err) return _err; } while (0)
102
104
 
103
105
  /**
104
106
  * Set the error message for this thread, formatting as needed.
105
107
  */
106
108
 
107
- void giterr_set(int error_class, const char *string, ...) GIT_FORMAT_PRINTF(2, 3);
109
+ void git_error_set(int error_class, const char *string, ...) GIT_FORMAT_PRINTF(2, 3);
108
110
 
109
111
  /**
110
112
  * Set the error message for a regex failure, using the internal regex
111
113
  * error code lookup and return a libgit error code.
112
114
  */
113
- int giterr_set_regex(const regex_t *regex, int error_code);
115
+ int git_error_set_regex(const regex_t *regex, int error_code);
114
116
 
115
117
  /**
116
118
  * Set error message for user callback if needed.
@@ -120,35 +122,35 @@ int giterr_set_regex(const regex_t *regex, int error_code);
120
122
  *
121
123
  * @return This always returns the `error_code` parameter.
122
124
  */
123
- GIT_INLINE(int) giterr_set_after_callback_function(
125
+ GIT_INLINE(int) git_error_set_after_callback_function(
124
126
  int error_code, const char *action)
125
127
  {
126
128
  if (error_code) {
127
- const git_error *e = giterr_last();
129
+ const git_error *e = git_error_last();
128
130
  if (!e || !e->message)
129
- giterr_set(e ? e->klass : GITERR_CALLBACK,
131
+ git_error_set(e ? e->klass : GIT_ERROR_CALLBACK,
130
132
  "%s callback returned %d", action, error_code);
131
133
  }
132
134
  return error_code;
133
135
  }
134
136
 
135
137
  #ifdef GIT_WIN32
136
- #define giterr_set_after_callback(code) \
137
- giterr_set_after_callback_function((code), __FUNCTION__)
138
+ #define git_error_set_after_callback(code) \
139
+ git_error_set_after_callback_function((code), __FUNCTION__)
138
140
  #else
139
- #define giterr_set_after_callback(code) \
140
- giterr_set_after_callback_function((code), __func__)
141
+ #define git_error_set_after_callback(code) \
142
+ git_error_set_after_callback_function((code), __func__)
141
143
  #endif
142
144
 
143
145
  /**
144
146
  * Gets the system error code for this thread.
145
147
  */
146
- int giterr_system_last(void);
148
+ int git_error_system_last(void);
147
149
 
148
150
  /**
149
151
  * Sets the system error code for this thread.
150
152
  */
151
- void giterr_system_set(int code);
153
+ void git_error_system_set(int code);
152
154
 
153
155
  /**
154
156
  * Structure to preserve libgit2 error state
@@ -164,20 +166,20 @@ typedef struct {
164
166
  * If `error_code` is zero, this does not clear the current error state.
165
167
  * You must either restore this error state, or free it.
166
168
  */
167
- extern int giterr_state_capture(git_error_state *state, int error_code);
169
+ extern int git_error_state_capture(git_error_state *state, int error_code);
168
170
 
169
171
  /**
170
172
  * Restore error state to a previous value, returning saved error code.
171
173
  */
172
- extern int giterr_state_restore(git_error_state *state);
174
+ extern int git_error_state_restore(git_error_state *state);
173
175
 
174
176
  /** Free an error state. */
175
- extern void giterr_state_free(git_error_state *state);
177
+ extern void git_error_state_free(git_error_state *state);
176
178
 
177
179
  /**
178
180
  * Check a versioned structure for validity
179
181
  */
180
- GIT_INLINE(int) giterr__check_version(const void *structure, unsigned int expected_max, const char *name)
182
+ GIT_INLINE(int) git_error__check_version(const void *structure, unsigned int expected_max, const char *name)
181
183
  {
182
184
  unsigned int actual;
183
185
 
@@ -188,10 +190,10 @@ GIT_INLINE(int) giterr__check_version(const void *structure, unsigned int expect
188
190
  if (actual > 0 && actual <= expected_max)
189
191
  return 0;
190
192
 
191
- giterr_set(GITERR_INVALID, "invalid version %d on %s", actual, name);
193
+ git_error_set(GIT_ERROR_INVALID, "invalid version %d on %s", actual, name);
192
194
  return -1;
193
195
  }
194
- #define GITERR_CHECK_VERSION(S,V,N) if (giterr__check_version(S,V,N) < 0) return -1
196
+ #define GIT_ERROR_CHECK_VERSION(S,V,N) if (git_error__check_version(S,V,N) < 0) return -1
195
197
 
196
198
  /**
197
199
  * Initialize a structure with a version.
@@ -205,42 +207,42 @@ GIT_INLINE(void) git__init_structure(void *structure, size_t len, unsigned int v
205
207
 
206
208
  #define GIT_INIT_STRUCTURE_FROM_TEMPLATE(PTR,VERSION,TYPE,TPL) do { \
207
209
  TYPE _tmpl = TPL; \
208
- GITERR_CHECK_VERSION(&(VERSION), _tmpl.version, #TYPE); \
210
+ GIT_ERROR_CHECK_VERSION(&(VERSION), _tmpl.version, #TYPE); \
209
211
  memcpy((PTR), &_tmpl, sizeof(_tmpl)); } while (0)
210
212
 
211
213
 
212
214
  /** Check for additive overflow, setting an error if would occur. */
213
215
  #define GIT_ADD_SIZET_OVERFLOW(out, one, two) \
214
- (git__add_sizet_overflow(out, one, two) ? (giterr_set_oom(), 1) : 0)
216
+ (git__add_sizet_overflow(out, one, two) ? (git_error_set_oom(), 1) : 0)
215
217
 
216
218
  /** Check for additive overflow, setting an error if would occur. */
217
219
  #define GIT_MULTIPLY_SIZET_OVERFLOW(out, nelem, elsize) \
218
- (git__multiply_sizet_overflow(out, nelem, elsize) ? (giterr_set_oom(), 1) : 0)
220
+ (git__multiply_sizet_overflow(out, nelem, elsize) ? (git_error_set_oom(), 1) : 0)
219
221
 
220
222
  /** Check for additive overflow, failing if it would occur. */
221
- #define GITERR_CHECK_ALLOC_ADD(out, one, two) \
223
+ #define GIT_ERROR_CHECK_ALLOC_ADD(out, one, two) \
222
224
  if (GIT_ADD_SIZET_OVERFLOW(out, one, two)) { return -1; }
223
225
 
224
- #define GITERR_CHECK_ALLOC_ADD3(out, one, two, three) \
226
+ #define GIT_ERROR_CHECK_ALLOC_ADD3(out, one, two, three) \
225
227
  if (GIT_ADD_SIZET_OVERFLOW(out, one, two) || \
226
228
  GIT_ADD_SIZET_OVERFLOW(out, *(out), three)) { return -1; }
227
229
 
228
- #define GITERR_CHECK_ALLOC_ADD4(out, one, two, three, four) \
230
+ #define GIT_ERROR_CHECK_ALLOC_ADD4(out, one, two, three, four) \
229
231
  if (GIT_ADD_SIZET_OVERFLOW(out, one, two) || \
230
232
  GIT_ADD_SIZET_OVERFLOW(out, *(out), three) || \
231
233
  GIT_ADD_SIZET_OVERFLOW(out, *(out), four)) { return -1; }
232
234
 
233
- #define GITERR_CHECK_ALLOC_ADD5(out, one, two, three, four, five) \
235
+ #define GIT_ERROR_CHECK_ALLOC_ADD5(out, one, two, three, four, five) \
234
236
  if (GIT_ADD_SIZET_OVERFLOW(out, one, two) || \
235
237
  GIT_ADD_SIZET_OVERFLOW(out, *(out), three) || \
236
238
  GIT_ADD_SIZET_OVERFLOW(out, *(out), four) || \
237
239
  GIT_ADD_SIZET_OVERFLOW(out, *(out), five)) { return -1; }
238
240
 
239
241
  /** Check for multiplicative overflow, failing if it would occur. */
240
- #define GITERR_CHECK_ALLOC_MULTIPLY(out, nelem, elsize) \
242
+ #define GIT_ERROR_CHECK_ALLOC_MULTIPLY(out, nelem, elsize) \
241
243
  if (GIT_MULTIPLY_SIZET_OVERFLOW(out, nelem, elsize)) { return -1; }
242
244
 
243
- /* NOTE: other giterr functions are in the public errors.h header file */
245
+ /* NOTE: other git_error functions are in the public errors.h header file */
244
246
 
245
247
  #include "util.h"
246
248
 
@@ -12,7 +12,7 @@
12
12
  #include "git2/sys/config.h"
13
13
  #include "vector.h"
14
14
  #include "buf_text.h"
15
- #include "config_file.h"
15
+ #include "config_backend.h"
16
16
  #include "transaction.h"
17
17
  #if GIT_WIN32
18
18
  # include <windows.h>
@@ -31,30 +31,30 @@ void git_config_entry_free(git_config_entry *entry)
31
31
  typedef struct {
32
32
  git_refcount rc;
33
33
 
34
- git_config_backend *file;
34
+ git_config_backend *backend;
35
35
  git_config_level_t level;
36
- } file_internal;
36
+ } backend_internal;
37
37
 
38
- static void file_internal_free(file_internal *internal)
38
+ static void backend_internal_free(backend_internal *internal)
39
39
  {
40
- git_config_backend *file;
40
+ git_config_backend *backend;
41
41
 
42
- file = internal->file;
43
- file->free(file);
42
+ backend = internal->backend;
43
+ backend->free(backend);
44
44
  git__free(internal);
45
45
  }
46
46
 
47
47
  static void config_free(git_config *cfg)
48
48
  {
49
49
  size_t i;
50
- file_internal *internal;
50
+ backend_internal *internal;
51
51
 
52
- for (i = 0; i < cfg->files.length; ++i) {
53
- internal = git_vector_get(&cfg->files, i);
54
- GIT_REFCOUNT_DEC(internal, file_internal_free);
52
+ for (i = 0; i < cfg->backends.length; ++i) {
53
+ internal = git_vector_get(&cfg->backends, i);
54
+ GIT_REFCOUNT_DEC(internal, backend_internal_free);
55
55
  }
56
56
 
57
- git_vector_free(&cfg->files);
57
+ git_vector_free(&cfg->backends);
58
58
 
59
59
  git__memzero(cfg, sizeof(*cfg));
60
60
  git__free(cfg);
@@ -70,8 +70,8 @@ void git_config_free(git_config *cfg)
70
70
 
71
71
  static int config_backend_cmp(const void *a, const void *b)
72
72
  {
73
- const file_internal *bk_a = (const file_internal *)(a);
74
- const file_internal *bk_b = (const file_internal *)(b);
73
+ const backend_internal *bk_a = (const backend_internal *)(a);
74
+ const backend_internal *bk_b = (const backend_internal *)(b);
75
75
 
76
76
  return bk_b->level - bk_a->level;
77
77
  }
@@ -81,11 +81,11 @@ int git_config_new(git_config **out)
81
81
  git_config *cfg;
82
82
 
83
83
  cfg = git__malloc(sizeof(git_config));
84
- GITERR_CHECK_ALLOC(cfg);
84
+ GIT_ERROR_CHECK_ALLOC(cfg);
85
85
 
86
86
  memset(cfg, 0x0, sizeof(git_config));
87
87
 
88
- if (git_vector_init(&cfg->files, 3, config_backend_cmp) < 0) {
88
+ if (git_vector_init(&cfg->backends, 3, config_backend_cmp) < 0) {
89
89
  git__free(cfg);
90
90
  return -1;
91
91
  }
@@ -110,11 +110,11 @@ int git_config_add_file_ondisk(
110
110
 
111
111
  res = p_stat(path, &st);
112
112
  if (res < 0 && errno != ENOENT && errno != ENOTDIR) {
113
- giterr_set(GITERR_CONFIG, "failed to stat '%s'", path);
113
+ git_error_set(GIT_ERROR_CONFIG, "failed to stat '%s'", path);
114
114
  return -1;
115
115
  }
116
116
 
117
- if (git_config_file__ondisk(&file, path) < 0)
117
+ if (git_config_backend_from_file(&file, path) < 0)
118
118
  return -1;
119
119
 
120
120
  if ((res = git_config_add_backend(cfg, file, level, repo, force)) < 0) {
@@ -151,7 +151,7 @@ int git_config_snapshot(git_config **out, git_config *in)
151
151
  {
152
152
  int error = 0;
153
153
  size_t i;
154
- file_internal *internal;
154
+ backend_internal *internal;
155
155
  git_config *config;
156
156
 
157
157
  *out = NULL;
@@ -159,10 +159,10 @@ int git_config_snapshot(git_config **out, git_config *in)
159
159
  if (git_config_new(&config) < 0)
160
160
  return -1;
161
161
 
162
- git_vector_foreach(&in->files, i, internal) {
162
+ git_vector_foreach(&in->backends, i, internal) {
163
163
  git_config_backend *b;
164
164
 
165
- if ((error = internal->file->snapshot(&b, internal->file)) < 0)
165
+ if ((error = internal->backend->snapshot(&b, internal->backend)) < 0)
166
166
  break;
167
167
 
168
168
  if ((error = git_config_add_backend(config, b, internal->level, NULL, 0)) < 0) {
@@ -179,59 +179,59 @@ int git_config_snapshot(git_config **out, git_config *in)
179
179
  return error;
180
180
  }
181
181
 
182
- static int find_internal_file_by_level(
183
- file_internal **internal_out,
182
+ static int find_backend_by_level(
183
+ backend_internal **out,
184
184
  const git_config *cfg,
185
185
  git_config_level_t level)
186
186
  {
187
187
  int pos = -1;
188
- file_internal *internal;
188
+ backend_internal *internal;
189
189
  size_t i;
190
190
 
191
- /* when passing GIT_CONFIG_HIGHEST_LEVEL, the idea is to get the config file
192
- * which has the highest level. As config files are stored in a vector
193
- * sorted by decreasing order of level, getting the file at position 0
191
+ /* when passing GIT_CONFIG_HIGHEST_LEVEL, the idea is to get the config backend
192
+ * which has the highest level. As config backends are stored in a vector
193
+ * sorted by decreasing order of level, getting the backend at position 0
194
194
  * will do the job.
195
195
  */
196
196
  if (level == GIT_CONFIG_HIGHEST_LEVEL) {
197
197
  pos = 0;
198
198
  } else {
199
- git_vector_foreach(&cfg->files, i, internal) {
199
+ git_vector_foreach(&cfg->backends, i, internal) {
200
200
  if (internal->level == level)
201
201
  pos = (int)i;
202
202
  }
203
203
  }
204
204
 
205
205
  if (pos == -1) {
206
- giterr_set(GITERR_CONFIG,
207
- "no config file exists for the given level '%i'", (int)level);
206
+ git_error_set(GIT_ERROR_CONFIG,
207
+ "no configuration exists for the given level '%i'", (int)level);
208
208
  return GIT_ENOTFOUND;
209
209
  }
210
210
 
211
- *internal_out = git_vector_get(&cfg->files, pos);
211
+ *out = git_vector_get(&cfg->backends, pos);
212
212
 
213
213
  return 0;
214
214
  }
215
215
 
216
216
  static int duplicate_level(void **old_raw, void *new_raw)
217
217
  {
218
- file_internal **old = (file_internal **)old_raw;
218
+ backend_internal **old = (backend_internal **)old_raw;
219
219
 
220
220
  GIT_UNUSED(new_raw);
221
221
 
222
- giterr_set(GITERR_CONFIG, "a file with the same level (%i) has already been added to the config", (int)(*old)->level);
222
+ git_error_set(GIT_ERROR_CONFIG, "there already exists a configuration for the given level (%i)", (int)(*old)->level);
223
223
  return GIT_EEXISTS;
224
224
  }
225
225
 
226
- static void try_remove_existing_file_internal(
226
+ static void try_remove_existing_backend(
227
227
  git_config *cfg,
228
228
  git_config_level_t level)
229
229
  {
230
230
  int pos = -1;
231
- file_internal *internal;
231
+ backend_internal *internal;
232
232
  size_t i;
233
233
 
234
- git_vector_foreach(&cfg->files, i, internal) {
234
+ git_vector_foreach(&cfg->backends, i, internal) {
235
235
  if (internal->level == level)
236
236
  pos = (int)i;
237
237
  }
@@ -239,32 +239,32 @@ static void try_remove_existing_file_internal(
239
239
  if (pos == -1)
240
240
  return;
241
241
 
242
- internal = git_vector_get(&cfg->files, pos);
242
+ internal = git_vector_get(&cfg->backends, pos);
243
243
 
244
- if (git_vector_remove(&cfg->files, pos) < 0)
244
+ if (git_vector_remove(&cfg->backends, pos) < 0)
245
245
  return;
246
246
 
247
- GIT_REFCOUNT_DEC(internal, file_internal_free);
247
+ GIT_REFCOUNT_DEC(internal, backend_internal_free);
248
248
  }
249
249
 
250
250
  static int git_config__add_internal(
251
251
  git_config *cfg,
252
- file_internal *internal,
252
+ backend_internal *internal,
253
253
  git_config_level_t level,
254
254
  int force)
255
255
  {
256
256
  int result;
257
257
 
258
- /* delete existing config file for level if it exists */
258
+ /* delete existing config backend for level if it exists */
259
259
  if (force)
260
- try_remove_existing_file_internal(cfg, level);
260
+ try_remove_existing_backend(cfg, level);
261
261
 
262
- if ((result = git_vector_insert_sorted(&cfg->files,
262
+ if ((result = git_vector_insert_sorted(&cfg->backends,
263
263
  internal, &duplicate_level)) < 0)
264
264
  return result;
265
265
 
266
- git_vector_sort(&cfg->files);
267
- internal->file->cfg = cfg;
266
+ git_vector_sort(&cfg->backends);
267
+ internal->backend->cfg = cfg;
268
268
 
269
269
  GIT_REFCOUNT_INC(internal);
270
270
 
@@ -285,10 +285,10 @@ int git_config_open_level(
285
285
  git_config_level_t level)
286
286
  {
287
287
  git_config *cfg;
288
- file_internal *internal;
288
+ backend_internal *internal;
289
289
  int res;
290
290
 
291
- if ((res = find_internal_file_by_level(&internal, cfg_parent, level)) < 0)
291
+ if ((res = find_backend_by_level(&internal, cfg_parent, level)) < 0)
292
292
  return res;
293
293
 
294
294
  if ((res = git_config_new(&cfg)) < 0)
@@ -306,27 +306,27 @@ int git_config_open_level(
306
306
 
307
307
  int git_config_add_backend(
308
308
  git_config *cfg,
309
- git_config_backend *file,
309
+ git_config_backend *backend,
310
310
  git_config_level_t level,
311
311
  const git_repository *repo,
312
312
  int force)
313
313
  {
314
- file_internal *internal;
314
+ backend_internal *internal;
315
315
  int result;
316
316
 
317
- assert(cfg && file);
317
+ assert(cfg && backend);
318
318
 
319
- GITERR_CHECK_VERSION(file, GIT_CONFIG_BACKEND_VERSION, "git_config_backend");
319
+ GIT_ERROR_CHECK_VERSION(backend, GIT_CONFIG_BACKEND_VERSION, "git_config_backend");
320
320
 
321
- if ((result = file->open(file, level, repo)) < 0)
321
+ if ((result = backend->open(backend, level, repo)) < 0)
322
322
  return result;
323
323
 
324
- internal = git__malloc(sizeof(file_internal));
325
- GITERR_CHECK_ALLOC(internal);
324
+ internal = git__malloc(sizeof(backend_internal));
325
+ GIT_ERROR_CHECK_ALLOC(internal);
326
326
 
327
- memset(internal, 0x0, sizeof(file_internal));
327
+ memset(internal, 0x0, sizeof(backend_internal));
328
328
 
329
- internal->file = file;
329
+ internal->backend = backend;
330
330
  internal->level = level;
331
331
 
332
332
  if ((result = git_config__add_internal(cfg, internal, level, force)) < 0) {
@@ -351,11 +351,11 @@ typedef struct {
351
351
 
352
352
  static int find_next_backend(size_t *out, const git_config *cfg, size_t i)
353
353
  {
354
- file_internal *internal;
354
+ backend_internal *internal;
355
355
 
356
356
  for (; i > 0; --i) {
357
- internal = git_vector_get(&cfg->files, i - 1);
358
- if (!internal || !internal->file)
357
+ internal = git_vector_get(&cfg->backends, i - 1);
358
+ if (!internal || !internal->backend)
359
359
  continue;
360
360
 
361
361
  *out = i;
@@ -368,7 +368,7 @@ static int find_next_backend(size_t *out, const git_config *cfg, size_t i)
368
368
  static int all_iter_next(git_config_entry **entry, git_config_iterator *_iter)
369
369
  {
370
370
  all_iter *iter = (all_iter *) _iter;
371
- file_internal *internal;
371
+ backend_internal *internal;
372
372
  git_config_backend *backend;
373
373
  size_t i;
374
374
  int error = 0;
@@ -385,8 +385,8 @@ static int all_iter_next(git_config_entry **entry, git_config_iterator *_iter)
385
385
  if (find_next_backend(&i, iter->cfg, iter->i) < 0)
386
386
  return GIT_ITEROVER;
387
387
 
388
- internal = git_vector_get(&iter->cfg->files, i - 1);
389
- backend = internal->file;
388
+ internal = git_vector_get(&iter->cfg->backends, i - 1);
389
+ backend = internal->backend;
390
390
  iter->i = i - 1;
391
391
 
392
392
  if (iter->current)
@@ -456,12 +456,12 @@ int git_config_iterator_new(git_config_iterator **out, const git_config *cfg)
456
456
  all_iter *iter;
457
457
 
458
458
  iter = git__calloc(1, sizeof(all_iter));
459
- GITERR_CHECK_ALLOC(iter);
459
+ GIT_ERROR_CHECK_ALLOC(iter);
460
460
 
461
461
  iter->parent.free = all_iter_free;
462
462
  iter->parent.next = all_iter_next;
463
463
 
464
- iter->i = cfg->files.length;
464
+ iter->i = cfg->backends.length;
465
465
  iter->cfg = cfg;
466
466
 
467
467
  *out = (git_config_iterator *) iter;
@@ -478,17 +478,17 @@ int git_config_iterator_glob_new(git_config_iterator **out, const git_config *cf
478
478
  return git_config_iterator_new(out, cfg);
479
479
 
480
480
  iter = git__calloc(1, sizeof(all_iter));
481
- GITERR_CHECK_ALLOC(iter);
481
+ GIT_ERROR_CHECK_ALLOC(iter);
482
482
 
483
483
  if ((result = p_regcomp(&iter->regex, regexp, REG_EXTENDED)) != 0) {
484
- giterr_set_regex(&iter->regex, result);
484
+ git_error_set_regex(&iter->regex, result);
485
485
  git__free(iter);
486
486
  return -1;
487
487
  }
488
488
 
489
489
  iter->parent.next = all_iter_glob_next;
490
490
  iter->parent.free = all_iter_glob_free;
491
- iter->i = cfg->files.length;
491
+ iter->i = cfg->backends.length;
492
492
  iter->cfg = cfg;
493
493
 
494
494
  *out = (git_config_iterator *) iter;
@@ -517,7 +517,7 @@ int git_config_backend_foreach_match(
517
517
 
518
518
  if (regexp != NULL) {
519
519
  if ((error = p_regcomp(&regex, regexp, REG_EXTENDED)) != 0) {
520
- giterr_set_regex(&regex, error);
520
+ git_error_set_regex(&regex, error);
521
521
  regfree(&regex);
522
522
  return -1;
523
523
  }
@@ -535,7 +535,7 @@ int git_config_backend_foreach_match(
535
535
 
536
536
  /* abort iterator on non-zero return value */
537
537
  if ((error = cb(entry, payload)) != 0) {
538
- giterr_set_after_callback(error);
538
+ git_error_set_after_callback(error);
539
539
  break;
540
540
  }
541
541
  }
@@ -563,7 +563,7 @@ int git_config_foreach_match(
563
563
 
564
564
  while (!(error = git_config_next(&entry, iter))) {
565
565
  if ((error = cb(entry, payload)) != 0) {
566
- giterr_set_after_callback(error);
566
+ git_error_set_after_callback(error);
567
567
  break;
568
568
  }
569
569
  }
@@ -594,38 +594,38 @@ static int get_backend_for_use(git_config_backend **out,
594
594
  git_config *cfg, const char *name, backend_use use)
595
595
  {
596
596
  size_t i;
597
- file_internal *f;
597
+ backend_internal *backend;
598
598
 
599
599
  *out = NULL;
600
600
 
601
- if (git_vector_length(&cfg->files) == 0) {
602
- giterr_set(GITERR_CONFIG,
603
- "cannot %s value for '%s' when no config files exist",
601
+ if (git_vector_length(&cfg->backends) == 0) {
602
+ git_error_set(GIT_ERROR_CONFIG,
603
+ "cannot %s value for '%s' when no config backends exist",
604
604
  uses[use], name);
605
605
  return GIT_ENOTFOUND;
606
606
  }
607
607
 
608
- git_vector_foreach(&cfg->files, i, f) {
609
- if (!f->file->readonly) {
610
- *out = f->file;
608
+ git_vector_foreach(&cfg->backends, i, backend) {
609
+ if (!backend->backend->readonly) {
610
+ *out = backend->backend;
611
611
  return 0;
612
612
  }
613
613
  }
614
614
 
615
- giterr_set(GITERR_CONFIG,
616
- "cannot %s value for '%s' when all config files are readonly",
615
+ git_error_set(GIT_ERROR_CONFIG,
616
+ "cannot %s value for '%s' when all config backends are readonly",
617
617
  uses[use], name);
618
618
  return GIT_ENOTFOUND;
619
619
  }
620
620
 
621
621
  int git_config_delete_entry(git_config *cfg, const char *name)
622
622
  {
623
- git_config_backend *file;
623
+ git_config_backend *backend;
624
624
 
625
- if (get_backend_for_use(&file, cfg, name, BACKEND_USE_DELETE) < 0)
625
+ if (get_backend_for_use(&backend, cfg, name, BACKEND_USE_DELETE) < 0)
626
626
  return GIT_ENOTFOUND;
627
627
 
628
- return file->del(file, name);
628
+ return backend->del(backend, name);
629
629
  }
630
630
 
631
631
  int git_config_set_int64(git_config *cfg, const char *name, int64_t value)
@@ -648,17 +648,17 @@ int git_config_set_bool(git_config *cfg, const char *name, int value)
648
648
  int git_config_set_string(git_config *cfg, const char *name, const char *value)
649
649
  {
650
650
  int error;
651
- git_config_backend *file;
651
+ git_config_backend *backend;
652
652
 
653
653
  if (!value) {
654
- giterr_set(GITERR_CONFIG, "the value to set cannot be NULL");
654
+ git_error_set(GIT_ERROR_CONFIG, "the value to set cannot be NULL");
655
655
  return -1;
656
656
  }
657
657
 
658
- if (get_backend_for_use(&file, cfg, name, BACKEND_USE_SET) < 0)
658
+ if (get_backend_for_use(&backend, cfg, name, BACKEND_USE_SET) < 0)
659
659
  return GIT_ENOTFOUND;
660
660
 
661
- error = file->set(file, name, value);
661
+ error = backend->set(backend, name, value);
662
662
 
663
663
  if (!error && GIT_REFCOUNT_OWNER(cfg) != NULL)
664
664
  git_repository__cvar_cache_clear(GIT_REFCOUNT_OWNER(cfg));
@@ -703,7 +703,7 @@ int git_config__update_entry(
703
703
 
704
704
  static int config_error_notfound(const char *name)
705
705
  {
706
- giterr_set(GITERR_CONFIG, "config value '%s' was not found", name);
706
+ git_error_set(GIT_ERROR_CONFIG, "config value '%s' was not found", name);
707
707
  return GIT_ENOTFOUND;
708
708
  }
709
709
 
@@ -724,7 +724,7 @@ static int get_entry(
724
724
  const char *key = name;
725
725
  char *normalized = NULL;
726
726
  size_t i;
727
- file_internal *internal;
727
+ backend_internal *internal;
728
728
 
729
729
  *out = NULL;
730
730
 
@@ -735,11 +735,11 @@ static int get_entry(
735
735
  }
736
736
 
737
737
  res = GIT_ENOTFOUND;
738
- git_vector_foreach(&cfg->files, i, internal) {
739
- if (!internal || !internal->file)
738
+ git_vector_foreach(&cfg->backends, i, internal) {
739
+ if (!internal || !internal->backend)
740
740
  continue;
741
741
 
742
- res = internal->file->get(internal->file, key, out);
742
+ res = internal->backend->get(internal->backend, key, out);
743
743
  if (res != GIT_ENOTFOUND)
744
744
  break;
745
745
  }
@@ -750,7 +750,7 @@ cleanup:
750
750
  if (res == GIT_ENOTFOUND)
751
751
  res = (want_errors > GET_ALL_ERRORS) ? 0 : config_error_notfound(name);
752
752
  else if (res && (want_errors == GET_NO_ERRORS)) {
753
- giterr_clear();
753
+ git_error_clear();
754
754
  res = 0;
755
755
  }
756
756
 
@@ -837,13 +837,13 @@ int git_config_get_bool(int *out, const git_config *cfg, const char *name)
837
837
  static int is_readonly(const git_config *cfg)
838
838
  {
839
839
  size_t i;
840
- file_internal *internal;
840
+ backend_internal *internal;
841
841
 
842
- git_vector_foreach(&cfg->files, i, internal) {
843
- if (!internal || !internal->file)
842
+ git_vector_foreach(&cfg->backends, i, internal) {
843
+ if (!internal || !internal->backend)
844
844
  continue;
845
845
 
846
- if (!internal->file->readonly)
846
+ if (!internal->backend->readonly)
847
847
  return 0;
848
848
  }
849
849
 
@@ -871,7 +871,7 @@ int git_config_get_string(
871
871
  int ret;
872
872
 
873
873
  if (!is_readonly(cfg)) {
874
- giterr_set(GITERR_CONFIG, "get_string called on a live config object");
874
+ git_error_set(GIT_ERROR_CONFIG, "get_string called on a live config object");
875
875
  return -1;
876
876
  }
877
877
 
@@ -925,7 +925,7 @@ int git_config__get_bool_force(
925
925
  get_entry(&entry, cfg, key, false, GET_NO_ERRORS);
926
926
 
927
927
  if (entry && git_config_parse_bool(&val, entry->value) < 0)
928
- giterr_clear();
928
+ git_error_clear();
929
929
 
930
930
  git_config_entry_free(entry);
931
931
  return val;
@@ -940,7 +940,7 @@ int git_config__get_int_force(
940
940
  get_entry(&entry, cfg, key, false, GET_NO_ERRORS);
941
941
 
942
942
  if (entry && git_config_parse_int32(&val, entry->value) < 0)
943
- giterr_clear();
943
+ git_error_clear();
944
944
 
945
945
  git_config_entry_free(entry);
946
946
  return (int)val;
@@ -962,7 +962,7 @@ int git_config_get_multivar_foreach(
962
962
  found = 1;
963
963
 
964
964
  if ((err = cb(entry, payload)) != 0) {
965
- giterr_set_after_callback(err);
965
+ git_error_set_after_callback(err);
966
966
  break;
967
967
  }
968
968
  }
@@ -1026,7 +1026,7 @@ int git_config_multivar_iterator_new(git_config_iterator **out, const git_config
1026
1026
  return error;
1027
1027
 
1028
1028
  iter = git__calloc(1, sizeof(multivar_iter));
1029
- GITERR_CHECK_ALLOC(iter);
1029
+ GIT_ERROR_CHECK_ALLOC(iter);
1030
1030
 
1031
1031
  if ((error = git_config__normalize_name(name, &iter->name)) < 0)
1032
1032
  goto on_error;
@@ -1034,7 +1034,7 @@ int git_config_multivar_iterator_new(git_config_iterator **out, const git_config
1034
1034
  if (regexp != NULL) {
1035
1035
  error = p_regcomp(&iter->regex, regexp, REG_EXTENDED);
1036
1036
  if (error != 0) {
1037
- giterr_set_regex(&iter->regex, error);
1037
+ git_error_set_regex(&iter->regex, error);
1038
1038
  error = -1;
1039
1039
  regfree(&iter->regex);
1040
1040
  goto on_error;
@@ -1060,22 +1060,22 @@ on_error:
1060
1060
 
1061
1061
  int git_config_set_multivar(git_config *cfg, const char *name, const char *regexp, const char *value)
1062
1062
  {
1063
- git_config_backend *file;
1063
+ git_config_backend *backend;
1064
1064
 
1065
- if (get_backend_for_use(&file, cfg, name, BACKEND_USE_DELETE) < 0)
1065
+ if (get_backend_for_use(&backend, cfg, name, BACKEND_USE_DELETE) < 0)
1066
1066
  return GIT_ENOTFOUND;
1067
1067
 
1068
- return file->set_multivar(file, name, regexp, value);
1068
+ return backend->set_multivar(backend, name, regexp, value);
1069
1069
  }
1070
1070
 
1071
1071
  int git_config_delete_multivar(git_config *cfg, const char *name, const char *regexp)
1072
1072
  {
1073
- git_config_backend *file;
1073
+ git_config_backend *backend;
1074
1074
 
1075
- if (get_backend_for_use(&file, cfg, name, BACKEND_USE_DELETE) < 0)
1075
+ if (get_backend_for_use(&backend, cfg, name, BACKEND_USE_DELETE) < 0)
1076
1076
  return GIT_ENOTFOUND;
1077
1077
 
1078
- return file->del_multivar(file, name, regexp);
1078
+ return backend->del_multivar(backend, name, regexp);
1079
1079
  }
1080
1080
 
1081
1081
  int git_config_next(git_config_entry **entry, git_config_iterator *iter)
@@ -1111,15 +1111,8 @@ int git_config_find_system(git_buf *path)
1111
1111
 
1112
1112
  int git_config_find_programdata(git_buf *path)
1113
1113
  {
1114
- int ret;
1115
-
1116
1114
  git_buf_sanitize(path);
1117
- ret = git_sysdir_find_programdata_file(path,
1118
- GIT_CONFIG_FILENAME_PROGRAMDATA);
1119
- if (ret != GIT_OK)
1120
- return ret;
1121
-
1122
- return git_path_validate_system_file_ownership(path->ptr);
1115
+ return git_sysdir_find_programdata_file(path, GIT_CONFIG_FILENAME_PROGRAMDATA);
1123
1116
  }
1124
1117
 
1125
1118
  int git_config__global_location(git_buf *buf)
@@ -1173,7 +1166,7 @@ int git_config_open_default(git_config **out)
1173
1166
  error = git_config_add_file_ondisk(cfg, buf.ptr,
1174
1167
  GIT_CONFIG_LEVEL_PROGRAMDATA, NULL, 0);
1175
1168
 
1176
- git_buf_free(&buf);
1169
+ git_buf_dispose(&buf);
1177
1170
 
1178
1171
  if (error) {
1179
1172
  git_config_free(cfg);
@@ -1188,17 +1181,19 @@ int git_config_open_default(git_config **out)
1188
1181
  int git_config_lock(git_transaction **out, git_config *cfg)
1189
1182
  {
1190
1183
  int error;
1191
- git_config_backend *file;
1192
- file_internal *internal;
1184
+ git_config_backend *backend;
1185
+ backend_internal *internal;
1186
+
1187
+ assert(cfg);
1193
1188
 
1194
- internal = git_vector_get(&cfg->files, 0);
1195
- if (!internal || !internal->file) {
1196
- giterr_set(GITERR_CONFIG, "cannot lock; the config has no backends/files");
1189
+ internal = git_vector_get(&cfg->backends, 0);
1190
+ if (!internal || !internal->backend) {
1191
+ git_error_set(GIT_ERROR_CONFIG, "cannot lock; the config has no backends");
1197
1192
  return -1;
1198
1193
  }
1199
- file = internal->file;
1194
+ backend = internal->backend;
1200
1195
 
1201
- if ((error = file->lock(file)) < 0)
1196
+ if ((error = backend->lock(backend)) < 0)
1202
1197
  return error;
1203
1198
 
1204
1199
  return git_transaction_config_new(out, cfg);
@@ -1206,18 +1201,20 @@ int git_config_lock(git_transaction **out, git_config *cfg)
1206
1201
 
1207
1202
  int git_config_unlock(git_config *cfg, int commit)
1208
1203
  {
1209
- git_config_backend *file;
1210
- file_internal *internal;
1204
+ git_config_backend *backend;
1205
+ backend_internal *internal;
1206
+
1207
+ assert(cfg);
1211
1208
 
1212
- internal = git_vector_get(&cfg->files, 0);
1213
- if (!internal || !internal->file) {
1214
- giterr_set(GITERR_CONFIG, "cannot lock; the config has no backends/files");
1209
+ internal = git_vector_get(&cfg->backends, 0);
1210
+ if (!internal || !internal->backend) {
1211
+ git_error_set(GIT_ERROR_CONFIG, "cannot lock; the config has no backends");
1215
1212
  return -1;
1216
1213
  }
1217
1214
 
1218
- file = internal->file;
1215
+ backend = internal->backend;
1219
1216
 
1220
- return file->unlock(file, commit);
1217
+ return backend->unlock(backend, commit);
1221
1218
  }
1222
1219
 
1223
1220
  /***********
@@ -1266,7 +1263,7 @@ int git_config_lookup_map_value(
1266
1263
  }
1267
1264
 
1268
1265
  fail_parse:
1269
- giterr_set(GITERR_CONFIG, "failed to map '%s'", value);
1266
+ git_error_set(GIT_ERROR_CONFIG, "failed to map '%s'", value);
1270
1267
  return -1;
1271
1268
  }
1272
1269
 
@@ -1286,7 +1283,7 @@ int git_config_lookup_map_enum(git_cvar_t *type_out, const char **str_out,
1286
1283
  return 0;
1287
1284
  }
1288
1285
 
1289
- giterr_set(GITERR_CONFIG, "invalid enum value");
1286
+ git_error_set(GIT_ERROR_CONFIG, "invalid enum value");
1290
1287
  return GIT_ENOTFOUND;
1291
1288
  }
1292
1289
 
@@ -1300,7 +1297,7 @@ int git_config_parse_bool(int *out, const char *value)
1300
1297
  return 0;
1301
1298
  }
1302
1299
 
1303
- giterr_set(GITERR_CONFIG, "failed to parse '%s' as a boolean value", value);
1300
+ git_error_set(GIT_ERROR_CONFIG, "failed to parse '%s' as a boolean value", value);
1304
1301
  return -1;
1305
1302
  }
1306
1303
 
@@ -1343,7 +1340,7 @@ int git_config_parse_int64(int64_t *out, const char *value)
1343
1340
  }
1344
1341
 
1345
1342
  fail_parse:
1346
- giterr_set(GITERR_CONFIG, "failed to parse '%s' as an integer", value ? value : "(null)");
1343
+ git_error_set(GIT_ERROR_CONFIG, "failed to parse '%s' as an integer", value ? value : "(null)");
1347
1344
  return -1;
1348
1345
  }
1349
1346
 
@@ -1363,7 +1360,7 @@ int git_config_parse_int32(int32_t *out, const char *value)
1363
1360
  return 0;
1364
1361
 
1365
1362
  fail_parse:
1366
- giterr_set(GITERR_CONFIG, "failed to parse '%s' as a 32-bit integer", value ? value : "(null)");
1363
+ git_error_set(GIT_ERROR_CONFIG, "failed to parse '%s' as a 32-bit integer", value ? value : "(null)");
1367
1364
  return -1;
1368
1365
  }
1369
1366
 
@@ -1375,7 +1372,7 @@ int git_config_parse_path(git_buf *out, const char *value)
1375
1372
 
1376
1373
  if (value[0] == '~') {
1377
1374
  if (value[1] != '\0' && value[1] != '/') {
1378
- giterr_set(GITERR_CONFIG, "retrieving a homedir by name is not supported");
1375
+ git_error_set(GIT_ERROR_CONFIG, "retrieving a homedir by name is not supported");
1379
1376
  return -1;
1380
1377
  }
1381
1378
 
@@ -1385,6 +1382,30 @@ int git_config_parse_path(git_buf *out, const char *value)
1385
1382
  return git_buf_sets(out, value);
1386
1383
  }
1387
1384
 
1385
+ static int normalize_section(char *start, char *end)
1386
+ {
1387
+ char *scan;
1388
+
1389
+ if (start == end)
1390
+ return GIT_EINVALIDSPEC;
1391
+
1392
+ /* Validate and downcase range */
1393
+ for (scan = start; *scan; ++scan) {
1394
+ if (end && scan >= end)
1395
+ break;
1396
+ if (isalnum(*scan))
1397
+ *scan = (char)git__tolower(*scan);
1398
+ else if (*scan != '-' || scan == start)
1399
+ return GIT_EINVALIDSPEC;
1400
+ }
1401
+
1402
+ if (scan == start)
1403
+ return GIT_EINVALIDSPEC;
1404
+
1405
+ return 0;
1406
+ }
1407
+
1408
+
1388
1409
  /* Take something the user gave us and make it nice for our hash function */
1389
1410
  int git_config__normalize_name(const char *in, char **out)
1390
1411
  {
@@ -1393,7 +1414,7 @@ int git_config__normalize_name(const char *in, char **out)
1393
1414
  assert(in && out);
1394
1415
 
1395
1416
  name = git__strdup(in);
1396
- GITERR_CHECK_ALLOC(name);
1417
+ GIT_ERROR_CHECK_ALLOC(name);
1397
1418
 
1398
1419
  fdot = strchr(name, '.');
1399
1420
  ldot = strrchr(name, '.');
@@ -1402,8 +1423,8 @@ int git_config__normalize_name(const char *in, char **out)
1402
1423
  goto invalid;
1403
1424
 
1404
1425
  /* Validate and downcase up to first dot and after last dot */
1405
- if (git_config_file_normalize_section(name, fdot) < 0 ||
1406
- git_config_file_normalize_section(ldot + 1, NULL) < 0)
1426
+ if (normalize_section(name, fdot) < 0 ||
1427
+ normalize_section(ldot + 1, NULL) < 0)
1407
1428
  goto invalid;
1408
1429
 
1409
1430
  /* If there is a middle range, make sure it doesn't have newlines */
@@ -1416,7 +1437,7 @@ int git_config__normalize_name(const char *in, char **out)
1416
1437
 
1417
1438
  invalid:
1418
1439
  git__free(name);
1419
- giterr_set(GITERR_CONFIG, "invalid config item name '%s'", in);
1440
+ git_error_set(GIT_ERROR_CONFIG, "invalid config item name '%s'", in);
1420
1441
  return GIT_EINVALIDSPEC;
1421
1442
  }
1422
1443
 
@@ -1475,11 +1496,10 @@ int git_config_rename_section(
1475
1496
  goto cleanup;
1476
1497
 
1477
1498
  if (new_section_name != NULL &&
1478
- (error = git_config_file_normalize_section(
1479
- replace.ptr, strchr(replace.ptr, '.'))) < 0)
1499
+ (error = normalize_section(replace.ptr, strchr(replace.ptr, '.'))) < 0)
1480
1500
  {
1481
- giterr_set(
1482
- GITERR_CONFIG, "invalid config section '%s'", new_section_name);
1501
+ git_error_set(
1502
+ GIT_ERROR_CONFIG, "invalid config section '%s'", new_section_name);
1483
1503
  goto cleanup;
1484
1504
  }
1485
1505
 
@@ -1487,8 +1507,8 @@ int git_config_rename_section(
1487
1507
  config, git_buf_cstr(&pattern), rename_config_entries_cb, &data);
1488
1508
 
1489
1509
  cleanup:
1490
- git_buf_free(&pattern);
1491
- git_buf_free(&replace);
1510
+ git_buf_dispose(&pattern);
1511
+ git_buf_dispose(&replace);
1492
1512
 
1493
1513
  return error;
1494
1514
  }