| 344 | } |
| 345 | |
| 346 | static int refspec_find_negative_match(struct refspec *rs, struct refspec_item *query) |
| 347 | { |
| 348 | int i, matched_negative = 0; |
| 349 | int find_src = !query->src; |
| 350 | struct string_list reversed = STRING_LIST_INIT_DUP; |
| 351 | const char *needle = find_src ? query->dst : query->src; |
| 352 | |
| 353 | /* |
| 354 | * Check whether the queried ref matches any negative refpsec. If so, |
| 355 | * then we should ultimately treat this as not matching the query at |
| 356 | * all. |
| 357 | * |
| 358 | * Note that negative refspecs always match the source, but the query |
| 359 | * item uses the destination. To handle this, we apply pattern |
| 360 | * refspecs in reverse to figure out if the query source matches any |
| 361 | * of the negative refspecs. |
| 362 | * |
| 363 | * The first loop finds and expands all positive refspecs |
| 364 | * matched by the queried ref. |
| 365 | * |
| 366 | * The second loop checks if any of the results of the first loop |
| 367 | * match any negative refspec. |
| 368 | */ |
| 369 | for (i = 0; i < rs->nr; i++) { |
| 370 | struct refspec_item *refspec = &rs->items[i]; |
| 371 | char *expn_name; |
| 372 | |
| 373 | if (refspec->negative) |
| 374 | continue; |
| 375 | |
| 376 | /* Note the reversal of src and dst */ |
| 377 | if (refspec->pattern) { |
| 378 | const char *key = refspec->dst ? refspec->dst : refspec->src; |
| 379 | const char *value = refspec->src; |
| 380 | |
| 381 | if (match_refname_with_pattern(key, needle, value, &expn_name)) |
| 382 | string_list_append_nodup(&reversed, expn_name); |
| 383 | } else if (refspec->matching) { |
| 384 | /* For the special matching refspec, any query should match */ |
| 385 | string_list_append(&reversed, needle); |
| 386 | } else if (!refspec->src) { |
| 387 | BUG("refspec->src should not be null here"); |
| 388 | } else if (!strcmp(needle, refspec->src)) { |
| 389 | string_list_append(&reversed, refspec->src); |
| 390 | } |
| 391 | } |
| 392 | |
| 393 | for (i = 0; !matched_negative && i < reversed.nr; i++) { |
| 394 | if (refname_matches_negative_refspec_item(reversed.items[i].string, rs)) |
| 395 | matched_negative = 1; |
| 396 | } |
| 397 | |
| 398 | string_list_clear(&reversed, 0); |
| 399 | |
| 400 | return matched_negative; |
| 401 | } |
| 402 | |
| 403 | void refspec_find_all_matches(struct refspec *rs, |
no test coverage detected