-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmvcs.h
More file actions
105 lines (86 loc) · 2.74 KB
/
mvcs.h
File metadata and controls
105 lines (86 loc) · 2.74 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#ifndef MVCS_H
#define MVCS_H
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <dirent.h>
#include <time.h>
#include <unistd.h>
/* Repository paths */
#define MVCS_DIR ".mvcs"
#define OBJECTS_DIR ".mvcs/objects"
#define REFS_DIR ".mvcs/refs"
#define REFS_HEADS_DIR ".mvcs/refs/heads"
#define HEAD_FILE ".mvcs/HEAD"
#define INDEX_FILE ".mvcs/index"
/* Object types */
#define OBJ_BLOB 1
#define OBJ_TREE 2
#define OBJ_COMMIT 3
/* Hash length (SHA-256) */
#define HASH_SIZE 32
#define HASH_HEX_SIZE 65
/* Maximum sizes */
#define MAX_PATH_LEN 4096
#define MAX_CONTENT_SIZE (10 * 1024 * 1024) /* 10MB */
#define MAX_TREE_ENTRIES 1000
#define MAX_INDEX_ENTRIES 1000
/* Tree entry structure */
typedef struct {
int mode;
char name[256];
unsigned char hash[HASH_SIZE];
} tree_entry_t;
/* Index entry structure */
typedef struct {
char path[MAX_PATH_LEN];
unsigned char hash[HASH_SIZE];
int mode;
} index_entry_t;
/* Commit structure */
typedef struct {
unsigned char tree_hash[HASH_SIZE];
unsigned char parent_hash[HASH_SIZE];
int has_parent;
char author[256];
char message[1024];
time_t timestamp;
} commit_t;
/* Function declarations */
/* Repository operations */
int mvcs_init(void);
int mvcs_is_repo(void);
/* Object operations */
int compute_hash(const void *data, size_t len, unsigned char *hash);
void hash_to_hex(const unsigned char *hash, char *hex);
int hex_to_hash(const char *hex, unsigned char *hash);
int write_object(int type, const void *data, size_t len, unsigned char *hash);
int read_object(const unsigned char *hash, int *type, void **data, size_t *len);
char *get_object_path(const unsigned char *hash, char *path);
/* Blob operations */
int hash_file(const char *path, unsigned char *hash);
int write_blob(const char *path, unsigned char *hash);
/* Tree operations */
int write_tree(tree_entry_t *entries, int count, unsigned char *hash);
int read_tree(const unsigned char *hash, tree_entry_t **entries, int *count);
/* Commit operations */
int write_commit(const commit_t *commit, unsigned char *hash);
int read_commit(const unsigned char *hash, commit_t *commit);
/* Index operations */
int read_index(index_entry_t **entries, int *count);
int write_index(index_entry_t *entries, int count);
int add_to_index(const char *path);
/* Reference operations */
int update_ref(const char *ref, const unsigned char *hash);
int read_ref(const char *ref, unsigned char *hash);
int get_head(unsigned char *hash);
/* High-level operations */
int mvcs_add(const char *path);
int mvcs_commit(const char *message);
int mvcs_log(void);
/* Utility functions */
int create_directory(const char *path);
int file_exists(const char *path);
int is_directory(const char *path);
#endif /* MVCS_H */