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

Function oidset_parse_file_carefully

oidset.c:73–110  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

71}
72
73void 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}

Callers 2

oidset_parse_fileFunction · 0.85
build_ignorelistFunction · 0.85

Calls 7

strbuf_getlineFunction · 0.85
strbuf_setlenFunction · 0.85
strbuf_trimFunction · 0.85
oidset_insertFunction · 0.85
die_errnoFunction · 0.85
strbuf_releaseFunction · 0.85
dieFunction · 0.70

Tested by

no test coverage detected