rugged 1.6.5 → 1.7.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ext/rugged/rugged_allocator.c +0 -54
- data/lib/rugged/version.rb +1 -1
- data/vendor/libgit2/CMakeLists.txt +3 -8
- data/vendor/libgit2/cmake/CheckPrototypeDefinitionSafe.cmake +16 -0
- data/vendor/libgit2/cmake/SelectGSSAPI.cmake +3 -3
- data/vendor/libgit2/cmake/SelectHTTPSBackend.cmake +21 -2
- data/vendor/libgit2/cmake/SelectHashes.cmake +4 -0
- data/vendor/libgit2/cmake/SelectXdiff.cmake +9 -0
- data/vendor/libgit2/deps/pcre/LICENCE +5 -5
- data/vendor/libgit2/deps/pcre/pcre.h +2 -2
- data/vendor/libgit2/deps/pcre/pcre_compile.c +6 -3
- data/vendor/libgit2/deps/pcre/pcre_exec.c +2 -2
- data/vendor/libgit2/deps/xdiff/CMakeLists.txt +28 -0
- data/vendor/libgit2/{src/libgit2 → deps}/xdiff/git-xdiff.h +4 -1
- data/vendor/libgit2/{src/libgit2 → deps}/xdiff/xdiffi.c +19 -18
- data/vendor/libgit2/{src/libgit2 → deps}/xdiff/xdiffi.h +2 -4
- data/vendor/libgit2/{src/libgit2 → deps}/xdiff/xemit.c +3 -3
- data/vendor/libgit2/{src/libgit2 → deps}/xdiff/xhistogram.c +7 -18
- data/vendor/libgit2/{src/libgit2 → deps}/xdiff/xmacros.h +18 -1
- data/vendor/libgit2/{src/libgit2 → deps}/xdiff/xmerge.c +24 -22
- data/vendor/libgit2/{src/libgit2 → deps}/xdiff/xpatience.c +21 -30
- data/vendor/libgit2/{src/libgit2 → deps}/xdiff/xprepare.c +13 -30
- data/vendor/libgit2/{src/libgit2 → deps}/xdiff/xutils.c +18 -1
- data/vendor/libgit2/{src/libgit2 → deps}/xdiff/xutils.h +2 -1
- data/vendor/libgit2/include/git2/common.h +26 -1
- data/vendor/libgit2/include/git2/diff.h +41 -3
- data/vendor/libgit2/include/git2/errors.h +4 -2
- data/vendor/libgit2/include/git2/index.h +9 -0
- data/vendor/libgit2/include/git2/oid.h +1 -1
- data/vendor/libgit2/include/git2/remote.h +18 -0
- data/vendor/libgit2/include/git2/repository.h +12 -2
- data/vendor/libgit2/include/git2/sys/alloc.h +0 -34
- data/vendor/libgit2/include/git2/sys/commit_graph.h +12 -2
- data/vendor/libgit2/include/git2/sys/midx.h +5 -1
- data/vendor/libgit2/include/git2/sys/stream.h +16 -2
- data/vendor/libgit2/include/git2/sys/transport.h +20 -2
- data/vendor/libgit2/include/git2/version.h +4 -4
- data/vendor/libgit2/include/git2/worktree.h +3 -1
- data/vendor/libgit2/src/CMakeLists.txt +34 -11
- data/vendor/libgit2/src/cli/cmd_clone.c +22 -6
- data/vendor/libgit2/src/cli/progress.c +9 -8
- data/vendor/libgit2/src/cli/progress.h +4 -4
- data/vendor/libgit2/src/libgit2/CMakeLists.txt +1 -19
- data/vendor/libgit2/src/libgit2/annotated_commit.c +2 -2
- data/vendor/libgit2/src/libgit2/annotated_commit.h +1 -1
- data/vendor/libgit2/src/libgit2/apply.c +4 -3
- data/vendor/libgit2/src/libgit2/blame.c +23 -16
- data/vendor/libgit2/src/libgit2/blame_git.c +0 -1
- 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 +3 -1
- data/vendor/libgit2/src/libgit2/commit.c +31 -9
- data/vendor/libgit2/src/libgit2/commit_graph.c +110 -43
- data/vendor/libgit2/src/libgit2/commit_graph.h +20 -4
- data/vendor/libgit2/src/libgit2/commit_list.c +12 -5
- data/vendor/libgit2/src/libgit2/commit_list.h +1 -0
- data/vendor/libgit2/src/libgit2/config_file.c +14 -8
- data/vendor/libgit2/src/libgit2/describe.c +10 -7
- data/vendor/libgit2/src/libgit2/diff.c +16 -7
- data/vendor/libgit2/src/libgit2/diff.h +6 -6
- data/vendor/libgit2/src/libgit2/diff_file.c +7 -7
- data/vendor/libgit2/src/libgit2/diff_generate.c +36 -15
- data/vendor/libgit2/src/libgit2/diff_parse.c +20 -4
- data/vendor/libgit2/src/libgit2/diff_print.c +26 -7
- data/vendor/libgit2/src/libgit2/diff_tform.c +4 -4
- data/vendor/libgit2/src/libgit2/diff_xdiff.h +1 -1
- data/vendor/libgit2/src/libgit2/email.c +4 -3
- data/vendor/libgit2/src/libgit2/errors.c +73 -18
- data/vendor/libgit2/src/libgit2/fetch.c +37 -9
- data/vendor/libgit2/src/libgit2/fetch.h +0 -2
- data/vendor/libgit2/src/libgit2/fetchhead.c +11 -9
- data/vendor/libgit2/src/libgit2/grafts.c +272 -0
- data/vendor/libgit2/src/libgit2/grafts.h +36 -0
- data/vendor/libgit2/src/libgit2/ident.c +3 -3
- data/vendor/libgit2/src/libgit2/index.c +325 -125
- data/vendor/libgit2/src/libgit2/index.h +14 -1
- data/vendor/libgit2/src/libgit2/indexer.c +10 -3
- data/vendor/libgit2/src/libgit2/iterator.c +20 -5
- data/vendor/libgit2/src/libgit2/iterator.h +3 -0
- data/vendor/libgit2/src/libgit2/libgit2.c +39 -0
- data/vendor/libgit2/src/libgit2/merge.c +14 -9
- data/vendor/libgit2/src/libgit2/merge_file.c +0 -2
- data/vendor/libgit2/src/libgit2/midx.c +66 -37
- data/vendor/libgit2/src/libgit2/midx.h +13 -3
- data/vendor/libgit2/src/libgit2/notes.c +9 -8
- data/vendor/libgit2/src/libgit2/object.c +40 -15
- data/vendor/libgit2/src/libgit2/object.h +6 -0
- data/vendor/libgit2/src/libgit2/odb.c +11 -5
- data/vendor/libgit2/src/libgit2/odb_pack.c +16 -3
- data/vendor/libgit2/src/libgit2/oid.c +7 -1
- data/vendor/libgit2/src/libgit2/oidarray.c +49 -3
- data/vendor/libgit2/src/libgit2/oidarray.h +5 -1
- data/vendor/libgit2/src/libgit2/pack-objects.c +19 -12
- data/vendor/libgit2/src/libgit2/pack-objects.h +5 -2
- data/vendor/libgit2/src/libgit2/pack.c +3 -3
- data/vendor/libgit2/src/libgit2/parse.c +7 -4
- data/vendor/libgit2/src/libgit2/parse.h +1 -1
- data/vendor/libgit2/src/libgit2/patch.h +7 -1
- data/vendor/libgit2/src/libgit2/patch_generate.c +24 -5
- data/vendor/libgit2/src/libgit2/patch_parse.c +16 -8
- data/vendor/libgit2/src/libgit2/push.c +2 -2
- data/vendor/libgit2/src/libgit2/reader.c +1 -1
- data/vendor/libgit2/src/libgit2/rebase.c +72 -84
- data/vendor/libgit2/src/libgit2/refdb_fs.c +22 -13
- data/vendor/libgit2/src/libgit2/refs.c +8 -1
- data/vendor/libgit2/src/libgit2/remote.c +15 -6
- data/vendor/libgit2/src/libgit2/remote.h +1 -0
- data/vendor/libgit2/src/libgit2/repository.c +580 -301
- data/vendor/libgit2/src/libgit2/repository.h +17 -2
- data/vendor/libgit2/src/libgit2/reset.c +2 -2
- data/vendor/libgit2/src/libgit2/revert.c +8 -11
- data/vendor/libgit2/src/libgit2/revparse.c +1 -4
- data/vendor/libgit2/src/libgit2/revwalk.c +26 -4
- data/vendor/libgit2/src/libgit2/stash.c +9 -8
- data/vendor/libgit2/src/libgit2/streams/mbedtls.c +0 -1
- data/vendor/libgit2/src/libgit2/streams/openssl.c +8 -16
- data/vendor/libgit2/src/libgit2/streams/schannel.c +715 -0
- data/vendor/libgit2/src/libgit2/streams/schannel.h +28 -0
- data/vendor/libgit2/src/libgit2/streams/socket.c +237 -51
- data/vendor/libgit2/src/libgit2/streams/socket.h +3 -1
- data/vendor/libgit2/src/libgit2/streams/stransport.c +40 -12
- data/vendor/libgit2/src/libgit2/streams/tls.c +5 -0
- data/vendor/libgit2/src/libgit2/submodule.h +3 -3
- data/vendor/libgit2/src/libgit2/threadstate.c +15 -2
- data/vendor/libgit2/src/libgit2/threadstate.h +1 -3
- data/vendor/libgit2/src/libgit2/transports/auth.h +1 -2
- data/vendor/libgit2/src/libgit2/transports/{auth_negotiate.c → auth_gssapi.c} +32 -32
- data/vendor/libgit2/src/libgit2/transports/auth_negotiate.h +1 -1
- data/vendor/libgit2/src/libgit2/transports/auth_ntlm.h +1 -1
- data/vendor/libgit2/src/libgit2/transports/{auth_ntlm.c → auth_ntlmclient.c} +12 -12
- data/vendor/libgit2/src/libgit2/transports/auth_sspi.c +341 -0
- data/vendor/libgit2/src/libgit2/transports/git.c +7 -8
- data/vendor/libgit2/src/libgit2/transports/http.c +7 -2
- data/vendor/libgit2/src/libgit2/transports/httpclient.c +5 -0
- data/vendor/libgit2/src/libgit2/transports/local.c +13 -4
- data/vendor/libgit2/src/libgit2/transports/smart.c +33 -27
- data/vendor/libgit2/src/libgit2/transports/smart.h +23 -8
- data/vendor/libgit2/src/libgit2/transports/smart_pkt.c +136 -17
- data/vendor/libgit2/src/libgit2/transports/smart_protocol.c +154 -47
- data/vendor/libgit2/src/libgit2/transports/ssh.c +3 -3
- data/vendor/libgit2/src/libgit2/transports/winhttp.c +14 -15
- data/vendor/libgit2/src/libgit2/tree-cache.c +26 -16
- data/vendor/libgit2/src/libgit2/tree-cache.h +5 -3
- data/vendor/libgit2/src/libgit2/tree.c +1 -1
- data/vendor/libgit2/src/libgit2/worktree.c +25 -10
- data/vendor/libgit2/src/util/alloc.c +65 -6
- data/vendor/libgit2/src/util/alloc.h +34 -9
- data/vendor/libgit2/src/util/allocators/failalloc.c +0 -60
- data/vendor/libgit2/src/util/allocators/failalloc.h +0 -6
- data/vendor/libgit2/src/util/allocators/stdalloc.c +2 -105
- data/vendor/libgit2/src/util/allocators/win32_leakcheck.c +0 -68
- data/vendor/libgit2/src/util/array.h +6 -1
- data/vendor/libgit2/src/util/cc-compat.h +2 -0
- data/vendor/libgit2/src/util/filebuf.c +6 -1
- data/vendor/libgit2/src/util/filebuf.h +19 -6
- data/vendor/libgit2/src/util/fs_path.c +1 -1
- data/vendor/libgit2/src/util/futils.c +8 -5
- data/vendor/libgit2/src/util/git2_features.h.in +9 -3
- data/vendor/libgit2/src/util/net.c +308 -157
- data/vendor/libgit2/src/util/net.h +25 -0
- data/vendor/libgit2/src/util/posix.c +54 -0
- data/vendor/libgit2/src/util/posix.h +22 -0
- data/vendor/libgit2/src/util/rand.c +6 -4
- data/vendor/libgit2/src/util/staticstr.h +66 -0
- data/vendor/libgit2/src/util/util.c +15 -10
- data/vendor/libgit2/src/util/util.h +24 -16
- data/vendor/libgit2/src/util/win32/error.c +1 -1
- data/vendor/libgit2/src/util/win32/path_w32.c +8 -8
- data/vendor/libgit2/src/util/win32/posix_w32.c +1 -1
- data/vendor/libgit2/src/util/win32/utf-conv.c +73 -75
- data/vendor/libgit2/src/util/win32/utf-conv.h +81 -14
- data/vendor/libgit2/src/util/win32/w32_util.c +1 -1
- metadata +29 -23
- data/vendor/libgit2/cmake/SelectWinHTTP.cmake +0 -17
- data/vendor/libgit2/src/libgit2/netops.c +0 -124
- data/vendor/libgit2/src/libgit2/netops.h +0 -68
- /data/vendor/libgit2/{src/libgit2 → deps}/xdiff/xdiff.h +0 -0
- /data/vendor/libgit2/{src/libgit2 → deps}/xdiff/xemit.h +0 -0
- /data/vendor/libgit2/{src/libgit2 → deps}/xdiff/xinclude.h +0 -0
- /data/vendor/libgit2/{src/libgit2 → deps}/xdiff/xprepare.h +0 -0
- /data/vendor/libgit2/{src/libgit2 → deps}/xdiff/xtypes.h +0 -0
@@ -17,9 +17,9 @@
|
|
17
17
|
#include "remote.h"
|
18
18
|
#include "refspec.h"
|
19
19
|
#include "pack.h"
|
20
|
-
#include "netops.h"
|
21
20
|
#include "repository.h"
|
22
21
|
#include "refs.h"
|
22
|
+
#include "transports/smart.h"
|
23
23
|
|
24
24
|
static int maybe_want(git_remote *remote, git_remote_head *head, git_refspec *tagspec, git_remote_autotag_option_t tagopt)
|
25
25
|
{
|
@@ -59,8 +59,10 @@ static int mark_local(git_remote *remote)
|
|
59
59
|
return -1;
|
60
60
|
|
61
61
|
git_vector_foreach(&remote->refs, i, head) {
|
62
|
-
/* If we have the object, mark it so we don't ask for it
|
63
|
-
|
62
|
+
/* If we have the object, mark it so we don't ask for it.
|
63
|
+
However if we are unshallowing, we need to ask for it
|
64
|
+
even though the head exists locally. */
|
65
|
+
if (remote->nego.depth != INT_MAX && git_odb_exists(odb, &head->oid))
|
64
66
|
head->local = 1;
|
65
67
|
else
|
66
68
|
remote->need_pack = 1;
|
@@ -76,7 +78,7 @@ static int maybe_want_oid(git_remote *remote, git_refspec *spec)
|
|
76
78
|
oid_head = git__calloc(1, sizeof(git_remote_head));
|
77
79
|
GIT_ERROR_CHECK_ALLOC(oid_head);
|
78
80
|
|
79
|
-
git_oid__fromstr(&oid_head->oid, spec->src,
|
81
|
+
git_oid__fromstr(&oid_head->oid, spec->src, remote->repo->oid_type);
|
80
82
|
|
81
83
|
if (spec->dst) {
|
82
84
|
oid_head->name = git__strdup(spec->dst);
|
@@ -137,7 +139,7 @@ static int filter_wants(git_remote *remote, const git_fetch_options *opts)
|
|
137
139
|
|
138
140
|
/* Handle explicitly specified OID specs */
|
139
141
|
git_vector_foreach(&remote->active_refspecs, i, spec) {
|
140
|
-
if (!git_oid__is_hexstr(spec->src,
|
142
|
+
if (!git_oid__is_hexstr(spec->src, remote->repo->oid_type))
|
141
143
|
continue;
|
142
144
|
|
143
145
|
if (!(remote_caps & oid_mask)) {
|
@@ -166,9 +168,15 @@ cleanup:
|
|
166
168
|
int git_fetch_negotiate(git_remote *remote, const git_fetch_options *opts)
|
167
169
|
{
|
168
170
|
git_transport *t = remote->transport;
|
171
|
+
int error;
|
169
172
|
|
170
173
|
remote->need_pack = 0;
|
171
174
|
|
175
|
+
if (opts) {
|
176
|
+
GIT_ASSERT_ARG(opts->depth >= 0);
|
177
|
+
remote->nego.depth = opts->depth;
|
178
|
+
}
|
179
|
+
|
172
180
|
if (filter_wants(remote, opts) < 0)
|
173
181
|
return -1;
|
174
182
|
|
@@ -180,20 +188,40 @@ int git_fetch_negotiate(git_remote *remote, const git_fetch_options *opts)
|
|
180
188
|
* Now we have everything set up so we can start tell the
|
181
189
|
* server what we want and what we have.
|
182
190
|
*/
|
183
|
-
|
191
|
+
remote->nego.refs = (const git_remote_head * const *)remote->refs.contents;
|
192
|
+
remote->nego.refs_len = remote->refs.length;
|
193
|
+
|
194
|
+
if (git_repository__shallow_roots(&remote->nego.shallow_roots,
|
195
|
+
&remote->nego.shallow_roots_len,
|
196
|
+
remote->repo) < 0)
|
197
|
+
return -1;
|
198
|
+
|
199
|
+
error = t->negotiate_fetch(t,
|
184
200
|
remote->repo,
|
185
|
-
|
186
|
-
|
201
|
+
&remote->nego);
|
202
|
+
|
203
|
+
git__free(remote->nego.shallow_roots);
|
204
|
+
|
205
|
+
return error;
|
187
206
|
}
|
188
207
|
|
189
208
|
int git_fetch_download_pack(git_remote *remote)
|
190
209
|
{
|
210
|
+
git_oidarray shallow_roots = { NULL };
|
191
211
|
git_transport *t = remote->transport;
|
212
|
+
int error;
|
192
213
|
|
193
214
|
if (!remote->need_pack)
|
194
215
|
return 0;
|
195
216
|
|
196
|
-
|
217
|
+
if ((error = t->download_pack(t, remote->repo, &remote->stats)) != 0 ||
|
218
|
+
(error = t->shallow_roots(&shallow_roots, t)) != 0)
|
219
|
+
return error;
|
220
|
+
|
221
|
+
error = git_repository__shallow_roots_write(remote->repo, &shallow_roots);
|
222
|
+
|
223
|
+
git_oidarray_dispose(&shallow_roots);
|
224
|
+
return error;
|
197
225
|
}
|
198
226
|
|
199
227
|
int git_fetch_options_init(git_fetch_options *opts, unsigned int version)
|
@@ -105,15 +105,14 @@ 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_MAX_HEXSIZE + 1];
|
109
109
|
const char *type, *name;
|
110
110
|
int head = 0;
|
111
111
|
|
112
112
|
GIT_ASSERT_ARG(file);
|
113
113
|
GIT_ASSERT_ARG(fetchhead_ref);
|
114
114
|
|
115
|
-
|
116
|
-
oid[GIT_OID_SHA1_HEXSIZE] = '\0';
|
115
|
+
git_oid_tostr(oid, GIT_OID_MAX_HEXSIZE + 1, &fetchhead_ref->oid);
|
117
116
|
|
118
117
|
if (git__prefixcmp(fetchhead_ref->ref_name, GIT_REFS_HEADS_DIR) == 0) {
|
119
118
|
type = "branch ";
|
@@ -174,7 +173,8 @@ static int fetchhead_ref_parse(
|
|
174
173
|
git_str *ref_name,
|
175
174
|
const char **remote_url,
|
176
175
|
char *line,
|
177
|
-
size_t line_num
|
176
|
+
size_t line_num,
|
177
|
+
git_oid_t oid_type)
|
178
178
|
{
|
179
179
|
char *oid_str, *is_merge_str, *desc, *name = NULL;
|
180
180
|
const char *type = NULL;
|
@@ -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_hexsize(oid_type)) {
|
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 (git_oid__fromstr(oid, oid_str,
|
205
|
+
if (git_oid__fromstr(oid, oid_str, oid_type) < 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
|
|
@@ -269,7 +269,8 @@ static int fetchhead_ref_parse(
|
|
269
269
|
return error;
|
270
270
|
}
|
271
271
|
|
272
|
-
int git_repository_fetchhead_foreach(
|
272
|
+
int git_repository_fetchhead_foreach(
|
273
|
+
git_repository *repo,
|
273
274
|
git_repository_fetchhead_foreach_cb cb,
|
274
275
|
void *payload)
|
275
276
|
{
|
@@ -296,8 +297,9 @@ int git_repository_fetchhead_foreach(git_repository *repo,
|
|
296
297
|
while ((line = git__strsep(&buffer, "\n")) != NULL) {
|
297
298
|
++line_num;
|
298
299
|
|
299
|
-
if ((error = fetchhead_ref_parse(
|
300
|
-
&
|
300
|
+
if ((error = fetchhead_ref_parse(&oid, &is_merge, &name,
|
301
|
+
&remote_url, line, line_num,
|
302
|
+
repo->oid_type)) < 0)
|
301
303
|
goto done;
|
302
304
|
|
303
305
|
if (git_str_len(&name) > 0)
|
@@ -0,0 +1,272 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (C) the libgit2 contributors. All rights reserved.
|
3
|
+
*
|
4
|
+
* This file is part of libgit2, distributed under the GNU GPL v2 with
|
5
|
+
* a Linking Exception. For full terms see the included COPYING file.
|
6
|
+
*/
|
7
|
+
|
8
|
+
#include "grafts.h"
|
9
|
+
|
10
|
+
#include "futils.h"
|
11
|
+
#include "oid.h"
|
12
|
+
#include "oidarray.h"
|
13
|
+
#include "parse.h"
|
14
|
+
|
15
|
+
struct git_grafts {
|
16
|
+
/* Map of `git_commit_graft`s */
|
17
|
+
git_oidmap *commits;
|
18
|
+
|
19
|
+
/* Type of object IDs */
|
20
|
+
git_oid_t oid_type;
|
21
|
+
|
22
|
+
/* File backing the graft. NULL if it's an in-memory graft */
|
23
|
+
char *path;
|
24
|
+
unsigned char path_checksum[GIT_HASH_SHA256_SIZE];
|
25
|
+
};
|
26
|
+
|
27
|
+
int git_grafts_new(git_grafts **out, git_oid_t oid_type)
|
28
|
+
{
|
29
|
+
git_grafts *grafts;
|
30
|
+
|
31
|
+
GIT_ASSERT_ARG(out && oid_type);
|
32
|
+
|
33
|
+
grafts = git__calloc(1, sizeof(*grafts));
|
34
|
+
GIT_ERROR_CHECK_ALLOC(grafts);
|
35
|
+
|
36
|
+
if ((git_oidmap_new(&grafts->commits)) < 0) {
|
37
|
+
git__free(grafts);
|
38
|
+
return -1;
|
39
|
+
}
|
40
|
+
|
41
|
+
grafts->oid_type = oid_type;
|
42
|
+
|
43
|
+
*out = grafts;
|
44
|
+
return 0;
|
45
|
+
}
|
46
|
+
|
47
|
+
int git_grafts_open(
|
48
|
+
git_grafts **out,
|
49
|
+
const char *path,
|
50
|
+
git_oid_t oid_type)
|
51
|
+
{
|
52
|
+
git_grafts *grafts = NULL;
|
53
|
+
int error;
|
54
|
+
|
55
|
+
GIT_ASSERT_ARG(out && path && oid_type);
|
56
|
+
|
57
|
+
if ((error = git_grafts_new(&grafts, oid_type)) < 0)
|
58
|
+
goto error;
|
59
|
+
|
60
|
+
grafts->path = git__strdup(path);
|
61
|
+
GIT_ERROR_CHECK_ALLOC(grafts->path);
|
62
|
+
|
63
|
+
if ((error = git_grafts_refresh(grafts)) < 0)
|
64
|
+
goto error;
|
65
|
+
|
66
|
+
*out = grafts;
|
67
|
+
|
68
|
+
error:
|
69
|
+
if (error < 0)
|
70
|
+
git_grafts_free(grafts);
|
71
|
+
|
72
|
+
return error;
|
73
|
+
}
|
74
|
+
|
75
|
+
int git_grafts_open_or_refresh(
|
76
|
+
git_grafts **out,
|
77
|
+
const char *path,
|
78
|
+
git_oid_t oid_type)
|
79
|
+
{
|
80
|
+
GIT_ASSERT_ARG(out && path && oid_type);
|
81
|
+
|
82
|
+
return *out ? git_grafts_refresh(*out) : git_grafts_open(out, path, oid_type);
|
83
|
+
}
|
84
|
+
|
85
|
+
void git_grafts_free(git_grafts *grafts)
|
86
|
+
{
|
87
|
+
if (!grafts)
|
88
|
+
return;
|
89
|
+
git__free(grafts->path);
|
90
|
+
git_grafts_clear(grafts);
|
91
|
+
git_oidmap_free(grafts->commits);
|
92
|
+
git__free(grafts);
|
93
|
+
}
|
94
|
+
|
95
|
+
void git_grafts_clear(git_grafts *grafts)
|
96
|
+
{
|
97
|
+
git_commit_graft *graft;
|
98
|
+
|
99
|
+
if (!grafts)
|
100
|
+
return;
|
101
|
+
|
102
|
+
git_oidmap_foreach_value(grafts->commits, graft, {
|
103
|
+
git__free(graft->parents.ptr);
|
104
|
+
git__free(graft);
|
105
|
+
});
|
106
|
+
|
107
|
+
git_oidmap_clear(grafts->commits);
|
108
|
+
}
|
109
|
+
|
110
|
+
int git_grafts_refresh(git_grafts *grafts)
|
111
|
+
{
|
112
|
+
git_str contents = GIT_STR_INIT;
|
113
|
+
int error, updated = 0;
|
114
|
+
|
115
|
+
GIT_ASSERT_ARG(grafts);
|
116
|
+
|
117
|
+
if (!grafts->path)
|
118
|
+
return 0;
|
119
|
+
|
120
|
+
if ((error = git_futils_readbuffer_updated(&contents, grafts->path,
|
121
|
+
grafts->path_checksum, &updated)) < 0) {
|
122
|
+
|
123
|
+
if (error == GIT_ENOTFOUND) {
|
124
|
+
git_grafts_clear(grafts);
|
125
|
+
error = 0;
|
126
|
+
}
|
127
|
+
|
128
|
+
goto cleanup;
|
129
|
+
}
|
130
|
+
|
131
|
+
if (!updated) {
|
132
|
+
goto cleanup;
|
133
|
+
}
|
134
|
+
|
135
|
+
if ((error = git_grafts_parse(grafts, contents.ptr, contents.size)) < 0)
|
136
|
+
goto cleanup;
|
137
|
+
|
138
|
+
cleanup:
|
139
|
+
git_str_dispose(&contents);
|
140
|
+
return error;
|
141
|
+
}
|
142
|
+
|
143
|
+
int git_grafts_parse(git_grafts *grafts, const char *buf, size_t len)
|
144
|
+
{
|
145
|
+
git_array_oid_t parents = GIT_ARRAY_INIT;
|
146
|
+
git_parse_ctx parser;
|
147
|
+
int error;
|
148
|
+
|
149
|
+
git_grafts_clear(grafts);
|
150
|
+
|
151
|
+
if ((error = git_parse_ctx_init(&parser, buf, len)) < 0)
|
152
|
+
goto error;
|
153
|
+
|
154
|
+
for (; parser.remain_len; git_parse_advance_line(&parser)) {
|
155
|
+
git_oid graft_oid;
|
156
|
+
|
157
|
+
if ((error = git_parse_advance_oid(&graft_oid, &parser, grafts->oid_type)) < 0) {
|
158
|
+
git_error_set(GIT_ERROR_GRAFTS, "invalid graft OID at line %" PRIuZ, parser.line_num);
|
159
|
+
goto error;
|
160
|
+
}
|
161
|
+
|
162
|
+
while (parser.line_len && git_parse_advance_expected(&parser, "\n", 1) != 0) {
|
163
|
+
git_oid *id = git_array_alloc(parents);
|
164
|
+
GIT_ERROR_CHECK_ALLOC(id);
|
165
|
+
|
166
|
+
if ((error = git_parse_advance_expected(&parser, " ", 1)) < 0 ||
|
167
|
+
(error = git_parse_advance_oid(id, &parser, grafts->oid_type)) < 0) {
|
168
|
+
git_error_set(GIT_ERROR_GRAFTS, "invalid parent OID at line %" PRIuZ, parser.line_num);
|
169
|
+
goto error;
|
170
|
+
}
|
171
|
+
}
|
172
|
+
|
173
|
+
if ((error = git_grafts_add(grafts, &graft_oid, parents)) < 0)
|
174
|
+
goto error;
|
175
|
+
|
176
|
+
git_array_clear(parents);
|
177
|
+
}
|
178
|
+
|
179
|
+
error:
|
180
|
+
git_array_clear(parents);
|
181
|
+
return error;
|
182
|
+
}
|
183
|
+
|
184
|
+
int git_grafts_add(git_grafts *grafts, const git_oid *oid, git_array_oid_t parents)
|
185
|
+
{
|
186
|
+
git_commit_graft *graft;
|
187
|
+
git_oid *parent_oid;
|
188
|
+
int error;
|
189
|
+
size_t i;
|
190
|
+
|
191
|
+
GIT_ASSERT_ARG(grafts && oid);
|
192
|
+
|
193
|
+
graft = git__calloc(1, sizeof(*graft));
|
194
|
+
GIT_ERROR_CHECK_ALLOC(graft);
|
195
|
+
|
196
|
+
git_array_init_to_size(graft->parents, git_array_size(parents));
|
197
|
+
git_array_foreach(parents, i, parent_oid) {
|
198
|
+
git_oid *id = git_array_alloc(graft->parents);
|
199
|
+
GIT_ERROR_CHECK_ALLOC(id);
|
200
|
+
|
201
|
+
git_oid_cpy(id, parent_oid);
|
202
|
+
}
|
203
|
+
git_oid_cpy(&graft->oid, oid);
|
204
|
+
|
205
|
+
if ((error = git_grafts_remove(grafts, &graft->oid)) < 0 && error != GIT_ENOTFOUND)
|
206
|
+
goto cleanup;
|
207
|
+
|
208
|
+
if ((error = git_oidmap_set(grafts->commits, &graft->oid, graft)) < 0)
|
209
|
+
goto cleanup;
|
210
|
+
|
211
|
+
return 0;
|
212
|
+
|
213
|
+
cleanup:
|
214
|
+
git_array_clear(graft->parents);
|
215
|
+
git__free(graft);
|
216
|
+
return error;
|
217
|
+
}
|
218
|
+
|
219
|
+
int git_grafts_remove(git_grafts *grafts, const git_oid *oid)
|
220
|
+
{
|
221
|
+
git_commit_graft *graft;
|
222
|
+
int error;
|
223
|
+
|
224
|
+
GIT_ASSERT_ARG(grafts && oid);
|
225
|
+
|
226
|
+
if ((graft = git_oidmap_get(grafts->commits, oid)) == NULL)
|
227
|
+
return GIT_ENOTFOUND;
|
228
|
+
|
229
|
+
if ((error = git_oidmap_delete(grafts->commits, oid)) < 0)
|
230
|
+
return error;
|
231
|
+
|
232
|
+
git__free(graft->parents.ptr);
|
233
|
+
git__free(graft);
|
234
|
+
|
235
|
+
return 0;
|
236
|
+
}
|
237
|
+
|
238
|
+
int git_grafts_get(git_commit_graft **out, git_grafts *grafts, const git_oid *oid)
|
239
|
+
{
|
240
|
+
GIT_ASSERT_ARG(out && grafts && oid);
|
241
|
+
if ((*out = git_oidmap_get(grafts->commits, oid)) == NULL)
|
242
|
+
return GIT_ENOTFOUND;
|
243
|
+
return 0;
|
244
|
+
}
|
245
|
+
|
246
|
+
int git_grafts_oids(git_oid **out, size_t *out_len, git_grafts *grafts)
|
247
|
+
{
|
248
|
+
git_array_oid_t array = GIT_ARRAY_INIT;
|
249
|
+
const git_oid *oid;
|
250
|
+
size_t existing, i = 0;
|
251
|
+
|
252
|
+
GIT_ASSERT_ARG(out && grafts);
|
253
|
+
|
254
|
+
if ((existing = git_oidmap_size(grafts->commits)) > 0)
|
255
|
+
git_array_init_to_size(array, existing);
|
256
|
+
|
257
|
+
while (git_oidmap_iterate(NULL, grafts->commits, &i, &oid) == 0) {
|
258
|
+
git_oid *cpy = git_array_alloc(array);
|
259
|
+
GIT_ERROR_CHECK_ALLOC(cpy);
|
260
|
+
git_oid_cpy(cpy, oid);
|
261
|
+
}
|
262
|
+
|
263
|
+
*out = array.ptr;
|
264
|
+
*out_len = array.size;
|
265
|
+
|
266
|
+
return 0;
|
267
|
+
}
|
268
|
+
|
269
|
+
size_t git_grafts_size(git_grafts *grafts)
|
270
|
+
{
|
271
|
+
return git_oidmap_size(grafts->commits);
|
272
|
+
}
|
@@ -0,0 +1,36 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (C) the libgit2 contributors. All rights reserved.
|
3
|
+
*
|
4
|
+
* This file is part of libgit2, distributed under the GNU GPL v2 with
|
5
|
+
* a Linking Exception. For full terms see the included COPYING file.
|
6
|
+
*/
|
7
|
+
#ifndef INCLUDE_graft_h__
|
8
|
+
#define INCLUDE_graft_h__
|
9
|
+
|
10
|
+
#include "common.h"
|
11
|
+
#include "oidarray.h"
|
12
|
+
#include "oidmap.h"
|
13
|
+
|
14
|
+
/** graft commit */
|
15
|
+
typedef struct {
|
16
|
+
git_oid oid;
|
17
|
+
git_array_oid_t parents;
|
18
|
+
} git_commit_graft;
|
19
|
+
|
20
|
+
typedef struct git_grafts git_grafts;
|
21
|
+
|
22
|
+
int git_grafts_new(git_grafts **out, git_oid_t oid_type);
|
23
|
+
int git_grafts_open(git_grafts **out, const char *path, git_oid_t oid_type);
|
24
|
+
int git_grafts_open_or_refresh(git_grafts **out, const char *path, git_oid_t oid_type);
|
25
|
+
void git_grafts_free(git_grafts *grafts);
|
26
|
+
void git_grafts_clear(git_grafts *grafts);
|
27
|
+
|
28
|
+
int git_grafts_refresh(git_grafts *grafts);
|
29
|
+
int git_grafts_parse(git_grafts *grafts, const char *buf, size_t len);
|
30
|
+
int git_grafts_add(git_grafts *grafts, const git_oid *oid, git_array_oid_t parents);
|
31
|
+
int git_grafts_remove(git_grafts *grafts, const git_oid *oid);
|
32
|
+
int git_grafts_get(git_commit_graft **out, git_grafts *grafts, const git_oid *oid);
|
33
|
+
int git_grafts_oids(git_oid **out, size_t *out_len, git_grafts *grafts);
|
34
|
+
size_t git_grafts_size(git_grafts *grafts);
|
35
|
+
|
36
|
+
#endif
|
@@ -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_MAX_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_MAX_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
|
-
|
68
|
+
git_str_puts(to, oid);
|
69
69
|
git_str_put(to, " $", 2);
|
70
70
|
git_str_put(to, id_end, (size_t)(from_end - id_end));
|
71
71
|
|