哪种语言具有最好的 Git API 绑定?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4034962/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 04:40:36  来源:igfitidea点击:

Which language has the best Git API Bindings?

c#cgitbinding

提问by Daniel Upton

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

我正在考虑构建一个与 git 关系密切的应用程序。

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

是否有可用的语言绑定,如果有,哪些是最全面的?

Would it mean going to Bare Metal C?

这是否意味着要去 Bare Metal C?

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

还是 perl/python/php/C# 有一套完整的绑定?

Thanks

谢谢

Daniel

丹尼尔

回答by Jakub Nar?bski

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

在某些编程语言中使用 Git 有以下三种不同的方法:

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

    • JGitwhich is reimplementation of Git in Java (used among others by EGit, the EclipseGit plugin, and Gerrit Code Review),
    • Gritis Ruby library for extracting information from a git repository in an object oriented manner, which includes a partialnative Ruby implementation. Used e.g. by GitHub.
    • GitSharpwhich is remplemantation of Git in C# for .NET and Mono, and which is following JGit wrt. functionality,
    • Dulwichwhich is pure-Python read-write implementation of the Git file formats and protocols.
    • Git::PurePerlis pure Perl interface to Git repositories (it was mostly based on Grit, initially).
    • Glipis "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.

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

    • The Git.pmmodule distributed with git (and used by some of its commands), Git::Wrapperand Git::Repositorywrap git commands for Perl.
    • JavaGitis a Java API that provides access to git repositories via calling git commands.
    • GitPythonis a Python library used to interact with Git repositories, by calling the Git executables and parsing output.
    • hs-libgitis 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).

    • libgit2itself 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.
    • Geefis 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 homepagefor details.

  • 不同的语言重新实现Git。这就是以下项目所做的:

    • JGit是用 Java 重新实现 Git(被EGitEclipseGit 插件和Gerrit Code Review 使用),
    • Grit是一个 Ruby 库,用于以面向对象的方式从 git 存储库中提取信息,其中包括部分原生 Ruby 实现。例如由 GitHub 使用。
    • GitSharp它是在 C# 中为 .NET 和 Mono 重新实现的 Git,它遵循 JGit wrt。功能,
    • Dulwich是 Git 文件格式和协议的纯 Python 读写实现。
    • Git::PurePerl是 Git 存储库的纯 Perl 接口(最初主要基于 Grit)。
    • Glip是“PHP 中的 git 库”——纯 PHP 实现。由其作者用于 eWiki。
    • Monodevelop 使用的 JGit NGit.NET 端口


    重新实现的问题在于它们并不总是实现完整的功能,有时会错误地实现它。另一方面,它们是原生的,实现良好的性能;它们的许可可能不同于 Git 的 C(原始)实现,即 GPLv2。

  • 包装其称之为Git命令,并在某种包装造成的,合适的目标语言。

    • 所述Git.pm模块与GIT分布(和使用它的一些命令的),GIT中::包装GIT中::库为Perl涡卷GIT中的命令。
    • JavaGit是一个 Java API,它通过调用 git 命令提供对 git 存储库的访问。
    • GitPython是一个 Python 库,用于通过调用 Git 可执行文件和解析输出与 Git 存储库进行交互。
    • hs-libgit是 git 的 Haskell 包装器。


    包装器的问题在于它们可能很慢(它们需要派生一个 git 进程),并且它们需要安装 git 才能工作。

    还要注意 git 本身是高度可编写脚本的(例如使用 shell 脚本),这要归功于除了面向最终用户(瓷器)的高级命令之外,它还提供用于脚本编写(管道)的低级命令。

  • 最后是libgit2 的绑定,这意味着是具有可靠 API 的可重入可链接库(是 Google Summer of Code 2010 项目)。

    • libgit2本身是一个可移植的纯 C 实现。
    • Rugged- Ruby 绑定。
    • php-git- PHP 绑定。
    • luagit2- Lua 绑定。
    • GitForDelphi- Delphi 绑定。
    • libgit2sharp- .NET 绑定。
    • pygit2- Python 绑定。
    • Geef是一个简单的 Erlang NIF,它向 Erlang 公开了一些 libgit2 库函数。Monodevelop 为 JGit 使用 .NET 端口


    Libgit2 是一个相当新的项目;这是正在进行的工作,因此并非所有事情都在当时实施。有关详细信息,请参阅libgit2 主页

All this information can be found at InterfacesFrontendsAndToolspage on Git Wiki

所有这些信息都可以在 Git Wiki 的InterfacesFrontendsAndTools页面上找到

回答by Tim Schaeffer

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.

您可以尝试不使用 API。git 被构造为一组不同抽象级别的实用程序。您应该能够构建一组全面的实用程序,这些实用程序通过调用这些实用程序并处理它们的输出来工作。许多高级 git 命令是执行此操作的 shell 脚本或 perl 脚本,因此您在 git 源代码本身中有大量示例可用作示例。

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.

  • magit : 用 emacs lisp 编写的 emacs git 接口

  • git gui : tcl, 自带 git

  • gitk : tcl, 也自带git

  • gitview :python,在 contrib 目录中带有 git。

  • tig : C,用于 git 的文本模式历史浏览器。

回答by Joe D

Depends what you want, by the looks of it your most comfortable with C/C#. Git is written in C, so if you want speed then maybe you should go with that. But if you want code clarity and ease of writing GitSharp is probably a better option.

取决于您想要什么,从外观上看,您对 C/C# 最满意。Git 是用 C 编写的,所以如果你想要速度,那么也许你应该选择它。但是如果你想要代码清晰和易于编写,GitSharp 可能是更好的选择。

回答by Pondidum

I'm not sure if it is the best, but for .net there is GitSharp

我不确定它是否是最好的,但是对于 .net 有GitSharp