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
@@ -10,6 +10,10 @@ struct git_pool_page {
10
10
  char data[GIT_FLEX_ARRAY];
11
11
  };
12
12
 
13
+ struct pool_freelist {
14
+ struct pool_freelist *next;
15
+ };
16
+
13
17
  #define GIT_POOL_MIN_USABLE 4
14
18
  #define GIT_POOL_MIN_PAGESZ 2 * sizeof(void*)
15
19
 
@@ -150,7 +154,7 @@ void *git_pool_malloc(git_pool *pool, uint32_t items)
150
154
  pool->has_multi_item_alloc = 1;
151
155
  else if (pool->free_list != NULL) {
152
156
  ptr = pool->free_list;
153
- pool->free_list = *((void **)pool->free_list);
157
+ pool->free_list = ((struct pool_freelist *)pool->free_list)->next;
154
158
  return ptr;
155
159
  }
156
160
 
@@ -235,10 +239,31 @@ char *git_pool_strcat(git_pool *pool, const char *a, const char *b)
235
239
 
236
240
  void git_pool_free(git_pool *pool, void *ptr)
237
241
  {
238
- assert(pool && ptr && pool->item_size >= sizeof(void*));
242
+ struct pool_freelist *item = ptr;
243
+
244
+ assert(pool && pool->item_size >= sizeof(void*));
245
+
246
+ if (item) {
247
+ item->next = pool->free_list;
248
+ pool->free_list = item;
249
+ }
250
+ }
251
+
252
+ void git_pool_free_array(git_pool *pool, size_t count, void **ptrs)
253
+ {
254
+ struct pool_freelist **items = (struct pool_freelist **)ptrs;
255
+ size_t i;
256
+
257
+ assert(pool && ptrs && pool->item_size >= sizeof(void*));
258
+
259
+ if (!count)
260
+ return;
261
+
262
+ for (i = count - 1; i > 0; --i)
263
+ items[i]->next = items[i - 1];
239
264
 
240
- *((void **)ptr) = pool->free_list;
241
- pool->free_list = ptr;
265
+ items[i]->next = pool->free_list;
266
+ pool->free_list = items[count - 1];
242
267
  }
243
268
 
244
269
  uint32_t git_pool__open_pages(git_pool *pool)
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright (C) 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.
@@ -126,6 +126,13 @@ extern char *git_pool_strcat(git_pool *pool, const char *a, const char *b);
126
126
  */
127
127
  extern void git_pool_free(git_pool *pool, void *ptr);
128
128
 
129
+ /**
130
+ * Push an array of pool allocated blocks efficiently onto the free list.
131
+ *
132
+ * This has the same constraints as `git_pool_free()` above.
133
+ */
134
+ extern void git_pool_free_array(git_pool *pool, size_t count, void **ptrs);
135
+
129
136
  /*
130
137
  * Misc utilities
131
138
  */
@@ -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.
@@ -13,25 +13,28 @@
13
13
  #ifndef GIT_WIN32
14
14
 
15
15
  #ifdef NO_ADDRINFO
16
+
16
17
  int p_getaddrinfo(
17
18
  const char *host,
18
19
  const char *port,
19
20
  struct addrinfo *hints,
20
21
  struct addrinfo **info)
21
22
  {
22
- GIT_UNUSED(hints);
23
-
24
23
  struct addrinfo *ainfo, *ai;
25
24
  int p = 0;
26
-
25
+
26
+ GIT_UNUSED(hints);
27
+
27
28
  if ((ainfo = malloc(sizeof(struct addrinfo))) == NULL)
28
29
  return -1;
29
-
30
- if ((ainfo->ai_hostent = gethostbyname(host)) == NULL)
30
+
31
+ if ((ainfo->ai_hostent = gethostbyname(host)) == NULL) {
32
+ free(ainfo);
31
33
  return -2;
32
-
34
+ }
35
+
33
36
  ainfo->ai_servent = getservbyname(port, 0);
34
-
37
+
35
38
  if (ainfo->ai_servent)
36
39
  ainfo->ai_port = ainfo->ai_servent->s_port;
37
40
  else
@@ -50,14 +53,14 @@ int p_getaddrinfo(
50
53
  ainfo->ai_addrlen = sizeof(struct sockaddr_in);
51
54
 
52
55
  *info = ainfo;
53
-
56
+
54
57
  if (ainfo->ai_hostent->h_addr_list[1] == NULL) {
55
58
  ainfo->ai_next = NULL;
56
59
  return 0;
57
60
  }
58
-
61
+
59
62
  ai = ainfo;
60
-
63
+
61
64
  for (p = 1; ainfo->ai_hostent->h_addr_list[p] != NULL; p++) {
62
65
  ai->ai_next = malloc(sizeof(struct addrinfo));
63
66
  memcpy(&ai->ai_next, ainfo, sizeof(struct addrinfo));
@@ -67,7 +70,7 @@ int p_getaddrinfo(
67
70
  ai->ai_next->ai_addr = (struct addrinfo *)&ai->ai_next->ai_addr_in;
68
71
  ai = ai->ai_next;
69
72
  }
70
-
73
+
71
74
  ai->ai_next = NULL;
72
75
  return 0;
73
76
  }
@@ -75,9 +78,9 @@ int p_getaddrinfo(
75
78
  void p_freeaddrinfo(struct addrinfo *info)
76
79
  {
77
80
  struct addrinfo *p, *next;
78
-
81
+
79
82
  p = info;
80
-
83
+
81
84
  while(p != NULL) {
82
85
  next = p->ai_next;
83
86
  free(p);
@@ -88,27 +91,19 @@ void p_freeaddrinfo(struct addrinfo *info)
88
91
  const char *p_gai_strerror(int ret)
89
92
  {
90
93
  switch(ret) {
91
- case -1:
92
- return "Out of memory";
93
- break;
94
-
95
- case -2:
96
- return "Address lookup failed";
97
- break;
98
-
99
- default:
100
- return "Unknown error";
101
- break;
94
+ case -1: return "Out of memory"; break;
95
+ case -2: return "Address lookup failed"; break;
96
+ default: return "Unknown error"; break;
102
97
  }
103
98
  }
99
+
104
100
  #endif /* NO_ADDRINFO */
105
101
 
106
102
  int p_open(const char *path, int flags, ...)
107
103
  {
108
104
  mode_t mode = 0;
109
105
 
110
- if (flags & O_CREAT)
111
- {
106
+ if (flags & O_CREAT) {
112
107
  va_list arg_list;
113
108
 
114
109
  va_start(arg_list, flags);
@@ -159,6 +154,7 @@ int p_rename(const char *from, const char *to)
159
154
  int p_read(git_file fd, void *buf, size_t cnt)
160
155
  {
161
156
  char *b = buf;
157
+
162
158
  while (cnt) {
163
159
  ssize_t r;
164
160
  #ifdef GIT_WIN32
@@ -183,6 +179,7 @@ int p_read(git_file fd, void *buf, size_t cnt)
183
179
  int p_write(git_file fd, const void *buf, size_t cnt)
184
180
  {
185
181
  const char *b = buf;
182
+
186
183
  while (cnt) {
187
184
  ssize_t r;
188
185
  #ifdef GIT_WIN32
@@ -205,3 +202,5 @@ int p_write(git_file fd, const void *buf, size_t cnt)
205
202
  }
206
203
  return 0;
207
204
  }
205
+
206
+
@@ -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.
@@ -32,14 +32,13 @@ typedef int git_file;
32
32
  * Standard POSIX Methods
33
33
  *
34
34
  * All the methods starting with the `p_` prefix are
35
- * direct ports of the standard POSIX methods.
35
+ * direct ports of the standard POSIX methods.
36
36
  *
37
37
  * Some of the methods are slightly wrapped to provide
38
38
  * saner defaults. Some of these methods are emulated
39
39
  * in Windows platforns.
40
40
  *
41
41
  * Use your manpages to check the docs on these.
42
- * Straightforward
43
42
  */
44
43
 
45
44
  extern int p_read(git_file fd, void *buf, size_t cnt);
@@ -1,8 +1,30 @@
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.
6
+ *
7
+ * This file is based on a modified version of the priority queue found
8
+ * in the Apache project and libpqueue library.
9
+ *
10
+ * https://github.com/vy/libpqueue
11
+ *
12
+ * Original file notice:
13
+ *
14
+ * Copyright 2010 Volkan Yazici <volkan.yazici@gmail.com>
15
+ * Copyright 2006-2010 The Apache Software Foundation
16
+ *
17
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
18
+ * use this file except in compliance with the License. You may obtain a copy of
19
+ * the License at
20
+ *
21
+ * http://www.apache.org/licenses/LICENSE-2.0
22
+ *
23
+ * Unless required by applicable law or agreed to in writing, software
24
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
25
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
26
+ * License for the specific language governing permissions and limitations under
27
+ * the License.
6
28
  */
7
29
 
8
30
  #include "common.h"
@@ -1,8 +1,30 @@
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.
6
+ *
7
+ * This file is based on a modified version of the priority queue found
8
+ * in the Apache project and libpqueue library.
9
+ *
10
+ * https://github.com/vy/libpqueue
11
+ *
12
+ * Original file notice:
13
+ *
14
+ * Copyright 2010 Volkan Yazici <volkan.yazici@gmail.com>
15
+ * Copyright 2006-2010 The Apache Software Foundation
16
+ *
17
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
18
+ * use this file except in compliance with the License. You may obtain a copy of
19
+ * the License at
20
+ *
21
+ * http://www.apache.org/licenses/LICENSE-2.0
22
+ *
23
+ * Unless required by applicable law or agreed to in writing, software
24
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
25
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
26
+ * License for the specific language governing permissions and limitations under
27
+ * the License.
6
28
  */
7
29
 
8
30
  #ifndef INCLUDE_pqueue_h__
@@ -0,0 +1,653 @@
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
+
8
+ #include "git2.h"
9
+
10
+ #include "common.h"
11
+ #include "pack.h"
12
+ #include "pack-objects.h"
13
+ #include "remote.h"
14
+ #include "vector.h"
15
+ #include "push.h"
16
+ #include "tree.h"
17
+
18
+ static int push_spec_rref_cmp(const void *a, const void *b)
19
+ {
20
+ const push_spec *push_spec_a = a, *push_spec_b = b;
21
+
22
+ return strcmp(push_spec_a->rref, push_spec_b->rref);
23
+ }
24
+
25
+ static int push_status_ref_cmp(const void *a, const void *b)
26
+ {
27
+ const push_status *push_status_a = a, *push_status_b = b;
28
+
29
+ return strcmp(push_status_a->ref, push_status_b->ref);
30
+ }
31
+
32
+ int git_push_new(git_push **out, git_remote *remote)
33
+ {
34
+ git_push *p;
35
+
36
+ *out = NULL;
37
+
38
+ p = git__calloc(1, sizeof(*p));
39
+ GITERR_CHECK_ALLOC(p);
40
+
41
+ p->repo = remote->repo;
42
+ p->remote = remote;
43
+ p->report_status = 1;
44
+ p->pb_parallelism = 1;
45
+
46
+ if (git_vector_init(&p->specs, 0, push_spec_rref_cmp) < 0) {
47
+ git__free(p);
48
+ return -1;
49
+ }
50
+
51
+ if (git_vector_init(&p->status, 0, push_status_ref_cmp) < 0) {
52
+ git_vector_free(&p->specs);
53
+ git__free(p);
54
+ return -1;
55
+ }
56
+
57
+ *out = p;
58
+ return 0;
59
+ }
60
+
61
+ int git_push_set_options(git_push *push, const git_push_options *opts)
62
+ {
63
+ if (!push || !opts)
64
+ return -1;
65
+
66
+ GITERR_CHECK_VERSION(opts, GIT_PUSH_OPTIONS_VERSION, "git_push_options");
67
+
68
+ push->pb_parallelism = opts->pb_parallelism;
69
+
70
+ return 0;
71
+ }
72
+
73
+ static void free_refspec(push_spec *spec)
74
+ {
75
+ if (spec == NULL)
76
+ return;
77
+
78
+ if (spec->lref)
79
+ git__free(spec->lref);
80
+
81
+ if (spec->rref)
82
+ git__free(spec->rref);
83
+
84
+ git__free(spec);
85
+ }
86
+
87
+ static int check_rref(char *ref)
88
+ {
89
+ if (git__prefixcmp(ref, "refs/")) {
90
+ giterr_set(GITERR_INVALID, "Not a valid reference '%s'", ref);
91
+ return -1;
92
+ }
93
+
94
+ return 0;
95
+ }
96
+
97
+ static int check_lref(git_push *push, char *ref)
98
+ {
99
+ /* lref must be resolvable to an existing object */
100
+ git_object *obj;
101
+ int error = git_revparse_single(&obj, push->repo, ref);
102
+ git_object_free(obj);
103
+
104
+ if (!error)
105
+ return 0;
106
+
107
+ if (error == GIT_ENOTFOUND)
108
+ giterr_set(GITERR_REFERENCE,
109
+ "src refspec '%s' does not match any existing object", ref);
110
+ else
111
+ giterr_set(GITERR_INVALID, "Not a valid reference '%s'", ref);
112
+ return -1;
113
+ }
114
+
115
+ static int parse_refspec(git_push *push, push_spec **spec, const char *str)
116
+ {
117
+ push_spec *s;
118
+ char *delim;
119
+
120
+ *spec = NULL;
121
+
122
+ s = git__calloc(1, sizeof(*s));
123
+ GITERR_CHECK_ALLOC(s);
124
+
125
+ if (str[0] == '+') {
126
+ s->force = true;
127
+ str++;
128
+ }
129
+
130
+ delim = strchr(str, ':');
131
+ if (delim == NULL) {
132
+ s->lref = git__strdup(str);
133
+ if (!s->lref || check_lref(push, s->lref) < 0)
134
+ goto on_error;
135
+ } else {
136
+ if (delim - str) {
137
+ s->lref = git__strndup(str, delim - str);
138
+ if (!s->lref || check_lref(push, s->lref) < 0)
139
+ goto on_error;
140
+ }
141
+
142
+ if (strlen(delim + 1)) {
143
+ s->rref = git__strdup(delim + 1);
144
+ if (!s->rref || check_rref(s->rref) < 0)
145
+ goto on_error;
146
+ }
147
+ }
148
+
149
+ if (!s->lref && !s->rref)
150
+ goto on_error;
151
+
152
+ /* If rref is ommitted, use the same ref name as lref */
153
+ if (!s->rref) {
154
+ s->rref = git__strdup(s->lref);
155
+ if (!s->rref || check_rref(s->rref) < 0)
156
+ goto on_error;
157
+ }
158
+
159
+ *spec = s;
160
+ return 0;
161
+
162
+ on_error:
163
+ free_refspec(s);
164
+ return -1;
165
+ }
166
+
167
+ int git_push_add_refspec(git_push *push, const char *refspec)
168
+ {
169
+ push_spec *spec;
170
+
171
+ if (parse_refspec(push, &spec, refspec) < 0 ||
172
+ git_vector_insert(&push->specs, spec) < 0)
173
+ return -1;
174
+
175
+ return 0;
176
+ }
177
+
178
+ int git_push_update_tips(git_push *push)
179
+ {
180
+ git_refspec *fetch_spec = &push->remote->fetch;
181
+ git_buf remote_ref_name = GIT_BUF_INIT;
182
+ size_t i, j;
183
+ push_spec *push_spec;
184
+ git_reference *remote_ref;
185
+ push_status *status;
186
+ int error = 0;
187
+
188
+ git_vector_foreach(&push->status, i, status) {
189
+ /* If this ref update was successful (ok, not ng), it will have an empty message */
190
+ if (status->msg)
191
+ continue;
192
+
193
+ /* Find the corresponding remote ref */
194
+ if (!git_refspec_src_matches(fetch_spec, status->ref))
195
+ continue;
196
+
197
+ if ((error = git_refspec_transform_r(&remote_ref_name, fetch_spec, status->ref)) < 0)
198
+ goto on_error;
199
+
200
+ /* Find matching push ref spec */
201
+ git_vector_foreach(&push->specs, j, push_spec) {
202
+ if (!strcmp(push_spec->rref, status->ref))
203
+ break;
204
+ }
205
+
206
+ /* Could not find the corresponding push ref spec for this push update */
207
+ if (j == push->specs.length)
208
+ continue;
209
+
210
+ /* Update the remote ref */
211
+ if (git_oid_iszero(&push_spec->loid)) {
212
+ error = git_reference_lookup(&remote_ref, push->remote->repo, git_buf_cstr(&remote_ref_name));
213
+
214
+ if (!error) {
215
+ if ((error = git_reference_delete(remote_ref)) < 0) {
216
+ git_reference_free(remote_ref);
217
+ goto on_error;
218
+ }
219
+ git_reference_free(remote_ref);
220
+ } else if (error == GIT_ENOTFOUND)
221
+ giterr_clear();
222
+ else
223
+ goto on_error;
224
+ } else if ((error = git_reference_create(NULL, push->remote->repo, git_buf_cstr(&remote_ref_name), &push_spec->loid, 1)) < 0)
225
+ goto on_error;
226
+ }
227
+
228
+ error = 0;
229
+
230
+ on_error:
231
+ git_buf_free(&remote_ref_name);
232
+ return error;
233
+ }
234
+
235
+ static int revwalk(git_vector *commits, git_push *push)
236
+ {
237
+ git_remote_head *head;
238
+ push_spec *spec;
239
+ git_revwalk *rw;
240
+ git_oid oid;
241
+ unsigned int i;
242
+ int error = -1;
243
+
244
+ if (git_revwalk_new(&rw, push->repo) < 0)
245
+ return -1;
246
+
247
+ git_revwalk_sorting(rw, GIT_SORT_TIME);
248
+
249
+ git_vector_foreach(&push->specs, i, spec) {
250
+ git_otype type;
251
+ size_t size;
252
+
253
+ if (git_oid_iszero(&spec->loid))
254
+ /*
255
+ * Delete reference on remote side;
256
+ * nothing to do here.
257
+ */
258
+ continue;
259
+
260
+ if (git_oid_equal(&spec->loid, &spec->roid))
261
+ continue; /* up-to-date */
262
+
263
+ if (git_odb_read_header(&size, &type, push->repo->_odb, &spec->loid) < 0)
264
+ goto on_error;
265
+
266
+ if (type == GIT_OBJ_TAG) {
267
+ git_tag *tag;
268
+ git_object *target;
269
+
270
+ if (git_packbuilder_insert(push->pb, &spec->loid, NULL) < 0)
271
+ goto on_error;
272
+
273
+ if (git_tag_lookup(&tag, push->repo, &spec->loid) < 0)
274
+ goto on_error;
275
+
276
+ if (git_tag_peel(&target, tag) < 0) {
277
+ git_tag_free(tag);
278
+ goto on_error;
279
+ }
280
+ git_tag_free(tag);
281
+
282
+ if (git_object_type(target) == GIT_OBJ_COMMIT) {
283
+ if (git_revwalk_push(rw, git_object_id(target)) < 0) {
284
+ git_object_free(target);
285
+ goto on_error;
286
+ }
287
+ } else {
288
+ if (git_packbuilder_insert(
289
+ push->pb, git_object_id(target), NULL) < 0) {
290
+ git_object_free(target);
291
+ goto on_error;
292
+ }
293
+ }
294
+ git_object_free(target);
295
+ } else if (git_revwalk_push(rw, &spec->loid) < 0)
296
+ goto on_error;
297
+
298
+ if (!spec->force) {
299
+ git_oid base;
300
+
301
+ if (git_oid_iszero(&spec->roid))
302
+ continue;
303
+
304
+ if (!git_odb_exists(push->repo->_odb, &spec->roid)) {
305
+ giterr_clear();
306
+ error = GIT_ENONFASTFORWARD;
307
+ goto on_error;
308
+ }
309
+
310
+ error = git_merge_base(&base, push->repo,
311
+ &spec->loid, &spec->roid);
312
+
313
+ if (error == GIT_ENOTFOUND ||
314
+ (!error && !git_oid_equal(&base, &spec->roid))) {
315
+ giterr_clear();
316
+ error = GIT_ENONFASTFORWARD;
317
+ goto on_error;
318
+ }
319
+
320
+ if (error < 0)
321
+ goto on_error;
322
+ }
323
+ }
324
+
325
+ git_vector_foreach(&push->remote->refs, i, head) {
326
+ if (git_oid_iszero(&head->oid))
327
+ continue;
328
+
329
+ /* TODO */
330
+ git_revwalk_hide(rw, &head->oid);
331
+ }
332
+
333
+ while ((error = git_revwalk_next(&oid, rw)) == 0) {
334
+ git_oid *o = git__malloc(GIT_OID_RAWSZ);
335
+ GITERR_CHECK_ALLOC(o);
336
+ git_oid_cpy(o, &oid);
337
+ if (git_vector_insert(commits, o) < 0) {
338
+ error = -1;
339
+ goto on_error;
340
+ }
341
+ }
342
+
343
+ on_error:
344
+ git_revwalk_free(rw);
345
+ return error == GIT_ITEROVER ? 0 : error;
346
+ }
347
+
348
+ static int enqueue_object(
349
+ const git_tree_entry *entry,
350
+ git_packbuilder *pb)
351
+ {
352
+ switch (git_tree_entry_type(entry)) {
353
+ case GIT_OBJ_COMMIT:
354
+ return 0;
355
+ case GIT_OBJ_TREE:
356
+ return git_packbuilder_insert_tree(pb, &entry->oid);
357
+ default:
358
+ return git_packbuilder_insert(pb, &entry->oid, entry->filename);
359
+ }
360
+ }
361
+
362
+ static int queue_differences(
363
+ git_tree *base,
364
+ git_tree *delta,
365
+ git_packbuilder *pb)
366
+ {
367
+ git_tree *b_child = NULL, *d_child = NULL;
368
+ size_t b_length = git_tree_entrycount(base);
369
+ size_t d_length = git_tree_entrycount(delta);
370
+ size_t i = 0, j = 0;
371
+ int error;
372
+
373
+ while (i < b_length && j < d_length) {
374
+ const git_tree_entry *b_entry = git_tree_entry_byindex(base, i);
375
+ const git_tree_entry *d_entry = git_tree_entry_byindex(delta, j);
376
+ int cmp = 0;
377
+
378
+ if (!git_oid_cmp(&b_entry->oid, &d_entry->oid))
379
+ goto loop;
380
+
381
+ cmp = strcmp(b_entry->filename, d_entry->filename);
382
+
383
+ /* If the entries are both trees and they have the same name but are
384
+ * different, then we'll recurse after adding the right-hand entry */
385
+ if (!cmp &&
386
+ git_tree_entry__is_tree(b_entry) &&
387
+ git_tree_entry__is_tree(d_entry)) {
388
+ /* Add the right-hand entry */
389
+ if ((error = git_packbuilder_insert(pb, &d_entry->oid,
390
+ d_entry->filename)) < 0)
391
+ goto on_error;
392
+
393
+ /* Acquire the subtrees and recurse */
394
+ if ((error = git_tree_lookup(&b_child,
395
+ git_tree_owner(base), &b_entry->oid)) < 0 ||
396
+ (error = git_tree_lookup(&d_child,
397
+ git_tree_owner(delta), &d_entry->oid)) < 0 ||
398
+ (error = queue_differences(b_child, d_child, pb)) < 0)
399
+ goto on_error;
400
+
401
+ git_tree_free(b_child); b_child = NULL;
402
+ git_tree_free(d_child); d_child = NULL;
403
+ }
404
+ /* If the object is new or different in the right-hand tree,
405
+ * then enumerate it */
406
+ else if (cmp >= 0 &&
407
+ (error = enqueue_object(d_entry, pb)) < 0)
408
+ goto on_error;
409
+
410
+ loop:
411
+ if (cmp <= 0) i++;
412
+ if (cmp >= 0) j++;
413
+ }
414
+
415
+ /* Drain the right-hand tree of entries */
416
+ for (; j < d_length; j++)
417
+ if ((error = enqueue_object(git_tree_entry_byindex(delta, j), pb)) < 0)
418
+ goto on_error;
419
+
420
+ error = 0;
421
+
422
+ on_error:
423
+ if (b_child)
424
+ git_tree_free(b_child);
425
+
426
+ if (d_child)
427
+ git_tree_free(d_child);
428
+
429
+ return error;
430
+ }
431
+
432
+ static int queue_objects(git_push *push)
433
+ {
434
+ git_vector commits = GIT_VECTOR_INIT;
435
+ git_oid *oid;
436
+ size_t i;
437
+ unsigned j;
438
+ int error;
439
+
440
+ if ((error = revwalk(&commits, push)) < 0)
441
+ goto on_error;
442
+
443
+ git_vector_foreach(&commits, i, oid) {
444
+ git_commit *parent = NULL, *commit;
445
+ git_tree *tree = NULL, *ptree = NULL;
446
+ size_t parentcount;
447
+
448
+ if ((error = git_commit_lookup(&commit, push->repo, oid)) < 0)
449
+ goto on_error;
450
+
451
+ /* Insert the commit */
452
+ if ((error = git_packbuilder_insert(push->pb, oid, NULL)) < 0)
453
+ goto loop_error;
454
+
455
+ parentcount = git_commit_parentcount(commit);
456
+
457
+ if (!parentcount) {
458
+ if ((error = git_packbuilder_insert_tree(push->pb,
459
+ git_commit_tree_id(commit))) < 0)
460
+ goto loop_error;
461
+ } else {
462
+ if ((error = git_tree_lookup(&tree, push->repo,
463
+ git_commit_tree_id(commit))) < 0 ||
464
+ (error = git_packbuilder_insert(push->pb,
465
+ git_commit_tree_id(commit), NULL)) < 0)
466
+ goto loop_error;
467
+
468
+ /* For each parent, add the items which are different */
469
+ for (j = 0; j < parentcount; j++) {
470
+ if ((error = git_commit_parent(&parent, commit, j)) < 0 ||
471
+ (error = git_commit_tree(&ptree, parent)) < 0 ||
472
+ (error = queue_differences(ptree, tree, push->pb)) < 0)
473
+ goto loop_error;
474
+
475
+ git_tree_free(ptree); ptree = NULL;
476
+ git_commit_free(parent); parent = NULL;
477
+ }
478
+ }
479
+
480
+ error = 0;
481
+
482
+ loop_error:
483
+ if (tree)
484
+ git_tree_free(tree);
485
+
486
+ if (ptree)
487
+ git_tree_free(ptree);
488
+
489
+ if (parent)
490
+ git_commit_free(parent);
491
+
492
+ git_commit_free(commit);
493
+
494
+ if (error < 0)
495
+ goto on_error;
496
+ }
497
+
498
+ error = 0;
499
+
500
+ on_error:
501
+ git_vector_foreach(&commits, i, oid)
502
+ git__free(oid);
503
+
504
+ git_vector_free(&commits);
505
+ return error;
506
+ }
507
+
508
+ static int calculate_work(git_push *push)
509
+ {
510
+ git_remote_head *head;
511
+ push_spec *spec;
512
+ unsigned int i, j;
513
+
514
+ /* Update local and remote oids*/
515
+
516
+ git_vector_foreach(&push->specs, i, spec) {
517
+ if (spec->lref) {
518
+ /* This is a create or update. Local ref must exist. */
519
+ if (git_reference_name_to_id(
520
+ &spec->loid, push->repo, spec->lref) < 0) {
521
+ giterr_set(GIT_ENOTFOUND, "No such reference '%s'", spec->lref);
522
+ return -1;
523
+ }
524
+ }
525
+
526
+ if (spec->rref) {
527
+ /* Remote ref may or may not (e.g. during create) already exist. */
528
+ git_vector_foreach(&push->remote->refs, j, head) {
529
+ if (!strcmp(spec->rref, head->name)) {
530
+ git_oid_cpy(&spec->roid, &head->oid);
531
+ break;
532
+ }
533
+ }
534
+ }
535
+ }
536
+
537
+ return 0;
538
+ }
539
+
540
+ static int do_push(git_push *push)
541
+ {
542
+ int error;
543
+ git_transport *transport = push->remote->transport;
544
+
545
+ if (!transport->push) {
546
+ giterr_set(GITERR_NET, "Remote transport doesn't support push");
547
+ error = -1;
548
+ goto on_error;
549
+ }
550
+
551
+ /*
552
+ * A pack-file MUST be sent if either create or update command
553
+ * is used, even if the server already has all the necessary
554
+ * objects. In this case the client MUST send an empty pack-file.
555
+ */
556
+
557
+ if ((error = git_packbuilder_new(&push->pb, push->repo)) < 0)
558
+ goto on_error;
559
+
560
+ git_packbuilder_set_threads(push->pb, push->pb_parallelism);
561
+
562
+ if ((error = calculate_work(push)) < 0 ||
563
+ (error = queue_objects(push)) < 0 ||
564
+ (error = transport->push(transport, push)) < 0)
565
+ goto on_error;
566
+
567
+ error = 0;
568
+
569
+ on_error:
570
+ git_packbuilder_free(push->pb);
571
+ return error;
572
+ }
573
+
574
+ static int cb_filter_refs(git_remote_head *ref, void *data)
575
+ {
576
+ git_remote *remote = (git_remote *) data;
577
+ return git_vector_insert(&remote->refs, ref);
578
+ }
579
+
580
+ static int filter_refs(git_remote *remote)
581
+ {
582
+ git_vector_clear(&remote->refs);
583
+ return git_remote_ls(remote, cb_filter_refs, remote);
584
+ }
585
+
586
+ int git_push_finish(git_push *push)
587
+ {
588
+ int error;
589
+
590
+ if (!git_remote_connected(push->remote) &&
591
+ (error = git_remote_connect(push->remote, GIT_DIRECTION_PUSH)) < 0)
592
+ return error;
593
+
594
+ if ((error = filter_refs(push->remote)) < 0 ||
595
+ (error = do_push(push)) < 0)
596
+ return error;
597
+
598
+ return 0;
599
+ }
600
+
601
+ int git_push_unpack_ok(git_push *push)
602
+ {
603
+ return push->unpack_ok;
604
+ }
605
+
606
+ int git_push_status_foreach(git_push *push,
607
+ int (*cb)(const char *ref, const char *msg, void *data),
608
+ void *data)
609
+ {
610
+ push_status *status;
611
+ unsigned int i;
612
+
613
+ git_vector_foreach(&push->status, i, status) {
614
+ if (cb(status->ref, status->msg, data) < 0)
615
+ return GIT_EUSER;
616
+ }
617
+
618
+ return 0;
619
+ }
620
+
621
+ void git_push_status_free(push_status *status)
622
+ {
623
+ if (status == NULL)
624
+ return;
625
+
626
+ if (status->msg)
627
+ git__free(status->msg);
628
+
629
+ git__free(status->ref);
630
+ git__free(status);
631
+ }
632
+
633
+ void git_push_free(git_push *push)
634
+ {
635
+ push_spec *spec;
636
+ push_status *status;
637
+ unsigned int i;
638
+
639
+ if (push == NULL)
640
+ return;
641
+
642
+ git_vector_foreach(&push->specs, i, spec) {
643
+ free_refspec(spec);
644
+ }
645
+ git_vector_free(&push->specs);
646
+
647
+ git_vector_foreach(&push->status, i, status) {
648
+ git_push_status_free(status);
649
+ }
650
+ git_vector_free(&push->status);
651
+
652
+ git__free(push);
653
+ }