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

Re: [PATCH v2 02/44] ruby: add support for internal ruby programs

From
Felipe Contreras <felipe.contreras@gmail.com>
Date
Sep 29, 2013, 05:07 UTC
Message-ID
<CAMP44s186x7uWh8-0hHK+3ye=-7UsdJSUZbFODG+bgKkS1PZwA@mail.gmail.com>
In-Reply-To
<CAMP44s28B+UX1ofQb_sZfaPG2htvQ=W_EvScVbFgmR9P4SnvPg@mail.gmail.com>

On Sat, Sep 28, 2013 at 11:56 PM, Felipe Contreras <felipe.contreras@gmail.com> wrote:

> On Sat, Sep 28, 2013 at 11:40 PM, Ramkumar Ramachandra
Show 62 quoted lines
>>> 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
Previous: Felipe ContrerasNext: Felipe Contreras
Message 8 of 62 in “Ruby support”
  1. 00/44 Ruby supportFelipe Contreras, Sep 28, 2013
  2. 01/44 Add support for ruby commandsFelipe Contreras, Sep 28, 2013
  3. Ramkumar RamachandraSep 29, 2013
  4. Felipe ContrerasSep 29, 2013
  5. 02/44 ruby: add support for internal ruby programsFelipe Contreras, Sep 28, 2013
  6. Ramkumar RamachandraSep 29, 2013
  7. Felipe ContrerasSep 29, 2013
  8. Felipe ContrerasSep 29, 2013
  9. 03/44 request-pull: fix annotated tag checkFelipe Contreras, Sep 28, 2013
  10. Ramkumar RamachandraSep 29, 2013
  11. 04/44 request-pull: fix for specific branchFelipe Contreras, Sep 28, 2013
  12. 05/44 request-pull: use appropriate refFelipe Contreras, Sep 28, 2013
  13. 06/44 request-pull: fix exact match checkingFelipe Contreras, Sep 28, 2013
  14. 07/44 request-pull: trivial simplificationFelipe Contreras, Sep 28, 2013
  15. 08/44 request-pull: t: trivial whitespace style fixesFelipe Contreras, Sep 28, 2013
  16. 09/44 request-pull: t: add missing catFelipe Contreras, Sep 28, 2013
  17. 10/44 ruby: rewrite 'request-pull'Felipe Contreras, Sep 28, 2013
  18. Ramkumar RamachandraSep 29, 2013
  19. 11/44 ruby: request-pull: rewrite perl scriptFelipe Contreras, Sep 28, 2013
  20. Ramkumar RamachandraSep 29, 2013
  21. 12/44 ruby: request-pull: trivial simplificationsFelipe Contreras, Sep 28, 2013
  22. 13/44 ruby: bind setup_git_directory()Felipe Contreras, Sep 28, 2013
  23. Ramkumar RamachandraSep 29, 2013
  24. Felipe ContrerasSep 29, 2013
  25. 14/44 ruby: bind dwim_ref()Felipe Contreras, Sep 28, 2013
  26. Ramkumar RamachandraSep 29, 2013
  27. Felipe ContrerasSep 29, 2013
  28. 15/44 ruby: request-pull: use native dwim_ref()Felipe Contreras, Sep 28, 2013
  29. 16/44 ruby: bind git_config()Felipe Contreras, Sep 28, 2013
  30. 17/44 ruby: request-pull: use native git_config()Felipe Contreras, Sep 28, 2013
  31. 18/44 ruby: bind read_ref()/peel_ref()Felipe Contreras, Sep 28, 2013
  32. 19/44 ruby: bind get_sha1()Felipe Contreras, Sep 28, 2013
  33. 20/44 ruby: request-pull: simplify tag fetchingFelipe Contreras, Sep 28, 2013
  34. 21/44 ruby: request-pull: use get_sha1()Felipe Contreras, Sep 28, 2013
  35. 22/44 ruby: add Commit classFelipe Contreras, Sep 28, 2013
  36. 23/44 ruby: bind get_merge_bases()Felipe Contreras, Sep 28, 2013
  37. 24/44 ruby: request-pull: use get_merge_bases()Felipe Contreras, Sep 28, 2013
  38. 25/44 ruby: request-pull: trivial cleanupsFelipe Contreras, Sep 28, 2013
  39. 26/44 ruby: bind remote and transport stuffFelipe Contreras, Sep 28, 2013
  40. 27/44 ruby: request-pull: use native remote and transportFelipe Contreras, Sep 28, 2013
  41. 28/44 ruby: bind find_unique_abbrev()Felipe Contreras, Sep 28, 2013
  42. 29/44 ruby: request-pull: use native commit infoFelipe Contreras, Sep 28, 2013
  43. 30/44 ruby: bind read_sha1_file()Felipe Contreras, Sep 28, 2013
  44. 31/44 ruby: request-pull: use read_sha1_file()Felipe Contreras, Sep 28, 2013
  45. 32/44 revision: add missing includeFelipe Contreras, Sep 28, 2013
  46. 33/44 shortlog: add missing declarationFelipe Contreras, Sep 28, 2013
  47. 34/44 shortlog: split builtin from common codeFelipe Contreras, Sep 28, 2013
  48. 35/44 ruby: add RevInfo and DiffOptionsFelipe Contreras, Sep 28, 2013
  49. 36/44 ruby: bind shortlog()Felipe Contreras, Sep 28, 2013
  50. 37/44 ruby: request-pull: use shortlog()Felipe Contreras, Sep 28, 2013
  51. 38/44 ruby: bind diff_tree_sha1()Felipe Contreras, Sep 28, 2013
  52. 39/44 ruby: bind log_tree_diff_flush()Felipe Contreras, Sep 28, 2013
  53. 40/44 ruby: request-pull: use native diff_tree stuffFelipe Contreras, Sep 28, 2013
  54. 41/44 ruby: request-pull: remove rescue blockFelipe Contreras, Sep 28, 2013
  55. 42/44 ruby: remove GIT_PAGER from environmentFelipe Contreras, Sep 28, 2013
  56. Stefan BellerSep 28, 2013
  57. Felipe ContrerasSep 28, 2013
  58. 43/44 ruby: add simpler option parserFelipe Contreras, Sep 28, 2013
  59. 44/44 request-pull: rewrite to CFelipe Contreras, Sep 28, 2013
  60. Ramkumar RamachandraSep 29, 2013
  61. Ramkumar RamachandraSep 29, 2013
  62. Felipe ContrerasSep 29, 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.