939232e72e
Added: Project Overview TUI Build Cache / Dirty Detection Post-Build Hooks gbuild status
83 lines
3.0 KiB
C
83 lines
3.0 KiB
C
#ifndef INDEX_H
|
|
#define INDEX_H
|
|
|
|
#include <time.h>
|
|
#include <stddef.h>
|
|
|
|
#define IDX_MAX_PROJECTS 256
|
|
#define IDX_NAME_LEN 128
|
|
#define IDX_HASH_LEN 64
|
|
#define IDX_PATH_LEN 512
|
|
|
|
/*
|
|
* Per-project record stored in ~/.gbuild_index.
|
|
*
|
|
* File format (INI-style, one section per project):
|
|
*
|
|
* [myproject]
|
|
* last_build_rc = 0
|
|
* last_build_ts = 1716000000
|
|
* last_head_hash = abc123def456
|
|
*/
|
|
typedef struct {
|
|
char name[IDX_NAME_LEN];
|
|
int last_build_rc; /* exit code of last make_build(); -1 = never built */
|
|
time_t last_build_ts; /* unix timestamp of last build attempt */
|
|
char last_head_hash[IDX_HASH_LEN]; /* git HEAD hash at last build */
|
|
} ProjectRecord;
|
|
|
|
typedef struct {
|
|
ProjectRecord projects[IDX_MAX_PROJECTS];
|
|
int count;
|
|
} ProjectIndex;
|
|
|
|
/* Load ~/.gbuild_index into idx. Returns 0 on success, -1 if not found
|
|
* (idx is still initialised to an empty index). */
|
|
int index_load(ProjectIndex *idx, const char *path);
|
|
|
|
/* Persist idx to path, creating or overwriting the file. */
|
|
int index_save(const ProjectIndex *idx, const char *path);
|
|
|
|
/* Find a record by name. Returns a pointer into idx->projects, or NULL. */
|
|
ProjectRecord *index_find(ProjectIndex *idx, const char *name);
|
|
|
|
/* Find or create a record by name. Returns NULL only if the index is full. */
|
|
ProjectRecord *index_upsert(ProjectIndex *idx, const char *name);
|
|
|
|
/* Walk clone_dir, find every subdir that contains .git, and upsert each one
|
|
* into idx. Does NOT overwrite existing build metadata — only adds new
|
|
* entries for projects that are not yet tracked.
|
|
* Returns the number of new entries added. */
|
|
int index_scan(ProjectIndex *idx, const char *clone_dir);
|
|
|
|
/* Canonical path for the index file (~/.gbuild_index). */
|
|
void index_get_path(char *out, size_t n);
|
|
|
|
/* ---------------------------------------------------------------- status scan */
|
|
|
|
/*
|
|
* Per-project status gathered by project_scan_all().
|
|
* All string fields are NUL-terminated; numeric fields are -1 when unknown.
|
|
*/
|
|
typedef struct {
|
|
char name[IDX_NAME_LEN];
|
|
char branch[128]; /* current branch / "(detached:HASH)" */
|
|
int behind; /* commits behind upstream; -1 = no upstream/error */
|
|
int dirty; /* 1 = dirty, 0 = clean, -1 = error */
|
|
int last_build_rc; /* from index; -1 = never built */
|
|
time_t last_build_ts; /* from index; 0 = never built */
|
|
} StatusResult;
|
|
|
|
/*
|
|
* Scan every subdirectory of clone_dir that contains .git.
|
|
* For each one, fetch the three git metrics and join them with build
|
|
* metadata from idx. Results are written into results[0..max-1].
|
|
* Worker threads run the git queries in parallel (pool of SCAN_THREADS).
|
|
* Returns the number of projects found (may be 0, capped at max).
|
|
*/
|
|
#define SCAN_THREADS 6
|
|
int project_scan_all(const char *clone_dir, const ProjectIndex *idx,
|
|
StatusResult *results, int max);
|
|
|
|
#endif /* INDEX_H */
|