Merge branch 'upstream'

* upstream: (1173 commits)
  Update CHANGELOG with the release number
  filter: add docs for streaming filters
  iterator_walk: cast away constness for free
  filter::stream: free the filter sanely
  submodule: correctly delimit the keys to use for lookup
  submodule: add failing test for loading the wrong submodule
  submodule: completely remove reload_all
  Fix 8.3 filename tests failure when 8.3 is disabled
  Fix #3093 - remove declaration of unused function git_fetch__download_pack
  http: fixed leak when asking for credentials again
  index tests: add eol to avoid compiler warning
  checkout test: mark unused vars
  winhttp: remove unused var
  posix compat: include sys/stat.h for mingw
  diff: use size_t format
  fix memory leak in refspec.c on errors.
  checkout test: check getcwd return value
  clar: test chdir
  filter test: pass base type
  examples: clean up some warnings
  ...
This commit is contained in:
Russell Sim 2015-07-26 20:52:12 +10:00
commit bc62400d7e
2416 changed files with 40228 additions and 11231 deletions

14
.editorconfig Normal file
View File

@ -0,0 +1,14 @@
; Check http://editorconfig.org/ for more informations
; Top-most EditorConfig file
root = true
; tab indentation
[*]
indent_style = tab
trim_trailing_whitespace = true
insert_final_newline = true
; 4-column space indentation
[*.md]
indent_style = space
indent_size = 4

3
.gitattributes vendored
View File

@ -1,2 +1 @@
*.c eol=lf
*.h eol=lf
* text=auto

1
.gitignore vendored
View File

@ -28,5 +28,6 @@ msvc/Release/
!cmake/Modules/*.cmake
.DS_Store
*~
.*.swp
tags
mkmf.log

View File

@ -15,9 +15,21 @@ compiler:
env:
global:
- secure: "YnhS+8n6B+uoyaYfaJ3Lei7cSJqHDPiKJCKFIF2c87YDfmCvAJke8QtE7IzjYDs7UFkTCM4ox+ph2bERUrxZbSCyEkHdjIZpKuMJfYWja/jgMqTMxdyOH9y8JLFbZsSXDIXDwqBlC6vVyl1fP90M35wuWcNTs6tctfVWVofEFbs="
- GITTEST_INVASIVE_FS_SIZE=1
matrix:
- OPTIONS="-DTHREADSAFE=ON -DCMAKE_BUILD_TYPE=Release"
- OPTIONS="-DBUILD_CLAR=ON -DBUILD_EXAMPLES=ON"
- OPTIONS="-DTHREADSAFE=OFF -DBUILD_EXAMPLES=ON"
addons:
apt:
packages:
- cmake
- libssh2-1-dev
- openssh-client
- openssh-server
- valgrind
sudo: false
matrix:
fast_finish: true
@ -26,16 +38,24 @@ matrix:
compiler: gcc
include:
- compiler: i586-mingw32msvc-gcc
env: OPTIONS="-DBUILD_CLAR=OFF -DWIN32=ON -DMINGW=ON -DUSE_SSH=OFF"
env: OPTIONS="-DCMAKE_TOOLCHAIN_FILE=../script/toolchain-mingw32.cmake" SKIP_TESTS=1
os: linux
- compiler: gcc
env: COVERITY=1
os: linux
- compiler: gcc
env:
- VALGRIND=1
OPTIONS="-DBUILD_CLAR=ON -DBUILD_EXAMPLES=OFF -DCMAKE_BUILD_TYPE=Debug"
os: linux
allow_failures:
- env: COVERITY=1
- env:
- VALGRIND=1
OPTIONS="-DBUILD_CLAR=ON -DBUILD_EXAMPLES=OFF -DCMAKE_BUILD_TYPE=Debug"
install:
- ./script/install-deps-${TRAVIS_OS_NAME}.sh
- if [ "$TRAVIS_OS_NAME" = "osx" ]; then ./script/install-deps-${TRAVIS_OS_NAME}.sh; fi
# Run the Build script and tests
script:
@ -43,13 +63,13 @@ script:
# Run Tests
after_success:
- if [ "$TRAVIS_OS_NAME" = "linux" ]; then sudo apt-get -qq install valgrind; fi
- if [ "$TRAVIS_OS_NAME" = "linux" ]; then valgrind --leak-check=full --show-reachable=yes --suppressions=./libgit2_clar.supp _build/libgit2_clar -ionline; fi
- if [ "$TRAVIS_OS_NAME" = "linux" -a -n "$VALGRIND" ]; then valgrind --leak-check=full --show-reachable=yes --suppressions=./libgit2_clar.supp _build/libgit2_clar -ionline; fi
# Only watch the development branch
# Only watch the development and master branches
branches:
only:
- development
- master
- /^maint.*/
# Notify development list when needed
notifications:

View File

@ -49,6 +49,7 @@ Microsoft Corporation
Olivier Ramonat
Peter Drahoš
Pierre Habouzit
Pierre-Olivier Latour
Przemyslaw Pawelczyk
Ramsay Jones
Robert G. Jakabosky

537
CHANGELOG.md Normal file
View File

@ -0,0 +1,537 @@
v0.23 + 1
-------
### Changes or improvements
### API additions
### API removals
v0.23
------
### Changes or improvements
* Patience and minimal diff drivers can now be used for merges.
* Merges can now ignore whitespace changes.
* Updated binary identification in CRLF filtering to avoid false positives in
UTF-8 files.
* Rename and copy detection is enabled for small files.
* Checkout can now handle an initial checkout of a repository, making
`GIT_CHECKOUT_SAFE_CREATE` unnecessary for users of clone.
* The signature parameter in the ref-modifying functions has been
removed. Use `git_repository_set_ident()` and
`git_repository_ident()` to override the signature to be used.
* The local transport now auto-scales the number of threads to use
when creating the packfile instead of sticking to one.
* Reference renaming now uses the right id for the old value.
* The annotated version of branch creation, HEAD detaching and reset
allow for specifying the expression from the user to be put into the
reflog.
* `git_rebase_commit` now returns `GIT_EUNMERGED` when you attempt to
commit with unstaged changes.
* On Mac OS X, we now use SecureTransport to provide the cryptographic
support for HTTPS connections insead of OpenSSL.
* Checkout can now accept an index for the baseline computations via the
`baseline_index` member.
* The configuration for fetching is no longer stored inside the
`git_remote` struct but has been moved to a `git_fetch_options`. The
remote functions now take these options or the callbacks instead of
setting them beforehand.
* `git_submodule` instances are no longer cached or shared across
lookup. Each submodule represents the configuration at the time of
loading.
* The index now uses diffs for `add_all()` and `update_all()` which
gives it a speed boost and closer semantics to git.
* The ssh transport now reports the stderr output from the server as
the error message, which allows you to get the "repository not
found" messages.
* `git_index_conflict_add()` will remove staged entries that exist for
conflicted paths.
* The flags for a `git_diff_file` will now have the `GIT_DIFF_FLAG_EXISTS`
bit set when a file exists on that side of the diff. This is useful
for understanding whether a side of the diff exists in the presence of
a conflict.
* The constructor for a write-stream into the odb now takes
`git_off_t` instead of `size_t` for the size of the blob, which
allows putting large files into the odb on 32-bit systems.
* The remote's push and pull URLs now honor the url.$URL.insteadOf
configuration. This allows modifying URL prefixes to a custom
value via gitconfig.
* `git_diff_foreach`, `git_diff_blobs`, `git_diff_blob_to_buffer`,
and `git_diff_buffers` now accept a new binary callback of type
`git_diff_binary_cb` that includes the binary diff information.
* The race condition mitigations described in `racy-git.txt` have been
implemented.
* If libcurl is installed, we will use it to connect to HTTP(S)
servers.
### API additions
* The `git_merge_options` gained a `file_flags` member.
* Parsing and retrieving a configuration value as a path is exposed
via `git_config_parse_path()` and `git_config_get_path()`
respectively.
* `git_repository_set_ident()` and `git_repository_ident()` serve to
set and query which identity will be used when writing to the
reflog.
* `git_config_entry_free()` frees a config entry.
* `git_config_get_string_buf()` provides a way to safely retrieve a
string from a non-snapshot configuration.
* `git_annotated_commit_from_revspec()` allows to get an annotated
commit from an extended sha synatx string.
* `git_repository_set_head_detached_from_annotated()`,
`git_branch_create_from_annotated()` and
`git_reset_from_annotated()` allow for the caller to provide an
annotated commit through which they can control what expression is
put into the reflog as the source/target.
* `git_index_add_frombuffer()` can now create a blob from memory
buffer and add it to the index which is attached to a repository.
* The structure `git_fetch_options` has been added to determine the
runtime configuration for fetching, such as callbacks, pruning and
autotag behaviour. It has the runtime initializer
`git_fetch_init_options()`.
* The enum `git_fetch_prune_t` has been added, letting you specify the
pruning behaviour for a fetch.
* A push operation will notify the caller of what updates it indends
to perform on the remote, which provides similar information to
git's pre-push hook.
* `git_stash_apply()` can now apply a stashed state from the stash list,
placing the data into the working directory and index.
* `git_stash_pop()` will apply a stashed state (like `git_stash_apply()`)
but will remove the stashed state after a successful application.
* A new error code `GIT_EEOF` indicates an early EOF from the
server. This typically indicates an error with the URL or
configuration of the server, and tools can use this to show messages
about failing to communicate with the server.
* A new error code `GIT_EINVALID` indicates that an argument to a
function is invalid, or an invalid operation was requested.
* `git_diff_index_to_workdir()` and `git_diff_tree_to_index()` will now
produce deltas of type `GIT_DELTA_CONFLICTED` to indicate that the index
side of the delta is a conflict.
* The `git_status` family of functions will now produce status of type
`GIT_STATUS_CONFLICTED` to indicate that a conflict exists for that file
in the index.
* `git_index_entry_is_conflict()` is a utility function to determine if
a given index entry has a non-zero stage entry, indicating that it is
one side of a conflict.
* It is now possible to pass a keypair via a buffer instead of a
path. For this, `GIT_CREDTYPE_SSH_MEMORY` and
`git_cred_ssh_key_memory_new()` have been added.
* `git_filter_list_contains` will indicate whether a particular
filter will be run in the given filter list.
* `git_commit_header_field()` has been added, which allows retrieving
the contents of an arbitrary header field.
* `git_submodule_set_branch()` allows to set the configured branch for
a submodule.
### API removals
* `git_remote_save()` and `git_remote_clear_refspecs()` have been
removed. Remote's configuration is changed via the configuration
directly or through a convenience function which performs changes to
the configuration directly.
* `git_remote_set_callbacks()`, `git_remote_get_callbacks()` and
`git_remote_set_transport()` have been removed and the remote no
longer stores this configuration.
* `git_remote_set_fetch_refpecs()` and
`git_remote_set_push_refspecs()` have been removed. There is no
longer a way to set the base refspecs at run-time.
* `git_submodule_save()` has been removed. The submodules are no
longer configured via the objects.
* `git_submodule_reload_all()` has been removed as we no longer cache
submodules.
### Breaking API changes
* `git_smart_subtransport_cb` now has a `param` parameter.
* The `git_merge_options` structure member `flags` has been renamed
to `tree_flags`.
* The `git_merge_file_options` structure member `flags` is now
an unsigned int. It was previously a `git_merge_file_flags_t`.
* `GIT_CHECKOUT_SAFE_CREATE` has been removed. Most users will generally
be able to switch to `GIT_CHECKOUT_SAFE`, but if you require missing
file handling during checkout, you may now use `GIT_CHECKOUT_SAFE |
GIT_CHECKOUT_RECREATE_MISSING`.
* The `git_clone_options` and `git_submodule_update_options`
structures no longer have a `signature` field.
* The following functions have removed the signature and/or log message
parameters in favour of git-emulating ones.
* `git_branch_create()`, `git_branch_move()`
* `git_rebase_init()`, `git_rebase_abort()`
* `git_reference_symbolic_create_matching()`,
`git_reference_symbolic_create()`, `git_reference_create()`,
`git_reference_create_matching()`,
`git_reference_symbolic_set_target()`,
`git_reference_set_target()`, `git_reference_rename()`
* `git_remote_update_tips()`, `git_remote_fetch()`, `git_remote_push()`
* `git_repository_set_head()`,
`git_repository_set_head_detached()`,
`git_repository_detach_head()`
* `git_reset()`
* `git_config_get_entry()` now gives back a ref-counted
`git_config_entry`. You must free it when you no longer need it.
* `git_config_get_string()` will return an error if used on a
non-snapshot configuration, as there can be no guarantee that the
returned pointer is valid.
* `git_note_default_ref()` now uses a `git_buf` to return the string,
as the string is otherwise not guaranteed to stay allocated.
* `git_rebase_operation_current()` will return `GIT_REBASE_NO_OPERATION`
if it is called immediately after creating a rebase session but before
you have applied the first patch.
* `git_rebase_options` now contains a `git_checkout_options` struct
that will be used for functions that modify the working directory,
namely `git_checkout_init`, `git_checkout_next` and
`git_checkout_abort`. As a result, `git_rebase_open` now also takes
a `git_rebase_options` and only the `git_rebase_init` and
`git_rebase_open` functions take a `git_rebase_options`, where they
will persist the options to subsequent `git_rebase` calls.
* The `git_clone_options` struct now has fetch options in a
`fetch_opts` field instead of remote callbacks in
`remote_callbacks`.
* The remote callbacks has gained a new member `push_negotiation`
which gets called before sending the update commands to the server.
* The following functions no longer act on a remote instance but
change the repository's configuration. Their signatures have changed
accordingly:
* `git_remote_set_url()`, `git_remote_seturl()`
* `git_remote_add_fetch()`, `git_remote_add_push()` and
* `git_remote_set_autotag()`
* `git_remote_connect()` and `git_remote_prune()` now take a pointer
to the callbacks.
* `git_remote_fetch()` and `git_remote_download()` now take a pointer
to fetch options which determine the runtime configuration.
* The `git_remote_autotag_option_t` values have been changed. It has
gained a `_UNSPECIFIED` default value to specify no override for the
configured setting.
* `git_remote_update_tips()` now takes a pointer to the callbacks as
well as a boolean whether to write `FETCH_HEAD` and the autotag
setting.
* `git_remote_create_anonymous()` no longer takes a fetch refspec as
url-only remotes cannot have configured refspecs.
* The `git_submodule_update_options` struct now has fetch options in
the `fetch_opts` field instead of callbacks in the
`remote_callbacks` field.
* The following functions no longer act on a submodule instance but
change the repository's configuration. Their signatures have changed
accordingly:
* `git_submodule_set_url()`, `git_submodule_set_ignore()`,
`git_submodule_set_update()`,
`git_submodule_set_fetch_recurse_submodules()`.
* `git_submodule_status()` no longer takes a submodule instance but a
repsitory, a submodule name and an ignore setting.
* The `push` function in the `git_transport` interface now takes a
pointer to the remote callbacks.
* The `git_index_entry` struct's fields' types have been changed to
more accurately reflect what is in fact stored in the
index. Specifically, time and file size are 32 bits intead of 64, as
these values are truncated.
* `GIT_EMERGECONFLICT` is now `GIT_ECONFLICT`, which more accurately
describes the nature of the error.
* It is no longer allowed to call `git_buf_grow()` on buffers
borrowing the memory they point to.
v0.22
------
### Changes or improvements
* `git_signature_new()` now requires a non-empty email address.
* Use CommonCrypto libraries for SHA-1 calculation on Mac OS X.
* Disable SSL compression and SSLv2 and SSLv3 ciphers in favor of TLSv1
in OpenSSL.
* The fetch behavior of remotes with autotag set to `GIT_REMOTE_DOWNLOAD_TAGS_ALL`
has been changed to match git 1.9.0 and later. In this mode, libgit2 now
fetches all tags in addition to whatever else needs to be fetched.
* `git_checkout()` now handles case-changing renames correctly on
case-insensitive filesystems; for example renaming "readme" to "README".
* The search for libssh2 is now done via pkg-config instead of a
custom search of a few directories.
* Add support for core.protectHFS and core.protectNTFS. Add more
validation for filenames which we write such as references.
* The local transport now generates textual progress output like
git-upload-pack does ("counting objects").
* `git_checkout_index()` can now check out an in-memory index that is not
necessarily the repository's index, so you may check out an index
that was produced by git_merge and friends while retaining the cached
information.
* Remove the default timeout for receiving / sending data over HTTP using
the WinHTTP transport layer.
* Add SPNEGO (Kerberos) authentication using GSSAPI on Unix systems.
* Provide built-in objects for the empty blob (e69de29) and empty
tree (4b825dc) objects.
* The index' tree cache is now filled upon read-tree and write-tree
and the cache is written to disk.
* LF -> CRLF filter refuses to handle mixed-EOL files
* LF -> CRLF filter now runs when * text = auto (with Git for Windows 1.9.4)
* File unlocks are atomic again via rename. Read-only files on Windows are
made read-write if necessary.
* Share open packfiles across repositories to share descriptors and mmaps.
* Use a map for the treebuilder, making insertion O(1)
* The build system now accepts an option EMBED_SSH_PATH which when set
tells it to include a copy of libssh2 at the given location. This is
enabled for MSVC.
* Add support for refspecs with the asterisk in the middle of a
pattern.
* Fetching now performs opportunistic updates. To achieve this, we
introduce a difference between active and passive refspecs, which
make `git_remote_download()` and `git_remote_fetch()` to take a list of
resfpecs to be the active list, similarly to how git fetch accepts a
list on the command-line.
* The THREADSAFE option to build libgit2 with threading support has
been flipped to be on by default.
* The remote object has learnt to prune remote-tracking branches. If
the remote is configured to do so, this will happen via
`git_remote_fetch()`. You can also call `git_remote_prune()` after
connecting or fetching to perform the prune.
### API additions
* Introduce `git_buf_text_is_binary()` and `git_buf_text_contains_nul()` for
consumers to perform binary detection on a git_buf.
* `git_branch_upstream_remote()` has been introduced to provide the
branch.<name>.remote configuration value.
* Introduce `git_describe_commit()` and `git_describe_workdir()` to provide
a description of the current commit (and working tree, respectively)
based on the nearest tag or reference
* Introduce `git_merge_bases()` and the `git_oidarray` type to expose all
merge bases between two commits.
* Introduce `git_merge_bases_many()` to expose all merge bases between
multiple commits.
* Introduce rebase functionality (using the merge algorithm only).
Introduce `git_rebase_init()` to begin a new rebase session,
`git_rebase_open()` to open an in-progress rebase session,
`git_rebase_commit()` to commit the current rebase operation,
`git_rebase_next()` to apply the next rebase operation,
`git_rebase_abort()` to abort an in-progress rebase and `git_rebase_finish()`
to complete a rebase operation.
* Introduce `git_note_author()` and `git_note_committer()` to get the author
and committer information on a `git_note`, respectively.
* A factory function for ssh has been added which allows to change the
path of the programs to execute for receive-pack and upload-pack on
the server, `git_transport_ssh_with_paths()`.
* The ssh transport supports asking the remote host for accepted
credential types as well as multiple challeges using a single
connection. This requires to know which username you want to connect
as, so this introduces the USERNAME credential type which the ssh
transport will use to ask for the username.
* The `GIT_EPEEL` error code has been introduced when we cannot peel a tag
to the requested object type; if the given object otherwise cannot be
peeled, `GIT_EINVALIDSPEC` is returned.
* Introduce `GIT_REPOSITORY_INIT_RELATIVE_GITLINK` to use relative paths
when writing gitlinks, as is used by git core for submodules.
* `git_remote_prune()` has been added. See above for description.
* Introduce reference transactions, which allow multiple references to
be locked at the same time and updates be queued. This also allows
us to safely update a reflog with arbitrary contents, as we need to
do for stash.
### API removals
* `git_remote_supported_url()` and `git_remote_is_valid_url()` have been
removed as they have become essentially useless with rsync-style ssh paths.
* `git_clone_into()` and `git_clone_local_into()` have been removed from the
public API in favour of `git_clone callbacks`.
* The option to ignore certificate errors via `git_remote_cert_check()`
is no longer present. Instead, `git_remote_callbacks` has gained a new
entry which lets the user perform their own certificate checks.
### Breaking API changes
* `git_cherry_pick()` is now `git_cherrypick()`.
* The `git_submodule_update()` function was renamed to
`git_submodule_update_strategy()`. `git_submodule_update()` is now used to
provide functionalty similar to "git submodule update".
* `git_treebuilder_create()` was renamed to `git_treebuilder_new()` to better
reflect it being a constructor rather than something which writes to
disk.
* `git_treebuilder_new()` (was `git_treebuilder_create()`) now takes a
repository so that it can query repository configuration.
Subsequently, `git_treebuilder_write()` no longer takes a repository.
* `git_threads_init()` and `git_threads_shutdown()` have been renamed to
`git_libgit2_init()` and `git_libgit2_shutdown()` to better explain what
their purpose is, as it's grown to be more than just about threads.
* `git_libgit2_init()` and `git_libgit2_shutdown()` now return the number of
initializations of the library, so consumers may schedule work on the
first initialization.
* The `git_transport_register()` function no longer takes a priority and takes
a URL scheme name (eg "http") instead of a prefix like "http://"
* `git_index_name_entrycount()` and `git_index_reuc_entrycount()` now
return size_t instead of unsigned int.
* The `context_lines` and `interhunk_lines` fields in `git_diff`_options are
now `uint32_t` instead of `uint16_t`. This allows to set them to `UINT_MAX`,
in effect asking for "infinite" context e.g. to iterate over all the
unmodified lines of a diff.
* `git_status_file()` now takes an exact path. Use `git_status_list_new()` if
pathspec searching is needed.
* `git_note_create()` has changed the position of the notes reference
name to match `git_note_remove()`.
* Rename `git_remote_load()` to `git_remote_lookup()` to bring it in line
with the rest of the lookup functions.
* `git_remote_rename()` now takes the repository and the remote's
current name. Accepting a remote indicates we want to change it,
which we only did partially. It is much clearer if we accept a name
and no loaded objects are changed.
* `git_remote_delete()` now accepts the repository and the remote's name
instead of a loaded remote.
* `git_merge_head` is now `git_annotated_commit`, to better reflect its usage
for multiple functions (including rebase)
* The `git_clone_options` struct no longer provides the `ignore_cert_errors` or
`remote_name` members for remote customization.
Instead, the `git_clone_options` struct has two new members, `remote_cb` and
`remote_cb_payload`, which allow the caller to completely override the remote
creation process. If needed, the caller can use this callback to give their
remote a name other than the default (origin) or disable cert checking.
The `remote_callbacks` member has been preserved for convenience, although it
is not used when a remote creation callback is supplied.
* The `git_clone`_options struct now provides `repository_cb` and
`repository_cb_payload` to allow the user to create a repository with
custom options.
* The `git_push` struct to perform a push has been replaced with
`git_remote_upload()`. The refspecs and options are passed as a
function argument. `git_push_update_tips()` is now also
`git_remote_update_tips()` and the callbacks are in the same struct as
the rest.
* The `git_remote_set_transport()` function now sets a transport factory function,
rather than a pre-existing transport instance.
* The `git_transport` structure definition has moved into the sys/transport.h
file.
* libgit2 no longer automatically sets the OpenSSL locking
functions. This is not something which we can know to do. A
last-resort convenience function is provided in sys/openssl.h,
`git_openssl_set_locking()` which can be used to set the locking.

View File

@ -13,18 +13,20 @@
PROJECT(libgit2 C)
CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
CMAKE_POLICY(SET CMP0015 NEW)
# Add find modules to the path
SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules/")
INCLUDE(CheckLibraryExists)
INCLUDE(AddCFlagIfSupported)
INCLUDE(FindPkgConfig)
# Build options
#
OPTION( SONAME "Set the (SO)VERSION of the target" ON )
OPTION( BUILD_SHARED_LIBS "Build Shared Library (OFF for Static)" ON )
OPTION( THREADSAFE "Build libgit2 as threadsafe" OFF )
OPTION( THREADSAFE "Build libgit2 as threadsafe" ON )
OPTION( BUILD_CLAR "Build Tests using the Clar suite" ON )
OPTION( BUILD_EXAMPLES "Build library usage example apps" OFF )
OPTION( TAGS "Generate tags" OFF )
@ -32,14 +34,16 @@ OPTION( PROFILE "Generate profiling information" OFF )
OPTION( ENABLE_TRACE "Enables tracing support" OFF )
OPTION( LIBGIT2_FILENAME "Name of the produced binary" OFF )
OPTION( ANDROID "Build for android NDK" OFF )
OPTION( USE_ICONV "Link with and use iconv library" OFF )
OPTION( USE_SSH "Link with libssh to enable SSH support" ON )
OPTION( USE_GSSAPI "Link with libgssapi for SPNEGO auth" OFF )
OPTION( VALGRIND "Configure build for valgrind" OFF )
OPTION( CURL "User curl for HTTP if available" ON)
IF(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
SET( USE_ICONV ON )
FIND_PACKAGE(Security)
FIND_PACKAGE(CoreFoundation REQUIRED)
ENDIF()
IF(MSVC)
@ -55,15 +59,27 @@ IF(MSVC)
# are linking statically
OPTION( STATIC_CRT "Link the static CRT libraries" ON )
# By default, libgit2 is built with WinHTTP. To use the built-in
# HTTP transport, invoke CMake with the "-DWINHTTP=OFF" argument.
OPTION( WINHTTP "Use Win32 WinHTTP routines" ON )
ADD_DEFINITIONS(-D_SCL_SECURE_NO_WARNINGS)
ADD_DEFINITIONS(-D_CRT_SECURE_NO_DEPRECATE)
ADD_DEFINITIONS(-D_CRT_NONSTDC_NO_DEPRECATE)
ENDIF()
IF(WIN32)
# By default, libgit2 is built with WinHTTP. To use the built-in
# HTTP transport, invoke CMake with the "-DWINHTTP=OFF" argument.
OPTION( WINHTTP "Use Win32 WinHTTP routines" ON )
ENDIF()
IF(MSVC)
# Enable MSVC CRTDBG memory leak reporting when in debug mode.
OPTION(MSVC_CRTDBG "Enable CRTDBG memory leak reporting" OFF)
ENDIF()
IF (NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
OPTION( USE_OPENSSL "Link with and use openssl library" ON )
ENDIF()
# This variable will contain the libraries we need to put into
# libgit2.pc's Requires.private. That is, what we're linking to or
# what someone who's statically linking us needs to link to.
@ -84,12 +100,14 @@ FUNCTION(TARGET_OS_LIBRARIES target)
TARGET_LINK_LIBRARIES(${target} ws2_32)
ELSEIF(CMAKE_SYSTEM_NAME MATCHES "(Solaris|SunOS)")
TARGET_LINK_LIBRARIES(${target} socket nsl)
SET(LIBGIT2_PC_LIBS "${LIBGIT2_PC_LIBS} -lsocket -lnsl" PARENT_SCOPE)
LIST(APPEND LIBGIT2_PC_LIBS "-lsocket" "-lnsl")
SET(LIBGIT2_PC_LIBS ${LIBGIT2_PC_LIBS} PARENT_SCOPE)
ENDIF()
CHECK_LIBRARY_EXISTS(rt clock_gettime "time.h" NEED_LIBRT)
IF(NEED_LIBRT)
TARGET_LINK_LIBRARIES(${target} rt)
SET(LIBGIT2_PC_LIBS "${LIBGIT2_PC_LIBS} -lrt" PARENT_SCOPE)
LIST(APPEND LIBGIT2_PC_LIBS "-lrt")
SET(LIBGIT2_PC_LIBS ${LIBGIT2_PC_LIBS} PARENT_SCOPE)
ENDIF()
IF(THREADSAFE)
@ -133,20 +151,77 @@ STRING(REGEX REPLACE "^.*LIBGIT2_SOVERSION ([0-9]+)$" "\\1" LIBGIT2_SOVERSION "$
# Find required dependencies
INCLUDE_DIRECTORIES(src include)
IF (WIN32 AND WINHTTP AND NOT MINGW)
IF (SECURITY_FOUND)
MESSAGE("-- Found Security ${SECURITY_DIRS}")
LIST(APPEND LIBGIT2_PC_LIBS "-framework Security")
ENDIF()
IF (COREFOUNDATION_FOUND)
MESSAGE("-- Found CoreFoundation ${COREFOUNDATION_DIRS}")
LIST(APPEND LIBGIT2_PC_LIBS "-framework CoreFoundation")
ENDIF()
IF (WIN32 AND WINHTTP)
ADD_DEFINITIONS(-DGIT_WINHTTP)
INCLUDE_DIRECTORIES(deps/http-parser)
FILE(GLOB SRC_HTTP deps/http-parser/*.c deps/http-parser/*.h)
# Since MinGW does not come with headers or an import library for winhttp,
# we have to include a private header and generate our own import library
IF (MINGW)
FIND_PROGRAM(DLLTOOL dlltool CMAKE_FIND_ROOT_PATH_BOTH)
IF (NOT DLLTOOL)
MESSAGE(FATAL_ERROR "Could not find dlltool command")
ENDIF ()
SET(LIBWINHTTP_PATH "${CMAKE_CURRENT_BINARY_DIR}/deps/winhttp")
FILE(MAKE_DIRECTORY ${LIBWINHTTP_PATH})
IF ("${CMAKE_SIZEOF_VOID_P}" EQUAL "8")
set(WINHTTP_DEF "${CMAKE_CURRENT_SOURCE_DIR}/deps/winhttp/winhttp64.def")
ELSE()
set(WINHTTP_DEF "${CMAKE_CURRENT_SOURCE_DIR}/deps/winhttp/winhttp.def")
ENDIF()
ADD_CUSTOM_COMMAND(
OUTPUT ${LIBWINHTTP_PATH}/libwinhttp.a
COMMAND ${DLLTOOL} -d ${WINHTTP_DEF} -k -D winhttp.dll -l libwinhttp.a
DEPENDS ${WINHTTP_DEF}
WORKING_DIRECTORY ${LIBWINHTTP_PATH}
)
SET_SOURCE_FILES_PROPERTIES(
${CMAKE_CURRENT_SOURCE_DIR}/src/transports/winhttp.c
PROPERTIES OBJECT_DEPENDS ${LIBWINHTTP_PATH}/libwinhttp.a
)
INCLUDE_DIRECTORIES(deps/winhttp)
LINK_DIRECTORIES(${LIBWINHTTP_PATH})
ENDIF ()
LINK_LIBRARIES(winhttp rpcrt4 crypt32)
ELSE ()
IF (NOT AMIGA)
IF (CURL)
PKG_CHECK_MODULES(CURL libcurl)
ENDIF ()
IF (NOT AMIGA AND USE_OPENSSL)
FIND_PACKAGE(OpenSSL)
ENDIF ()
IF (CURL_FOUND)
ADD_DEFINITIONS(-DGIT_CURL)
INCLUDE_DIRECTORIES(${CURL_INCLUDE_DIRS})
LINK_LIBRARIES(${CURL_LIBRARIES})
LIST(APPEND LIBGIT2_PC_LIBS ${CURL_LDFLAGS})
ENDIF()
FIND_PACKAGE(HTTP_Parser)
IF (HTTP_PARSER_FOUND AND HTTP_PARSER_VERSION_MAJOR EQUAL 2)
INCLUDE_DIRECTORIES(${HTTP_PARSER_INCLUDE_DIRS})
LINK_LIBRARIES(${HTTP_PARSER_LIBRARIES})
SET(LIBGIT2_PC_LIBS "${LIBGIT2_PC_LIBS} -lhttp_parser")
LIST(APPEND LIBGIT2_PC_LIBS "-lhttp_parser")
ELSE()
MESSAGE(STATUS "http-parser was not found or is too old; using bundled 3rd-party sources.")
INCLUDE_DIRECTORIES(deps/http-parser)
@ -158,10 +233,12 @@ ENDIF()
IF (WIN32 AND NOT MINGW AND NOT SHA1_TYPE STREQUAL "builtin")
ADD_DEFINITIONS(-DWIN32_SHA1)
FILE(GLOB SRC_SHA1 src/hash/hash_win32.c)
ELSEIF (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
ADD_DEFINITIONS(-DGIT_COMMON_CRYPTO)
ELSEIF (OPENSSL_FOUND AND NOT SHA1_TYPE STREQUAL "builtin")
ADD_DEFINITIONS(-DOPENSSL_SHA1)
IF (CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
SET(LIBGIT2_PC_LIBS "${LIBGIT2_PC_LIBS} -lssl")
LIST(APPEND LIBGIT2_PC_LIBS "-lssl")
ELSE()
SET(LIBGIT2_PC_REQUIRES "${LIBGIT2_PC_REQUIRES} openssl")
ENDIF ()
@ -175,7 +252,7 @@ IF (ENABLE_TRACE STREQUAL "ON")
ENDIF()
# Include POSIX regex when it is required
IF(WIN32 OR AMIGA OR ANDROID OR CMAKE_SYSTEM_NAME MATCHES "(Solaris|SunOS)")
IF(WIN32 OR AMIGA OR CMAKE_SYSTEM_NAME MATCHES "(Solaris|SunOS)")
INCLUDE_DIRECTORIES(deps/regex)
SET(SRC_REGEX deps/regex/regex.c)
ENDIF()
@ -186,7 +263,7 @@ IF (ZLIB_FOUND)
INCLUDE_DIRECTORIES(${ZLIB_INCLUDE_DIRS})
LINK_LIBRARIES(${ZLIB_LIBRARIES})
IF(APPLE OR CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
SET(LIBGIT2_PC_LIBS "${LIBGIT2_PC_LIBS} -lz")
LIST(APPEND LIBGIT2_PC_LIBS "-lz")
ELSE()
SET(LIBGIT2_PC_REQUIRES "${LIBGIT2_PC_REQUIRES} zlib")
ENDIF()
@ -199,13 +276,30 @@ ENDIF()
# Optional external dependency: libssh2
IF (USE_SSH)
FIND_PACKAGE(LIBSSH2)
PKG_CHECK_MODULES(LIBSSH2 libssh2)
ENDIF()
IF (LIBSSH2_FOUND)
ADD_DEFINITIONS(-DGIT_SSH)
INCLUDE_DIRECTORIES(${LIBSSH2_INCLUDE_DIR})
SET(LIBGIT2_PC_REQUIRES "${LIBGIT2_PC_REQUIRES} libssh2")
INCLUDE_DIRECTORIES(${LIBSSH2_INCLUDE_DIRS})
LINK_DIRECTORIES(${LIBSSH2_LIBRARY_DIRS})
LIST(APPEND LIBGIT2_PC_LIBS ${LIBSSH2_LDFLAGS})
#SET(LIBGIT2_PC_LIBS "${LIBGIT2_PC_LIBS} ${LIBSSH2_LDFLAGS}")
SET(SSH_LIBRARIES ${LIBSSH2_LIBRARIES})
CHECK_LIBRARY_EXISTS("${LIBSSH2_LIBRARIES}" libssh2_userauth_publickey_frommemory "" HAVE_LIBSSH2_MEMORY_CREDENTIALS)
IF (HAVE_LIBSSH2_MEMORY_CREDENTIALS)
ADD_DEFINITIONS(-DGIT_SSH_MEMORY_CREDENTIALS)
ENDIF()
ELSE()
MESSAGE(STATUS "LIBSSH2 not found. Set CMAKE_PREFIX_PATH if it is installed outside of the default search path.")
ENDIF()
# Optional external dependency: libgssapi
IF (USE_GSSAPI)
FIND_PACKAGE(GSSAPI)
ENDIF()
IF (GSSAPI_FOUND)
ADD_DEFINITIONS(-DGIT_GSSAPI)
ENDIF()
# Optional external dependency: iconv
@ -215,7 +309,7 @@ ENDIF()
IF (ICONV_FOUND)
ADD_DEFINITIONS(-DGIT_USE_ICONV)
INCLUDE_DIRECTORIES(${ICONV_INCLUDE_DIR})
SET(LIBGIT2_PC_LIBS "${LIBGIT2_PC_LIBS} ${ICONV_LIBRARIES}")
LIST(APPEND LIBGIT2_PC_LIBS ${ICONV_LIBRARIES})
ENDIF()
# Platform specific compilation flags
@ -240,6 +334,10 @@ IF (MSVC)
SET(CRT_FLAG_RELEASE "/MD")
ENDIF()
IF (MSVC_CRTDBG)
SET(CRT_FLAG_DEBUG "${CRT_FLAG_DEBUG} /DGIT_MSVC_CRTDBG")
ENDIF()
# /Zi - Create debugging information
# /Od - Disable optimization
# /D_DEBUG - #define _DEBUG
@ -341,12 +439,19 @@ ELSE()
# that uses CMAKE_CONFIGURATION_TYPES and not CMAKE_BUILD_TYPE
ENDIF()
IF (SECURITY_FOUND)
ADD_DEFINITIONS(-DGIT_SECURE_TRANSPORT)
INCLUDE_DIRECTORIES(${SECURITY_INCLUDE_DIR})
ENDIF ()
IF (OPENSSL_FOUND)
ADD_DEFINITIONS(-DGIT_SSL)
ADD_DEFINITIONS(-DGIT_OPENSSL)
INCLUDE_DIRECTORIES(${OPENSSL_INCLUDE_DIR})
SET(SSL_LIBRARIES ${OPENSSL_LIBRARIES})
ENDIF()
IF (THREADSAFE)
IF (NOT WIN32)
FIND_PACKAGE(Threads REQUIRED)
@ -385,8 +490,11 @@ ENDIF()
# Compile and link libgit2
ADD_LIBRARY(git2 ${SRC_H} ${SRC_GIT2} ${SRC_OS} ${SRC_ZLIB} ${SRC_HTTP} ${SRC_REGEX} ${SRC_SHA1} ${WIN_RC})
TARGET_LINK_LIBRARIES(git2 ${SECURITY_DIRS})
TARGET_LINK_LIBRARIES(git2 ${COREFOUNDATION_DIRS})
TARGET_LINK_LIBRARIES(git2 ${SSL_LIBRARIES})
TARGET_LINK_LIBRARIES(git2 ${SSH_LIBRARIES})
TARGET_LINK_LIBRARIES(git2 ${GSSAPI_LIBRARIES})
TARGET_LINK_LIBRARIES(git2 ${ICONV_LIBRARIES})
TARGET_OS_LIBRARIES(git2)
@ -406,6 +514,7 @@ IF (SONAME)
SET_TARGET_PROPERTIES(git2 PROPERTIES OUTPUT_NAME ${LIBGIT2_FILENAME})
ENDIF()
ENDIF()
STRING(REPLACE ";" " " LIBGIT2_PC_LIBS "${LIBGIT2_PC_LIBS}")
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/libgit2.pc.in ${CMAKE_CURRENT_BINARY_DIR}/libgit2.pc @ONLY)
IF (MSVC_IDE)
@ -433,10 +542,11 @@ IF (BUILD_CLAR)
SET(CLAR_RESOURCES "${CMAKE_CURRENT_SOURCE_DIR}/tests/resources" CACHE PATH "Path to test resources.")
ADD_DEFINITIONS(-DCLAR_FIXTURE_PATH=\"${CLAR_FIXTURES}\")
ADD_DEFINITIONS(-DCLAR_RESOURCES=\"${TEST_RESOURCES}\")
ADD_DEFINITIONS(-DCLAR_TMPDIR=\"libgit2_tests\")
INCLUDE_DIRECTORIES(${CLAR_PATH})
FILE(GLOB_RECURSE SRC_TEST ${CLAR_PATH}/*/*.c ${CLAR_PATH}/*/*.h)
SET(SRC_CLAR "${CLAR_PATH}/main.c" "${CLAR_PATH}/clar_libgit2.c" "${CLAR_PATH}/clar.c")
SET(SRC_CLAR "${CLAR_PATH}/main.c" "${CLAR_PATH}/clar_libgit2.c" "${CLAR_PATH}/clar_libgit2_trace.c" "${CLAR_PATH}/clar_libgit2_timer.c" "${CLAR_PATH}/clar.c")
ADD_CUSTOM_COMMAND(
OUTPUT ${CLAR_PATH}/clar.suite
@ -451,8 +561,11 @@ IF (BUILD_CLAR)
ADD_EXECUTABLE(libgit2_clar ${SRC_H} ${SRC_GIT2} ${SRC_OS} ${SRC_CLAR} ${SRC_TEST} ${SRC_ZLIB} ${SRC_HTTP} ${SRC_REGEX} ${SRC_SHA1})
TARGET_LINK_LIBRARIES(libgit2_clar ${COREFOUNDATION_DIRS})
TARGET_LINK_LIBRARIES(libgit2_clar ${SECURITY_DIRS})
TARGET_LINK_LIBRARIES(libgit2_clar ${SSL_LIBRARIES})
TARGET_LINK_LIBRARIES(libgit2_clar ${SSH_LIBRARIES})
TARGET_LINK_LIBRARIES(libgit2_clar ${GSSAPI_LIBRARIES})
TARGET_LINK_LIBRARIES(libgit2_clar ${ICONV_LIBRARIES})
TARGET_OS_LIBRARIES(libgit2_clar)
MSVC_SPLIT_SOURCES(libgit2_clar)
@ -463,7 +576,11 @@ IF (BUILD_CLAR)
ENDIF ()
ENABLE_TESTING()
ADD_TEST(libgit2_clar libgit2_clar -ionline)
IF (WINHTTP OR OPENSSL_FOUND OR SECURITY_FOUND)
ADD_TEST(libgit2_clar libgit2_clar -ionline)
ELSE ()
ADD_TEST(libgit2_clar libgit2_clar -v)
ENDIF ()
ENDIF ()
IF (TAGS)

View File

@ -15,24 +15,34 @@ from them into your own application.
## Discussion & Chat
We hang out in the #libgit2 channel on irc.freenode.net.
We hang out in the
[`#libgit2`](http://webchat.freenode.net/?channels=#libgit2)) channel on
irc.freenode.net.
Also, feel free to open an
[Issue](https://github.com/libgit2/libgit2/issues/new) to start a discussion
about any concerns you have. We like to use Issues for that so there is an
easily accessible permanent record of the conversation.
## Libgit2 Versions
The `master` branch is the main branch where development happens.
Releases are tagged
(e.g. [v0.21.0](https://github.com/libgit2/libgit2/releases/tag/v0.21.0) )
and when a critical bug fix needs to be backported, it will be done on a
`<tag>-maint` maintenance branch.
## Reporting Bugs
First, know which version of libgit2 your problem is in and include it in
your bug report. This can either be a tag (e.g.
[v0.17.0](https://github.com/libgit2/libgit2/tree/v0.17.0) ) or a commit
SHA (e.g.
[01be7863](https://github.com/libgit2/libgit2/commit/01be786319238fd6507a08316d1c265c1a89407f)
). Using [`git describe`](http://git-scm.com/docs/git-describe) is a great
way to tell us what version you're working with.
[v0.17.0](https://github.com/libgit2/libgit2/releases/tag/v0.17.0)) or a
commit SHA
(e.g. [01be7863](https://github.com/libgit2/libgit2/commit/01be7863)).
Using [`git describe`](http://git-scm.com/docs/git-describe) is a
great way to tell us what version you're working with.
If you're not running against the latest `development` branch version,
If you're not running against the latest `master` branch version,
please compile and test against that to avoid re-reporting an issue that's
already been fixed.
@ -44,25 +54,56 @@ out a way to help you.
## Pull Requests
Our work flow is a typical GitHub flow, where contributors fork the
[libgit2 repository](https://github.com/libgit2/libgit2), make their changes
on branch, and submit a
Our work flow is a [typical GitHub
flow](https://guides.github.com/introduction/flow/index.html), where
contributors fork the [libgit2 repository](https://github.com/libgit2/libgit2),
make their changes on branch, and submit a
[Pull Request](https://help.github.com/articles/using-pull-requests)
(a.k.a. "PR").
(a.k.a. "PR"). Pull requests should usually be targeted at the `master`
branch.
Life will be a lot easier for you (and us) if you follow this pattern
(i.e. fork, named branch, submit PR). If you use your fork's `development`
branch, things can get messy.
(i.e. fork, named branch, submit PR). If you use your fork's `master`
branch directly, things can get messy.
Please include a nice description of your changes with your PR; if we have
to read the whole diff to figure out why you're contributing in the first
place, you're less likely to get feedback and have your change merged in.
Please include a nice description of your changes when you submit your PR;
if we have to read the whole diff to figure out why you're contributing
in the first place, you're less likely to get feedback and have your change
merged in.
If you are working on a particular area then feel free to submit a PR that
highlights your work in progress (and flag in the PR title that it's not
ready to merge). This will help in getting visibility for your fix, allow
others to comment early on the changes and also let others know that you
are currently working on something.
If you are starting to work on a particular area, feel free to submit a PR
that highlights your work in progress (and note in the PR title that it's
not ready to merge). These early PRs are welcome and will help in getting
visibility for your fix, allow others to comment early on the changes and
also let others know that you are currently working on something.
Before wrapping up a PR, you should be sure to:
* Write tests to cover any functional changes
* Update documentation for any changed public APIs
* Add to the [`CHANGELOG.md`](CHANGELOG.md) file describing any major changes
## Unit Tests
We believe that our unit tests allow us to keep the quality of libgit2
high: any new changes must not cause unit test failures, and new changes
should include unit tests that cover the bug fixes or new features.
For bug fixes, we prefer unit tests that illustrate the failure before
the change, but pass with your changes.
In addition to new tests, please ensure that your changes do not cause
any other test failures. Running the entire test suite is helpful
before you submit a pull request. When you build libgit2, the test
suite will also be built. You can run all tests by simply running
the resultant `libgit2_clar` binary. If you want to run a specific
unit test, you can name it with the `-s` option. For example:
libgit2_clar -sstatus::worktree::long_filenames
Or you can run an entire class of tests. For example, to run all the
worktree status tests:
libgit2_clar -sstatus::worktree
## Porting Code From Other Open-Source Projects
@ -80,10 +121,10 @@ you're porting code *from* to see what you need to do. As a general rule,
MIT and BSD (3-clause) licenses are typically no problem. Apache 2.0
license typically doesn't work due to GPL incompatibility.
If you are pulling in code from core Git, another project or code you've
pulled from a forum / Stack Overflow then please flag this in your PR and
also make sure you've given proper credit to the original author in the
code snippet.
If your pull request uses code from core Git, another project, or code
from a forum / Stack Overflow, then *please* flag this in your PR and make
sure you've given proper credit to the original author in the code
snippet.
## Style Guide
@ -96,9 +137,10 @@ function and type naming, code formatting, and testing.
We like to keep the source code consistent and easy to read. Maintaining
this takes some discipline, but it's been more than worth it. Take a look
at the
[conventions file](https://github.com/libgit2/libgit2/blob/development/CONVENTIONS.md).
at the [conventions
file](https://github.com/libgit2/libgit2/blob/development/CONVENTIONS.md).
## Starter Projects
See our [projects list](https://github.com/libgit2/libgit2/blob/development/PROJECTS.md).
See our [projects
list](https://github.com/libgit2/libgit2/blob/development/PROJECTS.md).

30
COPYING
View File

@ -388,27 +388,21 @@ Copyright (C) 1995-2010 Jean-loup Gailly and Mark Adler
----------------------------------------------------------------------
The Clar framework is licensed under the MIT license:
The Clar framework is licensed under the ISC license:
Copyright (C) 2011 by Vicent Marti
Copyright (c) 2011-2015 Vicent Marti
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
----------------------------------------------------------------------

View File

@ -10,10 +10,11 @@ ideas that no one is actively working on.
## Before You Start
Please start by reading the README.md, CONTRIBUTING.md, and CONVENTIONS.md
files before diving into one of these projects. Those will explain our
work flow and coding conventions to help ensure that your work will be
easily integrated into libgit2.
Please start by reading the [README.md](README.md),
[CONTRIBUTING.md](CONTRIBUTING.md), and [CONVENTIONS.md](CONVENTIONS.md)
files before diving into one of these projects. Those explain our work
flow and coding conventions to help ensure that your work will be easily
integrated into libgit2.
Next, work through the build instructions and make sure you can clone the
repository, compile it, and run the tests successfully. That will make
@ -27,7 +28,7 @@ These are good small projects to get started with libgit2.
* Look at the `examples/` programs, find an existing one that mirrors a
core Git command and add a missing command-line option. There are many
gaps right now and this helps demonstrate how to use the library. Here
are some specific ideas:
are some specific ideas (though there are many more):
* Fix the `examples/diff.c` implementation of the `-B`
(a.k.a. `--break-rewrites`) command line option to actually look for
the optional `[<n>][/<m>]` configuration values. There is an
@ -52,9 +53,6 @@ These are good small projects to get started with libgit2.
* Submit a PR to clarify documentation! While we do try to document all of
the APIs, your fresh eyes on the documentation will find areas that are
confusing much more easily.
* Add support for the symref protocol extension, so we don't guess
what the remote's default branch is
[#2006](https://github.com/libgit2/libgit2/issues/2006)
If none of these appeal to you, take a look at our issues list to see if
there are any unresolved issues you'd like to jump in on.
@ -67,19 +65,37 @@ into one of these as a first project for libgit2 - we'd rather get to
know you first by successfully shipping your work on one of the smaller
projects above.
Some of these projects are broken down into subprojects and/or have
some incremental steps listed towards the larger goal. Those steps
might make good smaller projects by themselves.
* Port part of the Git test suite to run against the command line emulation
in examples/
* Pick a Git command that is emulated in our examples/ area
* Extract the Git tests that exercise that command
* Convert the tests to call our emulation
* These tests could go in examples/tests/...
* Fix symlink support for files in the .git directory (i.e. don't overwrite
the symlinks when writing the file contents back out)
* Implement a 'git describe' like API
* Add hooks API to enumerate and manage hooks (not run them at this point)
* Enumeration of available hooks
* Lookup API to see which hooks have a script and get the script
* Read/write API to load a hook script and write a hook script
* Eventually, callback API to invoke a hook callback when libgit2
executes the action in question
* Isolate logic of ignore evaluation into a standalone API
* Upgrade internal libxdiff code to latest from core Git
* Add a hashtable lookup for files in the index instead of binary search
every time
* Make the index write the cache out to disk (with tests to gain
confidence that the caching invalidation works correctly)
* Have the tree builder use a hash table when building instead of a
list.
* Move the tagopt mechanism to the newer git 1.9 interpretation of
--tags [#2120](https://github.com/libgit2/libgit2/issues/2120)
* Improve index internals with hashtable lookup for files instead of
using binary search every time
* Tree builder improvements:
* Extend to allow building a tree hierarchy
* Apply-patch API
* Add a patch editing API to enable "git add -p" type operations
* Textconv API to filter binary data before generating diffs (something
like the current Filter API, probably).
* Performance profiling and improvement
* Support "git replace" ref replacements
* Include conflicts in diff results and in status
* GIT_DELTA_CONFLICT for items in conflict (with multiple files)
* Appropriate flags for status
* Support sparse checkout (i.e. "core.sparsecheckout" and ".git/info/sparse-checkout")

View File

@ -1,7 +1,8 @@
libgit2 - the Git linkable library
==================================
[![Build Status](https://secure.travis-ci.org/libgit2/libgit2.png?branch=development)](http://travis-ci.org/libgit2/libgit2)
[![Travis Build Status](https://secure.travis-ci.org/libgit2/libgit2.svg?branch=master)](http://travis-ci.org/libgit2/libgit2)
[![AppVeyor Build Status](https://ci.appveyor.com/api/projects/status/xvof5b4t5480a2q3/branch/master?svg=true)](https://ci.appveyor.com/project/libgit2/libgit2/branch/master)
[![Coverity Scan Build Status](https://scan.coverity.com/projects/639/badge.svg)](https://scan.coverity.com/projects/639)
`libgit2` is a portable, pure C implementation of the Git core methods
@ -55,9 +56,30 @@ dependencies, it can make use of a few libraries to add to it:
- pthreads (non-Windows) to enable threadsafe access as well as multi-threaded pack generation
- OpenSSL (non-Windows) to talk over HTTPS and provide the SHA-1 functions
- LibSSH2 to enable the ssh transport
- LibSSH2 to enable the SSH transport
- iconv (OSX) to handle the HFS+ path encoding peculiarities
Initialization
===============
The 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 should
call `git_libgit2_shutdown` *after* those threads have exited. If you
require assistance coordinating this, simply have the worker threads call
`git_libgit2_init` at startup and `git_libgit2_shutdown` at shutdown.
Threading
=========
See [THREADING](THREADING.md) for information
Building libgit2 - Using CMake
==============================
@ -90,7 +112,7 @@ The following CMake variables are declared:
- `INCLUDE_INSTALL_DIR`: Where to install headers to.
- `BUILD_SHARED_LIBS`: Build libgit2 as a Shared Library (defaults to ON)
- `BUILD_CLAR`: Build [Clar](https://github.com/vmg/clar)-based test suite (defaults to ON)
- `THREADSAFE`: Build libgit2 with threading support (defaults to OFF)
- `THREADSAFE`: Build libgit2 with threading support (defaults to ON)
- `STDCALL`: Build libgit2 as `stdcall`. Turn off for `cdecl` (Windows; defaults to ON)
Compiler and linker options
@ -119,8 +141,7 @@ You need to run the CMake commands from the Visual Studio command
prompt, not the regular or Windows SDK one. Select the right generator
for your version with the `-G "Visual Studio X" option.
See [the wiki]
(https://github.com/libgit2/libgit2/wiki/Building-libgit2-on-Windows)
See [the website](https://libgit2.github.com/docs/guides/build-and-link)
for more detailed instructions.
Android
@ -133,16 +154,16 @@ with full path to the toolchain):
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 `-DCMAKE_TOOLCHAIN_FILE={pathToToolchainFile} -DANDROID=1` to cmake command
Add `-DCMAKE_TOOLCHAIN_FILE={pathToToolchainFile}` to cmake command
when configuring.
Language Bindings
@ -155,7 +176,7 @@ Here are the bindings to libgit2 that are currently available:
* Chicken Scheme
* chicken-git <https://wiki.call-cc.org/egg/git>
* D
* dlibgit <https://github.com/AndrejMitrovic/dlibgit>
* dlibgit <https://github.com/s-ludwig/dlibgit>
* Delphi
* GitForDelphi <https://github.com/libgit2/GitForDelphi>
* Erlang
@ -168,6 +189,8 @@ Here are the bindings to libgit2 that are currently available:
* hgit2 <https://github.com/fpco/gitlib>
* Java
* Jagged <https://github.com/ethomson/jagged>
* Julia
* LibGit2.jl <https://github.com/jakebolewski/LibGit2.jl>
* Lua
* luagit2 <https://github.com/libgit2/luagit2>
* .NET
@ -178,11 +201,11 @@ Here are the bindings to libgit2 that are currently available:
* Objective-C
* objective-git <https://github.com/libgit2/objective-git>
* OCaml
* libgit2-ocaml <https://github.com/burdges/libgit2-ocaml>
* ocaml-libgit2 <https://github.com/fxfactorial/ocaml-libgit2>
* Parrot Virtual Machine
* parrot-libgit2 <https://github.com/letolabs/parrot-libgit2>
* Perl
* Git-Raw <https://github.com/ghedo/p5-Git-Raw>
* Git-Raw <https://github.com/jacquesg/p5-Git-Raw>
* PHP
* php-git <https://github.com/libgit2/php-git>
* PowerShell
@ -193,6 +216,10 @@ Here are the bindings to libgit2 that are currently available:
* git2r <https://github.com/ropensci/git2r>
* Ruby
* Rugged <https://github.com/libgit2/rugged>
* Rust
* git2-rs <https://github.com/alexcrichton/git2-rs>
* Swift
* Gift <https://github.com/modocache/Gift>
* Vala
* libgit2.vapi <https://github.com/apmasell/vapis/blob/master/libgit2.vapi>
@ -209,7 +236,7 @@ workflow, the libgit2 [coding conventions](CONVENTIONS.md), and out list of
License
==================================
`libgit2` is under GPL2 **with linking exemption**. This means you can link to
`libgit2` is under GPL2 **with linking exception**. This means you can link to
and use the library from any program, proprietary or open source; paid or
gratis. However, you cannot modify libgit2 and distribute it without
supplying the source.

107
THREADING.md Normal file
View File

@ -0,0 +1,107 @@
Threads in libgit2
==================
You may safely use any libgit2 object from any thread, though there
may be issues depending on the cryptographic libraries libgit2 or its
dependencies link to (more on this later). For libgit2 itself,
provided you take the following into consideration you won't run into
issues:
Sharing objects
---------------
Use an object from a single thread at a time. Most data structures do
not guard against concurrent access themselves. This is because they
are rarely used in isolation and it makes more sense to synchronize
access via a larger lock or similar mechanism.
There are some objects which are read-only/immutable and are thus safe
to share across threads, such as references and configuration
snapshots.
Error messages
--------------
The error message is thread-local. The `giterr_last()` call must
happen on the same thread as the error in order to get the
message. Often this will be the case regardless, but if you use
something like the [GCD](http://en.wikipedia.org/wiki/Grand_Central_Dispatch)
on Mac OS X (where code is executed on an arbitrary thread), the code
must make sure to retrieve the error code on the thread where the error
happened.
Threads and cryptographic libraries
=======================================
On Windows
----------
When built as a native Windows DLL, libgit2 uses WinCNG and WinHTTP,
both of which are thread-safe. You do not need to do anything special.
When using libssh2 which itself uses WinCNG, there are no special
steps necessary. If you are using a MinGW or similar environment where
libssh2 uses OpenSSL or libgcrypt, then the general case affects
you.
On Mac OS X
-----------
By default we use libcurl to perform the encryption. The
system-provided libcurl uses SecureTransport, so no special steps are
necessary. If you link against another libcurl (e.g. from homebrew)
refer to the general case.
If the option to use libcurl was deactivated, the library makes use of
CommonCrypto and SecureTransport for cryptographic support. These are
thread-safe and you do not need to do anything special.
Note that libssh2 may still use OpenSSL itself. In that case, the
general case still affects you if you use ssh.
General Case
------------
By default we use libcurl, which has its own ![recommendations for
thread safety](http://curl.haxx.se/libcurl/c/libcurl-tutorial.html#Multi-threading).
If libcurl was not found or was disabled, libgit2 uses OpenSSL to be
able to use HTTPS as a transport. This library is made to be
thread-implementation agnostic, and the users of the library must set
which locking function it should use. This means that libgit2 cannot
know what to set as the user of libgit2 may use OpenSSL independently
and the locking settings must survive libgit2 shutting down.
libgit2 does provide a last-resort convenience function
`git_openssl_set_locking()` (available in `sys/openssl.h`) to use the
platform-native mutex mechanisms to perform the locking, which you may
rely on if you do not want to use OpenSSL outside of libgit2, or you
know that libgit2 will outlive the rest of the operations. It is not
safe to use OpenSSL multi-threaded after libgit2's shutdown function
has been called.
If your programming language offers a package/bindings for OpenSSL,
you should very strongly prefer to use that in order to set up
locking, as they provide a level of coördination which is impossible
when using this function.
See the
[OpenSSL documentation](https://www.openssl.org/docs/crypto/threads.html)
on threading for more details.
Be also aware that libgit2 does not always link against OpenSSL
if there are alternatives provided by the system.
libssh2 may be linked against OpenSSL or libgcrypt. If it uses
OpenSSL, you only need to set up threading for OpenSSL once and the
above paragraphs are enough. If it uses libgcrypt, then you need to
set up its locking before using it multi-threaded. libgit2 has no
direct connection to libgcrypt and thus has not convenience functions for
it (but libgcrypt has macros). Read libgcrypt's
[threading documentation for more information](http://www.gnupg.org/documentation/manuals/gcrypt/Multi_002dThreading.html)
It is your responsibility as an application author or packager to know
what your dependencies are linked against and to take the appropriate
steps to ensure the cryptographic libraries are thread-safe. We agree
that this situation is far from ideal but at this time it is something
the application authors need to deal with.

39
appveyor.yml Normal file
View File

@ -0,0 +1,39 @@
version: '{build}'
branches:
only:
- master
- /^maint.*/
environment:
GITTEST_INVASIVE_FS_STRUCTURE: 1
GITTEST_INVASIVE_FS_SIZE: 1
matrix:
- GENERATOR: "Visual Studio 11"
ARCH: 32
- GENERATOR: "Visual Studio 11 Win64"
ARCH: 64
- GENERATOR: "MSYS Makefiles"
ARCH: 32
- GENERATOR: "MSYS Makefiles"
ARCH: i686 # this is for 32-bit MinGW-w64
- GENERATOR: "MSYS Makefiles"
ARCH: 64
matrix:
allow_failures:
- GENERATOR: "MSYS Makefiles"
ARCH: 32
cache:
- i686-4.9.2-release-win32-sjlj-rt_v3-rev1.7z
- x86_64-4.9.2-release-win32-seh-rt_v3-rev1.7z
build_script:
- ps: |
mkdir build
cd build
if ($env:GENERATOR -ne "MSYS Makefiles") {
cmake -D ENABLE_TRACE=ON -D BUILD_CLAR=ON -D MSVC_CRTDBG=ON .. -G"$env:GENERATOR"
cmake --build . --config Debug
}
- cmd: |
if "%GENERATOR%"=="MSYS Makefiles" (C:\MinGW\msys\1.0\bin\sh --login /c/projects/libgit2/script/appveyor-mingw.sh)
test_script:
- ps: ctest -V .

View File

@ -0,0 +1,9 @@
IF (COREFOUNDATION_INCLUDE_DIR AND COREFOUNDATION_DIRS)
SET(COREFOUNDATION_FOUND TRUE)
ELSE ()
FIND_PATH(COREFOUNDATION_INCLUDE_DIR NAMES CoreFoundation.h)
FIND_LIBRARY(COREFOUNDATION_DIRS NAMES CoreFoundation)
IF (COREFOUNDATION_INCLUDE_DIR AND COREFOUNDATION_DIRS)
SET(COREFOUNDATION_FOUND TRUE)
ENDIF ()
ENDIF ()

View File

@ -0,0 +1,324 @@
# - Try to find GSSAPI
# Once done this will define
#
# KRB5_CONFIG - Path to krb5-config
# GSSAPI_ROOT_DIR - Set this variable to the root installation of GSSAPI
#
# Read-Only variables:
# GSSAPI_FLAVOR_MIT - set to TURE if MIT Kerberos has been found
# GSSAPI_FLAVOR_HEIMDAL - set to TRUE if Heimdal Keberos has been found
# GSSAPI_FOUND - system has GSSAPI
# GSSAPI_INCLUDE_DIR - the GSSAPI include directory
# GSSAPI_LIBRARIES - Link these to use GSSAPI
# GSSAPI_DEFINITIONS - Compiler switches required for using GSSAPI
#
#=============================================================================
# Copyright (c) 2013 Andreas Schneider <asn@cryptomilk.org>
#
# Distributed under the OSI-approved BSD License (the "License");
# see accompanying file Copyright.txt for details.
#
# This software is distributed WITHOUT ANY WARRANTY; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the License for more information.
#=============================================================================
#
find_path(GSSAPI_ROOT_DIR
NAMES
include/gssapi.h
include/gssapi/gssapi.h
HINTS
${_GSSAPI_ROOT_HINTS}
PATHS
${_GSSAPI_ROOT_PATHS}
)
mark_as_advanced(GSSAPI_ROOT_DIR)
if (UNIX)
find_program(KRB5_CONFIG
NAMES
krb5-config
PATHS
${GSSAPI_ROOT_DIR}/bin
/opt/local/bin)
mark_as_advanced(KRB5_CONFIG)
if (KRB5_CONFIG)
# Check if we have MIT KRB5
execute_process(
COMMAND
${KRB5_CONFIG} --vendor
RESULT_VARIABLE
_GSSAPI_VENDOR_RESULT
OUTPUT_VARIABLE
_GSSAPI_VENDOR_STRING)
if (_GSSAPI_VENDOR_STRING MATCHES ".*Massachusetts.*")
set(GSSAPI_FLAVOR_MIT TRUE)
else()
execute_process(
COMMAND
${KRB5_CONFIG} --libs gssapi
RESULT_VARIABLE
_GSSAPI_LIBS_RESULT
OUTPUT_VARIABLE
_GSSAPI_LIBS_STRING)
if (_GSSAPI_LIBS_STRING MATCHES ".*roken.*")
set(GSSAPI_FLAVOR_HEIMDAL TRUE)
endif()
endif()
# Get the include dir
execute_process(
COMMAND
${KRB5_CONFIG} --cflags gssapi
RESULT_VARIABLE
_GSSAPI_INCLUDE_RESULT
OUTPUT_VARIABLE
_GSSAPI_INCLUDE_STRING)
string(REGEX REPLACE "(\r?\n)+$" "" _GSSAPI_INCLUDE_STRING "${_GSSAPI_INCLUDE_STRING}")
string(REGEX REPLACE " *-I" "" _GSSAPI_INCLUDEDIR "${_GSSAPI_INCLUDE_STRING}")
endif()
if (NOT GSSAPI_FLAVOR_MIT AND NOT GSSAPI_FLAVOR_HEIMDAL)
# Check for HEIMDAL
find_package(PkgConfig)
if (PKG_CONFIG_FOUND)
pkg_check_modules(_GSSAPI heimdal-gssapi)
endif (PKG_CONFIG_FOUND)
if (_GSSAPI_FOUND)
set(GSSAPI_FLAVOR_HEIMDAL TRUE)
else()
find_path(_GSSAPI_ROKEN
NAMES
roken.h
PATHS
${GSSAPI_ROOT_DIR}/include
${_GSSAPI_INCLUDEDIR})
if (_GSSAPI_ROKEN)
set(GSSAPI_FLAVOR_HEIMDAL TRUE)
endif()
endif ()
endif()
endif (UNIX)
find_path(GSSAPI_INCLUDE_DIR
NAMES
gssapi.h
gssapi/gssapi.h
PATHS
${GSSAPI_ROOT_DIR}/include
${_GSSAPI_INCLUDEDIR}
)
if (GSSAPI_FLAVOR_MIT)
find_library(GSSAPI_LIBRARY
NAMES
gssapi_krb5
PATHS
${GSSAPI_ROOT_DIR}/lib
${_GSSAPI_LIBDIR}
)
find_library(KRB5_LIBRARY
NAMES
krb5
PATHS
${GSSAPI_ROOT_DIR}/lib
${_GSSAPI_LIBDIR}
)
find_library(K5CRYPTO_LIBRARY
NAMES
k5crypto
PATHS
${GSSAPI_ROOT_DIR}/lib
${_GSSAPI_LIBDIR}
)
find_library(COM_ERR_LIBRARY
NAMES
com_err
PATHS
${GSSAPI_ROOT_DIR}/lib
${_GSSAPI_LIBDIR}
)
if (GSSAPI_LIBRARY)
set(GSSAPI_LIBRARIES
${GSSAPI_LIBRARIES}
${GSSAPI_LIBRARY}
)
endif (GSSAPI_LIBRARY)
if (KRB5_LIBRARY)
set(GSSAPI_LIBRARIES
${GSSAPI_LIBRARIES}
${KRB5_LIBRARY}
)
endif (KRB5_LIBRARY)
if (K5CRYPTO_LIBRARY)
set(GSSAPI_LIBRARIES
${GSSAPI_LIBRARIES}
${K5CRYPTO_LIBRARY}
)
endif (K5CRYPTO_LIBRARY)
if (COM_ERR_LIBRARY)
set(GSSAPI_LIBRARIES
${GSSAPI_LIBRARIES}
${COM_ERR_LIBRARY}
)
endif (COM_ERR_LIBRARY)
endif (GSSAPI_FLAVOR_MIT)
if (GSSAPI_FLAVOR_HEIMDAL)
find_library(GSSAPI_LIBRARY
NAMES
gssapi
PATHS
${GSSAPI_ROOT_DIR}/lib
${_GSSAPI_LIBDIR}
)
find_library(KRB5_LIBRARY
NAMES
krb5
PATHS
${GSSAPI_ROOT_DIR}/lib
${_GSSAPI_LIBDIR}
)
find_library(HCRYPTO_LIBRARY
NAMES
hcrypto
PATHS
${GSSAPI_ROOT_DIR}/lib
${_GSSAPI_LIBDIR}
)
find_library(COM_ERR_LIBRARY
NAMES
com_err
PATHS
${GSSAPI_ROOT_DIR}/lib
${_GSSAPI_LIBDIR}
)
find_library(HEIMNTLM_LIBRARY
NAMES
heimntlm
PATHS
${GSSAPI_ROOT_DIR}/lib
${_GSSAPI_LIBDIR}
)
find_library(HX509_LIBRARY
NAMES
hx509
PATHS
${GSSAPI_ROOT_DIR}/lib
${_GSSAPI_LIBDIR}
)
find_library(ASN1_LIBRARY
NAMES
asn1
PATHS
${GSSAPI_ROOT_DIR}/lib
${_GSSAPI_LIBDIR}
)
find_library(WIND_LIBRARY
NAMES
wind
PATHS
${GSSAPI_ROOT_DIR}/lib
${_GSSAPI_LIBDIR}
)
find_library(ROKEN_LIBRARY
NAMES
roken
PATHS
${GSSAPI_ROOT_DIR}/lib
${_GSSAPI_LIBDIR}
)
if (GSSAPI_LIBRARY)
set(GSSAPI_LIBRARIES
${GSSAPI_LIBRARIES}
${GSSAPI_LIBRARY}
)
endif (GSSAPI_LIBRARY)
if (KRB5_LIBRARY)
set(GSSAPI_LIBRARIES
${GSSAPI_LIBRARIES}
${KRB5_LIBRARY}
)
endif (KRB5_LIBRARY)
if (HCRYPTO_LIBRARY)
set(GSSAPI_LIBRARIES
${GSSAPI_LIBRARIES}
${HCRYPTO_LIBRARY}
)
endif (HCRYPTO_LIBRARY)
if (COM_ERR_LIBRARY)
set(GSSAPI_LIBRARIES
${GSSAPI_LIBRARIES}
${COM_ERR_LIBRARY}
)
endif (COM_ERR_LIBRARY)
if (HEIMNTLM_LIBRARY)
set(GSSAPI_LIBRARIES
${GSSAPI_LIBRARIES}
${HEIMNTLM_LIBRARY}
)
endif (HEIMNTLM_LIBRARY)
if (HX509_LIBRARY)
set(GSSAPI_LIBRARIES
${GSSAPI_LIBRARIES}
${HX509_LIBRARY}
)
endif (HX509_LIBRARY)
if (ASN1_LIBRARY)
set(GSSAPI_LIBRARIES
${GSSAPI_LIBRARIES}
${ASN1_LIBRARY}
)
endif (ASN1_LIBRARY)
if (WIND_LIBRARY)
set(GSSAPI_LIBRARIES
${GSSAPI_LIBRARIES}
${WIND_LIBRARY}
)
endif (WIND_LIBRARY)
if (ROKEN_LIBRARY)
set(GSSAPI_LIBRARIES
${GSSAPI_LIBRARIES}
${WIND_LIBRARY}
)
endif (ROKEN_LIBRARY)
endif (GSSAPI_FLAVOR_HEIMDAL)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(GSSAPI DEFAULT_MSG GSSAPI_LIBRARIES GSSAPI_INCLUDE_DIR)
if (GSSAPI_INCLUDE_DIRS AND GSSAPI_LIBRARIES)
set(GSSAPI_FOUND TRUE)
endif (GSSAPI_INCLUDE_DIRS AND GSSAPI_LIBRARIES)
# show the GSSAPI_INCLUDE_DIRS and GSSAPI_LIBRARIES variables only in the advanced view
mark_as_advanced(GSSAPI_INCLUDE_DIRS GSSAPI_LIBRARIES)

View File

@ -11,10 +11,7 @@ IF(ICONV_INCLUDE_DIR AND ICONV_LIBRARIES)
SET(ICONV_FIND_QUIETLY TRUE)
ENDIF()
FIND_PATH(ICONV_INCLUDE_DIR iconv.h PATHS /opt/local/include NO_DEFAULT_PATH)
FIND_PATH(ICONV_INCLUDE_DIR iconv.h)
FIND_LIBRARY(iconv_lib NAMES iconv libiconv libiconv-2 c NO_DEFAULT_PATH PATHS /opt/local/lib)
FIND_LIBRARY(iconv_lib NAMES iconv libiconv libiconv-2 c)
IF(ICONV_INCLUDE_DIR AND iconv_lib)

View File

@ -1,44 +0,0 @@
if (LIBSSH2_LIBRARIES AND LIBSSH2_INCLUDE_DIRS)
set(LIBSSH2_FOUND TRUE)
else (LIBSSH2_LIBRARIES AND LIBSSH2_INCLUDE_DIRS)
find_path(LIBSSH2_INCLUDE_DIR
NAMES
libssh2.h
PATHS
/usr/include
/usr/local/include
/opt/local/include
/sw/include
${CMAKE_INCLUDE_PATH}
${CMAKE_INSTALL_PREFIX}/include
)
find_library(LIBSSH2_LIBRARY
NAMES
ssh2
libssh2
PATHS
/usr/lib
/usr/local/lib
/opt/local/lib
/sw/lib
${CMAKE_LIBRARY_PATH}
${CMAKE_INSTALL_PREFIX}/lib
)
if (LIBSSH2_INCLUDE_DIR AND LIBSSH2_LIBRARY)
set(LIBSSH2_FOUND TRUE)
endif (LIBSSH2_INCLUDE_DIR AND LIBSSH2_LIBRARY)
if (LIBSSH2_FOUND)
set(LIBSSH2_INCLUDE_DIRS
${LIBSSH2_INCLUDE_DIR}
)
set(LIBSSH2_LIBRARIES
${LIBSSH2_LIBRARIES}
${LIBSSH2_LIBRARY}
)
endif (LIBSSH2_FOUND)
endif (LIBSSH2_LIBRARIES AND LIBSSH2_INCLUDE_DIRS)

View File

@ -0,0 +1,9 @@
IF (SECURITY_INCLUDE_DIR AND SECURITY_DIRS)
SET(SECURITY_FOUND TRUE)
ELSE ()
FIND_PATH(SECURITY_INCLUDE_DIR NAMES Security/Security.h)
FIND_LIBRARY(SECURITY_DIRS NAMES Security)
IF (SECURITY_INCLUDE_DIR AND SECURITY_DIRS)
SET(SECURITY_FOUND TRUE)
ENDIF ()
ENDIF ()

View File

@ -40,6 +40,8 @@ typedef __int64 int64_t;
typedef unsigned __int64 uint64_t;
typedef SIZE_T size_t;
typedef SSIZE_T ssize_t;
#elif defined(__sun) || defined(__sun__)
#include <sys/inttypes.h>
#else
#include <stdint.h>
#endif

45
deps/winhttp/urlmon.h vendored Normal file
View File

@ -0,0 +1,45 @@
/*
* Copyright (C) the libgit2 contributors. All rights reserved.
*
* This file is part of libgit2, distributed under the GNU GPL v2 with
* a Linking Exception. For full terms see the included COPYING file.
*/
#if defined(__MINGW_VERSION) || defined(__MINGW32_VERSION)
#ifndef __CUSTOM_URLMON_H
#define __CUSTOM_URLMON_H
typedef struct IInternetSecurityManager IInternetSecurityManager;
typedef struct IInternetSecurityManagerVtbl
{
HRESULT(STDMETHODCALLTYPE *QueryInterface)(IInternetSecurityManager *, REFIID, void **);
ULONG(STDMETHODCALLTYPE *AddRef)(IInternetSecurityManager *);
ULONG(STDMETHODCALLTYPE *Release)(IInternetSecurityManager *);
LPVOID SetSecuritySite;
LPVOID GetSecuritySite;
HRESULT(STDMETHODCALLTYPE *MapUrlToZone)(IInternetSecurityManager *, LPCWSTR, DWORD *, DWORD);
LPVOID GetSecurityId;
LPVOID ProcessUrlAction;
LPVOID QueryCustomPolicy;
LPVOID SetZoneMapping;
LPVOID GetZoneMappings;
} IInternetSecurityManagerVtbl;
struct IInternetSecurityManager
{
CONST_VTBL struct IInternetSecurityManagerVtbl *lpVtbl;
};
#define URLZONE_LOCAL_MACHINE 0
#define URLZONE_INTRANET 1
#define URLZONE_TRUSTED 2
#endif /* __CUSTOM_URLMON_H */
#else
#include_next <urlmon.h>
#endif

29
deps/winhttp/winhttp.def vendored Normal file
View File

@ -0,0 +1,29 @@
LIBRARY WINHTTP
EXPORTS
WinHttpAddRequestHeaders@16
WinHttpCheckPlatform@0
WinHttpCloseHandle@4
WinHttpConnect@16
WinHttpCrackUrl@16
WinHttpCreateUrl@16
WinHttpDetectAutoProxyConfigUrl@8
WinHttpGetDefaultProxyConfiguration@4
WinHttpGetIEProxyConfigForCurrentUser@4
WinHttpGetProxyForUrl@16
WinHttpOpen@20
WinHttpOpenRequest@28
WinHttpQueryAuthSchemes@16
WinHttpQueryDataAvailable@8
WinHttpQueryHeaders@24
WinHttpQueryOption@16
WinHttpReadData@16
WinHttpReceiveResponse@8
WinHttpSendRequest@28
WinHttpSetCredentials@24
WinHttpSetDefaultProxyConfiguration@4
WinHttpSetOption@16
WinHttpSetStatusCallback@16
WinHttpSetTimeouts@20
WinHttpTimeFromSystemTime@8
WinHttpTimeToSystemTime@8
WinHttpWriteData@16

592
deps/winhttp/winhttp.h vendored Normal file
View File

@ -0,0 +1,592 @@
/*
* Copyright (C) 2007 Francois Gouget
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
#if defined(__MINGW_VERSION) || defined(__MINGW32_VERSION)
#ifndef __WINE_WINHTTP_H
#define __WINE_WINHTTP_H
#ifdef _WIN64
#include <pshpack8.h>
#else
#include <pshpack4.h>
#endif
#define WINHTTPAPI
#define BOOLAPI WINHTTPAPI BOOL WINAPI
typedef LPVOID HINTERNET;
typedef HINTERNET *LPHINTERNET;
#define INTERNET_DEFAULT_PORT 0
#define INTERNET_DEFAULT_HTTP_PORT 80
#define INTERNET_DEFAULT_HTTPS_PORT 443
typedef WORD INTERNET_PORT;
typedef INTERNET_PORT *LPINTERNET_PORT;
#define INTERNET_SCHEME_HTTP 1
#define INTERNET_SCHEME_HTTPS 2
typedef int INTERNET_SCHEME, *LPINTERNET_SCHEME;
#define ICU_ESCAPE 0x80000000
/* flags for WinHttpOpen */
#define WINHTTP_FLAG_ASYNC 0x10000000
/* flags for WinHttpOpenRequest */
#define WINHTTP_FLAG_ESCAPE_PERCENT 0x00000004
#define WINHTTP_FLAG_NULL_CODEPAGE 0x00000008
#define WINHTTP_FLAG_ESCAPE_DISABLE 0x00000040
#define WINHTTP_FLAG_ESCAPE_DISABLE_QUERY 0x00000080
#define WINHTTP_FLAG_BYPASS_PROXY_CACHE 0x00000100
#define WINHTTP_FLAG_REFRESH WINHTTP_FLAG_BYPASS_PROXY_CACHE
#define WINHTTP_FLAG_SECURE 0x00800000
#define WINHTTP_ACCESS_TYPE_DEFAULT_PROXY 0
#define WINHTTP_ACCESS_TYPE_NO_PROXY 1
#define WINHTTP_ACCESS_TYPE_NAMED_PROXY 3
#define WINHTTP_NO_PROXY_NAME NULL
#define WINHTTP_NO_PROXY_BYPASS NULL
#define WINHTTP_NO_REFERER NULL
#define WINHTTP_DEFAULT_ACCEPT_TYPES NULL
#define WINHTTP_NO_ADDITIONAL_HEADERS NULL
#define WINHTTP_NO_REQUEST_DATA NULL
#define WINHTTP_HEADER_NAME_BY_INDEX NULL
#define WINHTTP_NO_OUTPUT_BUFFER NULL
#define WINHTTP_NO_HEADER_INDEX NULL
#define WINHTTP_ADDREQ_INDEX_MASK 0x0000FFFF
#define WINHTTP_ADDREQ_FLAGS_MASK 0xFFFF0000
#define WINHTTP_ADDREQ_FLAG_ADD_IF_NEW 0x10000000
#define WINHTTP_ADDREQ_FLAG_ADD 0x20000000
#define WINHTTP_ADDREQ_FLAG_COALESCE_WITH_COMMA 0x40000000
#define WINHTTP_ADDREQ_FLAG_COALESCE_WITH_SEMICOLON 0x01000000
#define WINHTTP_ADDREQ_FLAG_COALESCE WINHTTP_ADDREQ_FLAG_COALESCE_WITH_COMMA
#define WINHTTP_ADDREQ_FLAG_REPLACE 0x80000000
#define WINHTTP_IGNORE_REQUEST_TOTAL_LENGTH 0
/* flags for WinHttp{Set/Query}Options */
#define WINHTTP_FIRST_OPTION WINHTTP_OPTION_CALLBACK
#define WINHTTP_OPTION_CALLBACK 1
#define WINHTTP_OPTION_RESOLVE_TIMEOUT 2
#define WINHTTP_OPTION_CONNECT_TIMEOUT 3
#define WINHTTP_OPTION_CONNECT_RETRIES 4
#define WINHTTP_OPTION_SEND_TIMEOUT 5
#define WINHTTP_OPTION_RECEIVE_TIMEOUT 6
#define WINHTTP_OPTION_RECEIVE_RESPONSE_TIMEOUT 7
#define WINHTTP_OPTION_HANDLE_TYPE 9
#define WINHTTP_OPTION_READ_BUFFER_SIZE 12
#define WINHTTP_OPTION_WRITE_BUFFER_SIZE 13
#define WINHTTP_OPTION_PARENT_HANDLE 21
#define WINHTTP_OPTION_EXTENDED_ERROR 24
#define WINHTTP_OPTION_SECURITY_FLAGS 31
#define WINHTTP_OPTION_SECURITY_CERTIFICATE_STRUCT 32
#define WINHTTP_OPTION_URL 34
#define WINHTTP_OPTION_SECURITY_KEY_BITNESS 36
#define WINHTTP_OPTION_PROXY 38
#define WINHTTP_OPTION_USER_AGENT 41
#define WINHTTP_OPTION_CONTEXT_VALUE 45
#define WINHTTP_OPTION_CLIENT_CERT_CONTEXT 47
#define WINHTTP_OPTION_REQUEST_PRIORITY 58
#define WINHTTP_OPTION_HTTP_VERSION 59
#define WINHTTP_OPTION_DISABLE_FEATURE 63
#define WINHTTP_OPTION_CODEPAGE 68
#define WINHTTP_OPTION_MAX_CONNS_PER_SERVER 73
#define WINHTTP_OPTION_MAX_CONNS_PER_1_0_SERVER 74
#define WINHTTP_OPTION_AUTOLOGON_POLICY 77
#define WINHTTP_OPTION_SERVER_CERT_CONTEXT 78
#define WINHTTP_OPTION_ENABLE_FEATURE 79
#define WINHTTP_OPTION_WORKER_THREAD_COUNT 80
#define WINHTTP_OPTION_PASSPORT_COBRANDING_TEXT 81
#define WINHTTP_OPTION_PASSPORT_COBRANDING_URL 82
#define WINHTTP_OPTION_CONFIGURE_PASSPORT_AUTH 83
#define WINHTTP_OPTION_SECURE_PROTOCOLS 84
#define WINHTTP_OPTION_ENABLETRACING 85
#define WINHTTP_OPTION_PASSPORT_SIGN_OUT 86
#define WINHTTP_OPTION_PASSPORT_RETURN_URL 87
#define WINHTTP_OPTION_REDIRECT_POLICY 88
#define WINHTTP_OPTION_MAX_HTTP_AUTOMATIC_REDIRECTS 89
#define WINHTTP_OPTION_MAX_HTTP_STATUS_CONTINUE 90
#define WINHTTP_OPTION_MAX_RESPONSE_HEADER_SIZE 91
#define WINHTTP_OPTION_MAX_RESPONSE_DRAIN_SIZE 92
#define WINHTTP_OPTION_CONNECTION_INFO 93
#define WINHTTP_OPTION_CLIENT_CERT_ISSUER_LIST 94
#define WINHTTP_OPTION_SPN 96
#define WINHTTP_OPTION_GLOBAL_PROXY_CREDS 97
#define WINHTTP_OPTION_GLOBAL_SERVER_CREDS 98
#define WINHTTP_OPTION_UNLOAD_NOTIFY_EVENT 99
#define WINHTTP_OPTION_REJECT_USERPWD_IN_URL 100
#define WINHTTP_OPTION_USE_GLOBAL_SERVER_CREDENTIALS 101
#define WINHTTP_LAST_OPTION WINHTTP_OPTION_USE_GLOBAL_SERVER_CREDENTIALS
#define WINHTTP_OPTION_USERNAME 0x1000
#define WINHTTP_OPTION_PASSWORD 0x1001
#define WINHTTP_OPTION_PROXY_USERNAME 0x1002
#define WINHTTP_OPTION_PROXY_PASSWORD 0x1003
#define WINHTTP_CONNS_PER_SERVER_UNLIMITED 0xFFFFFFFF
#define WINHTTP_AUTOLOGON_SECURITY_LEVEL_MEDIUM 0
#define WINHTTP_AUTOLOGON_SECURITY_LEVEL_LOW 1
#define WINHTTP_AUTOLOGON_SECURITY_LEVEL_HIGH 2
#define WINHTTP_AUTOLOGON_SECURITY_LEVEL_DEFAULT WINHTTP_AUTOLOGON_SECURITY_LEVEL_MEDIUM
#define WINHTTP_OPTION_REDIRECT_POLICY_NEVER 0
#define WINHTTP_OPTION_REDIRECT_POLICY_DISALLOW_HTTPS_TO_HTTP 1
#define WINHTTP_OPTION_REDIRECT_POLICY_ALWAYS 2
#define WINHTTP_OPTION_REDIRECT_POLICY_LAST WINHTTP_OPTION_REDIRECT_POLICY_ALWAYS
#define WINHTTP_OPTION_REDIRECT_POLICY_DEFAULT WINHTTP_OPTION_REDIRECT_POLICY_DISALLOW_HTTPS_TO_HTTP
#define WINHTTP_DISABLE_PASSPORT_AUTH 0x00000000
#define WINHTTP_ENABLE_PASSPORT_AUTH 0x10000000
#define WINHTTP_DISABLE_PASSPORT_KEYRING 0x20000000
#define WINHTTP_ENABLE_PASSPORT_KEYRING 0x40000000
#define WINHTTP_DISABLE_COOKIES 0x00000001
#define WINHTTP_DISABLE_REDIRECTS 0x00000002
#define WINHTTP_DISABLE_AUTHENTICATION 0x00000004
#define WINHTTP_DISABLE_KEEP_ALIVE 0x00000008
#define WINHTTP_ENABLE_SSL_REVOCATION 0x00000001
#define WINHTTP_ENABLE_SSL_REVERT_IMPERSONATION 0x00000002
#define WINHTTP_DISABLE_SPN_SERVER_PORT 0x00000000
#define WINHTTP_ENABLE_SPN_SERVER_PORT 0x00000001
#define WINHTTP_OPTION_SPN_MASK WINHTTP_ENABLE_SPN_SERVER_PORT
/* Options for WinHttpOpenRequest */
#define WINHTTP_NO_REFERER NULL
#define WINHTTP_DEFAULT_ACCEPT_TYPES NULL
/* Options for WinHttpSendRequest */
#define WINHTTP_NO_ADDITIONAL_HEADERS NULL
#define WINHTTP_NO_REQUEST_DATA NULL
/* WinHTTP error codes */
#define WINHTTP_ERROR_BASE 12000
#define ERROR_WINHTTP_OUT_OF_HANDLES (WINHTTP_ERROR_BASE + 1)
#define ERROR_WINHTTP_TIMEOUT (WINHTTP_ERROR_BASE + 2)
#define ERROR_WINHTTP_INTERNAL_ERROR (WINHTTP_ERROR_BASE + 4)
#define ERROR_WINHTTP_INVALID_URL (WINHTTP_ERROR_BASE + 5)
#define ERROR_WINHTTP_UNRECOGNIZED_SCHEME (WINHTTP_ERROR_BASE + 6)
#define ERROR_WINHTTP_NAME_NOT_RESOLVED (WINHTTP_ERROR_BASE + 7)
#define ERROR_WINHTTP_INVALID_OPTION (WINHTTP_ERROR_BASE + 9)
#define ERROR_WINHTTP_OPTION_NOT_SETTABLE (WINHTTP_ERROR_BASE + 11)
#define ERROR_WINHTTP_SHUTDOWN (WINHTTP_ERROR_BASE + 12)
#define ERROR_WINHTTP_LOGIN_FAILURE (WINHTTP_ERROR_BASE + 15)
#define ERROR_WINHTTP_OPERATION_CANCELLED (WINHTTP_ERROR_BASE + 17)
#define ERROR_WINHTTP_INCORRECT_HANDLE_TYPE (WINHTTP_ERROR_BASE + 18)
#define ERROR_WINHTTP_INCORRECT_HANDLE_STATE (WINHTTP_ERROR_BASE + 19)
#define ERROR_WINHTTP_CANNOT_CONNECT (WINHTTP_ERROR_BASE + 29)
#define ERROR_WINHTTP_CONNECTION_ERROR (WINHTTP_ERROR_BASE + 30)
#define ERROR_WINHTTP_RESEND_REQUEST (WINHTTP_ERROR_BASE + 32)
#define ERROR_WINHTTP_SECURE_CERT_DATE_INVALID (WINHTTP_ERROR_BASE + 37)
#define ERROR_WINHTTP_SECURE_CERT_CN_INVALID (WINHTTP_ERROR_BASE + 38)
#define ERROR_WINHTTP_CLIENT_AUTH_CERT_NEEDED (WINHTTP_ERROR_BASE + 44)
#define ERROR_WINHTTP_SECURE_INVALID_CA (WINHTTP_ERROR_BASE + 45)
#define ERROR_WINHTTP_SECURE_CERT_REV_FAILED (WINHTTP_ERROR_BASE + 57)
#define ERROR_WINHTTP_CANNOT_CALL_BEFORE_OPEN (WINHTTP_ERROR_BASE + 100)
#define ERROR_WINHTTP_CANNOT_CALL_BEFORE_SEND (WINHTTP_ERROR_BASE + 101)
#define ERROR_WINHTTP_CANNOT_CALL_AFTER_SEND (WINHTTP_ERROR_BASE + 102)
#define ERROR_WINHTTP_CANNOT_CALL_AFTER_OPEN (WINHTTP_ERROR_BASE + 103)
#define ERROR_WINHTTP_HEADER_NOT_FOUND (WINHTTP_ERROR_BASE + 150)
#define ERROR_WINHTTP_INVALID_SERVER_RESPONSE (WINHTTP_ERROR_BASE + 152)
#define ERROR_WINHTTP_INVALID_HEADER (WINHTTP_ERROR_BASE + 153)
#define ERROR_WINHTTP_INVALID_QUERY_REQUEST (WINHTTP_ERROR_BASE + 154)
#define ERROR_WINHTTP_HEADER_ALREADY_EXISTS (WINHTTP_ERROR_BASE + 155)
#define ERROR_WINHTTP_REDIRECT_FAILED (WINHTTP_ERROR_BASE + 156)
#define ERROR_WINHTTP_SECURE_CHANNEL_ERROR (WINHTTP_ERROR_BASE + 157)
#define ERROR_WINHTTP_BAD_AUTO_PROXY_SCRIPT (WINHTTP_ERROR_BASE + 166)
#define ERROR_WINHTTP_UNABLE_TO_DOWNLOAD_SCRIPT (WINHTTP_ERROR_BASE + 167)
#define ERROR_WINHTTP_SECURE_INVALID_CERT (WINHTTP_ERROR_BASE + 169)
#define ERROR_WINHTTP_SECURE_CERT_REVOKED (WINHTTP_ERROR_BASE + 170)
#define ERROR_WINHTTP_NOT_INITIALIZED (WINHTTP_ERROR_BASE + 172)
#define ERROR_WINHTTP_SECURE_FAILURE (WINHTTP_ERROR_BASE + 175)
#define ERROR_WINHTTP_AUTO_PROXY_SERVICE_ERROR (WINHTTP_ERROR_BASE + 178)
#define ERROR_WINHTTP_SECURE_CERT_WRONG_USAGE (WINHTTP_ERROR_BASE + 179)
#define ERROR_WINHTTP_AUTODETECTION_FAILED (WINHTTP_ERROR_BASE + 180)
#define ERROR_WINHTTP_HEADER_COUNT_EXCEEDED (WINHTTP_ERROR_BASE + 181)
#define ERROR_WINHTTP_HEADER_SIZE_OVERFLOW (WINHTTP_ERROR_BASE + 182)
#define ERROR_WINHTTP_CHUNKED_ENCODING_HEADER_SIZE_OVERFLOW (WINHTTP_ERROR_BASE + 183)
#define ERROR_WINHTTP_RESPONSE_DRAIN_OVERFLOW (WINHTTP_ERROR_BASE + 184)
#define ERROR_WINHTTP_CLIENT_CERT_NO_PRIVATE_KEY (WINHTTP_ERROR_BASE + 185)
#define ERROR_WINHTTP_CLIENT_CERT_NO_ACCESS_PRIVATE_KEY (WINHTTP_ERROR_BASE + 186)
#define WINHTTP_ERROR_LAST (WINHTTP_ERROR_BASE + 186)
/* WinHttp status codes */
#define HTTP_STATUS_CONTINUE 100
#define HTTP_STATUS_SWITCH_PROTOCOLS 101
#define HTTP_STATUS_OK 200
#define HTTP_STATUS_CREATED 201
#define HTTP_STATUS_ACCEPTED 202
#define HTTP_STATUS_PARTIAL 203
#define HTTP_STATUS_NO_CONTENT 204
#define HTTP_STATUS_RESET_CONTENT 205
#define HTTP_STATUS_PARTIAL_CONTENT 206
#define HTTP_STATUS_WEBDAV_MULTI_STATUS 207
#define HTTP_STATUS_AMBIGUOUS 300
#define HTTP_STATUS_MOVED 301
#define HTTP_STATUS_REDIRECT 302
#define HTTP_STATUS_REDIRECT_METHOD 303
#define HTTP_STATUS_NOT_MODIFIED 304
#define HTTP_STATUS_USE_PROXY 305
#define HTTP_STATUS_REDIRECT_KEEP_VERB 307
#define HTTP_STATUS_BAD_REQUEST 400
#define HTTP_STATUS_DENIED 401
#define HTTP_STATUS_PAYMENT_REQ 402
#define HTTP_STATUS_FORBIDDEN 403
#define HTTP_STATUS_NOT_FOUND 404
#define HTTP_STATUS_BAD_METHOD 405
#define HTTP_STATUS_NONE_ACCEPTABLE 406
#define HTTP_STATUS_PROXY_AUTH_REQ 407
#define HTTP_STATUS_REQUEST_TIMEOUT 408
#define HTTP_STATUS_CONFLICT 409
#define HTTP_STATUS_GONE 410
#define HTTP_STATUS_LENGTH_REQUIRED 411
#define HTTP_STATUS_PRECOND_FAILED 412
#define HTTP_STATUS_REQUEST_TOO_LARGE 413
#define HTTP_STATUS_URI_TOO_LONG 414
#define HTTP_STATUS_UNSUPPORTED_MEDIA 415
#define HTTP_STATUS_RETRY_WITH 449
#define HTTP_STATUS_SERVER_ERROR 500
#define HTTP_STATUS_NOT_SUPPORTED 501
#define HTTP_STATUS_BAD_GATEWAY 502
#define HTTP_STATUS_SERVICE_UNAVAIL 503
#define HTTP_STATUS_GATEWAY_TIMEOUT 504
#define HTTP_STATUS_VERSION_NOT_SUP 505
#define HTTP_STATUS_FIRST HTTP_STATUS_CONTINUE
#define HTTP_STATUS_LAST HTTP_STATUS_VERSION_NOT_SUP
#define SECURITY_FLAG_IGNORE_UNKNOWN_CA 0x00000100
#define SECURITY_FLAG_IGNORE_CERT_DATE_INVALID 0x00002000
#define SECURITY_FLAG_IGNORE_CERT_CN_INVALID 0x00001000
#define SECURITY_FLAG_IGNORE_CERT_WRONG_USAGE 0x00000200
#define SECURITY_FLAG_SECURE 0x00000001
#define SECURITY_FLAG_STRENGTH_WEAK 0x10000000
#define SECURITY_FLAG_STRENGTH_MEDIUM 0x40000000
#define SECURITY_FLAG_STRENGTH_STRONG 0x20000000
#define ICU_NO_ENCODE 0x20000000
#define ICU_DECODE 0x10000000
#define ICU_NO_META 0x08000000
#define ICU_ENCODE_SPACES_ONLY 0x04000000
#define ICU_BROWSER_MODE 0x02000000
#define ICU_ENCODE_PERCENT 0x00001000
/* Query flags */
#define WINHTTP_QUERY_MIME_VERSION 0
#define WINHTTP_QUERY_CONTENT_TYPE 1
#define WINHTTP_QUERY_CONTENT_TRANSFER_ENCODING 2
#define WINHTTP_QUERY_CONTENT_ID 3
#define WINHTTP_QUERY_CONTENT_DESCRIPTION 4
#define WINHTTP_QUERY_CONTENT_LENGTH 5
#define WINHTTP_QUERY_CONTENT_LANGUAGE 6
#define WINHTTP_QUERY_ALLOW 7
#define WINHTTP_QUERY_PUBLIC 8
#define WINHTTP_QUERY_DATE 9
#define WINHTTP_QUERY_EXPIRES 10
#define WINHTTP_QUERY_LAST_MODIFIED 11
#define WINHTTP_QUERY_MESSAGE_ID 12
#define WINHTTP_QUERY_URI 13
#define WINHTTP_QUERY_DERIVED_FROM 14
#define WINHTTP_QUERY_COST 15
#define WINHTTP_QUERY_LINK 16
#define WINHTTP_QUERY_PRAGMA 17
#define WINHTTP_QUERY_VERSION 18
#define WINHTTP_QUERY_STATUS_CODE 19
#define WINHTTP_QUERY_STATUS_TEXT 20
#define WINHTTP_QUERY_RAW_HEADERS 21
#define WINHTTP_QUERY_RAW_HEADERS_CRLF 22
#define WINHTTP_QUERY_CONNECTION 23
#define WINHTTP_QUERY_ACCEPT 24
#define WINHTTP_QUERY_ACCEPT_CHARSET 25
#define WINHTTP_QUERY_ACCEPT_ENCODING 26
#define WINHTTP_QUERY_ACCEPT_LANGUAGE 27
#define WINHTTP_QUERY_AUTHORIZATION 28
#define WINHTTP_QUERY_CONTENT_ENCODING 29
#define WINHTTP_QUERY_FORWARDED 30
#define WINHTTP_QUERY_FROM 31
#define WINHTTP_QUERY_IF_MODIFIED_SINCE 32
#define WINHTTP_QUERY_LOCATION 33
#define WINHTTP_QUERY_ORIG_URI 34
#define WINHTTP_QUERY_REFERER 35
#define WINHTTP_QUERY_RETRY_AFTER 36
#define WINHTTP_QUERY_SERVER 37
#define WINHTTP_QUERY_TITLE 38
#define WINHTTP_QUERY_USER_AGENT 39
#define WINHTTP_QUERY_WWW_AUTHENTICATE 40
#define WINHTTP_QUERY_PROXY_AUTHENTICATE 41
#define WINHTTP_QUERY_ACCEPT_RANGES 42
#define WINHTTP_QUERY_SET_COOKIE 43
#define WINHTTP_QUERY_COOKIE 44
#define WINHTTP_QUERY_REQUEST_METHOD 45
#define WINHTTP_QUERY_REFRESH 46
#define WINHTTP_QUERY_CONTENT_DISPOSITION 47
#define WINHTTP_QUERY_AGE 48
#define WINHTTP_QUERY_CACHE_CONTROL 49
#define WINHTTP_QUERY_CONTENT_BASE 50
#define WINHTTP_QUERY_CONTENT_LOCATION 51
#define WINHTTP_QUERY_CONTENT_MD5 52
#define WINHTTP_QUERY_CONTENT_RANGE 53
#define WINHTTP_QUERY_ETAG 54
#define WINHTTP_QUERY_HOST 55
#define WINHTTP_QUERY_IF_MATCH 56
#define WINHTTP_QUERY_IF_NONE_MATCH 57
#define WINHTTP_QUERY_IF_RANGE 58
#define WINHTTP_QUERY_IF_UNMODIFIED_SINCE 59
#define WINHTTP_QUERY_MAX_FORWARDS 60
#define WINHTTP_QUERY_PROXY_AUTHORIZATION 61
#define WINHTTP_QUERY_RANGE 62
#define WINHTTP_QUERY_TRANSFER_ENCODING 63
#define WINHTTP_QUERY_UPGRADE 64
#define WINHTTP_QUERY_VARY 65
#define WINHTTP_QUERY_VIA 66
#define WINHTTP_QUERY_WARNING 67
#define WINHTTP_QUERY_EXPECT 68
#define WINHTTP_QUERY_PROXY_CONNECTION 69
#define WINHTTP_QUERY_UNLESS_MODIFIED_SINCE 70
#define WINHTTP_QUERY_PROXY_SUPPORT 75
#define WINHTTP_QUERY_AUTHENTICATION_INFO 76
#define WINHTTP_QUERY_PASSPORT_URLS 77
#define WINHTTP_QUERY_PASSPORT_CONFIG 78
#define WINHTTP_QUERY_MAX 78
#define WINHTTP_QUERY_CUSTOM 65535
#define WINHTTP_QUERY_FLAG_REQUEST_HEADERS 0x80000000
#define WINHTTP_QUERY_FLAG_SYSTEMTIME 0x40000000
#define WINHTTP_QUERY_FLAG_NUMBER 0x20000000
/* Callback options */
#define WINHTTP_CALLBACK_STATUS_RESOLVING_NAME 0x00000001
#define WINHTTP_CALLBACK_STATUS_NAME_RESOLVED 0x00000002
#define WINHTTP_CALLBACK_STATUS_CONNECTING_TO_SERVER 0x00000004
#define WINHTTP_CALLBACK_STATUS_CONNECTED_TO_SERVER 0x00000008
#define WINHTTP_CALLBACK_STATUS_SENDING_REQUEST 0x00000010
#define WINHTTP_CALLBACK_STATUS_REQUEST_SENT 0x00000020
#define WINHTTP_CALLBACK_STATUS_RECEIVING_RESPONSE 0x00000040
#define WINHTTP_CALLBACK_STATUS_RESPONSE_RECEIVED 0x00000080
#define WINHTTP_CALLBACK_STATUS_CLOSING_CONNECTION 0x00000100
#define WINHTTP_CALLBACK_STATUS_CONNECTION_CLOSED 0x00000200
#define WINHTTP_CALLBACK_STATUS_HANDLE_CREATED 0x00000400
#define WINHTTP_CALLBACK_STATUS_HANDLE_CLOSING 0x00000800
#define WINHTTP_CALLBACK_STATUS_DETECTING_PROXY 0x00001000
#define WINHTTP_CALLBACK_STATUS_REDIRECT 0x00004000
#define WINHTTP_CALLBACK_STATUS_INTERMEDIATE_RESPONSE 0x00008000
#define WINHTTP_CALLBACK_STATUS_SECURE_FAILURE 0x00010000
#define WINHTTP_CALLBACK_STATUS_HEADERS_AVAILABLE 0x00020000
#define WINHTTP_CALLBACK_STATUS_DATA_AVAILABLE 0x00040000
#define WINHTTP_CALLBACK_STATUS_READ_COMPLETE 0x00080000
#define WINHTTP_CALLBACK_STATUS_WRITE_COMPLETE 0x00100000
#define WINHTTP_CALLBACK_STATUS_REQUEST_ERROR 0x00200000
#define WINHTTP_CALLBACK_STATUS_SENDREQUEST_COMPLETE 0x00400000
#define WINHTTP_CALLBACK_FLAG_RESOLVE_NAME (WINHTTP_CALLBACK_STATUS_RESOLVING_NAME | WINHTTP_CALLBACK_STATUS_NAME_RESOLVED)
#define WINHTTP_CALLBACK_FLAG_CONNECT_TO_SERVER (WINHTTP_CALLBACK_STATUS_CONNECTING_TO_SERVER | WINHTTP_CALLBACK_STATUS_CONNECTED_TO_SERVER)
#define WINHTTP_CALLBACK_FLAG_SEND_REQUEST (WINHTTP_CALLBACK_STATUS_SENDING_REQUEST | WINHTTP_CALLBACK_STATUS_REQUEST_SENT)
#define WINHTTP_CALLBACK_FLAG_RECEIVE_RESPONSE (WINHTTP_CALLBACK_STATUS_RECEIVING_RESPONSE | WINHTTP_CALLBACK_STATUS_RESPONSE_RECEIVED)
#define WINHTTP_CALLBACK_FLAG_CLOSE_CONNECTION (WINHTTP_CALLBACK_STATUS_CLOSING_CONNECTION | WINHTTP_CALLBACK_STATUS_CONNECTION_CLOSED)
#define WINHTTP_CALLBACK_FLAG_HANDLES (WINHTTP_CALLBACK_STATUS_HANDLE_CREATED | WINHTTP_CALLBACK_STATUS_HANDLE_CLOSING)
#define WINHTTP_CALLBACK_FLAG_DETECTING_PROXY WINHTTP_CALLBACK_STATUS_DETECTING_PROXY
#define WINHTTP_CALLBACK_FLAG_REDIRECT WINHTTP_CALLBACK_STATUS_REDIRECT
#define WINHTTP_CALLBACK_FLAG_INTERMEDIATE_RESPONSE WINHTTP_CALLBACK_STATUS_INTERMEDIATE_RESPONSE
#define WINHTTP_CALLBACK_FLAG_SECURE_FAILURE WINHTTP_CALLBACK_STATUS_SECURE_FAILURE
#define WINHTTP_CALLBACK_FLAG_SENDREQUEST_COMPLETE WINHTTP_CALLBACK_STATUS_SENDREQUEST_COMPLETE
#define WINHTTP_CALLBACK_FLAG_HEADERS_AVAILABLE WINHTTP_CALLBACK_STATUS_HEADERS_AVAILABLE
#define WINHTTP_CALLBACK_FLAG_DATA_AVAILABLE WINHTTP_CALLBACK_STATUS_DATA_AVAILABLE
#define WINHTTP_CALLBACK_FLAG_READ_COMPLETE WINHTTP_CALLBACK_STATUS_READ_COMPLETE
#define WINHTTP_CALLBACK_FLAG_WRITE_COMPLETE WINHTTP_CALLBACK_STATUS_WRITE_COMPLETE
#define WINHTTP_CALLBACK_FLAG_REQUEST_ERROR WINHTTP_CALLBACK_STATUS_REQUEST_ERROR
#define WINHTTP_CALLBACK_FLAG_ALL_COMPLETIONS (WINHTTP_CALLBACK_STATUS_SENDREQUEST_COMPLETE | WINHTTP_CALLBACK_STATUS_HEADERS_AVAILABLE \
| WINHTTP_CALLBACK_STATUS_DATA_AVAILABLE | WINHTTP_CALLBACK_STATUS_READ_COMPLETE \
| WINHTTP_CALLBACK_STATUS_WRITE_COMPLETE | WINHTTP_CALLBACK_STATUS_REQUEST_ERROR)
#define WINHTTP_CALLBACK_FLAG_ALL_NOTIFICATIONS 0xffffffff
#define WINHTTP_INVALID_STATUS_CALLBACK ((WINHTTP_STATUS_CALLBACK)(-1))
#define API_RECEIVE_RESPONSE (1)
#define API_QUERY_DATA_AVAILABLE (2)
#define API_READ_DATA (3)
#define API_WRITE_DATA (4)
#define API_SEND_REQUEST (5)
#define WINHTTP_HANDLE_TYPE_SESSION 1
#define WINHTTP_HANDLE_TYPE_CONNECT 2
#define WINHTTP_HANDLE_TYPE_REQUEST 3
#define WINHTTP_CALLBACK_STATUS_FLAG_CERT_REV_FAILED 0x00000001
#define WINHTTP_CALLBACK_STATUS_FLAG_INVALID_CERT 0x00000002
#define WINHTTP_CALLBACK_STATUS_FLAG_CERT_REVOKED 0x00000004
#define WINHTTP_CALLBACK_STATUS_FLAG_INVALID_CA 0x00000008
#define WINHTTP_CALLBACK_STATUS_FLAG_CERT_CN_INVALID 0x00000010
#define WINHTTP_CALLBACK_STATUS_FLAG_CERT_DATE_INVALID 0x00000020
#define WINHTTP_CALLBACK_STATUS_FLAG_CERT_WRONG_USAGE 0x00000040
#define WINHTTP_CALLBACK_STATUS_FLAG_SECURITY_CHANNEL_ERROR 0x80000000
#define WINHTTP_FLAG_SECURE_PROTOCOL_SSL2 0x00000008
#define WINHTTP_FLAG_SECURE_PROTOCOL_SSL3 0x00000020
#define WINHTTP_FLAG_SECURE_PROTOCOL_TLS1 0x00000080
#define WINHTTP_FLAG_SECURE_PROTOCOL_ALL (WINHTTP_FLAG_SECURE_PROTOCOL_SSL2 | WINHTTP_FLAG_SECURE_PROTOCOL_SSL3 | WINHTTP_FLAG_SECURE_PROTOCOL_TLS1)
#define WINHTTP_AUTH_SCHEME_BASIC 0x00000001
#define WINHTTP_AUTH_SCHEME_NTLM 0x00000002
#define WINHTTP_AUTH_SCHEME_PASSPORT 0x00000004
#define WINHTTP_AUTH_SCHEME_DIGEST 0x00000008
#define WINHTTP_AUTH_SCHEME_NEGOTIATE 0x00000010
#define WINHTTP_AUTH_TARGET_SERVER 0x00000000
#define WINHTTP_AUTH_TARGET_PROXY 0x00000001
#define WINHTTP_TIME_FORMAT_BUFSIZE 62
typedef struct
{
DWORD dwStructSize;
LPWSTR lpszScheme;
DWORD dwSchemeLength;
INTERNET_SCHEME nScheme;
LPWSTR lpszHostName;
DWORD dwHostNameLength;
INTERNET_PORT nPort;
LPWSTR lpszUserName;
DWORD dwUserNameLength;
LPWSTR lpszPassword;
DWORD dwPasswordLength;
LPWSTR lpszUrlPath;
DWORD dwUrlPathLength;
LPWSTR lpszExtraInfo;
DWORD dwExtraInfoLength;
} URL_COMPONENTS, *LPURL_COMPONENTS;
typedef URL_COMPONENTS URL_COMPONENTSW;
typedef LPURL_COMPONENTS LPURL_COMPONENTSW;
typedef struct
{
DWORD_PTR dwResult;
DWORD dwError;
} WINHTTP_ASYNC_RESULT, *LPWINHTTP_ASYNC_RESULT;
typedef struct
{
FILETIME ftExpiry;
FILETIME ftStart;
LPWSTR lpszSubjectInfo;
LPWSTR lpszIssuerInfo;
LPWSTR lpszProtocolName;
LPWSTR lpszSignatureAlgName;
LPWSTR lpszEncryptionAlgName;
DWORD dwKeySize;
} WINHTTP_CERTIFICATE_INFO;
typedef struct
{
DWORD dwAccessType;
LPWSTR lpszProxy;
LPWSTR lpszProxyBypass;
} WINHTTP_PROXY_INFO, *LPWINHTTP_PROXY_INFO;
typedef WINHTTP_PROXY_INFO WINHTTP_PROXY_INFOW;
typedef LPWINHTTP_PROXY_INFO LPWINHTTP_PROXY_INFOW;
typedef struct
{
BOOL fAutoDetect;
LPWSTR lpszAutoConfigUrl;
LPWSTR lpszProxy;
LPWSTR lpszProxyBypass;
} WINHTTP_CURRENT_USER_IE_PROXY_CONFIG;
typedef VOID (CALLBACK *WINHTTP_STATUS_CALLBACK)(HINTERNET,DWORD_PTR,DWORD,LPVOID,DWORD);
#define WINHTTP_AUTO_DETECT_TYPE_DHCP 0x00000001
#define WINHTTP_AUTO_DETECT_TYPE_DNS_A 0x00000002
#define WINHTTP_AUTOPROXY_AUTO_DETECT 0x00000001
#define WINHTTP_AUTOPROXY_CONFIG_URL 0x00000002
#define WINHTTP_AUTOPROXY_RUN_INPROCESS 0x00010000
#define WINHTTP_AUTOPROXY_RUN_OUTPROCESS_ONLY 0x00020000
typedef struct
{
DWORD dwFlags;
DWORD dwAutoDetectFlags;
LPCWSTR lpszAutoConfigUrl;
LPVOID lpvReserved;
DWORD dwReserved;
BOOL fAutoLogonIfChallenged;
} WINHTTP_AUTOPROXY_OPTIONS;
typedef struct
{
DWORD dwMajorVersion;
DWORD dwMinorVersion;
} HTTP_VERSION_INFO, *LPHTTP_VERSION_INFO;
#ifdef _WS2DEF_
typedef struct
{
DWORD cbSize;
SOCKADDR_STORAGE LocalAddress;
SOCKADDR_STORAGE RemoteAddress;
} WINHTTP_CONNECTION_INFO;
#endif
#ifdef __cplusplus
extern "C" {
#endif
BOOL WINAPI WinHttpAddRequestHeaders(HINTERNET,LPCWSTR,DWORD,DWORD);
BOOL WINAPI WinHttpDetectAutoProxyConfigUrl(DWORD,LPWSTR*);
BOOL WINAPI WinHttpCheckPlatform(void);
BOOL WINAPI WinHttpCloseHandle(HINTERNET);
HINTERNET WINAPI WinHttpConnect(HINTERNET,LPCWSTR,INTERNET_PORT,DWORD);
BOOL WINAPI WinHttpCrackUrl(LPCWSTR,DWORD,DWORD,LPURL_COMPONENTS);
BOOL WINAPI WinHttpCreateUrl(LPURL_COMPONENTS,DWORD,LPWSTR,LPDWORD);
BOOL WINAPI WinHttpGetDefaultProxyConfiguration(WINHTTP_PROXY_INFO*);
BOOL WINAPI WinHttpGetIEProxyConfigForCurrentUser(WINHTTP_CURRENT_USER_IE_PROXY_CONFIG*);
BOOL WINAPI WinHttpGetProxyForUrl(HINTERNET,LPCWSTR,WINHTTP_AUTOPROXY_OPTIONS*,WINHTTP_PROXY_INFO*);
HINTERNET WINAPI WinHttpOpen(LPCWSTR,DWORD,LPCWSTR,LPCWSTR,DWORD);
HINTERNET WINAPI WinHttpOpenRequest(HINTERNET,LPCWSTR,LPCWSTR,LPCWSTR,LPCWSTR,LPCWSTR*,DWORD);
BOOL WINAPI WinHttpQueryAuthParams(HINTERNET,DWORD,LPVOID*);
BOOL WINAPI WinHttpQueryAuthSchemes(HINTERNET,LPDWORD,LPDWORD,LPDWORD);
BOOL WINAPI WinHttpQueryDataAvailable(HINTERNET,LPDWORD);
BOOL WINAPI WinHttpQueryHeaders(HINTERNET,DWORD,LPCWSTR,LPVOID,LPDWORD,LPDWORD);
BOOL WINAPI WinHttpQueryOption(HINTERNET,DWORD,LPVOID,LPDWORD);
BOOL WINAPI WinHttpReadData(HINTERNET,LPVOID,DWORD,LPDWORD);
BOOL WINAPI WinHttpReceiveResponse(HINTERNET,LPVOID);
BOOL WINAPI WinHttpSendRequest(HINTERNET,LPCWSTR,DWORD,LPVOID,DWORD,DWORD,DWORD_PTR);
BOOL WINAPI WinHttpSetDefaultProxyConfiguration(WINHTTP_PROXY_INFO*);
BOOL WINAPI WinHttpSetCredentials(HINTERNET,DWORD,DWORD,LPCWSTR,LPCWSTR,LPVOID);
BOOL WINAPI WinHttpSetOption(HINTERNET,DWORD,LPVOID,DWORD);
WINHTTP_STATUS_CALLBACK WINAPI WinHttpSetStatusCallback(HINTERNET,WINHTTP_STATUS_CALLBACK,DWORD,DWORD_PTR);
BOOL WINAPI WinHttpSetTimeouts(HINTERNET,int,int,int,int);
BOOL WINAPI WinHttpTimeFromSystemTime(const SYSTEMTIME *,LPWSTR);
BOOL WINAPI WinHttpTimeToSystemTime(LPCWSTR,SYSTEMTIME*);
BOOL WINAPI WinHttpWriteData(HINTERNET,LPCVOID,DWORD,LPDWORD);
#ifdef __cplusplus
}
#endif
#include <poppack.h>
#endif /* __WINE_WINHTTP_H */
#else
#include_next <winhttp.h>
#endif

29
deps/winhttp/winhttp64.def vendored Normal file
View File

@ -0,0 +1,29 @@
LIBRARY WINHTTP
EXPORTS
WinHttpAddRequestHeaders
WinHttpCheckPlatform
WinHttpCloseHandle
WinHttpConnect
WinHttpCrackUrl
WinHttpCreateUrl
WinHttpDetectAutoProxyConfigUrl
WinHttpGetDefaultProxyConfiguration
WinHttpGetIEProxyConfigForCurrentUser
WinHttpGetProxyForUrl
WinHttpOpen
WinHttpOpenRequest
WinHttpQueryAuthSchemes
WinHttpQueryDataAvailable
WinHttpQueryHeaders
WinHttpQueryOption
WinHttpReadData
WinHttpReceiveResponse
WinHttpSendRequest
WinHttpSetCredentials
WinHttpSetDefaultProxyConfiguration
WinHttpSetOption
WinHttpSetStatusCallback
WinHttpSetTimeouts
WinHttpTimeFromSystemTime
WinHttpTimeToSystemTime
WinHttpWriteData

68
deps/zlib/adler32.c vendored
View File

@ -1,5 +1,5 @@
/* adler32.c -- compute the Adler-32 checksum of a data stream
* Copyright (C) 1995-2007 Mark Adler
* Copyright (C) 1995-2011 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h
*/
@ -9,9 +9,9 @@
#define local static
local uLong adler32_combine_(uLong adler1, uLong adler2, z_off64_t len2);
local uLong adler32_combine_ OF((uLong adler1, uLong adler2, z_off64_t len2));
#define BASE 65521UL /* largest prime smaller than 65536 */
#define BASE 65521 /* largest prime smaller than 65536 */
#define NMAX 5552
/* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */
@ -21,39 +21,44 @@ local uLong adler32_combine_(uLong adler1, uLong adler2, z_off64_t len2);
#define DO8(buf,i) DO4(buf,i); DO4(buf,i+4);
#define DO16(buf) DO8(buf,0); DO8(buf,8);
/* use NO_DIVIDE if your processor does not do division in hardware */
/* use NO_DIVIDE if your processor does not do division in hardware --
try it both ways to see which is faster */
#ifdef NO_DIVIDE
# define MOD(a) \
/* note that this assumes BASE is 65521, where 65536 % 65521 == 15
(thank you to John Reiser for pointing this out) */
# define CHOP(a) \
do { \
if (a >= (BASE << 16)) a -= (BASE << 16); \
if (a >= (BASE << 15)) a -= (BASE << 15); \
if (a >= (BASE << 14)) a -= (BASE << 14); \
if (a >= (BASE << 13)) a -= (BASE << 13); \
if (a >= (BASE << 12)) a -= (BASE << 12); \
if (a >= (BASE << 11)) a -= (BASE << 11); \
if (a >= (BASE << 10)) a -= (BASE << 10); \
if (a >= (BASE << 9)) a -= (BASE << 9); \
if (a >= (BASE << 8)) a -= (BASE << 8); \
if (a >= (BASE << 7)) a -= (BASE << 7); \
if (a >= (BASE << 6)) a -= (BASE << 6); \
if (a >= (BASE << 5)) a -= (BASE << 5); \
if (a >= (BASE << 4)) a -= (BASE << 4); \
if (a >= (BASE << 3)) a -= (BASE << 3); \
if (a >= (BASE << 2)) a -= (BASE << 2); \
if (a >= (BASE << 1)) a -= (BASE << 1); \
unsigned long tmp = a >> 16; \
a &= 0xffffUL; \
a += (tmp << 4) - tmp; \
} while (0)
# define MOD28(a) \
do { \
CHOP(a); \
if (a >= BASE) a -= BASE; \
} while (0)
# define MOD4(a) \
# define MOD(a) \
do { \
if (a >= (BASE << 4)) a -= (BASE << 4); \
if (a >= (BASE << 3)) a -= (BASE << 3); \
if (a >= (BASE << 2)) a -= (BASE << 2); \
if (a >= (BASE << 1)) a -= (BASE << 1); \
CHOP(a); \
MOD28(a); \
} while (0)
# define MOD63(a) \
do { /* this assumes a is not negative */ \
z_off64_t tmp = a >> 32; \
a &= 0xffffffffL; \
a += (tmp << 8) - (tmp << 5) + tmp; \
tmp = a >> 16; \
a &= 0xffffL; \
a += (tmp << 4) - tmp; \
tmp = a >> 16; \
a &= 0xffffL; \
a += (tmp << 4) - tmp; \
if (a >= BASE) a -= BASE; \
} while (0)
#else
# define MOD(a) a %= BASE
# define MOD4(a) a %= BASE
# define MOD28(a) a %= BASE
# define MOD63(a) a %= BASE
#endif
/* ========================================================================= */
@ -92,7 +97,7 @@ uLong ZEXPORT adler32(adler, buf, len)
}
if (adler >= BASE)
adler -= BASE;
MOD4(sum2); /* only added so many BASE's */
MOD28(sum2); /* only added so many BASE's */
return adler | (sum2 << 16);
}
@ -137,8 +142,13 @@ local uLong adler32_combine_(adler1, adler2, len2)
unsigned long sum2;
unsigned rem;
/* for negative len, return invalid adler32 as a clue for debugging */
if (len2 < 0)
return 0xffffffffUL;
/* the derivation of this formula is left as an exercise for the reader */
rem = (unsigned)(len2 % BASE);
MOD63(len2); /* assumes len2 >= 0 */
rem = (unsigned)len2;
sum1 = adler1 & 0xffff;
sum2 = rem * sum1;
MOD(sum2);

83
deps/zlib/crc32.c vendored
View File

@ -1,5 +1,5 @@
/* crc32.c -- compute the CRC-32 of a data stream
* Copyright (C) 1995-2006, 2010 Mark Adler
* Copyright (C) 1995-2006, 2010, 2011, 2012 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h
*
* Thanks to Rodney Brown <rbrown64@csc.com.au> for his contribution of faster
@ -17,6 +17,8 @@
of the crc tables. Therefore, if you #define DYNAMIC_CRC_TABLE, you should
first call get_crc_table() to initialize the tables before allowing more than
one thread to use crc32().
DYNAMIC_CRC_TABLE and MAKECRCH can be #defined to write out crc32.h.
*/
#ifdef MAKECRCH
@ -30,31 +32,11 @@
#define local static
/* Find a four-byte integer type for crc32_little() and crc32_big(). */
#ifndef NOBYFOUR
# ifdef STDC /* need ANSI C limits.h to determine sizes */
# include <limits.h>
# define BYFOUR
# if (UINT_MAX == 0xffffffffUL)
typedef unsigned int u4;
# else
# if (ULONG_MAX == 0xffffffffUL)
typedef unsigned long u4;
# else
# if (USHRT_MAX == 0xffffffffUL)
typedef unsigned short u4;
# else
# undef BYFOUR /* can't find a four-byte integer type! */
# endif
# endif
# endif
# endif /* STDC */
#endif /* !NOBYFOUR */
/* Definitions for doing the crc four data bytes at a time. */
#if !defined(NOBYFOUR) && defined(Z_U4)
# define BYFOUR
#endif
#ifdef BYFOUR
# define REV(w) ((((w)>>24)&0xff)+(((w)>>8)&0xff00)+ \
(((w)&0xff00)<<8)+(((w)&0xff)<<24))
local unsigned long crc32_little OF((unsigned long,
const unsigned char FAR *, unsigned));
local unsigned long crc32_big OF((unsigned long,
@ -68,16 +50,16 @@
local unsigned long gf2_matrix_times OF((unsigned long *mat,
unsigned long vec));
local void gf2_matrix_square OF((unsigned long *square, unsigned long *mat));
local uLong crc32_combine_(uLong crc1, uLong crc2, z_off64_t len2);
local uLong crc32_combine_ OF((uLong crc1, uLong crc2, z_off64_t len2));
#ifdef DYNAMIC_CRC_TABLE
local volatile int crc_table_empty = 1;
local unsigned long FAR crc_table[TBLS][256];
local z_crc_t FAR crc_table[TBLS][256];
local void make_crc_table OF((void));
#ifdef MAKECRCH
local void write_table OF((FILE *, const unsigned long FAR *));
local void write_table OF((FILE *, const z_crc_t FAR *));
#endif /* MAKECRCH */
/*
Generate tables for a byte-wise 32-bit CRC calculation on the polynomial:
@ -107,9 +89,9 @@ local void make_crc_table OF((void));
*/
local void make_crc_table()
{
unsigned long c;
z_crc_t c;
int n, k;
unsigned long poly; /* polynomial exclusive-or pattern */
z_crc_t poly; /* polynomial exclusive-or pattern */
/* terms of polynomial defining this crc (except x^32): */
static volatile int first = 1; /* flag to limit concurrent making */
static const unsigned char p[] = {0,1,2,4,5,7,8,10,11,12,16,22,23,26};
@ -121,13 +103,13 @@ local void make_crc_table()
first = 0;
/* make exclusive-or pattern from polynomial (0xedb88320UL) */
poly = 0UL;
for (n = 0; n < sizeof(p)/sizeof(unsigned char); n++)
poly |= 1UL << (31 - p[n]);
poly = 0;
for (n = 0; n < (int)(sizeof(p)/sizeof(unsigned char)); n++)
poly |= (z_crc_t)1 << (31 - p[n]);
/* generate a crc for every 8-bit value */
for (n = 0; n < 256; n++) {
c = (unsigned long)n;
c = (z_crc_t)n;
for (k = 0; k < 8; k++)
c = c & 1 ? poly ^ (c >> 1) : c >> 1;
crc_table[0][n] = c;
@ -138,11 +120,11 @@ local void make_crc_table()
and then the byte reversal of those as well as the first table */
for (n = 0; n < 256; n++) {
c = crc_table[0][n];
crc_table[4][n] = REV(c);
crc_table[4][n] = ZSWAP32(c);
for (k = 1; k < 4; k++) {
c = crc_table[0][c & 0xff] ^ (c >> 8);
crc_table[k][n] = c;
crc_table[k + 4][n] = REV(c);
crc_table[k + 4][n] = ZSWAP32(c);
}
}
#endif /* BYFOUR */
@ -164,7 +146,7 @@ local void make_crc_table()
if (out == NULL) return;
fprintf(out, "/* crc32.h -- tables for rapid CRC calculation\n");
fprintf(out, " * Generated automatically by crc32.c\n */\n\n");
fprintf(out, "local const unsigned long FAR ");
fprintf(out, "local const z_crc_t FAR ");
fprintf(out, "crc_table[TBLS][256] =\n{\n {\n");
write_table(out, crc_table[0]);
# ifdef BYFOUR
@ -184,12 +166,13 @@ local void make_crc_table()
#ifdef MAKECRCH
local void write_table(out, table)
FILE *out;
const unsigned long FAR *table;
const z_crc_t FAR *table;
{
int n;
for (n = 0; n < 256; n++)
fprintf(out, "%s0x%08lxUL%s", n % 5 ? "" : " ", table[n],
fprintf(out, "%s0x%08lxUL%s", n % 5 ? "" : " ",
(unsigned long)(table[n]),
n == 255 ? "\n" : (n % 5 == 4 ? ",\n" : ", "));
}
#endif /* MAKECRCH */
@ -204,13 +187,13 @@ local void write_table(out, table)
/* =========================================================================
* This function can be used by asm versions of crc32()
*/
const unsigned long FAR * ZEXPORT get_crc_table()
const z_crc_t FAR * ZEXPORT get_crc_table()
{
#ifdef DYNAMIC_CRC_TABLE
if (crc_table_empty)
make_crc_table();
#endif /* DYNAMIC_CRC_TABLE */
return (const unsigned long FAR *)crc_table;
return (const z_crc_t FAR *)crc_table;
}
/* ========================================================================= */
@ -232,7 +215,7 @@ unsigned long ZEXPORT crc32(crc, buf, len)
#ifdef BYFOUR
if (sizeof(void *) == sizeof(ptrdiff_t)) {
u4 endian;
z_crc_t endian;
endian = 1;
if (*((unsigned char *)(&endian)))
@ -266,17 +249,17 @@ local unsigned long crc32_little(crc, buf, len)
const unsigned char FAR *buf;
unsigned len;
{
register u4 c;
register const u4 FAR *buf4;
register z_crc_t c;
register const z_crc_t FAR *buf4;
c = (u4)crc;
c = (z_crc_t)crc;
c = ~c;
while (len && ((ptrdiff_t)buf & 3)) {
c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8);
len--;
}
buf4 = (const u4 FAR *)(const void FAR *)buf;
buf4 = (const z_crc_t FAR *)(const void FAR *)buf;
while (len >= 32) {
DOLIT32;
len -= 32;
@ -306,17 +289,17 @@ local unsigned long crc32_big(crc, buf, len)
const unsigned char FAR *buf;
unsigned len;
{
register u4 c;
register const u4 FAR *buf4;
register z_crc_t c;
register const z_crc_t FAR *buf4;
c = REV((u4)crc);
c = ZSWAP32((z_crc_t)crc);
c = ~c;
while (len && ((ptrdiff_t)buf & 3)) {
c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8);
len--;
}
buf4 = (const u4 FAR *)(const void FAR *)buf;
buf4 = (const z_crc_t FAR *)(const void FAR *)buf;
buf4--;
while (len >= 32) {
DOBIG32;
@ -333,7 +316,7 @@ local unsigned long crc32_big(crc, buf, len)
c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8);
} while (--len);
c = ~c;
return (unsigned long)(REV(c));
return (unsigned long)(ZSWAP32(c));
}
#endif /* BYFOUR */

2
deps/zlib/crc32.h vendored
View File

@ -2,7 +2,7 @@
* Generated automatically by crc32.c
*/
local const unsigned long FAR crc_table[TBLS][256] =
local const z_crc_t FAR crc_table[TBLS][256] =
{
{
0x00000000UL, 0x77073096UL, 0xee0e612cUL, 0x990951baUL, 0x076dc419UL,

261
deps/zlib/deflate.c vendored
View File

@ -1,5 +1,5 @@
/* deflate.c -- compress data using the deflation algorithm
* Copyright (C) 1995-2010 Jean-loup Gailly and Mark Adler
* Copyright (C) 1995-2013 Jean-loup Gailly and Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h
*/
@ -37,7 +37,7 @@
* REFERENCES
*
* Deutsch, L.P.,"DEFLATE Compressed Data Format Specification".
* Available in http://www.ietf.org/rfc/rfc1951.txt
* Available in http://tools.ietf.org/html/rfc1951
*
* A description of the Rabin and Karp algorithm is given in the book
* "Algorithms" by R. Sedgewick, Addison-Wesley, p252.
@ -52,7 +52,7 @@
#include "deflate.h"
const char deflate_copyright[] =
" deflate 1.2.5 Copyright 1995-2010 Jean-loup Gailly and Mark Adler ";
" deflate 1.2.8 Copyright 1995-2013 Jean-loup Gailly and Mark Adler ";
/*
If you use the zlib library in a product, an acknowledgment is welcome
in the documentation of your product. If for some reason you cannot
@ -155,6 +155,9 @@ local const config configuration_table[10] = {
struct static_tree_desc_s {int dummy;}; /* for buggy compilers */
#endif
/* rank Z_BLOCK between Z_NO_FLUSH and Z_PARTIAL_FLUSH */
#define RANK(f) (((f) << 1) - ((f) > 4 ? 9 : 0))
/* ===========================================================================
* Update a hash value with the given input byte
* IN assertion: all calls to to UPDATE_HASH are made with consecutive
@ -235,10 +238,19 @@ int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy,
strm->msg = Z_NULL;
if (strm->zalloc == (alloc_func)0) {
#ifdef Z_SOLO
return Z_STREAM_ERROR;
#else
strm->zalloc = zcalloc;
strm->opaque = (voidpf)0;
#endif
}
if (strm->zfree == (free_func)0) strm->zfree = zcfree;
if (strm->zfree == (free_func)0)
#ifdef Z_SOLO
return Z_STREAM_ERROR;
#else
strm->zfree = zcfree;
#endif
#ifdef FASTEST
if (level != 0) level = 1;
@ -293,7 +305,7 @@ int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy,
if (s->window == Z_NULL || s->prev == Z_NULL || s->head == Z_NULL ||
s->pending_buf == Z_NULL) {
s->status = FINISH_STATE;
strm->msg = (char*)ERR_MSG(Z_MEM_ERROR);
strm->msg = ERR_MSG(Z_MEM_ERROR);
deflateEnd (strm);
return Z_MEM_ERROR;
}
@ -314,43 +326,70 @@ int ZEXPORT deflateSetDictionary (strm, dictionary, dictLength)
uInt dictLength;
{
deflate_state *s;
uInt length = dictLength;
uInt n;
IPos hash_head = 0;
uInt str, n;
int wrap;
unsigned avail;
z_const unsigned char *next;
if (strm == Z_NULL || strm->state == Z_NULL || dictionary == Z_NULL ||
strm->state->wrap == 2 ||
(strm->state->wrap == 1 && strm->state->status != INIT_STATE))
if (strm == Z_NULL || strm->state == Z_NULL || dictionary == Z_NULL)
return Z_STREAM_ERROR;
s = strm->state;
wrap = s->wrap;
if (wrap == 2 || (wrap == 1 && s->status != INIT_STATE) || s->lookahead)
return Z_STREAM_ERROR;
s = strm->state;
if (s->wrap)
/* when using zlib wrappers, compute Adler-32 for provided dictionary */
if (wrap == 1)
strm->adler = adler32(strm->adler, dictionary, dictLength);
s->wrap = 0; /* avoid computing Adler-32 in read_buf */
if (length < MIN_MATCH) return Z_OK;
if (length > s->w_size) {
length = s->w_size;
dictionary += dictLength - length; /* use the tail of the dictionary */
/* if dictionary would fill window, just replace the history */
if (dictLength >= s->w_size) {
if (wrap == 0) { /* already empty otherwise */
CLEAR_HASH(s);
s->strstart = 0;
s->block_start = 0L;
s->insert = 0;
}
dictionary += dictLength - s->w_size; /* use the tail */
dictLength = s->w_size;
}
zmemcpy(s->window, dictionary, length);
s->strstart = length;
s->block_start = (long)length;
/* Insert all strings in the hash table (except for the last two bytes).
* s->lookahead stays null, so s->ins_h will be recomputed at the next
* call of fill_window.
*/
s->ins_h = s->window[0];
UPDATE_HASH(s, s->ins_h, s->window[1]);
for (n = 0; n <= length - MIN_MATCH; n++) {
INSERT_STRING(s, n, hash_head);
/* insert dictionary into window and hash */
avail = strm->avail_in;
next = strm->next_in;
strm->avail_in = dictLength;
strm->next_in = (z_const Bytef *)dictionary;
fill_window(s);
while (s->lookahead >= MIN_MATCH) {
str = s->strstart;
n = s->lookahead - (MIN_MATCH-1);
do {
UPDATE_HASH(s, s->ins_h, s->window[str + MIN_MATCH-1]);
#ifndef FASTEST
s->prev[str & s->w_mask] = s->head[s->ins_h];
#endif
s->head[s->ins_h] = (Pos)str;
str++;
} while (--n);
s->strstart = str;
s->lookahead = MIN_MATCH-1;
fill_window(s);
}
if (hash_head) hash_head = 0; /* to make compiler happy */
s->strstart += s->lookahead;
s->block_start = (long)s->strstart;
s->insert = s->lookahead;
s->lookahead = 0;
s->match_length = s->prev_length = MIN_MATCH-1;
s->match_available = 0;
strm->next_in = next;
strm->avail_in = avail;
s->wrap = wrap;
return Z_OK;
}
/* ========================================================================= */
int ZEXPORT deflateReset (strm)
int ZEXPORT deflateResetKeep (strm)
z_streamp strm;
{
deflate_state *s;
@ -380,11 +419,22 @@ int ZEXPORT deflateReset (strm)
s->last_flush = Z_NO_FLUSH;
_tr_init(s);
lm_init(s);
return Z_OK;
}
/* ========================================================================= */
int ZEXPORT deflateReset (strm)
z_streamp strm;
{
int ret;
ret = deflateResetKeep(strm);
if (ret == Z_OK)
lm_init(strm->state);
return ret;
}
/* ========================================================================= */
int ZEXPORT deflateSetHeader (strm, head)
z_streamp strm;
@ -396,15 +446,43 @@ int ZEXPORT deflateSetHeader (strm, head)
return Z_OK;
}
/* ========================================================================= */
int ZEXPORT deflatePending (strm, pending, bits)
unsigned *pending;
int *bits;
z_streamp strm;
{
if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
if (pending != Z_NULL)
*pending = strm->state->pending;
if (bits != Z_NULL)
*bits = strm->state->bi_valid;
return Z_OK;
}
/* ========================================================================= */
int ZEXPORT deflatePrime (strm, bits, value)
z_streamp strm;
int bits;
int value;
{
deflate_state *s;
int put;
if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
strm->state->bi_valid = bits;
strm->state->bi_buf = (ush)(value & ((1 << bits) - 1));
s = strm->state;
if ((Bytef *)(s->d_buf) < s->pending_out + ((Buf_size + 7) >> 3))
return Z_BUF_ERROR;
do {
put = Buf_size - s->bi_valid;
if (put > bits)
put = bits;
s->bi_buf |= (ush)((value & ((1 << put) - 1)) << s->bi_valid);
s->bi_valid += put;
_tr_flush_bits(s);
value >>= put;
bits -= put;
} while (bits);
return Z_OK;
}
@ -435,6 +513,8 @@ int ZEXPORT deflateParams(strm, level, strategy)
strm->total_in != 0) {
/* Flush the last buffer: */
err = deflate(strm, Z_BLOCK);
if (err == Z_BUF_ERROR && s->pending == 0)
err = Z_OK;
}
if (s->level != level) {
s->level = level;
@ -562,19 +642,22 @@ local void putShortMSB (s, b)
local void flush_pending(strm)
z_streamp strm;
{
unsigned len = strm->state->pending;
unsigned len;
deflate_state *s = strm->state;
_tr_flush_bits(s);
len = s->pending;
if (len > strm->avail_out) len = strm->avail_out;
if (len == 0) return;
zmemcpy(strm->next_out, strm->state->pending_out, len);
zmemcpy(strm->next_out, s->pending_out, len);
strm->next_out += len;
strm->state->pending_out += len;
s->pending_out += len;
strm->total_out += len;
strm->avail_out -= len;
strm->state->pending -= len;
if (strm->state->pending == 0) {
strm->state->pending_out = strm->state->pending_buf;
s->pending -= len;
if (s->pending == 0) {
s->pending_out = s->pending_buf;
}
}
@ -801,7 +884,7 @@ int ZEXPORT deflate (strm, flush)
* flushes. For repeated and useless calls with Z_FINISH, we keep
* returning Z_STREAM_END instead of Z_BUF_ERROR.
*/
} else if (strm->avail_in == 0 && flush <= old_flush &&
} else if (strm->avail_in == 0 && RANK(flush) <= RANK(old_flush) &&
flush != Z_FINISH) {
ERR_RETURN(strm, Z_BUF_ERROR);
}
@ -850,6 +933,7 @@ int ZEXPORT deflate (strm, flush)
if (s->lookahead == 0) {
s->strstart = 0;
s->block_start = 0L;
s->insert = 0;
}
}
}
@ -945,12 +1029,12 @@ int ZEXPORT deflateCopy (dest, source)
ss = source->state;
zmemcpy(dest, source, sizeof(z_stream));
zmemcpy((voidpf)dest, (voidpf)source, sizeof(z_stream));
ds = (deflate_state *) ZALLOC(dest, 1, sizeof(deflate_state));
if (ds == Z_NULL) return Z_MEM_ERROR;
dest->state = (struct internal_state FAR *) ds;
zmemcpy(ds, ss, sizeof(deflate_state));
zmemcpy((voidpf)ds, (voidpf)ss, sizeof(deflate_state));
ds->strm = dest;
ds->window = (Bytef *) ZALLOC(dest, ds->w_size, 2*sizeof(Byte));
@ -966,8 +1050,8 @@ int ZEXPORT deflateCopy (dest, source)
}
/* following zmemcpy do not work for 16-bit MSDOS */
zmemcpy(ds->window, ss->window, ds->w_size * 2 * sizeof(Byte));
zmemcpy(ds->prev, ss->prev, ds->w_size * sizeof(Pos));
zmemcpy(ds->head, ss->head, ds->hash_size * sizeof(Pos));
zmemcpy((voidpf)ds->prev, (voidpf)ss->prev, ds->w_size * sizeof(Pos));
zmemcpy((voidpf)ds->head, (voidpf)ss->head, ds->hash_size * sizeof(Pos));
zmemcpy(ds->pending_buf, ss->pending_buf, (uInt)ds->pending_buf_size);
ds->pending_out = ds->pending_buf + (ss->pending_out - ss->pending_buf);
@ -1001,15 +1085,15 @@ local int read_buf(strm, buf, size)
strm->avail_in -= len;
zmemcpy(buf, strm->next_in, len);
if (strm->state->wrap == 1) {
strm->adler = adler32(strm->adler, strm->next_in, len);
strm->adler = adler32(strm->adler, buf, len);
}
#ifdef GZIP
else if (strm->state->wrap == 2) {
strm->adler = crc32(strm->adler, strm->next_in, len);
strm->adler = crc32(strm->adler, buf, len);
}
#endif
zmemcpy(buf, strm->next_in, len);
strm->next_in += len;
strm->total_in += len;
@ -1036,6 +1120,7 @@ local void lm_init (s)
s->strstart = 0;
s->block_start = 0L;
s->lookahead = 0;
s->insert = 0;
s->match_length = s->prev_length = MIN_MATCH-1;
s->match_available = 0;
s->ins_h = 0;
@ -1310,6 +1395,8 @@ local void fill_window(s)
unsigned more; /* Amount of free space at the end of the window. */
uInt wsize = s->w_size;
Assert(s->lookahead < MIN_LOOKAHEAD, "already enough lookahead");
do {
more = (unsigned)(s->window_size -(ulg)s->lookahead -(ulg)s->strstart);
@ -1362,7 +1449,7 @@ local void fill_window(s)
#endif
more += wsize;
}
if (s->strm->avail_in == 0) return;
if (s->strm->avail_in == 0) break;
/* If there was no sliding:
* strstart <= WSIZE+MAX_DIST-1 && lookahead <= MIN_LOOKAHEAD - 1 &&
@ -1381,12 +1468,24 @@ local void fill_window(s)
s->lookahead += n;
/* Initialize the hash value now that we have some input: */
if (s->lookahead >= MIN_MATCH) {
s->ins_h = s->window[s->strstart];
UPDATE_HASH(s, s->ins_h, s->window[s->strstart+1]);
if (s->lookahead + s->insert >= MIN_MATCH) {
uInt str = s->strstart - s->insert;
s->ins_h = s->window[str];
UPDATE_HASH(s, s->ins_h, s->window[str + 1]);
#if MIN_MATCH != 3
Call UPDATE_HASH() MIN_MATCH-3 more times
#endif
while (s->insert) {
UPDATE_HASH(s, s->ins_h, s->window[str + MIN_MATCH-1]);
#ifndef FASTEST
s->prev[str & s->w_mask] = s->head[s->ins_h];
#endif
s->head[s->ins_h] = (Pos)str;
str++;
s->insert--;
if (s->lookahead + s->insert < MIN_MATCH)
break;
}
}
/* If the whole input has less than MIN_MATCH bytes, ins_h is garbage,
* but this is not important since only literal bytes will be emitted.
@ -1427,6 +1526,9 @@ local void fill_window(s)
s->high_water += init;
}
}
Assert((ulg)s->strstart <= s->window_size - MIN_LOOKAHEAD,
"not enough room for search");
}
/* ===========================================================================
@ -1506,8 +1608,14 @@ local block_state deflate_stored(s, flush)
FLUSH_BLOCK(s, 0);
}
}
FLUSH_BLOCK(s, flush == Z_FINISH);
return flush == Z_FINISH ? finish_done : block_done;
s->insert = 0;
if (flush == Z_FINISH) {
FLUSH_BLOCK(s, 1);
return finish_done;
}
if ((long)s->strstart > s->block_start)
FLUSH_BLOCK(s, 0);
return block_done;
}
/* ===========================================================================
@ -1603,8 +1711,14 @@ local block_state deflate_fast(s, flush)
}
if (bflush) FLUSH_BLOCK(s, 0);
}
FLUSH_BLOCK(s, flush == Z_FINISH);
return flush == Z_FINISH ? finish_done : block_done;
s->insert = s->strstart < MIN_MATCH-1 ? s->strstart : MIN_MATCH-1;
if (flush == Z_FINISH) {
FLUSH_BLOCK(s, 1);
return finish_done;
}
if (s->last_lit)
FLUSH_BLOCK(s, 0);
return block_done;
}
#ifndef FASTEST
@ -1728,8 +1842,14 @@ local block_state deflate_slow(s, flush)
_tr_tally_lit(s, s->window[s->strstart-1], bflush);
s->match_available = 0;
}
FLUSH_BLOCK(s, flush == Z_FINISH);
return flush == Z_FINISH ? finish_done : block_done;
s->insert = s->strstart < MIN_MATCH-1 ? s->strstart : MIN_MATCH-1;
if (flush == Z_FINISH) {
FLUSH_BLOCK(s, 1);
return finish_done;
}
if (s->last_lit)
FLUSH_BLOCK(s, 0);
return block_done;
}
#endif /* FASTEST */
@ -1749,11 +1869,11 @@ local block_state deflate_rle(s, flush)
for (;;) {
/* Make sure that we always have enough lookahead, except
* at the end of the input file. We need MAX_MATCH bytes
* for the longest encodable run.
* for the longest run, plus one for the unrolled loop.
*/
if (s->lookahead < MAX_MATCH) {
if (s->lookahead <= MAX_MATCH) {
fill_window(s);
if (s->lookahead < MAX_MATCH && flush == Z_NO_FLUSH) {
if (s->lookahead <= MAX_MATCH && flush == Z_NO_FLUSH) {
return need_more;
}
if (s->lookahead == 0) break; /* flush the current block */
@ -1776,6 +1896,7 @@ local block_state deflate_rle(s, flush)
if (s->match_length > s->lookahead)
s->match_length = s->lookahead;
}
Assert(scan <= s->window+(uInt)(s->window_size-1), "wild scan");
}
/* Emit match if have run of MIN_MATCH or longer, else emit literal */
@ -1796,8 +1917,14 @@ local block_state deflate_rle(s, flush)
}
if (bflush) FLUSH_BLOCK(s, 0);
}
FLUSH_BLOCK(s, flush == Z_FINISH);
return flush == Z_FINISH ? finish_done : block_done;
s->insert = 0;
if (flush == Z_FINISH) {
FLUSH_BLOCK(s, 1);
return finish_done;
}
if (s->last_lit)
FLUSH_BLOCK(s, 0);
return block_done;
}
/* ===========================================================================
@ -1829,6 +1956,12 @@ local block_state deflate_huff(s, flush)
s->strstart++;
if (bflush) FLUSH_BLOCK(s, 0);
}
FLUSH_BLOCK(s, flush == Z_FINISH);
return flush == Z_FINISH ? finish_done : block_done;
s->insert = 0;
if (flush == Z_FINISH) {
FLUSH_BLOCK(s, 1);
return finish_done;
}
if (s->last_lit)
FLUSH_BLOCK(s, 0);
return block_done;
}

12
deps/zlib/deflate.h vendored
View File

@ -1,5 +1,5 @@
/* deflate.h -- internal compression state
* Copyright (C) 1995-2010 Jean-loup Gailly
* Copyright (C) 1995-2012 Jean-loup Gailly
* For conditions of distribution and use, see copyright notice in zlib.h
*/
@ -48,6 +48,9 @@
#define MAX_BITS 15
/* All codes must not exceed MAX_BITS bits */
#define Buf_size 16
/* size of bit buffer in bi_buf */
#define INIT_STATE 42
#define EXTRA_STATE 69
#define NAME_STATE 73
@ -101,7 +104,7 @@ typedef struct internal_state {
int wrap; /* bit 0 true for zlib, bit 1 true for gzip */
gz_headerp gzhead; /* gzip header information to write */
uInt gzindex; /* where in extra, name, or comment */
Byte method; /* STORED (for zip only) or DEFLATED */
Byte method; /* can only be DEFLATED */
int last_flush; /* value of flush param for previous deflate call */
/* used by deflate.c: */
@ -188,7 +191,7 @@ typedef struct internal_state {
int nice_match; /* Stop searching when current match exceeds this */
/* used by trees.c: */
/* Didn't use ct_data typedef below to supress compiler warning */
/* Didn't use ct_data typedef below to suppress compiler warning */
struct ct_data_s dyn_ltree[HEAP_SIZE]; /* literal and length tree */
struct ct_data_s dyn_dtree[2*D_CODES+1]; /* distance tree */
struct ct_data_s bl_tree[2*BL_CODES+1]; /* Huffman tree for bit lengths */
@ -244,7 +247,7 @@ typedef struct internal_state {
ulg opt_len; /* bit length of current block with optimal trees */
ulg static_len; /* bit length of current block with static trees */
uInt matches; /* number of string matches in current block */
int last_eob_len; /* bit length of EOB code for last block */
uInt insert; /* bytes at end of window left to insert */
#ifdef DEBUG
ulg compressed_len; /* total bit length of compressed file mod 2^32 */
@ -294,6 +297,7 @@ void ZLIB_INTERNAL _tr_init OF((deflate_state *s));
int ZLIB_INTERNAL _tr_tally OF((deflate_state *s, unsigned dist, unsigned lc));
void ZLIB_INTERNAL _tr_flush_block OF((deflate_state *s, charf *buf,
ulg stored_len, int last));
void ZLIB_INTERNAL _tr_flush_bits OF((deflate_state *s));
void ZLIB_INTERNAL _tr_align OF((deflate_state *s));
void ZLIB_INTERNAL _tr_stored_block OF((deflate_state *s, charf *buf,
ulg stored_len, int last));

640
deps/zlib/infback.c vendored Normal file
View File

@ -0,0 +1,640 @@
/* infback.c -- inflate using a call-back interface
* Copyright (C) 1995-2011 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h
*/
/*
This code is largely copied from inflate.c. Normally either infback.o or
inflate.o would be linked into an application--not both. The interface
with inffast.c is retained so that optimized assembler-coded versions of
inflate_fast() can be used with either inflate.c or infback.c.
*/
#include "zutil.h"
#include "inftrees.h"
#include "inflate.h"
#include "inffast.h"
/* function prototypes */
local void fixedtables OF((struct inflate_state FAR *state));
/*
strm provides memory allocation functions in zalloc and zfree, or
Z_NULL to use the library memory allocation functions.
windowBits is in the range 8..15, and window is a user-supplied
window and output buffer that is 2**windowBits bytes.
*/
int ZEXPORT inflateBackInit_(strm, windowBits, window, version, stream_size)
z_streamp strm;
int windowBits;
unsigned char FAR *window;
const char *version;
int stream_size;
{
struct inflate_state FAR *state;
if (version == Z_NULL || version[0] != ZLIB_VERSION[0] ||
stream_size != (int)(sizeof(z_stream)))
return Z_VERSION_ERROR;
if (strm == Z_NULL || window == Z_NULL ||
windowBits < 8 || windowBits > 15)
return Z_STREAM_ERROR;
strm->msg = Z_NULL; /* in case we return an error */
if (strm->zalloc == (alloc_func)0) {
#ifdef Z_SOLO
return Z_STREAM_ERROR;
#else
strm->zalloc = zcalloc;
strm->opaque = (voidpf)0;
#endif
}
if (strm->zfree == (free_func)0)
#ifdef Z_SOLO
return Z_STREAM_ERROR;
#else
strm->zfree = zcfree;
#endif
state = (struct inflate_state FAR *)ZALLOC(strm, 1,
sizeof(struct inflate_state));
if (state == Z_NULL) return Z_MEM_ERROR;
Tracev((stderr, "inflate: allocated\n"));
strm->state = (struct internal_state FAR *)state;
state->dmax = 32768U;
state->wbits = windowBits;
state->wsize = 1U << windowBits;
state->window = window;
state->wnext = 0;
state->whave = 0;
return Z_OK;
}
/*
Return state with length and distance decoding tables and index sizes set to
fixed code decoding. Normally this returns fixed tables from inffixed.h.
If BUILDFIXED is defined, then instead this routine builds the tables the
first time it's called, and returns those tables the first time and
thereafter. This reduces the size of the code by about 2K bytes, in
exchange for a little execution time. However, BUILDFIXED should not be
used for threaded applications, since the rewriting of the tables and virgin
may not be thread-safe.
*/
local void fixedtables(state)
struct inflate_state FAR *state;
{
#ifdef BUILDFIXED
static int virgin = 1;
static code *lenfix, *distfix;
static code fixed[544];
/* build fixed huffman tables if first call (may not be thread safe) */
if (virgin) {
unsigned sym, bits;
static code *next;
/* literal/length table */
sym = 0;
while (sym < 144) state->lens[sym++] = 8;
while (sym < 256) state->lens[sym++] = 9;
while (sym < 280) state->lens[sym++] = 7;
while (sym < 288) state->lens[sym++] = 8;
next = fixed;
lenfix = next;
bits = 9;
inflate_table(LENS, state->lens, 288, &(next), &(bits), state->work);
/* distance table */
sym = 0;
while (sym < 32) state->lens[sym++] = 5;
distfix = next;
bits = 5;
inflate_table(DISTS, state->lens, 32, &(next), &(bits), state->work);
/* do this just once */
virgin = 0;
}
#else /* !BUILDFIXED */
# include "inffixed.h"
#endif /* BUILDFIXED */
state->lencode = lenfix;
state->lenbits = 9;
state->distcode = distfix;
state->distbits = 5;
}
/* Macros for inflateBack(): */
/* Load returned state from inflate_fast() */
#define LOAD() \
do { \
put = strm->next_out; \
left = strm->avail_out; \
next = strm->next_in; \
have = strm->avail_in; \
hold = state->hold; \
bits = state->bits; \
} while (0)
/* Set state from registers for inflate_fast() */
#define RESTORE() \
do { \
strm->next_out = put; \
strm->avail_out = left; \
strm->next_in = next; \
strm->avail_in = have; \
state->hold = hold; \
state->bits = bits; \
} while (0)
/* Clear the input bit accumulator */
#define INITBITS() \
do { \
hold = 0; \
bits = 0; \
} while (0)
/* Assure that some input is available. If input is requested, but denied,
then return a Z_BUF_ERROR from inflateBack(). */
#define PULL() \
do { \
if (have == 0) { \
have = in(in_desc, &next); \
if (have == 0) { \
next = Z_NULL; \
ret = Z_BUF_ERROR; \
goto inf_leave; \
} \
} \
} while (0)
/* Get a byte of input into the bit accumulator, or return from inflateBack()
with an error if there is no input available. */
#define PULLBYTE() \
do { \
PULL(); \
have--; \
hold += (unsigned long)(*next++) << bits; \
bits += 8; \
} while (0)
/* Assure that there are at least n bits in the bit accumulator. If there is
not enough available input to do that, then return from inflateBack() with
an error. */
#define NEEDBITS(n) \
do { \
while (bits < (unsigned)(n)) \
PULLBYTE(); \
} while (0)
/* Return the low n bits of the bit accumulator (n < 16) */
#define BITS(n) \
((unsigned)hold & ((1U << (n)) - 1))
/* Remove n bits from the bit accumulator */
#define DROPBITS(n) \
do { \
hold >>= (n); \
bits -= (unsigned)(n); \
} while (0)
/* Remove zero to seven bits as needed to go to a byte boundary */
#define BYTEBITS() \
do { \
hold >>= bits & 7; \
bits -= bits & 7; \
} while (0)
/* Assure that some output space is available, by writing out the window
if it's full. If the write fails, return from inflateBack() with a
Z_BUF_ERROR. */
#define ROOM() \
do { \
if (left == 0) { \
put = state->window; \
left = state->wsize; \
state->whave = left; \
if (out(out_desc, put, left)) { \
ret = Z_BUF_ERROR; \
goto inf_leave; \
} \
} \
} while (0)
/*
strm provides the memory allocation functions and window buffer on input,
and provides information on the unused input on return. For Z_DATA_ERROR
returns, strm will also provide an error message.
in() and out() are the call-back input and output functions. When
inflateBack() needs more input, it calls in(). When inflateBack() has
filled the window with output, or when it completes with data in the
window, it calls out() to write out the data. The application must not
change the provided input until in() is called again or inflateBack()
returns. The application must not change the window/output buffer until
inflateBack() returns.
in() and out() are called with a descriptor parameter provided in the
inflateBack() call. This parameter can be a structure that provides the
information required to do the read or write, as well as accumulated
information on the input and output such as totals and check values.
in() should return zero on failure. out() should return non-zero on
failure. If either in() or out() fails, than inflateBack() returns a
Z_BUF_ERROR. strm->next_in can be checked for Z_NULL to see whether it
was in() or out() that caused in the error. Otherwise, inflateBack()
returns Z_STREAM_END on success, Z_DATA_ERROR for an deflate format
error, or Z_MEM_ERROR if it could not allocate memory for the state.
inflateBack() can also return Z_STREAM_ERROR if the input parameters
are not correct, i.e. strm is Z_NULL or the state was not initialized.
*/
int ZEXPORT inflateBack(strm, in, in_desc, out, out_desc)
z_streamp strm;
in_func in;
void FAR *in_desc;
out_func out;
void FAR *out_desc;
{
struct inflate_state FAR *state;
z_const unsigned char FAR *next; /* next input */
unsigned char FAR *put; /* next output */
unsigned have, left; /* available input and output */
unsigned long hold; /* bit buffer */
unsigned bits; /* bits in bit buffer */
unsigned copy; /* number of stored or match bytes to copy */
unsigned char FAR *from; /* where to copy match bytes from */
code here; /* current decoding table entry */
code last; /* parent table entry */
unsigned len; /* length to copy for repeats, bits to drop */
int ret; /* return code */
static const unsigned short order[19] = /* permutation of code lengths */
{16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15};
/* Check that the strm exists and that the state was initialized */
if (strm == Z_NULL || strm->state == Z_NULL)
return Z_STREAM_ERROR;
state = (struct inflate_state FAR *)strm->state;
/* Reset the state */
strm->msg = Z_NULL;
state->mode = TYPE;
state->last = 0;
state->whave = 0;
next = strm->next_in;
have = next != Z_NULL ? strm->avail_in : 0;
hold = 0;
bits = 0;
put = state->window;
left = state->wsize;
/* Inflate until end of block marked as last */
for (;;)
switch (state->mode) {
case TYPE:
/* determine and dispatch block type */
if (state->last) {
BYTEBITS();
state->mode = DONE;
break;
}
NEEDBITS(3);
state->last = BITS(1);
DROPBITS(1);
switch (BITS(2)) {
case 0: /* stored block */
Tracev((stderr, "inflate: stored block%s\n",
state->last ? " (last)" : ""));
state->mode = STORED;
break;
case 1: /* fixed block */
fixedtables(state);
Tracev((stderr, "inflate: fixed codes block%s\n",
state->last ? " (last)" : ""));
state->mode = LEN; /* decode codes */
break;
case 2: /* dynamic block */
Tracev((stderr, "inflate: dynamic codes block%s\n",
state->last ? " (last)" : ""));
state->mode = TABLE;
break;
case 3:
strm->msg = (char *)"invalid block type";
state->mode = BAD;
}
DROPBITS(2);
break;
case STORED:
/* get and verify stored block length */
BYTEBITS(); /* go to byte boundary */
NEEDBITS(32);
if ((hold & 0xffff) != ((hold >> 16) ^ 0xffff)) {
strm->msg = (char *)"invalid stored block lengths";
state->mode = BAD;
break;
}
state->length = (unsigned)hold & 0xffff;
Tracev((stderr, "inflate: stored length %u\n",
state->length));
INITBITS();
/* copy stored block from input to output */
while (state->length != 0) {
copy = state->length;
PULL();
ROOM();
if (copy > have) copy = have;
if (copy > left) copy = left;
zmemcpy(put, next, copy);
have -= copy;
next += copy;
left -= copy;
put += copy;
state->length -= copy;
}
Tracev((stderr, "inflate: stored end\n"));
state->mode = TYPE;
break;
case TABLE:
/* get dynamic table entries descriptor */
NEEDBITS(14);
state->nlen = BITS(5) + 257;
DROPBITS(5);
state->ndist = BITS(5) + 1;
DROPBITS(5);
state->ncode = BITS(4) + 4;
DROPBITS(4);
#ifndef PKZIP_BUG_WORKAROUND
if (state->nlen > 286 || state->ndist > 30) {
strm->msg = (char *)"too many length or distance symbols";
state->mode = BAD;
break;
}
#endif
Tracev((stderr, "inflate: table sizes ok\n"));
/* get code length code lengths (not a typo) */
state->have = 0;
while (state->have < state->ncode) {
NEEDBITS(3);
state->lens[order[state->have++]] = (unsigned short)BITS(3);
DROPBITS(3);
}
while (state->have < 19)
state->lens[order[state->have++]] = 0;
state->next = state->codes;
state->lencode = (code const FAR *)(state->next);
state->lenbits = 7;
ret = inflate_table(CODES, state->lens, 19, &(state->next),
&(state->lenbits), state->work);
if (ret) {
strm->msg = (char *)"invalid code lengths set";
state->mode = BAD;
break;
}
Tracev((stderr, "inflate: code lengths ok\n"));
/* get length and distance code code lengths */
state->have = 0;
while (state->have < state->nlen + state->ndist) {
for (;;) {
here = state->lencode[BITS(state->lenbits)];
if ((unsigned)(here.bits) <= bits) break;
PULLBYTE();
}
if (here.val < 16) {
DROPBITS(here.bits);
state->lens[state->have++] = here.val;
}
else {
if (here.val == 16) {
NEEDBITS(here.bits + 2);
DROPBITS(here.bits);
if (state->have == 0) {
strm->msg = (char *)"invalid bit length repeat";
state->mode = BAD;
break;
}
len = (unsigned)(state->lens[state->have - 1]);
copy = 3 + BITS(2);
DROPBITS(2);
}
else if (here.val == 17) {
NEEDBITS(here.bits + 3);
DROPBITS(here.bits);
len = 0;
copy = 3 + BITS(3);
DROPBITS(3);
}
else {
NEEDBITS(here.bits + 7);
DROPBITS(here.bits);
len = 0;
copy = 11 + BITS(7);
DROPBITS(7);
}
if (state->have + copy > state->nlen + state->ndist) {
strm->msg = (char *)"invalid bit length repeat";
state->mode = BAD;
break;
}
while (copy--)
state->lens[state->have++] = (unsigned short)len;
}
}
/* handle error breaks in while */
if (state->mode == BAD) break;
/* check for end-of-block code (better have one) */
if (state->lens[256] == 0) {
strm->msg = (char *)"invalid code -- missing end-of-block";
state->mode = BAD;
break;
}
/* build code tables -- note: do not change the lenbits or distbits
values here (9 and 6) without reading the comments in inftrees.h
concerning the ENOUGH constants, which depend on those values */
state->next = state->codes;
state->lencode = (code const FAR *)(state->next);
state->lenbits = 9;
ret = inflate_table(LENS, state->lens, state->nlen, &(state->next),
&(state->lenbits), state->work);
if (ret) {
strm->msg = (char *)"invalid literal/lengths set";
state->mode = BAD;
break;
}
state->distcode = (code const FAR *)(state->next);
state->distbits = 6;
ret = inflate_table(DISTS, state->lens + state->nlen, state->ndist,
&(state->next), &(state->distbits), state->work);
if (ret) {
strm->msg = (char *)"invalid distances set";
state->mode = BAD;
break;
}
Tracev((stderr, "inflate: codes ok\n"));
state->mode = LEN;
case LEN:
/* use inflate_fast() if we have enough input and output */
if (have >= 6 && left >= 258) {
RESTORE();
if (state->whave < state->wsize)
state->whave = state->wsize - left;
inflate_fast(strm, state->wsize);
LOAD();
break;
}
/* get a literal, length, or end-of-block code */
for (;;) {
here = state->lencode[BITS(state->lenbits)];
if ((unsigned)(here.bits) <= bits) break;
PULLBYTE();
}
if (here.op && (here.op & 0xf0) == 0) {
last = here;
for (;;) {
here = state->lencode[last.val +
(BITS(last.bits + last.op) >> last.bits)];
if ((unsigned)(last.bits + here.bits) <= bits) break;
PULLBYTE();
}
DROPBITS(last.bits);
}
DROPBITS(here.bits);
state->length = (unsigned)here.val;
/* process literal */
if (here.op == 0) {
Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ?
"inflate: literal '%c'\n" :
"inflate: literal 0x%02x\n", here.val));
ROOM();
*put++ = (unsigned char)(state->length);
left--;
state->mode = LEN;
break;
}
/* process end of block */
if (here.op & 32) {
Tracevv((stderr, "inflate: end of block\n"));
state->mode = TYPE;
break;
}
/* invalid code */
if (here.op & 64) {
strm->msg = (char *)"invalid literal/length code";
state->mode = BAD;
break;
}
/* length code -- get extra bits, if any */
state->extra = (unsigned)(here.op) & 15;
if (state->extra != 0) {
NEEDBITS(state->extra);
state->length += BITS(state->extra);
DROPBITS(state->extra);
}
Tracevv((stderr, "inflate: length %u\n", state->length));
/* get distance code */
for (;;) {
here = state->distcode[BITS(state->distbits)];
if ((unsigned)(here.bits) <= bits) break;
PULLBYTE();
}
if ((here.op & 0xf0) == 0) {
last = here;
for (;;) {
here = state->distcode[last.val +
(BITS(last.bits + last.op) >> last.bits)];
if ((unsigned)(last.bits + here.bits) <= bits) break;
PULLBYTE();
}
DROPBITS(last.bits);
}
DROPBITS(here.bits);
if (here.op & 64) {
strm->msg = (char *)"invalid distance code";
state->mode = BAD;
break;
}
state->offset = (unsigned)here.val;
/* get distance extra bits, if any */
state->extra = (unsigned)(here.op) & 15;
if (state->extra != 0) {
NEEDBITS(state->extra);
state->offset += BITS(state->extra);
DROPBITS(state->extra);
}
if (state->offset > state->wsize - (state->whave < state->wsize ?
left : 0)) {
strm->msg = (char *)"invalid distance too far back";
state->mode = BAD;
break;
}
Tracevv((stderr, "inflate: distance %u\n", state->offset));
/* copy match from window to output */
do {
ROOM();
copy = state->wsize - state->offset;
if (copy < left) {
from = put + copy;
copy = left - copy;
}
else {
from = put - state->offset;
copy = left;
}
if (copy > state->length) copy = state->length;
state->length -= copy;
left -= copy;
do {
*put++ = *from++;
} while (--copy);
} while (state->length != 0);
break;
case DONE:
/* inflate stream terminated properly -- write leftover output */
ret = Z_STREAM_END;
if (left < state->wsize) {
if (out(out_desc, state->window, state->wsize - left))
ret = Z_BUF_ERROR;
}
goto inf_leave;
case BAD:
ret = Z_DATA_ERROR;
goto inf_leave;
default: /* can't happen, but makes compilers happy */
ret = Z_STREAM_ERROR;
goto inf_leave;
}
/* Return unused input */
inf_leave:
strm->next_in = next;
strm->avail_in = have;
return ret;
}
int ZEXPORT inflateBackEnd(strm)
z_streamp strm;
{
if (strm == Z_NULL || strm->state == Z_NULL || strm->zfree == (free_func)0)
return Z_STREAM_ERROR;
ZFREE(strm, strm->state);
strm->state = Z_NULL;
Tracev((stderr, "inflate: end\n"));
return Z_OK;
}

6
deps/zlib/inffast.c vendored
View File

@ -1,5 +1,5 @@
/* inffast.c -- fast decoding
* Copyright (C) 1995-2008, 2010 Mark Adler
* Copyright (C) 1995-2008, 2010, 2013 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h
*/
@ -69,8 +69,8 @@ z_streamp strm;
unsigned start; /* inflate()'s starting value for strm->avail_out */
{
struct inflate_state FAR *state;
unsigned char FAR *in; /* local strm->next_in */
unsigned char FAR *last; /* while in < last, enough input available */
z_const unsigned char FAR *in; /* local strm->next_in */
z_const unsigned char FAR *last; /* have enough input while in < last */
unsigned char FAR *out; /* local strm->next_out */
unsigned char FAR *beg; /* inflate()'s initial strm->next_out */
unsigned char FAR *end; /* while out < end, enough space available */

View File

@ -2,9 +2,9 @@
* Generated automatically by makefixed().
*/
/* WARNING: this file should *not* be used by applications. It
is part of the implementation of the compression library and
is subject to change. Applications should only use zlib.h.
/* WARNING: this file should *not* be used by applications.
It is part of the implementation of this library and is
subject to change. Applications should only use zlib.h.
*/
static const code lenfix[512] = {

136
deps/zlib/inflate.c vendored
View File

@ -1,5 +1,5 @@
/* inflate.c -- zlib decompression
* Copyright (C) 1995-2010 Mark Adler
* Copyright (C) 1995-2012 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h
*/
@ -93,14 +93,15 @@
/* function prototypes */
local void fixedtables OF((struct inflate_state FAR *state));
local int updatewindow OF((z_streamp strm, unsigned out));
local int updatewindow OF((z_streamp strm, const unsigned char FAR *end,
unsigned copy));
#ifdef BUILDFIXED
void makefixed OF((void));
#endif
local unsigned syncsearch OF((unsigned FAR *have, unsigned char FAR *buf,
local unsigned syncsearch OF((unsigned FAR *have, const unsigned char FAR *buf,
unsigned len));
int ZEXPORT inflateReset(strm)
int ZEXPORT inflateResetKeep(strm)
z_streamp strm;
{
struct inflate_state FAR *state;
@ -109,15 +110,13 @@ z_streamp strm;
state = (struct inflate_state FAR *)strm->state;
strm->total_in = strm->total_out = state->total = 0;
strm->msg = Z_NULL;
strm->adler = 1; /* to support ill-conceived Java test suite */
if (state->wrap) /* to support ill-conceived Java test suite */
strm->adler = state->wrap & 1;
state->mode = HEAD;
state->last = 0;
state->havedict = 0;
state->dmax = 32768U;
state->head = Z_NULL;
state->wsize = 0;
state->whave = 0;
state->wnext = 0;
state->hold = 0;
state->bits = 0;
state->lencode = state->distcode = state->next = state->codes;
@ -127,6 +126,19 @@ z_streamp strm;
return Z_OK;
}
int ZEXPORT inflateReset(strm)
z_streamp strm;
{
struct inflate_state FAR *state;
if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
state = (struct inflate_state FAR *)strm->state;
state->wsize = 0;
state->whave = 0;
state->wnext = 0;
return inflateResetKeep(strm);
}
int ZEXPORT inflateReset2(strm, windowBits)
z_streamp strm;
int windowBits;
@ -180,10 +192,19 @@ int stream_size;
if (strm == Z_NULL) return Z_STREAM_ERROR;
strm->msg = Z_NULL; /* in case we return an error */
if (strm->zalloc == (alloc_func)0) {
#ifdef Z_SOLO
return Z_STREAM_ERROR;
#else
strm->zalloc = zcalloc;
strm->opaque = (voidpf)0;
#endif
}
if (strm->zfree == (free_func)0) strm->zfree = zcfree;
if (strm->zfree == (free_func)0)
#ifdef Z_SOLO
return Z_STREAM_ERROR;
#else
strm->zfree = zcfree;
#endif
state = (struct inflate_state FAR *)
ZALLOC(strm, 1, sizeof(struct inflate_state));
if (state == Z_NULL) return Z_MEM_ERROR;
@ -321,8 +342,8 @@ void makefixed()
low = 0;
for (;;) {
if ((low % 7) == 0) printf("\n ");
printf("{%u,%u,%d}", state.lencode[low].op, state.lencode[low].bits,
state.lencode[low].val);
printf("{%u,%u,%d}", (low & 127) == 99 ? 64 : state.lencode[low].op,
state.lencode[low].bits, state.lencode[low].val);
if (++low == size) break;
putchar(',');
}
@ -355,12 +376,13 @@ void makefixed()
output will fall in the output data, making match copies simpler and faster.
The advantage may be dependent on the size of the processor's data caches.
*/
local int updatewindow(strm, out)
local int updatewindow(strm, end, copy)
z_streamp strm;
unsigned out;
const Bytef *end;
unsigned copy;
{
struct inflate_state FAR *state;
unsigned copy, dist;
unsigned dist;
state = (struct inflate_state FAR *)strm->state;
@ -380,19 +402,18 @@ unsigned out;
}
/* copy state->wsize or less output bytes into the circular window */
copy = out - strm->avail_out;
if (copy >= state->wsize) {
zmemcpy(state->window, strm->next_out - state->wsize, state->wsize);
zmemcpy(state->window, end - state->wsize, state->wsize);
state->wnext = 0;
state->whave = state->wsize;
}
else {
dist = state->wsize - state->wnext;
if (dist > copy) dist = copy;
zmemcpy(state->window + state->wnext, strm->next_out - copy, dist);
zmemcpy(state->window + state->wnext, end - copy, dist);
copy -= dist;
if (copy) {
zmemcpy(state->window, strm->next_out - copy, copy);
zmemcpy(state->window, end - copy, copy);
state->wnext = copy;
state->whave = state->wsize;
}
@ -499,11 +520,6 @@ unsigned out;
bits -= bits & 7; \
} while (0)
/* Reverse the bytes in a 32-bit value */
#define REVERSE(q) \
((((q) >> 24) & 0xff) + (((q) >> 8) & 0xff00) + \
(((q) & 0xff00) << 8) + (((q) & 0xff) << 24))
/*
inflate() uses a state machine to process as much input data and generate as
much output data as possible before returning. The state machine is
@ -591,7 +607,7 @@ z_streamp strm;
int flush;
{
struct inflate_state FAR *state;
unsigned char FAR *next; /* next input */
z_const unsigned char FAR *next; /* next input */
unsigned char FAR *put; /* next output */
unsigned have, left; /* available input and output */
unsigned long hold; /* bit buffer */
@ -797,7 +813,7 @@ int flush;
#endif
case DICTID:
NEEDBITS(32);
strm->adler = state->check = REVERSE(hold);
strm->adler = state->check = ZSWAP32(hold);
INITBITS();
state->mode = DICT;
case DICT:
@ -905,7 +921,7 @@ int flush;
while (state->have < 19)
state->lens[order[state->have++]] = 0;
state->next = state->codes;
state->lencode = (code const FAR *)(state->next);
state->lencode = (const code FAR *)(state->next);
state->lenbits = 7;
ret = inflate_table(CODES, state->lens, 19, &(state->next),
&(state->lenbits), state->work);
@ -925,7 +941,6 @@ int flush;
PULLBYTE();
}
if (here.val < 16) {
NEEDBITS(here.bits);
DROPBITS(here.bits);
state->lens[state->have++] = here.val;
}
@ -980,7 +995,7 @@ int flush;
values here (9 and 6) without reading the comments in inftrees.h
concerning the ENOUGH constants, which depend on those values */
state->next = state->codes;
state->lencode = (code const FAR *)(state->next);
state->lencode = (const code FAR *)(state->next);
state->lenbits = 9;
ret = inflate_table(LENS, state->lens, state->nlen, &(state->next),
&(state->lenbits), state->work);
@ -989,7 +1004,7 @@ int flush;
state->mode = BAD;
break;
}
state->distcode = (code const FAR *)(state->next);
state->distcode = (const code FAR *)(state->next);
state->distbits = 6;
ret = inflate_table(DISTS, state->lens + state->nlen, state->ndist,
&(state->next), &(state->distbits), state->work);
@ -1170,7 +1185,7 @@ int flush;
#ifdef GUNZIP
state->flags ? hold :
#endif
REVERSE(hold)) != state->check) {
ZSWAP32(hold)) != state->check) {
strm->msg = (char *)"incorrect data check";
state->mode = BAD;
break;
@ -1214,8 +1229,9 @@ int flush;
*/
inf_leave:
RESTORE();
if (state->wsize || (state->mode < CHECK && out != strm->avail_out))
if (updatewindow(strm, out)) {
if (state->wsize || (out != strm->avail_out && state->mode < BAD &&
(state->mode < CHECK || flush != Z_FINISH)))
if (updatewindow(strm, strm->next_out, out - strm->avail_out)) {
state->mode = MEM;
return Z_MEM_ERROR;
}
@ -1249,13 +1265,37 @@ z_streamp strm;
return Z_OK;
}
int ZEXPORT inflateGetDictionary(strm, dictionary, dictLength)
z_streamp strm;
Bytef *dictionary;
uInt *dictLength;
{
struct inflate_state FAR *state;
/* check state */
if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
state = (struct inflate_state FAR *)strm->state;
/* copy dictionary */
if (state->whave && dictionary != Z_NULL) {
zmemcpy(dictionary, state->window + state->wnext,
state->whave - state->wnext);
zmemcpy(dictionary + state->whave - state->wnext,
state->window, state->wnext);
}
if (dictLength != Z_NULL)
*dictLength = state->whave;
return Z_OK;
}
int ZEXPORT inflateSetDictionary(strm, dictionary, dictLength)
z_streamp strm;
const Bytef *dictionary;
uInt dictLength;
{
struct inflate_state FAR *state;
unsigned long id;
unsigned long dictid;
int ret;
/* check state */
if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
@ -1263,29 +1303,21 @@ uInt dictLength;
if (state->wrap != 0 && state->mode != DICT)
return Z_STREAM_ERROR;
/* check for correct dictionary id */
/* check for correct dictionary identifier */
if (state->mode == DICT) {
id = adler32(0L, Z_NULL, 0);
id = adler32(id, dictionary, dictLength);
if (id != state->check)
dictid = adler32(0L, Z_NULL, 0);
dictid = adler32(dictid, dictionary, dictLength);
if (dictid != state->check)
return Z_DATA_ERROR;
}
/* copy dictionary to window */
if (updatewindow(strm, strm->avail_out)) {
/* copy dictionary to window using updatewindow(), which will amend the
existing dictionary if appropriate */
ret = updatewindow(strm, dictionary + dictLength, dictLength);
if (ret) {
state->mode = MEM;
return Z_MEM_ERROR;
}
if (dictLength > state->wsize) {
zmemcpy(state->window, dictionary + dictLength - state->wsize,
state->wsize);
state->whave = state->wsize;
}
else {
zmemcpy(state->window + state->wsize - dictLength, dictionary,
dictLength);
state->whave = dictLength;
}
state->havedict = 1;
Tracev((stderr, "inflate: dictionary set\n"));
return Z_OK;
@ -1321,7 +1353,7 @@ gz_headerp head;
*/
local unsigned syncsearch(have, buf, len)
unsigned FAR *have;
unsigned char FAR *buf;
const unsigned char FAR *buf;
unsigned len;
{
unsigned got;
@ -1433,8 +1465,8 @@ z_streamp source;
}
/* copy state */
zmemcpy(dest, source, sizeof(z_stream));
zmemcpy(copy, state, sizeof(struct inflate_state));
zmemcpy((voidpf)dest, (voidpf)source, sizeof(z_stream));
zmemcpy((voidpf)copy, (voidpf)state, sizeof(struct inflate_state));
if (state->lencode >= state->codes &&
state->lencode <= state->codes + ENOUGH - 1) {
copy->lencode = copy->codes + (state->lencode - state->codes);

54
deps/zlib/inftrees.c vendored
View File

@ -1,5 +1,5 @@
/* inftrees.c -- generate Huffman trees for efficient decoding
* Copyright (C) 1995-2010 Mark Adler
* Copyright (C) 1995-2013 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h
*/
@ -9,7 +9,7 @@
#define MAXBITS 15
const char inflate_copyright[] =
" inflate 1.2.5 Copyright 1995-2010 Mark Adler ";
" inflate 1.2.8 Copyright 1995-2013 Mark Adler ";
/*
If you use the zlib library in a product, an acknowledgment is welcome
in the documentation of your product. If for some reason you cannot
@ -62,7 +62,7 @@ unsigned short FAR *work;
35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0};
static const unsigned short lext[31] = { /* Length codes 257..285 extra */
16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18,
19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 73, 195};
19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 72, 78};
static const unsigned short dbase[32] = { /* Distance codes 0..29 base */
1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
@ -208,8 +208,8 @@ unsigned short FAR *work;
mask = used - 1; /* mask for comparing low */
/* check available table space */
if ((type == LENS && used >= ENOUGH_LENS) ||
(type == DISTS && used >= ENOUGH_DISTS))
if ((type == LENS && used > ENOUGH_LENS) ||
(type == DISTS && used > ENOUGH_DISTS))
return 1;
/* process all codes and make table entries */
@ -277,8 +277,8 @@ unsigned short FAR *work;
/* check for enough space */
used += 1U << curr;
if ((type == LENS && used >= ENOUGH_LENS) ||
(type == DISTS && used >= ENOUGH_DISTS))
if ((type == LENS && used > ENOUGH_LENS) ||
(type == DISTS && used > ENOUGH_DISTS))
return 1;
/* point entry in root table to sub-table */
@ -289,38 +289,14 @@ unsigned short FAR *work;
}
}
/*
Fill in rest of table for incomplete codes. This loop is similar to the
loop above in incrementing huff for table indices. It is assumed that
len is equal to curr + drop, so there is no loop needed to increment
through high index bits. When the current sub-table is filled, the loop
drops back to the root table to fill in any remaining entries there.
*/
here.op = (unsigned char)64; /* invalid code marker */
here.bits = (unsigned char)(len - drop);
here.val = (unsigned short)0;
while (huff != 0) {
/* when done with sub-table, drop back to root table */
if (drop != 0 && (huff & mask) != low) {
drop = 0;
len = root;
next = *table;
here.bits = (unsigned char)len;
}
/* put invalid code marker in table */
next[huff >> drop] = here;
/* backwards increment the len-bit code huff */
incr = 1U << (len - 1);
while (huff & incr)
incr >>= 1;
if (incr != 0) {
huff &= incr - 1;
huff += incr;
}
else
huff = 0;
/* fill in remaining table entry if code is incomplete (guaranteed to have
at most one remaining entry, since if the code is incomplete, the
maximum code length that was allowed to get this far is one bit) */
if (huff != 0) {
here.op = (unsigned char)64; /* invalid code marker */
here.bits = (unsigned char)(len - drop);
here.val = (unsigned short)0;
next[huff] = here;
}
/* set return parameters */

54
deps/zlib/trees.c vendored
View File

@ -1,5 +1,5 @@
/* trees.c -- output deflated data using Huffman coding
* Copyright (C) 1995-2010 Jean-loup Gailly
* Copyright (C) 1995-2012 Jean-loup Gailly
* detect_data_type() function provided freely by Cosmin Truta, 2006
* For conditions of distribution and use, see copyright notice in zlib.h
*/
@ -74,11 +74,6 @@ local const uch bl_order[BL_CODES]
* probability, to avoid transmitting the lengths for unused bit length codes.
*/
#define Buf_size (8 * 2*sizeof(char))
/* Number of bits used within bi_buf. (bi_buf might be implemented on
* more than 16 bits on some systems.)
*/
/* ===========================================================================
* Local data. These are initialized only once.
*/
@ -151,8 +146,8 @@ local void send_tree OF((deflate_state *s, ct_data *tree, int max_code));
local int build_bl_tree OF((deflate_state *s));
local void send_all_trees OF((deflate_state *s, int lcodes, int dcodes,
int blcodes));
local void compress_block OF((deflate_state *s, ct_data *ltree,
ct_data *dtree));
local void compress_block OF((deflate_state *s, const ct_data *ltree,
const ct_data *dtree));
local int detect_data_type OF((deflate_state *s));
local unsigned bi_reverse OF((unsigned value, int length));
local void bi_windup OF((deflate_state *s));
@ -399,7 +394,6 @@ void ZLIB_INTERNAL _tr_init(s)
s->bi_buf = 0;
s->bi_valid = 0;
s->last_eob_len = 8; /* enough lookahead for inflate */
#ifdef DEBUG
s->compressed_len = 0L;
s->bits_sent = 0L;
@ -882,16 +876,18 @@ void ZLIB_INTERNAL _tr_stored_block(s, buf, stored_len, last)
copy_block(s, buf, (unsigned)stored_len, 1); /* with header */
}
/* ===========================================================================
* Flush the bits in the bit buffer to pending output (leaves at most 7 bits)
*/
void ZLIB_INTERNAL _tr_flush_bits(s)
deflate_state *s;
{
bi_flush(s);
}
/* ===========================================================================
* Send one empty static block to give enough lookahead for inflate.
* This takes 10 bits, of which 7 may remain in the bit buffer.
* The current inflate code requires 9 bits of lookahead. If the
* last two codes for the previous block (real code plus EOB) were coded
* on 5 bits or less, inflate may have only 5+3 bits of lookahead to decode
* the last real code. In this case we send two empty static blocks instead
* of one. (There are no problems if the previous block is stored or fixed.)
* To simplify the code, we assume the worst case of last real code encoded
* on one bit only.
*/
void ZLIB_INTERNAL _tr_align(s)
deflate_state *s;
@ -902,20 +898,6 @@ void ZLIB_INTERNAL _tr_align(s)
s->compressed_len += 10L; /* 3 for block type, 7 for EOB */
#endif
bi_flush(s);
/* Of the 10 bits for the empty block, we have already sent
* (10 - bi_valid) bits. The lookahead for the last real code (before
* the EOB of the previous block) was thus at least one plus the length
* of the EOB plus what we have just sent of the empty static block.
*/
if (1 + s->last_eob_len + 10 - s->bi_valid < 9) {
send_bits(s, STATIC_TREES<<1, 3);
send_code(s, END_BLOCK, static_ltree);
#ifdef DEBUG
s->compressed_len += 10L;
#endif
bi_flush(s);
}
s->last_eob_len = 7;
}
/* ===========================================================================
@ -990,7 +972,8 @@ void ZLIB_INTERNAL _tr_flush_block(s, buf, stored_len, last)
} else if (s->strategy == Z_FIXED || static_lenb == opt_lenb) {
#endif
send_bits(s, (STATIC_TREES<<1)+last, 3);
compress_block(s, (ct_data *)static_ltree, (ct_data *)static_dtree);
compress_block(s, (const ct_data *)static_ltree,
(const ct_data *)static_dtree);
#ifdef DEBUG
s->compressed_len += 3 + s->static_len;
#endif
@ -998,7 +981,8 @@ void ZLIB_INTERNAL _tr_flush_block(s, buf, stored_len, last)
send_bits(s, (DYN_TREES<<1)+last, 3);
send_all_trees(s, s->l_desc.max_code+1, s->d_desc.max_code+1,
max_blindex+1);
compress_block(s, (ct_data *)s->dyn_ltree, (ct_data *)s->dyn_dtree);
compress_block(s, (const ct_data *)s->dyn_ltree,
(const ct_data *)s->dyn_dtree);
#ifdef DEBUG
s->compressed_len += 3 + s->opt_len;
#endif
@ -1075,8 +1059,8 @@ int ZLIB_INTERNAL _tr_tally (s, dist, lc)
*/
local void compress_block(s, ltree, dtree)
deflate_state *s;
ct_data *ltree; /* literal tree */
ct_data *dtree; /* distance tree */
const ct_data *ltree; /* literal tree */
const ct_data *dtree; /* distance tree */
{
unsigned dist; /* distance of matched string */
int lc; /* match length or unmatched char (if dist == 0) */
@ -1118,7 +1102,6 @@ local void compress_block(s, ltree, dtree)
} while (lx < s->last_lit);
send_code(s, END_BLOCK, ltree);
s->last_eob_len = ltree[END_BLOCK].Len;
}
/* ===========================================================================
@ -1226,7 +1209,6 @@ local void copy_block(s, buf, len, header)
int header; /* true if block header must be written */
{
bi_windup(s); /* align on byte boundary */
s->last_eob_len = 8; /* enough lookahead for inflate */
if (header) {
put_short(s, (ush)len);

4
deps/zlib/zconf.h vendored
View File

@ -14,6 +14,7 @@
* forms, we didn't write zlib */
#if defined(_MSC_VER)
# pragma warning( disable : 4131 )
# pragma warning( disable : 4142 ) /* benign redefinition of type */
#endif
/* Maximum value for memLevel in deflateInit2 */
@ -33,10 +34,12 @@
# define FAR
#endif
#define OF(args) args
#define Z_ARG(args) args
typedef unsigned char Byte; /* 8 bits */
typedef unsigned int uInt; /* 16 bits or more */
typedef unsigned long uLong; /* 32 bits or more */
typedef unsigned long z_crc_t;
typedef Byte FAR Bytef;
typedef char FAR charf;
@ -50,5 +53,6 @@ typedef void *voidp;
#define z_off_t git_off_t
#define z_off64_t z_off_t
#define z_const const
#endif /* ZCONF_H */

343
deps/zlib/zlib.h vendored
View File

@ -1,7 +1,7 @@
/* zlib.h -- interface of the 'zlib' general purpose compression library
version 1.2.5, April 19th, 2010
version 1.2.8, April 28th, 2013
Copyright (C) 1995-2010 Jean-loup Gailly and Mark Adler
Copyright (C) 1995-2013 Jean-loup Gailly and Mark Adler
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -24,8 +24,8 @@
The data format used by the zlib library is described by RFCs (Request for
Comments) 1950 to 1952 in the files http://www.ietf.org/rfc/rfc1950.txt
(zlib format), rfc1951.txt (deflate format) and rfc1952.txt (gzip format).
Comments) 1950 to 1952 in the files http://tools.ietf.org/html/rfc1950
(zlib format), rfc1951 (deflate format) and rfc1952 (gzip format).
*/
#ifndef ZLIB_H
@ -37,11 +37,11 @@
extern "C" {
#endif
#define ZLIB_VERSION "1.2.5"
#define ZLIB_VERNUM 0x1250
#define ZLIB_VERSION "1.2.8"
#define ZLIB_VERNUM 0x1280
#define ZLIB_VER_MAJOR 1
#define ZLIB_VER_MINOR 2
#define ZLIB_VER_REVISION 5
#define ZLIB_VER_REVISION 8
#define ZLIB_VER_SUBREVISION 0
/*
@ -83,15 +83,15 @@ typedef void (*free_func) OF((voidpf opaque, voidpf address));
struct internal_state;
typedef struct z_stream_s {
Bytef *next_in; /* next input byte */
z_const Bytef *next_in; /* next input byte */
uInt avail_in; /* number of bytes available at next_in */
uLong total_in; /* total nb of input bytes read so far */
uLong total_in; /* total number of input bytes read so far */
Bytef *next_out; /* next output byte should be put there */
uInt avail_out; /* remaining free space at next_out */
uLong total_out; /* total nb of bytes output so far */
uLong total_out; /* total number of bytes output so far */
char *msg; /* last error message, NULL if no error */
z_const char *msg; /* last error message, NULL if no error */
struct internal_state FAR *state; /* not visible by applications */
alloc_func zalloc; /* used to allocate the internal state */
@ -327,8 +327,9 @@ ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush));
Z_FINISH can be used immediately after deflateInit if all the compression
is to be done in a single step. In this case, avail_out must be at least the
value returned by deflateBound (see below). If deflate does not return
Z_STREAM_END, then it must be called again as described above.
value returned by deflateBound (see below). Then deflate is guaranteed to
return Z_STREAM_END. If not enough output space is provided, deflate will
not return Z_STREAM_END, and it must be called again as described above.
deflate() sets strm->adler to the adler32 checksum of all input read
so far (that is, total_in bytes).
@ -451,23 +452,29 @@ ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush));
error. However if all decompression is to be performed in a single step (a
single call of inflate), the parameter flush should be set to Z_FINISH. In
this case all pending input is processed and all pending output is flushed;
avail_out must be large enough to hold all the uncompressed data. (The size
of the uncompressed data may have been saved by the compressor for this
purpose.) The next operation on this stream must be inflateEnd to deallocate
the decompression state. The use of Z_FINISH is never required, but can be
used to inform inflate that a faster approach may be used for the single
inflate() call.
avail_out must be large enough to hold all of the uncompressed data for the
operation to complete. (The size of the uncompressed data may have been
saved by the compressor for this purpose.) The use of Z_FINISH is not
required to perform an inflation in one step. However it may be used to
inform inflate that a faster approach can be used for the single inflate()
call. Z_FINISH also informs inflate to not maintain a sliding window if the
stream completes, which reduces inflate's memory footprint. If the stream
does not complete, either because not all of the stream is provided or not
enough output space is provided, then a sliding window will be allocated and
inflate() can be called again to continue the operation as if Z_NO_FLUSH had
been used.
In this implementation, inflate() always flushes as much output as
possible to the output buffer, and always uses the faster approach on the
first call. So the only effect of the flush parameter in this implementation
is on the return value of inflate(), as noted below, or when it returns early
because Z_BLOCK or Z_TREES is used.
first call. So the effects of the flush parameter in this implementation are
on the return value of inflate() as noted below, when inflate() returns early
when Z_BLOCK or Z_TREES is used, and when inflate() avoids the allocation of
memory for a sliding window when Z_FINISH is used.
If a preset dictionary is needed after this call (see inflateSetDictionary
below), inflate sets strm->adler to the adler32 checksum of the dictionary
below), inflate sets strm->adler to the Adler-32 checksum of the dictionary
chosen by the compressor and returns Z_NEED_DICT; otherwise it sets
strm->adler to the adler32 checksum of all output produced so far (that is,
strm->adler to the Adler-32 checksum of all output produced so far (that is,
total_out bytes) and returns Z_OK, Z_STREAM_END or an error code as described
below. At the end of the stream, inflate() checks that its computed adler32
checksum is equal to that saved by the compressor and returns Z_STREAM_END
@ -478,7 +485,9 @@ ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush));
initializing with inflateInit2(). Any information contained in the gzip
header is not retained, so applications that need that information should
instead use raw inflate, see inflateInit2() below, or inflateBack() and
perform their own processing of the gzip header and trailer.
perform their own processing of the gzip header and trailer. When processing
gzip-wrapped deflate data, strm->adler32 is set to the CRC-32 of the output
producted so far. The CRC-32 is checked against the gzip trailer.
inflate() returns Z_OK if some progress has been made (more input processed
or more output produced), Z_STREAM_END if the end of the compressed data has
@ -580,10 +589,15 @@ ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm,
uInt dictLength));
/*
Initializes the compression dictionary from the given byte sequence
without producing any compressed output. This function must be called
immediately after deflateInit, deflateInit2 or deflateReset, before any call
of deflate. The compressor and decompressor must use exactly the same
dictionary (see inflateSetDictionary).
without producing any compressed output. When using the zlib format, this
function must be called immediately after deflateInit, deflateInit2 or
deflateReset, and before any call of deflate. When doing raw deflate, this
function must be called either before any call of deflate, or immediately
after the completion of a deflate block, i.e. after all input has been
consumed and all output has been delivered when using any of the flush
options Z_BLOCK, Z_PARTIAL_FLUSH, Z_SYNC_FLUSH, or Z_FULL_FLUSH. The
compressor and decompressor must use exactly the same dictionary (see
inflateSetDictionary).
The dictionary should consist of strings (byte sequences) that are likely
to be encountered later in the data to be compressed, with the most commonly
@ -610,8 +624,8 @@ ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm,
deflateSetDictionary returns Z_OK if success, or Z_STREAM_ERROR if a
parameter is invalid (e.g. dictionary being Z_NULL) or the stream state is
inconsistent (for example if deflate has already been called for this stream
or if the compression method is bsort). deflateSetDictionary does not
perform any compression: this will be done by deflate().
or if not at a block boundary for raw deflate). deflateSetDictionary does
not perform any compression: this will be done by deflate().
*/
ZEXTERN int ZEXPORT deflateCopy OF((z_streamp dest,
@ -688,9 +702,29 @@ ZEXTERN uLong ZEXPORT deflateBound OF((z_streamp strm,
deflation of sourceLen bytes. It must be called after deflateInit() or
deflateInit2(), and after deflateSetHeader(), if used. This would be used
to allocate an output buffer for deflation in a single pass, and so would be
called before deflate().
called before deflate(). If that first deflate() call is provided the
sourceLen input bytes, an output buffer allocated to the size returned by
deflateBound(), and the flush value Z_FINISH, then deflate() is guaranteed
to return Z_STREAM_END. Note that it is possible for the compressed size to
be larger than the value returned by deflateBound() if flush options other
than Z_FINISH or Z_NO_FLUSH are used.
*/
ZEXTERN int ZEXPORT deflatePending OF((z_streamp strm,
unsigned *pending,
int *bits));
/*
deflatePending() returns the number of bytes and bits of output that have
been generated, but not yet provided in the available output. The bytes not
provided would be due to the available output space having being consumed.
The number of bits of output not provided are between 0 and 7, where they
await more bits to join them in order to fill out a full byte. If pending
or bits are Z_NULL, then those values are not set.
deflatePending returns Z_OK if success, or Z_STREAM_ERROR if the source
stream state was inconsistent.
*/
ZEXTERN int ZEXPORT deflatePrime OF((z_streamp strm,
int bits,
int value));
@ -703,8 +737,9 @@ ZEXTERN int ZEXPORT deflatePrime OF((z_streamp strm,
than or equal to 16, and that many of the least significant bits of value
will be inserted in the output.
deflatePrime returns Z_OK if success, or Z_STREAM_ERROR if the source
stream state was inconsistent.
deflatePrime returns Z_OK if success, Z_BUF_ERROR if there was not enough
room in the internal buffer to insert the bits, or Z_STREAM_ERROR if the
source stream state was inconsistent.
*/
ZEXTERN int ZEXPORT deflateSetHeader OF((z_streamp strm,
@ -790,10 +825,11 @@ ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm,
if that call returned Z_NEED_DICT. The dictionary chosen by the compressor
can be determined from the adler32 value returned by that call of inflate.
The compressor and decompressor must use exactly the same dictionary (see
deflateSetDictionary). For raw inflate, this function can be called
immediately after inflateInit2() or inflateReset() and before any call of
inflate() to set the dictionary. The application must insure that the
dictionary that was used for compression is provided.
deflateSetDictionary). For raw inflate, this function can be called at any
time to set the dictionary. If the provided dictionary is smaller than the
window and there is already data in the window, then the provided dictionary
will amend what's there. The application must insure that the dictionary
that was used for compression is provided.
inflateSetDictionary returns Z_OK if success, Z_STREAM_ERROR if a
parameter is invalid (e.g. dictionary being Z_NULL) or the stream state is
@ -803,19 +839,38 @@ ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm,
inflate().
*/
ZEXTERN int ZEXPORT inflateGetDictionary OF((z_streamp strm,
Bytef *dictionary,
uInt *dictLength));
/*
Returns the sliding dictionary being maintained by inflate. dictLength is
set to the number of bytes in the dictionary, and that many bytes are copied
to dictionary. dictionary must have enough space, where 32768 bytes is
always enough. If inflateGetDictionary() is called with dictionary equal to
Z_NULL, then only the dictionary length is returned, and nothing is copied.
Similary, if dictLength is Z_NULL, then it is not set.
inflateGetDictionary returns Z_OK on success, or Z_STREAM_ERROR if the
stream state is inconsistent.
*/
ZEXTERN int ZEXPORT inflateSync OF((z_streamp strm));
/*
Skips invalid compressed data until a full flush point (see above the
description of deflate with Z_FULL_FLUSH) can be found, or until all
Skips invalid compressed data until a possible full flush point (see above
for the description of deflate with Z_FULL_FLUSH) can be found, or until all
available input is skipped. No output is provided.
inflateSync returns Z_OK if a full flush point has been found, Z_BUF_ERROR
if no more input was provided, Z_DATA_ERROR if no flush point has been
found, or Z_STREAM_ERROR if the stream structure was inconsistent. In the
success case, the application may save the current current value of total_in
which indicates where valid compressed data was found. In the error case,
the application may repeatedly call inflateSync, providing more input each
time, until success or end of the input data.
inflateSync searches for a 00 00 FF FF pattern in the compressed data.
All full flush points have this pattern, but not all occurrences of this
pattern are full flush points.
inflateSync returns Z_OK if a possible full flush point has been found,
Z_BUF_ERROR if no more input was provided, Z_DATA_ERROR if no flush point
has been found, or Z_STREAM_ERROR if the stream structure was inconsistent.
In the success case, the application may save the current current value of
total_in which indicates where valid compressed data was found. In the
error case, the application may repeatedly call inflateSync, providing more
input each time, until success or end of the input data.
*/
ZEXTERN int ZEXPORT inflateCopy OF((z_streamp dest,
@ -962,12 +1017,13 @@ ZEXTERN int ZEXPORT inflateBackInit OF((z_streamp strm, int windowBits,
See inflateBack() for the usage of these routines.
inflateBackInit will return Z_OK on success, Z_STREAM_ERROR if any of
the paramaters are invalid, Z_MEM_ERROR if the internal state could not be
the parameters are invalid, Z_MEM_ERROR if the internal state could not be
allocated, or Z_VERSION_ERROR if the version of the library does not match
the version of the header file.
*/
typedef unsigned (*in_func) OF((void FAR *, unsigned char FAR * FAR *));
typedef unsigned (*in_func) OF((void FAR *,
z_const unsigned char FAR * FAR *));
typedef int (*out_func) OF((void FAR *, unsigned char FAR *, unsigned));
ZEXTERN int ZEXPORT inflateBack OF((z_streamp strm,
@ -975,11 +1031,12 @@ ZEXTERN int ZEXPORT inflateBack OF((z_streamp strm,
out_func out, void FAR *out_desc));
/*
inflateBack() does a raw inflate with a single call using a call-back
interface for input and output. This is more efficient than inflate() for
file i/o applications in that it avoids copying between the output and the
sliding window by simply making the window itself the output buffer. This
function trusts the application to not change the output buffer passed by
the output function, at least until inflateBack() returns.
interface for input and output. This is potentially more efficient than
inflate() for file i/o applications, in that it avoids copying between the
output and the sliding window by simply making the window itself the output
buffer. inflate() can be faster on modern CPUs when used with large
buffers. inflateBack() trusts the application to not change the output
buffer passed by the output function, at least until inflateBack() returns.
inflateBackInit() must be called first to allocate the internal state
and to initialize the state with the user-provided window buffer.
@ -1088,6 +1145,7 @@ ZEXTERN uLong ZEXPORT zlibCompileFlags OF((void));
27-31: 0 (reserved)
*/
#ifndef Z_SOLO
/* utility functions */
@ -1149,10 +1207,11 @@ ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen,
uncompress returns Z_OK if success, Z_MEM_ERROR if there was not
enough memory, Z_BUF_ERROR if there was not enough room in the output
buffer, or Z_DATA_ERROR if the input data was corrupted or incomplete.
buffer, or Z_DATA_ERROR if the input data was corrupted or incomplete. In
the case where there is not enough room, uncompress() will fill the output
buffer with the uncompressed data up to that point.
*/
/* gzip file access functions */
/*
@ -1162,7 +1221,7 @@ ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen,
wrapper, documented in RFC 1952, wrapped around a deflate stream.
*/
typedef voidp gzFile; /* opaque gzip file descriptor */
typedef struct gzFile_s *gzFile; /* semi-opaque gzip file descriptor */
/*
ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode));
@ -1172,13 +1231,28 @@ ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode));
a strategy: 'f' for filtered data as in "wb6f", 'h' for Huffman-only
compression as in "wb1h", 'R' for run-length encoding as in "wb1R", or 'F'
for fixed code compression as in "wb9F". (See the description of
deflateInit2 for more information about the strategy parameter.) Also "a"
can be used instead of "w" to request that the gzip stream that will be
written be appended to the file. "+" will result in an error, since reading
and writing to the same gzip file is not supported.
deflateInit2 for more information about the strategy parameter.) 'T' will
request transparent writing or appending with no compression and not using
the gzip format.
"a" can be used instead of "w" to request that the gzip stream that will
be written be appended to the file. "+" will result in an error, since
reading and writing to the same gzip file is not supported. The addition of
"x" when writing will create the file exclusively, which fails if the file
already exists. On systems that support it, the addition of "e" when
reading or writing will set the flag to close the file on an execve() call.
These functions, as well as gzip, will read and decode a sequence of gzip
streams in a file. The append function of gzopen() can be used to create
such a file. (Also see gzflush() for another way to do this.) When
appending, gzopen does not test whether the file begins with a gzip stream,
nor does it look for the end of the gzip streams to begin appending. gzopen
will simply append a gzip stream to the existing file.
gzopen can be used to read a file which is not in gzip format; in this
case gzread will directly read from the file without decompression.
case gzread will directly read from the file without decompression. When
reading, this will be detected automatically by looking for the magic two-
byte gzip header.
gzopen returns NULL if the file could not be opened, if there was
insufficient memory to allocate the gzFile state, or if an invalid mode was
@ -1197,7 +1271,11 @@ ZEXTERN gzFile ZEXPORT gzdopen OF((int fd, const char *mode));
descriptor fd, just like fclose(fdopen(fd, mode)) closes the file descriptor
fd. If you want to keep fd open, use fd = dup(fd_keep); gz = gzdopen(fd,
mode);. The duplicated descriptor should be saved to avoid a leak, since
gzdopen does not close fd if it fails.
gzdopen does not close fd if it fails. If you are using fileno() to get the
file descriptor from a FILE *, then you will have to use dup() to avoid
double-close()ing the file descriptor. Both gzclose() and fclose() will
close the associated file descriptor, so they need to have different file
descriptors.
gzdopen returns NULL if there was insufficient memory to allocate the
gzFile state, if an invalid mode was specified (an 'r', 'w', or 'a' was not
@ -1235,14 +1313,26 @@ ZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy));
ZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len));
/*
Reads the given number of uncompressed bytes from the compressed file. If
the input file was not in gzip format, gzread copies the given number of
bytes into the buffer.
the input file is not in gzip format, gzread copies the given number of
bytes into the buffer directly from the file.
After reaching the end of a gzip stream in the input, gzread will continue
to read, looking for another gzip stream, or failing that, reading the rest
of the input file directly without decompression. The entire input file
will be read if gzread is called until it returns less than the requested
len.
to read, looking for another gzip stream. Any number of gzip streams may be
concatenated in the input file, and will all be decompressed by gzread().
If something other than a gzip stream is encountered after a gzip stream,
that remaining trailing garbage is ignored (and no error is returned).
gzread can be used to read a gzip file that is being concurrently written.
Upon reaching the end of the input, gzread will return with the available
data. If the error code returned by gzerror is Z_OK or Z_BUF_ERROR, then
gzclearerr can be used to clear the end of file indicator in order to permit
gzread to be tried again. Z_OK indicates that a gzip stream was completed
on the last gzread. Z_BUF_ERROR indicates that the input file ended in the
middle of a gzip stream. Note that gzread does not return -1 in the event
of an incomplete gzip stream. This error is deferred until gzclose(), which
will return Z_BUF_ERROR if the last gzread ended in the middle of a gzip
stream. Alternatively, gzerror can be used before gzclose to detect this
case.
gzread returns the number of uncompressed bytes actually read, less than
len for end of file, or -1 for error.
@ -1256,7 +1346,7 @@ ZEXTERN int ZEXPORT gzwrite OF((gzFile file,
error.
*/
ZEXTERN int ZEXPORTVA gzprintf OF((gzFile file, const char *format, ...));
ZEXTERN int ZEXPORTVA gzprintf Z_ARG((gzFile file, const char *format, ...));
/*
Converts, formats, and writes the arguments to the compressed file under
control of the format string, as in fprintf. gzprintf returns the number of
@ -1301,7 +1391,10 @@ ZEXTERN int ZEXPORT gzputc OF((gzFile file, int c));
ZEXTERN int ZEXPORT gzgetc OF((gzFile file));
/*
Reads one byte from the compressed file. gzgetc returns this byte or -1
in case of end of file or error.
in case of end of file or error. This is implemented as a macro for speed.
As such, it does not do all of the checking the other functions do. I.e.
it does not check to see if file is NULL, nor whether the structure file
points to has been clobbered or not.
*/
ZEXTERN int ZEXPORT gzungetc OF((int c, gzFile file));
@ -1397,9 +1490,7 @@ ZEXTERN int ZEXPORT gzeof OF((gzFile file));
ZEXTERN int ZEXPORT gzdirect OF((gzFile file));
/*
Returns true (1) if file is being copied directly while reading, or false
(0) if file is a gzip stream being decompressed. This state can change from
false to true while reading the input file if the end of a gzip stream is
reached, but is followed by data that is not another gzip stream.
(0) if file is a gzip stream being decompressed.
If the input file is empty, gzdirect() will return true, since the input
does not contain a gzip stream.
@ -1408,6 +1499,13 @@ ZEXTERN int ZEXPORT gzdirect OF((gzFile file));
cause buffers to be allocated to allow reading the file to determine if it
is a gzip file. Therefore if gzbuffer() is used, it should be called before
gzdirect().
When writing, gzdirect() returns true (1) if transparent writing was
requested ("wT" for the gzopen() mode), or false (0) otherwise. (Note:
gzdirect() is not needed when writing. Transparent writing must be
explicitly requested, so the application already knows the answer. When
linking statically, using gzdirect() will include all of the zlib code for
gzip file reading and decompression, which may not be desired.)
*/
ZEXTERN int ZEXPORT gzclose OF((gzFile file));
@ -1419,7 +1517,8 @@ ZEXTERN int ZEXPORT gzclose OF((gzFile file));
must not be called more than once on the same allocation.
gzclose will return Z_STREAM_ERROR if file is not valid, Z_ERRNO on a
file operation error, or Z_OK on success.
file operation error, Z_MEM_ERROR if out of memory, Z_BUF_ERROR if the
last read ended in the middle of a gzip stream, or Z_OK on success.
*/
ZEXTERN int ZEXPORT gzclose_r OF((gzFile file));
@ -1457,6 +1556,7 @@ ZEXTERN void ZEXPORT gzclearerr OF((gzFile file));
file that is being written concurrently.
*/
#endif /* !Z_SOLO */
/* checksum functions */
@ -1492,16 +1592,17 @@ ZEXTERN uLong ZEXPORT adler32_combine OF((uLong adler1, uLong adler2,
Combine two Adler-32 checksums into one. For two sequences of bytes, seq1
and seq2 with lengths len1 and len2, Adler-32 checksums were calculated for
each, adler1 and adler2. adler32_combine() returns the Adler-32 checksum of
seq1 and seq2 concatenated, requiring only adler1, adler2, and len2.
seq1 and seq2 concatenated, requiring only adler1, adler2, and len2. Note
that the z_off_t type (like off_t) is a signed integer. If len2 is
negative, the result has no meaning or utility.
*/
ZEXTERN uLong ZEXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len));
/*
Update a running CRC-32 with the bytes buf[0..len-1] and return the
updated CRC-32. If buf is Z_NULL, this function returns the required
initial value for the for the crc. Pre- and post-conditioning (one's
complement) is performed within this function so it shouldn't be done by the
application.
initial value for the crc. Pre- and post-conditioning (one's complement) is
performed within this function so it shouldn't be done by the application.
Usage example:
@ -1544,17 +1645,42 @@ ZEXTERN int ZEXPORT inflateBackInit_ OF((z_streamp strm, int windowBits,
const char *version,
int stream_size));
#define deflateInit(strm, level) \
deflateInit_((strm), (level), ZLIB_VERSION, sizeof(z_stream))
deflateInit_((strm), (level), ZLIB_VERSION, (int)sizeof(z_stream))
#define inflateInit(strm) \
inflateInit_((strm), ZLIB_VERSION, sizeof(z_stream))
inflateInit_((strm), ZLIB_VERSION, (int)sizeof(z_stream))
#define deflateInit2(strm, level, method, windowBits, memLevel, strategy) \
deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\
(strategy), ZLIB_VERSION, sizeof(z_stream))
(strategy), ZLIB_VERSION, (int)sizeof(z_stream))
#define inflateInit2(strm, windowBits) \
inflateInit2_((strm), (windowBits), ZLIB_VERSION, sizeof(z_stream))
inflateInit2_((strm), (windowBits), ZLIB_VERSION, \
(int)sizeof(z_stream))
#define inflateBackInit(strm, windowBits, window) \
inflateBackInit_((strm), (windowBits), (window), \
ZLIB_VERSION, sizeof(z_stream))
ZLIB_VERSION, (int)sizeof(z_stream))
#ifndef Z_SOLO
/* gzgetc() macro and its supporting function and exposed data structure. Note
* that the real internal state is much larger than the exposed structure.
* This abbreviated structure exposes just enough for the gzgetc() macro. The
* user should not mess with these exposed elements, since their names or
* behavior could change in the future, perhaps even capriciously. They can
* only be used by the gzgetc() macro. You have been warned.
*/
struct gzFile_s {
unsigned have;
unsigned char *next;
z_off64_t pos;
};
ZEXTERN int ZEXPORT gzgetc_ OF((gzFile file)); /* backward compatibility */
#ifdef Z_PREFIX_SET
# undef z_gzgetc
# define z_gzgetc(g) \
((g)->have ? ((g)->have--, (g)->pos++, *((g)->next)++) : gzgetc(g))
#else
# define gzgetc(g) \
((g)->have ? ((g)->have--, (g)->pos++, *((g)->next)++) : gzgetc(g))
#endif
/* provide 64-bit offset functions if _LARGEFILE64_SOURCE defined, and/or
* change the regular functions to 64 bits if _FILE_OFFSET_BITS is 64 (if
@ -1562,7 +1688,7 @@ ZEXTERN int ZEXPORT inflateBackInit_ OF((z_streamp strm, int windowBits,
* functions are changed to 64 bits) -- in case these are set on systems
* without large file support, _LFS64_LARGEFILE must also be true
*/
#if defined(_LARGEFILE64_SOURCE) && _LFS64_LARGEFILE-0
#ifdef Z_LARGE64
ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *));
ZEXTERN z_off64_t ZEXPORT gzseek64 OF((gzFile, z_off64_t, int));
ZEXTERN z_off64_t ZEXPORT gztell64 OF((gzFile));
@ -1571,14 +1697,23 @@ ZEXTERN int ZEXPORT inflateBackInit_ OF((z_streamp strm, int windowBits,
ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off64_t));
#endif
#if !defined(ZLIB_INTERNAL) && _FILE_OFFSET_BITS-0 == 64 && _LFS64_LARGEFILE-0
# define gzopen gzopen64
# define gzseek gzseek64
# define gztell gztell64
# define gzoffset gzoffset64
# define adler32_combine adler32_combine64
# define crc32_combine crc32_combine64
# ifdef _LARGEFILE64_SOURCE
#if !defined(ZLIB_INTERNAL) && defined(Z_WANT64)
# ifdef Z_PREFIX_SET
# define z_gzopen z_gzopen64
# define z_gzseek z_gzseek64
# define z_gztell z_gztell64
# define z_gzoffset z_gzoffset64
# define z_adler32_combine z_adler32_combine64
# define z_crc32_combine z_crc32_combine64
# else
# define gzopen gzopen64
# define gzseek gzseek64
# define gztell gztell64
# define gzoffset gzoffset64
# define adler32_combine adler32_combine64
# define crc32_combine crc32_combine64
# endif
# ifndef Z_LARGE64
ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *));
ZEXTERN z_off_t ZEXPORT gzseek64 OF((gzFile, z_off_t, int));
ZEXTERN z_off_t ZEXPORT gztell64 OF((gzFile));
@ -1595,6 +1730,13 @@ ZEXTERN int ZEXPORT inflateBackInit_ OF((z_streamp strm, int windowBits,
ZEXTERN uLong ZEXPORT crc32_combine OF((uLong, uLong, z_off_t));
#endif
#else /* Z_SOLO */
ZEXTERN uLong ZEXPORT adler32_combine OF((uLong, uLong, z_off_t));
ZEXTERN uLong ZEXPORT crc32_combine OF((uLong, uLong, z_off_t));
#endif /* !Z_SOLO */
/* hack for buggy compilers */
#if !defined(ZUTIL_H) && !defined(NO_DUMMY_DECL)
struct internal_state {int dummy;};
@ -1603,8 +1745,21 @@ ZEXTERN int ZEXPORT inflateBackInit_ OF((z_streamp strm, int windowBits,
/* undocumented functions */
ZEXTERN const char * ZEXPORT zError OF((int));
ZEXTERN int ZEXPORT inflateSyncPoint OF((z_streamp));
ZEXTERN const uLongf * ZEXPORT get_crc_table OF((void));
ZEXTERN const z_crc_t FAR * ZEXPORT get_crc_table OF((void));
ZEXTERN int ZEXPORT inflateUndermine OF((z_streamp, int));
ZEXTERN int ZEXPORT inflateResetKeep OF((z_streamp));
ZEXTERN int ZEXPORT deflateResetKeep OF((z_streamp));
#if defined(_WIN32) && !defined(Z_SOLO)
ZEXTERN gzFile ZEXPORT gzopen_w OF((const wchar_t *path,
const char *mode));
#endif
#if defined(STDC) || defined(Z_HAVE_STDARG_H)
# ifndef Z_SOLO
ZEXTERN int ZEXPORTVA gzvprintf Z_ARG((gzFile file,
const char *format,
va_list va));
# endif
#endif
#ifdef __cplusplus
}

23
deps/zlib/zutil.c vendored
View File

@ -1,5 +1,5 @@
/* zutil.c -- target dependent utility functions for the compression library
* Copyright (C) 1995-2005, 2010 Jean-loup Gailly.
* Copyright (C) 1995-2005, 2010, 2011, 2012 Jean-loup Gailly.
* For conditions of distribution and use, see copyright notice in zlib.h
*/
@ -11,7 +11,7 @@
struct internal_state {int dummy;}; /* for buggy compilers */
#endif
const char * const z_errmsg[10] = {
z_const char * const z_errmsg[10] = {
"need dictionary", /* Z_NEED_DICT 2 */
"stream end", /* Z_STREAM_END 1 */
"", /* Z_OK 0 */
@ -85,27 +85,27 @@ uLong ZEXPORT zlibCompileFlags()
#ifdef FASTEST
flags += 1L << 21;
#endif
#ifdef STDC
#if defined(STDC) || defined(Z_HAVE_STDARG_H)
# ifdef NO_vsnprintf
flags += 1L << 25;
flags += 1L << 25;
# ifdef HAS_vsprintf_void
flags += 1L << 26;
flags += 1L << 26;
# endif
# else
# ifdef HAS_vsnprintf_void
flags += 1L << 26;
flags += 1L << 26;
# endif
# endif
#else
flags += 1L << 24;
flags += 1L << 24;
# ifdef NO_snprintf
flags += 1L << 25;
flags += 1L << 25;
# ifdef HAS_sprintf_void
flags += 1L << 26;
flags += 1L << 26;
# endif
# else
# ifdef HAS_snprintf_void
flags += 1L << 26;
flags += 1L << 26;
# endif
# endif
#endif
@ -181,6 +181,7 @@ void ZLIB_INTERNAL zmemzero(dest, len)
}
#endif
#ifndef Z_SOLO
#ifdef SYS16BIT
@ -316,3 +317,5 @@ void ZLIB_INTERNAL zcfree (opaque, ptr)
}
#endif /* MY_ZCALLOC */
#endif /* !Z_SOLO */

103
deps/zlib/zutil.h vendored
View File

@ -1,5 +1,5 @@
/* zutil.h -- internal interface and configuration of the compression library
* Copyright (C) 1995-2010 Jean-loup Gailly.
* Copyright (C) 1995-2013 Jean-loup Gailly.
* For conditions of distribution and use, see copyright notice in zlib.h
*/
@ -13,7 +13,7 @@
#ifndef ZUTIL_H
#define ZUTIL_H
#if ((__GNUC__-0) * 10 + __GNUC_MINOR__-0 >= 33) && !defined(NO_VIZ)
#ifdef HAVE_HIDDEN
# define ZLIB_INTERNAL __attribute__((visibility ("hidden")))
#else
# define ZLIB_INTERNAL
@ -21,7 +21,7 @@
#include "zlib.h"
#ifdef STDC
#if defined(STDC) && !defined(Z_SOLO)
# if !(defined(_WIN32_WCE) && defined(_MSC_VER))
# include <stddef.h>
# endif
@ -29,6 +29,10 @@
# include <stdlib.h>
#endif
#ifdef Z_SOLO
typedef long ptrdiff_t; /* guess -- will be caught if guess is wrong */
#endif
#ifndef local
# define local static
#endif
@ -40,13 +44,13 @@ typedef unsigned short ush;
typedef ush FAR ushf;
typedef unsigned long ulg;
extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
extern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
/* (size given to avoid silly warnings with Visual C++) */
#define ERR_MSG(err) z_errmsg[Z_NEED_DICT-(err)]
#define ERR_RETURN(strm,err) \
return (strm->msg = (char*)ERR_MSG(err), (err))
return (strm->msg = ERR_MSG(err), (err))
/* To be used only when the state is known to be valid */
/* common constants */
@ -78,16 +82,18 @@ extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
#if defined(MSDOS) || (defined(WINDOWS) && !defined(WIN32))
# define OS_CODE 0x00
# if defined(__TURBOC__) || defined(__BORLANDC__)
# if (__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__))
/* Allow compilation with ANSI keywords only enabled */
void _Cdecl farfree( void *block );
void *_Cdecl farmalloc( unsigned long nbytes );
# else
# include <alloc.h>
# ifndef Z_SOLO
# if defined(__TURBOC__) || defined(__BORLANDC__)
# if (__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__))
/* Allow compilation with ANSI keywords only enabled */
void _Cdecl farfree( void *block );
void *_Cdecl farmalloc( unsigned long nbytes );
# else
# include <alloc.h>
# endif
# else /* MSC or DJGPP */
# include <malloc.h>
# endif
# else /* MSC or DJGPP */
# include <malloc.h>
# endif
#endif
@ -107,18 +113,20 @@ extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
#ifdef OS2
# define OS_CODE 0x06
# ifdef M_I86
# if defined(M_I86) && !defined(Z_SOLO)
# include <malloc.h>
# endif
#endif
#if defined(MACOS) || defined(TARGET_OS_MAC)
# define OS_CODE 0x07
# if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os
# include <unix.h> /* for fdopen */
# else
# ifndef fdopen
# define fdopen(fd,mode) NULL /* No fdopen() */
# ifndef Z_SOLO
# if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os
# include <unix.h> /* for fdopen */
# else
# ifndef fdopen
# define fdopen(fd,mode) NULL /* No fdopen() */
# endif
# endif
# endif
#endif
@ -153,14 +161,15 @@ extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
# endif
#endif
#if defined(__BORLANDC__)
#if defined(__BORLANDC__) && !defined(MSDOS)
#pragma warn -8004
#pragma warn -8008
#pragma warn -8066
#endif
/* provide prototypes for these when building zlib without LFS */
#if !defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0
#if !defined(_WIN32) && \
(!defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0)
ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, z_off_t));
ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off_t));
#endif
@ -177,42 +186,7 @@ extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
/* functions */
#if defined(STDC99) || (defined(__TURBOC__) && __TURBOC__ >= 0x550)
# ifndef HAVE_VSNPRINTF
# define HAVE_VSNPRINTF
# endif
#endif
#if defined(__CYGWIN__)
# ifndef HAVE_VSNPRINTF
# define HAVE_VSNPRINTF
# endif
#endif
#ifndef HAVE_VSNPRINTF
# ifdef MSDOS
/* vsnprintf may exist on some MS-DOS compilers (DJGPP?),
but for now we just assume it doesn't. */
# define NO_vsnprintf
# endif
# ifdef __TURBOC__
# define NO_vsnprintf
# endif
# ifdef WIN32
/* In Win32, vsnprintf is available as the "non-ANSI" _vsnprintf. */
# if !defined(vsnprintf) && !defined(NO_vsnprintf)
# if !defined(_MSC_VER) || ( defined(_MSC_VER) && _MSC_VER < 1500 )
# define vsnprintf _vsnprintf
# endif
# endif
# endif
# ifdef __SASC
# define NO_vsnprintf
# endif
#endif
#ifdef VMS
# define NO_vsnprintf
#endif
#if defined(pyr)
#if defined(pyr) || defined(Z_SOLO)
# define NO_MEMCPY
#endif
#if defined(SMALL_MEDIUM) && !defined(_MSC_VER) && !defined(__SC__)
@ -261,14 +235,19 @@ extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
# define Tracecv(c,x)
#endif
voidpf ZLIB_INTERNAL zcalloc OF((voidpf opaque, unsigned items,
unsigned size));
void ZLIB_INTERNAL zcfree OF((voidpf opaque, voidpf ptr));
#ifndef Z_SOLO
voidpf ZLIB_INTERNAL zcalloc OF((voidpf opaque, unsigned items,
unsigned size));
void ZLIB_INTERNAL zcfree OF((voidpf opaque, voidpf ptr));
#endif
#define ZALLOC(strm, items, size) \
(*((strm)->zalloc))((strm)->opaque, (items), (size))
#define ZFREE(strm, addr) (*((strm)->zfree))((strm)->opaque, (voidpf)(addr))
#define TRY_FREE(s, p) {if (p) ZFREE(s, p);}
/* Reverse the bytes in a 32-bit value */
#define ZSWAP32(q) ((((q) >> 24) & 0xff) + (((q) >> 8) & 0xff00) + \
(((q) & 0xff00) << 8) + (((q) & 0xff) << 24))
#endif /* ZUTIL_H */

2
examples/.gitignore vendored
View File

@ -7,7 +7,9 @@ cat-file
init
log
rev-parse
remote
status
tag
for-each-ref
describe
*.dSYM

View File

@ -3,8 +3,9 @@
CC = gcc
CFLAGS = -g -I../include -I../src -Wall -Wextra -Wmissing-prototypes -Wno-missing-field-initializers
LFLAGS = -L../build -lgit2 -lz
APPS = general showindex diff rev-list cat-file status log rev-parse init blame tag
APPS = general showindex diff rev-list cat-file status log rev-parse init blame tag remote
APPS += for-each-ref
APPS += describe
all: $(APPS)

View File

@ -40,7 +40,7 @@ int main (int argc, char** argv)
int options = 0, count = 0;
struct print_payload payload = {0};
git_threads_init();
git_libgit2_init();
parse_opts(&options, &count, argc, argv);
@ -66,7 +66,7 @@ int main (int argc, char** argv)
git_index_free(index);
git_repository_free(repo);
git_threads_shutdown();
git_libgit2_shutdown();
return 0;
}

View File

@ -37,7 +37,8 @@ static void parse_opts(struct opts *o, int argc, char *argv[]);
int main(int argc, char *argv[])
{
int i, line, break_on_null_hunk;
int line, break_on_null_hunk;
size_t i, rawsize;
char spec[1024] = {0};
struct opts o = {0};
const char *rawdata;
@ -48,7 +49,7 @@ int main(int argc, char *argv[])
git_blob *blob;
git_object *obj;
git_threads_init();
git_libgit2_init();
parse_opts(&o, argc, argv);
if (o.M) blameopts.flags |= GIT_BLAME_TRACK_COPIES_SAME_COMMIT_MOVES;
@ -94,23 +95,24 @@ int main(int argc, char *argv[])
git_object_free(obj);
rawdata = git_blob_rawcontent(blob);
rawsize = git_blob_rawsize(blob);
/** Produce the output. */
line = 1;
i = 0;
break_on_null_hunk = 0;
while (i < git_blob_rawsize(blob)) {
const char *eol = strchr(rawdata+i, '\n');
while (i < rawsize) {
const char *eol = memchr(rawdata + i, '\n', rawsize - i);
char oid[10] = {0};
const git_blame_hunk *hunk = git_blame_get_hunk_byline(blame, line);
if (break_on_null_hunk && !hunk) break;
if (break_on_null_hunk && !hunk)
break;
if (hunk) {
char sig[128] = {0};
break_on_null_hunk = 1;
git_oid_tostr(oid, 10, &hunk->final_commit_id);
snprintf(sig, 30, "%s <%s>", hunk->final_signature->name, hunk->final_signature->email);
@ -118,8 +120,8 @@ int main(int argc, char *argv[])
oid,
sig,
line,
(int)(eol-rawdata-i),
rawdata+i);
(int)(eol - rawdata - i),
rawdata + i);
}
i = (int)(eol - rawdata + 1);
@ -131,7 +133,7 @@ int main(int argc, char *argv[])
git_blame_free(blame);
git_repository_free(repo);
git_threads_shutdown();
git_libgit2_shutdown();
return 0;
}

View File

@ -127,7 +127,7 @@ int main(int argc, char *argv[])
git_object *obj = NULL;
char oidstr[GIT_OID_HEXSZ + 1];
git_threads_init();
git_libgit2_init();
parse_opts(&o, argc, argv);
@ -190,7 +190,7 @@ int main(int argc, char *argv[])
git_object_free(obj);
git_repository_free(repo);
git_threads_shutdown();
git_libgit2_shutdown();
return 0;
}

View File

@ -53,6 +53,33 @@ size_t is_prefixed(const char *str, const char *pfx)
return strncmp(str, pfx, len) ? 0 : len;
}
int optional_str_arg(
const char **out, struct args_info *args, const char *opt, const char *def)
{
const char *found = args->argv[args->pos];
size_t len = is_prefixed(found, opt);
if (!len)
return 0;
if (!found[len]) {
if (args->pos + 1 == args->argc) {
*out = def;
return 1;
}
args->pos += 1;
*out = args->argv[args->pos];
return 1;
}
if (found[len] == '=') {
*out = found + len + 1;
return 1;
}
return 0;
}
int match_str_arg(
const char **out, struct args_info *args, const char *opt)
{

View File

@ -46,6 +46,15 @@ struct args_info {
};
#define ARGS_INFO_INIT { argc, argv, 0 }
/**
* Check current `args` entry against `opt` string. If it matches
* exactly, take the next arg as a string; if it matches as a prefix with
* an equal sign, take the remainder as a string; if value not supplied,
* default value `def` will be given. otherwise return 0.
*/
extern int optional_str_arg(
const char **out, struct args_info *args, const char *opt, const char *def);
/**
* Check current `args` entry against `opt` string. If it matches
* exactly, take the next arg as a string; if it matches as a prefix with

184
examples/describe.c Normal file
View File

@ -0,0 +1,184 @@
/*
* libgit2 "describe" example - shows how to describe commits
*
* Written by the libgit2 contributors
*
* To the extent possible under law, the author(s) have dedicated all copyright
* and related and neighboring rights to this software to the public domain
* worldwide. This software is distributed without any warranty.
*
* You should have received a copy of the CC0 Public Domain Dedication along
* with this software. If not, see
* <http://creativecommons.org/publicdomain/zero/1.0/>.
*/
#include "common.h"
#include <assert.h>
/**
* The following example partially reimplements the `git describe` command
* and some of its options.
*
* These commands should work:
* - Describe HEAD with default options (`describe`)
* - Describe specified revision (`describe master~2`)
* - Describe specified revisions (`describe master~2 HEAD~3`)
* - Describe HEAD with dirty state suffix (`describe --dirty=*`)
* - Describe consider all refs (`describe --all master`)
* - Describe consider lightweight tags (`describe --tags temp-tag`)
* - Describe show non-default abbreviated size (`describe --abbrev=10`)
* - Describe always output the long format if matches a tag (`describe --long v1.0`)
* - Describe consider only tags of specified pattern (`describe --match v*-release`)
* - Describe show the fallback result (`describe --always`)
* - Describe follow only the first parent commit (`describe --first-parent`)
*
* The command line parsing logic is simplified and doesn't handle
* all of the use cases.
*/
/** describe_options represents the parsed command line options */
typedef struct {
const char **commits;
size_t commit_count;
git_describe_options describe_options;
git_describe_format_options format_options;
} describe_options;
typedef struct args_info args_info;
static void *xrealloc(void *oldp, size_t newsz)
{
void *p = realloc(oldp, newsz);
if (p == NULL) {
fprintf(stderr, "Cannot allocate memory, exiting.\n");
exit(1);
}
return p;
}
static void opts_add_commit(describe_options *opts, const char *commit)
{
size_t sz;
assert(opts != NULL);
sz = ++opts->commit_count * sizeof(opts->commits[0]);
opts->commits = xrealloc(opts->commits, sz);
opts->commits[opts->commit_count - 1] = commit;
}
static void do_describe_single(git_repository *repo, describe_options *opts, const char *rev)
{
git_object *commit;
git_describe_result *describe_result;
git_buf buf = { 0 };
if (rev) {
check_lg2(git_revparse_single(&commit, repo, rev),
"Failed to lookup rev", rev);
check_lg2(git_describe_commit(&describe_result, commit, &opts->describe_options),
"Failed to describe rev", rev);
}
else
check_lg2(git_describe_workdir(&describe_result, repo, &opts->describe_options),
"Failed to describe workdir", NULL);
check_lg2(git_describe_format(&buf, describe_result, &opts->format_options),
"Failed to format describe rev", rev);
printf("%s\n", buf.ptr);
}
static void do_describe(git_repository *repo, describe_options *opts)
{
if (opts->commit_count == 0)
do_describe_single(repo, opts, NULL);
else
{
size_t i;
for (i = 0; i < opts->commit_count; i++)
do_describe_single(repo, opts, opts->commits[i]);
}
}
static void print_usage(void)
{
fprintf(stderr, "usage: see `git help describe`\n");
exit(1);
}
/** Parse command line arguments */
static void parse_options(describe_options *opts, int argc, char **argv)
{
args_info args = ARGS_INFO_INIT;
for (args.pos = 1; args.pos < argc; ++args.pos) {
const char *curr = argv[args.pos];
if (curr[0] != '-') {
opts_add_commit(opts, curr);
} else if (!strcmp(curr, "--all")) {
opts->describe_options.describe_strategy = GIT_DESCRIBE_ALL;
} else if (!strcmp(curr, "--tags")) {
opts->describe_options.describe_strategy = GIT_DESCRIBE_TAGS;
} else if (!strcmp(curr, "--exact-match")) {
opts->describe_options.max_candidates_tags = 0;
} else if (!strcmp(curr, "--long")) {
opts->format_options.always_use_long_format = 1;
} else if (!strcmp(curr, "--always")) {
opts->describe_options.show_commit_oid_as_fallback = 1;
} else if (!strcmp(curr, "--first-parent")) {
opts->describe_options.only_follow_first_parent = 1;
} else if (optional_str_arg(&opts->format_options.dirty_suffix, &args, "--dirty", "-dirty")) {
} else if (match_int_arg((int *)&opts->format_options.abbreviated_size, &args, "--abbrev", 0)) {
} else if (match_int_arg((int *)&opts->describe_options.max_candidates_tags, &args, "--candidates", 0)) {
} else if (match_str_arg(&opts->describe_options.pattern, &args, "--match")) {
} else {
print_usage();
}
}
if (opts->commit_count > 0) {
if (opts->format_options.dirty_suffix)
fatal("--dirty is incompatible with commit-ishes", NULL);
}
else {
if (!opts->format_options.dirty_suffix || !opts->format_options.dirty_suffix[0]) {
opts_add_commit(opts, "HEAD");
}
}
}
/** Initialize describe_options struct */
static void describe_options_init(describe_options *opts)
{
memset(opts, 0, sizeof(*opts));
opts->commits = NULL;
opts->commit_count = 0;
git_describe_init_options(&opts->describe_options, GIT_DESCRIBE_OPTIONS_VERSION);
git_describe_init_format_options(&opts->format_options, GIT_DESCRIBE_FORMAT_OPTIONS_VERSION);
}
int main(int argc, char **argv)
{
git_repository *repo;
describe_options opts;
git_libgit2_init();
check_lg2(git_repository_open_ext(&repo, ".", 0, NULL),
"Could not open repository", NULL);
describe_options_init(&opts);
parse_options(&opts, argc, argv);
do_describe(repo, &opts);
git_repository_free(repo);
git_libgit2_shutdown();
return 0;
}

View File

@ -77,7 +77,7 @@ int main(int argc, char *argv[])
-1, 0, 0, GIT_DIFF_FORMAT_PATCH, NULL, NULL, "."
};
git_threads_init();
git_libgit2_init();
parse_opts(&o, argc, argv);
@ -163,7 +163,7 @@ int main(int argc, char *argv[])
git_tree_free(t2);
git_repository_free(repo);
git_threads_shutdown();
git_libgit2_shutdown();
return 0;
}

View File

@ -34,6 +34,7 @@ static int show_ref(git_reference *ref, void *data)
int main(int argc, char **argv)
{
git_repository *repo;
git_libgit2_init();
if (argc != 1 || argv[1] /* silence -Wunused-parameter */)
fatal("Sorry, no for-each-ref options supported yet", NULL);
@ -42,5 +43,7 @@ int main(int argc, char **argv)
"Could not open repository", NULL);
check_lg2(git_reference_foreach(repo, show_ref, repo),
"Could not iterate over references", NULL);
git_libgit2_shutdown();
return 0;
}

View File

@ -59,6 +59,10 @@ static void check_error(int error_code, const char *action)
int main (int argc, char** argv)
{
// Initialize the library, this will set up any global state which libgit2 needs
// including threading and crypto
git_libgit2_init();
// ### Opening the Repository
// There are a couple of methods for opening a repository, this being the
@ -94,8 +98,8 @@ int main (int argc, char** argv)
// Next we will convert the 20 byte raw SHA1 value to a human readable 40
// char hex value.
printf("\n*Raw to Hex*\n");
char out[41];
out[40] = '\0';
char out[GIT_OID_HEXSZ+1];
out[GIT_OID_HEXSZ] = '\0';
// If you have a oid, you can easily get the hex value of the SHA as well.
git_oid_fmt(out, &oid);
@ -122,7 +126,7 @@ int main (int argc, char** argv)
// We can read raw objects directly from the object database if we have
// the oid (SHA) of the object. This allows us to access objects without
// knowing thier type and inspect the raw bytes unparsed.
// knowing their type and inspect the raw bytes unparsed.
error = git_odb_read(&obj, odb, &oid);
check_error(error, "finding object in repository");
@ -398,7 +402,7 @@ int main (int argc, char** argv)
// Now that we have the starting point pushed onto the walker, we start
// asking for ancestors. It will return them in the sorting order we asked
// for as commit oids. We can then lookup and parse the commited pointed
// for as commit oids. We can then lookup and parse the committed pointed
// at by the returned OID; note that this operation is specially fast
// since the raw contents of the commit object will be cached in memory
while ((git_revwalk_next(&oid, walk)) == 0) {

View File

@ -46,7 +46,7 @@ int main(int argc, char *argv[])
git_repository *repo = NULL;
struct opts o = { 1, 0, 0, 0, GIT_REPOSITORY_INIT_SHARED_UMASK, 0, 0, 0 };
git_threads_init();
git_libgit2_init();
parse_opts(&o, argc, argv);
@ -116,7 +116,7 @@ int main(int argc, char *argv[])
}
git_repository_free(repo);
git_threads_shutdown();
git_libgit2_shutdown();
return 0;
}

View File

@ -80,7 +80,7 @@ int main(int argc, char *argv[])
git_commit *commit = NULL;
git_pathspec *ps = NULL;
git_threads_init();
git_libgit2_init();
/** Parse arguments and set up revwalker. */
@ -180,7 +180,7 @@ int main(int argc, char *argv[])
git_pathspec_free(ps);
git_revwalk_free(s.walker);
git_repository_free(s.repo);
git_threads_shutdown();
git_libgit2_shutdown();
return 0;
}

View File

@ -18,14 +18,20 @@ typedef struct progress_data {
static void print_progress(const progress_data *pd)
{
int network_percent = (100*pd->fetch_progress.received_objects) / pd->fetch_progress.total_objects;
int index_percent = (100*pd->fetch_progress.indexed_objects) / pd->fetch_progress.total_objects;
int network_percent = pd->fetch_progress.total_objects > 0 ?
(100*pd->fetch_progress.received_objects) / pd->fetch_progress.total_objects :
0;
int index_percent = pd->fetch_progress.total_objects > 0 ?
(100*pd->fetch_progress.indexed_objects) / pd->fetch_progress.total_objects :
0;
int checkout_percent = pd->total_steps > 0
? (100 * pd->completed_steps) / pd->total_steps
: 0;
int kbytes = pd->fetch_progress.received_bytes / 1024;
if (pd->fetch_progress.received_objects == pd->fetch_progress.total_objects) {
if (pd->fetch_progress.total_objects &&
pd->fetch_progress.received_objects == pd->fetch_progress.total_objects) {
printf("Resolving deltas %d/%d\r",
pd->fetch_progress.indexed_deltas,
pd->fetch_progress.total_deltas);
@ -40,6 +46,15 @@ static void print_progress(const progress_data *pd)
}
}
static int sideband_progress(const char *str, int len, void *payload)
{
(void)payload; // unused
printf("remote: %*s", len, str);
fflush(stdout);
return 0;
}
static int fetch_progress(const git_transfer_progress *stats, void *payload)
{
progress_data *pd = (progress_data*)payload;
@ -76,13 +91,14 @@ int do_clone(git_repository *repo, int argc, char **argv)
}
// Set up options
checkout_opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
checkout_opts.checkout_strategy = GIT_CHECKOUT_SAFE;
checkout_opts.progress_cb = checkout_progress;
checkout_opts.progress_payload = &pd;
clone_opts.checkout_opts = checkout_opts;
clone_opts.remote_callbacks.transfer_progress = &fetch_progress;
clone_opts.remote_callbacks.credentials = cred_acquire_cb;
clone_opts.remote_callbacks.payload = &pd;
clone_opts.fetch_opts.callbacks.sideband_progress = sideband_progress;
clone_opts.fetch_opts.callbacks.transfer_progress = &fetch_progress;
clone_opts.fetch_opts.callbacks.credentials = cred_acquire_cb;
clone_opts.fetch_opts.callbacks.payload = &pd;
// Do the clone
error = git_clone(&cloned_repo, url, path, &clone_opts);

View File

@ -10,6 +10,7 @@
struct dl_data {
git_remote *remote;
git_fetch_options *fetch_opts;
int ret;
int finished;
};
@ -28,7 +29,7 @@ static void *download(void *ptr)
// Connect to the remote end specifying that we want to fetch
// information from it.
if (git_remote_connect(data->remote, GIT_DIRECTION_FETCH) < 0) {
if (git_remote_connect(data->remote, GIT_DIRECTION_FETCH, &data->fetch_opts->callbacks) < 0) {
data->ret = -1;
goto exit;
}
@ -36,7 +37,7 @@ static void *download(void *ptr)
// Download the packfile and index it. This function updates the
// amount of received data and the indexer stats which lets you
// inform the user about progress.
if (git_remote_download(data->remote) < 0) {
if (git_remote_download(data->remote, NULL, data->fetch_opts) < 0) {
data->ret = -1;
goto exit;
}
@ -78,7 +79,7 @@ int fetch(git_repository *repo, int argc, char **argv)
git_remote *remote = NULL;
const git_transfer_progress *stats;
struct dl_data data;
git_remote_callbacks callbacks = GIT_REMOTE_CALLBACKS_INIT;
git_fetch_options fetch_opts = GIT_FETCH_OPTIONS_INIT;
#ifndef _WIN32
pthread_t worker;
#endif
@ -90,19 +91,19 @@ int fetch(git_repository *repo, int argc, char **argv)
// Figure out whether it's a named remote or a URL
printf("Fetching %s for repo %p\n", argv[1], repo);
if (git_remote_load(&remote, repo, argv[1]) < 0) {
if (git_remote_create_anonymous(&remote, repo, argv[1], NULL) < 0)
if (git_remote_lookup(&remote, repo, argv[1]) < 0) {
if (git_remote_create_anonymous(&remote, repo, argv[1]) < 0)
return -1;
}
// Set up the callbacks (only update_tips for now)
callbacks.update_tips = &update_cb;
callbacks.sideband_progress = &progress_cb;
callbacks.credentials = cred_acquire_cb;
git_remote_set_callbacks(remote, &callbacks);
fetch_opts.callbacks.update_tips = &update_cb;
fetch_opts.callbacks.sideband_progress = &progress_cb;
fetch_opts.callbacks.credentials = cred_acquire_cb;
// Set up the information for the background worker thread
data.remote = remote;
data.fetch_opts = &fetch_opts;
data.ret = 0;
data.finished = 0;
@ -155,8 +156,8 @@ int fetch(git_repository *repo, int argc, char **argv)
// Update the references in the remote's namespace to point to the
// right commits. This may be needed even if there was no packfile
// to download, which can happen e.g. when the branches have been
// changed but all the neede objects are available locally.
if (git_remote_update_tips(remote, NULL, NULL) < 0)
// changed but all the needed objects are available locally.
if (git_remote_update_tips(remote, &fetch_opts.callbacks, 1, fetch_opts.download_tags, NULL) < 0)
return -1;
git_remote_free(remote);

View File

@ -23,8 +23,8 @@ static int run_command(git_cb fn, int argc, char **argv)
int error;
git_repository *repo;
// Before running the actual command, create an instance of the local
// repository and pass it to the function.
// Before running the actual command, create an instance of the local
// repository and pass it to the function.
error = git_repository_open(&repo, ".git");
if (error < 0)
@ -48,19 +48,26 @@ static int run_command(git_cb fn, int argc, char **argv)
int main(int argc, char **argv)
{
int i;
int return_code = 1;
if (argc < 2) {
fprintf(stderr, "usage: %s <cmd> [repo]\n", argv[0]);
exit(EXIT_FAILURE);
}
git_threads_init();
git_libgit2_init();
for (i = 0; commands[i].name != NULL; ++i) {
if (!strcmp(argv[1], commands[i].name))
return run_command(commands[i].fn, --argc, ++argv);
if (!strcmp(argv[1], commands[i].name)) {
return_code = run_command(commands[i].fn, --argc, ++argv);
goto shutdown;
}
}
fprintf(stderr, "Command not found: %s\n", argv[1]);
return 1;
shutdown:
git_libgit2_shutdown();
return return_code;
}

View File

@ -13,9 +13,9 @@ static int use_remote(git_repository *repo, char *name)
git_remote_callbacks callbacks = GIT_REMOTE_CALLBACKS_INIT;
// Find the remote by name
error = git_remote_load(&remote, repo, name);
error = git_remote_lookup(&remote, repo, name);
if (error < 0) {
error = git_remote_create_anonymous(&remote, repo, name, NULL);
error = git_remote_create_anonymous(&remote, repo, name);
if (error < 0)
goto cleanup;
}
@ -25,9 +25,8 @@ static int use_remote(git_repository *repo, char *name)
* each of the remote references.
*/
callbacks.credentials = cred_acquire_cb;
git_remote_set_callbacks(remote, &callbacks);
error = git_remote_connect(remote, GIT_DIRECTION_FETCH);
error = git_remote_connect(remote, GIT_DIRECTION_FETCH, &callbacks);
if (error < 0)
goto cleanup;

269
examples/remote.c Normal file
View File

@ -0,0 +1,269 @@
/*
* libgit2 "remote" example - shows how to modify remotes for a repo
*
* Written by the libgit2 contributors
*
* To the extent possible under law, the author(s) have dedicated all copyright
* and related and neighboring rights to this software to the public domain
* worldwide. This software is distributed without any warranty.
*
* You should have received a copy of the CC0 Public Domain Dedication along
* with this software. If not, see
* <http://creativecommons.org/publicdomain/zero/1.0/>.
*/
#include "common.h"
/**
* This is a sample program that is similar to "git remote". See the
* documentation for that (try "git help remote") to understand what this
* program is emulating.
*
* This demonstrates using the libgit2 APIs to modify remotes of a repository.
*/
enum subcmd {
subcmd_add,
subcmd_remove,
subcmd_rename,
subcmd_seturl,
subcmd_show,
};
struct opts {
enum subcmd cmd;
/* for command-specific args */
int argc;
char **argv;
};
static int cmd_add(git_repository *repo, struct opts *o);
static int cmd_remove(git_repository *repo, struct opts *o);
static int cmd_rename(git_repository *repo, struct opts *o);
static int cmd_seturl(git_repository *repo, struct opts *o);
static int cmd_show(git_repository *repo, struct opts *o);
static void parse_subcmd(
struct opts *opt, int argc, char **argv);
static void usage(const char *msg, const char *arg);
int main(int argc, char *argv[])
{
int retval = 0;
struct opts opt = {0};
git_buf buf = GIT_BUF_INIT_CONST(NULL, 0);
git_repository *repo = NULL;
parse_subcmd(&opt, argc, argv);
git_libgit2_init();
check_lg2(git_repository_discover(&buf, ".", 0, NULL),
"Could not find repository", NULL);
check_lg2(git_repository_open(&repo, buf.ptr),
"Could not open repository", NULL);
git_buf_free(&buf);
switch (opt.cmd)
{
case subcmd_add:
retval = cmd_add(repo, &opt);
break;
case subcmd_remove:
retval = cmd_remove(repo, &opt);
break;
case subcmd_rename:
retval = cmd_rename(repo, &opt);
break;
case subcmd_seturl:
retval = cmd_seturl(repo, &opt);
break;
case subcmd_show:
retval = cmd_show(repo, &opt);
break;
}
git_libgit2_shutdown();
return retval;
}
static int cmd_add(git_repository *repo, struct opts *o)
{
char *name, *url;
git_remote *remote = {0};
if (o->argc != 2)
usage("you need to specify a name and URL", NULL);
name = o->argv[0];
url = o->argv[1];
check_lg2(git_remote_create(&remote, repo, name, url),
"could not create remote", NULL);
return 0;
}
static int cmd_remove(git_repository *repo, struct opts *o)
{
char *name;
if (o->argc != 1)
usage("you need to specify a name", NULL);
name = o->argv[0];
check_lg2(git_remote_delete(repo, name),
"could not delete remote", name);
return 0;
}
static int cmd_rename(git_repository *repo, struct opts *o)
{
int i, retval;
char *old, *new;
git_strarray problems = {0};
if (o->argc != 2)
usage("you need to specify old and new remote name", NULL);
old = o->argv[0];
new = o->argv[1];
retval = git_remote_rename(&problems, repo, old, new);
if (!retval)
return 0;
for (i = 0; i < (int) problems.count; i++) {
puts(problems.strings[0]);
}
git_strarray_free(&problems);
return retval;
}
static int cmd_seturl(git_repository *repo, struct opts *o)
{
int i, retval, push = 0;
char *name = NULL, *url = NULL;
for (i = 0; i < o->argc; i++) {
char *arg = o->argv[i];
if (!strcmp(arg, "--push")) {
push = 1;
} else if (arg[0] != '-' && name == NULL) {
name = arg;
} else if (arg[0] != '-' && url == NULL) {
url = arg;
} else {
usage("invalid argument to set-url", arg);
}
}
if (name == NULL || url == NULL)
usage("you need to specify remote and the new URL", NULL);
if (push)
retval = git_remote_set_pushurl(repo, name, url);
else
retval = git_remote_set_url(repo, name, url);
check_lg2(retval, "could not set URL", url);
return 0;
}
static int cmd_show(git_repository *repo, struct opts *o)
{
int i;
const char *arg, *name, *fetch, *push;
int verbose = 0;
git_strarray remotes = {0};
git_remote *remote = {0};
for (i = 0; i < o->argc; i++) {
arg = o->argv[i];
if (!strcmp(arg, "-v") || !strcmp(arg, "--verbose")) {
verbose = 1;
}
}
check_lg2(git_remote_list(&remotes, repo),
"could not retrieve remotes", NULL);
for (i = 0; i < (int) remotes.count; i++) {
name = remotes.strings[i];
if (!verbose) {
puts(name);
continue;
}
check_lg2(git_remote_lookup(&remote, repo, name),
"could not look up remote", name);
fetch = git_remote_url(remote);
if (fetch)
printf("%s\t%s (fetch)\n", name, fetch);
push = git_remote_pushurl(remote);
/* use fetch URL if no distinct push URL has been set */
push = push ? push : fetch;
if (push)
printf("%s\t%s (push)\n", name, push);
git_remote_free(remote);
}
git_strarray_free(&remotes);
return 0;
}
static void parse_subcmd(
struct opts *opt, int argc, char **argv)
{
char *arg = argv[1];
enum subcmd cmd = 0;
if (argc < 2)
usage("no command specified", NULL);
if (!strcmp(arg, "add")) {
cmd = subcmd_add;
} else if (!strcmp(arg, "remove")) {
cmd = subcmd_remove;
} else if (!strcmp(arg, "rename")) {
cmd = subcmd_rename;
} else if (!strcmp(arg, "set-url")) {
cmd = subcmd_seturl;
} else if (!strcmp(arg, "show")) {
cmd = subcmd_show;
} else {
usage("command is not valid", arg);
}
opt->cmd = cmd;
opt->argc = argc - 2; /* executable and subcommand are removed */
opt->argv = argv + 2;
}
static void usage(const char *msg, const char *arg)
{
fputs("usage: remote add <name> <url>\n", stderr);
fputs(" remote remove <name>\n", stderr);
fputs(" remote rename <old> <new>\n", stderr);
fputs(" remote set-url [--push] <name> <newurl>\n", stderr);
fputs(" remote show [-v|--verbose]\n", stderr);
if (msg && !arg)
fprintf(stderr, "\n%s\n", msg);
else if (msg && arg)
fprintf(stderr, "\n%s: %s\n", msg, arg);
exit(1);
}

View File

@ -22,9 +22,9 @@ int main (int argc, char **argv)
git_repository *repo;
git_revwalk *walk;
git_oid oid;
char buf[41];
char buf[GIT_OID_HEXSZ+1];
git_threads_init();
git_libgit2_init();
check_lg2(git_repository_open_ext(&repo, ".", 0, NULL), "opening repository", NULL);
check_lg2(git_revwalk_new(&walk, repo), "allocating revwalk", NULL);
@ -32,11 +32,11 @@ int main (int argc, char **argv)
while (!git_revwalk_next(&oid, walk)) {
git_oid_fmt(buf, &oid);
buf[40] = '\0';
buf[GIT_OID_HEXSZ] = '\0';
printf("%s\n", buf);
}
git_threads_shutdown();
git_libgit2_shutdown();
return 0;
}

View File

@ -29,13 +29,13 @@ int main(int argc, char *argv[])
{
struct parse_state ps = {0};
git_threads_init();
git_libgit2_init();
parse_opts(&ps, argc, argv);
check_lg2(parse_revision(&ps), "Parsing", NULL);
git_repository_free(ps.repo);
git_threads_shutdown();
git_libgit2_shutdown();
return 0;
}

View File

@ -20,10 +20,10 @@ int main (int argc, char** argv)
unsigned int i, ecount;
char *dir = ".";
size_t dirlen;
char out[41];
out[40] = '\0';
char out[GIT_OID_HEXSZ+1];
out[GIT_OID_HEXSZ] = '\0';
git_threads_init();
git_libgit2_init();
if (argc > 2)
fatal("usage: showindex [<repo-dir>]", NULL);
@ -64,7 +64,7 @@ int main (int argc, char** argv)
}
git_index_free(index);
git_threads_shutdown();
git_libgit2_shutdown();
return 0;
}

View File

@ -73,7 +73,7 @@ int main(int argc, char *argv[])
git_status_list *status;
struct opts o = { GIT_STATUS_OPTIONS_INIT, "." };
git_threads_init();
git_libgit2_init();
o.statusopt.show = GIT_STATUS_SHOW_INDEX_AND_WORKDIR;
o.statusopt.flags = GIT_STATUS_OPT_INCLUDE_UNTRACKED |
@ -135,7 +135,7 @@ show_status:
}
git_repository_free(repo);
git_threads_shutdown();
git_libgit2_shutdown();
return 0;
}
@ -384,25 +384,19 @@ static void print_short(git_repository *repo, git_status_list *status)
if (s->index_to_workdir &&
s->index_to_workdir->new_file.mode == GIT_FILEMODE_COMMIT)
{
git_submodule *sm = NULL;
unsigned int smstatus = 0;
if (!git_submodule_lookup(
&sm, repo, s->index_to_workdir->new_file.path)) {
if (!git_submodule_status(&smstatus, sm)) {
if (smstatus & GIT_SUBMODULE_STATUS_WD_MODIFIED)
extra = " (new commits)";
else if (smstatus & GIT_SUBMODULE_STATUS_WD_INDEX_MODIFIED)
extra = " (modified content)";
else if (smstatus & GIT_SUBMODULE_STATUS_WD_WD_MODIFIED)
extra = " (modified content)";
else if (smstatus & GIT_SUBMODULE_STATUS_WD_UNTRACKED)
extra = " (untracked content)";
}
if (!git_submodule_status(&smstatus, repo, s->index_to_workdir->new_file.path,
GIT_SUBMODULE_IGNORE_UNSPECIFIED)) {
if (smstatus & GIT_SUBMODULE_STATUS_WD_MODIFIED)
extra = " (new commits)";
else if (smstatus & GIT_SUBMODULE_STATUS_WD_INDEX_MODIFIED)
extra = " (modified content)";
else if (smstatus & GIT_SUBMODULE_STATUS_WD_WD_MODIFIED)
extra = " (modified content)";
else if (smstatus & GIT_SUBMODULE_STATUS_WD_UNTRACKED)
extra = " (untracked content)";
}
git_submodule_free(sm);
}
/**

View File

@ -236,7 +236,7 @@ static void action_create_tag(tag_state *state)
git_signature_free(tagger);
}
static void print_usage()
static void print_usage(void)
{
fprintf(stderr, "usage: see `git help tag`\n");
exit(1);
@ -300,7 +300,7 @@ int main(int argc, char **argv)
tag_action action;
tag_state state;
git_threads_init();
git_libgit2_init();
check_lg2(git_repository_open_ext(&repo, ".", 0, NULL),
"Could not open repository", NULL);
@ -313,7 +313,7 @@ int main(int argc, char **argv)
action(&state);
git_repository_free(repo);
git_threads_shutdown();
git_libgit2_shutdown();
return 0;
}

View File

@ -8,6 +8,7 @@
#ifndef INCLUDE_git_git_h__
#define INCLUDE_git_git_h__
#include "git2/annotated_commit.h"
#include "git2/attr.h"
#include "git2/blob.h"
#include "git2/blame.h"
@ -19,9 +20,11 @@
#include "git2/commit.h"
#include "git2/common.h"
#include "git2/config.h"
#include "git2/describe.h"
#include "git2/diff.h"
#include "git2/errors.h"
#include "git2/filter.h"
#include "git2/global.h"
#include "git2/graph.h"
#include "git2/ignore.h"
#include "git2/index.h"
@ -32,11 +35,12 @@
#include "git2/notes.h"
#include "git2/object.h"
#include "git2/odb.h"
#include "git2/odb_backend.h"
#include "git2/oid.h"
#include "git2/pack.h"
#include "git2/patch.h"
#include "git2/pathspec.h"
#include "git2/push.h"
#include "git2/rebase.h"
#include "git2/refdb.h"
#include "git2/reflog.h"
#include "git2/refs.h"
@ -52,8 +56,8 @@
#include "git2/status.h"
#include "git2/submodule.h"
#include "git2/tag.h"
#include "git2/threads.h"
#include "git2/transport.h"
#include "git2/transaction.h"
#include "git2/tree.h"
#include "git2/types.h"
#include "git2/version.h"

View File

@ -0,0 +1,116 @@
/*
* Copyright (C) the libgit2 contributors. All rights reserved.
*
* This file is part of libgit2, distributed under the GNU GPL v2 with
* a Linking Exception. For full terms see the included COPYING file.
*/
#ifndef INCLUDE_git_annotated_commit_h__
#define INCLUDE_git_annotated_commit_h__
#include "common.h"
#include "repository.h"
#include "types.h"
/**
* @file git2/annotated_commit.h
* @brief Git annotated commit routines
* @defgroup git_annotated_commit Git annotated commit routines
* @ingroup Git
* @{
*/
GIT_BEGIN_DECL
/**
* Creates a `git_annotated_commit` from the given reference.
* The resulting git_annotated_commit must be freed with
* `git_annotated_commit_free`.
*
* @param out pointer to store the git_annotated_commit result in
* @param repo repository that contains the given reference
* @param ref reference to use to lookup the git_annotated_commit
* @return 0 on success or error code
*/
GIT_EXTERN(int) git_annotated_commit_from_ref(
git_annotated_commit **out,
git_repository *repo,
const git_reference *ref);
/**
* Creates a `git_annotated_commit` from the given fetch head data.
* The resulting git_annotated_commit must be freed with
* `git_annotated_commit_free`.
*
* @param out pointer to store the git_annotated_commit result in
* @param repo repository that contains the given commit
* @param branch_name name of the (remote) branch
* @param remote_url url of the remote
* @param id the commit object id of the remote branch
* @return 0 on success or error code
*/
GIT_EXTERN(int) git_annotated_commit_from_fetchhead(
git_annotated_commit **out,
git_repository *repo,
const char *branch_name,
const char *remote_url,
const git_oid *id);
/**
* Creates a `git_annotated_commit` from the given commit id.
* The resulting git_annotated_commit must be freed with
* `git_annotated_commit_free`.
*
* An annotated commit contains information about how it was
* looked up, which may be useful for functions like merge or
* rebase to provide context to the operation. For example,
* conflict files will include the name of the source or target
* branches being merged. It is therefore preferable to use the
* most specific function (eg `git_annotated_commit_from_ref`)
* instead of this one when that data is known.
*
* @param out pointer to store the git_annotated_commit result in
* @param repo repository that contains the given commit
* @param id the commit object id to lookup
* @return 0 on success or error code
*/
GIT_EXTERN(int) git_annotated_commit_lookup(
git_annotated_commit **out,
git_repository *repo,
const git_oid *id);
/**
* Creates a `git_annotated_comit` from a revision string.
*
* See `man gitrevisions`, or
* http://git-scm.com/docs/git-rev-parse.html#_specifying_revisions for
* information on the syntax accepted.
*
* @param out pointer to store the git_annotated_commit result in
* @param repo repository that contains the given commit
* @param revspec the extended sha syntax string to use to lookup the commit
* @return 0 on success or error code
*/
GIT_EXTERN(int) git_annotated_commit_from_revspec(
git_annotated_commit **out,
git_repository *repo,
const char *revspec);
/**
* Gets the commit ID that the given `git_annotated_commit` refers to.
*
* @param commit the given annotated commit
* @return commit id
*/
GIT_EXTERN(const git_oid *) git_annotated_commit_id(
const git_annotated_commit *commit);
/**
* Frees a `git_annotated_commit`.
*
* @param commit annotated commit to free
*/
GIT_EXTERN(void) git_annotated_commit_free(
git_annotated_commit *commit);
/** @} */
GIT_END_DECL
#endif

View File

@ -76,25 +76,28 @@ GIT_BEGIN_DECL
*/
#define GIT_ATTR_HAS_VALUE(attr) (git_attr_value(attr) == GIT_ATTR_VALUE_T)
/**
* Possible states for an attribute
*/
typedef enum {
GIT_ATTR_UNSPECIFIED_T = 0,
GIT_ATTR_TRUE_T,
GIT_ATTR_FALSE_T,
GIT_ATTR_VALUE_T,
GIT_ATTR_UNSPECIFIED_T = 0, /**< The attribute has been left unspecified */
GIT_ATTR_TRUE_T, /**< The attribute has been set */
GIT_ATTR_FALSE_T, /**< The attribute has been unset */
GIT_ATTR_VALUE_T, /**< This attribute has a value */
} git_attr_t;
/*
* Return the value type for a given attribute.
/**
* Return the value type for a given attribute.
*
* This can be either `TRUE`, `FALSE`, `UNSPECIFIED` (if the attribute
* was not set at all), or `VALUE`, if the attribute was set to
* an actual string.
* This can be either `TRUE`, `FALSE`, `UNSPECIFIED` (if the attribute
* was not set at all), or `VALUE`, if the attribute was set to an
* actual string.
*
* If the attribute has a `VALUE` string, it can be accessed normally
* as a NULL-terminated C string.
* If the attribute has a `VALUE` string, it can be accessed normally
* as a NULL-terminated C string.
*
* @param attr The attribute
* @return the value type for the attribute
* @param attr The attribute
* @return the value type for the attribute
*/
GIT_EXTERN(git_attr_t) git_attr_value(const char *attr);

View File

@ -67,7 +67,6 @@ typedef enum {
* - `max_line` is the last line in the file to blame. The default is the last
* line of the file.
*/
typedef struct git_blame_options {
unsigned int version;

View File

@ -107,12 +107,10 @@ GIT_EXTERN(git_off_t) git_blob_rawsize(const git_blob *blob);
* The output is written into a `git_buf` which the caller must free
* when done (via `git_buf_free`).
*
* If no filters need to be applied, then the `out` buffer will just be
* populated with a pointer to the raw content of the blob. In that case,
* be careful to *not* free the blob until done with the buffer. To keep
* the data detached from the blob, call `git_buf_grow` on the buffer
* with a `want_size` of 0 and the buffer will be reallocated to be
* detached from the blob.
* If no filters need to be applied, then the `out` buffer will just
* be populated with a pointer to the raw content of the blob. In
* that case, be careful to *not* free the blob until done with the
* buffer or copy it into memory you own.
*
* @param out The git_buf to be filled in
* @param blob Pointer to the blob

View File

@ -43,12 +43,6 @@ GIT_BEGIN_DECL
*
* @param force Overwrite existing branch.
*
* @param signature The identity that will used to populate the reflog entry
*
* @param log_message The one line long message to be appended to the reflog.
* If NULL, the default is "Branch: created"; if you want something more
* useful, provide a message.
*
* @return 0, GIT_EINVALIDSPEC or an error code.
* A proper reference is written in the refs/heads namespace
* pointing to the provided target commit.
@ -58,9 +52,25 @@ GIT_EXTERN(int) git_branch_create(
git_repository *repo,
const char *branch_name,
const git_commit *target,
int force,
const git_signature *signature,
const char *log_message);
int force);
/**
* Create a new branch pointing at a target commit
*
* This behaves like `git_branch_create()` but takes an annotated
* commit, which lets you specify which extended sha syntax string was
* specified by a user, allowing for more exact reflog messages.
*
* See the documentation for `git_branch_create()`.
*
* @see git_branch_create
*/
GIT_EXTERN(int) git_branch_create_from_annotated(
git_reference **ref_out,
git_repository *repository,
const char *branch_name,
const git_annotated_commit *commit,
int force);
/**
* Delete an existing branch reference.
@ -123,19 +133,13 @@ GIT_EXTERN(void) git_branch_iterator_free(git_branch_iterator *iter);
*
* @param force Overwrite existing branch.
*
* @param signature The identity that will used to populate the reflog entry
*
* @param log_message The one line long message to be appended to the reflog
*
* @return 0 on success, GIT_EINVALIDSPEC or an error code.
*/
GIT_EXTERN(int) git_branch_move(
git_reference **out,
git_reference *branch,
const char *new_branch_name,
int force,
const git_signature *signature,
const char *log_message);
int force);
/**
* Lookup a branch by its name in a repository.
@ -244,7 +248,7 @@ GIT_EXTERN(int) git_branch_is_head(
/**
* Return the name of remote that the remote tracking branch belongs to.
*
* @param out Pointer to the user-allocated git_buf which will be filled iwth the name of the remote.
* @param out Pointer to the user-allocated git_buf which will be filled with the name of the remote.
*
* @param repo The repository where the branch lives.
*
@ -260,6 +264,17 @@ GIT_EXTERN(int) git_branch_remote_name(
git_repository *repo,
const char *canonical_branch_name);
/**
* Retrieve the name fo the upstream remote of a local branch
*
* @param buf the buffer into which to write the name
* @param repo the repository in which to look
* @param refname the full name of the branch
* @return 0 or an error code
*/
GIT_EXTERN(int) git_branch_upstream_remote(git_buf *buf, git_repository *repo, const char *refname);
/** @} */
GIT_END_DECL
#endif

View File

@ -74,7 +74,7 @@ GIT_EXTERN(void) git_buf_free(git_buf *buffer);
/**
* Resize the buffer allocation to make more space.
*
* This will attempt to grow the buffer to accomodate the target size.
* This will attempt to grow the buffer to accommodate the target size.
*
* If the buffer refers to memory that was not allocated by libgit2 (i.e.
* the `asize` field is zero), then `ptr` will be replaced with a newly
@ -105,6 +105,22 @@ GIT_EXTERN(int) git_buf_grow(git_buf *buffer, size_t target_size);
GIT_EXTERN(int) git_buf_set(
git_buf *buffer, const void *data, size_t datalen);
/**
* Check quickly if buffer looks like it contains binary data
*
* @param buf Buffer to check
* @return 1 if buffer looks like non-text data
*/
GIT_EXTERN(int) git_buf_is_binary(const git_buf *buf);
/**
* Check quickly if buffer contains a NUL byte
*
* @param buf Buffer to check
* @return 1 if buffer contains a NUL byte
*/
GIT_EXTERN(int) git_buf_contains_nul(const git_buf *buf);
GIT_END_DECL
/** @} */

View File

@ -31,7 +31,7 @@ GIT_BEGIN_DECL
* check out, the "baseline" tree of what was checked out previously, the
* working directory for actual files, and the index for staged changes.
*
* You give checkout one of four strategies for update:
* You give checkout one of three strategies for update:
*
* - `GIT_CHECKOUT_NONE` is a dry-run strategy that checks for conflicts,
* etc., but doesn't make any actual changes.
@ -40,8 +40,8 @@ GIT_BEGIN_DECL
* make the working directory match the target (including potentially
* discarding modified files).
*
* In between those are `GIT_CHECKOUT_SAFE` and `GIT_CHECKOUT_SAFE_CREATE`
* both of which only make modifications that will not lose changes.
* - `GIT_CHECKOUT_SAFE` is between these two options, it will only make
* modifications that will not lose changes.
*
* | target == baseline | target != baseline |
* ---------------------|-----------------------|----------------------|
@ -51,28 +51,21 @@ GIT_BEGIN_DECL
* workdir exists and | no action | conflict (notify |
* is != baseline | notify dirty MODIFIED | and cancel checkout) |
* ---------------------|-----------------------|----------------------|
* workdir missing, | create if SAFE_CREATE | create file |
* baseline present | notify dirty DELETED | |
* workdir missing, | notify dirty DELETED | create file |
* baseline present | | |
* ---------------------|-----------------------|----------------------|
*
* The only difference between SAFE and SAFE_CREATE is that SAFE_CREATE
* will cause a file to be checked out if it is missing from the working
* directory even if it is not modified between the target and baseline.
*
*
* To emulate `git checkout`, use `GIT_CHECKOUT_SAFE` with a checkout
* notification callback (see below) that displays information about dirty
* files. The default behavior will cancel checkout on conflicts.
*
* To emulate `git checkout-index`, use `GIT_CHECKOUT_SAFE_CREATE` with a
* To emulate `git checkout-index`, use `GIT_CHECKOUT_SAFE` with a
* notification callback that cancels the operation if a dirty-but-existing
* file is found in the working directory. This core git command isn't
* quite "force" but is sensitive about some types of changes.
*
* To emulate `git checkout -f`, use `GIT_CHECKOUT_FORCE`.
*
* To emulate `git clone` use `GIT_CHECKOUT_SAFE_CREATE` in the options.
*
*
* There are some additional flags to modified the behavior of checkout:
*
@ -104,6 +97,11 @@ GIT_BEGIN_DECL
* overwritten. Normally, files that are ignored in the working directory
* are not considered "precious" and may be overwritten if the checkout
* target contains that file.
*
* - GIT_CHECKOUT_DONT_REMOVE_EXISTING prevents checkout from removing
* files or folders that fold to the same name on case insensitive
* filesystems. This can cause files to retain their existing names
* and write through existing symbolic links.
*/
typedef enum {
GIT_CHECKOUT_NONE = 0, /**< default is a dry run, no actual updates */
@ -111,13 +109,13 @@ typedef enum {
/** Allow safe updates that cannot overwrite uncommitted data */
GIT_CHECKOUT_SAFE = (1u << 0),
/** Allow safe updates plus creation of missing files */
GIT_CHECKOUT_SAFE_CREATE = (1u << 1),
/** Allow all updates to force working directory to look like index */
GIT_CHECKOUT_FORCE = (1u << 2),
GIT_CHECKOUT_FORCE = (1u << 1),
/** Allow checkout to recreate missing files */
GIT_CHECKOUT_RECREATE_MISSING = (1u << 2),
/** Allow checkout to make safe updates even if conflicts are found */
GIT_CHECKOUT_ALLOW_CONFLICTS = (1u << 4),
@ -130,7 +128,10 @@ typedef enum {
/** Only update existing files, don't create new ones */
GIT_CHECKOUT_UPDATE_ONLY = (1u << 7),
/** Normally checkout updates index entries as it goes; this stops that */
/**
* Normally checkout updates index entries as it goes; this stops that.
* Implies `GIT_CHECKOUT_DONT_WRITE_INDEX`.
*/
GIT_CHECKOUT_DONT_UPDATE_INDEX = (1u << 8),
/** Don't refresh index/config/etc before doing checkout */
@ -158,6 +159,12 @@ typedef enum {
/** Include common ancestor data in diff3 format files for conflicts */
GIT_CHECKOUT_CONFLICT_STYLE_DIFF3 = (1u << 21),
/** Don't overwrite existing files or folders */
GIT_CHECKOUT_DONT_REMOVE_EXISTING = (1u << 22),
/** Normally checkout writes the index upon completion; this prevents that. */
GIT_CHECKOUT_DONT_WRITE_INDEX = (1u << 23),
/**
* THE FOLLOWING OPTIONS ARE NOT YET IMPLEMENTED
*/
@ -206,6 +213,12 @@ typedef enum {
GIT_CHECKOUT_NOTIFY_ALL = 0x0FFFFu
} git_checkout_notify_t;
typedef struct {
size_t mkdir_calls;
size_t stat_calls;
size_t chmod_calls;
} git_checkout_perfdata;
/** Checkout notification callback function */
typedef int (*git_checkout_notify_cb)(
git_checkout_notify_t why,
@ -222,6 +235,11 @@ typedef void (*git_checkout_progress_cb)(
size_t total_steps,
void *payload);
/** Checkout perfdata notification function */
typedef void (*git_checkout_perfdata_cb)(
const git_checkout_perfdata *perfdata,
void *payload);
/**
* Checkout options structure
*
@ -233,18 +251,18 @@ typedef void (*git_checkout_progress_cb)(
typedef struct git_checkout_options {
unsigned int version;
unsigned int checkout_strategy; /** default will be a dry run */
unsigned int checkout_strategy; /**< default will be a dry run */
int disable_filters; /** don't apply filters like CRLF conversion */
unsigned int dir_mode; /** default is 0755 */
unsigned int file_mode; /** default is 0644 or 0755 as dictated by blob */
int file_open_flags; /** default is O_CREAT | O_TRUNC | O_WRONLY */
int disable_filters; /**< don't apply filters like CRLF conversion */
unsigned int dir_mode; /**< default is 0755 */
unsigned int file_mode; /**< default is 0644 or 0755 as dictated by blob */
int file_open_flags; /**< default is O_CREAT | O_TRUNC | O_WRONLY */
unsigned int notify_flags; /** see `git_checkout_notify_t` above */
unsigned int notify_flags; /**< see `git_checkout_notify_t` above */
git_checkout_notify_cb notify_cb;
void *notify_payload;
/* Optional callback to notify the consumer of checkout progress. */
/** Optional callback to notify the consumer of checkout progress. */
git_checkout_progress_cb progress_cb;
void *progress_payload;
@ -254,13 +272,26 @@ typedef struct git_checkout_options {
*/
git_strarray paths;
git_tree *baseline; /** expected content of workdir, defaults to HEAD */
/** The expected content of the working directory; defaults to HEAD.
* If the working directory does not match this baseline information,
* that will produce a checkout conflict.
*/
git_tree *baseline;
const char *target_directory; /** alternative checkout path to workdir */
/** Like `baseline` above, though expressed as an index. This
* option overrides `baseline`.
*/
git_index *baseline_index; /**< expected content of workdir, expressed as an index. */
const char *ancestor_label; /** the name of the common ancestor side of conflicts */
const char *our_label; /** the name of the "our" side of conflicts */
const char *their_label; /** the name of the "their" side of conflicts */
const char *target_directory; /**< alternative checkout path to workdir */
const char *ancestor_label; /**< the name of the common ancestor side of conflicts */
const char *our_label; /**< the name of the "our" side of conflicts */
const char *their_label; /**< the name of the "their" side of conflicts */
/** Optional callback to notify the consumer of performance data. */
git_checkout_perfdata_cb perfdata_cb;
void *perfdata_payload;
} git_checkout_options;
#define GIT_CHECKOUT_OPTIONS_VERSION 1

View File

@ -20,29 +20,32 @@
*/
GIT_BEGIN_DECL
/**
* Cherry-pick options
*/
typedef struct {
unsigned int version;
/** For merge commits, the "mainline" is treated as the parent. */
unsigned int mainline;
git_merge_options merge_opts;
git_checkout_options checkout_opts;
} git_cherry_pick_options;
git_merge_options merge_opts; /**< Options for the merging */
git_checkout_options checkout_opts; /**< Options for the checkout */
} git_cherrypick_options;
#define GIT_CHERRY_PICK_OPTIONS_VERSION 1
#define GIT_CHERRY_PICK_OPTIONS_INIT {GIT_CHERRY_PICK_OPTIONS_VERSION, 0, GIT_MERGE_OPTIONS_INIT, GIT_CHECKOUT_OPTIONS_INIT}
#define GIT_CHERRYPICK_OPTIONS_VERSION 1
#define GIT_CHERRYPICK_OPTIONS_INIT {GIT_CHERRYPICK_OPTIONS_VERSION, 0, GIT_MERGE_OPTIONS_INIT, GIT_CHECKOUT_OPTIONS_INIT}
/**
* Initializes a `git_cherry_pick_options` with default values. Equivalent to
* creating an instance with GIT_CHERRY_PICK_OPTIONS_INIT.
* Initializes a `git_cherrypick_options` with default values. Equivalent to
* creating an instance with GIT_CHERRYPICK_OPTIONS_INIT.
*
* @param opts the `git_cherry_pick_options` struct to initialize
* @param version Version of struct; pass `GIT_CHERRY_PICK_OPTIONS_VERSION`
* @param opts the `git_cherrypick_options` struct to initialize
* @param version Version of struct; pass `GIT_CHERRYPICK_OPTIONS_VERSION`
* @return Zero on success; -1 on failure.
*/
GIT_EXTERN(int) git_cherry_pick_init_options(
git_cherry_pick_options *opts,
GIT_EXTERN(int) git_cherrypick_init_options(
git_cherrypick_options *opts,
unsigned int version);
/**
@ -53,16 +56,16 @@ GIT_EXTERN(int) git_cherry_pick_init_options(
*
* @param out pointer to store the index result in
* @param repo the repository that contains the given commits
* @param cherry_pick_commit the commit to cherry-pick
* @param cherrypick_commit the commit to cherry-pick
* @param our_commit the commit to revert against (eg, HEAD)
* @param mainline the parent of the revert commit, if it is a merge
* @param merge_options the merge options (or null for defaults)
* @return zero on success, -1 on failure.
*/
GIT_EXTERN(int) git_cherry_pick_commit(
GIT_EXTERN(int) git_cherrypick_commit(
git_index **out,
git_repository *repo,
git_commit *cherry_pick_commit,
git_commit *cherrypick_commit,
git_commit *our_commit,
unsigned int mainline,
const git_merge_options *merge_options);
@ -72,13 +75,13 @@ GIT_EXTERN(int) git_cherry_pick_commit(
*
* @param repo the repository to cherry-pick
* @param commit the commit to cherry-pick
* @param cherry_pick_options the cherry-pick options (or null for defaults)
* @param cherrypick_options the cherry-pick options (or null for defaults)
* @return zero on success, -1 on failure.
*/
GIT_EXTERN(int) git_cherry_pick(
GIT_EXTERN(int) git_cherrypick(
git_repository *repo,
git_commit *commit,
const git_cherry_pick_options *cherry_pick_options);
const git_cherrypick_options *cherrypick_options);
/** @} */
GIT_END_DECL

View File

@ -12,6 +12,7 @@
#include "indexer.h"
#include "checkout.h"
#include "remote.h"
#include "transport.h"
/**
@ -51,6 +52,47 @@ typedef enum {
GIT_CLONE_LOCAL_NO_LINKS,
} git_clone_local_t;
/**
* The signature of a function matching git_remote_create, with an additional
* void* as a callback payload.
*
* Callers of git_clone may provide a function matching this signature to override
* the remote creation and customization process during a clone operation.
*
* @param out the resulting remote
* @param repo the repository in which to create the remote
* @param name the remote's name
* @param url the remote's url
* @param payload an opaque payload
* @return 0, GIT_EINVALIDSPEC, GIT_EEXISTS or an error code
*/
typedef int (*git_remote_create_cb)(
git_remote **out,
git_repository *repo,
const char *name,
const char *url,
void *payload);
/**
* The signature of a function matchin git_repository_init, with an
* aditional void * as callback payload.
*
* Callers of git_clone my provide a function matching this signature
* to override the repository creation and customization process
* during a clone operation.
*
* @param out the resulting repository
* @param path path in which to create the repository
* @param bare whether the repository is bare. This is the value from the clone options
* @param payload payload specified by the options
* @return 0, or a negative value to indicate error
*/
typedef int (*git_repository_create_cb)(
git_repository **out,
const char *path,
int bare,
void *payload);
/**
* Clone options structure
*
@ -58,23 +100,23 @@ typedef enum {
*
* git_clone_options opts = GIT_CLONE_OPTIONS_INIT;
*/
typedef struct git_clone_options {
unsigned int version;
/**
* These options are passed to the checkout step. To disable
* checkout, set the `checkout_strategy` to
* `GIT_CHECKOUT_NONE`. Generally you will want the use
* GIT_CHECKOUT_SAFE_CREATE to create all files in the working
* directory for the newly cloned repository.
* `GIT_CHECKOUT_NONE`.
*/
git_checkout_options checkout_opts;
/**
* Callbacks to use for reporting fetch progress.
* Options which control the fetch, including callbacks.
*
* The callbacks are used for reporting fetch progress, and for acquiring
* credentials in the event they are needed.
*/
git_remote_callbacks remote_callbacks;
git_fetch_options fetch_opts;
/**
* Set to zero (false) to create a standard repo, or non-zero
@ -82,23 +124,11 @@ typedef struct git_clone_options {
*/
int bare;
/**
* Set to 1 if errors validating the remote host's certificate
* should be ignored.
*/
int ignore_cert_errors;
/**
* Whether to use a fetch or copy the object database.
*/
git_clone_local_t local;
/**
* The name to be given to the remote that will be
* created. The default is "origin".
*/
const char *remote_name;
/**
* The name of the branch to checkout. NULL means use the
* remote's default branch.
@ -106,14 +136,37 @@ typedef struct git_clone_options {
const char* checkout_branch;
/**
* The identity used when updating the reflog. NULL means to
* use the default signature using the config.
* A callback used to create the new repository into which to
* clone. If NULL, the 'bare' field will be used to determine
* whether to create a bare repository.
*/
git_signature *signature;
git_repository_create_cb repository_cb;
/**
* An opaque payload to pass to the git_repository creation callback.
* This parameter is ignored unless repository_cb is non-NULL.
*/
void *repository_cb_payload;
/**
* A callback used to create the git_remote, prior to its being
* used to perform the clone operation. See the documentation for
* git_remote_create_cb for details. This parameter may be NULL,
* indicating that git_clone should provide default behavior.
*/
git_remote_create_cb remote_cb;
/**
* An opaque payload to pass to the git_remote creation callback.
* This parameter is ignored unless remote_cb is non-NULL.
*/
void *remote_cb_payload;
} git_clone_options;
#define GIT_CLONE_OPTIONS_VERSION 1
#define GIT_CLONE_OPTIONS_INIT {GIT_CLONE_OPTIONS_VERSION, {GIT_CHECKOUT_OPTIONS_VERSION, GIT_CHECKOUT_SAFE_CREATE}, GIT_REMOTE_CALLBACKS_INIT}
#define GIT_CLONE_OPTIONS_INIT { GIT_CLONE_OPTIONS_VERSION, \
{ GIT_CHECKOUT_OPTIONS_VERSION, GIT_CHECKOUT_SAFE }, \
GIT_FETCH_OPTIONS_INIT }
/**
* Initializes a `git_clone_options` with default values. Equivalent to
@ -130,9 +183,9 @@ GIT_EXTERN(int) git_clone_init_options(
/**
* Clone a remote repository.
*
* This version handles the simple case. If you'd like to create the
* repository or remote with non-default settings, you can create and
* configure them and then use `git_clone_into()`.
* By default this creates its repository and initial remote to match
* git's defaults. You can use the options in the callback to
* customize how these are created.
*
* @param out pointer that will receive the resulting repository object
* @param url the remote repository to clone
@ -149,59 +202,6 @@ GIT_EXTERN(int) git_clone(
const char *local_path,
const git_clone_options *options);
/**
* Clone into a repository
*
* After creating the repository and remote and configuring them for
* paths and callbacks respectively, you can call this function to
* perform the clone operation and optionally checkout files.
*
* @param repo the repository to use
* @param remote the remote repository to clone from
* @param co_opts options to use during checkout
* @param branch the branch to checkout after the clone, pass NULL for the
* remote's default branch
* @param signature The identity used when updating the reflog.
* @return 0 on success, any non-zero return value from a callback
* function, or a negative value to indicate an error (use
* `giterr_last` for a detailed error message)
*/
GIT_EXTERN(int) git_clone_into(
git_repository *repo,
git_remote *remote,
const git_checkout_options *co_opts,
const char *branch,
const git_signature *signature);
/**
* Perform a local clone into a repository
*
* A "local clone" bypasses any git-aware protocols and simply copies
* over the object database from the source repository. It is often
* faster than a git-aware clone, but no verification of the data is
* performed, and can copy over too much data.
*
* @param repo the repository to use
* @param remote the remote repository to clone from
* @param co_opts options to use during checkout
* @param branch the branch to checkout after the clone, pass NULL for the
* remote's default branch
* @param link wether to use hardlinks instead of copying
* objects. This is only possible if both repositories are on the same
* filesystem.
* @param signature the identity used when updating the reflog
* @return 0 on success, any non-zero return value from a callback
* function, or a negative value to indicate an error (use
* `giterr_last` for a detailed error message)
*/
GIT_EXTERN(int) git_clone_local_into(
git_repository *repo,
git_remote *remote,
const git_checkout_options *co_opts,
const char *branch,
int link,
const git_signature *signature);
/** @} */
GIT_END_DECL
#endif

View File

@ -239,6 +239,17 @@ GIT_EXTERN(int) git_commit_nth_gen_ancestor(
const git_commit *commit,
unsigned int n);
/**
* Get an arbitrary header field
*
* @param out the buffer to fill
* @param commit the commit to look in
* @param field the header field to return
* @return 0 on succeess, GIT_ENOTFOUND if the field does not exist,
* or an error code
*/
GIT_EXTERN(int) git_commit_header_field(git_buf *out, const git_commit *commit, const char *field);
/**
* Create new commit in the repository from a list of `git_object` pointers
*

View File

@ -123,7 +123,12 @@ typedef enum {
*/
GIT_EXTERN(int) git_libgit2_features(void);
/**
* Global library options
*
* These are used to select which global option to set or get and are
* used in `git_libgit2_opts()`.
*/
typedef enum {
GIT_OPT_GET_MWINDOW_SIZE,
GIT_OPT_SET_MWINDOW_SIZE,
@ -136,7 +141,8 @@ typedef enum {
GIT_OPT_ENABLE_CACHING,
GIT_OPT_GET_CACHED_MEMORY,
GIT_OPT_GET_TEMPLATE_PATH,
GIT_OPT_SET_TEMPLATE_PATH
GIT_OPT_SET_TEMPLATE_PATH,
GIT_OPT_SET_SSL_CERT_LOCATIONS,
} git_libgit2_opt_t;
/**
@ -221,6 +227,17 @@ typedef enum {
* >
* > - `path` directory of template.
*
* * opts(GIT_OPT_SET_SSL_CERT_LOCATIONS, const char *file, const char *path)
*
* > Set the SSL certificate-authority locations.
* >
* > - `file` is the location of a file containing several
* > certificates concatenated together.
* > - `path` is the location of a directory holding several
* > certificates, one per file.
* >
* > Either parameter may be `NULL`, but not both.
*
* @param option Option key
* @param ... value to set the option
* @return 0 on success, <0 on failure

View File

@ -55,15 +55,28 @@ typedef enum {
GIT_CONFIG_HIGHEST_LEVEL = -1,
} git_config_level_t;
typedef struct {
const char *name;
const char *value;
git_config_level_t level;
/**
* An entry in a configuration file
*/
typedef struct git_config_entry {
const char *name; /**< Name of the entry (normalised) */
const char *value; /**< String value of the entry */
git_config_level_t level; /**< Which config file this was found in */
void (*free)(struct git_config_entry *entry); /**< Free function for this entry */
void *payload; /**< Opaque value for the free function. Do not read or write */
} git_config_entry;
/**
* Free a config entry
*/
GIT_EXTERN(void) git_config_entry_free(git_config_entry *);
typedef int (*git_config_foreach_cb)(const git_config_entry *, void *);
typedef struct git_config_iterator git_config_iterator;
/**
* Config var type
*/
typedef enum {
GIT_CVAR_FALSE = 0,
GIT_CVAR_TRUE = 1,
@ -71,6 +84,9 @@ typedef enum {
GIT_CVAR_STRING
} git_cvar_t;
/**
* Mapping from config variables to values.
*/
typedef struct {
git_cvar_t cvar_type;
const char *str_match;
@ -242,20 +258,6 @@ GIT_EXTERN(int) git_config_open_global(git_config **out, git_config *config);
*/
GIT_EXTERN(int) git_config_snapshot(git_config **out, git_config *config);
/**
* Reload changed config files
*
* A config file may be changed on disk out from under the in-memory
* config object. This function causes us to look for files that have
* been modified since we last loaded them and refresh the config with
* the latest information.
*
* @param cfg The configuration to refresh
* @return 0 or an error code
*/
GIT_EXTERN(int) git_config_refresh(git_config *cfg);
/**
* Free the configuration and its associated memory and files
*
@ -266,16 +268,15 @@ GIT_EXTERN(void) git_config_free(git_config *cfg);
/**
* Get the git_config_entry of a config variable.
*
* The git_config_entry is owned by the config and should not be freed by the
* user.
* Free the git_config_entry after use with `git_config_entry_free()`.
*
* @param out pointer to the variable git_config_entry
* @param cfg where to look for the variable
* @param name the variable's name
* @return 0 or an error code
*/
GIT_EXTERN(int) git_config_get_entry(
const git_config_entry **out,
git_config_entry **out,
const git_config *cfg,
const char *name);
@ -284,7 +285,7 @@ GIT_EXTERN(int) git_config_get_entry(
*
* All config files will be looked into, in the order of their
* defined level. A higher level means a higher priority. The
* first occurence of the variable will be returned here.
* first occurrence of the variable will be returned here.
*
* @param out pointer to the variable where the value should be stored
* @param cfg where to look for the variable
@ -325,23 +326,57 @@ GIT_EXTERN(int) git_config_get_int64(int64_t *out, const git_config *cfg, const
GIT_EXTERN(int) git_config_get_bool(int *out, const git_config *cfg, const char *name);
/**
* Get the value of a string config variable.
* Get the value of a path config variable.
*
* The string is owned by the variable and should not be freed by the
* user. The pointer will be valid until the next operation on this
* config object.
* A leading '~' will be expanded to the global search path (which
* defaults to the user's home directory but can be overridden via
* `git_libgit2_opts()`.
*
* All config files will be looked into, in the order of their
* defined level. A higher level means a higher priority. The
* first occurrence of the variable will be returned here.
*
* @param out pointer to the variable's value
* @param out the buffer in which to store the result
* @param cfg where to look for the variable
* @param name the variable's name
* @return 0 or an error code
*/
GIT_EXTERN(int) git_config_get_path(git_buf *out, const git_config *cfg, const char *name);
/**
* Get the value of a string config variable.
*
* This function can only be used on snapshot config objects. The
* string is owned by the config and should not be freed by the
* user. The pointer will be valid until the config is freed.
*
* All config files will be looked into, in the order of their
* defined level. A higher level means a higher priority. The
* first occurrence of the variable will be returned here.
*
* @param out pointer to the string
* @param cfg where to look for the variable
* @param name the variable's name
* @return 0 or an error code
*/
GIT_EXTERN(int) git_config_get_string(const char **out, const git_config *cfg, const char *name);
/**
* Get the value of a string config variable.
*
* The value of the config will be copied into the buffer.
*
* All config files will be looked into, in the order of their
* defined level. A higher level means a higher priority. The
* first occurrence of the variable will be returned here.
*
* @param out buffer in which to store the string
* @param cfg where to look for the variable
* @param name the variable's name
* @return 0 or an error code
*/
GIT_EXTERN(int) git_config_get_string_buf(git_buf *out, const git_config *cfg, const char *name);
/**
* Get each value of a multivar in a foreach callback
*
@ -620,6 +655,20 @@ GIT_EXTERN(int) git_config_parse_int32(int32_t *out, const char *value);
*/
GIT_EXTERN(int) git_config_parse_int64(int64_t *out, const char *value);
/**
* Parse a string value as a path.
*
* A leading '~' will be expanded to the global search path (which
* defaults to the user's home directory but can be overridden via
* `git_libgit2_opts()`.
*
* If the value does not begin with a tilde, the input will be
* returned.
*
* @param out placae to store the result of parsing
* @param value the path to evaluate
*/
GIT_EXTERN(int) git_config_parse_path(git_buf *out, const char *value);
/**
* Perform an operation on each config variable in given config backend

View File

@ -22,8 +22,8 @@ GIT_BEGIN_DECL
* Payload for git_cred_stock_userpass_plaintext.
*/
typedef struct git_cred_userpass_payload {
char *username;
char *password;
const char *username;
const char *password;
} git_cred_userpass_payload;

163
include/git2/describe.h Normal file
View File

@ -0,0 +1,163 @@
/*
* Copyright (C) the libgit2 contributors. All rights reserved.
*
* This file is part of libgit2, distributed under the GNU GPL v2 with
* a Linking Exception. For full terms see the included COPYING file.
*/
#ifndef INCLUDE_git_describe_h__
#define INCLUDE_git_describe_h__
#include "common.h"
#include "types.h"
#include "buffer.h"
/**
* @file git2/describe.h
* @brief Git describing routines
* @defgroup git_describe Git describing routines
* @ingroup Git
* @{
*/
GIT_BEGIN_DECL
/**
* Reference lookup strategy
*
* These behave like the --tags and --all optios to git-describe,
* namely they say to look for any reference in either refs/tags/ or
* refs/ respectively.
*/
typedef enum {
GIT_DESCRIBE_DEFAULT,
GIT_DESCRIBE_TAGS,
GIT_DESCRIBE_ALL,
} git_describe_strategy_t;
/**
* Describe options structure
*
* Initialize with `GIT_DESCRIBE_OPTIONS_INIT` macro to correctly set
* the `version` field. E.g.
*
* git_describe_options opts = GIT_DESCRIBE_OPTIONS_INIT;
*/
typedef struct git_describe_options {
unsigned int version;
unsigned int max_candidates_tags; /** default: 10 */
unsigned int describe_strategy; /** default: GIT_DESCRIBE_DEFAULT */
const char *pattern;
/**
* When calculating the distance from the matching tag or
* reference, only walk down the first-parent ancestry.
*/
int only_follow_first_parent;
/**
* If no matching tag or reference is found, the describe
* operation would normally fail. If this option is set, it
* will instead fall back to showing the full id of the
* commit.
*/
int show_commit_oid_as_fallback;
} git_describe_options;
#define GIT_DESCRIBE_DEFAULT_MAX_CANDIDATES_TAGS 10
#define GIT_DESCRIBE_DEFAULT_ABBREVIATED_SIZE 7
#define GIT_DESCRIBE_OPTIONS_VERSION 1
#define GIT_DESCRIBE_OPTIONS_INIT { \
GIT_DESCRIBE_OPTIONS_VERSION, \
GIT_DESCRIBE_DEFAULT_MAX_CANDIDATES_TAGS, \
}
GIT_EXTERN(int) git_describe_init_options(git_describe_options *opts, unsigned int version);
/**
* Options for formatting the describe string
*/
typedef struct {
unsigned int version;
/**
* Size of the abbreviated commit id to use. This value is the
* lower bound for the length of the abbreviated string. The
* default is 7.
*/
unsigned int abbreviated_size;
/**
* Set to use the long format even when a shorter name could be used.
*/
int always_use_long_format;
/**
* If the workdir is dirty and this is set, this string will
* be appended to the description string.
*/
const char *dirty_suffix;
} git_describe_format_options;
#define GIT_DESCRIBE_FORMAT_OPTIONS_VERSION 1
#define GIT_DESCRIBE_FORMAT_OPTIONS_INIT { \
GIT_DESCRIBE_FORMAT_OPTIONS_VERSION, \
GIT_DESCRIBE_DEFAULT_ABBREVIATED_SIZE, \
}
GIT_EXTERN(int) git_describe_init_format_options(git_describe_format_options *opts, unsigned int version);
typedef struct git_describe_result git_describe_result;
/**
* Describe a commit
*
* Perform the describe operation on the given committish object.
*
* @param result pointer to store the result. You must free this once
* you're done with it.
* @param committish a committish to describe
* @param opts the lookup options
*/
GIT_EXTERN(int) git_describe_commit(
git_describe_result **result,
git_object *committish,
git_describe_options *opts);
/**
* Describe a commit
*
* Perform the describe operation on the current commit and the
* worktree. After peforming describe on HEAD, a status is run and the
* description is considered to be dirty if there are.
*
* @param out pointer to store the result. You must free this once
* you're done with it.
* @param repo the repository in which to perform the describe
* @param opts the lookup options
*/
GIT_EXTERN(int) git_describe_workdir(
git_describe_result **out,
git_repository *repo,
git_describe_options *opts);
/**
* Print the describe result to a buffer
*
* @param out The buffer to store the result
* @param result the result from `git_describe_commit()` or
* `git_describe_workdir()`.
* @param opts the formatting options
*/
GIT_EXTERN(int) git_describe_format(
git_buf *out,
const git_describe_result *result,
const git_describe_format_options *opts);
/**
* Free the describe result.
*/
GIT_EXTERN(void) git_describe_result_free(git_describe_result *result);
/** @} */
GIT_END_DECL
#endif

View File

@ -124,6 +124,11 @@ typedef enum {
/** Use case insensitive filename comparisons */
GIT_DIFF_IGNORE_CASE = (1u << 10),
/** May be combined with `GIT_DIFF_IGNORE_CASE` to specify that a file
* that has changed case will be returned as an add/delete pair.
*/
GIT_DIFF_INCLUDE_CASECHANGE = (1u << 11),
/** If the pathspec is set in the diff options, this flags means to
* apply it as an exact match instead of as an fnmatch pattern.
*/
@ -152,6 +157,12 @@ typedef enum {
*/
GIT_DIFF_UPDATE_INDEX = (1u << 15),
/** Include unreadable files in the diff */
GIT_DIFF_INCLUDE_UNREADABLE = (1u << 16),
/** Include unreadable files in the diff */
GIT_DIFF_INCLUDE_UNREADABLE_AS_UNTRACKED = (1u << 17),
/*
* Options controlling how output will be generated
*/
@ -214,7 +225,8 @@ typedef struct git_diff git_diff;
typedef enum {
GIT_DIFF_FLAG_BINARY = (1u << 0), /**< file(s) treated as binary data */
GIT_DIFF_FLAG_NOT_BINARY = (1u << 1), /**< file(s) treated as text data */
GIT_DIFF_FLAG_VALID_ID = (1u << 2), /**< `id` value is known correct */
GIT_DIFF_FLAG_VALID_ID = (1u << 2), /**< `id` value is known correct */
GIT_DIFF_FLAG_EXISTS = (1u << 3), /**< file exists at this side of the delta */
} git_diff_flag_t;
/**
@ -228,15 +240,17 @@ typedef enum {
* DELETED pairs).
*/
typedef enum {
GIT_DELTA_UNMODIFIED = 0, /**< no changes */
GIT_DELTA_ADDED = 1, /**< entry does not exist in old version */
GIT_DELTA_DELETED = 2, /**< entry does not exist in new version */
GIT_DELTA_MODIFIED = 3, /**< entry content changed between old and new */
GIT_DELTA_RENAMED = 4, /**< entry was renamed between old and new */
GIT_DELTA_COPIED = 5, /**< entry was copied from another old entry */
GIT_DELTA_IGNORED = 6, /**< entry is ignored item in workdir */
GIT_DELTA_UNTRACKED = 7, /**< entry is untracked item in workdir */
GIT_DELTA_TYPECHANGE = 8, /**< type of entry changed between old and new */
GIT_DELTA_UNMODIFIED = 0, /**< no changes */
GIT_DELTA_ADDED = 1, /**< entry does not exist in old version */
GIT_DELTA_DELETED = 2, /**< entry does not exist in new version */
GIT_DELTA_MODIFIED = 3, /**< entry content changed between old and new */
GIT_DELTA_RENAMED = 4, /**< entry was renamed between old and new */
GIT_DELTA_COPIED = 5, /**< entry was copied from another old entry */
GIT_DELTA_IGNORED = 6, /**< entry is ignored item in workdir */
GIT_DELTA_UNTRACKED = 7, /**< entry is untracked item in workdir */
GIT_DELTA_TYPECHANGE = 8, /**< type of entry changed between old and new */
GIT_DELTA_UNREADABLE = 9, /**< entry is unreadable */
GIT_DELTA_CONFLICTED = 10, /**< entry in the index is conflicted */
} git_delta_t;
/**
@ -370,8 +384,8 @@ typedef struct {
/* options controlling how to diff text is generated */
uint16_t context_lines; /**< defaults to 3 */
uint16_t interhunk_lines; /**< defaults to 0 */
uint32_t context_lines; /**< defaults to 3 */
uint32_t interhunk_lines; /**< defaults to 0 */
uint16_t id_abbrev; /**< default 'core.abbrev' or 7 if unset */
git_off_t max_size; /**< defaults to 512MB */
const char *old_prefix; /**< defaults to "a" */
@ -385,7 +399,7 @@ typedef struct {
* `git_diff_options_init` programmatic initialization.
*/
#define GIT_DIFF_OPTIONS_INIT \
{GIT_DIFF_OPTIONS_VERSION, 0, GIT_SUBMODULE_IGNORE_DEFAULT, {NULL,0}, NULL, NULL, 3}
{GIT_DIFF_OPTIONS_VERSION, 0, GIT_SUBMODULE_IGNORE_UNSPECIFIED, {NULL,0}, NULL, NULL, 3}
/**
* Initializes a `git_diff_options` with default values. Equivalent to
@ -411,18 +425,64 @@ typedef int (*git_diff_file_cb)(
float progress,
void *payload);
/**
* When producing a binary diff, the binary data returned will be
* either the deflated full ("literal") contents of the file, or
* the deflated binary delta between the two sides (whichever is
* smaller).
*/
typedef enum {
/** There is no binary delta. */
GIT_DIFF_BINARY_NONE,
/** The binary data is the literal contents of the file. */
GIT_DIFF_BINARY_LITERAL,
/** The binary data is the delta from one side to the other. */
GIT_DIFF_BINARY_DELTA,
} git_diff_binary_t;
/** The contents of one of the files in a binary diff. */
typedef struct {
/** The type of binary data for this file. */
git_diff_binary_t type;
/** The binary data, deflated. */
const char *data;
/** The length of the binary data. */
size_t datalen;
/** The length of the binary data after inflation. */
size_t inflatedlen;
} git_diff_binary_file;
/** Structure describing the binary contents of a diff. */
typedef struct {
git_diff_binary_file old_file; /**< The contents of the old file. */
git_diff_binary_file new_file; /**< The contents of the new file. */
} git_diff_binary;
/**
* When iterating over a diff, callback that will be made for
* binary content within the diff.
*/
typedef int(*git_diff_binary_cb)(
const git_diff_delta *delta,
const git_diff_binary *binary,
void *payload);
/**
* Structure describing a hunk of a diff.
*/
typedef struct git_diff_hunk git_diff_hunk;
struct git_diff_hunk {
typedef struct {
int old_start; /**< Starting line number in old_file */
int old_lines; /**< Number of lines in old_file */
int new_start; /**< Starting line number in new_file */
int new_lines; /**< Number of lines in new_file */
size_t header_len; /**< Number of bytes in header text */
char header[128]; /**< Header text, NUL-byte terminated */
};
} git_diff_hunk;
/**
* When iterating over a diff, callback that will be made per hunk.
@ -462,8 +522,7 @@ typedef enum {
/**
* Structure describing a line (or data span) of a diff.
*/
typedef struct git_diff_line git_diff_line;
struct git_diff_line {
typedef struct {
char origin; /**< A git_diff_line_t value */
int old_lineno; /**< Line number in old file or -1 for added line */
int new_lineno; /**< Line number in new file or -1 for deleted line */
@ -471,7 +530,7 @@ struct git_diff_line {
size_t content_len; /**< Number of bytes of data */
git_off_t content_offset; /**< Offset in the original file to the content */
const char *content; /**< Pointer to diff text, not NUL-byte terminated */
};
} git_diff_line;
/**
* When iterating over a diff, callback that will be made per text diff
@ -844,9 +903,9 @@ GIT_EXTERN(size_t) git_diff_num_deltas_of_type(
/**
* Return the diff delta for an entry in the diff list.
*
* The `git_delta` pointer points to internal data and you do not have
* to release it when you are done with it. It will go away when the
* `git_diff` (or any associated `git_patch`) goes away.
* The `git_diff_delta` pointer points to internal data and you do not
* have to release it when you are done with it. It will go away when
* the * `git_diff` (or any associated `git_patch`) goes away.
*
* Note that the flags on the delta related to whether it has binary
* content or not may not be set if there are no attributes set for the
@ -885,6 +944,7 @@ GIT_EXTERN(int) git_diff_is_sorted_icase(const git_diff *diff);
*
* @param diff A git_diff generated by one of the above functions.
* @param file_cb Callback function to make per file in the diff.
* @param binary_cb Optional callback to make for binary files.
* @param hunk_cb Optional callback to make per hunk of text diff. This
* callback is called to describe a range of lines in the
* diff. It will not be issued for binary files.
@ -897,6 +957,7 @@ GIT_EXTERN(int) git_diff_is_sorted_icase(const git_diff *diff);
GIT_EXTERN(int) git_diff_foreach(
git_diff *diff,
git_diff_file_cb file_cb,
git_diff_binary_cb binary_cb,
git_diff_hunk_cb hunk_cb,
git_diff_line_cb line_cb,
void *payload);
@ -972,6 +1033,7 @@ GIT_EXTERN(int) git_diff_print(
* @param new_as_path Treat new blob as if it had this filename; can be NULL
* @param options Options for diff, or NULL for default options
* @param file_cb Callback for "file"; made once if there is a diff; can be NULL
* @param binary_cb Callback for binary files; can be NULL
* @param hunk_cb Callback for each hunk in diff; can be NULL
* @param line_cb Callback for each line in diff; can be NULL
* @param payload Payload passed to each callback function
@ -984,6 +1046,7 @@ GIT_EXTERN(int) git_diff_blobs(
const char *new_as_path,
const git_diff_options *options,
git_diff_file_cb file_cb,
git_diff_binary_cb binary_cb,
git_diff_hunk_cb hunk_cb,
git_diff_line_cb line_cb,
void *payload);
@ -1007,6 +1070,7 @@ GIT_EXTERN(int) git_diff_blobs(
* @param buffer_as_path Treat buffer as if it had this filename; can be NULL
* @param options Options for diff, or NULL for default options
* @param file_cb Callback for "file"; made once if there is a diff; can be NULL
* @param binary_cb Callback for binary files; can be NULL
* @param hunk_cb Callback for each hunk in diff; can be NULL
* @param line_cb Callback for each line in diff; can be NULL
* @param payload Payload passed to each callback function
@ -1020,6 +1084,7 @@ GIT_EXTERN(int) git_diff_blob_to_buffer(
const char *buffer_as_path,
const git_diff_options *options,
git_diff_file_cb file_cb,
git_diff_binary_cb binary_cb,
git_diff_hunk_cb hunk_cb,
git_diff_line_cb line_cb,
void *payload);
@ -1039,6 +1104,7 @@ GIT_EXTERN(int) git_diff_blob_to_buffer(
* @param new_as_path Treat buffer as if it had this filename; can be NULL
* @param options Options for diff, or NULL for default options
* @param file_cb Callback for "file"; made once if there is a diff; can be NULL
* @param binary_cb Callback for binary files; can be NULL
* @param hunk_cb Callback for each hunk in diff; can be NULL
* @param line_cb Callback for each line in diff; can be NULL
* @param payload Payload passed to each callback function
@ -1053,6 +1119,7 @@ GIT_EXTERN(int) git_diff_buffers(
const char *new_as_path,
const git_diff_options *options,
git_diff_file_cb file_cb,
git_diff_binary_cb binary_cb,
git_diff_hunk_cb hunk_cb,
git_diff_line_cb line_cb,
void *payload);

View File

@ -38,9 +38,16 @@ typedef enum {
GIT_EUNMERGED = -10, /**< Merge in progress prevented operation */
GIT_ENONFASTFORWARD = -11, /**< Reference was not fast-forwardable */
GIT_EINVALIDSPEC = -12, /**< Name/ref spec was not in a valid format */
GIT_EMERGECONFLICT = -13, /**< Merge conflicts prevented operation */
GIT_ECONFLICT = -13, /**< Checkout conflicts prevented operation */
GIT_ELOCKED = -14, /**< Lock file prevented operation */
GIT_EMODIFIED = -15, /**< Reference value does not match expected */
GIT_EAUTH = -16, /**< Authentication error */
GIT_ECERTIFICATE = -17, /**< Server certificate is invalid */
GIT_EAPPLIED = -18, /**< Patch/merge has already been applied */
GIT_EPEEL = -19, /**< The requested peel operation is not possible */
GIT_EEOF = -20, /**< Unexpected EOF */
GIT_EINVALID = -21, /**< Invalid operation or input */
GIT_EUNCOMMITTED = -22, /**< Uncommitted changes in index prevented operation */
GIT_PASSTHROUGH = -30, /**< Internal only */
GIT_ITEROVER = -31, /**< Signals end of iteration with iterator */
@ -87,6 +94,9 @@ typedef enum {
GITERR_REVERT,
GITERR_CALLBACK,
GITERR_CHERRYPICK,
GITERR_DESCRIBE,
GITERR_REBASE,
GITERR_FILESYSTEM
} git_error_t;
/**

View File

@ -35,10 +35,13 @@ typedef enum {
GIT_FILTER_CLEAN = GIT_FILTER_TO_ODB,
} git_filter_mode_t;
/**
* Filter option flags.
*/
typedef enum {
GIT_FILTER_OPT_DEFAULT = 0u,
GIT_FILTER_OPT_ALLOW_UNSAFE = (1u << 0),
} git_filter_opt_t;
GIT_FILTER_DEFAULT = 0u,
GIT_FILTER_ALLOW_UNSAFE = (1u << 0),
} git_filter_flag_t;
/**
* A filter that can transform file data
@ -80,7 +83,7 @@ typedef struct git_filter_list git_filter_list;
* @param blob The blob to which the filter will be applied (if known)
* @param path Relative path of the file to be filtered
* @param mode Filtering direction (WT->ODB or ODB->WT)
* @param options Combination of `git_filter_opt_t` flags
* @param flags Combination of `git_filter_flag_t` flags
* @return 0 on success (which could still return NULL if no filters are
* needed for the requested file), <0 on error
*/
@ -90,7 +93,23 @@ GIT_EXTERN(int) git_filter_list_load(
git_blob *blob, /* can be NULL */
const char *path,
git_filter_mode_t mode,
uint32_t options);
uint32_t flags);
/**
* Query the filter list to see if a given filter (by name) will run.
* The built-in filters "crlf" and "ident" can be queried, otherwise this
* is the name of the filter specified by the filter attribute.
*
* This will return 0 if the given filter is not in the list, or 1 if
* the filter will be applied.
*
* @param filters A loaded git_filter_list (or NULL)
* @param name The name of the filter to query
* @return 1 if the filter is in the list, 0 otherwise
*/
GIT_EXTERN(int) git_filter_list_contains(
git_filter_list *filters,
const char *name);
/**
* Apply filter list to a data buffer.
@ -118,7 +137,13 @@ GIT_EXTERN(int) git_filter_list_apply_to_data(
git_buf *in);
/**
* Apply filter list to the contents of a file on disk
* Apply a filter list to the contents of a file on disk
*
* @param out buffer into which to store the filtered file
* @param filters the list of filters to apply
* @param repo the repository in which to perform the filtering
* @param path the path of the file to filter, a relative path will be
* taken as relative to the workdir
*/
GIT_EXTERN(int) git_filter_list_apply_to_file(
git_buf *out,
@ -127,13 +152,56 @@ GIT_EXTERN(int) git_filter_list_apply_to_file(
const char *path);
/**
* Apply filter list to the contents of a blob
* Apply a filter list to the contents of a blob
*
* @param out buffer into which to store the filtered file
* @param filters the list of filters to apply
* @param blob the blob to filter
*/
GIT_EXTERN(int) git_filter_list_apply_to_blob(
git_buf *out,
git_filter_list *filters,
git_blob *blob);
/**
* Apply a filter list to an arbitrary buffer as a stream
*
* @param filters the list of filters to apply
* @param data the buffer to filter
* @param target the stream into which the data will be written
*/
GIT_EXTERN(int) git_filter_list_stream_data(
git_filter_list *filters,
git_buf *data,
git_writestream *target);
/**
* Apply a filter list to a file as a stream
*
* @param filters the list of filters to apply
* @param repo the repository in which to perform the filtering
* @param path the path of the file to filter, a relative path will be
* taken as relative to the workdir
* @param target the stream into which the data will be written
*/
GIT_EXTERN(int) git_filter_list_stream_file(
git_filter_list *filters,
git_repository *repo,
const char *path,
git_writestream *target);
/**
* Apply a filter list to a blob as a stream
*
* @param filters the list of filters to apply
* @param blob the blob to filter
* @param target the stream into which the data will be written
*/
GIT_EXTERN(int) git_filter_list_stream_blob(
git_filter_list *filters,
git_blob *blob,
git_writestream *target);
/**
* Free a git_filter_list
*

44
include/git2/global.h Normal file
View File

@ -0,0 +1,44 @@
/*
* Copyright (C) the libgit2 contributors. All rights reserved.
*
* This file is part of libgit2, distributed under the GNU GPL v2 with
* a Linking Exception. For full terms see the included COPYING file.
*/
#ifndef INCLUDE_git_global_h__
#define INCLUDE_git_global_h__
#include "common.h"
GIT_BEGIN_DECL
/**
* Init the global state
*
* This function must the called before any other libgit2 function in
* order to set up global state and threading.
*
* This function may be called multiple times - it will return the number
* of times the initialization has been called (including this one) that have
* not subsequently been shutdown.
*
* @return the number of initializations of the library, or an error code.
*/
GIT_EXTERN(int) git_libgit2_init(void);
/**
* Shutdown the global state
*
* Clean up the global state and threading context after calling it as
* many times as `git_libgit2_init()` was called - it will return the
* number of remainining initializations that have not been shutdown
* (after this one).
*
* @return the number of remaining initializations of the library, or an
* error code.
*/
GIT_EXTERN(int) git_libgit2_shutdown(void);
/** @} */
GIT_END_DECL
#endif

View File

@ -24,9 +24,9 @@ GIT_BEGIN_DECL
/** Time structure used in a git index entry */
typedef struct {
git_time_t seconds;
int32_t seconds;
/* nsec should not be stored as time_t compatible */
unsigned int nanoseconds;
uint32_t nanoseconds;
} git_index_time;
/**
@ -44,22 +44,27 @@ typedef struct {
* accessed via the later `GIT_IDXENTRY_...` bitmasks below. Some of
* these flags are read from and written to disk, but some are set aside
* for in-memory only reference.
*
* Note that the time and size fields are truncated to 32 bits. This
* is enough to detect changes, which is enough for the index to
* function as a cache, but it should not be taken as an authoritative
* source for that data.
*/
typedef struct git_index_entry {
git_index_time ctime;
git_index_time mtime;
unsigned int dev;
unsigned int ino;
unsigned int mode;
unsigned int uid;
unsigned int gid;
git_off_t file_size;
uint32_t dev;
uint32_t ino;
uint32_t mode;
uint32_t uid;
uint32_t gid;
uint32_t file_size;
git_oid id;
unsigned short flags;
unsigned short flags_extended;
uint16_t flags;
uint16_t flags_extended;
const char *path;
} git_index_entry;
@ -75,6 +80,9 @@ typedef struct git_index_entry {
#define GIT_IDXENTRY_STAGEMASK (0x3000)
#define GIT_IDXENTRY_STAGESHIFT 12
/**
* Flags for index entries
*/
typedef enum {
GIT_IDXENTRY_EXTENDED = (0x4000),
GIT_IDXENTRY_VALID = (0x8000),
@ -265,6 +273,18 @@ GIT_EXTERN(int) git_index_write(git_index *index);
*/
GIT_EXTERN(const char *) git_index_path(const git_index *index);
/**
* Get the checksum of the index
*
* This checksum is the SHA-1 hash over the index file (except the
* last 20 bytes which are the checksum itself). In cases where the
* index does not exist on-disk, it will be zeroed out.
*
* @param index an existing index object
* @return a pointer to the checksum of the index
*/
GIT_EXTERN(const git_oid *) git_index_checksum(git_index *index);
/**
* Read a tree into the index file with stats
*
@ -422,6 +442,15 @@ GIT_EXTERN(int) git_index_add(git_index *index, const git_index_entry *source_en
*/
GIT_EXTERN(int) git_index_entry_stage(const git_index_entry *entry);
/**
* Return whether the given index entry is a conflict (has a high stage
* entry). This is simply shorthand for `git_index_entry_stage > 0`.
*
* @param entry The entry
* @return 1 if the entry is a conflict entry, 0 otherwise
*/
GIT_EXTERN(int) git_index_entry_is_conflict(const git_index_entry *entry);
/**@}*/
/** @name Workdir Index Entry Functions
@ -453,6 +482,38 @@ GIT_EXTERN(int) git_index_entry_stage(const git_index_entry *entry);
*/
GIT_EXTERN(int) git_index_add_bypath(git_index *index, const char *path);
/**
* Add or update an index entry from a buffer in memory
*
* This method will create a blob in the repository that owns the
* index and then add the index entry to the index. The `path` of the
* entry represents the position of the blob relative to the
* repository's root folder.
*
* If a previous index entry exists that has the same path as the
* given 'entry', it will be replaced. Otherwise, the 'entry' will be
* added. The `id` and the `file_size` of the 'entry' are updated with the
* real value of the blob.
*
* This forces the file to be added to the index, not looking
* at gitignore rules. Those rules can be evaluated through
* the git_status APIs (in status.h) before calling this.
*
* If this file currently is the result of a merge conflict, this
* file will no longer be marked as conflicting. The data about
* the conflict will be moved to the "resolve undo" (REUC) section.
*
* @param index an existing index object
* @param entry filename to add
* @param buffer data to be written into the blob
* @param len length of the data
* @return 0 or an error code
*/
GIT_EXTERN(int) git_index_add_frombuffer(
git_index *index,
const git_index_entry *entry,
const void *buffer, size_t len);
/**
* Remove an index entry corresponding to a file on disk
*
@ -591,7 +652,8 @@ GIT_EXTERN(int) git_index_find(size_t *at_pos, git_index *index, const char *pat
/**@{*/
/**
* Add or update index entries to represent a conflict
* Add or update index entries to represent a conflict. Any staged
* entries that exist at the given paths will be removed.
*
* The entries are the entries from the tree included in the merge. Any
* entry may be null to indicate that that file was not present in the

View File

@ -10,8 +10,10 @@
#include "common.h"
#include "types.h"
#include "oid.h"
#include "oidarray.h"
#include "checkout.h"
#include "index.h"
#include "annotated_commit.h"
/**
* @file git2/merge.h
@ -61,7 +63,7 @@ GIT_EXTERN(int) git_merge_file_init_input(
/**
* Flags for `git_merge_tree` options. A combination of these flags can be
* passed in via the `flags` value in the `git_merge_options`.
* passed in via the `tree_flags` value in the `git_merge_options`.
*/
typedef enum {
/**
@ -108,20 +110,41 @@ typedef enum {
GIT_MERGE_FILE_FAVOR_UNION = 3,
} git_merge_file_favor_t;
/**
* File merging flags
*/
typedef enum {
/* Defaults */
/** Defaults */
GIT_MERGE_FILE_DEFAULT = 0,
/* Create standard conflicted merge files */
/** Create standard conflicted merge files */
GIT_MERGE_FILE_STYLE_MERGE = (1 << 0),
/* Create diff3-style files */
/** Create diff3-style files */
GIT_MERGE_FILE_STYLE_DIFF3 = (1 << 1),
/* Condense non-alphanumeric regions for simplified diff file */
/** Condense non-alphanumeric regions for simplified diff file */
GIT_MERGE_FILE_SIMPLIFY_ALNUM = (1 << 2),
/** Ignore all whitespace */
GIT_MERGE_FILE_IGNORE_WHITESPACE = (1 << 3),
/** Ignore changes in amount of whitespace */
GIT_MERGE_FILE_IGNORE_WHITESPACE_CHANGE = (1 << 4),
/** Ignore whitespace at end of line */
GIT_MERGE_FILE_IGNORE_WHITESPACE_EOL = (1 << 5),
/** Use the "patience diff" algorithm */
GIT_MERGE_FILE_DIFF_PATIENCE = (1 << 6),
/** Take extra time to find minimal diff */
GIT_MERGE_FILE_DIFF_MINIMAL = (1 << 7),
} git_merge_file_flags_t;
/**
* Options for merging a file
*/
typedef struct {
unsigned int version;
@ -146,8 +169,8 @@ typedef struct {
/** The file to favor in region conflicts. */
git_merge_file_favor_t favor;
/** Merge file flags. */
git_merge_file_flags_t flags;
/** see `git_merge_file_flags_t` above */
unsigned int flags;
} git_merge_file_options;
#define GIT_MERGE_FILE_OPTIONS_VERSION 1
@ -166,6 +189,9 @@ GIT_EXTERN(int) git_merge_file_init_options(
git_merge_file_options *opts,
unsigned int version);
/**
* Information about file-level merging
*/
typedef struct {
/**
* True if the output was automerged, false if the output contains
@ -189,9 +215,12 @@ typedef struct {
size_t len;
} git_merge_file_result;
/**
* Merging options
*/
typedef struct {
unsigned int version;
git_merge_tree_flag_t flags;
git_merge_tree_flag_t tree_flags;
/**
* Similarity to consider a file renamed (default 50). If
@ -216,6 +245,9 @@ typedef struct {
/** Flags for handling conflicting content. */
git_merge_file_favor_t file_favor;
/** see `git_merge_file_flags_t` above */
unsigned int file_flags;
} git_merge_options;
#define GIT_MERGE_OPTIONS_VERSION 1
@ -268,8 +300,11 @@ typedef enum {
GIT_MERGE_ANALYSIS_UNBORN = (1 << 3),
} git_merge_analysis_t;
/**
* The user's stated preference for merges.
*/
typedef enum {
/*
/**
* No configuration was found that suggests a preferred behavior for
* merge.
*/
@ -302,7 +337,7 @@ GIT_EXTERN(int) git_merge_analysis(
git_merge_analysis_t *analysis_out,
git_merge_preference_t *preference_out,
git_repository *repo,
const git_merge_head **their_heads,
const git_annotated_commit **their_heads,
size_t their_heads_len);
/**
@ -320,6 +355,21 @@ GIT_EXTERN(int) git_merge_base(
const git_oid *one,
const git_oid *two);
/**
* Find merge bases between two commits
*
* @param out array in which to store the resulting ids
* @param repo the repository where the commits exist
* @param one one of the commits
* @param two the other commit
* @return 0 on success, GIT_ENOTFOUND if not found or error code
*/
GIT_EXTERN(int) git_merge_bases(
git_oidarray *out,
git_repository *repo,
const git_oid *one,
const git_oid *two);
/**
* Find a merge base given a list of commits
*
@ -335,6 +385,21 @@ GIT_EXTERN(int) git_merge_base_many(
size_t length,
const git_oid input_array[]);
/**
* Find all merge bases given a list of commits
*
* @param out array in which to store the resulting ids
* @param repo the repository where the commits exist
* @param length The number of commits in the provided `input_array`
* @param input_array oids of the commits
* @return Zero on success; GIT_ENOTFOUND or -1 on failure.
*/
GIT_EXTERN(int) git_merge_bases_many(
git_oidarray *out,
git_repository *repo,
size_t length,
const git_oid input_array[]);
/**
* Find a merge base in preparation for an octopus merge
*
@ -350,69 +415,6 @@ GIT_EXTERN(int) git_merge_base_octopus(
size_t length,
const git_oid input_array[]);
/**
* Creates a `git_merge_head` from the given reference. The resulting
* git_merge_head must be freed with `git_merge_head_free`.
*
* @param out pointer to store the git_merge_head result in
* @param repo repository that contains the given reference
* @param ref reference to use as a merge input
* @return 0 on success or error code
*/
GIT_EXTERN(int) git_merge_head_from_ref(
git_merge_head **out,
git_repository *repo,
const git_reference *ref);
/**
* Creates a `git_merge_head` from the given fetch head data. The resulting
* git_merge_head must be freed with `git_merge_head_free`.
*
* @param out pointer to store the git_merge_head result in
* @param repo repository that contains the given commit
* @param branch_name name of the (remote) branch
* @param remote_url url of the remote
* @param oid the commit object id to use as a merge input
* @return 0 on success or error code
*/
GIT_EXTERN(int) git_merge_head_from_fetchhead(
git_merge_head **out,
git_repository *repo,
const char *branch_name,
const char *remote_url,
const git_oid *oid);
/**
* Creates a `git_merge_head` from the given commit id. The resulting
* git_merge_head must be freed with `git_merge_head_free`.
*
* @param out pointer to store the git_merge_head result in
* @param repo repository that contains the given commit
* @param id the commit object id to use as a merge input
* @return 0 on success or error code
*/
GIT_EXTERN(int) git_merge_head_from_id(
git_merge_head **out,
git_repository *repo,
const git_oid *id);
/**
* Gets the commit ID that the given `git_merge_head` refers to.
*
* @param head the given merge head
* @return commit id
*/
GIT_EXTERN(const git_oid *) git_merge_head_id(
const git_merge_head *head);
/**
* Frees a `git_merge_head`.
*
* @param head merge head to free
*/
GIT_EXTERN(void) git_merge_head_free(
git_merge_head *head);
/**
* Merge two files as they exist in the in-memory data structures, using
* the given common ancestor as the baseline, producing a
@ -495,6 +497,10 @@ GIT_EXTERN(int) git_merge_trees(
* or checked out. If the index is to be converted to a tree, the caller
* should resolve any conflicts that arose as part of the merge.
*
* The merge performed uses the first common ancestor, unlike the
* `git-merge-recursive` strategy, which may produce an artificial common
* ancestor tree when there are multiple ancestors.
*
* The returned index must be freed explicitly with `git_index_free`.
*
* @param out pointer to store the index result in
@ -517,6 +523,15 @@ GIT_EXTERN(int) git_merge_commits(
* to the index. Callers should inspect the repository's index after this
* completes, resolve any conflicts and prepare a commit.
*
* The merge performed uses the first common ancestor, unlike the
* `git-merge-recursive` strategy, which may produce an artificial common
* ancestor tree when there are multiple ancestors.
*
* For compatibility with git, the repository is put into a merging
* state. Once the commit is done (or if the uses wishes to abort),
* you should clear this state by calling
* `git_repository_state_cleanup()`.
*
* @param repo the repository to merge
* @param their_heads the heads to merge into
* @param their_heads_len the number of heads to merge
@ -526,7 +541,7 @@ GIT_EXTERN(int) git_merge_commits(
*/
GIT_EXTERN(int) git_merge(
git_repository *repo,
const git_merge_head **their_heads,
const git_annotated_commit **their_heads,
size_t their_heads_len,
const git_merge_options *merge_opts,
const git_checkout_options *checkout_opts);

View File

@ -21,20 +21,21 @@ GIT_BEGIN_DECL
#define GIT_DEFAULT_PORT "9418"
/*
/**
* Direction of the connection.
*
* We need this because we need to know whether we should call
* git-upload-pack or git-receive-pack on the remote end when get_refs
* gets called.
*/
typedef enum {
GIT_DIRECTION_FETCH = 0,
GIT_DIRECTION_PUSH = 1
} git_direction;
/**
* Remote head description, given out on `ls` calls.
* Description of a reference advertised by a remote server, given out
* on `ls` calls.
*/
struct git_remote_head {
int local; /* available locally */

View File

@ -59,14 +59,12 @@ GIT_EXTERN(int) git_note_iterator_new(
GIT_EXTERN(void) git_note_iterator_free(git_note_iterator *it);
/**
* Returns the current item (note_id and annotated_id) and advance the iterator
* Return the current item (note_id and annotated_id) and advance the iterator
* internally to the next value
*
* The notes must not be freed manually by the user.
*
* @param it pointer to the iterator
* @param note_id id of blob containing the message
* @param annotated_id id of the git object being annotated
* @param it pointer to the iterator
*
* @return 0 (no error), GIT_ITEROVER (iteration is done) or an error code
* (negative value)
@ -96,6 +94,23 @@ GIT_EXTERN(int) git_note_read(
const char *notes_ref,
const git_oid *oid);
/**
* Get the note author
*
* @param note the note
* @return the author
*/
GIT_EXTERN(const git_signature *) git_note_author(const git_note *note);
/**
* Get the note committer
*
* @param note the note
* @return the committer
*/
GIT_EXTERN(const git_signature *) git_note_committer(const git_note *note);
/**
* Get the note message
*
@ -118,10 +133,10 @@ GIT_EXTERN(const git_oid *) git_note_id(const git_note *note);
*
* @param out pointer to store the OID (optional); NULL in case of error
* @param repo repository where to store the note
* @param author signature of the notes commit author
* @param committer signature of the notes commit committer
* @param notes_ref canonical name of the reference to use (optional);
* defaults to "refs/notes/commits"
* @param author signature of the notes commit author
* @param committer signature of the notes commit committer
* @param oid OID of the git object to decorate
* @param note Content of the note to add for object oid
* @param force Overwrite existing note
@ -131,9 +146,9 @@ GIT_EXTERN(const git_oid *) git_note_id(const git_note *note);
GIT_EXTERN(int) git_note_create(
git_oid *out,
git_repository *repo,
const char *notes_ref,
const git_signature *author,
const git_signature *committer,
const char *notes_ref,
const git_oid *oid,
const char *note,
int force);
@ -168,12 +183,12 @@ GIT_EXTERN(void) git_note_free(git_note *note);
/**
* Get the default notes reference for a repository
*
* @param out Pointer to the default notes reference
* @param out buffer in which to store the name of the default notes reference
* @param repo The Git repository
*
* @return 0 or an error code
*/
GIT_EXTERN(int) git_note_default_ref(const char **out, git_repository *repo);
GIT_EXTERN(int) git_note_default_ref(git_buf *out, git_repository *repo);
/**
* Loop over all the notes within a specified namespace

View File

@ -202,18 +202,25 @@ GIT_EXTERN(size_t) git_object__size(git_otype type);
/**
* Recursively peel an object until an object of the specified type is met.
*
* The retrieved `peeled` object is owned by the repository and should be
* closed with the `git_object_free` method.
* If the query cannot be satisfied due to the object model,
* GIT_EINVALIDSPEC will be returned (e.g. trying to peel a blob to a
* tree).
*
* If you pass `GIT_OBJ_ANY` as the target type, then the object will be
* peeled until the type changes (e.g. a tag will be chased until the
* referenced object is no longer a tag).
* If you pass `GIT_OBJ_ANY` as the target type, then the object will
* be peeled until the type changes. A tag will be peeled until the
* referenced object is no longer a tag, and a commit will be peeled
* to a tree. Any other object type will return GIT_EINVALIDSPEC.
*
* If peeling a tag we discover an object which cannot be peeled to
* the target type due to the object model, GIT_EPEEL will be
* returned.
*
* You must free the returned object.
*
* @param peeled Pointer to the peeled git_object
* @param object The object to be processed
* @param target_type The type of the requested object (GIT_OBJ_COMMIT,
* GIT_OBJ_TAG, GIT_OBJ_TREE, GIT_OBJ_BLOB or GIT_OBJ_ANY).
* @return 0 on success, GIT_EAMBIGUOUS, GIT_ENOTFOUND or an error code
* @param target_type The type of the requested object (a GIT_OBJ_ value)
* @return 0 on success, GIT_EINVALIDSPEC, GIT_EPEEL, or an error code
*/
GIT_EXTERN(int) git_object_peel(
git_object **peeled,

View File

@ -247,7 +247,7 @@ GIT_EXTERN(int) git_odb_write(git_oid *out, git_odb *odb, const void *data, size
* @param type type of the object that will be written
* @return 0 if the stream was created; error code otherwise
*/
GIT_EXTERN(int) git_odb_open_wstream(git_odb_stream **out, git_odb *db, size_t size, git_otype type);
GIT_EXTERN(int) git_odb_open_wstream(git_odb_stream **out, git_odb *db, git_off_t size, git_otype type);
/**
* Write to an odb stream

View File

@ -86,8 +86,8 @@ struct git_odb_stream {
unsigned int mode;
void *hash_ctx;
size_t declared_size;
size_t received_bytes;
git_off_t declared_size;
git_off_t received_bytes;
/**
* Write at most `len` bytes into `buffer` and advance the stream.

View File

@ -116,13 +116,17 @@ GIT_EXTERN(void) git_oid_nfmt(char *out, size_t n, const git_oid *id);
GIT_EXTERN(void) git_oid_pathfmt(char *out, const git_oid *id);
/**
* Format a git_oid into a newly allocated c-string.
* Format a git_oid into a statically allocated c-string.
*
* @param id the oid structure to format
* @return the c-string; NULL if memory is exhausted. Caller must
* deallocate the string with git__free().
* The c-string is owned by the library and should not be freed
* by the user. If libgit2 is built with thread support, the string
* will be stored in TLS (i.e. one buffer per thread) to allow for
* concurrent calls of the function.
*
* @param oid The oid structure to format
* @return the c-string
*/
GIT_EXTERN(char *) git_oid_allocfmt(const git_oid *id);
GIT_EXTERN(char *) git_oid_tostr_s(const git_oid *oid);
/**
* Format a git_oid into a buffer as a hex format c-string.

40
include/git2/oidarray.h Normal file
View File

@ -0,0 +1,40 @@
/*
* Copyright (C) the libgit2 contributors. All rights reserved.
*
* This file is part of libgit2, distributed under the GNU GPL v2 with
* a Linking Exception. For full terms see the included COPYING file.
*/
#ifndef INCLUDE_git_oidarray_h__
#define INCLUDE_git_oidarray_h__
#include "common.h"
#include "oid.h"
GIT_BEGIN_DECL
/** Array of object ids */
typedef struct git_oidarray {
git_oid *ids;
size_t count;
} git_oidarray;
/**
* Free the OID array
*
* This method must (and must only) be called on `git_oidarray`
* objects where the array is allocated by the library. Not doing so,
* will result in a memory leak.
*
* This does not free the `git_oidarray` itself, since the library will
* never allocate that object directly itself (it is more commonly embedded
* inside another struct or created on the stack).
*
* @param array git_oidarray from which to free oid data
*/
GIT_EXTERN(void) git_oidarray_free(git_oidarray *array);
/** @} */
GIT_END_DECL
#endif

View File

@ -114,6 +114,31 @@ GIT_EXTERN(int) git_packbuilder_insert_tree(git_packbuilder *pb, const git_oid *
*/
GIT_EXTERN(int) git_packbuilder_insert_commit(git_packbuilder *pb, const git_oid *id);
/**
* Insert objects as given by the walk
*
* Those commits and all objects they reference will be inserted into
* the packbuilder.
*
* @param pb the packbuilder
* @param walk the revwalk to use to fill the packbuilder
*
* @return 0 or an error code
*/
GIT_EXTERN(int) git_packbuilder_insert_walk(git_packbuilder *pb, git_revwalk *walk);
/**
* Recursively insert an object and its referenced objects
*
* Insert the object as well as any object it references.
*
* @param pb the packbuilder
* @param id the id of the root object to insert
* @param name optional name for the object
* @return 0 or an error code
*/
GIT_EXTERN(int) git_packbuilder_insert_recur(git_packbuilder *pb, const git_oid *id, const char *name);
/**
* Write the contents of the packfile to an in-memory buffer
*

View File

@ -29,7 +29,7 @@ GIT_BEGIN_DECL
typedef struct git_patch git_patch;
/**
* Return the diff delta and patch for an entry in the diff list.
* Return a patch for an entry in the diff list.
*
* The `git_patch` is a newly created object contains the text diffs
* for the delta. You have to call `git_patch_free()` when you are
@ -40,10 +40,6 @@ typedef struct git_patch git_patch;
* created, the output will be set to NULL, and the `binary` flag will be
* set true in the `git_diff_delta` structure.
*
* The `git_diff_delta` pointer points to internal data and you do not have
* to release it when you are done with it. It will go away when the
* `git_diff` and `git_patch` go away.
*
* It is okay to pass NULL for either of the output parameters; if you pass
* NULL for the `git_patch`, then the text diff will not be calculated.
*
@ -139,7 +135,8 @@ GIT_EXTERN(int) git_patch_from_buffers(
GIT_EXTERN(void) git_patch_free(git_patch *patch);
/**
* Get the delta associated with a patch
* Get the delta associated with a patch. This delta points to internal
* data and you do not have to release it when you are done with it.
*/
GIT_EXTERN(const git_diff_delta *) git_patch_get_delta(const git_patch *patch);

View File

@ -1,181 +0,0 @@
/*
* Copyright (C) the libgit2 contributors. All rights reserved.
*
* This file is part of libgit2, distributed under the GNU GPL v2 with
* a Linking Exception. For full terms see the included COPYING file.
*/
#ifndef INCLUDE_git_push_h__
#define INCLUDE_git_push_h__
#include "common.h"
#include "pack.h"
/**
* @file git2/push.h
* @brief Git push management functions
* @defgroup git_push push management functions
* @ingroup Git
* @{
*/
GIT_BEGIN_DECL
/**
* Controls the behavior of a git_push object.
*/
typedef struct {
unsigned int version;
/**
* If the transport being used to push to the remote requires the creation
* of a pack file, this controls the number of worker threads used by
* the packbuilder when creating that pack file to be sent to the remote.
*
* If set to 0, the packbuilder will auto-detect the number of threads
* to create. The default value is 1.
*/
unsigned int pb_parallelism;
} git_push_options;
#define GIT_PUSH_OPTIONS_VERSION 1
#define GIT_PUSH_OPTIONS_INIT { GIT_PUSH_OPTIONS_VERSION }
/**
* Initializes a `git_push_options` with default values. Equivalent to
* creating an instance with GIT_PUSH_OPTIONS_INIT.
*
* @param opts the `git_push_options` instance to initialize.
* @param version the version of the struct; you should pass
* `GIT_PUSH_OPTIONS_VERSION` here.
* @return Zero on success; -1 on failure.
*/
GIT_EXTERN(int) git_push_init_options(
git_push_options *opts,
unsigned int version);
/** Push network progress notification function */
typedef int (*git_push_transfer_progress)(
unsigned int current,
unsigned int total,
size_t bytes,
void* payload);
/**
* Create a new push object
*
* @param out New push object
* @param remote Remote instance
*
* @return 0 or an error code
*/
GIT_EXTERN(int) git_push_new(git_push **out, git_remote *remote);
/**
* Set options on a push object
*
* @param push The push object
* @param opts The options to set on the push object
*
* @return 0 or an error code
*/
GIT_EXTERN(int) git_push_set_options(
git_push *push,
const git_push_options *opts);
/**
* Set the callbacks for a push
*
* @param push The push object
* @param pack_progress_cb Function to call with progress information during
* pack building. Be aware that this is called inline with pack building
* operations, so performance may be affected.
* @param pack_progress_cb_payload Payload for the pack progress callback.
* @param transfer_progress_cb Function to call with progress information during
* the upload portion of a push. Be aware that this is called inline with
* pack building operations, so performance may be affected.
* @param transfer_progress_cb_payload Payload for the network progress callback.
* @return 0 or an error code
*/
GIT_EXTERN(int) git_push_set_callbacks(
git_push *push,
git_packbuilder_progress pack_progress_cb,
void *pack_progress_cb_payload,
git_push_transfer_progress transfer_progress_cb,
void *transfer_progress_cb_payload);
/**
* Add a refspec to be pushed
*
* @param push The push object
* @param refspec Refspec string
*
* @return 0 or an error code
*/
GIT_EXTERN(int) git_push_add_refspec(git_push *push, const char *refspec);
/**
* Update remote tips after a push
*
* @param push The push object
* @param signature The identity to use when updating reflogs
* @param reflog_message The message to insert into the reflogs. If NULL, the
* default is "update by push".
*
* @return 0 or an error code
*/
GIT_EXTERN(int) git_push_update_tips(
git_push *push,
const git_signature *signature,
const char *reflog_message);
/**
* Actually push all given refspecs
*
* Note: To check if the push was successful (i.e. all remote references
* have been updated as requested), you need to call both
* `git_push_unpack_ok` and `git_push_status_foreach`. The remote
* repository might have refused to update some or all of the references.
*
* @param push The push object
*
* @return 0 or an error code
*/
GIT_EXTERN(int) git_push_finish(git_push *push);
/**
* Check if remote side successfully unpacked
*
* @param push The push object
*
* @return true if remote side successfully unpacked, false otherwise
*/
GIT_EXTERN(int) git_push_unpack_ok(const git_push *push);
/**
* Invoke callback `cb' on each status entry
*
* For each of the updated references, we receive a status report in the
* form of `ok refs/heads/master` or `ng refs/heads/master <msg>`.
* `msg != NULL` means the reference has not been updated for the given
* reason.
*
* Return a non-zero value from the callback to stop the loop.
*
* @param push The push object
* @param cb The callback to call on each object
*
* @return 0 on success, non-zero callback return value, or error code
*/
GIT_EXTERN(int) git_push_status_foreach(git_push *push,
int (*cb)(const char *ref, const char *msg, void *data),
void *data);
/**
* Free the given push object
*
* @param push The push object
*/
GIT_EXTERN(void) git_push_free(git_push *push);
/** @} */
GIT_END_DECL
#endif

290
include/git2/rebase.h Normal file
View File

@ -0,0 +1,290 @@
/*
* Copyright (C) the libgit2 contributors. All rights reserved.
*
* This file is part of libgit2, distributed under the GNU GPL v2 with
* a Linking Exception. For full terms see the included COPYING file.
*/
#ifndef INCLUDE_git_rebase_h__
#define INCLUDE_git_rebase_h__
#include "common.h"
#include "types.h"
#include "oid.h"
#include "annotated_commit.h"
/**
* @file git2/rebase.h
* @brief Git rebase routines
* @defgroup git_rebase Git merge routines
* @ingroup Git
* @{
*/
GIT_BEGIN_DECL
/**
* Rebase options
*
* Use to tell the rebase machinery how to operate.
*/
typedef struct {
unsigned int version;
/**
* Used by `git_rebase_init`, this will instruct other clients working
* on this rebase that you want a quiet rebase experience, which they
* may choose to provide in an application-specific manner. This has no
* effect upon libgit2 directly, but is provided for interoperability
* between Git tools.
*/
int quiet;
/**
* Used by `git_rebase_finish`, this is the name of the notes reference
* used to rewrite notes for rebased commits when finishing the rebase;
* if NULL, the contents of the coniguration option `notes.rewriteRef`
* is examined, unless the configuration option `notes.rewrite.rebase`
* is set to false. If `notes.rewriteRef` is also NULL, notes will
* not be rewritten.
*/
const char *rewrite_notes_ref;
/**
* Options to control how files are written during `git_rebase_init`,
* `git_checkout_next` and `git_checkout_abort`. Note that a minimum
* strategy of `GIT_CHECKOUT_SAFE` is defaulted in `init` and `next`,
* and a minimum strategy of `GIT_CHECKOUT_FORCE` is defaulted in
* `abort` to match git semantics.
*/
git_checkout_options checkout_options;
} git_rebase_options;
/**
* Type of rebase operation in-progress after calling `git_rebase_next`.
*/
typedef enum {
/**
* The given commit is to be cherry-picked. The client should commit
* the changes and continue if there are no conflicts.
*/
GIT_REBASE_OPERATION_PICK = 0,
/**
* The given commit is to be cherry-picked, but the client should prompt
* the user to provide an updated commit message.
*/
GIT_REBASE_OPERATION_REWORD,
/**
* The given commit is to be cherry-picked, but the client should stop
* to allow the user to edit the changes before committing them.
*/
GIT_REBASE_OPERATION_EDIT,
/**
* The given commit is to be squashed into the previous commit. The
* commit message will be merged with the previous message.
*/
GIT_REBASE_OPERATION_SQUASH,
/**
* The given commit is to be squashed into the previous commit. The
* commit message from this commit will be discarded.
*/
GIT_REBASE_OPERATION_FIXUP,
/**
* No commit will be cherry-picked. The client should run the given
* command and (if successful) continue.
*/
GIT_REBASE_OPERATION_EXEC,
} git_rebase_operation_t;
#define GIT_REBASE_OPTIONS_VERSION 1
#define GIT_REBASE_OPTIONS_INIT \
{GIT_REBASE_OPTIONS_VERSION, 0, NULL, GIT_CHECKOUT_OPTIONS_INIT}
/** Indicates that a rebase operation is not (yet) in progress. */
#define GIT_REBASE_NO_OPERATION SIZE_MAX
/**
* A rebase operation
*
* Describes a single instruction/operation to be performed during the
* rebase.
*/
typedef struct {
/** The type of rebase operation. */
git_rebase_operation_t type;
/**
* The commit ID being cherry-picked. This will be populated for
* all operations except those of type `GIT_REBASE_OPERATION_EXEC`.
*/
const git_oid id;
/**
* The executable the user has requested be run. This will only
* be populated for operations of type `GIT_REBASE_OPERATION_EXEC`.
*/
const char *exec;
} git_rebase_operation;
/**
* Initializes a `git_rebase_options` with default values. Equivalent to
* creating an instance with GIT_REBASE_OPTIONS_INIT.
*
* @param opts the `git_rebase_options` instance to initialize.
* @param version the version of the struct; you should pass
* `GIT_REBASE_OPTIONS_VERSION` here.
* @return Zero on success; -1 on failure.
*/
GIT_EXTERN(int) git_rebase_init_options(
git_rebase_options *opts,
unsigned int version);
/**
* Initializes a rebase operation to rebase the changes in `branch`
* relative to `upstream` onto another branch. To begin the rebase
* process, call `git_rebase_next`. When you have finished with this
* object, call `git_rebase_free`.
*
* @param out Pointer to store the rebase object
* @param repo The repository to perform the rebase
* @param branch The terminal commit to rebase, or NULL to rebase the
* current branch
* @param upstream The commit to begin rebasing from, or NULL to rebase all
* reachable commits
* @param onto The branch to rebase onto, or NULL to rebase onto the given
* upstream
* @param opts Options to specify how rebase is performed, or NULL
* @return Zero on success; -1 on failure.
*/
GIT_EXTERN(int) git_rebase_init(
git_rebase **out,
git_repository *repo,
const git_annotated_commit *branch,
const git_annotated_commit *upstream,
const git_annotated_commit *onto,
const git_rebase_options *opts);
/**
* Opens an existing rebase that was previously started by either an
* invocation of `git_rebase_init` or by another client.
*
* @param out Pointer to store the rebase object
* @param repo The repository that has a rebase in-progress
* @param opts Options to specify how rebase is performed
* @return Zero on success; -1 on failure.
*/
GIT_EXTERN(int) git_rebase_open(
git_rebase **out,
git_repository *repo,
const git_rebase_options *opts);
/**
* Gets the count of rebase operations that are to be applied.
*
* @param rebase The in-progress rebase
* @return The number of rebase operations in total
*/
GIT_EXTERN(size_t) git_rebase_operation_entrycount(git_rebase *rebase);
/**
* Gets the index of the rebase operation that is currently being applied.
* If the first operation has not yet been applied (because you have
* called `init` but not yet `next`) then this returns
* `GIT_REBASE_NO_OPERATION`.
*
* @param rebase The in-progress rebase
* @return The index of the rebase operation currently being applied.
*/
GIT_EXTERN(size_t) git_rebase_operation_current(git_rebase *rebase);
/**
* Gets the rebase operation specified by the given index.
*
* @param rebase The in-progress rebase
* @param idx The index of the rebase operation to retrieve
* @return The rebase operation or NULL if `idx` was out of bounds
*/
GIT_EXTERN(git_rebase_operation *) git_rebase_operation_byindex(
git_rebase *rebase,
size_t idx);
/**
* Performs the next rebase operation and returns the information about it.
* If the operation is one that applies a patch (which is any operation except
* GIT_REBASE_OPERATION_EXEC) then the patch will be applied and the index and
* working directory will be updated with the changes. If there are conflicts,
* you will need to address those before committing the changes.
*
* @param operation Pointer to store the rebase operation that is to be performed next
* @param rebase The rebase in progress
* @return Zero on success; -1 on failure.
*/
GIT_EXTERN(int) git_rebase_next(
git_rebase_operation **operation,
git_rebase *rebase);
/**
* Commits the current patch. You must have resolved any conflicts that
* were introduced during the patch application from the `git_rebase_next`
* invocation.
*
* @param id Pointer in which to store the OID of the newly created commit
* @param rebase The rebase that is in-progress
* @param author The author of the updated commit, or NULL to keep the
* author from the original commit
* @param committer The committer of the rebase
* @param message_encoding The encoding for the message in the commit,
* represented with a standard encoding name. If message is NULL,
* this should also be NULL, and the encoding from the original
* commit will be maintained. If message is specified, this may be
* NULL to indicate that "UTF-8" is to be used.
* @param message The message for this commit, or NULL to use the message
* from the original commit.
* @return Zero on success, GIT_EUNMERGED if there are unmerged changes in
* the index, GIT_EAPPLIED if the current commit has already
* been applied to the upstream and there is nothing to commit,
* -1 on failure.
*/
GIT_EXTERN(int) git_rebase_commit(
git_oid *id,
git_rebase *rebase,
const git_signature *author,
const git_signature *committer,
const char *message_encoding,
const char *message);
/**
* Aborts a rebase that is currently in progress, resetting the repository
* and working directory to their state before rebase began.
*
* @param rebase The rebase that is in-progress
* @return Zero on success; GIT_ENOTFOUND if a rebase is not in progress,
* -1 on other errors.
*/
GIT_EXTERN(int) git_rebase_abort(git_rebase *rebase);
/**
* Finishes a rebase that is currently in progress once all patches have
* been applied.
*
* @param rebase The rebase that is in-progress
* @param signature The identity that is finishing the rebase (optional)
* @return Zero on success; -1 on error
*/
GIT_EXTERN(int) git_rebase_finish(
git_rebase *rebase,
const git_signature *signature);
/**
* Frees the `git_rebase` object.
*
* @param rebase The rebase object
*/
GIT_EXTERN(void) git_rebase_free(git_rebase *rebase);
/** @} */
GIT_END_DECL
#endif

View File

@ -102,7 +102,7 @@ GIT_EXTERN(size_t) git_reflog_entrycount(git_reflog *reflog);
* equal to 0 (zero) and less than `git_reflog_entrycount()`.
* @return the entry; NULL if not found
*/
GIT_EXTERN(const git_reflog_entry *) git_reflog_entry_byindex(git_reflog *reflog, size_t idx);
GIT_EXTERN(const git_reflog_entry *) git_reflog_entry_byindex(const git_reflog *reflog, size_t idx);
/**
* Remove an entry from the reflog by its index

View File

@ -58,7 +58,7 @@ GIT_EXTERN(int) git_reference_name_to_id(
* Lookup a reference by DWIMing its short name
*
* Apply the git precendence rules to the given shorthand to determine
* which reference the user is refering to.
* which reference the user is referring to.
*
* @param out pointer in which to store the reference
* @param repo the repository in which to look
@ -89,9 +89,9 @@ GIT_EXTERN(int) git_reference_dwim(git_reference **out, git_repository *repo, co
* This function will return an error if a reference already exists with the
* given name unless `force` is true, in which case it will be overwritten.
*
* The signature and message for the reflog will be ignored if the
* reference does not belong in the standard set (HEAD, branches and
* remote-tracking branches) and it does not have a reflog.
* The message for the reflog will be ignored if the reference does
* not belong in the standard set (HEAD, branches and remote-tracking
* branches) and it does not have a reflog.
*
* It will return GIT_EMODIFIED if the reference's value at the time
* of updating does not match the one passed through `current_value`
@ -103,11 +103,10 @@ GIT_EXTERN(int) git_reference_dwim(git_reference **out, git_repository *repo, co
* @param target The target of the reference
* @param force Overwrite existing references
* @param current_value The expected value of the reference when updating
* @param signature The identity that will used to populate the reflog entry
* @param log_message The one line long message to be appended to the reflog
* @return 0 on success, GIT_EEXISTS, GIT_EINVALIDSPEC, GIT_EMODIFIED or an error code
*/
GIT_EXTERN(int) git_reference_symbolic_create_matching(git_reference **out, git_repository *repo, const char *name, const char *target, int force, const char *current_value, const git_signature *signature, const char *log_message);
GIT_EXTERN(int) git_reference_symbolic_create_matching(git_reference **out, git_repository *repo, const char *name, const char *target, int force, const char *current_value, const char *log_message);
/**
* Create a new symbolic reference.
@ -131,20 +130,19 @@ GIT_EXTERN(int) git_reference_symbolic_create_matching(git_reference **out, git_
* This function will return an error if a reference already exists with the
* given name unless `force` is true, in which case it will be overwritten.
*
* The signature and message for the reflog will be ignored if the
* reference does not belong in the standard set (HEAD, branches and
* remote-tracking branches) and it does not have a reflog.
* The message for the reflog will be ignored if the reference does
* not belong in the standard set (HEAD, branches and remote-tracking
* branches) and it does not have a reflog.
*
* @param out Pointer to the newly created reference
* @param repo Repository where that reference will live
* @param name The name of the reference
* @param target The target of the reference
* @param force Overwrite existing references
* @param signature The identity that will used to populate the reflog entry
* @param log_message The one line long message to be appended to the reflog
* @return 0 on success, GIT_EEXISTS, GIT_EINVALIDSPEC or an error code
*/
GIT_EXTERN(int) git_reference_symbolic_create(git_reference **out, git_repository *repo, const char *name, const char *target, int force, const git_signature *signature, const char *log_message);
GIT_EXTERN(int) git_reference_symbolic_create(git_reference **out, git_repository *repo, const char *name, const char *target, int force, const char *log_message);
/**
* Create a new direct reference.
@ -169,20 +167,19 @@ GIT_EXTERN(int) git_reference_symbolic_create(git_reference **out, git_repositor
* This function will return an error if a reference already exists with the
* given name unless `force` is true, in which case it will be overwritten.
*
* The signature and message for the reflog will be ignored if the
* reference does not belong in the standard set (HEAD, branches and
* remote-tracking branches) and and it does not have a reflog.
* The message for the reflog will be ignored if the reference does
* not belong in the standard set (HEAD, branches and remote-tracking
* branches) and and it does not have a reflog.
*
* @param out Pointer to the newly created reference
* @param repo Repository where that reference will live
* @param name The name of the reference
* @param id The object id pointed to by the reference.
* @param force Overwrite existing references
* @param signature The identity that will used to populate the reflog entry
* @param log_message The one line long message to be appended to the reflog
* @return 0 on success, GIT_EEXISTS, GIT_EINVALIDSPEC or an error code
*/
GIT_EXTERN(int) git_reference_create(git_reference **out, git_repository *repo, const char *name, const git_oid *id, int force, const git_signature *signature, const char *log_message);
GIT_EXTERN(int) git_reference_create(git_reference **out, git_repository *repo, const char *name, const git_oid *id, int force, const char *log_message);
/**
* Conditionally create new direct reference
@ -207,9 +204,9 @@ GIT_EXTERN(int) git_reference_create(git_reference **out, git_repository *repo,
* This function will return an error if a reference already exists with the
* given name unless `force` is true, in which case it will be overwritten.
*
* The signature and message for the reflog will be ignored if the
* reference does not belong in the standard set (HEAD, branches and
* remote-tracking branches) and and it does not have a reflog.
* The message for the reflog will be ignored if the reference does
* not belong in the standard set (HEAD, branches and remote-tracking
* branches) and and it does not have a reflog.
*
* It will return GIT_EMODIFIED if the reference's value at the time
* of updating does not match the one passed through `current_id`
@ -221,12 +218,11 @@ GIT_EXTERN(int) git_reference_create(git_reference **out, git_repository *repo,
* @param id The object id pointed to by the reference.
* @param force Overwrite existing references
* @param current_id The expected value of the reference at the time of update
* @param signature The identity that will used to populate the reflog entry
* @param log_message The one line long message to be appended to the reflog
* @return 0 on success, GIT_EMODIFIED if the value of the reference
* has changed, GIT_EEXISTS, GIT_EINVALIDSPEC or an error code
*/
GIT_EXTERN(int) git_reference_create_matching(git_reference **out, git_repository *repo, const char *name, const git_oid *id, int force, const git_oid *current_id, const git_signature *signature, const char *log_message);
GIT_EXTERN(int) git_reference_create_matching(git_reference **out, git_repository *repo, const char *name, const git_oid *id, int force, const git_oid *current_id, const char *log_message);
/**
* Get the OID pointed to by a direct reference.
@ -320,14 +316,13 @@ GIT_EXTERN(git_repository *) git_reference_owner(const git_reference *ref);
* The target name will be checked for validity.
* See `git_reference_symbolic_create()` for rules about valid names.
*
* The signature and message for the reflog will be ignored if the
* reference does not belong in the standard set (HEAD, branches and
* remote-tracking branches) and and it does not have a reflog.
* The message for the reflog will be ignored if the reference does
* not belong in the standard set (HEAD, branches and remote-tracking
* branches) and and it does not have a reflog.
*
* @param out Pointer to the newly created reference
* @param ref The reference
* @param target The new target for the reference
* @param signature The identity that will used to populate the reflog entry
* @param log_message The one line long message to be appended to the reflog
* @return 0 on success, GIT_EINVALIDSPEC or an error code
*/
@ -335,7 +330,6 @@ GIT_EXTERN(int) git_reference_symbolic_set_target(
git_reference **out,
git_reference *ref,
const char *target,
const git_signature *signature,
const char *log_message);
/**
@ -348,7 +342,6 @@ GIT_EXTERN(int) git_reference_symbolic_set_target(
* @param out Pointer to the newly created reference
* @param ref The reference
* @param id The new target OID for the reference
* @param signature The identity that will used to populate the reflog entry
* @param log_message The one line long message to be appended to the reflog
* @return 0 on success, GIT_EMODIFIED if the value of the reference
* has changed since it was read, or an error code
@ -357,7 +350,6 @@ GIT_EXTERN(int) git_reference_set_target(
git_reference **out,
git_reference *ref,
const git_oid *id,
const git_signature *signature,
const char *log_message);
/**
@ -379,7 +371,6 @@ GIT_EXTERN(int) git_reference_set_target(
* @param ref The reference to rename
* @param new_name The new name for the reference
* @param force Overwrite an existing reference
* @param signature The identity that will used to populate the reflog entry
* @param log_message The one line long message to be appended to the reflog
* @return 0 on success, GIT_EINVALIDSPEC, GIT_EEXISTS or an error code
*
@ -389,7 +380,6 @@ GIT_EXTERN(int) git_reference_rename(
git_reference *ref,
const char *new_name,
int force,
const git_signature *signature,
const char *log_message);
/**
@ -629,7 +619,13 @@ GIT_EXTERN(int) git_reference_is_tag(const git_reference *ref);
*/
GIT_EXTERN(int) git_reference_is_note(const git_reference *ref);
/**
* Normalization options for reference lookup
*/
typedef enum {
/**
* No particular normalization.
*/
GIT_REF_FORMAT_NORMAL = 0u,
/**

View File

@ -14,6 +14,7 @@
#include "indexer.h"
#include "strarray.h"
#include "transport.h"
#include "pack.h"
/**
* @file git2/remote.h
@ -27,8 +28,7 @@ GIT_BEGIN_DECL
typedef int (*git_remote_rename_problem_cb)(const char *problematic_refspec, void *payload);
/**
* Add a remote with the default fetch refspec to the repository's configuration. This
* calls git_remote_save before returning.
* Add a remote with the default fetch refspec to the repository's configuration.
*
* @param out the resulting remote
* @param repo the repository in which to create the remote
@ -44,8 +44,7 @@ GIT_EXTERN(int) git_remote_create(
/**
* Add a remote with the provided fetch refspec (or default if NULL) to the repository's
* configuration. This
* calls git_remote_save before returning.
* configuration.
*
* @param out the resulting remote
* @param repo the repository in which to create the remote
@ -64,24 +63,18 @@ GIT_EXTERN(int) git_remote_create_with_fetchspec(
/**
* Create an anonymous remote
*
* Create a remote with the given url and refspec in memory. You can use
* this when you have a URL instead of a remote's name. Note that anonymous
* remotes cannot be converted to persisted remotes.
* Create a remote with the given url in-memory. You can use this when
* you have a URL instead of a remote's name.
*
* The name, when provided, will be checked for validity.
* See `git_tag_create()` for rules about valid names.
*
* @param out pointer to the new remote object
* @param out pointer to the new remote objects
* @param repo the associated repository
* @param url the remote repository's URL
* @param fetch the fetch refspec to use for this remote.
* @return 0 or an error code
*/
GIT_EXTERN(int) git_remote_create_anonymous(
git_remote **out,
git_repository *repo,
const char *url,
const char *fetch);
const char *url);
/**
* Get the information for a particular remote
@ -94,18 +87,7 @@ GIT_EXTERN(int) git_remote_create_anonymous(
* @param name the remote's name
* @return 0, GIT_ENOTFOUND, GIT_EINVALIDSPEC or an error code
*/
GIT_EXTERN(int) git_remote_load(git_remote **out, git_repository *repo, const char *name);
/**
* Save a remote to its repository's configuration
*
* One can't save a in-memory remote. Doing so will
* result in a GIT_EINVALIDSPEC being returned.
*
* @param remote the remote to save to config
* @return 0, GIT_EINVALIDSPEC or an error code
*/
GIT_EXTERN(int) git_remote_save(const git_remote *remote);
GIT_EXTERN(int) git_remote_lookup(git_remote **out, git_repository *repo, const char *name);
/**
* Create a copy of an existing remote. All internal strings are also
@ -138,6 +120,9 @@ GIT_EXTERN(const char *) git_remote_name(const git_remote *remote);
/**
* Get the remote's url
*
* If url.*.insteadOf has been configured for this URL, it will
* return the modified URL.
*
* @param remote the remote
* @return a pointer to the url
*/
@ -146,44 +131,52 @@ GIT_EXTERN(const char *) git_remote_url(const git_remote *remote);
/**
* Get the remote's url for pushing
*
* If url.*.pushInsteadOf has been configured for this URL, it
* will return the modified URL.
*
* @param remote the remote
* @return a pointer to the url or NULL if no special url for pushing is set
*/
GIT_EXTERN(const char *) git_remote_pushurl(const git_remote *remote);
/**
* Set the remote's url
* Set the remote's url in the configuration
*
* Existing connections will not be updated.
* Remote objects already in memory will not be affected. This assumes
* the common case of a single-url remote and will otherwise return an error.
*
* @param remote the remote
* @param repo the repository in which to perform the change
* @param remote the remote's name
* @param url the url to set
* @return 0 or an error value
*/
GIT_EXTERN(int) git_remote_set_url(git_remote *remote, const char* url);
GIT_EXTERN(int) git_remote_set_url(git_repository *repo, const char *remote, const char* url);
/**
* Set the remote's url for pushing
* Set the remote's url for pushing in the configuration.
*
* Existing connections will not be updated.
* Remote objects already in memory will not be affected. This assumes
* the common case of a single-url remote and will otherwise return an error.
*
* @param remote the remote
* @param url the url to set or NULL to clear the pushurl
* @return 0 or an error value
*
* @param repo the repository in which to perform the change
* @param remote the remote's name
* @param url the url to set
*/
GIT_EXTERN(int) git_remote_set_pushurl(git_remote *remote, const char* url);
GIT_EXTERN(int) git_remote_set_pushurl(git_repository *repo, const char *remote, const char* url);
/**
* Add a fetch refspec to the remote
* Add a fetch refspec to the remote's configuration
*
* Convenience function for adding a single fetch refspec to the
* current list in the remote.
* Add the given refspec to the fetch list in the configuration. No
* loaded remote instances will be affected.
*
* @param remote the remote
* @param repo the repository in which to change the configuration
* @param remote the name of the remote to change
* @param refspec the new fetch refspec
* @return 0 or an error value
* @return 0, GIT_EINVALIDSPEC if refspec is invalid or an error value
*/
GIT_EXTERN(int) git_remote_add_fetch(git_remote *remote, const char *refspec);
GIT_EXTERN(int) git_remote_add_fetch(git_repository *repo, const char *remote, const char *refspec);
/**
* Get the remote's list of fetch refspecs
@ -197,26 +190,17 @@ GIT_EXTERN(int) git_remote_add_fetch(git_remote *remote, const char *refspec);
GIT_EXTERN(int) git_remote_get_fetch_refspecs(git_strarray *array, const git_remote *remote);
/**
* Set the remote's list of fetch refspecs
* Add a push refspec to the remote's configuration
*
* The contents of the string array are copied.
* Add the given refspec to the push list in the configuration. No
* loaded remote instances will be affected.
*
* @param remote the remote to modify
* @param array the new list of fetch resfpecs
*/
GIT_EXTERN(int) git_remote_set_fetch_refspecs(git_remote *remote, git_strarray *array);
/**
* Add a push refspec to the remote
*
* Convenience function for adding a single push refspec to the
* current list in the remote.
*
* @param remote the remote
* @param repo the repository in which to change the configuration
* @param remote the name of the remote to change
* @param refspec the new push refspec
* @return 0 or an error value
* @return 0, GIT_EINVALIDSPEC if refspec is invalid or an error value
*/
GIT_EXTERN(int) git_remote_add_push(git_remote *remote, const char *refspec);
GIT_EXTERN(int) git_remote_add_push(git_repository *repo, const char *remote, const char *refspec);
/**
* Get the remote's list of push refspecs
@ -229,25 +213,6 @@ GIT_EXTERN(int) git_remote_add_push(git_remote *remote, const char *refspec);
*/
GIT_EXTERN(int) git_remote_get_push_refspecs(git_strarray *array, const git_remote *remote);
/**
* Set the remote's list of push refspecs
*
* The contents of the string array are copied.
*
* @param remote the remote to modify
* @param array the new list of push resfpecs
*/
GIT_EXTERN(int) git_remote_set_push_refspecs(git_remote *remote, git_strarray *array);
/**
* Clear the refspecs
*
* Remove all configured fetch and push refspecs from the remote.
*
* @param remote the remote
*/
GIT_EXTERN(void) git_remote_clear_refspecs(git_remote *remote);
/**
* Get the number of refspecs for a remote
*
@ -275,19 +240,25 @@ GIT_EXTERN(const git_refspec *)git_remote_get_refspec(const git_remote *remote,
* @param remote the remote to connect to
* @param direction GIT_DIRECTION_FETCH if you want to fetch or
* GIT_DIRECTION_PUSH if you want to push
* @param callbacks the callbacks to use for this connection
* @return 0 or an error code
*/
GIT_EXTERN(int) git_remote_connect(git_remote *remote, git_direction direction);
GIT_EXTERN(int) git_remote_connect(git_remote *remote, git_direction direction, const git_remote_callbacks *callbacks);
/**
* Get a list of refs at the remote
* Get the remote repository's reference advertisement list
*
* The remote (or more exactly its transport) must be connected. The
* memory belongs to the remote.
* Get the list of references with which the server responds to a new
* connection.
*
* The array will stay valid as long as the remote object exists and
* its transport isn't changed, but a copy is recommended for usage of
* the data.
* The remote (or more exactly its transport) must have connected to
* the remote repository. This list is available as soon as the
* connection to the remote is initiated and it remains available
* after disconnecting.
*
* The memory belongs to the remote. The pointer will be valid as long
* as a new connection is not initiated, but it is recommended that
* you make a copy in order to make use of the data.
*
* @param out pointer to the array
* @param size the number of remote heads
@ -296,20 +267,6 @@ GIT_EXTERN(int) git_remote_connect(git_remote *remote, git_direction direction);
*/
GIT_EXTERN(int) git_remote_ls(const git_remote_head ***out, size_t *size, git_remote *remote);
/**
* Download and index the packfile
*
* Connect to the remote if it hasn't been done yet, negotiate with
* the remote git which objects are missing, download and index the
* packfile.
*
* The .idx file will be created and both it and the packfile with be
* renamed to their final name.
*
* @return 0 or an error code
*/
GIT_EXTERN(int) git_remote_download(git_remote *remote);
/**
* Check whether the remote is connected
*
@ -334,8 +291,7 @@ GIT_EXTERN(void) git_remote_stop(git_remote *remote);
/**
* Disconnect from the remote
*
* Close the connection to the remote and free the underlying
* transport.
* Close the connection to the remote.
*
* @param remote the remote to disconnect from
*/
@ -351,54 +307,6 @@ GIT_EXTERN(void) git_remote_disconnect(git_remote *remote);
*/
GIT_EXTERN(void) git_remote_free(git_remote *remote);
/**
* Update the tips to the new state
*
* @param remote the remote to update
* @param signature The identity to use when updating reflogs
* @param reflog_message The message to insert into the reflogs. If NULL, the
* default is "fetch <name>", where <name> is the name of
* the remote (or its url, for in-memory remotes).
* @return 0 or an error code
*/
GIT_EXTERN(int) git_remote_update_tips(
git_remote *remote,
const git_signature *signature,
const char *reflog_message);
/**
* Download new data and update tips
*
* Convenience function to connect to a remote, download the data,
* disconnect and update the remote-tracking branches.
*
* @param remote the remote to fetch from
* @param signature The identity to use when updating reflogs
* @param reflog_message The message to insert into the reflogs. If NULL, the
* default is "fetch"
* @return 0 or an error code
*/
GIT_EXTERN(int) git_remote_fetch(
git_remote *remote,
const git_signature *signature,
const char *reflog_message);
/**
* Return whether a string is a valid remote URL
*
* @param url the url to check
* @return 1 if the url is valid, 0 otherwise
*/
GIT_EXTERN(int) git_remote_valid_url(const char *url);
/**
* Return whether the passed URL is supported by this version of the library.
*
* @param url the url to check
* @return 1 if the url is supported, 0 otherwise
*/
GIT_EXTERN(int) git_remote_supported_url(const char* url);
/**
* Get a list of the configured remotes for a repo
*
@ -410,30 +318,6 @@ GIT_EXTERN(int) git_remote_supported_url(const char* url);
*/
GIT_EXTERN(int) git_remote_list(git_strarray *out, git_repository *repo);
/**
* Choose whether to check the server's certificate (applies to HTTPS only)
*
* @param remote the remote to configure
* @param check whether to check the server's certificate (defaults to yes)
*/
GIT_EXTERN(void) git_remote_check_cert(git_remote *remote, int check);
/**
* Sets a custom transport for the remote. The caller can use this function
* to bypass the automatic discovery of a transport by URL scheme (i.e.
* http://, https://, git://) and supply their own transport to be used
* instead. After providing the transport to a remote using this function,
* the transport object belongs exclusively to that remote, and the remote will
* free it when it is freed with git_remote_free.
*
* @param remote the remote to configure
* @param transport the transport object for the remote to use
* @return 0 or an error code
*/
GIT_EXTERN(int) git_remote_set_transport(
git_remote *remote,
git_transport *transport);
/**
* Argument to the completion callback which tells it which operation
* finished.
@ -444,6 +328,42 @@ typedef enum git_remote_completion_type {
GIT_REMOTE_COMPLETION_ERROR,
} git_remote_completion_type;
/** Push network progress notification function */
typedef int (*git_push_transfer_progress)(
unsigned int current,
unsigned int total,
size_t bytes,
void* payload);
/**
* Represents an update which will be performed on the remote during push
*/
typedef struct {
/**
* The source name of the reference
*/
char *src_refname;
/**
* The name of the reference to update on the server
*/
char *dst_refname;
/**
* The current target of the reference
*/
git_oid src;
/**
* The new target for the reference
*/
git_oid dst;
} git_push_update;
/**
* @param updates an array containing the updates which will be sent
* as commands to the destination.
* @param len number of elements in `updates`
* @param payload Payload provided by the caller
*/
typedef int (*git_push_negotiation)(const git_push_update **updates, size_t len, void *payload);
/**
* The callback settings structure
*
@ -474,6 +394,14 @@ struct git_remote_callbacks {
*/
git_cred_acquire_cb credentials;
/**
* If cert verification fails, this will be called to let the
* user make the final decision of whether to allow the
* connection to proceed. Returns 1 to allow the connection, 0
* to disallow it or a negative value to indicate an error.
*/
git_transport_certificate_check_cb certificate_check;
/**
* During the download of new data, this will be regularly
* called with the current count of progress done by the
@ -487,6 +415,40 @@ struct git_remote_callbacks {
*/
int (*update_tips)(const char *refname, const git_oid *a, const git_oid *b, void *data);
/**
* Function to call with progress information during pack
* building. Be aware that this is called inline with pack
* building operations, so performance may be affected.
*/
git_packbuilder_progress pack_progress;
/**
* Function to call with progress information during the
* upload portion of a push. Be aware that this is called
* inline with pack building operations, so performance may be
* affected.
*/
git_push_transfer_progress push_transfer_progress;
/**
* Called for each updated reference on push. If `status` is
* not `NULL`, the update was rejected by the remote server
* and `status` contains the reason given.
*/
int (*push_update_reference)(const char *refname, const char *status, void *data);
/**
* Called once between the negotiation step and the upload. It
* provides information about what updates will be performed.
*/
git_push_negotiation push_negotiation;
/**
* Create the transport to use for this operation. Leave NULL
* to auto-detect.
*/
git_transport_cb transport;
/**
* This will be passed to each of the callbacks in this struct
* as the last parameter.
@ -509,40 +471,231 @@ GIT_EXTERN(int) git_remote_init_callbacks(
git_remote_callbacks *opts,
unsigned int version);
/**
* Set the callbacks for a remote
*
* Note that the remote keeps its own copy of the data and you need to
* call this function again if you want to change the callbacks.
*
* @param remote the remote to configure
* @param callbacks a pointer to the user's callback settings
* @return 0 or an error code
*/
GIT_EXTERN(int) git_remote_set_callbacks(git_remote *remote, const git_remote_callbacks *callbacks);
typedef enum {
/**
* Use the setting from the configuration
*/
GIT_FETCH_PRUNE_UNSPECIFIED,
/**
* Force pruning on
*/
GIT_FETCH_PRUNE,
/**
* Force pruning off
*/
GIT_FETCH_NO_PRUNE,
} git_fetch_prune_t;
/**
* Retrieve the current callback structure
* Automatic tag following option
*
* This provides read access to the callbacks structure as the remote
* sees it.
*
* @param remote the remote to query
* @return a pointer to the callbacks structure
* Lets us select the --tags option to use.
*/
GIT_EXTERN(const git_remote_callbacks *) git_remote_get_callbacks(git_remote *remote);
typedef enum {
/**
* Use the setting from the configuration.
*/
GIT_REMOTE_DOWNLOAD_TAGS_UNSPECIFIED = 0,
/**
* Ask the server for tags pointing to objects we're already
* downloading.
*/
GIT_REMOTE_DOWNLOAD_TAGS_AUTO,
/**
* Don't ask for any tags beyond the refspecs.
*/
GIT_REMOTE_DOWNLOAD_TAGS_NONE,
/**
* Ask for the all the tags.
*/
GIT_REMOTE_DOWNLOAD_TAGS_ALL,
} git_remote_autotag_option_t;
typedef struct {
int version;
/**
* Callbacks to use for this fetch operation
*/
git_remote_callbacks callbacks;
/**
* Whether to perform a prune after the fetch
*/
git_fetch_prune_t prune;
/**
* Whether to write the results to FETCH_HEAD. Defaults to
* on. Leave this default in order to behave like git.
*/
int update_fetchhead;
/**
* Determines how to behave regarding tags on the remote, such
* as auto-downloading tags for objects we're downloading or
* downloading all of them.
*
* The default is to auto-follow tags.
*/
git_remote_autotag_option_t download_tags;
} git_fetch_options;
#define GIT_FETCH_OPTIONS_VERSION 1
#define GIT_FETCH_OPTIONS_INIT { GIT_FETCH_OPTIONS_VERSION, GIT_REMOTE_CALLBACKS_INIT, GIT_FETCH_PRUNE_UNSPECIFIED, 1 }
/**
* Initializes a `git_fetch_options` with default values. Equivalent to
* creating an instance with GIT_FETCH_OPTIONS_INIT.
*
* @param opts the `git_push_options` instance to initialize.
* @param version the version of the struct; you should pass
* `GIT_FETCH_OPTIONS_VERSION` here.
* @return Zero on success; -1 on failure.
*/
GIT_EXTERN(int) git_fetch_init_options(
git_fetch_options *opts,
unsigned int version);
/**
* Controls the behavior of a git_push object.
*/
typedef struct {
unsigned int version;
/**
* If the transport being used to push to the remote requires the creation
* of a pack file, this controls the number of worker threads used by
* the packbuilder when creating that pack file to be sent to the remote.
*
* If set to 0, the packbuilder will auto-detect the number of threads
* to create. The default value is 1.
*/
unsigned int pb_parallelism;
/**
* Callbacks to use for this push operation
*/
git_remote_callbacks callbacks;
} git_push_options;
#define GIT_PUSH_OPTIONS_VERSION 1
#define GIT_PUSH_OPTIONS_INIT { GIT_PUSH_OPTIONS_VERSION, 0, GIT_REMOTE_CALLBACKS_INIT }
/**
* Initializes a `git_push_options` with default values. Equivalent to
* creating an instance with GIT_PUSH_OPTIONS_INIT.
*
* @param opts the `git_push_options` instance to initialize.
* @param version the version of the struct; you should pass
* `GIT_PUSH_OPTIONS_VERSION` here.
* @return Zero on success; -1 on failure.
*/
GIT_EXTERN(int) git_push_init_options(
git_push_options *opts,
unsigned int version);
/**
* Download and index the packfile
*
* Connect to the remote if it hasn't been done yet, negotiate with
* the remote git which objects are missing, download and index the
* packfile.
*
* The .idx file will be created and both it and the packfile with be
* renamed to their final name.
*
* @param remote the remote
* @param refspecs the refspecs to use for this negotiation and
* download. Use NULL or an empty array to use the base refspecs
* @param opts the options to use for this fetch
* @return 0 or an error code
*/
GIT_EXTERN(int) git_remote_download(git_remote *remote, const git_strarray *refspecs, const git_fetch_options *opts);
/**
* Create a packfile and send it to the server
*
* Connect to the remote if it hasn't been done yet, negotiate with
* the remote git which objects are missing, create a packfile with the missing objects and send it.
*
* @param remote the remote
* @param refspecs the refspecs to use for this negotiation and
* upload. Use NULL or an empty array to use the base refspecs
* @param opts the options to use for this push
* @return 0 or an error code
*/
GIT_EXTERN(int) git_remote_upload(git_remote *remote, const git_strarray *refspecs, const git_push_options *opts);
/**
* Update the tips to the new state
*
* @param remote the remote to update
* @param reflog_message The message to insert into the reflogs. If
* NULL and fetching, the default is "fetch <name>", where <name> is
* the name of the remote (or its url, for in-memory remotes). This
* parameter is ignored when pushing.
* @param callbacks pointer to the callback structure to use
* @param update_fetchhead whether to write to FETCH_HEAD. Pass 1 to behave like git.
* @param download_tags what the behaviour for downloading tags is for this fetch. This is
* ignored for push. This must be the same value passed to `git_remote_download()`.
* @return 0 or an error code
*/
GIT_EXTERN(int) git_remote_update_tips(
git_remote *remote,
const git_remote_callbacks *callbacks,
int update_fetchhead,
git_remote_autotag_option_t download_tags,
const char *reflog_message);
/**
* Download new data and update tips
*
* Convenience function to connect to a remote, download the data,
* disconnect and update the remote-tracking branches.
*
* @param remote the remote to fetch from
* @param refspecs the refspecs to use for this fetch. Pass NULL or an
* empty array to use the base refspecs.
* @param opts options to use for this fetch
* @param reflog_message The message to insert into the reflogs. If NULL, the
* default is "fetch"
* @return 0 or an error code
*/
GIT_EXTERN(int) git_remote_fetch(
git_remote *remote,
const git_strarray *refspecs,
const git_fetch_options *opts,
const char *reflog_message);
/**
* Prune tracking refs that are no longer present on remote
*
* @param remote the remote to prune
* @param callbacks callbacks to use for this prune
* @return 0 or an error code
*/
GIT_EXTERN(int) git_remote_prune(git_remote *remote, const git_remote_callbacks *callbacks);
/**
* Perform a push
*
* Peform all the steps from a push.
*
* @param remote the remote to push to
* @param refspecs the refspecs to use for pushing. If none are
* passed, the configured refspecs will be used
* @param opts options to use for this push
*/
GIT_EXTERN(int) git_remote_push(git_remote *remote,
const git_strarray *refspecs,
const git_push_options *opts);
/**
* Get the statistics structure that is filled in by the fetch operation.
*/
GIT_EXTERN(const git_transfer_progress *) git_remote_stats(git_remote *remote);
typedef enum {
GIT_REMOTE_DOWNLOAD_TAGS_AUTO = 0,
GIT_REMOTE_DOWNLOAD_TAGS_NONE = 1,
GIT_REMOTE_DOWNLOAD_TAGS_ALL = 2
} git_remote_autotag_option_t;
/**
* Retrieve the tag auto-follow setting
*
@ -552,14 +705,23 @@ typedef enum {
GIT_EXTERN(git_remote_autotag_option_t) git_remote_autotag(const git_remote *remote);
/**
* Set the tag auto-follow setting
* Set the remote's tag following setting.
*
* @param remote the remote to configure
* @param value a GIT_REMOTE_DOWNLOAD_TAGS value
* The change will be made in the configuration. No loaded remotes
* will be affected.
*
* @param repo the repository in which to make the change
* @param remote the name of the remote
* @param value the new value to take.
*/
GIT_EXTERN(void) git_remote_set_autotag(
git_remote *remote,
git_remote_autotag_option_t value);
GIT_EXTERN(int) git_remote_set_autotag(git_repository *repo, const char *remote, git_remote_autotag_option_t value);
/**
* Retrieve the ref-prune setting
*
* @param remote the remote to query
* @return the ref-prune setting
*/
GIT_EXTERN(int) git_remote_prune_refs(const git_remote *remote);
/**
* Give the remote a new name
@ -570,37 +732,23 @@ GIT_EXTERN(void) git_remote_set_autotag(
* The new name will be checked for validity.
* See `git_tag_create()` for rules about valid names.
*
* A temporary in-memory remote cannot be given a name with this method.
* No loaded instances of a the remote with the old name will change
* their name or their list of refspecs.
*
* @param problems non-default refspecs cannot be renamed and will be
* stored here for further processing by the caller. Always free this
* strarray on succesful return.
* @param remote the remote to rename
* strarray on successful return.
* @param repo the repository in which to rename
* @param name the current name of the reamote
* @param new_name the new name the remote should bear
* @return 0, GIT_EINVALIDSPEC, GIT_EEXISTS or an error code
*/
GIT_EXTERN(int) git_remote_rename(
git_strarray *problems,
git_remote *remote,
git_repository *repo,
const char *name,
const char *new_name);
/**
* Retrieve the update FETCH_HEAD setting.
*
* @param remote the remote to query
* @return the update FETCH_HEAD setting
*/
GIT_EXTERN(int) git_remote_update_fetchhead(git_remote *remote);
/**
* Sets the update FETCH_HEAD setting. By default, FETCH_HEAD will be
* updated on every fetch. Set to 0 to disable.
*
* @param remote the remote to configure
* @param value 0 to disable updating FETCH_HEAD
*/
GIT_EXTERN(void) git_remote_set_update_fetchhead(git_remote *remote, int value);
/**
* Ensure the remote name is well-formed.
*
@ -615,10 +763,11 @@ GIT_EXTERN(int) git_remote_is_valid_name(const char *remote_name);
* All remote-tracking branches and configuration settings
* for the remote will be removed.
*
* @param remote A valid remote
* @param repo the repository in which to act
* @param name the name of the remove to delete
* @return 0 on success, or an error code.
*/
GIT_EXTERN(int) git_remote_delete(git_remote *remote);
GIT_EXTERN(int) git_remote_delete(git_repository *repo, const char *name);
/**
* Retrieve the name of the remote's default branch

View File

@ -196,6 +196,8 @@ GIT_EXTERN(int) git_repository_init(
* looking the "template_path" from the options if set, or the
* `init.templatedir` global config if not, or falling back on
* "/usr/share/git-core/templates" if it exists.
* * GIT_REPOSITORY_INIT_RELATIVE_GITLINK - If an alternate workdir is
* specified, use relative paths for the gitdir and core.worktree.
*/
typedef enum {
GIT_REPOSITORY_INIT_BARE = (1u << 0),
@ -204,6 +206,7 @@ typedef enum {
GIT_REPOSITORY_INIT_MKDIR = (1u << 3),
GIT_REPOSITORY_INIT_MKPATH = (1u << 4),
GIT_REPOSITORY_INIT_EXTERNAL_TEMPLATE = (1u << 5),
GIT_REPOSITORY_INIT_RELATIVE_GITLINK = (1u << 6),
} git_repository_init_flag_t;
/**
@ -339,8 +342,8 @@ GIT_EXTERN(int) git_repository_head_unborn(git_repository *repo);
/**
* Check if a repository is empty
*
* An empty repository has just been initialized and contains
* no references.
* An empty repository has just been initialized and contains no references
* apart from HEAD, which must be pointing to the unborn master branch.
*
* @param repo Repo to test
* @return 1 if the repository is empty, 0 if it isn't, error code
@ -600,15 +603,11 @@ GIT_EXTERN(int) git_repository_hashfile(
*
* @param repo Repository pointer
* @param refname Canonical name of the reference the HEAD should point at
* @param signature The identity that will used to populate the reflog entry
* @param log_message The one line long message to be appended to the reflog
* @return 0 on success, or an error code
*/
GIT_EXTERN(int) git_repository_set_head(
git_repository* repo,
const char* refname,
const git_signature *signature,
const char *log_message);
const char* refname);
/**
* Make the repository HEAD directly point to the Commit.
@ -624,15 +623,27 @@ GIT_EXTERN(int) git_repository_set_head(
*
* @param repo Repository pointer
* @param commitish Object id of the Commit the HEAD should point to
* @param signature The identity that will used to populate the reflog entry
* @param log_message The one line long message to be appended to the reflog
* @return 0 on success, or an error code
*/
GIT_EXTERN(int) git_repository_set_head_detached(
git_repository* repo,
const git_oid* commitish,
const git_signature *signature,
const char *log_message);
const git_oid* commitish);
/**
* Make the repository HEAD directly point to the Commit.
*
* This behaves like `git_repository_set_head_detached()` but takes an
* annotated commit, which lets you specify which extended sha syntax
* string was specified by a user, allowing for more exact reflog
* messages.
*
* See the documentation for `git_repository_set_head_detached()`.
*
* @see git_repository_set_head_detached
*/
GIT_EXTERN(int) git_repository_set_head_detached_from_annotated(
git_repository *repo,
const git_annotated_commit *commitish);
/**
* Detach the HEAD.
@ -648,21 +659,23 @@ GIT_EXTERN(int) git_repository_set_head_detached(
* Otherwise, the HEAD will be detached and point to the peeled Commit.
*
* @param repo Repository pointer
* @param signature The identity that will used to populate the reflog entry
* @param reflog_message The one line long message to be appended to the reflog
* @return 0 on success, GIT_EUNBORNBRANCH when HEAD points to a non existing
* branch or an error code
*/
GIT_EXTERN(int) git_repository_detach_head(
git_repository* repo,
const git_signature *signature,
const char *reflog_message);
git_repository* repo);
/**
* Repository state
*
* These values represent possible states for the repository to be in,
* based on the current operation which is ongoing.
*/
typedef enum {
GIT_REPOSITORY_STATE_NONE,
GIT_REPOSITORY_STATE_MERGE,
GIT_REPOSITORY_STATE_REVERT,
GIT_REPOSITORY_STATE_CHERRY_PICK,
GIT_REPOSITORY_STATE_CHERRYPICK,
GIT_REPOSITORY_STATE_BISECT,
GIT_REPOSITORY_STATE_REBASE,
GIT_REPOSITORY_STATE_REBASE_INTERACTIVE,
@ -711,6 +724,31 @@ GIT_EXTERN(const char *) git_repository_get_namespace(git_repository *repo);
*/
GIT_EXTERN(int) git_repository_is_shallow(git_repository *repo);
/**
* Retrieve the configured identity to use for reflogs
*
* The memory is owned by the repository and must not be freed by the
* user.
*
* @param name where to store the pointer to the name
* @param email where to store the pointer to the email
* @param repo the repository
*/
GIT_EXTERN(int) git_repository_ident(const char **name, const char **email, const git_repository *repo);
/**
* Set the identity to be used for writing reflogs
*
* If both are set, this name and email will be used to write to the
* reflog. Pass NULL to unset. When unset, the identity will be taken
* from the repository's configuration.
*
* @param repo the repository to configure
* @param name the name to use for the reflog entries
* @param name the email to use for the reflog entries
*/
GIT_EXTERN(int) git_repository_set_ident(git_repository *repo, const char *name, const char *email);
/** @} */
GIT_END_DECL
#endif

View File

@ -7,6 +7,11 @@
#ifndef INCLUDE_git_reset_h__
#define INCLUDE_git_reset_h__
#include "common.h"
#include "types.h"
#include "strarray.h"
#include "checkout.h"
/**
* @file git2/reset.h
* @brief Git reset management routines
@ -48,12 +53,9 @@ typedef enum {
*
* @param reset_type Kind of reset operation to perform.
*
* @param signature The identity that will used to populate the reflog entry
*
* @param log_message The one line long message to be appended to the reflog.
* The reflog is only updated if the affected direct reference is actually
* changing. If NULL, the default is "reset: moving"; if you want something more
* useful, provide a message.
* @param checkout_opts Checkout options to be used for a HARD reset.
* The checkout_strategy field will be overridden (based on reset_type).
* This parameter can be used to propagate notify and progress callbacks.
*
* @return 0 on success or an error code
*/
@ -61,8 +63,25 @@ GIT_EXTERN(int) git_reset(
git_repository *repo,
git_object *target,
git_reset_t reset_type,
git_signature *signature,
const char *log_message);
const git_checkout_options *checkout_opts);
/**
* Sets the current head to the specified commit oid and optionally
* resets the index and working tree to match.
*
* This behaves like `git_reset()` but takes an annotated commit,
* which lets you specify which extended sha syntax string was
* specified by a user, allowing for more exact reflog messages.
*
* See the documentation for `git_reset()`.
*
* @see git_reset
*/
GIT_EXTERN(int) git_reset_from_annotated(
git_repository *repo,
git_annotated_commit *commit,
git_reset_t reset_type,
const git_checkout_options *checkout_opts);
/**
* Updates some entries in the index from the target commit tree.

View File

@ -20,14 +20,17 @@
*/
GIT_BEGIN_DECL
/**
* Options for revert
*/
typedef struct {
unsigned int version;
/** For merge commits, the "mainline" is treated as the parent. */
unsigned int mainline;
git_merge_options merge_opts;
git_checkout_options checkout_opts;
git_merge_options merge_opts; /**< Options for the merging */
git_checkout_options checkout_opts; /**< Options for the checkout */
} git_revert_options;
#define GIT_REVERT_OPTIONS_VERSION 1
@ -59,7 +62,7 @@ GIT_EXTERN(int) git_revert_init_options(
* @param merge_options the merge options (or null for defaults)
* @return zero on success, -1 on failure.
*/
int git_revert_commit(
GIT_EXTERN(int) git_revert_commit(
git_index **out,
git_repository *repo,
git_commit *revert_commit,
@ -68,7 +71,7 @@ int git_revert_commit(
const git_merge_options *merge_options);
/**
* Reverts the given commit, producing changes in the working directory.
* Reverts the given commit, producing changes in the index and working directory.
*
* @param repo the repository to revert
* @param commit the commit to revert

View File

@ -21,33 +21,38 @@
GIT_BEGIN_DECL
/**
* Sort the repository contents in no particular ordering;
* this sorting is arbitrary, implementation-specific
* and subject to change at any time.
* This is the default sorting for new walkers.
* Flags to specify the sorting which a revwalk should perform.
*/
#define GIT_SORT_NONE (0)
typedef enum {
/**
* Sort the repository contents in no particular ordering;
* this sorting is arbitrary, implementation-specific
* and subject to change at any time.
* This is the default sorting for new walkers.
*/
GIT_SORT_NONE = 0,
/**
* Sort the repository contents in topological order
* (parents before children); this sorting mode
* can be combined with time sorting.
*/
#define GIT_SORT_TOPOLOGICAL (1 << 0)
/**
* Sort the repository contents in topological order
* (parents before children); this sorting mode
* can be combined with time sorting.
*/
GIT_SORT_TOPOLOGICAL = 1 << 0,
/**
* Sort the repository contents by commit time;
* this sorting mode can be combined with
* topological sorting.
*/
#define GIT_SORT_TIME (1 << 1)
/**
* Sort the repository contents by commit time;
* this sorting mode can be combined with
* topological sorting.
*/
GIT_SORT_TIME = 1 << 1,
/**
* Iterate through the repository contents in reverse
* order; this sorting mode can be combined with
* any of the above.
*/
#define GIT_SORT_REVERSE (1 << 2)
/**
* Iterate through the repository contents in reverse
* order; this sorting mode can be combined with
* any of the above.
*/
GIT_SORT_REVERSE = 1 << 2,
} git_sort_t;
/**
* Allocate a new revision walker to iterate through a repo.
@ -85,16 +90,18 @@ GIT_EXTERN(int) git_revwalk_new(git_revwalk **out, git_repository *repo);
GIT_EXTERN(void) git_revwalk_reset(git_revwalk *walker);
/**
* Mark a commit to start traversal from.
* Add a new root for the traversal
*
* The given OID must belong to a committish on the walked
* The pushed commit will be marked as one of the roots from which to
* start the walk. This commit may not be walked if it or a child is
* hidden.
*
* At least one commit must be pushed onto the walker before a walk
* can be started.
*
* The given id must belong to a committish on the walked
* repository.
*
* The given commit will be used as one of the roots
* when starting the revision walk. At least one commit
* must be pushed onto the walker before a walk can
* be started.
*
* @param walk the walker being used for the traversal.
* @param id the oid of the commit to start from.
* @return 0 or an error code
@ -130,7 +137,7 @@ GIT_EXTERN(int) git_revwalk_push_head(git_revwalk *walk);
/**
* Mark a commit (and its ancestors) uninteresting for the output.
*
* The given OID must belong to a committish on the walked
* The given id must belong to a committish on the walked
* repository.
*
* The resolved commit and all its parents will be hidden from the

Some files were not shown because too many files have changed in this diff Show More