/* * montauk-paths.h -- teach git what an absolute path looks like on MontaukOS. * * FORCE-INCLUDED into every translation unit (-include, see the port * Makefile), because it has to win the #ifndef guards in git-compat-util.h. * * MontaukOS paths are drive-prefixed: "0:/users/dan/repo". getcwd() returns * one of those, and the kernel's path resolver (kernel/src/Api/Path.hpp) * accepts three forms -- "N:/abs", "/abs" (the current drive's root) and * "rel/ative" against the process cwd. * * Without this header git's is_absolute_path() is just is_dir_sep(path[0]), * so every MontaukOS absolute path reads as RELATIVE and git helpfully * prepends the cwd to it: "0:/users/dan/repo/0:/users/dan/repo". That breaks * setup_git_directory(), real_path() and every worktree path it stores. * * The fix reuses git's existing Windows abstraction rather than inventing * one: has_dos_drive_prefix / skip_dos_drive_prefix / offset_1st_component * are exactly the hooks the DOS "C:/" case goes through, and a MontaukOS * drive differs only in being a digit run rather than a letter. The bodies * below mirror compat/win32/path-utils.c, minus the UNC handling, which has * no MontaukOS equivalent. */ #ifndef _MONTAUK_GIT_PATHS_H_ #define _MONTAUK_GIT_PATHS_H_ /* * "12:" as well as "0:" -- ParseDrivePrefix() accepts a multi-digit drive * number, so this must too, or a two-digit drive would silently be treated * as a relative path. */ static inline int montauk_has_drive_prefix(const char *path) { int i = 0; if (!path) return 0; while (path[i] >= '0' && path[i] <= '9') i++; return i > 0 && path[i] == ':'; } #define has_dos_drive_prefix montauk_has_drive_prefix static inline int montauk_skip_drive_prefix(char **path) { int i = 0; if (!montauk_has_drive_prefix(*path)) return 0; while ((*path)[i] >= '0' && (*path)[i] <= '9') i++; *path += i + 1; /* the digits and the ':' */ return 1; } #define skip_dos_drive_prefix montauk_skip_drive_prefix /* * Length of the leading "root" of the path: the drive prefix plus one * separator if present. Mirrors win32_offset_1st_component(). */ static inline int montauk_offset_1st_component(const char *path) { char *pos = (char *)path; montauk_skip_drive_prefix(&pos); return (int)(pos - path) + (*pos == '/'); } #define offset_1st_component montauk_offset_1st_component #endif /* _MONTAUK_GIT_PATHS_H_ */