| 1340 | } |
| 1341 | |
| 1342 | static char *get_ref_match(const struct refspec *rs, const struct ref *ref, |
| 1343 | int send_mirror, int direction, |
| 1344 | const struct refspec_item **ret_pat) |
| 1345 | { |
| 1346 | const struct refspec_item *pat; |
| 1347 | char *name; |
| 1348 | int i; |
| 1349 | int matching_refs = -1; |
| 1350 | for (i = 0; i < rs->nr; i++) { |
| 1351 | const struct refspec_item *item = &rs->items[i]; |
| 1352 | |
| 1353 | if (item->negative) |
| 1354 | continue; |
| 1355 | |
| 1356 | if (item->matching && |
| 1357 | (matching_refs == -1 || item->force)) { |
| 1358 | matching_refs = i; |
| 1359 | continue; |
| 1360 | } |
| 1361 | |
| 1362 | if (item->pattern) { |
| 1363 | const char *dst_side = item->dst ? item->dst : item->src; |
| 1364 | int match; |
| 1365 | if (direction == FROM_SRC) |
| 1366 | match = match_refname_with_pattern(item->src, ref->name, dst_side, &name); |
| 1367 | else |
| 1368 | match = match_refname_with_pattern(dst_side, ref->name, item->src, &name); |
| 1369 | if (match) { |
| 1370 | matching_refs = i; |
| 1371 | break; |
| 1372 | } |
| 1373 | } |
| 1374 | } |
| 1375 | if (matching_refs == -1) |
| 1376 | return NULL; |
| 1377 | |
| 1378 | pat = &rs->items[matching_refs]; |
| 1379 | if (pat->matching) { |
| 1380 | /* |
| 1381 | * "matching refs"; traditionally we pushed everything |
| 1382 | * including refs outside refs/heads/ hierarchy, but |
| 1383 | * that does not make much sense these days. |
| 1384 | */ |
| 1385 | if (!send_mirror && !starts_with(ref->name, "refs/heads/")) |
| 1386 | return NULL; |
| 1387 | name = xstrdup(ref->name); |
| 1388 | } |
| 1389 | if (ret_pat) |
| 1390 | *ret_pat = pat; |
| 1391 | return name; |
| 1392 | } |
| 1393 | |
| 1394 | static struct ref **tail_ref(struct ref **head) |
| 1395 | { |
no test coverage detected