line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
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 "refspec.h" |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
#include "buf.h" |
11
|
|
|
|
|
|
|
#include "refs.h" |
12
|
|
|
|
|
|
|
#include "util.h" |
13
|
|
|
|
|
|
|
#include "vector.h" |
14
|
|
|
|
|
|
|
#include "wildmatch.h" |
15
|
|
|
|
|
|
|
|
16
|
45
|
|
|
|
|
|
int git_refspec__parse(git_refspec *refspec, const char *input, bool is_fetch) |
17
|
|
|
|
|
|
|
{ |
18
|
|
|
|
|
|
|
/* Ported from https://github.com/git/git/blob/f06d47e7e0d9db709ee204ed13a8a7486149f494/remote.c#L518-636 */ |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
size_t llen; |
21
|
45
|
|
|
|
|
|
int is_glob = 0; |
22
|
|
|
|
|
|
|
const char *lhs, *rhs; |
23
|
45
|
|
|
|
|
|
int valid = 0; |
24
|
|
|
|
|
|
|
unsigned int flags; |
25
|
|
|
|
|
|
|
|
26
|
45
|
50
|
|
|
|
|
GIT_ASSERT_ARG(refspec); |
27
|
45
|
50
|
|
|
|
|
GIT_ASSERT_ARG(input); |
28
|
|
|
|
|
|
|
|
29
|
45
|
|
|
|
|
|
memset(refspec, 0x0, sizeof(git_refspec)); |
30
|
45
|
|
|
|
|
|
refspec->push = !is_fetch; |
31
|
|
|
|
|
|
|
|
32
|
45
|
|
|
|
|
|
lhs = input; |
33
|
45
|
100
|
|
|
|
|
if (*lhs == '+') { |
34
|
13
|
|
|
|
|
|
refspec->force = 1; |
35
|
13
|
|
|
|
|
|
lhs++; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
45
|
|
|
|
|
|
rhs = strrchr(lhs, ':'); |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
/* |
41
|
|
|
|
|
|
|
* Before going on, special case ":" (or "+:") as a refspec |
42
|
|
|
|
|
|
|
* for matching refs. |
43
|
|
|
|
|
|
|
*/ |
44
|
45
|
100
|
|
|
|
|
if (!is_fetch && rhs == lhs && rhs[1] == '\0') { |
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
45
|
0
|
|
|
|
|
|
refspec->matching = 1; |
46
|
0
|
|
|
|
|
|
refspec->string = git__strdup(input); |
47
|
0
|
0
|
|
|
|
|
GIT_ERROR_CHECK_ALLOC(refspec->string); |
48
|
0
|
|
|
|
|
|
refspec->src = git__strdup(""); |
49
|
0
|
0
|
|
|
|
|
GIT_ERROR_CHECK_ALLOC(refspec->src); |
50
|
0
|
|
|
|
|
|
refspec->dst = git__strdup(""); |
51
|
0
|
0
|
|
|
|
|
GIT_ERROR_CHECK_ALLOC(refspec->dst); |
52
|
0
|
|
|
|
|
|
return 0; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
45
|
50
|
|
|
|
|
if (rhs) { |
56
|
45
|
|
|
|
|
|
size_t rlen = strlen(++rhs); |
57
|
45
|
50
|
|
|
|
|
if (rlen || !is_fetch) { |
|
|
0
|
|
|
|
|
|
58
|
45
|
50
|
|
|
|
|
is_glob = (1 <= rlen && strchr(rhs, '*')); |
|
|
100
|
|
|
|
|
|
59
|
45
|
|
|
|
|
|
refspec->dst = git__strndup(rhs, rlen); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
45
|
50
|
|
|
|
|
llen = (rhs ? (size_t)(rhs - lhs - 1) : strlen(lhs)); |
64
|
45
|
50
|
|
|
|
|
if (1 <= llen && memchr(lhs, '*', llen)) { |
|
|
100
|
|
|
|
|
|
65
|
13
|
50
|
|
|
|
|
if ((rhs && !is_glob) || (!rhs && is_fetch)) |
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
66
|
|
|
|
|
|
|
goto invalid; |
67
|
13
|
|
|
|
|
|
is_glob = 1; |
68
|
32
|
50
|
|
|
|
|
} else if (rhs && is_glob) |
|
|
50
|
|
|
|
|
|
69
|
0
|
|
|
|
|
|
goto invalid; |
70
|
|
|
|
|
|
|
|
71
|
45
|
|
|
|
|
|
refspec->pattern = is_glob; |
72
|
45
|
|
|
|
|
|
refspec->src = git__strndup(lhs, llen); |
73
|
45
|
100
|
|
|
|
|
flags = GIT_REFERENCE_FORMAT_ALLOW_ONELEVEL | |
74
|
|
|
|
|
|
|
GIT_REFERENCE_FORMAT_REFSPEC_SHORTHAND | |
75
|
|
|
|
|
|
|
(is_glob ? GIT_REFERENCE_FORMAT_REFSPEC_PATTERN : 0); |
76
|
|
|
|
|
|
|
|
77
|
45
|
100
|
|
|
|
|
if (is_fetch) { |
78
|
|
|
|
|
|
|
/* |
79
|
|
|
|
|
|
|
* LHS |
80
|
|
|
|
|
|
|
* - empty is allowed; it means HEAD. |
81
|
|
|
|
|
|
|
* - otherwise it must be a valid looking ref. |
82
|
|
|
|
|
|
|
*/ |
83
|
43
|
50
|
|
|
|
|
if (!*refspec->src) |
84
|
|
|
|
|
|
|
; /* empty is ok */ |
85
|
43
|
50
|
|
|
|
|
else if (git_reference__name_is_valid(&valid, refspec->src, flags) < 0) |
86
|
0
|
|
|
|
|
|
goto on_error; |
87
|
43
|
50
|
|
|
|
|
else if (!valid) |
88
|
0
|
|
|
|
|
|
goto invalid; |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
/* |
91
|
|
|
|
|
|
|
* RHS |
92
|
|
|
|
|
|
|
* - missing is ok, and is same as empty. |
93
|
|
|
|
|
|
|
* - empty is ok; it means not to store. |
94
|
|
|
|
|
|
|
* - otherwise it must be a valid looking ref. |
95
|
|
|
|
|
|
|
*/ |
96
|
43
|
50
|
|
|
|
|
if (!refspec->dst) |
97
|
|
|
|
|
|
|
; /* ok */ |
98
|
43
|
50
|
|
|
|
|
else if (!*refspec->dst) |
99
|
|
|
|
|
|
|
; /* ok */ |
100
|
43
|
50
|
|
|
|
|
else if (git_reference__name_is_valid(&valid, refspec->dst, flags) < 0) |
101
|
0
|
|
|
|
|
|
goto on_error; |
102
|
43
|
50
|
|
|
|
|
else if (!valid) |
103
|
0
|
|
|
|
|
|
goto invalid; |
104
|
|
|
|
|
|
|
} else { |
105
|
|
|
|
|
|
|
/* |
106
|
|
|
|
|
|
|
* LHS |
107
|
|
|
|
|
|
|
* - empty is allowed; it means delete. |
108
|
|
|
|
|
|
|
* - when wildcarded, it must be a valid looking ref. |
109
|
|
|
|
|
|
|
* - otherwise, it must be an extended SHA-1, but |
110
|
|
|
|
|
|
|
* there is no existing way to validate this. |
111
|
|
|
|
|
|
|
*/ |
112
|
2
|
50
|
|
|
|
|
if (!*refspec->src) |
113
|
|
|
|
|
|
|
; /* empty is ok */ |
114
|
2
|
50
|
|
|
|
|
else if (is_glob) { |
115
|
0
|
0
|
|
|
|
|
if (git_reference__name_is_valid(&valid, refspec->src, flags) < 0) |
116
|
0
|
|
|
|
|
|
goto on_error; |
117
|
0
|
0
|
|
|
|
|
else if (!valid) |
118
|
0
|
|
|
|
|
|
goto invalid; |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
else { |
121
|
|
|
|
|
|
|
; /* anything goes, for now */ |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
/* |
125
|
|
|
|
|
|
|
* RHS |
126
|
|
|
|
|
|
|
* - missing is allowed, but LHS then must be a |
127
|
|
|
|
|
|
|
* valid looking ref. |
128
|
|
|
|
|
|
|
* - empty is not allowed. |
129
|
|
|
|
|
|
|
* - otherwise it must be a valid looking ref. |
130
|
|
|
|
|
|
|
*/ |
131
|
2
|
50
|
|
|
|
|
if (!refspec->dst) { |
132
|
0
|
0
|
|
|
|
|
if (git_reference__name_is_valid(&valid, refspec->src, flags) < 0) |
133
|
0
|
|
|
|
|
|
goto on_error; |
134
|
0
|
0
|
|
|
|
|
else if (!valid) |
135
|
0
|
|
|
|
|
|
goto invalid; |
136
|
2
|
50
|
|
|
|
|
} else if (!*refspec->dst) { |
137
|
0
|
|
|
|
|
|
goto invalid; |
138
|
|
|
|
|
|
|
} else { |
139
|
2
|
50
|
|
|
|
|
if (git_reference__name_is_valid(&valid, refspec->dst, flags) < 0) |
140
|
0
|
|
|
|
|
|
goto on_error; |
141
|
2
|
50
|
|
|
|
|
else if (!valid) |
142
|
0
|
|
|
|
|
|
goto invalid; |
143
|
|
|
|
|
|
|
} |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
/* if the RHS is empty, then it's a copy of the LHS */ |
146
|
2
|
50
|
|
|
|
|
if (!refspec->dst) { |
147
|
0
|
|
|
|
|
|
refspec->dst = git__strdup(refspec->src); |
148
|
0
|
0
|
|
|
|
|
GIT_ERROR_CHECK_ALLOC(refspec->dst); |
149
|
|
|
|
|
|
|
} |
150
|
|
|
|
|
|
|
} |
151
|
|
|
|
|
|
|
|
152
|
45
|
|
|
|
|
|
refspec->string = git__strdup(input); |
153
|
45
|
50
|
|
|
|
|
GIT_ERROR_CHECK_ALLOC(refspec->string); |
154
|
|
|
|
|
|
|
|
155
|
45
|
|
|
|
|
|
return 0; |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
invalid: |
158
|
0
|
|
|
|
|
|
git_error_set(GIT_ERROR_INVALID, |
159
|
|
|
|
|
|
|
"'%s' is not a valid refspec.", input); |
160
|
0
|
|
|
|
|
|
git_refspec__dispose(refspec); |
161
|
0
|
|
|
|
|
|
return GIT_EINVALIDSPEC; |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
on_error: |
164
|
0
|
|
|
|
|
|
git_refspec__dispose(refspec); |
165
|
45
|
|
|
|
|
|
return -1; |
166
|
|
|
|
|
|
|
} |
167
|
|
|
|
|
|
|
|
168
|
44
|
|
|
|
|
|
void git_refspec__dispose(git_refspec *refspec) |
169
|
|
|
|
|
|
|
{ |
170
|
44
|
50
|
|
|
|
|
if (refspec == NULL) |
171
|
0
|
|
|
|
|
|
return; |
172
|
|
|
|
|
|
|
|
173
|
44
|
|
|
|
|
|
git__free(refspec->src); |
174
|
44
|
|
|
|
|
|
git__free(refspec->dst); |
175
|
44
|
|
|
|
|
|
git__free(refspec->string); |
176
|
|
|
|
|
|
|
|
177
|
44
|
|
|
|
|
|
memset(refspec, 0x0, sizeof(git_refspec)); |
178
|
|
|
|
|
|
|
} |
179
|
|
|
|
|
|
|
|
180
|
1
|
|
|
|
|
|
int git_refspec_parse(git_refspec **out_refspec, const char *input, int is_fetch) |
181
|
|
|
|
|
|
|
{ |
182
|
|
|
|
|
|
|
git_refspec *refspec; |
183
|
1
|
50
|
|
|
|
|
GIT_ASSERT_ARG(out_refspec); |
184
|
1
|
50
|
|
|
|
|
GIT_ASSERT_ARG(input); |
185
|
|
|
|
|
|
|
|
186
|
1
|
|
|
|
|
|
*out_refspec = NULL; |
187
|
|
|
|
|
|
|
|
188
|
1
|
|
|
|
|
|
refspec = git__malloc(sizeof(git_refspec)); |
189
|
1
|
50
|
|
|
|
|
GIT_ERROR_CHECK_ALLOC(refspec); |
190
|
|
|
|
|
|
|
|
191
|
1
|
50
|
|
|
|
|
if (git_refspec__parse(refspec, input, !!is_fetch) != 0) { |
192
|
0
|
|
|
|
|
|
git__free(refspec); |
193
|
0
|
|
|
|
|
|
return -1; |
194
|
|
|
|
|
|
|
} |
195
|
|
|
|
|
|
|
|
196
|
1
|
|
|
|
|
|
*out_refspec = refspec; |
197
|
1
|
|
|
|
|
|
return 0; |
198
|
|
|
|
|
|
|
} |
199
|
|
|
|
|
|
|
|
200
|
1
|
|
|
|
|
|
void git_refspec_free(git_refspec *refspec) |
201
|
|
|
|
|
|
|
{ |
202
|
1
|
|
|
|
|
|
git_refspec__dispose(refspec); |
203
|
1
|
|
|
|
|
|
git__free(refspec); |
204
|
1
|
|
|
|
|
|
} |
205
|
|
|
|
|
|
|
|
206
|
3
|
|
|
|
|
|
const char *git_refspec_src(const git_refspec *refspec) |
207
|
|
|
|
|
|
|
{ |
208
|
3
|
50
|
|
|
|
|
return refspec == NULL ? NULL : refspec->src; |
209
|
|
|
|
|
|
|
} |
210
|
|
|
|
|
|
|
|
211
|
3
|
|
|
|
|
|
const char *git_refspec_dst(const git_refspec *refspec) |
212
|
|
|
|
|
|
|
{ |
213
|
3
|
50
|
|
|
|
|
return refspec == NULL ? NULL : refspec->dst; |
214
|
|
|
|
|
|
|
} |
215
|
|
|
|
|
|
|
|
216
|
5
|
|
|
|
|
|
const char *git_refspec_string(const git_refspec *refspec) |
217
|
|
|
|
|
|
|
{ |
218
|
5
|
50
|
|
|
|
|
return refspec == NULL ? NULL : refspec->string; |
219
|
|
|
|
|
|
|
} |
220
|
|
|
|
|
|
|
|
221
|
2
|
|
|
|
|
|
int git_refspec_force(const git_refspec *refspec) |
222
|
|
|
|
|
|
|
{ |
223
|
2
|
50
|
|
|
|
|
GIT_ASSERT_ARG(refspec); |
224
|
|
|
|
|
|
|
|
225
|
2
|
|
|
|
|
|
return refspec->force; |
226
|
|
|
|
|
|
|
} |
227
|
|
|
|
|
|
|
|
228
|
2
|
|
|
|
|
|
int git_refspec_src_matches(const git_refspec *refspec, const char *refname) |
229
|
|
|
|
|
|
|
{ |
230
|
2
|
50
|
|
|
|
|
if (refspec == NULL || refspec->src == NULL) |
|
|
50
|
|
|
|
|
|
231
|
0
|
|
|
|
|
|
return false; |
232
|
|
|
|
|
|
|
|
233
|
2
|
|
|
|
|
|
return (wildmatch(refspec->src, refname, 0) == 0); |
234
|
|
|
|
|
|
|
} |
235
|
|
|
|
|
|
|
|
236
|
5
|
|
|
|
|
|
int git_refspec_dst_matches(const git_refspec *refspec, const char *refname) |
237
|
|
|
|
|
|
|
{ |
238
|
5
|
50
|
|
|
|
|
if (refspec == NULL || refspec->dst == NULL) |
|
|
50
|
|
|
|
|
|
239
|
0
|
|
|
|
|
|
return false; |
240
|
|
|
|
|
|
|
|
241
|
5
|
|
|
|
|
|
return (wildmatch(refspec->dst, refname, 0) == 0); |
242
|
|
|
|
|
|
|
} |
243
|
|
|
|
|
|
|
|
244
|
2
|
|
|
|
|
|
static int refspec_transform( |
245
|
|
|
|
|
|
|
git_str *out, const char *from, const char *to, const char *name) |
246
|
|
|
|
|
|
|
{ |
247
|
|
|
|
|
|
|
const char *from_star, *to_star; |
248
|
|
|
|
|
|
|
size_t replacement_len, star_offset; |
249
|
|
|
|
|
|
|
|
250
|
2
|
|
|
|
|
|
git_str_clear(out); |
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
/* |
253
|
|
|
|
|
|
|
* There are two parts to each side of a refspec, the bit |
254
|
|
|
|
|
|
|
* before the star and the bit after it. The star can be in |
255
|
|
|
|
|
|
|
* the middle of the pattern, so we need to look at each bit |
256
|
|
|
|
|
|
|
* individually. |
257
|
|
|
|
|
|
|
*/ |
258
|
2
|
|
|
|
|
|
from_star = strchr(from, '*'); |
259
|
2
|
|
|
|
|
|
to_star = strchr(to, '*'); |
260
|
|
|
|
|
|
|
|
261
|
2
|
50
|
|
|
|
|
GIT_ASSERT(from_star && to_star); |
|
|
50
|
|
|
|
|
|
262
|
|
|
|
|
|
|
|
263
|
|
|
|
|
|
|
/* star offset, both in 'from' and in 'name' */ |
264
|
2
|
|
|
|
|
|
star_offset = from_star - from; |
265
|
|
|
|
|
|
|
|
266
|
|
|
|
|
|
|
/* the first half is copied over */ |
267
|
2
|
|
|
|
|
|
git_str_put(out, to, to_star - to); |
268
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
/* |
270
|
|
|
|
|
|
|
* Copy over the name, but exclude the trailing part in "from" starting |
271
|
|
|
|
|
|
|
* after the glob |
272
|
|
|
|
|
|
|
*/ |
273
|
2
|
|
|
|
|
|
replacement_len = strlen(name + star_offset) - strlen(from_star + 1); |
274
|
2
|
|
|
|
|
|
git_str_put(out, name + star_offset, replacement_len); |
275
|
|
|
|
|
|
|
|
276
|
2
|
|
|
|
|
|
return git_str_puts(out, to_star + 1); |
277
|
|
|
|
|
|
|
} |
278
|
|
|
|
|
|
|
|
279
|
1
|
|
|
|
|
|
int git_refspec_transform(git_buf *out, const git_refspec *spec, const char *name) |
280
|
|
|
|
|
|
|
{ |
281
|
1
|
50
|
|
|
|
|
GIT_BUF_WRAP_PRIVATE(out, git_refspec__transform, spec, name); |
|
|
50
|
|
|
|
|
|
282
|
|
|
|
|
|
|
} |
283
|
|
|
|
|
|
|
|
284
|
1
|
|
|
|
|
|
int git_refspec__transform(git_str *out, const git_refspec *spec, const char *name) |
285
|
|
|
|
|
|
|
{ |
286
|
1
|
50
|
|
|
|
|
GIT_ASSERT_ARG(out); |
287
|
1
|
50
|
|
|
|
|
GIT_ASSERT_ARG(spec); |
288
|
1
|
50
|
|
|
|
|
GIT_ASSERT_ARG(name); |
289
|
|
|
|
|
|
|
|
290
|
1
|
50
|
|
|
|
|
if (!git_refspec_src_matches(spec, name)) { |
291
|
0
|
|
|
|
|
|
git_error_set(GIT_ERROR_INVALID, "ref '%s' doesn't match the source", name); |
292
|
0
|
|
|
|
|
|
return -1; |
293
|
|
|
|
|
|
|
} |
294
|
|
|
|
|
|
|
|
295
|
1
|
50
|
|
|
|
|
if (!spec->pattern) |
296
|
0
|
0
|
|
|
|
|
return git_str_puts(out, spec->dst ? spec->dst : ""); |
297
|
|
|
|
|
|
|
|
298
|
1
|
|
|
|
|
|
return refspec_transform(out, spec->src, spec->dst, name); |
299
|
|
|
|
|
|
|
} |
300
|
|
|
|
|
|
|
|
301
|
1
|
|
|
|
|
|
int git_refspec_rtransform(git_buf *out, const git_refspec *spec, const char *name) |
302
|
|
|
|
|
|
|
{ |
303
|
1
|
50
|
|
|
|
|
GIT_BUF_WRAP_PRIVATE(out, git_refspec__rtransform, spec, name); |
|
|
50
|
|
|
|
|
|
304
|
|
|
|
|
|
|
} |
305
|
|
|
|
|
|
|
|
306
|
1
|
|
|
|
|
|
int git_refspec__rtransform(git_str *out, const git_refspec *spec, const char *name) |
307
|
|
|
|
|
|
|
{ |
308
|
1
|
50
|
|
|
|
|
GIT_ASSERT_ARG(out); |
309
|
1
|
50
|
|
|
|
|
GIT_ASSERT_ARG(spec); |
310
|
1
|
50
|
|
|
|
|
GIT_ASSERT_ARG(name); |
311
|
|
|
|
|
|
|
|
312
|
1
|
50
|
|
|
|
|
if (!git_refspec_dst_matches(spec, name)) { |
313
|
0
|
|
|
|
|
|
git_error_set(GIT_ERROR_INVALID, "ref '%s' doesn't match the destination", name); |
314
|
0
|
|
|
|
|
|
return -1; |
315
|
|
|
|
|
|
|
} |
316
|
|
|
|
|
|
|
|
317
|
1
|
50
|
|
|
|
|
if (!spec->pattern) |
318
|
0
|
|
|
|
|
|
return git_str_puts(out, spec->src); |
319
|
|
|
|
|
|
|
|
320
|
1
|
|
|
|
|
|
return refspec_transform(out, spec->dst, spec->src, name); |
321
|
|
|
|
|
|
|
} |
322
|
|
|
|
|
|
|
|
323
|
0
|
|
|
|
|
|
int git_refspec__serialize(git_str *out, const git_refspec *refspec) |
324
|
|
|
|
|
|
|
{ |
325
|
0
|
0
|
|
|
|
|
if (refspec->force) |
326
|
0
|
|
|
|
|
|
git_str_putc(out, '+'); |
327
|
|
|
|
|
|
|
|
328
|
0
|
0
|
|
|
|
|
git_str_printf(out, "%s:%s", |
|
|
0
|
|
|
|
|
|
329
|
0
|
|
|
|
|
|
refspec->src != NULL ? refspec->src : "", |
330
|
0
|
|
|
|
|
|
refspec->dst != NULL ? refspec->dst : ""); |
331
|
|
|
|
|
|
|
|
332
|
0
|
|
|
|
|
|
return git_str_oom(out) == false; |
333
|
|
|
|
|
|
|
} |
334
|
|
|
|
|
|
|
|
335
|
0
|
|
|
|
|
|
int git_refspec_is_wildcard(const git_refspec *spec) |
336
|
|
|
|
|
|
|
{ |
337
|
0
|
0
|
|
|
|
|
GIT_ASSERT_ARG(spec); |
338
|
0
|
0
|
|
|
|
|
GIT_ASSERT_ARG(spec->src); |
339
|
|
|
|
|
|
|
|
340
|
0
|
|
|
|
|
|
return (spec->src[strlen(spec->src) - 1] == '*'); |
341
|
|
|
|
|
|
|
} |
342
|
|
|
|
|
|
|
|
343
|
3
|
|
|
|
|
|
git_direction git_refspec_direction(const git_refspec *spec) |
344
|
|
|
|
|
|
|
{ |
345
|
3
|
50
|
|
|
|
|
GIT_ASSERT_ARG(spec); |
346
|
|
|
|
|
|
|
|
347
|
3
|
|
|
|
|
|
return spec->push; |
348
|
|
|
|
|
|
|
} |
349
|
|
|
|
|
|
|
|
350
|
13
|
|
|
|
|
|
int git_refspec__dwim_one(git_vector *out, git_refspec *spec, git_vector *refs) |
351
|
|
|
|
|
|
|
{ |
352
|
13
|
|
|
|
|
|
git_str buf = GIT_STR_INIT; |
353
|
|
|
|
|
|
|
size_t j, pos; |
354
|
|
|
|
|
|
|
git_remote_head key; |
355
|
|
|
|
|
|
|
git_refspec *cur; |
356
|
|
|
|
|
|
|
|
357
|
13
|
|
|
|
|
|
const char *formatters[] = { |
358
|
|
|
|
|
|
|
GIT_REFS_DIR "%s", |
359
|
|
|
|
|
|
|
GIT_REFS_TAGS_DIR "%s", |
360
|
|
|
|
|
|
|
GIT_REFS_HEADS_DIR "%s", |
361
|
|
|
|
|
|
|
NULL |
362
|
|
|
|
|
|
|
}; |
363
|
|
|
|
|
|
|
|
364
|
13
|
50
|
|
|
|
|
GIT_ASSERT_ARG(out); |
365
|
13
|
50
|
|
|
|
|
GIT_ASSERT_ARG(spec); |
366
|
13
|
50
|
|
|
|
|
GIT_ASSERT_ARG(refs); |
367
|
|
|
|
|
|
|
|
368
|
13
|
|
|
|
|
|
cur = git__calloc(1, sizeof(git_refspec)); |
369
|
13
|
50
|
|
|
|
|
GIT_ERROR_CHECK_ALLOC(cur); |
370
|
|
|
|
|
|
|
|
371
|
13
|
|
|
|
|
|
cur->force = spec->force; |
372
|
13
|
|
|
|
|
|
cur->push = spec->push; |
373
|
13
|
|
|
|
|
|
cur->pattern = spec->pattern; |
374
|
13
|
|
|
|
|
|
cur->matching = spec->matching; |
375
|
13
|
|
|
|
|
|
cur->string = git__strdup(spec->string); |
376
|
|
|
|
|
|
|
|
377
|
|
|
|
|
|
|
/* shorthand on the lhs */ |
378
|
13
|
50
|
|
|
|
|
if (git__prefixcmp(spec->src, GIT_REFS_DIR)) { |
379
|
0
|
0
|
|
|
|
|
for (j = 0; formatters[j]; j++) { |
380
|
0
|
|
|
|
|
|
git_str_clear(&buf); |
381
|
0
|
|
|
|
|
|
git_str_printf(&buf, formatters[j], spec->src); |
382
|
0
|
0
|
|
|
|
|
GIT_ERROR_CHECK_ALLOC_STR(&buf); |
383
|
|
|
|
|
|
|
|
384
|
0
|
|
|
|
|
|
key.name = (char *) git_str_cstr(&buf); |
385
|
0
|
0
|
|
|
|
|
if (!git_vector_search(&pos, refs, &key)) { |
386
|
|
|
|
|
|
|
/* we found something to match the shorthand, set src to that */ |
387
|
0
|
|
|
|
|
|
cur->src = git_str_detach(&buf); |
388
|
|
|
|
|
|
|
} |
389
|
|
|
|
|
|
|
} |
390
|
|
|
|
|
|
|
} |
391
|
|
|
|
|
|
|
|
392
|
|
|
|
|
|
|
/* No shorthands found, copy over the name */ |
393
|
13
|
50
|
|
|
|
|
if (cur->src == NULL && spec->src != NULL) { |
|
|
50
|
|
|
|
|
|
394
|
13
|
|
|
|
|
|
cur->src = git__strdup(spec->src); |
395
|
13
|
50
|
|
|
|
|
GIT_ERROR_CHECK_ALLOC(cur->src); |
396
|
|
|
|
|
|
|
} |
397
|
|
|
|
|
|
|
|
398
|
13
|
50
|
|
|
|
|
if (spec->dst && git__prefixcmp(spec->dst, GIT_REFS_DIR)) { |
|
|
50
|
|
|
|
|
|
399
|
|
|
|
|
|
|
/* if it starts with "remotes" then we just prepend "refs/" */ |
400
|
0
|
0
|
|
|
|
|
if (!git__prefixcmp(spec->dst, "remotes/")) { |
401
|
0
|
|
|
|
|
|
git_str_puts(&buf, GIT_REFS_DIR); |
402
|
|
|
|
|
|
|
} else { |
403
|
0
|
|
|
|
|
|
git_str_puts(&buf, GIT_REFS_HEADS_DIR); |
404
|
|
|
|
|
|
|
} |
405
|
|
|
|
|
|
|
|
406
|
0
|
|
|
|
|
|
git_str_puts(&buf, spec->dst); |
407
|
0
|
0
|
|
|
|
|
GIT_ERROR_CHECK_ALLOC_STR(&buf); |
408
|
|
|
|
|
|
|
|
409
|
0
|
|
|
|
|
|
cur->dst = git_str_detach(&buf); |
410
|
|
|
|
|
|
|
} |
411
|
|
|
|
|
|
|
|
412
|
13
|
|
|
|
|
|
git_str_dispose(&buf); |
413
|
|
|
|
|
|
|
|
414
|
13
|
50
|
|
|
|
|
if (cur->dst == NULL && spec->dst != NULL) { |
|
|
50
|
|
|
|
|
|
415
|
13
|
|
|
|
|
|
cur->dst = git__strdup(spec->dst); |
416
|
13
|
50
|
|
|
|
|
GIT_ERROR_CHECK_ALLOC(cur->dst); |
417
|
|
|
|
|
|
|
} |
418
|
|
|
|
|
|
|
|
419
|
13
|
|
|
|
|
|
return git_vector_insert(out, cur); |
420
|
|
|
|
|
|
|
} |