From 7ca2408b51b94fc2d3740cbd4bb02b368efa457c Mon Sep 17 00:00:00 2001 From: Tom Willemsen Date: Tue, 31 Jul 2012 02:40:56 +0200 Subject: Add relative directory parsing As of now, when using `-r' or `-R', relative directories can be used. This *does not* include locations starting with `~', those still need to be handled by your shell. Because every repo is treated as a possible relative path, and thus passed on to `realpath', the paths have become very uniform. This means that it will now only register and unregister paths that don't have a trailing `/'. This is not true during usage, so those paths still work, but they can't be removed by gitto, and adding them again will create a duplicate entry. * gitto/Makefile (objects): Add `path.scm' and `path.go'. (.PHONY): Add `all' as a phony target. (all): New target, compiles all `.go' targets. ($(filter %.go,$(objects))): Use `env' to run guild so that include paths are setup properly. * gitto/main.scm (gitto): Use new `(gitto path)' module, it contains the `realpath' function. (register-repository): (remove-repository): Always pass REPOSITORY through `realpath' and use the result. * gitto/path.scm: New file. Loads the `libguile-gitto-path' extension and exports its `realpath' function. * src/Makefile (CFLAGS): (LDFLAGS): Use `pkg-config' to gather the necessary values for guile. (libguile-gitto-path.so): New guile extension, wraps the `readline' POSIX function. * src/gitto-path.c: New file, wraps and exports the `realpath' POSIX function from `stdlib.h'. --- src/gitto-path.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 src/gitto-path.c (limited to 'src/gitto-path.c') diff --git a/src/gitto-path.c b/src/gitto-path.c new file mode 100644 index 0000000..ad1400a --- /dev/null +++ b/src/gitto-path.c @@ -0,0 +1,21 @@ +#include +#include + +SCM +realpath_wrapper(SCM str) +{ + char *path = scm_to_locale_string(str); + char *resolved_path = realpath(path, NULL); + SCM scm_resolved_path = scm_from_locale_string(resolved_path); + + free(path); + free(resolved_path); + + return scm_resolved_path; +} + +void +init_gitto() +{ + scm_c_define_gsubr("realpath", 1, 0, 0, realpath_wrapper); +} -- cgit v1.2.3-54-g00ecf