| 71 | } |
| 72 | |
| 73 | void oidset_parse_file_carefully(struct oidset *set, const char *path, |
| 74 | const struct git_hash_algo *algop, |
| 75 | oidset_parse_tweak_fn fn, void *cbdata) |
| 76 | { |
| 77 | FILE *fp; |
| 78 | struct strbuf sb = STRBUF_INIT; |
| 79 | struct object_id oid; |
| 80 | |
| 81 | fp = fopen(path, "r"); |
| 82 | if (!fp) |
| 83 | die("could not open object name list: %s", path); |
| 84 | while (!strbuf_getline(&sb, fp)) { |
| 85 | const char *p; |
| 86 | const char *name; |
| 87 | |
| 88 | /* |
| 89 | * Allow trailing comments, leading whitespace |
| 90 | * (including before commits), and empty or whitespace |
| 91 | * only lines. |
| 92 | */ |
| 93 | name = strchr(sb.buf, '#'); |
| 94 | if (name) |
| 95 | strbuf_setlen(&sb, name - sb.buf); |
| 96 | strbuf_trim(&sb); |
| 97 | if (!sb.len) |
| 98 | continue; |
| 99 | |
| 100 | if (parse_oid_hex_algop(sb.buf, &oid, &p, algop) || *p != '\0') |
| 101 | die("invalid object name: %s", sb.buf); |
| 102 | if (fn && fn(&oid, cbdata)) |
| 103 | continue; |
| 104 | oidset_insert(set, &oid); |
| 105 | } |
| 106 | if (ferror(fp)) |
| 107 | die_errno("Could not read '%s'", path); |
| 108 | fclose(fp); |
| 109 | strbuf_release(&sb); |
| 110 | } |
no test coverage detected