MCPcopy Create free account
hub / github.com/git/git / get_oid_oneline

Function get_oid_oneline

object-name.c:1184–1236  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1182}
1183
1184static 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(&regex, 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(&copy, 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(&copy, 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(&regex, 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(&regex);
1232 for (l = list; l; l = l->next)
1233 clear_commit_marks(l->item, ONELINE_SEEN);
1234 clear_prio_queue(&copy);
1235 return found ? 0 : -1;
1236}
1237
1238struct grab_nth_branch_switch_cbdata {
1239 int remaining;

Callers 2

peel_onionFunction · 0.85
get_oid_with_context_1Function · 0.85

Calls 10

regcompFunction · 0.85
prio_queue_putFunction · 0.85
pop_most_recent_commitFunction · 0.85
parse_objectFunction · 0.85
repo_get_commit_bufferFunction · 0.85
repo_unuse_commit_bufferFunction · 0.85
oidcpyFunction · 0.85
regfreeFunction · 0.85
clear_commit_marksFunction · 0.85
clear_prio_queueFunction · 0.85

Tested by

no test coverage detected