rugged 0.16.0 → 0.17.0b1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (392) hide show
  1. data/README.md +373 -243
  2. data/Rakefile +22 -0
  3. data/ext/rugged/extconf.rb +9 -6
  4. data/ext/rugged/rugged.c +123 -31
  5. data/ext/rugged/rugged.h +11 -10
  6. data/ext/rugged/rugged_blob.c +181 -18
  7. data/ext/rugged/rugged_commit.c +196 -18
  8. data/ext/rugged/rugged_config.c +94 -5
  9. data/ext/rugged/rugged_object.c +54 -1
  10. data/ext/rugged/rugged_reference.c +203 -15
  11. data/ext/rugged/{remote.c → rugged_remote.c} +35 -10
  12. data/ext/rugged/rugged_repo.c +323 -81
  13. data/ext/rugged/rugged_revwalk.c +57 -4
  14. data/ext/rugged/rugged_signature.c +3 -3
  15. data/ext/rugged/rugged_tag.c +72 -1
  16. data/ext/rugged/rugged_tree.c +70 -2
  17. data/ext/rugged/vendor/libgit2-dist/deps/regex/config.h +7 -0
  18. data/ext/rugged/vendor/libgit2-dist/deps/regex/regcomp.c +3856 -0
  19. data/ext/rugged/vendor/libgit2-dist/deps/regex/regex.c +85 -0
  20. data/ext/rugged/vendor/libgit2-dist/deps/regex/regex.h +582 -0
  21. data/ext/rugged/vendor/libgit2-dist/deps/regex/regex_internal.c +1744 -0
  22. data/ext/rugged/vendor/libgit2-dist/deps/regex/regex_internal.h +810 -0
  23. data/ext/rugged/vendor/libgit2-dist/deps/regex/regexec.c +4369 -0
  24. data/ext/rugged/vendor/libgit2-dist/examples/diff.c +238 -0
  25. data/ext/rugged/vendor/libgit2-dist/examples/general.c +4 -4
  26. data/ext/rugged/vendor/libgit2-dist/examples/network/fetch.c +101 -85
  27. data/ext/rugged/vendor/libgit2-dist/examples/network/git2.c +7 -3
  28. data/ext/rugged/vendor/libgit2-dist/examples/network/index-pack.c +80 -25
  29. data/ext/rugged/vendor/libgit2-dist/examples/network/ls-remote.c +6 -6
  30. data/ext/rugged/vendor/libgit2-dist/include/git2/attr.h +224 -0
  31. data/ext/rugged/vendor/libgit2-dist/include/git2/blob.h +59 -5
  32. data/ext/rugged/vendor/libgit2-dist/include/git2/branch.h +114 -7
  33. data/ext/rugged/vendor/libgit2-dist/include/git2/commit.h +14 -7
  34. data/ext/rugged/vendor/libgit2-dist/include/git2/common.h +4 -3
  35. data/ext/rugged/vendor/libgit2-dist/include/git2/config.h +105 -27
  36. data/ext/rugged/vendor/libgit2-dist/include/git2/diff.h +409 -0
  37. data/ext/rugged/vendor/libgit2-dist/include/git2/errors.h +47 -82
  38. data/ext/rugged/vendor/libgit2-dist/include/git2/index.h +25 -10
  39. data/ext/rugged/vendor/libgit2-dist/include/git2/indexer.h +46 -1
  40. data/ext/rugged/vendor/libgit2-dist/include/git2/merge.h +35 -0
  41. data/ext/rugged/vendor/libgit2-dist/include/git2/net.h +1 -1
  42. data/ext/rugged/vendor/libgit2-dist/include/git2/notes.h +139 -0
  43. data/ext/rugged/vendor/libgit2-dist/include/git2/object.h +5 -5
  44. data/ext/rugged/vendor/libgit2-dist/include/git2/odb.h +13 -13
  45. data/ext/rugged/vendor/libgit2-dist/include/git2/odb_backend.h +8 -8
  46. data/ext/rugged/vendor/libgit2-dist/include/git2/oid.h +14 -9
  47. data/ext/rugged/vendor/libgit2-dist/include/git2/reflog.h +5 -5
  48. data/ext/rugged/vendor/libgit2-dist/include/git2/refs.h +37 -17
  49. data/ext/rugged/vendor/libgit2-dist/include/git2/refspec.h +17 -9
  50. data/ext/rugged/vendor/libgit2-dist/include/git2/remote.h +83 -16
  51. data/ext/rugged/vendor/libgit2-dist/include/git2/repository.h +24 -10
  52. data/ext/rugged/vendor/libgit2-dist/include/git2/reset.h +44 -0
  53. data/ext/rugged/vendor/libgit2-dist/include/git2/revparse.h +36 -0
  54. data/ext/rugged/vendor/libgit2-dist/include/git2/revwalk.h +74 -6
  55. data/ext/rugged/vendor/libgit2-dist/include/git2/signature.h +3 -3
  56. data/ext/rugged/vendor/libgit2-dist/include/git2/status.h +120 -19
  57. data/ext/rugged/vendor/libgit2-dist/include/git2/submodule.h +103 -0
  58. data/ext/rugged/vendor/libgit2-dist/include/git2/tag.h +28 -10
  59. data/ext/rugged/vendor/libgit2-dist/include/git2/threads.h +1 -1
  60. data/ext/rugged/vendor/libgit2-dist/include/git2/tree.h +13 -13
  61. data/ext/rugged/vendor/libgit2-dist/include/git2/types.h +16 -2
  62. data/ext/rugged/vendor/libgit2-dist/include/git2/version.h +3 -3
  63. data/ext/rugged/vendor/libgit2-dist/include/git2/windows.h +1 -1
  64. data/ext/rugged/vendor/libgit2-dist/include/git2.h +7 -2
  65. data/ext/rugged/vendor/libgit2-dist/src/attr.c +677 -0
  66. data/ext/rugged/vendor/libgit2-dist/src/attr.h +56 -0
  67. data/ext/rugged/vendor/libgit2-dist/src/attr_file.c +609 -0
  68. data/ext/rugged/vendor/libgit2-dist/src/attr_file.h +145 -0
  69. data/ext/rugged/vendor/libgit2-dist/src/blob.c +213 -60
  70. data/ext/rugged/vendor/libgit2-dist/src/blob.h +2 -1
  71. data/ext/rugged/vendor/libgit2-dist/src/branch.c +208 -0
  72. data/ext/rugged/vendor/libgit2-dist/src/branch.h +17 -0
  73. data/ext/rugged/vendor/libgit2-dist/src/bswap.h +1 -1
  74. data/ext/rugged/vendor/libgit2-dist/src/buffer.c +395 -46
  75. data/ext/rugged/vendor/libgit2-dist/src/buffer.h +112 -9
  76. data/ext/rugged/vendor/libgit2-dist/src/cache.c +37 -49
  77. data/ext/rugged/vendor/libgit2-dist/src/cache.h +7 -17
  78. data/ext/rugged/vendor/libgit2-dist/src/cc-compat.h +18 -16
  79. data/ext/rugged/vendor/libgit2-dist/src/commit.c +56 -90
  80. data/ext/rugged/vendor/libgit2-dist/src/commit.h +1 -1
  81. data/ext/rugged/vendor/libgit2-dist/src/common.h +12 -5
  82. data/ext/rugged/vendor/libgit2-dist/src/{win32 → compat}/fnmatch.c +1 -1
  83. data/ext/rugged/vendor/libgit2-dist/src/{win32 → compat}/fnmatch.h +3 -3
  84. data/ext/rugged/vendor/libgit2-dist/src/config.c +247 -158
  85. data/ext/rugged/vendor/libgit2-dist/src/config.h +10 -1
  86. data/ext/rugged/vendor/libgit2-dist/src/config_cache.c +94 -0
  87. data/ext/rugged/vendor/libgit2-dist/src/config_file.c +606 -496
  88. data/ext/rugged/vendor/libgit2-dist/src/config_file.h +31 -0
  89. data/ext/rugged/vendor/libgit2-dist/src/crlf.c +228 -0
  90. data/ext/rugged/vendor/libgit2-dist/src/date.c +876 -0
  91. data/ext/rugged/vendor/libgit2-dist/src/delta-apply.c +15 -9
  92. data/ext/rugged/vendor/libgit2-dist/src/delta-apply.h +2 -2
  93. data/ext/rugged/vendor/libgit2-dist/src/diff.c +814 -0
  94. data/ext/rugged/vendor/libgit2-dist/src/diff.h +43 -0
  95. data/ext/rugged/vendor/libgit2-dist/src/diff_output.c +794 -0
  96. data/ext/rugged/vendor/libgit2-dist/src/errors.c +89 -74
  97. data/ext/rugged/vendor/libgit2-dist/src/fetch.c +94 -66
  98. data/ext/rugged/vendor/libgit2-dist/src/fetch.h +5 -4
  99. data/ext/rugged/vendor/libgit2-dist/src/filebuf.c +157 -100
  100. data/ext/rugged/vendor/libgit2-dist/src/filebuf.h +22 -8
  101. data/ext/rugged/vendor/libgit2-dist/src/fileops.c +330 -206
  102. data/ext/rugged/vendor/libgit2-dist/src/fileops.h +82 -51
  103. data/ext/rugged/vendor/libgit2-dist/src/filter.c +165 -0
  104. data/ext/rugged/vendor/libgit2-dist/src/filter.h +119 -0
  105. data/ext/rugged/vendor/libgit2-dist/src/global.c +4 -4
  106. data/ext/rugged/vendor/libgit2-dist/src/global.h +4 -1
  107. data/ext/rugged/vendor/libgit2-dist/src/hash.c +1 -1
  108. data/ext/rugged/vendor/libgit2-dist/src/hash.h +1 -1
  109. data/ext/rugged/vendor/libgit2-dist/src/ignore.c +203 -0
  110. data/ext/rugged/vendor/libgit2-dist/src/ignore.h +38 -0
  111. data/ext/rugged/vendor/libgit2-dist/src/index.c +220 -169
  112. data/ext/rugged/vendor/libgit2-dist/src/index.h +5 -1
  113. data/ext/rugged/vendor/libgit2-dist/src/indexer.c +601 -102
  114. data/ext/rugged/vendor/libgit2-dist/src/iterator.c +748 -0
  115. data/ext/rugged/vendor/libgit2-dist/src/iterator.h +151 -0
  116. data/ext/rugged/vendor/libgit2-dist/src/khash.h +608 -0
  117. data/ext/rugged/vendor/libgit2-dist/src/map.h +6 -1
  118. data/ext/rugged/vendor/libgit2-dist/src/message.c +61 -0
  119. data/ext/rugged/vendor/libgit2-dist/src/message.h +14 -0
  120. data/ext/rugged/vendor/libgit2-dist/src/mwindow.c +27 -29
  121. data/ext/rugged/vendor/libgit2-dist/src/mwindow.h +4 -4
  122. data/ext/rugged/vendor/libgit2-dist/src/netops.c +375 -56
  123. data/ext/rugged/vendor/libgit2-dist/src/netops.h +12 -9
  124. data/ext/rugged/vendor/libgit2-dist/src/notes.c +548 -0
  125. data/ext/rugged/vendor/libgit2-dist/src/notes.h +28 -0
  126. data/ext/rugged/vendor/libgit2-dist/src/object.c +59 -21
  127. data/ext/rugged/vendor/libgit2-dist/src/odb.c +212 -175
  128. data/ext/rugged/vendor/libgit2-dist/src/odb.h +39 -2
  129. data/ext/rugged/vendor/libgit2-dist/src/odb_loose.c +238 -241
  130. data/ext/rugged/vendor/libgit2-dist/src/odb_pack.c +94 -106
  131. data/ext/rugged/vendor/libgit2-dist/src/oid.c +59 -60
  132. data/ext/rugged/vendor/libgit2-dist/src/oidmap.h +42 -0
  133. data/ext/rugged/vendor/libgit2-dist/src/pack.c +198 -170
  134. data/ext/rugged/vendor/libgit2-dist/src/pack.h +16 -9
  135. data/ext/rugged/vendor/libgit2-dist/src/path.c +496 -106
  136. data/ext/rugged/vendor/libgit2-dist/src/path.h +214 -20
  137. data/ext/rugged/vendor/libgit2-dist/src/pkt.c +88 -159
  138. data/ext/rugged/vendor/libgit2-dist/src/pkt.h +9 -5
  139. data/ext/rugged/vendor/libgit2-dist/src/pool.c +294 -0
  140. data/ext/rugged/vendor/libgit2-dist/src/pool.h +125 -0
  141. data/ext/rugged/vendor/libgit2-dist/src/posix.c +38 -16
  142. data/ext/rugged/vendor/libgit2-dist/src/posix.h +20 -2
  143. data/ext/rugged/vendor/libgit2-dist/src/ppc/sha1.c +1 -1
  144. data/ext/rugged/vendor/libgit2-dist/src/ppc/sha1.h +1 -1
  145. data/ext/rugged/vendor/libgit2-dist/src/pqueue.c +7 -7
  146. data/ext/rugged/vendor/libgit2-dist/src/pqueue.h +1 -1
  147. data/ext/rugged/vendor/libgit2-dist/src/protocol.c +21 -13
  148. data/ext/rugged/vendor/libgit2-dist/src/protocol.h +1 -1
  149. data/ext/rugged/vendor/libgit2-dist/src/reflog.c +125 -103
  150. data/ext/rugged/vendor/libgit2-dist/src/reflog.h +1 -1
  151. data/ext/rugged/vendor/libgit2-dist/src/refs.c +713 -640
  152. data/ext/rugged/vendor/libgit2-dist/src/refs.h +27 -3
  153. data/ext/rugged/vendor/libgit2-dist/src/refspec.c +51 -17
  154. data/ext/rugged/vendor/libgit2-dist/src/refspec.h +13 -1
  155. data/ext/rugged/vendor/libgit2-dist/src/remote.c +307 -119
  156. data/ext/rugged/vendor/libgit2-dist/src/remote.h +3 -2
  157. data/ext/rugged/vendor/libgit2-dist/src/repository.c +593 -442
  158. data/ext/rugged/vendor/libgit2-dist/src/repository.h +80 -2
  159. data/ext/rugged/vendor/libgit2-dist/src/reset.c +103 -0
  160. data/ext/rugged/vendor/libgit2-dist/src/revparse.c +753 -0
  161. data/ext/rugged/vendor/libgit2-dist/src/revwalk.c +434 -158
  162. data/ext/rugged/vendor/libgit2-dist/src/sha1.c +3 -3
  163. data/ext/rugged/vendor/libgit2-dist/src/sha1.h +2 -2
  164. data/ext/rugged/vendor/libgit2-dist/src/sha1_lookup.c +3 -2
  165. data/ext/rugged/vendor/libgit2-dist/src/sha1_lookup.h +1 -1
  166. data/ext/rugged/vendor/libgit2-dist/src/signature.c +69 -80
  167. data/ext/rugged/vendor/libgit2-dist/src/signature.h +1 -1
  168. data/ext/rugged/vendor/libgit2-dist/src/status.c +184 -638
  169. data/ext/rugged/vendor/libgit2-dist/src/strmap.h +64 -0
  170. data/ext/rugged/vendor/libgit2-dist/src/submodule.c +387 -0
  171. data/ext/rugged/vendor/libgit2-dist/src/tag.c +162 -137
  172. data/ext/rugged/vendor/libgit2-dist/src/tag.h +2 -1
  173. data/ext/rugged/vendor/libgit2-dist/src/thread-utils.c +1 -1
  174. data/ext/rugged/vendor/libgit2-dist/src/thread-utils.h +8 -8
  175. data/ext/rugged/vendor/libgit2-dist/src/transport.c +31 -19
  176. data/ext/rugged/vendor/libgit2-dist/src/transport.h +31 -11
  177. data/ext/rugged/vendor/libgit2-dist/src/transports/git.c +168 -193
  178. data/ext/rugged/vendor/libgit2-dist/src/transports/http.c +192 -241
  179. data/ext/rugged/vendor/libgit2-dist/src/transports/local.c +92 -86
  180. data/ext/rugged/vendor/libgit2-dist/src/tree-cache.c +32 -49
  181. data/ext/rugged/vendor/libgit2-dist/src/tree-cache.h +1 -1
  182. data/ext/rugged/vendor/libgit2-dist/src/tree.c +172 -145
  183. data/ext/rugged/vendor/libgit2-dist/src/tree.h +16 -2
  184. data/ext/rugged/vendor/libgit2-dist/src/tsort.c +16 -14
  185. data/ext/rugged/vendor/libgit2-dist/src/unix/map.c +8 -24
  186. data/ext/rugged/vendor/libgit2-dist/src/unix/posix.h +9 -3
  187. data/ext/rugged/vendor/libgit2-dist/src/util.c +94 -38
  188. data/ext/rugged/vendor/libgit2-dist/src/util.h +119 -13
  189. data/ext/rugged/vendor/libgit2-dist/src/vector.c +84 -31
  190. data/ext/rugged/vendor/libgit2-dist/src/vector.h +37 -4
  191. data/ext/rugged/vendor/libgit2-dist/src/win32/dir.c +81 -41
  192. data/ext/rugged/vendor/libgit2-dist/src/{dir.h → win32/dir.h} +4 -9
  193. data/ext/rugged/vendor/libgit2-dist/src/win32/map.c +19 -35
  194. data/ext/rugged/vendor/libgit2-dist/src/win32/mingw-compat.h +1 -1
  195. data/ext/rugged/vendor/libgit2-dist/src/win32/msvc-compat.h +5 -1
  196. data/ext/rugged/vendor/libgit2-dist/src/win32/posix.h +10 -8
  197. data/ext/rugged/vendor/libgit2-dist/src/win32/posix_w32.c +262 -118
  198. data/ext/rugged/vendor/libgit2-dist/src/win32/pthread.c +12 -9
  199. data/ext/rugged/vendor/libgit2-dist/src/win32/pthread.h +1 -1
  200. data/ext/rugged/vendor/libgit2-dist/src/win32/utf-conv.c +30 -26
  201. data/ext/rugged/vendor/libgit2-dist/src/win32/utf-conv.h +2 -1
  202. data/ext/rugged/vendor/libgit2-dist/src/xdiff/xdiff.h +135 -0
  203. data/ext/rugged/vendor/libgit2-dist/src/xdiff/xdiffi.c +572 -0
  204. data/ext/rugged/vendor/libgit2-dist/src/xdiff/xdiffi.h +63 -0
  205. data/ext/rugged/vendor/libgit2-dist/src/xdiff/xemit.c +253 -0
  206. data/ext/rugged/vendor/libgit2-dist/src/xdiff/xemit.h +36 -0
  207. data/ext/rugged/vendor/libgit2-dist/src/xdiff/xhistogram.c +371 -0
  208. data/ext/rugged/vendor/libgit2-dist/src/xdiff/xinclude.h +46 -0
  209. data/ext/rugged/vendor/libgit2-dist/src/xdiff/xmacros.h +54 -0
  210. data/ext/rugged/vendor/libgit2-dist/src/xdiff/xmerge.c +619 -0
  211. data/ext/rugged/vendor/libgit2-dist/src/xdiff/xpatience.c +358 -0
  212. data/ext/rugged/vendor/libgit2-dist/src/xdiff/xprepare.c +483 -0
  213. data/ext/rugged/vendor/libgit2-dist/src/xdiff/xprepare.h +34 -0
  214. data/ext/rugged/vendor/libgit2-dist/src/xdiff/xtypes.h +67 -0
  215. data/ext/rugged/vendor/libgit2-dist/src/xdiff/xutils.c +419 -0
  216. data/ext/rugged/vendor/libgit2-dist/src/xdiff/xutils.h +49 -0
  217. data/ext/rugged/vendor/libgit2-dist/tests-clar/attr/attr_expect.h +43 -0
  218. data/ext/rugged/vendor/libgit2-dist/tests-clar/attr/file.c +226 -0
  219. data/ext/rugged/vendor/libgit2-dist/tests-clar/attr/flags.c +108 -0
  220. data/ext/rugged/vendor/libgit2-dist/tests-clar/attr/lookup.c +262 -0
  221. data/ext/rugged/vendor/libgit2-dist/tests-clar/attr/repo.c +273 -0
  222. data/ext/rugged/vendor/libgit2-dist/{tests-clay → tests-clar}/buf/basic.c +5 -5
  223. data/ext/rugged/vendor/libgit2-dist/tests-clar/clar_helpers.c +181 -0
  224. data/ext/rugged/vendor/libgit2-dist/tests-clar/clar_libgit2.h +55 -0
  225. data/ext/rugged/vendor/libgit2-dist/tests-clar/commit/commit.c +44 -0
  226. data/ext/rugged/vendor/libgit2-dist/tests-clar/commit/parse.c +350 -0
  227. data/ext/rugged/vendor/libgit2-dist/tests-clar/commit/signature.c +65 -0
  228. data/ext/rugged/vendor/libgit2-dist/tests-clar/commit/write.c +140 -0
  229. data/ext/rugged/vendor/libgit2-dist/{tests-clay → tests-clar}/config/add.c +3 -3
  230. data/ext/rugged/vendor/libgit2-dist/tests-clar/config/multivar.c +151 -0
  231. data/ext/rugged/vendor/libgit2-dist/{tests-clay → tests-clar}/config/new.c +5 -5
  232. data/ext/rugged/vendor/libgit2-dist/{tests-clay → tests-clar}/config/read.c +44 -32
  233. data/ext/rugged/vendor/libgit2-dist/tests-clar/config/stress.c +61 -0
  234. data/ext/rugged/vendor/libgit2-dist/{tests-clay → tests-clar}/config/write.c +20 -5
  235. data/ext/rugged/vendor/libgit2-dist/tests-clar/core/buffer.c +613 -0
  236. data/ext/rugged/vendor/libgit2-dist/{tests-clay → tests-clar}/core/dirent.c +39 -26
  237. data/ext/rugged/vendor/libgit2-dist/tests-clar/core/env.c +115 -0
  238. data/ext/rugged/vendor/libgit2-dist/tests-clar/core/errors.c +60 -0
  239. data/ext/rugged/vendor/libgit2-dist/{tests-clay → tests-clar}/core/filebuf.c +4 -18
  240. data/ext/rugged/vendor/libgit2-dist/tests-clar/core/hex.c +22 -0
  241. data/ext/rugged/vendor/libgit2-dist/{tests-clay → tests-clar}/core/oid.c +6 -6
  242. data/ext/rugged/vendor/libgit2-dist/tests-clar/core/path.c +420 -0
  243. data/ext/rugged/vendor/libgit2-dist/tests-clar/core/pool.c +85 -0
  244. data/ext/rugged/vendor/libgit2-dist/tests-clar/core/rmdir.c +68 -0
  245. data/ext/rugged/vendor/libgit2-dist/{tests-clay → tests-clar}/core/string.c +1 -1
  246. data/ext/rugged/vendor/libgit2-dist/tests-clar/core/strmap.c +102 -0
  247. data/ext/rugged/vendor/libgit2-dist/{tests-clay → tests-clar}/core/strtol.c +1 -1
  248. data/ext/rugged/vendor/libgit2-dist/tests-clar/core/vector.c +191 -0
  249. data/ext/rugged/vendor/libgit2-dist/tests-clar/date/date.c +15 -0
  250. data/ext/rugged/vendor/libgit2-dist/tests-clar/diff/blob.c +254 -0
  251. data/ext/rugged/vendor/libgit2-dist/tests-clar/diff/diff_helpers.c +104 -0
  252. data/ext/rugged/vendor/libgit2-dist/tests-clar/diff/diff_helpers.h +47 -0
  253. data/ext/rugged/vendor/libgit2-dist/tests-clar/diff/index.c +92 -0
  254. data/ext/rugged/vendor/libgit2-dist/tests-clar/diff/iterator.c +572 -0
  255. data/ext/rugged/vendor/libgit2-dist/tests-clar/diff/patch.c +99 -0
  256. data/ext/rugged/vendor/libgit2-dist/tests-clar/diff/tree.c +210 -0
  257. data/ext/rugged/vendor/libgit2-dist/tests-clar/diff/workdir.c +543 -0
  258. data/ext/rugged/vendor/libgit2-dist/tests-clar/index/read_tree.c +46 -0
  259. data/ext/rugged/vendor/libgit2-dist/{tests-clay → tests-clar}/index/rename.c +2 -12
  260. data/ext/rugged/vendor/libgit2-dist/tests-clar/index/tests.c +246 -0
  261. data/ext/rugged/vendor/libgit2-dist/tests-clar/network/createremotethenload.c +33 -0
  262. data/ext/rugged/vendor/libgit2-dist/tests-clar/network/remotelocal.c +137 -0
  263. data/ext/rugged/vendor/libgit2-dist/tests-clar/network/remotes.c +183 -0
  264. data/ext/rugged/vendor/libgit2-dist/tests-clar/notes/notes.c +133 -0
  265. data/ext/rugged/vendor/libgit2-dist/tests-clar/notes/notesref.c +57 -0
  266. data/ext/rugged/vendor/libgit2-dist/tests-clar/object/blob/filter.c +125 -0
  267. data/ext/rugged/vendor/libgit2-dist/tests-clar/object/blob/fromchunks.c +87 -0
  268. data/ext/rugged/vendor/libgit2-dist/tests-clar/object/blob/write.c +69 -0
  269. data/ext/rugged/vendor/libgit2-dist/tests-clar/object/commit/commitstagedfile.c +126 -0
  270. data/ext/rugged/vendor/libgit2-dist/tests-clar/object/lookup.c +63 -0
  271. data/ext/rugged/vendor/libgit2-dist/tests-clar/object/message.c +171 -0
  272. data/ext/rugged/vendor/libgit2-dist/{tests-clay → tests-clar}/object/raw/chars.c +3 -14
  273. data/ext/rugged/vendor/libgit2-dist/{tests-clay → tests-clar}/object/raw/compare.c +4 -4
  274. data/ext/rugged/vendor/libgit2-dist/{tests-clay → tests-clar}/object/raw/convert.c +10 -10
  275. data/ext/rugged/vendor/libgit2-dist/{tests-clay → tests-clar}/object/raw/data.h +0 -0
  276. data/ext/rugged/vendor/libgit2-dist/{tests-clay → tests-clar}/object/raw/fromstr.c +1 -1
  277. data/ext/rugged/vendor/libgit2-dist/{tests-clay → tests-clar}/object/raw/hash.c +21 -17
  278. data/ext/rugged/vendor/libgit2-dist/{tests-clay → tests-clar}/object/raw/short.c +1 -1
  279. data/ext/rugged/vendor/libgit2-dist/{tests-clay → tests-clar}/object/raw/size.c +1 -1
  280. data/ext/rugged/vendor/libgit2-dist/{tests-clay → tests-clar}/object/raw/type2string.c +14 -14
  281. data/ext/rugged/vendor/libgit2-dist/tests-clar/object/raw/write.c +455 -0
  282. data/ext/rugged/vendor/libgit2-dist/tests-clar/object/tag/peel.c +56 -0
  283. data/ext/rugged/vendor/libgit2-dist/tests-clar/object/tag/read.c +130 -0
  284. data/ext/rugged/vendor/libgit2-dist/tests-clar/object/tag/write.c +192 -0
  285. data/ext/rugged/vendor/libgit2-dist/{tests-clay → tests-clar}/object/tree/frompath.c +22 -16
  286. data/ext/rugged/vendor/libgit2-dist/tests-clar/object/tree/read.c +75 -0
  287. data/ext/rugged/vendor/libgit2-dist/tests-clar/object/tree/write.c +84 -0
  288. data/ext/rugged/vendor/libgit2-dist/{tests-clay → tests-clar}/odb/loose.c +1 -1
  289. data/ext/rugged/vendor/libgit2-dist/{tests-clay → tests-clar}/odb/loose_data.h +0 -0
  290. data/ext/rugged/vendor/libgit2-dist/tests-clar/odb/mixed.c +24 -0
  291. data/ext/rugged/vendor/libgit2-dist/{tests-clay → tests-clar}/odb/pack_data.h +0 -0
  292. data/ext/rugged/vendor/libgit2-dist/{tests-clay → tests-clar}/odb/packed.c +1 -1
  293. data/ext/rugged/vendor/libgit2-dist/{tests-clay → tests-clar}/odb/sorting.c +1 -1
  294. data/ext/rugged/vendor/libgit2-dist/tests-clar/refs/branches/create.c +113 -0
  295. data/ext/rugged/vendor/libgit2-dist/tests-clar/refs/branches/delete.c +91 -0
  296. data/ext/rugged/vendor/libgit2-dist/tests-clar/refs/branches/listall.c +78 -0
  297. data/ext/rugged/vendor/libgit2-dist/tests-clar/refs/branches/move.c +72 -0
  298. data/ext/rugged/vendor/libgit2-dist/tests-clar/refs/crashes.c +17 -0
  299. data/ext/rugged/vendor/libgit2-dist/tests-clar/refs/create.c +149 -0
  300. data/ext/rugged/vendor/libgit2-dist/tests-clar/refs/delete.c +85 -0
  301. data/ext/rugged/vendor/libgit2-dist/tests-clar/refs/list.c +53 -0
  302. data/ext/rugged/vendor/libgit2-dist/tests-clar/refs/listall.c +36 -0
  303. data/ext/rugged/vendor/libgit2-dist/tests-clar/refs/lookup.c +42 -0
  304. data/ext/rugged/vendor/libgit2-dist/tests-clar/refs/normalize.c +200 -0
  305. data/ext/rugged/vendor/libgit2-dist/tests-clar/refs/overwrite.c +136 -0
  306. data/ext/rugged/vendor/libgit2-dist/tests-clar/refs/pack.c +67 -0
  307. data/ext/rugged/vendor/libgit2-dist/tests-clar/refs/read.c +194 -0
  308. data/ext/rugged/vendor/libgit2-dist/tests-clar/refs/reflog.c +123 -0
  309. data/ext/rugged/vendor/libgit2-dist/tests-clar/refs/rename.c +339 -0
  310. data/ext/rugged/vendor/libgit2-dist/tests-clar/refs/revparse.c +174 -0
  311. data/ext/rugged/vendor/libgit2-dist/tests-clar/refs/unicode.c +42 -0
  312. data/ext/rugged/vendor/libgit2-dist/tests-clar/repo/discover.c +142 -0
  313. data/ext/rugged/vendor/libgit2-dist/{tests-clay → tests-clar}/repo/getters.c +19 -1
  314. data/ext/rugged/vendor/libgit2-dist/tests-clar/repo/init.c +235 -0
  315. data/ext/rugged/vendor/libgit2-dist/tests-clar/repo/open.c +282 -0
  316. data/ext/rugged/vendor/libgit2-dist/tests-clar/repo/setters.c +80 -0
  317. data/ext/rugged/vendor/libgit2-dist/tests-clar/reset/mixed.c +47 -0
  318. data/ext/rugged/vendor/libgit2-dist/tests-clar/reset/reset_helpers.c +10 -0
  319. data/ext/rugged/vendor/libgit2-dist/tests-clar/reset/reset_helpers.h +6 -0
  320. data/ext/rugged/vendor/libgit2-dist/tests-clar/reset/soft.c +102 -0
  321. data/ext/rugged/vendor/libgit2-dist/{tests/t05-revwalk.c → tests-clar/revwalk/basic.c} +85 -44
  322. data/ext/rugged/vendor/libgit2-dist/tests-clar/revwalk/mergebase.c +148 -0
  323. data/ext/rugged/vendor/libgit2-dist/tests-clar/status/ignore.c +133 -0
  324. data/ext/rugged/vendor/libgit2-dist/{tests-clay → tests-clar}/status/single.c +2 -11
  325. data/ext/rugged/vendor/libgit2-dist/tests-clar/status/status_data.h +202 -0
  326. data/ext/rugged/vendor/libgit2-dist/tests-clar/status/status_helpers.c +49 -0
  327. data/ext/rugged/vendor/libgit2-dist/tests-clar/status/status_helpers.h +33 -0
  328. data/ext/rugged/vendor/libgit2-dist/tests-clar/status/submodules.c +112 -0
  329. data/ext/rugged/vendor/libgit2-dist/tests-clar/status/worktree.c +649 -0
  330. data/ext/rugged/vendor/libgit2-dist/tests-clar/threads/basic.c +20 -0
  331. data/ext/rugged/vendor/libgit2-dist.tar.gz +0 -0
  332. data/lib/rugged/commit.rb +35 -0
  333. data/lib/rugged/object.rb +7 -0
  334. data/lib/rugged/reference.rb +9 -0
  335. data/lib/rugged/repository.rb +99 -3
  336. data/lib/rugged/tag.rb +22 -0
  337. data/lib/rugged/tree.rb +8 -0
  338. data/lib/rugged/version.rb +1 -1
  339. data/lib/rugged.rb +4 -1
  340. data/test/blob_test.rb +2 -2
  341. data/test/commit_test.rb +27 -13
  342. data/test/config_test.rb +44 -0
  343. data/test/coverage/HEAD.json +1 -1
  344. data/test/fixtures/testrepo.git/config +2 -0
  345. data/test/fixtures/testrepo.git/objects/7f/043268ea43ce18e3540acaabf9e090c91965b0 +0 -0
  346. data/test/lib_test.rb +7 -0
  347. data/test/object_test.rb +3 -3
  348. data/test/reference_test.rb +46 -8
  349. data/test/remote_test.rb +8 -2
  350. data/test/repo_pack_test.rb +3 -3
  351. data/test/repo_test.rb +79 -11
  352. data/test/tag_test.rb +9 -2
  353. data/test/test_helper.rb +21 -0
  354. data/test/tree_test.rb +18 -6
  355. metadata +205 -81
  356. data/ext/rugged/vendor/libgit2-dist/include/git2/zlib.h +0 -40
  357. data/ext/rugged/vendor/libgit2-dist/src/hashtable.c +0 -243
  358. data/ext/rugged/vendor/libgit2-dist/src/hashtable.h +0 -80
  359. data/ext/rugged/vendor/libgit2-dist/tests/t00-core.c +0 -628
  360. data/ext/rugged/vendor/libgit2-dist/tests/t01-data.h +0 -322
  361. data/ext/rugged/vendor/libgit2-dist/tests/t01-rawobj.c +0 -638
  362. data/ext/rugged/vendor/libgit2-dist/tests/t03-data.h +0 -344
  363. data/ext/rugged/vendor/libgit2-dist/tests/t03-objwrite.c +0 -255
  364. data/ext/rugged/vendor/libgit2-dist/tests/t04-commit.c +0 -788
  365. data/ext/rugged/vendor/libgit2-dist/tests/t06-index.c +0 -219
  366. data/ext/rugged/vendor/libgit2-dist/tests/t07-hashtable.c +0 -192
  367. data/ext/rugged/vendor/libgit2-dist/tests/t08-tag.c +0 -357
  368. data/ext/rugged/vendor/libgit2-dist/tests/t09-tree.c +0 -221
  369. data/ext/rugged/vendor/libgit2-dist/tests/t10-refs.c +0 -1294
  370. data/ext/rugged/vendor/libgit2-dist/tests/t12-repo.c +0 -174
  371. data/ext/rugged/vendor/libgit2-dist/tests/t13-threads.c +0 -41
  372. data/ext/rugged/vendor/libgit2-dist/tests/t17-bufs.c +0 -61
  373. data/ext/rugged/vendor/libgit2-dist/tests/t18-status.c +0 -448
  374. data/ext/rugged/vendor/libgit2-dist/tests/test_helpers.c +0 -310
  375. data/ext/rugged/vendor/libgit2-dist/tests/test_helpers.h +0 -83
  376. data/ext/rugged/vendor/libgit2-dist/tests/test_lib.c +0 -198
  377. data/ext/rugged/vendor/libgit2-dist/tests/test_lib.h +0 -54
  378. data/ext/rugged/vendor/libgit2-dist/tests/test_main.c +0 -89
  379. data/ext/rugged/vendor/libgit2-dist/tests-clay/clay.h +0 -187
  380. data/ext/rugged/vendor/libgit2-dist/tests-clay/clay_libgit2.h +0 -28
  381. data/ext/rugged/vendor/libgit2-dist/tests-clay/clay_main.c +0 -1073
  382. data/ext/rugged/vendor/libgit2-dist/tests-clay/config/stress.c +0 -39
  383. data/ext/rugged/vendor/libgit2-dist/tests-clay/core/path.c +0 -139
  384. data/ext/rugged/vendor/libgit2-dist/tests-clay/core/rmdir.c +0 -50
  385. data/ext/rugged/vendor/libgit2-dist/tests-clay/core/vector.c +0 -66
  386. data/ext/rugged/vendor/libgit2-dist/tests-clay/network/remotes.c +0 -50
  387. data/ext/rugged/vendor/libgit2-dist/tests-clay/repo/init.c +0 -104
  388. data/ext/rugged/vendor/libgit2-dist/tests-clay/repo/open.c +0 -54
  389. data/ext/rugged/vendor/libgit2-dist/tests-clay/status/status_data.h +0 -48
  390. data/ext/rugged/vendor/libgit2-dist/tests-clay/status/worktree.c +0 -124
  391. data/lib/rugged/objects.rb +0 -45
  392. data/test/fixtures/testrepo.git/refs/heads/new_name +0 -1
@@ -0,0 +1,876 @@
1
+ /*
2
+ * GIT - The information manager from hell
3
+ *
4
+ * Copyright (C) Linus Torvalds, 2005
5
+ */
6
+
7
+ #include "common.h"
8
+
9
+ #ifndef GIT_WIN32
10
+ #include <sys/time.h>
11
+ #endif
12
+
13
+ #include "util.h"
14
+ #include "cache.h"
15
+ #include "posix.h"
16
+
17
+ #include <ctype.h>
18
+ #include <time.h>
19
+
20
+ typedef enum {
21
+ DATE_NORMAL = 0,
22
+ DATE_RELATIVE,
23
+ DATE_SHORT,
24
+ DATE_LOCAL,
25
+ DATE_ISO8601,
26
+ DATE_RFC2822,
27
+ DATE_RAW
28
+ } date_mode;
29
+
30
+ /*
31
+ * This is like mktime, but without normalization of tm_wday and tm_yday.
32
+ */
33
+ static git_time_t tm_to_time_t(const struct tm *tm)
34
+ {
35
+ static const int mdays[] = {
36
+ 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334
37
+ };
38
+ int year = tm->tm_year - 70;
39
+ int month = tm->tm_mon;
40
+ int day = tm->tm_mday;
41
+
42
+ if (year < 0 || year > 129) /* algo only works for 1970-2099 */
43
+ return -1;
44
+ if (month < 0 || month > 11) /* array bounds */
45
+ return -1;
46
+ if (month < 2 || (year + 2) % 4)
47
+ day--;
48
+ if (tm->tm_hour < 0 || tm->tm_min < 0 || tm->tm_sec < 0)
49
+ return -1;
50
+ return (year * 365 + (year + 1) / 4 + mdays[month] + day) * 24*60*60UL +
51
+ tm->tm_hour * 60*60 + tm->tm_min * 60 + tm->tm_sec;
52
+ }
53
+
54
+ static const char *month_names[] = {
55
+ "January", "February", "March", "April", "May", "June",
56
+ "July", "August", "September", "October", "November", "December"
57
+ };
58
+
59
+ static const char *weekday_names[] = {
60
+ "Sundays", "Mondays", "Tuesdays", "Wednesdays", "Thursdays", "Fridays", "Saturdays"
61
+ };
62
+
63
+
64
+
65
+ /*
66
+ * Check these. And note how it doesn't do the summer-time conversion.
67
+ *
68
+ * In my world, it's always summer, and things are probably a bit off
69
+ * in other ways too.
70
+ */
71
+ static const struct {
72
+ const char *name;
73
+ int offset;
74
+ int dst;
75
+ } timezone_names[] = {
76
+ { "IDLW", -12, 0, }, /* International Date Line West */
77
+ { "NT", -11, 0, }, /* Nome */
78
+ { "CAT", -10, 0, }, /* Central Alaska */
79
+ { "HST", -10, 0, }, /* Hawaii Standard */
80
+ { "HDT", -10, 1, }, /* Hawaii Daylight */
81
+ { "YST", -9, 0, }, /* Yukon Standard */
82
+ { "YDT", -9, 1, }, /* Yukon Daylight */
83
+ { "PST", -8, 0, }, /* Pacific Standard */
84
+ { "PDT", -8, 1, }, /* Pacific Daylight */
85
+ { "MST", -7, 0, }, /* Mountain Standard */
86
+ { "MDT", -7, 1, }, /* Mountain Daylight */
87
+ { "CST", -6, 0, }, /* Central Standard */
88
+ { "CDT", -6, 1, }, /* Central Daylight */
89
+ { "EST", -5, 0, }, /* Eastern Standard */
90
+ { "EDT", -5, 1, }, /* Eastern Daylight */
91
+ { "AST", -3, 0, }, /* Atlantic Standard */
92
+ { "ADT", -3, 1, }, /* Atlantic Daylight */
93
+ { "WAT", -1, 0, }, /* West Africa */
94
+
95
+ { "GMT", 0, 0, }, /* Greenwich Mean */
96
+ { "UTC", 0, 0, }, /* Universal (Coordinated) */
97
+ { "Z", 0, 0, }, /* Zulu, alias for UTC */
98
+
99
+ { "WET", 0, 0, }, /* Western European */
100
+ { "BST", 0, 1, }, /* British Summer */
101
+ { "CET", +1, 0, }, /* Central European */
102
+ { "MET", +1, 0, }, /* Middle European */
103
+ { "MEWT", +1, 0, }, /* Middle European Winter */
104
+ { "MEST", +1, 1, }, /* Middle European Summer */
105
+ { "CEST", +1, 1, }, /* Central European Summer */
106
+ { "MESZ", +1, 1, }, /* Middle European Summer */
107
+ { "FWT", +1, 0, }, /* French Winter */
108
+ { "FST", +1, 1, }, /* French Summer */
109
+ { "EET", +2, 0, }, /* Eastern Europe, USSR Zone 1 */
110
+ { "EEST", +2, 1, }, /* Eastern European Daylight */
111
+ { "WAST", +7, 0, }, /* West Australian Standard */
112
+ { "WADT", +7, 1, }, /* West Australian Daylight */
113
+ { "CCT", +8, 0, }, /* China Coast, USSR Zone 7 */
114
+ { "JST", +9, 0, }, /* Japan Standard, USSR Zone 8 */
115
+ { "EAST", +10, 0, }, /* Eastern Australian Standard */
116
+ { "EADT", +10, 1, }, /* Eastern Australian Daylight */
117
+ { "GST", +10, 0, }, /* Guam Standard, USSR Zone 9 */
118
+ { "NZT", +12, 0, }, /* New Zealand */
119
+ { "NZST", +12, 0, }, /* New Zealand Standard */
120
+ { "NZDT", +12, 1, }, /* New Zealand Daylight */
121
+ { "IDLE", +12, 0, }, /* International Date Line East */
122
+ };
123
+
124
+ static int match_string(const char *date, const char *str)
125
+ {
126
+ int i = 0;
127
+
128
+ for (i = 0; *date; date++, str++, i++) {
129
+ if (*date == *str)
130
+ continue;
131
+ if (toupper(*date) == toupper(*str))
132
+ continue;
133
+ if (!isalnum(*date))
134
+ break;
135
+ return 0;
136
+ }
137
+ return i;
138
+ }
139
+
140
+ static int skip_alpha(const char *date)
141
+ {
142
+ int i = 0;
143
+ do {
144
+ i++;
145
+ } while (isalpha(date[i]));
146
+ return i;
147
+ }
148
+
149
+ /*
150
+ * Parse month, weekday, or timezone name
151
+ */
152
+ static int match_alpha(const char *date, struct tm *tm, int *offset)
153
+ {
154
+ unsigned int i;
155
+
156
+ for (i = 0; i < 12; i++) {
157
+ int match = match_string(date, month_names[i]);
158
+ if (match >= 3) {
159
+ tm->tm_mon = i;
160
+ return match;
161
+ }
162
+ }
163
+
164
+ for (i = 0; i < 7; i++) {
165
+ int match = match_string(date, weekday_names[i]);
166
+ if (match >= 3) {
167
+ tm->tm_wday = i;
168
+ return match;
169
+ }
170
+ }
171
+
172
+ for (i = 0; i < ARRAY_SIZE(timezone_names); i++) {
173
+ int match = match_string(date, timezone_names[i].name);
174
+ if (match >= 3 || match == (int)strlen(timezone_names[i].name)) {
175
+ int off = timezone_names[i].offset;
176
+
177
+ /* This is bogus, but we like summer */
178
+ off += timezone_names[i].dst;
179
+
180
+ /* Only use the tz name offset if we don't have anything better */
181
+ if (*offset == -1)
182
+ *offset = 60*off;
183
+
184
+ return match;
185
+ }
186
+ }
187
+
188
+ if (match_string(date, "PM") == 2) {
189
+ tm->tm_hour = (tm->tm_hour % 12) + 12;
190
+ return 2;
191
+ }
192
+
193
+ if (match_string(date, "AM") == 2) {
194
+ tm->tm_hour = (tm->tm_hour % 12) + 0;
195
+ return 2;
196
+ }
197
+
198
+ /* BAD CRAP */
199
+ return skip_alpha(date);
200
+ }
201
+
202
+ static int is_date(int year, int month, int day, struct tm *now_tm, time_t now, struct tm *tm)
203
+ {
204
+ if (month > 0 && month < 13 && day > 0 && day < 32) {
205
+ struct tm check = *tm;
206
+ struct tm *r = (now_tm ? &check : tm);
207
+ time_t specified;
208
+
209
+ r->tm_mon = month - 1;
210
+ r->tm_mday = day;
211
+ if (year == -1) {
212
+ if (!now_tm)
213
+ return 1;
214
+ r->tm_year = now_tm->tm_year;
215
+ }
216
+ else if (year >= 1970 && year < 2100)
217
+ r->tm_year = year - 1900;
218
+ else if (year > 70 && year < 100)
219
+ r->tm_year = year;
220
+ else if (year < 38)
221
+ r->tm_year = year + 100;
222
+ else
223
+ return 0;
224
+ if (!now_tm)
225
+ return 1;
226
+
227
+ specified = tm_to_time_t(r);
228
+
229
+ /* Be it commit time or author time, it does not make
230
+ * sense to specify timestamp way into the future. Make
231
+ * sure it is not later than ten days from now...
232
+ */
233
+ if (now + 10*24*3600 < specified)
234
+ return 0;
235
+ tm->tm_mon = r->tm_mon;
236
+ tm->tm_mday = r->tm_mday;
237
+ if (year != -1)
238
+ tm->tm_year = r->tm_year;
239
+ return 1;
240
+ }
241
+ return 0;
242
+ }
243
+
244
+ static int match_multi_number(unsigned long num, char c, const char *date, char *end, struct tm *tm)
245
+ {
246
+ time_t now;
247
+ struct tm now_tm;
248
+ struct tm *refuse_future;
249
+ long num2, num3;
250
+
251
+ num2 = strtol(end+1, &end, 10);
252
+ num3 = -1;
253
+ if (*end == c && isdigit(end[1]))
254
+ num3 = strtol(end+1, &end, 10);
255
+
256
+ /* Time? Date? */
257
+ switch (c) {
258
+ case ':':
259
+ if (num3 < 0)
260
+ num3 = 0;
261
+ if (num < 25 && num2 >= 0 && num2 < 60 && num3 >= 0 && num3 <= 60) {
262
+ tm->tm_hour = num;
263
+ tm->tm_min = num2;
264
+ tm->tm_sec = num3;
265
+ break;
266
+ }
267
+ return 0;
268
+
269
+ case '-':
270
+ case '/':
271
+ case '.':
272
+ now = time(NULL);
273
+ refuse_future = NULL;
274
+ if (p_gmtime_r(&now, &now_tm))
275
+ refuse_future = &now_tm;
276
+
277
+ if (num > 70) {
278
+ /* yyyy-mm-dd? */
279
+ if (is_date(num, num2, num3, refuse_future, now, tm))
280
+ break;
281
+ /* yyyy-dd-mm? */
282
+ if (is_date(num, num3, num2, refuse_future, now, tm))
283
+ break;
284
+ }
285
+ /* Our eastern European friends say dd.mm.yy[yy]
286
+ * is the norm there, so giving precedence to
287
+ * mm/dd/yy[yy] form only when separator is not '.'
288
+ */
289
+ if (c != '.' &&
290
+ is_date(num3, num, num2, refuse_future, now, tm))
291
+ break;
292
+ /* European dd.mm.yy[yy] or funny US dd/mm/yy[yy] */
293
+ if (is_date(num3, num2, num, refuse_future, now, tm))
294
+ break;
295
+ /* Funny European mm.dd.yy */
296
+ if (c == '.' &&
297
+ is_date(num3, num, num2, refuse_future, now, tm))
298
+ break;
299
+ return 0;
300
+ }
301
+ return end - date;
302
+ }
303
+
304
+ /*
305
+ * Have we filled in any part of the time/date yet?
306
+ * We just do a binary 'and' to see if the sign bit
307
+ * is set in all the values.
308
+ */
309
+ static int nodate(struct tm *tm)
310
+ {
311
+ return (tm->tm_year &
312
+ tm->tm_mon &
313
+ tm->tm_mday &
314
+ tm->tm_hour &
315
+ tm->tm_min &
316
+ tm->tm_sec) < 0;
317
+ }
318
+
319
+ /*
320
+ * We've seen a digit. Time? Year? Date?
321
+ */
322
+ static int match_digit(const char *date, struct tm *tm, int *offset, int *tm_gmt)
323
+ {
324
+ int n;
325
+ char *end;
326
+ unsigned long num;
327
+
328
+ num = strtoul(date, &end, 10);
329
+
330
+ /*
331
+ * Seconds since 1970? We trigger on that for any numbers with
332
+ * more than 8 digits. This is because we don't want to rule out
333
+ * numbers like 20070606 as a YYYYMMDD date.
334
+ */
335
+ if (num >= 100000000 && nodate(tm)) {
336
+ time_t time = num;
337
+ if (p_gmtime_r(&time, tm)) {
338
+ *tm_gmt = 1;
339
+ return end - date;
340
+ }
341
+ }
342
+
343
+ /*
344
+ * Check for special formats: num[-.:/]num[same]num
345
+ */
346
+ switch (*end) {
347
+ case ':':
348
+ case '.':
349
+ case '/':
350
+ case '-':
351
+ if (isdigit(end[1])) {
352
+ int match = match_multi_number(num, *end, date, end, tm);
353
+ if (match)
354
+ return match;
355
+ }
356
+ }
357
+
358
+ /*
359
+ * None of the special formats? Try to guess what
360
+ * the number meant. We use the number of digits
361
+ * to make a more educated guess..
362
+ */
363
+ n = 0;
364
+ do {
365
+ n++;
366
+ } while (isdigit(date[n]));
367
+
368
+ /* Four-digit year or a timezone? */
369
+ if (n == 4) {
370
+ if (num <= 1400 && *offset == -1) {
371
+ unsigned int minutes = num % 100;
372
+ unsigned int hours = num / 100;
373
+ *offset = hours*60 + minutes;
374
+ } else if (num > 1900 && num < 2100)
375
+ tm->tm_year = num - 1900;
376
+ return n;
377
+ }
378
+
379
+ /*
380
+ * Ignore lots of numerals. We took care of 4-digit years above.
381
+ * Days or months must be one or two digits.
382
+ */
383
+ if (n > 2)
384
+ return n;
385
+
386
+ /*
387
+ * NOTE! We will give precedence to day-of-month over month or
388
+ * year numbers in the 1-12 range. So 05 is always "mday 5",
389
+ * unless we already have a mday..
390
+ *
391
+ * IOW, 01 Apr 05 parses as "April 1st, 2005".
392
+ */
393
+ if (num > 0 && num < 32 && tm->tm_mday < 0) {
394
+ tm->tm_mday = num;
395
+ return n;
396
+ }
397
+
398
+ /* Two-digit year? */
399
+ if (n == 2 && tm->tm_year < 0) {
400
+ if (num < 10 && tm->tm_mday >= 0) {
401
+ tm->tm_year = num + 100;
402
+ return n;
403
+ }
404
+ if (num >= 70) {
405
+ tm->tm_year = num;
406
+ return n;
407
+ }
408
+ }
409
+
410
+ if (num > 0 && num < 13 && tm->tm_mon < 0)
411
+ tm->tm_mon = num-1;
412
+
413
+ return n;
414
+ }
415
+
416
+ static int match_tz(const char *date, int *offp)
417
+ {
418
+ char *end;
419
+ int hour = strtoul(date + 1, &end, 10);
420
+ int n = end - (date + 1);
421
+ int min = 0;
422
+
423
+ if (n == 4) {
424
+ /* hhmm */
425
+ min = hour % 100;
426
+ hour = hour / 100;
427
+ } else if (n != 2) {
428
+ min = 99; /* random crap */
429
+ } else if (*end == ':') {
430
+ /* hh:mm? */
431
+ min = strtoul(end + 1, &end, 10);
432
+ if (end - (date + 1) != 5)
433
+ min = 99; /* random crap */
434
+ } /* otherwise we parsed "hh" */
435
+
436
+ /*
437
+ * Don't accept any random crap. Even though some places have
438
+ * offset larger than 12 hours (e.g. Pacific/Kiritimati is at
439
+ * UTC+14), there is something wrong if hour part is much
440
+ * larger than that. We might also want to check that the
441
+ * minutes are divisible by 15 or something too. (Offset of
442
+ * Kathmandu, Nepal is UTC+5:45)
443
+ */
444
+ if (min < 60 && hour < 24) {
445
+ int offset = hour * 60 + min;
446
+ if (*date == '-')
447
+ offset = -offset;
448
+ *offp = offset;
449
+ }
450
+ return end - date;
451
+ }
452
+
453
+ /*
454
+ * Parse a string like "0 +0000" as ancient timestamp near epoch, but
455
+ * only when it appears not as part of any other string.
456
+ */
457
+ static int match_object_header_date(const char *date, git_time_t *timestamp, int *offset)
458
+ {
459
+ char *end;
460
+ unsigned long stamp;
461
+ int ofs;
462
+
463
+ if (*date < '0' || '9' <= *date)
464
+ return -1;
465
+ stamp = strtoul(date, &end, 10);
466
+ if (*end != ' ' || stamp == ULONG_MAX || (end[1] != '+' && end[1] != '-'))
467
+ return -1;
468
+ date = end + 2;
469
+ ofs = strtol(date, &end, 10);
470
+ if ((*end != '\0' && (*end != '\n')) || end != date + 4)
471
+ return -1;
472
+ ofs = (ofs / 100) * 60 + (ofs % 100);
473
+ if (date[-1] == '-')
474
+ ofs = -ofs;
475
+ *timestamp = stamp;
476
+ *offset = ofs;
477
+ return 0;
478
+ }
479
+
480
+ /* Gr. strptime is crap for this; it doesn't have a way to require RFC2822
481
+ (i.e. English) day/month names, and it doesn't work correctly with %z. */
482
+ static int parse_date_basic(const char *date, git_time_t *timestamp, int *offset)
483
+ {
484
+ struct tm tm;
485
+ int tm_gmt;
486
+ git_time_t dummy_timestamp;
487
+ int dummy_offset;
488
+
489
+ if (!timestamp)
490
+ timestamp = &dummy_timestamp;
491
+ if (!offset)
492
+ offset = &dummy_offset;
493
+
494
+ memset(&tm, 0, sizeof(tm));
495
+ tm.tm_year = -1;
496
+ tm.tm_mon = -1;
497
+ tm.tm_mday = -1;
498
+ tm.tm_isdst = -1;
499
+ tm.tm_hour = -1;
500
+ tm.tm_min = -1;
501
+ tm.tm_sec = -1;
502
+ *offset = -1;
503
+ tm_gmt = 0;
504
+
505
+ if (*date == '@' &&
506
+ !match_object_header_date(date + 1, timestamp, offset))
507
+ return 0; /* success */
508
+ for (;;) {
509
+ int match = 0;
510
+ unsigned char c = *date;
511
+
512
+ /* Stop at end of string or newline */
513
+ if (!c || c == '\n')
514
+ break;
515
+
516
+ if (isalpha(c))
517
+ match = match_alpha(date, &tm, offset);
518
+ else if (isdigit(c))
519
+ match = match_digit(date, &tm, offset, &tm_gmt);
520
+ else if ((c == '-' || c == '+') && isdigit(date[1]))
521
+ match = match_tz(date, offset);
522
+
523
+ if (!match) {
524
+ /* BAD CRAP */
525
+ match = 1;
526
+ }
527
+
528
+ date += match;
529
+ }
530
+
531
+ /* mktime uses local timezone */
532
+ *timestamp = tm_to_time_t(&tm);
533
+ if (*offset == -1)
534
+ *offset = (int)((time_t)*timestamp - mktime(&tm)) / 60;
535
+
536
+ if (*timestamp == (git_time_t)-1)
537
+ return -1;
538
+
539
+ if (!tm_gmt)
540
+ *timestamp -= *offset * 60;
541
+ return 0; /* success */
542
+ }
543
+
544
+
545
+ /*
546
+ * Relative time update (eg "2 days ago"). If we haven't set the time
547
+ * yet, we need to set it from current time.
548
+ */
549
+ static git_time_t update_tm(struct tm *tm, struct tm *now, unsigned long sec)
550
+ {
551
+ time_t n;
552
+
553
+ if (tm->tm_mday < 0)
554
+ tm->tm_mday = now->tm_mday;
555
+ if (tm->tm_mon < 0)
556
+ tm->tm_mon = now->tm_mon;
557
+ if (tm->tm_year < 0) {
558
+ tm->tm_year = now->tm_year;
559
+ if (tm->tm_mon > now->tm_mon)
560
+ tm->tm_year--;
561
+ }
562
+
563
+ n = mktime(tm) - sec;
564
+ p_localtime_r(&n, tm);
565
+ return n;
566
+ }
567
+
568
+ static void date_now(struct tm *tm, struct tm *now, int *num)
569
+ {
570
+ GIT_UNUSED(num);
571
+ update_tm(tm, now, 0);
572
+ }
573
+
574
+ static void date_yesterday(struct tm *tm, struct tm *now, int *num)
575
+ {
576
+ GIT_UNUSED(num);
577
+ update_tm(tm, now, 24*60*60);
578
+ }
579
+
580
+ static void date_time(struct tm *tm, struct tm *now, int hour)
581
+ {
582
+ if (tm->tm_hour < hour)
583
+ date_yesterday(tm, now, NULL);
584
+ tm->tm_hour = hour;
585
+ tm->tm_min = 0;
586
+ tm->tm_sec = 0;
587
+ }
588
+
589
+ static void date_midnight(struct tm *tm, struct tm *now, int *num)
590
+ {
591
+ GIT_UNUSED(num);
592
+ date_time(tm, now, 0);
593
+ }
594
+
595
+ static void date_noon(struct tm *tm, struct tm *now, int *num)
596
+ {
597
+ GIT_UNUSED(num);
598
+ date_time(tm, now, 12);
599
+ }
600
+
601
+ static void date_tea(struct tm *tm, struct tm *now, int *num)
602
+ {
603
+ GIT_UNUSED(num);
604
+ date_time(tm, now, 17);
605
+ }
606
+
607
+ static void date_pm(struct tm *tm, struct tm *now, int *num)
608
+ {
609
+ int hour, n = *num;
610
+ *num = 0;
611
+ GIT_UNUSED(now);
612
+
613
+ hour = tm->tm_hour;
614
+ if (n) {
615
+ hour = n;
616
+ tm->tm_min = 0;
617
+ tm->tm_sec = 0;
618
+ }
619
+ tm->tm_hour = (hour % 12) + 12;
620
+ }
621
+
622
+ static void date_am(struct tm *tm, struct tm *now, int *num)
623
+ {
624
+ int hour, n = *num;
625
+ *num = 0;
626
+ GIT_UNUSED(now);
627
+
628
+ hour = tm->tm_hour;
629
+ if (n) {
630
+ hour = n;
631
+ tm->tm_min = 0;
632
+ tm->tm_sec = 0;
633
+ }
634
+ tm->tm_hour = (hour % 12);
635
+ }
636
+
637
+ static void date_never(struct tm *tm, struct tm *now, int *num)
638
+ {
639
+ time_t n = 0;
640
+ GIT_UNUSED(now);
641
+ GIT_UNUSED(num);
642
+ p_localtime_r(&n, tm);
643
+ }
644
+
645
+ static const struct special {
646
+ const char *name;
647
+ void (*fn)(struct tm *, struct tm *, int *);
648
+ } special[] = {
649
+ { "yesterday", date_yesterday },
650
+ { "noon", date_noon },
651
+ { "midnight", date_midnight },
652
+ { "tea", date_tea },
653
+ { "PM", date_pm },
654
+ { "AM", date_am },
655
+ { "never", date_never },
656
+ { "now", date_now },
657
+ { NULL }
658
+ };
659
+
660
+ static const char *number_name[] = {
661
+ "zero", "one", "two", "three", "four",
662
+ "five", "six", "seven", "eight", "nine", "ten",
663
+ };
664
+
665
+ static const struct typelen {
666
+ const char *type;
667
+ int length;
668
+ } typelen[] = {
669
+ { "seconds", 1 },
670
+ { "minutes", 60 },
671
+ { "hours", 60*60 },
672
+ { "days", 24*60*60 },
673
+ { "weeks", 7*24*60*60 },
674
+ { NULL }
675
+ };
676
+
677
+ static const char *approxidate_alpha(const char *date, struct tm *tm, struct tm *now, int *num, int *touched)
678
+ {
679
+ const struct typelen *tl;
680
+ const struct special *s;
681
+ const char *end = date;
682
+ int i;
683
+
684
+ while (isalpha(*++end));
685
+ ;
686
+
687
+ for (i = 0; i < 12; i++) {
688
+ int match = match_string(date, month_names[i]);
689
+ if (match >= 3) {
690
+ tm->tm_mon = i;
691
+ *touched = 1;
692
+ return end;
693
+ }
694
+ }
695
+
696
+ for (s = special; s->name; s++) {
697
+ int len = strlen(s->name);
698
+ if (match_string(date, s->name) == len) {
699
+ s->fn(tm, now, num);
700
+ *touched = 1;
701
+ return end;
702
+ }
703
+ }
704
+
705
+ if (!*num) {
706
+ for (i = 1; i < 11; i++) {
707
+ int len = strlen(number_name[i]);
708
+ if (match_string(date, number_name[i]) == len) {
709
+ *num = i;
710
+ *touched = 1;
711
+ return end;
712
+ }
713
+ }
714
+ if (match_string(date, "last") == 4) {
715
+ *num = 1;
716
+ *touched = 1;
717
+ }
718
+ return end;
719
+ }
720
+
721
+ tl = typelen;
722
+ while (tl->type) {
723
+ int len = strlen(tl->type);
724
+ if (match_string(date, tl->type) >= len-1) {
725
+ update_tm(tm, now, tl->length * *num);
726
+ *num = 0;
727
+ *touched = 1;
728
+ return end;
729
+ }
730
+ tl++;
731
+ }
732
+
733
+ for (i = 0; i < 7; i++) {
734
+ int match = match_string(date, weekday_names[i]);
735
+ if (match >= 3) {
736
+ int diff, n = *num -1;
737
+ *num = 0;
738
+
739
+ diff = tm->tm_wday - i;
740
+ if (diff <= 0)
741
+ n++;
742
+ diff += 7*n;
743
+
744
+ update_tm(tm, now, diff * 24 * 60 * 60);
745
+ *touched = 1;
746
+ return end;
747
+ }
748
+ }
749
+
750
+ if (match_string(date, "months") >= 5) {
751
+ int n;
752
+ update_tm(tm, now, 0); /* fill in date fields if needed */
753
+ n = tm->tm_mon - *num;
754
+ *num = 0;
755
+ while (n < 0) {
756
+ n += 12;
757
+ tm->tm_year--;
758
+ }
759
+ tm->tm_mon = n;
760
+ *touched = 1;
761
+ return end;
762
+ }
763
+
764
+ if (match_string(date, "years") >= 4) {
765
+ update_tm(tm, now, 0); /* fill in date fields if needed */
766
+ tm->tm_year -= *num;
767
+ *num = 0;
768
+ *touched = 1;
769
+ return end;
770
+ }
771
+
772
+ return end;
773
+ }
774
+
775
+ static const char *approxidate_digit(const char *date, struct tm *tm, int *num)
776
+ {
777
+ char *end;
778
+ unsigned long number = strtoul(date, &end, 10);
779
+
780
+ switch (*end) {
781
+ case ':':
782
+ case '.':
783
+ case '/':
784
+ case '-':
785
+ if (isdigit(end[1])) {
786
+ int match = match_multi_number(number, *end, date, end, tm);
787
+ if (match)
788
+ return date + match;
789
+ }
790
+ }
791
+
792
+ /* Accept zero-padding only for small numbers ("Dec 02", never "Dec 0002") */
793
+ if (date[0] != '0' || end - date <= 2)
794
+ *num = number;
795
+ return end;
796
+ }
797
+
798
+ /*
799
+ * Do we have a pending number at the end, or when
800
+ * we see a new one? Let's assume it's a month day,
801
+ * as in "Dec 6, 1992"
802
+ */
803
+ static void pending_number(struct tm *tm, int *num)
804
+ {
805
+ int number = *num;
806
+
807
+ if (number) {
808
+ *num = 0;
809
+ if (tm->tm_mday < 0 && number < 32)
810
+ tm->tm_mday = number;
811
+ else if (tm->tm_mon < 0 && number < 13)
812
+ tm->tm_mon = number-1;
813
+ else if (tm->tm_year < 0) {
814
+ if (number > 1969 && number < 2100)
815
+ tm->tm_year = number - 1900;
816
+ else if (number > 69 && number < 100)
817
+ tm->tm_year = number;
818
+ else if (number < 38)
819
+ tm->tm_year = 100 + number;
820
+ /* We screw up for number = 00 ? */
821
+ }
822
+ }
823
+ }
824
+
825
+ static git_time_t approxidate_str(const char *date,
826
+ const struct timeval *tv,
827
+ int *error_ret)
828
+ {
829
+ int number = 0;
830
+ int touched = 0;
831
+ struct tm tm = {0}, now;
832
+ time_t time_sec;
833
+
834
+ time_sec = tv->tv_sec;
835
+ p_localtime_r(&time_sec, &tm);
836
+ now = tm;
837
+
838
+ tm.tm_year = -1;
839
+ tm.tm_mon = -1;
840
+ tm.tm_mday = -1;
841
+
842
+ for (;;) {
843
+ unsigned char c = *date;
844
+ if (!c)
845
+ break;
846
+ date++;
847
+ if (isdigit(c)) {
848
+ pending_number(&tm, &number);
849
+ date = approxidate_digit(date-1, &tm, &number);
850
+ touched = 1;
851
+ continue;
852
+ }
853
+ if (isalpha(c))
854
+ date = approxidate_alpha(date-1, &tm, &now, &number, &touched);
855
+ }
856
+ pending_number(&tm, &number);
857
+ if (!touched)
858
+ *error_ret = 1;
859
+ return update_tm(&tm, &now, 0);
860
+ }
861
+
862
+ int git__date_parse(git_time_t *out, const char *date)
863
+ {
864
+ struct timeval tv;
865
+ git_time_t timestamp;
866
+ int offset, error_ret=0;
867
+
868
+ if (!parse_date_basic(date, &timestamp, &offset)) {
869
+ *out = timestamp;
870
+ return 0;
871
+ }
872
+
873
+ p_gettimeofday(&tv, NULL);
874
+ *out = approxidate_str(date, &tv, &error_ret);
875
+ return error_ret;
876
+ }