Add new pristine subcommand
Dependencies
- [2]
SMB3M6ESchange: rework to make more testable - [3]
Q7TKZCJPAdd initial support for reading the offsets from a (fixed) change - [4]
XJ2PEH74add meson.build - [5]
XTKRT6OQformat the codebase - [6]
L3HKOF4Wwrap vendored zstd seekable in own file, #2 - [7]
YM2LC6QPwrap vendored blake3 in own file, #2 - [8]
ZPNA2D42ani: add functions to locate .pijul - [9]
B3XLVPNCAdd ani.c and initial Makefile - [*]
67HZZ5HSmeson: shuffle lib and exe sources - [*]
PEUS54XQ - [*]
FB67XX5Eadd argument parsing setup - [*]
ZTDGWUGPadd repository structure - [*]
DRK7G22JAdd header guard to commands.h
Change contents
- replacement in meson.build at line 32
'change.c''change.c','db.c', - edit in meson.build at line 46
'cmd-pristine.c', - file addition: db.h[12.1]
#ifndef ANI_DB_H#define ANI_DB_Hstruct globalheader {u16 version; // sanakirja versionu8 root; // which page is currently the root page?u8 nroots; // how many root pages are there?u32 crc; // CRC of this pageu64 length; // first free page at the end of the fileu64 freedb; // offset of the free listu64 rcdb; // offset of the RC db};void dbrun(char *);#endif - file addition: db.c[12.1]
#include <stdint.h>#include <stddef.h>#include <stdio.h>#include <stdlib.h>#include <fcntl.h>#include <unistd.h>#include <stdbool.h>#include <sys/mman.h>#include "common.h"#include "types.h"#include "scaffold.h"#include "db.h"#define err(msg) \do { \perror(msg); \exit(EXIT_FAILURE); \} while (0)static voiddumpbytes(u8 *mem, usize len){usize i;for (i = 0; i < len; i++) {printf("%02x ", mem[i]);}printf("\n");}static voidreadglobalheader(u8 *mem, struct globalheader *gh){dumpbytes(mem, sizeof(struct globalheader));// FIXME: Does not work for big-endian systems*gh = *((struct globalheader *)mem);}static voidprintglobalheader(struct globalheader *gh, bool currentroot){printf("version = %u root = %u %s nroots = %u\n", gh->version, gh->root,currentroot ? "(current)" : "", gh->nroots);printf("CRC = 0x%04x (%u)\n", gh->crc, gh->crc);printf("length = %lu (0x%08lx)\n", gh->length, gh->length);printf("freedb = %lu\n", gh->freedb);printf("rcdb = %lu\n", gh->rcdb);}voiddbrun(char *db){int fd;u8 *addr;u8 nroots, curroot;size i;struct globalheader gh;printf("opening %s\n", db);fd = open(db, O_RDONLY);if (fd == -1)err("open");usize length = 4096;int prot = PROT_READ; // memory protection; PROT_{EXEC,READ,WRITE,NONE}int flags = MAP_PRIVATE; // determines visibilityoff_t offset = 0;addr = mmap(NULL, length, prot, flags, fd, offset);if (addr == MAP_FAILED)err("mmap");readglobalheader(addr, &gh);munmap(addr, length);nroots = gh.nroots;curroot = gh.root;printglobalheader(&gh, curroot == 0);// for nroots-1 times, read the i << 12'th pagefor (i = 1; i < nroots; i++) {addr = mmap(NULL, length, prot, flags, fd, i << 12);if (addr == MAP_FAILED)err("mmap2");readglobalheader(addr, &gh);munmap(addr, length);printglobalheader(&gh, curroot == i);}close(fd);} - edit in commands.h at line 6[14.423][15.40]
int cmd_pristine(int, const char **, struct repository *); - file addition: cmd-pristine.c[12.1]
#include <stdint.h>#include <stddef.h>#include <unistd.h>#include <string.h>#include "common.h"#include "types.h"#include "repository.h"#include "db.h"static voidformatdbpath(char *dst, const char *repodir){char *p;p = stpncpy(dst, repodir, PATH_MAX);*p++ = '/';p = stpncpy(p, DOTPIJUL, 6);*p++ = '/';p = stpncpy(p, "pristine/db", 11);}intcmd_pristine(int argc, char *argv, struct repository *repo){char dbpath[4096] = { 0 };(void)argc;(void)argv;formatdbpath(dbpath, repo->path);dbrun(dbpath);return 0;} - replacement in ani.c at line 18
" init Initialize empty repository\n"" change Show information about a particular change\n";" init Initialize empty repository\n"" change Show information about a particular change\n"" pristine Show information about the repository database\n"; - edit in ani.c at line 32
{ "pristine", cmd_pristine, NEED_WORK_TREE },