rugged 0.24.6.1 → 0.25.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE +1 -1
- data/ext/rugged/extconf.rb +9 -2
- data/ext/rugged/rugged.c +85 -21
- data/ext/rugged/rugged.h +7 -21
- data/ext/rugged/rugged_backend.c +3 -20
- data/ext/rugged/rugged_blame.c +7 -24
- data/ext/rugged/rugged_blob.c +136 -59
- data/ext/rugged/rugged_branch.c +3 -20
- data/ext/rugged/rugged_branch_collection.c +3 -20
- data/ext/rugged/rugged_commit.c +251 -101
- data/ext/rugged/rugged_config.c +3 -20
- data/ext/rugged/rugged_cred.c +3 -20
- data/ext/rugged/rugged_diff.c +3 -20
- data/ext/rugged/rugged_diff_delta.c +3 -20
- data/ext/rugged/rugged_diff_hunk.c +3 -20
- data/ext/rugged/rugged_diff_line.c +3 -20
- data/ext/rugged/rugged_index.c +46 -229
- data/ext/rugged/rugged_note.c +3 -20
- data/ext/rugged/rugged_object.c +3 -20
- data/ext/rugged/rugged_patch.c +192 -34
- data/ext/rugged/rugged_rebase.c +90 -48
- data/ext/rugged/rugged_reference.c +4 -21
- data/ext/rugged/rugged_reference_collection.c +3 -20
- data/ext/rugged/rugged_remote.c +70 -42
- data/ext/rugged/rugged_remote_collection.c +3 -20
- data/ext/rugged/rugged_repo.c +50 -59
- data/ext/rugged/rugged_revwalk.c +4 -21
- data/ext/rugged/rugged_settings.c +3 -20
- data/ext/rugged/rugged_signature.c +3 -20
- data/ext/rugged/rugged_submodule.c +4 -21
- data/ext/rugged/rugged_submodule_collection.c +3 -20
- data/ext/rugged/rugged_tag.c +3 -20
- data/ext/rugged/rugged_tag_collection.c +3 -20
- data/ext/rugged/rugged_tree.c +189 -184
- data/lib/rugged/attributes.rb +5 -0
- data/lib/rugged/blob.rb +5 -0
- data/lib/rugged/branch.rb +6 -1
- data/lib/rugged/commit.rb +5 -0
- data/lib/rugged/console.rb +5 -0
- data/lib/rugged/credentials.rb +5 -0
- data/lib/rugged/diff/delta.rb +5 -0
- data/lib/rugged/diff/hunk.rb +5 -0
- data/lib/rugged/diff/line.rb +5 -0
- data/lib/rugged/diff.rb +5 -0
- data/lib/rugged/index.rb +120 -0
- data/lib/rugged/object.rb +5 -0
- data/lib/rugged/patch.rb +5 -0
- data/lib/rugged/reference.rb +5 -0
- data/lib/rugged/remote.rb +5 -0
- data/lib/rugged/repository.rb +9 -4
- data/lib/rugged/submodule_collection.rb +5 -0
- data/lib/rugged/tag.rb +5 -0
- data/lib/rugged/tree.rb +156 -1
- data/lib/rugged/version.rb +6 -1
- data/lib/rugged/walker.rb +5 -0
- data/lib/rugged.rb +5 -0
- data/vendor/libgit2/CMakeLists.txt +12 -2
- data/vendor/libgit2/include/git2/blob.h +39 -28
- data/vendor/libgit2/include/git2/commit.h +76 -0
- data/vendor/libgit2/include/git2/common.h +21 -1
- data/vendor/libgit2/include/git2/describe.h +5 -2
- data/vendor/libgit2/include/git2/diff.h +62 -7
- data/vendor/libgit2/include/git2/errors.h +2 -1
- data/vendor/libgit2/include/git2/index.h +25 -0
- data/vendor/libgit2/include/git2/merge.h +10 -1
- data/vendor/libgit2/include/git2/odb.h +47 -1
- data/vendor/libgit2/include/git2/pack.h +4 -4
- data/vendor/libgit2/include/git2/patch.h +1 -1
- data/vendor/libgit2/include/git2/proxy.h +92 -0
- data/vendor/libgit2/include/git2/refs.h +11 -0
- data/vendor/libgit2/include/git2/remote.h +21 -8
- data/vendor/libgit2/include/git2/repository.h +20 -1
- data/vendor/libgit2/include/git2/revwalk.h +4 -6
- data/vendor/libgit2/include/git2/signature.h +13 -0
- data/vendor/libgit2/include/git2/submodule.h +11 -3
- data/vendor/libgit2/include/git2/sys/merge.h +177 -0
- data/vendor/libgit2/include/git2/sys/odb_backend.h +11 -0
- data/vendor/libgit2/include/git2/sys/remote.h +16 -0
- data/vendor/libgit2/include/git2/sys/stream.h +2 -1
- data/vendor/libgit2/include/git2/sys/time.h +31 -0
- data/vendor/libgit2/include/git2/sys/transport.h +3 -1
- data/vendor/libgit2/include/git2/tag.h +9 -0
- data/vendor/libgit2/include/git2/transaction.h +9 -0
- data/vendor/libgit2/include/git2/tree.h +55 -0
- data/vendor/libgit2/include/git2/version.h +4 -4
- data/vendor/libgit2/include/git2.h +1 -0
- data/vendor/libgit2/src/annotated_commit.c +99 -80
- data/vendor/libgit2/src/annotated_commit.h +5 -2
- data/vendor/libgit2/src/apply.c +377 -0
- data/vendor/libgit2/src/apply.h +21 -0
- data/vendor/libgit2/src/array.h +0 -1
- data/vendor/libgit2/src/blob.c +71 -39
- data/vendor/libgit2/src/branch.c +7 -5
- data/vendor/libgit2/src/buffer.c +252 -20
- data/vendor/libgit2/src/buffer.h +8 -0
- data/vendor/libgit2/src/checkout.c +69 -42
- data/vendor/libgit2/src/clone.c +0 -8
- data/vendor/libgit2/src/commit.c +193 -49
- data/vendor/libgit2/src/commit_list.c +8 -3
- data/vendor/libgit2/src/commit_list.h +1 -0
- data/vendor/libgit2/src/common.h +2 -1
- data/vendor/libgit2/src/config.c +3 -3
- data/vendor/libgit2/src/config_file.c +20 -10
- data/vendor/libgit2/src/crlf.c +1 -0
- data/vendor/libgit2/src/curl_stream.c +106 -6
- data/vendor/libgit2/src/delta.c +238 -62
- data/vendor/libgit2/src/delta.h +79 -58
- data/vendor/libgit2/src/describe.c +1 -1
- data/vendor/libgit2/src/diff.c +32 -1554
- data/vendor/libgit2/src/diff.h +14 -122
- data/vendor/libgit2/src/diff_driver.c +4 -6
- data/vendor/libgit2/src/diff_file.c +3 -0
- data/vendor/libgit2/src/diff_generate.c +1613 -0
- data/vendor/libgit2/src/diff_generate.h +123 -0
- data/vendor/libgit2/src/diff_parse.c +101 -0
- data/vendor/libgit2/src/diff_parse.h +18 -0
- data/vendor/libgit2/src/diff_print.c +263 -144
- data/vendor/libgit2/src/diff_stats.c +21 -12
- data/vendor/libgit2/src/diff_tform.c +1 -0
- data/vendor/libgit2/src/diff_tform.h +22 -0
- data/vendor/libgit2/src/diff_xdiff.c +9 -9
- data/vendor/libgit2/src/diff_xdiff.h +5 -5
- data/vendor/libgit2/src/fetchhead.c +8 -8
- data/vendor/libgit2/src/filebuf.c +6 -1
- data/vendor/libgit2/src/filebuf.h +1 -0
- data/vendor/libgit2/src/fileops.c +22 -1
- data/vendor/libgit2/src/fileops.h +8 -2
- data/vendor/libgit2/src/fnmatch.c +18 -5
- data/vendor/libgit2/src/global.c +21 -4
- data/vendor/libgit2/src/global.h +6 -0
- data/vendor/libgit2/src/graph.c +1 -1
- data/vendor/libgit2/src/index.c +159 -46
- data/vendor/libgit2/src/index.h +2 -0
- data/vendor/libgit2/src/iterator.c +1573 -1468
- data/vendor/libgit2/src/iterator.h +52 -69
- data/vendor/libgit2/src/merge.c +163 -64
- data/vendor/libgit2/src/merge.h +61 -2
- data/vendor/libgit2/src/merge_driver.c +397 -0
- data/vendor/libgit2/src/merge_driver.h +60 -0
- data/vendor/libgit2/src/merge_file.c +11 -49
- data/vendor/libgit2/src/netops.c +12 -10
- data/vendor/libgit2/src/object_api.c +19 -1
- data/vendor/libgit2/src/odb.c +228 -52
- data/vendor/libgit2/src/odb_loose.c +19 -1
- data/vendor/libgit2/src/odb_mempack.c +1 -1
- data/vendor/libgit2/src/odb_pack.c +27 -1
- data/vendor/libgit2/src/openssl_stream.c +4 -5
- data/vendor/libgit2/src/pack-objects.c +105 -76
- data/vendor/libgit2/src/pack-objects.h +13 -12
- data/vendor/libgit2/src/pack.c +16 -10
- data/vendor/libgit2/src/pack.h +2 -0
- data/vendor/libgit2/src/patch.c +216 -0
- data/vendor/libgit2/src/patch.h +66 -0
- data/vendor/libgit2/src/{diff_patch.c → patch_generate.c} +203 -376
- data/vendor/libgit2/src/patch_generate.h +68 -0
- data/vendor/libgit2/src/patch_parse.c +1159 -0
- data/vendor/libgit2/src/patch_parse.h +56 -0
- data/vendor/libgit2/src/path.c +38 -2
- data/vendor/libgit2/src/path.h +18 -0
- data/vendor/libgit2/src/pathspec.c +1 -1
- data/vendor/libgit2/src/pool.h +5 -0
- data/vendor/libgit2/src/pqueue.c +12 -5
- data/vendor/libgit2/src/pqueue.h +1 -0
- data/vendor/libgit2/src/proxy.c +32 -0
- data/vendor/libgit2/src/proxy.h +14 -0
- data/vendor/libgit2/src/push.c +1 -1
- data/vendor/libgit2/src/rebase.c +63 -36
- data/vendor/libgit2/src/refdb.c +4 -2
- data/vendor/libgit2/src/refdb_fs.c +82 -54
- data/vendor/libgit2/src/refs.c +13 -1
- data/vendor/libgit2/src/remote.c +20 -81
- data/vendor/libgit2/src/repository.c +212 -29
- data/vendor/libgit2/src/reset.c +1 -1
- data/vendor/libgit2/src/revparse.c +1 -1
- data/vendor/libgit2/src/revwalk.c +260 -184
- data/vendor/libgit2/src/settings.c +11 -3
- data/vendor/libgit2/src/signature.c +27 -2
- data/vendor/libgit2/src/sortedcache.c +14 -5
- data/vendor/libgit2/src/stash.c +1 -0
- data/vendor/libgit2/src/status.c +1 -0
- data/vendor/libgit2/src/stransport_stream.c +4 -2
- data/vendor/libgit2/src/stream.h +2 -2
- data/vendor/libgit2/src/submodule.c +16 -4
- data/vendor/libgit2/src/sysdir.c +1 -1
- data/vendor/libgit2/src/transport.c +3 -5
- data/vendor/libgit2/src/transports/http.c +38 -13
- data/vendor/libgit2/src/transports/local.c +4 -1
- data/vendor/libgit2/src/transports/smart.c +6 -0
- data/vendor/libgit2/src/transports/smart.h +1 -0
- data/vendor/libgit2/src/transports/smart_pkt.c +5 -13
- data/vendor/libgit2/src/transports/smart_protocol.c +22 -7
- data/vendor/libgit2/src/transports/winhttp.c +144 -11
- data/vendor/libgit2/src/tree.c +267 -2
- data/vendor/libgit2/src/unix/posix.h +10 -0
- data/vendor/libgit2/src/unix/pthread.h +2 -0
- data/vendor/libgit2/src/util.c +25 -2
- data/vendor/libgit2/src/util.h +10 -0
- data/vendor/libgit2/src/varint.c +44 -0
- data/vendor/libgit2/src/varint.h +15 -0
- data/vendor/libgit2/src/vector.c +58 -0
- data/vendor/libgit2/src/vector.h +8 -0
- data/vendor/libgit2/src/win32/posix.h +3 -0
- data/vendor/libgit2/src/win32/thread.c +18 -0
- data/vendor/libgit2/src/win32/thread.h +2 -0
- data/vendor/libgit2/src/win32/w32_util.h +1 -1
- data/vendor/libgit2/src/zstream.c +37 -8
- data/vendor/libgit2/src/zstream.h +8 -1
- metadata +100 -82
- data/vendor/libgit2/Makefile.embed +0 -60
- data/vendor/libgit2/src/delta-apply.c +0 -166
- data/vendor/libgit2/src/delta-apply.h +0 -62
- data/vendor/libgit2/src/diff_patch.h +0 -83
@@ -0,0 +1,397 @@
|
|
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 "common.h"
|
9
|
+
#include "vector.h"
|
10
|
+
#include "global.h"
|
11
|
+
#include "merge.h"
|
12
|
+
#include "merge_driver.h"
|
13
|
+
#include "git2/merge.h"
|
14
|
+
#include "git2/sys/merge.h"
|
15
|
+
|
16
|
+
static const char *merge_driver_name__text = "text";
|
17
|
+
static const char *merge_driver_name__union = "union";
|
18
|
+
static const char *merge_driver_name__binary = "binary";
|
19
|
+
|
20
|
+
struct merge_driver_registry {
|
21
|
+
git_rwlock lock;
|
22
|
+
git_vector drivers;
|
23
|
+
};
|
24
|
+
|
25
|
+
typedef struct {
|
26
|
+
git_merge_driver *driver;
|
27
|
+
int initialized;
|
28
|
+
char name[GIT_FLEX_ARRAY];
|
29
|
+
} git_merge_driver_entry;
|
30
|
+
|
31
|
+
static struct merge_driver_registry merge_driver_registry;
|
32
|
+
|
33
|
+
static void git_merge_driver_global_shutdown(void);
|
34
|
+
|
35
|
+
|
36
|
+
int git_merge_driver__builtin_apply(
|
37
|
+
git_merge_driver *self,
|
38
|
+
const char **path_out,
|
39
|
+
uint32_t *mode_out,
|
40
|
+
git_buf *merged_out,
|
41
|
+
const char *filter_name,
|
42
|
+
const git_merge_driver_source *src)
|
43
|
+
{
|
44
|
+
git_merge_driver__builtin *driver = (git_merge_driver__builtin *)self;
|
45
|
+
git_merge_file_options file_opts = GIT_MERGE_FILE_OPTIONS_INIT;
|
46
|
+
git_merge_file_result result = {0};
|
47
|
+
int error;
|
48
|
+
|
49
|
+
GIT_UNUSED(filter_name);
|
50
|
+
|
51
|
+
if (src->file_opts)
|
52
|
+
memcpy(&file_opts, src->file_opts, sizeof(git_merge_file_options));
|
53
|
+
|
54
|
+
if (driver->favor)
|
55
|
+
file_opts.favor = driver->favor;
|
56
|
+
|
57
|
+
if ((error = git_merge_file_from_index(&result, src->repo,
|
58
|
+
src->ancestor, src->ours, src->theirs, &file_opts)) < 0)
|
59
|
+
goto done;
|
60
|
+
|
61
|
+
if (!result.automergeable &&
|
62
|
+
!(file_opts.flags & GIT_MERGE_FILE_FAVOR__CONFLICTED)) {
|
63
|
+
error = GIT_EMERGECONFLICT;
|
64
|
+
goto done;
|
65
|
+
}
|
66
|
+
|
67
|
+
*path_out = git_merge_file__best_path(
|
68
|
+
src->ancestor ? src->ancestor->path : NULL,
|
69
|
+
src->ours ? src->ours->path : NULL,
|
70
|
+
src->theirs ? src->theirs->path : NULL);
|
71
|
+
|
72
|
+
*mode_out = git_merge_file__best_mode(
|
73
|
+
src->ancestor ? src->ancestor->mode : 0,
|
74
|
+
src->ours ? src->ours->mode : 0,
|
75
|
+
src->theirs ? src->theirs->mode : 0);
|
76
|
+
|
77
|
+
merged_out->ptr = (char *)result.ptr;
|
78
|
+
merged_out->size = result.len;
|
79
|
+
merged_out->asize = result.len;
|
80
|
+
result.ptr = NULL;
|
81
|
+
|
82
|
+
done:
|
83
|
+
git_merge_file_result_free(&result);
|
84
|
+
return error;
|
85
|
+
}
|
86
|
+
|
87
|
+
static int merge_driver_binary_apply(
|
88
|
+
git_merge_driver *self,
|
89
|
+
const char **path_out,
|
90
|
+
uint32_t *mode_out,
|
91
|
+
git_buf *merged_out,
|
92
|
+
const char *filter_name,
|
93
|
+
const git_merge_driver_source *src)
|
94
|
+
{
|
95
|
+
GIT_UNUSED(self);
|
96
|
+
GIT_UNUSED(path_out);
|
97
|
+
GIT_UNUSED(mode_out);
|
98
|
+
GIT_UNUSED(merged_out);
|
99
|
+
GIT_UNUSED(filter_name);
|
100
|
+
GIT_UNUSED(src);
|
101
|
+
|
102
|
+
return GIT_EMERGECONFLICT;
|
103
|
+
}
|
104
|
+
|
105
|
+
static int merge_driver_entry_cmp(const void *a, const void *b)
|
106
|
+
{
|
107
|
+
const git_merge_driver_entry *entry_a = a;
|
108
|
+
const git_merge_driver_entry *entry_b = b;
|
109
|
+
|
110
|
+
return strcmp(entry_a->name, entry_b->name);
|
111
|
+
}
|
112
|
+
|
113
|
+
static int merge_driver_entry_search(const void *a, const void *b)
|
114
|
+
{
|
115
|
+
const char *name_a = a;
|
116
|
+
const git_merge_driver_entry *entry_b = b;
|
117
|
+
|
118
|
+
return strcmp(name_a, entry_b->name);
|
119
|
+
}
|
120
|
+
|
121
|
+
git_merge_driver__builtin git_merge_driver__text = {
|
122
|
+
{
|
123
|
+
GIT_MERGE_DRIVER_VERSION,
|
124
|
+
NULL,
|
125
|
+
NULL,
|
126
|
+
git_merge_driver__builtin_apply,
|
127
|
+
},
|
128
|
+
GIT_MERGE_FILE_FAVOR_NORMAL
|
129
|
+
};
|
130
|
+
|
131
|
+
git_merge_driver__builtin git_merge_driver__union = {
|
132
|
+
{
|
133
|
+
GIT_MERGE_DRIVER_VERSION,
|
134
|
+
NULL,
|
135
|
+
NULL,
|
136
|
+
git_merge_driver__builtin_apply,
|
137
|
+
},
|
138
|
+
GIT_MERGE_FILE_FAVOR_UNION
|
139
|
+
};
|
140
|
+
|
141
|
+
git_merge_driver git_merge_driver__binary = {
|
142
|
+
GIT_MERGE_DRIVER_VERSION,
|
143
|
+
NULL,
|
144
|
+
NULL,
|
145
|
+
merge_driver_binary_apply
|
146
|
+
};
|
147
|
+
|
148
|
+
/* Note: callers must lock the registry before calling this function */
|
149
|
+
static int merge_driver_registry_insert(
|
150
|
+
const char *name, git_merge_driver *driver)
|
151
|
+
{
|
152
|
+
git_merge_driver_entry *entry;
|
153
|
+
|
154
|
+
entry = git__calloc(1, sizeof(git_merge_driver_entry) + strlen(name) + 1);
|
155
|
+
GITERR_CHECK_ALLOC(entry);
|
156
|
+
|
157
|
+
strcpy(entry->name, name);
|
158
|
+
entry->driver = driver;
|
159
|
+
|
160
|
+
return git_vector_insert_sorted(
|
161
|
+
&merge_driver_registry.drivers, entry, NULL);
|
162
|
+
}
|
163
|
+
|
164
|
+
int git_merge_driver_global_init(void)
|
165
|
+
{
|
166
|
+
int error;
|
167
|
+
|
168
|
+
if (git_rwlock_init(&merge_driver_registry.lock) < 0)
|
169
|
+
return -1;
|
170
|
+
|
171
|
+
if ((error = git_vector_init(&merge_driver_registry.drivers, 3,
|
172
|
+
merge_driver_entry_cmp)) < 0)
|
173
|
+
goto done;
|
174
|
+
|
175
|
+
if ((error = merge_driver_registry_insert(
|
176
|
+
merge_driver_name__text, &git_merge_driver__text.base)) < 0 ||
|
177
|
+
(error = merge_driver_registry_insert(
|
178
|
+
merge_driver_name__union, &git_merge_driver__union.base)) < 0 ||
|
179
|
+
(error = merge_driver_registry_insert(
|
180
|
+
merge_driver_name__binary, &git_merge_driver__binary)) < 0)
|
181
|
+
goto done;
|
182
|
+
|
183
|
+
git__on_shutdown(git_merge_driver_global_shutdown);
|
184
|
+
|
185
|
+
done:
|
186
|
+
if (error < 0)
|
187
|
+
git_vector_free_deep(&merge_driver_registry.drivers);
|
188
|
+
|
189
|
+
return error;
|
190
|
+
}
|
191
|
+
|
192
|
+
static void git_merge_driver_global_shutdown(void)
|
193
|
+
{
|
194
|
+
git_merge_driver_entry *entry;
|
195
|
+
size_t i;
|
196
|
+
|
197
|
+
if (git_rwlock_wrlock(&merge_driver_registry.lock) < 0)
|
198
|
+
return;
|
199
|
+
|
200
|
+
git_vector_foreach(&merge_driver_registry.drivers, i, entry) {
|
201
|
+
if (entry->driver->shutdown)
|
202
|
+
entry->driver->shutdown(entry->driver);
|
203
|
+
|
204
|
+
git__free(entry);
|
205
|
+
}
|
206
|
+
|
207
|
+
git_vector_free(&merge_driver_registry.drivers);
|
208
|
+
|
209
|
+
git_rwlock_wrunlock(&merge_driver_registry.lock);
|
210
|
+
git_rwlock_free(&merge_driver_registry.lock);
|
211
|
+
}
|
212
|
+
|
213
|
+
/* Note: callers must lock the registry before calling this function */
|
214
|
+
static int merge_driver_registry_find(size_t *pos, const char *name)
|
215
|
+
{
|
216
|
+
return git_vector_search2(pos, &merge_driver_registry.drivers,
|
217
|
+
merge_driver_entry_search, name);
|
218
|
+
}
|
219
|
+
|
220
|
+
/* Note: callers must lock the registry before calling this function */
|
221
|
+
static git_merge_driver_entry *merge_driver_registry_lookup(
|
222
|
+
size_t *pos, const char *name)
|
223
|
+
{
|
224
|
+
git_merge_driver_entry *entry = NULL;
|
225
|
+
|
226
|
+
if (!merge_driver_registry_find(pos, name))
|
227
|
+
entry = git_vector_get(&merge_driver_registry.drivers, *pos);
|
228
|
+
|
229
|
+
return entry;
|
230
|
+
}
|
231
|
+
|
232
|
+
int git_merge_driver_register(const char *name, git_merge_driver *driver)
|
233
|
+
{
|
234
|
+
int error;
|
235
|
+
|
236
|
+
assert(name && driver);
|
237
|
+
|
238
|
+
if (git_rwlock_wrlock(&merge_driver_registry.lock) < 0) {
|
239
|
+
giterr_set(GITERR_OS, "failed to lock merge driver registry");
|
240
|
+
return -1;
|
241
|
+
}
|
242
|
+
|
243
|
+
if (!merge_driver_registry_find(NULL, name)) {
|
244
|
+
giterr_set(GITERR_MERGE, "attempt to reregister existing driver '%s'",
|
245
|
+
name);
|
246
|
+
error = GIT_EEXISTS;
|
247
|
+
goto done;
|
248
|
+
}
|
249
|
+
|
250
|
+
error = merge_driver_registry_insert(name, driver);
|
251
|
+
|
252
|
+
done:
|
253
|
+
git_rwlock_wrunlock(&merge_driver_registry.lock);
|
254
|
+
return error;
|
255
|
+
}
|
256
|
+
|
257
|
+
int git_merge_driver_unregister(const char *name)
|
258
|
+
{
|
259
|
+
git_merge_driver_entry *entry;
|
260
|
+
size_t pos;
|
261
|
+
int error = 0;
|
262
|
+
|
263
|
+
if (git_rwlock_wrlock(&merge_driver_registry.lock) < 0) {
|
264
|
+
giterr_set(GITERR_OS, "failed to lock merge driver registry");
|
265
|
+
return -1;
|
266
|
+
}
|
267
|
+
|
268
|
+
if ((entry = merge_driver_registry_lookup(&pos, name)) == NULL) {
|
269
|
+
giterr_set(GITERR_MERGE, "cannot find merge driver '%s' to unregister",
|
270
|
+
name);
|
271
|
+
error = GIT_ENOTFOUND;
|
272
|
+
goto done;
|
273
|
+
}
|
274
|
+
|
275
|
+
git_vector_remove(&merge_driver_registry.drivers, pos);
|
276
|
+
|
277
|
+
if (entry->initialized && entry->driver->shutdown) {
|
278
|
+
entry->driver->shutdown(entry->driver);
|
279
|
+
entry->initialized = false;
|
280
|
+
}
|
281
|
+
|
282
|
+
git__free(entry);
|
283
|
+
|
284
|
+
done:
|
285
|
+
git_rwlock_wrunlock(&merge_driver_registry.lock);
|
286
|
+
return error;
|
287
|
+
}
|
288
|
+
|
289
|
+
git_merge_driver *git_merge_driver_lookup(const char *name)
|
290
|
+
{
|
291
|
+
git_merge_driver_entry *entry;
|
292
|
+
size_t pos;
|
293
|
+
int error;
|
294
|
+
|
295
|
+
/* If we've decided the merge driver to use internally - and not
|
296
|
+
* based on user configuration (in merge_driver_name_for_path)
|
297
|
+
* then we can use a hardcoded name to compare instead of bothering
|
298
|
+
* to take a lock and look it up in the vector.
|
299
|
+
*/
|
300
|
+
if (name == merge_driver_name__text)
|
301
|
+
return &git_merge_driver__text.base;
|
302
|
+
else if (name == merge_driver_name__binary)
|
303
|
+
return &git_merge_driver__binary;
|
304
|
+
|
305
|
+
if (git_rwlock_rdlock(&merge_driver_registry.lock) < 0) {
|
306
|
+
giterr_set(GITERR_OS, "failed to lock merge driver registry");
|
307
|
+
return NULL;
|
308
|
+
}
|
309
|
+
|
310
|
+
entry = merge_driver_registry_lookup(&pos, name);
|
311
|
+
|
312
|
+
git_rwlock_rdunlock(&merge_driver_registry.lock);
|
313
|
+
|
314
|
+
if (entry == NULL) {
|
315
|
+
giterr_set(GITERR_MERGE, "cannot use an unregistered filter");
|
316
|
+
return NULL;
|
317
|
+
}
|
318
|
+
|
319
|
+
if (!entry->initialized) {
|
320
|
+
if (entry->driver->initialize &&
|
321
|
+
(error = entry->driver->initialize(entry->driver)) < 0)
|
322
|
+
return NULL;
|
323
|
+
|
324
|
+
entry->initialized = 1;
|
325
|
+
}
|
326
|
+
|
327
|
+
return entry->driver;
|
328
|
+
}
|
329
|
+
|
330
|
+
static int merge_driver_name_for_path(
|
331
|
+
const char **out,
|
332
|
+
git_repository *repo,
|
333
|
+
const char *path,
|
334
|
+
const char *default_driver)
|
335
|
+
{
|
336
|
+
const char *value;
|
337
|
+
int error;
|
338
|
+
|
339
|
+
*out = NULL;
|
340
|
+
|
341
|
+
if ((error = git_attr_get(&value, repo, 0, path, "merge")) < 0)
|
342
|
+
return error;
|
343
|
+
|
344
|
+
/* set: use the built-in 3-way merge driver ("text") */
|
345
|
+
if (GIT_ATTR_TRUE(value))
|
346
|
+
*out = merge_driver_name__text;
|
347
|
+
|
348
|
+
/* unset: do not merge ("binary") */
|
349
|
+
else if (GIT_ATTR_FALSE(value))
|
350
|
+
*out = merge_driver_name__binary;
|
351
|
+
|
352
|
+
else if (GIT_ATTR_UNSPECIFIED(value) && default_driver)
|
353
|
+
*out = default_driver;
|
354
|
+
|
355
|
+
else if (GIT_ATTR_UNSPECIFIED(value))
|
356
|
+
*out = merge_driver_name__text;
|
357
|
+
|
358
|
+
else
|
359
|
+
*out = value;
|
360
|
+
|
361
|
+
return 0;
|
362
|
+
}
|
363
|
+
|
364
|
+
|
365
|
+
GIT_INLINE(git_merge_driver *) merge_driver_lookup_with_wildcard(
|
366
|
+
const char *name)
|
367
|
+
{
|
368
|
+
git_merge_driver *driver = git_merge_driver_lookup(name);
|
369
|
+
|
370
|
+
if (driver == NULL)
|
371
|
+
driver = git_merge_driver_lookup("*");
|
372
|
+
|
373
|
+
return driver;
|
374
|
+
}
|
375
|
+
|
376
|
+
int git_merge_driver_for_source(
|
377
|
+
const char **name_out,
|
378
|
+
git_merge_driver **driver_out,
|
379
|
+
const git_merge_driver_source *src)
|
380
|
+
{
|
381
|
+
const char *path, *driver_name;
|
382
|
+
int error = 0;
|
383
|
+
|
384
|
+
path = git_merge_file__best_path(
|
385
|
+
src->ancestor ? src->ancestor->path : NULL,
|
386
|
+
src->ours ? src->ours->path : NULL,
|
387
|
+
src->theirs ? src->theirs->path : NULL);
|
388
|
+
|
389
|
+
if ((error = merge_driver_name_for_path(
|
390
|
+
&driver_name, src->repo, path, src->default_driver)) < 0)
|
391
|
+
return error;
|
392
|
+
|
393
|
+
*name_out = driver_name;
|
394
|
+
*driver_out = merge_driver_lookup_with_wildcard(driver_name);
|
395
|
+
return error;
|
396
|
+
}
|
397
|
+
|
@@ -0,0 +1,60 @@
|
|
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_merge_driver_h__
|
8
|
+
#define INCLUDE_merge_driver_h__
|
9
|
+
|
10
|
+
#include "git2/merge.h"
|
11
|
+
#include "git2/index.h"
|
12
|
+
#include "git2/sys/merge.h"
|
13
|
+
|
14
|
+
struct git_merge_driver_source {
|
15
|
+
git_repository *repo;
|
16
|
+
const char *default_driver;
|
17
|
+
const git_merge_file_options *file_opts;
|
18
|
+
|
19
|
+
const git_index_entry *ancestor;
|
20
|
+
const git_index_entry *ours;
|
21
|
+
const git_index_entry *theirs;
|
22
|
+
};
|
23
|
+
|
24
|
+
typedef struct git_merge_driver__builtin {
|
25
|
+
git_merge_driver base;
|
26
|
+
git_merge_file_favor_t favor;
|
27
|
+
} git_merge_driver__builtin;
|
28
|
+
|
29
|
+
extern int git_merge_driver_global_init(void);
|
30
|
+
|
31
|
+
extern int git_merge_driver_for_path(
|
32
|
+
char **name_out,
|
33
|
+
git_merge_driver **driver_out,
|
34
|
+
git_repository *repo,
|
35
|
+
const char *path);
|
36
|
+
|
37
|
+
/* Merge driver configuration */
|
38
|
+
extern int git_merge_driver_for_source(
|
39
|
+
const char **name_out,
|
40
|
+
git_merge_driver **driver_out,
|
41
|
+
const git_merge_driver_source *src);
|
42
|
+
|
43
|
+
extern int git_merge_driver__builtin_apply(
|
44
|
+
git_merge_driver *self,
|
45
|
+
const char **path_out,
|
46
|
+
uint32_t *mode_out,
|
47
|
+
git_buf *merged_out,
|
48
|
+
const char *filter_name,
|
49
|
+
const git_merge_driver_source *src);
|
50
|
+
|
51
|
+
/* Merge driver for text files, performs a standard three-way merge */
|
52
|
+
extern git_merge_driver__builtin git_merge_driver__text;
|
53
|
+
|
54
|
+
/* Merge driver for union-style merging */
|
55
|
+
extern git_merge_driver__builtin git_merge_driver__union;
|
56
|
+
|
57
|
+
/* Merge driver for unmergeable (binary) files: always produces conflicts */
|
58
|
+
extern git_merge_driver git_merge_driver__binary;
|
59
|
+
|
60
|
+
#endif
|
@@ -11,6 +11,7 @@
|
|
11
11
|
#include "fileops.h"
|
12
12
|
#include "index.h"
|
13
13
|
#include "diff_xdiff.h"
|
14
|
+
#include "merge.h"
|
14
15
|
|
15
16
|
#include "git2/repository.h"
|
16
17
|
#include "git2/object.h"
|
@@ -26,52 +27,6 @@
|
|
26
27
|
|
27
28
|
#define GIT_MERGE_FILE_SIDE_EXISTS(X) ((X)->mode != 0)
|
28
29
|
|
29
|
-
GIT_INLINE(const char *) merge_file_best_path(
|
30
|
-
const git_merge_file_input *ancestor,
|
31
|
-
const git_merge_file_input *ours,
|
32
|
-
const git_merge_file_input *theirs)
|
33
|
-
{
|
34
|
-
if (!ancestor) {
|
35
|
-
if (ours && theirs && strcmp(ours->path, theirs->path) == 0)
|
36
|
-
return ours->path;
|
37
|
-
|
38
|
-
return NULL;
|
39
|
-
}
|
40
|
-
|
41
|
-
if (ours && strcmp(ancestor->path, ours->path) == 0)
|
42
|
-
return theirs ? theirs->path : NULL;
|
43
|
-
else if(theirs && strcmp(ancestor->path, theirs->path) == 0)
|
44
|
-
return ours ? ours->path : NULL;
|
45
|
-
|
46
|
-
return NULL;
|
47
|
-
}
|
48
|
-
|
49
|
-
GIT_INLINE(int) merge_file_best_mode(
|
50
|
-
const git_merge_file_input *ancestor,
|
51
|
-
const git_merge_file_input *ours,
|
52
|
-
const git_merge_file_input *theirs)
|
53
|
-
{
|
54
|
-
/*
|
55
|
-
* If ancestor didn't exist and either ours or theirs is executable,
|
56
|
-
* assume executable. Otherwise, if any mode changed from the ancestor,
|
57
|
-
* use that one.
|
58
|
-
*/
|
59
|
-
if (!ancestor) {
|
60
|
-
if ((ours && ours->mode == GIT_FILEMODE_BLOB_EXECUTABLE) ||
|
61
|
-
(theirs && theirs->mode == GIT_FILEMODE_BLOB_EXECUTABLE))
|
62
|
-
return GIT_FILEMODE_BLOB_EXECUTABLE;
|
63
|
-
|
64
|
-
return GIT_FILEMODE_BLOB;
|
65
|
-
} else if (ours && theirs) {
|
66
|
-
if (ancestor->mode == ours->mode)
|
67
|
-
return theirs->mode;
|
68
|
-
|
69
|
-
return ours->mode;
|
70
|
-
}
|
71
|
-
|
72
|
-
return 0;
|
73
|
-
}
|
74
|
-
|
75
30
|
int git_merge_file__input_from_index(
|
76
31
|
git_merge_file_input *input_out,
|
77
32
|
git_odb_object **odb_object_out,
|
@@ -177,8 +132,12 @@ static int merge_file__xdiff(
|
|
177
132
|
goto done;
|
178
133
|
}
|
179
134
|
|
180
|
-
|
181
|
-
|
135
|
+
path = git_merge_file__best_path(
|
136
|
+
ancestor ? ancestor->path : NULL,
|
137
|
+
ours->path,
|
138
|
+
theirs->path);
|
139
|
+
|
140
|
+
if (path != NULL && (out->path = git__strdup(path)) == NULL) {
|
182
141
|
error = -1;
|
183
142
|
goto done;
|
184
143
|
}
|
@@ -186,7 +145,10 @@ static int merge_file__xdiff(
|
|
186
145
|
out->automergeable = (xdl_result == 0);
|
187
146
|
out->ptr = (const char *)mmbuffer.ptr;
|
188
147
|
out->len = mmbuffer.size;
|
189
|
-
out->mode =
|
148
|
+
out->mode = git_merge_file__best_mode(
|
149
|
+
ancestor ? ancestor->mode : 0,
|
150
|
+
ours->mode,
|
151
|
+
theirs->mode);
|
190
152
|
|
191
153
|
done:
|
192
154
|
if (error < 0)
|
data/vendor/libgit2/src/netops.c
CHANGED
@@ -257,16 +257,18 @@ int gitno_extract_url_parts(
|
|
257
257
|
*port = git__strdup(default_port);
|
258
258
|
GITERR_CHECK_ALLOC(*port);
|
259
259
|
|
260
|
-
if (
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
260
|
+
if (path) {
|
261
|
+
if (u.field_set & (1 << UF_PATH)) {
|
262
|
+
*path = git__substrdup(_path, u.field_data[UF_PATH].len);
|
263
|
+
GITERR_CHECK_ALLOC(*path);
|
264
|
+
} else {
|
265
|
+
git__free(*port);
|
266
|
+
*port = NULL;
|
267
|
+
git__free(*host);
|
268
|
+
*host = NULL;
|
269
|
+
giterr_set(GITERR_NET, "invalid url, missing path");
|
270
|
+
return GIT_EINVALIDSPEC;
|
271
|
+
}
|
270
272
|
}
|
271
273
|
|
272
274
|
if (u.field_set & (1 << UF_USERINFO)) {
|
@@ -15,7 +15,7 @@
|
|
15
15
|
#include "tag.h"
|
16
16
|
|
17
17
|
/**
|
18
|
-
*
|
18
|
+
* Commit
|
19
19
|
*/
|
20
20
|
int git_commit_lookup(git_commit **out, git_repository *repo, const git_oid *id)
|
21
21
|
{
|
@@ -42,6 +42,10 @@ git_repository *git_commit_owner(const git_commit *obj)
|
|
42
42
|
return git_object_owner((const git_object *)obj);
|
43
43
|
}
|
44
44
|
|
45
|
+
int git_commit_dup(git_commit **out, git_commit *obj)
|
46
|
+
{
|
47
|
+
return git_object_dup((git_object **)out, (git_object *)obj);
|
48
|
+
}
|
45
49
|
|
46
50
|
/**
|
47
51
|
* Tree
|
@@ -71,6 +75,10 @@ git_repository *git_tree_owner(const git_tree *obj)
|
|
71
75
|
return git_object_owner((const git_object *)obj);
|
72
76
|
}
|
73
77
|
|
78
|
+
int git_tree_dup(git_tree **out, git_tree *obj)
|
79
|
+
{
|
80
|
+
return git_object_dup((git_object **)out, (git_object *)obj);
|
81
|
+
}
|
74
82
|
|
75
83
|
/**
|
76
84
|
* Tag
|
@@ -100,6 +108,11 @@ git_repository *git_tag_owner(const git_tag *obj)
|
|
100
108
|
return git_object_owner((const git_object *)obj);
|
101
109
|
}
|
102
110
|
|
111
|
+
int git_tag_dup(git_tag **out, git_tag *obj)
|
112
|
+
{
|
113
|
+
return git_object_dup((git_object **)out, (git_object *)obj);
|
114
|
+
}
|
115
|
+
|
103
116
|
/**
|
104
117
|
* Blob
|
105
118
|
*/
|
@@ -127,3 +140,8 @@ git_repository *git_blob_owner(const git_blob *obj)
|
|
127
140
|
{
|
128
141
|
return git_object_owner((const git_object *)obj);
|
129
142
|
}
|
143
|
+
|
144
|
+
int git_blob_dup(git_blob **out, git_blob *obj)
|
145
|
+
{
|
146
|
+
return git_object_dup((git_object **)out, (git_object *)obj);
|
147
|
+
}
|