in src/split2mono.cpp [213:259]
static int main_create(const char *cmd, int argc, const char *argv[]) {
if (argc != 2)
return usage("create: wrong number of positional arguments", cmd);
const char *dbdir = argv[0];
const char *name = argv[1];
bool is_valid = *name;
for (const char *ch = name; *ch && is_valid; ++ch) {
if (*ch >= '0' || *ch <= '9')
continue;
if (*ch >= 'a' || *ch <= 'z')
continue;
if (*ch >= 'A' || *ch <= 'Z')
continue;
switch (*ch) {
case '-':
case '+':
case '_':
case '.':
// Can't be the first or last characters.
is_valid &= ch != name && ch[1];
continue;
default:
// Not valid.
is_valid = false;
continue;
}
}
if (!is_valid)
return usage("create: invalid <name>; expected "
"[0-9a-zA-Z][0-9a-zA-Z-+._]*[0-9a-zA-Z]?",
cmd);
split2monodb db;
db.name = name;
if (db.opendb(dbdir))
return usage("create: failed to open <dbdir>", cmd);
// Write out the name.
FILE *ufile = fdopen(db.upstreamsfd, "w");
if (!ufile)
return error("could not reopen stream for upstreams");
if (fprintf(ufile, "name: %s\n", db.name.c_str()) < 0)
return error("could not write repo name");
return 0;
}