rugged 0.18.0.gh.de28323 → 0.19.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +9 -4
- data/Rakefile +1 -1
- data/ext/rugged/extconf.rb +10 -0
- data/ext/rugged/rugged.c +153 -86
- data/ext/rugged/rugged.h +44 -33
- data/ext/rugged/rugged_blob.c +288 -60
- data/ext/rugged/rugged_branch.c +82 -57
- data/ext/rugged/rugged_commit.c +83 -86
- data/ext/rugged/rugged_config.c +68 -68
- data/ext/rugged/rugged_diff.c +509 -0
- data/ext/rugged/rugged_diff_delta.c +94 -0
- data/ext/rugged/rugged_diff_hunk.c +100 -0
- data/ext/rugged/rugged_diff_line.c +79 -0
- data/ext/rugged/rugged_diff_patch.c +169 -0
- data/ext/rugged/rugged_index.c +539 -8
- data/ext/rugged/rugged_note.c +74 -80
- data/ext/rugged/rugged_object.c +63 -8
- data/ext/rugged/rugged_reference.c +231 -145
- data/ext/rugged/rugged_remote.c +509 -53
- data/ext/rugged/rugged_repo.c +572 -236
- data/ext/rugged/rugged_revwalk.c +59 -36
- data/ext/rugged/rugged_settings.c +7 -9
- data/ext/rugged/rugged_signature.c +7 -11
- data/ext/rugged/rugged_tag.c +93 -39
- data/ext/rugged/rugged_tree.c +321 -58
- data/lib/rugged.rb +1 -0
- data/lib/rugged/commit.rb +16 -1
- data/lib/rugged/console.rb +9 -0
- data/lib/rugged/diff.rb +19 -0
- data/lib/rugged/diff/delta.rb +54 -0
- data/lib/rugged/diff/hunk.rb +23 -0
- data/lib/rugged/diff/line.rb +29 -0
- data/lib/rugged/diff/patch.rb +28 -0
- data/lib/rugged/repository.rb +36 -39
- data/lib/rugged/version.rb +1 -1
- data/test/blob_test.rb +308 -1
- data/test/branch_test.rb +7 -0
- data/test/commit_test.rb +7 -10
- data/test/coverage/cover.rb +9 -1
- data/test/diff_test.rb +777 -0
- data/test/fixtures/archive.tar.gz +0 -0
- data/test/fixtures/attr/attr0 +1 -0
- data/test/fixtures/attr/attr1 +29 -0
- data/test/fixtures/attr/attr2 +21 -0
- data/test/fixtures/attr/attr3 +4 -0
- data/test/fixtures/attr/binfile +1 -0
- data/test/fixtures/attr/dir/file +0 -0
- data/test/fixtures/attr/file +1 -0
- data/test/fixtures/attr/gitattributes +29 -0
- data/test/fixtures/attr/gitignore +2 -0
- data/test/fixtures/attr/ign +1 -0
- data/test/fixtures/attr/macro_bad +1 -0
- data/test/fixtures/attr/macro_test +1 -0
- data/test/fixtures/attr/root_test1 +1 -0
- data/test/fixtures/attr/root_test2 +6 -0
- data/test/fixtures/attr/root_test3 +19 -0
- data/test/fixtures/attr/root_test4.txt +14 -0
- data/test/fixtures/attr/sub/abc +37 -0
- data/test/fixtures/attr/sub/dir/file +0 -0
- data/test/fixtures/attr/sub/file +1 -0
- data/test/fixtures/attr/sub/ign/file +1 -0
- data/test/fixtures/attr/sub/ign/sub/file +1 -0
- data/test/fixtures/attr/sub/sub/dir +0 -0
- data/test/fixtures/attr/sub/sub/file +1 -0
- data/test/fixtures/attr/sub/sub/subsub.txt +1 -0
- data/test/fixtures/attr/sub/subdir_test1 +2 -0
- data/test/fixtures/attr/sub/subdir_test2.txt +1 -0
- data/test/fixtures/diff/another.txt +38 -0
- data/test/fixtures/diff/readme.txt +36 -0
- data/test/fixtures/mergedrepo/conflicts-one.txt +5 -0
- data/test/fixtures/mergedrepo/conflicts-two.txt +5 -0
- data/test/fixtures/mergedrepo/one.txt +10 -0
- data/test/fixtures/mergedrepo/two.txt +12 -0
- data/test/fixtures/status/current_file +1 -0
- data/test/fixtures/status/ignored_file +1 -0
- data/test/fixtures/status/modified_file +2 -0
- data/test/fixtures/status/new_file +1 -0
- data/test/fixtures/status/staged_changes +2 -0
- data/test/fixtures/status/staged_changes_modified_file +3 -0
- data/test/fixtures/status/staged_delete_modified_file +1 -0
- data/test/fixtures/status/staged_new_file +1 -0
- data/test/fixtures/status/staged_new_file_modified_file +2 -0
- data/test/fixtures/status/subdir.txt +2 -0
- data/test/fixtures/status/subdir/current_file +1 -0
- data/test/fixtures/status/subdir/modified_file +2 -0
- data/test/fixtures/status/subdir/new_file +1 -0
- data/test/fixtures/status//350/277/231 +1 -0
- data/test/fixtures/testrepo.git/config +5 -0
- data/test/fixtures/testrepo.git/objects/77/71329dfa3002caf8c61a0ceb62a31d09023f37 +0 -0
- data/test/fixtures/text_file.md +464 -0
- data/test/fixtures/unsymlinked.git/HEAD +1 -0
- data/test/fixtures/unsymlinked.git/config +6 -0
- data/test/fixtures/unsymlinked.git/description +1 -0
- data/test/fixtures/unsymlinked.git/info/exclude +2 -0
- data/test/fixtures/unsymlinked.git/objects/08/8b64704e0d6b8bd061dea879418cb5442a3fbf +0 -0
- data/test/fixtures/unsymlinked.git/objects/13/a5e939bca25940c069fd2169d993dba328e30b +0 -0
- data/test/fixtures/unsymlinked.git/objects/19/bf568e59e3a0b363cafb4106226e62d4a4c41c +0 -0
- data/test/fixtures/unsymlinked.git/objects/58/1fadd35b4cf320d102a152f918729011604773 +0 -0
- data/test/fixtures/unsymlinked.git/objects/5c/87b6791e8b13da658a14d1ef7e09b5dc3bac8c +0 -0
- data/test/fixtures/unsymlinked.git/objects/6f/e5f5398af85fb3de8a6aba0339b6d3bfa26a27 +0 -0
- data/test/fixtures/unsymlinked.git/objects/7f/ccd75616ec188b8f1b23d67506a334cc34a49d +0 -0
- data/test/fixtures/unsymlinked.git/objects/80/6999882bf91d24241e4077906b9017605eb1f3 +0 -0
- data/test/fixtures/unsymlinked.git/objects/83/7d176303c5005505ec1e4a30231c40930c0230 +0 -0
- data/test/fixtures/unsymlinked.git/objects/a8/595ccca04f40818ae0155c8f9c77a230e597b6 +2 -0
- data/test/fixtures/unsymlinked.git/objects/cf/8f1cf5cce859c438d6cc067284cb5e161206e7 +0 -0
- data/test/fixtures/unsymlinked.git/objects/d5/278d05c8607ec420bfee4cf219fbc0eeebfd6a +0 -0
- data/test/fixtures/unsymlinked.git/objects/f4/e16fb76536591a41454194058d048d8e4dd2e9 +0 -0
- data/test/fixtures/unsymlinked.git/objects/f9/e65619d93fdf2673882e0a261c5e93b1a84006 +0 -0
- data/test/fixtures/unsymlinked.git/refs/heads/exe-file +1 -0
- data/test/fixtures/unsymlinked.git/refs/heads/master +1 -0
- data/test/fixtures/unsymlinked.git/refs/heads/reg-file +1 -0
- data/test/index_test.rb +120 -0
- data/test/reference_test.rb +38 -3
- data/test/remote_test.rb +224 -3
- data/test/repo_reset_test.rb +2 -0
- data/test/repo_test.rb +147 -10
- data/test/test_helper.rb +5 -2
- data/vendor/libgit2/include/git2/attr.h +3 -3
- data/vendor/libgit2/include/git2/blob.h +11 -17
- data/vendor/libgit2/include/git2/branch.h +3 -2
- data/vendor/libgit2/include/git2/checkout.h +7 -0
- data/vendor/libgit2/include/git2/clone.h +3 -0
- data/vendor/libgit2/include/git2/commit.h +61 -66
- data/vendor/libgit2/include/git2/common.h +73 -42
- data/vendor/libgit2/include/git2/config.h +57 -71
- data/vendor/libgit2/include/git2/cred_helpers.h +2 -2
- data/vendor/libgit2/include/git2/diff.h +179 -30
- data/vendor/libgit2/include/git2/errors.h +3 -3
- data/vendor/libgit2/include/git2/index.h +225 -146
- data/vendor/libgit2/include/git2/indexer.h +2 -22
- data/vendor/libgit2/include/git2/inttypes.h +9 -9
- data/vendor/libgit2/include/git2/merge.h +123 -5
- data/vendor/libgit2/include/git2/odb.h +59 -38
- data/vendor/libgit2/include/git2/odb_backend.h +45 -104
- data/vendor/libgit2/include/git2/oid.h +30 -19
- data/vendor/libgit2/include/git2/pack.h +21 -3
- data/vendor/libgit2/include/git2/refdb.h +0 -35
- data/vendor/libgit2/include/git2/refs.h +93 -31
- data/vendor/libgit2/include/git2/refspec.h +17 -0
- data/vendor/libgit2/include/git2/remote.h +60 -20
- data/vendor/libgit2/include/git2/repository.h +48 -70
- data/vendor/libgit2/include/git2/reset.h +3 -3
- data/vendor/libgit2/include/git2/revparse.h +22 -0
- data/vendor/libgit2/include/git2/stash.h +1 -1
- data/vendor/libgit2/include/git2/status.h +131 -56
- data/vendor/libgit2/include/git2/strarray.h +2 -2
- data/vendor/libgit2/include/git2/submodule.h +16 -16
- data/vendor/libgit2/include/git2/sys/commit.h +46 -0
- data/vendor/libgit2/include/git2/sys/config.h +71 -0
- data/vendor/libgit2/include/git2/sys/index.h +179 -0
- data/vendor/libgit2/include/git2/sys/odb_backend.h +86 -0
- data/vendor/libgit2/include/git2/sys/refdb_backend.h +158 -0
- data/vendor/libgit2/include/git2/sys/refs.h +38 -0
- data/vendor/libgit2/include/git2/sys/repository.h +106 -0
- data/vendor/libgit2/include/git2/tag.h +44 -18
- data/vendor/libgit2/include/git2/trace.h +1 -2
- data/vendor/libgit2/include/git2/transport.h +74 -0
- data/vendor/libgit2/include/git2/tree.h +12 -22
- data/vendor/libgit2/include/git2/types.h +33 -0
- data/vendor/libgit2/include/git2/version.h +2 -2
- data/vendor/libgit2/src/array.h +66 -0
- data/vendor/libgit2/src/attr.c +26 -13
- data/vendor/libgit2/src/attr_file.c +3 -2
- data/vendor/libgit2/src/attr_file.h +3 -3
- data/vendor/libgit2/src/attrcache.h +4 -4
- data/vendor/libgit2/src/blob.c +13 -9
- data/vendor/libgit2/src/blob.h +2 -2
- data/vendor/libgit2/src/branch.c +67 -49
- data/vendor/libgit2/src/cache.c +224 -54
- data/vendor/libgit2/src/cache.h +33 -20
- data/vendor/libgit2/src/checkout.c +145 -85
- data/vendor/libgit2/src/clone.c +62 -50
- data/vendor/libgit2/src/commit.c +74 -40
- data/vendor/libgit2/src/commit.h +2 -3
- data/vendor/libgit2/src/commit_list.c +14 -8
- data/vendor/libgit2/src/config.c +119 -36
- data/vendor/libgit2/src/config.h +3 -0
- data/vendor/libgit2/src/config_cache.c +24 -7
- data/vendor/libgit2/src/config_file.c +9 -6
- data/vendor/libgit2/src/crlf.c +4 -2
- data/vendor/libgit2/src/date.c +3 -3
- data/vendor/libgit2/src/delta.c +1 -1
- data/vendor/libgit2/src/diff.c +681 -303
- data/vendor/libgit2/src/diff.h +34 -2
- data/vendor/libgit2/src/diff_driver.c +405 -0
- data/vendor/libgit2/src/diff_driver.h +49 -0
- data/vendor/libgit2/src/diff_file.c +447 -0
- data/vendor/libgit2/src/diff_file.h +58 -0
- data/vendor/libgit2/src/diff_patch.c +995 -0
- data/vendor/libgit2/src/diff_patch.h +46 -0
- data/vendor/libgit2/src/diff_print.c +430 -0
- data/vendor/libgit2/src/diff_tform.c +464 -203
- data/vendor/libgit2/src/diff_xdiff.c +166 -0
- data/vendor/libgit2/src/diff_xdiff.h +28 -0
- data/vendor/libgit2/src/fetch.c +11 -4
- data/vendor/libgit2/src/fileops.c +85 -61
- data/vendor/libgit2/src/fileops.h +4 -0
- data/vendor/libgit2/src/global.c +10 -2
- data/vendor/libgit2/src/global.h +0 -8
- data/vendor/libgit2/src/hash/hash_generic.h +3 -3
- data/vendor/libgit2/src/hash/hash_win32.h +4 -4
- data/vendor/libgit2/src/hashsig.c +0 -1
- data/vendor/libgit2/src/ignore.c +68 -28
- data/vendor/libgit2/src/ignore.h +10 -1
- data/vendor/libgit2/src/index.c +666 -84
- data/vendor/libgit2/src/index.h +6 -0
- data/vendor/libgit2/src/indexer.c +10 -28
- data/vendor/libgit2/src/iterator.c +427 -283
- data/vendor/libgit2/src/iterator.h +58 -4
- data/vendor/libgit2/src/merge.c +1892 -32
- data/vendor/libgit2/src/merge.h +132 -5
- data/vendor/libgit2/src/merge_file.c +174 -0
- data/vendor/libgit2/src/merge_file.h +71 -0
- data/vendor/libgit2/src/mwindow.c +1 -1
- data/vendor/libgit2/src/notes.c +45 -48
- data/vendor/libgit2/src/object.c +89 -127
- data/vendor/libgit2/src/object.h +0 -1
- data/vendor/libgit2/src/object_api.c +129 -0
- data/vendor/libgit2/src/odb.c +156 -59
- data/vendor/libgit2/src/odb.h +5 -2
- data/vendor/libgit2/src/odb_loose.c +31 -17
- data/vendor/libgit2/src/odb_pack.c +39 -43
- data/vendor/libgit2/src/oid.c +62 -27
- data/vendor/libgit2/src/oid.h +33 -0
- data/vendor/libgit2/src/oidmap.h +4 -6
- data/vendor/libgit2/src/pack-objects.c +54 -22
- data/vendor/libgit2/src/pack.c +98 -56
- data/vendor/libgit2/src/pack.h +3 -1
- data/vendor/libgit2/src/pathspec.c +26 -1
- data/vendor/libgit2/src/pathspec.h +14 -0
- data/vendor/libgit2/src/pool.c +5 -0
- data/vendor/libgit2/src/posix.c +2 -2
- data/vendor/libgit2/src/posix.h +3 -0
- data/vendor/libgit2/src/push.c +13 -10
- data/vendor/libgit2/src/refdb.c +82 -62
- data/vendor/libgit2/src/refdb.h +16 -16
- data/vendor/libgit2/src/refdb_fs.c +386 -133
- data/vendor/libgit2/src/reflog.c +3 -1
- data/vendor/libgit2/src/refs.c +247 -221
- data/vendor/libgit2/src/refs.h +2 -1
- data/vendor/libgit2/src/refspec.c +18 -1
- data/vendor/libgit2/src/refspec.h +3 -1
- data/vendor/libgit2/src/remote.c +434 -253
- data/vendor/libgit2/src/remote.h +5 -3
- data/vendor/libgit2/src/repository.c +197 -111
- data/vendor/libgit2/src/repository.h +26 -5
- data/vendor/libgit2/src/reset.c +1 -1
- data/vendor/libgit2/src/revparse.c +84 -79
- data/vendor/libgit2/src/revwalk.c +1 -1
- data/vendor/libgit2/src/signature.c +22 -10
- data/vendor/libgit2/src/stash.c +5 -2
- data/vendor/libgit2/src/status.c +311 -107
- data/vendor/libgit2/src/status.h +23 -0
- data/vendor/libgit2/src/submodule.c +21 -13
- data/vendor/libgit2/src/tag.c +42 -31
- data/vendor/libgit2/src/tag.h +2 -3
- data/vendor/libgit2/src/thread-utils.h +105 -3
- data/vendor/libgit2/src/trace.c +1 -2
- data/vendor/libgit2/src/trace.h +3 -3
- data/vendor/libgit2/src/transport.c +18 -6
- data/vendor/libgit2/src/transports/cred.c +103 -1
- data/vendor/libgit2/src/transports/local.c +19 -9
- data/vendor/libgit2/src/transports/smart_protocol.c +32 -12
- data/vendor/libgit2/src/transports/ssh.c +519 -0
- data/vendor/libgit2/src/transports/winhttp.c +3 -1
- data/vendor/libgit2/src/tree.c +26 -28
- data/vendor/libgit2/src/tree.h +3 -3
- data/vendor/libgit2/src/unix/posix.h +2 -0
- data/vendor/libgit2/src/util.c +43 -6
- data/vendor/libgit2/src/util.h +40 -12
- data/vendor/libgit2/src/vector.c +3 -5
- data/vendor/libgit2/src/vector.h +9 -0
- data/vendor/libgit2/src/win32/dir.c +1 -1
- data/vendor/libgit2/src/win32/error.c +2 -0
- data/vendor/libgit2/src/win32/findfile.c +3 -6
- data/vendor/libgit2/src/win32/posix_w32.c +85 -59
- data/vendor/libgit2/src/win32/pthread.c +16 -8
- data/vendor/libgit2/src/win32/pthread.h +7 -4
- metadata +407 -306
- data/test/coverage/HEAD.json +0 -1
- data/vendor/libgit2/include/git2/refdb_backend.h +0 -109
- data/vendor/libgit2/src/diff_output.c +0 -1819
- data/vendor/libgit2/src/diff_output.h +0 -93
data/vendor/libgit2/src/branch.c
CHANGED
@@ -11,6 +11,7 @@
|
|
11
11
|
#include "config.h"
|
12
12
|
#include "refspec.h"
|
13
13
|
#include "refs.h"
|
14
|
+
#include "remote.h"
|
14
15
|
|
15
16
|
#include "git2/branch.h"
|
16
17
|
|
@@ -123,40 +124,48 @@ on_error:
|
|
123
124
|
return error;
|
124
125
|
}
|
125
126
|
|
126
|
-
typedef struct {
|
127
|
-
git_branch_foreach_cb branch_cb;
|
128
|
-
void *callback_payload;
|
129
|
-
unsigned int branch_type;
|
130
|
-
} branch_foreach_filter;
|
131
|
-
|
132
|
-
static int branch_foreach_cb(const char *branch_name, void *payload)
|
133
|
-
{
|
134
|
-
branch_foreach_filter *filter = (branch_foreach_filter *)payload;
|
135
|
-
|
136
|
-
if (filter->branch_type & GIT_BRANCH_LOCAL &&
|
137
|
-
git__prefixcmp(branch_name, GIT_REFS_HEADS_DIR) == 0)
|
138
|
-
return filter->branch_cb(branch_name + strlen(GIT_REFS_HEADS_DIR), GIT_BRANCH_LOCAL, filter->callback_payload);
|
139
|
-
|
140
|
-
if (filter->branch_type & GIT_BRANCH_REMOTE &&
|
141
|
-
git__prefixcmp(branch_name, GIT_REFS_REMOTES_DIR) == 0)
|
142
|
-
return filter->branch_cb(branch_name + strlen(GIT_REFS_REMOTES_DIR), GIT_BRANCH_REMOTE, filter->callback_payload);
|
143
|
-
|
144
|
-
return 0;
|
145
|
-
}
|
146
|
-
|
147
127
|
int git_branch_foreach(
|
148
128
|
git_repository *repo,
|
149
129
|
unsigned int list_flags,
|
150
|
-
git_branch_foreach_cb
|
130
|
+
git_branch_foreach_cb callback,
|
151
131
|
void *payload)
|
152
132
|
{
|
153
|
-
|
133
|
+
git_reference_iterator *iter;
|
134
|
+
git_reference *ref;
|
135
|
+
int error = 0;
|
136
|
+
|
137
|
+
if (git_reference_iterator_new(&iter, repo) < 0)
|
138
|
+
return -1;
|
139
|
+
|
140
|
+
while ((error = git_reference_next(&ref, iter)) == 0) {
|
141
|
+
if (list_flags & GIT_BRANCH_LOCAL &&
|
142
|
+
git__prefixcmp(ref->name, GIT_REFS_HEADS_DIR) == 0) {
|
143
|
+
if (callback(ref->name + strlen(GIT_REFS_HEADS_DIR),
|
144
|
+
GIT_BRANCH_LOCAL, payload)) {
|
145
|
+
error = GIT_EUSER;
|
146
|
+
}
|
147
|
+
}
|
148
|
+
|
149
|
+
if (list_flags & GIT_BRANCH_REMOTE &&
|
150
|
+
git__prefixcmp(ref->name, GIT_REFS_REMOTES_DIR) == 0) {
|
151
|
+
if (callback(ref->name + strlen(GIT_REFS_REMOTES_DIR),
|
152
|
+
GIT_BRANCH_REMOTE, payload)) {
|
153
|
+
error = GIT_EUSER;
|
154
|
+
}
|
155
|
+
}
|
156
|
+
|
157
|
+
git_reference_free(ref);
|
154
158
|
|
155
|
-
|
156
|
-
|
157
|
-
|
159
|
+
/* check if the callback has cancelled iteration */
|
160
|
+
if (error == GIT_EUSER)
|
161
|
+
break;
|
162
|
+
}
|
163
|
+
|
164
|
+
if (error == GIT_ITEROVER)
|
165
|
+
error = 0;
|
158
166
|
|
159
|
-
|
167
|
+
git_reference_iterator_free(iter);
|
168
|
+
return error;
|
160
169
|
}
|
161
170
|
|
162
171
|
int git_branch_move(
|
@@ -175,18 +184,21 @@ int git_branch_move(
|
|
175
184
|
if (!git_reference_is_branch(branch))
|
176
185
|
return not_a_local_branch(git_reference_name(branch));
|
177
186
|
|
178
|
-
|
179
|
-
|
180
|
-
(error = git_buf_printf(&new_config_section, "branch.%s", new_branch_name)) < 0)
|
187
|
+
error = git_buf_joinpath(&new_reference_name, GIT_REFS_HEADS_DIR, new_branch_name);
|
188
|
+
if (error < 0)
|
181
189
|
goto done;
|
182
190
|
|
191
|
+
git_buf_printf(&old_config_section,
|
192
|
+
"branch.%s", git_reference_name(branch) + strlen(GIT_REFS_HEADS_DIR));
|
193
|
+
|
194
|
+
git_buf_printf(&new_config_section, "branch.%s", new_branch_name);
|
195
|
+
|
183
196
|
if ((error = git_config_rename_section(git_reference_owner(branch),
|
184
197
|
git_buf_cstr(&old_config_section),
|
185
198
|
git_buf_cstr(&new_config_section))) < 0)
|
186
199
|
goto done;
|
187
|
-
|
188
|
-
|
189
|
-
goto done;
|
200
|
+
|
201
|
+
error = git_reference_rename(out, branch, git_buf_cstr(&new_reference_name), force);
|
190
202
|
|
191
203
|
done:
|
192
204
|
git_buf_free(&new_reference_name);
|
@@ -275,6 +287,8 @@ int git_branch_upstream__name(
|
|
275
287
|
goto cleanup;
|
276
288
|
|
277
289
|
if (!*remote_name || !*merge_name) {
|
290
|
+
giterr_set(GITERR_REFERENCE,
|
291
|
+
"branch '%s' does not have an upstream", canonical_branch_name);
|
278
292
|
error = GIT_ENOTFOUND;
|
279
293
|
goto cleanup;
|
280
294
|
}
|
@@ -283,12 +297,10 @@ int git_branch_upstream__name(
|
|
283
297
|
if ((error = git_remote_load(&remote, repo, remote_name)) < 0)
|
284
298
|
goto cleanup;
|
285
299
|
|
286
|
-
refspec =
|
287
|
-
if (refspec
|
288
|
-
|
289
|
-
|
290
|
-
error = GIT_ENOTFOUND;
|
291
|
-
goto cleanup;
|
300
|
+
refspec = git_remote__matching_refspec(remote, merge_name);
|
301
|
+
if (!refspec) {
|
302
|
+
error = GIT_ENOTFOUND;
|
303
|
+
goto cleanup;
|
292
304
|
}
|
293
305
|
|
294
306
|
if (git_refspec_transform_r(&buf, refspec, merge_name) < 0)
|
@@ -333,11 +345,8 @@ static int remote_name(git_buf *buf, git_repository *repo, const char *canonical
|
|
333
345
|
if ((error = git_remote_load(&remote, repo, remote_list.strings[i])) < 0)
|
334
346
|
continue;
|
335
347
|
|
336
|
-
fetchspec =
|
337
|
-
|
338
|
-
/* Defensivly check that we have a fetchspec */
|
339
|
-
if (fetchspec &&
|
340
|
-
git_refspec_dst_matches(fetchspec, canonical_branch_name)) {
|
348
|
+
fetchspec = git_remote__matching_dst_refspec(remote, canonical_branch_name);
|
349
|
+
if (fetchspec) {
|
341
350
|
/* If we have not already set out yet, then set
|
342
351
|
* it to the matching remote name. Otherwise
|
343
352
|
* multiple remotes match this reference, and it
|
@@ -346,6 +355,9 @@ static int remote_name(git_buf *buf, git_repository *repo, const char *canonical
|
|
346
355
|
remote_name = remote_list.strings[i];
|
347
356
|
} else {
|
348
357
|
git_remote_free(remote);
|
358
|
+
|
359
|
+
giterr_set(GITERR_REFERENCE,
|
360
|
+
"Reference '%s' is ambiguous", canonical_branch_name);
|
349
361
|
error = GIT_EAMBIGUOUS;
|
350
362
|
goto cleanup;
|
351
363
|
}
|
@@ -358,6 +370,8 @@ static int remote_name(git_buf *buf, git_repository *repo, const char *canonical
|
|
358
370
|
git_buf_clear(buf);
|
359
371
|
error = git_buf_puts(buf, remote_name);
|
360
372
|
} else {
|
373
|
+
giterr_set(GITERR_REFERENCE,
|
374
|
+
"Could not determine remote for '%s'", canonical_branch_name);
|
361
375
|
error = GIT_ENOTFOUND;
|
362
376
|
}
|
363
377
|
|
@@ -377,7 +391,7 @@ int git_branch_remote_name(char *buffer, size_t buffer_len, git_repository *repo
|
|
377
391
|
if (buffer)
|
378
392
|
git_buf_copy_cstr(buffer, buffer_len, &buf);
|
379
393
|
|
380
|
-
ret = git_buf_len(&buf) + 1;
|
394
|
+
ret = (int)git_buf_len(&buf) + 1;
|
381
395
|
git_buf_free(&buf);
|
382
396
|
|
383
397
|
return ret;
|
@@ -494,8 +508,11 @@ int git_branch_set_upstream(git_reference *branch, const char *upstream_name)
|
|
494
508
|
local = 1;
|
495
509
|
else if (git_branch_lookup(&upstream, repo, upstream_name, GIT_BRANCH_REMOTE) == 0)
|
496
510
|
local = 0;
|
497
|
-
else
|
511
|
+
else {
|
512
|
+
giterr_set(GITERR_REFERENCE,
|
513
|
+
"Cannot set upstream for branch '%s'", shortname);
|
498
514
|
return GIT_ENOTFOUND;
|
515
|
+
}
|
499
516
|
|
500
517
|
/*
|
501
518
|
* If it's local, the remote is "." and the branch name is
|
@@ -515,16 +532,17 @@ int git_branch_set_upstream(git_reference *branch, const char *upstream_name)
|
|
515
532
|
goto on_error;
|
516
533
|
|
517
534
|
if (local) {
|
518
|
-
|
535
|
+
git_buf_clear(&value);
|
536
|
+
if (git_buf_puts(&value, git_reference_name(upstream)) < 0)
|
519
537
|
goto on_error;
|
520
538
|
} else {
|
521
539
|
/* Get the remoe-tracking branch's refname in its repo */
|
522
540
|
if (git_remote_load(&remote, repo, git_buf_cstr(&value)) < 0)
|
523
541
|
goto on_error;
|
524
542
|
|
525
|
-
fetchspec =
|
543
|
+
fetchspec = git_remote__matching_dst_refspec(remote, git_reference_name(upstream));
|
526
544
|
git_buf_clear(&value);
|
527
|
-
if (git_refspec_transform_l(&value, fetchspec, git_reference_name(upstream)) < 0)
|
545
|
+
if (!fetchspec || git_refspec_transform_l(&value, fetchspec, git_reference_name(upstream)) < 0)
|
528
546
|
goto on_error;
|
529
547
|
|
530
548
|
git_remote_free(remote);
|
data/vendor/libgit2/src/cache.c
CHANGED
@@ -11,100 +11,270 @@
|
|
11
11
|
#include "thread-utils.h"
|
12
12
|
#include "util.h"
|
13
13
|
#include "cache.h"
|
14
|
+
#include "odb.h"
|
15
|
+
#include "object.h"
|
14
16
|
#include "git2/oid.h"
|
15
17
|
|
16
|
-
|
18
|
+
GIT__USE_OIDMAP
|
19
|
+
|
20
|
+
bool git_cache__enabled = true;
|
21
|
+
ssize_t git_cache__max_storage = (256 * 1024 * 1024);
|
22
|
+
git_atomic_ssize git_cache__current_storage = {0};
|
23
|
+
|
24
|
+
static size_t git_cache__max_object_size[8] = {
|
25
|
+
0, /* GIT_OBJ__EXT1 */
|
26
|
+
4096, /* GIT_OBJ_COMMIT */
|
27
|
+
4096, /* GIT_OBJ_TREE */
|
28
|
+
0, /* GIT_OBJ_BLOB */
|
29
|
+
4096, /* GIT_OBJ_TAG */
|
30
|
+
0, /* GIT_OBJ__EXT2 */
|
31
|
+
0, /* GIT_OBJ_OFS_DELTA */
|
32
|
+
0 /* GIT_OBJ_REF_DELTA */
|
33
|
+
};
|
34
|
+
|
35
|
+
int git_cache_set_max_object_size(git_otype type, size_t size)
|
36
|
+
{
|
37
|
+
if (type < 0 || (size_t)type >= ARRAY_SIZE(git_cache__max_object_size)) {
|
38
|
+
giterr_set(GITERR_INVALID, "type out of range");
|
39
|
+
return -1;
|
40
|
+
}
|
41
|
+
|
42
|
+
git_cache__max_object_size[type] = size;
|
43
|
+
return 0;
|
44
|
+
}
|
45
|
+
|
46
|
+
void git_cache_dump_stats(git_cache *cache)
|
17
47
|
{
|
18
|
-
|
19
|
-
size = 8;
|
20
|
-
size = git__size_t_powerof2(size);
|
48
|
+
git_cached_obj *object;
|
21
49
|
|
22
|
-
cache->
|
23
|
-
|
24
|
-
cache->free_obj = free_ptr;
|
50
|
+
if (kh_size(cache->map) == 0)
|
51
|
+
return;
|
25
52
|
|
26
|
-
|
53
|
+
printf("Cache %p: %d items cached, %d bytes\n",
|
54
|
+
cache, kh_size(cache->map), (int)cache->used_memory);
|
27
55
|
|
28
|
-
cache->
|
29
|
-
|
56
|
+
kh_foreach_value(cache->map, object, {
|
57
|
+
char oid_str[9];
|
58
|
+
printf(" %s%c %s (%d)\n",
|
59
|
+
git_object_type2string(object->type),
|
60
|
+
object->flags == GIT_CACHE_STORE_PARSED ? '*' : ' ',
|
61
|
+
git_oid_tostr(oid_str, sizeof(oid_str), &object->oid),
|
62
|
+
(int)object->size
|
63
|
+
);
|
64
|
+
});
|
65
|
+
}
|
30
66
|
|
31
|
-
|
67
|
+
int git_cache_init(git_cache *cache)
|
68
|
+
{
|
69
|
+
memset(cache, 0, sizeof(*cache));
|
70
|
+
cache->map = git_oidmap_alloc();
|
71
|
+
if (git_mutex_init(&cache->lock)) {
|
72
|
+
giterr_set(GITERR_OS, "Failed to initialize cache mutex");
|
73
|
+
return -1;
|
74
|
+
}
|
32
75
|
return 0;
|
33
76
|
}
|
34
77
|
|
78
|
+
/* called with lock */
|
79
|
+
static void clear_cache(git_cache *cache)
|
80
|
+
{
|
81
|
+
git_cached_obj *evict = NULL;
|
82
|
+
|
83
|
+
if (kh_size(cache->map) == 0)
|
84
|
+
return;
|
85
|
+
|
86
|
+
kh_foreach_value(cache->map, evict, {
|
87
|
+
git_cached_obj_decref(evict);
|
88
|
+
});
|
89
|
+
|
90
|
+
kh_clear(oid, cache->map);
|
91
|
+
git_atomic_ssize_add(&git_cache__current_storage, -cache->used_memory);
|
92
|
+
cache->used_memory = 0;
|
93
|
+
}
|
94
|
+
|
95
|
+
void git_cache_clear(git_cache *cache)
|
96
|
+
{
|
97
|
+
if (git_mutex_lock(&cache->lock) < 0)
|
98
|
+
return;
|
99
|
+
|
100
|
+
clear_cache(cache);
|
101
|
+
|
102
|
+
git_mutex_unlock(&cache->lock);
|
103
|
+
}
|
104
|
+
|
35
105
|
void git_cache_free(git_cache *cache)
|
36
106
|
{
|
37
|
-
|
107
|
+
git_cache_clear(cache);
|
108
|
+
git_oidmap_free(cache->map);
|
109
|
+
git_mutex_free(&cache->lock);
|
110
|
+
git__memzero(cache, sizeof(*cache));
|
111
|
+
}
|
112
|
+
|
113
|
+
/* Called with lock */
|
114
|
+
static void cache_evict_entries(git_cache *cache)
|
115
|
+
{
|
116
|
+
uint32_t seed = rand();
|
117
|
+
size_t evict_count = 8;
|
118
|
+
ssize_t evicted_memory = 0;
|
38
119
|
|
39
|
-
|
40
|
-
|
41
|
-
|
120
|
+
/* do not infinite loop if there's not enough entries to evict */
|
121
|
+
if (evict_count > kh_size(cache->map)) {
|
122
|
+
clear_cache(cache);
|
123
|
+
return;
|
42
124
|
}
|
43
125
|
|
44
|
-
|
45
|
-
|
126
|
+
while (evict_count > 0) {
|
127
|
+
khiter_t pos = seed++ % kh_end(cache->map);
|
128
|
+
|
129
|
+
if (kh_exist(cache->map, pos)) {
|
130
|
+
git_cached_obj *evict = kh_val(cache->map, pos);
|
131
|
+
|
132
|
+
evict_count--;
|
133
|
+
evicted_memory += evict->size;
|
134
|
+
git_cached_obj_decref(evict);
|
135
|
+
|
136
|
+
kh_del(oid, cache->map, pos);
|
137
|
+
}
|
138
|
+
}
|
139
|
+
|
140
|
+
cache->used_memory -= evicted_memory;
|
141
|
+
git_atomic_ssize_add(&git_cache__current_storage, -evicted_memory);
|
46
142
|
}
|
47
143
|
|
48
|
-
|
144
|
+
static bool cache_should_store(git_otype object_type, size_t object_size)
|
49
145
|
{
|
50
|
-
|
51
|
-
|
146
|
+
size_t max_size = git_cache__max_object_size[object_type];
|
147
|
+
return git_cache__enabled && object_size < max_size;
|
148
|
+
}
|
52
149
|
|
53
|
-
|
150
|
+
static void *cache_get(git_cache *cache, const git_oid *oid, unsigned int flags)
|
151
|
+
{
|
152
|
+
khiter_t pos;
|
153
|
+
git_cached_obj *entry = NULL;
|
54
154
|
|
55
|
-
if (git_mutex_lock(&cache->lock))
|
56
|
-
giterr_set(GITERR_THREAD, "unable to lock cache mutex");
|
155
|
+
if (!git_cache__enabled || git_mutex_lock(&cache->lock) < 0)
|
57
156
|
return NULL;
|
58
|
-
}
|
59
157
|
|
60
|
-
|
61
|
-
|
158
|
+
pos = kh_get(oid, cache->map, oid);
|
159
|
+
if (pos != kh_end(cache->map)) {
|
160
|
+
entry = kh_val(cache->map, pos);
|
62
161
|
|
63
|
-
if (
|
64
|
-
|
65
|
-
|
162
|
+
if (flags && entry->flags != flags) {
|
163
|
+
entry = NULL;
|
164
|
+
} else {
|
165
|
+
git_cached_obj_incref(entry);
|
66
166
|
}
|
67
167
|
}
|
168
|
+
|
68
169
|
git_mutex_unlock(&cache->lock);
|
69
170
|
|
70
|
-
return
|
171
|
+
return entry;
|
71
172
|
}
|
72
173
|
|
73
|
-
void *
|
174
|
+
static void *cache_store(git_cache *cache, git_cached_obj *entry)
|
74
175
|
{
|
75
|
-
|
76
|
-
uint32_t hash;
|
176
|
+
khiter_t pos;
|
77
177
|
|
78
|
-
|
178
|
+
git_cached_obj_incref(entry);
|
79
179
|
|
80
|
-
if (
|
81
|
-
|
82
|
-
return
|
180
|
+
if (!git_cache__enabled && cache->used_memory > 0) {
|
181
|
+
git_cache_clear(cache);
|
182
|
+
return entry;
|
83
183
|
}
|
84
184
|
|
85
|
-
|
86
|
-
|
185
|
+
if (!cache_should_store(entry->type, entry->size))
|
186
|
+
return entry;
|
87
187
|
|
88
|
-
|
89
|
-
|
90
|
-
git_cached_obj_incref(entry);
|
188
|
+
if (git_mutex_lock(&cache->lock) < 0)
|
189
|
+
return entry;
|
91
190
|
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
191
|
+
/* soften the load on the cache */
|
192
|
+
if (git_cache__current_storage.val > git_cache__max_storage)
|
193
|
+
cache_evict_entries(cache);
|
194
|
+
|
195
|
+
pos = kh_get(oid, cache->map, &entry->oid);
|
196
|
+
|
197
|
+
/* not found */
|
198
|
+
if (pos == kh_end(cache->map)) {
|
199
|
+
int rval;
|
200
|
+
|
201
|
+
pos = kh_put(oid, cache->map, &entry->oid, &rval);
|
202
|
+
if (rval >= 0) {
|
203
|
+
kh_key(cache->map, pos) = &entry->oid;
|
204
|
+
kh_val(cache->map, pos) = entry;
|
205
|
+
git_cached_obj_incref(entry);
|
206
|
+
cache->used_memory += entry->size;
|
207
|
+
git_atomic_ssize_add(&git_cache__current_storage, (ssize_t)entry->size);
|
100
208
|
}
|
209
|
+
}
|
210
|
+
/* found */
|
211
|
+
else {
|
212
|
+
git_cached_obj *stored_entry = kh_val(cache->map, pos);
|
101
213
|
|
102
|
-
|
103
|
-
|
104
|
-
|
214
|
+
if (stored_entry->flags == entry->flags) {
|
215
|
+
git_cached_obj_decref(entry);
|
216
|
+
git_cached_obj_incref(stored_entry);
|
217
|
+
entry = stored_entry;
|
218
|
+
} else if (stored_entry->flags == GIT_CACHE_STORE_RAW &&
|
219
|
+
entry->flags == GIT_CACHE_STORE_PARSED) {
|
220
|
+
git_cached_obj_decref(stored_entry);
|
221
|
+
git_cached_obj_incref(entry);
|
105
222
|
|
223
|
+
kh_key(cache->map, pos) = &entry->oid;
|
224
|
+
kh_val(cache->map, pos) = entry;
|
225
|
+
} else {
|
226
|
+
/* NO OP */
|
227
|
+
}
|
106
228
|
}
|
107
|
-
git_mutex_unlock(&cache->lock);
|
108
229
|
|
230
|
+
git_mutex_unlock(&cache->lock);
|
109
231
|
return entry;
|
110
232
|
}
|
233
|
+
|
234
|
+
void *git_cache_store_raw(git_cache *cache, git_odb_object *entry)
|
235
|
+
{
|
236
|
+
entry->cached.flags = GIT_CACHE_STORE_RAW;
|
237
|
+
return cache_store(cache, (git_cached_obj *)entry);
|
238
|
+
}
|
239
|
+
|
240
|
+
void *git_cache_store_parsed(git_cache *cache, git_object *entry)
|
241
|
+
{
|
242
|
+
entry->cached.flags = GIT_CACHE_STORE_PARSED;
|
243
|
+
return cache_store(cache, (git_cached_obj *)entry);
|
244
|
+
}
|
245
|
+
|
246
|
+
git_odb_object *git_cache_get_raw(git_cache *cache, const git_oid *oid)
|
247
|
+
{
|
248
|
+
return cache_get(cache, oid, GIT_CACHE_STORE_RAW);
|
249
|
+
}
|
250
|
+
|
251
|
+
git_object *git_cache_get_parsed(git_cache *cache, const git_oid *oid)
|
252
|
+
{
|
253
|
+
return cache_get(cache, oid, GIT_CACHE_STORE_PARSED);
|
254
|
+
}
|
255
|
+
|
256
|
+
void *git_cache_get_any(git_cache *cache, const git_oid *oid)
|
257
|
+
{
|
258
|
+
return cache_get(cache, oid, GIT_CACHE_STORE_ANY);
|
259
|
+
}
|
260
|
+
|
261
|
+
void git_cached_obj_decref(void *_obj)
|
262
|
+
{
|
263
|
+
git_cached_obj *obj = _obj;
|
264
|
+
|
265
|
+
if (git_atomic_dec(&obj->refcount) == 0) {
|
266
|
+
switch (obj->flags) {
|
267
|
+
case GIT_CACHE_STORE_RAW:
|
268
|
+
git_odb_object__free(_obj);
|
269
|
+
break;
|
270
|
+
|
271
|
+
case GIT_CACHE_STORE_PARSED:
|
272
|
+
git_object__free(_obj);
|
273
|
+
break;
|
274
|
+
|
275
|
+
default:
|
276
|
+
git__free(_obj);
|
277
|
+
break;
|
278
|
+
}
|
279
|
+
}
|
280
|
+
}
|