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.
@@ -8,149 +8,18 @@
8
8
  #include "common.h"
9
9
  #include "commit.h"
10
10
  #include "odb.h"
11
- #include "pqueue.h"
12
11
  #include "pool.h"
13
- #include "oidmap.h"
14
12
 
15
- #include "git2/revwalk.h"
16
- #include "git2/merge.h"
13
+ #include "revwalk.h"
14
+ #include "git2/revparse.h"
15
+ #include "merge.h"
17
16
 
18
17
  #include <regex.h>
19
18
 
20
- GIT__USE_OIDMAP;
21
-
22
- #define PARENT1 (1 << 0)
23
- #define PARENT2 (1 << 1)
24
- #define RESULT (1 << 2)
25
- #define STALE (1 << 3)
26
-
27
- typedef struct commit_object {
28
- git_oid oid;
29
- uint32_t time;
30
- unsigned int seen:1,
31
- uninteresting:1,
32
- topo_delay:1,
33
- parsed:1,
34
- flags : 4;
35
-
36
- unsigned short in_degree;
37
- unsigned short out_degree;
38
-
39
- struct commit_object **parents;
40
- } commit_object;
41
-
42
- typedef struct commit_list {
43
- commit_object *item;
44
- struct commit_list *next;
45
- } commit_list;
46
-
47
- struct git_revwalk {
48
- git_repository *repo;
49
- git_odb *odb;
50
-
51
- git_oidmap *commits;
52
- git_pool commit_pool;
53
-
54
- commit_list *iterator_topo;
55
- commit_list *iterator_rand;
56
- commit_list *iterator_reverse;
57
- git_pqueue iterator_time;
58
-
59
- int (*get_next)(commit_object **, git_revwalk *);
60
- int (*enqueue)(git_revwalk *, commit_object *);
61
-
62
- unsigned walking:1;
63
- unsigned int sorting;
64
-
65
- /* merge base calculation */
66
- commit_object *one;
67
- git_vector twos;
68
- };
69
-
70
- static int commit_time_cmp(void *a, void *b)
71
- {
72
- commit_object *commit_a = (commit_object *)a;
73
- commit_object *commit_b = (commit_object *)b;
74
-
75
- return (commit_a->time < commit_b->time);
76
- }
77
-
78
- static commit_list *commit_list_insert(commit_object *item, commit_list **list_p)
79
- {
80
- commit_list *new_list = git__malloc(sizeof(commit_list));
81
- if (new_list != NULL) {
82
- new_list->item = item;
83
- new_list->next = *list_p;
84
- }
85
- *list_p = new_list;
86
- return new_list;
87
- }
88
-
89
- static commit_list *commit_list_insert_by_date(commit_object *item, commit_list **list_p)
90
- {
91
- commit_list **pp = list_p;
92
- commit_list *p;
93
-
94
- while ((p = *pp) != NULL) {
95
- if (commit_time_cmp(p->item, item) < 0)
96
- break;
97
-
98
- pp = &p->next;
99
- }
100
-
101
- return commit_list_insert(item, pp);
102
- }
103
- static void commit_list_free(commit_list **list_p)
104
- {
105
- commit_list *list = *list_p;
106
-
107
- if (list == NULL)
108
- return;
109
-
110
- while (list) {
111
- commit_list *temp = list;
112
- list = temp->next;
113
- git__free(temp);
114
- }
115
-
116
- *list_p = NULL;
117
- }
118
-
119
- static commit_object *commit_list_pop(commit_list **stack)
120
- {
121
- commit_list *top = *stack;
122
- commit_object *item = top ? top->item : NULL;
123
-
124
- if (top) {
125
- *stack = top->next;
126
- git__free(top);
127
- }
128
- return item;
129
- }
130
-
131
- #define PARENTS_PER_COMMIT 2
132
- #define COMMIT_ALLOC \
133
- (sizeof(commit_object) + PARENTS_PER_COMMIT * sizeof(commit_object *))
134
-
135
- static commit_object *alloc_commit(git_revwalk *walk)
136
- {
137
- return (commit_object *)git_pool_malloc(&walk->commit_pool, COMMIT_ALLOC);
138
- }
139
-
140
- static commit_object **alloc_parents(
141
- git_revwalk *walk, commit_object *commit, size_t n_parents)
142
- {
143
- if (n_parents <= PARENTS_PER_COMMIT)
144
- return (commit_object **)((char *)commit + sizeof(commit_object));
145
-
146
- return (commit_object **)git_pool_malloc(
147
- &walk->commit_pool, (uint32_t)(n_parents * sizeof(commit_object *)));
148
- }
149
-
150
-
151
- static commit_object *commit_lookup(git_revwalk *walk, const git_oid *oid)
19
+ git_commit_list_node *git_revwalk__commit_lookup(
20
+ git_revwalk *walk, const git_oid *oid)
152
21
  {
153
- commit_object *commit;
22
+ git_commit_list_node *commit;
154
23
  khiter_t pos;
155
24
  int ret;
156
25
 
@@ -159,7 +28,7 @@ static commit_object *commit_lookup(git_revwalk *walk, const git_oid *oid)
159
28
  if (pos != kh_end(walk->commits))
160
29
  return kh_value(walk->commits, pos);
161
30
 
162
- commit = alloc_commit(walk);
31
+ commit = git_commit_list_alloc_node(walk);
163
32
  if (commit == NULL)
164
33
  return NULL;
165
34
 
@@ -172,300 +41,7 @@ static commit_object *commit_lookup(git_revwalk *walk, const git_oid *oid)
172
41
  return commit;
173
42
  }
174
43
 
175
- static int commit_error(commit_object *commit, const char *msg)
176
- {
177
- char commit_oid[GIT_OID_HEXSZ + 1];
178
- git_oid_fmt(commit_oid, &commit->oid);
179
- commit_oid[GIT_OID_HEXSZ] = '\0';
180
-
181
- giterr_set(GITERR_ODB, "Failed to parse commit %s - %s", commit_oid, msg);
182
-
183
- return -1;
184
- }
185
-
186
- static int commit_quick_parse(git_revwalk *walk, commit_object *commit, git_rawobj *raw)
187
- {
188
- const size_t parent_len = strlen("parent ") + GIT_OID_HEXSZ + 1;
189
- unsigned char *buffer = raw->data;
190
- unsigned char *buffer_end = buffer + raw->len;
191
- unsigned char *parents_start, *committer_start;
192
- int i, parents = 0;
193
- int commit_time;
194
-
195
- buffer += strlen("tree ") + GIT_OID_HEXSZ + 1;
196
-
197
- parents_start = buffer;
198
- while (buffer + parent_len < buffer_end && memcmp(buffer, "parent ", strlen("parent ")) == 0) {
199
- parents++;
200
- buffer += parent_len;
201
- }
202
-
203
- commit->parents = alloc_parents(walk, commit, parents);
204
- GITERR_CHECK_ALLOC(commit->parents);
205
-
206
- buffer = parents_start;
207
- for (i = 0; i < parents; ++i) {
208
- git_oid oid;
209
-
210
- if (git_oid_fromstr(&oid, (char *)buffer + strlen("parent ")) < 0)
211
- return -1;
212
-
213
- commit->parents[i] = commit_lookup(walk, &oid);
214
- if (commit->parents[i] == NULL)
215
- return -1;
216
-
217
- buffer += parent_len;
218
- }
219
-
220
- commit->out_degree = (unsigned short)parents;
221
-
222
- if ((committer_start = buffer = memchr(buffer, '\n', buffer_end - buffer)) == NULL)
223
- return commit_error(commit, "object is corrupted");
224
-
225
- buffer++;
226
-
227
- if ((buffer = memchr(buffer, '\n', buffer_end - buffer)) == NULL)
228
- return commit_error(commit, "object is corrupted");
229
-
230
- /* Skip trailing spaces */
231
- while (buffer > committer_start && git__isspace(*buffer))
232
- buffer--;
233
-
234
- /* Seek for the begining of the pack of digits */
235
- while (buffer > committer_start && git__isdigit(*buffer))
236
- buffer--;
237
-
238
- /* Skip potential timezone offset */
239
- if ((buffer > committer_start) && (*buffer == '+' || *buffer == '-')) {
240
- buffer--;
241
-
242
- while (buffer > committer_start && git__isspace(*buffer))
243
- buffer--;
244
-
245
- while (buffer > committer_start && git__isdigit(*buffer))
246
- buffer--;
247
- }
248
-
249
- if ((buffer == committer_start) || (git__strtol32(&commit_time, (char *)(buffer + 1), NULL, 10) < 0))
250
- return commit_error(commit, "cannot parse commit time");
251
-
252
- commit->time = (time_t)commit_time;
253
- commit->parsed = 1;
254
- return 0;
255
- }
256
-
257
- static int commit_parse(git_revwalk *walk, commit_object *commit)
258
- {
259
- git_odb_object *obj;
260
- int error;
261
-
262
- if (commit->parsed)
263
- return 0;
264
-
265
- if ((error = git_odb_read(&obj, walk->odb, &commit->oid)) < 0)
266
- return error;
267
- assert(obj->raw.type == GIT_OBJ_COMMIT);
268
-
269
- error = commit_quick_parse(walk, commit, &obj->raw);
270
- git_odb_object_free(obj);
271
- return error;
272
- }
273
-
274
- static int interesting(git_pqueue *list)
275
- {
276
- unsigned int i;
277
- /* element 0 isn't used - we need to start at 1 */
278
- for (i = 1; i < list->size; i++) {
279
- commit_object *commit = list->d[i];
280
- if ((commit->flags & STALE) == 0)
281
- return 1;
282
- }
283
-
284
- return 0;
285
- }
286
-
287
- static int merge_bases_many(commit_list **out, git_revwalk *walk, commit_object *one, git_vector *twos)
288
- {
289
- int error;
290
- unsigned int i;
291
- commit_object *two;
292
- commit_list *result = NULL, *tmp = NULL;
293
- git_pqueue list;
294
-
295
- /* if the commit is repeated, we have a our merge base already */
296
- git_vector_foreach(twos, i, two) {
297
- if (one == two)
298
- return commit_list_insert(one, out) ? 0 : -1;
299
- }
300
-
301
- if (git_pqueue_init(&list, twos->length * 2, commit_time_cmp) < 0)
302
- return -1;
303
-
304
- if (commit_parse(walk, one) < 0)
305
- return -1;
306
-
307
- one->flags |= PARENT1;
308
- if (git_pqueue_insert(&list, one) < 0)
309
- return -1;
310
-
311
- git_vector_foreach(twos, i, two) {
312
- commit_parse(walk, two);
313
- two->flags |= PARENT2;
314
- if (git_pqueue_insert(&list, two) < 0)
315
- return -1;
316
- }
317
-
318
- /* as long as there are non-STALE commits */
319
- while (interesting(&list)) {
320
- commit_object *commit;
321
- int flags;
322
-
323
- commit = git_pqueue_pop(&list);
324
-
325
- flags = commit->flags & (PARENT1 | PARENT2 | STALE);
326
- if (flags == (PARENT1 | PARENT2)) {
327
- if (!(commit->flags & RESULT)) {
328
- commit->flags |= RESULT;
329
- if (commit_list_insert(commit, &result) == NULL)
330
- return -1;
331
- }
332
- /* we mark the parents of a merge stale */
333
- flags |= STALE;
334
- }
335
-
336
- for (i = 0; i < commit->out_degree; i++) {
337
- commit_object *p = commit->parents[i];
338
- if ((p->flags & flags) == flags)
339
- continue;
340
-
341
- if ((error = commit_parse(walk, p)) < 0)
342
- return error;
343
-
344
- p->flags |= flags;
345
- if (git_pqueue_insert(&list, p) < 0)
346
- return -1;
347
- }
348
- }
349
-
350
- git_pqueue_free(&list);
351
-
352
- /* filter out any stale commits in the results */
353
- tmp = result;
354
- result = NULL;
355
-
356
- while (tmp) {
357
- struct commit_list *next = tmp->next;
358
- if (!(tmp->item->flags & STALE))
359
- if (commit_list_insert_by_date(tmp->item, &result) == NULL)
360
- return -1;
361
-
362
- git__free(tmp);
363
- tmp = next;
364
- }
365
-
366
- *out = result;
367
- return 0;
368
- }
369
-
370
- int git_merge_base_many(git_oid *out, git_repository *repo, const git_oid input_array[], size_t length)
371
- {
372
- git_revwalk *walk;
373
- git_vector list;
374
- commit_list *result = NULL;
375
- int error = -1;
376
- unsigned int i;
377
- commit_object *commit;
378
-
379
- assert(out && repo && input_array);
380
-
381
- if (length < 2) {
382
- giterr_set(GITERR_INVALID, "At least two commits are required to find an ancestor. Provided 'length' was %u.", length);
383
- return -1;
384
- }
385
-
386
- if (git_vector_init(&list, length - 1, NULL) < 0)
387
- return -1;
388
-
389
- if (git_revwalk_new(&walk, repo) < 0)
390
- goto cleanup;
391
-
392
- for (i = 1; i < length; i++) {
393
- commit = commit_lookup(walk, &input_array[i]);
394
- if (commit == NULL)
395
- goto cleanup;
396
-
397
- git_vector_insert(&list, commit);
398
- }
399
-
400
- commit = commit_lookup(walk, &input_array[0]);
401
- if (commit == NULL)
402
- goto cleanup;
403
-
404
- if (merge_bases_many(&result, walk, commit, &list) < 0)
405
- goto cleanup;
406
-
407
- if (!result) {
408
- error = GIT_ENOTFOUND;
409
- goto cleanup;
410
- }
411
-
412
- git_oid_cpy(out, &result->item->oid);
413
-
414
- error = 0;
415
-
416
- cleanup:
417
- commit_list_free(&result);
418
- git_revwalk_free(walk);
419
- git_vector_free(&list);
420
- return error;
421
- }
422
-
423
- int git_merge_base(git_oid *out, git_repository *repo, const git_oid *one, const git_oid *two)
424
- {
425
- git_revwalk *walk;
426
- git_vector list;
427
- commit_list *result = NULL;
428
- commit_object *commit;
429
- void *contents[1];
430
-
431
- if (git_revwalk_new(&walk, repo) < 0)
432
- return -1;
433
-
434
- commit = commit_lookup(walk, two);
435
- if (commit == NULL)
436
- goto on_error;
437
-
438
- /* This is just one value, so we can do it on the stack */
439
- memset(&list, 0x0, sizeof(git_vector));
440
- contents[0] = commit;
441
- list.length = 1;
442
- list.contents = contents;
443
-
444
- commit = commit_lookup(walk, one);
445
- if (commit == NULL)
446
- goto on_error;
447
-
448
- if (merge_bases_many(&result, walk, commit, &list) < 0)
449
- goto on_error;
450
-
451
- if (!result) {
452
- git_revwalk_free(walk);
453
- giterr_clear();
454
- return GIT_ENOTFOUND;
455
- }
456
-
457
- git_oid_cpy(out, &result->item->oid);
458
- commit_list_free(&result);
459
- git_revwalk_free(walk);
460
-
461
- return 0;
462
-
463
- on_error:
464
- git_revwalk_free(walk);
465
- return -1;
466
- }
467
-
468
- static void mark_uninteresting(commit_object *commit)
44
+ static void mark_uninteresting(git_commit_list_node *commit)
469
45
  {
470
46
  unsigned short i;
471
47
  assert(commit);
@@ -481,7 +57,7 @@ static void mark_uninteresting(commit_object *commit)
481
57
  mark_uninteresting(commit->parents[i]);
482
58
  }
483
59
 
484
- static int process_commit(git_revwalk *walk, commit_object *commit, int hide)
60
+ static int process_commit(git_revwalk *walk, git_commit_list_node *commit, int hide)
485
61
  {
486
62
  int error;
487
63
 
@@ -493,13 +69,13 @@ static int process_commit(git_revwalk *walk, commit_object *commit, int hide)
493
69
 
494
70
  commit->seen = 1;
495
71
 
496
- if ((error = commit_parse(walk, commit)) < 0)
72
+ if ((error = git_commit_list_parse(walk, commit)) < 0)
497
73
  return error;
498
74
 
499
75
  return walk->enqueue(walk, commit);
500
76
  }
501
77
 
502
- static int process_commit_parents(git_revwalk *walk, commit_object *commit)
78
+ static int process_commit_parents(git_revwalk *walk, git_commit_list_node *commit)
503
79
  {
504
80
  unsigned short i;
505
81
  int error = 0;
@@ -514,7 +90,7 @@ static int push_commit(git_revwalk *walk, const git_oid *oid, int uninteresting)
514
90
  {
515
91
  git_object *obj;
516
92
  git_otype type;
517
- commit_object *commit;
93
+ git_commit_list_node *commit;
518
94
 
519
95
  if (git_object_lookup(&obj, walk->repo, oid, GIT_OBJ_ANY) < 0)
520
96
  return -1;
@@ -527,7 +103,7 @@ static int push_commit(git_revwalk *walk, const git_oid *oid, int uninteresting)
527
103
  return -1;
528
104
  }
529
105
 
530
- commit = commit_lookup(walk, oid);
106
+ commit = git_revwalk__commit_lookup(walk, oid);
531
107
  if (commit == NULL)
532
108
  return -1; /* error already reported by failed lookup */
533
109
 
@@ -559,7 +135,7 @@ static int push_ref(git_revwalk *walk, const char *refname, int hide)
559
135
  {
560
136
  git_oid oid;
561
137
 
562
- if (git_reference_name_to_oid(&oid, walk->repo, refname) < 0)
138
+ if (git_reference_name_to_id(&oid, walk->repo, refname) < 0)
563
139
  return -1;
564
140
 
565
141
  return push_commit(walk, &oid, hide);
@@ -653,26 +229,51 @@ int git_revwalk_push_ref(git_revwalk *walk, const char *refname)
653
229
  return push_ref(walk, refname, 0);
654
230
  }
655
231
 
232
+ int git_revwalk_push_range(git_revwalk *walk, const char *range)
233
+ {
234
+ git_revspec revspec;
235
+ int error = 0;
236
+
237
+ if ((error = git_revparse(&revspec, walk->repo, range)))
238
+ return error;
239
+
240
+ if (revspec.flags & GIT_REVPARSE_MERGE_BASE) {
241
+ /* TODO: support "<commit>...<commit>" */
242
+ giterr_set(GITERR_INVALID, "Symmetric differences not implemented in revwalk");
243
+ return GIT_EINVALIDSPEC;
244
+ }
245
+
246
+ if ((error = push_commit(walk, git_object_id(revspec.from), 1)))
247
+ goto out;
248
+
249
+ error = push_commit(walk, git_object_id(revspec.to), 0);
250
+
251
+ out:
252
+ git_object_free(revspec.from);
253
+ git_object_free(revspec.to);
254
+ return error;
255
+ }
256
+
656
257
  int git_revwalk_hide_ref(git_revwalk *walk, const char *refname)
657
258
  {
658
259
  assert(walk && refname);
659
260
  return push_ref(walk, refname, 1);
660
261
  }
661
262
 
662
- static int revwalk_enqueue_timesort(git_revwalk *walk, commit_object *commit)
263
+ static int revwalk_enqueue_timesort(git_revwalk *walk, git_commit_list_node *commit)
663
264
  {
664
265
  return git_pqueue_insert(&walk->iterator_time, commit);
665
266
  }
666
267
 
667
- static int revwalk_enqueue_unsorted(git_revwalk *walk, commit_object *commit)
268
+ static int revwalk_enqueue_unsorted(git_revwalk *walk, git_commit_list_node *commit)
668
269
  {
669
- return commit_list_insert(commit, &walk->iterator_rand) ? 0 : -1;
270
+ return git_commit_list_insert(commit, &walk->iterator_rand) ? 0 : -1;
670
271
  }
671
272
 
672
- static int revwalk_next_timesort(commit_object **object_out, git_revwalk *walk)
273
+ static int revwalk_next_timesort(git_commit_list_node **object_out, git_revwalk *walk)
673
274
  {
674
275
  int error;
675
- commit_object *next;
276
+ git_commit_list_node *next;
676
277
 
677
278
  while ((next = git_pqueue_pop(&walk->iterator_time)) != NULL) {
678
279
  if ((error = process_commit_parents(walk, next)) < 0)
@@ -688,12 +289,12 @@ static int revwalk_next_timesort(commit_object **object_out, git_revwalk *walk)
688
289
  return GIT_ITEROVER;
689
290
  }
690
291
 
691
- static int revwalk_next_unsorted(commit_object **object_out, git_revwalk *walk)
292
+ static int revwalk_next_unsorted(git_commit_list_node **object_out, git_revwalk *walk)
692
293
  {
693
294
  int error;
694
- commit_object *next;
295
+ git_commit_list_node *next;
695
296
 
696
- while ((next = commit_list_pop(&walk->iterator_rand)) != NULL) {
297
+ while ((next = git_commit_list_pop(&walk->iterator_rand)) != NULL) {
697
298
  if ((error = process_commit_parents(walk, next)) < 0)
698
299
  return error;
699
300
 
@@ -707,13 +308,13 @@ static int revwalk_next_unsorted(commit_object **object_out, git_revwalk *walk)
707
308
  return GIT_ITEROVER;
708
309
  }
709
310
 
710
- static int revwalk_next_toposort(commit_object **object_out, git_revwalk *walk)
311
+ static int revwalk_next_toposort(git_commit_list_node **object_out, git_revwalk *walk)
711
312
  {
712
- commit_object *next;
313
+ git_commit_list_node *next;
713
314
  unsigned short i;
714
315
 
715
316
  for (;;) {
716
- next = commit_list_pop(&walk->iterator_topo);
317
+ next = git_commit_list_pop(&walk->iterator_topo);
717
318
  if (next == NULL) {
718
319
  giterr_clear();
719
320
  return GIT_ITEROVER;
@@ -725,11 +326,11 @@ static int revwalk_next_toposort(commit_object **object_out, git_revwalk *walk)
725
326
  }
726
327
 
727
328
  for (i = 0; i < next->out_degree; ++i) {
728
- commit_object *parent = next->parents[i];
329
+ git_commit_list_node *parent = next->parents[i];
729
330
 
730
331
  if (--parent->in_degree == 0 && parent->topo_delay) {
731
332
  parent->topo_delay = 0;
732
- if (commit_list_insert(parent, &walk->iterator_topo) == NULL)
333
+ if (git_commit_list_insert(parent, &walk->iterator_topo) == NULL)
733
334
  return -1;
734
335
  }
735
336
  }
@@ -739,9 +340,9 @@ static int revwalk_next_toposort(commit_object **object_out, git_revwalk *walk)
739
340
  }
740
341
  }
741
342
 
742
- static int revwalk_next_reverse(commit_object **object_out, git_revwalk *walk)
343
+ static int revwalk_next_reverse(git_commit_list_node **object_out, git_revwalk *walk)
743
344
  {
744
- *object_out = commit_list_pop(&walk->iterator_reverse);
345
+ *object_out = git_commit_list_pop(&walk->iterator_reverse);
745
346
  return *object_out ? 0 : GIT_ITEROVER;
746
347
  }
747
348
 
@@ -750,8 +351,8 @@ static int prepare_walk(git_revwalk *walk)
750
351
  {
751
352
  int error;
752
353
  unsigned int i;
753
- commit_object *next, *two;
754
- commit_list *bases = NULL;
354
+ git_commit_list_node *next, *two;
355
+ git_commit_list *bases = NULL;
755
356
 
756
357
  /*
757
358
  * If walk->one is NULL, there were no positive references,
@@ -763,10 +364,10 @@ static int prepare_walk(git_revwalk *walk)
763
364
  }
764
365
 
765
366
  /* first figure out what the merge bases are */
766
- if (merge_bases_many(&bases, walk, walk->one, &walk->twos) < 0)
367
+ if (git_merge__bases_many(&bases, walk, walk->one, &walk->twos) < 0)
767
368
  return -1;
768
369
 
769
- commit_list_free(&bases);
370
+ git_commit_list_free(&bases);
770
371
  if (process_commit(walk, walk->one, walk->one->uninteresting) < 0)
771
372
  return -1;
772
373
 
@@ -780,11 +381,11 @@ static int prepare_walk(git_revwalk *walk)
780
381
 
781
382
  while ((error = walk->get_next(&next, walk)) == 0) {
782
383
  for (i = 0; i < next->out_degree; ++i) {
783
- commit_object *parent = next->parents[i];
384
+ git_commit_list_node *parent = next->parents[i];
784
385
  parent->in_degree++;
785
386
  }
786
387
 
787
- if (commit_list_insert(next, &walk->iterator_topo) == NULL)
388
+ if (git_commit_list_insert(next, &walk->iterator_topo) == NULL)
788
389
  return -1;
789
390
  }
790
391
 
@@ -797,7 +398,7 @@ static int prepare_walk(git_revwalk *walk)
797
398
  if (walk->sorting & GIT_SORT_REVERSE) {
798
399
 
799
400
  while ((error = walk->get_next(&next, walk)) == 0)
800
- if (commit_list_insert(next, &walk->iterator_reverse) == NULL)
401
+ if (git_commit_list_insert(next, &walk->iterator_reverse) == NULL)
801
402
  return -1;
802
403
 
803
404
  if (error != GIT_ITEROVER)
@@ -811,9 +412,6 @@ static int prepare_walk(git_revwalk *walk)
811
412
  }
812
413
 
813
414
 
814
-
815
-
816
-
817
415
  int git_revwalk_new(git_revwalk **revwalk_out, git_repository *repo)
818
416
  {
819
417
  git_revwalk *walk;
@@ -826,7 +424,7 @@ int git_revwalk_new(git_revwalk **revwalk_out, git_repository *repo)
826
424
  walk->commits = git_oidmap_alloc();
827
425
  GITERR_CHECK_ALLOC(walk->commits);
828
426
 
829
- if (git_pqueue_init(&walk->iterator_time, 8, commit_time_cmp) < 0 ||
427
+ if (git_pqueue_init(&walk->iterator_time, 8, git_commit_list_time_cmp) < 0 ||
830
428
  git_vector_init(&walk->twos, 4, NULL) < 0 ||
831
429
  git_pool_init(&walk->commit_pool, 1,
832
430
  git_pool__suggest_items_per_page(COMMIT_ALLOC) * COMMIT_ALLOC) < 0)
@@ -888,7 +486,7 @@ void git_revwalk_sorting(git_revwalk *walk, unsigned int sort_mode)
888
486
  int git_revwalk_next(git_oid *oid, git_revwalk *walk)
889
487
  {
890
488
  int error;
891
- commit_object *next;
489
+ git_commit_list_node *next;
892
490
 
893
491
  assert(walk && oid);
894
492
 
@@ -913,7 +511,7 @@ int git_revwalk_next(git_oid *oid, git_revwalk *walk)
913
511
 
914
512
  void git_revwalk_reset(git_revwalk *walk)
915
513
  {
916
- commit_object *commit;
514
+ git_commit_list_node *commit;
917
515
 
918
516
  assert(walk);
919
517
 
@@ -925,9 +523,9 @@ void git_revwalk_reset(git_revwalk *walk)
925
523
  });
926
524
 
927
525
  git_pqueue_clear(&walk->iterator_time);
928
- commit_list_free(&walk->iterator_topo);
929
- commit_list_free(&walk->iterator_rand);
930
- commit_list_free(&walk->iterator_reverse);
526
+ git_commit_list_free(&walk->iterator_topo);
527
+ git_commit_list_free(&walk->iterator_rand);
528
+ git_commit_list_free(&walk->iterator_reverse);
931
529
  walk->walking = 0;
932
530
 
933
531
  walk->one = NULL;