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
@@ -12,8 +12,8 @@
12
12
  #include "oid.h"
13
13
  #include "parse.h"
14
14
 
15
- static const char *git_config_escapes = "ntb\"\\";
16
- static const char *git_config_escaped = "\n\t\b\"\\";
15
+ extern const char *git_config_escapes;
16
+ extern const char *git_config_escaped;
17
17
 
18
18
  typedef struct config_file {
19
19
  git_oid checksum;
@@ -36,8 +36,8 @@ typedef int (*git_config_parser_section_cb)(
36
36
  typedef int (*git_config_parser_variable_cb)(
37
37
  git_config_parser *parser,
38
38
  const char *current_section,
39
- char *var_name,
40
- char *var_value,
39
+ const char *var_name,
40
+ const char *var_value,
41
41
  const char *line,
42
42
  size_t line_len,
43
43
  void *data);
@@ -18,65 +18,58 @@
18
18
  #include "buf_text.h"
19
19
  #include "repository.h"
20
20
 
21
+ typedef enum {
22
+ GIT_CRLF_UNDEFINED,
23
+ GIT_CRLF_BINARY,
24
+ GIT_CRLF_TEXT,
25
+ GIT_CRLF_TEXT_INPUT,
26
+ GIT_CRLF_TEXT_CRLF,
27
+ GIT_CRLF_AUTO,
28
+ GIT_CRLF_AUTO_INPUT,
29
+ GIT_CRLF_AUTO_CRLF,
30
+ } git_crlf_t;
31
+
21
32
  struct crlf_attrs {
22
- int crlf_action;
23
- int eol;
33
+ int attr_action; /* the .gitattributes setting */
34
+ int crlf_action; /* the core.autocrlf setting */
35
+
24
36
  int auto_crlf;
25
37
  int safe_crlf;
38
+ int core_eol;
26
39
  };
27
40
 
28
41
  struct crlf_filter {
29
42
  git_filter f;
30
43
  };
31
44
 
32
- static int check_crlf(const char *value)
45
+ static git_crlf_t check_crlf(const char *value)
33
46
  {
34
47
  if (GIT_ATTR_TRUE(value))
35
48
  return GIT_CRLF_TEXT;
36
-
37
- if (GIT_ATTR_FALSE(value))
49
+ else if (GIT_ATTR_FALSE(value))
38
50
  return GIT_CRLF_BINARY;
39
-
40
- if (GIT_ATTR_UNSPECIFIED(value))
41
- return GIT_CRLF_GUESS;
42
-
43
- if (strcmp(value, "input") == 0)
44
- return GIT_CRLF_INPUT;
45
-
46
- if (strcmp(value, "auto") == 0)
51
+ else if (GIT_ATTR_UNSPECIFIED(value))
52
+ ;
53
+ else if (strcmp(value, "input") == 0)
54
+ return GIT_CRLF_TEXT_INPUT;
55
+ else if (strcmp(value, "auto") == 0)
47
56
  return GIT_CRLF_AUTO;
48
57
 
49
- return GIT_CRLF_GUESS;
58
+ return GIT_CRLF_UNDEFINED;
50
59
  }
51
60
 
52
- static int check_eol(const char *value)
61
+ static git_cvar_value check_eol(const char *value)
53
62
  {
54
63
  if (GIT_ATTR_UNSPECIFIED(value))
55
- return GIT_EOL_UNSET;
56
-
57
- if (strcmp(value, "lf") == 0)
64
+ ;
65
+ else if (strcmp(value, "lf") == 0)
58
66
  return GIT_EOL_LF;
59
-
60
- if (strcmp(value, "crlf") == 0)
67
+ else if (strcmp(value, "crlf") == 0)
61
68
  return GIT_EOL_CRLF;
62
69
 
63
70
  return GIT_EOL_UNSET;
64
71
  }
65
72
 
66
- static int crlf_input_action(struct crlf_attrs *ca)
67
- {
68
- if (ca->crlf_action == GIT_CRLF_BINARY)
69
- return GIT_CRLF_BINARY;
70
-
71
- if (ca->eol == GIT_EOL_LF)
72
- return GIT_CRLF_INPUT;
73
-
74
- if (ca->eol == GIT_EOL_CRLF)
75
- return GIT_CRLF_CRLF;
76
-
77
- return ca->crlf_action;
78
- }
79
-
80
73
  static int has_cr_in_index(const git_filter_source *src)
81
74
  {
82
75
  git_repository *repo = git_filter_source_repo(src);
@@ -92,7 +85,7 @@ static int has_cr_in_index(const git_filter_source *src)
92
85
  return false;
93
86
 
94
87
  if (git_repository_index__weakptr(&index, repo) < 0) {
95
- giterr_clear();
88
+ git_error_clear();
96
89
  return false;
97
90
  }
98
91
 
@@ -119,146 +112,168 @@ static int has_cr_in_index(const git_filter_source *src)
119
112
  return found_cr;
120
113
  }
121
114
 
122
- static int crlf_apply_to_odb(
123
- struct crlf_attrs *ca,
124
- git_buf *to,
125
- const git_buf *from,
126
- const git_filter_source *src)
115
+ static int text_eol_is_crlf(struct crlf_attrs *ca)
127
116
  {
128
- /* Empty file? Nothing to do */
129
- if (!git_buf_len(from))
117
+ if (ca->auto_crlf == GIT_AUTO_CRLF_TRUE)
118
+ return 1;
119
+ else if (ca->auto_crlf == GIT_AUTO_CRLF_INPUT)
130
120
  return 0;
131
121
 
132
- /* Heuristics to see if we can skip the conversion.
133
- * Straight from Core Git.
134
- */
135
- if (ca->crlf_action == GIT_CRLF_AUTO || ca->crlf_action == GIT_CRLF_GUESS) {
136
- git_buf_text_stats stats;
122
+ if (ca->core_eol == GIT_EOL_CRLF)
123
+ return 1;
124
+ if (ca->core_eol == GIT_EOL_UNSET && GIT_EOL_NATIVE == GIT_EOL_CRLF)
125
+ return 1;
137
126
 
138
- /* Check heuristics for binary vs text - returns true if binary */
139
- if (git_buf_text_gather_stats(&stats, from, false))
140
- return GIT_PASSTHROUGH;
127
+ return 0;
128
+ }
141
129
 
142
- /* If there are no CR characters to filter out, then just pass */
143
- if (!stats.cr)
144
- return GIT_PASSTHROUGH;
130
+ static git_cvar_value output_eol(struct crlf_attrs *ca)
131
+ {
132
+ switch (ca->crlf_action) {
133
+ case GIT_CRLF_BINARY:
134
+ return GIT_EOL_UNSET;
135
+ case GIT_CRLF_TEXT_CRLF:
136
+ return GIT_EOL_CRLF;
137
+ case GIT_CRLF_TEXT_INPUT:
138
+ return GIT_EOL_LF;
139
+ case GIT_CRLF_UNDEFINED:
140
+ case GIT_CRLF_AUTO_CRLF:
141
+ return GIT_EOL_CRLF;
142
+ case GIT_CRLF_AUTO_INPUT:
143
+ return GIT_EOL_LF;
144
+ case GIT_CRLF_TEXT:
145
+ case GIT_CRLF_AUTO:
146
+ return text_eol_is_crlf(ca) ? GIT_EOL_CRLF : GIT_EOL_LF;
147
+ }
148
+
149
+ /* TODO: warn when available */
150
+ return ca->core_eol;
151
+ }
152
+
153
+ GIT_INLINE(int) check_safecrlf(
154
+ struct crlf_attrs *ca,
155
+ const git_filter_source *src,
156
+ git_buf_text_stats *stats)
157
+ {
158
+ const char *filename = git_filter_source_path(src);
159
+
160
+ if (!ca->safe_crlf)
161
+ return 0;
162
+
163
+ if (output_eol(ca) == GIT_EOL_LF) {
164
+ /*
165
+ * CRLFs would not be restored by checkout:
166
+ * check if we'd remove CRLFs
167
+ */
168
+ if (stats->crlf) {
169
+ if (ca->safe_crlf == GIT_SAFE_CRLF_WARN) {
170
+ /* TODO: issue a warning when available */
171
+ } else {
172
+ if (filename && *filename)
173
+ git_error_set(
174
+ GIT_ERROR_FILTER, "CRLF would be replaced by LF in '%s'",
175
+ filename);
176
+ else
177
+ git_error_set(
178
+ GIT_ERROR_FILTER, "CRLF would be replaced by LF");
145
179
 
146
- /* If safecrlf is enabled, sanity-check the result. */
147
- if (stats.cr != stats.crlf || stats.lf != stats.crlf) {
148
- switch (ca->safe_crlf) {
149
- case GIT_SAFE_CRLF_FAIL:
150
- giterr_set(
151
- GITERR_FILTER, "LF would be replaced by CRLF in '%s'",
152
- git_filter_source_path(src));
153
180
  return -1;
154
- case GIT_SAFE_CRLF_WARN:
155
- /* TODO: issue warning when warning API is available */;
156
- break;
157
- default:
158
- break;
159
181
  }
160
182
  }
161
-
183
+ } else if (output_eol(ca) == GIT_EOL_CRLF) {
162
184
  /*
163
- * We're currently not going to even try to convert stuff
164
- * that has bare CR characters. Does anybody do that crazy
165
- * stuff?
185
+ * CRLFs would be added by checkout:
186
+ * check if we have "naked" LFs
166
187
  */
167
- if (stats.cr != stats.crlf)
168
- return GIT_PASSTHROUGH;
188
+ if (stats->crlf != stats->lf) {
189
+ if (ca->safe_crlf == GIT_SAFE_CRLF_WARN) {
190
+ /* TODO: issue a warning when available */
191
+ } else {
192
+ if (filename && *filename)
193
+ git_error_set(
194
+ GIT_ERROR_FILTER, "LF would be replaced by CRLF in '%s'",
195
+ filename);
196
+ else
197
+ git_error_set(
198
+ GIT_ERROR_FILTER, "LF would be replaced by CRLF");
169
199
 
170
- if (ca->crlf_action == GIT_CRLF_GUESS) {
171
- /*
172
- * If the file in the index has any CR in it, do not convert.
173
- * This is the new safer autocrlf handling.
174
- */
175
- if (has_cr_in_index(src))
176
- return GIT_PASSTHROUGH;
200
+ return -1;
201
+ }
177
202
  }
178
-
179
- if (!stats.cr)
180
- return GIT_PASSTHROUGH;
181
203
  }
182
204
 
183
- /* Actually drop the carriage returns */
184
- return git_buf_text_crlf_to_lf(to, from);
205
+ return 0;
185
206
  }
186
207
 
187
- static const char *line_ending(struct crlf_attrs *ca)
208
+ static int crlf_apply_to_odb(
209
+ struct crlf_attrs *ca,
210
+ git_buf *to,
211
+ const git_buf *from,
212
+ const git_filter_source *src)
188
213
  {
189
- switch (ca->crlf_action) {
190
- case GIT_CRLF_BINARY:
191
- case GIT_CRLF_INPUT:
192
- return "\n";
214
+ git_buf_text_stats stats;
215
+ bool is_binary;
216
+ int error;
193
217
 
194
- case GIT_CRLF_CRLF:
195
- return "\r\n";
218
+ /* Binary attribute? Empty file? Nothing to do */
219
+ if (ca->crlf_action == GIT_CRLF_BINARY || !git_buf_len(from))
220
+ return GIT_PASSTHROUGH;
196
221
 
197
- case GIT_CRLF_GUESS:
198
- if (ca->auto_crlf == GIT_AUTO_CRLF_FALSE)
199
- return "\n";
200
- break;
222
+ is_binary = git_buf_text_gather_stats(&stats, from, false);
201
223
 
202
- case GIT_CRLF_AUTO:
203
- case GIT_CRLF_TEXT:
204
- break;
224
+ /* Heuristics to see if we can skip the conversion.
225
+ * Straight from Core Git.
226
+ */
227
+ if (ca->crlf_action == GIT_CRLF_AUTO ||
228
+ ca->crlf_action == GIT_CRLF_AUTO_INPUT ||
229
+ ca->crlf_action == GIT_CRLF_AUTO_CRLF) {
230
+
231
+ if (is_binary)
232
+ return GIT_PASSTHROUGH;
205
233
 
206
- default:
207
- goto line_ending_error;
234
+ /*
235
+ * If the file in the index has any CR in it, do not convert.
236
+ * This is the new safer autocrlf handling.
237
+ */
238
+ if (has_cr_in_index(src))
239
+ return GIT_PASSTHROUGH;
208
240
  }
209
241
 
210
- if (ca->auto_crlf == GIT_AUTO_CRLF_TRUE)
211
- return "\r\n";
212
- else if (ca->auto_crlf == GIT_AUTO_CRLF_INPUT)
213
- return "\n";
214
- else if (ca->eol == GIT_EOL_UNSET)
215
- return GIT_EOL_NATIVE == GIT_EOL_CRLF ? "\r\n" : "\n";
216
- else if (ca->eol == GIT_EOL_LF)
217
- return "\n";
218
- else if (ca->eol == GIT_EOL_CRLF)
219
- return "\r\n";
220
-
221
- line_ending_error:
222
- giterr_set(GITERR_INVALID, "invalid input to line ending filter");
223
- return NULL;
242
+ if ((error = check_safecrlf(ca, src, &stats)) < 0)
243
+ return error;
244
+
245
+ /* If there are no CR characters to filter out, then just pass */
246
+ if (!stats.crlf)
247
+ return GIT_PASSTHROUGH;
248
+
249
+ /* Actually drop the carriage returns */
250
+ return git_buf_text_crlf_to_lf(to, from);
224
251
  }
225
252
 
226
253
  static int crlf_apply_to_workdir(
227
- struct crlf_attrs *ca, git_buf *to, const git_buf *from)
254
+ struct crlf_attrs *ca,
255
+ git_buf *to,
256
+ const git_buf *from)
228
257
  {
229
258
  git_buf_text_stats stats;
230
- const char *workdir_ending = NULL;
231
259
  bool is_binary;
232
260
 
233
261
  /* Empty file? Nothing to do. */
234
- if (git_buf_len(from) == 0)
235
- return 0;
236
-
237
- /* Determine proper line ending */
238
- workdir_ending = line_ending(ca);
239
- if (!workdir_ending)
240
- return -1;
241
-
242
- /* only LF->CRLF conversion is supported, do nothing on LF platforms */
243
- if (strcmp(workdir_ending, "\r\n") != 0)
262
+ if (git_buf_len(from) == 0 || output_eol(ca) != GIT_EOL_CRLF)
244
263
  return GIT_PASSTHROUGH;
245
264
 
246
- /* If there are no LFs, or all LFs are part of a CRLF, nothing to do */
247
265
  is_binary = git_buf_text_gather_stats(&stats, from, false);
248
266
 
267
+ /* If there are no LFs, or all LFs are part of a CRLF, nothing to do */
249
268
  if (stats.lf == 0 || stats.lf == stats.crlf)
250
269
  return GIT_PASSTHROUGH;
251
270
 
252
271
  if (ca->crlf_action == GIT_CRLF_AUTO ||
253
- ca->crlf_action == GIT_CRLF_GUESS) {
272
+ ca->crlf_action == GIT_CRLF_AUTO_INPUT ||
273
+ ca->crlf_action == GIT_CRLF_AUTO_CRLF) {
254
274
 
255
275
  /* If we have any existing CR or CRLF line endings, do nothing */
256
- if (ca->crlf_action == GIT_CRLF_GUESS &&
257
- stats.cr > 0 && stats.crlf > 0)
258
- return GIT_PASSTHROUGH;
259
-
260
- /* If we have bare CR characters, do nothing */
261
- if (stats.cr != stats.crlf)
276
+ if (stats.cr > 0)
262
277
  return GIT_PASSTHROUGH;
263
278
 
264
279
  /* Don't filter binary files */
@@ -269,85 +284,99 @@ static int crlf_apply_to_workdir(
269
284
  return git_buf_text_lf_to_crlf(to, from);
270
285
  }
271
286
 
272
- static int crlf_check(
273
- git_filter *self,
274
- void **payload, /* points to NULL ptr on entry, may be set */
275
- const git_filter_source *src,
276
- const char **attr_values)
287
+ static int convert_attrs(
288
+ struct crlf_attrs *ca,
289
+ const char **attr_values,
290
+ const git_filter_source *src)
277
291
  {
278
292
  int error;
279
- struct crlf_attrs ca;
280
293
 
281
- GIT_UNUSED(self);
294
+ memset(ca, 0, sizeof(struct crlf_attrs));
295
+
296
+ if ((error = git_repository__cvar(&ca->auto_crlf,
297
+ git_filter_source_repo(src), GIT_CVAR_AUTO_CRLF)) < 0 ||
298
+ (error = git_repository__cvar(&ca->safe_crlf,
299
+ git_filter_source_repo(src), GIT_CVAR_SAFE_CRLF)) < 0 ||
300
+ (error = git_repository__cvar(&ca->core_eol,
301
+ git_filter_source_repo(src), GIT_CVAR_EOL)) < 0)
302
+ return error;
303
+
304
+ /* downgrade FAIL to WARN if ALLOW_UNSAFE option is used */
305
+ if ((git_filter_source_flags(src) & GIT_FILTER_ALLOW_UNSAFE) &&
306
+ ca->safe_crlf == GIT_SAFE_CRLF_FAIL)
307
+ ca->safe_crlf = GIT_SAFE_CRLF_WARN;
308
+
309
+ if (attr_values) {
310
+ /* load the text attribute */
311
+ ca->crlf_action = check_crlf(attr_values[2]); /* text */
312
+
313
+ if (ca->crlf_action == GIT_CRLF_UNDEFINED)
314
+ ca->crlf_action = check_crlf(attr_values[0]); /* crlf */
315
+
316
+ if (ca->crlf_action != GIT_CRLF_BINARY) {
317
+ /* load the eol attribute */
318
+ int eol_attr = check_eol(attr_values[1]);
319
+
320
+ if (ca->crlf_action == GIT_CRLF_AUTO && eol_attr == GIT_EOL_LF)
321
+ ca->crlf_action = GIT_CRLF_AUTO_INPUT;
322
+ else if (ca->crlf_action == GIT_CRLF_AUTO && eol_attr == GIT_EOL_CRLF)
323
+ ca->crlf_action = GIT_CRLF_AUTO_CRLF;
324
+ else if (eol_attr == GIT_EOL_LF)
325
+ ca->crlf_action = GIT_CRLF_TEXT_INPUT;
326
+ else if (eol_attr == GIT_EOL_CRLF)
327
+ ca->crlf_action = GIT_CRLF_TEXT_CRLF;
328
+ }
282
329
 
283
- if (!attr_values) {
284
- ca.crlf_action = GIT_CRLF_GUESS;
285
- ca.eol = GIT_EOL_UNSET;
330
+ ca->attr_action = ca->crlf_action;
286
331
  } else {
287
- ca.crlf_action = check_crlf(attr_values[2]); /* text */
288
- if (ca.crlf_action == GIT_CRLF_GUESS)
289
- ca.crlf_action = check_crlf(attr_values[0]); /* clrf */
290
- ca.eol = check_eol(attr_values[1]); /* eol */
332
+ ca->crlf_action = GIT_CRLF_UNDEFINED;
291
333
  }
292
- ca.auto_crlf = GIT_AUTO_CRLF_DEFAULT;
293
- ca.safe_crlf = GIT_SAFE_CRLF_DEFAULT;
294
334
 
295
- /*
296
- * Use the core Git logic to see if we should perform CRLF for this file
297
- * based on its attributes & the value of `core.autocrlf`
298
- */
299
- ca.crlf_action = crlf_input_action(&ca);
335
+ if (ca->crlf_action == GIT_CRLF_TEXT)
336
+ ca->crlf_action = text_eol_is_crlf(ca) ? GIT_CRLF_TEXT_CRLF : GIT_CRLF_TEXT_INPUT;
337
+ if (ca->crlf_action == GIT_CRLF_UNDEFINED && ca->auto_crlf == GIT_AUTO_CRLF_FALSE)
338
+ ca->crlf_action = GIT_CRLF_BINARY;
339
+ if (ca->crlf_action == GIT_CRLF_UNDEFINED && ca->auto_crlf == GIT_AUTO_CRLF_TRUE)
340
+ ca->crlf_action = GIT_CRLF_AUTO_CRLF;
341
+ if (ca->crlf_action == GIT_CRLF_UNDEFINED && ca->auto_crlf == GIT_AUTO_CRLF_INPUT)
342
+ ca->crlf_action = GIT_CRLF_AUTO_INPUT;
300
343
 
301
- if (ca.crlf_action == GIT_CRLF_BINARY)
302
- return GIT_PASSTHROUGH;
303
-
304
- if (ca.crlf_action == GIT_CRLF_GUESS ||
305
- ((ca.crlf_action == GIT_CRLF_AUTO || ca.crlf_action == GIT_CRLF_TEXT) &&
306
- git_filter_source_mode(src) == GIT_FILTER_SMUDGE)) {
307
-
308
- error = git_repository__cvar(
309
- &ca.auto_crlf, git_filter_source_repo(src), GIT_CVAR_AUTO_CRLF);
310
- if (error < 0)
311
- return error;
344
+ return 0;
345
+ }
312
346
 
313
- if (ca.crlf_action == GIT_CRLF_GUESS &&
314
- ca.auto_crlf == GIT_AUTO_CRLF_FALSE)
315
- return GIT_PASSTHROUGH;
347
+ static int crlf_check(
348
+ git_filter *self,
349
+ void **payload, /* points to NULL ptr on entry, may be set */
350
+ const git_filter_source *src,
351
+ const char **attr_values)
352
+ {
353
+ struct crlf_attrs ca;
316
354
 
317
- if (ca.auto_crlf == GIT_AUTO_CRLF_INPUT &&
318
- git_filter_source_mode(src) == GIT_FILTER_SMUDGE)
319
- return GIT_PASSTHROUGH;
320
- }
355
+ GIT_UNUSED(self);
321
356
 
322
- if (git_filter_source_mode(src) == GIT_FILTER_CLEAN) {
323
- error = git_repository__cvar(
324
- &ca.safe_crlf, git_filter_source_repo(src), GIT_CVAR_SAFE_CRLF);
325
- if (error < 0)
326
- return error;
357
+ convert_attrs(&ca, attr_values, src);
327
358
 
328
- /* downgrade FAIL to WARN if ALLOW_UNSAFE option is used */
329
- if ((git_filter_source_flags(src) & GIT_FILTER_ALLOW_UNSAFE) &&
330
- ca.safe_crlf == GIT_SAFE_CRLF_FAIL)
331
- ca.safe_crlf = GIT_SAFE_CRLF_WARN;
332
- }
359
+ if (ca.crlf_action == GIT_CRLF_BINARY)
360
+ return GIT_PASSTHROUGH;
333
361
 
334
362
  *payload = git__malloc(sizeof(ca));
335
- GITERR_CHECK_ALLOC(*payload);
363
+ GIT_ERROR_CHECK_ALLOC(*payload);
336
364
  memcpy(*payload, &ca, sizeof(ca));
337
365
 
338
366
  return 0;
339
367
  }
340
368
 
341
369
  static int crlf_apply(
342
- git_filter *self,
343
- void **payload, /* may be read and/or set */
344
- git_buf *to,
370
+ git_filter *self,
371
+ void **payload, /* may be read and/or set */
372
+ git_buf *to,
345
373
  const git_buf *from,
346
374
  const git_filter_source *src)
347
375
  {
348
376
  /* initialize payload in case `check` was bypassed */
349
377
  if (!*payload) {
350
378
  int error = crlf_check(self, payload, src, NULL);
379
+
351
380
  if (error < 0)
352
381
  return error;
353
382
  }