lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

> I don't know if things improved, but using os.execue used to be the only
> choice, since the git C part was not meant to be a library, or better,
> it was meant to be a library for one-shot commands. AFAIK they
> deliberately omitted frees, since git commands run for few seconds and
> then terminate (thus memory is "collected by the OS).

Yes, Sputnik's git backend is using os.execute() because this seemed
like the only option at the time (last summer). There were a few
attempts at turning git into a library in the summer and the fall, but
I am not sure what their status is. There has also been an attempt to
re-write git in pure Python.

I would love to see a lua binding, though os.execute has been working
ok for me. When I started on it, I tried to write an LPEG parser for
git output and almost got it working, but then realized that you can
tell git-log how to format the history as **Lua** and just loadstring
the output. The downside to this approach is that you have to run
git-log twice: first time you just look for the longest sequence of
equal signs, the second time you tell git to generate history as Lua
using [===...===[ with the proper number of equal signs as string

   local format = '--pretty=format:"'.."table.insert(commits, "
                     .."{version='%h', timestamp='%ct', author='%ae',"
                     .." comment=["..max_eqs.."=[%s%n%n%b]="..max_eqs.."]})"
   local history_as_lua = "commits = {}\n"
                          ..git("log", format, path)
                          .."\nreturn commits"

Then evaluate history_as_lua in a sandbox.

- yuri