diff options
| author | Sadeep Madurange <sadeep@asciimx.com> | 2026-02-28 22:07:39 +0800 |
|---|---|---|
| committer | Sadeep Madurange <sadeep@asciimx.com> | 2026-03-01 11:42:37 +0800 |
| commit | 999a97899d67924dd66c5a632a12f8fe4201a9a7 (patch) | |
| tree | e1fb1e3eaba045dc5363abdfda029b2f1b2b163e | |
| parent | 81267fd2afcbe5516018ec2f4fdd4c0c1bbbf1aa (diff) | |
| download | cvn-999a97899d67924dd66c5a632a12f8fe4201a9a7.tar.gz | |
Create .cvn dir and empty index.
| -rw-r--r-- | .gitignore | 4 | ||||
| -rw-r--r-- | Makefile | 2 | ||||
| -rw-r--r-- | main.c | 42 |
3 files changed, 40 insertions, 8 deletions
@@ -1,4 +1,6 @@ -svs +cvn +.cvn/ + **/*.o **/*.out **/*.swp @@ -1,5 +1,5 @@ CC = cc -TARGET = svs +TARGET = cvn SRC = main.c OBJ = $(SRC:.c=.o) @@ -1,8 +1,14 @@ +#include <errno.h> +#include <fcntl.h> #include <stdio.h> #include <string.h> #include <unistd.h> -#define DEFAULT_BRANCH_NAME "master" +#include <sys/stat.h> +#include <sys/types.h> + +#define REPO ".cvn" +#define INDEX "index" static inline void init(int argc, char *argv[]); @@ -35,22 +41,46 @@ int main(int argc, char *argv[]) return 0; } -void init(int argc, char *argv[]) +static inline void init(int argc, char *argv[]) { - int opt; char *branch; + int opt, repo_fd, idx_fd; optind = 1; - branch = DEFAULT_BRANCH_NAME; + branch = "master"; while ((opt = getopt(argc, argv, "b:")) != -1) { switch (opt) { case 'b': branch = optarg; break; - default: return; + default: + break; } } - printf("Initialized repository, branch: %s\n", branch); + + if (mkdir(REPO, 0755) == -1) { + if (errno != EEXIST) { + perror("Failed to create repository"); + return; + } + } + + if ((repo_fd = open(REPO, O_RDONLY | O_DIRECTORY)) == -1) { + perror("Failed to open repository"); + return; + } + + if ((idx_fd = openat(repo_fd, INDEX, O_WRONLY | O_CREAT | O_EXCL, 0644)) == -1) { + if (errno != EEXIST) { + close(repo_fd); + perror("Failed to create index"); + return; + } + } + + close(idx_fd); + close(repo_fd); + printf("Initialized repository in %s\n", REPO); } |
