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
@@ -29,14 +29,14 @@ typedef struct {
29
29
  /* EXPORT */
30
30
  struct git_odb_object {
31
31
  git_cached_obj cached;
32
- git_rawobj raw;
32
+ void *buffer;
33
33
  };
34
34
 
35
35
  /* EXPORT */
36
36
  struct git_odb {
37
37
  git_refcount rc;
38
38
  git_vector backends;
39
- git_cache cache;
39
+ git_cache own_cache;
40
40
  };
41
41
 
42
42
  /*
@@ -96,4 +96,7 @@ int git_odb__read_header_or_object(
96
96
  git_odb_object **out, size_t *len_p, git_otype *type_p,
97
97
  git_odb *db, const git_oid *id);
98
98
 
99
+ /* fully free the object; internal method, DO NOT EXPORT */
100
+ void git_odb_object__free(void *object);
101
+
99
102
  #endif
@@ -8,7 +8,7 @@
8
8
  #include "common.h"
9
9
  #include <zlib.h>
10
10
  #include "git2/object.h"
11
- #include "git2/oid.h"
11
+ #include "git2/sys/odb_backend.h"
12
12
  #include "fileops.h"
13
13
  #include "hash.h"
14
14
  #include "odb.h"
@@ -33,7 +33,9 @@ typedef struct loose_backend {
33
33
 
34
34
  int object_zlib_level; /** loose object zlib compression level. */
35
35
  int fsync_object_files; /** loose object file fsync flag. */
36
- char *objects_dir;
36
+
37
+ size_t objects_dirlen;
38
+ char objects_dir[GIT_FLEX_ARRAY];
37
39
  } loose_backend;
38
40
 
39
41
  /* State structure for exploring directories,
@@ -56,24 +58,30 @@ typedef struct {
56
58
  *
57
59
  ***********************************************************/
58
60
 
59
- static int object_file_name(git_buf *name, const char *dir, const git_oid *id)
61
+ static int object_file_name(
62
+ git_buf *name, const loose_backend *be, const git_oid *id)
60
63
  {
61
- git_buf_sets(name, dir);
62
-
63
- /* expand length for 40 hex sha1 chars + 2 * '/' + '\0' */
64
- if (git_buf_grow(name, git_buf_len(name) + GIT_OID_HEXSZ + 3) < 0)
64
+ /* expand length for object root + 40 hex sha1 chars + 2 * '/' + '\0' */
65
+ if (git_buf_grow(name, be->objects_dirlen + GIT_OID_HEXSZ + 3) < 0)
65
66
  return -1;
66
67
 
68
+ git_buf_set(name, be->objects_dir, be->objects_dirlen);
67
69
  git_path_to_dir(name);
68
70
 
69
71
  /* loose object filename: aa/aaa... (41 bytes) */
70
- git_oid_pathfmt(name->ptr + git_buf_len(name), id);
72
+ git_oid_pathfmt(name->ptr + name->size, id);
71
73
  name->size += GIT_OID_HEXSZ + 1;
72
74
  name->ptr[name->size] = '\0';
73
75
 
74
76
  return 0;
75
77
  }
76
78
 
79
+ static int object_mkdir(const git_buf *name, const loose_backend *be)
80
+ {
81
+ return git_futils_mkdir(
82
+ name->ptr + be->objects_dirlen, be->objects_dir, GIT_OBJECT_DIR_MODE,
83
+ GIT_MKDIR_PATH | GIT_MKDIR_SKIP_LAST | GIT_MKDIR_VERIFY_DIR);
84
+ }
77
85
 
78
86
  static size_t get_binary_object_header(obj_hdr *hdr, git_buf *obj)
79
87
  {
@@ -457,7 +465,7 @@ static int locate_object(
457
465
  loose_backend *backend,
458
466
  const git_oid *oid)
459
467
  {
460
- int error = object_file_name(object_location, backend->objects_dir, oid);
468
+ int error = object_file_name(object_location, backend, oid);
461
469
 
462
470
  if (!error && !git_path_exists(object_location->ptr))
463
471
  return GIT_ENOTFOUND;
@@ -769,8 +777,8 @@ static int loose_backend__stream_fwrite(git_oid *oid, git_odb_stream *_stream)
769
777
  int error = 0;
770
778
 
771
779
  if (git_filebuf_hash(oid, &stream->fbuf) < 0 ||
772
- object_file_name(&final_path, backend->objects_dir, oid) < 0 ||
773
- git_futils_mkpath2file(final_path.ptr, GIT_OBJECT_DIR_MODE) < 0)
780
+ object_file_name(&final_path, backend, oid) < 0 ||
781
+ object_mkdir(&final_path, backend) < 0)
774
782
  error = -1;
775
783
  /*
776
784
  * Don't try to add an existing object to the repository. This
@@ -880,8 +888,8 @@ static int loose_backend__write(git_oid *oid, git_odb_backend *_backend, const v
880
888
  git_filebuf_write(&fbuf, header, header_len);
881
889
  git_filebuf_write(&fbuf, data, len);
882
890
 
883
- if (object_file_name(&final_path, backend->objects_dir, oid) < 0 ||
884
- git_futils_mkpath2file(final_path.ptr, GIT_OBJECT_DIR_MODE) < 0 ||
891
+ if (object_file_name(&final_path, backend, oid) < 0 ||
892
+ object_mkdir(&final_path, backend) < 0 ||
885
893
  git_filebuf_commit_at(&fbuf, final_path.ptr, GIT_OBJECT_FILE_MODE) < 0)
886
894
  error = -1;
887
895
 
@@ -898,7 +906,6 @@ static void loose_backend__free(git_odb_backend *_backend)
898
906
  assert(_backend);
899
907
  backend = (loose_backend *)_backend;
900
908
 
901
- git__free(backend->objects_dir);
902
909
  git__free(backend);
903
910
  }
904
911
 
@@ -909,13 +916,20 @@ int git_odb_backend_loose(
909
916
  int do_fsync)
910
917
  {
911
918
  loose_backend *backend;
919
+ size_t objects_dirlen;
920
+
921
+ assert(backend_out && objects_dir);
922
+
923
+ objects_dirlen = strlen(objects_dir);
912
924
 
913
- backend = git__calloc(1, sizeof(loose_backend));
925
+ backend = git__calloc(1, sizeof(loose_backend) + objects_dirlen + 2);
914
926
  GITERR_CHECK_ALLOC(backend);
915
927
 
916
928
  backend->parent.version = GIT_ODB_BACKEND_VERSION;
917
- backend->objects_dir = git__strdup(objects_dir);
918
- GITERR_CHECK_ALLOC(backend->objects_dir);
929
+ backend->objects_dirlen = objects_dirlen;
930
+ memcpy(backend->objects_dir, objects_dir, objects_dirlen);
931
+ if (backend->objects_dir[backend->objects_dirlen - 1] != '/')
932
+ backend->objects_dir[backend->objects_dirlen++] = '/';
919
933
 
920
934
  if (compression_level < 0)
921
935
  compression_level = Z_BEST_SPEED;
@@ -8,7 +8,8 @@
8
8
  #include "common.h"
9
9
  #include <zlib.h>
10
10
  #include "git2/repository.h"
11
- #include "git2/oid.h"
11
+ #include "git2/indexer.h"
12
+ #include "git2/sys/odb_backend.h"
12
13
  #include "fileops.h"
13
14
  #include "hash.h"
14
15
  #include "odb.h"
@@ -206,7 +207,7 @@ static int packfile_load__cb(void *_data, git_buf *path)
206
207
  return 0;
207
208
  }
208
209
 
209
- error = git_packfile_check(&pack, path->ptr);
210
+ error = git_packfile_alloc(&pack, path->ptr);
210
211
  if (error == GIT_ENOTFOUND)
211
212
  /* ignore missing .pack file as git does */
212
213
  return 0;
@@ -526,80 +527,75 @@ static void pack_backend__free(git_odb_backend *_backend)
526
527
  git__free(backend);
527
528
  }
528
529
 
529
- int git_odb_backend_one_pack(git_odb_backend **backend_out, const char *idx)
530
+ static int pack_backend__alloc(struct pack_backend **out, size_t initial_size)
530
531
  {
531
- struct pack_backend *backend = NULL;
532
- struct git_pack_file *packfile = NULL;
532
+ struct pack_backend *backend = git__calloc(1, sizeof(struct pack_backend));
533
+ GITERR_CHECK_ALLOC(backend);
533
534
 
534
- if (git_packfile_check(&packfile, idx) < 0)
535
+ if (git_vector_init(&backend->packs, initial_size, packfile_sort__cb) < 0) {
536
+ git__free(backend);
535
537
  return -1;
538
+ }
536
539
 
537
- backend = git__calloc(1, sizeof(struct pack_backend));
538
- GITERR_CHECK_ALLOC(backend);
539
540
  backend->parent.version = GIT_ODB_BACKEND_VERSION;
540
541
 
541
- if (git_vector_init(&backend->packs, 1, NULL) < 0)
542
- goto on_error;
543
-
544
- if (git_vector_insert(&backend->packs, packfile) < 0)
545
- goto on_error;
546
-
547
542
  backend->parent.read = &pack_backend__read;
548
543
  backend->parent.read_prefix = &pack_backend__read_prefix;
549
544
  backend->parent.read_header = &pack_backend__read_header;
550
545
  backend->parent.exists = &pack_backend__exists;
551
546
  backend->parent.refresh = &pack_backend__refresh;
552
547
  backend->parent.foreach = &pack_backend__foreach;
548
+ backend->parent.writepack = &pack_backend__writepack;
553
549
  backend->parent.free = &pack_backend__free;
554
550
 
555
- *backend_out = (git_odb_backend *)backend;
556
-
551
+ *out = backend;
557
552
  return 0;
558
-
559
- on_error:
560
- git_vector_free(&backend->packs);
561
- git__free(backend);
562
- git__free(packfile);
563
- return -1;
564
553
  }
565
554
 
566
- int git_odb_backend_pack(git_odb_backend **backend_out, const char *objects_dir)
555
+ int git_odb_backend_one_pack(git_odb_backend **backend_out, const char *idx)
567
556
  {
568
557
  struct pack_backend *backend = NULL;
569
- git_buf path = GIT_BUF_INIT;
558
+ struct git_pack_file *packfile = NULL;
570
559
 
571
- backend = git__calloc(1, sizeof(struct pack_backend));
572
- GITERR_CHECK_ALLOC(backend);
573
- backend->parent.version = GIT_ODB_BACKEND_VERSION;
560
+ if (pack_backend__alloc(&backend, 1) < 0)
561
+ return -1;
574
562
 
575
- if (git_vector_init(&backend->packs, 8, packfile_sort__cb) < 0 ||
576
- git_buf_joinpath(&path, objects_dir, "pack") < 0)
563
+ if (git_packfile_alloc(&packfile, idx) < 0 ||
564
+ git_vector_insert(&backend->packs, packfile) < 0)
577
565
  {
578
- git__free(backend);
566
+ pack_backend__free((git_odb_backend *)backend);
579
567
  return -1;
580
568
  }
581
569
 
582
- if (git_path_isdir(git_buf_cstr(&path)) == true) {
583
- int error;
570
+ *backend_out = (git_odb_backend *)backend;
571
+ return 0;
572
+ }
573
+
574
+ int git_odb_backend_pack(git_odb_backend **backend_out, const char *objects_dir)
575
+ {
576
+ int error = 0;
577
+ struct pack_backend *backend = NULL;
578
+ git_buf path = GIT_BUF_INIT;
579
+
580
+ if (pack_backend__alloc(&backend, 8) < 0)
581
+ return -1;
584
582
 
583
+ if (!(error = git_buf_joinpath(&path, objects_dir, "pack")) &&
584
+ git_path_isdir(git_buf_cstr(&path)))
585
+ {
585
586
  backend->pack_folder = git_buf_detach(&path);
587
+
586
588
  error = pack_backend__refresh((git_odb_backend *)backend);
587
- if (error < 0)
588
- return error;
589
589
  }
590
590
 
591
- backend->parent.read = &pack_backend__read;
592
- backend->parent.read_prefix = &pack_backend__read_prefix;
593
- backend->parent.read_header = &pack_backend__read_header;
594
- backend->parent.exists = &pack_backend__exists;
595
- backend->parent.refresh = &pack_backend__refresh;
596
- backend->parent.foreach = &pack_backend__foreach;
597
- backend->parent.writepack = &pack_backend__writepack;
598
- backend->parent.free = &pack_backend__free;
591
+ if (error < 0) {
592
+ pack_backend__free((git_odb_backend *)backend);
593
+ backend = NULL;
594
+ }
599
595
 
600
596
  *backend_out = (git_odb_backend *)backend;
601
597
 
602
598
  git_buf_free(&path);
603
599
 
604
- return 0;
600
+ return error;
605
601
  }
@@ -68,12 +68,31 @@ GIT_INLINE(char) *fmt_one(char *str, unsigned int val)
68
68
  return str;
69
69
  }
70
70
 
71
- void git_oid_fmt(char *str, const git_oid *oid)
71
+ void git_oid_nfmt(char *str, size_t n, const git_oid *oid)
72
72
  {
73
- size_t i;
73
+ size_t i, max_i;
74
+
75
+ if (!oid) {
76
+ memset(str, 0, n);
77
+ return;
78
+ }
79
+ if (n > GIT_OID_HEXSZ) {
80
+ memset(&str[GIT_OID_HEXSZ], 0, n - GIT_OID_HEXSZ);
81
+ n = GIT_OID_HEXSZ;
82
+ }
83
+
84
+ max_i = n / 2;
74
85
 
75
- for (i = 0; i < sizeof(oid->id); i++)
86
+ for (i = 0; i < max_i; i++)
76
87
  str = fmt_one(str, oid->id[i]);
88
+
89
+ if (n & 1)
90
+ *str++ = to_hex[oid->id[i] >> 4];
91
+ }
92
+
93
+ void git_oid_fmt(char *str, const git_oid *oid)
94
+ {
95
+ git_oid_nfmt(str, GIT_OID_HEXSZ, oid);
77
96
  }
78
97
 
79
98
  void git_oid_pathfmt(char *str, const git_oid *oid)
@@ -91,31 +110,20 @@ char *git_oid_allocfmt(const git_oid *oid)
91
110
  char *str = git__malloc(GIT_OID_HEXSZ + 1);
92
111
  if (!str)
93
112
  return NULL;
94
- git_oid_fmt(str, oid);
95
- str[GIT_OID_HEXSZ] = '\0';
113
+ git_oid_nfmt(str, GIT_OID_HEXSZ + 1, oid);
96
114
  return str;
97
115
  }
98
116
 
99
117
  char *git_oid_tostr(char *out, size_t n, const git_oid *oid)
100
118
  {
101
- char str[GIT_OID_HEXSZ];
102
-
103
119
  if (!out || n == 0)
104
120
  return "";
105
121
 
106
- n--; /* allow room for terminating NUL */
107
-
108
- if (oid == NULL)
109
- n = 0;
110
-
111
- if (n > 0) {
112
- git_oid_fmt(str, oid);
113
- if (n > GIT_OID_HEXSZ)
114
- n = GIT_OID_HEXSZ;
115
- memcpy(out, str, n);
116
- }
122
+ if (n > GIT_OID_HEXSZ + 1)
123
+ n = GIT_OID_HEXSZ + 1;
117
124
 
118
- out[n] = '\0';
125
+ git_oid_nfmt(out, n - 1, oid); /* allow room for terminating NUL */
126
+ out[n - 1] = '\0';
119
127
 
120
128
  return out;
121
129
  }
@@ -166,18 +174,26 @@ void git_oid_cpy(git_oid *out, const git_oid *src)
166
174
  memcpy(out->id, src->id, sizeof(out->id));
167
175
  }
168
176
 
177
+ int git_oid_cmp(const git_oid *a, const git_oid *b)
178
+ {
179
+ return git_oid__cmp(a, b);
180
+ }
181
+
169
182
  int git_oid_ncmp(const git_oid *oid_a, const git_oid *oid_b, size_t len)
170
183
  {
171
184
  const unsigned char *a = oid_a->id;
172
185
  const unsigned char *b = oid_b->id;
173
186
 
174
- do {
187
+ if (len > GIT_OID_HEXSZ)
188
+ len = GIT_OID_HEXSZ;
189
+
190
+ while (len > 1) {
175
191
  if (*a != *b)
176
192
  return 1;
177
193
  a++;
178
194
  b++;
179
195
  len -= 2;
180
- } while (len > 1);
196
+ };
181
197
 
182
198
  if (len)
183
199
  if ((*a ^ *b) & 0xf0)
@@ -186,14 +202,31 @@ int git_oid_ncmp(const git_oid *oid_a, const git_oid *oid_b, size_t len)
186
202
  return 0;
187
203
  }
188
204
 
189
- int git_oid_streq(const git_oid *a, const char *str)
205
+ int git_oid_strcmp(const git_oid *oid_a, const char *str)
190
206
  {
191
- git_oid id;
207
+ const unsigned char *a = oid_a->id;
208
+ unsigned char strval;
209
+ int hexval;
192
210
 
193
- if (git_oid_fromstr(&id, str) < 0)
194
- return -1;
211
+ for (a = oid_a->id; *str && (a - oid_a->id) < GIT_OID_RAWSZ; ++a) {
212
+ if ((hexval = git__fromhex(*str++)) < 0)
213
+ return -1;
214
+ strval = hexval << 4;
215
+ if (*str) {
216
+ if ((hexval = git__fromhex(*str++)) < 0)
217
+ return -1;
218
+ strval |= hexval;
219
+ }
220
+ if (*a != strval)
221
+ return (*a - strval);
222
+ }
195
223
 
196
- return git_oid_cmp(a, &id) == 0 ? 0 : -1;
224
+ return 0;
225
+ }
226
+
227
+ int git_oid_streq(const git_oid *oid_a, const char *str)
228
+ {
229
+ return git_oid_strcmp(oid_a, str) == 0 ? 0 : -1;
197
230
  }
198
231
 
199
232
  int git_oid_iszero(const git_oid *oid_a)
@@ -244,8 +277,10 @@ static trie_node *push_leaf(git_oid_shorten *os, node_index idx, int push_at, co
244
277
 
245
278
  idx_leaf = (node_index)os->node_count++;
246
279
 
247
- if (os->node_count == SHRT_MAX)
280
+ if (os->node_count == SHRT_MAX) {
248
281
  os->full = 1;
282
+ return NULL;
283
+ }
249
284
 
250
285
  node = &os->nodes[idx];
251
286
  node->children[push_at] = -idx_leaf;
@@ -0,0 +1,33 @@
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_oid_h__
8
+ #define INCLUDE_oid_h__
9
+
10
+ #include "git2/oid.h"
11
+
12
+ /*
13
+ * Compare two oid structures.
14
+ *
15
+ * @param a first oid structure.
16
+ * @param b second oid structure.
17
+ * @return <0, 0, >0 if a < b, a == b, a > b.
18
+ */
19
+ GIT_INLINE(int) git_oid__cmp(const git_oid *a, const git_oid *b)
20
+ {
21
+ const unsigned char *sha1 = a->id;
22
+ const unsigned char *sha2 = b->id;
23
+ int i;
24
+
25
+ for (i = 0; i < GIT_OID_RAWSZ; i++, sha1++, sha2++) {
26
+ if (*sha1 != *sha2)
27
+ return *sha1 - *sha2;
28
+ }
29
+
30
+ return 0;
31
+ }
32
+
33
+ #endif