Artifact a732976f7b8d4a2275cfd569d7ba07ea34c322c1a46860b91e0bf8c6d13fdb9f:
- File
src/main.c
— part of check-in
[1ed63201f4]
at
2026-11-18 03:02:04
on branch trunk
— suit curate apply turns the page's choices into config changes
suit curate apply FILE reads the choices file the curation page makes and prints a plan: which outfits and wears it edits, which wardrobes it checks in and in what order, and the links that will appear and disappear at each scope. Without --yes nothing changes. With --yes it edits each wardrobe's suit.conf and checks it in, with a comment such as "Curate: 3 kept, 1 limited, 12 retired". It does not place anything; the next run sees the config changed and applies.
- keep leaves a worn asset as it is. A loose asset, or one coming back from the attic, goes to the outfit kept.WARDROBE, worn at user scope. - limit moves the asset from its user outfits to personal.WARDROBE.SLUG, worn by [wear personal PROJECT], created or reused wherever it is. - retire removes the asset from every outfit of its wardrobe and adds it to attic.WARDROBE, which nothing wears. Apply refuses if a wear reaches an attic. - Removing one name from an outfit that lists `*` turns the `*` into an explicit list of the names it reached, minus that one, and the plan says so: names added to the store later are then not included by that outfit. No exclusion syntax was added.
Outfit names carry the wardrobe because outfit names are one set across wardrobes; a name too long for that is refused for its line. A wardrobe that defines a new outfit is checked in before any wardrobe whose wear names it, so a failure part-way leaves only an outfit nothing wears; a run that would need the opposite order is refused before anything changes.
Configs are edited as text: only the lines that must change are rewritten, and comments, blank lines, alignment, line endings and the order of everything else are kept. Every edited config must parse and the combined set must pass the merge check before anything is written. A wardrobe with local changes is refused, so the check-in holds the curation only. A failed check-in puts that wardrobe's file back.
A malformed line, a duplicate, a bad header or a path given as a project refuses the whole file, listing every problem. An unknown asset is warned about and skipped; a choice already true is silent.
A new suite, test/curate_apply.sh, with 376 cases, is part of the gate, and a new fuzz target covers the choices parser and the line editor.
3669 unit checks (was 2993), 625 shell cases, 1153 store cases, 985 placement cases, 378 project cases, 236 usage cases, 288 curate cases and 376 curate-apply cases, under clang, under gcc 16, with no user name set, and under a strict umask, in one run of make gate (44 minutes). 100% coverage in all 32 source files. No existing case was changed. (user: dmestas, size: 6942) [annotate] [blame] [check-ins using]
#include "bench.h" #include "commands.h" #include "conf.h" #include "curate.h" #include "hook.h" #include "install.h" #include "platform.h" #include "remote.h" #include "stamp.h" #include "store.h" #include "tally.h" #include "upstream.h" #include <errno.h> #include <string.h> #include <unistd.h> static Conf conf; static int usage(void) { say(STDERR_FILENO, "usage: suit check [FILE]\n" " suit store open|status|update|repair NAME\n" " suit plan | apply | status | off | run\n" " suit needs | need HARNESS NAME\n" " suit why NAME\n" " suit machine [NAME]\n" " suit roots [add|rm FOLDER]\n" " suit projects [scan]\n" " suit project set FOLDER KEY | unset FOLDER\n" " suit compare\n" " suit lint NAME\n" " suit commit NAME -m TEXT [--confirm-deletions]\n" " suit tend [NAME]\n" " suit usage [scan | [--since DAYS] [--kind KIND] [--harness NAME] [--project KEY] [--tsv]]\n" " suit curate [--since DAYS] [--out FILE]\n" " suit curate apply FILE [--yes]\n" " suit clone NAME URL\n" " suit back NAME\n" " suit remote NAME [URL|--none]\n" " suit login NAME USER (the secret on standard input)\n" " suit logout NAME\n" " suit sync NAME\n" " suit upstream NAME take FOLDER | diff\n" " suit upstream NAME accept [--theirs PATH] [--mine PATH]...\n" " suit upstream NAME undo\n" " suit upstreams\n" " suit stamp PATH...\n" " suit run\n" " suit hook EVENT | hooks\n" " suit install [--print] | uninstall\n" " suit status [--line]\n" " suit bench [-n N] [-e EMPTY_PROGRAM] [-t MICROSECONDS] [-m KIB]\n"); return 2; } static int cmd_check(const char *path) { ConfError err; if (!conf_load(&conf, path, &err)) { say(STDERR_FILENO, "%s:%d: %s\n", path, err.line, err.msg); return 2; } if (!conf_dump(&conf, STDOUT_FILENO)) { say(STDERR_FILENO, "suit: cannot write the dump: %s\n", strerror(errno)); return 1; } return 0; } static int cmd_store(int argc, char **argv) { if (argc != 4) return usage(); const char *verb = argv[2]; if (strcmp(verb, "open") == 0) return store_open(argv[3]); if (strcmp(verb, "status") == 0) return store_status(argv[3]); if (strcmp(verb, "update") == 0) return store_update(argv[3]); if (strcmp(verb, "repair") == 0) return store_repair(argv[3]); return usage(); } static int cmd_roots_args(int argc, char **argv) { if (argc == 2) return cmd_roots(nullptr, nullptr); bool verb = argc == 4 && (strcmp(argv[2], "add") == 0 || strcmp(argv[2], "rm") == 0); return verb ? cmd_roots(argv[2], argv[3]) : usage(); } static int cmd_project_args(int argc, char **argv) { if (argc == 5 && strcmp(argv[2], "set") == 0) return cmd_project(argv[3], argv[4]); if (argc == 4 && strcmp(argv[2], "unset") == 0) return cmd_project(argv[3], nullptr); return usage(); } static int cmd_commit(int argc, char **argv) { bool confirm = argc == 6 && strcmp(argv[5], "--confirm-deletions") == 0; if (argc < 5 || argc > 6 || strcmp(argv[3], "-m") != 0 || (argc == 6 && !confirm)) return usage(); return store_commit(argv[2], argv[4], confirm); } int main(int argc, char **argv) { if (argc < 2) return usage(); const char *cmd = argv[1]; if (strcmp(cmd, "run") == 0) return argc == 2 ? cmd_run() : usage(); if (strcmp(cmd, "compare") == 0) return argc == 2 ? stamp_check(true) : usage(); if (strcmp(cmd, "plan") == 0) return argc == 2 ? cmd_plan() : usage(); if (strcmp(cmd, "apply") == 0) return argc == 2 ? cmd_apply() : usage(); if (strcmp(cmd, "status") == 0) { if (argc == 2) return cmd_status(); return argc == 3 && strcmp(argv[2], "--line") == 0 ? cmd_status_line() : usage(); } if (strcmp(cmd, "install") == 0) { if (argc == 2) return cmd_install(false); return argc == 3 && strcmp(argv[2], "--print") == 0 ? cmd_install(true) : usage(); } if (strcmp(cmd, "uninstall") == 0) return argc == 2 ? cmd_uninstall() : usage(); if (strcmp(cmd, "why") == 0) return argc == 3 ? cmd_why(argv[2]) : usage(); if (strcmp(cmd, "needs") == 0) return argc == 2 ? cmd_needs() : usage(); if (strcmp(cmd, "need") == 0) return argc == 4 ? cmd_need(argv[2], argv[3]) : usage(); if (strcmp(cmd, "off") == 0) return argc == 2 ? cmd_off() : usage(); if (strcmp(cmd, "machine") == 0) return argc <= 3 ? cmd_machine(argc == 3 ? argv[2] : nullptr) : usage(); if (strcmp(cmd, "roots") == 0) return cmd_roots_args(argc, argv); if (strcmp(cmd, "projects") == 0) { if (argc == 2) return cmd_projects(false); return argc == 3 && strcmp(argv[2], "scan") == 0 ? cmd_projects(true) : usage(); } if (strcmp(cmd, "project") == 0) return cmd_project_args(argc, argv); if (strcmp(cmd, "check") == 0) return argc == 2 ? cmd_check_set() : argc == 3 ? cmd_check(argv[2]) : usage(); if (strcmp(cmd, "stamp") == 0) return argc >= 3 ? stamp_write(argc - 2, argv + 2) : usage(); if (strcmp(cmd, "store") == 0) return cmd_store(argc, argv); if (strcmp(cmd, "back") == 0) return argc == 3 ? store_back(argv[2]) : usage(); if (strcmp(cmd, "lint") == 0) return argc == 3 ? store_lint(argv[2]) : usage(); if (strcmp(cmd, "remote") == 0) return argc == 3 || argc == 4 ? cmd_remote(argv[2], argc == 4 ? argv[3] : nullptr) : usage(); if (strcmp(cmd, "login") == 0) return argc == 4 ? cmd_login(argv[2], argv[3]) : usage(); if (strcmp(cmd, "logout") == 0) return argc == 3 ? cmd_logout(argv[2]) : usage(); if (strcmp(cmd, "sync") == 0) return argc == 3 ? store_sync(argv[2]) : usage(); if (strcmp(cmd, "tend") == 0) return argc == 2 ? cmd_tend_all() : argc == 3 ? store_tend(argv[2]) : usage(); if (strcmp(cmd, "usage") == 0) return cmd_usage(argc - 2, argv + 2); if (strcmp(cmd, "curate") == 0) { if (argc >= 3 && strcmp(argv[2], "apply") == 0) return cmd_curate_apply(argc - 3, argv + 3); return cmd_curate(argc - 2, argv + 2); } if (strcmp(cmd, "clone") == 0) return argc == 4 ? store_clone(argv[2], argv[3]) : usage(); if (strcmp(cmd, "commit") == 0) return cmd_commit(argc, argv); if (strcmp(cmd, "upstream") == 0) return argc >= 4 ? cmd_upstream(argc, argv) : usage(); if (strcmp(cmd, "upstreams") == 0) return argc == 2 ? cmd_upstreams() : usage(); if (strcmp(cmd, "hook") == 0) return argc == 3 ? hook_dispatch(argv[2]) : usage(); if (strcmp(cmd, "hooks") == 0) return argc == 2 ? cmd_hooks() : usage(); if (strcmp(cmd, "bench") == 0) return bench_main(argc - 2, argv + 2); return usage(); }