Artifact 984ab8126ccb5c6f5b344e46c7e81a0cc696d752a726aa591b6f9cd6468b1eaa:
- File
src/upstream.h
— part of check-in
[2d73c831f4]
at
2026-11-16 18:00:10
on branch trunk
— An accepted upstream update can be undone, and merges use the recorded base
suit upstream NAME undo reverses the last accept by a new check-in on trunk. Every file that accept changed goes back to what it was, the record upstreams/NAME goes back to the check-in accepted before (or is removed), and the upstream is waiting for review again. History is not rewritten. A file edited on trunk since the accept is a conflict: the command lists it and changes nothing. Undo twice walks back two accepts. An undo is never followed by an automatic accept.
The merge base for an upstream is now the branch check-in the record names, or trunk's first check-in when there is no record, and no longer what the library infers from ancestry. The dry run, the merge and suit's own check for deleted files all use that one base. Because of it:
- the same update can be accepted again after an undo, and gives exactly the files it gave before; - a newer take accepted after an undo brings all of its content, not only its difference from the undone one; - after accept --mine, a later update that leaves the settled lines alone merges cleanly, where it could conflict again before. One that changes them again is a conflict, as it should be.
A take no longer mistakes a file an undo brought back for one of the owner's own. The settle writer restores a file's mode as well as its bytes.
Left: a record edited by hand to name a check-in that is not on the branch makes accept fall back to the library's common ancestor.
159 new store cases, among them the undo story both ways, undo across two machines, and undo in the fault sweep.
1473 unit checks, 620 shell cases, 1153 store cases (was 994), 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 (44 minutes). 100% coverage in all 26 source files. One existing line changed: the fault sweep's list gained undo. (user: dmestas, size: 3001) [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]...`, // `diff` and `undo`. 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