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
@@ -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.
@@ -10,33 +10,68 @@
10
10
  #include "posix.h"
11
11
  #include "common.h"
12
12
 
13
+ #ifdef GIT_SSL
14
+ # include <openssl/ssl.h>
15
+ #endif
16
+
17
+ struct gitno_ssl {
18
+ #ifdef GIT_SSL
19
+ SSL_CTX *ctx;
20
+ SSL *ssl;
21
+ #else
22
+ size_t dummy;
23
+ #endif
24
+ };
25
+
26
+ typedef struct gitno_ssl gitno_ssl;
27
+
28
+ /* Represents a socket that may or may not be using SSL */
29
+ struct gitno_socket {
30
+ GIT_SOCKET socket;
31
+ gitno_ssl ssl;
32
+ };
33
+
34
+ typedef struct gitno_socket gitno_socket;
35
+
13
36
  struct gitno_buffer {
14
37
  char *data;
15
38
  size_t len;
16
39
  size_t offset;
17
- GIT_SOCKET fd;
18
- #ifdef GIT_SSL
19
- struct gitno_ssl *ssl;
20
- #endif
21
- int (*recv)(gitno_buffer *buffer);
40
+ gitno_socket *socket;
41
+ int (*recv)(struct gitno_buffer *buffer);
22
42
  void *cb_data;
23
43
  };
24
44
 
25
- void gitno_buffer_setup(git_transport *t, gitno_buffer *buf, char *data, size_t len);
26
- void gitno_buffer_setup_callback(git_transport *t, gitno_buffer *buf, char *data, size_t len, int (*recv)(gitno_buffer *buf), void *cb_data);
45
+ typedef struct gitno_buffer gitno_buffer;
46
+
47
+ /* Flags to gitno_connect */
48
+ enum {
49
+ /* Attempt to create an SSL connection. */
50
+ GITNO_CONNECT_SSL = 1,
51
+
52
+ /* Valid only when GITNO_CONNECT_SSL is also specified.
53
+ * Indicates that the server certificate should not be validated. */
54
+ GITNO_CONNECT_SSL_NO_CHECK_CERT = 2,
55
+ };
56
+
57
+ void gitno_buffer_setup(gitno_socket *t, gitno_buffer *buf, char *data, size_t len);
58
+ void gitno_buffer_setup_callback(gitno_socket *t, gitno_buffer *buf, char *data, size_t len, int (*recv)(gitno_buffer *buf), void *cb_data);
27
59
  int gitno_recv(gitno_buffer *buf);
28
- int gitno__recv(gitno_buffer *buf);
29
60
 
30
61
  void gitno_consume(gitno_buffer *buf, const char *ptr);
31
62
  void gitno_consume_n(gitno_buffer *buf, size_t cons);
32
63
 
33
- int gitno_connect(git_transport *t, const char *host, const char *port);
34
- int gitno_send(git_transport *t, const char *msg, size_t len, int flags);
35
- int gitno_close(GIT_SOCKET s);
36
- int gitno_ssl_teardown(git_transport *t);
37
- int gitno_send_chunk_size(int s, size_t len);
64
+ int gitno_connect(gitno_socket *socket, const char *host, const char *port, int flags);
65
+ int gitno_send(gitno_socket *socket, const char *msg, size_t len, int flags);
66
+ int gitno_close(gitno_socket *s);
38
67
  int gitno_select_in(gitno_buffer *buf, long int sec, long int usec);
39
68
 
40
- int gitno_extract_host_and_port(char **host, char **port, const char *url, const char *default_port);
69
+ int gitno_extract_url_parts(
70
+ char **host,
71
+ char **port,
72
+ char **username,
73
+ char **password,
74
+ const char *url,
75
+ const char *default_port);
41
76
 
42
77
  #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.
@@ -11,6 +11,7 @@
11
11
  #include "refs.h"
12
12
  #include "config.h"
13
13
  #include "iterator.h"
14
+ #include "signature.h"
14
15
 
15
16
  static int find_subtree_in_current_level(
16
17
  git_tree **out,
@@ -19,11 +20,11 @@ static int find_subtree_in_current_level(
19
20
  const char *annotated_object_sha,
20
21
  int fanout)
21
22
  {
22
- unsigned int i;
23
+ size_t i;
23
24
  const git_tree_entry *entry;
24
25
 
25
26
  *out = NULL;
26
-
27
+
27
28
  if (parent == NULL)
28
29
  return GIT_ENOTFOUND;
29
30
 
@@ -34,12 +35,12 @@ static int find_subtree_in_current_level(
34
35
  continue;
35
36
 
36
37
  if (S_ISDIR(git_tree_entry_filemode(entry))
37
- && strlen(git_tree_entry_name(entry)) == 2
38
+ && strlen(git_tree_entry_name(entry)) == 2
38
39
  && !strncmp(git_tree_entry_name(entry), annotated_object_sha + fanout, 2))
39
40
  return git_tree_lookup(out, repo, git_tree_entry_id(entry));
40
41
 
41
42
  /* Not a DIR, so do we have an already existing blob? */
42
- if (!strcmp(git_tree_entry_name(entry), annotated_object_sha + fanout))
43
+ if (!strcmp(git_tree_entry_name(entry), annotated_object_sha + fanout))
43
44
  return GIT_EEXISTS;
44
45
  }
45
46
 
@@ -71,7 +72,7 @@ static int find_subtree_r(git_tree **out, git_tree *root,
71
72
 
72
73
  static int find_blob(git_oid *blob, git_tree *tree, const char *target)
73
74
  {
74
- unsigned int i;
75
+ size_t i;
75
76
  const git_tree_entry *entry;
76
77
 
77
78
  for (i=0; i<git_tree_entrycount(tree); i++) {
@@ -128,10 +129,10 @@ static int manipulate_note_in_tree_r(
128
129
  git_tree *parent,
129
130
  git_oid *note_oid,
130
131
  const char *annotated_object_sha,
131
- int fanout,
132
+ int fanout,
132
133
  int (*note_exists_cb)(
133
- git_tree **out,
134
- git_repository *repo,
134
+ git_tree **out,
135
+ git_repository *repo,
135
136
  git_tree *parent,
136
137
  git_oid *note_oid,
137
138
  const char *annotated_object_sha,
@@ -146,7 +147,7 @@ static int manipulate_note_in_tree_r(
146
147
  int fanout,
147
148
  int current_error))
148
149
  {
149
- int error = -1;
150
+ int error;
150
151
  git_tree *subtree = NULL, *new = NULL;
151
152
  char subtree_name[3];
152
153
 
@@ -263,18 +264,19 @@ static int insert_note_in_tree_enotfound_cb(git_tree **out,
263
264
 
264
265
  static int note_write(git_oid *out,
265
266
  git_repository *repo,
266
- git_signature *author,
267
- git_signature *committer,
267
+ const git_signature *author,
268
+ const git_signature *committer,
268
269
  const char *notes_ref,
269
270
  const char *note,
270
271
  git_tree *commit_tree,
271
272
  const char *target,
272
- git_commit **parents)
273
+ git_commit **parents,
274
+ int allow_note_overwrite)
273
275
  {
274
276
  int error;
275
277
  git_oid oid;
276
278
  git_tree *tree = NULL;
277
-
279
+
278
280
  // TODO: should we apply filters?
279
281
  /* create note object */
280
282
  if ((error = git_blob_create_frombuffer(&oid, repo, note, strlen(note))) < 0)
@@ -282,7 +284,8 @@ static int note_write(git_oid *out,
282
284
 
283
285
  if ((error = manipulate_note_in_tree_r(
284
286
  &tree, repo, commit_tree, &oid, target, 0,
285
- insert_note_in_tree_eexists_cb, insert_note_in_tree_enotfound_cb)) < 0)
287
+ allow_note_overwrite ? insert_note_in_tree_enotfound_cb : insert_note_in_tree_eexists_cb,
288
+ insert_note_in_tree_enotfound_cb)) < 0)
286
289
  goto cleanup;
287
290
 
288
291
  if (out)
@@ -343,14 +346,14 @@ cleanup:
343
346
  }
344
347
 
345
348
  static int note_remove(git_repository *repo,
346
- git_signature *author, git_signature *committer,
347
- const char *notes_ref, git_tree *tree,
348
- const char *target, git_commit **parents)
349
+ const git_signature *author, const git_signature *committer,
350
+ const char *notes_ref, git_tree *tree,
351
+ const char *target, git_commit **parents)
349
352
  {
350
353
  int error;
351
354
  git_tree *tree_after_removal = NULL;
352
355
  git_oid oid;
353
-
356
+
354
357
  if ((error = manipulate_note_in_tree_r(
355
358
  &tree_after_removal, repo, tree, NULL, target, 0,
356
359
  remove_note_in_tree_eexists_cb, remove_note_in_tree_enotfound_cb)) < 0)
@@ -406,7 +409,7 @@ static int retrieve_note_tree_and_commit(
406
409
  if ((error = normalize_namespace(notes_ref, repo)) < 0)
407
410
  return error;
408
411
 
409
- if ((error = git_reference_name_to_oid(&oid, repo, *notes_ref)) < 0)
412
+ if ((error = git_reference_name_to_id(&oid, repo, *notes_ref)) < 0)
410
413
  return error;
411
414
 
412
415
  if (git_commit_lookup(commit_out, repo, &oid) < 0)
@@ -442,10 +445,14 @@ cleanup:
442
445
  }
443
446
 
444
447
  int git_note_create(
445
- git_oid *out, git_repository *repo,
446
- git_signature *author, git_signature *committer,
447
- const char *notes_ref, const git_oid *oid,
448
- const char *note)
448
+ git_oid *out,
449
+ git_repository *repo,
450
+ const git_signature *author,
451
+ const git_signature *committer,
452
+ const char *notes_ref,
453
+ const git_oid *oid,
454
+ const char *note,
455
+ int allow_note_overwrite)
449
456
  {
450
457
  int error;
451
458
  char *target = NULL;
@@ -461,7 +468,7 @@ int git_note_create(
461
468
  goto cleanup;
462
469
 
463
470
  error = note_write(out, repo, author, committer, notes_ref,
464
- note, tree, target, &commit);
471
+ note, tree, target, &commit, allow_note_overwrite);
465
472
 
466
473
  cleanup:
467
474
  git__free(target);
@@ -471,8 +478,8 @@ cleanup:
471
478
  }
472
479
 
473
480
  int git_note_remove(git_repository *repo, const char *notes_ref,
474
- git_signature *author, git_signature *committer,
475
- const git_oid *oid)
481
+ const git_signature *author, const git_signature *committer,
482
+ const git_oid *oid)
476
483
  {
477
484
  int error;
478
485
  char *target = NULL;
@@ -501,13 +508,13 @@ int git_note_default_ref(const char **out, git_repository *repo)
501
508
  return note_get_default_ref(out, repo);
502
509
  }
503
510
 
504
- const char * git_note_message(git_note *note)
511
+ const char * git_note_message(const git_note *note)
505
512
  {
506
513
  assert(note);
507
514
  return note->message;
508
515
  }
509
516
 
510
- const git_oid * git_note_oid(git_note *note)
517
+ const git_oid * git_note_oid(const git_note *note)
511
518
  {
512
519
  assert(note);
513
520
  return &note->oid;
@@ -524,14 +531,11 @@ void git_note_free(git_note *note)
524
531
 
525
532
  static int process_entry_path(
526
533
  const char* entry_path,
527
- const git_oid *note_oid,
528
- int (*note_cb)(git_note_data *note_data, void *payload),
529
- void *payload)
534
+ git_oid *annotated_object_id)
530
535
  {
531
536
  int error = -1;
532
537
  size_t i = 0, j = 0, len;
533
538
  git_buf buf = GIT_BUF_INIT;
534
- git_note_data note_data;
535
539
 
536
540
  if ((error = git_buf_puts(&buf, entry_path)) < 0)
537
541
  goto cleanup;
@@ -564,14 +568,7 @@ static int process_entry_path(
564
568
  goto cleanup;
565
569
  }
566
570
 
567
- if ((error = git_oid_fromstr(
568
- &note_data.annotated_object_oid, buf.ptr)) < 0)
569
- goto cleanup;
570
-
571
- git_oid_cpy(&note_data.blob_oid, note_oid);
572
-
573
- if (note_cb(&note_data, payload))
574
- error = GIT_EUSER;
571
+ error = git_oid_fromstr(annotated_object_id, buf.ptr);
575
572
 
576
573
  cleanup:
577
574
  git_buf_free(&buf);
@@ -579,32 +576,86 @@ cleanup:
579
576
  }
580
577
 
581
578
  int git_note_foreach(
579
+ git_repository *repo,
580
+ const char *notes_ref,
581
+ git_note_foreach_cb note_cb,
582
+ void *payload)
583
+ {
584
+ int error;
585
+ git_note_iterator *iter = NULL;
586
+ git_oid note_id, annotated_id;
587
+
588
+ if ((error = git_note_iterator_new(&iter, repo, notes_ref)) < 0)
589
+ return error;
590
+
591
+ while (!(error = git_note_next(&note_id, &annotated_id, iter))) {
592
+ if (note_cb(&note_id, &annotated_id, payload)) {
593
+ error = GIT_EUSER;
594
+ break;
595
+ }
596
+ }
597
+
598
+ if (error == GIT_ITEROVER)
599
+ error = 0;
600
+
601
+ git_note_iterator_free(iter);
602
+ return error;
603
+ }
604
+
605
+
606
+ void git_note_iterator_free(git_note_iterator *it)
607
+ {
608
+ if (it == NULL)
609
+ return;
610
+
611
+ git_iterator_free(it);
612
+ }
613
+
614
+
615
+ int git_note_iterator_new(
616
+ git_note_iterator **it,
582
617
  git_repository *repo,
583
- const char *notes_ref,
584
- int (*note_cb)(git_note_data *note_data, void *payload),
585
- void *payload)
618
+ const char *notes_ref)
586
619
  {
587
620
  int error;
588
- git_iterator *iter = NULL;
589
- git_tree *tree = NULL;
590
621
  git_commit *commit = NULL;
591
- const git_index_entry *item;
592
-
593
- if (!(error = retrieve_note_tree_and_commit(
594
- &tree, &commit, repo, &notes_ref)) &&
595
- !(error = git_iterator_for_tree(&iter, repo, tree)))
596
- error = git_iterator_current(iter, &item);
622
+ git_tree *tree = NULL;
597
623
 
598
- while (!error && item) {
599
- error = process_entry_path(item->path, &item->oid, note_cb, payload);
624
+ error = retrieve_note_tree_and_commit(&tree, &commit, repo, &notes_ref);
625
+ if (error < 0)
626
+ goto cleanup;
600
627
 
601
- if (!error)
602
- error = git_iterator_advance(iter, &item);
603
- }
628
+ if ((error = git_iterator_for_tree(it, tree, 0, NULL, NULL)) < 0)
629
+ git_iterator_free(*it);
604
630
 
605
- git_iterator_free(iter);
631
+ cleanup:
606
632
  git_tree_free(tree);
607
633
  git_commit_free(commit);
608
634
 
609
635
  return error;
610
636
  }
637
+
638
+ int git_note_next(
639
+ git_oid* note_id,
640
+ git_oid* annotated_id,
641
+ git_note_iterator *it)
642
+ {
643
+ int error;
644
+ const git_index_entry *item;
645
+
646
+ if ((error = git_iterator_current(&item, it)) < 0)
647
+ goto exit;
648
+
649
+ if (item != NULL) {
650
+ git_oid_cpy(note_id, &item->oid);
651
+ error = process_entry_path(item->path, annotated_id);
652
+
653
+ if (error >= 0)
654
+ error = git_iterator_advance(NULL, it);
655
+ } else {
656
+ error = GIT_ITEROVER;
657
+ }
658
+
659
+ exit:
660
+ return error;
661
+ }
@@ -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.
@@ -10,6 +10,7 @@
10
10
  #include "common.h"
11
11
 
12
12
  #include "git2/oid.h"
13
+ #include "git2/types.h"
13
14
 
14
15
  #define GIT_NOTES_DEFAULT_REF "refs/notes/commits"
15
16
 
@@ -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.
@@ -87,7 +87,7 @@ int git_object__from_odb_object(
87
87
  git_object *object = NULL;
88
88
 
89
89
  if (type != GIT_OBJ_ANY && type != odb_obj->raw.type) {
90
- giterr_set(GITERR_ODB, "The requested type does not match the type in the ODB");
90
+ giterr_set(GITERR_INVALID, "The requested type does not match the type in the ODB");
91
91
  return GIT_ENOTFOUND;
92
92
  }
93
93
 
@@ -161,7 +161,7 @@ int git_object_lookup_prefix(
161
161
  if (object != NULL) {
162
162
  if (type != GIT_OBJ_ANY && type != object->type) {
163
163
  git_object_free(object);
164
- giterr_set(GITERR_ODB, "The given type does not match the type in ODB");
164
+ giterr_set(GITERR_INVALID, "The requested type does not match the type in ODB");
165
165
  return GIT_ENOTFOUND;
166
166
  }
167
167
 
@@ -304,52 +304,6 @@ size_t git_object__size(git_otype type)
304
304
  return git_objects_table[type].size;
305
305
  }
306
306
 
307
- int git_object__resolve_to_type(git_object **obj, git_otype type)
308
- {
309
- int error = 0;
310
- git_object *scan, *next;
311
-
312
- if (type == GIT_OBJ_ANY)
313
- return 0;
314
-
315
- scan = *obj;
316
-
317
- while (!error && scan && git_object_type(scan) != type) {
318
-
319
- switch (git_object_type(scan)) {
320
- case GIT_OBJ_COMMIT:
321
- {
322
- git_tree *tree = NULL;
323
- error = git_commit_tree(&tree, (git_commit *)scan);
324
- next = (git_object *)tree;
325
- break;
326
- }
327
-
328
- case GIT_OBJ_TAG:
329
- error = git_tag_target(&next, (git_tag *)scan);
330
- break;
331
-
332
- default:
333
- giterr_set(GITERR_REFERENCE, "Object does not resolve to type");
334
- error = -1;
335
- next = NULL;
336
- break;
337
- }
338
-
339
- git_object_free(scan);
340
- scan = next;
341
- }
342
-
343
- *obj = scan;
344
- return error;
345
- }
346
-
347
- static int peel_error(int error, const char* msg)
348
- {
349
- giterr_set(GITERR_INVALID, "The given object cannot be peeled - %s", msg);
350
- return error;
351
- }
352
-
353
307
  static int dereference_object(git_object **dereferenced, git_object *obj)
354
308
  {
355
309
  git_otype type = git_object_type(obj);
@@ -362,31 +316,55 @@ static int dereference_object(git_object **dereferenced, git_object *obj)
362
316
  return git_tag_target(dereferenced, (git_tag*)obj);
363
317
 
364
318
  case GIT_OBJ_BLOB:
365
- return peel_error(GIT_ERROR, "cannot dereference blob");
319
+ return GIT_ENOTFOUND;
366
320
 
367
321
  case GIT_OBJ_TREE:
368
- return peel_error(GIT_ERROR, "cannot dereference tree");
322
+ return GIT_EAMBIGUOUS;
369
323
 
370
324
  default:
371
- return peel_error(GIT_ENOTFOUND, "unexpected object type encountered");
325
+ return GIT_EINVALIDSPEC;
372
326
  }
373
327
  }
374
328
 
329
+ static int peel_error(int error, const git_oid *oid, git_otype type)
330
+ {
331
+ const char *type_name;
332
+ char hex_oid[GIT_OID_HEXSZ + 1];
333
+
334
+ type_name = git_object_type2string(type);
335
+
336
+ git_oid_fmt(hex_oid, oid);
337
+ hex_oid[GIT_OID_HEXSZ] = '\0';
338
+
339
+ giterr_set(GITERR_OBJECT, "The git_object of id '%s' can not be "
340
+ "successfully peeled into a %s (git_otype=%i).", hex_oid, type_name, type);
341
+
342
+ return error;
343
+ }
344
+
375
345
  int git_object_peel(
376
346
  git_object **peeled,
377
- git_object *object,
347
+ const git_object *object,
378
348
  git_otype target_type)
379
349
  {
380
350
  git_object *source, *deref = NULL;
351
+ int error;
352
+
353
+ if (target_type != GIT_OBJ_TAG &&
354
+ target_type != GIT_OBJ_COMMIT &&
355
+ target_type != GIT_OBJ_TREE &&
356
+ target_type != GIT_OBJ_BLOB &&
357
+ target_type != GIT_OBJ_ANY)
358
+ return GIT_EINVALIDSPEC;
381
359
 
382
360
  assert(object && peeled);
383
361
 
384
362
  if (git_object_type(object) == target_type)
385
- return git_object__dup(peeled, object);
363
+ return git_object_dup(peeled, (git_object *)object);
386
364
 
387
- source = object;
365
+ source = (git_object *)object;
388
366
 
389
- while (!dereference_object(&deref, source)) {
367
+ while (!(error = dereference_object(&deref, source))) {
390
368
 
391
369
  if (source != object)
392
370
  git_object_free(source);
@@ -411,5 +389,16 @@ int git_object_peel(
411
389
  git_object_free(source);
412
390
 
413
391
  git_object_free(deref);
414
- return -1;
392
+
393
+ if (error)
394
+ error = peel_error(error, git_object_id(object), target_type);
395
+
396
+ return error;
397
+ }
398
+
399
+ int git_object_dup(git_object **dest, git_object *source)
400
+ {
401
+ git_cached_obj_incref(source);
402
+ *dest = source;
403
+ return 0;
415
404
  }