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
@@ -11,7 +11,7 @@
11
11
  #include "git2/transport.h"
12
12
 
13
13
  #include "refspec.h"
14
- #include "repository.h"
14
+ #include "vector.h"
15
15
 
16
16
  #define GIT_REMOTE_ORIGIN "origin"
17
17
 
@@ -20,8 +20,7 @@ struct git_remote {
20
20
  char *url;
21
21
  char *pushurl;
22
22
  git_vector refs;
23
- struct git_refspec fetch;
24
- struct git_refspec push;
23
+ git_vector refspecs;
25
24
  git_cred_acquire_cb cred_acquire_cb;
26
25
  void *cred_acquire_payload;
27
26
  git_transport *transport;
@@ -37,4 +36,7 @@ struct git_remote {
37
36
  const char* git_remote__urlfordirection(struct git_remote *remote, int direction);
38
37
  int git_remote__get_http_proxy(git_remote *remote, bool use_ssl, char **proxy_url);
39
38
 
39
+ git_refspec *git_remote__matching_refspec(git_remote *remote, const char *refname);
40
+ git_refspec *git_remote__matching_dst_refspec(git_remote *remote, const char *refname);
41
+
40
42
  #endif
@@ -9,6 +9,7 @@
9
9
 
10
10
  #include "git2/object.h"
11
11
  #include "git2/refdb.h"
12
+ #include "git2/sys/repository.h"
12
13
 
13
14
  #include "common.h"
14
15
  #include "repository.h"
@@ -16,12 +17,15 @@
16
17
  #include "tag.h"
17
18
  #include "blob.h"
18
19
  #include "fileops.h"
20
+ #include "filebuf.h"
21
+ #include "index.h"
19
22
  #include "config.h"
20
23
  #include "refs.h"
21
24
  #include "filter.h"
22
25
  #include "odb.h"
23
26
  #include "remote.h"
24
27
  #include "merge.h"
28
+ #include "diff_driver.h"
25
29
 
26
30
  #define GIT_FILE_CONTENT_PREFIX "gitdir:"
27
31
 
@@ -31,61 +35,91 @@
31
35
 
32
36
  #define GIT_TEMPLATE_DIR "/usr/share/git-core/templates"
33
37
 
34
- static void drop_odb(git_repository *repo)
38
+ static void set_odb(git_repository *repo, git_odb *odb)
35
39
  {
36
- if (repo->_odb != NULL) {
37
- GIT_REFCOUNT_OWN(repo->_odb, NULL);
38
- git_odb_free(repo->_odb);
39
- repo->_odb = NULL;
40
+ if (odb) {
41
+ GIT_REFCOUNT_OWN(odb, repo);
42
+ GIT_REFCOUNT_INC(odb);
43
+ }
44
+
45
+ if ((odb = git__swap(repo->_odb, odb)) != NULL) {
46
+ GIT_REFCOUNT_OWN(odb, NULL);
47
+ git_odb_free(odb);
40
48
  }
41
49
  }
42
50
 
43
- static void drop_refdb(git_repository *repo)
51
+ static void set_refdb(git_repository *repo, git_refdb *refdb)
44
52
  {
45
- if (repo->_refdb != NULL) {
46
- GIT_REFCOUNT_OWN(repo->_refdb, NULL);
47
- git_refdb_free(repo->_refdb);
48
- repo->_refdb = NULL;
53
+ if (refdb) {
54
+ GIT_REFCOUNT_OWN(refdb, repo);
55
+ GIT_REFCOUNT_INC(refdb);
56
+ }
57
+
58
+ if ((refdb = git__swap(repo->_refdb, refdb)) != NULL) {
59
+ GIT_REFCOUNT_OWN(refdb, NULL);
60
+ git_refdb_free(refdb);
49
61
  }
50
62
  }
51
63
 
52
- static void drop_config(git_repository *repo)
64
+ static void set_config(git_repository *repo, git_config *config)
53
65
  {
54
- if (repo->_config != NULL) {
55
- GIT_REFCOUNT_OWN(repo->_config, NULL);
56
- git_config_free(repo->_config);
57
- repo->_config = NULL;
66
+ if (config) {
67
+ GIT_REFCOUNT_OWN(config, repo);
68
+ GIT_REFCOUNT_INC(config);
69
+ }
70
+
71
+ if ((config = git__swap(repo->_config, config)) != NULL) {
72
+ GIT_REFCOUNT_OWN(config, NULL);
73
+ git_config_free(config);
58
74
  }
59
75
 
60
76
  git_repository__cvar_cache_clear(repo);
61
77
  }
62
78
 
63
- static void drop_index(git_repository *repo)
79
+ static void set_index(git_repository *repo, git_index *index)
64
80
  {
65
- if (repo->_index != NULL) {
66
- GIT_REFCOUNT_OWN(repo->_index, NULL);
67
- git_index_free(repo->_index);
68
- repo->_index = NULL;
81
+ if (index) {
82
+ GIT_REFCOUNT_OWN(index, repo);
83
+ GIT_REFCOUNT_INC(index);
84
+ }
85
+
86
+ if ((index = git__swap(repo->_index, index)) != NULL) {
87
+ GIT_REFCOUNT_OWN(index, NULL);
88
+ git_index_free(index);
69
89
  }
70
90
  }
71
91
 
92
+ void git_repository__cleanup(git_repository *repo)
93
+ {
94
+ assert(repo);
95
+
96
+ git_cache_clear(&repo->objects);
97
+ git_attr_cache_flush(repo);
98
+
99
+ set_config(repo, NULL);
100
+ set_index(repo, NULL);
101
+ set_odb(repo, NULL);
102
+ set_refdb(repo, NULL);
103
+ }
104
+
72
105
  void git_repository_free(git_repository *repo)
73
106
  {
74
107
  if (repo == NULL)
75
108
  return;
76
109
 
110
+ git_repository__cleanup(repo);
111
+
77
112
  git_cache_free(&repo->objects);
78
- git_attr_cache_flush(repo);
79
113
  git_submodule_config_free(repo);
80
114
 
115
+ git_diff_driver_registry_free(repo->diff_drivers);
116
+ repo->diff_drivers = NULL;
117
+
81
118
  git__free(repo->path_repository);
82
119
  git__free(repo->workdir);
120
+ git__free(repo->namespace);
83
121
 
84
- drop_config(repo);
85
- drop_index(repo);
86
- drop_odb(repo);
87
- drop_refdb(repo);
88
-
122
+ git__memzero(repo, sizeof(*repo));
89
123
  git__free(repo);
90
124
  }
91
125
 
@@ -112,13 +146,11 @@ static bool valid_repository_path(git_buf *repository_path)
112
146
 
113
147
  static git_repository *repository_alloc(void)
114
148
  {
115
- git_repository *repo = git__malloc(sizeof(git_repository));
149
+ git_repository *repo = git__calloc(1, sizeof(git_repository));
116
150
  if (!repo)
117
151
  return NULL;
118
152
 
119
- memset(repo, 0x0, sizeof(git_repository));
120
-
121
- if (git_cache_init(&repo->objects, GIT_DEFAULT_CACHE_SIZE, &git_object__free) < 0) {
153
+ if (git_cache_init(&repo->objects) < 0) {
122
154
  git__free(repo);
123
155
  return NULL;
124
156
  }
@@ -129,6 +161,12 @@ static git_repository *repository_alloc(void)
129
161
  return repo;
130
162
  }
131
163
 
164
+ int git_repository_new(git_repository **out)
165
+ {
166
+ *out = repository_alloc();
167
+ return 0;
168
+ }
169
+
132
170
  static int load_config_data(git_repository *repo)
133
171
  {
134
172
  int is_bare;
@@ -542,39 +580,51 @@ on_error:
542
580
  return error;
543
581
  }
544
582
 
545
- int git_repository_config__weakptr(git_config **out, git_repository *repo)
583
+ static const char *path_unless_empty(git_buf *buf)
546
584
  {
547
- if (repo->_config == NULL) {
548
- git_buf global_buf = GIT_BUF_INIT, xdg_buf = GIT_BUF_INIT, system_buf = GIT_BUF_INIT;
549
- int res;
550
-
551
- const char *global_config_path = NULL;
552
- const char *xdg_config_path = NULL;
553
- const char *system_config_path = NULL;
554
-
555
- if (git_config_find_global_r(&global_buf) == 0)
556
- global_config_path = global_buf.ptr;
585
+ return git_buf_len(buf) > 0 ? git_buf_cstr(buf) : NULL;
586
+ }
557
587
 
558
- if (git_config_find_xdg_r(&xdg_buf) == 0)
559
- xdg_config_path = xdg_buf.ptr;
588
+ int git_repository_config__weakptr(git_config **out, git_repository *repo)
589
+ {
590
+ int error = 0;
560
591
 
561
- if (git_config_find_system_r(&system_buf) == 0)
562
- system_config_path = system_buf.ptr;
592
+ if (repo->_config == NULL) {
593
+ git_buf global_buf = GIT_BUF_INIT;
594
+ git_buf xdg_buf = GIT_BUF_INIT;
595
+ git_buf system_buf = GIT_BUF_INIT;
596
+ git_config *config;
563
597
 
564
- res = load_config(&repo->_config, repo, global_config_path, xdg_config_path, system_config_path);
598
+ git_config_find_global_r(&global_buf);
599
+ git_config_find_xdg_r(&xdg_buf);
600
+ git_config_find_system_r(&system_buf);
601
+
602
+ /* If there is no global file, open a backend for it anyway */
603
+ if (git_buf_len(&global_buf) == 0)
604
+ git_config__global_location(&global_buf);
605
+
606
+ error = load_config(
607
+ &config, repo,
608
+ path_unless_empty(&global_buf),
609
+ path_unless_empty(&xdg_buf),
610
+ path_unless_empty(&system_buf));
611
+ if (!error) {
612
+ GIT_REFCOUNT_OWN(config, repo);
613
+
614
+ config = git__compare_and_swap(&repo->_config, NULL, config);
615
+ if (config != NULL) {
616
+ GIT_REFCOUNT_OWN(config, NULL);
617
+ git_config_free(config);
618
+ }
619
+ }
565
620
 
566
621
  git_buf_free(&global_buf);
567
622
  git_buf_free(&xdg_buf);
568
623
  git_buf_free(&system_buf);
569
-
570
- if (res < 0)
571
- return -1;
572
-
573
- GIT_REFCOUNT_OWN(repo->_config, repo);
574
624
  }
575
625
 
576
626
  *out = repo->_config;
577
- return 0;
627
+ return error;
578
628
  }
579
629
 
580
630
  int git_repository_config(git_config **out, git_repository *repo)
@@ -589,36 +639,37 @@ int git_repository_config(git_config **out, git_repository *repo)
589
639
  void git_repository_set_config(git_repository *repo, git_config *config)
590
640
  {
591
641
  assert(repo && config);
592
-
593
- drop_config(repo);
594
-
595
- repo->_config = config;
596
- GIT_REFCOUNT_OWN(repo->_config, repo);
597
- GIT_REFCOUNT_INC(repo->_config);
642
+ set_config(repo, config);
598
643
  }
599
644
 
600
645
  int git_repository_odb__weakptr(git_odb **out, git_repository *repo)
601
646
  {
647
+ int error = 0;
648
+
602
649
  assert(repo && out);
603
650
 
604
651
  if (repo->_odb == NULL) {
605
652
  git_buf odb_path = GIT_BUF_INIT;
606
- int res;
653
+ git_odb *odb;
607
654
 
608
- if (git_buf_joinpath(&odb_path, repo->path_repository, GIT_OBJECTS_DIR) < 0)
609
- return -1;
655
+ git_buf_joinpath(&odb_path, repo->path_repository, GIT_OBJECTS_DIR);
610
656
 
611
- res = git_odb_open(&repo->_odb, odb_path.ptr);
612
- git_buf_free(&odb_path); /* done with path */
657
+ error = git_odb_open(&odb, odb_path.ptr);
658
+ if (!error) {
659
+ GIT_REFCOUNT_OWN(odb, repo);
613
660
 
614
- if (res < 0)
615
- return -1;
661
+ odb = git__compare_and_swap(&repo->_odb, NULL, odb);
662
+ if (odb != NULL) {
663
+ GIT_REFCOUNT_OWN(odb, NULL);
664
+ git_odb_free(odb);
665
+ }
666
+ }
616
667
 
617
- GIT_REFCOUNT_OWN(repo->_odb, repo);
668
+ git_buf_free(&odb_path);
618
669
  }
619
670
 
620
671
  *out = repo->_odb;
621
- return 0;
672
+ return error;
622
673
  }
623
674
 
624
675
  int git_repository_odb(git_odb **out, git_repository *repo)
@@ -633,31 +684,32 @@ int git_repository_odb(git_odb **out, git_repository *repo)
633
684
  void git_repository_set_odb(git_repository *repo, git_odb *odb)
634
685
  {
635
686
  assert(repo && odb);
636
-
637
- drop_odb(repo);
638
-
639
- repo->_odb = odb;
640
- GIT_REFCOUNT_OWN(repo->_odb, repo);
641
- GIT_REFCOUNT_INC(odb);
687
+ set_odb(repo, odb);
642
688
  }
643
689
 
644
690
  int git_repository_refdb__weakptr(git_refdb **out, git_repository *repo)
645
691
  {
692
+ int error = 0;
693
+
646
694
  assert(out && repo);
647
695
 
648
696
  if (repo->_refdb == NULL) {
649
- int res;
650
-
651
- res = git_refdb_open(&repo->_refdb, repo);
697
+ git_refdb *refdb;
652
698
 
653
- if (res < 0)
654
- return -1;
699
+ error = git_refdb_open(&refdb, repo);
700
+ if (!error) {
701
+ GIT_REFCOUNT_OWN(refdb, repo);
655
702
 
656
- GIT_REFCOUNT_OWN(repo->_refdb, repo);
703
+ refdb = git__compare_and_swap(&repo->_refdb, NULL, refdb);
704
+ if (refdb != NULL) {
705
+ GIT_REFCOUNT_OWN(refdb, NULL);
706
+ git_refdb_free(refdb);
707
+ }
708
+ }
657
709
  }
658
710
 
659
711
  *out = repo->_refdb;
660
- return 0;
712
+ return error;
661
713
  }
662
714
 
663
715
  int git_repository_refdb(git_refdb **out, git_repository *repo)
@@ -671,40 +723,40 @@ int git_repository_refdb(git_refdb **out, git_repository *repo)
671
723
 
672
724
  void git_repository_set_refdb(git_repository *repo, git_refdb *refdb)
673
725
  {
674
- assert (repo && refdb);
675
-
676
- drop_refdb(repo);
677
-
678
- repo->_refdb = refdb;
679
- GIT_REFCOUNT_OWN(repo->_refdb, repo);
680
- GIT_REFCOUNT_INC(refdb);
726
+ assert(repo && refdb);
727
+ set_refdb(repo, refdb);
681
728
  }
682
729
 
683
730
  int git_repository_index__weakptr(git_index **out, git_repository *repo)
684
731
  {
732
+ int error = 0;
733
+
685
734
  assert(out && repo);
686
735
 
687
736
  if (repo->_index == NULL) {
688
- int res;
689
737
  git_buf index_path = GIT_BUF_INIT;
738
+ git_index *index;
690
739
 
691
- if (git_buf_joinpath(&index_path, repo->path_repository, GIT_INDEX_FILE) < 0)
692
- return -1;
740
+ git_buf_joinpath(&index_path, repo->path_repository, GIT_INDEX_FILE);
693
741
 
694
- res = git_index_open(&repo->_index, index_path.ptr);
695
- git_buf_free(&index_path); /* done with path */
742
+ error = git_index_open(&index, index_path.ptr);
743
+ if (!error) {
744
+ GIT_REFCOUNT_OWN(index, repo);
696
745
 
697
- if (res < 0)
698
- return -1;
746
+ index = git__compare_and_swap(&repo->_index, NULL, index);
747
+ if (index != NULL) {
748
+ GIT_REFCOUNT_OWN(index, NULL);
749
+ git_index_free(index);
750
+ }
699
751
 
700
- GIT_REFCOUNT_OWN(repo->_index, repo);
752
+ error = git_index_set_caps(repo->_index, GIT_INDEXCAP_FROM_OWNER);
753
+ }
701
754
 
702
- if (git_index_set_caps(repo->_index, GIT_INDEXCAP_FROM_OWNER) < 0)
703
- return -1;
755
+ git_buf_free(&index_path);
704
756
  }
705
757
 
706
758
  *out = repo->_index;
707
- return 0;
759
+ return error;
708
760
  }
709
761
 
710
762
  int git_repository_index(git_index **out, git_repository *repo)
@@ -719,12 +771,24 @@ int git_repository_index(git_index **out, git_repository *repo)
719
771
  void git_repository_set_index(git_repository *repo, git_index *index)
720
772
  {
721
773
  assert(repo && index);
774
+ set_index(repo, index);
775
+ }
776
+
777
+ int git_repository_set_namespace(git_repository *repo, const char *namespace)
778
+ {
779
+ git__free(repo->namespace);
722
780
 
723
- drop_index(repo);
781
+ if (namespace == NULL) {
782
+ repo->namespace = NULL;
783
+ return 0;
784
+ }
724
785
 
725
- repo->_index = index;
726
- GIT_REFCOUNT_OWN(repo->_index, repo);
727
- GIT_REFCOUNT_INC(index);
786
+ return (repo->namespace = git__strdup(namespace)) ? 0 : -1;
787
+ }
788
+
789
+ const char *git_repository_get_namespace(git_repository *repo)
790
+ {
791
+ return repo->namespace;
728
792
  }
729
793
 
730
794
  static int check_repositoryformatversion(git_config *config)
@@ -1414,14 +1478,15 @@ static int at_least_one_cb(const char *refname, void *payload)
1414
1478
 
1415
1479
  static int repo_contains_no_reference(git_repository *repo)
1416
1480
  {
1417
- int error;
1418
-
1419
- error = git_reference_foreach(repo, GIT_REF_LISTALL, at_least_one_cb, NULL);
1481
+ int error = git_reference_foreach_name(repo, &at_least_one_cb, NULL);
1420
1482
 
1421
1483
  if (error == GIT_EUSER)
1422
1484
  return 0;
1423
1485
 
1424
- return error == 0 ? 1 : error;
1486
+ if (!error)
1487
+ return 1;
1488
+
1489
+ return error;
1425
1490
  }
1426
1491
 
1427
1492
  int git_repository_is_empty(git_repository *repo)
@@ -1538,12 +1603,16 @@ int git_repository_message(char *buffer, size_t len, git_repository *repo)
1538
1603
  struct stat st;
1539
1604
  int error;
1540
1605
 
1606
+ if (buffer != NULL)
1607
+ *buffer = '\0';
1608
+
1541
1609
  if (git_buf_joinpath(&path, repo->path_repository, GIT_MERGE_MSG_FILE) < 0)
1542
1610
  return -1;
1543
1611
 
1544
1612
  if ((error = p_stat(git_buf_cstr(&path), &st)) < 0) {
1545
1613
  if (errno == ENOENT)
1546
1614
  error = GIT_ENOTFOUND;
1615
+ giterr_set(GITERR_OS, "Could not access message file");
1547
1616
  }
1548
1617
  else if (buffer != NULL) {
1549
1618
  error = git_futils_readbuffer(&buf, git_buf_cstr(&path));
@@ -1574,11 +1643,11 @@ int git_repository_message_remove(git_repository *repo)
1574
1643
  }
1575
1644
 
1576
1645
  int git_repository_hashfile(
1577
- git_oid *out,
1578
- git_repository *repo,
1579
- const char *path,
1580
- git_otype type,
1581
- const char *as_path)
1646
+ git_oid *out,
1647
+ git_repository *repo,
1648
+ const char *path,
1649
+ git_otype type,
1650
+ const char *as_path)
1582
1651
  {
1583
1652
  int error;
1584
1653
  git_vector filters = GIT_VECTOR_INIT;
@@ -1760,3 +1829,20 @@ int git_repository_state(git_repository *repo)
1760
1829
  git_buf_free(&repo_path);
1761
1830
  return state;
1762
1831
  }
1832
+
1833
+ int git_repository_is_shallow(git_repository *repo)
1834
+ {
1835
+ git_buf path = GIT_BUF_INIT;
1836
+ struct stat st;
1837
+ int error;
1838
+
1839
+ git_buf_joinpath(&path, repo->path_repository, "shallow");
1840
+ error = git_path_lstat(path.ptr, &st);
1841
+ git_buf_free(&path);
1842
+
1843
+ if (error == GIT_ENOTFOUND)
1844
+ return 0;
1845
+ if (error < 0)
1846
+ return -1;
1847
+ return st.st_size == 0 ? 0 : 1;
1848
+ }