| 1182 | } |
| 1183 | |
| 1184 | static int get_oid_oneline(struct repository *r, |
| 1185 | const char *prefix, struct object_id *oid, |
| 1186 | const struct commit_list *list) |
| 1187 | { |
| 1188 | struct prio_queue copy = { compare_commits_by_commit_date }; |
| 1189 | const struct commit_list *l; |
| 1190 | int found = 0; |
| 1191 | int negative = 0; |
| 1192 | regex_t regex; |
| 1193 | |
| 1194 | if (prefix[0] == '!') { |
| 1195 | prefix++; |
| 1196 | |
| 1197 | if (prefix[0] == '-') { |
| 1198 | prefix++; |
| 1199 | negative = 1; |
| 1200 | } else if (prefix[0] != '!') { |
| 1201 | return -1; |
| 1202 | } |
| 1203 | } |
| 1204 | |
| 1205 | if (regcomp(®ex, prefix, REG_EXTENDED)) |
| 1206 | return -1; |
| 1207 | |
| 1208 | for (l = list; l; l = l->next) { |
| 1209 | l->item->object.flags |= ONELINE_SEEN; |
| 1210 | prio_queue_put(©, l->item); |
| 1211 | } |
| 1212 | while (copy.nr) { |
| 1213 | const char *p, *buf; |
| 1214 | struct commit *commit; |
| 1215 | int matches; |
| 1216 | |
| 1217 | commit = pop_most_recent_commit(©, ONELINE_SEEN); |
| 1218 | if (!parse_object(r, &commit->object.oid)) |
| 1219 | continue; |
| 1220 | buf = repo_get_commit_buffer(r, commit, NULL); |
| 1221 | p = strstr(buf, "\n\n"); |
| 1222 | matches = negative ^ (p && !regexec(®ex, p + 2, 0, NULL, 0)); |
| 1223 | repo_unuse_commit_buffer(r, commit, buf); |
| 1224 | |
| 1225 | if (matches) { |
| 1226 | oidcpy(oid, &commit->object.oid); |
| 1227 | found = 1; |
| 1228 | break; |
| 1229 | } |
| 1230 | } |
| 1231 | regfree(®ex); |
| 1232 | for (l = list; l; l = l->next) |
| 1233 | clear_commit_marks(l->item, ONELINE_SEEN); |
| 1234 | clear_prio_queue(©); |
| 1235 | return found ? 0 : -1; |
| 1236 | } |
| 1237 | |
| 1238 | struct grab_nth_branch_switch_cbdata { |
| 1239 | int remaining; |
no test coverage detected