[PATCH v2 02/44] ruby: add support for internal ruby programs
Signed-off-by: Felipe Contreras felipe.contre...@gmail.com --- Makefile | 9 + ruby.c | 19 ++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 2fdee15..27e61c0 100644 --- a/Makefile +++ b/Makefile @@ -429,6 +429,7 @@ BASIC_LDFLAGS = # Guard against environment variables BUILTIN_OBJS = BUILT_INS = +RUBY_PROGRAMS = COMPAT_CFLAGS = COMPAT_OBJS = XDIFF_OBJS = @@ -493,6 +494,8 @@ SCRIPT_PYTHON += git-p4.py SCRIPT_RUBY += git-rb-setup.rb +PROGRAMS += $(RUBY_PROGRAMS) + NO_INSTALL += git-remote-testgit NO_INSTALL += git-remote-testpy @@ -1754,6 +1757,12 @@ $(BUILT_INS): git$X ln -s $ $@ 2/dev/null || \ cp $ $@ +$(RUBY_PROGRAMS): git-ruby$X + $(QUIET_BUILT_IN)$(RM) $@ \ + ln $ $@ 2/dev/null || \ + ln -s $ $@ 2/dev/null || \ + cp $ $@ + common-cmds.h: ./generate-cmdlist.sh command-list.txt common-cmds.h: $(wildcard Documentation/git-*.txt) diff --git a/ruby.c b/ruby.c index ee6a0e7..339e376 100644 --- a/ruby.c +++ b/ruby.c @@ -52,5 +52,22 @@ static int run_ruby_command(const char *cmd, int argc, const char **argv) int main(int argc, const char **argv) { - return run_ruby_command(argv[1], argc, argv); + if (!strcmp(argv[0], git-ruby)) { + return run_ruby_command(argv[1], argc, argv); + } else { + const char *cmd = argv[0]; + static char buf[PATH_MAX + 1]; + const char *args[argc + 1]; + int i; + + snprintf(buf, PATH_MAX, %s/%s.rb, + git_exec_path(), basename((char *)cmd)); + + args[0] = git; + args[1] = buf; + for (i = 0; i argc - 1; i++) + args[i + 2] = (char *)argv[i + 1]; + + return run_ruby_command(cmd, argc + 1, args); + } } -- 1.8.4-fc -- To unsubscribe from this list: send the line unsubscribe git in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v2 02/44] ruby: add support for internal ruby programs
Felipe Contreras wrote: +$(RUBY_PROGRAMS): git-ruby$X + $(QUIET_BUILT_IN)$(RM) $@ \ + ln lt; $@ 2/dev/null || \ + ln -s lt; $@ 2/dev/null || \ + cp lt; $@ Why so many fallbacks? Will the hard-link (the first ln) ever fail? diff --git a/ruby.c b/ruby.c index ee6a0e7..339e376 100644 --- a/ruby.c +++ b/ruby.c @@ -52,5 +52,22 @@ static int run_ruby_command(const char *cmd, int argc, const char **argv) int main(int argc, const char **argv) { - return run_ruby_command(argv[1], argc, argv); + if (!strcmp(argv[0], git-ruby)) { + return run_ruby_command(argv[1], argc, argv); + } else { + const char *cmd = argv[0]; + static char buf[PATH_MAX + 1]; + const char *args[argc + 1]; + int i; + + snprintf(buf, PATH_MAX, %s/%s.rb, + git_exec_path(), basename((char *)cmd)); + + args[0] = git; + args[1] = buf; + for (i = 0; i argc - 1; i++) + args[i + 2] = (char *)argv[i + 1]; + + return run_ruby_command(cmd, argc + 1, args); + } } Can you explain this in greater detail in your commit message? When I pass an argument, $ git ruby foo git-ruby: No such file or directory -- foo (LoadError) I get this as before. How exactly will new ruby scripts be executed? (I can only guess at this point) -- To unsubscribe from this list: send the line unsubscribe git in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v2 02/44] ruby: add support for internal ruby programs
On Sat, Sep 28, 2013 at 11:40 PM, Ramkumar Ramachandra artag...@gmail.com wrote: Felipe Contreras wrote: +$(RUBY_PROGRAMS): git-ruby$X + $(QUIET_BUILT_IN)$(RM) $@ \ + ln lt; $@ 2/dev/null || \ + ln -s lt; $@ 2/dev/null || \ + cp lt; $@ Why so many fallbacks? Will the hard-link (the first ln) ever fail? Because that's what the code right on top of this is doing. I presume it would fail in file-systems that don't have hard-links. diff --git a/ruby.c b/ruby.c index ee6a0e7..339e376 100644 --- a/ruby.c +++ b/ruby.c @@ -52,5 +52,22 @@ static int run_ruby_command(const char *cmd, int argc, const char **argv) int main(int argc, const char **argv) { - return run_ruby_command(argv[1], argc, argv); + if (!strcmp(argv[0], git-ruby)) { + return run_ruby_command(argv[1], argc, argv); + } else { + const char *cmd = argv[0]; + static char buf[PATH_MAX + 1]; + const char *args[argc + 1]; + int i; + + snprintf(buf, PATH_MAX, %s/%s.rb, + git_exec_path(), basename((char *)cmd)); + + args[0] = git; + args[1] = buf; + for (i = 0; i argc - 1; i++) + args[i + 2] = (char *)argv[i + 1]; + + return run_ruby_command(cmd, argc + 1, args); + } } Can you explain this in greater detail in your commit message? When I pass an argument, $ git ruby foo git-ruby: No such file or directory -- foo (LoadError) I get this as before. How exactly will new ruby scripts be executed? (I can only guess at this point) If you do: % git ruby foo It's the same as % ruby foo You need the script right there, as a file named foo. However, this already works before this patch. What this patch does is enable: % git foo But for this you need two things: 1) A binary named git-foo in your path, that is a link to git-ruby, which is what the variable RUBY_PROGRAMS is for in the Makefile 2) A script named git-foo.rb in your exec-path. So basically git-foo is the same as git ruby $GIT_EXEC_PATH/git-foo.rb. -- Felipe Contreras -- To unsubscribe from this list: send the line unsubscribe git in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v2 02/44] ruby: add support for internal ruby programs
On Sat, Sep 28, 2013 at 11:56 PM, Felipe Contreras felipe.contre...@gmail.com wrote: On Sat, Sep 28, 2013 at 11:40 PM, Ramkumar Ramachandra diff --git a/ruby.c b/ruby.c index ee6a0e7..339e376 100644 --- a/ruby.c +++ b/ruby.c @@ -52,5 +52,22 @@ static int run_ruby_command(const char *cmd, int argc, const char **argv) int main(int argc, const char **argv) { - return run_ruby_command(argv[1], argc, argv); + if (!strcmp(argv[0], git-ruby)) { + return run_ruby_command(argv[1], argc, argv); + } else { + const char *cmd = argv[0]; + static char buf[PATH_MAX + 1]; + const char *args[argc + 1]; + int i; + + snprintf(buf, PATH_MAX, %s/%s.rb, + git_exec_path(), basename((char *)cmd)); + + args[0] = git; + args[1] = buf; + for (i = 0; i argc - 1; i++) + args[i + 2] = (char *)argv[i + 1]; + + return run_ruby_command(cmd, argc + 1, args); + } } Can you explain this in greater detail in your commit message? When I pass an argument, $ git ruby foo git-ruby: No such file or directory -- foo (LoadError) I get this as before. How exactly will new ruby scripts be executed? (I can only guess at this point) If you do: % git ruby foo It's the same as % ruby foo You need the script right there, as a file named foo. However, this already works before this patch. What this patch does is enable: % git foo But for this you need two things: 1) A binary named git-foo in your path, that is a link to git-ruby, which is what the variable RUBY_PROGRAMS is for in the Makefile 2) A script named git-foo.rb in your exec-path. So basically git-foo is the same as git ruby $GIT_EXEC_PATH/git-foo.rb. Note that this is for _internal_ Ruby programs, if you want git foo to run yours, or a third party script, you can do it like this: cat git-foo EOF #!git ruby #ruby code EOF chmod +x and put it on your PATH, done :) -- Felipe Contreras -- To unsubscribe from this list: send the line unsubscribe git in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html