rugged 0.24.0b13 → 0.24.0b14
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.
- data/ext/rugged/rugged_commit.c +6 -6
- data/ext/rugged/rugged_revwalk.c +7 -3
- data/ext/rugged/rugged_settings.c +5 -0
- data/lib/rugged/tag.rb +1 -1
- data/lib/rugged/version.rb +1 -1
- data/vendor/libgit2/CMakeLists.txt +21 -8
- data/vendor/libgit2/include/git2/commit.h +6 -0
- data/vendor/libgit2/include/git2/common.h +15 -0
- data/vendor/libgit2/include/git2/errors.h +0 -5
- data/vendor/libgit2/include/git2/rebase.h +1 -1
- data/vendor/libgit2/include/git2/sys/filter.h +34 -25
- data/vendor/libgit2/include/git2/sys/index.h +1 -1
- data/vendor/libgit2/src/checkout.c +1 -1
- data/vendor/libgit2/src/commit.c +44 -12
- data/vendor/libgit2/src/common.h +11 -0
- data/vendor/libgit2/src/crlf.c +1 -1
- data/vendor/libgit2/src/diff_print.c +5 -1
- data/vendor/libgit2/src/diff_tform.c +16 -11
- data/vendor/libgit2/src/fileops.c +8 -15
- data/vendor/libgit2/src/filter.c +155 -124
- data/vendor/libgit2/src/filter.h +2 -0
- data/vendor/libgit2/src/global.c +56 -162
- data/vendor/libgit2/src/index.c +68 -30
- data/vendor/libgit2/src/index.h +1 -1
- data/vendor/libgit2/src/iterator.c +9 -3
- data/vendor/libgit2/src/netops.c +4 -0
- data/vendor/libgit2/src/object.c +26 -0
- data/vendor/libgit2/src/object.h +23 -0
- data/vendor/libgit2/src/openssl_stream.c +135 -3
- data/vendor/libgit2/src/openssl_stream.h +2 -0
- data/vendor/libgit2/src/pack-objects.c +6 -6
- data/vendor/libgit2/src/pack.c +18 -1
- data/vendor/libgit2/src/path.c +7 -3
- data/vendor/libgit2/src/path.h +14 -4
- data/vendor/libgit2/src/pool.c +78 -30
- data/vendor/libgit2/src/pool.h +28 -0
- data/vendor/libgit2/src/posix.c +5 -2
- data/vendor/libgit2/src/rebase.c +12 -10
- data/vendor/libgit2/src/refdb_fs.c +3 -4
- data/vendor/libgit2/src/refs.c +1 -7
- data/vendor/libgit2/src/refspec.c +4 -4
- data/vendor/libgit2/src/remote.c +2 -2
- data/vendor/libgit2/src/revwalk.c +1 -2
- data/vendor/libgit2/src/settings.c +9 -0
- data/vendor/libgit2/src/signature.c +2 -3
- data/vendor/libgit2/src/submodule.c +2 -2
- data/vendor/libgit2/src/thread-utils.h +1 -1
- data/vendor/libgit2/src/transports/smart_pkt.c +15 -9
- data/vendor/libgit2/src/transports/smart_protocol.c +2 -0
- data/vendor/libgit2/src/transports/winhttp.c +1 -1
- data/vendor/libgit2/src/tree.c +31 -10
- data/vendor/libgit2/src/unix/map.c +1 -1
- data/vendor/libgit2/src/unix/posix.h +15 -1
- data/vendor/libgit2/src/win32/posix.h +6 -4
- data/vendor/libgit2/src/win32/posix_w32.c +18 -2
- data/vendor/libgit2/src/win32/utf-conv.c +3 -18
- data/vendor/libgit2/src/win32/w32_util.h +44 -11
- data/vendor/libgit2/src/win32/win32-compat.h +10 -0
- data/vendor/libgit2/src/xdiff/xmerge.c +2 -0
- metadata +416 -405
- checksums.yaml +0 -7
data/vendor/libgit2/src/filter.h
CHANGED
data/vendor/libgit2/src/global.c
CHANGED
@@ -8,9 +8,11 @@
|
|
8
8
|
#include "global.h"
|
9
9
|
#include "hash.h"
|
10
10
|
#include "sysdir.h"
|
11
|
-
#include "
|
12
|
-
#include "
|
11
|
+
#include "filter.h"
|
12
|
+
#include "openssl_stream.h"
|
13
13
|
#include "thread-utils.h"
|
14
|
+
#include "git2/global.h"
|
15
|
+
|
14
16
|
#if defined(GIT_MSVC_CRTDBG)
|
15
17
|
#include "win32/w32_stack.h"
|
16
18
|
#include "win32/w32_crtdbg_stacktrace.h"
|
@@ -20,14 +22,6 @@ git_mutex git__mwindow_mutex;
|
|
20
22
|
|
21
23
|
#define MAX_SHUTDOWN_CB 8
|
22
24
|
|
23
|
-
#ifdef GIT_OPENSSL
|
24
|
-
# include <openssl/ssl.h>
|
25
|
-
SSL_CTX *git__ssl_ctx;
|
26
|
-
# ifdef GIT_THREADS
|
27
|
-
static git_mutex *openssl_locks;
|
28
|
-
# endif
|
29
|
-
#endif
|
30
|
-
|
31
25
|
static git_global_shutdown_fn git__shutdown_callbacks[MAX_SHUTDOWN_CB];
|
32
26
|
static git_atomic git__n_shutdown_callbacks;
|
33
27
|
static git_atomic git__n_inits;
|
@@ -49,118 +43,48 @@ static void git__global_state_cleanup(git_global_st *st)
|
|
49
43
|
st->error_t.message = NULL;
|
50
44
|
}
|
51
45
|
|
52
|
-
static
|
46
|
+
static int init_common(void)
|
53
47
|
{
|
54
|
-
int
|
55
|
-
|
56
|
-
/* Shutdown subsystems that have registered */
|
57
|
-
for (pos = git_atomic_get(&git__n_shutdown_callbacks); pos > 0; pos = git_atomic_dec(&git__n_shutdown_callbacks)) {
|
58
|
-
git_global_shutdown_fn cb = git__swap(git__shutdown_callbacks[pos - 1], NULL);
|
59
|
-
if (cb != NULL)
|
60
|
-
cb();
|
61
|
-
}
|
62
|
-
}
|
63
|
-
|
64
|
-
#if defined(GIT_THREADS) && defined(GIT_OPENSSL)
|
65
|
-
void openssl_locking_function(int mode, int n, const char *file, int line)
|
66
|
-
{
|
67
|
-
int lock;
|
68
|
-
|
69
|
-
GIT_UNUSED(file);
|
70
|
-
GIT_UNUSED(line);
|
71
|
-
|
72
|
-
lock = mode & CRYPTO_LOCK;
|
48
|
+
int ret;
|
73
49
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
}
|
50
|
+
/* Initialize the CRT debug allocator first, before our first malloc */
|
51
|
+
#if defined(GIT_MSVC_CRTDBG)
|
52
|
+
git_win32__crtdbg_stacktrace_init();
|
53
|
+
git_win32__stack_init();
|
54
|
+
#endif
|
80
55
|
|
81
|
-
|
82
|
-
|
83
|
-
|
56
|
+
/* Initialize any other subsystems that have global state */
|
57
|
+
if ((ret = git_hash_global_init()) == 0 &&
|
58
|
+
(ret = git_sysdir_global_init()) == 0 &&
|
59
|
+
(ret = git_filter_global_init()) == 0)
|
60
|
+
ret = git_openssl_stream_global_init();
|
84
61
|
|
85
|
-
|
86
|
-
CRYPTO_set_locking_callback(NULL);
|
62
|
+
GIT_MEMORY_BARRIER;
|
87
63
|
|
88
|
-
|
89
|
-
git_mutex_free(openssl_locks);
|
90
|
-
git__free(openssl_locks);
|
64
|
+
return ret;
|
91
65
|
}
|
92
|
-
#endif
|
93
66
|
|
94
|
-
static void
|
67
|
+
static void shutdown_common(void)
|
95
68
|
{
|
96
|
-
|
97
|
-
long ssl_opts = SSL_OP_NO_SSLv2 | SSL_OP_NO_SSLv3;
|
69
|
+
int pos;
|
98
70
|
|
99
|
-
/*
|
100
|
-
|
101
|
-
|
102
|
-
|
71
|
+
/* Shutdown subsystems that have registered */
|
72
|
+
for (pos = git_atomic_get(&git__n_shutdown_callbacks);
|
73
|
+
pos > 0;
|
74
|
+
pos = git_atomic_dec(&git__n_shutdown_callbacks)) {
|
103
75
|
|
104
|
-
|
105
|
-
|
106
|
-
/*
|
107
|
-
* Load SSLv{2,3} and TLSv1 so that we can talk with servers
|
108
|
-
* which use the SSL hellos, which are often used for
|
109
|
-
* compatibility. We then disable SSL so we only allow OpenSSL
|
110
|
-
* to speak TLSv1 to perform the encryption itself.
|
111
|
-
*/
|
112
|
-
git__ssl_ctx = SSL_CTX_new(SSLv23_method());
|
113
|
-
SSL_CTX_set_options(git__ssl_ctx, ssl_opts);
|
114
|
-
SSL_CTX_set_mode(git__ssl_ctx, SSL_MODE_AUTO_RETRY);
|
115
|
-
SSL_CTX_set_verify(git__ssl_ctx, SSL_VERIFY_NONE, NULL);
|
116
|
-
if (!SSL_CTX_set_default_verify_paths(git__ssl_ctx)) {
|
117
|
-
SSL_CTX_free(git__ssl_ctx);
|
118
|
-
git__ssl_ctx = NULL;
|
119
|
-
}
|
120
|
-
#endif
|
121
|
-
}
|
76
|
+
git_global_shutdown_fn cb = git__swap(
|
77
|
+
git__shutdown_callbacks[pos - 1], NULL);
|
122
78
|
|
123
|
-
|
124
|
-
|
125
|
-
* we allocated.
|
126
|
-
*/
|
127
|
-
static void uninit_ssl(void)
|
128
|
-
{
|
129
|
-
#ifdef GIT_OPENSSL
|
130
|
-
if (git__ssl_ctx) {
|
131
|
-
SSL_CTX_free(git__ssl_ctx);
|
132
|
-
git__ssl_ctx = NULL;
|
79
|
+
if (cb != NULL)
|
80
|
+
cb();
|
133
81
|
}
|
134
|
-
#endif
|
135
|
-
}
|
136
82
|
|
137
|
-
|
138
|
-
{
|
139
|
-
#ifdef GIT_OPENSSL
|
140
|
-
# ifdef GIT_THREADS
|
141
|
-
int num_locks, i;
|
142
|
-
|
143
|
-
num_locks = CRYPTO_num_locks();
|
144
|
-
openssl_locks = git__calloc(num_locks, sizeof(git_mutex));
|
145
|
-
GITERR_CHECK_ALLOC(openssl_locks);
|
146
|
-
|
147
|
-
for (i = 0; i < num_locks; i++) {
|
148
|
-
if (git_mutex_init(&openssl_locks[i]) != 0) {
|
149
|
-
giterr_set(GITERR_SSL, "failed to initialize openssl locks");
|
150
|
-
return -1;
|
151
|
-
}
|
152
|
-
}
|
83
|
+
git__free(git__user_agent);
|
153
84
|
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
# else
|
158
|
-
giterr_set(GITERR_THREAD, "libgit2 as not built with threads");
|
159
|
-
return -1;
|
160
|
-
# endif
|
161
|
-
#else
|
162
|
-
giterr_set(GITERR_SSL, "libgit2 was not built with OpenSSL support");
|
163
|
-
return -1;
|
85
|
+
#if defined(GIT_MSVC_CRTDBG)
|
86
|
+
git_win32__crtdbg_stacktrace_cleanup();
|
87
|
+
git_win32__stack_cleanup();
|
164
88
|
#endif
|
165
89
|
}
|
166
90
|
|
@@ -208,14 +132,13 @@ static int synchronized_threads_init(void)
|
|
208
132
|
int error;
|
209
133
|
|
210
134
|
_tls_index = TlsAlloc();
|
135
|
+
|
136
|
+
win32_pthread_initialize();
|
137
|
+
|
211
138
|
if (git_mutex_init(&git__mwindow_mutex))
|
212
139
|
return -1;
|
213
140
|
|
214
|
-
|
215
|
-
if ((error = git_hash_global_init()) >= 0)
|
216
|
-
error = git_sysdir_global_init();
|
217
|
-
|
218
|
-
win32_pthread_initialize();
|
141
|
+
error = init_common();
|
219
142
|
|
220
143
|
return error;
|
221
144
|
}
|
@@ -229,11 +152,6 @@ int git_libgit2_init(void)
|
|
229
152
|
|
230
153
|
/* Only do work on a 0 -> 1 transition of the refcount */
|
231
154
|
if ((ret = git_atomic_inc(&git__n_inits)) == 1) {
|
232
|
-
#if defined(GIT_MSVC_CRTDBG)
|
233
|
-
git_win32__crtdbg_stacktrace_init();
|
234
|
-
git_win32__stack_init();
|
235
|
-
#endif
|
236
|
-
|
237
155
|
if (synchronized_threads_init() < 0)
|
238
156
|
ret = -1;
|
239
157
|
}
|
@@ -244,17 +162,6 @@ int git_libgit2_init(void)
|
|
244
162
|
return ret;
|
245
163
|
}
|
246
164
|
|
247
|
-
static void synchronized_threads_shutdown(void)
|
248
|
-
{
|
249
|
-
/* Shut down any subsystems that have global state */
|
250
|
-
git__shutdown();
|
251
|
-
|
252
|
-
git__free_tls_data();
|
253
|
-
|
254
|
-
TlsFree(_tls_index);
|
255
|
-
git_mutex_free(&git__mwindow_mutex);
|
256
|
-
}
|
257
|
-
|
258
165
|
int git_libgit2_shutdown(void)
|
259
166
|
{
|
260
167
|
int ret;
|
@@ -264,14 +171,12 @@ int git_libgit2_shutdown(void)
|
|
264
171
|
|
265
172
|
/* Only do work on a 1 -> 0 transition of the refcount */
|
266
173
|
if ((ret = git_atomic_dec(&git__n_inits)) == 0) {
|
267
|
-
|
174
|
+
shutdown_common();
|
268
175
|
|
269
|
-
|
270
|
-
git_win32__crtdbg_stacktrace_cleanup();
|
271
|
-
git_win32__stack_cleanup();
|
272
|
-
#endif
|
176
|
+
git__free_tls_data();
|
273
177
|
|
274
|
-
|
178
|
+
TlsFree(_tls_index);
|
179
|
+
git_mutex_free(&git__mwindow_mutex);
|
275
180
|
}
|
276
181
|
|
277
182
|
/* Exit the lock */
|
@@ -331,17 +236,10 @@ static void init_once(void)
|
|
331
236
|
{
|
332
237
|
if ((init_error = git_mutex_init(&git__mwindow_mutex)) != 0)
|
333
238
|
return;
|
334
|
-
pthread_key_create(&_tls_key, &cb__free_status);
|
335
|
-
|
336
239
|
|
337
|
-
|
338
|
-
if ((init_error = git_hash_global_init()) >= 0)
|
339
|
-
init_error = git_sysdir_global_init();
|
340
|
-
|
341
|
-
/* OpenSSL needs to be initialized from the main thread */
|
342
|
-
init_ssl();
|
240
|
+
pthread_key_create(&_tls_key, &cb__free_status);
|
343
241
|
|
344
|
-
|
242
|
+
init_error = init_common();
|
345
243
|
}
|
346
244
|
|
347
245
|
int git_libgit2_init(void)
|
@@ -364,15 +262,13 @@ int git_libgit2_shutdown(void)
|
|
364
262
|
return ret;
|
365
263
|
|
366
264
|
/* Shut down any subsystems that have global state */
|
367
|
-
|
368
|
-
uninit_ssl();
|
265
|
+
shutdown_common();
|
369
266
|
|
370
267
|
ptr = pthread_getspecific(_tls_key);
|
371
268
|
pthread_setspecific(_tls_key, NULL);
|
372
269
|
|
373
270
|
git__global_state_cleanup(ptr);
|
374
271
|
git__free(ptr);
|
375
|
-
git__free(git__user_agent);
|
376
272
|
|
377
273
|
pthread_key_delete(_tls_key);
|
378
274
|
git_mutex_free(&git__mwindow_mutex);
|
@@ -405,15 +301,16 @@ static git_global_st __state;
|
|
405
301
|
|
406
302
|
int git_libgit2_init(void)
|
407
303
|
{
|
408
|
-
|
304
|
+
int ret;
|
409
305
|
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
}
|
306
|
+
/* Only init SSL the first time */
|
307
|
+
if ((ret = git_atomic_inc(&git__n_inits)) != 1)
|
308
|
+
return ret;
|
414
309
|
|
415
|
-
|
416
|
-
|
310
|
+
if ((ret = init_common()) < 0)
|
311
|
+
return ret;
|
312
|
+
|
313
|
+
return 1;
|
417
314
|
}
|
418
315
|
|
419
316
|
int git_libgit2_shutdown(void)
|
@@ -421,15 +318,12 @@ int git_libgit2_shutdown(void)
|
|
421
318
|
int ret;
|
422
319
|
|
423
320
|
/* Shut down any subsystems that have global state */
|
424
|
-
if ((ret = git_atomic_dec(&git__n_inits))
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
git__global_state_cleanup(&__state);
|
429
|
-
uninit_ssl();
|
430
|
-
git__free(git__user_agent);
|
321
|
+
if ((ret = git_atomic_dec(&git__n_inits)) == 0) {
|
322
|
+
shutdown_common();
|
323
|
+
git__global_state_cleanup(&__state);
|
324
|
+
}
|
431
325
|
|
432
|
-
return
|
326
|
+
return ret;
|
433
327
|
}
|
434
328
|
|
435
329
|
git_global_st *git__global_state(void)
|
data/vendor/libgit2/src/index.c
CHANGED
@@ -603,14 +603,14 @@ const git_oid *git_index_checksum(git_index *index)
|
|
603
603
|
*/
|
604
604
|
static int compare_checksum(git_index *index)
|
605
605
|
{
|
606
|
-
int fd
|
606
|
+
int fd;
|
607
607
|
ssize_t bytes_read;
|
608
608
|
git_oid checksum = {{ 0 }};
|
609
609
|
|
610
610
|
if ((fd = p_open(index->index_file_path, O_RDONLY)) < 0)
|
611
611
|
return fd;
|
612
612
|
|
613
|
-
if (
|
613
|
+
if (p_lseek(fd, -20, SEEK_END) < 0) {
|
614
614
|
p_close(fd);
|
615
615
|
giterr_set(GITERR_OS, "failed to seek to end of file");
|
616
616
|
return -1;
|
@@ -826,11 +826,11 @@ const git_index_entry *git_index_get_bypath(
|
|
826
826
|
void git_index_entry__init_from_stat(
|
827
827
|
git_index_entry *entry, struct stat *st, bool trust_mode)
|
828
828
|
{
|
829
|
-
entry->ctime.seconds = (
|
830
|
-
entry->mtime.seconds = (
|
829
|
+
entry->ctime.seconds = (int32_t)st->st_ctime;
|
830
|
+
entry->mtime.seconds = (int32_t)st->st_mtime;
|
831
831
|
#if defined(GIT_USE_NSEC)
|
832
|
-
entry->mtime.nanoseconds = st->
|
833
|
-
entry->ctime.nanoseconds = st->
|
832
|
+
entry->mtime.nanoseconds = st->st_mtime_nsec;
|
833
|
+
entry->ctime.nanoseconds = st->st_ctime_nsec;
|
834
834
|
#endif
|
835
835
|
entry->dev = st->st_rdev;
|
836
836
|
entry->ino = st->st_ino;
|
@@ -838,7 +838,7 @@ void git_index_entry__init_from_stat(
|
|
838
838
|
git_index__create_mode(0666) : git_index__create_mode(st->st_mode);
|
839
839
|
entry->uid = st->st_uid;
|
840
840
|
entry->gid = st->st_gid;
|
841
|
-
entry->file_size = st->st_size;
|
841
|
+
entry->file_size = (uint32_t)st->st_size;
|
842
842
|
}
|
843
843
|
|
844
844
|
static void index_entry_adjust_namemask(
|
@@ -853,17 +853,31 @@ static void index_entry_adjust_namemask(
|
|
853
853
|
entry->flags |= GIT_IDXENTRY_NAMEMASK;
|
854
854
|
}
|
855
855
|
|
856
|
+
/* When `from_workdir` is true, we will validate the paths to avoid placing
|
857
|
+
* paths that are invalid for the working directory on the current filesystem
|
858
|
+
* (eg, on Windows, we will disallow `GIT~1`, `AUX`, `COM1`, etc). This
|
859
|
+
* function will *always* prevent `.git` and directory traversal `../` from
|
860
|
+
* being added to the index.
|
861
|
+
*/
|
856
862
|
static int index_entry_create(
|
857
863
|
git_index_entry **out,
|
858
864
|
git_repository *repo,
|
859
|
-
const char *path
|
865
|
+
const char *path,
|
866
|
+
bool from_workdir)
|
860
867
|
{
|
861
868
|
size_t pathlen = strlen(path), alloclen;
|
862
869
|
struct entry_internal *entry;
|
870
|
+
unsigned int path_valid_flags = GIT_PATH_REJECT_INDEX_DEFAULTS;
|
871
|
+
|
872
|
+
/* always reject placing `.git` in the index and directory traversal.
|
873
|
+
* when requested, disallow platform-specific filenames and upgrade to
|
874
|
+
* the platform-specific `.git` tests (eg, `git~1`, etc).
|
875
|
+
*/
|
876
|
+
if (from_workdir)
|
877
|
+
path_valid_flags |= GIT_PATH_REJECT_WORKDIR_DEFAULTS;
|
863
878
|
|
864
|
-
if (!git_path_isvalid(repo, path,
|
865
|
-
|
866
|
-
giterr_set(GITERR_INDEX, "Invalid path: '%s'", path);
|
879
|
+
if (!git_path_isvalid(repo, path, path_valid_flags)) {
|
880
|
+
giterr_set(GITERR_INDEX, "invalid path: '%s'", path);
|
867
881
|
return -1;
|
868
882
|
}
|
869
883
|
|
@@ -895,7 +909,7 @@ static int index_entry_init(
|
|
895
909
|
"Could not initialize index entry. "
|
896
910
|
"Index is not backed up by an existing repository.");
|
897
911
|
|
898
|
-
if (index_entry_create(&entry, INDEX_OWNER(index), rel_path) < 0)
|
912
|
+
if (index_entry_create(&entry, INDEX_OWNER(index), rel_path, true) < 0)
|
899
913
|
return -1;
|
900
914
|
|
901
915
|
/* write the blob to disk and get the oid and stat info */
|
@@ -975,7 +989,7 @@ static int index_entry_dup(
|
|
975
989
|
git_index *index,
|
976
990
|
const git_index_entry *src)
|
977
991
|
{
|
978
|
-
if (index_entry_create(out, INDEX_OWNER(index), src->path) < 0)
|
992
|
+
if (index_entry_create(out, INDEX_OWNER(index), src->path, false) < 0)
|
979
993
|
return -1;
|
980
994
|
|
981
995
|
index_entry_cpy(*out, src);
|
@@ -997,7 +1011,7 @@ static int index_entry_dup_nocache(
|
|
997
1011
|
git_index *index,
|
998
1012
|
const git_index_entry *src)
|
999
1013
|
{
|
1000
|
-
if (index_entry_create(out, INDEX_OWNER(index), src->path) < 0)
|
1014
|
+
if (index_entry_create(out, INDEX_OWNER(index), src->path, false) < 0)
|
1001
1015
|
return -1;
|
1002
1016
|
|
1003
1017
|
index_entry_cpy_nocache(*out, src);
|
@@ -1231,17 +1245,22 @@ static void index_existing_and_best(
|
|
1231
1245
|
* it, then it will return an error **and also free the entry**. When
|
1232
1246
|
* it replaces an existing entry, it will update the entry_ptr with the
|
1233
1247
|
* actual entry in the index (and free the passed in one).
|
1248
|
+
*
|
1234
1249
|
* trust_path is whether we use the given path, or whether (on case
|
1235
1250
|
* insensitive systems only) we try to canonicalize the given path to
|
1236
1251
|
* be within an existing directory.
|
1252
|
+
*
|
1237
1253
|
* trust_mode is whether we trust the mode in entry_ptr.
|
1254
|
+
*
|
1255
|
+
* trust_id is whether we trust the id or it should be validated.
|
1238
1256
|
*/
|
1239
1257
|
static int index_insert(
|
1240
1258
|
git_index *index,
|
1241
1259
|
git_index_entry **entry_ptr,
|
1242
1260
|
int replace,
|
1243
1261
|
bool trust_path,
|
1244
|
-
bool trust_mode
|
1262
|
+
bool trust_mode,
|
1263
|
+
bool trust_id)
|
1245
1264
|
{
|
1246
1265
|
int error = 0;
|
1247
1266
|
size_t path_length, position;
|
@@ -1274,6 +1293,15 @@ static int index_insert(
|
|
1274
1293
|
if (!trust_path)
|
1275
1294
|
error = canonicalize_directory_path(index, entry, best);
|
1276
1295
|
|
1296
|
+
/* ensure that the given id exists (unless it's a submodule) */
|
1297
|
+
if (!error && !trust_id && INDEX_OWNER(index) &&
|
1298
|
+
(entry->mode & GIT_FILEMODE_COMMIT) != GIT_FILEMODE_COMMIT) {
|
1299
|
+
|
1300
|
+
if (!git_object__is_valid(INDEX_OWNER(index), &entry->id,
|
1301
|
+
git_object__type_from_filemode(entry->mode)))
|
1302
|
+
error = -1;
|
1303
|
+
}
|
1304
|
+
|
1277
1305
|
/* look for tree / blob name collisions, removing conflicts if requested */
|
1278
1306
|
if (!error)
|
1279
1307
|
error = check_file_directory_collision(index, entry, position, replace);
|
@@ -1381,7 +1409,7 @@ int git_index_add_frombuffer(
|
|
1381
1409
|
git_oid_cpy(&entry->id, &id);
|
1382
1410
|
entry->file_size = len;
|
1383
1411
|
|
1384
|
-
if ((error = index_insert(index, &entry, 1, true, true)) < 0)
|
1412
|
+
if ((error = index_insert(index, &entry, 1, true, true, true)) < 0)
|
1385
1413
|
return error;
|
1386
1414
|
|
1387
1415
|
/* Adding implies conflict was resolved, move conflict entries to REUC */
|
@@ -1402,7 +1430,7 @@ static int add_repo_as_submodule(git_index_entry **out, git_index *index, const
|
|
1402
1430
|
struct stat st;
|
1403
1431
|
int error;
|
1404
1432
|
|
1405
|
-
if (index_entry_create(&entry, INDEX_OWNER(index), path) < 0)
|
1433
|
+
if (index_entry_create(&entry, INDEX_OWNER(index), path, true) < 0)
|
1406
1434
|
return -1;
|
1407
1435
|
|
1408
1436
|
if ((error = git_buf_joinpath(&abspath, git_repository_workdir(repo), path)) < 0)
|
@@ -1440,7 +1468,7 @@ int git_index_add_bypath(git_index *index, const char *path)
|
|
1440
1468
|
assert(index && path);
|
1441
1469
|
|
1442
1470
|
if ((ret = index_entry_init(&entry, index, path)) == 0)
|
1443
|
-
ret = index_insert(index, &entry, 1, false, false);
|
1471
|
+
ret = index_insert(index, &entry, 1, false, false, true);
|
1444
1472
|
|
1445
1473
|
/* If we were given a directory, let's see if it's a submodule */
|
1446
1474
|
if (ret < 0 && ret != GIT_EDIRECTORY)
|
@@ -1466,7 +1494,7 @@ int git_index_add_bypath(git_index *index, const char *path)
|
|
1466
1494
|
if ((ret = add_repo_as_submodule(&entry, index, path)) < 0)
|
1467
1495
|
return ret;
|
1468
1496
|
|
1469
|
-
if ((ret = index_insert(index, &entry, 1, false, false)) < 0)
|
1497
|
+
if ((ret = index_insert(index, &entry, 1, false, false, true)) < 0)
|
1470
1498
|
return ret;
|
1471
1499
|
} else if (ret < 0) {
|
1472
1500
|
return ret;
|
@@ -1515,7 +1543,7 @@ int git_index__fill(git_index *index, const git_vector *source_entries)
|
|
1515
1543
|
return 0;
|
1516
1544
|
|
1517
1545
|
git_vector_size_hint(&index->entries, source_entries->length);
|
1518
|
-
git_idxmap_resize(index->entries_map, source_entries->length * 1.3);
|
1546
|
+
git_idxmap_resize(index->entries_map, (khint_t)(source_entries->length * 1.3));
|
1519
1547
|
|
1520
1548
|
git_vector_foreach(source_entries, i, source_entry) {
|
1521
1549
|
git_index_entry *entry = NULL;
|
@@ -1555,7 +1583,7 @@ int git_index_add(git_index *index, const git_index_entry *source_entry)
|
|
1555
1583
|
}
|
1556
1584
|
|
1557
1585
|
if ((ret = index_entry_dup(&entry, index, source_entry)) < 0 ||
|
1558
|
-
(ret = index_insert(index, &entry, 1, true, true)) < 0)
|
1586
|
+
(ret = index_insert(index, &entry, 1, true, true, false)) < 0)
|
1559
1587
|
return ret;
|
1560
1588
|
|
1561
1589
|
git_tree_cache_invalidate_path(index->tree, entry->path);
|
@@ -1717,7 +1745,7 @@ int git_index_conflict_add(git_index *index,
|
|
1717
1745
|
/* Make sure stage is correct */
|
1718
1746
|
GIT_IDXENTRY_STAGE_SET(entries[i], i + 1);
|
1719
1747
|
|
1720
|
-
if ((ret = index_insert(index, &entries[i], 1, true, true)) < 0)
|
1748
|
+
if ((ret = index_insert(index, &entries[i], 1, true, true, false)) < 0)
|
1721
1749
|
goto on_error;
|
1722
1750
|
|
1723
1751
|
entries[i] = NULL; /* don't free if later entry fails */
|
@@ -2121,11 +2149,11 @@ static int read_reuc(git_index *index, const char *buffer, size_t size)
|
|
2121
2149
|
|
2122
2150
|
/* read 3 ASCII octal numbers for stage entries */
|
2123
2151
|
for (i = 0; i < 3; i++) {
|
2124
|
-
|
2152
|
+
int64_t tmp;
|
2125
2153
|
|
2126
|
-
if (
|
2154
|
+
if (git__strtol64(&tmp, buffer, &endptr, 8) < 0 ||
|
2127
2155
|
!endptr || endptr == buffer || *endptr ||
|
2128
|
-
|
2156
|
+
tmp < 0) {
|
2129
2157
|
index_entry_reuc_free(lost);
|
2130
2158
|
return index_error_invalid("reading reuc entry stage");
|
2131
2159
|
}
|
@@ -2179,9 +2207,10 @@ static int read_conflict_names(git_index *index, const char *buffer, size_t size
|
|
2179
2207
|
|
2180
2208
|
#define read_conflict_name(ptr) \
|
2181
2209
|
len = p_strnlen(buffer, size) + 1; \
|
2182
|
-
if (size < len) \
|
2183
|
-
|
2184
|
-
|
2210
|
+
if (size < len) { \
|
2211
|
+
index_error_invalid("reading conflict name entries"); \
|
2212
|
+
goto out_err; \
|
2213
|
+
} \
|
2185
2214
|
if (len == 1) \
|
2186
2215
|
ptr = NULL; \
|
2187
2216
|
else { \
|
@@ -2202,7 +2231,16 @@ static int read_conflict_names(git_index *index, const char *buffer, size_t size
|
|
2202
2231
|
read_conflict_name(conflict_name->theirs);
|
2203
2232
|
|
2204
2233
|
if (git_vector_insert(&index->names, conflict_name) < 0)
|
2205
|
-
|
2234
|
+
goto out_err;
|
2235
|
+
|
2236
|
+
continue;
|
2237
|
+
|
2238
|
+
out_err:
|
2239
|
+
git__free(conflict_name->ancestor);
|
2240
|
+
git__free(conflict_name->ours);
|
2241
|
+
git__free(conflict_name->theirs);
|
2242
|
+
git__free(conflict_name);
|
2243
|
+
return -1;
|
2206
2244
|
}
|
2207
2245
|
|
2208
2246
|
#undef read_conflict_name
|
@@ -2788,7 +2826,7 @@ static int read_tree_cb(
|
|
2788
2826
|
if (git_buf_joinpath(&path, root, tentry->filename) < 0)
|
2789
2827
|
return -1;
|
2790
2828
|
|
2791
|
-
if (index_entry_create(&entry, INDEX_OWNER(data->index), path.ptr) < 0)
|
2829
|
+
if (index_entry_create(&entry, INDEX_OWNER(data->index), path.ptr, false) < 0)
|
2792
2830
|
return -1;
|
2793
2831
|
|
2794
2832
|
entry->mode = tentry->attr;
|