rugged 0.17.0b2 → 0.17.0.b6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (374) hide show
  1. data/Rakefile +10 -11
  2. data/ext/rugged/extconf.rb +5 -13
  3. data/ext/rugged/rugged_commit.c +2 -5
  4. data/ext/rugged/rugged_reference.c +29 -28
  5. data/ext/rugged/rugged_remote.c +1 -1
  6. data/ext/rugged/rugged_repo.c +4 -1
  7. data/ext/rugged/rugged_tree.c +20 -19
  8. data/lib/rugged/commit.rb +5 -1
  9. data/lib/rugged/repository.rb +6 -4
  10. data/lib/rugged/version.rb +1 -1
  11. data/test/config_test.rb +1 -1
  12. data/test/index_test.rb +4 -2
  13. data/test/object_test.rb +3 -3
  14. data/test/reference_test.rb +66 -1
  15. data/test/repo_test.rb +4 -4
  16. data/test/tree_test.rb +1 -1
  17. data/test/walker_test.rb +1 -1
  18. data/vendor/libgit2/Makefile.embed +42 -0
  19. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/deps/http-parser/http_parser.c +0 -0
  20. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/deps/http-parser/http_parser.h +0 -0
  21. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/deps/regex/config.h +0 -0
  22. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/deps/regex/regcomp.c +0 -0
  23. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/deps/regex/regex.c +0 -0
  24. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/deps/regex/regex.h +0 -0
  25. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/deps/regex/regex_internal.c +0 -0
  26. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/deps/regex/regex_internal.h +0 -0
  27. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/deps/regex/regexec.c +0 -0
  28. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/deps/zlib/adler32.c +0 -0
  29. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/deps/zlib/crc32.c +0 -0
  30. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/deps/zlib/crc32.h +0 -0
  31. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/deps/zlib/deflate.c +0 -0
  32. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/deps/zlib/deflate.h +0 -0
  33. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/deps/zlib/inffast.c +0 -0
  34. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/deps/zlib/inffast.h +0 -0
  35. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/deps/zlib/inffixed.h +0 -0
  36. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/deps/zlib/inflate.c +0 -0
  37. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/deps/zlib/inflate.h +0 -0
  38. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/deps/zlib/inftrees.c +0 -0
  39. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/deps/zlib/inftrees.h +0 -0
  40. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/deps/zlib/trees.c +0 -0
  41. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/deps/zlib/trees.h +0 -0
  42. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/deps/zlib/zconf.h +0 -0
  43. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/deps/zlib/zlib.h +0 -0
  44. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/deps/zlib/zutil.c +0 -0
  45. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/deps/zlib/zutil.h +0 -0
  46. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/include/git2.h +6 -0
  47. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/include/git2/attr.h +35 -20
  48. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/include/git2/blob.h +1 -1
  49. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/include/git2/branch.h +62 -24
  50. data/vendor/libgit2/include/git2/checkout.h +66 -0
  51. data/vendor/libgit2/include/git2/clone.h +59 -0
  52. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/include/git2/commit.h +22 -3
  53. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/include/git2/common.h +27 -0
  54. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/include/git2/config.h +22 -4
  55. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/include/git2/diff.h +20 -1
  56. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/include/git2/errors.h +2 -37
  57. data/vendor/libgit2/include/git2/ignore.h +74 -0
  58. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/include/git2/index.h +37 -5
  59. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/include/git2/indexer.h +2 -2
  60. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/include/git2/inttypes.h +0 -0
  61. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/include/git2/merge.h +10 -0
  62. data/vendor/libgit2/include/git2/message.h +43 -0
  63. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/include/git2/net.h +0 -0
  64. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/include/git2/notes.h +24 -20
  65. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/include/git2/object.h +18 -1
  66. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/include/git2/odb.h +16 -1
  67. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/include/git2/odb_backend.h +8 -1
  68. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/include/git2/oid.h +26 -2
  69. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/include/git2/reflog.h +39 -9
  70. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/include/git2/refs.h +55 -3
  71. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/include/git2/refspec.h +0 -0
  72. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/include/git2/remote.h +68 -2
  73. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/include/git2/repository.h +39 -1
  74. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/include/git2/reset.h +0 -0
  75. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/include/git2/revparse.h +0 -0
  76. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/include/git2/revwalk.h +2 -2
  77. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/include/git2/signature.h +3 -0
  78. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/include/git2/status.h +5 -2
  79. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/include/git2/stdint.h +0 -0
  80. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/include/git2/submodule.h +0 -0
  81. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/include/git2/tag.h +3 -3
  82. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/include/git2/threads.h +0 -0
  83. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/include/git2/tree.h +77 -20
  84. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/include/git2/types.h +14 -0
  85. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/include/git2/version.h +0 -0
  86. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/include/git2/windows.h +0 -0
  87. data/vendor/libgit2/src/amiga/map.c +51 -0
  88. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/attr.c +39 -6
  89. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/attr.h +1 -0
  90. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/attr_file.c +2 -16
  91. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/attr_file.h +4 -0
  92. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/blob.c +0 -0
  93. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/blob.h +0 -0
  94. data/vendor/libgit2/src/branch.c +294 -0
  95. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/bswap.h +0 -0
  96. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/buffer.c +40 -0
  97. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/buffer.h +22 -0
  98. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/cache.c +1 -0
  99. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/cache.h +0 -0
  100. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/cc-compat.h +0 -0
  101. data/vendor/libgit2/src/checkout.c +230 -0
  102. data/vendor/libgit2/src/clone.c +254 -0
  103. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/commit.c +42 -16
  104. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/commit.h +0 -0
  105. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/common.h +3 -9
  106. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/compat/fnmatch.c +0 -0
  107. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/compat/fnmatch.h +0 -0
  108. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/config.c +15 -5
  109. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/config.h +0 -0
  110. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/config_cache.c +0 -0
  111. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/config_file.c +86 -19
  112. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/config_file.h +16 -1
  113. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/crlf.c +92 -4
  114. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/date.c +20 -20
  115. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/delta-apply.c +0 -0
  116. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/delta-apply.h +0 -0
  117. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/diff.c +45 -18
  118. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/diff.h +0 -0
  119. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/diff_output.c +63 -46
  120. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/errors.c +0 -0
  121. data/vendor/libgit2/src/fetch.c +380 -0
  122. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/fetch.h +1 -2
  123. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/filebuf.c +7 -2
  124. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/filebuf.h +0 -0
  125. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/fileops.c +16 -1
  126. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/fileops.h +10 -0
  127. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/filter.c +38 -2
  128. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/filter.h +15 -0
  129. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/global.c +5 -0
  130. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/global.h +2 -6
  131. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/hash.c +0 -0
  132. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/hash.h +0 -0
  133. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/ignore.c +50 -1
  134. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/ignore.h +0 -0
  135. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/index.c +95 -28
  136. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/index.h +5 -0
  137. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/indexer.c +27 -25
  138. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/iterator.c +0 -0
  139. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/iterator.h +0 -0
  140. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/khash.h +6 -4
  141. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/map.h +4 -0
  142. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/message.c +27 -2
  143. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/message.h +2 -1
  144. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/mwindow.c +54 -10
  145. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/mwindow.h +1 -1
  146. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/netops.c +48 -38
  147. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/netops.h +7 -4
  148. data/vendor/libgit2/src/notes.c +610 -0
  149. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/notes.h +0 -0
  150. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/object.c +73 -2
  151. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/odb.c +20 -1
  152. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/odb.h +0 -0
  153. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/odb_loose.c +89 -3
  154. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/odb_pack.c +61 -3
  155. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/oid.c +1 -6
  156. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/oidmap.h +1 -6
  157. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/pack.c +49 -4
  158. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/pack.h +5 -1
  159. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/path.c +144 -21
  160. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/path.h +46 -0
  161. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/pkt.c +30 -8
  162. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/pkt.h +0 -0
  163. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/pool.c +7 -0
  164. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/pool.h +7 -0
  165. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/posix.c +92 -1
  166. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/posix.h +36 -1
  167. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/ppc/sha1.c +0 -0
  168. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/ppc/sha1.h +0 -0
  169. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/pqueue.c +0 -0
  170. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/pqueue.h +0 -0
  171. data/vendor/libgit2/src/protocol.c +88 -0
  172. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/protocol.h +3 -9
  173. data/vendor/libgit2/src/reflog.c +489 -0
  174. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/reflog.h +3 -0
  175. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/refs.c +95 -52
  176. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/refs.h +0 -0
  177. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/refspec.c +0 -0
  178. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/refspec.h +0 -0
  179. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/remote.c +130 -8
  180. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/remote.h +6 -0
  181. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/repository.c +167 -42
  182. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/repository.h +7 -0
  183. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/reset.c +1 -1
  184. data/vendor/libgit2/src/revparse.c +830 -0
  185. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/revwalk.c +83 -15
  186. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/sha1.c +0 -0
  187. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/sha1.h +5 -0
  188. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/sha1_lookup.c +0 -0
  189. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/sha1_lookup.h +0 -0
  190. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/signature.c +19 -5
  191. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/signature.h +0 -0
  192. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/status.c +24 -18
  193. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/strmap.h +1 -1
  194. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/submodule.c +3 -3
  195. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/tag.c +2 -9
  196. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/tag.h +0 -0
  197. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/thread-utils.c +0 -0
  198. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/thread-utils.h +0 -0
  199. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/transport.c +0 -0
  200. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/transport.h +13 -9
  201. data/vendor/libgit2/src/transports/git.c +245 -0
  202. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/transports/http.c +93 -336
  203. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/transports/local.c +35 -32
  204. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/tree-cache.c +0 -0
  205. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/tree-cache.h +0 -0
  206. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/tree.c +214 -124
  207. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/tree.h +7 -3
  208. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/tsort.c +0 -0
  209. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/unix/map.c +2 -0
  210. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/unix/posix.h +2 -1
  211. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/util.c +30 -0
  212. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/util.h +13 -6
  213. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/vector.c +1 -1
  214. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/vector.h +5 -5
  215. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/win32/dir.c +0 -0
  216. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/win32/dir.h +0 -0
  217. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/win32/map.c +0 -0
  218. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/win32/mingw-compat.h +0 -0
  219. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/win32/msvc-compat.h +0 -0
  220. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/win32/posix.h +1 -0
  221. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/win32/posix_w32.c +17 -1
  222. data/vendor/libgit2/src/win32/precompiled.c +1 -0
  223. data/vendor/libgit2/src/win32/precompiled.h +19 -0
  224. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/win32/pthread.c +0 -0
  225. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/win32/pthread.h +0 -0
  226. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/win32/utf-conv.c +0 -0
  227. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/win32/utf-conv.h +0 -0
  228. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/xdiff/xdiff.h +0 -0
  229. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/xdiff/xdiffi.c +0 -0
  230. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/xdiff/xdiffi.h +0 -0
  231. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/xdiff/xemit.c +0 -0
  232. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/xdiff/xemit.h +0 -0
  233. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/xdiff/xhistogram.c +0 -0
  234. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/xdiff/xinclude.h +0 -0
  235. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/xdiff/xmacros.h +0 -0
  236. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/xdiff/xmerge.c +0 -0
  237. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/xdiff/xpatience.c +0 -0
  238. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/xdiff/xprepare.c +0 -0
  239. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/xdiff/xprepare.h +0 -0
  240. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/xdiff/xtypes.h +0 -0
  241. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/xdiff/xutils.c +0 -0
  242. data/{ext/rugged/vendor/libgit2-dist → vendor/libgit2}/src/xdiff/xutils.h +0 -0
  243. metadata +265 -348
  244. data/ext/rugged/vendor/libgit2-dist.tar.gz +0 -0
  245. data/ext/rugged/vendor/libgit2-dist/examples/diff.c +0 -238
  246. data/ext/rugged/vendor/libgit2-dist/examples/general.c +0 -451
  247. data/ext/rugged/vendor/libgit2-dist/examples/network/common.h +0 -14
  248. data/ext/rugged/vendor/libgit2-dist/examples/network/fetch.c +0 -113
  249. data/ext/rugged/vendor/libgit2-dist/examples/network/git2.c +0 -62
  250. data/ext/rugged/vendor/libgit2-dist/examples/network/index-pack.c +0 -102
  251. data/ext/rugged/vendor/libgit2-dist/examples/network/ls-remote.c +0 -76
  252. data/ext/rugged/vendor/libgit2-dist/examples/showindex.c +0 -43
  253. data/ext/rugged/vendor/libgit2-dist/src/branch.c +0 -208
  254. data/ext/rugged/vendor/libgit2-dist/src/branch.h +0 -17
  255. data/ext/rugged/vendor/libgit2-dist/src/fetch.c +0 -200
  256. data/ext/rugged/vendor/libgit2-dist/src/notes.c +0 -548
  257. data/ext/rugged/vendor/libgit2-dist/src/protocol.c +0 -58
  258. data/ext/rugged/vendor/libgit2-dist/src/reflog.c +0 -340
  259. data/ext/rugged/vendor/libgit2-dist/src/revparse.c +0 -748
  260. data/ext/rugged/vendor/libgit2-dist/src/transports/git.c +0 -477
  261. data/ext/rugged/vendor/libgit2-dist/tests-clar/attr/attr_expect.h +0 -43
  262. data/ext/rugged/vendor/libgit2-dist/tests-clar/attr/file.c +0 -226
  263. data/ext/rugged/vendor/libgit2-dist/tests-clar/attr/flags.c +0 -108
  264. data/ext/rugged/vendor/libgit2-dist/tests-clar/attr/lookup.c +0 -262
  265. data/ext/rugged/vendor/libgit2-dist/tests-clar/attr/repo.c +0 -273
  266. data/ext/rugged/vendor/libgit2-dist/tests-clar/buf/basic.c +0 -29
  267. data/ext/rugged/vendor/libgit2-dist/tests-clar/clar_helpers.c +0 -181
  268. data/ext/rugged/vendor/libgit2-dist/tests-clar/clar_libgit2.h +0 -55
  269. data/ext/rugged/vendor/libgit2-dist/tests-clar/commit/commit.c +0 -44
  270. data/ext/rugged/vendor/libgit2-dist/tests-clar/commit/parse.c +0 -350
  271. data/ext/rugged/vendor/libgit2-dist/tests-clar/commit/signature.c +0 -65
  272. data/ext/rugged/vendor/libgit2-dist/tests-clar/commit/write.c +0 -140
  273. data/ext/rugged/vendor/libgit2-dist/tests-clar/config/add.c +0 -37
  274. data/ext/rugged/vendor/libgit2-dist/tests-clar/config/multivar.c +0 -151
  275. data/ext/rugged/vendor/libgit2-dist/tests-clar/config/new.c +0 -36
  276. data/ext/rugged/vendor/libgit2-dist/tests-clar/config/read.c +0 -221
  277. data/ext/rugged/vendor/libgit2-dist/tests-clar/config/stress.c +0 -61
  278. data/ext/rugged/vendor/libgit2-dist/tests-clar/config/write.c +0 -92
  279. data/ext/rugged/vendor/libgit2-dist/tests-clar/core/buffer.c +0 -613
  280. data/ext/rugged/vendor/libgit2-dist/tests-clar/core/dirent.c +0 -235
  281. data/ext/rugged/vendor/libgit2-dist/tests-clar/core/env.c +0 -115
  282. data/ext/rugged/vendor/libgit2-dist/tests-clar/core/errors.c +0 -60
  283. data/ext/rugged/vendor/libgit2-dist/tests-clar/core/filebuf.c +0 -92
  284. data/ext/rugged/vendor/libgit2-dist/tests-clar/core/hex.c +0 -22
  285. data/ext/rugged/vendor/libgit2-dist/tests-clar/core/oid.c +0 -18
  286. data/ext/rugged/vendor/libgit2-dist/tests-clar/core/path.c +0 -420
  287. data/ext/rugged/vendor/libgit2-dist/tests-clar/core/pool.c +0 -85
  288. data/ext/rugged/vendor/libgit2-dist/tests-clar/core/rmdir.c +0 -68
  289. data/ext/rugged/vendor/libgit2-dist/tests-clar/core/string.c +0 -28
  290. data/ext/rugged/vendor/libgit2-dist/tests-clar/core/strmap.c +0 -102
  291. data/ext/rugged/vendor/libgit2-dist/tests-clar/core/strtol.c +0 -37
  292. data/ext/rugged/vendor/libgit2-dist/tests-clar/core/vector.c +0 -191
  293. data/ext/rugged/vendor/libgit2-dist/tests-clar/date/date.c +0 -15
  294. data/ext/rugged/vendor/libgit2-dist/tests-clar/diff/blob.c +0 -254
  295. data/ext/rugged/vendor/libgit2-dist/tests-clar/diff/diff_helpers.c +0 -104
  296. data/ext/rugged/vendor/libgit2-dist/tests-clar/diff/diff_helpers.h +0 -47
  297. data/ext/rugged/vendor/libgit2-dist/tests-clar/diff/index.c +0 -92
  298. data/ext/rugged/vendor/libgit2-dist/tests-clar/diff/iterator.c +0 -572
  299. data/ext/rugged/vendor/libgit2-dist/tests-clar/diff/patch.c +0 -99
  300. data/ext/rugged/vendor/libgit2-dist/tests-clar/diff/tree.c +0 -210
  301. data/ext/rugged/vendor/libgit2-dist/tests-clar/diff/workdir.c +0 -543
  302. data/ext/rugged/vendor/libgit2-dist/tests-clar/index/read_tree.c +0 -46
  303. data/ext/rugged/vendor/libgit2-dist/tests-clar/index/rename.c +0 -50
  304. data/ext/rugged/vendor/libgit2-dist/tests-clar/index/tests.c +0 -246
  305. data/ext/rugged/vendor/libgit2-dist/tests-clar/network/createremotethenload.c +0 -33
  306. data/ext/rugged/vendor/libgit2-dist/tests-clar/network/remotelocal.c +0 -137
  307. data/ext/rugged/vendor/libgit2-dist/tests-clar/network/remotes.c +0 -183
  308. data/ext/rugged/vendor/libgit2-dist/tests-clar/notes/notes.c +0 -133
  309. data/ext/rugged/vendor/libgit2-dist/tests-clar/notes/notesref.c +0 -57
  310. data/ext/rugged/vendor/libgit2-dist/tests-clar/object/blob/filter.c +0 -125
  311. data/ext/rugged/vendor/libgit2-dist/tests-clar/object/blob/fromchunks.c +0 -87
  312. data/ext/rugged/vendor/libgit2-dist/tests-clar/object/blob/write.c +0 -69
  313. data/ext/rugged/vendor/libgit2-dist/tests-clar/object/commit/commitstagedfile.c +0 -126
  314. data/ext/rugged/vendor/libgit2-dist/tests-clar/object/lookup.c +0 -63
  315. data/ext/rugged/vendor/libgit2-dist/tests-clar/object/message.c +0 -171
  316. data/ext/rugged/vendor/libgit2-dist/tests-clar/object/raw/chars.c +0 -41
  317. data/ext/rugged/vendor/libgit2-dist/tests-clar/object/raw/compare.c +0 -124
  318. data/ext/rugged/vendor/libgit2-dist/tests-clar/object/raw/convert.c +0 -75
  319. data/ext/rugged/vendor/libgit2-dist/tests-clar/object/raw/data.h +0 -323
  320. data/ext/rugged/vendor/libgit2-dist/tests-clar/object/raw/fromstr.c +0 -30
  321. data/ext/rugged/vendor/libgit2-dist/tests-clar/object/raw/hash.c +0 -166
  322. data/ext/rugged/vendor/libgit2-dist/tests-clar/object/raw/short.c +0 -94
  323. data/ext/rugged/vendor/libgit2-dist/tests-clar/object/raw/size.c +0 -13
  324. data/ext/rugged/vendor/libgit2-dist/tests-clar/object/raw/type2string.c +0 -54
  325. data/ext/rugged/vendor/libgit2-dist/tests-clar/object/raw/write.c +0 -455
  326. data/ext/rugged/vendor/libgit2-dist/tests-clar/object/tag/peel.c +0 -56
  327. data/ext/rugged/vendor/libgit2-dist/tests-clar/object/tag/read.c +0 -130
  328. data/ext/rugged/vendor/libgit2-dist/tests-clar/object/tag/write.c +0 -192
  329. data/ext/rugged/vendor/libgit2-dist/tests-clar/object/tree/frompath.c +0 -81
  330. data/ext/rugged/vendor/libgit2-dist/tests-clar/object/tree/read.c +0 -75
  331. data/ext/rugged/vendor/libgit2-dist/tests-clar/object/tree/write.c +0 -84
  332. data/ext/rugged/vendor/libgit2-dist/tests-clar/odb/loose.c +0 -84
  333. data/ext/rugged/vendor/libgit2-dist/tests-clar/odb/loose_data.h +0 -522
  334. data/ext/rugged/vendor/libgit2-dist/tests-clar/odb/mixed.c +0 -24
  335. data/ext/rugged/vendor/libgit2-dist/tests-clar/odb/pack_data.h +0 -151
  336. data/ext/rugged/vendor/libgit2-dist/tests-clar/odb/packed.c +0 -78
  337. data/ext/rugged/vendor/libgit2-dist/tests-clar/odb/sorting.c +0 -71
  338. data/ext/rugged/vendor/libgit2-dist/tests-clar/refs/branches/create.c +0 -113
  339. data/ext/rugged/vendor/libgit2-dist/tests-clar/refs/branches/delete.c +0 -91
  340. data/ext/rugged/vendor/libgit2-dist/tests-clar/refs/branches/listall.c +0 -78
  341. data/ext/rugged/vendor/libgit2-dist/tests-clar/refs/branches/move.c +0 -72
  342. data/ext/rugged/vendor/libgit2-dist/tests-clar/refs/crashes.c +0 -17
  343. data/ext/rugged/vendor/libgit2-dist/tests-clar/refs/create.c +0 -149
  344. data/ext/rugged/vendor/libgit2-dist/tests-clar/refs/delete.c +0 -85
  345. data/ext/rugged/vendor/libgit2-dist/tests-clar/refs/list.c +0 -53
  346. data/ext/rugged/vendor/libgit2-dist/tests-clar/refs/listall.c +0 -36
  347. data/ext/rugged/vendor/libgit2-dist/tests-clar/refs/lookup.c +0 -42
  348. data/ext/rugged/vendor/libgit2-dist/tests-clar/refs/normalize.c +0 -200
  349. data/ext/rugged/vendor/libgit2-dist/tests-clar/refs/overwrite.c +0 -136
  350. data/ext/rugged/vendor/libgit2-dist/tests-clar/refs/pack.c +0 -67
  351. data/ext/rugged/vendor/libgit2-dist/tests-clar/refs/read.c +0 -194
  352. data/ext/rugged/vendor/libgit2-dist/tests-clar/refs/reflog.c +0 -123
  353. data/ext/rugged/vendor/libgit2-dist/tests-clar/refs/rename.c +0 -339
  354. data/ext/rugged/vendor/libgit2-dist/tests-clar/refs/revparse.c +0 -174
  355. data/ext/rugged/vendor/libgit2-dist/tests-clar/refs/unicode.c +0 -42
  356. data/ext/rugged/vendor/libgit2-dist/tests-clar/repo/discover.c +0 -142
  357. data/ext/rugged/vendor/libgit2-dist/tests-clar/repo/getters.c +0 -86
  358. data/ext/rugged/vendor/libgit2-dist/tests-clar/repo/init.c +0 -249
  359. data/ext/rugged/vendor/libgit2-dist/tests-clar/repo/open.c +0 -282
  360. data/ext/rugged/vendor/libgit2-dist/tests-clar/repo/setters.c +0 -80
  361. data/ext/rugged/vendor/libgit2-dist/tests-clar/reset/mixed.c +0 -47
  362. data/ext/rugged/vendor/libgit2-dist/tests-clar/reset/reset_helpers.c +0 -10
  363. data/ext/rugged/vendor/libgit2-dist/tests-clar/reset/reset_helpers.h +0 -6
  364. data/ext/rugged/vendor/libgit2-dist/tests-clar/reset/soft.c +0 -102
  365. data/ext/rugged/vendor/libgit2-dist/tests-clar/revwalk/basic.c +0 -181
  366. data/ext/rugged/vendor/libgit2-dist/tests-clar/revwalk/mergebase.c +0 -148
  367. data/ext/rugged/vendor/libgit2-dist/tests-clar/status/ignore.c +0 -147
  368. data/ext/rugged/vendor/libgit2-dist/tests-clar/status/single.c +0 -29
  369. data/ext/rugged/vendor/libgit2-dist/tests-clar/status/status_data.h +0 -202
  370. data/ext/rugged/vendor/libgit2-dist/tests-clar/status/status_helpers.c +0 -49
  371. data/ext/rugged/vendor/libgit2-dist/tests-clar/status/status_helpers.h +0 -33
  372. data/ext/rugged/vendor/libgit2-dist/tests-clar/status/submodules.c +0 -112
  373. data/ext/rugged/vendor/libgit2-dist/tests-clar/status/worktree.c +0 -649
  374. data/ext/rugged/vendor/libgit2-dist/tests-clar/threads/basic.c +0 -20
@@ -7,6 +7,8 @@
7
7
  #ifndef INCLUDE_remote_h__
8
8
  #define INCLUDE_remote_h__
9
9
 
10
+ #include "git2/remote.h"
11
+
10
12
  #include "refspec.h"
11
13
  #include "transport.h"
12
14
  #include "repository.h"
@@ -14,13 +16,17 @@
14
16
  struct git_remote {
15
17
  char *name;
16
18
  char *url;
19
+ char *pushurl;
17
20
  git_vector refs;
18
21
  struct git_refspec fetch;
19
22
  struct git_refspec push;
20
23
  git_transport *transport;
21
24
  git_repository *repo;
25
+ git_remote_callbacks callbacks;
22
26
  unsigned int need_pack:1,
23
27
  check_cert;
24
28
  };
25
29
 
30
+ const char* git_remote__urlfordirection(struct git_remote *remote, int direction);
31
+
26
32
  #endif
@@ -388,6 +388,19 @@ int git_repository_open(git_repository **repo_out, const char *path)
388
388
  repo_out, path, GIT_REPOSITORY_OPEN_NO_SEARCH, NULL);
389
389
  }
390
390
 
391
+ int git_repository_wrap_odb(git_repository **repo_out, git_odb *odb)
392
+ {
393
+ git_repository *repo;
394
+
395
+ repo = repository_alloc();
396
+ GITERR_CHECK_ALLOC(repo);
397
+
398
+ git_repository_set_odb(repo, odb);
399
+ *repo_out = repo;
400
+
401
+ return 0;
402
+ }
403
+
391
404
  int git_repository_discover(
392
405
  char *repository_path,
393
406
  size_t size,
@@ -573,6 +586,9 @@ int git_repository_index__weakptr(git_index **out, git_repository *repo)
573
586
  return -1;
574
587
 
575
588
  GIT_REFCOUNT_OWN(repo->_index, repo);
589
+
590
+ if (git_index_set_caps(repo->_index, GIT_INDEXCAP_FROM_OWNER) < 0)
591
+ return -1;
576
592
  }
577
593
 
578
594
  *out = repo->_index;
@@ -599,14 +615,10 @@ void git_repository_set_index(git_repository *repo, git_index *index)
599
615
  GIT_REFCOUNT_INC(index);
600
616
  }
601
617
 
602
- static int check_repositoryformatversion(git_repository *repo)
618
+ static int check_repositoryformatversion(git_config *config)
603
619
  {
604
- git_config *config;
605
620
  int version;
606
621
 
607
- if (git_repository_config__weakptr(&config, repo) < 0)
608
- return -1;
609
-
610
622
  if (git_config_get_int32(&version, config, "core.repositoryformatversion") < 0)
611
623
  return -1;
612
624
 
@@ -620,26 +632,6 @@ static int check_repositoryformatversion(git_repository *repo)
620
632
  return 0;
621
633
  }
622
634
 
623
- static int repo_init_reinit(git_repository **repo_out, const char *repository_path, int is_bare)
624
- {
625
- git_repository *repo = NULL;
626
-
627
- GIT_UNUSED(is_bare);
628
-
629
- if (git_repository_open(&repo, repository_path) < 0)
630
- return -1;
631
-
632
- if (check_repositoryformatversion(repo) < 0) {
633
- git_repository_free(repo);
634
- return -1;
635
- }
636
-
637
- /* TODO: reinitialize the templates */
638
-
639
- *repo_out = repo;
640
- return 0;
641
- }
642
-
643
635
  static int repo_init_createhead(const char *git_dir)
644
636
  {
645
637
  git_buf ref_path = GIT_BUF_INIT;
@@ -714,6 +706,12 @@ static int repo_init_config(const char *git_dir, bool is_bare, bool is_reinit)
714
706
  return -1;
715
707
  }
716
708
 
709
+ if (is_reinit && check_repositoryformatversion(config) < 0) {
710
+ git_buf_free(&cfg_path);
711
+ git_config_free(config);
712
+ return -1;
713
+ }
714
+
717
715
  SET_REPO_CONFIG(bool, "core.bare", is_bare);
718
716
  SET_REPO_CONFIG(int32, "core.repositoryformatversion", GIT_REPO_VERSION);
719
717
  SET_REPO_CONFIG(bool, "core.filemode", is_chmod_supported(git_buf_cstr(&cfg_path)));
@@ -756,15 +754,24 @@ static int repo_init_config(const char *git_dir, bool is_bare, bool is_reinit)
756
754
  #define GIT_DESC_CONTENT "Unnamed repository; edit this file 'description' to name the repository.\n"
757
755
 
758
756
  static int repo_write_template(
759
- const char *git_dir, const char *file, mode_t mode, const char *content)
757
+ const char *git_dir,
758
+ bool allow_overwrite,
759
+ const char *file,
760
+ mode_t mode,
761
+ const char *content)
760
762
  {
761
763
  git_buf path = GIT_BUF_INIT;
762
- int fd, error = 0;
764
+ int fd, error = 0, flags;
763
765
 
764
766
  if (git_buf_joinpath(&path, git_dir, file) < 0)
765
767
  return -1;
766
768
 
767
- fd = p_open(git_buf_cstr(&path), O_WRONLY | O_CREAT | O_EXCL, mode);
769
+ if (allow_overwrite)
770
+ flags = O_WRONLY | O_CREAT | O_TRUNC;
771
+ else
772
+ flags = O_WRONLY | O_CREAT | O_EXCL;
773
+
774
+ fd = p_open(git_buf_cstr(&path), flags, mode);
768
775
 
769
776
  if (fd >= 0) {
770
777
  error = p_write(fd, content, strlen(content));
@@ -826,7 +833,7 @@ static int repo_init_structure(const char *git_dir, int is_bare)
826
833
  /* Make template files as needed */
827
834
  for (i = 0; tmpl[i].file != NULL; ++i) {
828
835
  if (repo_write_template(
829
- git_dir, tmpl[i].file, tmpl[i].mode, tmpl[i].content) < 0)
836
+ git_dir, false, tmpl[i].file, tmpl[i].mode, tmpl[i].content) < 0)
830
837
  return -1;
831
838
  }
832
839
 
@@ -847,20 +854,18 @@ int git_repository_init(git_repository **repo_out, const char *path, unsigned is
847
854
  is_reinit = git_path_isdir(repository_path.ptr) && valid_repository_path(&repository_path);
848
855
 
849
856
  if (is_reinit) {
850
- if (repo_init_reinit(repo_out, repository_path.ptr, is_bare) < 0)
851
- goto cleanup;
857
+ /* TODO: reinitialize the templates */
852
858
 
853
- result = repo_init_config(repository_path.ptr, is_bare, is_reinit);
854
- }
859
+ if (repo_init_config(repository_path.ptr, is_bare, is_reinit) < 0)
860
+ goto cleanup;
855
861
 
856
- if (repo_init_structure(repository_path.ptr, is_bare) < 0 ||
862
+ } else if (repo_init_structure(repository_path.ptr, is_bare) < 0 ||
857
863
  repo_init_config(repository_path.ptr, is_bare, is_reinit) < 0 ||
858
- repo_init_createhead(repository_path.ptr) < 0 ||
859
- git_repository_open(repo_out, repository_path.ptr) < 0) {
864
+ repo_init_createhead(repository_path.ptr) < 0) {
860
865
  goto cleanup;
861
866
  }
862
867
 
863
- result = 0;
868
+ result = git_repository_open(repo_out, repository_path.ptr);
864
869
 
865
870
  cleanup:
866
871
  git_buf_free(&repository_path);
@@ -960,8 +965,47 @@ const char *git_repository_workdir(git_repository *repo)
960
965
  return repo->workdir;
961
966
  }
962
967
 
963
- int git_repository_set_workdir(git_repository *repo, const char *workdir)
968
+ static int write_gitlink(
969
+ const char *in_dir, const char *to_repo)
970
+ {
971
+ int error;
972
+ git_buf buf = GIT_BUF_INIT;
973
+ struct stat st;
974
+
975
+ if (git_path_dirname_r(&buf, to_repo) < 0 ||
976
+ git_path_to_dir(&buf) < 0)
977
+ return -1;
978
+
979
+ /* don't write gitlink to natural workdir */
980
+ if (git__suffixcmp(to_repo, "/" DOT_GIT "/") == 0 &&
981
+ strcmp(in_dir, buf.ptr) == 0)
982
+ return GIT_PASSTHROUGH;
983
+
984
+ if (git_buf_joinpath(&buf, in_dir, DOT_GIT) < 0)
985
+ return -1;
986
+
987
+ if (!p_stat(buf.ptr, &st) && !S_ISREG(st.st_mode)) {
988
+ giterr_set(GITERR_REPOSITORY,
989
+ "Cannot overwrite gitlink file into path '%s'", in_dir);
990
+ return GIT_EEXISTS;
991
+ }
992
+
993
+ git_buf_clear(&buf);
994
+
995
+ if (git_buf_printf(&buf, "%s %s", GIT_FILE_CONTENT_PREFIX, to_repo) < 0)
996
+ return -1;
997
+
998
+ error = repo_write_template(in_dir, true, DOT_GIT, 0644, buf.ptr);
999
+
1000
+ git_buf_free(&buf);
1001
+
1002
+ return error;
1003
+ }
1004
+
1005
+ int git_repository_set_workdir(
1006
+ git_repository *repo, const char *workdir, int update_gitlink)
964
1007
  {
1008
+ int error = 0;
965
1009
  git_buf path = GIT_BUF_INIT;
966
1010
 
967
1011
  assert(repo && workdir);
@@ -969,11 +1013,37 @@ int git_repository_set_workdir(git_repository *repo, const char *workdir)
969
1013
  if (git_path_prettify_dir(&path, workdir, NULL) < 0)
970
1014
  return -1;
971
1015
 
972
- git__free(repo->workdir);
1016
+ if (repo->workdir && strcmp(repo->workdir, path.ptr) == 0)
1017
+ return 0;
973
1018
 
974
- repo->workdir = git_buf_detach(&path);
975
- repo->is_bare = 0;
976
- return 0;
1019
+ if (update_gitlink) {
1020
+ git_config *config;
1021
+
1022
+ if (git_repository_config__weakptr(&config, repo) < 0)
1023
+ return -1;
1024
+
1025
+ error = write_gitlink(path.ptr, git_repository_path(repo));
1026
+
1027
+ /* passthrough error means gitlink is unnecessary */
1028
+ if (error == GIT_PASSTHROUGH)
1029
+ error = git_config_delete(config, "core.worktree");
1030
+ else if (!error)
1031
+ error = git_config_set_string(config, "core.worktree", path.ptr);
1032
+
1033
+ if (!error)
1034
+ error = git_config_set_bool(config, "core.bare", false);
1035
+ }
1036
+
1037
+ if (!error) {
1038
+ char *old_workdir = repo->workdir;
1039
+
1040
+ repo->workdir = git_buf_detach(&path);
1041
+ repo->is_bare = 0;
1042
+
1043
+ git__free(old_workdir);
1044
+ }
1045
+
1046
+ return error;
977
1047
  }
978
1048
 
979
1049
  int git_repository_is_bare(git_repository *repo)
@@ -1001,3 +1071,58 @@ int git_repository_head_tree(git_tree **tree, git_repository *repo)
1001
1071
  *tree = (git_tree *)obj;
1002
1072
  return 0;
1003
1073
  }
1074
+
1075
+ #define MERGE_MSG_FILE "MERGE_MSG"
1076
+
1077
+ int git_repository_message(char *buffer, size_t len, git_repository *repo)
1078
+ {
1079
+ git_buf buf = GIT_BUF_INIT, path = GIT_BUF_INIT;
1080
+ struct stat st;
1081
+ ssize_t size;
1082
+ int error;
1083
+
1084
+ if (git_buf_joinpath(&path, repo->path_repository, MERGE_MSG_FILE) < 0)
1085
+ return -1;
1086
+
1087
+ error = p_stat(git_buf_cstr(&path), &st);
1088
+ if (error < 0) {
1089
+ if (errno == ENOENT)
1090
+ error = GIT_ENOTFOUND;
1091
+
1092
+ git_buf_free(&path);
1093
+ return error;
1094
+ }
1095
+
1096
+ if (buffer == NULL) {
1097
+ git_buf_free(&path);
1098
+ return (int)st.st_size;
1099
+ }
1100
+
1101
+ if (git_futils_readbuffer(&buf, git_buf_cstr(&path)) < 0)
1102
+ goto on_error;
1103
+
1104
+ memcpy(buffer, git_buf_cstr(&buf), len);
1105
+ size = git_buf_len(&buf);
1106
+
1107
+ git_buf_free(&path);
1108
+ git_buf_free(&buf);
1109
+ return size;
1110
+
1111
+ on_error:
1112
+ git_buf_free(&path);
1113
+ return -1;
1114
+ }
1115
+
1116
+ int git_repository_message_remove(git_repository *repo)
1117
+ {
1118
+ git_buf path = GIT_BUF_INIT;
1119
+ int error;
1120
+
1121
+ if (git_buf_joinpath(&path, repo->path_repository, MERGE_MSG_FILE) < 0)
1122
+ return -1;
1123
+
1124
+ error = p_unlink(git_buf_cstr(&path));
1125
+ git_buf_free(&path);
1126
+
1127
+ return error;
1128
+ }
@@ -98,6 +98,13 @@ struct git_repository {
98
98
  * export */
99
99
  void git_object__free(void *object);
100
100
 
101
+ GIT_INLINE(int) git_object__dup(git_object **dest, git_object *source)
102
+ {
103
+ git_cached_obj_incref(source);
104
+ *dest = source;
105
+ return 0;
106
+ }
107
+
101
108
  int git_object__resolve_to_type(git_object **obj, git_otype type);
102
109
 
103
110
  int git_oid__parse(git_oid *oid, const char **buffer_out, const char *buffer_end, const char *header);
@@ -80,7 +80,7 @@ int git_reset(
80
80
  goto cleanup;
81
81
  }
82
82
 
83
- if (git_index_read_tree(index, tree) < 0) {
83
+ if (git_index_read_tree(index, tree, NULL) < 0) {
84
84
  giterr_set(GITERR_INDEX, "%s - Failed to update the index.", ERROR_MSG);
85
85
  goto cleanup;
86
86
  }
@@ -0,0 +1,830 @@
1
+ /*
2
+ * Copyright (C) 2009-2012 the libgit2 contributors
3
+ *
4
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
5
+ * a Linking Exception. For full terms see the included COPYING file.
6
+ */
7
+
8
+ #include <assert.h>
9
+
10
+ #include "common.h"
11
+ #include "buffer.h"
12
+ #include "tree.h"
13
+
14
+ #include "git2.h"
15
+
16
+ static int revspec_error(const char *revspec)
17
+ {
18
+ giterr_set(GITERR_INVALID, "Failed to parse revision specifier - Invalid pattern '%s'", revspec);
19
+ return -1;
20
+ }
21
+
22
+ static int disambiguate_refname(git_reference **out, git_repository *repo, const char *refname)
23
+ {
24
+ int error, i;
25
+ bool fallbackmode = true;
26
+ git_reference *ref;
27
+ git_buf refnamebuf = GIT_BUF_INIT, name = GIT_BUF_INIT;
28
+
29
+ static const char* formatters[] = {
30
+ "%s",
31
+ "refs/%s",
32
+ "refs/tags/%s",
33
+ "refs/heads/%s",
34
+ "refs/remotes/%s",
35
+ "refs/remotes/%s/HEAD",
36
+ NULL
37
+ };
38
+
39
+ if (*refname)
40
+ git_buf_puts(&name, refname);
41
+ else {
42
+ git_buf_puts(&name, GIT_HEAD_FILE);
43
+ fallbackmode = false;
44
+ }
45
+
46
+ for (i = 0; formatters[i] && (fallbackmode || i == 0); i++) {
47
+
48
+ git_buf_clear(&refnamebuf);
49
+
50
+ if ((error = git_buf_printf(&refnamebuf, formatters[i], git_buf_cstr(&name))) < 0)
51
+ goto cleanup;
52
+
53
+ error = git_reference_lookup_resolved(&ref, repo, git_buf_cstr(&refnamebuf), -1);
54
+
55
+ if (!error) {
56
+ *out = ref;
57
+ error = 0;
58
+ goto cleanup;
59
+ }
60
+
61
+ if (error != GIT_ENOTFOUND)
62
+ goto cleanup;
63
+ }
64
+
65
+ cleanup:
66
+ git_buf_free(&name);
67
+ git_buf_free(&refnamebuf);
68
+ return error;
69
+ }
70
+
71
+ static int maybe_sha_or_abbrev(git_object**out, git_repository *repo, const char *spec)
72
+ {
73
+ git_oid oid;
74
+ size_t speclen = strlen(spec);
75
+
76
+ if (git_oid_fromstrn(&oid, spec, speclen) < 0)
77
+ return GIT_ENOTFOUND;
78
+
79
+ return git_object_lookup_prefix(out, repo, &oid, speclen, GIT_OBJ_ANY);
80
+ }
81
+
82
+ static int build_regex(regex_t *regex, const char *pattern)
83
+ {
84
+ int error;
85
+
86
+ if (*pattern == '\0') {
87
+ giterr_set(GITERR_REGEX, "Empty pattern");
88
+ return -1;
89
+ }
90
+
91
+ error = regcomp(regex, pattern, REG_EXTENDED);
92
+ if (!error)
93
+ return 0;
94
+
95
+ giterr_set_regex(regex, error);
96
+ regfree(regex);
97
+
98
+ return -1;
99
+ }
100
+
101
+ static int maybe_describe(git_object**out, git_repository *repo, const char *spec)
102
+ {
103
+ const char *substr;
104
+ int error;
105
+ regex_t regex;
106
+
107
+ substr = strstr(spec, "-g");
108
+
109
+ if (substr == NULL)
110
+ return GIT_ENOTFOUND;
111
+
112
+ if (build_regex(&regex, ".+-[0-9]+-g[0-9a-fA-F]+") < 0)
113
+ return -1;
114
+
115
+ error = regexec(&regex, spec, 0, NULL, 0);
116
+ regfree(&regex);
117
+
118
+ if (error)
119
+ return GIT_ENOTFOUND;
120
+
121
+ return maybe_sha_or_abbrev(out, repo, substr+2);
122
+ }
123
+
124
+ static int revparse_lookup_object(git_object **out, git_repository *repo, const char *spec)
125
+ {
126
+ int error;
127
+ git_reference *ref;
128
+
129
+ error = maybe_describe(out, repo, spec);
130
+ if (!error)
131
+ return 0;
132
+
133
+ if (error < 0 && error != GIT_ENOTFOUND)
134
+ return error;
135
+
136
+ error = disambiguate_refname(&ref, repo, spec);
137
+ if (!error) {
138
+ error = git_object_lookup(out, repo, git_reference_oid(ref), GIT_OBJ_ANY);
139
+ git_reference_free(ref);
140
+ return error;
141
+ }
142
+
143
+ if (error < 0 && error != GIT_ENOTFOUND)
144
+ return error;
145
+
146
+ error = maybe_sha_or_abbrev(out, repo, spec);
147
+ if (!error)
148
+ return 0;
149
+
150
+ if (error < 0 && error != GIT_ENOTFOUND)
151
+ return error;
152
+
153
+ giterr_set(GITERR_REFERENCE, "Refspec '%s' not found.", spec);
154
+ return GIT_ENOTFOUND;
155
+ }
156
+
157
+ static int try_parse_numeric(int *n, const char *curly_braces_content)
158
+ {
159
+ int content;
160
+ const char *end_ptr;
161
+
162
+ if (git__strtol32(&content, curly_braces_content, &end_ptr, 10) < 0)
163
+ return -1;
164
+
165
+ if (*end_ptr != '\0')
166
+ return -1;
167
+
168
+ *n = content;
169
+ return 0;
170
+ }
171
+
172
+ static int retrieve_previously_checked_out_branch_or_revision(git_object **out, git_reference **base_ref, git_repository *repo, const char *spec, const char *identifier, unsigned int position)
173
+ {
174
+ git_reference *ref = NULL;
175
+ git_reflog *reflog = NULL;
176
+ regex_t preg;
177
+ int numentries, i, cur, error = -1;
178
+ const git_reflog_entry *entry;
179
+ const char *msg;
180
+ regmatch_t regexmatches[2];
181
+ git_buf buf = GIT_BUF_INIT;
182
+
183
+ cur = position;
184
+
185
+ if (*identifier != '\0' || *base_ref != NULL)
186
+ return revspec_error(spec);
187
+
188
+ if (build_regex(&preg, "checkout: moving from (.*) to .*") < 0)
189
+ return -1;
190
+
191
+ if (git_reference_lookup(&ref, repo, GIT_HEAD_FILE) < 0)
192
+ goto cleanup;
193
+
194
+ if (git_reflog_read(&reflog, ref) < 0)
195
+ goto cleanup;
196
+
197
+ numentries = git_reflog_entrycount(reflog);
198
+
199
+ for (i = numentries - 1; i >= 0; i--) {
200
+ entry = git_reflog_entry_byindex(reflog, i);
201
+ msg = git_reflog_entry_msg(entry);
202
+
203
+ if (regexec(&preg, msg, 2, regexmatches, 0))
204
+ continue;
205
+
206
+ cur--;
207
+
208
+ if (cur > 0)
209
+ continue;
210
+
211
+ git_buf_put(&buf, msg+regexmatches[1].rm_so, regexmatches[1].rm_eo - regexmatches[1].rm_so);
212
+
213
+ if ((error = disambiguate_refname(base_ref, repo, git_buf_cstr(&buf))) == 0)
214
+ goto cleanup;
215
+
216
+ if (error < 0 && error != GIT_ENOTFOUND)
217
+ goto cleanup;
218
+
219
+ error = maybe_sha_or_abbrev(out, repo, git_buf_cstr(&buf));
220
+
221
+ goto cleanup;
222
+ }
223
+
224
+ error = GIT_ENOTFOUND;
225
+
226
+ cleanup:
227
+ git_reference_free(ref);
228
+ git_buf_free(&buf);
229
+ regfree(&preg);
230
+ git_reflog_free(reflog);
231
+ return error;
232
+ }
233
+
234
+ static int retrieve_oid_from_reflog(git_oid *oid, git_reference *ref, unsigned int identifier)
235
+ {
236
+ git_reflog *reflog;
237
+ int error = -1;
238
+ unsigned int numentries;
239
+ const git_reflog_entry *entry;
240
+ bool search_by_pos = (identifier <= 100000000);
241
+
242
+ if (git_reflog_read(&reflog, ref) < 0)
243
+ return -1;
244
+
245
+ numentries = git_reflog_entrycount(reflog);
246
+
247
+ if (search_by_pos) {
248
+ if (numentries < identifier + 1) {
249
+ giterr_set(
250
+ GITERR_REFERENCE,
251
+ "Reflog for '%s' has only %d entries, asked for %d",
252
+ git_reference_name(ref),
253
+ numentries,
254
+ identifier);
255
+
256
+ error = GIT_ENOTFOUND;
257
+ goto cleanup;
258
+ }
259
+
260
+ entry = git_reflog_entry_byindex(reflog, identifier);
261
+ git_oid_cpy(oid, git_reflog_entry_oidold(entry));
262
+ error = 0;
263
+ goto cleanup;
264
+
265
+ } else {
266
+ int i;
267
+ git_time commit_time;
268
+
269
+ for (i = numentries - 1; i >= 0; i--) {
270
+ entry = git_reflog_entry_byindex(reflog, i);
271
+ commit_time = git_reflog_entry_committer(entry)->when;
272
+
273
+ if (commit_time.time - identifier > 0)
274
+ continue;
275
+
276
+ git_oid_cpy(oid, git_reflog_entry_oidnew(entry));
277
+ error = 0;
278
+ goto cleanup;
279
+ }
280
+
281
+ error = GIT_ENOTFOUND;
282
+ }
283
+
284
+ cleanup:
285
+ git_reflog_free(reflog);
286
+ return error;
287
+ }
288
+
289
+ static int retrieve_revobject_from_reflog(git_object **out, git_reference **base_ref, git_repository *repo, const char *identifier, unsigned int position)
290
+ {
291
+ git_reference *ref;
292
+ git_oid oid;
293
+ int error = -1;
294
+
295
+ if (*base_ref == NULL) {
296
+ if ((error = disambiguate_refname(&ref, repo, identifier)) < 0)
297
+ return error;
298
+ } else {
299
+ ref = *base_ref;
300
+ *base_ref = NULL;
301
+ }
302
+
303
+ if (position == 0) {
304
+ error = git_object_lookup(out, repo, git_reference_oid(ref), GIT_OBJ_ANY);
305
+ goto cleanup;
306
+ }
307
+
308
+ if ((error = retrieve_oid_from_reflog(&oid, ref, position)) < 0)
309
+ goto cleanup;
310
+
311
+ error = git_object_lookup(out, repo, &oid, GIT_OBJ_ANY);
312
+
313
+ cleanup:
314
+ git_reference_free(ref);
315
+ return error;
316
+ }
317
+
318
+ static int retrieve_remote_tracking_reference(git_reference **base_ref, const char *identifier, git_repository *repo)
319
+ {
320
+ git_reference *tracking, *ref;
321
+ int error = -1;
322
+
323
+ if (*base_ref == NULL) {
324
+ if ((error = disambiguate_refname(&ref, repo, identifier)) < 0)
325
+ return error;
326
+ } else {
327
+ ref = *base_ref;
328
+ *base_ref = NULL;
329
+ }
330
+
331
+ if ((error = git_branch_tracking(&tracking, ref)) < 0)
332
+ goto cleanup;
333
+
334
+ *base_ref = tracking;
335
+
336
+ cleanup:
337
+ git_reference_free(ref);
338
+ return error;
339
+ }
340
+
341
+ static int handle_at_syntax(git_object **out, git_reference **ref, const char *spec, size_t identifier_len, git_repository* repo, const char *curly_braces_content)
342
+ {
343
+ bool is_numeric;
344
+ int parsed = 0, error = -1;
345
+ git_buf identifier = GIT_BUF_INIT;
346
+ git_time_t timestamp;
347
+
348
+ assert(*out == NULL);
349
+
350
+ if (git_buf_put(&identifier, spec, identifier_len) < 0)
351
+ return -1;
352
+
353
+ is_numeric = !try_parse_numeric(&parsed, curly_braces_content);
354
+
355
+ if (*curly_braces_content == '-' && (!is_numeric || parsed == 0)) {
356
+ error = revspec_error(spec);
357
+ goto cleanup;
358
+ }
359
+
360
+ if (is_numeric) {
361
+ if (parsed < 0)
362
+ error = retrieve_previously_checked_out_branch_or_revision(out, ref, repo, spec, git_buf_cstr(&identifier), -parsed);
363
+ else
364
+ error = retrieve_revobject_from_reflog(out, ref, repo, git_buf_cstr(&identifier), parsed);
365
+
366
+ goto cleanup;
367
+ }
368
+
369
+ if (!strcmp(curly_braces_content, "u") || !strcmp(curly_braces_content, "upstream")) {
370
+ error = retrieve_remote_tracking_reference(ref, git_buf_cstr(&identifier), repo);
371
+
372
+ goto cleanup;
373
+ }
374
+
375
+ if (git__date_parse(&timestamp, curly_braces_content) < 0)
376
+ goto cleanup;
377
+
378
+ error = retrieve_revobject_from_reflog(out, ref, repo, git_buf_cstr(&identifier), (unsigned int)timestamp);
379
+
380
+ cleanup:
381
+ git_buf_free(&identifier);
382
+ return error;
383
+ }
384
+
385
+ static git_otype parse_obj_type(const char *str)
386
+ {
387
+ if (!strcmp(str, "commit"))
388
+ return GIT_OBJ_COMMIT;
389
+
390
+ if (!strcmp(str, "tree"))
391
+ return GIT_OBJ_TREE;
392
+
393
+ if (!strcmp(str, "blob"))
394
+ return GIT_OBJ_BLOB;
395
+
396
+ if (!strcmp(str, "tag"))
397
+ return GIT_OBJ_TAG;
398
+
399
+ return GIT_OBJ_BAD;
400
+ }
401
+
402
+ static int dereference_to_non_tag(git_object **out, git_object *obj)
403
+ {
404
+ if (git_object_type(obj) == GIT_OBJ_TAG)
405
+ return git_tag_peel(out, (git_tag *)obj);
406
+
407
+ return git_object__dup(out, obj);
408
+ }
409
+
410
+ static int handle_caret_parent_syntax(git_object **out, git_object *obj, int n)
411
+ {
412
+ git_object *temp_commit = NULL;
413
+ int error;
414
+
415
+ if (git_object_peel(&temp_commit, obj, GIT_OBJ_COMMIT) < 0)
416
+ return -1;
417
+
418
+ if (n == 0) {
419
+ *out = temp_commit;
420
+ return 0;
421
+ }
422
+
423
+ error = git_commit_parent((git_commit **)out, (git_commit*)temp_commit, n - 1);
424
+
425
+ git_object_free(temp_commit);
426
+ return error;
427
+ }
428
+
429
+ static int handle_linear_syntax(git_object **out, git_object *obj, int n)
430
+ {
431
+ git_object *temp_commit = NULL;
432
+ int error;
433
+
434
+ if (git_object_peel(&temp_commit, obj, GIT_OBJ_COMMIT) < 0)
435
+ return -1;
436
+
437
+ error = git_commit_nth_gen_ancestor((git_commit **)out, (git_commit*)temp_commit, n);
438
+
439
+ git_object_free(temp_commit);
440
+ return error;
441
+ }
442
+
443
+ static int handle_colon_syntax(
444
+ git_object **out,
445
+ git_object *obj,
446
+ const char *path)
447
+ {
448
+ git_object *tree;
449
+ int error = -1;
450
+ git_tree_entry *entry = NULL;
451
+
452
+ if (git_object_peel(&tree, obj, GIT_OBJ_TREE) < 0)
453
+ return -1;
454
+
455
+ if (*path == '\0') {
456
+ *out = tree;
457
+ return 0;
458
+ }
459
+
460
+ /*
461
+ * TODO: Handle the relative path syntax
462
+ * (:./relative/path and :../relative/path)
463
+ */
464
+ if ((error = git_tree_entry_bypath(&entry, (git_tree *)tree, path)) < 0)
465
+ goto cleanup;
466
+
467
+ error = git_tree_entry_to_object(out, git_object_owner(tree), entry);
468
+
469
+ cleanup:
470
+ git_tree_entry_free(entry);
471
+ git_object_free(tree);
472
+
473
+ return error;
474
+ }
475
+
476
+ static int walk_and_search(git_object **out, git_revwalk *walk, regex_t *regex)
477
+ {
478
+ int error;
479
+ git_oid oid;
480
+ git_object *obj;
481
+
482
+ while (!(error = git_revwalk_next(&oid, walk))) {
483
+
484
+ if ((error = git_object_lookup(&obj, git_revwalk_repository(walk), &oid, GIT_OBJ_COMMIT) < 0) &&
485
+ (error != GIT_ENOTFOUND))
486
+ return -1;
487
+
488
+ if (!regexec(regex, git_commit_message((git_commit*)obj), 0, NULL, 0)) {
489
+ *out = obj;
490
+ return 0;
491
+ }
492
+
493
+ git_object_free(obj);
494
+ }
495
+
496
+ if (error < 0 && error == GIT_REVWALKOVER)
497
+ error = GIT_ENOTFOUND;
498
+
499
+ return error;
500
+ }
501
+
502
+ static int handle_grep_syntax(git_object **out, git_repository *repo, const git_oid *spec_oid, const char *pattern)
503
+ {
504
+ regex_t preg;
505
+ git_revwalk *walk = NULL;
506
+ int error = -1;
507
+
508
+ if (build_regex(&preg, pattern) < 0)
509
+ return -1;
510
+
511
+ if (git_revwalk_new(&walk, repo) < 0)
512
+ goto cleanup;
513
+
514
+ git_revwalk_sorting(walk, GIT_SORT_TIME);
515
+
516
+ if (spec_oid == NULL) {
517
+ // TODO: @carlosmn: The glob should be refs/* but this makes git_revwalk_next() fails
518
+ if (git_revwalk_push_glob(walk, "refs/heads/*") < 0)
519
+ goto cleanup;
520
+ } else if (git_revwalk_push(walk, spec_oid) < 0)
521
+ goto cleanup;
522
+
523
+ error = walk_and_search(out, walk, &preg);
524
+
525
+ cleanup:
526
+ regfree(&preg);
527
+ git_revwalk_free(walk);
528
+
529
+ return error;
530
+ }
531
+
532
+ static int handle_caret_curly_syntax(git_object **out, git_object *obj, const char *curly_braces_content)
533
+ {
534
+ git_otype expected_type;
535
+
536
+ if (*curly_braces_content == '\0')
537
+ return dereference_to_non_tag(out, obj);
538
+
539
+ if (*curly_braces_content == '/')
540
+ return handle_grep_syntax(out, git_object_owner(obj), git_object_id(obj), curly_braces_content + 1);
541
+
542
+ expected_type = parse_obj_type(curly_braces_content);
543
+
544
+ if (expected_type == GIT_OBJ_BAD)
545
+ return -1;
546
+
547
+ return git_object_peel(out, obj, expected_type);
548
+ }
549
+
550
+ static int extract_curly_braces_content(git_buf *buf, const char *spec, size_t *pos)
551
+ {
552
+ git_buf_clear(buf);
553
+
554
+ assert(spec[*pos] == '^' || spec[*pos] == '@');
555
+
556
+ (*pos)++;
557
+
558
+ if (spec[*pos] == '\0' || spec[*pos] != '{')
559
+ return revspec_error(spec);
560
+
561
+ (*pos)++;
562
+
563
+ while (spec[*pos] != '}') {
564
+ if (spec[*pos] == '\0')
565
+ return revspec_error(spec);
566
+
567
+ git_buf_putc(buf, spec[(*pos)++]);
568
+ }
569
+
570
+ (*pos)++;
571
+
572
+ return 0;
573
+ }
574
+
575
+ static int extract_path(git_buf *buf, const char *spec, size_t *pos)
576
+ {
577
+ git_buf_clear(buf);
578
+
579
+ assert(spec[*pos] == ':');
580
+
581
+ (*pos)++;
582
+
583
+ if (git_buf_puts(buf, spec + *pos) < 0)
584
+ return -1;
585
+
586
+ *pos += git_buf_len(buf);
587
+
588
+ return 0;
589
+ }
590
+
591
+ static int extract_how_many(int *n, const char *spec, size_t *pos)
592
+ {
593
+ const char *end_ptr;
594
+ int parsed, accumulated;
595
+ char kind = spec[*pos];
596
+
597
+ assert(spec[*pos] == '^' || spec[*pos] == '~');
598
+
599
+ accumulated = 0;
600
+
601
+ do {
602
+ do {
603
+ (*pos)++;
604
+ accumulated++;
605
+ } while (spec[(*pos)] == kind && kind == '~');
606
+
607
+ if (git__isdigit(spec[*pos])) {
608
+ if ((git__strtol32(&parsed, spec + *pos, &end_ptr, 10) < 0) < 0)
609
+ return revspec_error(spec);
610
+
611
+ accumulated += (parsed - 1);
612
+ *pos = end_ptr - spec;
613
+ }
614
+
615
+ } while (spec[(*pos)] == kind && kind == '~');
616
+
617
+ *n = accumulated;
618
+
619
+ return 0;
620
+ }
621
+
622
+ static int object_from_reference(git_object **object, git_reference *reference)
623
+ {
624
+ git_reference *resolved = NULL;
625
+ int error;
626
+
627
+ if (git_reference_resolve(&resolved, reference) < 0)
628
+ return -1;
629
+
630
+ error = git_object_lookup(object, reference->owner, git_reference_oid(resolved), GIT_OBJ_ANY);
631
+ git_reference_free(resolved);
632
+
633
+ return error;
634
+ }
635
+
636
+ static int ensure_base_rev_loaded(git_object **object, git_reference **reference, const char *spec, size_t identifier_len, git_repository *repo, bool allow_empty_identifier)
637
+ {
638
+ int error;
639
+ git_buf identifier = GIT_BUF_INIT;
640
+
641
+ if (*object != NULL)
642
+ return 0;
643
+
644
+ if (*reference != NULL) {
645
+ if ((error = object_from_reference(object, *reference)) < 0)
646
+ return error;
647
+
648
+ git_reference_free(*reference);
649
+ *reference = NULL;
650
+ return 0;
651
+ }
652
+
653
+ if (!allow_empty_identifier && identifier_len == 0)
654
+ return revspec_error(spec);
655
+
656
+ if (git_buf_put(&identifier, spec, identifier_len) < 0)
657
+ return -1;
658
+
659
+ error = revparse_lookup_object(object, repo, git_buf_cstr(&identifier));
660
+ git_buf_free(&identifier);
661
+
662
+ return error;
663
+ }
664
+
665
+ static int ensure_base_rev_is_not_known_yet(git_object *object, const char *spec)
666
+ {
667
+ if (object == NULL)
668
+ return 0;
669
+
670
+ return revspec_error(spec);
671
+ }
672
+
673
+ static bool any_left_hand_identifier(git_object *object, git_reference *reference, size_t identifier_len)
674
+ {
675
+ if (object != NULL)
676
+ return true;
677
+
678
+ if (reference != NULL)
679
+ return true;
680
+
681
+ if (identifier_len > 0)
682
+ return true;
683
+
684
+ return false;
685
+ }
686
+
687
+ static int ensure_left_hand_identifier_is_not_known_yet(git_object *object, git_reference *reference, const char *spec)
688
+ {
689
+ if (!ensure_base_rev_is_not_known_yet(object, spec) && reference == NULL)
690
+ return 0;
691
+
692
+ return revspec_error(spec);
693
+ }
694
+
695
+ int git_revparse_single(git_object **out, git_repository *repo, const char *spec)
696
+ {
697
+ size_t pos = 0, identifier_len = 0;
698
+ int error = -1, n;
699
+ git_buf buf = GIT_BUF_INIT;
700
+
701
+ git_reference *reference = NULL;
702
+ git_object *base_rev = NULL;
703
+
704
+ assert(out && repo && spec);
705
+
706
+ *out = NULL;
707
+
708
+ while (spec[pos]) {
709
+ switch (spec[pos]) {
710
+ case '^':
711
+ if ((error = ensure_base_rev_loaded(&base_rev, &reference, spec, identifier_len, repo, false)) < 0)
712
+ goto cleanup;
713
+
714
+ if (spec[pos+1] == '{') {
715
+ git_object *temp_object = NULL;
716
+
717
+ if ((error = extract_curly_braces_content(&buf, spec, &pos)) < 0)
718
+ goto cleanup;
719
+
720
+ if ((error = handle_caret_curly_syntax(&temp_object, base_rev, git_buf_cstr(&buf))) < 0)
721
+ goto cleanup;
722
+
723
+ git_object_free(base_rev);
724
+ base_rev = temp_object;
725
+ } else {
726
+ git_object *temp_object = NULL;
727
+
728
+ if ((error = extract_how_many(&n, spec, &pos)) < 0)
729
+ goto cleanup;
730
+
731
+ if ((error = handle_caret_parent_syntax(&temp_object, base_rev, n)) < 0)
732
+ goto cleanup;
733
+
734
+ git_object_free(base_rev);
735
+ base_rev = temp_object;
736
+ }
737
+ break;
738
+
739
+ case '~':
740
+ {
741
+ git_object *temp_object = NULL;
742
+
743
+ if ((error = extract_how_many(&n, spec, &pos)) < 0)
744
+ goto cleanup;
745
+
746
+ if ((error = ensure_base_rev_loaded(&base_rev, &reference, spec, identifier_len, repo, false)) < 0)
747
+ goto cleanup;
748
+
749
+ if ((error = handle_linear_syntax(&temp_object, base_rev, n)) < 0)
750
+ goto cleanup;
751
+
752
+ git_object_free(base_rev);
753
+ base_rev = temp_object;
754
+ break;
755
+ }
756
+
757
+ case ':':
758
+ {
759
+ git_object *temp_object = NULL;
760
+
761
+ if ((error = extract_path(&buf, spec, &pos)) < 0)
762
+ goto cleanup;
763
+
764
+ if (any_left_hand_identifier(base_rev, reference, identifier_len)) {
765
+ if ((error = ensure_base_rev_loaded(&base_rev, &reference, spec, identifier_len, repo, true)) < 0)
766
+ goto cleanup;
767
+
768
+ if ((error = handle_colon_syntax(&temp_object, base_rev, git_buf_cstr(&buf))) < 0)
769
+ goto cleanup;
770
+ } else {
771
+ if (*git_buf_cstr(&buf) == '/') {
772
+ if ((error = handle_grep_syntax(&temp_object, repo, NULL, git_buf_cstr(&buf) + 1)) < 0)
773
+ goto cleanup;
774
+ } else {
775
+
776
+ /*
777
+ * TODO: support merge-stage path lookup (":2:Makefile")
778
+ * and plain index blob lookup (:i-am/a/blob)
779
+ */
780
+ giterr_set(GITERR_INVALID, "Unimplemented");
781
+ error = GIT_ERROR;
782
+ goto cleanup;
783
+ }
784
+ }
785
+
786
+ git_object_free(base_rev);
787
+ base_rev = temp_object;
788
+ break;
789
+ }
790
+
791
+ case '@':
792
+ {
793
+ git_object *temp_object = NULL;
794
+
795
+ if ((error = extract_curly_braces_content(&buf, spec, &pos)) < 0)
796
+ goto cleanup;
797
+
798
+ if ((error = ensure_base_rev_is_not_known_yet(base_rev, spec)) < 0)
799
+ goto cleanup;
800
+
801
+ if ((error = handle_at_syntax(&temp_object, &reference, spec, identifier_len, repo, git_buf_cstr(&buf))) < 0)
802
+ goto cleanup;
803
+
804
+ if (temp_object != NULL)
805
+ base_rev = temp_object;
806
+ break;
807
+ }
808
+
809
+ default:
810
+ if ((error = ensure_left_hand_identifier_is_not_known_yet(base_rev, reference, spec)) < 0)
811
+ goto cleanup;
812
+
813
+ pos++;
814
+ identifier_len++;
815
+ }
816
+ }
817
+
818
+ if ((error = ensure_base_rev_loaded(&base_rev, &reference, spec, identifier_len, repo, false)) < 0)
819
+ goto cleanup;
820
+
821
+ *out = base_rev;
822
+ error = 0;
823
+
824
+ cleanup:
825
+ if (error)
826
+ git_object_free(base_rev);
827
+ git_reference_free(reference);
828
+ git_buf_free(&buf);
829
+ return error;
830
+ }