xonecas.io
7814
Ta

tiny-c-agent / files

tiny-c-agent / src / diff.h

1.5 KB
1// tiny working-tree diffs: what a tool run changed on disk.
2//
3// The changes are display-only. A snapshot records the working tree; diffing
4// the snapshots around a run yields the changed files, each a unified patch or
5// a note for content that cannot be tracked. A process-wide cache keyed by the
6// stat triple (size, mtime, ino) means a later snapshot re-reads only files
7// whose stat moved.
8
9#ifndef TINY_DIFF_H
10#define TINY_DIFF_H
11
12#include <stddef.h>
13#include <time.h>
14
15#include "tool.h"
16
17struct tiny_snapshot;
18
19// Captures the working tree under the current directory. Files modified at or
20// after `force_since` (realtime, may be NULL) are re-read even if their stat is
21// unchanged, covering edits within one mtime tick.
22struct tiny_snapshot *tiny_snapshot_capture(const struct timespec *force_since);
23void tiny_snapshot_free(struct tiny_snapshot *s);
24
25// The files that differ between two snapshots, sorted by path. The caller owns
26// the result; free it with tiny_file_diffs_free.
27tiny_file_diff *tiny_snapshot_diff(const struct tiny_snapshot *before,
28                                   const struct tiny_snapshot *after, size_t *len);
29void tiny_file_diffs_free(tiny_file_diff *diffs, size_t len);
30
31// A unified diff of two in-memory texts, with the same header a working-tree
32// patch carries. `a`/`b` may be NULL when their length is 0. The caller owns
33// the result.
34char *tiny_unified_diff(const char *path, const char *a, size_t alen,
35                        const char *b, size_t blen);
36
37#endif