Signed-off-by: Felipe Contreras <felipe.contreras@xxxxxxxxx> --- Makefile | 4 ++++ cache.h | 2 ++ git.c | 3 +++ ruby.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 57 insertions(+) create mode 100644 ruby.c diff --git a/Makefile b/Makefile index 3588ca1..7cbcbcb 100644 --- a/Makefile +++ b/Makefile @@ -899,6 +899,7 @@ LIB_OBJS += ws.o LIB_OBJS += wt-status.o LIB_OBJS += xdiff-interface.o LIB_OBJS += zlib.o +LIB_OBJS += ruby.o BUILTIN_OBJS += builtin/add.o BUILTIN_OBJS += builtin/annotate.o @@ -1502,6 +1503,9 @@ ifneq (,$(XDL_FAST_HASH)) BASIC_CFLAGS += -DXDL_FAST_HASH endif +EXTLIBS += $(shell pkg-config --libs ruby-2.0) +BASIC_CFLAGS += $(shell pkg-config --cflags ruby-2.0) + ifeq ($(TCLTK_PATH),) NO_TCLTK = NoThanks endif diff --git a/cache.h b/cache.h index 85b544f..4b1abd4 100644 --- a/cache.h +++ b/cache.h @@ -1393,4 +1393,6 @@ int stat_validity_check(struct stat_validity *sv, const char *path); */ void stat_validity_update(struct stat_validity *sv, int fd); +extern void handle_ruby_command(int argc, const char **argv); + #endif /* CACHE_H */ diff --git a/git.c b/git.c index 2025f77..0e1d97d 100644 --- a/git.c +++ b/git.c @@ -499,6 +499,9 @@ static int run_argv(int *argcp, const char ***argv) /* See if it's an internal command */ handle_internal_command(*argcp, *argv); + /* See if it's a ruby command */ + handle_ruby_command(*argcp, *argv); + /* .. then try the external ones */ execv_dashed_external(*argv); diff --git a/ruby.c b/ruby.c new file mode 100644 index 0000000..5701753 --- /dev/null +++ b/ruby.c @@ -0,0 +1,48 @@ +#include "cache.h" +#include "exec_cmd.h" + +#undef NORETURN +#undef PATH_SEP + +#include <ruby.h> + +static const char *commands[] = { +}; + +static void run_ruby_command(int argc, const char **argv) +{ + const char *cmd = argv[0]; + static char buf[PATH_MAX + 1]; + const char *dir; + char *args[argc + 2]; + void *node; + VALUE prefix; + int i; + + dir = git_exec_path(); + snprintf(buf, PATH_MAX, "%s/git-%s.rb", dir, cmd); + + ruby_init(); + + prefix = Qnil; + rb_define_variable("$prefix", &prefix); + + args[0] = "git"; + args[1] = buf; + for (i = 0; i < argc; i++) + args[i + 2] = (char*)argv[i]; + node = ruby_options(argc + 2, args); + + exit(ruby_run_node(node)); +} + +void handle_ruby_command(int argc, const char **argv) +{ + int i; + for (i = 0; i < ARRAY_SIZE(commands); i++) { + if (strcmp(commands[i], argv[0])) + continue; + + run_ruby_command(argc, argv); + } +} -- 1.8.4-fc -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html