Artifact 9d68a503d44939ae17932366887f3ce24cbe0a58bb8a97c941ea8fac8545771e:
- File
src/upstream.h
— part of check-in
[3cb21b0428]
at
2026-11-16 08:11:34
on branch trunk
— Phase 8c-1: an upstream is taken from a folder, reviewed, and merged
suit upstream NAME take FOLDER checks the upstream's files in on the branch upstream-NAME of the wardrobe that defines it, at INTO/ENTRY, with the comment upstream NAME at PIN. The check-in is built as a deck on a repository opened with no checkout, so the working copy is not touched. Its first parent is trunk's first check-in, so a later merge is three-way. Dot entries are skipped, links are refused, the lint runs, and a file that something else supplies is a clash. into is a new key, default skills; trust defaults to review.
With trust = review the update waits: the attention file says so, suit upstreams lists each upstream as never taken, current, waiting for review or conflict, and suit upstream NAME diff lists what accept would add, change, remove or conflict on. suit upstream NAME accept merges the branch into trunk after a dry run. A conflict changes no file and writes no marker; --mine PATH and --theirs PATH settle one. With trust = auto a clean take is accepted at once.
Every accept writes the tracked file upstreams/NAME, holding the hash and pin it accepted, into its merge check-in. So a merge that changes no other file can still be checked in, and keeping your version of the only conflict ends as current.
The proof: a local fix to a taken file survives an update that changes another line, and an update that rewrites the same line waits as a conflict with trunk byte-identical to before.
Limits, all in docs/upstreams.md. suit back after an accept refuses, as after any check-in, and no command undoes an accept. diff prints the list of files, not their text. After --mine, a later take that touches the same lines can conflict again, because the library leaves the merge parent off that check-in. Accept works only at trunk's tip. A wardrobe and an upstream of one name share an attention item. Fetching over the network is part two and is not built.
1473 unit checks (was 1431), 620 shell cases (was 612), 968 store cases (was 669), 846 placement cases and 378 project cases, under clang, under gcc 16, with no user name set, and under a strict umask, in one run of make gate (34 minutes). 100% coverage in all 26 source files. The speed budget still passes. No existing case was changed. (user: dmestas, size: 3102) [annotate] [blame] [check-ins using]
#ifndef SUIT_UPSTREAM_H #define SUIT_UPSTREAM_H #include "conf.h" #include <stddef.h> #include <stdint.h> // Upstreams (docs/upstreams.md): an upstream's files are taken from a folder // onto the branch upstream-NAME of the wardrobe that defines it, and merged // into trunk when they are accepted. constexpr uint32_t UPSTREAM_FILES_MAX = 4096; constexpr uint64_t UPSTREAM_BYTES_MAX = 64ull * 1024 * 1024; constexpr size_t UPSTREAM_REL_MAX = 512; // a file's path inside its entry's folder constexpr size_t UPSTREAM_NAME_MAX = CONF_INTO_MAX + 1 + UPSTREAM_REL_MAX; // INTO/REL constexpr size_t UPSTREAM_PIN_MAX = 256; // the longest pin constexpr uint32_t UPSTREAM_SETTLE_MAX = 64; // --theirs and --mine in all // The files a take reads, in byte order of name: NAME is the path in the // wardrobe (INTO/ENTRY/...) and the file is ROOT/REL, REL being NAME without // the INTO/ in front. typedef struct { const char *name; uint64_t size; bool exec; } UpstreamFile; typedef struct { uint32_t n; uint64_t bytes; char prefix[CONF_INTO_MAX + 2]; // INTO and a slash size_t into_len; // strlen of prefix char root[4096]; // the folder read UpstreamFile f[UPSTREAM_FILES_MAX]; char pool[UPSTREAM_FILES_MAX][UPSTREAM_NAME_MAX + 1]; } UpstreamFiles; // What a take is asked to do, after the config has been read. typedef struct { const char *name; // the upstream const char *pin; // the config's pin: a word const char *into; // where the files land in the wardrobe bool auto_accept; // trust = auto } UpstreamSpec; // The paths `accept` is told to settle: the upstream's version for THEIRS and // trunk's for MINE. typedef struct { uint32_t ntheirs; uint32_t nmine; const char *theirs[UPSTREAM_SETTLE_MAX]; const char *mine[UPSTREAM_SETTLE_MAX]; } UpstreamSettle; // Where an upstream stands. typedef enum { UPSTREAM_NEVER_TAKEN, UPSTREAM_CURRENT, UPSTREAM_WAITING, UPSTREAM_CONFLICT, } UpstreamState; // The attention item's kind, and the texts of its two headers. constexpr char UPSTREAM_ITEM[] = "upstream"; // The folder of the wardrobe that holds upstreams/NAME, the record of what was accepted. constexpr char UPSTREAM_RECORD_DIR[] = "upstreams"; // Read FOLDER, or FOLDER/PATH when PATH is given, for the upstream NAME into F: skip every entry whose // name starts with a dot, refuse a symlink, take regular files, keep the // executable bit. Returns 0; 1 after a message on stderr (a file or folder // that cannot be read, a symlink, a path that is too long, more than // UPSTREAM_FILES_MAX files or UPSTREAM_BYTES_MAX bytes). int upstream_scan(UpstreamFiles *f, const char *name, const char *folder, const char *path, const char *into); // `suit upstream NAME take FOLDER`, `accept [--theirs PATH] [--mine PATH]...` // and `diff`. ARGV is the whole command line; ARGC is at least 4. int cmd_upstream(int argc, char **argv); // `suit upstreams`. int cmd_upstreams(void); #endif