在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
libgit2 - the Git linkable library
Table of Contents
Using libgit2Most of these instructions assume that you're writing an applicationin C and want to use libgit2 directly. If you're not using C,and you're writing in a different language or platform like .NET,Node.js, or Ruby, then there is probably a"language binding" that you can use to take careof the messy tasks of calling into native code. But if you do want to use libgit2 directly - because you're buildingan application in C - then you may be able use an existing binary.There are packages for thevcpkg andconanpackage managers. And libgit2 is available inHomebrew and most Linuxdistributions. However, these versions may be outdated and we recommend using thelatest version if possible. Thankfully libgit2 is not hard to compile. Quick StartPrerequisites for building libgit2:
Build
Trouble with these steps? Read our troubleshooting guide.More detailed build guidance is available below. Getting HelpChat with us
Getting Help If you have questions about the library, please be sure to check out theAPI documentation. If you still havequestions, reach out to us on Slack or post a question onStackOverflow (with the Reporting Bugs Please open a GitHub Issue andinclude as much information as possible. If possible, provide sample codethat illustrates the problem you're seeing. If you're seeing a bug onlyon a specific repository, please provide a link to it if possible. We ask that you not open a GitHub Issue for help, only for bug reports. Reporting Security Issues Please have a look at SECURITY.md. What It Can Dolibgit2 provides you with the ability to manage Git repositories in theprogramming language of your choice. It's used in production to power manyapplications including GitHub.com, Plastic SCM and Azure DevOps. It does not aim to replace the git tool or its user-facing commands. Some APIsresemble the plumbing commands as those align closely with the concepts of theGit system, but most commands a user would type are out of scope for thislibrary to implement directly. The library provides:
As libgit2 is purely a consumer of the Git system, we have toadjust to changes made upstream. This has two major consequences:
Optional dependenciesWhile the library provides git functionality without the need fordependencies, it can make use of a few libraries to add to it:
InitializationThe library needs to keep track of some global state. Call git_libgit2_init(); before calling any other libgit2 functions. You can call this function many times. A matching number of calls to git_libgit2_shutdown(); will free the resources. Note that if you have worker threads, you shouldcall ThreadingSee threading for information ConventionsSee conventions for an overview of the externaland internal API/coding conventions we use. Building libgit2 - Using CMakeBuilding
The On most systems you can build the library using the following commands $ mkdir build && cd build$ cmake ..$ cmake --build . Alternatively you can point the CMake GUI tool to the CMakeLists.txt file and generate platform specific build project or IDE workspace. If you're not familiar with CMake, a more detailed explanation may be helpful. Running TestsOnce built, you can run the tests from the $ ctest -V Alternatively you can run the test suite directly using, $ ./libgit2_tests Invoking the test suite directly is useful because it allows you to executeindividual tests, or groups of tests using the $ ./libgit2_tests -sindex To run a single test named $ ./libgit2_tests -sindex::racy::diff The test suite will print a Note: There should be no failing tests when you build an unmodifiedsource tree from a release,or from the main branch.Please contact us or open an issueif you see test failures. InstallationTo install the library you can specify the install prefix by setting: $ cmake .. -DCMAKE_INSTALL_PREFIX=/install/prefix$ cmake --build . --target install Advanced UsageFor more advanced use or questions about CMake please read https://cmake.org/Wiki/CMake_FAQ. The following CMake variables are declared:
To list all build options and their current value, you can do thefollowing: # Create and set up a build directory$ mkdir build$ cmake ..# List all build options and their values$ cmake -L Compiler and linker optionsCMake lets you specify a few variables to control the behavior of thecompiler and linker. These flags are rarely used but can be useful for64-bit to 32-bit cross-compilation.
MacOS XIf you want to build a universal binary for Mac OS X, CMake sets itall up for you if you use AndroidExtract toolchain from NDK using, SET(CMAKE_SYSTEM_NAME Linux)SET(CMAKE_SYSTEM_VERSION Android)SET(CMAKE_C_COMPILER {PATH}/bin/arm-linux-androideabi-gcc)SET(CMAKE_CXX_COMPILER {PATH}/bin/arm-linux-androideabi-g++)SET(CMAKE_FIND_ROOT_PATH {PATH}/sysroot/)SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) Add MinGWIf you want to build the library in MinGW environment with SSH support enabled,you may need to pass Another option would be to install Language BindingsHere are the bindings to libgit2 that are currently available:
If you start another language binding to libgit2, please let us know sowe can add it to the list. How Can I Contribute?We welcome new contributors! We have a number of issues marked as"up for grabs"and"easy fix"that are good places to jump in and get started. There's much more detailedinformation in our list of outstanding projects. Please be sure to check the contribution guidelines tounderstand our workflow, and the libgit2 coding conventions. License
See the COPYING file for the full license text. |
请发表评论