summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSadeep Madurange <sadeep@asciimx.com>2026-02-28 22:07:39 +0800
committerSadeep Madurange <sadeep@asciimx.com>2026-03-01 11:42:37 +0800
commit999a97899d67924dd66c5a632a12f8fe4201a9a7 (patch)
treee1fb1e3eaba045dc5363abdfda029b2f1b2b163e
parent81267fd2afcbe5516018ec2f4fdd4c0c1bbbf1aa (diff)
downloadcvn-999a97899d67924dd66c5a632a12f8fe4201a9a7.tar.gz
Create .cvn dir and empty index.
-rw-r--r--.gitignore4
-rw-r--r--Makefile2
-rw-r--r--main.c42
3 files changed, 40 insertions, 8 deletions
diff --git a/.gitignore b/.gitignore
index c803222..b398ecb 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,6 @@
-svs
+cvn
+.cvn/
+
**/*.o
**/*.out
**/*.swp
diff --git a/Makefile b/Makefile
index 780931c..9104cae 100644
--- a/Makefile
+++ b/Makefile
@@ -1,5 +1,5 @@
CC = cc
-TARGET = svs
+TARGET = cvn
SRC = main.c
OBJ = $(SRC:.c=.o)
diff --git a/main.c b/main.c
index ddf094e..d9c3c53 100644
--- a/main.c
+++ b/main.c
@@ -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);
}