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/refs.h
CHANGED
@@ -13,6 +13,7 @@
|
|
13
13
|
#include "git2/refdb.h"
|
14
14
|
#include "strmap.h"
|
15
15
|
#include "buffer.h"
|
16
|
+
#include "oid.h"
|
16
17
|
|
17
18
|
#define GIT_REFS_DIR "refs/"
|
18
19
|
#define GIT_REFS_HEADS_DIR GIT_REFS_DIR "heads/"
|
@@ -25,7 +26,7 @@
|
|
25
26
|
|
26
27
|
#define GIT_SYMREF "ref: "
|
27
28
|
#define GIT_PACKEDREFS_FILE "packed-refs"
|
28
|
-
#define GIT_PACKEDREFS_HEADER "# pack-refs with: peeled "
|
29
|
+
#define GIT_PACKEDREFS_HEADER "# pack-refs with: peeled fully-peeled "
|
29
30
|
#define GIT_PACKEDREFS_FILE_MODE 0666
|
30
31
|
|
31
32
|
#define GIT_HEAD_FILE "HEAD"
|
@@ -25,6 +25,7 @@ int git_refspec__parse(git_refspec *refspec, const char *input, bool is_fetch)
|
|
25
25
|
assert(refspec && input);
|
26
26
|
|
27
27
|
memset(refspec, 0x0, sizeof(git_refspec));
|
28
|
+
refspec->push = !is_fetch;
|
28
29
|
|
29
30
|
lhs = input;
|
30
31
|
if (*lhs == '+') {
|
@@ -59,7 +60,7 @@ int git_refspec__parse(git_refspec *refspec, const char *input, bool is_fetch)
|
|
59
60
|
|
60
61
|
refspec->pattern = is_glob;
|
61
62
|
refspec->src = git__strndup(lhs, llen);
|
62
|
-
flags = GIT_REF_FORMAT_ALLOW_ONELEVEL
|
63
|
+
flags = GIT_REF_FORMAT_ALLOW_ONELEVEL | GIT_REF_FORMAT_REFSPEC_SHORTHAND
|
63
64
|
| (is_glob ? GIT_REF_FORMAT_REFSPEC_PATTERN : 0);
|
64
65
|
|
65
66
|
if (is_fetch) {
|
@@ -119,6 +120,9 @@ int git_refspec__parse(git_refspec *refspec, const char *input, bool is_fetch)
|
|
119
120
|
}
|
120
121
|
}
|
121
122
|
|
123
|
+
refspec->string = git__strdup(input);
|
124
|
+
GITERR_CHECK_ALLOC(refspec->string);
|
125
|
+
|
122
126
|
return 0;
|
123
127
|
|
124
128
|
invalid:
|
@@ -132,6 +136,7 @@ void git_refspec__free(git_refspec *refspec)
|
|
132
136
|
|
133
137
|
git__free(refspec->src);
|
134
138
|
git__free(refspec->dst);
|
139
|
+
git__free(refspec->string);
|
135
140
|
}
|
136
141
|
|
137
142
|
const char *git_refspec_src(const git_refspec *refspec)
|
@@ -144,6 +149,11 @@ const char *git_refspec_dst(const git_refspec *refspec)
|
|
144
149
|
return refspec == NULL ? NULL : refspec->dst;
|
145
150
|
}
|
146
151
|
|
152
|
+
const char *git_refspec_string(const git_refspec *refspec)
|
153
|
+
{
|
154
|
+
return refspec == NULL ? NULL : refspec->string;
|
155
|
+
}
|
156
|
+
|
147
157
|
int git_refspec_force(const git_refspec *refspec)
|
148
158
|
{
|
149
159
|
assert(refspec);
|
@@ -264,3 +274,10 @@ int git_refspec_is_wildcard(const git_refspec *spec)
|
|
264
274
|
|
265
275
|
return (spec->src[strlen(spec->src) - 1] == '*');
|
266
276
|
}
|
277
|
+
|
278
|
+
git_direction git_refspec_direction(const git_refspec *spec)
|
279
|
+
{
|
280
|
+
assert(spec);
|
281
|
+
|
282
|
+
return spec->push;
|
283
|
+
}
|
data/vendor/libgit2/src/remote.c
CHANGED
@@ -8,6 +8,7 @@
|
|
8
8
|
#include "git2/config.h"
|
9
9
|
#include "git2/types.h"
|
10
10
|
#include "git2/oid.h"
|
11
|
+
#include "git2/net.h"
|
11
12
|
|
12
13
|
#include "config.h"
|
13
14
|
#include "repository.h"
|
@@ -19,15 +20,26 @@
|
|
19
20
|
|
20
21
|
#include <regex.h>
|
21
22
|
|
22
|
-
static int
|
23
|
+
static int add_refspec(git_remote *remote, const char *string, bool is_fetch)
|
23
24
|
{
|
24
|
-
|
25
|
-
const char *val;
|
25
|
+
git_refspec *spec;
|
26
26
|
|
27
|
-
|
28
|
-
|
27
|
+
spec = git__calloc(1, sizeof(git_refspec));
|
28
|
+
GITERR_CHECK_ALLOC(spec);
|
29
|
+
|
30
|
+
if (git_refspec__parse(spec, string, is_fetch) < 0) {
|
31
|
+
git__free(spec);
|
32
|
+
return -1;
|
33
|
+
}
|
29
34
|
|
30
|
-
|
35
|
+
spec->push = !is_fetch;
|
36
|
+
if (git_vector_insert(&remote->refspecs, spec) < 0) {
|
37
|
+
git_refspec__free(spec);
|
38
|
+
git__free(spec);
|
39
|
+
return -1;
|
40
|
+
}
|
41
|
+
|
42
|
+
return 0;
|
31
43
|
}
|
32
44
|
|
33
45
|
static int download_tags_value(git_remote *remote, git_config *cfg)
|
@@ -36,11 +48,7 @@ static int download_tags_value(git_remote *remote, git_config *cfg)
|
|
36
48
|
git_buf buf = GIT_BUF_INIT;
|
37
49
|
int error;
|
38
50
|
|
39
|
-
|
40
|
-
return 0;
|
41
|
-
|
42
|
-
/* This is the default, let's see if we need to change it */
|
43
|
-
remote->download_tags = GIT_REMOTE_DOWNLOAD_TAGS_AUTO;
|
51
|
+
/* The 0 value is the default (auto), let's see if we need to change it */
|
44
52
|
if (git_buf_printf(&buf, "remote.%s.tagopt", remote->name) < 0)
|
45
53
|
return -1;
|
46
54
|
|
@@ -51,8 +59,10 @@ static int download_tags_value(git_remote *remote, git_config *cfg)
|
|
51
59
|
else if (!error && !strcmp(val, "--tags"))
|
52
60
|
remote->download_tags = GIT_REMOTE_DOWNLOAD_TAGS_ALL;
|
53
61
|
|
54
|
-
if (error == GIT_ENOTFOUND)
|
62
|
+
if (error == GIT_ENOTFOUND) {
|
63
|
+
giterr_clear();
|
55
64
|
error = 0;
|
65
|
+
}
|
56
66
|
|
57
67
|
return error;
|
58
68
|
}
|
@@ -99,14 +109,13 @@ static int create_internal(git_remote **out, git_repository *repo, const char *n
|
|
99
109
|
}
|
100
110
|
|
101
111
|
if (fetch != NULL) {
|
102
|
-
if (
|
112
|
+
if (add_refspec(remote, fetch, true) < 0)
|
103
113
|
goto on_error;
|
104
114
|
}
|
105
115
|
|
106
|
-
|
107
|
-
|
116
|
+
if (!name)
|
117
|
+
/* A remote without a name doesn't download tags */
|
108
118
|
remote->download_tags = GIT_REMOTE_DOWNLOAD_TAGS_NONE;
|
109
|
-
}
|
110
119
|
|
111
120
|
*out = remote;
|
112
121
|
git_buf_free(&fetchbuf);
|
@@ -186,6 +195,43 @@ int git_remote_create_inmemory(git_remote **out, git_repository *repo, const cha
|
|
186
195
|
return 0;
|
187
196
|
}
|
188
197
|
|
198
|
+
struct refspec_cb_data {
|
199
|
+
git_remote *remote;
|
200
|
+
int fetch;
|
201
|
+
};
|
202
|
+
|
203
|
+
static int refspec_cb(const git_config_entry *entry, void *payload)
|
204
|
+
{
|
205
|
+
const struct refspec_cb_data *data = (struct refspec_cb_data *)payload;
|
206
|
+
|
207
|
+
return add_refspec(data->remote, entry->value, data->fetch);
|
208
|
+
}
|
209
|
+
|
210
|
+
static int get_optional_config(
|
211
|
+
git_config *config, git_buf *buf, git_config_foreach_cb cb, void *payload)
|
212
|
+
{
|
213
|
+
int error = 0;
|
214
|
+
const char *key = git_buf_cstr(buf);
|
215
|
+
|
216
|
+
if (git_buf_oom(buf))
|
217
|
+
return -1;
|
218
|
+
|
219
|
+
if (cb != NULL)
|
220
|
+
error = git_config_get_multivar(config, key, NULL, cb, payload);
|
221
|
+
else
|
222
|
+
error = git_config_get_string(payload, config, key);
|
223
|
+
|
224
|
+
if (error == GIT_ENOTFOUND) {
|
225
|
+
giterr_clear();
|
226
|
+
error = 0;
|
227
|
+
}
|
228
|
+
|
229
|
+
if (error < 0)
|
230
|
+
error = -1;
|
231
|
+
|
232
|
+
return error;
|
233
|
+
}
|
234
|
+
|
189
235
|
int git_remote_load(git_remote **out, git_repository *repo, const char *name)
|
190
236
|
{
|
191
237
|
git_remote *remote;
|
@@ -193,6 +239,7 @@ int git_remote_load(git_remote **out, git_repository *repo, const char *name)
|
|
193
239
|
const char *val;
|
194
240
|
int error = 0;
|
195
241
|
git_config *config;
|
242
|
+
struct refspec_cb_data data;
|
196
243
|
|
197
244
|
assert(out && repo && name);
|
198
245
|
|
@@ -211,7 +258,8 @@ int git_remote_load(git_remote **out, git_repository *repo, const char *name)
|
|
211
258
|
remote->name = git__strdup(name);
|
212
259
|
GITERR_CHECK_ALLOC(remote->name);
|
213
260
|
|
214
|
-
if (git_vector_init(&remote->refs, 32, NULL) < 0)
|
261
|
+
if ((git_vector_init(&remote->refs, 32, NULL) < 0) ||
|
262
|
+
(git_vector_init(&remote->refspecs, 2, NULL))) {
|
215
263
|
error = -1;
|
216
264
|
goto cleanup;
|
217
265
|
}
|
@@ -223,7 +271,7 @@ int git_remote_load(git_remote **out, git_repository *repo, const char *name)
|
|
223
271
|
|
224
272
|
if ((error = git_config_get_string(&val, config, git_buf_cstr(&buf))) < 0)
|
225
273
|
goto cleanup;
|
226
|
-
|
274
|
+
|
227
275
|
if (strlen(val) == 0) {
|
228
276
|
giterr_set(GITERR_INVALID, "Malformed remote '%s' - missing URL", name);
|
229
277
|
error = -1;
|
@@ -234,57 +282,32 @@ int git_remote_load(git_remote **out, git_repository *repo, const char *name)
|
|
234
282
|
remote->url = git__strdup(val);
|
235
283
|
GITERR_CHECK_ALLOC(remote->url);
|
236
284
|
|
285
|
+
val = NULL;
|
237
286
|
git_buf_clear(&buf);
|
238
|
-
|
239
|
-
error = -1;
|
240
|
-
goto cleanup;
|
241
|
-
}
|
242
|
-
|
243
|
-
error = git_config_get_string(&val, config, git_buf_cstr(&buf));
|
244
|
-
if (error == GIT_ENOTFOUND) {
|
245
|
-
val = NULL;
|
246
|
-
error = 0;
|
247
|
-
}
|
287
|
+
git_buf_printf(&buf, "remote.%s.pushurl", name);
|
248
288
|
|
249
|
-
if (error < 0)
|
250
|
-
error = -1;
|
289
|
+
if ((error = get_optional_config(config, &buf, NULL, (void *)&val)) < 0)
|
251
290
|
goto cleanup;
|
252
|
-
}
|
253
291
|
|
254
292
|
if (val) {
|
255
293
|
remote->pushurl = git__strdup(val);
|
256
294
|
GITERR_CHECK_ALLOC(remote->pushurl);
|
257
295
|
}
|
258
296
|
|
297
|
+
data.remote = remote;
|
298
|
+
data.fetch = true;
|
259
299
|
git_buf_clear(&buf);
|
260
|
-
|
261
|
-
error = -1;
|
262
|
-
goto cleanup;
|
263
|
-
}
|
264
|
-
|
265
|
-
error = parse_remote_refspec(config, &remote->fetch, git_buf_cstr(&buf), true);
|
266
|
-
if (error == GIT_ENOTFOUND)
|
267
|
-
error = 0;
|
300
|
+
git_buf_printf(&buf, "remote.%s.fetch", name);
|
268
301
|
|
269
|
-
if (error < 0)
|
270
|
-
error = -1;
|
302
|
+
if ((error = get_optional_config(config, &buf, refspec_cb, &data)) < 0)
|
271
303
|
goto cleanup;
|
272
|
-
}
|
273
304
|
|
305
|
+
data.fetch = false;
|
274
306
|
git_buf_clear(&buf);
|
275
|
-
|
276
|
-
error = -1;
|
277
|
-
goto cleanup;
|
278
|
-
}
|
307
|
+
git_buf_printf(&buf, "remote.%s.push", name);
|
279
308
|
|
280
|
-
error =
|
281
|
-
if (error == GIT_ENOTFOUND)
|
282
|
-
error = 0;
|
283
|
-
|
284
|
-
if (error < 0) {
|
285
|
-
error = -1;
|
309
|
+
if ((error = get_optional_config(config, &buf, refspec_cb, &data)) < 0)
|
286
310
|
goto cleanup;
|
287
|
-
}
|
288
311
|
|
289
312
|
if (download_tags_value(remote, config) < 0)
|
290
313
|
goto cleanup;
|
@@ -300,36 +323,44 @@ cleanup:
|
|
300
323
|
return error;
|
301
324
|
}
|
302
325
|
|
303
|
-
static int update_config_refspec(
|
304
|
-
git_config *config,
|
305
|
-
const char *remote_name,
|
306
|
-
const git_refspec *refspec,
|
307
|
-
int git_direction)
|
326
|
+
static int update_config_refspec(const git_remote *remote, git_config *config, int direction)
|
308
327
|
{
|
309
|
-
git_buf name = GIT_BUF_INIT
|
310
|
-
int
|
328
|
+
git_buf name = GIT_BUF_INIT;
|
329
|
+
int push;
|
330
|
+
const char *dir;
|
331
|
+
size_t i;
|
332
|
+
int error = 0;
|
311
333
|
|
312
|
-
|
313
|
-
|
334
|
+
push = direction == GIT_DIRECTION_PUSH;
|
335
|
+
dir = push ? "push" : "fetch";
|
314
336
|
|
315
|
-
if (git_buf_printf(
|
316
|
-
|
317
|
-
"remote.%s.%s",
|
318
|
-
remote_name,
|
319
|
-
git_direction == GIT_DIRECTION_FETCH ? "fetch" : "push") < 0)
|
320
|
-
goto cleanup;
|
337
|
+
if (git_buf_printf(&name, "remote.%s.%s", remote->name, dir) < 0)
|
338
|
+
return -1;
|
321
339
|
|
322
|
-
|
323
|
-
|
340
|
+
/* Clear out the existing config */
|
341
|
+
while (!error)
|
342
|
+
error = git_config_delete_entry(config, git_buf_cstr(&name));
|
324
343
|
|
325
|
-
error
|
326
|
-
|
327
|
-
|
328
|
-
|
344
|
+
if (error != GIT_ENOTFOUND)
|
345
|
+
return error;
|
346
|
+
|
347
|
+
for (i = 0; i < remote->refspecs.length; i++) {
|
348
|
+
git_refspec *spec = git_vector_get(&remote->refspecs, i);
|
349
|
+
|
350
|
+
if (spec->push != push)
|
351
|
+
continue;
|
352
|
+
|
353
|
+
if ((error = git_config_set_multivar(
|
354
|
+
config, git_buf_cstr(&name), "", spec->string)) < 0) {
|
355
|
+
goto cleanup;
|
356
|
+
}
|
357
|
+
}
|
358
|
+
|
359
|
+
giterr_clear();
|
360
|
+
error = 0;
|
329
361
|
|
330
362
|
cleanup:
|
331
363
|
git_buf_free(&name);
|
332
|
-
git_buf_free(&value);
|
333
364
|
|
334
365
|
return error;
|
335
366
|
}
|
@@ -383,19 +414,11 @@ int git_remote_save(const git_remote *remote)
|
|
383
414
|
}
|
384
415
|
}
|
385
416
|
|
386
|
-
if (update_config_refspec(
|
387
|
-
|
388
|
-
remote->name,
|
389
|
-
&remote->fetch,
|
390
|
-
GIT_DIRECTION_FETCH) < 0)
|
391
|
-
goto on_error;
|
417
|
+
if (update_config_refspec(remote, config, GIT_DIRECTION_FETCH) < 0)
|
418
|
+
goto on_error;
|
392
419
|
|
393
|
-
if (update_config_refspec(
|
394
|
-
|
395
|
-
remote->name,
|
396
|
-
&remote->push,
|
397
|
-
GIT_DIRECTION_PUSH) < 0)
|
398
|
-
goto on_error;
|
420
|
+
if (update_config_refspec(remote, config, GIT_DIRECTION_PUSH) < 0)
|
421
|
+
goto on_error;
|
399
422
|
|
400
423
|
/*
|
401
424
|
* What action to take depends on the old and new values. This
|
@@ -482,49 +505,6 @@ int git_remote_set_pushurl(git_remote *remote, const char* url)
|
|
482
505
|
return 0;
|
483
506
|
}
|
484
507
|
|
485
|
-
int git_remote_set_fetchspec(git_remote *remote, const char *spec)
|
486
|
-
{
|
487
|
-
git_refspec refspec;
|
488
|
-
|
489
|
-
assert(remote && spec);
|
490
|
-
|
491
|
-
if (git_refspec__parse(&refspec, spec, true) < 0)
|
492
|
-
return -1;
|
493
|
-
|
494
|
-
git_refspec__free(&remote->fetch);
|
495
|
-
memcpy(&remote->fetch, &refspec, sizeof(git_refspec));
|
496
|
-
|
497
|
-
return 0;
|
498
|
-
}
|
499
|
-
|
500
|
-
const git_refspec *git_remote_fetchspec(const git_remote *remote)
|
501
|
-
{
|
502
|
-
assert(remote);
|
503
|
-
return &remote->fetch;
|
504
|
-
}
|
505
|
-
|
506
|
-
int git_remote_set_pushspec(git_remote *remote, const char *spec)
|
507
|
-
{
|
508
|
-
git_refspec refspec;
|
509
|
-
|
510
|
-
assert(remote && spec);
|
511
|
-
|
512
|
-
if (git_refspec__parse(&refspec, spec, false) < 0)
|
513
|
-
return -1;
|
514
|
-
|
515
|
-
git_refspec__free(&remote->push);
|
516
|
-
remote->push.src = refspec.src;
|
517
|
-
remote->push.dst = refspec.dst;
|
518
|
-
|
519
|
-
return 0;
|
520
|
-
}
|
521
|
-
|
522
|
-
const git_refspec *git_remote_pushspec(const git_remote *remote)
|
523
|
-
{
|
524
|
-
assert(remote);
|
525
|
-
return &remote->push;
|
526
|
-
}
|
527
|
-
|
528
508
|
const char* git_remote__urlfordirection(git_remote *remote, int direction)
|
529
509
|
{
|
530
510
|
assert(remote);
|
@@ -646,28 +626,105 @@ int git_remote__get_http_proxy(git_remote *remote, bool use_ssl, char **proxy_ur
|
|
646
626
|
return 0;
|
647
627
|
}
|
648
628
|
|
629
|
+
static int store_refs(git_remote_head *head, void *payload)
|
630
|
+
{
|
631
|
+
git_vector *refs = (git_vector *)payload;
|
632
|
+
|
633
|
+
return git_vector_insert(refs, head);
|
634
|
+
}
|
635
|
+
|
636
|
+
static int dwim_refspecs(git_vector *refspecs, git_vector *refs)
|
637
|
+
{
|
638
|
+
git_buf buf = GIT_BUF_INIT;
|
639
|
+
git_refspec *spec;
|
640
|
+
size_t i, j, pos;
|
641
|
+
git_remote_head key;
|
642
|
+
|
643
|
+
const char* formatters[] = {
|
644
|
+
GIT_REFS_DIR "%s",
|
645
|
+
GIT_REFS_TAGS_DIR "%s",
|
646
|
+
GIT_REFS_HEADS_DIR "%s",
|
647
|
+
NULL
|
648
|
+
};
|
649
|
+
|
650
|
+
git_vector_foreach(refspecs, i, spec) {
|
651
|
+
if (spec->dwim)
|
652
|
+
continue;
|
653
|
+
|
654
|
+
/* shorthand on the lhs */
|
655
|
+
if (git__prefixcmp(spec->src, GIT_REFS_DIR)) {
|
656
|
+
for (j = 0; formatters[j]; j++) {
|
657
|
+
git_buf_clear(&buf);
|
658
|
+
if (git_buf_printf(&buf, formatters[j], spec->src) < 0)
|
659
|
+
return -1;
|
660
|
+
|
661
|
+
key.name = (char *) git_buf_cstr(&buf);
|
662
|
+
if (!git_vector_search(&pos, refs, &key)) {
|
663
|
+
/* we found something to match the shorthand, set src to that */
|
664
|
+
git__free(spec->src);
|
665
|
+
spec->src = git_buf_detach(&buf);
|
666
|
+
}
|
667
|
+
}
|
668
|
+
}
|
669
|
+
|
670
|
+
if (spec->dst && git__prefixcmp(spec->dst, GIT_REFS_DIR)) {
|
671
|
+
/* if it starts with "remotes" then we just prepend "refs/" */
|
672
|
+
if (!git__prefixcmp(spec->dst, "remotes/")) {
|
673
|
+
git_buf_puts(&buf, GIT_REFS_DIR);
|
674
|
+
} else {
|
675
|
+
git_buf_puts(&buf, GIT_REFS_HEADS_DIR);
|
676
|
+
}
|
677
|
+
|
678
|
+
if (git_buf_puts(&buf, spec->dst) < 0)
|
679
|
+
return -1;
|
680
|
+
|
681
|
+
git__free(spec->dst);
|
682
|
+
spec->dst = git_buf_detach(&buf);
|
683
|
+
}
|
684
|
+
|
685
|
+
spec->dwim = 1;
|
686
|
+
}
|
687
|
+
|
688
|
+
git_buf_free(&buf);
|
689
|
+
return 0;
|
690
|
+
}
|
691
|
+
|
692
|
+
static int remote_head_cmp(const void *_a, const void *_b)
|
693
|
+
{
|
694
|
+
const git_remote_head *a = (git_remote_head *) _a;
|
695
|
+
const git_remote_head *b = (git_remote_head *) _b;
|
696
|
+
|
697
|
+
return git__strcmp_cb(a->name, b->name);
|
698
|
+
}
|
699
|
+
|
649
700
|
int git_remote_download(
|
650
701
|
git_remote *remote,
|
651
702
|
git_transfer_progress_callback progress_cb,
|
652
703
|
void *progress_payload)
|
653
704
|
{
|
654
705
|
int error;
|
706
|
+
git_vector refs;
|
655
707
|
|
656
708
|
assert(remote);
|
657
709
|
|
710
|
+
if (git_vector_init(&refs, 16, remote_head_cmp) < 0)
|
711
|
+
return -1;
|
712
|
+
|
713
|
+
if (git_remote_ls(remote, store_refs, &refs) < 0) {
|
714
|
+
return -1;
|
715
|
+
}
|
716
|
+
|
717
|
+
error = dwim_refspecs(&remote->refspecs, &refs);
|
718
|
+
git_vector_free(&refs);
|
719
|
+
if (error < 0)
|
720
|
+
return -1;
|
721
|
+
|
658
722
|
if ((error = git_fetch_negotiate(remote)) < 0)
|
659
723
|
return error;
|
660
724
|
|
661
725
|
return git_fetch_download_pack(remote, progress_cb, progress_payload);
|
662
726
|
}
|
663
727
|
|
664
|
-
static int update_tips_callback(git_remote_head *head, void *payload)
|
665
|
-
{
|
666
|
-
git_vector *refs = (git_vector *)payload;
|
667
|
-
|
668
|
-
return git_vector_insert(refs, head);
|
669
|
-
}
|
670
|
-
|
671
728
|
static int remote_head_for_fetchspec_src(git_remote_head **out, git_vector *update_heads, const char *fetchspec_src)
|
672
729
|
{
|
673
730
|
unsigned int i;
|
@@ -687,21 +744,21 @@ static int remote_head_for_fetchspec_src(git_remote_head **out, git_vector *upda
|
|
687
744
|
return 0;
|
688
745
|
}
|
689
746
|
|
690
|
-
static int remote_head_for_ref(git_remote_head **out,
|
747
|
+
static int remote_head_for_ref(git_remote_head **out, git_refspec *spec, git_vector *update_heads, git_reference *ref)
|
691
748
|
{
|
692
749
|
git_reference *resolved_ref = NULL;
|
693
750
|
git_reference *tracking_ref = NULL;
|
694
751
|
git_buf remote_name = GIT_BUF_INIT;
|
695
752
|
int error = 0;
|
696
753
|
|
697
|
-
assert(out &&
|
754
|
+
assert(out && spec && ref);
|
698
755
|
|
699
756
|
*out = NULL;
|
700
757
|
|
701
758
|
if ((error = git_reference_resolve(&resolved_ref, ref)) < 0 ||
|
702
759
|
(!git_reference_is_branch(resolved_ref)) ||
|
703
760
|
(error = git_branch_upstream(&tracking_ref, resolved_ref)) < 0 ||
|
704
|
-
(error = git_refspec_transform_l(&remote_name,
|
761
|
+
(error = git_refspec_transform_l(&remote_name, spec, git_reference_name(tracking_ref))) < 0) {
|
705
762
|
/* Not an error if HEAD is orphaned or no tracking branch */
|
706
763
|
if (error == GIT_ENOTFOUND)
|
707
764
|
error = 0;
|
@@ -718,9 +775,8 @@ cleanup:
|
|
718
775
|
return error;
|
719
776
|
}
|
720
777
|
|
721
|
-
static int git_remote_write_fetchhead(git_remote *remote, git_vector *update_heads)
|
778
|
+
static int git_remote_write_fetchhead(git_remote *remote, git_refspec *spec, git_vector *update_heads)
|
722
779
|
{
|
723
|
-
struct git_refspec *spec;
|
724
780
|
git_reference *head_ref = NULL;
|
725
781
|
git_fetchhead_ref *fetchhead_ref;
|
726
782
|
git_remote_head *remote_ref, *merge_remote_ref;
|
@@ -735,8 +791,6 @@ static int git_remote_write_fetchhead(git_remote *remote, git_vector *update_hea
|
|
735
791
|
if (update_heads->length == 0)
|
736
792
|
return 0;
|
737
793
|
|
738
|
-
spec = &remote->fetch;
|
739
|
-
|
740
794
|
if (git_vector_init(&fetchhead_refs, update_heads->length, git_fetchhead_ref_cmp) < 0)
|
741
795
|
return -1;
|
742
796
|
|
@@ -746,7 +800,7 @@ static int git_remote_write_fetchhead(git_remote *remote, git_vector *update_hea
|
|
746
800
|
/* Determine what to merge: if refspec was a wildcard, just use HEAD */
|
747
801
|
if (git_refspec_is_wildcard(spec)) {
|
748
802
|
if ((error = git_reference_lookup(&head_ref, remote->repo, GIT_HEAD_FILE)) < 0 ||
|
749
|
-
(error = remote_head_for_ref(&merge_remote_ref,
|
803
|
+
(error = remote_head_for_ref(&merge_remote_ref, spec, update_heads, head_ref)) < 0)
|
750
804
|
goto cleanup;
|
751
805
|
} else {
|
752
806
|
/* If we're fetching a single refspec, that's the only thing that should be in FETCH_HEAD. */
|
@@ -786,7 +840,7 @@ cleanup:
|
|
786
840
|
return error;
|
787
841
|
}
|
788
842
|
|
789
|
-
int
|
843
|
+
static int update_tips_for_spec(git_remote *remote, git_refspec *spec, git_vector *refs)
|
790
844
|
{
|
791
845
|
int error = 0, autotag;
|
792
846
|
unsigned int i = 0;
|
@@ -795,14 +849,11 @@ int git_remote_update_tips(git_remote *remote)
|
|
795
849
|
git_odb *odb;
|
796
850
|
git_remote_head *head;
|
797
851
|
git_reference *ref;
|
798
|
-
struct git_refspec *spec;
|
799
852
|
git_refspec tagspec;
|
800
|
-
git_vector
|
853
|
+
git_vector update_heads;
|
801
854
|
|
802
855
|
assert(remote);
|
803
856
|
|
804
|
-
spec = &remote->fetch;
|
805
|
-
|
806
857
|
if (git_repository_odb__weakptr(&odb, remote->repo) < 0)
|
807
858
|
return -1;
|
808
859
|
|
@@ -810,35 +861,18 @@ int git_remote_update_tips(git_remote *remote)
|
|
810
861
|
return -1;
|
811
862
|
|
812
863
|
/* Make a copy of the transport's refs */
|
813
|
-
if (git_vector_init(&
|
814
|
-
git_vector_init(&update_heads, 16, NULL) < 0)
|
864
|
+
if (git_vector_init(&update_heads, 16, NULL) < 0)
|
815
865
|
return -1;
|
816
866
|
|
817
|
-
|
818
|
-
|
819
|
-
|
820
|
-
/* Let's go find HEAD, if it exists. Check only the first ref in the vector. */
|
821
|
-
if (refs.length > 0) {
|
822
|
-
head = (git_remote_head *)refs.contents[0];
|
823
|
-
|
824
|
-
if (!strcmp(head->name, GIT_HEAD_FILE)) {
|
825
|
-
if (git_reference_create(&ref, remote->repo, GIT_FETCH_HEAD_FILE, &head->oid, 1) < 0)
|
826
|
-
goto on_error;
|
827
|
-
|
828
|
-
i = 1;
|
829
|
-
git_reference_free(ref);
|
830
|
-
}
|
831
|
-
}
|
832
|
-
|
833
|
-
for (; i < refs.length; ++i) {
|
834
|
-
head = (git_remote_head *)refs.contents[i];
|
867
|
+
for (; i < refs->length; ++i) {
|
868
|
+
head = git_vector_get(refs, i);
|
835
869
|
autotag = 0;
|
836
870
|
|
837
871
|
/* Ignore malformed ref names (which also saves us from tag^{} */
|
838
872
|
if (!git_reference_is_valid_name(head->name))
|
839
873
|
continue;
|
840
874
|
|
841
|
-
if (git_refspec_src_matches(spec, head->name)) {
|
875
|
+
if (git_refspec_src_matches(spec, head->name) && spec->dst) {
|
842
876
|
if (git_refspec_transform_r(&refname, spec, head->name) < 0)
|
843
877
|
goto on_error;
|
844
878
|
} else if (remote->download_tags != GIT_REMOTE_DOWNLOAD_TAGS_NONE) {
|
@@ -869,7 +903,7 @@ int git_remote_update_tips(git_remote *remote)
|
|
869
903
|
if (error == GIT_ENOTFOUND)
|
870
904
|
memset(&old, 0, GIT_OID_RAWSZ);
|
871
905
|
|
872
|
-
if (!
|
906
|
+
if (!git_oid__cmp(&old, &head->oid))
|
873
907
|
continue;
|
874
908
|
|
875
909
|
/* In autotag mode, don't overwrite any locally-existing tags */
|
@@ -886,17 +920,15 @@ int git_remote_update_tips(git_remote *remote)
|
|
886
920
|
}
|
887
921
|
|
888
922
|
if (git_remote_update_fetchhead(remote) &&
|
889
|
-
|
923
|
+
(error = git_remote_write_fetchhead(remote, spec, &update_heads)) < 0)
|
890
924
|
goto on_error;
|
891
925
|
|
892
|
-
git_vector_free(&refs);
|
893
926
|
git_vector_free(&update_heads);
|
894
927
|
git_refspec__free(&tagspec);
|
895
928
|
git_buf_free(&refname);
|
896
929
|
return 0;
|
897
930
|
|
898
931
|
on_error:
|
899
|
-
git_vector_free(&refs);
|
900
932
|
git_vector_free(&update_heads);
|
901
933
|
git_refspec__free(&tagspec);
|
902
934
|
git_buf_free(&refname);
|
@@ -904,6 +936,42 @@ on_error:
|
|
904
936
|
|
905
937
|
}
|
906
938
|
|
939
|
+
int git_remote_update_tips(git_remote *remote)
|
940
|
+
{
|
941
|
+
git_refspec *spec, tagspec;
|
942
|
+
git_vector refs;
|
943
|
+
int error;
|
944
|
+
size_t i;
|
945
|
+
|
946
|
+
|
947
|
+
if (git_refspec__parse(&tagspec, GIT_REFSPEC_TAGS, true) < 0)
|
948
|
+
return -1;
|
949
|
+
|
950
|
+
if (git_vector_init(&refs, 16, NULL) < 0)
|
951
|
+
return -1;
|
952
|
+
|
953
|
+
if ((error = git_remote_ls(remote, store_refs, &refs)) < 0)
|
954
|
+
goto out;
|
955
|
+
|
956
|
+
if (remote->download_tags == GIT_REMOTE_DOWNLOAD_TAGS_ALL) {
|
957
|
+
error = update_tips_for_spec(remote, &tagspec, &refs);
|
958
|
+
goto out;
|
959
|
+
}
|
960
|
+
|
961
|
+
git_vector_foreach(&remote->refspecs, i, spec) {
|
962
|
+
if (spec->push)
|
963
|
+
continue;
|
964
|
+
|
965
|
+
if ((error = update_tips_for_spec(remote, spec, &refs)) < 0)
|
966
|
+
goto out;
|
967
|
+
}
|
968
|
+
|
969
|
+
out:
|
970
|
+
git_refspec__free(&tagspec);
|
971
|
+
git_vector_free(&refs);
|
972
|
+
return error;
|
973
|
+
}
|
974
|
+
|
907
975
|
int git_remote_connected(git_remote *remote)
|
908
976
|
{
|
909
977
|
assert(remote);
|
@@ -933,6 +1001,9 @@ void git_remote_disconnect(git_remote *remote)
|
|
933
1001
|
|
934
1002
|
void git_remote_free(git_remote *remote)
|
935
1003
|
{
|
1004
|
+
git_refspec *spec;
|
1005
|
+
size_t i;
|
1006
|
+
|
936
1007
|
if (remote == NULL)
|
937
1008
|
return;
|
938
1009
|
|
@@ -945,8 +1016,12 @@ void git_remote_free(git_remote *remote)
|
|
945
1016
|
|
946
1017
|
git_vector_free(&remote->refs);
|
947
1018
|
|
948
|
-
|
949
|
-
|
1019
|
+
git_vector_foreach(&remote->refspecs, i, spec) {
|
1020
|
+
git_refspec__free(spec);
|
1021
|
+
git__free(spec);
|
1022
|
+
}
|
1023
|
+
git_vector_free(&remote->refspecs);
|
1024
|
+
|
950
1025
|
git__free(remote->url);
|
951
1026
|
git__free(remote->pushurl);
|
952
1027
|
git__free(remote->name);
|
@@ -1157,40 +1232,24 @@ static int update_branch_remote_config_entry(
|
|
1157
1232
|
update_config_entries_cb, &data);
|
1158
1233
|
}
|
1159
1234
|
|
1160
|
-
static int rename_cb(const char *ref, void *data)
|
1161
|
-
{
|
1162
|
-
if (git__prefixcmp(ref, GIT_REFS_REMOTES_DIR))
|
1163
|
-
return 0;
|
1164
|
-
|
1165
|
-
return git_vector_insert((git_vector *)data, git__strdup(ref));
|
1166
|
-
}
|
1167
|
-
|
1168
1235
|
static int rename_one_remote_reference(
|
1169
|
-
|
1170
|
-
const char *reference_name,
|
1236
|
+
git_reference *reference,
|
1171
1237
|
const char *old_remote_name,
|
1172
1238
|
const char *new_remote_name)
|
1173
1239
|
{
|
1174
1240
|
int error = -1;
|
1175
1241
|
git_buf new_name = GIT_BUF_INIT;
|
1176
|
-
git_reference *reference = NULL;
|
1177
|
-
git_reference *newref = NULL;
|
1178
1242
|
|
1179
1243
|
if (git_buf_printf(
|
1180
1244
|
&new_name,
|
1181
1245
|
GIT_REFS_REMOTES_DIR "%s%s",
|
1182
1246
|
new_remote_name,
|
1183
|
-
|
1247
|
+
reference->name + strlen(GIT_REFS_REMOTES_DIR) + strlen(old_remote_name)) < 0)
|
1184
1248
|
return -1;
|
1185
1249
|
|
1186
|
-
|
1187
|
-
goto cleanup;
|
1188
|
-
|
1189
|
-
error = git_reference_rename(&newref, reference, git_buf_cstr(&new_name), 0);
|
1250
|
+
error = git_reference_rename(NULL, reference, git_buf_cstr(&new_name), 0);
|
1190
1251
|
git_reference_free(reference);
|
1191
1252
|
|
1192
|
-
cleanup:
|
1193
|
-
git_reference_free(newref);
|
1194
1253
|
git_buf_free(&new_name);
|
1195
1254
|
return error;
|
1196
1255
|
}
|
@@ -1200,33 +1259,30 @@ static int rename_remote_references(
|
|
1200
1259
|
const char *old_name,
|
1201
1260
|
const char *new_name)
|
1202
1261
|
{
|
1203
|
-
git_vector refnames;
|
1204
1262
|
int error = -1;
|
1205
|
-
|
1206
|
-
|
1263
|
+
git_reference *ref;
|
1264
|
+
git_reference_iterator *iter;
|
1207
1265
|
|
1208
|
-
if (
|
1209
|
-
|
1266
|
+
if (git_reference_iterator_new(&iter, repo) < 0)
|
1267
|
+
return -1;
|
1210
1268
|
|
1211
|
-
|
1212
|
-
|
1213
|
-
|
1214
|
-
|
1215
|
-
|
1216
|
-
goto cleanup;
|
1269
|
+
while ((error = git_reference_next(&ref, iter)) == 0) {
|
1270
|
+
if (git__prefixcmp(ref->name, GIT_REFS_REMOTES_DIR)) {
|
1271
|
+
git_reference_free(ref);
|
1272
|
+
continue;
|
1273
|
+
}
|
1217
1274
|
|
1218
|
-
|
1219
|
-
|
1220
|
-
|
1275
|
+
if ((error = rename_one_remote_reference(ref, old_name, new_name)) < 0) {
|
1276
|
+
git_reference_iterator_free(iter);
|
1277
|
+
return error;
|
1278
|
+
}
|
1221
1279
|
}
|
1222
1280
|
|
1223
|
-
|
1224
|
-
|
1225
|
-
|
1226
|
-
|
1227
|
-
}
|
1281
|
+
git_reference_iterator_free(iter);
|
1282
|
+
|
1283
|
+
if (error == GIT_ITEROVER)
|
1284
|
+
return 0;
|
1228
1285
|
|
1229
|
-
git_vector_free(&refnames);
|
1230
1286
|
return error;
|
1231
1287
|
}
|
1232
1288
|
|
@@ -1237,58 +1293,58 @@ static int rename_fetch_refspecs(
|
|
1237
1293
|
void *payload)
|
1238
1294
|
{
|
1239
1295
|
git_config *config;
|
1240
|
-
|
1241
|
-
|
1242
|
-
|
1296
|
+
git_buf base = GIT_BUF_INIT, var = GIT_BUF_INIT, val = GIT_BUF_INIT;
|
1297
|
+
const git_refspec *spec;
|
1298
|
+
size_t i;
|
1243
1299
|
int error = -1;
|
1244
1300
|
|
1245
|
-
|
1246
|
-
|
1247
|
-
/* Is there a refspec to deal with? */
|
1248
|
-
if (fetch_refspec->src == NULL &&
|
1249
|
-
fetch_refspec->dst == NULL)
|
1250
|
-
return 0;
|
1251
|
-
|
1252
|
-
if (git_refspec__serialize(&serialized, fetch_refspec) < 0)
|
1301
|
+
if (git_buf_printf(&base, "+refs/heads/*:refs/remotes/%s/*", remote->name) < 0)
|
1253
1302
|
goto cleanup;
|
1254
1303
|
|
1255
|
-
|
1256
|
-
|
1257
|
-
|
1258
|
-
goto cleanup;
|
1259
|
-
}
|
1304
|
+
git_vector_foreach(&remote->refspecs, i, spec) {
|
1305
|
+
if (spec->push)
|
1306
|
+
continue;
|
1260
1307
|
|
1261
|
-
|
1262
|
-
|
1308
|
+
/* Every refspec is a problem refspec for an in-memory remote */
|
1309
|
+
if (!remote->name) {
|
1310
|
+
if (callback(spec->string, payload) < 0) {
|
1311
|
+
error = GIT_EUSER;
|
1312
|
+
goto cleanup;
|
1313
|
+
}
|
1263
1314
|
|
1264
|
-
|
1315
|
+
continue;
|
1316
|
+
}
|
1265
1317
|
|
1266
|
-
|
1267
|
-
|
1268
|
-
|
1269
|
-
|
1270
|
-
|
1318
|
+
/* Does the dst part of the refspec follow the extected standard format? */
|
1319
|
+
if (strcmp(git_buf_cstr(&base), spec->string)) {
|
1320
|
+
if (callback(spec->string, payload) < 0) {
|
1321
|
+
error = GIT_EUSER;
|
1322
|
+
goto cleanup;
|
1323
|
+
}
|
1271
1324
|
|
1272
|
-
|
1273
|
-
|
1274
|
-
|
1275
|
-
|
1276
|
-
|
1325
|
+
continue;
|
1326
|
+
}
|
1327
|
+
|
1328
|
+
/* If we do want to move it to the new section */
|
1329
|
+
if (git_buf_printf(&val, "+refs/heads/*:refs/remotes/%s/*", new_name) < 0)
|
1277
1330
|
goto cleanup;
|
1278
1331
|
|
1279
|
-
|
1332
|
+
if (git_buf_printf(&var, "remote.%s.fetch", new_name) < 0)
|
1333
|
+
goto cleanup;
|
1280
1334
|
|
1281
|
-
|
1282
|
-
|
1335
|
+
if (git_repository_config__weakptr(&config, remote->repo) < 0)
|
1336
|
+
goto cleanup;
|
1283
1337
|
|
1284
|
-
|
1285
|
-
|
1338
|
+
if (git_config_set_string(config, git_buf_cstr(&var), git_buf_cstr(&val)) < 0)
|
1339
|
+
goto cleanup;
|
1340
|
+
}
|
1286
1341
|
|
1287
|
-
error =
|
1342
|
+
error = 0;
|
1288
1343
|
|
1289
1344
|
cleanup:
|
1290
|
-
git_buf_free(&
|
1291
|
-
git_buf_free(&
|
1345
|
+
git_buf_free(&base);
|
1346
|
+
git_buf_free(&var);
|
1347
|
+
git_buf_free(&val);
|
1292
1348
|
return error;
|
1293
1349
|
}
|
1294
1350
|
|
@@ -1389,3 +1445,128 @@ int git_remote_is_valid_name(
|
|
1389
1445
|
giterr_clear();
|
1390
1446
|
return error == 0;
|
1391
1447
|
}
|
1448
|
+
|
1449
|
+
git_refspec *git_remote__matching_refspec(git_remote *remote, const char *refname)
|
1450
|
+
{
|
1451
|
+
git_refspec *spec;
|
1452
|
+
size_t i;
|
1453
|
+
|
1454
|
+
git_vector_foreach(&remote->refspecs, i, spec) {
|
1455
|
+
if (spec->push)
|
1456
|
+
continue;
|
1457
|
+
|
1458
|
+
if (git_refspec_src_matches(spec, refname))
|
1459
|
+
return spec;
|
1460
|
+
}
|
1461
|
+
|
1462
|
+
return NULL;
|
1463
|
+
}
|
1464
|
+
|
1465
|
+
git_refspec *git_remote__matching_dst_refspec(git_remote *remote, const char *refname)
|
1466
|
+
{
|
1467
|
+
git_refspec *spec;
|
1468
|
+
size_t i;
|
1469
|
+
|
1470
|
+
git_vector_foreach(&remote->refspecs, i, spec) {
|
1471
|
+
if (spec->push)
|
1472
|
+
continue;
|
1473
|
+
|
1474
|
+
if (git_refspec_dst_matches(spec, refname))
|
1475
|
+
return spec;
|
1476
|
+
}
|
1477
|
+
|
1478
|
+
return NULL;
|
1479
|
+
}
|
1480
|
+
|
1481
|
+
void git_remote_clear_refspecs(git_remote *remote)
|
1482
|
+
{
|
1483
|
+
git_refspec *spec;
|
1484
|
+
size_t i;
|
1485
|
+
|
1486
|
+
git_vector_foreach(&remote->refspecs, i, spec) {
|
1487
|
+
git_refspec__free(spec);
|
1488
|
+
git__free(spec);
|
1489
|
+
}
|
1490
|
+
git_vector_clear(&remote->refspecs);
|
1491
|
+
}
|
1492
|
+
|
1493
|
+
int git_remote_add_fetch(git_remote *remote, const char *refspec)
|
1494
|
+
{
|
1495
|
+
return add_refspec(remote, refspec, true);
|
1496
|
+
}
|
1497
|
+
|
1498
|
+
int git_remote_add_push(git_remote *remote, const char *refspec)
|
1499
|
+
{
|
1500
|
+
return add_refspec(remote, refspec, false);
|
1501
|
+
}
|
1502
|
+
|
1503
|
+
static int copy_refspecs(git_strarray *array, git_remote *remote, int push)
|
1504
|
+
{
|
1505
|
+
size_t i;
|
1506
|
+
git_vector refspecs;
|
1507
|
+
git_refspec *spec;
|
1508
|
+
char *dup;
|
1509
|
+
|
1510
|
+
if (git_vector_init(&refspecs, remote->refspecs.length, NULL) < 0)
|
1511
|
+
return -1;
|
1512
|
+
|
1513
|
+
git_vector_foreach(&remote->refspecs, i, spec) {
|
1514
|
+
if (spec->push != push)
|
1515
|
+
continue;
|
1516
|
+
|
1517
|
+
if ((dup = git__strdup(spec->string)) == NULL)
|
1518
|
+
goto on_error;
|
1519
|
+
|
1520
|
+
if (git_vector_insert(&refspecs, dup) < 0) {
|
1521
|
+
git__free(dup);
|
1522
|
+
goto on_error;
|
1523
|
+
}
|
1524
|
+
}
|
1525
|
+
|
1526
|
+
array->strings = (char **)refspecs.contents;
|
1527
|
+
array->count = refspecs.length;
|
1528
|
+
|
1529
|
+
return 0;
|
1530
|
+
|
1531
|
+
on_error:
|
1532
|
+
git_vector_foreach(&refspecs, i, dup)
|
1533
|
+
git__free(dup);
|
1534
|
+
git_vector_free(&refspecs);
|
1535
|
+
|
1536
|
+
return -1;
|
1537
|
+
}
|
1538
|
+
|
1539
|
+
int git_remote_get_fetch_refspecs(git_strarray *array, git_remote *remote)
|
1540
|
+
{
|
1541
|
+
return copy_refspecs(array, remote, false);
|
1542
|
+
}
|
1543
|
+
|
1544
|
+
int git_remote_get_push_refspecs(git_strarray *array, git_remote *remote)
|
1545
|
+
{
|
1546
|
+
return copy_refspecs(array, remote, true);
|
1547
|
+
}
|
1548
|
+
|
1549
|
+
size_t git_remote_refspec_count(git_remote *remote)
|
1550
|
+
{
|
1551
|
+
return remote->refspecs.length;
|
1552
|
+
}
|
1553
|
+
|
1554
|
+
const git_refspec *git_remote_get_refspec(git_remote *remote, size_t n)
|
1555
|
+
{
|
1556
|
+
return git_vector_get(&remote->refspecs, n);
|
1557
|
+
}
|
1558
|
+
|
1559
|
+
int git_remote_remove_refspec(git_remote *remote, size_t n)
|
1560
|
+
{
|
1561
|
+
git_refspec *spec;
|
1562
|
+
|
1563
|
+
assert(remote);
|
1564
|
+
|
1565
|
+
spec = git_vector_get(&remote->refspecs, n);
|
1566
|
+
if (spec) {
|
1567
|
+
git_refspec__free(spec);
|
1568
|
+
git__free(spec);
|
1569
|
+
}
|
1570
|
+
|
1571
|
+
return git_vector_remove(&remote->refspecs, n);
|
1572
|
+
}
|