rugged 1.5.1 → 1.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/ext/rugged/extconf.rb +2 -2
- data/ext/rugged/rugged_blame.c +2 -0
- data/ext/rugged/rugged_blob.c +3 -0
- data/ext/rugged/rugged_commit.c +1 -0
- data/ext/rugged/rugged_config.c +2 -0
- data/ext/rugged/rugged_diff.c +1 -0
- data/ext/rugged/rugged_index.c +2 -0
- data/ext/rugged/rugged_patch.c +1 -0
- data/ext/rugged/rugged_rebase.c +1 -0
- data/ext/rugged/rugged_reference.c +1 -0
- data/ext/rugged/rugged_remote.c +1 -0
- data/ext/rugged/rugged_repo.c +5 -2
- data/ext/rugged/rugged_revwalk.c +5 -1
- data/ext/rugged/rugged_submodule.c +1 -0
- data/ext/rugged/rugged_tag.c +1 -0
- data/ext/rugged/rugged_tree.c +4 -0
- data/lib/rugged/index.rb +1 -1
- data/lib/rugged/tree.rb +1 -1
- data/lib/rugged/version.rb +1 -1
- data/vendor/libgit2/CMakeLists.txt +5 -1
- data/vendor/libgit2/COPYING +30 -0
- data/vendor/libgit2/cmake/ExperimentalFeatures.cmake +23 -0
- data/vendor/libgit2/deps/ntlmclient/CMakeLists.txt +2 -0
- data/vendor/libgit2/include/git2/common.h +13 -6
- data/vendor/libgit2/include/git2/deprecated.h +6 -0
- data/vendor/libgit2/include/git2/diff.h +1 -1
- data/vendor/libgit2/include/git2/experimental.h +20 -0
- data/vendor/libgit2/include/git2/indexer.h +29 -0
- data/vendor/libgit2/include/git2/object.h +28 -2
- data/vendor/libgit2/include/git2/odb.h +58 -7
- data/vendor/libgit2/include/git2/odb_backend.h +106 -18
- data/vendor/libgit2/include/git2/oid.h +115 -15
- data/vendor/libgit2/include/git2/repository.h +20 -1
- data/vendor/libgit2/include/git2/stash.h +60 -6
- data/vendor/libgit2/include/git2/strarray.h +0 -13
- data/vendor/libgit2/include/git2/sys/odb_backend.h +1 -1
- data/vendor/libgit2/include/git2/sys/transport.h +12 -0
- data/vendor/libgit2/include/git2/version.h +4 -4
- data/vendor/libgit2/include/git2.h +1 -0
- data/vendor/libgit2/src/CMakeLists.txt +0 -6
- data/vendor/libgit2/src/cli/CMakeLists.txt +6 -2
- data/vendor/libgit2/src/cli/cmd_hash_object.c +27 -8
- data/vendor/libgit2/src/cli/opt.c +1 -1
- data/vendor/libgit2/src/libgit2/CMakeLists.txt +25 -15
- data/vendor/libgit2/src/libgit2/annotated_commit.c +1 -1
- data/vendor/libgit2/src/libgit2/annotated_commit.h +1 -1
- data/vendor/libgit2/src/libgit2/attr_file.c +1 -1
- data/vendor/libgit2/src/libgit2/attrcache.c +1 -1
- data/vendor/libgit2/src/libgit2/blame.c +2 -0
- data/vendor/libgit2/src/libgit2/blob.c +4 -2
- data/vendor/libgit2/src/libgit2/blob.h +2 -2
- data/vendor/libgit2/src/libgit2/branch.c +2 -2
- data/vendor/libgit2/src/libgit2/cherrypick.c +3 -3
- data/vendor/libgit2/src/libgit2/clone.c +31 -2
- data/vendor/libgit2/src/libgit2/commit.c +52 -17
- data/vendor/libgit2/src/libgit2/commit.h +25 -7
- data/vendor/libgit2/src/libgit2/commit_graph.c +47 -32
- data/vendor/libgit2/src/libgit2/commit_graph.h +3 -0
- data/vendor/libgit2/src/libgit2/commit_list.c +6 -2
- data/vendor/libgit2/src/libgit2/config.c +1 -1
- data/vendor/libgit2/src/libgit2/config_file.c +2 -2
- data/vendor/libgit2/src/libgit2/describe.c +8 -8
- data/vendor/libgit2/src/libgit2/diff.c +5 -1
- data/vendor/libgit2/src/libgit2/diff_file.c +15 -6
- data/vendor/libgit2/src/libgit2/diff_generate.c +17 -12
- data/vendor/libgit2/src/libgit2/diff_print.c +5 -5
- data/vendor/libgit2/src/libgit2/diff_tform.c +4 -0
- data/vendor/libgit2/src/libgit2/email.c +2 -2
- data/vendor/libgit2/src/libgit2/experimental.h.in +13 -0
- data/vendor/libgit2/src/libgit2/fetch.c +3 -6
- data/vendor/libgit2/src/libgit2/fetchhead.c +4 -4
- data/vendor/libgit2/src/libgit2/ident.c +3 -3
- data/vendor/libgit2/src/libgit2/index.c +11 -9
- data/vendor/libgit2/src/libgit2/indexer.c +107 -44
- data/vendor/libgit2/src/libgit2/iterator.c +4 -2
- data/vendor/libgit2/src/libgit2/libgit2.c +19 -0
- data/vendor/libgit2/src/libgit2/merge.c +3 -3
- data/vendor/libgit2/src/libgit2/midx.c +16 -15
- data/vendor/libgit2/src/libgit2/mwindow.c +5 -2
- data/vendor/libgit2/src/libgit2/mwindow.h +4 -1
- data/vendor/libgit2/src/libgit2/notes.c +5 -5
- data/vendor/libgit2/src/libgit2/object.c +89 -25
- data/vendor/libgit2/src/libgit2/object.h +12 -3
- data/vendor/libgit2/src/libgit2/odb.c +194 -50
- data/vendor/libgit2/src/libgit2/odb.h +43 -4
- data/vendor/libgit2/src/libgit2/odb_loose.c +128 -70
- data/vendor/libgit2/src/libgit2/odb_pack.c +96 -44
- data/vendor/libgit2/src/libgit2/oid.c +134 -76
- data/vendor/libgit2/src/libgit2/oid.h +183 -9
- data/vendor/libgit2/src/libgit2/pack-objects.c +15 -4
- data/vendor/libgit2/src/libgit2/pack.c +90 -66
- data/vendor/libgit2/src/libgit2/pack.h +29 -15
- data/vendor/libgit2/src/libgit2/parse.c +4 -3
- data/vendor/libgit2/src/libgit2/patch_parse.c +5 -5
- data/vendor/libgit2/src/libgit2/push.c +13 -3
- data/vendor/libgit2/src/libgit2/reader.c +1 -1
- data/vendor/libgit2/src/libgit2/rebase.c +19 -18
- data/vendor/libgit2/src/libgit2/refdb_fs.c +70 -39
- data/vendor/libgit2/src/libgit2/reflog.c +7 -5
- data/vendor/libgit2/src/libgit2/reflog.h +1 -2
- data/vendor/libgit2/src/libgit2/refs.c +2 -0
- data/vendor/libgit2/src/libgit2/remote.c +38 -37
- data/vendor/libgit2/src/libgit2/remote.h +40 -0
- data/vendor/libgit2/src/libgit2/repository.c +212 -36
- data/vendor/libgit2/src/libgit2/repository.h +9 -0
- data/vendor/libgit2/src/libgit2/reset.c +2 -2
- data/vendor/libgit2/src/libgit2/revert.c +4 -4
- data/vendor/libgit2/src/libgit2/revparse.c +23 -7
- data/vendor/libgit2/src/libgit2/revwalk.c +5 -1
- data/vendor/libgit2/src/libgit2/stash.c +201 -26
- data/vendor/libgit2/src/libgit2/strarray.c +1 -0
- data/vendor/libgit2/src/libgit2/strarray.h +25 -0
- data/vendor/libgit2/src/libgit2/streams/openssl.c +1 -1
- data/vendor/libgit2/src/libgit2/streams/openssl_dynamic.c +7 -3
- data/vendor/libgit2/src/libgit2/streams/socket.c +4 -1
- data/vendor/libgit2/src/libgit2/submodule.c +6 -2
- data/vendor/libgit2/src/libgit2/sysdir.c +294 -7
- data/vendor/libgit2/src/libgit2/sysdir.h +39 -9
- data/vendor/libgit2/src/libgit2/tag.c +29 -10
- data/vendor/libgit2/src/libgit2/tag.h +2 -2
- data/vendor/libgit2/src/libgit2/threadstate.h +1 -1
- data/vendor/libgit2/src/libgit2/transports/http.c +8 -7
- data/vendor/libgit2/src/libgit2/transports/httpclient.c +9 -0
- data/vendor/libgit2/src/libgit2/transports/httpclient.h +10 -0
- data/vendor/libgit2/src/libgit2/transports/local.c +14 -0
- data/vendor/libgit2/src/libgit2/transports/smart.c +35 -0
- data/vendor/libgit2/src/libgit2/transports/smart.h +10 -1
- data/vendor/libgit2/src/libgit2/transports/smart_pkt.c +153 -41
- data/vendor/libgit2/src/libgit2/transports/smart_protocol.c +42 -12
- data/vendor/libgit2/src/libgit2/transports/ssh.c +62 -65
- data/vendor/libgit2/src/libgit2/transports/winhttp.c +9 -4
- data/vendor/libgit2/src/libgit2/tree-cache.c +4 -4
- data/vendor/libgit2/src/libgit2/tree.c +22 -16
- data/vendor/libgit2/src/libgit2/tree.h +2 -2
- data/vendor/libgit2/src/libgit2/worktree.c +5 -0
- data/vendor/libgit2/src/util/CMakeLists.txt +7 -1
- data/vendor/libgit2/src/util/fs_path.c +1 -1
- data/vendor/libgit2/src/util/futils.c +0 -3
- data/vendor/libgit2/src/util/git2_util.h +2 -2
- data/vendor/libgit2/src/util/hash/openssl.c +4 -3
- data/vendor/libgit2/src/util/hash/rfc6234/sha.h +0 -112
- data/vendor/libgit2/src/util/hash.h +13 -0
- data/vendor/libgit2/src/util/net.c +338 -84
- data/vendor/libgit2/src/util/net.h +7 -0
- data/vendor/libgit2/src/util/posix.h +2 -0
- data/vendor/libgit2/src/util/rand.c +4 -0
- data/vendor/libgit2/src/util/regexp.c +3 -3
- data/vendor/libgit2/src/util/thread.h +20 -19
- data/vendor/libgit2/src/util/util.h +1 -0
- metadata +7 -5
- data/vendor/libgit2/src/util/win32/findfile.c +0 -286
- data/vendor/libgit2/src/util/win32/findfile.h +0 -22
- /data/vendor/libgit2/src/{features.h.in → util/git2_features.h.in} +0 -0
@@ -26,6 +26,7 @@
|
|
26
26
|
|
27
27
|
struct pack_backend {
|
28
28
|
git_odb_backend parent;
|
29
|
+
git_odb_backend_pack_options opts;
|
29
30
|
git_midx_file *midx;
|
30
31
|
git_vector midx_packs;
|
31
32
|
git_vector packs;
|
@@ -95,24 +96,24 @@ struct pack_writepack {
|
|
95
96
|
* --------------------------------------------------
|
96
97
|
*
|
97
98
|
* # pack_backend__exists / pack_backend__exists_prefix
|
98
|
-
* | Check if the given
|
99
|
+
* | Check if the given oid (or an oid prefix) exists in any of the
|
99
100
|
* | packs that have been loaded for our ODB.
|
100
101
|
* |
|
101
102
|
* |-# pack_entry_find / pack_entry_find_prefix
|
102
|
-
* | If there is a multi-pack-index present, search the
|
103
|
+
* | If there is a multi-pack-index present, search the oid in that
|
103
104
|
* | index first. If it is not found there, iterate through all the unindexed
|
104
105
|
* | packs that have been preloaded (starting by the pack where the latest
|
105
106
|
* | object was found) to try to find the OID in one of them.
|
106
107
|
* |
|
107
108
|
* |-# git_midx_entry_find
|
108
|
-
* | Search for the
|
109
|
+
* | Search for the oid in the multi-pack-index. See
|
109
110
|
* | <https://github.com/git/git/blob/master/Documentation/technical/pack-format.txt>
|
110
111
|
* | for specifics on the multi-pack-index format and how do we find
|
111
112
|
* | entries in it.
|
112
113
|
* |
|
113
114
|
* |-# git_pack_entry_find
|
114
|
-
* | Check the index of an individual unindexed pack to see if the
|
115
|
-
* | OID can be found. If we can find the offset to that
|
115
|
+
* | Check the index of an individual unindexed pack to see if the
|
116
|
+
* | OID can be found. If we can find the offset to that inside of the
|
116
117
|
* | index, that means the object is contained inside of the packfile and
|
117
118
|
* | we can stop searching. Before returning, we verify that the
|
118
119
|
* | packfile behind the index we are searching still exists on disk.
|
@@ -141,13 +142,13 @@ struct pack_writepack {
|
|
141
142
|
* --------------------------------------------------
|
142
143
|
*
|
143
144
|
* # pack_backend__read / pack_backend__read_prefix
|
144
|
-
* | Check if the given
|
145
|
+
* | Check if the given oid (or an oid prefix) exists in any of the
|
145
146
|
* | packs that have been loaded for our ODB. If it does, open the packfile and
|
146
147
|
* | read from it.
|
147
148
|
* |
|
148
149
|
* |-# git_packfile_unpack
|
149
150
|
* Armed with a packfile and the offset within it, we can finally unpack
|
150
|
-
* the object pointed at by the
|
151
|
+
* the object pointed at by the oid. This involves mmapping part of
|
151
152
|
* the `.pack` file, and uncompressing the object within it (if it is
|
152
153
|
* stored in the undelfitied representation), or finding a base object and
|
153
154
|
* applying some deltas to its uncompressed representation (if it is stored
|
@@ -177,7 +178,7 @@ static int pack_entry_find(struct git_pack_entry *e,
|
|
177
178
|
* a prefix of an identifier.
|
178
179
|
* Sets GIT_EAMBIGUOUS if short oid is ambiguous.
|
179
180
|
* This method assumes that len is between
|
180
|
-
* GIT_OID_MINPREFIXLEN and
|
181
|
+
* GIT_OID_MINPREFIXLEN and the hexsize for the hash type.
|
181
182
|
*/
|
182
183
|
static int pack_entry_find_prefix(
|
183
184
|
struct git_pack_entry *e,
|
@@ -251,7 +252,7 @@ static int packfile_load__cb(void *data, git_str *path)
|
|
251
252
|
if (git_vector_search2(NULL, &backend->packs, packfile_byname_search_cmp, &index_prefix) == 0)
|
252
253
|
return 0;
|
253
254
|
|
254
|
-
error = git_mwindow_get_pack(&pack, path->ptr);
|
255
|
+
error = git_mwindow_get_pack(&pack, path->ptr, backend->opts.oid_type);
|
255
256
|
|
256
257
|
/* ignore missing .pack file as git does */
|
257
258
|
if (error == GIT_ENOTFOUND) {
|
@@ -270,33 +271,34 @@ static int pack_entry_find(struct git_pack_entry *e, struct pack_backend *backen
|
|
270
271
|
{
|
271
272
|
struct git_pack_file *last_found = backend->last_found, *p;
|
272
273
|
git_midx_entry midx_entry;
|
274
|
+
size_t oid_hexsize = git_oid_hexsize(backend->opts.oid_type);
|
273
275
|
size_t i;
|
274
276
|
|
275
277
|
if (backend->midx &&
|
276
|
-
git_midx_entry_find(&midx_entry, backend->midx, oid,
|
278
|
+
git_midx_entry_find(&midx_entry, backend->midx, oid, oid_hexsize) == 0 &&
|
277
279
|
midx_entry.pack_index < git_vector_length(&backend->midx_packs)) {
|
278
280
|
e->offset = midx_entry.offset;
|
279
|
-
git_oid_cpy(&e->
|
281
|
+
git_oid_cpy(&e->id, &midx_entry.sha1);
|
280
282
|
e->p = git_vector_get(&backend->midx_packs, midx_entry.pack_index);
|
281
283
|
return 0;
|
282
284
|
}
|
283
285
|
|
284
286
|
if (last_found &&
|
285
|
-
git_pack_entry_find(e, last_found, oid,
|
287
|
+
git_pack_entry_find(e, last_found, oid, oid_hexsize) == 0)
|
286
288
|
return 0;
|
287
289
|
|
288
290
|
git_vector_foreach(&backend->packs, i, p) {
|
289
291
|
if (p == last_found)
|
290
292
|
continue;
|
291
293
|
|
292
|
-
if (git_pack_entry_find(e, p, oid,
|
294
|
+
if (git_pack_entry_find(e, p, oid, oid_hexsize) == 0) {
|
293
295
|
backend->last_found = p;
|
294
296
|
return 0;
|
295
297
|
}
|
296
298
|
}
|
297
299
|
|
298
300
|
return git_odb__error_notfound(
|
299
|
-
"failed to find pack entry", oid,
|
301
|
+
"failed to find pack entry", oid, oid_hexsize);
|
300
302
|
}
|
301
303
|
|
302
304
|
static int pack_entry_find_prefix(
|
@@ -307,7 +309,7 @@ static int pack_entry_find_prefix(
|
|
307
309
|
{
|
308
310
|
int error;
|
309
311
|
size_t i;
|
310
|
-
git_oid found_full_oid =
|
312
|
+
git_oid found_full_oid = GIT_OID_SHA1_ZERO;
|
311
313
|
bool found = false;
|
312
314
|
struct git_pack_file *last_found = backend->last_found, *p;
|
313
315
|
git_midx_entry midx_entry;
|
@@ -318,9 +320,9 @@ static int pack_entry_find_prefix(
|
|
318
320
|
return error;
|
319
321
|
if (!error && midx_entry.pack_index < git_vector_length(&backend->midx_packs)) {
|
320
322
|
e->offset = midx_entry.offset;
|
321
|
-
git_oid_cpy(&e->
|
323
|
+
git_oid_cpy(&e->id, &midx_entry.sha1);
|
322
324
|
e->p = git_vector_get(&backend->midx_packs, midx_entry.pack_index);
|
323
|
-
git_oid_cpy(&found_full_oid, &e->
|
325
|
+
git_oid_cpy(&found_full_oid, &e->id);
|
324
326
|
found = true;
|
325
327
|
}
|
326
328
|
}
|
@@ -330,9 +332,9 @@ static int pack_entry_find_prefix(
|
|
330
332
|
if (error == GIT_EAMBIGUOUS)
|
331
333
|
return error;
|
332
334
|
if (!error) {
|
333
|
-
if (found && git_oid_cmp(&e->
|
335
|
+
if (found && git_oid_cmp(&e->id, &found_full_oid))
|
334
336
|
return git_odb__error_ambiguous("found multiple pack entries");
|
335
|
-
git_oid_cpy(&found_full_oid, &e->
|
337
|
+
git_oid_cpy(&found_full_oid, &e->id);
|
336
338
|
found = true;
|
337
339
|
}
|
338
340
|
}
|
@@ -345,9 +347,9 @@ static int pack_entry_find_prefix(
|
|
345
347
|
if (error == GIT_EAMBIGUOUS)
|
346
348
|
return error;
|
347
349
|
if (!error) {
|
348
|
-
if (found && git_oid_cmp(&e->
|
350
|
+
if (found && git_oid_cmp(&e->id, &found_full_oid))
|
349
351
|
return git_odb__error_ambiguous("found multiple pack entries");
|
350
|
-
git_oid_cpy(&found_full_oid, &e->
|
352
|
+
git_oid_cpy(&found_full_oid, &e->id);
|
351
353
|
found = true;
|
352
354
|
backend->last_found = p;
|
353
355
|
}
|
@@ -425,7 +427,10 @@ static int process_multi_pack_index_pack(
|
|
425
427
|
}
|
426
428
|
|
427
429
|
/* Pack was not found. Allocate a new one. */
|
428
|
-
error = git_mwindow_get_pack(
|
430
|
+
error = git_mwindow_get_pack(
|
431
|
+
&pack,
|
432
|
+
git_str_cstr(&pack_path),
|
433
|
+
backend->opts.oid_type);
|
429
434
|
git_str_dispose(&pack_path);
|
430
435
|
if (error < 0)
|
431
436
|
return error;
|
@@ -596,32 +601,33 @@ static int pack_backend__read_prefix(
|
|
596
601
|
void **buffer_p,
|
597
602
|
size_t *len_p,
|
598
603
|
git_object_t *type_p,
|
599
|
-
git_odb_backend *
|
604
|
+
git_odb_backend *_backend,
|
600
605
|
const git_oid *short_oid,
|
601
606
|
size_t len)
|
602
607
|
{
|
608
|
+
struct pack_backend *backend = (struct pack_backend *)_backend;
|
603
609
|
int error = 0;
|
604
610
|
|
605
611
|
if (len < GIT_OID_MINPREFIXLEN)
|
606
612
|
error = git_odb__error_ambiguous("prefix length too short");
|
607
613
|
|
608
|
-
else if (len >=
|
614
|
+
else if (len >= git_oid_hexsize(backend->opts.oid_type)) {
|
609
615
|
/* We can fall back to regular read method */
|
610
|
-
error = pack_backend__read(buffer_p, len_p, type_p,
|
616
|
+
error = pack_backend__read(buffer_p, len_p, type_p, _backend, short_oid);
|
611
617
|
if (!error)
|
612
618
|
git_oid_cpy(out_oid, short_oid);
|
613
619
|
} else {
|
614
620
|
struct git_pack_entry e;
|
615
621
|
git_rawobj raw = {NULL};
|
616
622
|
|
617
|
-
if ((error = pack_entry_find_prefix(
|
618
|
-
|
619
|
-
|
623
|
+
if ((error = pack_entry_find_prefix(&e,
|
624
|
+
backend, short_oid, len)) == 0 &&
|
625
|
+
(error = git_packfile_unpack(&raw, e.p, &e.offset)) == 0)
|
620
626
|
{
|
621
627
|
*buffer_p = raw.data;
|
622
628
|
*len_p = raw.len;
|
623
629
|
*type_p = raw.type;
|
624
|
-
git_oid_cpy(out_oid, &e.
|
630
|
+
git_oid_cpy(out_oid, &e.id);
|
625
631
|
}
|
626
632
|
}
|
627
633
|
|
@@ -642,7 +648,7 @@ static int pack_backend__exists_prefix(
|
|
642
648
|
struct git_pack_entry e = {0};
|
643
649
|
|
644
650
|
error = pack_entry_find_prefix(&e, pb, short_id, len);
|
645
|
-
git_oid_cpy(out, &e.
|
651
|
+
git_oid_cpy(out, &e.id);
|
646
652
|
return error;
|
647
653
|
}
|
648
654
|
|
@@ -712,6 +718,7 @@ static int pack_backend__writepack(struct git_odb_writepack **out,
|
|
712
718
|
git_indexer_options opts = GIT_INDEXER_OPTIONS_INIT;
|
713
719
|
struct pack_backend *backend;
|
714
720
|
struct pack_writepack *writepack;
|
721
|
+
int error;
|
715
722
|
|
716
723
|
GIT_ASSERT_ARG(out);
|
717
724
|
GIT_ASSERT_ARG(_backend);
|
@@ -726,11 +733,20 @@ static int pack_backend__writepack(struct git_odb_writepack **out,
|
|
726
733
|
writepack = git__calloc(1, sizeof(struct pack_writepack));
|
727
734
|
GIT_ERROR_CHECK_ALLOC(writepack);
|
728
735
|
|
729
|
-
|
730
|
-
|
731
|
-
|
736
|
+
#ifdef GIT_EXPERIMENTAL_SHA256
|
737
|
+
opts.odb = odb;
|
738
|
+
|
739
|
+
error = git_indexer_new(&writepack->indexer,
|
740
|
+
backend->pack_folder,
|
741
|
+
backend->opts.oid_type,
|
742
|
+
&opts);
|
743
|
+
#else
|
744
|
+
error = git_indexer_new(&writepack->indexer,
|
745
|
+
backend->pack_folder, 0, odb, &opts);
|
746
|
+
#endif
|
747
|
+
|
748
|
+
if (error < 0)
|
732
749
|
return -1;
|
733
|
-
}
|
734
750
|
|
735
751
|
writepack->parent.backend = _backend;
|
736
752
|
writepack->parent.append = pack_backend__writepack_append;
|
@@ -840,7 +856,10 @@ static void pack_backend__free(git_odb_backend *_backend)
|
|
840
856
|
git__free(backend);
|
841
857
|
}
|
842
858
|
|
843
|
-
static int pack_backend__alloc(
|
859
|
+
static int pack_backend__alloc(
|
860
|
+
struct pack_backend **out,
|
861
|
+
size_t initial_size,
|
862
|
+
const git_odb_backend_pack_options *opts)
|
844
863
|
{
|
845
864
|
struct pack_backend *backend = git__calloc(1, sizeof(struct pack_backend));
|
846
865
|
GIT_ERROR_CHECK_ALLOC(backend);
|
@@ -849,12 +868,19 @@ static int pack_backend__alloc(struct pack_backend **out, size_t initial_size)
|
|
849
868
|
git__free(backend);
|
850
869
|
return -1;
|
851
870
|
}
|
871
|
+
|
852
872
|
if (git_vector_init(&backend->packs, initial_size, packfile_sort__cb) < 0) {
|
853
873
|
git_vector_free(&backend->midx_packs);
|
854
874
|
git__free(backend);
|
855
875
|
return -1;
|
856
876
|
}
|
857
877
|
|
878
|
+
if (opts)
|
879
|
+
memcpy(&backend->opts, opts, sizeof(git_odb_backend_pack_options));
|
880
|
+
|
881
|
+
if (!backend->opts.oid_type)
|
882
|
+
backend->opts.oid_type = GIT_OID_DEFAULT;
|
883
|
+
|
858
884
|
backend->parent.version = GIT_ODB_BACKEND_VERSION;
|
859
885
|
|
860
886
|
backend->parent.read = &pack_backend__read;
|
@@ -873,17 +899,31 @@ static int pack_backend__alloc(struct pack_backend **out, size_t initial_size)
|
|
873
899
|
return 0;
|
874
900
|
}
|
875
901
|
|
876
|
-
|
902
|
+
#ifdef GIT_EXPERIMENTAL_SHA256
|
903
|
+
int git_odb_backend_one_pack(
|
904
|
+
git_odb_backend **backend_out,
|
905
|
+
const char *idx,
|
906
|
+
const git_odb_backend_pack_options *opts)
|
907
|
+
#else
|
908
|
+
int git_odb_backend_one_pack(
|
909
|
+
git_odb_backend **backend_out,
|
910
|
+
const char *idx)
|
911
|
+
#endif
|
877
912
|
{
|
878
913
|
struct pack_backend *backend = NULL;
|
879
914
|
struct git_pack_file *packfile = NULL;
|
880
915
|
|
881
|
-
|
916
|
+
#ifndef GIT_EXPERIMENTAL_SHA256
|
917
|
+
git_odb_backend_pack_options *opts = NULL;
|
918
|
+
#endif
|
919
|
+
|
920
|
+
git_oid_t oid_type = opts ? opts->oid_type : 0;
|
921
|
+
|
922
|
+
if (pack_backend__alloc(&backend, 1, opts) < 0)
|
882
923
|
return -1;
|
883
924
|
|
884
|
-
if (git_mwindow_get_pack(&packfile, idx) < 0 ||
|
885
|
-
|
886
|
-
{
|
925
|
+
if (git_mwindow_get_pack(&packfile, idx, oid_type) < 0 ||
|
926
|
+
git_vector_insert(&backend->packs, packfile) < 0) {
|
887
927
|
pack_backend__free((git_odb_backend *)backend);
|
888
928
|
return -1;
|
889
929
|
}
|
@@ -892,18 +932,30 @@ int git_odb_backend_one_pack(git_odb_backend **backend_out, const char *idx)
|
|
892
932
|
return 0;
|
893
933
|
}
|
894
934
|
|
895
|
-
|
935
|
+
#ifdef GIT_EXPERIMENTAL_SHA256
|
936
|
+
int git_odb_backend_pack(
|
937
|
+
git_odb_backend **backend_out,
|
938
|
+
const char *objects_dir,
|
939
|
+
const git_odb_backend_pack_options *opts)
|
940
|
+
#else
|
941
|
+
int git_odb_backend_pack(
|
942
|
+
git_odb_backend **backend_out,
|
943
|
+
const char *objects_dir)
|
944
|
+
#endif
|
896
945
|
{
|
897
946
|
int error = 0;
|
898
947
|
struct pack_backend *backend = NULL;
|
899
948
|
git_str path = GIT_STR_INIT;
|
900
949
|
|
901
|
-
|
950
|
+
#ifndef GIT_EXPERIMENTAL_SHA256
|
951
|
+
git_odb_backend_pack_options *opts = NULL;
|
952
|
+
#endif
|
953
|
+
|
954
|
+
if (pack_backend__alloc(&backend, 8, opts) < 0)
|
902
955
|
return -1;
|
903
956
|
|
904
957
|
if (!(error = git_str_joinpath(&path, objects_dir, "pack")) &&
|
905
|
-
|
906
|
-
{
|
958
|
+
git_fs_path_isdir(git_str_cstr(&path))) {
|
907
959
|
backend->pack_folder = git_str_detach(&path);
|
908
960
|
error = pack_backend__refresh((git_odb_backend *)backend);
|
909
961
|
}
|
@@ -14,13 +14,13 @@
|
|
14
14
|
#include <limits.h>
|
15
15
|
|
16
16
|
const git_oid git_oid__empty_blob_sha1 =
|
17
|
-
|
18
|
-
|
17
|
+
GIT_OID_INIT(GIT_OID_SHA1,
|
18
|
+
{ 0xe6, 0x9d, 0xe2, 0x9b, 0xb2, 0xd1, 0xd6, 0x43, 0x4b, 0x8b,
|
19
|
+
0x29, 0xae, 0x77, 0x5a, 0xd8, 0xc2, 0xe4, 0x8c, 0x53, 0x91 });
|
19
20
|
const git_oid git_oid__empty_tree_sha1 =
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
static char to_hex[] = "0123456789abcdef";
|
21
|
+
GIT_OID_INIT(GIT_OID_SHA1,
|
22
|
+
{ 0x4b, 0x82, 0x5d, 0xc6, 0x42, 0xcb, 0x6e, 0xb9, 0xa0, 0x60,
|
23
|
+
0xe5, 0x4b, 0xf8, 0xd6, 0x92, 0x88, 0xfb, 0xee, 0x49, 0x04 });
|
24
24
|
|
25
25
|
static int oid_error_invalid(const char *msg)
|
26
26
|
{
|
@@ -28,21 +28,31 @@ static int oid_error_invalid(const char *msg)
|
|
28
28
|
return -1;
|
29
29
|
}
|
30
30
|
|
31
|
-
int
|
31
|
+
int git_oid__fromstrn(
|
32
|
+
git_oid *out,
|
33
|
+
const char *str,
|
34
|
+
size_t length,
|
35
|
+
git_oid_t type)
|
32
36
|
{
|
33
|
-
size_t p;
|
37
|
+
size_t size, p;
|
34
38
|
int v;
|
35
39
|
|
36
40
|
GIT_ASSERT_ARG(out);
|
37
41
|
GIT_ASSERT_ARG(str);
|
38
42
|
|
43
|
+
if (!(size = git_oid_size(type)))
|
44
|
+
return oid_error_invalid("unknown type");
|
45
|
+
|
39
46
|
if (!length)
|
40
47
|
return oid_error_invalid("too short");
|
41
48
|
|
42
|
-
if (length >
|
49
|
+
if (length > git_oid_hexsize(type))
|
43
50
|
return oid_error_invalid("too long");
|
44
51
|
|
45
|
-
|
52
|
+
#ifdef GIT_EXPERIMENTAL_SHA256
|
53
|
+
out->type = type;
|
54
|
+
#endif
|
55
|
+
memset(out->id, 0, size);
|
46
56
|
|
47
57
|
for (p = 0; p < length; p++) {
|
48
58
|
v = git__fromhex(str[p]);
|
@@ -55,87 +65,128 @@ int git_oid_fromstrn(git_oid *out, const char *str, size_t length)
|
|
55
65
|
return 0;
|
56
66
|
}
|
57
67
|
|
58
|
-
int
|
68
|
+
int git_oid__fromstrp(git_oid *out, const char *str, git_oid_t type)
|
59
69
|
{
|
60
|
-
return
|
70
|
+
return git_oid__fromstrn(out, str, strlen(str), type);
|
61
71
|
}
|
62
72
|
|
63
|
-
int
|
73
|
+
int git_oid__fromstr(git_oid *out, const char *str, git_oid_t type)
|
64
74
|
{
|
65
|
-
return
|
75
|
+
return git_oid__fromstrn(out, str, git_oid_hexsize(type), type);
|
66
76
|
}
|
67
77
|
|
68
|
-
|
78
|
+
#ifdef GIT_EXPERIMENTAL_SHA256
|
79
|
+
int git_oid_fromstrn(
|
80
|
+
git_oid *out,
|
81
|
+
const char *str,
|
82
|
+
size_t length,
|
83
|
+
git_oid_t type)
|
69
84
|
{
|
70
|
-
|
71
|
-
*str++ = to_hex[val & 0xf];
|
72
|
-
return str;
|
85
|
+
return git_oid__fromstrn(out, str, length, type);
|
73
86
|
}
|
74
87
|
|
88
|
+
int git_oid_fromstrp(git_oid *out, const char *str, git_oid_t type)
|
89
|
+
{
|
90
|
+
return git_oid_fromstrn(out, str, strlen(str), type);
|
91
|
+
}
|
92
|
+
|
93
|
+
int git_oid_fromstr(git_oid *out, const char *str, git_oid_t type)
|
94
|
+
{
|
95
|
+
return git_oid_fromstrn(out, str, git_oid_hexsize(type), type);
|
96
|
+
}
|
97
|
+
#else
|
98
|
+
int git_oid_fromstrn(
|
99
|
+
git_oid *out,
|
100
|
+
const char *str,
|
101
|
+
size_t length)
|
102
|
+
{
|
103
|
+
return git_oid__fromstrn(out, str, length, GIT_OID_SHA1);
|
104
|
+
}
|
105
|
+
|
106
|
+
int git_oid_fromstrp(git_oid *out, const char *str)
|
107
|
+
{
|
108
|
+
return git_oid__fromstrn(out, str, strlen(str), GIT_OID_SHA1);
|
109
|
+
}
|
110
|
+
|
111
|
+
int git_oid_fromstr(git_oid *out, const char *str)
|
112
|
+
{
|
113
|
+
return git_oid__fromstrn(out, str, GIT_OID_SHA1_HEXSIZE, GIT_OID_SHA1);
|
114
|
+
}
|
115
|
+
#endif
|
116
|
+
|
75
117
|
int git_oid_nfmt(char *str, size_t n, const git_oid *oid)
|
76
118
|
{
|
77
|
-
size_t
|
119
|
+
size_t hex_size;
|
78
120
|
|
79
121
|
if (!oid) {
|
80
122
|
memset(str, 0, n);
|
81
123
|
return 0;
|
82
124
|
}
|
83
|
-
if (n > GIT_OID_HEXSZ) {
|
84
|
-
memset(&str[GIT_OID_HEXSZ], 0, n - GIT_OID_HEXSZ);
|
85
|
-
n = GIT_OID_HEXSZ;
|
86
|
-
}
|
87
125
|
|
88
|
-
|
126
|
+
if (!(hex_size = git_oid_hexsize(git_oid_type(oid))))
|
127
|
+
return oid_error_invalid("unknown type");
|
89
128
|
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
*str++ = to_hex[oid->id[i] >> 4];
|
129
|
+
if (n > hex_size) {
|
130
|
+
memset(&str[hex_size], 0, n - hex_size);
|
131
|
+
n = hex_size;
|
132
|
+
}
|
95
133
|
|
134
|
+
git_oid_fmt_substr(str, oid, 0, n);
|
96
135
|
return 0;
|
97
136
|
}
|
98
137
|
|
99
138
|
int git_oid_fmt(char *str, const git_oid *oid)
|
100
139
|
{
|
101
|
-
return git_oid_nfmt(str,
|
140
|
+
return git_oid_nfmt(str, git_oid_hexsize(git_oid_type(oid)), oid);
|
102
141
|
}
|
103
142
|
|
104
143
|
int git_oid_pathfmt(char *str, const git_oid *oid)
|
105
144
|
{
|
106
|
-
size_t
|
145
|
+
size_t hex_size;
|
107
146
|
|
108
|
-
|
109
|
-
|
110
|
-
for (i = 1; i < sizeof(oid->id); i++)
|
111
|
-
str = fmt_one(str, oid->id[i]);
|
147
|
+
if (!(hex_size = git_oid_hexsize(git_oid_type(oid))))
|
148
|
+
return oid_error_invalid("unknown type");
|
112
149
|
|
150
|
+
git_oid_fmt_substr(str, oid, 0, 2);
|
151
|
+
str[2] = '/';
|
152
|
+
git_oid_fmt_substr(&str[3], oid, 2, (hex_size - 2));
|
113
153
|
return 0;
|
114
154
|
}
|
115
155
|
|
116
156
|
char *git_oid_tostr_s(const git_oid *oid)
|
117
157
|
{
|
118
158
|
char *str = GIT_THREADSTATE->oid_fmt;
|
119
|
-
git_oid_nfmt(str,
|
159
|
+
git_oid_nfmt(str, git_oid_hexsize(git_oid_type(oid)) + 1, oid);
|
120
160
|
return str;
|
121
161
|
}
|
122
162
|
|
123
163
|
char *git_oid_allocfmt(const git_oid *oid)
|
124
164
|
{
|
125
|
-
|
126
|
-
|
165
|
+
size_t hex_size = git_oid_hexsize(git_oid_type(oid));
|
166
|
+
char *str = git__malloc(hex_size + 1);
|
167
|
+
|
168
|
+
if (!hex_size || !str)
|
169
|
+
return NULL;
|
170
|
+
|
171
|
+
if (git_oid_nfmt(str, hex_size + 1, oid) < 0) {
|
172
|
+
git__free(str);
|
127
173
|
return NULL;
|
128
|
-
|
174
|
+
}
|
175
|
+
|
129
176
|
return str;
|
130
177
|
}
|
131
178
|
|
132
179
|
char *git_oid_tostr(char *out, size_t n, const git_oid *oid)
|
133
180
|
{
|
181
|
+
size_t hex_size;
|
182
|
+
|
134
183
|
if (!out || n == 0)
|
135
184
|
return "";
|
136
185
|
|
137
|
-
|
138
|
-
|
186
|
+
hex_size = oid ? git_oid_hexsize(git_oid_type(oid)) : 0;
|
187
|
+
|
188
|
+
if (n > hex_size + 1)
|
189
|
+
n = hex_size + 1;
|
139
190
|
|
140
191
|
git_oid_nfmt(out, n - 1, oid); /* allow room for terminating NUL */
|
141
192
|
out[n - 1] = '\0';
|
@@ -143,51 +194,44 @@ char *git_oid_tostr(char *out, size_t n, const git_oid *oid)
|
|
143
194
|
return out;
|
144
195
|
}
|
145
196
|
|
146
|
-
int
|
147
|
-
git_oid *oid, const char **buffer_out,
|
148
|
-
const char *buffer_end, const char *header)
|
197
|
+
int git_oid__fromraw(git_oid *out, const unsigned char *raw, git_oid_t type)
|
149
198
|
{
|
150
|
-
|
151
|
-
const size_t header_len = strlen(header);
|
152
|
-
|
153
|
-
const char *buffer = *buffer_out;
|
154
|
-
|
155
|
-
if (buffer + (header_len + sha_len + 1) > buffer_end)
|
156
|
-
return -1;
|
199
|
+
size_t size;
|
157
200
|
|
158
|
-
if (
|
159
|
-
return
|
160
|
-
|
161
|
-
if (buffer[header_len + sha_len] != '\n')
|
162
|
-
return -1;
|
163
|
-
|
164
|
-
if (git_oid_fromstr(oid, buffer + header_len) < 0)
|
165
|
-
return -1;
|
166
|
-
|
167
|
-
*buffer_out = buffer + (header_len + sha_len + 1);
|
201
|
+
if (!(size = git_oid_size(type)))
|
202
|
+
return oid_error_invalid("unknown type");
|
168
203
|
|
204
|
+
#ifdef GIT_EXPERIMENTAL_SHA256
|
205
|
+
out->type = type;
|
206
|
+
#endif
|
207
|
+
memcpy(out->id, raw, size);
|
169
208
|
return 0;
|
170
209
|
}
|
171
210
|
|
172
|
-
|
211
|
+
#ifdef GIT_EXPERIMENTAL_SHA256
|
212
|
+
int git_oid_fromraw(git_oid *out, const unsigned char *raw, git_oid_t type)
|
173
213
|
{
|
174
|
-
|
175
|
-
|
176
|
-
git_oid_fmt(hex_oid, oid);
|
177
|
-
git_str_puts(buf, header);
|
178
|
-
git_str_put(buf, hex_oid, GIT_OID_HEXSZ);
|
179
|
-
git_str_putc(buf, '\n');
|
214
|
+
return git_oid__fromraw(out, raw, type);
|
180
215
|
}
|
181
|
-
|
216
|
+
#else
|
182
217
|
int git_oid_fromraw(git_oid *out, const unsigned char *raw)
|
183
218
|
{
|
184
|
-
|
185
|
-
return 0;
|
219
|
+
return git_oid__fromraw(out, raw, GIT_OID_SHA1);
|
186
220
|
}
|
221
|
+
#endif
|
187
222
|
|
188
223
|
int git_oid_cpy(git_oid *out, const git_oid *src)
|
189
224
|
{
|
190
|
-
|
225
|
+
size_t size;
|
226
|
+
|
227
|
+
if (!(size = git_oid_size(git_oid_type(src))))
|
228
|
+
return oid_error_invalid("unknown type");
|
229
|
+
|
230
|
+
#ifdef GIT_EXPERIMENTAL_SHA256
|
231
|
+
out->type = src->type;
|
232
|
+
#endif
|
233
|
+
|
234
|
+
return git_oid_raw_cpy(out->id, src->id, size);
|
191
235
|
}
|
192
236
|
|
193
237
|
int git_oid_cmp(const git_oid *a, const git_oid *b)
|
@@ -202,6 +246,11 @@ int git_oid_equal(const git_oid *a, const git_oid *b)
|
|
202
246
|
|
203
247
|
int git_oid_ncmp(const git_oid *oid_a, const git_oid *oid_b, size_t len)
|
204
248
|
{
|
249
|
+
#ifdef GIT_EXPERIMENTAL_SHA256
|
250
|
+
if (oid_a->type != oid_b->type)
|
251
|
+
return oid_a->type - oid_b->type;
|
252
|
+
#endif
|
253
|
+
|
205
254
|
return git_oid_raw_ncmp(oid_a->id, oid_b->id, len);
|
206
255
|
}
|
207
256
|
|
@@ -209,9 +258,10 @@ int git_oid_strcmp(const git_oid *oid_a, const char *str)
|
|
209
258
|
{
|
210
259
|
const unsigned char *a;
|
211
260
|
unsigned char strval;
|
261
|
+
long size = (long)git_oid_size(git_oid_type(oid_a));
|
212
262
|
int hexval;
|
213
263
|
|
214
|
-
for (a = oid_a->id; *str && (a - oid_a->id) <
|
264
|
+
for (a = oid_a->id; *str && (a - oid_a->id) < size; ++a) {
|
215
265
|
if ((hexval = git__fromhex(*str++)) < 0)
|
216
266
|
return -1;
|
217
267
|
strval = (unsigned char)(hexval << 4);
|
@@ -235,8 +285,16 @@ int git_oid_streq(const git_oid *oid_a, const char *str)
|
|
235
285
|
int git_oid_is_zero(const git_oid *oid_a)
|
236
286
|
{
|
237
287
|
const unsigned char *a = oid_a->id;
|
238
|
-
|
239
|
-
|
288
|
+
size_t size = git_oid_size(git_oid_type(oid_a)), i;
|
289
|
+
|
290
|
+
#ifdef GIT_EXPERIMENTAL_SHA256
|
291
|
+
if (!oid_a->type)
|
292
|
+
return 1;
|
293
|
+
else if (!size)
|
294
|
+
return 0;
|
295
|
+
#endif
|
296
|
+
|
297
|
+
for (i = 0; i < size; ++i, ++a)
|
240
298
|
if (*a != 0)
|
241
299
|
return 0;
|
242
300
|
return 1;
|
@@ -393,7 +451,7 @@ int git_oid_shorten_add(git_oid_shorten *os, const char *text_oid)
|
|
393
451
|
idx = 0;
|
394
452
|
is_leaf = false;
|
395
453
|
|
396
|
-
for (i = 0; i <
|
454
|
+
for (i = 0; i < GIT_OID_SHA1_HEXSIZE; ++i) {
|
397
455
|
int c = git__fromhex(text_oid[i]);
|
398
456
|
trie_node *node;
|
399
457
|
|