Artifact 93e2b4354b443172e134fb1161e81545b404548487f0579ebbf495fe2c8fedf4:
- File
src/upstream.h
— part of check-in
[db386ba414]
at
2026-11-16 14:13:46
on branch trunk
— An upstream's attention item survives tend and goes when it is settled
Two faults in how upstream items were kept.
suit tend removes a wardrobe's items without naming a kind, and that matched the item of an upstream with the same name, so a pending update was forgotten until someone ran suit upstreams. A remove with no kind now leaves upstream items alone. The item's text is unchanged and files written before this read as before.
A machine that had taken an upstream kept its item after the update was accepted on another machine and synced here. After the working copy is updated, every upstream whose tip the tracked file upstreams/NAME records as accepted has its item removed; one still waiting keeps its item. With no upstream branch this costs one query.
26 new store cases: a wardrobe and an upstream of one name through take, tend and accept; a file in the old form; two machines; and the read, open and rename failures.
1473 unit checks, 620 shell cases, 994 store cases (was 968), 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 (43 minutes). 100% coverage in all 26 source files. No existing case was changed. (user: dmestas, size: 2993) [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 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