-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.h
More file actions
56 lines (44 loc) · 1.7 KB
/
Copy pathindex.h
File metadata and controls
56 lines (44 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// index.h — Staging area (index) interface
//
// The index is a text file (.pes/index) that tracks which files are
// staged for the next commit. It maps file paths to their blob hashes
// and stores metadata for fast change detection.
#ifndef INDEX_H
#define INDEX_H
#include "pes.h"
#define MAX_INDEX_ENTRIES 10000
typedef struct {
uint32_t mode; // File mode (100644, 100755, etc.)
ObjectID hash; // SHA-256 of the staged blob
uint64_t mtime_sec; // Last modification time (seconds since epoch)
uint32_t size; // File size in bytes at time of staging
char path[512]; // Relative path from repo root (e.g., "src/main.c")
} IndexEntry;
typedef struct {
IndexEntry entries[MAX_INDEX_ENTRIES];
int count;
} Index;
// Load the index from .pes/index into memory.
// If the file does not exist (no files staged yet), initializes an empty index.
int index_load(Index *index);
// Save the index to .pes/index using atomic write (temp file + rename).
int index_save(const Index *index);
// Stage a file: read its contents, write as a blob, update/add index entry.
int index_add(Index *index, const char *path);
// Remove a file from the index (unstage it).
int index_remove(Index *index, const char *path);
// Find an entry by path. Returns pointer to the entry, or NULL if not found.
IndexEntry* index_find(Index *index, const char *path);
// Print the status of the working directory compared to the index and HEAD.
// Output format:
// Staged changes:
// staged: <path>
//
// Unstaged changes:
// modified: <path>
// deleted: <path>
//
// Untracked files:
// untracked: <path>
int index_status(const Index *index);
#endif // INDEX_H