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
@@ -59,24 +59,6 @@ extern int git_win32__set_hidden(const char *path, bool hidden);
59
59
  */
60
60
  extern int git_win32__hidden(bool *hidden, const char *path);
61
61
 
62
- /**
63
- * Removes any trailing backslashes from a path, except in the case of a drive
64
- * letter path (C:\, D:\, etc.). This function cannot fail.
65
- *
66
- * @param path The path which should be trimmed.
67
- * @return The length of the modified string (<= the input length)
68
- */
69
- size_t git_win32__path_trim_end(wchar_t *str, size_t len);
70
-
71
- /**
72
- * Removes any of the following namespace prefixes from a path,
73
- * if found: "\??\", "\\?\", "\\?\UNC\". This function cannot fail.
74
- *
75
- * @param path The path which should be converted.
76
- * @return The length of the modified string (<= the input length)
77
- */
78
- size_t git_win32__canonicalize_path(wchar_t *str, size_t len);
79
-
80
62
  /**
81
63
  * Converts a FILETIME structure to a struct timespec.
82
64
  *
@@ -176,7 +158,7 @@ GIT_INLINE(int) git_win32__file_attribute_to_stat(
176
158
  /* st_size gets the UTF-8 length of the target name, in bytes,
177
159
  * not counting the NULL terminator */
178
160
  if ((st->st_size = git__utf16_to_8(NULL, 0, target)) < 0) {
179
- giterr_set(GITERR_OS, "could not convert reparse point name for '%ls'", path);
161
+ git_error_set(GIT_ERROR_OS, "could not convert reparse point name for '%ls'", path);
180
162
  return -1;
181
163
  }
182
164
  }
@@ -25,7 +25,7 @@ static bool is_worktree_dir(const char *dir)
25
25
  && git_path_contains_file(&buf, "gitdir")
26
26
  && git_path_contains_file(&buf, "HEAD");
27
27
 
28
- git_buf_free(&buf);
28
+ git_buf_dispose(&buf);
29
29
  return error;
30
30
  }
31
31
 
@@ -64,7 +64,7 @@ int git_worktree_list(git_strarray *wts, git_repository *repo)
64
64
  wts->strings = (char **)git_vector_detach(&wts->count, NULL, &worktrees);
65
65
 
66
66
  exit:
67
- git_buf_free(&path);
67
+ git_buf_dispose(&path);
68
68
 
69
69
  return error;
70
70
  }
@@ -79,7 +79,7 @@ char *git_worktree__read_link(const char *base, const char *file)
79
79
  goto err;
80
80
  if (git_futils_readbuffer(&buf, path.ptr) < 0)
81
81
  goto err;
82
- git_buf_free(&path);
82
+ git_buf_dispose(&path);
83
83
 
84
84
  git_buf_rtrim(&buf);
85
85
 
@@ -90,13 +90,13 @@ char *git_worktree__read_link(const char *base, const char *file)
90
90
  goto err;
91
91
  if (git_path_apply_relative(&path, buf.ptr) < 0)
92
92
  goto err;
93
- git_buf_free(&buf);
93
+ git_buf_dispose(&buf);
94
94
 
95
95
  return git_buf_detach(&path);
96
96
 
97
97
  err:
98
- git_buf_free(&buf);
99
- git_buf_free(&path);
98
+ git_buf_dispose(&buf);
99
+ git_buf_dispose(&path);
100
100
 
101
101
  return NULL;
102
102
  }
@@ -115,7 +115,7 @@ static int write_wtfile(const char *base, const char *file, const git_buf *buf)
115
115
  goto out;
116
116
 
117
117
  out:
118
- git_buf_free(&path);
118
+ git_buf_dispose(&path);
119
119
 
120
120
  return err;
121
121
  }
@@ -139,7 +139,8 @@ static int open_worktree_dir(git_worktree **out, const char *parent, const char
139
139
  if ((wt->name = git__strdup(name)) == NULL
140
140
  || (wt->commondir_path = git_worktree__read_link(dir, "commondir")) == NULL
141
141
  || (wt->gitlink_path = git_worktree__read_link(dir, "gitdir")) == NULL
142
- || (parent && (wt->parent_path = git__strdup(parent)) == NULL)) {
142
+ || (parent && (wt->parent_path = git__strdup(parent)) == NULL)
143
+ || (wt->worktree_path = git_path_dirname(wt->gitlink_path)) == NULL) {
143
144
  error = -1;
144
145
  goto out;
145
146
  }
@@ -155,7 +156,7 @@ static int open_worktree_dir(git_worktree **out, const char *parent, const char
155
156
  out:
156
157
  if (error)
157
158
  git_worktree_free(wt);
158
- git_buf_free(&gitdir);
159
+ git_buf_dispose(&gitdir);
159
160
 
160
161
  return error;
161
162
  }
@@ -177,7 +178,7 @@ int git_worktree_lookup(git_worktree **out, git_repository *repo, const char *na
177
178
  goto out;
178
179
 
179
180
  out:
180
- git_buf_free(&path);
181
+ git_buf_dispose(&path);
181
182
 
182
183
  if (error)
183
184
  git_worktree_free(wt);
@@ -193,7 +194,7 @@ int git_worktree_open_from_repository(git_worktree **out, git_repository *repo)
193
194
  int error = 0;
194
195
 
195
196
  if (!git_repository_is_worktree(repo)) {
196
- giterr_set(GITERR_WORKTREE, "cannot open worktree of a non-worktree repo");
197
+ git_error_set(GIT_ERROR_WORKTREE, "cannot open worktree of a non-worktree repo");
197
198
  error = -1;
198
199
  goto out;
199
200
  }
@@ -212,7 +213,7 @@ int git_worktree_open_from_repository(git_worktree **out, git_repository *repo)
212
213
 
213
214
  out:
214
215
  git__free(name);
215
- git_buf_free(&parent);
216
+ git_buf_dispose(&parent);
216
217
 
217
218
  return error;
218
219
  }
@@ -223,6 +224,7 @@ void git_worktree_free(git_worktree *wt)
223
224
  return;
224
225
 
225
226
  git__free(wt->commondir_path);
227
+ git__free(wt->worktree_path);
226
228
  git__free(wt->gitlink_path);
227
229
  git__free(wt->gitdir_path);
228
230
  git__free(wt->parent_path);
@@ -232,40 +234,30 @@ void git_worktree_free(git_worktree *wt)
232
234
 
233
235
  int git_worktree_validate(const git_worktree *wt)
234
236
  {
235
- git_buf buf = GIT_BUF_INIT;
236
- int err = 0;
237
-
238
237
  assert(wt);
239
238
 
240
- git_buf_puts(&buf, wt->gitdir_path);
241
- if (!is_worktree_dir(buf.ptr)) {
242
- giterr_set(GITERR_WORKTREE,
239
+ if (!is_worktree_dir(wt->gitdir_path)) {
240
+ git_error_set(GIT_ERROR_WORKTREE,
243
241
  "Worktree gitdir ('%s') is not valid",
244
242
  wt->gitlink_path);
245
- err = -1;
246
- goto out;
243
+ return GIT_ERROR;
247
244
  }
248
245
 
249
- if (!git_path_exists(wt->parent_path)) {
250
- giterr_set(GITERR_WORKTREE,
246
+ if (wt->parent_path && !git_path_exists(wt->parent_path)) {
247
+ git_error_set(GIT_ERROR_WORKTREE,
251
248
  "Worktree parent directory ('%s') does not exist ",
252
249
  wt->parent_path);
253
- err = -2;
254
- goto out;
250
+ return GIT_ERROR;
255
251
  }
256
252
 
257
253
  if (!git_path_exists(wt->commondir_path)) {
258
- giterr_set(GITERR_WORKTREE,
254
+ git_error_set(GIT_ERROR_WORKTREE,
259
255
  "Worktree common directory ('%s') does not exist ",
260
256
  wt->commondir_path);
261
- err = -3;
262
- goto out;
257
+ return GIT_ERROR;
263
258
  }
264
259
 
265
- out:
266
- git_buf_free(&buf);
267
-
268
- return err;
260
+ return 0;
269
261
  }
270
262
 
271
263
  int git_worktree_add_init_options(git_worktree_add_options *opts,
@@ -288,7 +280,7 @@ int git_worktree_add(git_worktree **out, git_repository *repo,
288
280
  git_worktree_add_options wtopts = GIT_WORKTREE_ADD_OPTIONS_INIT;
289
281
  int err;
290
282
 
291
- GITERR_CHECK_VERSION(
283
+ GIT_ERROR_CHECK_VERSION(
292
284
  opts, GIT_WORKTREE_ADD_OPTIONS_VERSION, "git_worktree_add_options");
293
285
 
294
286
  if (opts)
@@ -348,13 +340,30 @@ int git_worktree_add(git_worktree **out, git_repository *repo,
348
340
  || (err = write_wtfile(gitdir.ptr, "gitdir", &buf)) < 0)
349
341
  goto out;
350
342
 
351
- /* Create new branch */
352
- if ((err = git_repository_head(&head, repo)) < 0)
353
- goto out;
354
- if ((err = git_commit_lookup(&commit, repo, &head->target.oid)) < 0)
355
- goto out;
356
- if ((err = git_branch_create(&ref, repo, name, commit, false)) < 0)
357
- goto out;
343
+ /* Set up worktree reference */
344
+ if (wtopts.ref) {
345
+ if (!git_reference_is_branch(wtopts.ref)) {
346
+ git_error_set(GIT_ERROR_WORKTREE, "reference is not a branch");
347
+ err = -1;
348
+ goto out;
349
+ }
350
+
351
+ if (git_branch_is_checked_out(wtopts.ref)) {
352
+ git_error_set(GIT_ERROR_WORKTREE, "reference is already checked out");
353
+ err = -1;
354
+ goto out;
355
+ }
356
+
357
+ if ((err = git_reference_dup(&ref, wtopts.ref)) < 0)
358
+ goto out;
359
+ } else {
360
+ if ((err = git_repository_head(&head, repo)) < 0)
361
+ goto out;
362
+ if ((err = git_commit_lookup(&commit, repo, &head->target.oid)) < 0)
363
+ goto out;
364
+ if ((err = git_branch_create(&ref, repo, name, commit, false)) < 0)
365
+ goto out;
366
+ }
358
367
 
359
368
  /* Set worktree's HEAD */
360
369
  if ((err = git_repository_create_head(gitdir.ptr, git_reference_name(ref))) < 0)
@@ -372,9 +381,9 @@ int git_worktree_add(git_worktree **out, git_repository *repo,
372
381
  goto out;
373
382
 
374
383
  out:
375
- git_buf_free(&gitdir);
376
- git_buf_free(&wddir);
377
- git_buf_free(&buf);
384
+ git_buf_dispose(&gitdir);
385
+ git_buf_dispose(&wddir);
386
+ git_buf_dispose(&buf);
378
387
  git_reference_free(ref);
379
388
  git_reference_free(head);
380
389
  git_commit_free(commit);
@@ -405,7 +414,7 @@ int git_worktree_lock(git_worktree *wt, const char *reason)
405
414
  wt->locked = 1;
406
415
 
407
416
  out:
408
- git_buf_free(&path);
417
+ git_buf_dispose(&path);
409
418
 
410
419
  return err;
411
420
  }
@@ -423,13 +432,13 @@ int git_worktree_unlock(git_worktree *wt)
423
432
  return -1;
424
433
 
425
434
  if (p_unlink(path.ptr) != 0) {
426
- git_buf_free(&path);
435
+ git_buf_dispose(&path);
427
436
  return -1;
428
437
  }
429
438
 
430
439
  wt->locked = 0;
431
440
 
432
- git_buf_free(&path);
441
+ git_buf_dispose(&path);
433
442
 
434
443
  return 0;
435
444
  }
@@ -450,11 +459,23 @@ int git_worktree_is_locked(git_buf *reason, const git_worktree *wt)
450
459
  git_futils_readbuffer(reason, path.ptr);
451
460
 
452
461
  out:
453
- git_buf_free(&path);
462
+ git_buf_dispose(&path);
454
463
 
455
464
  return ret;
456
465
  }
457
466
 
467
+ const char *git_worktree_name(const git_worktree *wt)
468
+ {
469
+ assert(wt);
470
+ return wt->name;
471
+ }
472
+
473
+ const char *git_worktree_path(const git_worktree *wt)
474
+ {
475
+ assert(wt);
476
+ return wt->worktree_path;
477
+ }
478
+
458
479
  int git_worktree_prune_init_options(
459
480
  git_worktree_prune_options *opts,
460
481
  unsigned int version)
@@ -470,7 +491,7 @@ int git_worktree_is_prunable(git_worktree *wt,
470
491
  git_buf reason = GIT_BUF_INIT;
471
492
  git_worktree_prune_options popts = GIT_WORKTREE_PRUNE_OPTIONS_INIT;
472
493
 
473
- GITERR_CHECK_VERSION(
494
+ GIT_ERROR_CHECK_VERSION(
474
495
  opts, GIT_WORKTREE_PRUNE_OPTIONS_VERSION,
475
496
  "git_worktree_prune_options");
476
497
 
@@ -482,8 +503,8 @@ int git_worktree_is_prunable(git_worktree *wt,
482
503
  {
483
504
  if (!reason.size)
484
505
  git_buf_attach_notowned(&reason, "no reason given", 15);
485
- giterr_set(GITERR_WORKTREE, "Not pruning locked working tree: '%s'", reason.ptr);
486
- git_buf_free(&reason);
506
+ git_error_set(GIT_ERROR_WORKTREE, "Not pruning locked working tree: '%s'", reason.ptr);
507
+ git_buf_dispose(&reason);
487
508
 
488
509
  return 0;
489
510
  }
@@ -491,7 +512,7 @@ int git_worktree_is_prunable(git_worktree *wt,
491
512
  if ((popts.flags & GIT_WORKTREE_PRUNE_VALID) == 0 &&
492
513
  git_worktree_validate(wt) == 0)
493
514
  {
494
- giterr_set(GITERR_WORKTREE, "Not pruning valid working tree");
515
+ git_error_set(GIT_ERROR_WORKTREE, "Not pruning valid working tree");
495
516
  return 0;
496
517
  }
497
518
 
@@ -506,7 +527,7 @@ int git_worktree_prune(git_worktree *wt,
506
527
  char *wtpath;
507
528
  int err;
508
529
 
509
- GITERR_CHECK_VERSION(
530
+ GIT_ERROR_CHECK_VERSION(
510
531
  opts, GIT_WORKTREE_PRUNE_OPTIONS_VERSION,
511
532
  "git_worktree_prune_options");
512
533
 
@@ -523,7 +544,7 @@ int git_worktree_prune(git_worktree *wt,
523
544
  goto out;
524
545
  if (!git_path_exists(path.ptr))
525
546
  {
526
- giterr_set(GITERR_WORKTREE, "Worktree gitdir '%s' does not exist", path.ptr);
547
+ git_error_set(GIT_ERROR_WORKTREE, "Worktree gitdir '%s' does not exist", path.ptr);
527
548
  err = -1;
528
549
  goto out;
529
550
  }
@@ -543,7 +564,7 @@ int git_worktree_prune(git_worktree *wt,
543
564
  git_buf_attach(&path, wtpath, 0);
544
565
  if (!git_path_exists(path.ptr))
545
566
  {
546
- giterr_set(GITERR_WORKTREE, "Working tree '%s' does not exist", path.ptr);
567
+ git_error_set(GIT_ERROR_WORKTREE, "Working tree '%s' does not exist", path.ptr);
547
568
  err = -1;
548
569
  goto out;
549
570
  }
@@ -551,7 +572,7 @@ int git_worktree_prune(git_worktree *wt,
551
572
  goto out;
552
573
 
553
574
  out:
554
- git_buf_free(&path);
575
+ git_buf_dispose(&path);
555
576
 
556
577
  return err;
557
578
  }
@@ -18,6 +18,8 @@ struct git_worktree {
18
18
  * directory. */
19
19
  char *name;
20
20
 
21
+ /* Path to the where the worktree lives in the filesystem */
22
+ char *worktree_path;
21
23
  /* Path to the .git file in the working tree's repository */
22
24
  char *gitlink_path;
23
25
  /* Path to the .git directory inside the parent's
@@ -33,8 +33,10 @@
33
33
  /** Declare a function as always inlined. */
34
34
  #if defined(_MSC_VER)
35
35
  # define XDL_INLINE(type) static __inline type
36
+ #elif defined(__GNUC__)
37
+ # define XDL_INLINE(type) static __inline__ type
36
38
  #else
37
- # define XDL_INLINE(type) static inline type
39
+ #define XDG_INLINE(type) static type
38
40
  #endif
39
41
 
40
42
  typedef struct s_xdpsplit {
@@ -348,10 +350,10 @@ int xdl_do_diff(mmfile_t *mf1, mmfile_t *mf2, xpparam_t const *xpp,
348
350
  * Allocate and setup K vectors to be used by the differential algorithm.
349
351
  * One is to store the forward path and one to store the backward path.
350
352
  */
351
- GITERR_CHECK_ALLOC_ADD3(&ndiags, xe->xdf1.nreff, xe->xdf2.nreff, 3);
352
- GITERR_CHECK_ALLOC_MULTIPLY(&allocsize, ndiags, 2);
353
- GITERR_CHECK_ALLOC_ADD(&allocsize, allocsize, 2);
354
- GITERR_CHECK_ALLOC_MULTIPLY(&allocsize, allocsize, sizeof(long));
353
+ GIT_ERROR_CHECK_ALLOC_ADD3(&ndiags, xe->xdf1.nreff, xe->xdf2.nreff, 3);
354
+ GIT_ERROR_CHECK_ALLOC_MULTIPLY(&allocsize, ndiags, 2);
355
+ GIT_ERROR_CHECK_ALLOC_ADD(&allocsize, allocsize, 2);
356
+ GIT_ERROR_CHECK_ALLOC_MULTIPLY(&allocsize, allocsize, sizeof(long));
355
357
 
356
358
  if (!(kvd = (long *) xdl_malloc(allocsize))) {
357
359
  xdl_free_env(xe);
@@ -302,7 +302,7 @@ static int histogram_diff(
302
302
 
303
303
  index.table_bits = xdl_hashbits(count1);
304
304
  sz = index.records_size = 1 << index.table_bits;
305
- GITERR_CHECK_ALLOC_MULTIPLY(&sz, sz, sizeof(struct record *));
305
+ GIT_ERROR_CHECK_ALLOC_MULTIPLY(&sz, sz, sizeof(struct record *));
306
306
 
307
307
  if (!(index.records = (struct record **) xdl_malloc(sz)))
308
308
  goto cleanup;
@@ -125,7 +125,7 @@ static int xdl_recs_copy_0(size_t *out, int use_orig, xdfenv_t *xe, int i, int c
125
125
  if (dest)
126
126
  memcpy(dest + size, recs[i]->ptr, recs[i]->size);
127
127
 
128
- GITERR_CHECK_ALLOC_ADD(&size, size, recs[i++]->size);
128
+ GIT_ERROR_CHECK_ALLOC_ADD(&size, size, recs[i++]->size);
129
129
  }
130
130
 
131
131
  if (add_nl) {
@@ -134,13 +134,13 @@ static int xdl_recs_copy_0(size_t *out, int use_orig, xdfenv_t *xe, int i, int c
134
134
  if (needs_cr) {
135
135
  if (dest)
136
136
  dest[size] = '\r';
137
- GITERR_CHECK_ALLOC_ADD(&size, size, 1);
137
+ GIT_ERROR_CHECK_ALLOC_ADD(&size, size, 1);
138
138
  }
139
139
 
140
140
  if (dest)
141
141
  dest[size] = '\n';
142
142
 
143
- GITERR_CHECK_ALLOC_ADD(&size, size, 1);
143
+ GIT_ERROR_CHECK_ALLOC_ADD(&size, size, 1);
144
144
  }
145
145
  }
146
146
 
@@ -224,10 +224,10 @@ static int fill_conflict_hunk(size_t *out, xdfenv_t *xe1, const char *name1,
224
224
  dest ? dest + size : NULL) < 0)
225
225
  return -1;
226
226
 
227
- GITERR_CHECK_ALLOC_ADD(&size, size, copied);
227
+ GIT_ERROR_CHECK_ALLOC_ADD(&size, size, copied);
228
228
 
229
229
  if (!dest) {
230
- GITERR_CHECK_ALLOC_ADD5(&size, size, marker_size, 1, needs_cr, marker1_size);
230
+ GIT_ERROR_CHECK_ALLOC_ADD5(&size, size, marker_size, 1, needs_cr, marker1_size);
231
231
  } else {
232
232
  memset(dest + size, '<', marker_size);
233
233
  size += marker_size;
@@ -246,12 +246,12 @@ static int fill_conflict_hunk(size_t *out, xdfenv_t *xe1, const char *name1,
246
246
  dest ? dest + size : NULL) < 0)
247
247
  return -1;
248
248
 
249
- GITERR_CHECK_ALLOC_ADD(&size, size, copied);
249
+ GIT_ERROR_CHECK_ALLOC_ADD(&size, size, copied);
250
250
 
251
251
  if (style == XDL_MERGE_DIFF3) {
252
252
  /* Shared preimage */
253
253
  if (!dest) {
254
- GITERR_CHECK_ALLOC_ADD5(&size, size, marker_size, 1, needs_cr, marker3_size);
254
+ GIT_ERROR_CHECK_ALLOC_ADD5(&size, size, marker_size, 1, needs_cr, marker3_size);
255
255
  } else {
256
256
  memset(dest + size, '|', marker_size);
257
257
  size += marker_size;
@@ -268,11 +268,11 @@ static int fill_conflict_hunk(size_t *out, xdfenv_t *xe1, const char *name1,
268
268
  if (xdl_orig_copy(&copied, xe1, m->i0, m->chg0, needs_cr, 1,
269
269
  dest ? dest + size : NULL) < 0)
270
270
  return -1;
271
- GITERR_CHECK_ALLOC_ADD(&size, size, copied);
271
+ GIT_ERROR_CHECK_ALLOC_ADD(&size, size, copied);
272
272
  }
273
273
 
274
274
  if (!dest) {
275
- GITERR_CHECK_ALLOC_ADD4(&size, size, marker_size, 1, needs_cr);
275
+ GIT_ERROR_CHECK_ALLOC_ADD4(&size, size, marker_size, 1, needs_cr);
276
276
  } else {
277
277
  memset(dest + size, '=', marker_size);
278
278
  size += marker_size;
@@ -286,10 +286,10 @@ static int fill_conflict_hunk(size_t *out, xdfenv_t *xe1, const char *name1,
286
286
  if (xdl_recs_copy(&copied, xe2, m->i2, m->chg2, needs_cr, 1,
287
287
  dest ? dest + size : NULL) < 0)
288
288
  return -1;
289
- GITERR_CHECK_ALLOC_ADD(&size, size, copied);
289
+ GIT_ERROR_CHECK_ALLOC_ADD(&size, size, copied);
290
290
 
291
291
  if (!dest) {
292
- GITERR_CHECK_ALLOC_ADD5(&size, size, marker_size, 1, needs_cr, marker2_size);
292
+ GIT_ERROR_CHECK_ALLOC_ADD5(&size, size, marker_size, 1, needs_cr, marker2_size);
293
293
  } else {
294
294
  memset(dest + size, '>', marker_size);
295
295
  size += marker_size;
@@ -336,7 +336,7 @@ static int xdl_fill_merge_buffer(size_t *out,
336
336
  if (xdl_recs_copy(&copied, xe1, i, m->i1 - i, 0, 0,
337
337
  dest ? dest + size : NULL) < 0)
338
338
  return -1;
339
- GITERR_CHECK_ALLOC_ADD(&size, size, copied);
339
+ GIT_ERROR_CHECK_ALLOC_ADD(&size, size, copied);
340
340
 
341
341
  /* Postimage from side #1 */
342
342
  if (m->mode & 1) {
@@ -345,7 +345,7 @@ static int xdl_fill_merge_buffer(size_t *out,
345
345
  if (xdl_recs_copy(&copied, xe1, m->i1, m->chg1, needs_cr, (m->mode & 2),
346
346
  dest ? dest + size : NULL) < 0)
347
347
  return -1;
348
- GITERR_CHECK_ALLOC_ADD(&size, size, copied);
348
+ GIT_ERROR_CHECK_ALLOC_ADD(&size, size, copied);
349
349
  }
350
350
 
351
351
  /* Postimage from side #2 */
@@ -353,7 +353,7 @@ static int xdl_fill_merge_buffer(size_t *out,
353
353
  if (xdl_recs_copy(&copied, xe2, m->i2, m->chg2, 0, 0,
354
354
  dest ? dest + size : NULL) < 0)
355
355
  return -1;
356
- GITERR_CHECK_ALLOC_ADD(&size, size, copied);
356
+ GIT_ERROR_CHECK_ALLOC_ADD(&size, size, copied);
357
357
  }
358
358
  } else
359
359
  continue;
@@ -363,7 +363,7 @@ static int xdl_fill_merge_buffer(size_t *out,
363
363
  if (xdl_recs_copy(&copied, xe1, i, xe1->xdf2.nrec - i, 0, 0,
364
364
  dest ? dest + size : NULL) < 0)
365
365
  return -1;
366
- GITERR_CHECK_ALLOC_ADD(&size, size, copied);
366
+ GIT_ERROR_CHECK_ALLOC_ADD(&size, size, copied);
367
367
 
368
368
  *out = size;
369
369
  return 0;