Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which language has the best Git API Bindings? [closed]

Tags:

git

c

c#

binding

I am looking at building an application with heavy ties to git..

Are there language bindings available and if so which are the most comprehensive?

Would it mean going to Bare Metal C?

Or does perl / python / php / C# have a set of full bindings?

Thanks

Daniel

like image 478
Daniel Upton Avatar asked Oct 27 '10 15:10

Daniel Upton


People also ask

What language does git use?

Git was designed as a set of programs written in C and several shell scripts that provide wrappers around those programs. Although most of those scripts have since been rewritten in C for speed and portability, the design remains, and it is easy to chain the components together.

Is there a git API?

Libgit2 is a dependency-free implementation of Git, with a focus on having a nice API for use within other programs. You can find it at https://libgit2.org.


2 Answers

There are three different approaches with respect to using Git from within some programming language:

  • Reimplementation of Git in different language. That is what the following projects do:

    • JGit which is reimplementation of Git in Java (used among others by EGit, the Eclipse Git plugin, and Gerrit Code Review),
    • Grit is Ruby library for extracting information from a git repository in an object oriented manner, which includes a partial native Ruby implementation. Used e.g. by GitHub.
    • GitSharp which is remplemantation of Git in C# for .NET and Mono, and which is following JGit wrt. functionality,
    • Dulwich which is pure-Python read-write implementation of the Git file formats and protocols.
    • Git::PurePerl is pure Perl interface to Git repositories (it was mostly based on Grit, initially).
    • Glip is "git library in PHP" - pure PHP implementation. Used by its author for eWiki.
    • NGit .NET port of JGit used by Monodevelop


    The problem with reimplementations is that they do not always implement the full functionality, and sometimes implement it wrong. On the other hand they are native, implement good performance; they may be licensed differently than C (original) implementation of Git, which is GPLv2.

  • Wrappers which call Git commands and wrap result it in some kind, suitably for target language.

    • The Git.pm module distributed with git (and used by some of its commands), Git::Wrapper and Git::Repository wrap git commands for Perl.
    • JavaGit is a Java API that provides access to git repositories via calling git commands.
    • GitPython is a Python library used to interact with Git repositories, by calling the Git executables and parsing output.
    • hs-libgit is Haskell wrapper for git.


    The problem with wrappers is that they can be slow (they require forking a git process), and that they require git to be installed to work.

    Note also that git itself is highly scriptable (e.g. using shell scripts), thanks to the fact that beside higher level commands meant for end user (porcelain) it also provides low level commands meant for scripting (plumbing).

  • Finally there are bindings to libgit2, which means to be re-entrant linkable library with a solid API (was Google Summer of Code 2010 project).

    • libgit2 itself is a portable, pure C implementation.
    • Rugged - Ruby bindings.
    • php-git - PHP bindings.
    • luagit2 - Lua bindings.
    • GitForDelphi - Delphi bindings.
    • libgit2sharp - .NET bindings.
    • pygit2 - Python bindings.
    • Geef is a simple Erlang NIF that exposes some of the libgit2 library functions to Erlang. Monodevelop uses a .NET port for JGit


    Libgit2 is quite new project; it is work in progress, so not everything is implemented at the time of being. See libgit2 homepage for details.

All this information can be found at InterfacesFrontendsAndTools page on Git Wiki

like image 72
Jakub Narębski Avatar answered Sep 22 '22 10:09

Jakub Narębski


You might try not using an API. git is structured as a suite of utilities at different levels of abstraction. You should be able to build a comprehensive set of utilities which work by calling out to these utilities and processing their output. Many of the high-level git commands are shell scripts or perl scripts which do just this, so you have plenty of examples in the git source itself to use as examples.

Good examples to start with:

  • magit : git interface for emacs written in emacs lisp

  • git gui : tcl, comes with git

  • gitk : tcl, also comes with git

  • gitview : python, comes with git in the contrib directory.

  • tig : C, text-mode history browswer for git.

like image 22
Tim Schaeffer Avatar answered Sep 21 '22 10:09

Tim Schaeffer