rugged 0.18.0.gh.de28323 → 0.19.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (283) hide show
  1. data/README.md +9 -4
  2. data/Rakefile +1 -1
  3. data/ext/rugged/extconf.rb +10 -0
  4. data/ext/rugged/rugged.c +153 -86
  5. data/ext/rugged/rugged.h +44 -33
  6. data/ext/rugged/rugged_blob.c +288 -60
  7. data/ext/rugged/rugged_branch.c +82 -57
  8. data/ext/rugged/rugged_commit.c +83 -86
  9. data/ext/rugged/rugged_config.c +68 -68
  10. data/ext/rugged/rugged_diff.c +509 -0
  11. data/ext/rugged/rugged_diff_delta.c +94 -0
  12. data/ext/rugged/rugged_diff_hunk.c +100 -0
  13. data/ext/rugged/rugged_diff_line.c +79 -0
  14. data/ext/rugged/rugged_diff_patch.c +169 -0
  15. data/ext/rugged/rugged_index.c +539 -8
  16. data/ext/rugged/rugged_note.c +74 -80
  17. data/ext/rugged/rugged_object.c +63 -8
  18. data/ext/rugged/rugged_reference.c +231 -145
  19. data/ext/rugged/rugged_remote.c +509 -53
  20. data/ext/rugged/rugged_repo.c +572 -236
  21. data/ext/rugged/rugged_revwalk.c +59 -36
  22. data/ext/rugged/rugged_settings.c +7 -9
  23. data/ext/rugged/rugged_signature.c +7 -11
  24. data/ext/rugged/rugged_tag.c +93 -39
  25. data/ext/rugged/rugged_tree.c +321 -58
  26. data/lib/rugged.rb +1 -0
  27. data/lib/rugged/commit.rb +16 -1
  28. data/lib/rugged/console.rb +9 -0
  29. data/lib/rugged/diff.rb +19 -0
  30. data/lib/rugged/diff/delta.rb +54 -0
  31. data/lib/rugged/diff/hunk.rb +23 -0
  32. data/lib/rugged/diff/line.rb +29 -0
  33. data/lib/rugged/diff/patch.rb +28 -0
  34. data/lib/rugged/repository.rb +36 -39
  35. data/lib/rugged/version.rb +1 -1
  36. data/test/blob_test.rb +308 -1
  37. data/test/branch_test.rb +7 -0
  38. data/test/commit_test.rb +7 -10
  39. data/test/coverage/cover.rb +9 -1
  40. data/test/diff_test.rb +777 -0
  41. data/test/fixtures/archive.tar.gz +0 -0
  42. data/test/fixtures/attr/attr0 +1 -0
  43. data/test/fixtures/attr/attr1 +29 -0
  44. data/test/fixtures/attr/attr2 +21 -0
  45. data/test/fixtures/attr/attr3 +4 -0
  46. data/test/fixtures/attr/binfile +1 -0
  47. data/test/fixtures/attr/dir/file +0 -0
  48. data/test/fixtures/attr/file +1 -0
  49. data/test/fixtures/attr/gitattributes +29 -0
  50. data/test/fixtures/attr/gitignore +2 -0
  51. data/test/fixtures/attr/ign +1 -0
  52. data/test/fixtures/attr/macro_bad +1 -0
  53. data/test/fixtures/attr/macro_test +1 -0
  54. data/test/fixtures/attr/root_test1 +1 -0
  55. data/test/fixtures/attr/root_test2 +6 -0
  56. data/test/fixtures/attr/root_test3 +19 -0
  57. data/test/fixtures/attr/root_test4.txt +14 -0
  58. data/test/fixtures/attr/sub/abc +37 -0
  59. data/test/fixtures/attr/sub/dir/file +0 -0
  60. data/test/fixtures/attr/sub/file +1 -0
  61. data/test/fixtures/attr/sub/ign/file +1 -0
  62. data/test/fixtures/attr/sub/ign/sub/file +1 -0
  63. data/test/fixtures/attr/sub/sub/dir +0 -0
  64. data/test/fixtures/attr/sub/sub/file +1 -0
  65. data/test/fixtures/attr/sub/sub/subsub.txt +1 -0
  66. data/test/fixtures/attr/sub/subdir_test1 +2 -0
  67. data/test/fixtures/attr/sub/subdir_test2.txt +1 -0
  68. data/test/fixtures/diff/another.txt +38 -0
  69. data/test/fixtures/diff/readme.txt +36 -0
  70. data/test/fixtures/mergedrepo/conflicts-one.txt +5 -0
  71. data/test/fixtures/mergedrepo/conflicts-two.txt +5 -0
  72. data/test/fixtures/mergedrepo/one.txt +10 -0
  73. data/test/fixtures/mergedrepo/two.txt +12 -0
  74. data/test/fixtures/status/current_file +1 -0
  75. data/test/fixtures/status/ignored_file +1 -0
  76. data/test/fixtures/status/modified_file +2 -0
  77. data/test/fixtures/status/new_file +1 -0
  78. data/test/fixtures/status/staged_changes +2 -0
  79. data/test/fixtures/status/staged_changes_modified_file +3 -0
  80. data/test/fixtures/status/staged_delete_modified_file +1 -0
  81. data/test/fixtures/status/staged_new_file +1 -0
  82. data/test/fixtures/status/staged_new_file_modified_file +2 -0
  83. data/test/fixtures/status/subdir.txt +2 -0
  84. data/test/fixtures/status/subdir/current_file +1 -0
  85. data/test/fixtures/status/subdir/modified_file +2 -0
  86. data/test/fixtures/status/subdir/new_file +1 -0
  87. data/test/fixtures/status//350/277/231 +1 -0
  88. data/test/fixtures/testrepo.git/config +5 -0
  89. data/test/fixtures/testrepo.git/objects/77/71329dfa3002caf8c61a0ceb62a31d09023f37 +0 -0
  90. data/test/fixtures/text_file.md +464 -0
  91. data/test/fixtures/unsymlinked.git/HEAD +1 -0
  92. data/test/fixtures/unsymlinked.git/config +6 -0
  93. data/test/fixtures/unsymlinked.git/description +1 -0
  94. data/test/fixtures/unsymlinked.git/info/exclude +2 -0
  95. data/test/fixtures/unsymlinked.git/objects/08/8b64704e0d6b8bd061dea879418cb5442a3fbf +0 -0
  96. data/test/fixtures/unsymlinked.git/objects/13/a5e939bca25940c069fd2169d993dba328e30b +0 -0
  97. data/test/fixtures/unsymlinked.git/objects/19/bf568e59e3a0b363cafb4106226e62d4a4c41c +0 -0
  98. data/test/fixtures/unsymlinked.git/objects/58/1fadd35b4cf320d102a152f918729011604773 +0 -0
  99. data/test/fixtures/unsymlinked.git/objects/5c/87b6791e8b13da658a14d1ef7e09b5dc3bac8c +0 -0
  100. data/test/fixtures/unsymlinked.git/objects/6f/e5f5398af85fb3de8a6aba0339b6d3bfa26a27 +0 -0
  101. data/test/fixtures/unsymlinked.git/objects/7f/ccd75616ec188b8f1b23d67506a334cc34a49d +0 -0
  102. data/test/fixtures/unsymlinked.git/objects/80/6999882bf91d24241e4077906b9017605eb1f3 +0 -0
  103. data/test/fixtures/unsymlinked.git/objects/83/7d176303c5005505ec1e4a30231c40930c0230 +0 -0
  104. data/test/fixtures/unsymlinked.git/objects/a8/595ccca04f40818ae0155c8f9c77a230e597b6 +2 -0
  105. data/test/fixtures/unsymlinked.git/objects/cf/8f1cf5cce859c438d6cc067284cb5e161206e7 +0 -0
  106. data/test/fixtures/unsymlinked.git/objects/d5/278d05c8607ec420bfee4cf219fbc0eeebfd6a +0 -0
  107. data/test/fixtures/unsymlinked.git/objects/f4/e16fb76536591a41454194058d048d8e4dd2e9 +0 -0
  108. data/test/fixtures/unsymlinked.git/objects/f9/e65619d93fdf2673882e0a261c5e93b1a84006 +0 -0
  109. data/test/fixtures/unsymlinked.git/refs/heads/exe-file +1 -0
  110. data/test/fixtures/unsymlinked.git/refs/heads/master +1 -0
  111. data/test/fixtures/unsymlinked.git/refs/heads/reg-file +1 -0
  112. data/test/index_test.rb +120 -0
  113. data/test/reference_test.rb +38 -3
  114. data/test/remote_test.rb +224 -3
  115. data/test/repo_reset_test.rb +2 -0
  116. data/test/repo_test.rb +147 -10
  117. data/test/test_helper.rb +5 -2
  118. data/vendor/libgit2/include/git2/attr.h +3 -3
  119. data/vendor/libgit2/include/git2/blob.h +11 -17
  120. data/vendor/libgit2/include/git2/branch.h +3 -2
  121. data/vendor/libgit2/include/git2/checkout.h +7 -0
  122. data/vendor/libgit2/include/git2/clone.h +3 -0
  123. data/vendor/libgit2/include/git2/commit.h +61 -66
  124. data/vendor/libgit2/include/git2/common.h +73 -42
  125. data/vendor/libgit2/include/git2/config.h +57 -71
  126. data/vendor/libgit2/include/git2/cred_helpers.h +2 -2
  127. data/vendor/libgit2/include/git2/diff.h +179 -30
  128. data/vendor/libgit2/include/git2/errors.h +3 -3
  129. data/vendor/libgit2/include/git2/index.h +225 -146
  130. data/vendor/libgit2/include/git2/indexer.h +2 -22
  131. data/vendor/libgit2/include/git2/inttypes.h +9 -9
  132. data/vendor/libgit2/include/git2/merge.h +123 -5
  133. data/vendor/libgit2/include/git2/odb.h +59 -38
  134. data/vendor/libgit2/include/git2/odb_backend.h +45 -104
  135. data/vendor/libgit2/include/git2/oid.h +30 -19
  136. data/vendor/libgit2/include/git2/pack.h +21 -3
  137. data/vendor/libgit2/include/git2/refdb.h +0 -35
  138. data/vendor/libgit2/include/git2/refs.h +93 -31
  139. data/vendor/libgit2/include/git2/refspec.h +17 -0
  140. data/vendor/libgit2/include/git2/remote.h +60 -20
  141. data/vendor/libgit2/include/git2/repository.h +48 -70
  142. data/vendor/libgit2/include/git2/reset.h +3 -3
  143. data/vendor/libgit2/include/git2/revparse.h +22 -0
  144. data/vendor/libgit2/include/git2/stash.h +1 -1
  145. data/vendor/libgit2/include/git2/status.h +131 -56
  146. data/vendor/libgit2/include/git2/strarray.h +2 -2
  147. data/vendor/libgit2/include/git2/submodule.h +16 -16
  148. data/vendor/libgit2/include/git2/sys/commit.h +46 -0
  149. data/vendor/libgit2/include/git2/sys/config.h +71 -0
  150. data/vendor/libgit2/include/git2/sys/index.h +179 -0
  151. data/vendor/libgit2/include/git2/sys/odb_backend.h +86 -0
  152. data/vendor/libgit2/include/git2/sys/refdb_backend.h +158 -0
  153. data/vendor/libgit2/include/git2/sys/refs.h +38 -0
  154. data/vendor/libgit2/include/git2/sys/repository.h +106 -0
  155. data/vendor/libgit2/include/git2/tag.h +44 -18
  156. data/vendor/libgit2/include/git2/trace.h +1 -2
  157. data/vendor/libgit2/include/git2/transport.h +74 -0
  158. data/vendor/libgit2/include/git2/tree.h +12 -22
  159. data/vendor/libgit2/include/git2/types.h +33 -0
  160. data/vendor/libgit2/include/git2/version.h +2 -2
  161. data/vendor/libgit2/src/array.h +66 -0
  162. data/vendor/libgit2/src/attr.c +26 -13
  163. data/vendor/libgit2/src/attr_file.c +3 -2
  164. data/vendor/libgit2/src/attr_file.h +3 -3
  165. data/vendor/libgit2/src/attrcache.h +4 -4
  166. data/vendor/libgit2/src/blob.c +13 -9
  167. data/vendor/libgit2/src/blob.h +2 -2
  168. data/vendor/libgit2/src/branch.c +67 -49
  169. data/vendor/libgit2/src/cache.c +224 -54
  170. data/vendor/libgit2/src/cache.h +33 -20
  171. data/vendor/libgit2/src/checkout.c +145 -85
  172. data/vendor/libgit2/src/clone.c +62 -50
  173. data/vendor/libgit2/src/commit.c +74 -40
  174. data/vendor/libgit2/src/commit.h +2 -3
  175. data/vendor/libgit2/src/commit_list.c +14 -8
  176. data/vendor/libgit2/src/config.c +119 -36
  177. data/vendor/libgit2/src/config.h +3 -0
  178. data/vendor/libgit2/src/config_cache.c +24 -7
  179. data/vendor/libgit2/src/config_file.c +9 -6
  180. data/vendor/libgit2/src/crlf.c +4 -2
  181. data/vendor/libgit2/src/date.c +3 -3
  182. data/vendor/libgit2/src/delta.c +1 -1
  183. data/vendor/libgit2/src/diff.c +681 -303
  184. data/vendor/libgit2/src/diff.h +34 -2
  185. data/vendor/libgit2/src/diff_driver.c +405 -0
  186. data/vendor/libgit2/src/diff_driver.h +49 -0
  187. data/vendor/libgit2/src/diff_file.c +447 -0
  188. data/vendor/libgit2/src/diff_file.h +58 -0
  189. data/vendor/libgit2/src/diff_patch.c +995 -0
  190. data/vendor/libgit2/src/diff_patch.h +46 -0
  191. data/vendor/libgit2/src/diff_print.c +430 -0
  192. data/vendor/libgit2/src/diff_tform.c +464 -203
  193. data/vendor/libgit2/src/diff_xdiff.c +166 -0
  194. data/vendor/libgit2/src/diff_xdiff.h +28 -0
  195. data/vendor/libgit2/src/fetch.c +11 -4
  196. data/vendor/libgit2/src/fileops.c +85 -61
  197. data/vendor/libgit2/src/fileops.h +4 -0
  198. data/vendor/libgit2/src/global.c +10 -2
  199. data/vendor/libgit2/src/global.h +0 -8
  200. data/vendor/libgit2/src/hash/hash_generic.h +3 -3
  201. data/vendor/libgit2/src/hash/hash_win32.h +4 -4
  202. data/vendor/libgit2/src/hashsig.c +0 -1
  203. data/vendor/libgit2/src/ignore.c +68 -28
  204. data/vendor/libgit2/src/ignore.h +10 -1
  205. data/vendor/libgit2/src/index.c +666 -84
  206. data/vendor/libgit2/src/index.h +6 -0
  207. data/vendor/libgit2/src/indexer.c +10 -28
  208. data/vendor/libgit2/src/iterator.c +427 -283
  209. data/vendor/libgit2/src/iterator.h +58 -4
  210. data/vendor/libgit2/src/merge.c +1892 -32
  211. data/vendor/libgit2/src/merge.h +132 -5
  212. data/vendor/libgit2/src/merge_file.c +174 -0
  213. data/vendor/libgit2/src/merge_file.h +71 -0
  214. data/vendor/libgit2/src/mwindow.c +1 -1
  215. data/vendor/libgit2/src/notes.c +45 -48
  216. data/vendor/libgit2/src/object.c +89 -127
  217. data/vendor/libgit2/src/object.h +0 -1
  218. data/vendor/libgit2/src/object_api.c +129 -0
  219. data/vendor/libgit2/src/odb.c +156 -59
  220. data/vendor/libgit2/src/odb.h +5 -2
  221. data/vendor/libgit2/src/odb_loose.c +31 -17
  222. data/vendor/libgit2/src/odb_pack.c +39 -43
  223. data/vendor/libgit2/src/oid.c +62 -27
  224. data/vendor/libgit2/src/oid.h +33 -0
  225. data/vendor/libgit2/src/oidmap.h +4 -6
  226. data/vendor/libgit2/src/pack-objects.c +54 -22
  227. data/vendor/libgit2/src/pack.c +98 -56
  228. data/vendor/libgit2/src/pack.h +3 -1
  229. data/vendor/libgit2/src/pathspec.c +26 -1
  230. data/vendor/libgit2/src/pathspec.h +14 -0
  231. data/vendor/libgit2/src/pool.c +5 -0
  232. data/vendor/libgit2/src/posix.c +2 -2
  233. data/vendor/libgit2/src/posix.h +3 -0
  234. data/vendor/libgit2/src/push.c +13 -10
  235. data/vendor/libgit2/src/refdb.c +82 -62
  236. data/vendor/libgit2/src/refdb.h +16 -16
  237. data/vendor/libgit2/src/refdb_fs.c +386 -133
  238. data/vendor/libgit2/src/reflog.c +3 -1
  239. data/vendor/libgit2/src/refs.c +247 -221
  240. data/vendor/libgit2/src/refs.h +2 -1
  241. data/vendor/libgit2/src/refspec.c +18 -1
  242. data/vendor/libgit2/src/refspec.h +3 -1
  243. data/vendor/libgit2/src/remote.c +434 -253
  244. data/vendor/libgit2/src/remote.h +5 -3
  245. data/vendor/libgit2/src/repository.c +197 -111
  246. data/vendor/libgit2/src/repository.h +26 -5
  247. data/vendor/libgit2/src/reset.c +1 -1
  248. data/vendor/libgit2/src/revparse.c +84 -79
  249. data/vendor/libgit2/src/revwalk.c +1 -1
  250. data/vendor/libgit2/src/signature.c +22 -10
  251. data/vendor/libgit2/src/stash.c +5 -2
  252. data/vendor/libgit2/src/status.c +311 -107
  253. data/vendor/libgit2/src/status.h +23 -0
  254. data/vendor/libgit2/src/submodule.c +21 -13
  255. data/vendor/libgit2/src/tag.c +42 -31
  256. data/vendor/libgit2/src/tag.h +2 -3
  257. data/vendor/libgit2/src/thread-utils.h +105 -3
  258. data/vendor/libgit2/src/trace.c +1 -2
  259. data/vendor/libgit2/src/trace.h +3 -3
  260. data/vendor/libgit2/src/transport.c +18 -6
  261. data/vendor/libgit2/src/transports/cred.c +103 -1
  262. data/vendor/libgit2/src/transports/local.c +19 -9
  263. data/vendor/libgit2/src/transports/smart_protocol.c +32 -12
  264. data/vendor/libgit2/src/transports/ssh.c +519 -0
  265. data/vendor/libgit2/src/transports/winhttp.c +3 -1
  266. data/vendor/libgit2/src/tree.c +26 -28
  267. data/vendor/libgit2/src/tree.h +3 -3
  268. data/vendor/libgit2/src/unix/posix.h +2 -0
  269. data/vendor/libgit2/src/util.c +43 -6
  270. data/vendor/libgit2/src/util.h +40 -12
  271. data/vendor/libgit2/src/vector.c +3 -5
  272. data/vendor/libgit2/src/vector.h +9 -0
  273. data/vendor/libgit2/src/win32/dir.c +1 -1
  274. data/vendor/libgit2/src/win32/error.c +2 -0
  275. data/vendor/libgit2/src/win32/findfile.c +3 -6
  276. data/vendor/libgit2/src/win32/posix_w32.c +85 -59
  277. data/vendor/libgit2/src/win32/pthread.c +16 -8
  278. data/vendor/libgit2/src/win32/pthread.h +7 -4
  279. metadata +407 -306
  280. data/test/coverage/HEAD.json +0 -1
  281. data/vendor/libgit2/include/git2/refdb_backend.h +0 -109
  282. data/vendor/libgit2/src/diff_output.c +0 -1819
  283. data/vendor/libgit2/src/diff_output.h +0 -93
@@ -0,0 +1,23 @@
1
+ /*
2
+ * Copyright (C) the libgit2 contributors. All rights reserved.
3
+ *
4
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
5
+ * a Linking Exception. For full terms see the included COPYING file.
6
+ */
7
+ #ifndef INCLUDE_status_h__
8
+ #define INCLUDE_status_h__
9
+
10
+ #include "diff.h"
11
+ #include "git2/status.h"
12
+ #include "git2/diff.h"
13
+
14
+ struct git_status_list {
15
+ git_status_options opts;
16
+
17
+ git_diff_list *head2idx;
18
+ git_diff_list *idx2wd;
19
+
20
+ git_vector paired;
21
+ };
22
+
23
+ #endif
@@ -7,6 +7,7 @@
7
7
 
8
8
  #include "common.h"
9
9
  #include "git2/config.h"
10
+ #include "git2/sys/config.h"
10
11
  #include "git2/types.h"
11
12
  #include "git2/repository.h"
12
13
  #include "git2/index.h"
@@ -21,6 +22,8 @@
21
22
  #include "submodule.h"
22
23
  #include "tree.h"
23
24
  #include "iterator.h"
25
+ #include "path.h"
26
+ #include "index.h"
24
27
 
25
28
  #define GIT_MODULES_FILE ".gitmodules"
26
29
 
@@ -127,6 +130,10 @@ int git_submodule_lookup(
127
130
  git_buf_free(&path);
128
131
  }
129
132
 
133
+ giterr_set(GITERR_SUBMODULE, (error == GIT_ENOTFOUND) ?
134
+ "No submodule named '%s'" :
135
+ "Submodule '%s' has not been added yet", name);
136
+
130
137
  return error;
131
138
  }
132
139
 
@@ -144,7 +151,7 @@ int git_submodule_foreach(
144
151
  int error;
145
152
  git_submodule *sm;
146
153
  git_vector seen = GIT_VECTOR_INIT;
147
- seen._cmp = submodule_cmp;
154
+ git_vector_set_cmp(&seen, submodule_cmp);
148
155
 
149
156
  assert(repo && callback);
150
157
 
@@ -1138,9 +1145,7 @@ static int load_submodule_config_from_index(
1138
1145
  (error = git_iterator_for_index(&i, index, 0, NULL, NULL)) < 0)
1139
1146
  return error;
1140
1147
 
1141
- error = git_iterator_current(&entry, i);
1142
-
1143
- while (!error && entry != NULL) {
1148
+ while (!(error = git_iterator_advance(&entry, i))) {
1144
1149
 
1145
1150
  if (S_ISGITLINK(entry->mode)) {
1146
1151
  error = submodule_load_from_index(repo, entry);
@@ -1153,10 +1158,11 @@ static int load_submodule_config_from_index(
1153
1158
  if (strcmp(entry->path, GIT_MODULES_FILE) == 0)
1154
1159
  git_oid_cpy(gitmodules_oid, &entry->oid);
1155
1160
  }
1156
-
1157
- error = git_iterator_advance(&entry, i);
1158
1161
  }
1159
1162
 
1163
+ if (error == GIT_ITEROVER)
1164
+ error = 0;
1165
+
1160
1166
  git_iterator_free(i);
1161
1167
 
1162
1168
  return error;
@@ -1170,17 +1176,18 @@ static int load_submodule_config_from_head(
1170
1176
  git_iterator *i;
1171
1177
  const git_index_entry *entry;
1172
1178
 
1173
- if ((error = git_repository_head_tree(&head, repo)) < 0)
1174
- return error;
1179
+ /* if we can't look up current head, then there's no submodule in it */
1180
+ if (git_repository_head_tree(&head, repo) < 0) {
1181
+ giterr_clear();
1182
+ return 0;
1183
+ }
1175
1184
 
1176
1185
  if ((error = git_iterator_for_tree(&i, head, 0, NULL, NULL)) < 0) {
1177
1186
  git_tree_free(head);
1178
1187
  return error;
1179
1188
  }
1180
1189
 
1181
- error = git_iterator_current(&entry, i);
1182
-
1183
- while (!error && entry != NULL) {
1190
+ while (!(error = git_iterator_advance(&entry, i))) {
1184
1191
 
1185
1192
  if (S_ISGITLINK(entry->mode)) {
1186
1193
  error = submodule_load_from_head(repo, entry->path, &entry->oid);
@@ -1194,10 +1201,11 @@ static int load_submodule_config_from_head(
1194
1201
  git_oid_iszero(gitmodules_oid))
1195
1202
  git_oid_cpy(gitmodules_oid, &entry->oid);
1196
1203
  }
1197
-
1198
- error = git_iterator_advance(&entry, i);
1199
1204
  }
1200
1205
 
1206
+ if (error == GIT_ITEROVER)
1207
+ error = 0;
1208
+
1201
1209
  git_iterator_free(i);
1202
1210
  git_tree_free(head);
1203
1211
 
@@ -13,20 +13,17 @@
13
13
  #include "git2/object.h"
14
14
  #include "git2/repository.h"
15
15
  #include "git2/signature.h"
16
+ #include "git2/odb_backend.h"
16
17
 
17
- void git_tag__free(git_tag *tag)
18
+ void git_tag__free(void *_tag)
18
19
  {
20
+ git_tag *tag = _tag;
19
21
  git_signature_free(tag->tagger);
20
22
  git__free(tag->message);
21
23
  git__free(tag->tag_name);
22
24
  git__free(tag);
23
25
  }
24
26
 
25
- const git_oid *git_tag_id(const git_tag *c)
26
- {
27
- return git_object_id((const git_object *)c);
28
- }
29
-
30
27
  int git_tag_target(git_object **target, const git_tag *t)
31
28
  {
32
29
  assert(t);
@@ -68,7 +65,7 @@ static int tag_error(const char *str)
68
65
  return -1;
69
66
  }
70
67
 
71
- int git_tag__parse_buffer(git_tag *tag, const char *buffer, size_t length)
68
+ static int tag_parse(git_tag *tag, const char *buffer, const char *buffer_end)
72
69
  {
73
70
  static const char *tag_types[] = {
74
71
  NULL, "commit\n", "tree\n", "blob\n", "tag\n"
@@ -78,8 +75,6 @@ int git_tag__parse_buffer(git_tag *tag, const char *buffer, size_t length)
78
75
  size_t text_len;
79
76
  char *search;
80
77
 
81
- const char *buffer_end = buffer + length;
82
-
83
78
  if (git_oid__parse(&tag->target, &buffer, buffer_end, "object ") < 0)
84
79
  return tag_error("Object field invalid");
85
80
 
@@ -156,6 +151,15 @@ int git_tag__parse_buffer(git_tag *tag, const char *buffer, size_t length)
156
151
  return 0;
157
152
  }
158
153
 
154
+ int git_tag__parse(void *_tag, git_odb_object *odb_obj)
155
+ {
156
+ git_tag *tag = _tag;
157
+ const char *buffer = git_odb_object_data(odb_obj);
158
+ const char *buffer_end = buffer + git_odb_object_size(odb_obj);
159
+
160
+ return tag_parse(tag, buffer, buffer_end);
161
+ }
162
+
159
163
  static int retrieve_tag_reference(
160
164
  git_reference **tag_reference_out,
161
165
  git_buf *ref_name_out,
@@ -276,23 +280,36 @@ cleanup:
276
280
  }
277
281
 
278
282
  int git_tag_create(
279
- git_oid *oid,
280
- git_repository *repo,
281
- const char *tag_name,
282
- const git_object *target,
283
- const git_signature *tagger,
284
- const char *message,
285
- int allow_ref_overwrite)
283
+ git_oid *oid,
284
+ git_repository *repo,
285
+ const char *tag_name,
286
+ const git_object *target,
287
+ const git_signature *tagger,
288
+ const char *message,
289
+ int allow_ref_overwrite)
286
290
  {
287
291
  return git_tag_create__internal(oid, repo, tag_name, target, tagger, message, allow_ref_overwrite, 1);
288
292
  }
289
293
 
294
+ int git_tag_annotation_create(
295
+ git_oid *oid,
296
+ git_repository *repo,
297
+ const char *tag_name,
298
+ const git_object *target,
299
+ const git_signature *tagger,
300
+ const char *message)
301
+ {
302
+ assert(oid && repo && tag_name && target && tagger && message);
303
+
304
+ return write_tag_annotation(oid, repo, tag_name, target, tagger, message);
305
+ }
306
+
290
307
  int git_tag_create_lightweight(
291
- git_oid *oid,
292
- git_repository *repo,
293
- const char *tag_name,
294
- const git_object *target,
295
- int allow_ref_overwrite)
308
+ git_oid *oid,
309
+ git_repository *repo,
310
+ const char *tag_name,
311
+ const git_object *target,
312
+ int allow_ref_overwrite)
296
313
  {
297
314
  return git_tag_create__internal(oid, repo, tag_name, target, NULL, NULL, allow_ref_overwrite, 0);
298
315
  }
@@ -316,14 +333,14 @@ int git_tag_create_frombuffer(git_oid *oid, git_repository *repo, const char *bu
316
333
  return -1;
317
334
 
318
335
  /* validate the buffer */
319
- if (git_tag__parse_buffer(&tag, buffer, strlen(buffer)) < 0)
336
+ if (tag_parse(&tag, buffer, buffer + strlen(buffer)) < 0)
320
337
  return -1;
321
338
 
322
339
  /* validate the target */
323
340
  if (git_odb_read(&target_obj, odb, &tag.target) < 0)
324
341
  goto on_error;
325
342
 
326
- if (tag.type != target_obj->raw.type) {
343
+ if (tag.type != target_obj->cached.type) {
327
344
  giterr_set(GITERR_TAG, "The type for the given target is invalid");
328
345
  goto on_error;
329
346
  }
@@ -389,14 +406,8 @@ int git_tag_delete(git_repository *repo, const char *tag_name)
389
406
 
390
407
  if ((error = git_reference_delete(tag_ref)) == 0)
391
408
  git_reference_free(tag_ref);
392
-
393
- return error;
394
- }
395
409
 
396
- int git_tag__parse(git_tag *tag, git_odb_object *obj)
397
- {
398
- assert(tag);
399
- return git_tag__parse_buffer(tag, obj->raw.data, obj->raw.len);
410
+ return error;
400
411
  }
401
412
 
402
413
  typedef struct {
@@ -429,7 +440,7 @@ int git_tag_foreach(git_repository *repo, git_tag_foreach_cb cb, void *cb_data)
429
440
  data.cb_data = cb_data;
430
441
  data.repo = repo;
431
442
 
432
- return git_reference_foreach(repo, GIT_REF_OID, &tags_cb, &data);
443
+ return git_reference_foreach_name(repo, &tags_cb, &data);
433
444
  }
434
445
 
435
446
  typedef struct {
@@ -22,8 +22,7 @@ struct git_tag {
22
22
  char *message;
23
23
  };
24
24
 
25
- void git_tag__free(git_tag *tag);
26
- int git_tag__parse(git_tag *tag, git_odb_object *obj);
27
- int git_tag__parse_buffer(git_tag *tag, const char *data, size_t len);
25
+ void git_tag__free(void *tag);
26
+ int git_tag__parse(void *tag, git_odb_object *obj);
28
27
 
29
28
  #endif
@@ -7,8 +7,6 @@
7
7
  #ifndef INCLUDE_thread_utils_h__
8
8
  #define INCLUDE_thread_utils_h__
9
9
 
10
- #include "common.h"
11
-
12
10
  /* Common operations even if threading has been disabled */
13
11
  typedef struct {
14
12
  #if defined(GIT_WIN32)
@@ -18,6 +16,28 @@ typedef struct {
18
16
  #endif
19
17
  } git_atomic;
20
18
 
19
+ #ifdef GIT_ARCH_64
20
+
21
+ typedef struct {
22
+ #if defined(GIT_WIN32)
23
+ __int64 val;
24
+ #else
25
+ int64_t val;
26
+ #endif
27
+ } git_atomic64;
28
+
29
+ typedef git_atomic64 git_atomic_ssize;
30
+
31
+ #define git_atomic_ssize_add git_atomic64_add
32
+
33
+ #else
34
+
35
+ typedef git_atomic git_atomic_ssize;
36
+
37
+ #define git_atomic_ssize_add git_atomic_add
38
+
39
+ #endif
40
+
21
41
  GIT_INLINE(void) git_atomic_set(git_atomic *a, int val)
22
42
  {
23
43
  a->val = val;
@@ -57,6 +77,17 @@ GIT_INLINE(int) git_atomic_inc(git_atomic *a)
57
77
  #endif
58
78
  }
59
79
 
80
+ GIT_INLINE(int) git_atomic_add(git_atomic *a, int32_t addend)
81
+ {
82
+ #if defined(GIT_WIN32)
83
+ return InterlockedExchangeAdd(&a->val, addend);
84
+ #elif defined(__GNUC__)
85
+ return __sync_add_and_fetch(&a->val, addend);
86
+ #else
87
+ # error "Unsupported architecture for atomic operations"
88
+ #endif
89
+ }
90
+
60
91
  GIT_INLINE(int) git_atomic_dec(git_atomic *a)
61
92
  {
62
93
  #if defined(GIT_WIN32)
@@ -68,6 +99,35 @@ GIT_INLINE(int) git_atomic_dec(git_atomic *a)
68
99
  #endif
69
100
  }
70
101
 
102
+ GIT_INLINE(void *) git___compare_and_swap(
103
+ volatile void **ptr, void *oldval, void *newval)
104
+ {
105
+ volatile void *foundval;
106
+ #if defined(GIT_WIN32)
107
+ foundval = InterlockedCompareExchangePointer((volatile PVOID *)ptr, newval, oldval);
108
+ #elif defined(__GNUC__)
109
+ foundval = __sync_val_compare_and_swap(ptr, oldval, newval);
110
+ #else
111
+ # error "Unsupported architecture for atomic operations"
112
+ #endif
113
+ return (foundval == oldval) ? oldval : newval;
114
+ }
115
+
116
+ #ifdef GIT_ARCH_64
117
+
118
+ GIT_INLINE(int64_t) git_atomic64_add(git_atomic64 *a, int64_t addend)
119
+ {
120
+ #if defined(GIT_WIN32)
121
+ return InterlockedExchangeAdd64(&a->val, addend);
122
+ #elif defined(__GNUC__)
123
+ return __sync_add_and_fetch(&a->val, addend);
124
+ #else
125
+ # error "Unsupported architecture for atomic operations"
126
+ #endif
127
+ }
128
+
129
+ #endif
130
+
71
131
  #else
72
132
 
73
133
  #define git_thread unsigned int
@@ -78,7 +138,7 @@ GIT_INLINE(int) git_atomic_dec(git_atomic *a)
78
138
 
79
139
  /* Pthreads Mutex */
80
140
  #define git_mutex unsigned int
81
- #define git_mutex_init(a) (void)0
141
+ #define git_mutex_init(a) 0
82
142
  #define git_mutex_lock(a) 0
83
143
  #define git_mutex_unlock(a) (void)0
84
144
  #define git_mutex_free(a) (void)0
@@ -96,13 +156,55 @@ GIT_INLINE(int) git_atomic_inc(git_atomic *a)
96
156
  return ++a->val;
97
157
  }
98
158
 
159
+ GIT_INLINE(int) git_atomic_add(git_atomic *a, int32_t addend)
160
+ {
161
+ a->val += addend;
162
+ return a->val;
163
+ }
164
+
99
165
  GIT_INLINE(int) git_atomic_dec(git_atomic *a)
100
166
  {
101
167
  return --a->val;
102
168
  }
103
169
 
170
+ GIT_INLINE(void *) git___compare_and_swap(
171
+ volatile void **ptr, void *oldval, void *newval)
172
+ {
173
+ if (*ptr == oldval)
174
+ *ptr = newval;
175
+ else
176
+ oldval = newval;
177
+ return oldval;
178
+ }
179
+
180
+ #ifdef GIT_ARCH_64
181
+
182
+ GIT_INLINE(int64_t) git_atomic64_add(git_atomic64 *a, int64_t addend)
183
+ {
184
+ a->val += addend;
185
+ return a->val;
186
+ }
187
+
104
188
  #endif
105
189
 
190
+ #endif
191
+
192
+ /* Atomically replace oldval with newval
193
+ * @return oldval if it was replaced or newval if it was not
194
+ */
195
+ #define git__compare_and_swap(P,O,N) \
196
+ git___compare_and_swap((volatile void **)P, O, N)
197
+
198
+ #define git__swap(ptr, val) git__compare_and_swap(&ptr, ptr, val)
199
+
106
200
  extern int git_online_cpus(void);
107
201
 
202
+ #if defined(GIT_THREADS) && defined(GIT_WIN32)
203
+ # define GIT_MEMORY_BARRIER MemoryBarrier()
204
+ #elif defined(GIT_THREADS)
205
+ # define GIT_MEMORY_BARRIER __sync_synchronize()
206
+ #else
207
+ # define GIT_MEMORY_BARRIER /* noop */
208
+ #endif
209
+
108
210
  #endif /* INCLUDE_thread_utils_h__ */
@@ -25,7 +25,7 @@ int git_trace_set(git_trace_level_t level, git_trace_callback callback)
25
25
  git_trace__data.level = level;
26
26
  git_trace__data.callback = callback;
27
27
  GIT_MEMORY_BARRIER;
28
-
28
+
29
29
  return 0;
30
30
  #else
31
31
  GIT_UNUSED(level);
@@ -36,4 +36,3 @@ int git_trace_set(git_trace_level_t level, git_trace_callback callback)
36
36
  return -1;
37
37
  #endif
38
38
  }
39
-