rugged 0.17.0.b7 → 0.18.0.b1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (310) hide show
  1. data/LICENSE +1 -1
  2. data/README.md +88 -32
  3. data/ext/rugged/extconf.rb +4 -2
  4. data/ext/rugged/rugged.c +72 -10
  5. data/ext/rugged/rugged.h +14 -10
  6. data/ext/rugged/rugged_blob.c +8 -10
  7. data/ext/rugged/rugged_branch.c +11 -14
  8. data/ext/rugged/rugged_commit.c +31 -24
  9. data/ext/rugged/rugged_config.c +2 -2
  10. data/ext/rugged/rugged_index.c +133 -198
  11. data/ext/rugged/rugged_note.c +372 -0
  12. data/ext/rugged/rugged_object.c +50 -22
  13. data/ext/rugged/rugged_reference.c +122 -130
  14. data/ext/rugged/rugged_remote.c +72 -29
  15. data/ext/rugged/rugged_repo.c +402 -20
  16. data/ext/rugged/rugged_revwalk.c +7 -3
  17. data/ext/rugged/rugged_settings.c +110 -0
  18. data/ext/rugged/rugged_signature.c +23 -7
  19. data/ext/rugged/rugged_tag.c +32 -16
  20. data/ext/rugged/rugged_tree.c +44 -15
  21. data/lib/rugged.rb +1 -0
  22. data/lib/rugged/index.rb +8 -0
  23. data/lib/rugged/remote.rb +13 -0
  24. data/lib/rugged/repository.rb +3 -3
  25. data/lib/rugged/version.rb +1 -1
  26. data/test/blob_test.rb +13 -15
  27. data/test/branch_test.rb +32 -67
  28. data/test/commit_test.rb +50 -12
  29. data/test/config_test.rb +12 -11
  30. data/test/coverage/HEAD.json +1 -1
  31. data/test/coverage/cover.rb +40 -21
  32. data/test/errors_test.rb +34 -0
  33. data/test/fixtures/alternate/objects/14/6ae76773c91e3b1d00cf7a338ec55ae58297e2 +0 -0
  34. data/test/fixtures/alternate/objects/14/9c32d47e99d0a3572ff1e70a2e0051bbf347a9 +0 -0
  35. data/test/fixtures/alternate/objects/14/fb3108588f9421bf764041e5e3ac305eb6277f +0 -0
  36. data/test/fixtures/testrepo.git/logs/refs/notes/commits +1 -0
  37. data/test/fixtures/testrepo.git/objects/44/1034f860c1d5d90e4188d11ae0d325176869a8 +1 -0
  38. data/test/fixtures/testrepo.git/objects/60/d415052a33de2150bf68757f6461df4f563ae4 +0 -0
  39. data/test/fixtures/testrepo.git/objects/68/8a8f4ef7496901d15322972f96e212a9e466cc +1 -0
  40. data/test/fixtures/testrepo.git/objects/94/eca2de348d5f672faf56b0decafa5937e3235e +0 -0
  41. data/test/fixtures/testrepo.git/objects/9b/7384fe1676186192842f5d3e129457b62db9e3 +0 -0
  42. data/test/fixtures/testrepo.git/objects/b7/4713326bc972cc15751ed504dca6f6f3b91f7a +3 -0
  43. data/test/fixtures/testrepo.git/refs/notes/commits +1 -0
  44. data/test/index_test.rb +65 -69
  45. data/test/lib_test.rb +76 -11
  46. data/test/note_test.rb +158 -0
  47. data/test/object_test.rb +8 -11
  48. data/test/reference_test.rb +77 -85
  49. data/test/remote_test.rb +86 -8
  50. data/test/repo_pack_test.rb +9 -7
  51. data/test/repo_reset_test.rb +80 -0
  52. data/test/repo_test.rb +176 -53
  53. data/test/tag_test.rb +44 -7
  54. data/test/test_helper.rb +63 -35
  55. data/test/tree_test.rb +34 -13
  56. data/test/walker_test.rb +14 -14
  57. data/vendor/libgit2/Makefile.embed +1 -1
  58. data/vendor/libgit2/deps/http-parser/http_parser.c +974 -578
  59. data/vendor/libgit2/deps/http-parser/http_parser.h +106 -70
  60. data/vendor/libgit2/deps/regex/regcomp.c +7 -6
  61. data/vendor/libgit2/deps/regex/regex_internal.c +1 -1
  62. data/vendor/libgit2/deps/regex/regex_internal.h +12 -3
  63. data/vendor/libgit2/deps/regex/regexec.c +5 -5
  64. data/vendor/libgit2/include/git2.h +5 -1
  65. data/vendor/libgit2/include/git2/attr.h +4 -2
  66. data/vendor/libgit2/include/git2/blob.h +39 -12
  67. data/vendor/libgit2/include/git2/branch.h +123 -35
  68. data/vendor/libgit2/include/git2/checkout.h +206 -48
  69. data/vendor/libgit2/include/git2/clone.h +72 -27
  70. data/vendor/libgit2/include/git2/commit.h +20 -17
  71. data/vendor/libgit2/include/git2/common.h +67 -1
  72. data/vendor/libgit2/include/git2/config.h +81 -60
  73. data/vendor/libgit2/include/git2/cred_helpers.h +53 -0
  74. data/vendor/libgit2/include/git2/diff.h +459 -150
  75. data/vendor/libgit2/include/git2/errors.h +9 -1
  76. data/vendor/libgit2/include/git2/graph.h +41 -0
  77. data/vendor/libgit2/include/git2/ignore.h +7 -6
  78. data/vendor/libgit2/include/git2/index.h +323 -97
  79. data/vendor/libgit2/include/git2/indexer.h +27 -59
  80. data/vendor/libgit2/include/git2/inttypes.h +4 -0
  81. data/vendor/libgit2/include/git2/merge.h +13 -3
  82. data/vendor/libgit2/include/git2/message.h +14 -8
  83. data/vendor/libgit2/include/git2/net.h +9 -7
  84. data/vendor/libgit2/include/git2/notes.h +88 -29
  85. data/vendor/libgit2/include/git2/object.h +16 -6
  86. data/vendor/libgit2/include/git2/odb.h +80 -17
  87. data/vendor/libgit2/include/git2/odb_backend.h +47 -11
  88. data/vendor/libgit2/include/git2/oid.h +26 -17
  89. data/vendor/libgit2/include/git2/pack.h +62 -8
  90. data/vendor/libgit2/include/git2/push.h +131 -0
  91. data/vendor/libgit2/include/git2/refdb.h +103 -0
  92. data/vendor/libgit2/include/git2/refdb_backend.h +109 -0
  93. data/vendor/libgit2/include/git2/reflog.h +30 -21
  94. data/vendor/libgit2/include/git2/refs.h +215 -193
  95. data/vendor/libgit2/include/git2/refspec.h +22 -2
  96. data/vendor/libgit2/include/git2/remote.h +158 -37
  97. data/vendor/libgit2/include/git2/repository.h +150 -31
  98. data/vendor/libgit2/include/git2/reset.h +43 -9
  99. data/vendor/libgit2/include/git2/revparse.h +48 -4
  100. data/vendor/libgit2/include/git2/revwalk.h +25 -10
  101. data/vendor/libgit2/include/git2/signature.h +20 -12
  102. data/vendor/libgit2/include/git2/stash.h +121 -0
  103. data/vendor/libgit2/include/git2/status.h +122 -53
  104. data/vendor/libgit2/include/git2/strarray.h +17 -11
  105. data/vendor/libgit2/include/git2/submodule.h +42 -7
  106. data/vendor/libgit2/include/git2/tag.h +72 -59
  107. data/vendor/libgit2/include/git2/threads.h +4 -2
  108. data/vendor/libgit2/include/git2/trace.h +68 -0
  109. data/vendor/libgit2/include/git2/transport.h +328 -0
  110. data/vendor/libgit2/include/git2/tree.h +149 -120
  111. data/vendor/libgit2/include/git2/types.h +13 -12
  112. data/vendor/libgit2/include/git2/version.h +3 -3
  113. data/vendor/libgit2/src/amiga/map.c +2 -2
  114. data/vendor/libgit2/src/attr.c +58 -48
  115. data/vendor/libgit2/src/attr.h +4 -18
  116. data/vendor/libgit2/src/attr_file.c +30 -6
  117. data/vendor/libgit2/src/attr_file.h +6 -8
  118. data/vendor/libgit2/src/attrcache.h +24 -0
  119. data/vendor/libgit2/src/blob.c +30 -7
  120. data/vendor/libgit2/src/blob.h +1 -1
  121. data/vendor/libgit2/src/branch.c +361 -68
  122. data/vendor/libgit2/src/branch.h +17 -0
  123. data/vendor/libgit2/src/bswap.h +1 -1
  124. data/vendor/libgit2/src/buf_text.c +291 -0
  125. data/vendor/libgit2/src/buf_text.h +122 -0
  126. data/vendor/libgit2/src/buffer.c +27 -101
  127. data/vendor/libgit2/src/buffer.h +54 -39
  128. data/vendor/libgit2/src/cache.c +15 -6
  129. data/vendor/libgit2/src/cache.h +1 -1
  130. data/vendor/libgit2/src/cc-compat.h +3 -1
  131. data/vendor/libgit2/src/checkout.c +1165 -222
  132. data/vendor/libgit2/src/checkout.h +24 -0
  133. data/vendor/libgit2/src/clone.c +171 -86
  134. data/vendor/libgit2/src/commit.c +44 -45
  135. data/vendor/libgit2/src/commit.h +3 -3
  136. data/vendor/libgit2/src/commit_list.c +194 -0
  137. data/vendor/libgit2/src/commit_list.h +49 -0
  138. data/vendor/libgit2/src/common.h +44 -10
  139. data/vendor/libgit2/src/compress.c +1 -1
  140. data/vendor/libgit2/src/compress.h +1 -1
  141. data/vendor/libgit2/src/config.c +211 -124
  142. data/vendor/libgit2/src/config.h +23 -4
  143. data/vendor/libgit2/src/config_cache.c +2 -2
  144. data/vendor/libgit2/src/config_file.c +129 -53
  145. data/vendor/libgit2/src/config_file.h +10 -8
  146. data/vendor/libgit2/src/crlf.c +66 -67
  147. data/vendor/libgit2/src/date.c +12 -12
  148. data/vendor/libgit2/src/delta-apply.c +14 -1
  149. data/vendor/libgit2/src/delta-apply.h +18 -1
  150. data/vendor/libgit2/src/delta.c +40 -107
  151. data/vendor/libgit2/src/delta.h +19 -17
  152. data/vendor/libgit2/src/diff.c +347 -496
  153. data/vendor/libgit2/src/diff.h +27 -1
  154. data/vendor/libgit2/src/diff_output.c +564 -249
  155. data/vendor/libgit2/src/diff_output.h +15 -8
  156. data/vendor/libgit2/src/diff_tform.c +687 -0
  157. data/vendor/libgit2/src/errors.c +27 -36
  158. data/vendor/libgit2/src/fetch.c +13 -351
  159. data/vendor/libgit2/src/fetch.h +13 -3
  160. data/vendor/libgit2/src/fetchhead.c +295 -0
  161. data/vendor/libgit2/src/fetchhead.h +34 -0
  162. data/vendor/libgit2/src/filebuf.c +42 -15
  163. data/vendor/libgit2/src/filebuf.h +4 -2
  164. data/vendor/libgit2/src/fileops.c +466 -113
  165. data/vendor/libgit2/src/fileops.h +154 -28
  166. data/vendor/libgit2/src/filter.c +3 -75
  167. data/vendor/libgit2/src/filter.h +1 -29
  168. data/vendor/libgit2/src/fnmatch.c +1 -1
  169. data/vendor/libgit2/src/fnmatch.h +1 -1
  170. data/vendor/libgit2/src/global.c +54 -10
  171. data/vendor/libgit2/src/global.h +10 -1
  172. data/vendor/libgit2/src/graph.c +178 -0
  173. data/vendor/libgit2/src/hash.c +25 -52
  174. data/vendor/libgit2/src/hash.h +21 -9
  175. data/vendor/libgit2/src/{sha1/sha1.c → hash/hash_generic.c} +20 -12
  176. data/vendor/libgit2/src/hash/hash_generic.h +24 -0
  177. data/vendor/libgit2/src/hash/hash_openssl.h +45 -0
  178. data/vendor/libgit2/src/hash/hash_win32.c +291 -0
  179. data/vendor/libgit2/src/hash/hash_win32.h +140 -0
  180. data/vendor/libgit2/src/hashsig.c +368 -0
  181. data/vendor/libgit2/src/hashsig.h +72 -0
  182. data/vendor/libgit2/src/ignore.c +22 -15
  183. data/vendor/libgit2/src/ignore.h +6 -1
  184. data/vendor/libgit2/src/index.c +770 -171
  185. data/vendor/libgit2/src/index.h +13 -5
  186. data/vendor/libgit2/src/indexer.c +286 -431
  187. data/vendor/libgit2/src/iterator.c +854 -466
  188. data/vendor/libgit2/src/iterator.h +134 -109
  189. data/vendor/libgit2/src/map.h +1 -1
  190. data/vendor/libgit2/src/merge.c +296 -0
  191. data/vendor/libgit2/src/merge.h +22 -0
  192. data/vendor/libgit2/src/message.c +1 -1
  193. data/vendor/libgit2/src/message.h +1 -1
  194. data/vendor/libgit2/src/mwindow.c +35 -30
  195. data/vendor/libgit2/src/mwindow.h +2 -2
  196. data/vendor/libgit2/src/netops.c +162 -98
  197. data/vendor/libgit2/src/netops.h +50 -15
  198. data/vendor/libgit2/src/notes.c +109 -58
  199. data/vendor/libgit2/src/notes.h +2 -1
  200. data/vendor/libgit2/src/object.c +46 -57
  201. data/vendor/libgit2/src/object.h +1 -8
  202. data/vendor/libgit2/src/odb.c +151 -40
  203. data/vendor/libgit2/src/odb.h +5 -1
  204. data/vendor/libgit2/src/odb_loose.c +4 -5
  205. data/vendor/libgit2/src/odb_pack.c +122 -80
  206. data/vendor/libgit2/src/offmap.h +65 -0
  207. data/vendor/libgit2/src/oid.c +12 -4
  208. data/vendor/libgit2/src/oidmap.h +1 -1
  209. data/vendor/libgit2/src/pack-objects.c +88 -61
  210. data/vendor/libgit2/src/pack-objects.h +8 -8
  211. data/vendor/libgit2/src/pack.c +293 -28
  212. data/vendor/libgit2/src/pack.h +49 -4
  213. data/vendor/libgit2/src/path.c +103 -14
  214. data/vendor/libgit2/src/path.h +23 -7
  215. data/vendor/libgit2/src/pathspec.c +168 -0
  216. data/vendor/libgit2/src/pathspec.h +40 -0
  217. data/vendor/libgit2/src/pool.c +29 -4
  218. data/vendor/libgit2/src/pool.h +8 -1
  219. data/vendor/libgit2/src/posix.c +26 -27
  220. data/vendor/libgit2/src/posix.h +2 -3
  221. data/vendor/libgit2/src/pqueue.c +23 -1
  222. data/vendor/libgit2/src/pqueue.h +23 -1
  223. data/vendor/libgit2/src/push.c +653 -0
  224. data/vendor/libgit2/src/push.h +51 -0
  225. data/vendor/libgit2/src/refdb.c +185 -0
  226. data/vendor/libgit2/src/refdb.h +46 -0
  227. data/vendor/libgit2/src/refdb_fs.c +1024 -0
  228. data/vendor/libgit2/src/refdb_fs.h +15 -0
  229. data/vendor/libgit2/src/reflog.c +77 -45
  230. data/vendor/libgit2/src/reflog.h +1 -3
  231. data/vendor/libgit2/src/refs.c +366 -1326
  232. data/vendor/libgit2/src/refs.h +22 -13
  233. data/vendor/libgit2/src/refspec.c +46 -7
  234. data/vendor/libgit2/src/refspec.h +11 -1
  235. data/vendor/libgit2/src/remote.c +758 -120
  236. data/vendor/libgit2/src/remote.h +10 -5
  237. data/vendor/libgit2/src/repo_template.h +6 -6
  238. data/vendor/libgit2/src/repository.c +315 -96
  239. data/vendor/libgit2/src/repository.h +5 -3
  240. data/vendor/libgit2/src/reset.c +99 -81
  241. data/vendor/libgit2/src/revparse.c +157 -84
  242. data/vendor/libgit2/src/revwalk.c +68 -470
  243. data/vendor/libgit2/src/revwalk.h +44 -0
  244. data/vendor/libgit2/src/sha1_lookup.c +1 -1
  245. data/vendor/libgit2/src/sha1_lookup.h +1 -1
  246. data/vendor/libgit2/src/signature.c +68 -200
  247. data/vendor/libgit2/src/signature.h +1 -1
  248. data/vendor/libgit2/src/stash.c +663 -0
  249. data/vendor/libgit2/src/status.c +101 -79
  250. data/vendor/libgit2/src/strmap.h +1 -1
  251. data/vendor/libgit2/src/submodule.c +67 -51
  252. data/vendor/libgit2/src/submodule.h +1 -1
  253. data/vendor/libgit2/src/tag.c +35 -29
  254. data/vendor/libgit2/src/tag.h +1 -1
  255. data/vendor/libgit2/src/thread-utils.c +1 -1
  256. data/vendor/libgit2/src/thread-utils.h +2 -2
  257. data/vendor/libgit2/src/trace.c +39 -0
  258. data/vendor/libgit2/src/trace.h +56 -0
  259. data/vendor/libgit2/src/transport.c +81 -34
  260. data/vendor/libgit2/src/transports/cred.c +60 -0
  261. data/vendor/libgit2/src/transports/cred_helpers.c +49 -0
  262. data/vendor/libgit2/src/transports/git.c +234 -127
  263. data/vendor/libgit2/src/transports/http.c +761 -433
  264. data/vendor/libgit2/src/transports/local.c +460 -64
  265. data/vendor/libgit2/src/transports/smart.c +345 -0
  266. data/vendor/libgit2/src/transports/smart.h +179 -0
  267. data/vendor/libgit2/src/{pkt.c → transports/smart_pkt.c} +131 -12
  268. data/vendor/libgit2/src/transports/smart_protocol.c +856 -0
  269. data/vendor/libgit2/src/transports/winhttp.c +1136 -0
  270. data/vendor/libgit2/src/tree-cache.c +2 -2
  271. data/vendor/libgit2/src/tree-cache.h +1 -1
  272. data/vendor/libgit2/src/tree.c +239 -166
  273. data/vendor/libgit2/src/tree.h +11 -2
  274. data/vendor/libgit2/src/tsort.c +39 -23
  275. data/vendor/libgit2/src/unix/map.c +1 -1
  276. data/vendor/libgit2/src/unix/posix.h +12 -2
  277. data/vendor/libgit2/src/unix/realpath.c +30 -0
  278. data/vendor/libgit2/src/util.c +250 -13
  279. data/vendor/libgit2/src/util.h +71 -14
  280. data/vendor/libgit2/src/vector.c +123 -60
  281. data/vendor/libgit2/src/vector.h +24 -22
  282. data/vendor/libgit2/src/win32/dir.c +1 -1
  283. data/vendor/libgit2/src/win32/dir.h +1 -1
  284. data/vendor/libgit2/src/win32/error.c +77 -0
  285. data/vendor/libgit2/src/win32/error.h +13 -0
  286. data/vendor/libgit2/src/win32/findfile.c +143 -54
  287. data/vendor/libgit2/src/win32/findfile.h +10 -6
  288. data/vendor/libgit2/src/win32/map.c +1 -1
  289. data/vendor/libgit2/src/win32/mingw-compat.h +1 -1
  290. data/vendor/libgit2/src/win32/msvc-compat.h +10 -1
  291. data/vendor/libgit2/src/win32/posix.h +10 -1
  292. data/vendor/libgit2/src/win32/posix_w32.c +132 -63
  293. data/vendor/libgit2/src/win32/precompiled.c +1 -1
  294. data/vendor/libgit2/src/win32/pthread.c +1 -1
  295. data/vendor/libgit2/src/win32/pthread.h +1 -1
  296. data/vendor/libgit2/src/win32/utf-conv.c +5 -5
  297. data/vendor/libgit2/src/win32/utf-conv.h +3 -3
  298. data/vendor/libgit2/src/win32/version.h +20 -0
  299. metadata +308 -252
  300. data/test/fixtures/testrepo.git/objects/4b/825dc642cb6eb9a060e54bf8d69288fbee4904 +0 -0
  301. data/test/fixtures/testrepo.git/objects/7f/043268ea43ce18e3540acaabf9e090c91965b0 +0 -0
  302. data/test/fixtures/testrepo.git/objects/a3/e05719b428a2d0ed7a55c4ce53dcc5768c6d5e +0 -0
  303. data/test/index_test.rb~ +0 -218
  304. data/vendor/libgit2/src/pkt.h +0 -91
  305. data/vendor/libgit2/src/ppc/sha1.c +0 -70
  306. data/vendor/libgit2/src/ppc/sha1.h +0 -26
  307. data/vendor/libgit2/src/protocol.c +0 -110
  308. data/vendor/libgit2/src/protocol.h +0 -21
  309. data/vendor/libgit2/src/sha1.h +0 -33
  310. data/vendor/libgit2/src/transport.h +0 -148
@@ -0,0 +1,24 @@
1
+ /*
2
+ * Copyright (C) the libgit2 contributors. All rights reserved.
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
+ #ifndef INCLUDE_checkout_h__
8
+ #define INCLUDE_checkout_h__
9
+
10
+ #include "git2/checkout.h"
11
+ #include "iterator.h"
12
+
13
+ #define GIT_CHECKOUT__NOTIFY_CONFLICT_TREE (1u << 12)
14
+
15
+ /**
16
+ * Update the working directory to match the target iterator. The
17
+ * expected baseline value can be passed in via the checkout options
18
+ * or else will default to the HEAD commit.
19
+ */
20
+ extern int git_checkout_iterator(
21
+ git_iterator *target,
22
+ git_checkout_opts *opts);
23
+
24
+ #endif
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright (C) 2009-2012 the libgit2 contributors
2
+ * Copyright (C) the libgit2 contributors. All rights reserved.
3
3
  *
4
4
  * This file is part of libgit2, distributed under the GNU GPL v2 with
5
5
  * a Linking Exception. For full terms see the included COPYING file.
@@ -18,7 +18,6 @@
18
18
 
19
19
  #include "common.h"
20
20
  #include "remote.h"
21
- #include "pkt.h"
22
21
  #include "fileops.h"
23
22
  #include "refs.h"
24
23
  #include "path.h"
@@ -29,18 +28,18 @@ static int create_branch(
29
28
  const git_oid *target,
30
29
  const char *name)
31
30
  {
32
- git_object *head_obj = NULL;
33
- git_reference *branch_ref;
31
+ git_commit *head_obj = NULL;
32
+ git_reference *branch_ref = NULL;
34
33
  int error;
35
34
 
36
35
  /* Find the target commit */
37
- if ((error = git_object_lookup(&head_obj, repo, target, GIT_OBJ_ANY)) < 0)
36
+ if ((error = git_commit_lookup(&head_obj, repo, target)) < 0)
38
37
  return error;
39
38
 
40
39
  /* Create the new branch */
41
40
  error = git_branch_create(&branch_ref, repo, name, head_obj, 0);
42
41
 
43
- git_object_free(head_obj);
42
+ git_commit_free(head_obj);
44
43
 
45
44
  if (!error)
46
45
  *branch = branch_ref;
@@ -106,6 +105,7 @@ struct head_info {
106
105
  git_oid remote_head_oid;
107
106
  git_buf branchname;
108
107
  const git_refspec *refspec;
108
+ bool found;
109
109
  };
110
110
 
111
111
  static int reference_matches_remote_head(
@@ -120,16 +120,16 @@ static int reference_matches_remote_head(
120
120
  */
121
121
 
122
122
  /* Stop looking if we've already found a match */
123
- if (git_buf_len(&head_info->branchname) > 0)
123
+ if (head_info->found)
124
124
  return 0;
125
125
 
126
- if (git_reference_name_to_oid(
126
+ if (git_reference_name_to_id(
127
127
  &oid,
128
128
  head_info->repo,
129
129
  reference_name) < 0) {
130
- /* TODO: How to handle not found references?
131
- */
132
- return -1;
130
+ /* If the reference doesn't exists, it obviously cannot match the expected oid. */
131
+ giterr_clear();
132
+ return 0;
133
133
  }
134
134
 
135
135
  if (git_oid_cmp(&head_info->remote_head_oid, &oid) == 0) {
@@ -140,10 +140,14 @@ static int reference_matches_remote_head(
140
140
  reference_name) < 0)
141
141
  return -1;
142
142
 
143
- if (git_buf_sets(
144
- &head_info->branchname,
145
- git_buf_cstr(&head_info->branchname) + strlen(GIT_REFS_HEADS_DIR)) < 0)
146
- return -1;
143
+ if (git_buf_len(&head_info->branchname) > 0) {
144
+ if (git_buf_sets(
145
+ &head_info->branchname,
146
+ git_buf_cstr(&head_info->branchname) + strlen(GIT_REFS_HEADS_DIR)) < 0)
147
+ return -1;
148
+
149
+ head_info->found = 1;
150
+ }
147
151
  }
148
152
 
149
153
  return 0;
@@ -171,11 +175,19 @@ static int update_head_to_new_branch(
171
175
  return error;
172
176
  }
173
177
 
178
+ static int get_head_callback(git_remote_head *head, void *payload)
179
+ {
180
+ git_remote_head **destination = (git_remote_head **)payload;
181
+
182
+ /* Save the first entry, and terminate the enumeration */
183
+ *destination = head;
184
+ return 1;
185
+ }
186
+
174
187
  static int update_head_to_remote(git_repository *repo, git_remote *remote)
175
188
  {
176
189
  int retcode = -1;
177
190
  git_remote_head *remote_head;
178
- git_pkt_ref *pkt;
179
191
  struct head_info head_info;
180
192
  git_buf remote_master_name = GIT_BUF_INIT;
181
193
 
@@ -189,12 +201,18 @@ static int update_head_to_remote(git_repository *repo, git_remote *remote)
189
201
  }
190
202
 
191
203
  /* Get the remote's HEAD. This is always the first ref in remote->refs. */
192
- pkt = remote->transport->refs.contents[0];
193
- remote_head = &pkt->head;
204
+ remote_head = NULL;
205
+
206
+ if (!remote->transport->ls(remote->transport, get_head_callback, &remote_head))
207
+ return -1;
208
+
209
+ assert(remote_head);
210
+
194
211
  git_oid_cpy(&head_info.remote_head_oid, &remote_head->oid);
195
212
  git_buf_init(&head_info.branchname, 16);
196
213
  head_info.repo = repo;
197
214
  head_info.refspec = git_remote_fetchspec(remote);
215
+ head_info.found = 0;
198
216
 
199
217
  /* Determine the remote tracking reference name from the local master */
200
218
  if (git_refspec_transform_r(
@@ -207,7 +225,7 @@ static int update_head_to_remote(git_repository *repo, git_remote *remote)
207
225
  if (reference_matches_remote_head(git_buf_cstr(&remote_master_name), &head_info) < 0)
208
226
  goto cleanup;
209
227
 
210
- if (git_buf_len(&head_info.branchname) > 0) {
228
+ if (head_info.found) {
211
229
  retcode = update_head_to_new_branch(
212
230
  repo,
213
231
  &head_info.remote_head_oid,
@@ -224,7 +242,7 @@ static int update_head_to_remote(git_repository *repo, git_remote *remote)
224
242
  &head_info) < 0)
225
243
  goto cleanup;
226
244
 
227
- if (git_buf_len(&head_info.branchname) > 0) {
245
+ if (head_info.found) {
228
246
  retcode = update_head_to_new_branch(
229
247
  repo,
230
248
  &head_info.remote_head_oid,
@@ -232,8 +250,10 @@ static int update_head_to_remote(git_repository *repo, git_remote *remote)
232
250
 
233
251
  goto cleanup;
234
252
  } else {
235
- /* TODO: What should we do if nothing has been found?
236
- */
253
+ retcode = git_repository_set_head_detached(
254
+ repo,
255
+ &head_info.remote_head_oid);
256
+ goto cleanup;
237
257
  }
238
258
 
239
259
  cleanup:
@@ -242,32 +262,110 @@ cleanup:
242
262
  return retcode;
243
263
  }
244
264
 
265
+ static int update_head_to_branch(
266
+ git_repository *repo,
267
+ const git_clone_options *options)
268
+ {
269
+ int retcode;
270
+ git_buf remote_branch_name = GIT_BUF_INIT;
271
+ git_reference* remote_ref = NULL;
272
+
273
+ assert(options->checkout_branch);
274
+
275
+ if ((retcode = git_buf_printf(&remote_branch_name, GIT_REFS_REMOTES_DIR "%s/%s",
276
+ options->remote_name, options->checkout_branch)) < 0 )
277
+ goto cleanup;
278
+
279
+ if ((retcode = git_reference_lookup(&remote_ref, repo, git_buf_cstr(&remote_branch_name))) < 0)
280
+ goto cleanup;
281
+
282
+ retcode = update_head_to_new_branch(repo, git_reference_target(remote_ref),
283
+ options->checkout_branch);
284
+
285
+ cleanup:
286
+ git_reference_free(remote_ref);
287
+ git_buf_free(&remote_branch_name);
288
+ return retcode;
289
+ }
290
+
245
291
  /*
246
292
  * submodules?
247
293
  */
248
294
 
295
+ static int create_and_configure_origin(
296
+ git_remote **out,
297
+ git_repository *repo,
298
+ const char *url,
299
+ const git_clone_options *options)
300
+ {
301
+ int error;
302
+ git_remote *origin = NULL;
303
+
304
+ if ((error = git_remote_create(&origin, repo, options->remote_name, url)) < 0)
305
+ goto on_error;
306
+
307
+ git_remote_set_cred_acquire_cb(origin, options->cred_acquire_cb,
308
+ options->cred_acquire_payload);
309
+ git_remote_set_autotag(origin, options->remote_autotag);
310
+ /*
311
+ * Don't write FETCH_HEAD, we'll check out the remote tracking
312
+ * branch ourselves based on the server's default.
313
+ */
314
+ git_remote_set_update_fetchhead(origin, 0);
315
+
316
+ if (options->remote_callbacks &&
317
+ (error = git_remote_set_callbacks(origin, options->remote_callbacks)) < 0)
318
+ goto on_error;
319
+
320
+ if (options->fetch_spec &&
321
+ (error = git_remote_set_fetchspec(origin, options->fetch_spec)) < 0)
322
+ goto on_error;
323
+
324
+ if (options->push_spec &&
325
+ (error = git_remote_set_pushspec(origin, options->push_spec)) < 0)
326
+ goto on_error;
327
+
328
+ if (options->pushurl &&
329
+ (error = git_remote_set_pushurl(origin, options->pushurl)) < 0)
330
+ goto on_error;
331
+
332
+ if ((error = git_remote_save(origin)) < 0)
333
+ goto on_error;
334
+
335
+ *out = origin;
336
+ return 0;
249
337
 
338
+ on_error:
339
+ git_remote_free(origin);
340
+ return error;
341
+ }
250
342
 
251
- static int setup_remotes_and_fetch(git_repository *repo,
252
- const char *origin_url,
253
- git_indexer_stats *fetch_stats)
343
+
344
+ static int setup_remotes_and_fetch(
345
+ git_repository *repo,
346
+ const char *url,
347
+ const git_clone_options *options)
254
348
  {
255
349
  int retcode = GIT_ERROR;
256
- git_remote *origin = NULL;
257
- git_off_t bytes = 0;
258
- git_indexer_stats dummy_stats;
350
+ git_remote *origin;
259
351
 
260
- if (!fetch_stats) fetch_stats = &dummy_stats;
352
+ /* Construct an origin remote */
353
+ if (!create_and_configure_origin(&origin, repo, url, options)) {
354
+ git_remote_set_update_fetchhead(origin, 0);
261
355
 
262
- /* Create the "origin" remote */
263
- if (!git_remote_add(&origin, repo, GIT_REMOTE_ORIGIN, origin_url)) {
264
356
  /* Connect and download everything */
265
- if (!git_remote_connect(origin, GIT_DIR_FETCH)) {
266
- if (!git_remote_download(origin, &bytes, fetch_stats)) {
357
+ if (!git_remote_connect(origin, GIT_DIRECTION_FETCH)) {
358
+ if (!(retcode = git_remote_download(origin, options->fetch_progress_cb,
359
+ options->fetch_progress_payload))) {
267
360
  /* Create "origin/foo" branches for all remote branches */
268
361
  if (!git_remote_update_tips(origin)) {
362
+ /* Point HEAD to the requested branch */
363
+ if (options->checkout_branch) {
364
+ if (!update_head_to_branch(repo, options))
365
+ retcode = 0;
366
+ }
269
367
  /* Point HEAD to the same ref as the remote's head */
270
- if (!update_head_to_remote(repo, origin)) {
368
+ else if (!update_head_to_remote(repo, origin)) {
271
369
  retcode = 0;
272
370
  }
273
371
  }
@@ -304,78 +402,65 @@ static bool should_checkout(
304
402
  if (!opts)
305
403
  return false;
306
404
 
405
+ if (opts->checkout_strategy == GIT_CHECKOUT_NONE)
406
+ return false;
407
+
307
408
  return !git_repository_head_orphan(repo);
308
409
  }
309
410
 
310
- static int clone_internal(
411
+ static void normalize_options(git_clone_options *dst, const git_clone_options *src)
412
+ {
413
+ git_clone_options default_options = GIT_CLONE_OPTIONS_INIT;
414
+ if (!src) src = &default_options;
415
+
416
+ *dst = *src;
417
+
418
+ /* Provide defaults for null pointers */
419
+ if (!dst->remote_name) dst->remote_name = "origin";
420
+ if (!dst->remote_autotag) dst->remote_autotag = GIT_REMOTE_DOWNLOAD_TAGS_ALL;
421
+ }
422
+
423
+ int git_clone(
311
424
  git_repository **out,
312
- const char *origin_url,
313
- const char *path,
314
- git_indexer_stats *fetch_stats,
315
- git_indexer_stats *checkout_stats,
316
- git_checkout_opts *checkout_opts,
317
- bool is_bare)
425
+ const char *url,
426
+ const char *local_path,
427
+ const git_clone_options *options)
318
428
  {
319
429
  int retcode = GIT_ERROR;
320
430
  git_repository *repo = NULL;
321
- git_indexer_stats dummy_stats;
431
+ git_clone_options normOptions;
432
+ int remove_directory_on_failure = 0;
322
433
 
323
- if (!fetch_stats) fetch_stats = &dummy_stats;
434
+ assert(out && url && local_path);
324
435
 
325
- if (!path_is_okay(path)) {
436
+ normalize_options(&normOptions, options);
437
+ GITERR_CHECK_VERSION(&normOptions, GIT_CLONE_OPTIONS_VERSION, "git_clone_options");
438
+
439
+ if (!path_is_okay(local_path)) {
326
440
  return GIT_ERROR;
327
441
  }
328
442
 
329
- if (!(retcode = git_repository_init(&repo, path, is_bare))) {
330
- if ((retcode = setup_remotes_and_fetch(repo, origin_url, fetch_stats)) < 0) {
443
+ /* Only remove the directory on failure if we create it */
444
+ remove_directory_on_failure = !git_path_exists(local_path);
445
+
446
+ if (!(retcode = git_repository_init(&repo, local_path, normOptions.bare))) {
447
+ if ((retcode = setup_remotes_and_fetch(repo, url, &normOptions)) < 0) {
331
448
  /* Failed to fetch; clean up */
332
449
  git_repository_free(repo);
333
- git_futils_rmdir_r(path, NULL, GIT_DIRREMOVAL_FILES_AND_DIRS);
450
+
451
+ if (remove_directory_on_failure)
452
+ git_futils_rmdir_r(local_path, NULL, GIT_RMDIR_REMOVE_FILES);
453
+ else
454
+ git_futils_cleanupdir_r(local_path);
455
+
334
456
  } else {
335
457
  *out = repo;
336
458
  retcode = 0;
337
459
  }
338
460
  }
339
461
 
340
- if (!retcode && should_checkout(repo, is_bare, checkout_opts))
341
- retcode = git_checkout_head(*out, checkout_opts, checkout_stats);
462
+ if (!retcode && should_checkout(repo, normOptions.bare, &normOptions.checkout_opts))
463
+ retcode = git_checkout_head(*out, &normOptions.checkout_opts);
342
464
 
343
465
  return retcode;
344
466
  }
345
-
346
- int git_clone_bare(git_repository **out,
347
- const char *origin_url,
348
- const char *dest_path,
349
- git_indexer_stats *fetch_stats)
350
- {
351
- assert(out && origin_url && dest_path);
352
-
353
- return clone_internal(
354
- out,
355
- origin_url,
356
- dest_path,
357
- fetch_stats,
358
- NULL,
359
- NULL,
360
- 1);
361
- }
362
-
363
-
364
- int git_clone(git_repository **out,
365
- const char *origin_url,
366
- const char *workdir_path,
367
- git_indexer_stats *fetch_stats,
368
- git_indexer_stats *checkout_stats,
369
- git_checkout_opts *checkout_opts)
370
- {
371
- assert(out && origin_url && workdir_path);
372
-
373
- return clone_internal(
374
- out,
375
- origin_url,
376
- workdir_path,
377
- fetch_stats,
378
- checkout_stats,
379
- checkout_opts,
380
- 0);
381
- }
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright (C) 2009-2012 the libgit2 contributors
2
+ * Copyright (C) the libgit2 contributors. All rights reserved.
3
3
  *
4
4
  * This file is part of libgit2, distributed under the GNU GPL v2 with
5
5
  * a Linking Exception. For full terms see the included COPYING file.
@@ -20,20 +20,20 @@
20
20
 
21
21
  static void clear_parents(git_commit *commit)
22
22
  {
23
- unsigned int i;
23
+ size_t i;
24
24
 
25
- for (i = 0; i < commit->parent_oids.length; ++i) {
26
- git_oid *parent = git_vector_get(&commit->parent_oids, i);
25
+ for (i = 0; i < commit->parent_ids.length; ++i) {
26
+ git_oid *parent = git_vector_get(&commit->parent_ids, i);
27
27
  git__free(parent);
28
28
  }
29
29
 
30
- git_vector_clear(&commit->parent_oids);
30
+ git_vector_clear(&commit->parent_ids);
31
31
  }
32
32
 
33
33
  void git_commit__free(git_commit *commit)
34
34
  {
35
35
  clear_parents(commit);
36
- git_vector_free(&commit->parent_oids);
36
+ git_vector_free(&commit->parent_ids);
37
37
 
38
38
  git_signature_free(commit->author);
39
39
  git_signature_free(commit->committer);
@@ -43,11 +43,6 @@ void git_commit__free(git_commit *commit)
43
43
  git__free(commit);
44
44
  }
45
45
 
46
- const git_oid *git_commit_id(git_commit *c)
47
- {
48
- return git_object_id((git_object *)c);
49
- }
50
-
51
46
  int git_commit_create_v(
52
47
  git_oid *oid,
53
48
  git_repository *repo,
@@ -126,7 +121,7 @@ int git_commit_create(
126
121
  git_buf_free(&commit);
127
122
 
128
123
  if (update_ref != NULL)
129
- return git_reference__update(repo, oid, update_ref);
124
+ return git_reference__update_terminal(repo, update_ref, oid);
130
125
 
131
126
  return 0;
132
127
 
@@ -140,27 +135,25 @@ int git_commit__parse_buffer(git_commit *commit, const void *data, size_t len)
140
135
  {
141
136
  const char *buffer = data;
142
137
  const char *buffer_end = (const char *)data + len;
138
+ git_oid parent_id;
143
139
 
144
- git_oid parent_oid;
145
-
146
- git_vector_init(&commit->parent_oids, 4, NULL);
140
+ if (git_vector_init(&commit->parent_ids, 4, NULL) < 0)
141
+ return -1;
147
142
 
148
- if (git_oid__parse(&commit->tree_oid, &buffer, buffer_end, "tree ") < 0)
143
+ if (git_oid__parse(&commit->tree_id, &buffer, buffer_end, "tree ") < 0)
149
144
  goto bad_buffer;
150
145
 
151
146
  /*
152
147
  * TODO: commit grafts!
153
148
  */
154
149
 
155
- while (git_oid__parse(&parent_oid, &buffer, buffer_end, "parent ") == 0) {
156
- git_oid *new_oid;
150
+ while (git_oid__parse(&parent_id, &buffer, buffer_end, "parent ") == 0) {
151
+ git_oid *new_id = git__malloc(sizeof(git_oid));
152
+ GITERR_CHECK_ALLOC(new_id);
157
153
 
158
- new_oid = git__malloc(sizeof(git_oid));
159
- GITERR_CHECK_ALLOC(new_oid);
154
+ git_oid_cpy(new_id, &parent_id);
160
155
 
161
- git_oid_cpy(new_oid, &parent_oid);
162
-
163
- if (git_vector_insert(&commit->parent_oids, new_oid) < 0)
156
+ if (git_vector_insert(&commit->parent_ids, new_id) < 0)
164
157
  return -1;
165
158
  }
166
159
 
@@ -177,24 +170,30 @@ int git_commit__parse_buffer(git_commit *commit, const void *data, size_t len)
177
170
  if (git_signature__parse(commit->committer, &buffer, buffer_end, "committer ", '\n') < 0)
178
171
  return -1;
179
172
 
180
- if (git__prefixcmp(buffer, "encoding ") == 0) {
181
- const char *encoding_end;
182
- buffer += strlen("encoding ");
173
+ /* Parse add'l header entries until blank line found */
174
+ while (buffer < buffer_end && *buffer != '\n') {
175
+ const char *eoln = buffer;
176
+ while (eoln < buffer_end && *eoln != '\n')
177
+ ++eoln;
178
+
179
+ if (git__prefixcmp(buffer, "encoding ") == 0) {
180
+ buffer += strlen("encoding ");
183
181
 
184
- encoding_end = buffer;
185
- while (encoding_end < buffer_end && *encoding_end != '\n')
186
- encoding_end++;
182
+ commit->message_encoding = git__strndup(buffer, eoln - buffer);
183
+ GITERR_CHECK_ALLOC(commit->message_encoding);
184
+ }
187
185
 
188
- commit->message_encoding = git__strndup(buffer, encoding_end - buffer);
189
- GITERR_CHECK_ALLOC(commit->message_encoding);
186
+ if (eoln < buffer_end && *eoln == '\n')
187
+ ++eoln;
190
188
 
191
- buffer = encoding_end;
189
+ buffer = eoln;
192
190
  }
193
191
 
194
- /* parse commit message */
195
- while (buffer < buffer_end - 1 && *buffer == '\n')
192
+ /* buffer is now at the end of the header, double-check and move forward into the message */
193
+ if (buffer < buffer_end && *buffer == '\n')
196
194
  buffer++;
197
195
 
196
+ /* parse commit message */
198
197
  if (buffer <= buffer_end) {
199
198
  commit->message = git__strndup(buffer, buffer_end - buffer);
200
199
  GITERR_CHECK_ALLOC(commit->message);
@@ -214,7 +213,7 @@ int git_commit__parse(git_commit *commit, git_odb_object *obj)
214
213
  }
215
214
 
216
215
  #define GIT_COMMIT_GETTER(_rvalue, _name, _return) \
217
- _rvalue git_commit_##_name(git_commit *commit) \
216
+ _rvalue git_commit_##_name(const git_commit *commit) \
218
217
  {\
219
218
  assert(commit); \
220
219
  return _return; \
@@ -226,34 +225,34 @@ GIT_COMMIT_GETTER(const char *, message, commit->message)
226
225
  GIT_COMMIT_GETTER(const char *, message_encoding, commit->message_encoding)
227
226
  GIT_COMMIT_GETTER(git_time_t, time, commit->committer->when.time)
228
227
  GIT_COMMIT_GETTER(int, time_offset, commit->committer->when.offset)
229
- GIT_COMMIT_GETTER(unsigned int, parentcount, (unsigned int)commit->parent_oids.length)
230
- GIT_COMMIT_GETTER(const git_oid *, tree_oid, &commit->tree_oid);
228
+ GIT_COMMIT_GETTER(unsigned int, parentcount, (unsigned int)commit->parent_ids.length)
229
+ GIT_COMMIT_GETTER(const git_oid *, tree_id, &commit->tree_id);
231
230
 
232
- int git_commit_tree(git_tree **tree_out, git_commit *commit)
231
+ int git_commit_tree(git_tree **tree_out, const git_commit *commit)
233
232
  {
234
233
  assert(commit);
235
- return git_tree_lookup(tree_out, commit->object.repo, &commit->tree_oid);
234
+ return git_tree_lookup(tree_out, commit->object.repo, &commit->tree_id);
236
235
  }
237
236
 
238
- const git_oid *git_commit_parent_oid(git_commit *commit, unsigned int n)
237
+ const git_oid *git_commit_parent_id(git_commit *commit, unsigned int n)
239
238
  {
240
239
  assert(commit);
241
240
 
242
- return git_vector_get(&commit->parent_oids, n);
241
+ return git_vector_get(&commit->parent_ids, n);
243
242
  }
244
243
 
245
244
  int git_commit_parent(git_commit **parent, git_commit *commit, unsigned int n)
246
245
  {
247
- const git_oid *parent_oid;
246
+ const git_oid *parent_id;
248
247
  assert(commit);
249
248
 
250
- parent_oid = git_commit_parent_oid(commit, n);
251
- if (parent_oid == NULL) {
249
+ parent_id = git_commit_parent_id(commit, n);
250
+ if (parent_id == NULL) {
252
251
  giterr_set(GITERR_INVALID, "Parent %u does not exist", n);
253
252
  return GIT_ENOTFOUND;
254
253
  }
255
254
 
256
- return git_commit_lookup(parent, commit->object.repo, parent_oid);
255
+ return git_commit_lookup(parent, commit->object.repo, parent_id);
257
256
  }
258
257
 
259
258
  int git_commit_nth_gen_ancestor(