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'.
This commit is contained in:
Tom Willemsen 2012-07-31 02:40:56 +02:00
parent 731fba1dc4
commit 7ca2408b51
6 changed files with 53 additions and 9 deletions

View file

@ -3,14 +3,16 @@ SITEDIR = $(shell pkg-config guile-2.0 --variable=sitedir \
--define-variable=prefix=$(DESTDIR))
COMPDIR = $(DESTDIR)/lib/guile/2.0/site-ccache
objects = main.scm main.go
objects = main.scm main.go path.scm path.go
install-objects = $(addprefix install-,$(objects))
uninstall-objects = $(addprefix uninstall-,$(objects))
$(filter %.go,$(objects)): %.go: %.scm
guild compile -o $@ $^
.PHONY: all install $(install-objects) uninstall $(uninstall-objects)
.PHONY: install $(install-objects) uninstall $(uninstall-objects)
all: $(filter %.go,$(objects))
$(filter %.go,$(objects)): %.go: %.scm
../env guild compile -o $@ $^
install: $(install-objects)
uninstall: $(uninstall-objects)

View file

@ -21,6 +21,7 @@
#:use-module (ice-9 getopt-long)
#:use-module (ice-9 popen)
#:use-module (ice-9 rdelim)
#:use-module (gitto path)
#:export (main))
(define data-dir
@ -86,6 +87,7 @@ gitto [options]
(define (register-repository repository)
"Register REPOSITORY in the repository list."
(set! repository (realpath repository))
(if (not (member repository repositories))
(begin
(set! repositories (append `(,repository) repositories))
@ -96,6 +98,7 @@ gitto [options]
(define (remove-repository repository)
"Remove/unregister REPOSITORY from the repository list."
(set! repository (realpath repository))
(if (member repository repositories)
(begin
(set! repositories (delete repository repositories))

4
gitto/path.scm Normal file
View file

@ -0,0 +1,4 @@
(define-module (gitto path)
#:export (realpath))
(load-extension "libguile-gitto-path" "init_gitto")

2
src/.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
*.o
*.so

View file

@ -1,11 +1,23 @@
DESTDIR ?= /usr/local
CFLAGS = $(shell pkg-config --cflags guile-2.0) -fPIC
LDFLAGS = $(shell pkg-config --libs guile-2.0)
all:
objects = gitto-path.o
all: libguile-gitto-path.so
.PHONY: install uninstall
install: gitto
install -Dm 755 $^ ${DESTDIR}/bin/$^
libguile-gitto-path.so: gitto-path.o
$(CC) $(CFLAGS) -shared -o libguile-gitto-path.so $^
uninstall: gitto
rm -f ${DESTDIR}/bin/$^
install-gitto: gitto
install -Dm 755 $^ ${DESTDIR}/bin/$^
install-libguile-gitto-path: libguile-gitto-path.so
install -Dm 755 $^ \
$(shell pkg-config guile-2.0 --variable=extensiondir)/$^
install: install-gitto install-libguile-gitto-path
uninstall:
rm -f ${DESTDIR}/bin/gitto
rm -f $(shell pkg-config guile-2.0 --variable=extensiondir)/libguile-gitto-path.so

21
src/gitto-path.c Normal file
View file

@ -0,0 +1,21 @@
#include <stdlib.h>
#include <libguile.h>
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);
}