54
for_each_ref(expand_one_ref, NULL);
55
}
56
57
+struct wildcard_cb {
58
+ const char *from_prefix;
59
+ int from_prefix_len;
60
+ const char *to_prefix;
61
+ int to_prefix_len;
62
+ int force;
63
+};
64
+
65
+static int expand_wildcard_ref(const char *ref, const unsigned char *sha1, int flag, void *cb_data)
66
+{
67
+ struct wildcard_cb *cb = cb_data;
68
+ int len = strlen(ref);
69
+ char *expanded, *newref;
70
+
71
+ if (len < cb->from_prefix_len ||
72
+ memcmp(cb->from_prefix, ref, cb->from_prefix_len))
73
+ return 0;
74
+ expanded = xmalloc(len * 2 + cb->force +
75
+ (cb->to_prefix_len - cb->from_prefix_len) + 2);
76
+ newref = expanded + cb->force;
77
+ if (cb->force)
78
+ expanded[0] = '+';
79
+ memcpy(newref, ref, len);
80
+ newref[len] = ':';
81
+ memcpy(newref + len + 1, cb->to_prefix, cb->to_prefix_len);
82
+ strcpy(newref + len + 1 + cb->to_prefix_len,
83
+ ref + cb->from_prefix_len);
84
+ add_refspec(expanded);
85
+ return 0;
86
+}
87
+
88
+static int wildcard_ref(const char *ref)
89
+{
90
+ int len;
91
+ const char *colon;
92
+ struct wildcard_cb cb;
93
+
94
+ memset(&cb, 0, sizeof(cb));
95
+ if (ref[0] == '+') {
96
+ cb.force = 1;
97
+ ref++;
98
+ }
99
+ len = strlen(ref);
100
+ colon = strchr(ref, ':');
101
+ if (! (colon && ref < colon &&
102
+ colon[-2] == '/' && colon[-1] == '*' &&
103
+ /* "<mine>/<asterisk>:<yours>/<asterisk>" is at least 7 bytes */
104
+ 7 <= len &&
105
+ ref[len-2] == '/' && ref[len-1] == '*') )
106
+ return 0 ;
107
+ cb.from_prefix = ref;
108
+ cb.from_prefix_len = colon - ref - 1;
109
+ cb.to_prefix = colon + 1;
110
+ cb.to_prefix_len = len - (colon - ref) - 2;
111
+ for_each_ref(expand_wildcard_ref, &cb);
112
+ return 1;
113
+}
114
+
115
static void set_refspecs(const char **refs, int nr)
116
{
117
if (nr) {
60
- int pass;
61
- for (pass = 0; pass < 2; pass++) {
62
- /* pass 0 counts and allocates, pass 1 fills */
63
- int i, cnt;
64
- for (i = cnt = 0; i < nr; i++) {
65
- if (!strcmp("tag", refs[i])) {
66
- int len;
67
- char *tag;
68
- if (nr <= ++i)
69
- die("tag <tag> shorthand without <tag>");
70
- if (pass) {
71
- len = strlen(refs[i]) + 11;
72
- tag = xmalloc(len);
73
- strcpy(tag, "refs/tags/");
74
- strcat(tag, refs[i]);
75
- refspec[cnt] = tag;
76
- }
77
- cnt++;
78
- continue;
79
- }
80
- if (pass)
81
- refspec[cnt] = refs[i];
82
- cnt++;
83
- }
84
- if (!pass) {
85
- size_t bytes = cnt * sizeof(char *);
86
- refspec_nr = cnt;
87
- refspec = xrealloc(refspec, bytes);
118
+ int i;
119
+ for (i = 0; i < nr; i++) {
120
+ const char *ref = refs[i];
121
+ if (!strcmp("tag", ref)) {
122
+ char *tag;
123
+ int len;
124
+ if (nr <= ++i)
125
+ die("tag shorthand without <tag>");
126
+ len = strlen(refs[i]) + 11;
127
+ tag = xmalloc(len);
128
+ strcpy(tag, "refs/tags/");
129
+ strcat(tag, refs[i]);
130
+ ref = tag;
131
}
132
+ else if (wildcard_ref(ref))
133
+ continue;
134
+ add_refspec(ref);
135
}
136
}
137
expand_refspecs();
175
else
176
error("more than %d URL's specified, ignoring the rest", MAX_URI);
177
}
132
- else if (is_refspec && !has_explicit_refspec)
133
- add_refspec(xstrdup(s));
178
+ else if (is_refspec && !has_explicit_refspec) {
179
+ if (!wildcard_ref(s))
180
+ add_refspec(xstrdup(s));
181
+ }
182
}
183
fclose(f);
184
if (!n)
204
error("more than %d URL's specified, ignoring the rest", MAX_URI);
205
}
206
else if (config_get_refspecs &&
159
- !strcmp(key + 7 + config_repo_len, ".push"))
160
- add_refspec(xstrdup(value));
207
+ !strcmp(key + 7 + config_repo_len, ".push")) {
208
+ if (!wildcard_ref(value))
209
+ add_refspec(xstrdup(value));
210
+ }
211
else if (config_get_receivepack &&
212
!strcmp(key + 7 + config_repo_len, ".receivepack")) {
213
if (!receivepack) {