From 0f3997d6ff2d25c0941824ec3daa3c8e767bd73e Mon Sep 17 00:00:00 2001 From: Aargh Rai Date: Tue, 20 Oct 2026 11:20:15 +0530 Subject: wrote the entire thing using libgit2 --- src/lib.h | 61 ++++++++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 42 insertions(+), 19 deletions(-) mode change 100755 => 100644 src/lib.h (limited to 'src/lib.h') diff --git a/src/lib.h b/src/lib.h old mode 100755 new mode 100644 index 999e7d7..6c098c7 --- a/src/lib.h +++ b/src/lib.h @@ -1,24 +1,47 @@ -#include -#include -#include -#include -#include +#ifndef LIB_H_ +#define LIB_H_ + +#include +#include #include -#include -#define NULL_STR (char*)0 -#define DEFAULT_CONFIG_CONTENTS "^node_modules$\n^target$\n^build$\n^dist$\n^\\.next$\n^\\.output$\n^\\.vercel$\n^\\.wrangler$\n^\\.venv$\n^\\.astro$\n^\\.devenv$\n^__pycache__$" +#define debugf(...) if (debug) (void)printf("[debug] " __VA_ARGS__) + +int is_git_metadata_dir(char *path); + +struct tmp_repo { + git_repository* repo; + char path[70]; +}; +struct tmp_repo tmp_repo_init(); +void tmp_repo_deinit(struct tmp_repo repo); + +int check_for_backupignore(); +void copy_over_backupignore(struct tmp_repo repo); + +int is_ignored(struct tmp_repo repo, char *path); + +struct recursive_reader { + FILE *pfile; + char *line; + size_t capacity; +}; +struct recursive_reader recursive_reader_init(); +int recursive_reader_read(struct recursive_reader *reader); +void recursive_reader_deinit(struct recursive_reader reader); + +struct backup_streamer { + int cwd_length; + char to_prefix[PATH_MAX]; + char cursor[PATH_MAX]; +}; +struct backup_streamer backup_streamer_init(char *cwd); +void get_backup_destination(struct backup_streamer *streamer, char* from); -typedef enum { - path_type_unknown, - path_type_directory, - path_type_file -} path_type; +int is_dir(char *path); +void backup_file(char *from, char *to); +void ensure_parents_exist(char *path); -char* get_default_config(); -char* shift(int* argc, char*** argv); -char* get_ignore_file(char* ignore_file, int VERBOSE); -void mkdir_if_not_exist(char* path, int VERBOSE); -void verify_parent_dirs_exist(char* file_path, int VERBOSE); +int debug; -void backup(char* target, char* ignore_instructions, int VERBOSE); +#endif // LIB_H_ -- cgit v1.2.3