rugged 1.5.1 → 1.6.2
Sign up to get free protection for your applications and to get access to all the features.
- 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
@@ -13,6 +13,7 @@
|
|
13
13
|
#include "git2/transport.h"
|
14
14
|
#include "git2/sys/remote.h"
|
15
15
|
|
16
|
+
#include "oid.h"
|
16
17
|
#include "remote.h"
|
17
18
|
#include "refspec.h"
|
18
19
|
#include "pack.h"
|
@@ -75,7 +76,7 @@ static int maybe_want_oid(git_remote *remote, git_refspec *spec)
|
|
75
76
|
oid_head = git__calloc(1, sizeof(git_remote_head));
|
76
77
|
GIT_ERROR_CHECK_ALLOC(oid_head);
|
77
78
|
|
78
|
-
|
79
|
+
git_oid__fromstr(&oid_head->oid, spec->src, GIT_OID_SHA1);
|
79
80
|
|
80
81
|
if (spec->dst) {
|
81
82
|
oid_head->name = git__strdup(spec->dst);
|
@@ -94,7 +95,6 @@ static int filter_wants(git_remote *remote, const git_fetch_options *opts)
|
|
94
95
|
git_remote_head **heads;
|
95
96
|
git_refspec tagspec, head, *spec;
|
96
97
|
int error = 0;
|
97
|
-
git_odb *odb;
|
98
98
|
size_t i, heads_len;
|
99
99
|
unsigned int remote_caps;
|
100
100
|
unsigned int oid_mask = GIT_REMOTE_CAPABILITY_TIP_OID |
|
@@ -125,9 +125,6 @@ static int filter_wants(git_remote *remote, const git_fetch_options *opts)
|
|
125
125
|
goto cleanup;
|
126
126
|
}
|
127
127
|
|
128
|
-
if ((error = git_repository_odb__weakptr(&odb, remote->repo)) < 0)
|
129
|
-
goto cleanup;
|
130
|
-
|
131
128
|
if ((error = git_remote_ls((const git_remote_head ***)&heads, &heads_len, remote)) < 0 ||
|
132
129
|
(error = git_remote_capabilities(&remote_caps, remote)) < 0)
|
133
130
|
goto cleanup;
|
@@ -140,7 +137,7 @@ static int filter_wants(git_remote *remote, const git_fetch_options *opts)
|
|
140
137
|
|
141
138
|
/* Handle explicitly specified OID specs */
|
142
139
|
git_vector_foreach(&remote->active_refspecs, i, spec) {
|
143
|
-
if (!git_oid__is_hexstr(spec->src))
|
140
|
+
if (!git_oid__is_hexstr(spec->src, GIT_OID_SHA1))
|
144
141
|
continue;
|
145
142
|
|
146
143
|
if (!(remote_caps & oid_mask)) {
|
@@ -105,7 +105,7 @@ static int fetchhead_ref_write(
|
|
105
105
|
git_filebuf *file,
|
106
106
|
git_fetchhead_ref *fetchhead_ref)
|
107
107
|
{
|
108
|
-
char oid[
|
108
|
+
char oid[GIT_OID_SHA1_HEXSIZE + 1];
|
109
109
|
const char *type, *name;
|
110
110
|
int head = 0;
|
111
111
|
|
@@ -113,7 +113,7 @@ static int fetchhead_ref_write(
|
|
113
113
|
GIT_ASSERT_ARG(fetchhead_ref);
|
114
114
|
|
115
115
|
git_oid_fmt(oid, &fetchhead_ref->oid);
|
116
|
-
oid[
|
116
|
+
oid[GIT_OID_SHA1_HEXSIZE] = '\0';
|
117
117
|
|
118
118
|
if (git__prefixcmp(fetchhead_ref->ref_name, GIT_REFS_HEADS_DIR) == 0) {
|
119
119
|
type = "branch ";
|
@@ -196,13 +196,13 @@ static int fetchhead_ref_parse(
|
|
196
196
|
*is_merge = 1;
|
197
197
|
}
|
198
198
|
|
199
|
-
if (strlen(oid_str) !=
|
199
|
+
if (strlen(oid_str) != GIT_OID_SHA1_HEXSIZE) {
|
200
200
|
git_error_set(GIT_ERROR_FETCHHEAD,
|
201
201
|
"invalid object ID in FETCH_HEAD line %"PRIuZ, line_num);
|
202
202
|
return -1;
|
203
203
|
}
|
204
204
|
|
205
|
-
if (
|
205
|
+
if (git_oid__fromstr(oid, oid_str, GIT_OID_SHA1) < 0) {
|
206
206
|
const git_error *oid_err = git_error_last();
|
207
207
|
const char *err_msg = oid_err ? oid_err->message : "invalid object ID";
|
208
208
|
|
@@ -42,7 +42,7 @@ static int ident_find_id(
|
|
42
42
|
static int ident_insert_id(
|
43
43
|
git_str *to, const git_str *from, const git_filter_source *src)
|
44
44
|
{
|
45
|
-
char oid[
|
45
|
+
char oid[GIT_OID_SHA1_HEXSIZE+1];
|
46
46
|
const char *id_start, *id_end, *from_end = from->ptr + from->size;
|
47
47
|
size_t need_size;
|
48
48
|
|
@@ -57,7 +57,7 @@ static int ident_insert_id(
|
|
57
57
|
return GIT_PASSTHROUGH;
|
58
58
|
|
59
59
|
need_size = (size_t)(id_start - from->ptr) +
|
60
|
-
5 /* "$Id: " */ +
|
60
|
+
5 /* "$Id: " */ + GIT_OID_SHA1_HEXSIZE + 2 /* " $" */ +
|
61
61
|
(size_t)(from_end - id_end);
|
62
62
|
|
63
63
|
if (git_str_grow(to, need_size) < 0)
|
@@ -65,7 +65,7 @@ static int ident_insert_id(
|
|
65
65
|
|
66
66
|
git_str_set(to, from->ptr, (size_t)(id_start - from->ptr));
|
67
67
|
git_str_put(to, "$Id: ", 5);
|
68
|
-
git_str_put(to, oid,
|
68
|
+
git_str_put(to, oid, GIT_OID_SHA1_HEXSIZE);
|
69
69
|
git_str_put(to, " $", 2);
|
70
70
|
git_str_put(to, id_end, (size_t)(from_end - id_end));
|
71
71
|
|
@@ -74,7 +74,7 @@ struct entry_short {
|
|
74
74
|
uint32_t uid;
|
75
75
|
uint32_t gid;
|
76
76
|
uint32_t file_size;
|
77
|
-
unsigned char oid[
|
77
|
+
unsigned char oid[GIT_OID_SHA1_SIZE];
|
78
78
|
uint16_t flags;
|
79
79
|
char path[1]; /* arbitrary length */
|
80
80
|
};
|
@@ -88,7 +88,7 @@ struct entry_long {
|
|
88
88
|
uint32_t uid;
|
89
89
|
uint32_t gid;
|
90
90
|
uint32_t file_size;
|
91
|
-
unsigned char oid[
|
91
|
+
unsigned char oid[GIT_OID_SHA1_SIZE];
|
92
92
|
uint16_t flags;
|
93
93
|
uint16_t flags_extended;
|
94
94
|
char path[1]; /* arbitrary length */
|
@@ -2354,14 +2354,16 @@ static int read_reuc(git_index *index, const char *buffer, size_t size)
|
|
2354
2354
|
for (i = 0; i < 3; i++) {
|
2355
2355
|
if (!lost->mode[i])
|
2356
2356
|
continue;
|
2357
|
-
if (size <
|
2357
|
+
if (size < GIT_OID_SHA1_SIZE) {
|
2358
2358
|
index_entry_reuc_free(lost);
|
2359
2359
|
return index_error_invalid("reading reuc entry oid");
|
2360
2360
|
}
|
2361
2361
|
|
2362
|
-
|
2363
|
-
|
2364
|
-
|
2362
|
+
if (git_oid__fromraw(&lost->oid[i], (const unsigned char *) buffer, GIT_OID_SHA1) < 0)
|
2363
|
+
return -1;
|
2364
|
+
|
2365
|
+
size -= GIT_OID_SHA1_SIZE;
|
2366
|
+
buffer += GIT_OID_SHA1_SIZE;
|
2365
2367
|
}
|
2366
2368
|
|
2367
2369
|
/* entry was read successfully - insert into reuc vector */
|
@@ -2482,7 +2484,7 @@ static int read_entry(
|
|
2482
2484
|
entry.file_size = ntohl(source.file_size);
|
2483
2485
|
entry.flags = ntohs(source.flags);
|
2484
2486
|
|
2485
|
-
if (
|
2487
|
+
if (git_oid__fromraw(&entry.id, source.oid, GIT_OID_SHA1) < 0)
|
2486
2488
|
return -1;
|
2487
2489
|
|
2488
2490
|
if (entry.flags & GIT_INDEX_ENTRY_EXTENDED) {
|
@@ -2805,7 +2807,7 @@ static int write_disk_entry(git_filebuf *file, git_index_entry *entry, const cha
|
|
2805
2807
|
ondisk.uid = htonl(entry->uid);
|
2806
2808
|
ondisk.gid = htonl(entry->gid);
|
2807
2809
|
ondisk.file_size = htonl((uint32_t)entry->file_size);
|
2808
|
-
git_oid_raw_cpy(ondisk.oid, entry->id.id);
|
2810
|
+
git_oid_raw_cpy(ondisk.oid, entry->id.id, GIT_OID_SHA1_SIZE);
|
2809
2811
|
ondisk.flags = htons(entry->flags);
|
2810
2812
|
|
2811
2813
|
if (entry->flags & GIT_INDEX_ENTRY_EXTENDED) {
|
@@ -2968,7 +2970,7 @@ static int create_reuc_extension_data(git_str *reuc_buf, git_index_reuc_entry *r
|
|
2968
2970
|
}
|
2969
2971
|
|
2970
2972
|
for (i = 0; i < 3; i++) {
|
2971
|
-
if (reuc->mode[i] && (error = git_str_put(reuc_buf, (char *)&reuc->oid[i].id,
|
2973
|
+
if (reuc->mode[i] && (error = git_str_put(reuc_buf, (char *)&reuc->oid[i].id, GIT_OID_SHA1_SIZE)) < 0)
|
2972
2974
|
return error;
|
2973
2975
|
}
|
2974
2976
|
|
@@ -42,6 +42,7 @@ struct git_indexer {
|
|
42
42
|
have_delta :1,
|
43
43
|
do_fsync :1,
|
44
44
|
do_verify :1;
|
45
|
+
git_oid_t oid_type;
|
45
46
|
struct git_pack_header hdr;
|
46
47
|
struct git_pack_file *pack;
|
47
48
|
unsigned int mode;
|
@@ -55,8 +56,8 @@ struct git_indexer {
|
|
55
56
|
git_vector deltas;
|
56
57
|
unsigned int fanout[256];
|
57
58
|
git_hash_ctx hash_ctx;
|
58
|
-
unsigned char checksum[
|
59
|
-
char name[(
|
59
|
+
unsigned char checksum[GIT_HASH_MAX_SIZE];
|
60
|
+
char name[(GIT_HASH_MAX_SIZE * 2) + 1];
|
60
61
|
git_indexer_progress_cb progress_cb;
|
61
62
|
void *progress_payload;
|
62
63
|
char objbuf[8*1024];
|
@@ -68,7 +69,7 @@ struct git_indexer {
|
|
68
69
|
git_odb *odb;
|
69
70
|
|
70
71
|
/* Fields for calculating the packfile trailer (hash of everything before it) */
|
71
|
-
char inbuf[
|
72
|
+
char inbuf[GIT_HASH_MAX_SIZE];
|
72
73
|
size_t inbuf_len;
|
73
74
|
git_hash_ctx trailer;
|
74
75
|
};
|
@@ -136,17 +137,33 @@ int git_indexer_init_options(git_indexer_options *opts, unsigned int version)
|
|
136
137
|
}
|
137
138
|
#endif
|
138
139
|
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
140
|
+
GIT_INLINE(git_hash_algorithm_t) indexer_hash_algorithm(git_indexer *idx)
|
141
|
+
{
|
142
|
+
switch (idx->oid_type) {
|
143
|
+
case GIT_OID_SHA1:
|
144
|
+
return GIT_HASH_ALGORITHM_SHA1;
|
145
|
+
#ifdef GIT_EXPERIMENTAL_SHA256
|
146
|
+
case GIT_OID_SHA256:
|
147
|
+
return GIT_HASH_ALGORITHM_SHA256;
|
148
|
+
#endif
|
149
|
+
}
|
150
|
+
|
151
|
+
return GIT_HASH_ALGORITHM_NONE;
|
152
|
+
}
|
153
|
+
|
154
|
+
static int indexer_new(
|
155
|
+
git_indexer **out,
|
156
|
+
const char *prefix,
|
157
|
+
git_oid_t oid_type,
|
158
|
+
unsigned int mode,
|
159
|
+
git_odb *odb,
|
160
|
+
git_indexer_options *in_opts)
|
145
161
|
{
|
146
162
|
git_indexer_options opts = GIT_INDEXER_OPTIONS_INIT;
|
147
163
|
git_indexer *idx;
|
148
164
|
git_str path = GIT_STR_INIT, tmp_path = GIT_STR_INIT;
|
149
165
|
static const char suff[] = "/pack";
|
166
|
+
git_hash_algorithm_t checksum_type;
|
150
167
|
int error, fd = -1;
|
151
168
|
|
152
169
|
if (in_opts)
|
@@ -154,14 +171,17 @@ int git_indexer_new(
|
|
154
171
|
|
155
172
|
idx = git__calloc(1, sizeof(git_indexer));
|
156
173
|
GIT_ERROR_CHECK_ALLOC(idx);
|
174
|
+
idx->oid_type = oid_type;
|
157
175
|
idx->odb = odb;
|
158
176
|
idx->progress_cb = opts.progress_cb;
|
159
177
|
idx->progress_payload = opts.progress_cb_payload;
|
160
178
|
idx->mode = mode ? mode : GIT_PACK_FILE_MODE;
|
161
179
|
git_str_init(&idx->entry_data, 0);
|
162
180
|
|
163
|
-
|
164
|
-
|
181
|
+
checksum_type = indexer_hash_algorithm(idx);
|
182
|
+
|
183
|
+
if ((error = git_hash_ctx_init(&idx->hash_ctx, checksum_type)) < 0 ||
|
184
|
+
(error = git_hash_ctx_init(&idx->trailer, checksum_type)) < 0 ||
|
165
185
|
(error = git_oidmap_new(&idx->expected_oids)) < 0)
|
166
186
|
goto cleanup;
|
167
187
|
|
@@ -179,7 +199,7 @@ int git_indexer_new(
|
|
179
199
|
if (fd < 0)
|
180
200
|
goto cleanup;
|
181
201
|
|
182
|
-
error = git_packfile_alloc(&idx->pack, git_str_cstr(&tmp_path));
|
202
|
+
error = git_packfile_alloc(&idx->pack, git_str_cstr(&tmp_path), oid_type);
|
183
203
|
git_str_dispose(&tmp_path);
|
184
204
|
|
185
205
|
if (error < 0)
|
@@ -208,6 +228,33 @@ cleanup:
|
|
208
228
|
return -1;
|
209
229
|
}
|
210
230
|
|
231
|
+
#ifdef GIT_EXPERIMENTAL_SHA256
|
232
|
+
int git_indexer_new(
|
233
|
+
git_indexer **out,
|
234
|
+
const char *prefix,
|
235
|
+
git_oid_t oid_type,
|
236
|
+
git_indexer_options *opts)
|
237
|
+
{
|
238
|
+
return indexer_new(
|
239
|
+
out,
|
240
|
+
prefix,
|
241
|
+
oid_type,
|
242
|
+
opts ? opts->mode : 0,
|
243
|
+
opts ? opts->odb : NULL,
|
244
|
+
opts);
|
245
|
+
}
|
246
|
+
#else
|
247
|
+
int git_indexer_new(
|
248
|
+
git_indexer **out,
|
249
|
+
const char *prefix,
|
250
|
+
unsigned int mode,
|
251
|
+
git_odb *odb,
|
252
|
+
git_indexer_options *opts)
|
253
|
+
{
|
254
|
+
return indexer_new(out, prefix, GIT_OID_SHA1, mode, odb, opts);
|
255
|
+
}
|
256
|
+
#endif
|
257
|
+
|
211
258
|
void git_indexer__set_fsync(git_indexer *idx, int do_fsync)
|
212
259
|
{
|
213
260
|
idx->do_fsync = !!do_fsync;
|
@@ -272,7 +319,7 @@ static int advance_delta_offset(git_indexer *idx, git_object_t type)
|
|
272
319
|
GIT_ASSERT_ARG(type == GIT_OBJECT_REF_DELTA || type == GIT_OBJECT_OFS_DELTA);
|
273
320
|
|
274
321
|
if (type == GIT_OBJECT_REF_DELTA) {
|
275
|
-
idx->off +=
|
322
|
+
idx->off += git_oid_size(idx->oid_type);
|
276
323
|
} else {
|
277
324
|
off64_t base_off;
|
278
325
|
int error = get_delta_base(&base_off, idx->pack, &w, &idx->off, type, idx->entry_start);
|
@@ -356,7 +403,7 @@ static int check_object_connectivity(git_indexer *idx, const git_rawobj *obj)
|
|
356
403
|
obj->type != GIT_OBJECT_TAG)
|
357
404
|
return 0;
|
358
405
|
|
359
|
-
if (git_object__from_raw(&object, obj->data, obj->len, obj->type) < 0) {
|
406
|
+
if (git_object__from_raw(&object, obj->data, obj->len, obj->type, idx->oid_type) < 0) {
|
360
407
|
/*
|
361
408
|
* parse_raw returns EINVALID on invalid data; downgrade
|
362
409
|
* that to a normal -1 error code.
|
@@ -444,6 +491,11 @@ static int store_object(git_indexer *idx)
|
|
444
491
|
git__free(pentry);
|
445
492
|
goto on_error;
|
446
493
|
}
|
494
|
+
|
495
|
+
#ifdef GIT_EXPERIMENTAL_SHA256
|
496
|
+
oid.type = idx->oid_type;
|
497
|
+
#endif
|
498
|
+
|
447
499
|
entry_size = idx->off - entry_start;
|
448
500
|
if (entry_start > UINT31_MAX) {
|
449
501
|
entry->offset = UINT32_MAX;
|
@@ -463,16 +515,16 @@ static int store_object(git_indexer *idx)
|
|
463
515
|
goto on_error;
|
464
516
|
}
|
465
517
|
|
466
|
-
git_oid_cpy(&pentry->
|
518
|
+
git_oid_cpy(&pentry->id, &oid);
|
467
519
|
pentry->offset = entry_start;
|
468
520
|
|
469
|
-
if (git_oidmap_exists(idx->pack->idx_cache, &pentry->
|
470
|
-
git_error_set(GIT_ERROR_INDEXER, "duplicate object %s found in pack", git_oid_tostr_s(&pentry->
|
521
|
+
if (git_oidmap_exists(idx->pack->idx_cache, &pentry->id)) {
|
522
|
+
git_error_set(GIT_ERROR_INDEXER, "duplicate object %s found in pack", git_oid_tostr_s(&pentry->id));
|
471
523
|
git__free(pentry);
|
472
524
|
goto on_error;
|
473
525
|
}
|
474
526
|
|
475
|
-
if ((error = git_oidmap_set(idx->pack->idx_cache, &pentry->
|
527
|
+
if ((error = git_oidmap_set(idx->pack->idx_cache, &pentry->id, pentry)) < 0) {
|
476
528
|
git__free(pentry);
|
477
529
|
git_error_set_oom();
|
478
530
|
goto on_error;
|
@@ -517,8 +569,8 @@ static int save_entry(git_indexer *idx, struct entry *entry, struct git_pack_ent
|
|
517
569
|
|
518
570
|
pentry->offset = entry_start;
|
519
571
|
|
520
|
-
if (git_oidmap_exists(idx->pack->idx_cache, &pentry->
|
521
|
-
git_oidmap_set(idx->pack->idx_cache, &pentry->
|
572
|
+
if (git_oidmap_exists(idx->pack->idx_cache, &pentry->id) ||
|
573
|
+
git_oidmap_set(idx->pack->idx_cache, &pentry->id, pentry) < 0) {
|
522
574
|
git_error_set(GIT_ERROR_INDEXER, "cannot insert object into pack");
|
523
575
|
return -1;
|
524
576
|
}
|
@@ -544,7 +596,7 @@ static int hash_and_save(git_indexer *idx, git_rawobj *obj, off64_t entry_start)
|
|
544
596
|
entry = git__calloc(1, sizeof(*entry));
|
545
597
|
GIT_ERROR_CHECK_ALLOC(entry);
|
546
598
|
|
547
|
-
if (git_odb__hashobj(&oid, obj) < 0) {
|
599
|
+
if (git_odb__hashobj(&oid, obj, idx->oid_type) < 0) {
|
548
600
|
git_error_set(GIT_ERROR_INDEXER, "failed to hash object");
|
549
601
|
goto on_error;
|
550
602
|
}
|
@@ -552,7 +604,7 @@ static int hash_and_save(git_indexer *idx, git_rawobj *obj, off64_t entry_start)
|
|
552
604
|
pentry = git__calloc(1, sizeof(struct git_pack_entry));
|
553
605
|
GIT_ERROR_CHECK_ALLOC(pentry);
|
554
606
|
|
555
|
-
git_oid_cpy(&pentry->
|
607
|
+
git_oid_cpy(&pentry->id, &oid);
|
556
608
|
git_oid_cpy(&entry->oid, &oid);
|
557
609
|
entry->crc = crc32(0L, Z_NULL, 0);
|
558
610
|
|
@@ -578,34 +630,38 @@ static int do_progress_callback(git_indexer *idx, git_indexer_progress *stats)
|
|
578
630
|
return 0;
|
579
631
|
}
|
580
632
|
|
581
|
-
/* Hash everything but the
|
633
|
+
/* Hash everything but the checksum trailer */
|
582
634
|
static void hash_partially(git_indexer *idx, const uint8_t *data, size_t size)
|
583
635
|
{
|
584
636
|
size_t to_expell, to_keep;
|
637
|
+
size_t oid_size = git_oid_size(idx->oid_type);
|
585
638
|
|
586
639
|
if (size == 0)
|
587
640
|
return;
|
588
641
|
|
589
|
-
/*
|
590
|
-
|
642
|
+
/*
|
643
|
+
* Easy case, dump the buffer and the data minus the trailing
|
644
|
+
* checksum (SHA1 or SHA256).
|
645
|
+
*/
|
646
|
+
if (size >= oid_size) {
|
591
647
|
git_hash_update(&idx->trailer, idx->inbuf, idx->inbuf_len);
|
592
|
-
git_hash_update(&idx->trailer, data, size -
|
648
|
+
git_hash_update(&idx->trailer, data, size - oid_size);
|
593
649
|
|
594
|
-
data += size -
|
595
|
-
memcpy(idx->inbuf, data,
|
596
|
-
idx->inbuf_len =
|
650
|
+
data += size - oid_size;
|
651
|
+
memcpy(idx->inbuf, data, oid_size);
|
652
|
+
idx->inbuf_len = oid_size;
|
597
653
|
return;
|
598
654
|
}
|
599
655
|
|
600
656
|
/* We can just append */
|
601
|
-
if (idx->inbuf_len + size <=
|
657
|
+
if (idx->inbuf_len + size <= oid_size) {
|
602
658
|
memcpy(idx->inbuf + idx->inbuf_len, data, size);
|
603
659
|
idx->inbuf_len += size;
|
604
660
|
return;
|
605
661
|
}
|
606
662
|
|
607
663
|
/* We need to partially drain the buffer and then append */
|
608
|
-
to_keep =
|
664
|
+
to_keep = oid_size - size;
|
609
665
|
to_expell = idx->inbuf_len - to_keep;
|
610
666
|
|
611
667
|
git_hash_update(&idx->trailer, idx->inbuf, to_expell);
|
@@ -724,12 +780,14 @@ static int read_stream_object(git_indexer *idx, git_indexer_progress *stats)
|
|
724
780
|
{
|
725
781
|
git_packfile_stream *stream = &idx->stream;
|
726
782
|
off64_t entry_start = idx->off;
|
727
|
-
size_t entry_size;
|
783
|
+
size_t oid_size, entry_size;
|
728
784
|
git_object_t type;
|
729
785
|
git_mwindow *w = NULL;
|
730
786
|
int error;
|
731
787
|
|
732
|
-
|
788
|
+
oid_size = git_oid_size(idx->oid_type);
|
789
|
+
|
790
|
+
if (idx->pack->mwf.size <= idx->off + (long long)oid_size)
|
733
791
|
return GIT_EBUFS;
|
734
792
|
|
735
793
|
if (!idx->have_stream) {
|
@@ -900,7 +958,7 @@ static int index_path(git_str *path, git_indexer *idx, const char *suffix)
|
|
900
958
|
slash--;
|
901
959
|
|
902
960
|
if (git_str_grow(path, slash + 1 + strlen(prefix) +
|
903
|
-
|
961
|
+
git_oid_hexsize(idx->oid_type) + strlen(suffix) + 1) < 0)
|
904
962
|
return -1;
|
905
963
|
|
906
964
|
git_str_truncate(path, slash);
|
@@ -917,7 +975,7 @@ static int index_path(git_str *path, git_indexer *idx, const char *suffix)
|
|
917
975
|
*/
|
918
976
|
static int seek_back_trailer(git_indexer *idx)
|
919
977
|
{
|
920
|
-
idx->pack->mwf.size -=
|
978
|
+
idx->pack->mwf.size -= git_oid_size(idx->oid_type);
|
921
979
|
return git_mwindow_free_all(&idx->pack->mwf);
|
922
980
|
}
|
923
981
|
|
@@ -926,15 +984,17 @@ static int inject_object(git_indexer *idx, git_oid *id)
|
|
926
984
|
git_odb_object *obj = NULL;
|
927
985
|
struct entry *entry = NULL;
|
928
986
|
struct git_pack_entry *pentry = NULL;
|
929
|
-
unsigned char empty_checksum[
|
987
|
+
unsigned char empty_checksum[GIT_HASH_MAX_SIZE] = {0};
|
930
988
|
unsigned char hdr[64];
|
931
989
|
git_str buf = GIT_STR_INIT;
|
932
990
|
off64_t entry_start;
|
933
991
|
const void *data;
|
934
992
|
size_t len, hdr_len;
|
935
|
-
size_t checksum_size
|
993
|
+
size_t checksum_size;
|
936
994
|
int error;
|
937
995
|
|
996
|
+
checksum_size = git_hash_size(indexer_hash_algorithm(idx));
|
997
|
+
|
938
998
|
if ((error = seek_back_trailer(idx)) < 0)
|
939
999
|
goto cleanup;
|
940
1000
|
|
@@ -977,12 +1037,12 @@ static int inject_object(git_indexer *idx, git_oid *id)
|
|
977
1037
|
if ((error = append_to_pack(idx, empty_checksum, checksum_size)) < 0)
|
978
1038
|
goto cleanup;
|
979
1039
|
|
980
|
-
idx->pack->mwf.size +=
|
1040
|
+
idx->pack->mwf.size += git_oid_size(idx->oid_type);
|
981
1041
|
|
982
1042
|
pentry = git__calloc(1, sizeof(struct git_pack_entry));
|
983
1043
|
GIT_ERROR_CHECK_ALLOC(pentry);
|
984
1044
|
|
985
|
-
git_oid_cpy(&pentry->
|
1045
|
+
git_oid_cpy(&pentry->id, id);
|
986
1046
|
git_oid_cpy(&entry->oid, id);
|
987
1047
|
idx->off = entry_start + hdr_len + len;
|
988
1048
|
|
@@ -1040,13 +1100,13 @@ static int fix_thin_pack(git_indexer *idx, git_indexer_progress *stats)
|
|
1040
1100
|
}
|
1041
1101
|
|
1042
1102
|
/* curpos now points to the base information, which is an OID */
|
1043
|
-
base_info = git_mwindow_open(&idx->pack->mwf, &w, curpos,
|
1103
|
+
base_info = git_mwindow_open(&idx->pack->mwf, &w, curpos, git_oid_size(idx->oid_type), &left);
|
1044
1104
|
if (base_info == NULL) {
|
1045
1105
|
git_error_set(GIT_ERROR_INDEXER, "failed to map delta information");
|
1046
1106
|
return -1;
|
1047
1107
|
}
|
1048
1108
|
|
1049
|
-
|
1109
|
+
git_oid__fromraw(&base, base_info, idx->oid_type);
|
1050
1110
|
git_mwindow_close(&w);
|
1051
1111
|
|
1052
1112
|
if (has_entry(idx, &base))
|
@@ -1168,10 +1228,10 @@ int git_indexer_commit(git_indexer *idx, git_indexer_progress *stats)
|
|
1168
1228
|
struct git_pack_idx_header hdr;
|
1169
1229
|
git_str filename = GIT_STR_INIT;
|
1170
1230
|
struct entry *entry;
|
1171
|
-
unsigned char checksum[
|
1231
|
+
unsigned char checksum[GIT_HASH_MAX_SIZE];
|
1172
1232
|
git_filebuf index_file = {0};
|
1173
1233
|
void *packfile_trailer;
|
1174
|
-
size_t checksum_size
|
1234
|
+
size_t checksum_size;
|
1175
1235
|
bool mismatch;
|
1176
1236
|
|
1177
1237
|
if (!idx->parsed_header) {
|
@@ -1179,6 +1239,9 @@ int git_indexer_commit(git_indexer *idx, git_indexer_progress *stats)
|
|
1179
1239
|
return -1;
|
1180
1240
|
}
|
1181
1241
|
|
1242
|
+
checksum_size = git_hash_size(indexer_hash_algorithm(idx));
|
1243
|
+
GIT_ASSERT(checksum_size);
|
1244
|
+
|
1182
1245
|
/* Test for this before resolve_deltas(), as it plays with idx->off */
|
1183
1246
|
if (idx->off + (ssize_t)checksum_size < idx->pack->mwf.size) {
|
1184
1247
|
git_error_set(GIT_ERROR_INDEXER, "unexpected data at the end of the pack");
|
@@ -1269,7 +1332,7 @@ int git_indexer_commit(git_indexer *idx, git_indexer_progress *stats)
|
|
1269
1332
|
|
1270
1333
|
/* Write out the object names (SHA-1 hashes) */
|
1271
1334
|
git_vector_foreach(&idx->objects, i, entry) {
|
1272
|
-
git_filebuf_write(&index_file, &entry->oid.id,
|
1335
|
+
git_filebuf_write(&index_file, &entry->oid.id, git_oid_size(idx->oid_type));
|
1273
1336
|
}
|
1274
1337
|
|
1275
1338
|
/* Write out the CRC32 values */
|
@@ -1271,7 +1271,7 @@ static int filesystem_iterator_entry_hash(
|
|
1271
1271
|
int error;
|
1272
1272
|
|
1273
1273
|
if (S_ISDIR(entry->st.st_mode)) {
|
1274
|
-
memset(&entry->id, 0,
|
1274
|
+
memset(&entry->id, 0, GIT_OID_SHA1_SIZE);
|
1275
1275
|
return 0;
|
1276
1276
|
}
|
1277
1277
|
|
@@ -1281,7 +1281,7 @@ static int filesystem_iterator_entry_hash(
|
|
1281
1281
|
|
1282
1282
|
if (!(error = git_str_joinpath(&fullpath, iter->root, entry->path)) &&
|
1283
1283
|
!(error = git_path_validate_str_length(iter->base.repo, &fullpath)))
|
1284
|
-
error =
|
1284
|
+
error = git_odb__hashfile(&entry->id, fullpath.ptr, GIT_OBJECT_BLOB, GIT_OID_SHA1);
|
1285
1285
|
|
1286
1286
|
git_str_dispose(&fullpath);
|
1287
1287
|
return error;
|
@@ -1529,6 +1529,8 @@ static void filesystem_iterator_set_current(
|
|
1529
1529
|
|
1530
1530
|
if (iter->base.flags & GIT_ITERATOR_INCLUDE_HASH)
|
1531
1531
|
git_oid_cpy(&iter->entry.id, &entry->id);
|
1532
|
+
else
|
1533
|
+
git_oid_clear(&iter->entry.id, GIT_OID_SHA1);
|
1532
1534
|
|
1533
1535
|
iter->entry.path = entry->path;
|
1534
1536
|
|
@@ -414,6 +414,25 @@ int git_libgit2_opts(int key, ...)
|
|
414
414
|
git_repository__validate_ownership = (va_arg(ap, int) != 0);
|
415
415
|
break;
|
416
416
|
|
417
|
+
case GIT_OPT_GET_HOMEDIR:
|
418
|
+
{
|
419
|
+
git_buf *out = va_arg(ap, git_buf *);
|
420
|
+
git_str str = GIT_STR_INIT;
|
421
|
+
const git_str *tmp;
|
422
|
+
|
423
|
+
if ((error = git_buf_tostr(&str, out)) < 0 ||
|
424
|
+
(error = git_sysdir_get(&tmp, GIT_SYSDIR_HOME)) < 0 ||
|
425
|
+
(error = git_str_put(&str, tmp->ptr, tmp->size)) < 0)
|
426
|
+
break;
|
427
|
+
|
428
|
+
error = git_buf_fromstr(out, &str);
|
429
|
+
}
|
430
|
+
break;
|
431
|
+
|
432
|
+
case GIT_OPT_SET_HOMEDIR:
|
433
|
+
error = git_sysdir_set(GIT_SYSDIR_HOME, va_arg(ap, const char *));
|
434
|
+
break;
|
435
|
+
|
417
436
|
default:
|
418
437
|
git_error_set(GIT_ERROR_INVALID, "invalid option key");
|
419
438
|
error = -1;
|
@@ -611,13 +611,13 @@ int git_repository_mergehead_foreach(
|
|
611
611
|
buffer = merge_head_file.ptr;
|
612
612
|
|
613
613
|
while ((line = git__strsep(&buffer, "\n")) != NULL) {
|
614
|
-
if (strlen(line) !=
|
614
|
+
if (strlen(line) != GIT_OID_SHA1_HEXSIZE) {
|
615
615
|
git_error_set(GIT_ERROR_INVALID, "unable to parse OID - invalid length");
|
616
616
|
error = -1;
|
617
617
|
goto cleanup;
|
618
618
|
}
|
619
619
|
|
620
|
-
if ((error =
|
620
|
+
if ((error = git_oid__fromstr(&oid, line, GIT_OID_SHA1)) < 0)
|
621
621
|
goto cleanup;
|
622
622
|
|
623
623
|
if ((error = cb(&oid, payload)) != 0) {
|
@@ -1061,7 +1061,7 @@ static int index_entry_similarity_calc(
|
|
1061
1061
|
const git_merge_options *opts)
|
1062
1062
|
{
|
1063
1063
|
git_blob *blob;
|
1064
|
-
git_diff_file diff_file = {
|
1064
|
+
git_diff_file diff_file = { GIT_OID_SHA1_ZERO };
|
1065
1065
|
git_object_size_t blobsize;
|
1066
1066
|
int error;
|
1067
1067
|
|