rugged 1.5.0.1 → 1.7.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (250) hide show
  1. checksums.yaml +4 -4
  2. data/ext/rugged/extconf.rb +2 -2
  3. data/ext/rugged/rugged_allocator.c +0 -54
  4. data/ext/rugged/rugged_blame.c +2 -0
  5. data/ext/rugged/rugged_blob.c +3 -0
  6. data/ext/rugged/rugged_commit.c +1 -0
  7. data/ext/rugged/rugged_config.c +2 -0
  8. data/ext/rugged/rugged_diff.c +1 -0
  9. data/ext/rugged/rugged_index.c +2 -0
  10. data/ext/rugged/rugged_patch.c +1 -0
  11. data/ext/rugged/rugged_rebase.c +1 -0
  12. data/ext/rugged/rugged_reference.c +1 -0
  13. data/ext/rugged/rugged_remote.c +1 -0
  14. data/ext/rugged/rugged_repo.c +5 -2
  15. data/ext/rugged/rugged_revwalk.c +5 -1
  16. data/ext/rugged/rugged_submodule.c +1 -0
  17. data/ext/rugged/rugged_tag.c +1 -0
  18. data/ext/rugged/rugged_tree.c +4 -0
  19. data/lib/rugged/index.rb +1 -1
  20. data/lib/rugged/tree.rb +1 -1
  21. data/lib/rugged/version.rb +1 -1
  22. data/vendor/libgit2/CMakeLists.txt +7 -8
  23. data/vendor/libgit2/COPYING +30 -0
  24. data/vendor/libgit2/cmake/CheckPrototypeDefinitionSafe.cmake +16 -0
  25. data/vendor/libgit2/cmake/ExperimentalFeatures.cmake +23 -0
  26. data/vendor/libgit2/cmake/SelectGSSAPI.cmake +3 -3
  27. data/vendor/libgit2/cmake/SelectHTTPSBackend.cmake +21 -2
  28. data/vendor/libgit2/cmake/SelectHashes.cmake +4 -0
  29. data/vendor/libgit2/cmake/SelectXdiff.cmake +9 -0
  30. data/vendor/libgit2/deps/ntlmclient/CMakeLists.txt +2 -0
  31. data/vendor/libgit2/deps/pcre/LICENCE +5 -5
  32. data/vendor/libgit2/deps/pcre/pcre.h +2 -2
  33. data/vendor/libgit2/deps/pcre/pcre_compile.c +6 -3
  34. data/vendor/libgit2/deps/pcre/pcre_exec.c +2 -2
  35. data/vendor/libgit2/deps/xdiff/CMakeLists.txt +28 -0
  36. data/vendor/libgit2/{src/libgit2 → deps}/xdiff/git-xdiff.h +4 -1
  37. data/vendor/libgit2/{src/libgit2 → deps}/xdiff/xdiffi.c +19 -18
  38. data/vendor/libgit2/{src/libgit2 → deps}/xdiff/xdiffi.h +2 -4
  39. data/vendor/libgit2/{src/libgit2 → deps}/xdiff/xemit.c +3 -3
  40. data/vendor/libgit2/{src/libgit2 → deps}/xdiff/xhistogram.c +7 -18
  41. data/vendor/libgit2/{src/libgit2 → deps}/xdiff/xmacros.h +18 -1
  42. data/vendor/libgit2/{src/libgit2 → deps}/xdiff/xmerge.c +24 -22
  43. data/vendor/libgit2/{src/libgit2 → deps}/xdiff/xpatience.c +21 -30
  44. data/vendor/libgit2/{src/libgit2 → deps}/xdiff/xprepare.c +13 -30
  45. data/vendor/libgit2/{src/libgit2 → deps}/xdiff/xutils.c +18 -1
  46. data/vendor/libgit2/{src/libgit2 → deps}/xdiff/xutils.h +2 -1
  47. data/vendor/libgit2/include/git2/common.h +38 -6
  48. data/vendor/libgit2/include/git2/deprecated.h +6 -0
  49. data/vendor/libgit2/include/git2/diff.h +42 -4
  50. data/vendor/libgit2/include/git2/errors.h +4 -2
  51. data/vendor/libgit2/include/git2/experimental.h +20 -0
  52. data/vendor/libgit2/include/git2/index.h +9 -0
  53. data/vendor/libgit2/include/git2/indexer.h +29 -0
  54. data/vendor/libgit2/include/git2/object.h +28 -2
  55. data/vendor/libgit2/include/git2/odb.h +58 -7
  56. data/vendor/libgit2/include/git2/odb_backend.h +106 -18
  57. data/vendor/libgit2/include/git2/oid.h +116 -16
  58. data/vendor/libgit2/include/git2/remote.h +18 -0
  59. data/vendor/libgit2/include/git2/repository.h +32 -3
  60. data/vendor/libgit2/include/git2/stash.h +60 -6
  61. data/vendor/libgit2/include/git2/strarray.h +0 -13
  62. data/vendor/libgit2/include/git2/sys/alloc.h +0 -34
  63. data/vendor/libgit2/include/git2/sys/commit_graph.h +12 -2
  64. data/vendor/libgit2/include/git2/sys/midx.h +5 -1
  65. data/vendor/libgit2/include/git2/sys/odb_backend.h +1 -1
  66. data/vendor/libgit2/include/git2/sys/stream.h +16 -2
  67. data/vendor/libgit2/include/git2/sys/transport.h +32 -2
  68. data/vendor/libgit2/include/git2/version.h +4 -4
  69. data/vendor/libgit2/include/git2/worktree.h +3 -1
  70. data/vendor/libgit2/include/git2.h +1 -0
  71. data/vendor/libgit2/src/CMakeLists.txt +34 -17
  72. data/vendor/libgit2/src/cli/CMakeLists.txt +5 -2
  73. data/vendor/libgit2/src/cli/cmd_clone.c +22 -6
  74. data/vendor/libgit2/src/cli/cmd_hash_object.c +27 -8
  75. data/vendor/libgit2/src/cli/opt.c +1 -1
  76. data/vendor/libgit2/src/cli/progress.c +9 -8
  77. data/vendor/libgit2/src/cli/progress.h +4 -4
  78. data/vendor/libgit2/src/libgit2/CMakeLists.txt +25 -34
  79. data/vendor/libgit2/src/libgit2/annotated_commit.c +2 -2
  80. data/vendor/libgit2/src/libgit2/annotated_commit.h +1 -1
  81. data/vendor/libgit2/src/libgit2/apply.c +4 -3
  82. data/vendor/libgit2/src/libgit2/attr_file.c +1 -1
  83. data/vendor/libgit2/src/libgit2/attrcache.c +1 -1
  84. data/vendor/libgit2/src/libgit2/blame.c +23 -14
  85. data/vendor/libgit2/src/libgit2/blame_git.c +0 -1
  86. data/vendor/libgit2/src/libgit2/blob.c +4 -2
  87. data/vendor/libgit2/src/libgit2/blob.h +2 -2
  88. data/vendor/libgit2/src/libgit2/branch.c +2 -2
  89. data/vendor/libgit2/src/libgit2/cherrypick.c +3 -3
  90. data/vendor/libgit2/src/libgit2/clone.c +34 -3
  91. data/vendor/libgit2/src/libgit2/commit.c +78 -21
  92. data/vendor/libgit2/src/libgit2/commit.h +25 -7
  93. data/vendor/libgit2/src/libgit2/commit_graph.c +129 -47
  94. data/vendor/libgit2/src/libgit2/commit_graph.h +23 -4
  95. data/vendor/libgit2/src/libgit2/commit_list.c +16 -5
  96. data/vendor/libgit2/src/libgit2/commit_list.h +1 -0
  97. data/vendor/libgit2/src/libgit2/config.c +6 -3
  98. data/vendor/libgit2/src/libgit2/config_file.c +16 -10
  99. data/vendor/libgit2/src/libgit2/describe.c +11 -8
  100. data/vendor/libgit2/src/libgit2/diff.c +19 -6
  101. data/vendor/libgit2/src/libgit2/diff.h +6 -6
  102. data/vendor/libgit2/src/libgit2/diff_file.c +16 -7
  103. data/vendor/libgit2/src/libgit2/diff_generate.c +37 -11
  104. data/vendor/libgit2/src/libgit2/diff_parse.c +20 -4
  105. data/vendor/libgit2/src/libgit2/diff_print.c +26 -7
  106. data/vendor/libgit2/src/libgit2/diff_tform.c +4 -0
  107. data/vendor/libgit2/src/libgit2/diff_xdiff.h +1 -1
  108. data/vendor/libgit2/src/libgit2/email.c +4 -3
  109. data/vendor/libgit2/src/libgit2/errors.c +73 -18
  110. data/vendor/libgit2/src/libgit2/experimental.h.in +13 -0
  111. data/vendor/libgit2/src/libgit2/fetch.c +38 -13
  112. data/vendor/libgit2/src/libgit2/fetch.h +0 -2
  113. data/vendor/libgit2/src/libgit2/fetchhead.c +11 -9
  114. data/vendor/libgit2/src/libgit2/grafts.c +272 -0
  115. data/vendor/libgit2/src/libgit2/grafts.h +36 -0
  116. data/vendor/libgit2/src/libgit2/ident.c +3 -3
  117. data/vendor/libgit2/src/libgit2/index.c +327 -123
  118. data/vendor/libgit2/src/libgit2/index.h +14 -1
  119. data/vendor/libgit2/src/libgit2/indexer.c +116 -46
  120. data/vendor/libgit2/src/libgit2/iterator.c +21 -4
  121. data/vendor/libgit2/src/libgit2/iterator.h +3 -0
  122. data/vendor/libgit2/src/libgit2/libgit2.c +58 -0
  123. data/vendor/libgit2/src/libgit2/merge.c +14 -9
  124. data/vendor/libgit2/src/libgit2/merge_file.c +0 -2
  125. data/vendor/libgit2/src/libgit2/midx.c +68 -38
  126. data/vendor/libgit2/src/libgit2/midx.h +13 -3
  127. data/vendor/libgit2/src/libgit2/mwindow.c +5 -2
  128. data/vendor/libgit2/src/libgit2/mwindow.h +4 -1
  129. data/vendor/libgit2/src/libgit2/notes.c +9 -8
  130. data/vendor/libgit2/src/libgit2/object.c +118 -29
  131. data/vendor/libgit2/src/libgit2/object.h +17 -2
  132. data/vendor/libgit2/src/libgit2/odb.c +224 -55
  133. data/vendor/libgit2/src/libgit2/odb.h +43 -4
  134. data/vendor/libgit2/src/libgit2/odb_loose.c +128 -70
  135. data/vendor/libgit2/src/libgit2/odb_pack.c +111 -46
  136. data/vendor/libgit2/src/libgit2/oid.c +141 -77
  137. data/vendor/libgit2/src/libgit2/oid.h +183 -9
  138. data/vendor/libgit2/src/libgit2/oidarray.c +49 -3
  139. data/vendor/libgit2/src/libgit2/oidarray.h +5 -1
  140. data/vendor/libgit2/src/libgit2/pack-objects.c +31 -13
  141. data/vendor/libgit2/src/libgit2/pack-objects.h +5 -2
  142. data/vendor/libgit2/src/libgit2/pack.c +93 -70
  143. data/vendor/libgit2/src/libgit2/pack.h +29 -15
  144. data/vendor/libgit2/src/libgit2/parse.c +8 -4
  145. data/vendor/libgit2/src/libgit2/parse.h +1 -1
  146. data/vendor/libgit2/src/libgit2/patch.h +7 -1
  147. data/vendor/libgit2/src/libgit2/patch_generate.c +24 -5
  148. data/vendor/libgit2/src/libgit2/patch_parse.c +16 -8
  149. data/vendor/libgit2/src/libgit2/push.c +13 -3
  150. data/vendor/libgit2/src/libgit2/reader.c +1 -1
  151. data/vendor/libgit2/src/libgit2/rebase.c +72 -83
  152. data/vendor/libgit2/src/libgit2/refdb_fs.c +92 -52
  153. data/vendor/libgit2/src/libgit2/reflog.c +7 -5
  154. data/vendor/libgit2/src/libgit2/reflog.h +1 -2
  155. data/vendor/libgit2/src/libgit2/refs.c +9 -0
  156. data/vendor/libgit2/src/libgit2/remote.c +47 -37
  157. data/vendor/libgit2/src/libgit2/remote.h +41 -0
  158. data/vendor/libgit2/src/libgit2/repository.c +784 -329
  159. data/vendor/libgit2/src/libgit2/repository.h +26 -2
  160. data/vendor/libgit2/src/libgit2/reset.c +2 -2
  161. data/vendor/libgit2/src/libgit2/revert.c +8 -11
  162. data/vendor/libgit2/src/libgit2/revparse.c +23 -7
  163. data/vendor/libgit2/src/libgit2/revwalk.c +31 -5
  164. data/vendor/libgit2/src/libgit2/stash.c +209 -33
  165. data/vendor/libgit2/src/libgit2/strarray.c +1 -0
  166. data/vendor/libgit2/src/libgit2/strarray.h +25 -0
  167. data/vendor/libgit2/src/libgit2/streams/mbedtls.c +0 -1
  168. data/vendor/libgit2/src/libgit2/streams/openssl.c +9 -17
  169. data/vendor/libgit2/src/libgit2/streams/openssl_dynamic.c +7 -3
  170. data/vendor/libgit2/src/libgit2/streams/schannel.c +715 -0
  171. data/vendor/libgit2/src/libgit2/streams/schannel.h +28 -0
  172. data/vendor/libgit2/src/libgit2/streams/socket.c +240 -51
  173. data/vendor/libgit2/src/libgit2/streams/socket.h +3 -1
  174. data/vendor/libgit2/src/libgit2/streams/stransport.c +40 -12
  175. data/vendor/libgit2/src/libgit2/streams/tls.c +5 -0
  176. data/vendor/libgit2/src/libgit2/submodule.c +6 -2
  177. data/vendor/libgit2/src/libgit2/submodule.h +3 -3
  178. data/vendor/libgit2/src/libgit2/sysdir.c +294 -7
  179. data/vendor/libgit2/src/libgit2/sysdir.h +41 -9
  180. data/vendor/libgit2/src/libgit2/tag.c +29 -10
  181. data/vendor/libgit2/src/libgit2/tag.h +2 -2
  182. data/vendor/libgit2/src/libgit2/threadstate.c +15 -2
  183. data/vendor/libgit2/src/libgit2/threadstate.h +1 -3
  184. data/vendor/libgit2/src/libgit2/transports/auth.h +1 -2
  185. data/vendor/libgit2/src/libgit2/transports/{auth_negotiate.c → auth_gssapi.c} +32 -32
  186. data/vendor/libgit2/src/libgit2/transports/auth_negotiate.h +1 -1
  187. data/vendor/libgit2/src/libgit2/transports/auth_ntlm.h +1 -1
  188. data/vendor/libgit2/src/libgit2/transports/{auth_ntlm.c → auth_ntlmclient.c} +12 -12
  189. data/vendor/libgit2/src/libgit2/transports/auth_sspi.c +341 -0
  190. data/vendor/libgit2/src/libgit2/transports/git.c +7 -8
  191. data/vendor/libgit2/src/libgit2/transports/http.c +15 -9
  192. data/vendor/libgit2/src/libgit2/transports/httpclient.c +14 -0
  193. data/vendor/libgit2/src/libgit2/transports/httpclient.h +10 -0
  194. data/vendor/libgit2/src/libgit2/transports/local.c +27 -4
  195. data/vendor/libgit2/src/libgit2/transports/smart.c +68 -27
  196. data/vendor/libgit2/src/libgit2/transports/smart.h +33 -9
  197. data/vendor/libgit2/src/libgit2/transports/smart_pkt.c +281 -49
  198. data/vendor/libgit2/src/libgit2/transports/smart_protocol.c +192 -55
  199. data/vendor/libgit2/src/libgit2/transports/ssh.c +334 -102
  200. data/vendor/libgit2/src/libgit2/transports/winhttp.c +22 -18
  201. data/vendor/libgit2/src/libgit2/tree-cache.c +26 -16
  202. data/vendor/libgit2/src/libgit2/tree-cache.h +5 -3
  203. data/vendor/libgit2/src/libgit2/tree.c +23 -17
  204. data/vendor/libgit2/src/libgit2/tree.h +2 -2
  205. data/vendor/libgit2/src/libgit2/worktree.c +30 -10
  206. data/vendor/libgit2/src/util/CMakeLists.txt +6 -1
  207. data/vendor/libgit2/src/util/alloc.c +65 -6
  208. data/vendor/libgit2/src/util/alloc.h +34 -9
  209. data/vendor/libgit2/src/util/allocators/failalloc.c +0 -60
  210. data/vendor/libgit2/src/util/allocators/failalloc.h +0 -6
  211. data/vendor/libgit2/src/util/allocators/stdalloc.c +2 -105
  212. data/vendor/libgit2/src/util/allocators/win32_leakcheck.c +0 -68
  213. data/vendor/libgit2/src/util/array.h +6 -1
  214. data/vendor/libgit2/src/util/cc-compat.h +2 -0
  215. data/vendor/libgit2/src/util/filebuf.c +6 -1
  216. data/vendor/libgit2/src/util/filebuf.h +19 -6
  217. data/vendor/libgit2/src/util/fs_path.c +2 -2
  218. data/vendor/libgit2/src/util/futils.c +8 -8
  219. data/vendor/libgit2/src/{features.h.in → util/git2_features.h.in} +9 -3
  220. data/vendor/libgit2/src/util/git2_util.h +2 -2
  221. data/vendor/libgit2/src/util/hash/openssl.c +4 -3
  222. data/vendor/libgit2/src/util/hash/rfc6234/sha.h +0 -112
  223. data/vendor/libgit2/src/util/hash.h +13 -0
  224. data/vendor/libgit2/src/util/net.c +492 -87
  225. data/vendor/libgit2/src/util/net.h +32 -0
  226. data/vendor/libgit2/src/util/posix.c +54 -0
  227. data/vendor/libgit2/src/util/posix.h +24 -0
  228. data/vendor/libgit2/src/util/rand.c +10 -4
  229. data/vendor/libgit2/src/util/regexp.c +3 -3
  230. data/vendor/libgit2/src/util/staticstr.h +66 -0
  231. data/vendor/libgit2/src/util/thread.h +20 -19
  232. data/vendor/libgit2/src/util/util.c +15 -10
  233. data/vendor/libgit2/src/util/util.h +25 -16
  234. data/vendor/libgit2/src/util/win32/error.c +1 -1
  235. data/vendor/libgit2/src/util/win32/path_w32.c +8 -8
  236. data/vendor/libgit2/src/util/win32/posix_w32.c +1 -1
  237. data/vendor/libgit2/src/util/win32/utf-conv.c +73 -75
  238. data/vendor/libgit2/src/util/win32/utf-conv.h +81 -14
  239. data/vendor/libgit2/src/util/win32/w32_util.c +1 -1
  240. metadata +34 -26
  241. data/vendor/libgit2/cmake/SelectWinHTTP.cmake +0 -17
  242. data/vendor/libgit2/src/libgit2/netops.c +0 -124
  243. data/vendor/libgit2/src/libgit2/netops.h +0 -68
  244. data/vendor/libgit2/src/util/win32/findfile.c +0 -286
  245. data/vendor/libgit2/src/util/win32/findfile.h +0 -22
  246. /data/vendor/libgit2/{src/libgit2 → deps}/xdiff/xdiff.h +0 -0
  247. /data/vendor/libgit2/{src/libgit2 → deps}/xdiff/xemit.h +0 -0
  248. /data/vendor/libgit2/{src/libgit2 → deps}/xdiff/xinclude.h +0 -0
  249. /data/vendor/libgit2/{src/libgit2 → deps}/xdiff/xprepare.h +0 -0
  250. /data/vendor/libgit2/{src/libgit2 → deps}/xdiff/xtypes.h +0 -0
@@ -11,7 +11,6 @@
11
11
  #include "zstream.h"
12
12
  #include "delta.h"
13
13
  #include "iterator.h"
14
- #include "netops.h"
15
14
  #include "pack.h"
16
15
  #include "thread.h"
17
16
  #include "tree.h"
@@ -127,6 +126,7 @@ out:
127
126
 
128
127
  int git_packbuilder_new(git_packbuilder **out, git_repository *repo)
129
128
  {
129
+ git_hash_algorithm_t hash_algorithm;
130
130
  git_packbuilder *pb;
131
131
 
132
132
  *out = NULL;
@@ -134,6 +134,11 @@ int git_packbuilder_new(git_packbuilder **out, git_repository *repo)
134
134
  pb = git__calloc(1, sizeof(*pb));
135
135
  GIT_ERROR_CHECK_ALLOC(pb);
136
136
 
137
+ pb->oid_type = repo->oid_type;
138
+
139
+ hash_algorithm = git_oid_algorithm(pb->oid_type);
140
+ GIT_ASSERT(hash_algorithm);
141
+
137
142
  if (git_oidmap_new(&pb->object_ix) < 0 ||
138
143
  git_oidmap_new(&pb->walk_objects) < 0 ||
139
144
  git_pool_init(&pb->object_pool, sizeof(struct walk_object)) < 0)
@@ -142,7 +147,7 @@ int git_packbuilder_new(git_packbuilder **out, git_repository *repo)
142
147
  pb->repo = repo;
143
148
  pb->nr_threads = 1; /* do not spawn any thread by default */
144
149
 
145
- if (git_hash_ctx_init(&pb->ctx, GIT_HASH_ALGORITHM_SHA1) < 0 ||
150
+ if (git_hash_ctx_init(&pb->ctx, hash_algorithm) < 0 ||
146
151
  git_zstream_init(&pb->zstream, GIT_ZSTREAM_DEFLATE) < 0 ||
147
152
  git_repository_odb(&pb->odb, repo) < 0 ||
148
153
  packbuilder_config(pb) < 0)
@@ -249,10 +254,10 @@ int git_packbuilder_insert(git_packbuilder *pb, const git_oid *oid,
249
254
  pb->done = false;
250
255
 
251
256
  if (pb->progress_cb) {
252
- double current_time = git__timer();
253
- double elapsed = current_time - pb->last_progress_report_time;
257
+ uint64_t current_time = git_time_monotonic();
258
+ uint64_t elapsed = current_time - pb->last_progress_report_time;
254
259
 
255
- if (elapsed < 0 || elapsed >= MIN_PROGRESS_UPDATE_INTERVAL) {
260
+ if (elapsed >= MIN_PROGRESS_UPDATE_INTERVAL) {
256
261
  pb->last_progress_report_time = current_time;
257
262
 
258
263
  ret = pb->progress_cb(
@@ -315,9 +320,11 @@ static int write_object(
315
320
  git_object_t type;
316
321
  unsigned char hdr[10], *zbuf = NULL;
317
322
  void *data = NULL;
318
- size_t hdr_len, zbuf_len = COMPRESS_BUFLEN, data_len;
323
+ size_t hdr_len, zbuf_len = COMPRESS_BUFLEN, data_len, oid_size;
319
324
  int error;
320
325
 
326
+ oid_size = git_oid_size(pb->oid_type);
327
+
321
328
  /*
322
329
  * If we have a delta base, let's use the delta to save space.
323
330
  * Otherwise load the whole object. 'data' ends up pointing to
@@ -347,8 +354,8 @@ static int write_object(
347
354
  goto done;
348
355
 
349
356
  if (type == GIT_OBJECT_REF_DELTA) {
350
- if ((error = write_cb(po->delta->id.id, GIT_OID_RAWSZ, cb_data)) < 0 ||
351
- (error = git_hash_update(&pb->ctx, po->delta->id.id, GIT_OID_RAWSZ)) < 0)
357
+ if ((error = write_cb(po->delta->id.id, oid_size, cb_data)) < 0 ||
358
+ (error = git_hash_update(&pb->ctx, po->delta->id.id, oid_size)) < 0)
352
359
  goto done;
353
360
  }
354
361
 
@@ -668,7 +675,7 @@ static int write_pack(git_packbuilder *pb,
668
675
  if ((error = git_hash_final(entry_oid.id, &pb->ctx)) < 0)
669
676
  goto done;
670
677
 
671
- error = write_cb(entry_oid.id, GIT_OID_RAWSZ, cb_data);
678
+ error = write_cb(entry_oid.id, git_oid_size(pb->oid_type), cb_data);
672
679
 
673
680
  done:
674
681
  /* if callback cancelled writing, we must still free delta_data */
@@ -926,10 +933,10 @@ static int report_delta_progress(
926
933
  int ret;
927
934
 
928
935
  if (pb->progress_cb) {
929
- double current_time = git__timer();
930
- double elapsed = current_time - pb->last_progress_report_time;
936
+ uint64_t current_time = git_time_monotonic();
937
+ uint64_t elapsed = current_time - pb->last_progress_report_time;
931
938
 
932
- if (force || elapsed < 0 || elapsed >= MIN_PROGRESS_UPDATE_INTERVAL) {
939
+ if (force || elapsed >= MIN_PROGRESS_UPDATE_INTERVAL) {
933
940
  pb->last_progress_report_time = current_time;
934
941
 
935
942
  ret = pb->progress_cb(
@@ -1407,7 +1414,18 @@ int git_packbuilder_write(
1407
1414
  opts.progress_cb = progress_cb;
1408
1415
  opts.progress_cb_payload = progress_cb_payload;
1409
1416
 
1410
- if ((error = git_indexer_new(&indexer, path, mode, pb->odb, &opts)) < 0)
1417
+ /* TODO: SHA256 */
1418
+
1419
+ #ifdef GIT_EXPERIMENTAL_SHA256
1420
+ opts.mode = mode;
1421
+ opts.odb = pb->odb;
1422
+
1423
+ error = git_indexer_new(&indexer, path, GIT_OID_SHA1, &opts);
1424
+ #else
1425
+ error = git_indexer_new(&indexer, path, mode, pb->odb, &opts);
1426
+ #endif
1427
+
1428
+ if (error < 0)
1411
1429
  goto cleanup;
1412
1430
 
1413
1431
  if (!git_repository__configmap_lookup(&t, pb->repo, GIT_CONFIGMAP_FSYNCOBJECTFILES) && t)
@@ -13,7 +13,6 @@
13
13
  #include "str.h"
14
14
  #include "hash.h"
15
15
  #include "oidmap.h"
16
- #include "netops.h"
17
16
  #include "zstream.h"
18
17
  #include "pool.h"
19
18
  #include "indexer.h"
@@ -56,6 +55,8 @@ struct git_packbuilder {
56
55
  git_repository *repo; /* associated repository */
57
56
  git_odb *odb; /* associated object database */
58
57
 
58
+ git_oid_t oid_type;
59
+
59
60
  git_hash_ctx ctx;
60
61
  git_zstream zstream;
61
62
 
@@ -94,7 +95,9 @@ struct git_packbuilder {
94
95
 
95
96
  git_packbuilder_progress progress_cb;
96
97
  void *progress_cb_payload;
97
- double last_progress_report_time; /* the time progress was last reported */
98
+
99
+ /* the time progress was last reported, in millisecond ticks */
100
+ uint64_t last_progress_report_time;
98
101
 
99
102
  bool done;
100
103
  };
@@ -32,7 +32,7 @@ static int packfile_unpack_compressed(
32
32
  * Throws GIT_EAMBIGUOUSOIDPREFIX if short oid
33
33
  * is ambiguous within the pack.
34
34
  * This method assumes that len is between
35
- * GIT_OID_MINPREFIXLEN and GIT_OID_HEXSZ.
35
+ * GIT_OID_MINPREFIXLEN and the oid type's hexsize.
36
36
  */
37
37
  static int pack_entry_find_offset(
38
38
  off64_t *offset_out,
@@ -186,9 +186,9 @@ static int cache_add(
186
186
 
187
187
  static void pack_index_free(struct git_pack_file *p)
188
188
  {
189
- if (p->oids) {
190
- git__free(p->oids);
191
- p->oids = NULL;
189
+ if (p->ids) {
190
+ git__free(p->ids);
191
+ p->ids = NULL;
192
192
  }
193
193
  if (p->index_map.data) {
194
194
  git_futils_mmap_free(&p->index_map);
@@ -200,11 +200,12 @@ static void pack_index_free(struct git_pack_file *p)
200
200
  static int pack_index_check_locked(const char *path, struct git_pack_file *p)
201
201
  {
202
202
  struct git_pack_idx_header *hdr;
203
- uint32_t version, nr, i, *index;
203
+ uint32_t version, nr = 0, i, *index;
204
204
  void *idx_map;
205
205
  size_t idx_size;
206
206
  struct stat st;
207
207
  int error;
208
+
208
209
  /* TODO: properly open the file without access time using O_NOATIME */
209
210
  git_file fd = git_futils_open_ro(path);
210
211
  if (fd < 0)
@@ -218,8 +219,7 @@ static int pack_index_check_locked(const char *path, struct git_pack_file *p)
218
219
 
219
220
  if (!S_ISREG(st.st_mode) ||
220
221
  !git__is_sizet(st.st_size) ||
221
- (idx_size = (size_t)st.st_size) < 4 * 256 + 20 + 20)
222
- {
222
+ (idx_size = (size_t)st.st_size) < (size_t)((4 * 256) + (p->oid_size * 2))) {
223
223
  p_close(fd);
224
224
  git_error_set(GIT_ERROR_ODB, "invalid pack index '%s'", path);
225
225
  return -1;
@@ -242,10 +242,10 @@ static int pack_index_check_locked(const char *path, struct git_pack_file *p)
242
242
  return packfile_error("unsupported index version");
243
243
  }
244
244
 
245
- } else
245
+ } else {
246
246
  version = 1;
247
+ }
247
248
 
248
- nr = 0;
249
249
  index = idx_map;
250
250
 
251
251
  if (version > 1)
@@ -264,11 +264,11 @@ static int pack_index_check_locked(const char *path, struct git_pack_file *p)
264
264
  /*
265
265
  * Total size:
266
266
  * - 256 index entries 4 bytes each
267
- * - 24-byte entries * nr (20-byte sha1 + 4-byte offset)
268
- * - 20-byte SHA1 of the packfile
269
- * - 20-byte SHA1 file checksum
267
+ * - 24/36-byte entries * nr (20/32 byte SHA + 4-byte offset)
268
+ * - 20/32-byte SHA of the packfile
269
+ * - 20/32-byte SHA file checksum
270
270
  */
271
- if (idx_size != 4*256 + nr * 24 + 20 + 20) {
271
+ if (idx_size != (4 * 256 + ((uint64_t) nr * (p->oid_size + 4)) + (p->oid_size * 2))) {
272
272
  git_futils_mmap_free(&p->index_map);
273
273
  return packfile_error("index is corrupted");
274
274
  }
@@ -277,17 +277,17 @@ static int pack_index_check_locked(const char *path, struct git_pack_file *p)
277
277
  * Minimum size:
278
278
  * - 8 bytes of header
279
279
  * - 256 index entries 4 bytes each
280
- * - 20-byte sha1 entry * nr
280
+ * - 20/32-byte SHA entry * nr
281
281
  * - 4-byte crc entry * nr
282
282
  * - 4-byte offset entry * nr
283
- * - 20-byte SHA1 of the packfile
284
- * - 20-byte SHA1 file checksum
283
+ * - 20/32-byte SHA of the packfile
284
+ * - 20/32-byte SHA file checksum
285
285
  * And after the 4-byte offset table might be a
286
286
  * variable sized table containing 8-byte entries
287
287
  * for offsets larger than 2^31.
288
288
  */
289
- unsigned long min_size = 8 + 4*256 + nr*(20 + 4 + 4) + 20 + 20;
290
- unsigned long max_size = min_size;
289
+ uint64_t min_size = 8 + (4 * 256) + ((uint64_t)nr * (p->oid_size + 4 + 4)) + (p->oid_size * 2);
290
+ uint64_t max_size = min_size;
291
291
 
292
292
  if (nr)
293
293
  max_size += (nr - 1)*8;
@@ -365,12 +365,12 @@ static unsigned char *pack_window_open(
365
365
  * Don't allow a negative offset, as that means we've wrapped
366
366
  * around.
367
367
  */
368
- if (offset > (p->mwf.size - 20))
368
+ if (offset > (p->mwf.size - p->oid_size))
369
369
  goto cleanup;
370
370
  if (offset < 0)
371
371
  goto cleanup;
372
372
 
373
- pack_data = git_mwindow_open(&p->mwf, w_cursor, offset, 20, left);
373
+ pack_data = git_mwindow_open(&p->mwf, w_cursor, offset, p->oid_size, left);
374
374
 
375
375
  cleanup:
376
376
  git_mutex_unlock(&p->mwf.lock);
@@ -473,13 +473,13 @@ int git_packfile_unpack_header(
473
473
  return error;
474
474
  }
475
475
 
476
- /* pack_window_open() assures us we have [base, base + 20) available
477
- * as a range that we can look at at. (Its actually the hash
478
- * size that is assured.) With our object header encoding
479
- * the maximum deflated object size is 2^137, which is just
480
- * insane, so we know won't exceed what we have been given.
476
+ /* pack_window_open() assures us we have [base, base + oid_size)
477
+ * available as a range that we can look at at. (It's actually
478
+ * the hash size that is assured.) With our object header
479
+ * encoding the maximum deflated object size is 2^137, which is
480
+ * just insane, so we know won't exceed what we have been given.
481
481
  */
482
- base = git_mwindow_open(&p->mwf, w_curs, *curpos, 20, &left);
482
+ base = git_mwindow_open(&p->mwf, w_curs, *curpos, p->oid_size, &left);
483
483
  git_mutex_unlock(&p->lock);
484
484
  git_mutex_unlock(&p->mwf.lock);
485
485
  if (base == NULL)
@@ -977,11 +977,12 @@ int get_delta_base(
977
977
  /* Assumption: the only reason this would fail is because the file is too small */
978
978
  if (base_info == NULL)
979
979
  return GIT_EBUFS;
980
- /* pack_window_open() assured us we have [base_info, base_info + 20)
981
- * as a range that we can look at without walking off the
982
- * end of the mapped window. Its actually the hash size
983
- * that is assured. An OFS_DELTA longer than the hash size
984
- * is stupid, as then a REF_DELTA would be smaller to store.
980
+ /* pack_window_open() assured us we have
981
+ * [base_info, base_info + oid_size) as a range that we can look
982
+ * at without walking off the end of the mapped window. Its
983
+ * actually the hash size that is assured. An OFS_DELTA longer
984
+ * than the hash size is stupid, as then a REF_DELTA would be
985
+ * smaller to store.
985
986
  */
986
987
  if (type == GIT_OBJECT_OFS_DELTA) {
987
988
  unsigned used = 0;
@@ -1002,7 +1003,7 @@ int get_delta_base(
1002
1003
  *curpos += used;
1003
1004
  } else if (type == GIT_OBJECT_REF_DELTA) {
1004
1005
  git_oid base_oid;
1005
- git_oid_fromraw(&base_oid, base_info);
1006
+ git_oid__fromraw(&base_oid, base_info, p->oid_type);
1006
1007
 
1007
1008
  /* If we have the cooperative cache, search in it first */
1008
1009
  if (p->has_cache) {
@@ -1012,7 +1013,7 @@ int get_delta_base(
1012
1013
  if (entry->offset == 0)
1013
1014
  return packfile_error("delta offset is zero");
1014
1015
 
1015
- *curpos += 20;
1016
+ *curpos += p->oid_size;
1016
1017
  *delta_base_out = entry->offset;
1017
1018
  return 0;
1018
1019
  } else {
@@ -1025,9 +1026,9 @@ int get_delta_base(
1025
1026
  }
1026
1027
 
1027
1028
  /* The base entry _must_ be in the same pack */
1028
- if (pack_entry_find_offset(&base_offset, &unused, p, &base_oid, GIT_OID_HEXSZ) < 0)
1029
+ if (pack_entry_find_offset(&base_offset, &unused, p, &base_oid, p->oid_hexsize) < 0)
1029
1030
  return packfile_error("base entry delta is not in the same pack");
1030
- *curpos += 20;
1031
+ *curpos += p->oid_size;
1031
1032
  } else
1032
1033
  return packfile_error("unknown object type");
1033
1034
 
@@ -1070,7 +1071,7 @@ void git_packfile_free(struct git_pack_file *p, bool unlink_packfile)
1070
1071
 
1071
1072
  pack_index_free(p);
1072
1073
 
1073
- git__free(p->bad_object_sha1);
1074
+ git__free(p->bad_object_ids);
1074
1075
 
1075
1076
  git_mutex_free(&p->bases.lock);
1076
1077
  git_mutex_free(&p->mwf.lock);
@@ -1083,8 +1084,8 @@ static int packfile_open_locked(struct git_pack_file *p)
1083
1084
  {
1084
1085
  struct stat st;
1085
1086
  struct git_pack_header hdr;
1086
- unsigned char sha1[GIT_OID_RAWSZ];
1087
- unsigned char *idx_sha1;
1087
+ unsigned char checksum[GIT_OID_MAX_SIZE];
1088
+ unsigned char *idx_checksum;
1088
1089
 
1089
1090
  if (pack_index_open_locked(p) < 0)
1090
1091
  return git_odb__error_notfound("failed to open packfile", NULL, 0);
@@ -1131,12 +1132,13 @@ static int packfile_open_locked(struct git_pack_file *p)
1131
1132
 
1132
1133
  /* Verify the pack matches its index. */
1133
1134
  if (p->num_objects != ntohl(hdr.hdr_entries) ||
1134
- p_pread(p->mwf.fd, sha1, GIT_OID_RAWSZ, p->mwf.size - GIT_OID_RAWSZ) < 0)
1135
+ p_pread(p->mwf.fd, checksum, p->oid_size, p->mwf.size - p->oid_size) < 0)
1135
1136
  goto cleanup;
1136
1137
 
1137
- idx_sha1 = ((unsigned char *)p->index_map.data) + p->index_map.len - 40;
1138
+ idx_checksum = ((unsigned char *)p->index_map.data) +
1139
+ p->index_map.len - (p->oid_size * 2);
1138
1140
 
1139
- if (git_oid_raw_cmp(sha1, idx_sha1) != 0)
1141
+ if (git_oid_raw_cmp(checksum, idx_checksum, p->oid_size) != 0)
1140
1142
  goto cleanup;
1141
1143
 
1142
1144
  if (git_mwindow_file_register(&p->mwf) < 0)
@@ -1171,7 +1173,10 @@ int git_packfile__name(char **out, const char *path)
1171
1173
  return 0;
1172
1174
  }
1173
1175
 
1174
- int git_packfile_alloc(struct git_pack_file **pack_out, const char *path)
1176
+ int git_packfile_alloc(
1177
+ struct git_pack_file **pack_out,
1178
+ const char *path,
1179
+ git_oid_t oid_type)
1175
1180
  {
1176
1181
  struct stat st;
1177
1182
  struct git_pack_file *p;
@@ -1219,6 +1224,9 @@ int git_packfile_alloc(struct git_pack_file **pack_out, const char *path)
1219
1224
  p->pack_local = 1;
1220
1225
  p->mtime = (git_time_t)st.st_mtime;
1221
1226
  p->index_version = -1;
1227
+ p->oid_type = oid_type ? oid_type : GIT_OID_DEFAULT;
1228
+ p->oid_size = (unsigned int)git_oid_size(p->oid_type);
1229
+ p->oid_hexsize = (unsigned int)git_oid_hexsize(p->oid_type);
1222
1230
 
1223
1231
  if (git_mutex_init(&p->lock) < 0) {
1224
1232
  git_error_set(GIT_ERROR_OS, "failed to initialize packfile mutex");
@@ -1260,20 +1268,20 @@ static off64_t nth_packed_object_offset_locked(struct git_pack_file *p, uint32_t
1260
1268
  end = index + p->index_map.len;
1261
1269
  index += 4 * 256;
1262
1270
  if (p->index_version == 1)
1263
- return ntohl(*((uint32_t *)(index + 24 * n)));
1271
+ return ntohl(*((uint32_t *)(index + (p->oid_size + 4) * (size_t) n)));
1264
1272
 
1265
- index += 8 + p->num_objects * (20 + 4);
1273
+ index += 8 + (size_t) p->num_objects * (p->oid_size + 4);
1266
1274
  off32 = ntohl(*((uint32_t *)(index + 4 * n)));
1267
1275
  if (!(off32 & 0x80000000))
1268
1276
  return off32;
1269
- index += p->num_objects * 4 + (off32 & 0x7fffffff) * 8;
1277
+ index += (size_t) p->num_objects * 4 + (off32 & 0x7fffffff) * 8;
1270
1278
 
1271
1279
  /* Make sure we're not being sent out of bounds */
1272
1280
  if (index >= end - 8)
1273
1281
  return -1;
1274
1282
 
1275
1283
  return (((uint64_t)ntohl(*((uint32_t *)(index + 0)))) << 32) |
1276
- ntohl(*((uint32_t *)(index + 4)));
1284
+ ntohl(*((uint32_t *)(index + 4)));
1277
1285
  }
1278
1286
 
1279
1287
  static int git__memcmp4(const void *a, const void *b) {
@@ -1312,7 +1320,7 @@ int git_pack_foreach_entry(
1312
1320
 
1313
1321
  index += 4 * 256;
1314
1322
 
1315
- if (p->oids == NULL) {
1323
+ if (p->ids == NULL) {
1316
1324
  git_vector offsets, oids;
1317
1325
 
1318
1326
  if ((error = git_vector_init(&oids, p->num_objects, NULL))) {
@@ -1326,22 +1334,25 @@ int git_pack_foreach_entry(
1326
1334
  }
1327
1335
 
1328
1336
  if (p->index_version > 1) {
1329
- const unsigned char *off = index + 24 * p->num_objects;
1337
+ const unsigned char *off = index +
1338
+ (p->oid_size + 4) * p->num_objects;
1339
+
1330
1340
  for (i = 0; i < p->num_objects; i++)
1331
1341
  git_vector_insert(&offsets, (void*)&off[4 * i]);
1342
+
1332
1343
  git_vector_sort(&offsets);
1333
1344
  git_vector_foreach(&offsets, i, current)
1334
1345
  git_vector_insert(&oids, (void*)&index[5 * (current - off)]);
1335
1346
  } else {
1336
1347
  for (i = 0; i < p->num_objects; i++)
1337
- git_vector_insert(&offsets, (void*)&index[24 * i]);
1348
+ git_vector_insert(&offsets, (void*)&index[(p->oid_size + 4) * i]);
1338
1349
  git_vector_sort(&offsets);
1339
1350
  git_vector_foreach(&offsets, i, current)
1340
1351
  git_vector_insert(&oids, (void*)&current[4]);
1341
1352
  }
1342
1353
 
1343
1354
  git_vector_free(&offsets);
1344
- p->oids = (unsigned char **)git_vector_detach(NULL, NULL, &oids);
1355
+ p->ids = (unsigned char **)git_vector_detach(NULL, NULL, &oids);
1345
1356
  }
1346
1357
 
1347
1358
  /*
@@ -1362,7 +1373,7 @@ int git_pack_foreach_entry(
1362
1373
  git_array_clear(oids);
1363
1374
  GIT_ERROR_CHECK_ALLOC(oid);
1364
1375
  }
1365
- git_oid_fromraw(oid, p->oids[i]);
1376
+ git_oid__fromraw(oid, p->ids[i], p->oid_type);
1366
1377
  }
1367
1378
 
1368
1379
  git_mutex_unlock(&p->lock);
@@ -1412,10 +1423,13 @@ int git_pack_foreach_entry_offset(
1412
1423
 
1413
1424
  /* all offsets should have been validated by pack_index_check_locked */
1414
1425
  if (p->index_version > 1) {
1415
- const unsigned char *offsets = index + 24 * p->num_objects;
1426
+ const unsigned char *offsets = index +
1427
+ (p->oid_size + 4) * p->num_objects;
1416
1428
  const unsigned char *large_offset_ptr;
1417
- const unsigned char *large_offsets = index + 28 * p->num_objects;
1418
- const unsigned char *large_offsets_end = ((const unsigned char *)p->index_map.data) + p->index_map.len - 20;
1429
+ const unsigned char *large_offsets = index +
1430
+ (p->oid_size + 8) * p->num_objects;
1431
+ const unsigned char *large_offsets_end = ((const unsigned char *)p->index_map.data) + p->index_map.len - p->oid_size;
1432
+
1419
1433
  for (i = 0; i < p->num_objects; i++) {
1420
1434
  current_offset = ntohl(*(const uint32_t *)(offsets + 4 * i));
1421
1435
  if (current_offset & 0x80000000) {
@@ -1428,7 +1442,7 @@ int git_pack_foreach_entry_offset(
1428
1442
  ntohl(*((uint32_t *)(large_offset_ptr + 4)));
1429
1443
  }
1430
1444
 
1431
- git_oid_fromraw(&current_oid, (index + 20 * i));
1445
+ git_oid__fromraw(&current_oid, (index + p->oid_size * i), p->oid_type);
1432
1446
  if ((error = cb(&current_oid, current_offset, data)) != 0) {
1433
1447
  error = git_error_set_after_callback(error);
1434
1448
  goto cleanup;
@@ -1436,8 +1450,8 @@ int git_pack_foreach_entry_offset(
1436
1450
  }
1437
1451
  } else {
1438
1452
  for (i = 0; i < p->num_objects; i++) {
1439
- current_offset = ntohl(*(const uint32_t *)(index + 24 * i));
1440
- git_oid_fromraw(&current_oid, (index + 24 * i + 4));
1453
+ current_offset = ntohl(*(const uint32_t *)(index + (p->oid_size + 4) * i));
1454
+ git_oid__fromraw(&current_oid, (index + (p->oid_size + 4) * i + 4), p->oid_type);
1441
1455
  if ((error = cb(&current_oid, current_offset, data)) != 0) {
1442
1456
  error = git_error_set_after_callback(error);
1443
1457
  goto cleanup;
@@ -1450,14 +1464,20 @@ cleanup:
1450
1464
  return error;
1451
1465
  }
1452
1466
 
1453
- int git_pack__lookup_sha1(const void *oid_lookup_table, size_t stride, unsigned lo,
1454
- unsigned hi, const unsigned char *oid_prefix)
1467
+ int git_pack__lookup_id(
1468
+ const void *oid_lookup_table,
1469
+ size_t stride,
1470
+ unsigned lo,
1471
+ unsigned hi,
1472
+ const unsigned char *oid_prefix,
1473
+ const git_oid_t oid_type)
1455
1474
  {
1456
1475
  const unsigned char *base = oid_lookup_table;
1476
+ size_t oid_size = git_oid_size(oid_type);
1457
1477
 
1458
1478
  while (lo < hi) {
1459
1479
  unsigned mi = (lo + hi) / 2;
1460
- int cmp = git_oid_raw_cmp(base + mi * stride, oid_prefix);
1480
+ int cmp = git_oid_raw_cmp(base + mi * stride, oid_prefix, oid_size);
1461
1481
 
1462
1482
  if (!cmp)
1463
1483
  return mi;
@@ -1512,9 +1532,9 @@ static int pack_entry_find_offset(
1512
1532
  lo = ((short_oid->id[0] == 0x0) ? 0 : ntohl(level1_ofs[(int)short_oid->id[0] - 1]));
1513
1533
 
1514
1534
  if (p->index_version > 1) {
1515
- stride = 20;
1535
+ stride = p->oid_size;
1516
1536
  } else {
1517
- stride = 24;
1537
+ stride = p->oid_size + 4;
1518
1538
  index += 4;
1519
1539
  }
1520
1540
 
@@ -1523,7 +1543,8 @@ static int pack_entry_find_offset(
1523
1543
  short_oid->id[0], short_oid->id[1], short_oid->id[2], lo, hi, p->num_objects);
1524
1544
  #endif
1525
1545
 
1526
- pos = git_pack__lookup_sha1(index, stride, lo, hi, short_oid->id);
1546
+ pos = git_pack__lookup_id(index, stride, lo, hi,
1547
+ short_oid->id, p->oid_type);
1527
1548
 
1528
1549
  if (pos >= 0) {
1529
1550
  /* An object matching exactly the oid was found */
@@ -1541,7 +1562,9 @@ static int pack_entry_find_offset(
1541
1562
  }
1542
1563
  }
1543
1564
 
1544
- if (found && len != GIT_OID_HEXSZ && pos + 1 < (int)p->num_objects) {
1565
+ if (found &&
1566
+ len != p->oid_hexsize &&
1567
+ pos + 1 < (int)p->num_objects) {
1545
1568
  /* Check for ambiguousity */
1546
1569
  const unsigned char *next = current + stride;
1547
1570
 
@@ -1566,13 +1589,13 @@ static int pack_entry_find_offset(
1566
1589
  }
1567
1590
 
1568
1591
  *offset_out = offset;
1569
- git_oid_fromraw(found_oid, current);
1592
+ git_oid__fromraw(found_oid, current, p->oid_type);
1570
1593
 
1571
1594
  #ifdef INDEX_DEBUG_LOOKUP
1572
1595
  {
1573
- unsigned char hex_sha1[GIT_OID_HEXSZ + 1];
1596
+ char hex_sha1[p->oid_hexsize + 1];
1574
1597
  git_oid_fmt(hex_sha1, found_oid);
1575
- hex_sha1[GIT_OID_HEXSZ] = '\0';
1598
+ hex_sha1[p->oid_hexsize] = '\0';
1576
1599
  printf("found lo=%d %s\n", lo, hex_sha1);
1577
1600
  }
1578
1601
  #endif
@@ -1594,10 +1617,10 @@ int git_pack_entry_find(
1594
1617
 
1595
1618
  GIT_ASSERT_ARG(p);
1596
1619
 
1597
- if (len == GIT_OID_HEXSZ && p->num_bad_objects) {
1620
+ if (len == p->oid_hexsize && p->num_bad_objects) {
1598
1621
  unsigned i;
1599
1622
  for (i = 0; i < p->num_bad_objects; i++)
1600
- if (git_oid__cmp(short_oid, &p->bad_object_sha1[i]) == 0)
1623
+ if (git_oid__cmp(short_oid, &p->bad_object_ids[i]) == 0)
1601
1624
  return packfile_error("bad object found in packfile");
1602
1625
  }
1603
1626
 
@@ -1630,6 +1653,6 @@ int git_pack_entry_find(
1630
1653
  e->offset = offset;
1631
1654
  e->p = p;
1632
1655
 
1633
- git_oid_cpy(&e->sha1, &found_oid);
1656
+ git_oid_cpy(&e->id, &found_oid);
1634
1657
  return 0;
1635
1658
  }
@@ -99,13 +99,19 @@ struct git_pack_file {
99
99
 
100
100
  uint32_t num_objects;
101
101
  uint32_t num_bad_objects;
102
- git_oid *bad_object_sha1; /* array of git_oid */
102
+ git_oid *bad_object_ids; /* array of git_oid */
103
+
104
+ git_oid_t oid_type;
105
+ unsigned oid_hexsize:7,
106
+ oid_size:6,
107
+ pack_local:1,
108
+ pack_keep:1,
109
+ has_cache:1;
103
110
 
104
111
  int index_version;
105
112
  git_time_t mtime;
106
- unsigned pack_local:1, pack_keep:1, has_cache:1;
107
113
  git_oidmap *idx_cache;
108
- unsigned char **oids;
114
+ unsigned char **ids;
109
115
 
110
116
  git_pack_cache bases; /* delta base cache */
111
117
 
@@ -116,21 +122,26 @@ struct git_pack_file {
116
122
  };
117
123
 
118
124
  /**
119
- * Return the position where an OID (or a prefix) would be inserted within the
120
- * OID Lookup Table of an .idx file. This performs binary search between the lo
121
- * and hi indices.
125
+ * Return the position where an OID (or a prefix) would be inserted within
126
+ * the OID Lookup Table of an .idx file. This performs binary search
127
+ * between the lo and hi indices.
122
128
  *
123
- * The stride parameter is provided because .idx files version 1 store the OIDs
124
- * interleaved with the 4-byte file offsets of the objects within the .pack
125
- * file (stride = 24), whereas files with version 2 store them in a contiguous
126
- * flat array (stride = 20).
129
+ * The stride parameter is provided because .idx files version 1 store the
130
+ * OIDs interleaved with the 4-byte file offsets of the objects within the
131
+ * .pack file (stride = oid_size + 4), whereas files with version 2 store
132
+ * them in a contiguous flat array (stride = oid_size).
127
133
  */
128
- int git_pack__lookup_sha1(const void *oid_lookup_table, size_t stride, unsigned lo,
129
- unsigned hi, const unsigned char *oid_prefix);
134
+ int git_pack__lookup_id(
135
+ const void *id_lookup_table,
136
+ size_t stride,
137
+ unsigned lo,
138
+ unsigned hi,
139
+ const unsigned char *id_prefix,
140
+ const git_oid_t oid_type);
130
141
 
131
142
  struct git_pack_entry {
132
143
  off64_t offset;
133
- git_oid sha1;
144
+ git_oid id;
134
145
  struct git_pack_file *p;
135
146
  };
136
147
 
@@ -174,12 +185,15 @@ int get_delta_base(
174
185
  off64_t delta_obj_offset);
175
186
 
176
187
  void git_packfile_free(struct git_pack_file *p, bool unlink_packfile);
177
- int git_packfile_alloc(struct git_pack_file **pack_out, const char *path);
188
+ int git_packfile_alloc(
189
+ struct git_pack_file **pack_out,
190
+ const char *path,
191
+ git_oid_t oid_type);
178
192
 
179
193
  int git_pack_entry_find(
180
194
  struct git_pack_entry *e,
181
195
  struct git_pack_file *p,
182
- const git_oid *short_oid,
196
+ const git_oid *short_id,
183
197
  size_t len);
184
198
  int git_pack_foreach_entry(
185
199
  struct git_pack_file *p,
@@ -5,6 +5,7 @@
5
5
  * a Linking Exception. For full terms see the included COPYING file.
6
6
  */
7
7
  #include "parse.h"
8
+ #include "oid.h"
8
9
 
9
10
  int git_parse_ctx_init(git_parse_ctx *ctx, const char *content, size_t content_len)
10
11
  {
@@ -101,13 +102,16 @@ int git_parse_advance_digit(int64_t *out, git_parse_ctx *ctx, int base)
101
102
  return 0;
102
103
  }
103
104
 
104
- int git_parse_advance_oid(git_oid *out, git_parse_ctx *ctx)
105
+ int git_parse_advance_oid(git_oid *out, git_parse_ctx *ctx, git_oid_t oid_type)
105
106
  {
106
- if (ctx->line_len < GIT_OID_HEXSZ)
107
+ size_t oid_hexsize = git_oid_hexsize(oid_type);
108
+ GIT_ASSERT(oid_hexsize);
109
+
110
+ if (ctx->line_len < oid_hexsize)
107
111
  return -1;
108
- if ((git_oid_fromstrn(out, ctx->line, GIT_OID_HEXSZ)) < 0)
112
+ if ((git_oid__fromstrn(out, ctx->line, oid_hexsize, oid_type)) < 0)
109
113
  return -1;
110
- git_parse_advance_chars(ctx, GIT_OID_HEXSZ);
114
+ git_parse_advance_chars(ctx, oid_hexsize);
111
115
  return 0;
112
116
  }
113
117