ani: add functions to locate .pijul
Dependencies
- [2]
2U7P5SFQChange struct names "struct foo -> typedef struct Foo" - [3]
XJ2PEH74add meson.build - [4]
FB67XX5Eadd argument parsing setup - [5]
AHIXA5ZEGet rid of all warnings, rework init code. How do I do multiline messages? - [6]
QMTJBCUJani: remove comment - [7]
XTKRT6OQformat the codebase - [8]
Q7TKZCJPAdd initial support for reading the offsets from a (fixed) change - [9]
B3XLVPNCAdd ani.c and initial Makefile - [*]
Y26WT3ZFchange: decode message, description and timestamp - [*]
PEUS54XQ
Change contents
- edit in scaffold.h at line 7
char *xstrdup(const char *str); - edit in scaffold.c at line 55[11.522]
char *xstrdup(const char *str){char *ret = strdup(str);if (!ret)die("out of memory, strdup failed");return ret;} - edit in meson.build at line 27
'dir.c', - replacement in init.c at line 32
cmd_init(int argc, const char **argv)cmd_init(int argc, const char **argv, const char *_ignore) - file addition: dir.h[12.1]
#ifndef ANI_DIR_H#define ANI_DIR_H/* Routines for working with directories */int has_dotpijul(const char *); /* check if given directory has a .pijul *//*** Search for a .pijul folder. Starts from the current working* directory, and walks up the parent directories until a directory is* found. If found, returns the absolute path (without "/.pijul" as an* allocated string. Otherwise, returns NULL*/char *find_dotpijul(void);#endif - file addition: dir.c[12.1]
#include <unistd.h>#include <stdio.h>#include <sys/types.h>#include <dirent.h>#include <string.h>#include "scaffold.h"#include "dir.h"inthas_dotpijul(const char *path){struct dirent *d;DIR *dir;int ret;ret = 0;if (!(dir = opendir(path)))return ret;while ((d = readdir(dir)) != NULL) {if (!strncmp(d->d_name, ".pijul", 6)) {ret = 1;break;}}closedir(dir);return ret;}#ifndef PATH_MAX#define PATH_MAX 4096#endifchar *find_dotpijul(){/*** idea is this: set a string to current directory, check if* ".pijul" is present - if not, cd("..") and look again.*/char path[PATH_MAX] = { 0 };char *s = NULL;int found = 0;if (!getcwd(path, PATH_MAX))die("unable to get current working directory");while (!(found = has_dotpijul(path)) && path != s) {s = strrchr(path, '/');*s = '\0';}if (!found)return NULL;s = xstrdup(path);return s;} - replacement in change.c at line 654
cmd_change(int argc, char **argv)cmd_change(int argc, char **argv, const char *pijul_dir) - edit in ani.c at line 7
#include "dir.h" - edit in ani.c at line 10
#define NEED_WORK_TREE (1 << 0) - replacement in ani.c at line 22
int (*fn)(int, const char **);int (*fn)(int, const char **, const char *);unsigned int flags; - replacement in ani.c at line 27
{ "init", cmd_init },{ "change", cmd_change },{ "init", cmd_init, 0 },{ "change", cmd_change, NEED_WORK_TREE }, - edit in ani.c at line 58
char *pijul_dir = NULL; - replacement in ani.c at line 71
return (command->fn)(argc, argv);if (command->flags & NEED_WORK_TREE) {pijul_dir = find_dotpijul();if (!pijul_dir)die("no Pijul repository found");}return (command->fn)(argc, argv, pijul_dir);