git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH/RFC 1/7] Add support for ruby commands

From
Felipe Contreras <felipe.contreras@gmail.com>
Date
Sep 21, 2013, 18:48 UTC
Message-ID
<1379789295-18519-2-git-send-email-felipe.contreras@gmail.com>
In-Reply-To
<1379789295-18519-1-git-send-email-felipe.contreras@gmail.com>
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 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
Previous: Felipe ContrerasNext: Felipe Contreras
Message 2 of 26 in “Support for Ruby”
  1. 0/7 Support for RubyFelipe Contreras, Sep 21, 2013
  2. 1/7 Add support for ruby commandsFelipe Contreras, Sep 21, 2013
  3. 2/7 ruby: add setup scriptFelipe Contreras, Sep 21, 2013
  4. 3/7 ruby: add simple wrappersFelipe Contreras, Sep 21, 2013
  5. 4/7 ruby: rewrite 'request-pull'Felipe Contreras, Sep 21, 2013
  6. 5/7 ruby: rewrite perl scriptFelipe Contreras, Sep 21, 2013
  7. 6/7 ruby: remove one forkFelipe Contreras, Sep 21, 2013
  8. 7/7 ruby: rewrite 'reset'Felipe Contreras, Sep 21, 2013
  9. brian m. carlsonSep 21, 2013
  10. Felipe ContrerasSep 21, 2013
  11. brian m. carlsonSep 21, 2013
  12. Felipe ContrerasSep 22, 2013
  13. Fredrik GustafssonSep 22, 2013
  14. Felipe ContrerasSep 22, 2013
  15. Fredrik GustafssonSep 22, 2013
  16. Felipe ContrerasSep 22, 2013
  17. Patrick DonnellySep 23, 2013
  18. Felipe ContrerasSep 23, 2013
  19. Patrick DonnellySep 23, 2013
  20. Felipe ContrerasSep 23, 2013
  21. Junio C HamanoSep 23, 2013
  22. brian m. carlsonSep 23, 2013
  23. Felipe ContrerasSep 28, 2013
  24. Felipe ContrerasSep 23, 2013
  25. Felipe ContrerasSep 28, 2013
  26. Felipe ContrerasSep 28, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.