| 1039 | } |
| 1040 | |
| 1041 | int count_refspec_match(const char *pattern, |
| 1042 | struct ref *refs, |
| 1043 | struct ref **matched_ref) |
| 1044 | { |
| 1045 | int patlen = strlen(pattern); |
| 1046 | struct ref *matched_weak = NULL; |
| 1047 | struct ref *matched = NULL; |
| 1048 | int weak_match = 0; |
| 1049 | int match = 0; |
| 1050 | |
| 1051 | for (weak_match = match = 0; refs; refs = refs->next) { |
| 1052 | char *name = refs->name; |
| 1053 | int namelen = strlen(name); |
| 1054 | |
| 1055 | if (!refname_match(pattern, name)) |
| 1056 | continue; |
| 1057 | |
| 1058 | /* A match is "weak" if it is with refs outside |
| 1059 | * heads or tags, and did not specify the pattern |
| 1060 | * in full (e.g. "refs/remotes/origin/master") or at |
| 1061 | * least from the toplevel (e.g. "remotes/origin/master"); |
| 1062 | * otherwise "git push $URL master" would result in |
| 1063 | * ambiguity between remotes/origin/master and heads/master |
| 1064 | * at the remote site. |
| 1065 | */ |
| 1066 | if (namelen != patlen && |
| 1067 | patlen != namelen - 5 && |
| 1068 | !starts_with(name, "refs/heads/") && |
| 1069 | !starts_with(name, "refs/tags/")) { |
| 1070 | /* We want to catch the case where only weak |
| 1071 | * matches are found and there are multiple |
| 1072 | * matches, and where more than one strong |
| 1073 | * matches are found, as ambiguous. One |
| 1074 | * strong match with zero or more weak matches |
| 1075 | * are acceptable as a unique match. |
| 1076 | */ |
| 1077 | matched_weak = refs; |
| 1078 | weak_match++; |
| 1079 | } |
| 1080 | else { |
| 1081 | matched = refs; |
| 1082 | match++; |
| 1083 | } |
| 1084 | } |
| 1085 | if (!matched) { |
| 1086 | if (matched_ref) |
| 1087 | *matched_ref = matched_weak; |
| 1088 | return weak_match; |
| 1089 | } |
| 1090 | else { |
| 1091 | if (matched_ref) |
| 1092 | *matched_ref = matched; |
| 1093 | return match; |
| 1094 | } |
| 1095 | } |
| 1096 | |
| 1097 | void tail_link_ref(struct ref *ref, struct ref ***tail) |
| 1098 | { |
no test coverage detected