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

Re: [RFC PATCH] repack: rewrite the shell script in C.

From
Stefan Beller <stefanbeller@googlemail.com>
Date
Aug 15, 2013, 07:46 UTC
Message-ID
<520C873A.9070900@googlemail.com>
In-Reply-To
<201308141725.43127.mfick@codeaurora.org>
On 08/15/2013 01:25 AM, Martin Fick wrote:
Show 46 quoted lines
> On Wednesday, August 14, 2013 04:51:14 pm Matthieu Moy 
> wrote:
>> Antoine Pelisse <apelisse@gmail.com> writes:
>>> On Wed, Aug 14, 2013 at 6:27 PM, Stefan Beller
>>>
>>> <stefanbeller@googlemail.com> wrote:
>>>>  builtin/repack.c               | 410
>>>>  +++++++++++++++++++++++++++++++++++++++++
>>>>  contrib/examples/git-repack.sh | 194
>>>>  +++++++++++++++++++ git-repack.sh                  |
>>>>  194 -------------------
>>>
>>> I'm still not sure I understand the trade-off here.
>>>
>>> Most of what git-repack does is compute some file
>>> paths, (re)move those files and call git-pack-objects,
>>> and potentially git-prune-packed and
>>> git-update-server-info.
>>> Maybe I'm wrong, but I have the feeling that the
>>> correct tool for that is Shell, rather than C (and I
>>> think the code looks less intuitive in C for that
>>> matter).
>>
>> There's a real problem with git-repack being shell (I
>> already mentionned it in the previous thread about the
>> rewrite): it creates dependencies on a few external
>> binaries, and a restricted server may not have them. I
>> have this issue on a fusionforge server where Git repos
>> are accessed in a chroot with very few commands
>> available: everything went OK until the first project
>> grew enough to require a "git gc --auto", and then it
>> stopped accepting pushes for that project.
>>
>> I tracked down the origin of the problem and the
>> sysadmins disabled auto-gc, but that's not a very
>> satisfactory solution.
>>
>> C is rather painfull to write, but as a sysadmin, drop
>> the binary on your server and it just works. That's
>> really important. AFAIK, git-repack is the only
>> remaining shell part on the server, and it's rather
>> small. I'd really love to see it disapear.
> 
> I didn't review the proposed C version, but how was it 
> planning on removing the dependencies on these binaries?  
> Was it planning to reimplement mv, cp, find?  

These small programms (at least mv and cp) are just convenient interfaces for system calls from within the shell. You can use these system calls to achieve a similar results compared to the commandline option. http://linux.die.net/man/2/rename http://linux.die.net/man/2/unlink

> Were there 
> other binaries that were problematic that you were thinking 
> of?  From what I can tell it also uses test, mkdir, sed, 
> chmod and naturally sh, that is 8 dependencies. 

mkdir, test, chmod are also easily done via system calls. The system calls are usually capsulated by the libc to have an easy C interface. (A standard C function call)

sed and find are tricky indeed, but you can get around it with a few lines of C (maybe 10?) for each occurrence. We don't need the full power of sed and find, but rather only the exact specific matching regexp.

 If those
Show 6 quoted lines
> can't be depended upon for existing, perhaps git should just 
> consider bundling busy-box or some other limited shell 
> utils, or yikes!, even its own reimplementation of these 
> instead of implementing these independently inside other git 
> programs?
> 

The C version as of now has twice the lines of code than the shell version. And I am pretty sure I did some rookie mistakes, so the code can be down-sized by better use of already existing functions. So I guess the final version will have less lines than in the proposed patch as of now.

Previous: Martin FickNext: Martin Fick
Message 67 of 72 in “Rewriting git-repack in C”
  1. Rewriting git-repack in CStefan Beller, Aug 13, 2013
  2. repack: rewrite the shell script in C.Stefan Beller, Aug 13, 2013
  3. Matthieu MoyAug 14, 2013
  4. Stefan BellerAug 14, 2013
  5. repack: rewrite the shell script in C.Stefan Beller, Aug 14, 2013
  6. Antoine PelisseAug 14, 2013
  7. Stefan BellerAug 14, 2013
  8. Jeff KingAug 14, 2013
  9. Martin FickAug 14, 2013
  10. Stefan BellerAug 14, 2013
  11. Martin FickAug 14, 2013
  12. Junio C HamanoAug 14, 2013
  13. Martin FickAug 14, 2013
  14. Junio C HamanoAug 15, 2013
  15. [RFC PATCHv2] repack: rewrite the shell script in C.Stefan Beller, Aug 16, 2013
  16. René ScharfeAug 17, 2013
  17. Kyle J. McKayAug 17, 2013
  18. Stefan BellerAug 18, 2013
  19. [RFC PATCHv3] repack: rewrite the shell script in C.Stefan Beller, Aug 18, 2013
  20. Kyle J. McKayAug 18, 2013
  21. René ScharfeAug 18, 2013
  22. [RFC PATCHv4] repack: rewrite the shell script in C.Stefan Beller, Aug 18, 2013
  23. [RFC PATCHv4] repack: rewrite the shell script in C.Stefan Beller, Aug 19, 2013
  24. Johannes SixtAug 20, 2013
  25. Stefan BellerAug 20, 2013
  26. Johannes SixtAug 20, 2013
  27. René ScharfeAug 20, 2013
  28. Stefan BellerAug 20, 2013
  29. repack: rewrite the shell script in C.Stefan Beller, Aug 20, 2013
  30. Jonathan NiederAug 21, 2013
  31. Stefan BellerAug 21, 2013
  32. Stefan BellerAug 21, 2013
  33. 1/2 repack: rewrite the shell script in CStefan Beller, Aug 21, 2013
  34. 2/2 repack: retain the return value of pack-objectsStefan Beller, Aug 21, 2013
  35. Junio C HamanoAug 21, 2013
  36. Matthieu MoyAug 21, 2013
  37. Stefan BellerAug 21, 2013
  38. Junio C HamanoAug 21, 2013
  39. Stefan BellerAug 21, 2013
  40. Johannes SixtAug 22, 2013
  41. Jonathan NiederAug 22, 2013
  42. Matthieu MoyAug 21, 2013
  43. Stefan BellerAug 21, 2013
  44. Matthieu MoyAug 21, 2013
  45. Stefan BellerAug 21, 2013
  46. Matthieu MoyAug 21, 2013
  47. Johannes SixtAug 22, 2013
  48. Johannes SixtAug 22, 2013
  49. repack: rewrite the shell script in C (squashing proposal)Stefan Beller, Aug 22, 2013
  50. Junio C HamanoAug 22, 2013
  51. Jonathan NiederAug 20, 2013
  52. Johannes SixtAug 21, 2013
  53. Stefan BellerAug 20, 2013
  54. Jonathan NiederAug 20, 2013
  55. Dokumenting api-paths.txtStefan Beller, Aug 20, 2013
  56. Jonathan NiederAug 20, 2013
  57. Stefan BellerAug 21, 2013
  58. Junio C HamanoAug 22, 2013
  59. Junio C HamanoAug 14, 2013
  60. Matthieu MoyAug 14, 2013
  61. Stefan BellerAug 15, 2013
  62. Duy NguyenAug 15, 2013
  63. Junio C HamanoAug 14, 2013
  64. Matthieu MoyAug 14, 2013
  65. Martin FickAug 14, 2013
  66. Martin FickAug 15, 2013
  67. Stefan BellerAug 15, 2013
  68. Martin FickAug 15, 2013
  69. Duy NguyenAug 15, 2013
  70. Junio C HamanoAug 14, 2013
  71. Stefan BellerAug 15, 2013
  72. Matthieu MoyAug 14, 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.