mirror of
https://github.com/atom/atom.git
synced 2026-01-24 22:38:20 -05:00
Merge branch 'master' into absolute-paths-in-fuzzy-finder
Conflicts: src/packages/fuzzy-finder/lib/load-paths-handler.coffee
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1,3 +1,4 @@
|
||||
*.swp
|
||||
.DS_Store
|
||||
.project
|
||||
.svn
|
||||
@@ -10,3 +11,4 @@ npm-debug.log
|
||||
/tags
|
||||
/cef/
|
||||
/sources.gypi
|
||||
/node/
|
||||
|
||||
6
.gitmodules
vendored
6
.gitmodules
vendored
@@ -70,3 +70,9 @@
|
||||
[submodule "vendor/packages/less.tmbundle"]
|
||||
path = vendor/packages/less.tmbundle
|
||||
url = https://github.com/mathewbyrne/less.tmbundle.git
|
||||
[submodule "vendor/packages/Mustache.tmbundle"]
|
||||
path = vendor/packages/Mustache.tmbundle
|
||||
url = https://github.com/kevinsawicki/Mustache.tmbundle.git
|
||||
[submodule "vendor/packages/Go.tmbundle"]
|
||||
path = vendor/packages/Go.tmbundle
|
||||
url = https://github.com/rsms/Go.tmbundle
|
||||
|
||||
15
Rakefile
15
Rakefile
@@ -12,7 +12,7 @@ task :build => "create-xcode-project" do
|
||||
end
|
||||
|
||||
desc "Create xcode project from gyp file"
|
||||
task "create-xcode-project" => "update-cef" do
|
||||
task "create-xcode-project" => ["update-cef", "update-node"] do
|
||||
`rm -rf atom.xcodeproj`
|
||||
`script/generate-sources-gypi`
|
||||
`gyp --depth=. -D CODE_SIGN="#{ENV['CODE_SIGN']}" atom.gyp`
|
||||
@@ -20,15 +20,20 @@ end
|
||||
|
||||
desc "Update CEF to the latest version specified by the prebuilt-cef submodule"
|
||||
task "update-cef" => "bootstrap" do
|
||||
exit 1 unless system %{prebuilt-cef/script/download -f cef}
|
||||
exit 1 unless system %{script/update-cefode}
|
||||
Dir.glob('cef/*.gypi').each do |filename|
|
||||
`sed -i '' -e "s/'include\\//'cef\\/include\\//" -e "s/'libcef_dll\\//'cef\\/libcef_dll\\//" #{filename}`
|
||||
end
|
||||
end
|
||||
|
||||
desc "Download node binary"
|
||||
task "update-node" do
|
||||
`script/update-node v0.10.1`
|
||||
end
|
||||
|
||||
desc "Download debug symbols for CEF"
|
||||
task "download-cef-symbols" => "update-cef" do
|
||||
sh %{prebuilt-cef/script/download -s cef}
|
||||
sh %{script/update-cefode -s}
|
||||
end
|
||||
|
||||
task "bootstrap" do
|
||||
@@ -80,13 +85,15 @@ task :clean do
|
||||
`rm -rf #{application_path()}`
|
||||
`rm -rf #{BUILD_DIR}`
|
||||
`rm -rf /tmp/atom-compiled-scripts`
|
||||
`rm -rf node_modules`
|
||||
`rm -rf cef`
|
||||
end
|
||||
|
||||
desc "Run the specs"
|
||||
task :test => ["clean", "update-cef", "clone-default-bundles", "build"] do
|
||||
`pkill Atom`
|
||||
if path = application_path()
|
||||
cmd = "#{path}/Contents/MacOS/Atom --test --resource-path=#{ATOM_SRC_PATH} 2> /dev/null"
|
||||
cmd = "#{path}/Contents/MacOS/Atom --test --resource-path=#{ATOM_SRC_PATH}"
|
||||
system(cmd)
|
||||
exit($?.exitstatus)
|
||||
else
|
||||
|
||||
52
atom.gyp
52
atom.gyp
@@ -22,20 +22,13 @@
|
||||
'@executable_path/libcef.dylib',
|
||||
'@rpath/Chromium Embedded Framework.framework/Libraries/libcef.dylib',
|
||||
'-change',
|
||||
'@executable_path/../Frameworks/CocoaOniguruma.framework/Versions/A/CocoaOniguruma',
|
||||
'@rpath/CocoaOniguruma.framework/Versions/A/CocoaOniguruma',
|
||||
'-change',
|
||||
'@loader_path/../Frameworks/Sparkle.framework/Versions/A/Sparkle',
|
||||
'@rpath/Sparkle.framework/Versions/A/Sparkle',
|
||||
'-change',
|
||||
'@executable_path/libgit2.0.17.0.dylib',
|
||||
'@rpath/libgit2.framework/Libraries/libgit2.0.17.0.dylib',
|
||||
'${BUILT_PRODUCTS_DIR}/${EXECUTABLE_PATH}'
|
||||
],
|
||||
},
|
||||
'includes': [
|
||||
'cef/cef_paths2.gypi',
|
||||
'git2/libgit2.gypi',
|
||||
'sources.gypi',
|
||||
],
|
||||
'target_defaults': {
|
||||
@@ -142,22 +135,22 @@
|
||||
'files': [
|
||||
'<(PRODUCT_DIR)/Atom Helper.app',
|
||||
'<(PRODUCT_DIR)/Atom.framework',
|
||||
'native/frameworks/CocoaOniguruma.framework',
|
||||
'native/frameworks/Sparkle.framework',
|
||||
],
|
||||
},
|
||||
{
|
||||
'destination': '<(PRODUCT_DIR)/Atom.app/Contents/Frameworks/libgit2.framework/Libraries',
|
||||
'files': [
|
||||
'git2/frameworks/libgit2.0.17.0.dylib',
|
||||
],
|
||||
},
|
||||
{
|
||||
'destination': '<(PRODUCT_DIR)/Atom.app/Contents/Frameworks/Chromium Embedded Framework.framework',
|
||||
'files': [
|
||||
'cef/Resources',
|
||||
],
|
||||
},
|
||||
{
|
||||
# Copy node binary for worker process support.
|
||||
'destination': '<(PRODUCT_DIR)/Atom.app/Contents/Resources',
|
||||
'files': [
|
||||
'node/node',
|
||||
],
|
||||
},
|
||||
],
|
||||
'postbuilds': [
|
||||
{
|
||||
@@ -231,7 +224,7 @@
|
||||
'INFOPLIST_FILE': 'native/mac/framework-info.plist',
|
||||
'LD_DYLIB_INSTALL_NAME': '@rpath/Atom.framework/Atom',
|
||||
},
|
||||
'include_dirs': [ '.', 'cef', 'git2' ],
|
||||
'include_dirs': [ '.', 'cef' ],
|
||||
'mac_framework_dirs': [ 'native/frameworks' ],
|
||||
'sources': [
|
||||
'<@(includes_common)',
|
||||
@@ -257,24 +250,12 @@
|
||||
'native/path_watcher.mm',
|
||||
'native/v8_extensions/atom.h',
|
||||
'native/v8_extensions/atom.mm',
|
||||
'native/v8_extensions/git.h',
|
||||
'native/v8_extensions/git.mm',
|
||||
'native/v8_extensions/native.h',
|
||||
'native/v8_extensions/native.mm',
|
||||
'native/v8_extensions/onig_reg_exp.h',
|
||||
'native/v8_extensions/onig_reg_exp.mm',
|
||||
'native/v8_extensions/onig_scanner.h',
|
||||
'native/v8_extensions/onig_scanner.mm',
|
||||
'native/v8_extensions/readtags.c',
|
||||
'native/v8_extensions/readtags.h',
|
||||
'native/v8_extensions/tags.h',
|
||||
'native/v8_extensions/tags.mm',
|
||||
],
|
||||
'link_settings': {
|
||||
'libraries': [
|
||||
'$(SDKROOT)/System/Library/Frameworks/AppKit.framework',
|
||||
'git2/frameworks/libgit2.0.17.0.dylib',
|
||||
'native/frameworks/CocoaOniguruma.framework',
|
||||
'native/frameworks/Sparkle.framework',
|
||||
],
|
||||
},
|
||||
@@ -326,6 +307,7 @@
|
||||
'sources': [
|
||||
'<@(coffee_sources)',
|
||||
'<@(cson_sources)',
|
||||
'<@(less_sources)'
|
||||
],
|
||||
'rules': [
|
||||
{
|
||||
@@ -360,6 +342,22 @@
|
||||
'<(compiled_sources_dir)/<(RULE_INPUT_DIRNAME)/<(RULE_INPUT_ROOT).json',
|
||||
],
|
||||
},
|
||||
{
|
||||
'rule_name': 'less',
|
||||
'extension': 'less',
|
||||
'inputs': [
|
||||
'script/compile-less',
|
||||
],
|
||||
'outputs': [
|
||||
'<(compiled_sources_dir)/<(RULE_INPUT_DIRNAME)/<(RULE_INPUT_ROOT).css',
|
||||
],
|
||||
'action': [
|
||||
'sh',
|
||||
'script/compile-less',
|
||||
'<(RULE_INPUT_PATH)',
|
||||
'<(compiled_sources_dir)/<(RULE_INPUT_DIRNAME)/<(RULE_INPUT_ROOT).css',
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
require 'benchmark-helper'
|
||||
fs = require 'fs'
|
||||
fs = require 'fs-utils'
|
||||
$ = require 'jquery'
|
||||
_ = require 'underscore'
|
||||
TokenizedBuffer = require 'tokenized-buffer'
|
||||
|
||||
@@ -145,7 +145,7 @@ generate_html = (source, sections) ->
|
||||
|
||||
# Require our external dependencies, including **Showdown.js**
|
||||
# (the JavaScript implementation of Markdown).
|
||||
fs = require 'fs'
|
||||
fs = require 'fs-utils'
|
||||
path = require 'path'
|
||||
showdown = require('./../vendor/showdown').Showdown
|
||||
{spawn, exec} = require 'child_process'
|
||||
|
||||
Binary file not shown.
@@ -1,60 +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_git_h__
|
||||
#define INCLUDE_git_git_h__
|
||||
|
||||
#include "git2/version.h"
|
||||
|
||||
#include "git2/common.h"
|
||||
#include "git2/threads.h"
|
||||
#include "git2/errors.h"
|
||||
|
||||
#include "git2/types.h"
|
||||
|
||||
#include "git2/oid.h"
|
||||
#include "git2/signature.h"
|
||||
#include "git2/odb.h"
|
||||
|
||||
#include "git2/repository.h"
|
||||
#include "git2/revwalk.h"
|
||||
#include "git2/merge.h"
|
||||
#include "git2/graph.h"
|
||||
#include "git2/refs.h"
|
||||
#include "git2/reflog.h"
|
||||
#include "git2/revparse.h"
|
||||
|
||||
#include "git2/object.h"
|
||||
#include "git2/blob.h"
|
||||
#include "git2/commit.h"
|
||||
#include "git2/tag.h"
|
||||
#include "git2/tree.h"
|
||||
#include "git2/diff.h"
|
||||
|
||||
#include "git2/index.h"
|
||||
#include "git2/config.h"
|
||||
#include "git2/transport.h"
|
||||
#include "git2/remote.h"
|
||||
#include "git2/clone.h"
|
||||
#include "git2/checkout.h"
|
||||
#include "git2/push.h"
|
||||
|
||||
#include "git2/attr.h"
|
||||
#include "git2/ignore.h"
|
||||
#include "git2/branch.h"
|
||||
#include "git2/refspec.h"
|
||||
#include "git2/net.h"
|
||||
#include "git2/status.h"
|
||||
#include "git2/indexer.h"
|
||||
#include "git2/submodule.h"
|
||||
#include "git2/notes.h"
|
||||
#include "git2/reset.h"
|
||||
#include "git2/message.h"
|
||||
#include "git2/pack.h"
|
||||
#include "git2/stash.h"
|
||||
|
||||
#endif
|
||||
@@ -1,241 +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_attr_h__
|
||||
#define INCLUDE_git_attr_h__
|
||||
|
||||
#include "common.h"
|
||||
#include "types.h"
|
||||
|
||||
/**
|
||||
* @file git2/attr.h
|
||||
* @brief Git attribute management routines
|
||||
* @defgroup git_attr Git attribute management routines
|
||||
* @ingroup Git
|
||||
* @{
|
||||
*/
|
||||
GIT_BEGIN_DECL
|
||||
|
||||
/**
|
||||
* GIT_ATTR_TRUE checks if an attribute is set on. In core git
|
||||
* parlance, this the value for "Set" attributes.
|
||||
*
|
||||
* For example, if the attribute file contains:
|
||||
*
|
||||
* *.c foo
|
||||
*
|
||||
* Then for file `xyz.c` looking up attribute "foo" gives a value for
|
||||
* which `GIT_ATTR_TRUE(value)` is true.
|
||||
*/
|
||||
#define GIT_ATTR_TRUE(attr) (git_attr_value(attr) == GIT_ATTR_TRUE_T)
|
||||
|
||||
/**
|
||||
* GIT_ATTR_FALSE checks if an attribute is set off. In core git
|
||||
* parlance, this is the value for attributes that are "Unset" (not to
|
||||
* be confused with values that a "Unspecified").
|
||||
*
|
||||
* For example, if the attribute file contains:
|
||||
*
|
||||
* *.h -foo
|
||||
*
|
||||
* Then for file `zyx.h` looking up attribute "foo" gives a value for
|
||||
* which `GIT_ATTR_FALSE(value)` is true.
|
||||
*/
|
||||
#define GIT_ATTR_FALSE(attr) (git_attr_value(attr) == GIT_ATTR_FALSE_T)
|
||||
|
||||
/**
|
||||
* GIT_ATTR_UNSPECIFIED checks if an attribute is unspecified. This
|
||||
* may be due to the attribute not being mentioned at all or because
|
||||
* the attribute was explicitly set unspecified via the `!` operator.
|
||||
*
|
||||
* For example, if the attribute file contains:
|
||||
*
|
||||
* *.c foo
|
||||
* *.h -foo
|
||||
* onefile.c !foo
|
||||
*
|
||||
* Then for `onefile.c` looking up attribute "foo" yields a value with
|
||||
* `GIT_ATTR_UNSPECIFIED(value)` of true. Also, looking up "foo" on
|
||||
* file `onefile.rb` or looking up "bar" on any file will all give
|
||||
* `GIT_ATTR_UNSPECIFIED(value)` of true.
|
||||
*/
|
||||
#define GIT_ATTR_UNSPECIFIED(attr) (git_attr_value(attr) == GIT_ATTR_UNSPECIFIED_T)
|
||||
|
||||
/**
|
||||
* GIT_ATTR_HAS_VALUE checks if an attribute is set to a value (as
|
||||
* opposed to TRUE, FALSE or UNSPECIFIED). This would be the case if
|
||||
* for a file with something like:
|
||||
*
|
||||
* *.txt eol=lf
|
||||
*
|
||||
* Given this, looking up "eol" for `onefile.txt` will give back the
|
||||
* string "lf" and `GIT_ATTR_SET_TO_VALUE(attr)` will return true.
|
||||
*/
|
||||
#define GIT_ATTR_HAS_VALUE(attr) (git_attr_value(attr) == GIT_ATTR_VALUE_T)
|
||||
|
||||
typedef enum {
|
||||
GIT_ATTR_UNSPECIFIED_T = 0,
|
||||
GIT_ATTR_TRUE_T,
|
||||
GIT_ATTR_FALSE_T,
|
||||
GIT_ATTR_VALUE_T,
|
||||
} git_attr_t;
|
||||
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
GIT_EXTERN(git_attr_t) git_attr_value(const char *attr);
|
||||
|
||||
/**
|
||||
* Check attribute flags: Reading values from index and working directory.
|
||||
*
|
||||
* When checking attributes, it is possible to check attribute files
|
||||
* in both the working directory (if there is one) and the index (if
|
||||
* there is one). You can explicitly choose where to check and in
|
||||
* which order using the following flags.
|
||||
*
|
||||
* Core git usually checks the working directory then the index,
|
||||
* except during a checkout when it checks the index first. It will
|
||||
* use index only for creating archives or for a bare repo (if an
|
||||
* index has been specified for the bare repo).
|
||||
*/
|
||||
#define GIT_ATTR_CHECK_FILE_THEN_INDEX 0
|
||||
#define GIT_ATTR_CHECK_INDEX_THEN_FILE 1
|
||||
#define GIT_ATTR_CHECK_INDEX_ONLY 2
|
||||
|
||||
/**
|
||||
* Check attribute flags: Using the system attributes file.
|
||||
*
|
||||
* Normally, attribute checks include looking in the /etc (or system
|
||||
* equivalent) directory for a `gitattributes` file. Passing this
|
||||
* flag will cause attribute checks to ignore that file.
|
||||
*/
|
||||
#define GIT_ATTR_CHECK_NO_SYSTEM (1 << 2)
|
||||
|
||||
/**
|
||||
* Look up the value of one git attribute for path.
|
||||
*
|
||||
* @param value_out Output of the value of the attribute. Use the GIT_ATTR_...
|
||||
* macros to test for TRUE, FALSE, UNSPECIFIED, etc. or just
|
||||
* use the string value for attributes set to a value. You
|
||||
* should NOT modify or free this value.
|
||||
* @param repo The repository containing the path.
|
||||
* @param flags A combination of GIT_ATTR_CHECK... flags.
|
||||
* @param path The path to check for attributes. Relative paths are
|
||||
* interpreted relative to the repo root. The file does
|
||||
* not have to exist, but if it does not, then it will be
|
||||
* treated as a plain file (not a directory).
|
||||
* @param name The name of the attribute to look up.
|
||||
*/
|
||||
GIT_EXTERN(int) git_attr_get(
|
||||
const char **value_out,
|
||||
git_repository *repo,
|
||||
uint32_t flags,
|
||||
const char *path,
|
||||
const char *name);
|
||||
|
||||
/**
|
||||
* Look up a list of git attributes for path.
|
||||
*
|
||||
* Use this if you have a known list of attributes that you want to
|
||||
* look up in a single call. This is somewhat more efficient than
|
||||
* calling `git_attr_get()` multiple times.
|
||||
*
|
||||
* For example, you might write:
|
||||
*
|
||||
* const char *attrs[] = { "crlf", "diff", "foo" };
|
||||
* const char **values[3];
|
||||
* git_attr_get_many(values, repo, 0, "my/fun/file.c", 3, attrs);
|
||||
*
|
||||
* Then you could loop through the 3 values to get the settings for
|
||||
* the three attributes you asked about.
|
||||
*
|
||||
* @param values An array of num_attr entries that will have string
|
||||
* pointers written into it for the values of the attributes.
|
||||
* You should not modify or free the values that are written
|
||||
* into this array (although of course, you should free the
|
||||
* array itself if you allocated it).
|
||||
* @param repo The repository containing the path.
|
||||
* @param flags A combination of GIT_ATTR_CHECK... flags.
|
||||
* @param path The path inside the repo to check attributes. This
|
||||
* does not have to exist, but if it does not, then
|
||||
* it will be treated as a plain file (i.e. not a directory).
|
||||
* @param num_attr The number of attributes being looked up
|
||||
* @param names An array of num_attr strings containing attribute names.
|
||||
*/
|
||||
GIT_EXTERN(int) git_attr_get_many(
|
||||
const char **values_out,
|
||||
git_repository *repo,
|
||||
uint32_t flags,
|
||||
const char *path,
|
||||
size_t num_attr,
|
||||
const char **names);
|
||||
|
||||
typedef int (*git_attr_foreach_cb)(const char *name, const char *value, void *payload);
|
||||
|
||||
/**
|
||||
* Loop over all the git attributes for a path.
|
||||
*
|
||||
* @param repo The repository containing the path.
|
||||
* @param flags A combination of GIT_ATTR_CHECK... flags.
|
||||
* @param path Path inside the repo to check attributes. This does not have
|
||||
* to exist, but if it does not, then it will be treated as a
|
||||
* plain file (i.e. not a directory).
|
||||
* @param callback Function to invoke on each attribute name and value. The
|
||||
* value may be NULL is the attribute is explicitly set to
|
||||
* UNSPECIFIED using the '!' sign. Callback will be invoked
|
||||
* only once per attribute name, even if there are multiple
|
||||
* rules for a given file. The highest priority rule will be
|
||||
* used. Return a non-zero value from this to stop looping.
|
||||
* @param payload Passed on as extra parameter to callback function.
|
||||
* @return 0 on success, GIT_EUSER on non-zero callback, or error code
|
||||
*/
|
||||
GIT_EXTERN(int) git_attr_foreach(
|
||||
git_repository *repo,
|
||||
uint32_t flags,
|
||||
const char *path,
|
||||
git_attr_foreach_cb callback,
|
||||
void *payload);
|
||||
|
||||
/**
|
||||
* Flush the gitattributes cache.
|
||||
*
|
||||
* Call this if you have reason to believe that the attributes files on
|
||||
* disk no longer match the cached contents of memory. This will cause
|
||||
* the attributes files to be reloaded the next time that an attribute
|
||||
* access function is called.
|
||||
*/
|
||||
GIT_EXTERN(void) git_attr_cache_flush(
|
||||
git_repository *repo);
|
||||
|
||||
/**
|
||||
* Add a macro definition.
|
||||
*
|
||||
* Macros will automatically be loaded from the top level `.gitattributes`
|
||||
* file of the repository (plus the build-in "binary" macro). This
|
||||
* function allows you to add others. For example, to add the default
|
||||
* macro, you would call:
|
||||
*
|
||||
* git_attr_add_macro(repo, "binary", "-diff -crlf");
|
||||
*/
|
||||
GIT_EXTERN(int) git_attr_add_macro(
|
||||
git_repository *repo,
|
||||
const char *name,
|
||||
const char *values);
|
||||
|
||||
/** @} */
|
||||
GIT_END_DECL
|
||||
#endif
|
||||
|
||||
@@ -1,201 +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_blob_h__
|
||||
#define INCLUDE_git_blob_h__
|
||||
|
||||
#include "common.h"
|
||||
#include "types.h"
|
||||
#include "oid.h"
|
||||
#include "object.h"
|
||||
|
||||
/**
|
||||
* @file git2/blob.h
|
||||
* @brief Git blob load and write routines
|
||||
* @defgroup git_blob Git blob load and write routines
|
||||
* @ingroup Git
|
||||
* @{
|
||||
*/
|
||||
GIT_BEGIN_DECL
|
||||
|
||||
/**
|
||||
* Lookup a blob object from a repository.
|
||||
*
|
||||
* @param blob pointer to the looked up blob
|
||||
* @param repo the repo to use when locating the blob.
|
||||
* @param id identity of the blob to locate.
|
||||
* @return 0 or an error code
|
||||
*/
|
||||
GIT_INLINE(int) git_blob_lookup(git_blob **blob, git_repository *repo, const git_oid *id)
|
||||
{
|
||||
return git_object_lookup((git_object **)blob, repo, id, GIT_OBJ_BLOB);
|
||||
}
|
||||
|
||||
/**
|
||||
* Lookup a blob object from a repository,
|
||||
* given a prefix of its identifier (short id).
|
||||
*
|
||||
* @see git_object_lookup_prefix
|
||||
*
|
||||
* @param blob pointer to the looked up blob
|
||||
* @param repo the repo to use when locating the blob.
|
||||
* @param id identity of the blob to locate.
|
||||
* @param len the length of the short identifier
|
||||
* @return 0 or an error code
|
||||
*/
|
||||
GIT_INLINE(int) git_blob_lookup_prefix(git_blob **blob, git_repository *repo, const git_oid *id, size_t len)
|
||||
{
|
||||
return git_object_lookup_prefix((git_object **)blob, repo, id, len, GIT_OBJ_BLOB);
|
||||
}
|
||||
|
||||
/**
|
||||
* Close an open blob
|
||||
*
|
||||
* This is a wrapper around git_object_free()
|
||||
*
|
||||
* IMPORTANT:
|
||||
* It *is* necessary to call this method when you stop
|
||||
* using a blob. Failure to do so will cause a memory leak.
|
||||
*
|
||||
* @param blob the blob to close
|
||||
*/
|
||||
|
||||
GIT_INLINE(void) git_blob_free(git_blob *blob)
|
||||
{
|
||||
git_object_free((git_object *) blob);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the id of a blob.
|
||||
*
|
||||
* @param blob a previously loaded blob.
|
||||
* @return SHA1 hash for this blob.
|
||||
*/
|
||||
GIT_INLINE(const git_oid *) git_blob_id(const git_blob *blob)
|
||||
{
|
||||
return git_object_id((const git_object *)blob);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get a read-only buffer with the raw content of a blob.
|
||||
*
|
||||
* A pointer to the raw content of a blob is returned;
|
||||
* this pointer is owned internally by the object and shall
|
||||
* not be free'd. The pointer may be invalidated at a later
|
||||
* time.
|
||||
*
|
||||
* @param blob pointer to the blob
|
||||
* @return the pointer; NULL if the blob has no contents
|
||||
*/
|
||||
GIT_EXTERN(const void *) git_blob_rawcontent(const git_blob *blob);
|
||||
|
||||
/**
|
||||
* Get the size in bytes of the contents of a blob
|
||||
*
|
||||
* @param blob pointer to the blob
|
||||
* @return size on bytes
|
||||
*/
|
||||
GIT_EXTERN(git_off_t) git_blob_rawsize(const git_blob *blob);
|
||||
|
||||
/**
|
||||
* Read a file from the working folder of a repository
|
||||
* and write it to the Object Database as a loose blob
|
||||
*
|
||||
* @param id return the id of the written blob
|
||||
* @param repo repository where the blob will be written.
|
||||
* this repository cannot be bare
|
||||
* @param relative_path file from which the blob will be created,
|
||||
* relative to the repository's working dir
|
||||
* @return 0 or an error code
|
||||
*/
|
||||
GIT_EXTERN(int) git_blob_create_fromworkdir(git_oid *id, git_repository *repo, const char *relative_path);
|
||||
|
||||
/**
|
||||
* Read a file from the filesystem and write its content
|
||||
* to the Object Database as a loose blob
|
||||
*
|
||||
* @param id return the id of the written blob
|
||||
* @param repo repository where the blob will be written.
|
||||
* this repository can be bare or not
|
||||
* @param path file from which the blob will be created
|
||||
* @return 0 or an error code
|
||||
*/
|
||||
GIT_EXTERN(int) git_blob_create_fromdisk(git_oid *id, git_repository *repo, const char *path);
|
||||
|
||||
|
||||
typedef int (*git_blob_chunk_cb)(char *content, size_t max_length, void *payload);
|
||||
|
||||
/**
|
||||
* Write a loose blob to the Object Database from a
|
||||
* provider of chunks of data.
|
||||
*
|
||||
* Provided the `hintpath` parameter is filled, its value
|
||||
* will help to determine what git filters should be applied
|
||||
* to the object before it can be placed to the object database.
|
||||
*
|
||||
*
|
||||
* The implementation of the callback has to respect the
|
||||
* following rules:
|
||||
*
|
||||
* - `content` will have to be filled by the consumer. The maximum number
|
||||
* of bytes that the buffer can accept per call is defined by the
|
||||
* `max_length` parameter. Allocation and freeing of the buffer will be taken
|
||||
* care of by the function.
|
||||
*
|
||||
* - The callback is expected to return the number of bytes
|
||||
* that `content` have been filled with.
|
||||
*
|
||||
* - When there is no more data to stream, the callback should
|
||||
* return 0. This will prevent it from being invoked anymore.
|
||||
*
|
||||
* - When an error occurs, the callback should return -1.
|
||||
*
|
||||
*
|
||||
* @param id Return the id of the written blob
|
||||
*
|
||||
* @param repo repository where the blob will be written.
|
||||
* This repository can be bare or not.
|
||||
*
|
||||
* @param hintpath if not NULL, will help selecting the filters
|
||||
* to apply onto the content of the blob to be created.
|
||||
*
|
||||
* @return GIT_SUCCESS or an error code
|
||||
*/
|
||||
GIT_EXTERN(int) git_blob_create_fromchunks(
|
||||
git_oid *id,
|
||||
git_repository *repo,
|
||||
const char *hintpath,
|
||||
git_blob_chunk_cb callback,
|
||||
void *payload);
|
||||
|
||||
/**
|
||||
* Write an in-memory buffer to the ODB as a blob
|
||||
*
|
||||
* @param oid return the oid of the written blob
|
||||
* @param repo repository where to blob will be written
|
||||
* @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_blob_create_frombuffer(git_oid *oid, git_repository *repo, const void *buffer, size_t len);
|
||||
|
||||
/**
|
||||
* Determine if the blob content is most certainly binary or not.
|
||||
*
|
||||
* The heuristic used to guess if a file is binary is taken from core git:
|
||||
* Searching for NUL bytes and looking for a reasonable ratio of printable
|
||||
* to non-printable characters among the first 4000 bytes.
|
||||
*
|
||||
* @param blob The blob which content should be analyzed
|
||||
* @return 1 if the content of the blob is detected
|
||||
* as binary; 0 otherwise.
|
||||
*/
|
||||
GIT_EXTERN(int) git_blob_is_binary(git_blob *blob);
|
||||
|
||||
/** @} */
|
||||
GIT_END_DECL
|
||||
#endif
|
||||
@@ -1,173 +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_branch_h__
|
||||
#define INCLUDE_git_branch_h__
|
||||
|
||||
#include "common.h"
|
||||
#include "oid.h"
|
||||
#include "types.h"
|
||||
|
||||
/**
|
||||
* @file git2/branch.h
|
||||
* @brief Git branch parsing routines
|
||||
* @defgroup git_branch Git branch management
|
||||
* @ingroup Git
|
||||
* @{
|
||||
*/
|
||||
GIT_BEGIN_DECL
|
||||
|
||||
/**
|
||||
* Create a new branch pointing at a target commit
|
||||
*
|
||||
* A new direct reference will be created pointing to
|
||||
* this target commit. If `force` is true and a reference
|
||||
* already exists with the given name, it'll be replaced.
|
||||
*
|
||||
* The returned reference must be freed by the user.
|
||||
*
|
||||
* The branch name will be checked for validity.
|
||||
* See `git_tag_create()` for rules about valid names.
|
||||
*
|
||||
* @param out Pointer where to store the underlying reference.
|
||||
*
|
||||
* @param branch_name Name for the branch; this name is
|
||||
* validated for consistency. It should also not conflict with
|
||||
* an already existing branch name.
|
||||
*
|
||||
* @param target Object to which this branch should point. This object
|
||||
* must belong to the given `repo` and can either be a git_commit or a
|
||||
* git_tag. When a git_tag is being passed, it should be dereferencable
|
||||
* to a git_commit which oid will be used as the target of the branch.
|
||||
*
|
||||
* @param force Overwrite existing branch.
|
||||
*
|
||||
* @return 0, GIT_EINVALIDSPEC or an error code.
|
||||
* A proper reference is written in the refs/heads namespace
|
||||
* pointing to the provided target commit.
|
||||
*/
|
||||
GIT_EXTERN(int) git_branch_create(
|
||||
git_reference **out,
|
||||
git_repository *repo,
|
||||
const char *branch_name,
|
||||
const git_commit *target,
|
||||
int force);
|
||||
|
||||
/**
|
||||
* Delete an existing branch reference.
|
||||
*
|
||||
* If the branch is successfully deleted, the passed reference
|
||||
* object will be freed and invalidated.
|
||||
*
|
||||
* @param branch A valid reference representing a branch
|
||||
* @return 0 on success, or an error code.
|
||||
*/
|
||||
GIT_EXTERN(int) git_branch_delete(git_reference *branch);
|
||||
|
||||
/**
|
||||
* Loop over all the branches and issue a callback for each one.
|
||||
*
|
||||
* If the callback returns a non-zero value, this will stop looping.
|
||||
*
|
||||
* @param repo Repository where to find the branches.
|
||||
*
|
||||
* @param list_flags Filtering flags for the branch
|
||||
* listing. Valid values are GIT_BRANCH_LOCAL, GIT_BRANCH_REMOTE
|
||||
* or a combination of the two.
|
||||
*
|
||||
* @param branch_cb Callback to invoke per found branch.
|
||||
*
|
||||
* @param payload Extra parameter to callback function.
|
||||
*
|
||||
* @return 0 on success, GIT_EUSER on non-zero callback, or error code
|
||||
*/
|
||||
GIT_EXTERN(int) git_branch_foreach(
|
||||
git_repository *repo,
|
||||
unsigned int list_flags,
|
||||
int (*branch_cb)(
|
||||
const char *branch_name,
|
||||
git_branch_t branch_type,
|
||||
void *payload),
|
||||
void *payload
|
||||
);
|
||||
|
||||
/**
|
||||
* Move/rename an existing local branch reference.
|
||||
*
|
||||
* The new branch name will be checked for validity.
|
||||
* See `git_tag_create()` for rules about valid names.
|
||||
*
|
||||
* @param branch Current underlying reference of the branch.
|
||||
*
|
||||
* @param new_branch_name Target name of the branch once the move
|
||||
* is performed; this name is validated for consistency.
|
||||
*
|
||||
* @param force Overwrite existing branch.
|
||||
*
|
||||
* @return 0 on success, GIT_EINVALIDSPEC or an error code.
|
||||
*/
|
||||
GIT_EXTERN(int) git_branch_move(
|
||||
git_reference *branch,
|
||||
const char *new_branch_name,
|
||||
int force);
|
||||
|
||||
/**
|
||||
* Lookup a branch by its name in a repository.
|
||||
*
|
||||
* The generated reference must be freed by the user.
|
||||
*
|
||||
* The branch name will be checked for validity.
|
||||
* See `git_tag_create()` for rules about valid names.
|
||||
*
|
||||
* @param out pointer to the looked-up branch reference
|
||||
*
|
||||
* @param repo the repository to look up the branch
|
||||
*
|
||||
* @param branch_name Name of the branch to be looked-up;
|
||||
* this name is validated for consistency.
|
||||
*
|
||||
* @param branch_type Type of the considered branch. This should
|
||||
* be valued with either GIT_BRANCH_LOCAL or GIT_BRANCH_REMOTE.
|
||||
*
|
||||
* @return 0 on success; GIT_ENOTFOUND when no matching branch
|
||||
* exists, GIT_EINVALIDSPEC, otherwise an error code.
|
||||
*/
|
||||
GIT_EXTERN(int) git_branch_lookup(
|
||||
git_reference **out,
|
||||
git_repository *repo,
|
||||
const char *branch_name,
|
||||
git_branch_t branch_type);
|
||||
|
||||
/**
|
||||
* Return the reference supporting the remote tracking branch,
|
||||
* given a local branch reference.
|
||||
*
|
||||
* @param out Pointer where to store the retrieved
|
||||
* reference.
|
||||
*
|
||||
* @param branch Current underlying reference of the branch.
|
||||
*
|
||||
* @return 0 on success; GIT_ENOTFOUND when no remote tracking
|
||||
* reference exists, otherwise an error code.
|
||||
*/
|
||||
GIT_EXTERN(int) git_branch_tracking(
|
||||
git_reference **out,
|
||||
git_reference *branch);
|
||||
|
||||
/**
|
||||
* Determine if the current local branch is pointed at by HEAD.
|
||||
*
|
||||
* @param branch Current underlying reference of the branch.
|
||||
*
|
||||
* @return 1 if HEAD points at the branch, 0 if it isn't,
|
||||
* error code otherwise.
|
||||
*/
|
||||
GIT_EXTERN(int) git_branch_is_head(
|
||||
git_reference *branch);
|
||||
|
||||
/** @} */
|
||||
GIT_END_DECL
|
||||
#endif
|
||||
@@ -1,281 +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_checkout_h__
|
||||
#define INCLUDE_git_checkout_h__
|
||||
|
||||
#include "common.h"
|
||||
#include "types.h"
|
||||
#include "diff.h"
|
||||
|
||||
/**
|
||||
* @file git2/checkout.h
|
||||
* @brief Git checkout routines
|
||||
* @defgroup git_checkout Git checkout routines
|
||||
* @ingroup Git
|
||||
* @{
|
||||
*/
|
||||
GIT_BEGIN_DECL
|
||||
|
||||
/**
|
||||
* Checkout behavior flags
|
||||
*
|
||||
* In libgit2, checkout is used to update the working directory and index
|
||||
* to match a target tree. Unlike git checkout, it does not move the HEAD
|
||||
* commit for you - use `git_repository_set_head` or the like to do that.
|
||||
*
|
||||
* Checkout looks at (up to) four things: the "target" tree you want to
|
||||
* 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:
|
||||
*
|
||||
* - `GIT_CHECKOUT_NONE` is a dry-run strategy that checks for conflicts,
|
||||
* etc., but doesn't make any actual changes.
|
||||
*
|
||||
* - `GIT_CHECKOUT_FORCE` is at the opposite extreme, taking any action to
|
||||
* 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.
|
||||
*
|
||||
* | target == baseline | target != baseline |
|
||||
* ---------------------|-----------------------|----------------------|
|
||||
* workdir == baseline | no action | create, update, or |
|
||||
* | | delete file |
|
||||
* ---------------------|-----------------------|----------------------|
|
||||
* 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 | |
|
||||
* ---------------------|-----------------------|----------------------|
|
||||
*
|
||||
* 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
|
||||
* 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:
|
||||
*
|
||||
* - GIT_CHECKOUT_ALLOW_CONFLICTS makes SAFE mode apply safe file updates
|
||||
* even if there are conflicts (instead of cancelling the checkout).
|
||||
*
|
||||
* - GIT_CHECKOUT_REMOVE_UNTRACKED means remove untracked files (i.e. not
|
||||
* in target, baseline, or index, and not ignored) from the working dir.
|
||||
*
|
||||
* - GIT_CHECKOUT_REMOVE_IGNORED means remove ignored files (that are also
|
||||
* untracked) from the working directory as well.
|
||||
*
|
||||
* - GIT_CHECKOUT_UPDATE_ONLY means to only update the content of files that
|
||||
* already exist. Files will not be created nor deleted. This just skips
|
||||
* applying adds, deletes, and typechanges.
|
||||
*
|
||||
* - GIT_CHECKOUT_DONT_UPDATE_INDEX prevents checkout from writing the
|
||||
* updated files' information to the index.
|
||||
*
|
||||
* - Normally, checkout will reload the index and git attributes from disk
|
||||
* before any operations. GIT_CHECKOUT_NO_REFRESH prevents this reload.
|
||||
*
|
||||
* - Unmerged index entries are conflicts. GIT_CHECKOUT_SKIP_UNMERGED skips
|
||||
* files with unmerged index entries instead. GIT_CHECKOUT_USE_OURS and
|
||||
* GIT_CHECKOUT_USE_THEIRS to proceed with the checkout using either the
|
||||
* stage 2 ("ours") or stage 3 ("theirs") version of files in the index.
|
||||
*/
|
||||
typedef enum {
|
||||
GIT_CHECKOUT_NONE = 0, /** default is a dry run, no actual updates */
|
||||
|
||||
/** 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),
|
||||
|
||||
|
||||
/** Allow checkout to make safe updates even if conflicts are found */
|
||||
GIT_CHECKOUT_ALLOW_CONFLICTS = (1u << 4),
|
||||
|
||||
/** Remove untracked files not in index (that are not ignored) */
|
||||
GIT_CHECKOUT_REMOVE_UNTRACKED = (1u << 5),
|
||||
|
||||
/** Remove ignored files not in index */
|
||||
GIT_CHECKOUT_REMOVE_IGNORED = (1u << 6),
|
||||
|
||||
/** 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 */
|
||||
GIT_CHECKOUT_DONT_UPDATE_INDEX = (1u << 8),
|
||||
|
||||
/** Don't refresh index/config/etc before doing checkout */
|
||||
GIT_CHECKOUT_NO_REFRESH = (1u << 9),
|
||||
|
||||
/**
|
||||
* THE FOLLOWING OPTIONS ARE NOT YET IMPLEMENTED
|
||||
*/
|
||||
|
||||
/** Allow checkout to skip unmerged files (NOT IMPLEMENTED) */
|
||||
GIT_CHECKOUT_SKIP_UNMERGED = (1u << 10),
|
||||
/** For unmerged files, checkout stage 2 from index (NOT IMPLEMENTED) */
|
||||
GIT_CHECKOUT_USE_OURS = (1u << 11),
|
||||
/** For unmerged files, checkout stage 3 from index (NOT IMPLEMENTED) */
|
||||
GIT_CHECKOUT_USE_THEIRS = (1u << 12),
|
||||
|
||||
/** Recursively checkout submodules with same options (NOT IMPLEMENTED) */
|
||||
GIT_CHECKOUT_UPDATE_SUBMODULES = (1u << 16),
|
||||
/** Recursively checkout submodules if HEAD moved in super repo (NOT IMPLEMENTED) */
|
||||
GIT_CHECKOUT_UPDATE_SUBMODULES_IF_CHANGED = (1u << 17),
|
||||
|
||||
} git_checkout_strategy_t;
|
||||
|
||||
/**
|
||||
* Checkout notification flags
|
||||
*
|
||||
* Checkout will invoke an options notification callback (`notify_cb`) for
|
||||
* certain cases - you pick which ones via `notify_flags`:
|
||||
*
|
||||
* - GIT_CHECKOUT_NOTIFY_CONFLICT invokes checkout on conflicting paths.
|
||||
*
|
||||
* - GIT_CHECKOUT_NOTIFY_DIRTY notifies about "dirty" files, i.e. those that
|
||||
* do not need an update but no longer match the baseline. Core git
|
||||
* displays these files when checkout runs, but won't stop the checkout.
|
||||
*
|
||||
* - GIT_CHECKOUT_NOTIFY_UPDATED sends notification for any file changed.
|
||||
*
|
||||
* - GIT_CHECKOUT_NOTIFY_UNTRACKED notifies about untracked files.
|
||||
*
|
||||
* - GIT_CHECKOUT_NOTIFY_IGNORED notifies about ignored files.
|
||||
*
|
||||
* Returning a non-zero value from this callback will cancel the checkout.
|
||||
* Notification callbacks are made prior to modifying any files on disk.
|
||||
*/
|
||||
typedef enum {
|
||||
GIT_CHECKOUT_NOTIFY_NONE = 0,
|
||||
GIT_CHECKOUT_NOTIFY_CONFLICT = (1u << 0),
|
||||
GIT_CHECKOUT_NOTIFY_DIRTY = (1u << 1),
|
||||
GIT_CHECKOUT_NOTIFY_UPDATED = (1u << 2),
|
||||
GIT_CHECKOUT_NOTIFY_UNTRACKED = (1u << 3),
|
||||
GIT_CHECKOUT_NOTIFY_IGNORED = (1u << 4),
|
||||
} git_checkout_notify_t;
|
||||
|
||||
/** Checkout notification callback function */
|
||||
typedef int (*git_checkout_notify_cb)(
|
||||
git_checkout_notify_t why,
|
||||
const char *path,
|
||||
const git_diff_file *baseline,
|
||||
const git_diff_file *target,
|
||||
const git_diff_file *workdir,
|
||||
void *payload);
|
||||
|
||||
/** Checkout progress notification function */
|
||||
typedef void (*git_checkout_progress_cb)(
|
||||
const char *path,
|
||||
size_t completed_steps,
|
||||
size_t total_steps,
|
||||
void *payload);
|
||||
|
||||
/**
|
||||
* Checkout options structure
|
||||
*
|
||||
* Zero out for defaults. Initialize with `GIT_CHECKOUT_OPTS_INIT` macro to
|
||||
* correctly set the `version` field. E.g.
|
||||
*
|
||||
* git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
|
||||
*/
|
||||
typedef struct git_checkout_opts {
|
||||
unsigned int version;
|
||||
|
||||
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 */
|
||||
|
||||
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. */
|
||||
git_checkout_progress_cb progress_cb;
|
||||
void *progress_payload;
|
||||
|
||||
/** When not zeroed out, array of fnmatch patterns specifying which
|
||||
* paths should be taken into account, otherwise all files.
|
||||
*/
|
||||
git_strarray paths;
|
||||
|
||||
git_tree *baseline; /** expected content of workdir, defaults to HEAD */
|
||||
} git_checkout_opts;
|
||||
|
||||
#define GIT_CHECKOUT_OPTS_VERSION 1
|
||||
#define GIT_CHECKOUT_OPTS_INIT {GIT_CHECKOUT_OPTS_VERSION}
|
||||
|
||||
/**
|
||||
* Updates files in the index and the working tree to match the content of
|
||||
* the commit pointed at by HEAD.
|
||||
*
|
||||
* @param repo repository to check out (must be non-bare)
|
||||
* @param opts specifies checkout options (may be NULL)
|
||||
* @return 0 on success, GIT_EORPHANEDHEAD when HEAD points to a non existing
|
||||
* branch, GIT_ERROR otherwise (use giterr_last for information
|
||||
* about the error)
|
||||
*/
|
||||
GIT_EXTERN(int) git_checkout_head(
|
||||
git_repository *repo,
|
||||
git_checkout_opts *opts);
|
||||
|
||||
/**
|
||||
* Updates files in the working tree to match the content of the index.
|
||||
*
|
||||
* @param repo repository into which to check out (must be non-bare)
|
||||
* @param index index to be checked out (or NULL to use repository index)
|
||||
* @param opts specifies checkout options (may be NULL)
|
||||
* @return 0 on success, GIT_ERROR otherwise (use giterr_last for information
|
||||
* about the error)
|
||||
*/
|
||||
GIT_EXTERN(int) git_checkout_index(
|
||||
git_repository *repo,
|
||||
git_index *index,
|
||||
git_checkout_opts *opts);
|
||||
|
||||
/**
|
||||
* Updates files in the index and working tree to match the content of the
|
||||
* tree pointed at by the treeish.
|
||||
*
|
||||
* @param repo repository to check out (must be non-bare)
|
||||
* @param treeish a commit, tag or tree which content will be used to update
|
||||
* the working directory
|
||||
* @param opts specifies checkout options (may be NULL)
|
||||
* @return 0 on success, GIT_ERROR otherwise (use giterr_last for information
|
||||
* about the error)
|
||||
*/
|
||||
GIT_EXTERN(int) git_checkout_tree(
|
||||
git_repository *repo,
|
||||
const git_object *treeish,
|
||||
git_checkout_opts *opts);
|
||||
|
||||
/** @} */
|
||||
GIT_END_DECL
|
||||
#endif
|
||||
@@ -1,104 +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_clone_h__
|
||||
#define INCLUDE_git_clone_h__
|
||||
|
||||
#include "common.h"
|
||||
#include "types.h"
|
||||
#include "indexer.h"
|
||||
#include "checkout.h"
|
||||
#include "remote.h"
|
||||
|
||||
|
||||
/**
|
||||
* @file git2/clone.h
|
||||
* @brief Git cloning routines
|
||||
* @defgroup git_clone Git cloning routines
|
||||
* @ingroup Git
|
||||
* @{
|
||||
*/
|
||||
GIT_BEGIN_DECL
|
||||
|
||||
/**
|
||||
* Clone options structure
|
||||
*
|
||||
* Use zeros to indicate default settings. It's easiest to use the
|
||||
* `GIT_CLONE_OPTIONS_INIT` macro:
|
||||
*
|
||||
* git_clone_options opts = GIT_CLONE_OPTIONS_INIT;
|
||||
*
|
||||
* - `checkout_opts` is options for the checkout step. To disable checkout,
|
||||
* set the `checkout_strategy` to GIT_CHECKOUT_DEFAULT.
|
||||
* - `bare` should be set to zero to create a standard repo, non-zero for
|
||||
* a bare repo
|
||||
* - `fetch_progress_cb` is optional callback for fetch progress. Be aware that
|
||||
* this is called inline with network and indexing operations, so performance
|
||||
* may be affected.
|
||||
* - `fetch_progress_payload` is payload for fetch_progress_cb
|
||||
*
|
||||
* ** "origin" remote options: **
|
||||
* - `remote_name` is the name given to the "origin" remote. The default is
|
||||
* "origin".
|
||||
* - `pushurl` is a URL to be used for pushing. NULL means use the fetch url.
|
||||
* - `fetch_spec` is the fetch specification to be used for fetching. NULL
|
||||
* results in the same behavior as GIT_REMOTE_DEFAULT_FETCH.
|
||||
* - `push_spec` is the fetch specification to be used for pushing. NULL means
|
||||
* use the same spec as for fetching.
|
||||
* - `cred_acquire_cb` is a callback to be used if credentials are required
|
||||
* during the initial fetch.
|
||||
* - `cred_acquire_payload` is the payload for the above callback.
|
||||
* - `transport` is a custom transport to be used for the initial fetch. NULL
|
||||
* means use the transport autodetected from the URL.
|
||||
* - `remote_callbacks` may be used to specify custom progress callbacks for
|
||||
* the origin remote before the fetch is initiated.
|
||||
* - `remote_autotag` may be used to specify the autotag setting before the
|
||||
* initial fetch.
|
||||
*/
|
||||
|
||||
typedef struct git_clone_options {
|
||||
unsigned int version;
|
||||
|
||||
git_checkout_opts checkout_opts;
|
||||
int bare;
|
||||
git_transfer_progress_callback fetch_progress_cb;
|
||||
void *fetch_progress_payload;
|
||||
|
||||
const char *remote_name;
|
||||
const char *pushurl;
|
||||
const char *fetch_spec;
|
||||
const char *push_spec;
|
||||
git_cred_acquire_cb cred_acquire_cb;
|
||||
void *cred_acquire_payload;
|
||||
git_transport *transport;
|
||||
git_remote_callbacks *remote_callbacks;
|
||||
git_remote_autotag_option_t remote_autotag;
|
||||
} git_clone_options;
|
||||
|
||||
#define GIT_CLONE_OPTIONS_VERSION 1
|
||||
#define GIT_CLONE_OPTIONS_INIT {GIT_CLONE_OPTIONS_VERSION, {GIT_CHECKOUT_OPTS_VERSION, GIT_CHECKOUT_SAFE}}
|
||||
|
||||
/**
|
||||
* Clone a remote repository, and checkout the branch pointed to by the remote
|
||||
* HEAD.
|
||||
*
|
||||
* @param out pointer that will receive the resulting repository object
|
||||
* @param origin_remote a remote which will act as the initial fetch source
|
||||
* @param local_path local directory to clone to
|
||||
* @param options configuration options for the clone. If NULL, the function
|
||||
* works as though GIT_OPTIONS_INIT were passed.
|
||||
* @return 0 on success, GIT_ERROR otherwise (use giterr_last for information
|
||||
* about the error)
|
||||
*/
|
||||
GIT_EXTERN(int) git_clone(
|
||||
git_repository **out,
|
||||
const char *url,
|
||||
const char *local_path,
|
||||
const git_clone_options *options);
|
||||
|
||||
/** @} */
|
||||
GIT_END_DECL
|
||||
#endif
|
||||
@@ -1,292 +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_commit_h__
|
||||
#define INCLUDE_git_commit_h__
|
||||
|
||||
#include "common.h"
|
||||
#include "types.h"
|
||||
#include "oid.h"
|
||||
#include "object.h"
|
||||
|
||||
/**
|
||||
* @file git2/commit.h
|
||||
* @brief Git commit parsing, formatting routines
|
||||
* @defgroup git_commit Git commit parsing, formatting routines
|
||||
* @ingroup Git
|
||||
* @{
|
||||
*/
|
||||
GIT_BEGIN_DECL
|
||||
|
||||
/**
|
||||
* Lookup a commit object from a repository.
|
||||
*
|
||||
* @param commit pointer to the looked up commit
|
||||
* @param repo the repo to use when locating the commit.
|
||||
* @param id identity of the commit to locate. If the object is
|
||||
* an annotated tag it will be peeled back to the commit.
|
||||
* @return 0 or an error code
|
||||
*/
|
||||
GIT_INLINE(int) git_commit_lookup(git_commit **commit, git_repository *repo, const git_oid *id)
|
||||
{
|
||||
return git_object_lookup((git_object **)commit, repo, id, GIT_OBJ_COMMIT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Lookup a commit object from a repository,
|
||||
* given a prefix of its identifier (short id).
|
||||
*
|
||||
* @see git_object_lookup_prefix
|
||||
*
|
||||
* @param commit pointer to the looked up commit
|
||||
* @param repo the repo to use when locating the commit.
|
||||
* @param id identity of the commit to locate. If the object is
|
||||
* an annotated tag it will be peeled back to the commit.
|
||||
* @param len the length of the short identifier
|
||||
* @return 0 or an error code
|
||||
*/
|
||||
GIT_INLINE(int) git_commit_lookup_prefix(git_commit **commit, git_repository *repo, const git_oid *id, size_t len)
|
||||
{
|
||||
return git_object_lookup_prefix((git_object **)commit, repo, id, len, GIT_OBJ_COMMIT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Close an open commit
|
||||
*
|
||||
* This is a wrapper around git_object_free()
|
||||
*
|
||||
* IMPORTANT:
|
||||
* It *is* necessary to call this method when you stop
|
||||
* using a commit. Failure to do so will cause a memory leak.
|
||||
*
|
||||
* @param commit the commit to close
|
||||
*/
|
||||
|
||||
GIT_INLINE(void) git_commit_free(git_commit *commit)
|
||||
{
|
||||
git_object_free((git_object *) commit);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the id of a commit.
|
||||
*
|
||||
* @param commit a previously loaded commit.
|
||||
* @return object identity for the commit.
|
||||
*/
|
||||
GIT_INLINE(const git_oid *) git_commit_id(const git_commit *commit)
|
||||
{
|
||||
return git_object_id((const git_object *)commit);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the encoding for the message of a commit,
|
||||
* as a string representing a standard encoding name.
|
||||
*
|
||||
* The encoding may be NULL if the `encoding` header
|
||||
* in the commit is missing; in that case UTF-8 is assumed.
|
||||
*
|
||||
* @param commit a previously loaded commit.
|
||||
* @return NULL, or the encoding
|
||||
*/
|
||||
GIT_EXTERN(const char *) git_commit_message_encoding(const git_commit *commit);
|
||||
|
||||
/**
|
||||
* Get the full message of a commit.
|
||||
*
|
||||
* @param commit a previously loaded commit.
|
||||
* @return the message of a commit
|
||||
*/
|
||||
GIT_EXTERN(const char *) git_commit_message(const git_commit *commit);
|
||||
|
||||
/**
|
||||
* Get the commit time (i.e. committer time) of a commit.
|
||||
*
|
||||
* @param commit a previously loaded commit.
|
||||
* @return the time of a commit
|
||||
*/
|
||||
GIT_EXTERN(git_time_t) git_commit_time(const git_commit *commit);
|
||||
|
||||
/**
|
||||
* Get the commit timezone offset (i.e. committer's preferred timezone) of a commit.
|
||||
*
|
||||
* @param commit a previously loaded commit.
|
||||
* @return positive or negative timezone offset, in minutes from UTC
|
||||
*/
|
||||
GIT_EXTERN(int) git_commit_time_offset(const git_commit *commit);
|
||||
|
||||
/**
|
||||
* Get the committer of a commit.
|
||||
*
|
||||
* @param commit a previously loaded commit.
|
||||
* @return the committer of a commit
|
||||
*/
|
||||
GIT_EXTERN(const git_signature *) git_commit_committer(const git_commit *commit);
|
||||
|
||||
/**
|
||||
* Get the author of a commit.
|
||||
*
|
||||
* @param commit a previously loaded commit.
|
||||
* @return the author of a commit
|
||||
*/
|
||||
GIT_EXTERN(const git_signature *) git_commit_author(const git_commit *commit);
|
||||
|
||||
/**
|
||||
* Get the tree pointed to by a commit.
|
||||
*
|
||||
* @param tree_out pointer where to store the tree object
|
||||
* @param commit a previously loaded commit.
|
||||
* @return 0 or an error code
|
||||
*/
|
||||
GIT_EXTERN(int) git_commit_tree(git_tree **tree_out, const git_commit *commit);
|
||||
|
||||
/**
|
||||
* Get the id of the tree pointed to by a commit. This differs from
|
||||
* `git_commit_tree` in that no attempts are made to fetch an object
|
||||
* from the ODB.
|
||||
*
|
||||
* @param commit a previously loaded commit.
|
||||
* @return the id of tree pointed to by commit.
|
||||
*/
|
||||
GIT_EXTERN(const git_oid *) git_commit_tree_id(const git_commit *commit);
|
||||
|
||||
/**
|
||||
* Get the number of parents of this commit
|
||||
*
|
||||
* @param commit a previously loaded commit.
|
||||
* @return integer of count of parents
|
||||
*/
|
||||
GIT_EXTERN(unsigned int) git_commit_parentcount(const git_commit *commit);
|
||||
|
||||
/**
|
||||
* Get the specified parent of the commit.
|
||||
*
|
||||
* @param out Pointer where to store the parent commit
|
||||
* @param commit a previously loaded commit.
|
||||
* @param n the position of the parent (from 0 to `parentcount`)
|
||||
* @return 0 or an error code
|
||||
*/
|
||||
GIT_EXTERN(int) git_commit_parent(git_commit **out, git_commit *commit, unsigned int n);
|
||||
|
||||
/**
|
||||
* Get the oid of a specified parent for a commit. This is different from
|
||||
* `git_commit_parent`, which will attempt to load the parent commit from
|
||||
* the ODB.
|
||||
*
|
||||
* @param commit a previously loaded commit.
|
||||
* @param n the position of the parent (from 0 to `parentcount`)
|
||||
* @return the id of the parent, NULL on error.
|
||||
*/
|
||||
GIT_EXTERN(const git_oid *) git_commit_parent_id(git_commit *commit, unsigned int n);
|
||||
|
||||
/**
|
||||
* Get the commit object that is the <n>th generation ancestor
|
||||
* of the named commit object, following only the first parents.
|
||||
* The returned commit has to be freed by the caller.
|
||||
*
|
||||
* Passing `0` as the generation number returns another instance of the
|
||||
* base commit itself.
|
||||
*
|
||||
* @param ancestor Pointer where to store the ancestor commit
|
||||
* @param commit a previously loaded commit.
|
||||
* @param n the requested generation
|
||||
* @return 0 on success; GIT_ENOTFOUND if no matching ancestor exists
|
||||
* or an error code
|
||||
*/
|
||||
GIT_EXTERN(int) git_commit_nth_gen_ancestor(
|
||||
git_commit **ancestor,
|
||||
const git_commit *commit,
|
||||
unsigned int n);
|
||||
|
||||
/**
|
||||
* Create a new commit in the repository using `git_object`
|
||||
* instances as parameters.
|
||||
*
|
||||
* The message will not be cleaned up. This can be achieved
|
||||
* through `git_message_prettify()`.
|
||||
*
|
||||
* @param id Pointer where to store the OID of the
|
||||
* newly created commit
|
||||
*
|
||||
* @param repo Repository where to store the commit
|
||||
*
|
||||
* @param update_ref If not NULL, name of the reference that
|
||||
* will be updated to point to this commit. If the reference
|
||||
* is not direct, it will be resolved to a direct reference.
|
||||
* Use "HEAD" to update the HEAD of the current branch and
|
||||
* make it point to this commit. If the reference doesn't
|
||||
* exist yet, it will be created.
|
||||
*
|
||||
* @param author Signature representing the author and the authory
|
||||
* time of this commit
|
||||
*
|
||||
* @param committer Signature representing the committer and the
|
||||
* commit time of this commit
|
||||
*
|
||||
* @param message_encoding The encoding for the message in the
|
||||
* commit, represented with a standard encoding name.
|
||||
* E.g. "UTF-8". If NULL, no encoding header is written and
|
||||
* UTF-8 is assumed.
|
||||
*
|
||||
* @param message Full message for this commit
|
||||
*
|
||||
* @param tree An instance of a `git_tree` object that will
|
||||
* be used as the tree for the commit. This tree object must
|
||||
* also be owned by the given `repo`.
|
||||
*
|
||||
* @param parent_count Number of parents for this commit
|
||||
*
|
||||
* @param parents[] Array of `parent_count` pointers to `git_commit`
|
||||
* objects that will be used as the parents for this commit. This
|
||||
* array may be NULL if `parent_count` is 0 (root commit). All the
|
||||
* given commits must be owned by the `repo`.
|
||||
*
|
||||
* @return 0 or an error code
|
||||
* The created commit will be written to the Object Database and
|
||||
* the given reference will be updated to point to it
|
||||
*/
|
||||
GIT_EXTERN(int) git_commit_create(
|
||||
git_oid *id,
|
||||
git_repository *repo,
|
||||
const char *update_ref,
|
||||
const git_signature *author,
|
||||
const git_signature *committer,
|
||||
const char *message_encoding,
|
||||
const char *message,
|
||||
const git_tree *tree,
|
||||
int parent_count,
|
||||
const git_commit *parents[]);
|
||||
|
||||
/**
|
||||
* Create a new commit in the repository using a variable
|
||||
* argument list.
|
||||
*
|
||||
* The message will be cleaned up from excess whitespace
|
||||
* it will be made sure that the last line ends with a '\n'.
|
||||
*
|
||||
* The parents for the commit are specified as a variable
|
||||
* list of pointers to `const git_commit *`. Note that this
|
||||
* is a convenience method which may not be safe to export
|
||||
* for certain languages or compilers
|
||||
*
|
||||
* All other parameters remain the same
|
||||
*
|
||||
* @see git_commit_create
|
||||
*/
|
||||
GIT_EXTERN(int) git_commit_create_v(
|
||||
git_oid *id,
|
||||
git_repository *repo,
|
||||
const char *update_ref,
|
||||
const git_signature *author,
|
||||
const git_signature *committer,
|
||||
const char *message_encoding,
|
||||
const char *message,
|
||||
const git_tree *tree,
|
||||
int parent_count,
|
||||
...);
|
||||
|
||||
/** @} */
|
||||
GIT_END_DECL
|
||||
#endif
|
||||
@@ -1,129 +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_common_h__
|
||||
#define INCLUDE_git_common_h__
|
||||
|
||||
#include <time.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifdef _MSC_VER
|
||||
# include "inttypes.h"
|
||||
#else
|
||||
# include <inttypes.h>
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
# define GIT_BEGIN_DECL extern "C" {
|
||||
# define GIT_END_DECL }
|
||||
#else
|
||||
/** Start declarations in C mode */
|
||||
# define GIT_BEGIN_DECL /* empty */
|
||||
/** End declarations in C mode */
|
||||
# define GIT_END_DECL /* empty */
|
||||
#endif
|
||||
|
||||
/** Declare a public function exported for application use. */
|
||||
#if __GNUC__ >= 4
|
||||
# define GIT_EXTERN(type) extern \
|
||||
__attribute__((visibility("default"))) \
|
||||
type
|
||||
#elif defined(_MSC_VER)
|
||||
# define GIT_EXTERN(type) __declspec(dllexport) type
|
||||
#else
|
||||
# define GIT_EXTERN(type) extern type
|
||||
#endif
|
||||
|
||||
/** Declare a function as always inlined. */
|
||||
#if defined(_MSC_VER)
|
||||
# define GIT_INLINE(type) static __inline type
|
||||
#else
|
||||
# define GIT_INLINE(type) static inline type
|
||||
#endif
|
||||
|
||||
/** Declare a function's takes printf style arguments. */
|
||||
#ifdef __GNUC__
|
||||
# define GIT_FORMAT_PRINTF(a,b) __attribute__((format (printf, a, b)))
|
||||
#else
|
||||
# define GIT_FORMAT_PRINTF(a,b) /* empty */
|
||||
#endif
|
||||
|
||||
#if (defined(_WIN32)) && !defined(__CYGWIN__)
|
||||
#define GIT_WIN32 1
|
||||
#endif
|
||||
|
||||
#ifdef __amigaos4__
|
||||
#include <netinet/in.h>
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @file git2/common.h
|
||||
* @brief Git common platform definitions
|
||||
* @defgroup git_common Git common platform definitions
|
||||
* @ingroup Git
|
||||
* @{
|
||||
*/
|
||||
|
||||
GIT_BEGIN_DECL
|
||||
|
||||
/**
|
||||
* The separator used in path list strings (ie like in the PATH
|
||||
* environment variable). A semi-colon ";" is used on Windows, and
|
||||
* a colon ":" for all other systems.
|
||||
*/
|
||||
#ifdef GIT_WIN32
|
||||
#define GIT_PATH_LIST_SEPARATOR ';'
|
||||
#else
|
||||
#define GIT_PATH_LIST_SEPARATOR ':'
|
||||
#endif
|
||||
|
||||
/**
|
||||
* The maximum length of a valid git path.
|
||||
*/
|
||||
#define GIT_PATH_MAX 4096
|
||||
|
||||
/**
|
||||
* The string representation of the null object ID.
|
||||
*/
|
||||
#define GIT_OID_HEX_ZERO "0000000000000000000000000000000000000000"
|
||||
|
||||
/**
|
||||
* Return the version of the libgit2 library
|
||||
* being currently used.
|
||||
*
|
||||
* @param major Store the major version number
|
||||
* @param minor Store the minor version number
|
||||
* @param rev Store the revision (patch) number
|
||||
*/
|
||||
GIT_EXTERN(void) git_libgit2_version(int *major, int *minor, int *rev);
|
||||
|
||||
/**
|
||||
* Combinations of these values describe the capabilities of libgit2.
|
||||
*/
|
||||
enum {
|
||||
GIT_CAP_THREADS = ( 1 << 0 ),
|
||||
GIT_CAP_HTTPS = ( 1 << 1 )
|
||||
};
|
||||
|
||||
/**
|
||||
* Query compile time options for libgit2.
|
||||
*
|
||||
* @return A combination of GIT_CAP_* values.
|
||||
*
|
||||
* - GIT_CAP_THREADS
|
||||
* Libgit2 was compiled with thread support. Note that thread support is still to be seen as a
|
||||
* 'work in progress'.
|
||||
*
|
||||
* - GIT_CAP_HTTPS
|
||||
* Libgit2 supports the https:// protocol. This requires the open ssl library to be
|
||||
* found when compiling libgit2.
|
||||
*/
|
||||
GIT_EXTERN(int) git_libgit2_capabilities(void);
|
||||
|
||||
/** @} */
|
||||
GIT_END_DECL
|
||||
|
||||
#endif
|
||||
@@ -1,554 +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_config_h__
|
||||
#define INCLUDE_git_config_h__
|
||||
|
||||
#include "common.h"
|
||||
#include "types.h"
|
||||
|
||||
/**
|
||||
* @file git2/config.h
|
||||
* @brief Git config management routines
|
||||
* @defgroup git_config Git config management routines
|
||||
* @ingroup Git
|
||||
* @{
|
||||
*/
|
||||
GIT_BEGIN_DECL
|
||||
|
||||
/**
|
||||
* Priority level of a config file.
|
||||
* These priority levels correspond to the natural escalation logic
|
||||
* (from higher to lower) when searching for config entries in git.git.
|
||||
*
|
||||
* git_config_open_default() and git_repository_config() honor those
|
||||
* priority levels as well.
|
||||
*/
|
||||
enum {
|
||||
GIT_CONFIG_LEVEL_SYSTEM = 1, /**< System-wide configuration file. */
|
||||
GIT_CONFIG_LEVEL_XDG = 2, /**< XDG compatible configuration file (.config/git/config). */
|
||||
GIT_CONFIG_LEVEL_GLOBAL = 3, /**< User-specific configuration file, also called Global configuration file. */
|
||||
GIT_CONFIG_LEVEL_LOCAL = 4, /**< Repository specific configuration file. */
|
||||
GIT_CONFIG_HIGHEST_LEVEL = -1, /**< Represents the highest level of a config file. */
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
const char *name;
|
||||
const char *value;
|
||||
unsigned int level;
|
||||
} git_config_entry;
|
||||
|
||||
typedef int (*git_config_foreach_cb)(const git_config_entry *, void *);
|
||||
|
||||
|
||||
/**
|
||||
* Generic backend that implements the interface to
|
||||
* access a configuration file
|
||||
*/
|
||||
struct git_config_backend {
|
||||
unsigned int version;
|
||||
struct git_config *cfg;
|
||||
|
||||
/* Open means open the file/database and parse if necessary */
|
||||
int (*open)(struct git_config_backend *, unsigned int level);
|
||||
int (*get)(const struct git_config_backend *, const char *key, const git_config_entry **entry);
|
||||
int (*get_multivar)(struct git_config_backend *, const char *key, const char *regexp, git_config_foreach_cb callback, void *payload);
|
||||
int (*set)(struct git_config_backend *, const char *key, const char *value);
|
||||
int (*set_multivar)(git_config_backend *cfg, const char *name, const char *regexp, const char *value);
|
||||
int (*del)(struct git_config_backend *, const char *key);
|
||||
int (*foreach)(struct git_config_backend *, const char *, git_config_foreach_cb callback, void *payload);
|
||||
int (*refresh)(struct git_config_backend *);
|
||||
void (*free)(struct git_config_backend *);
|
||||
};
|
||||
#define GIT_CONFIG_BACKEND_VERSION 1
|
||||
#define GIT_CONFIG_BACKEND_INIT {GIT_CONFIG_BACKEND_VERSION}
|
||||
|
||||
typedef enum {
|
||||
GIT_CVAR_FALSE = 0,
|
||||
GIT_CVAR_TRUE = 1,
|
||||
GIT_CVAR_INT32,
|
||||
GIT_CVAR_STRING
|
||||
} git_cvar_t;
|
||||
|
||||
typedef struct {
|
||||
git_cvar_t cvar_type;
|
||||
const char *str_match;
|
||||
int map_value;
|
||||
} git_cvar_map;
|
||||
|
||||
/**
|
||||
* Locate the path to the global configuration file
|
||||
*
|
||||
* The user or global configuration file is usually
|
||||
* located in `$HOME/.gitconfig`.
|
||||
*
|
||||
* This method will try to guess the full path to that
|
||||
* file, if the file exists. The returned path
|
||||
* may be used on any `git_config` call to load the
|
||||
* global configuration file.
|
||||
*
|
||||
* This method will not guess the path to the xdg compatible
|
||||
* config file (.config/git/config).
|
||||
*
|
||||
* @param out Buffer to store the path in
|
||||
* @param length size of the buffer in bytes
|
||||
* @return 0 if a global configuration file has been found. Its path will be stored in `buffer`.
|
||||
*/
|
||||
GIT_EXTERN(int) git_config_find_global(char *out, size_t length);
|
||||
|
||||
/**
|
||||
* Locate the path to the global xdg compatible configuration file
|
||||
*
|
||||
* The xdg compatible configuration file is usually
|
||||
* located in `$HOME/.config/git/config`.
|
||||
*
|
||||
* This method will try to guess the full path to that
|
||||
* file, if the file exists. The returned path
|
||||
* may be used on any `git_config` call to load the
|
||||
* xdg compatible configuration file.
|
||||
*
|
||||
* @param out Buffer to store the path in
|
||||
* @param length size of the buffer in bytes
|
||||
* @return 0 if a xdg compatible configuration file has been
|
||||
* found. Its path will be stored in `buffer`.
|
||||
*/
|
||||
GIT_EXTERN(int) git_config_find_xdg(char *out, size_t length);
|
||||
|
||||
/**
|
||||
* Locate the path to the system configuration file
|
||||
*
|
||||
* If /etc/gitconfig doesn't exist, it will look for
|
||||
* %PROGRAMFILES%\Git\etc\gitconfig.
|
||||
|
||||
* @param global_config_path Buffer to store the path in
|
||||
* @param length size of the buffer in bytes
|
||||
* @return 0 if a system configuration file has been
|
||||
* found. Its path will be stored in `buffer`.
|
||||
*/
|
||||
GIT_EXTERN(int) git_config_find_system(char *out, size_t length);
|
||||
|
||||
/**
|
||||
* Open the global, XDG and system configuration files
|
||||
*
|
||||
* Utility wrapper that finds the global, XDG and system configuration files
|
||||
* and opens them into a single prioritized config object that can be
|
||||
* used when accessing default config data outside a repository.
|
||||
*
|
||||
* @param out Pointer to store the config instance
|
||||
* @return 0 or an error code
|
||||
*/
|
||||
GIT_EXTERN(int) git_config_open_default(git_config **out);
|
||||
|
||||
/**
|
||||
* Allocate a new configuration object
|
||||
*
|
||||
* This object is empty, so you have to add a file to it before you
|
||||
* can do anything with it.
|
||||
*
|
||||
* @param out pointer to the new configuration
|
||||
* @return 0 or an error code
|
||||
*/
|
||||
GIT_EXTERN(int) git_config_new(git_config **out);
|
||||
|
||||
/**
|
||||
* Add a generic config file instance to an existing config
|
||||
*
|
||||
* Note that the configuration object will free the file
|
||||
* automatically.
|
||||
*
|
||||
* Further queries on this config object will access each
|
||||
* of the config file instances in order (instances with
|
||||
* a higher priority level will be accessed first).
|
||||
*
|
||||
* @param cfg the configuration to add the file to
|
||||
* @param file the configuration file (backend) to add
|
||||
* @param level the priority level of the backend
|
||||
* @param force if a config file already exists for the given
|
||||
* priority level, replace it
|
||||
* @return 0 on success, GIT_EEXISTS when adding more than one file
|
||||
* for a given priority level (and force_replace set to 0), or error code
|
||||
*/
|
||||
GIT_EXTERN(int) git_config_add_backend(
|
||||
git_config *cfg,
|
||||
git_config_backend *file,
|
||||
unsigned int level,
|
||||
int force);
|
||||
|
||||
/**
|
||||
* Add an on-disk config file instance to an existing config
|
||||
*
|
||||
* The on-disk file pointed at by `path` will be opened and
|
||||
* parsed; it's expected to be a native Git config file following
|
||||
* the default Git config syntax (see man git-config).
|
||||
*
|
||||
* Note that the configuration object will free the file
|
||||
* automatically.
|
||||
*
|
||||
* Further queries on this config object will access each
|
||||
* of the config file instances in order (instances with
|
||||
* a higher priority level will be accessed first).
|
||||
*
|
||||
* @param cfg the configuration to add the file to
|
||||
* @param path path to the configuration file (backend) to add
|
||||
* @param level the priority level of the backend
|
||||
* @param force if a config file already exists for the given
|
||||
* priority level, replace it
|
||||
* @return 0 on success, GIT_EEXISTS when adding more than one file
|
||||
* for a given priority level (and force_replace set to 0),
|
||||
* GIT_ENOTFOUND when the file doesn't exist or error code
|
||||
*/
|
||||
GIT_EXTERN(int) git_config_add_file_ondisk(
|
||||
git_config *cfg,
|
||||
const char *path,
|
||||
unsigned int level,
|
||||
int force);
|
||||
|
||||
/**
|
||||
* Create a new config instance containing a single on-disk file
|
||||
*
|
||||
* This method is a simple utility wrapper for the following sequence
|
||||
* of calls:
|
||||
* - git_config_new
|
||||
* - git_config_add_file_ondisk
|
||||
*
|
||||
* @param out The configuration instance to create
|
||||
* @param path Path to the on-disk file to open
|
||||
* @return 0 on success, GIT_ENOTFOUND when the file doesn't exist
|
||||
* or an error code
|
||||
*/
|
||||
GIT_EXTERN(int) git_config_open_ondisk(git_config **out, const char *path);
|
||||
|
||||
/**
|
||||
* Build a single-level focused config object from a multi-level one.
|
||||
*
|
||||
* The returned config object can be used to perform get/set/delete operations
|
||||
* on a single specific level.
|
||||
*
|
||||
* Getting several times the same level from the same parent multi-level config
|
||||
* will return different config instances, but containing the same config_file
|
||||
* instance.
|
||||
*
|
||||
* @param out The configuration instance to create
|
||||
* @param parent Multi-level config to search for the given level
|
||||
* @param level Configuration level to search for
|
||||
* @return 0, GIT_ENOTFOUND if the passed level cannot be found in the
|
||||
* multi-level parent config, or an error code
|
||||
*/
|
||||
GIT_EXTERN(int) git_config_open_level(
|
||||
git_config **out,
|
||||
const git_config *parent,
|
||||
unsigned int level);
|
||||
|
||||
/**
|
||||
* 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
|
||||
*
|
||||
* @param cfg the configuration to free
|
||||
*/
|
||||
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.
|
||||
|
||||
* @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,
|
||||
const git_config *cfg,
|
||||
const char *name);
|
||||
|
||||
/**
|
||||
* Get the value of an integer config variable.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* @param out pointer to the variable where the value should be stored
|
||||
* @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_int32(int32_t *out, const git_config *cfg, const char *name);
|
||||
|
||||
/**
|
||||
* Get the value of a long integer config variable.
|
||||
*
|
||||
* 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 where the value should be stored
|
||||
* @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_int64(int64_t *out, const git_config *cfg, const char *name);
|
||||
|
||||
/**
|
||||
* Get the value of a boolean config variable.
|
||||
*
|
||||
* This function uses the usual C convention of 0 being false and
|
||||
* anything else true.
|
||||
*
|
||||
* 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 where the value should be stored
|
||||
* @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_bool(int *out, const git_config *cfg, const char *name);
|
||||
|
||||
/**
|
||||
* Get the value of a string config variable.
|
||||
*
|
||||
* The string is owned by the variable and should not be freed by the
|
||||
* user.
|
||||
*
|
||||
* 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 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 each value of a multivar.
|
||||
*
|
||||
* The callback will be called on each variable found
|
||||
*
|
||||
* @param cfg where to look for the variable
|
||||
* @param name the variable's name
|
||||
* @param regexp regular expression to filter which variables we're
|
||||
* interested in. Use NULL to indicate all
|
||||
* @param fn the function to be called on each value of the variable
|
||||
* @param data opaque pointer to pass to the callback
|
||||
*/
|
||||
GIT_EXTERN(int) git_config_get_multivar(const git_config *cfg, const char *name, const char *regexp, git_config_foreach_cb callback, void *payload);
|
||||
|
||||
/**
|
||||
* Set the value of an integer config variable in the config file
|
||||
* with the highest level (usually the local one).
|
||||
*
|
||||
* @param cfg where to look for the variable
|
||||
* @param name the variable's name
|
||||
* @param value Integer value for the variable
|
||||
* @return 0 or an error code
|
||||
*/
|
||||
GIT_EXTERN(int) git_config_set_int32(git_config *cfg, const char *name, int32_t value);
|
||||
|
||||
/**
|
||||
* Set the value of a long integer config variable in the config file
|
||||
* with the highest level (usually the local one).
|
||||
*
|
||||
* @param cfg where to look for the variable
|
||||
* @param name the variable's name
|
||||
* @param value Long integer value for the variable
|
||||
* @return 0 or an error code
|
||||
*/
|
||||
GIT_EXTERN(int) git_config_set_int64(git_config *cfg, const char *name, int64_t value);
|
||||
|
||||
/**
|
||||
* Set the value of a boolean config variable in the config file
|
||||
* with the highest level (usually the local one).
|
||||
*
|
||||
* @param cfg where to look for the variable
|
||||
* @param name the variable's name
|
||||
* @param value the value to store
|
||||
* @return 0 or an error code
|
||||
*/
|
||||
GIT_EXTERN(int) git_config_set_bool(git_config *cfg, const char *name, int value);
|
||||
|
||||
/**
|
||||
* Set the value of a string config variable in the config file
|
||||
* with the highest level (usually the local one).
|
||||
*
|
||||
* A copy of the string is made and the user is free to use it
|
||||
* afterwards.
|
||||
*
|
||||
* @param cfg where to look for the variable
|
||||
* @param name the variable's name
|
||||
* @param value the string to store.
|
||||
* @return 0 or an error code
|
||||
*/
|
||||
GIT_EXTERN(int) git_config_set_string(git_config *cfg, const char *name, const char *value);
|
||||
|
||||
/**
|
||||
* Set a multivar in the local config file.
|
||||
*
|
||||
* @param cfg where to look for the variable
|
||||
* @param name the variable's name
|
||||
* @param regexp a regular expression to indicate which values to replace
|
||||
* @param value the new value.
|
||||
*/
|
||||
GIT_EXTERN(int) git_config_set_multivar(git_config *cfg, const char *name, const char *regexp, const char *value);
|
||||
|
||||
/**
|
||||
* Delete a config variable from the config file
|
||||
* with the highest level (usually the local one).
|
||||
*
|
||||
* @param cfg the configuration
|
||||
* @param name the variable to delete
|
||||
*/
|
||||
GIT_EXTERN(int) git_config_delete_entry(git_config *cfg, const char *name);
|
||||
|
||||
/**
|
||||
* Perform an operation on each config variable.
|
||||
*
|
||||
* The callback receives the normalized name and value of each variable
|
||||
* in the config backend, and the data pointer passed to this function.
|
||||
* As soon as one of the callback functions returns something other than 0,
|
||||
* this function stops iterating and returns `GIT_EUSER`.
|
||||
*
|
||||
* @param cfg where to get the variables from
|
||||
* @param callback the function to call on each variable
|
||||
* @param payload the data to pass to the callback
|
||||
* @return 0 on success, GIT_EUSER on non-zero callback, or error code
|
||||
*/
|
||||
GIT_EXTERN(int) git_config_foreach(
|
||||
const git_config *cfg,
|
||||
git_config_foreach_cb callback,
|
||||
void *payload);
|
||||
|
||||
/**
|
||||
* Perform an operation on each config variable matching a regular expression.
|
||||
*
|
||||
* This behaviors like `git_config_foreach` with an additional filter of a
|
||||
* regular expression that filters which config keys are passed to the
|
||||
* callback.
|
||||
*
|
||||
* @param cfg where to get the variables from
|
||||
* @param regexp regular expression to match against config names
|
||||
* @param callback the function to call on each variable
|
||||
* @param payload the data to pass to the callback
|
||||
* @return 0 or the return value of the callback which didn't return 0
|
||||
*/
|
||||
GIT_EXTERN(int) git_config_foreach_match(
|
||||
const git_config *cfg,
|
||||
const char *regexp,
|
||||
git_config_foreach_cb callback,
|
||||
void *payload);
|
||||
|
||||
/**
|
||||
* Query the value of a config variable and return it mapped to
|
||||
* an integer constant.
|
||||
*
|
||||
* This is a helper method to easily map different possible values
|
||||
* to a variable to integer constants that easily identify them.
|
||||
*
|
||||
* A mapping array looks as follows:
|
||||
*
|
||||
* git_cvar_map autocrlf_mapping[] = {
|
||||
* {GIT_CVAR_FALSE, NULL, GIT_AUTO_CRLF_FALSE},
|
||||
* {GIT_CVAR_TRUE, NULL, GIT_AUTO_CRLF_TRUE},
|
||||
* {GIT_CVAR_STRING, "input", GIT_AUTO_CRLF_INPUT},
|
||||
* {GIT_CVAR_STRING, "default", GIT_AUTO_CRLF_DEFAULT}};
|
||||
*
|
||||
* On any "false" value for the variable (e.g. "false", "FALSE", "no"), the
|
||||
* mapping will store `GIT_AUTO_CRLF_FALSE` in the `out` parameter.
|
||||
*
|
||||
* The same thing applies for any "true" value such as "true", "yes" or "1", storing
|
||||
* the `GIT_AUTO_CRLF_TRUE` variable.
|
||||
*
|
||||
* Otherwise, if the value matches the string "input" (with case insensitive comparison),
|
||||
* the given constant will be stored in `out`, and likewise for "default".
|
||||
*
|
||||
* If not a single match can be made to store in `out`, an error code will be
|
||||
* returned.
|
||||
*
|
||||
* @param out place to store the result of the mapping
|
||||
* @param cfg config file to get the variables from
|
||||
* @param name name of the config variable to lookup
|
||||
* @param maps array of `git_cvar_map` objects specifying the possible mappings
|
||||
* @param map_n number of mapping objects in `maps`
|
||||
* @return 0 on success, error code otherwise
|
||||
*/
|
||||
GIT_EXTERN(int) git_config_get_mapped(
|
||||
int *out,
|
||||
const git_config *cfg,
|
||||
const char *name,
|
||||
const git_cvar_map *maps,
|
||||
size_t map_n);
|
||||
|
||||
/**
|
||||
* Maps a string value to an integer constant
|
||||
*
|
||||
* @param out place to store the result of the parsing
|
||||
* @param maps array of `git_cvar_map` objects specifying the possible mappings
|
||||
* @param map_n number of mapping objects in `maps`
|
||||
* @param value value to parse
|
||||
*/
|
||||
GIT_EXTERN(int) git_config_lookup_map_value(
|
||||
int *out,
|
||||
const git_cvar_map *maps,
|
||||
size_t map_n,
|
||||
const char *value);
|
||||
|
||||
/**
|
||||
* Parse a string value as a bool.
|
||||
*
|
||||
* Valid values for true are: 'true', 'yes', 'on', 1 or any
|
||||
* number different from 0
|
||||
* Valid values for false are: 'false', 'no', 'off', 0
|
||||
*
|
||||
* @param out place to store the result of the parsing
|
||||
* @param value value to parse
|
||||
*/
|
||||
GIT_EXTERN(int) git_config_parse_bool(int *out, const char *value);
|
||||
|
||||
/**
|
||||
* Parse a string value as an int32.
|
||||
*
|
||||
* An optional value suffix of 'k', 'm', or 'g' will
|
||||
* cause the value to be multiplied by 1024, 1048576,
|
||||
* or 1073741824 prior to output.
|
||||
*
|
||||
* @param out place to store the result of the parsing
|
||||
* @param value value to parse
|
||||
*/
|
||||
GIT_EXTERN(int) git_config_parse_int32(int32_t *out, const char *value);
|
||||
|
||||
/**
|
||||
* Parse a string value as an int64.
|
||||
*
|
||||
* An optional value suffix of 'k', 'm', or 'g' will
|
||||
* cause the value to be multiplied by 1024, 1048576,
|
||||
* or 1073741824 prior to output.
|
||||
*
|
||||
* @param out place to store the result of the parsing
|
||||
* @param value value to parse
|
||||
*/
|
||||
GIT_EXTERN(int) git_config_parse_int64(int64_t *out, const char *value);
|
||||
|
||||
|
||||
/** @} */
|
||||
GIT_END_DECL
|
||||
#endif
|
||||
@@ -1,853 +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_diff_h__
|
||||
#define INCLUDE_git_diff_h__
|
||||
|
||||
#include "common.h"
|
||||
#include "types.h"
|
||||
#include "oid.h"
|
||||
#include "tree.h"
|
||||
#include "refs.h"
|
||||
|
||||
/**
|
||||
* @file git2/diff.h
|
||||
* @brief Git tree and file differencing routines.
|
||||
*
|
||||
* Overview
|
||||
* --------
|
||||
*
|
||||
* Calculating diffs is generally done in two phases: building a diff list
|
||||
* then traversing the diff list. This makes is easier to share logic
|
||||
* across the various types of diffs (tree vs tree, workdir vs index, etc.),
|
||||
* and also allows you to insert optional diff list post-processing phases,
|
||||
* such as rename detected, in between the steps. When you are done with a
|
||||
* diff list object, it must be freed.
|
||||
*
|
||||
* Terminology
|
||||
* -----------
|
||||
*
|
||||
* To understand the diff APIs, you should know the following terms:
|
||||
*
|
||||
* - A `diff` or `diff list` represents the cumulative list of differences
|
||||
* between two snapshots of a repository (possibly filtered by a set of
|
||||
* file name patterns). This is the `git_diff_list` object.
|
||||
* - A `delta` is a file pair with an old and new revision. The old version
|
||||
* may be absent if the file was just created and the new version may be
|
||||
* absent if the file was deleted. A diff is mostly just a list of deltas.
|
||||
* - A `binary` file / delta is a file (or pair) for which no text diffs
|
||||
* should be generated. A diff list can contain delta entries that are
|
||||
* binary, but no diff content will be output for those files. There is
|
||||
* a base heuristic for binary detection and you can further tune the
|
||||
* behavior with git attributes or diff flags and option settings.
|
||||
* - A `hunk` is a span of modified lines in a delta along with some stable
|
||||
* surrounding context. You can configure the amount of context and other
|
||||
* properties of how hunks are generated. Each hunk also comes with a
|
||||
* header that described where it starts and ends in both the old and new
|
||||
* versions in the delta.
|
||||
* - A `line` is a range of characters inside a hunk. It could be a context
|
||||
* line (i.e. in both old and new versions), an added line (i.e. only in
|
||||
* the new version), or a removed line (i.e. only in the old version).
|
||||
* Unfortunately, we don't know anything about the encoding of data in the
|
||||
* file being diffed, so we cannot tell you much about the line content.
|
||||
* Line data will not be NUL-byte terminated, however, because it will be
|
||||
* just a span of bytes inside the larger file.
|
||||
*
|
||||
* @ingroup Git
|
||||
* @{
|
||||
*/
|
||||
GIT_BEGIN_DECL
|
||||
|
||||
/**
|
||||
* Flags for diff options. A combination of these flags can be passed
|
||||
* in via the `flags` value in the `git_diff_options`.
|
||||
*/
|
||||
typedef enum {
|
||||
/** Normal diff, the default */
|
||||
GIT_DIFF_NORMAL = 0,
|
||||
/** Reverse the sides of the diff */
|
||||
GIT_DIFF_REVERSE = (1 << 0),
|
||||
/** Treat all files as text, disabling binary attributes & detection */
|
||||
GIT_DIFF_FORCE_TEXT = (1 << 1),
|
||||
/** Ignore all whitespace */
|
||||
GIT_DIFF_IGNORE_WHITESPACE = (1 << 2),
|
||||
/** Ignore changes in amount of whitespace */
|
||||
GIT_DIFF_IGNORE_WHITESPACE_CHANGE = (1 << 3),
|
||||
/** Ignore whitespace at end of line */
|
||||
GIT_DIFF_IGNORE_WHITESPACE_EOL = (1 << 4),
|
||||
/** Exclude submodules from the diff completely */
|
||||
GIT_DIFF_IGNORE_SUBMODULES = (1 << 5),
|
||||
/** Use the "patience diff" algorithm (currently unimplemented) */
|
||||
GIT_DIFF_PATIENCE = (1 << 6),
|
||||
/** Include ignored files in the diff list */
|
||||
GIT_DIFF_INCLUDE_IGNORED = (1 << 7),
|
||||
/** Include untracked files in the diff list */
|
||||
GIT_DIFF_INCLUDE_UNTRACKED = (1 << 8),
|
||||
/** Include unmodified files in the diff list */
|
||||
GIT_DIFF_INCLUDE_UNMODIFIED = (1 << 9),
|
||||
/** Even with the GIT_DIFF_INCLUDE_UNTRACKED flag, when an untracked
|
||||
* directory is found, only a single entry for the directory is added
|
||||
* to the diff list; with this flag, all files under the directory will
|
||||
* be included, too.
|
||||
*/
|
||||
GIT_DIFF_RECURSE_UNTRACKED_DIRS = (1 << 10),
|
||||
/** 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.
|
||||
*/
|
||||
GIT_DIFF_DISABLE_PATHSPEC_MATCH = (1 << 11),
|
||||
/** Use case insensitive filename comparisons */
|
||||
GIT_DIFF_DELTAS_ARE_ICASE = (1 << 12),
|
||||
/** When generating patch text, include the content of untracked files */
|
||||
GIT_DIFF_INCLUDE_UNTRACKED_CONTENT = (1 << 13),
|
||||
/** Disable updating of the `binary` flag in delta records. This is
|
||||
* useful when iterating over a diff if you don't need hunk and data
|
||||
* callbacks and want to avoid having to load file completely.
|
||||
*/
|
||||
GIT_DIFF_SKIP_BINARY_CHECK = (1 << 14),
|
||||
/** Normally, a type change between files will be converted into a
|
||||
* DELETED record for the old and an ADDED record for the new; this
|
||||
* options enabled the generation of TYPECHANGE delta records.
|
||||
*/
|
||||
GIT_DIFF_INCLUDE_TYPECHANGE = (1 << 15),
|
||||
/** Even with GIT_DIFF_INCLUDE_TYPECHANGE, blob->tree changes still
|
||||
* generally show as a DELETED blob. This flag tries to correctly
|
||||
* label blob->tree transitions as TYPECHANGE records with new_file's
|
||||
* mode set to tree. Note: the tree SHA will not be available.
|
||||
*/
|
||||
GIT_DIFF_INCLUDE_TYPECHANGE_TREES = (1 << 16),
|
||||
/** Ignore file mode changes */
|
||||
GIT_DIFF_IGNORE_FILEMODE = (1 << 17),
|
||||
} git_diff_option_t;
|
||||
|
||||
/**
|
||||
* Structure describing options about how the diff should be executed.
|
||||
*
|
||||
* Setting all values of the structure to zero will yield the default
|
||||
* values. Similarly, passing NULL for the options structure will
|
||||
* give the defaults. The default values are marked below.
|
||||
*
|
||||
* - `flags` is a combination of the `git_diff_option_t` values above
|
||||
* - `context_lines` is the number of unchanged lines that define the
|
||||
* boundary of a hunk (and to display before and after)
|
||||
* - `interhunk_lines` is the maximum number of unchanged lines between
|
||||
* hunk boundaries before the hunks will be merged into a one.
|
||||
* - `old_prefix` is the virtual "directory" to prefix to old file names
|
||||
* in hunk headers (default "a")
|
||||
* - `new_prefix` is the virtual "directory" to prefix to new file names
|
||||
* in hunk headers (default "b")
|
||||
* - `pathspec` is an array of paths / fnmatch patterns to constrain diff
|
||||
* - `max_size` is a file size (in bytes) above which a blob will be marked
|
||||
* as binary automatically; pass a negative value to disable.
|
||||
*/
|
||||
typedef struct {
|
||||
unsigned int version; /**< version for the struct */
|
||||
uint32_t flags; /**< defaults to GIT_DIFF_NORMAL */
|
||||
uint16_t context_lines; /**< defaults to 3 */
|
||||
uint16_t interhunk_lines; /**< defaults to 0 */
|
||||
const char *old_prefix; /**< defaults to "a" */
|
||||
const char *new_prefix; /**< defaults to "b" */
|
||||
git_strarray pathspec; /**< defaults to include all paths */
|
||||
git_off_t max_size; /**< defaults to 512MB */
|
||||
} git_diff_options;
|
||||
|
||||
#define GIT_DIFF_OPTIONS_VERSION 1
|
||||
#define GIT_DIFF_OPTIONS_INIT {GIT_DIFF_OPTIONS_VERSION}
|
||||
|
||||
/**
|
||||
* The diff list object that contains all individual file deltas.
|
||||
*
|
||||
* This is an opaque structure which will be allocated by one of the diff
|
||||
* generator functions below (such as `git_diff_tree_to_tree`). You are
|
||||
* responsible for releasing the object memory when done, using the
|
||||
* `git_diff_list_free()` function.
|
||||
*/
|
||||
typedef struct git_diff_list git_diff_list;
|
||||
|
||||
/**
|
||||
* Flags for the file object on each side of a diff.
|
||||
*
|
||||
* Note: most of these flags are just for **internal** consumption by
|
||||
* libgit2, but some of them may be interesting to external users.
|
||||
*/
|
||||
typedef enum {
|
||||
GIT_DIFF_FILE_VALID_OID = (1 << 0), /** `oid` value is known correct */
|
||||
GIT_DIFF_FILE_FREE_PATH = (1 << 1), /** `path` is allocated memory */
|
||||
GIT_DIFF_FILE_BINARY = (1 << 2), /** should be considered binary data */
|
||||
GIT_DIFF_FILE_NOT_BINARY = (1 << 3), /** should be considered text data */
|
||||
GIT_DIFF_FILE_FREE_DATA = (1 << 4), /** internal file data is allocated */
|
||||
GIT_DIFF_FILE_UNMAP_DATA = (1 << 5), /** internal file data is mmap'ed */
|
||||
GIT_DIFF_FILE_NO_DATA = (1 << 6), /** file data should not be loaded */
|
||||
} git_diff_file_flag_t;
|
||||
|
||||
/**
|
||||
* What type of change is described by a git_diff_delta?
|
||||
*
|
||||
* `GIT_DELTA_RENAMED` and `GIT_DELTA_COPIED` will only show up if you run
|
||||
* `git_diff_find_similar()` on the diff list object.
|
||||
*
|
||||
* `GIT_DELTA_TYPECHANGE` only shows up given `GIT_DIFF_INCLUDE_TYPECHANGE`
|
||||
* in the option flags (otherwise type changes will be split into ADDED /
|
||||
* 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_t;
|
||||
|
||||
/**
|
||||
* Description of one side of a diff entry.
|
||||
*
|
||||
* Although this is called a "file", it may actually represent a file, a
|
||||
* symbolic link, a submodule commit id, or even a tree (although that only
|
||||
* if you are tracking type changes or ignored/untracked directories).
|
||||
*
|
||||
* The `oid` is the `git_oid` of the item. If the entry represents an
|
||||
* absent side of a diff (e.g. the `old_file` of a `GIT_DELTA_ADDED` delta),
|
||||
* then the oid will be zeroes.
|
||||
*
|
||||
* `path` is the NUL-terminated path to the entry relative to the working
|
||||
* directory of the repository.
|
||||
*
|
||||
* `size` is the size of the entry in bytes.
|
||||
*
|
||||
* `flags` is a combination of the `git_diff_file_flag_t` types, but those
|
||||
* are largely internal values.
|
||||
*
|
||||
* `mode` is, roughly, the stat() `st_mode` value for the item. This will
|
||||
* be restricted to one of the `git_filemode_t` values.
|
||||
*/
|
||||
typedef struct {
|
||||
git_oid oid;
|
||||
const char *path;
|
||||
git_off_t size;
|
||||
unsigned int flags;
|
||||
uint16_t mode;
|
||||
} git_diff_file;
|
||||
|
||||
/**
|
||||
* Description of changes to one entry.
|
||||
*
|
||||
* When iterating over a diff list object, this will be passed to most
|
||||
* callback functions and you can use the contents to understand exactly
|
||||
* what has changed.
|
||||
*
|
||||
* The `old_file` represents the "from" side of the diff and the `new_file`
|
||||
* represents to "to" side of the diff. What those means depend on the
|
||||
* function that was used to generate the diff and will be documented below.
|
||||
* You can also use the `GIT_DIFF_REVERSE` flag to flip it around.
|
||||
*
|
||||
* Although the two sides of the delta are named "old_file" and "new_file",
|
||||
* they actually may correspond to entries that represent a file, a symbolic
|
||||
* link, a submodule commit id, or even a tree (if you are tracking type
|
||||
* changes or ignored/untracked directories).
|
||||
*
|
||||
* Under some circumstances, in the name of efficiency, not all fields will
|
||||
* be filled in, but we generally try to fill in as much as possible. One
|
||||
* example is that the "binary" field will not examine file contents if you
|
||||
* do not pass in hunk and/or line callbacks to the diff foreach iteration
|
||||
* function. It will just use the git attributes for those files.
|
||||
*/
|
||||
typedef struct {
|
||||
git_diff_file old_file;
|
||||
git_diff_file new_file;
|
||||
git_delta_t status;
|
||||
unsigned int similarity; /**< for RENAMED and COPIED, value 0-100 */
|
||||
int binary;
|
||||
} git_diff_delta;
|
||||
|
||||
/**
|
||||
* When iterating over a diff, callback that will be made per file.
|
||||
*
|
||||
* @param delta A pointer to the delta data for the file
|
||||
* @param progress Goes from 0 to 1 over the diff list
|
||||
* @param payload User-specified pointer from foreach function
|
||||
*/
|
||||
typedef int (*git_diff_file_cb)(
|
||||
const git_diff_delta *delta,
|
||||
float progress,
|
||||
void *payload);
|
||||
|
||||
/**
|
||||
* Structure describing a hunk of a diff.
|
||||
*/
|
||||
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 */
|
||||
} git_diff_range;
|
||||
|
||||
/**
|
||||
* When iterating over a diff, callback that will be made per hunk.
|
||||
*/
|
||||
typedef int (*git_diff_hunk_cb)(
|
||||
const git_diff_delta *delta,
|
||||
const git_diff_range *range,
|
||||
const char *header,
|
||||
size_t header_len,
|
||||
void *payload);
|
||||
|
||||
/**
|
||||
* Line origin constants.
|
||||
*
|
||||
* These values describe where a line came from and will be passed to
|
||||
* the git_diff_data_cb when iterating over a diff. There are some
|
||||
* special origin constants at the end that are used for the text
|
||||
* output callbacks to demarcate lines that are actually part of
|
||||
* the file or hunk headers.
|
||||
*/
|
||||
typedef enum {
|
||||
/* These values will be sent to `git_diff_data_cb` along with the line */
|
||||
GIT_DIFF_LINE_CONTEXT = ' ',
|
||||
GIT_DIFF_LINE_ADDITION = '+',
|
||||
GIT_DIFF_LINE_DELETION = '-',
|
||||
GIT_DIFF_LINE_ADD_EOFNL = '\n', /**< Removed line w/o LF & added one with */
|
||||
GIT_DIFF_LINE_DEL_EOFNL = '\0', /**< LF was removed at end of file */
|
||||
|
||||
/* The following values will only be sent to a `git_diff_data_cb` when
|
||||
* the content of a diff is being formatted (eg. through
|
||||
* git_diff_print_patch() or git_diff_print_compact(), for instance).
|
||||
*/
|
||||
GIT_DIFF_LINE_FILE_HDR = 'F',
|
||||
GIT_DIFF_LINE_HUNK_HDR = 'H',
|
||||
GIT_DIFF_LINE_BINARY = 'B'
|
||||
} git_diff_line_t;
|
||||
|
||||
/**
|
||||
* When iterating over a diff, callback that will be made per text diff
|
||||
* line. In this context, the provided range will be NULL.
|
||||
*
|
||||
* When printing a diff, callback that will be made to output each line
|
||||
* of text. This uses some extra GIT_DIFF_LINE_... constants for output
|
||||
* of lines of file and hunk headers.
|
||||
*/
|
||||
typedef int (*git_diff_data_cb)(
|
||||
const git_diff_delta *delta, /** delta that contains this data */
|
||||
const git_diff_range *range, /** range of lines containing this data */
|
||||
char line_origin, /** git_diff_list_t value from above */
|
||||
const char *content, /** diff data - not NUL terminated */
|
||||
size_t content_len, /** number of bytes of diff data */
|
||||
void *payload); /** user reference data */
|
||||
|
||||
/**
|
||||
* The diff patch is used to store all the text diffs for a delta.
|
||||
*
|
||||
* You can easily loop over the content of patches and get information about
|
||||
* them.
|
||||
*/
|
||||
typedef struct git_diff_patch git_diff_patch;
|
||||
|
||||
/**
|
||||
* Flags to control the behavior of diff rename/copy detection.
|
||||
*/
|
||||
typedef enum {
|
||||
/** look for renames? (`--find-renames`) */
|
||||
GIT_DIFF_FIND_RENAMES = (1 << 0),
|
||||
/** consider old size of modified for renames? (`--break-rewrites=N`) */
|
||||
GIT_DIFF_FIND_RENAMES_FROM_REWRITES = (1 << 1),
|
||||
|
||||
/** look for copies? (a la `--find-copies`) */
|
||||
GIT_DIFF_FIND_COPIES = (1 << 2),
|
||||
/** consider unmodified as copy sources? (`--find-copies-harder`) */
|
||||
GIT_DIFF_FIND_COPIES_FROM_UNMODIFIED = (1 << 3),
|
||||
|
||||
/** split large rewrites into delete/add pairs (`--break-rewrites=/M`) */
|
||||
GIT_DIFF_FIND_AND_BREAK_REWRITES = (1 << 4),
|
||||
} git_diff_find_t;
|
||||
|
||||
/**
|
||||
* Control behavior of rename and copy detection
|
||||
*/
|
||||
typedef struct {
|
||||
unsigned int version;
|
||||
|
||||
/** Combination of git_diff_find_t values (default FIND_RENAMES) */
|
||||
unsigned int flags;
|
||||
|
||||
/** Similarity to consider a file renamed (default 50) */
|
||||
unsigned int rename_threshold;
|
||||
/** Similarity of modified to be eligible rename source (default 50) */
|
||||
unsigned int rename_from_rewrite_threshold;
|
||||
/** Similarity to consider a file a copy (default 50) */
|
||||
unsigned int copy_threshold;
|
||||
/** Similarity to split modify into delete/add pair (default 60) */
|
||||
unsigned int break_rewrite_threshold;
|
||||
|
||||
/** Maximum similarity sources to examine (a la diff's `-l` option or
|
||||
* the `diff.renameLimit` config) (default 200)
|
||||
*/
|
||||
unsigned int target_limit;
|
||||
} git_diff_find_options;
|
||||
|
||||
#define GIT_DIFF_FIND_OPTIONS_VERSION 1
|
||||
#define GIT_DIFF_FIND_OPTIONS_INIT {GIT_DIFF_FIND_OPTIONS_VERSION}
|
||||
|
||||
/** @name Diff List Generator Functions
|
||||
*
|
||||
* These are the functions you would use to create (or destroy) a
|
||||
* git_diff_list from various objects in a repository.
|
||||
*/
|
||||
/**@{*/
|
||||
|
||||
/**
|
||||
* Deallocate a diff list.
|
||||
*/
|
||||
GIT_EXTERN(void) git_diff_list_free(git_diff_list *diff);
|
||||
|
||||
/**
|
||||
* Create a diff list with the difference between two tree objects.
|
||||
*
|
||||
* This is equivalent to `git diff <old-tree> <new-tree>`
|
||||
*
|
||||
* The first tree will be used for the "old_file" side of the delta and the
|
||||
* second tree will be used for the "new_file" side of the delta.
|
||||
*
|
||||
* @param diff Output pointer to a git_diff_list pointer to be allocated.
|
||||
* @param repo The repository containing the trees.
|
||||
* @param old_tree A git_tree object to diff from.
|
||||
* @param new_tree A git_tree object to diff to.
|
||||
* @param opts Structure with options to influence diff or NULL for defaults.
|
||||
*/
|
||||
GIT_EXTERN(int) git_diff_tree_to_tree(
|
||||
git_diff_list **diff,
|
||||
git_repository *repo,
|
||||
git_tree *old_tree,
|
||||
git_tree *new_tree,
|
||||
const git_diff_options *opts); /**< can be NULL for defaults */
|
||||
|
||||
/**
|
||||
* Create a diff list between a tree and repository index.
|
||||
*
|
||||
* This is equivalent to `git diff --cached <treeish>` or if you pass
|
||||
* the HEAD tree, then like `git diff --cached`.
|
||||
*
|
||||
* The tree you pass will be used for the "old_file" side of the delta, and
|
||||
* the index will be used for the "new_file" side of the delta.
|
||||
*
|
||||
* @param diff Output pointer to a git_diff_list pointer to be allocated.
|
||||
* @param repo The repository containing the tree and index.
|
||||
* @param old_tree A git_tree object to diff from.
|
||||
* @param index The index to diff with; repo index used if NULL.
|
||||
* @param opts Structure with options to influence diff or NULL for defaults.
|
||||
*/
|
||||
GIT_EXTERN(int) git_diff_tree_to_index(
|
||||
git_diff_list **diff,
|
||||
git_repository *repo,
|
||||
git_tree *old_tree,
|
||||
git_index *index,
|
||||
const git_diff_options *opts); /**< can be NULL for defaults */
|
||||
|
||||
/**
|
||||
* Create a diff list between the repository index and the workdir directory.
|
||||
*
|
||||
* This matches the `git diff` command. See the note below on
|
||||
* `git_diff_tree_to_workdir` for a discussion of the difference between
|
||||
* `git diff` and `git diff HEAD` and how to emulate a `git diff <treeish>`
|
||||
* using libgit2.
|
||||
*
|
||||
* The index will be used for the "old_file" side of the delta, and the
|
||||
* working directory will be used for the "new_file" side of the delta.
|
||||
*
|
||||
* @param diff Output pointer to a git_diff_list pointer to be allocated.
|
||||
* @param repo The repository.
|
||||
* @param index The index to diff from; repo index used if NULL.
|
||||
* @param opts Structure with options to influence diff or NULL for defaults.
|
||||
*/
|
||||
GIT_EXTERN(int) git_diff_index_to_workdir(
|
||||
git_diff_list **diff,
|
||||
git_repository *repo,
|
||||
git_index *index,
|
||||
const git_diff_options *opts); /**< can be NULL for defaults */
|
||||
|
||||
/**
|
||||
* Create a diff list between a tree and the working directory.
|
||||
*
|
||||
* The tree you provide will be used for the "old_file" side of the delta,
|
||||
* and the working directory will be used for the "new_file" side.
|
||||
*
|
||||
* Please note: this is *NOT* the same as `git diff <treeish>`. Running
|
||||
* `git diff HEAD` or the like actually uses information from the index,
|
||||
* along with the tree and working directory info.
|
||||
*
|
||||
* This function returns strictly the differences between the tree and the
|
||||
* files contained in the working directory, regardless of the state of
|
||||
* files in the index. It may come as a surprise, but there is no direct
|
||||
* equivalent in core git.
|
||||
*
|
||||
* To emulate `git diff <treeish>`, call both `git_diff_tree_to_index` and
|
||||
* `git_diff_index_to_workdir`, then call `git_diff_merge` on the results.
|
||||
* That will yield a `git_diff_list` that matches the git output.
|
||||
*
|
||||
* If this seems confusing, take the case of a file with a staged deletion
|
||||
* where the file has then been put back into the working dir and modified.
|
||||
* The tree-to-workdir diff for that file is 'modified', but core git would
|
||||
* show status 'deleted' since there is a pending deletion in the index.
|
||||
*
|
||||
* @param diff A pointer to a git_diff_list pointer that will be allocated.
|
||||
* @param repo The repository containing the tree.
|
||||
* @param old_tree A git_tree object to diff from.
|
||||
* @param opts Structure with options to influence diff or NULL for defaults.
|
||||
*/
|
||||
GIT_EXTERN(int) git_diff_tree_to_workdir(
|
||||
git_diff_list **diff,
|
||||
git_repository *repo,
|
||||
git_tree *old_tree,
|
||||
const git_diff_options *opts); /**< can be NULL for defaults */
|
||||
|
||||
/**
|
||||
* Merge one diff list into another.
|
||||
*
|
||||
* This merges items from the "from" list into the "onto" list. The
|
||||
* resulting diff list will have all items that appear in either list.
|
||||
* If an item appears in both lists, then it will be "merged" to appear
|
||||
* as if the old version was from the "onto" list and the new version
|
||||
* is from the "from" list (with the exception that if the item has a
|
||||
* pending DELETE in the middle, then it will show as deleted).
|
||||
*
|
||||
* @param onto Diff to merge into.
|
||||
* @param from Diff to merge.
|
||||
*/
|
||||
GIT_EXTERN(int) git_diff_merge(
|
||||
git_diff_list *onto,
|
||||
const git_diff_list *from);
|
||||
|
||||
/**
|
||||
* Transform a diff list marking file renames, copies, etc.
|
||||
*
|
||||
* This modifies a diff list in place, replacing old entries that look
|
||||
* like renames or copies with new entries reflecting those changes.
|
||||
* This also will, if requested, break modified files into add/remove
|
||||
* pairs if the amount of change is above a threshold.
|
||||
*
|
||||
* @param diff Diff list to run detection algorithms on
|
||||
* @param options Control how detection should be run, NULL for defaults
|
||||
* @return 0 on success, -1 on failure
|
||||
*/
|
||||
GIT_EXTERN(int) git_diff_find_similar(
|
||||
git_diff_list *diff,
|
||||
git_diff_find_options *options);
|
||||
|
||||
/**@}*/
|
||||
|
||||
|
||||
/** @name Diff List Processor Functions
|
||||
*
|
||||
* These are the functions you apply to a diff list to process it
|
||||
* or read it in some way.
|
||||
*/
|
||||
/**@{*/
|
||||
|
||||
/**
|
||||
* Loop over all deltas in a diff list issuing callbacks.
|
||||
*
|
||||
* This will iterate through all of the files described in a diff. You
|
||||
* should provide a file callback to learn about each file.
|
||||
*
|
||||
* The "hunk" and "line" callbacks are optional, and the text diff of the
|
||||
* files will only be calculated if they are not NULL. Of course, these
|
||||
* callbacks will not be invoked for binary files on the diff list or for
|
||||
* files whose only changed is a file mode change.
|
||||
*
|
||||
* Returning a non-zero value from any of the callbacks will terminate
|
||||
* the iteration and cause this return `GIT_EUSER`.
|
||||
*
|
||||
* @param diff A git_diff_list generated by one of the above functions.
|
||||
* @param file_cb Callback function to make per file in the diff.
|
||||
* @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.
|
||||
* @param line_cb Optional callback to make per line of diff text. This
|
||||
* same callback will be made for context lines, added, and
|
||||
* removed lines, and even for a deleted trailing newline.
|
||||
* @param payload Reference pointer that will be passed to your callbacks.
|
||||
* @return 0 on success, GIT_EUSER on non-zero callback, or error code
|
||||
*/
|
||||
GIT_EXTERN(int) git_diff_foreach(
|
||||
git_diff_list *diff,
|
||||
git_diff_file_cb file_cb,
|
||||
git_diff_hunk_cb hunk_cb,
|
||||
git_diff_data_cb line_cb,
|
||||
void *payload);
|
||||
|
||||
/**
|
||||
* Iterate over a diff generating text output like "git diff --name-status".
|
||||
*
|
||||
* Returning a non-zero value from the callbacks will terminate the
|
||||
* iteration and cause this return `GIT_EUSER`.
|
||||
*
|
||||
* @param diff A git_diff_list generated by one of the above functions.
|
||||
* @param print_cb Callback to make per line of diff text.
|
||||
* @param payload Reference pointer that will be passed to your callback.
|
||||
* @return 0 on success, GIT_EUSER on non-zero callback, or error code
|
||||
*/
|
||||
GIT_EXTERN(int) git_diff_print_compact(
|
||||
git_diff_list *diff,
|
||||
git_diff_data_cb print_cb,
|
||||
void *payload);
|
||||
|
||||
/**
|
||||
* Look up the single character abbreviation for a delta status code.
|
||||
*
|
||||
* When you call `git_diff_print_compact` it prints single letter codes into
|
||||
* the output such as 'A' for added, 'D' for deleted, 'M' for modified, etc.
|
||||
* It is sometimes convenient to convert a git_delta_t value into these
|
||||
* letters for your own purposes. This function does just that. By the
|
||||
* way, unmodified will return a space (i.e. ' ').
|
||||
*
|
||||
* @param delta_t The git_delta_t value to look up
|
||||
* @return The single character label for that code
|
||||
*/
|
||||
GIT_EXTERN(char) git_diff_status_char(git_delta_t status);
|
||||
|
||||
/**
|
||||
* Iterate over a diff generating text output like "git diff".
|
||||
*
|
||||
* This is a super easy way to generate a patch from a diff.
|
||||
*
|
||||
* Returning a non-zero value from the callbacks will terminate the
|
||||
* iteration and cause this return `GIT_EUSER`.
|
||||
*
|
||||
* @param diff A git_diff_list generated by one of the above functions.
|
||||
* @param payload Reference pointer that will be passed to your callbacks.
|
||||
* @param print_cb Callback function to output lines of the diff. This
|
||||
* same function will be called for file headers, hunk
|
||||
* headers, and diff lines. Fortunately, you can probably
|
||||
* use various GIT_DIFF_LINE constants to determine what
|
||||
* text you are given.
|
||||
* @return 0 on success, GIT_EUSER on non-zero callback, or error code
|
||||
*/
|
||||
GIT_EXTERN(int) git_diff_print_patch(
|
||||
git_diff_list *diff,
|
||||
git_diff_data_cb print_cb,
|
||||
void *payload);
|
||||
|
||||
/**
|
||||
* Query how many diff records are there in a diff list.
|
||||
*
|
||||
* @param diff A git_diff_list generated by one of the above functions
|
||||
* @return Count of number of deltas in the list
|
||||
*/
|
||||
GIT_EXTERN(size_t) git_diff_num_deltas(git_diff_list *diff);
|
||||
|
||||
/**
|
||||
* Query how many diff deltas are there in a diff list filtered by type.
|
||||
*
|
||||
* This works just like `git_diff_entrycount()` with an extra parameter
|
||||
* that is a `git_delta_t` and returns just the count of how many deltas
|
||||
* match that particular type.
|
||||
*
|
||||
* @param diff A git_diff_list generated by one of the above functions
|
||||
* @param type A git_delta_t value to filter the count
|
||||
* @return Count of number of deltas matching delta_t type
|
||||
*/
|
||||
GIT_EXTERN(size_t) git_diff_num_deltas_of_type(
|
||||
git_diff_list *diff,
|
||||
git_delta_t type);
|
||||
|
||||
/**
|
||||
* Return the diff delta and patch for an entry in the diff list.
|
||||
*
|
||||
* The `git_diff_patch` is a newly created object contains the text diffs
|
||||
* for the delta. You have to call `git_diff_patch_free()` when you are
|
||||
* done with it. You can use the patch object to loop over all the hunks
|
||||
* and lines in the diff of the one delta.
|
||||
*
|
||||
* For an unchanged file or a binary file, no `git_diff_patch` will be
|
||||
* 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_list` and `git_diff_patch` go away.
|
||||
*
|
||||
* It is okay to pass NULL for either of the output parameters; if you pass
|
||||
* NULL for the `git_diff_patch`, then the text diff will not be calculated.
|
||||
*
|
||||
* @param patch_out Output parameter for the delta patch object
|
||||
* @param delta_out Output parameter for the delta object
|
||||
* @param diff Diff list object
|
||||
* @param idx Index into diff list
|
||||
* @return 0 on success, other value < 0 on error
|
||||
*/
|
||||
GIT_EXTERN(int) git_diff_get_patch(
|
||||
git_diff_patch **patch_out,
|
||||
const git_diff_delta **delta_out,
|
||||
git_diff_list *diff,
|
||||
size_t idx);
|
||||
|
||||
/**
|
||||
* Free a git_diff_patch object.
|
||||
*/
|
||||
GIT_EXTERN(void) git_diff_patch_free(
|
||||
git_diff_patch *patch);
|
||||
|
||||
/**
|
||||
* Get the delta associated with a patch
|
||||
*/
|
||||
GIT_EXTERN(const git_diff_delta *) git_diff_patch_delta(
|
||||
git_diff_patch *patch);
|
||||
|
||||
/**
|
||||
* Get the number of hunks in a patch
|
||||
*/
|
||||
GIT_EXTERN(size_t) git_diff_patch_num_hunks(
|
||||
git_diff_patch *patch);
|
||||
|
||||
/**
|
||||
* Get the information about a hunk in a patch
|
||||
*
|
||||
* Given a patch and a hunk index into the patch, this returns detailed
|
||||
* information about that hunk. Any of the output pointers can be passed
|
||||
* as NULL if you don't care about that particular piece of information.
|
||||
*
|
||||
* @param range Output pointer to git_diff_range of hunk
|
||||
* @param header Output pointer to header string for hunk. Unlike the
|
||||
* content pointer for each line, this will be NUL-terminated
|
||||
* @param header_len Output value of characters in header string
|
||||
* @param lines_in_hunk Output count of total lines in this hunk
|
||||
* @param patch Input pointer to patch object
|
||||
* @param hunk_idx Input index of hunk to get information about
|
||||
* @return 0 on success, GIT_ENOTFOUND if hunk_idx out of range, <0 on error
|
||||
*/
|
||||
GIT_EXTERN(int) git_diff_patch_get_hunk(
|
||||
const git_diff_range **range,
|
||||
const char **header,
|
||||
size_t *header_len,
|
||||
size_t *lines_in_hunk,
|
||||
git_diff_patch *patch,
|
||||
size_t hunk_idx);
|
||||
|
||||
/**
|
||||
* Get the number of lines in a hunk.
|
||||
*
|
||||
* @param patch The git_diff_patch object
|
||||
* @param hunk_idx Index of the hunk
|
||||
* @return Number of lines in hunk or -1 if invalid hunk index
|
||||
*/
|
||||
GIT_EXTERN(int) git_diff_patch_num_lines_in_hunk(
|
||||
git_diff_patch *patch,
|
||||
size_t hunk_idx);
|
||||
|
||||
/**
|
||||
* Get data about a line in a hunk of a patch.
|
||||
*
|
||||
* Given a patch, a hunk index, and a line index in the hunk, this
|
||||
* will return a lot of details about that line. If you pass a hunk
|
||||
* index larger than the number of hunks or a line index larger than
|
||||
* the number of lines in the hunk, this will return -1.
|
||||
*
|
||||
* @param line_origin A GIT_DIFF_LINE constant from above
|
||||
* @param content Pointer to content of diff line, not NUL-terminated
|
||||
* @param content_len Number of characters in content
|
||||
* @param old_lineno Line number in old file or -1 if line is added
|
||||
* @param new_lineno Line number in new file or -1 if line is deleted
|
||||
* @param patch The patch to look in
|
||||
* @param hunk_idx The index of the hunk
|
||||
* @param line_of_index The index of the line in the hunk
|
||||
* @return 0 on success, <0 on failure
|
||||
*/
|
||||
GIT_EXTERN(int) git_diff_patch_get_line_in_hunk(
|
||||
char *line_origin,
|
||||
const char **content,
|
||||
size_t *content_len,
|
||||
int *old_lineno,
|
||||
int *new_lineno,
|
||||
git_diff_patch *patch,
|
||||
size_t hunk_idx,
|
||||
size_t line_of_hunk);
|
||||
|
||||
/**
|
||||
* Serialize the patch to text via callback.
|
||||
*
|
||||
* Returning a non-zero value from the callback will terminate the iteration
|
||||
* and cause this return `GIT_EUSER`.
|
||||
*
|
||||
* @param patch A git_diff_patch representing changes to one file
|
||||
* @param print_cb Callback function to output lines of the patch. Will be
|
||||
* called for file headers, hunk headers, and diff lines.
|
||||
* @param payload Reference pointer that will be passed to your callbacks.
|
||||
* @return 0 on success, GIT_EUSER on non-zero callback, or error code
|
||||
*/
|
||||
GIT_EXTERN(int) git_diff_patch_print(
|
||||
git_diff_patch *patch,
|
||||
git_diff_data_cb print_cb,
|
||||
void *payload);
|
||||
|
||||
/**
|
||||
* Get the content of a patch as a single diff text.
|
||||
*
|
||||
* @param string Allocated string; caller must free.
|
||||
* @param patch A git_diff_patch representing changes to one file
|
||||
* @return 0 on success, <0 on failure.
|
||||
*/
|
||||
GIT_EXTERN(int) git_diff_patch_to_str(
|
||||
char **string,
|
||||
git_diff_patch *patch);
|
||||
|
||||
/**@}*/
|
||||
|
||||
|
||||
/*
|
||||
* Misc
|
||||
*/
|
||||
|
||||
/**
|
||||
* Directly run a diff on two blobs.
|
||||
*
|
||||
* Compared to a file, a blob lacks some contextual information. As such,
|
||||
* the `git_diff_file` given to the callback will have some fake data; i.e.
|
||||
* `mode` will be 0 and `path` will be NULL.
|
||||
*
|
||||
* NULL is allowed for either `old_blob` or `new_blob` and will be treated
|
||||
* as an empty blob, with the `oid` set to NULL in the `git_diff_file` data.
|
||||
*
|
||||
* We do run a binary content check on the two blobs and if either of the
|
||||
* blobs looks like binary data, the `git_diff_delta` binary attribute will
|
||||
* be set to 1 and no call to the hunk_cb nor line_cb will be made (unless
|
||||
* you pass `GIT_DIFF_FORCE_TEXT` of course).
|
||||
*
|
||||
* @return 0 on success, GIT_EUSER on non-zero callback, or error code
|
||||
*/
|
||||
GIT_EXTERN(int) git_diff_blobs(
|
||||
const git_blob *old_blob,
|
||||
const git_blob *new_blob,
|
||||
const git_diff_options *options,
|
||||
git_diff_file_cb file_cb,
|
||||
git_diff_hunk_cb hunk_cb,
|
||||
git_diff_data_cb line_cb,
|
||||
void *payload);
|
||||
|
||||
/**
|
||||
* Directly run a diff between a blob and a buffer.
|
||||
*
|
||||
* As with `git_diff_blobs`, comparing a blob and buffer lacks some context,
|
||||
* so the `git_diff_file` parameters to the callbacks will be faked a la the
|
||||
* rules for `git_diff_blobs()`.
|
||||
*
|
||||
* @return 0 on success, GIT_EUSER on non-zero callback, or error code
|
||||
*/
|
||||
GIT_EXTERN(int) git_diff_blob_to_buffer(
|
||||
const git_blob *old_blob,
|
||||
const char *buffer,
|
||||
size_t buffer_len,
|
||||
const git_diff_options *options,
|
||||
git_diff_file_cb file_cb,
|
||||
git_diff_hunk_cb hunk_cb,
|
||||
git_diff_data_cb data_cb,
|
||||
void *payload);
|
||||
|
||||
GIT_END_DECL
|
||||
|
||||
/** @} */
|
||||
|
||||
#endif
|
||||
@@ -1,119 +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_errors_h__
|
||||
#define INCLUDE_git_errors_h__
|
||||
|
||||
#include "common.h"
|
||||
|
||||
/**
|
||||
* @file git2/errors.h
|
||||
* @brief Git error handling routines and variables
|
||||
* @ingroup Git
|
||||
* @{
|
||||
*/
|
||||
GIT_BEGIN_DECL
|
||||
|
||||
/** Generic return codes */
|
||||
enum {
|
||||
GIT_OK = 0,
|
||||
GIT_ERROR = -1,
|
||||
GIT_ENOTFOUND = -3,
|
||||
GIT_EEXISTS = -4,
|
||||
GIT_EAMBIGUOUS = -5,
|
||||
GIT_EBUFS = -6,
|
||||
GIT_EUSER = -7,
|
||||
GIT_EBAREREPO = -8,
|
||||
GIT_EORPHANEDHEAD = -9,
|
||||
GIT_EUNMERGED = -10,
|
||||
GIT_ENONFASTFORWARD = -11,
|
||||
GIT_EINVALIDSPEC = -12,
|
||||
|
||||
GIT_PASSTHROUGH = -30,
|
||||
GIT_ITEROVER = -31,
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
char *message;
|
||||
int klass;
|
||||
} git_error;
|
||||
|
||||
/** Error classes */
|
||||
typedef enum {
|
||||
GITERR_NOMEMORY,
|
||||
GITERR_OS,
|
||||
GITERR_INVALID,
|
||||
GITERR_REFERENCE,
|
||||
GITERR_ZLIB,
|
||||
GITERR_REPOSITORY,
|
||||
GITERR_CONFIG,
|
||||
GITERR_REGEX,
|
||||
GITERR_ODB,
|
||||
GITERR_INDEX,
|
||||
GITERR_OBJECT,
|
||||
GITERR_NET,
|
||||
GITERR_TAG,
|
||||
GITERR_TREE,
|
||||
GITERR_INDEXER,
|
||||
GITERR_SSL,
|
||||
GITERR_SUBMODULE,
|
||||
GITERR_THREAD,
|
||||
GITERR_STASH,
|
||||
GITERR_CHECKOUT,
|
||||
GITERR_FETCHHEAD,
|
||||
GITERR_MERGE,
|
||||
} git_error_t;
|
||||
|
||||
/**
|
||||
* Return the last `git_error` object that was generated for the
|
||||
* current thread or NULL if no error has occurred.
|
||||
*
|
||||
* @return A git_error object.
|
||||
*/
|
||||
GIT_EXTERN(const git_error *) giterr_last(void);
|
||||
|
||||
/**
|
||||
* Clear the last library error that occurred for this thread.
|
||||
*/
|
||||
GIT_EXTERN(void) giterr_clear(void);
|
||||
|
||||
/**
|
||||
* Set the error message string for this thread.
|
||||
*
|
||||
* This function is public so that custom ODB backends and the like can
|
||||
* relay an error message through libgit2. Most regular users of libgit2
|
||||
* will never need to call this function -- actually, calling it in most
|
||||
* circumstances (for example, calling from within a callback function)
|
||||
* will just end up having the value overwritten by libgit2 internals.
|
||||
*
|
||||
* This error message is stored in thread-local storage and only applies
|
||||
* to the particular thread that this libgit2 call is made from.
|
||||
*
|
||||
* NOTE: Passing the `error_class` as GITERR_OS has a special behavior: we
|
||||
* attempt to append the system default error message for the last OS error
|
||||
* that occurred and then clear the last error. The specific implementation
|
||||
* of looking up and clearing this last OS error will vary by platform.
|
||||
*
|
||||
* @param error_class One of the `git_error_t` enum above describing the
|
||||
* general subsystem that is responsible for the error.
|
||||
* @param message The formatted error message to keep
|
||||
*/
|
||||
GIT_EXTERN(void) giterr_set_str(int error_class, const char *string);
|
||||
|
||||
/**
|
||||
* Set the error message to a special value for memory allocation failure.
|
||||
*
|
||||
* The normal `giterr_set_str()` function attempts to `strdup()` the string
|
||||
* that is passed in. This is not a good idea when the error in question
|
||||
* is a memory allocation failure. That circumstance has a special setter
|
||||
* function that sets the error string to a known and statically allocated
|
||||
* internal value.
|
||||
*/
|
||||
GIT_EXTERN(void) giterr_set_oom(void);
|
||||
|
||||
/** @} */
|
||||
GIT_END_DECL
|
||||
#endif
|
||||
@@ -1,36 +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_graph_h__
|
||||
#define INCLUDE_git_graph_h__
|
||||
|
||||
#include "common.h"
|
||||
#include "types.h"
|
||||
#include "oid.h"
|
||||
|
||||
/**
|
||||
* @file git2/graph.h
|
||||
* @brief Git graph traversal routines
|
||||
* @defgroup git_revwalk Git graph traversal routines
|
||||
* @ingroup Git
|
||||
* @{
|
||||
*/
|
||||
GIT_BEGIN_DECL
|
||||
|
||||
/**
|
||||
* Count the number of unique commits between two commit objects
|
||||
*
|
||||
* @param ahead number of commits, starting at `one`, unique from commits in `two`
|
||||
* @param behind number of commits, starting at `two`, unique from commits in `one`
|
||||
* @param repo the repository where the commits exist
|
||||
* @param one one of the commits
|
||||
* @param two the other commit
|
||||
*/
|
||||
GIT_EXTERN(int) git_graph_ahead_behind(size_t *ahead, size_t *behind, git_repository *repo, const git_oid *one, const git_oid *two);
|
||||
|
||||
/** @} */
|
||||
GIT_END_DECL
|
||||
#endif
|
||||
@@ -1,78 +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_ignore_h__
|
||||
#define INCLUDE_git_ignore_h__
|
||||
|
||||
#include "common.h"
|
||||
#include "types.h"
|
||||
|
||||
GIT_BEGIN_DECL
|
||||
|
||||
/**
|
||||
* Add ignore rules for a repository.
|
||||
*
|
||||
* Excludesfile rules (i.e. .gitignore rules) are generally read from
|
||||
* .gitignore files in the repository tree or from a shared system file
|
||||
* only if a "core.excludesfile" config value is set. The library also
|
||||
* keeps a set of per-repository internal ignores that can be configured
|
||||
* in-memory and will not persist. This function allows you to add to
|
||||
* that internal rules list.
|
||||
*
|
||||
* Example usage:
|
||||
*
|
||||
* error = git_ignore_add_rule(myrepo, "*.c\ndir/\nFile with space\n");
|
||||
*
|
||||
* This would add three rules to the ignores.
|
||||
*
|
||||
* @param repo The repository to add ignore rules to.
|
||||
* @param rules Text of rules, a la the contents of a .gitignore file.
|
||||
* It is okay to have multiple rules in the text; if so,
|
||||
* each rule should be terminated with a newline.
|
||||
* @return 0 on success
|
||||
*/
|
||||
GIT_EXTERN(int) git_ignore_add_rule(
|
||||
git_repository *repo,
|
||||
const char *rules);
|
||||
|
||||
/**
|
||||
* Clear ignore rules that were explicitly added.
|
||||
*
|
||||
* Resets to the default internal ignore rules. This will not turn off
|
||||
* rules in .gitignore files that actually exist in the filesystem.
|
||||
*
|
||||
* The default internal ignores ignore ".", ".." and ".git" entries.
|
||||
*
|
||||
* @param repo The repository to remove ignore rules from.
|
||||
* @return 0 on success
|
||||
*/
|
||||
GIT_EXTERN(int) git_ignore_clear_internal_rules(
|
||||
git_repository *repo);
|
||||
|
||||
/**
|
||||
* Test if the ignore rules apply to a given path.
|
||||
*
|
||||
* This function checks the ignore rules to see if they would apply to the
|
||||
* given file. This indicates if the file would be ignored regardless of
|
||||
* whether the file is already in the index or committed to the repository.
|
||||
*
|
||||
* One way to think of this is if you were to do "git add ." on the
|
||||
* directory containing the file, would it be added or not?
|
||||
*
|
||||
* @param ignored boolean returning 0 if the file is not ignored, 1 if it is
|
||||
* @param repo a repository object
|
||||
* @param path the file to check ignores for, relative to the repo's workdir.
|
||||
* @return 0 if ignore rules could be processed for the file (regardless
|
||||
* of whether it exists or not), or an error < 0 if they could not.
|
||||
*/
|
||||
GIT_EXTERN(int) git_ignore_path_is_ignored(
|
||||
int *ignored,
|
||||
git_repository *repo,
|
||||
const char *path);
|
||||
|
||||
GIT_END_DECL
|
||||
|
||||
#endif
|
||||
@@ -1,552 +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_index_h__
|
||||
#define INCLUDE_git_index_h__
|
||||
|
||||
#include "common.h"
|
||||
#include "indexer.h"
|
||||
#include "types.h"
|
||||
#include "oid.h"
|
||||
|
||||
/**
|
||||
* @file git2/index.h
|
||||
* @brief Git index parsing and manipulation routines
|
||||
* @defgroup git_index Git index parsing and manipulation routines
|
||||
* @ingroup Git
|
||||
* @{
|
||||
*/
|
||||
GIT_BEGIN_DECL
|
||||
|
||||
#define GIT_IDXENTRY_NAMEMASK (0x0fff)
|
||||
#define GIT_IDXENTRY_STAGEMASK (0x3000)
|
||||
#define GIT_IDXENTRY_EXTENDED (0x4000)
|
||||
#define GIT_IDXENTRY_VALID (0x8000)
|
||||
#define GIT_IDXENTRY_STAGESHIFT 12
|
||||
|
||||
/*
|
||||
* Flags are divided into two parts: in-memory flags and
|
||||
* on-disk ones. Flags in GIT_IDXENTRY_EXTENDED_FLAGS
|
||||
* will get saved on-disk.
|
||||
*
|
||||
* In-memory only flags:
|
||||
*/
|
||||
#define GIT_IDXENTRY_UPDATE (1 << 0)
|
||||
#define GIT_IDXENTRY_REMOVE (1 << 1)
|
||||
#define GIT_IDXENTRY_UPTODATE (1 << 2)
|
||||
#define GIT_IDXENTRY_ADDED (1 << 3)
|
||||
|
||||
#define GIT_IDXENTRY_HASHED (1 << 4)
|
||||
#define GIT_IDXENTRY_UNHASHED (1 << 5)
|
||||
#define GIT_IDXENTRY_WT_REMOVE (1 << 6) /* remove in work directory */
|
||||
#define GIT_IDXENTRY_CONFLICTED (1 << 7)
|
||||
|
||||
#define GIT_IDXENTRY_UNPACKED (1 << 8)
|
||||
#define GIT_IDXENTRY_NEW_SKIP_WORKTREE (1 << 9)
|
||||
|
||||
/*
|
||||
* Extended on-disk flags:
|
||||
*/
|
||||
#define GIT_IDXENTRY_INTENT_TO_ADD (1 << 13)
|
||||
#define GIT_IDXENTRY_SKIP_WORKTREE (1 << 14)
|
||||
/* GIT_IDXENTRY_EXTENDED2 is for future extension */
|
||||
#define GIT_IDXENTRY_EXTENDED2 (1 << 15)
|
||||
|
||||
#define GIT_IDXENTRY_EXTENDED_FLAGS (GIT_IDXENTRY_INTENT_TO_ADD | GIT_IDXENTRY_SKIP_WORKTREE)
|
||||
|
||||
/** Time used in a git index entry */
|
||||
typedef struct {
|
||||
git_time_t seconds;
|
||||
/* nsec should not be stored as time_t compatible */
|
||||
unsigned int nanoseconds;
|
||||
} git_index_time;
|
||||
|
||||
/** Memory representation of a file entry in the index. */
|
||||
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;
|
||||
|
||||
git_oid oid;
|
||||
|
||||
unsigned short flags;
|
||||
unsigned short flags_extended;
|
||||
|
||||
char *path;
|
||||
} git_index_entry;
|
||||
|
||||
/** Representation of a resolve undo entry in the index. */
|
||||
typedef struct git_index_reuc_entry {
|
||||
unsigned int mode[3];
|
||||
git_oid oid[3];
|
||||
char *path;
|
||||
} git_index_reuc_entry;
|
||||
|
||||
/** Capabilities of system that affect index actions. */
|
||||
enum {
|
||||
GIT_INDEXCAP_IGNORE_CASE = 1,
|
||||
GIT_INDEXCAP_NO_FILEMODE = 2,
|
||||
GIT_INDEXCAP_NO_SYMLINKS = 4,
|
||||
GIT_INDEXCAP_FROM_OWNER = ~0u
|
||||
};
|
||||
|
||||
/** @name Index File Functions
|
||||
*
|
||||
* These functions work on the index file itself.
|
||||
*/
|
||||
/**@{*/
|
||||
|
||||
/**
|
||||
* Create a new bare Git index object as a memory representation
|
||||
* of the Git index file in 'index_path', without a repository
|
||||
* to back it.
|
||||
*
|
||||
* Since there is no ODB or working directory behind this index,
|
||||
* any Index methods which rely on these (e.g. index_add) will
|
||||
* fail with the GIT_EBAREINDEX error code.
|
||||
*
|
||||
* If you need to access the index of an actual repository,
|
||||
* use the `git_repository_index` wrapper.
|
||||
*
|
||||
* The index must be freed once it's no longer in use.
|
||||
*
|
||||
* @param out the pointer for the new index
|
||||
* @param index_path the path to the index file in disk
|
||||
* @return 0 or an error code
|
||||
*/
|
||||
GIT_EXTERN(int) git_index_open(git_index **out, const char *index_path);
|
||||
|
||||
/**
|
||||
* Create an in-memory index object.
|
||||
*
|
||||
* This index object cannot be read/written to the filesystem,
|
||||
* but may be used to perform in-memory index operations.
|
||||
*
|
||||
* The index must be freed once it's no longer in use.
|
||||
*
|
||||
* @param out the pointer for the new index
|
||||
* @return 0 or an error code
|
||||
*/
|
||||
GIT_EXTERN(int) git_index_new(git_index **out);
|
||||
|
||||
/**
|
||||
* Free an existing index object.
|
||||
*
|
||||
* @param index an existing index object
|
||||
*/
|
||||
GIT_EXTERN(void) git_index_free(git_index *index);
|
||||
|
||||
/**
|
||||
* Get the repository this index relates to
|
||||
*
|
||||
* @param index The index
|
||||
* @return A pointer to the repository
|
||||
*/
|
||||
GIT_EXTERN(git_repository *) git_index_owner(const git_index *index);
|
||||
|
||||
/**
|
||||
* Read index capabilities flags.
|
||||
*
|
||||
* @param index An existing index object
|
||||
* @return A combination of GIT_INDEXCAP values
|
||||
*/
|
||||
GIT_EXTERN(unsigned int) git_index_caps(const git_index *index);
|
||||
|
||||
/**
|
||||
* Set index capabilities flags.
|
||||
*
|
||||
* If you pass `GIT_INDEXCAP_FROM_OWNER` for the caps, then the
|
||||
* capabilities will be read from the config of the owner object,
|
||||
* looking at `core.ignorecase`, `core.filemode`, `core.symlinks`.
|
||||
*
|
||||
* @param index An existing index object
|
||||
* @param caps A combination of GIT_INDEXCAP values
|
||||
* @return 0 on success, -1 on failure
|
||||
*/
|
||||
GIT_EXTERN(int) git_index_set_caps(git_index *index, unsigned int caps);
|
||||
|
||||
/**
|
||||
* Update the contents of an existing index object in memory
|
||||
* by reading from the hard disk.
|
||||
*
|
||||
* @param index an existing index object
|
||||
* @return 0 or an error code
|
||||
*/
|
||||
GIT_EXTERN(int) git_index_read(git_index *index);
|
||||
|
||||
/**
|
||||
* Write an existing index object from memory back to disk
|
||||
* using an atomic file lock.
|
||||
*
|
||||
* @param index an existing index object
|
||||
* @return 0 or an error code
|
||||
*/
|
||||
GIT_EXTERN(int) git_index_write(git_index *index);
|
||||
|
||||
/**
|
||||
* Read a tree into the index file with stats
|
||||
*
|
||||
* The current index contents will be replaced by the specified tree.
|
||||
*
|
||||
* @param index an existing index object
|
||||
* @param tree tree to read
|
||||
* @return 0 or an error code
|
||||
*/
|
||||
GIT_EXTERN(int) git_index_read_tree(git_index *index, const git_tree *tree);
|
||||
|
||||
/**
|
||||
* Write the index as a tree
|
||||
*
|
||||
* This method will scan the index and write a representation
|
||||
* of its current state back to disk; it recursively creates
|
||||
* tree objects for each of the subtrees stored in the index,
|
||||
* but only returns the OID of the root tree. This is the OID
|
||||
* that can be used e.g. to create a commit.
|
||||
*
|
||||
* The index instance cannot be bare, and needs to be associated
|
||||
* to an existing repository.
|
||||
*
|
||||
* The index must not contain any file in conflict.
|
||||
*
|
||||
* @param out Pointer where to store the OID of the written tree
|
||||
* @param index Index to write
|
||||
* @return 0 on success, GIT_EUNMERGED when the index is not clean
|
||||
* or an error code
|
||||
*/
|
||||
GIT_EXTERN(int) git_index_write_tree(git_oid *out, git_index *index);
|
||||
|
||||
/**
|
||||
* Write the index as a tree to the given repository
|
||||
*
|
||||
* This method will do the same as `git_index_write_tree`, but
|
||||
* letting the user choose the repository where the tree will
|
||||
* be written.
|
||||
*
|
||||
* The index must not contain any file in conflict.
|
||||
*
|
||||
* @param out Pointer where to store OID of the the written tree
|
||||
* @param index Index to write
|
||||
* @param repo Repository where to write the tree
|
||||
* @return 0 on success, GIT_EUNMERGED when the index is not clean
|
||||
* or an error code
|
||||
*/
|
||||
GIT_EXTERN(int) git_index_write_tree_to(git_oid *out, git_index *index, git_repository *repo);
|
||||
|
||||
/**@}*/
|
||||
|
||||
/** @name Raw Index Entry Functions
|
||||
*
|
||||
* These functions work on index entries, and allow for raw manipulation
|
||||
* of the entries.
|
||||
*/
|
||||
/**@{*/
|
||||
|
||||
/* Index entry manipulation */
|
||||
|
||||
/**
|
||||
* Get the count of entries currently in the index
|
||||
*
|
||||
* @param index an existing index object
|
||||
* @return integer of count of current entries
|
||||
*/
|
||||
GIT_EXTERN(size_t) git_index_entrycount(const git_index *index);
|
||||
|
||||
/**
|
||||
* Clear the contents (all the entries) of an index object.
|
||||
* This clears the index object in memory; changes must be manually
|
||||
* written to disk for them to take effect.
|
||||
*
|
||||
* @param index an existing index object
|
||||
*/
|
||||
GIT_EXTERN(void) git_index_clear(git_index *index);
|
||||
|
||||
/**
|
||||
* Get a pointer to one of the entries in the index
|
||||
*
|
||||
* The values of this entry can be modified (except the path)
|
||||
* and the changes will be written back to disk on the next
|
||||
* write() call.
|
||||
*
|
||||
* The entry should not be freed by the caller.
|
||||
*
|
||||
* @param index an existing index object
|
||||
* @param n the position of the entry
|
||||
* @return a pointer to the entry; NULL if out of bounds
|
||||
*/
|
||||
GIT_EXTERN(const git_index_entry *) git_index_get_byindex(
|
||||
git_index *index, size_t n);
|
||||
|
||||
/**
|
||||
* Get a pointer to one of the entries in the index
|
||||
*
|
||||
* The values of this entry can be modified (except the path)
|
||||
* and the changes will be written back to disk on the next
|
||||
* write() call.
|
||||
*
|
||||
* The entry should not be freed by the caller.
|
||||
*
|
||||
* @param index an existing index object
|
||||
* @param path path to search
|
||||
* @param stage stage to search
|
||||
* @return a pointer to the entry; NULL if it was not found
|
||||
*/
|
||||
GIT_EXTERN(const git_index_entry *) git_index_get_bypath(
|
||||
git_index *index, const char *path, int stage);
|
||||
|
||||
/**
|
||||
* Remove an entry from the index
|
||||
*
|
||||
* @param index an existing index object
|
||||
* @param path path to search
|
||||
* @param stage stage to search
|
||||
* @return 0 or an error code
|
||||
*/
|
||||
GIT_EXTERN(int) git_index_remove(git_index *index, const char *path, int stage);
|
||||
|
||||
/**
|
||||
* Remove all entries from the index under a given directory
|
||||
*
|
||||
* @param index an existing index object
|
||||
* @param dir container directory path
|
||||
* @param stage stage to search
|
||||
* @return 0 or an error code
|
||||
*/
|
||||
GIT_EXTERN(int) git_index_remove_directory(
|
||||
git_index *index, const char *dir, int stage);
|
||||
|
||||
/**
|
||||
* Add or update an index entry from an in-memory struct
|
||||
*
|
||||
* If a previous index entry exists that has the same path and stage
|
||||
* as the given 'source_entry', it will be replaced. Otherwise, the
|
||||
* 'source_entry' will be added.
|
||||
*
|
||||
* A full copy (including the 'path' string) of the given
|
||||
* 'source_entry' will be inserted on the index.
|
||||
*
|
||||
* @param index an existing index object
|
||||
* @param source_entry new entry object
|
||||
* @return 0 or an error code
|
||||
*/
|
||||
GIT_EXTERN(int) git_index_add(git_index *index, const git_index_entry *source_entry);
|
||||
|
||||
/**
|
||||
* Return the stage number from a git index entry
|
||||
*
|
||||
* This entry is calculated from the entry's flag
|
||||
* attribute like this:
|
||||
*
|
||||
* (entry->flags & GIT_IDXENTRY_STAGEMASK) >> GIT_IDXENTRY_STAGESHIFT
|
||||
*
|
||||
* @param entry The entry
|
||||
* @returns the stage number
|
||||
*/
|
||||
GIT_EXTERN(int) git_index_entry_stage(const git_index_entry *entry);
|
||||
|
||||
/**@}*/
|
||||
|
||||
/** @name Workdir Index Entry Functions
|
||||
*
|
||||
* These functions work on index entries specifically in the working
|
||||
* directory (ie, stage 0).
|
||||
*/
|
||||
/**@{*/
|
||||
|
||||
/**
|
||||
* Add or update an index entry from a file in disk
|
||||
*
|
||||
* The file `path` must be relative to the repository's
|
||||
* working folder and must be readable.
|
||||
*
|
||||
* This method will fail in bare index instances.
|
||||
*
|
||||
* 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 path filename to add
|
||||
* @return 0 or an error code
|
||||
*/
|
||||
GIT_EXTERN(int) git_index_add_from_workdir(git_index *index, const char *path);
|
||||
|
||||
/**
|
||||
* Find the first index of any entries which point to given
|
||||
* path in the Git index.
|
||||
*
|
||||
* @param index an existing index object
|
||||
* @param path path to search
|
||||
* @return an index >= 0 if found, -1 otherwise
|
||||
*/
|
||||
GIT_EXTERN(int) git_index_find(git_index *index, const char *path);
|
||||
|
||||
/**@}*/
|
||||
|
||||
/** @name Conflict Index Entry Functions
|
||||
*
|
||||
* These functions work on conflict index entries specifically (ie, stages 1-3)
|
||||
*/
|
||||
/**@{*/
|
||||
|
||||
/**
|
||||
* Add or update index entries to represent a conflict
|
||||
*
|
||||
* 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
|
||||
* trees during the merge. For example, ancestor_entry may be NULL to
|
||||
* indicate that a file was added in both branches and must be resolved.
|
||||
*
|
||||
* @param index an existing index object
|
||||
* @param ancestor_entry the entry data for the ancestor of the conflict
|
||||
* @param our_entry the entry data for our side of the merge conflict
|
||||
* @param their_entry the entry data for their side of the merge conflict
|
||||
* @return 0 or an error code
|
||||
*/
|
||||
GIT_EXTERN(int) git_index_conflict_add(
|
||||
git_index *index,
|
||||
const git_index_entry *ancestor_entry,
|
||||
const git_index_entry *our_entry,
|
||||
const git_index_entry *their_entry);
|
||||
|
||||
/**
|
||||
* Get the index entries that represent a conflict of a single file.
|
||||
*
|
||||
* The values of this entry can be modified (except the paths)
|
||||
* and the changes will be written back to disk on the next
|
||||
* write() call.
|
||||
*
|
||||
* @param ancestor_out Pointer to store the ancestor entry
|
||||
* @param our_out Pointer to store the our entry
|
||||
* @param their_out Pointer to store the their entry
|
||||
* @param index an existing index object
|
||||
* @param path path to search
|
||||
*/
|
||||
GIT_EXTERN(int) git_index_conflict_get(git_index_entry **ancestor_out, git_index_entry **our_out, git_index_entry **their_out, git_index *index, const char *path);
|
||||
|
||||
/**
|
||||
* Removes the index entries that represent a conflict of a single file.
|
||||
*
|
||||
* @param index an existing index object
|
||||
* @param path to search
|
||||
*/
|
||||
GIT_EXTERN(int) git_index_conflict_remove(git_index *index, const char *path);
|
||||
|
||||
/**
|
||||
* Remove all conflicts in the index (entries with a stage greater than 0.)
|
||||
*
|
||||
* @param index an existing index object
|
||||
*/
|
||||
GIT_EXTERN(void) git_index_conflict_cleanup(git_index *index);
|
||||
|
||||
/**
|
||||
* Determine if the index contains entries representing file conflicts.
|
||||
*
|
||||
* @return 1 if at least one conflict is found, 0 otherwise.
|
||||
*/
|
||||
GIT_EXTERN(int) git_index_has_conflicts(const git_index *index);
|
||||
|
||||
/**@}*/
|
||||
|
||||
/** @name Resolve Undo (REUC) index entry manipulation.
|
||||
*
|
||||
* These functions work on the Resolve Undo index extension and contains
|
||||
* data about the original files that led to a merge conflict.
|
||||
*/
|
||||
/**@{*/
|
||||
|
||||
/**
|
||||
* Get the count of resolve undo entries currently in the index.
|
||||
*
|
||||
* @param index an existing index object
|
||||
* @return integer of count of current resolve undo entries
|
||||
*/
|
||||
GIT_EXTERN(unsigned int) git_index_reuc_entrycount(git_index *index);
|
||||
|
||||
/**
|
||||
* Finds the resolve undo entry that points to the given path in the Git
|
||||
* index.
|
||||
*
|
||||
* @param index an existing index object
|
||||
* @param path path to search
|
||||
* @return an index >= 0 if found, -1 otherwise
|
||||
*/
|
||||
GIT_EXTERN(int) git_index_reuc_find(git_index *index, const char *path);
|
||||
|
||||
/**
|
||||
* Get a resolve undo entry from the index.
|
||||
*
|
||||
* The returned entry is read-only and should not be modified
|
||||
* or freed by the caller.
|
||||
*
|
||||
* @param index an existing index object
|
||||
* @param path path to search
|
||||
* @return the resolve undo entry; NULL if not found
|
||||
*/
|
||||
GIT_EXTERN(const git_index_reuc_entry *) git_index_reuc_get_bypath(git_index *index, const char *path);
|
||||
|
||||
/**
|
||||
* Get a resolve undo entry from the index.
|
||||
*
|
||||
* The returned entry is read-only and should not be modified
|
||||
* or freed by the caller.
|
||||
*
|
||||
* @param index an existing index object
|
||||
* @param n the position of the entry
|
||||
* @return a pointer to the resolve undo entry; NULL if out of bounds
|
||||
*/
|
||||
GIT_EXTERN(const git_index_reuc_entry *) git_index_reuc_get_byindex(git_index *index, size_t n);
|
||||
|
||||
/**
|
||||
* Adds a resolve undo entry for a file based on the given parameters.
|
||||
*
|
||||
* The resolve undo entry contains the OIDs of files that were involved
|
||||
* in a merge conflict after the conflict has been resolved. This allows
|
||||
* conflicts to be re-resolved later.
|
||||
*
|
||||
* If there exists a resolve undo entry for the given path in the index,
|
||||
* it will be removed.
|
||||
*
|
||||
* This method will fail in bare index instances.
|
||||
*
|
||||
* @param index an existing index object
|
||||
* @param path filename to add
|
||||
* @param ancestor_mode mode of the ancestor file
|
||||
* @param ancestor_id oid of the ancestor file
|
||||
* @param our_mode mode of our file
|
||||
* @param our_id oid of our file
|
||||
* @param their_mode mode of their file
|
||||
* @param their_id oid of their file
|
||||
* @return 0 or an error code
|
||||
*/
|
||||
GIT_EXTERN(int) git_index_reuc_add(git_index *index, const char *path,
|
||||
int ancestor_mode, git_oid *ancestor_id,
|
||||
int our_mode, git_oid *our_id,
|
||||
int their_mode, git_oid *their_id);
|
||||
|
||||
/**
|
||||
* Remove an resolve undo entry from the index
|
||||
*
|
||||
* @param index an existing index object
|
||||
* @param n position of the resolve undo entry to remove
|
||||
* @return 0 or an error code
|
||||
*/
|
||||
GIT_EXTERN(int) git_index_reuc_remove(git_index *index, size_t n);
|
||||
|
||||
/**@}*/
|
||||
|
||||
/** @} */
|
||||
GIT_END_DECL
|
||||
#endif
|
||||
@@ -1,134 +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_indexer_h__
|
||||
#define _INCLUDE_git_indexer_h__
|
||||
|
||||
#include "common.h"
|
||||
#include "oid.h"
|
||||
|
||||
GIT_BEGIN_DECL
|
||||
|
||||
/**
|
||||
* This is passed as the first argument to the callback to allow the
|
||||
* user to see the progress.
|
||||
*/
|
||||
typedef struct git_transfer_progress {
|
||||
unsigned int total_objects;
|
||||
unsigned int indexed_objects;
|
||||
unsigned int received_objects;
|
||||
size_t received_bytes;
|
||||
} git_transfer_progress;
|
||||
|
||||
|
||||
/**
|
||||
* Type for progress callbacks during indexing
|
||||
*/
|
||||
typedef void (*git_transfer_progress_callback)(const git_transfer_progress *stats, void *payload);
|
||||
|
||||
typedef struct git_indexer git_indexer;
|
||||
typedef struct git_indexer_stream git_indexer_stream;
|
||||
|
||||
/**
|
||||
* Create a new streaming indexer instance
|
||||
*
|
||||
* @param out where to store the indexer instance
|
||||
* @param path to the directory where the packfile should be stored
|
||||
* @param progress_cb function to call with progress information
|
||||
* @param progress_payload payload for the progress callback
|
||||
*/
|
||||
GIT_EXTERN(int) git_indexer_stream_new(
|
||||
git_indexer_stream **out,
|
||||
const char *path,
|
||||
git_transfer_progress_callback progress_cb,
|
||||
void *progress_cb_payload);
|
||||
|
||||
/**
|
||||
* Add data to the indexer
|
||||
*
|
||||
* @param idx the indexer
|
||||
* @param data the data to add
|
||||
* @param size the size of the data in bytes
|
||||
* @param stats stat storage
|
||||
*/
|
||||
GIT_EXTERN(int) git_indexer_stream_add(git_indexer_stream *idx, const void *data, size_t size, git_transfer_progress *stats);
|
||||
|
||||
/**
|
||||
* Finalize the pack and index
|
||||
*
|
||||
* Resolve any pending deltas and write out the index file
|
||||
*
|
||||
* @param idx the indexer
|
||||
*/
|
||||
GIT_EXTERN(int) git_indexer_stream_finalize(git_indexer_stream *idx, git_transfer_progress *stats);
|
||||
|
||||
/**
|
||||
* Get the packfile's hash
|
||||
*
|
||||
* A packfile's name is derived from the sorted hashing of all object
|
||||
* names. This is only correct after the index has been finalized.
|
||||
*
|
||||
* @param idx the indexer instance
|
||||
*/
|
||||
GIT_EXTERN(const git_oid *) git_indexer_stream_hash(const git_indexer_stream *idx);
|
||||
|
||||
/**
|
||||
* Free the indexer and its resources
|
||||
*
|
||||
* @param idx the indexer to free
|
||||
*/
|
||||
GIT_EXTERN(void) git_indexer_stream_free(git_indexer_stream *idx);
|
||||
|
||||
/**
|
||||
* Create a new indexer instance
|
||||
*
|
||||
* @param out where to store the indexer instance
|
||||
* @param packname the absolute filename of the packfile to index
|
||||
*/
|
||||
GIT_EXTERN(int) git_indexer_new(git_indexer **out, const char *packname);
|
||||
|
||||
/**
|
||||
* Iterate over the objects in the packfile and extract the information
|
||||
*
|
||||
* Indexing a packfile can be very expensive so this function is
|
||||
* expected to be run in a worker thread and the stats used to provide
|
||||
* feedback the user.
|
||||
*
|
||||
* @param idx the indexer instance
|
||||
* @param stats storage for the running state
|
||||
*/
|
||||
GIT_EXTERN(int) git_indexer_run(git_indexer *idx, git_transfer_progress *stats);
|
||||
|
||||
/**
|
||||
* Write the index file to disk.
|
||||
*
|
||||
* The file will be stored as pack-$hash.idx in the same directory as
|
||||
* the packfile.
|
||||
*
|
||||
* @param idx the indexer instance
|
||||
*/
|
||||
GIT_EXTERN(int) git_indexer_write(git_indexer *idx);
|
||||
|
||||
/**
|
||||
* Get the packfile's hash
|
||||
*
|
||||
* A packfile's name is derived from the sorted hashing of all object
|
||||
* names. This is only correct after the index has been written to disk.
|
||||
*
|
||||
* @param idx the indexer instance
|
||||
*/
|
||||
GIT_EXTERN(const git_oid *) git_indexer_hash(const git_indexer *idx);
|
||||
|
||||
/**
|
||||
* Free the indexer and its resources
|
||||
*
|
||||
* @param idx the indexer to free
|
||||
*/
|
||||
GIT_EXTERN(void) git_indexer_free(git_indexer *idx);
|
||||
|
||||
GIT_END_DECL
|
||||
|
||||
#endif
|
||||
@@ -1,55 +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_merge_h__
|
||||
#define INCLUDE_git_merge_h__
|
||||
|
||||
#include "common.h"
|
||||
#include "types.h"
|
||||
#include "oid.h"
|
||||
|
||||
/**
|
||||
* @file git2/merge.h
|
||||
* @brief Git merge-base routines
|
||||
* @defgroup git_revwalk Git merge-base routines
|
||||
* @ingroup Git
|
||||
* @{
|
||||
*/
|
||||
GIT_BEGIN_DECL
|
||||
|
||||
/**
|
||||
* Find a merge base between two commits
|
||||
*
|
||||
* @param out the OID of a merge base between 'one' and 'two'
|
||||
* @param repo the repository where the commits exist
|
||||
* @param one one of the commits
|
||||
* @param two the other commit
|
||||
* @return Zero on success; GIT_ENOTFOUND or -1 on failure.
|
||||
*/
|
||||
GIT_EXTERN(int) git_merge_base(
|
||||
git_oid *out,
|
||||
git_repository *repo,
|
||||
const git_oid *one,
|
||||
const git_oid *two);
|
||||
|
||||
/**
|
||||
* Find a merge base given a list of commits
|
||||
*
|
||||
* @param out the OID of a merge base considering all the commits
|
||||
* @param repo the repository where the commits exist
|
||||
* @param input_array oids of the commits
|
||||
* @param length The number of commits in the provided `input_array`
|
||||
* @return Zero on success; GIT_ENOTFOUND or -1 on failure.
|
||||
*/
|
||||
GIT_EXTERN(int) git_merge_base_many(
|
||||
git_oid *out,
|
||||
git_repository *repo,
|
||||
const git_oid input_array[],
|
||||
size_t length);
|
||||
|
||||
/** @} */
|
||||
GIT_END_DECL
|
||||
#endif
|
||||
@@ -1,49 +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_message_h__
|
||||
#define INCLUDE_git_message_h__
|
||||
|
||||
#include "common.h"
|
||||
|
||||
/**
|
||||
* @file git2/message.h
|
||||
* @brief Git message management routines
|
||||
* @ingroup Git
|
||||
* @{
|
||||
*/
|
||||
GIT_BEGIN_DECL
|
||||
|
||||
/**
|
||||
* Clean up message from excess whitespace and make sure that the last line
|
||||
* ends with a '\n'.
|
||||
*
|
||||
* Optionally, can remove lines starting with a "#".
|
||||
*
|
||||
* @param out The user-allocated buffer which will be filled with the
|
||||
* cleaned up message. Pass NULL if you just want to get the needed
|
||||
* size of the prettified message as the output value.
|
||||
*
|
||||
* @param out_size Size of the `out` buffer in bytes.
|
||||
*
|
||||
* @param message The message to be prettified.
|
||||
*
|
||||
* @param strip_comments Non-zero to remove lines starting with "#", 0 to
|
||||
* leave them in.
|
||||
*
|
||||
* @return -1 on error, else number of characters in prettified message
|
||||
* including the trailing NUL byte
|
||||
*/
|
||||
GIT_EXTERN(int) git_message_prettify(
|
||||
char *out,
|
||||
size_t out_size,
|
||||
const char *message,
|
||||
int strip_comments);
|
||||
|
||||
/** @} */
|
||||
GIT_END_DECL
|
||||
|
||||
#endif /* INCLUDE_git_message_h__ */
|
||||
@@ -1,53 +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_net_h__
|
||||
#define INCLUDE_git_net_h__
|
||||
|
||||
#include "common.h"
|
||||
#include "oid.h"
|
||||
#include "types.h"
|
||||
|
||||
/**
|
||||
* @file git2/net.h
|
||||
* @brief Git networking declarations
|
||||
* @ingroup Git
|
||||
* @{
|
||||
*/
|
||||
GIT_BEGIN_DECL
|
||||
|
||||
#define GIT_DEFAULT_PORT "9418"
|
||||
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
struct git_remote_head {
|
||||
int local:1; /* available locally */
|
||||
git_oid oid;
|
||||
git_oid loid;
|
||||
char *name;
|
||||
};
|
||||
|
||||
/**
|
||||
* Callback for listing the remote heads
|
||||
*/
|
||||
typedef int (*git_headlist_cb)(git_remote_head *rhead, void *payload);
|
||||
|
||||
/** @} */
|
||||
GIT_END_DECL
|
||||
#endif
|
||||
@@ -1,154 +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_note_h__
|
||||
#define INCLUDE_git_note_h__
|
||||
|
||||
#include "oid.h"
|
||||
|
||||
/**
|
||||
* @file git2/notes.h
|
||||
* @brief Git notes management routines
|
||||
* @defgroup git_note Git notes management routines
|
||||
* @ingroup Git
|
||||
* @{
|
||||
*/
|
||||
GIT_BEGIN_DECL
|
||||
|
||||
/**
|
||||
* Callback for git_note_foreach.
|
||||
*
|
||||
* Receives:
|
||||
* - blob_id: Oid of the blob containing the message
|
||||
* - annotated_object_id: Oid of the git object being annotated
|
||||
* - payload: Payload data passed to `git_note_foreach`
|
||||
*/
|
||||
typedef int (*git_note_foreach_cb)(
|
||||
const git_oid *blob_id, const git_oid *annotated_object_id, void *payload);
|
||||
|
||||
/**
|
||||
* Read the note for an object
|
||||
*
|
||||
* The note must be freed manually by the user.
|
||||
*
|
||||
* @param out pointer to the read note; NULL in case of error
|
||||
* @param repo repository where to look up the note
|
||||
* @param notes_ref canonical name of the reference to use (optional); defaults to
|
||||
* "refs/notes/commits"
|
||||
* @param oid OID of the git object to read the note from
|
||||
*
|
||||
* @return 0 or an error code
|
||||
*/
|
||||
GIT_EXTERN(int) git_note_read(
|
||||
git_note **out,
|
||||
git_repository *repo,
|
||||
const char *notes_ref,
|
||||
const git_oid *oid);
|
||||
|
||||
/**
|
||||
* Get the note message
|
||||
*
|
||||
* @param note
|
||||
* @return the note message
|
||||
*/
|
||||
GIT_EXTERN(const char *) git_note_message(const git_note *note);
|
||||
|
||||
|
||||
/**
|
||||
* Get the note object OID
|
||||
*
|
||||
* @param note
|
||||
* @return the note object OID
|
||||
*/
|
||||
GIT_EXTERN(const git_oid *) git_note_oid(const git_note *note);
|
||||
|
||||
/**
|
||||
* Add a note for an object
|
||||
*
|
||||
* @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 oid OID of the git object to decorate
|
||||
* @param note Content of the note to add for object oid
|
||||
* @param force Overwrite existing note
|
||||
*
|
||||
* @return 0 or an error code
|
||||
*/
|
||||
GIT_EXTERN(int) git_note_create(
|
||||
git_oid *out,
|
||||
git_repository *repo,
|
||||
const git_signature *author,
|
||||
const git_signature *committer,
|
||||
const char *notes_ref,
|
||||
const git_oid *oid,
|
||||
const char *note,
|
||||
int force);
|
||||
|
||||
|
||||
/**
|
||||
* Remove the note for an object
|
||||
*
|
||||
* @param repo repository where the note lives
|
||||
* @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 remove the note from
|
||||
*
|
||||
* @return 0 or an error code
|
||||
*/
|
||||
GIT_EXTERN(int) git_note_remove(
|
||||
git_repository *repo,
|
||||
const char *notes_ref,
|
||||
const git_signature *author,
|
||||
const git_signature *committer,
|
||||
const git_oid *oid);
|
||||
|
||||
/**
|
||||
* Free a git_note object
|
||||
*
|
||||
* @param note git_note object
|
||||
*/
|
||||
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 repo The Git repository
|
||||
*
|
||||
* @return 0 or an error code
|
||||
*/
|
||||
GIT_EXTERN(int) git_note_default_ref(const char **out, git_repository *repo);
|
||||
|
||||
/**
|
||||
* Loop over all the notes within a specified namespace
|
||||
* and issue a callback for each one.
|
||||
*
|
||||
* @param repo Repository where to find the notes.
|
||||
*
|
||||
* @param notes_ref Reference to read from (optional); defaults to
|
||||
* "refs/notes/commits".
|
||||
*
|
||||
* @param note_cb Callback to invoke per found annotation. Return non-zero
|
||||
* to stop looping.
|
||||
*
|
||||
* @param payload Extra parameter to callback function.
|
||||
*
|
||||
* @return 0 on success, GIT_EUSER on non-zero callback, or error code
|
||||
*/
|
||||
GIT_EXTERN(int) git_note_foreach(
|
||||
git_repository *repo,
|
||||
const char *notes_ref,
|
||||
git_note_foreach_cb note_cb,
|
||||
void *payload);
|
||||
|
||||
/** @} */
|
||||
GIT_END_DECL
|
||||
#endif
|
||||
@@ -1,194 +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_object_h__
|
||||
#define INCLUDE_git_object_h__
|
||||
|
||||
#include "common.h"
|
||||
#include "types.h"
|
||||
#include "oid.h"
|
||||
|
||||
/**
|
||||
* @file git2/object.h
|
||||
* @brief Git revision object management routines
|
||||
* @defgroup git_object Git revision object management routines
|
||||
* @ingroup Git
|
||||
* @{
|
||||
*/
|
||||
GIT_BEGIN_DECL
|
||||
|
||||
/**
|
||||
* Lookup a reference to one of the objects in a repository.
|
||||
*
|
||||
* The generated reference is owned by the repository and
|
||||
* should be closed with the `git_object_free` method
|
||||
* instead of free'd manually.
|
||||
*
|
||||
* The 'type' parameter must match the type of the object
|
||||
* in the odb; the method will fail otherwise.
|
||||
* The special value 'GIT_OBJ_ANY' may be passed to let
|
||||
* the method guess the object's type.
|
||||
*
|
||||
* @param object pointer to the looked-up object
|
||||
* @param repo the repository to look up the object
|
||||
* @param id the unique identifier for the object
|
||||
* @param type the type of the object
|
||||
* @return a reference to the object
|
||||
*/
|
||||
GIT_EXTERN(int) git_object_lookup(
|
||||
git_object **object,
|
||||
git_repository *repo,
|
||||
const git_oid *id,
|
||||
git_otype type);
|
||||
|
||||
/**
|
||||
* Lookup a reference to one of the objects in a repository,
|
||||
* given a prefix of its identifier (short id).
|
||||
*
|
||||
* The object obtained will be so that its identifier
|
||||
* matches the first 'len' hexadecimal characters
|
||||
* (packets of 4 bits) of the given 'id'.
|
||||
* 'len' must be at least GIT_OID_MINPREFIXLEN, and
|
||||
* long enough to identify a unique object matching
|
||||
* the prefix; otherwise the method will fail.
|
||||
*
|
||||
* The generated reference is owned by the repository and
|
||||
* should be closed with the `git_object_free` method
|
||||
* instead of free'd manually.
|
||||
*
|
||||
* The 'type' parameter must match the type of the object
|
||||
* in the odb; the method will fail otherwise.
|
||||
* The special value 'GIT_OBJ_ANY' may be passed to let
|
||||
* the method guess the object's type.
|
||||
*
|
||||
* @param object_out pointer where to store the looked-up object
|
||||
* @param repo the repository to look up the object
|
||||
* @param id a short identifier for the object
|
||||
* @param len the length of the short identifier
|
||||
* @param type the type of the object
|
||||
* @return 0 or an error code
|
||||
*/
|
||||
GIT_EXTERN(int) git_object_lookup_prefix(
|
||||
git_object **object_out,
|
||||
git_repository *repo,
|
||||
const git_oid *id,
|
||||
size_t len,
|
||||
git_otype type);
|
||||
|
||||
/**
|
||||
* Get the id (SHA1) of a repository object
|
||||
*
|
||||
* @param obj the repository object
|
||||
* @return the SHA1 id
|
||||
*/
|
||||
GIT_EXTERN(const git_oid *) git_object_id(const git_object *obj);
|
||||
|
||||
/**
|
||||
* Get the object type of an object
|
||||
*
|
||||
* @param obj the repository object
|
||||
* @return the object's type
|
||||
*/
|
||||
GIT_EXTERN(git_otype) git_object_type(const git_object *obj);
|
||||
|
||||
/**
|
||||
* Get the repository that owns this object
|
||||
*
|
||||
* Freeing or calling `git_repository_close` on the
|
||||
* returned pointer will invalidate the actual object.
|
||||
*
|
||||
* Any other operation may be run on the repository without
|
||||
* affecting the object.
|
||||
*
|
||||
* @param obj the object
|
||||
* @return the repository who owns this object
|
||||
*/
|
||||
GIT_EXTERN(git_repository *) git_object_owner(const git_object *obj);
|
||||
|
||||
/**
|
||||
* Close an open object
|
||||
*
|
||||
* This method instructs the library to close an existing
|
||||
* object; note that git_objects are owned and cached by the repository
|
||||
* so the object may or may not be freed after this library call,
|
||||
* depending on how aggressive is the caching mechanism used
|
||||
* by the repository.
|
||||
*
|
||||
* IMPORTANT:
|
||||
* It *is* necessary to call this method when you stop using
|
||||
* an object. Failure to do so will cause a memory leak.
|
||||
*
|
||||
* @param object the object to close
|
||||
*/
|
||||
GIT_EXTERN(void) git_object_free(git_object *object);
|
||||
|
||||
/**
|
||||
* Convert an object type to it's string representation.
|
||||
*
|
||||
* The result is a pointer to a string in static memory and
|
||||
* should not be free()'ed.
|
||||
*
|
||||
* @param type object type to convert.
|
||||
* @return the corresponding string representation.
|
||||
*/
|
||||
GIT_EXTERN(const char *) git_object_type2string(git_otype type);
|
||||
|
||||
/**
|
||||
* Convert a string object type representation to it's git_otype.
|
||||
*
|
||||
* @param str the string to convert.
|
||||
* @return the corresponding git_otype.
|
||||
*/
|
||||
GIT_EXTERN(git_otype) git_object_string2type(const char *str);
|
||||
|
||||
/**
|
||||
* Determine if the given git_otype is a valid loose object type.
|
||||
*
|
||||
* @param type object type to test.
|
||||
* @return true if the type represents a valid loose object type,
|
||||
* false otherwise.
|
||||
*/
|
||||
GIT_EXTERN(int) git_object_typeisloose(git_otype type);
|
||||
|
||||
/**
|
||||
* Get the size in bytes for the structure which
|
||||
* acts as an in-memory representation of any given
|
||||
* object type.
|
||||
*
|
||||
* For all the core types, this would the equivalent
|
||||
* of calling `sizeof(git_commit)` if the core types
|
||||
* were not opaque on the external API.
|
||||
*
|
||||
* @param type object type to get its size
|
||||
* @return size in bytes of the object
|
||||
*/
|
||||
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 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).
|
||||
*
|
||||
* @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
|
||||
*/
|
||||
GIT_EXTERN(int) git_object_peel(
|
||||
git_object **peeled,
|
||||
const git_object *object,
|
||||
git_otype target_type);
|
||||
|
||||
/** @} */
|
||||
GIT_END_DECL
|
||||
|
||||
#endif
|
||||
@@ -1,391 +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_odb_h__
|
||||
#define INCLUDE_git_odb_h__
|
||||
|
||||
#include "common.h"
|
||||
#include "types.h"
|
||||
#include "oid.h"
|
||||
#include "odb_backend.h"
|
||||
#include "indexer.h"
|
||||
|
||||
/**
|
||||
* @file git2/odb.h
|
||||
* @brief Git object database routines
|
||||
* @defgroup git_odb Git object database routines
|
||||
* @ingroup Git
|
||||
* @{
|
||||
*/
|
||||
GIT_BEGIN_DECL
|
||||
|
||||
/**
|
||||
* Create a new object database with no backends.
|
||||
*
|
||||
* Before the ODB can be used for read/writing, a custom database
|
||||
* backend must be manually added using `git_odb_add_backend()`
|
||||
*
|
||||
* @param out location to store the database pointer, if opened.
|
||||
* Set to NULL if the open failed.
|
||||
* @return 0 or an error code
|
||||
*/
|
||||
GIT_EXTERN(int) git_odb_new(git_odb **out);
|
||||
|
||||
/**
|
||||
* Create a new object database and automatically add
|
||||
* the two default backends:
|
||||
*
|
||||
* - git_odb_backend_loose: read and write loose object files
|
||||
* from disk, assuming `objects_dir` as the Objects folder
|
||||
*
|
||||
* - git_odb_backend_pack: read objects from packfiles,
|
||||
* assuming `objects_dir` as the Objects folder which
|
||||
* contains a 'pack/' folder with the corresponding data
|
||||
*
|
||||
* @param out location to store the database pointer, if opened.
|
||||
* Set to NULL if the open failed.
|
||||
* @param objects_dir path of the backends' "objects" directory.
|
||||
* @return 0 or an error code
|
||||
*/
|
||||
GIT_EXTERN(int) git_odb_open(git_odb **out, const char *objects_dir);
|
||||
|
||||
/**
|
||||
* Add a custom backend to an existing Object DB
|
||||
*
|
||||
* The backends are checked in relative ordering, based on the
|
||||
* value of the `priority` parameter.
|
||||
*
|
||||
* Read <odb_backends.h> for more information.
|
||||
*
|
||||
* @param odb database to add the backend to
|
||||
* @param backend pointer to a git_odb_backend instance
|
||||
* @param priority Value for ordering the backends queue
|
||||
* @return 0 on success; error code otherwise
|
||||
*/
|
||||
GIT_EXTERN(int) git_odb_add_backend(git_odb *odb, git_odb_backend *backend, int priority);
|
||||
|
||||
/**
|
||||
* Add a custom backend to an existing Object DB; this
|
||||
* backend will work as an alternate.
|
||||
*
|
||||
* Alternate backends are always checked for objects *after*
|
||||
* all the main backends have been exhausted.
|
||||
*
|
||||
* The backends are checked in relative ordering, based on the
|
||||
* value of the `priority` parameter.
|
||||
*
|
||||
* Writing is disabled on alternate backends.
|
||||
*
|
||||
* Read <odb_backends.h> for more information.
|
||||
*
|
||||
* @param odb database to add the backend to
|
||||
* @param backend pointer to a git_odb_backend instance
|
||||
* @param priority Value for ordering the backends queue
|
||||
* @return 0 on success; error code otherwise
|
||||
*/
|
||||
GIT_EXTERN(int) git_odb_add_alternate(git_odb *odb, git_odb_backend *backend, int priority);
|
||||
|
||||
/**
|
||||
* Add an on-disk alternate to an existing Object DB.
|
||||
*
|
||||
* Note that the added path must point to an `objects`, not
|
||||
* to a full repository, to use it as an alternate store.
|
||||
*
|
||||
* Alternate backends are always checked for objects *after*
|
||||
* all the main backends have been exhausted.
|
||||
*
|
||||
* Writing is disabled on alternate backends.
|
||||
*
|
||||
* @param odb database to add the backend to
|
||||
* @param path path to the objects folder for the alternate
|
||||
* @return 0 on success; error code otherwise
|
||||
*/
|
||||
GIT_EXTERN(int) git_odb_add_disk_alternate(git_odb *odb, const char *path);
|
||||
|
||||
/**
|
||||
* Close an open object database.
|
||||
*
|
||||
* @param db database pointer to close. If NULL no action is taken.
|
||||
*/
|
||||
GIT_EXTERN(void) git_odb_free(git_odb *db);
|
||||
|
||||
/**
|
||||
* Read an object from the database.
|
||||
*
|
||||
* This method queries all available ODB backends
|
||||
* trying to read the given OID.
|
||||
*
|
||||
* The returned object is reference counted and
|
||||
* internally cached, so it should be closed
|
||||
* by the user once it's no longer in use.
|
||||
*
|
||||
* @param out pointer where to store the read object
|
||||
* @param db database to search for the object in.
|
||||
* @param id identity of the object to read.
|
||||
* @return
|
||||
* - 0 if the object was read;
|
||||
* - GIT_ENOTFOUND if the object is not in the database.
|
||||
*/
|
||||
GIT_EXTERN(int) git_odb_read(git_odb_object **out, git_odb *db, const git_oid *id);
|
||||
|
||||
/**
|
||||
* Read an object from the database, given a prefix
|
||||
* of its identifier.
|
||||
*
|
||||
* This method queries all available ODB backends
|
||||
* trying to match the 'len' first hexadecimal
|
||||
* characters of the 'short_id'.
|
||||
* The remaining (GIT_OID_HEXSZ-len)*4 bits of
|
||||
* 'short_id' must be 0s.
|
||||
* 'len' must be at least GIT_OID_MINPREFIXLEN,
|
||||
* and the prefix must be long enough to identify
|
||||
* a unique object in all the backends; the
|
||||
* method will fail otherwise.
|
||||
*
|
||||
* The returned object is reference counted and
|
||||
* internally cached, so it should be closed
|
||||
* by the user once it's no longer in use.
|
||||
*
|
||||
* @param out pointer where to store the read object
|
||||
* @param db database to search for the object in.
|
||||
* @param short_id a prefix of the id of the object to read.
|
||||
* @param len the length of the prefix
|
||||
* @return
|
||||
* - 0 if the object was read;
|
||||
* - GIT_ENOTFOUND if the object is not in the database.
|
||||
* - GIT_EAMBIGUOUS if the prefix is ambiguous (several objects match the prefix)
|
||||
*/
|
||||
GIT_EXTERN(int) git_odb_read_prefix(git_odb_object **out, git_odb *db, const git_oid *short_id, size_t len);
|
||||
|
||||
/**
|
||||
* Read the header of an object from the database, without
|
||||
* reading its full contents.
|
||||
*
|
||||
* The header includes the length and the type of an object.
|
||||
*
|
||||
* Note that most backends do not support reading only the header
|
||||
* of an object, so the whole object will be read and then the
|
||||
* header will be returned.
|
||||
*
|
||||
* @param len_out pointer where to store the length
|
||||
* @param type_out pointer where to store the type
|
||||
* @param db database to search for the object in.
|
||||
* @param id identity of the object to read.
|
||||
* @return
|
||||
* - 0 if the object was read;
|
||||
* - GIT_ENOTFOUND if the object is not in the database.
|
||||
*/
|
||||
GIT_EXTERN(int) git_odb_read_header(size_t *len_out, git_otype *type_out, git_odb *db, const git_oid *id);
|
||||
|
||||
/**
|
||||
* Determine if the given object can be found in the object database.
|
||||
*
|
||||
* @param db database to be searched for the given object.
|
||||
* @param id the object to search for.
|
||||
* @return
|
||||
* - 1, if the object was found
|
||||
* - 0, otherwise
|
||||
*/
|
||||
GIT_EXTERN(int) git_odb_exists(git_odb *db, const git_oid *id);
|
||||
|
||||
/**
|
||||
* List all objects available in the database
|
||||
*
|
||||
* The callback will be called for each object available in the
|
||||
* database. Note that the objects are likely to be returned in the index
|
||||
* order, which would make accessing the objects in that order inefficient.
|
||||
* Return a non-zero value from the callback to stop looping.
|
||||
*
|
||||
* @param db database to use
|
||||
* @param cb the callback to call for each object
|
||||
* @param payload data to pass to the callback
|
||||
* @return 0 on success, GIT_EUSER on non-zero callback, or error code
|
||||
*/
|
||||
GIT_EXTERN(int) git_odb_foreach(git_odb *db, git_odb_foreach_cb cb, void *payload);
|
||||
|
||||
/**
|
||||
* Write an object directly into the ODB
|
||||
*
|
||||
* This method writes a full object straight into the ODB.
|
||||
* For most cases, it is preferred to write objects through a write
|
||||
* stream, which is both faster and less memory intensive, specially
|
||||
* for big objects.
|
||||
*
|
||||
* This method is provided for compatibility with custom backends
|
||||
* which are not able to support streaming writes
|
||||
*
|
||||
* @param out pointer to store the OID result of the write
|
||||
* @param odb object database where to store the object
|
||||
* @param data buffer with the data to store
|
||||
* @param len size of the buffer
|
||||
* @param type type of the data to store
|
||||
* @return 0 or an error code
|
||||
*/
|
||||
GIT_EXTERN(int) git_odb_write(git_oid *out, git_odb *odb, const void *data, size_t len, git_otype type);
|
||||
|
||||
/**
|
||||
* Open a stream to write an object into the ODB
|
||||
*
|
||||
* The type and final length of the object must be specified
|
||||
* when opening the stream.
|
||||
*
|
||||
* The returned stream will be of type `GIT_STREAM_WRONLY` and
|
||||
* will have the following methods:
|
||||
*
|
||||
* - stream->write: write `n` bytes into the stream
|
||||
* - stream->finalize_write: close the stream and store the object in
|
||||
* the odb
|
||||
* - stream->free: free the stream
|
||||
*
|
||||
* The streaming write won't be effective until `stream->finalize_write`
|
||||
* is called and returns without an error
|
||||
*
|
||||
* The stream must always be free'd or will leak memory.
|
||||
*
|
||||
* @see git_odb_stream
|
||||
*
|
||||
* @param out pointer where to store the stream
|
||||
* @param db object database where the stream will write
|
||||
* @param size final size of the object that will be written
|
||||
* @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);
|
||||
|
||||
/**
|
||||
* Open a stream to read an object from the ODB
|
||||
*
|
||||
* Note that most backends do *not* support streaming reads
|
||||
* because they store their objects as compressed/delta'ed blobs.
|
||||
*
|
||||
* It's recommended to use `git_odb_read` instead, which is
|
||||
* assured to work on all backends.
|
||||
*
|
||||
* The returned stream will be of type `GIT_STREAM_RDONLY` and
|
||||
* will have the following methods:
|
||||
*
|
||||
* - stream->read: read `n` bytes from the stream
|
||||
* - stream->free: free the stream
|
||||
*
|
||||
* The stream must always be free'd or will leak memory.
|
||||
*
|
||||
* @see git_odb_stream
|
||||
*
|
||||
* @param out pointer where to store the stream
|
||||
* @param db object database where the stream will read from
|
||||
* @param oid oid of the object the stream will read from
|
||||
* @return 0 if the stream was created; error code otherwise
|
||||
*/
|
||||
GIT_EXTERN(int) git_odb_open_rstream(git_odb_stream **out, git_odb *db, const git_oid *oid);
|
||||
|
||||
/**
|
||||
* Open a stream for writing a pack file to the ODB.
|
||||
*
|
||||
* If the ODB layer understands pack files, then the given
|
||||
* packfile will likely be streamed directly to disk (and a
|
||||
* corresponding index created). If the ODB layer does not
|
||||
* understand pack files, the objects will be stored in whatever
|
||||
* format the ODB layer uses.
|
||||
*
|
||||
* @see git_odb_writepack
|
||||
*
|
||||
* @param out pointer to the writepack functions
|
||||
* @param db object database where the stream will read from
|
||||
* @param progress_cb function to call with progress information.
|
||||
* Be aware that this is called inline with network and indexing operations,
|
||||
* so performance may be affected.
|
||||
* @param progress_payload payload for the progress callback
|
||||
*/
|
||||
GIT_EXTERN(int) git_odb_write_pack(
|
||||
git_odb_writepack **out,
|
||||
git_odb *db,
|
||||
git_transfer_progress_callback progress_cb,
|
||||
void *progress_payload);
|
||||
|
||||
/**
|
||||
* Determine the object-ID (sha1 hash) of a data buffer
|
||||
*
|
||||
* The resulting SHA-1 OID will be the identifier for the data
|
||||
* buffer as if the data buffer it were to written to the ODB.
|
||||
*
|
||||
* @param out the resulting object-ID.
|
||||
* @param data data to hash
|
||||
* @param len size of the data
|
||||
* @param type of the data to hash
|
||||
* @return 0 or an error code
|
||||
*/
|
||||
GIT_EXTERN(int) git_odb_hash(git_oid *out, const void *data, size_t len, git_otype type);
|
||||
|
||||
/**
|
||||
* Read a file from disk and fill a git_oid with the object id
|
||||
* that the file would have if it were written to the Object
|
||||
* Database as an object of the given type (w/o applying filters).
|
||||
* Similar functionality to git.git's `git hash-object` without
|
||||
* the `-w` flag, however, with the --no-filters flag.
|
||||
* If you need filters, see git_repository_hashfile.
|
||||
*
|
||||
* @param out oid structure the result is written into.
|
||||
* @param path file to read and determine object id for
|
||||
* @param type the type of the object that will be hashed
|
||||
* @return 0 or an error code
|
||||
*/
|
||||
GIT_EXTERN(int) git_odb_hashfile(git_oid *out, const char *path, git_otype type);
|
||||
|
||||
/**
|
||||
* Close an ODB object
|
||||
*
|
||||
* This method must always be called once a `git_odb_object` is no
|
||||
* longer needed, otherwise memory will leak.
|
||||
*
|
||||
* @param object object to close
|
||||
*/
|
||||
GIT_EXTERN(void) git_odb_object_free(git_odb_object *object);
|
||||
|
||||
/**
|
||||
* Return the OID of an ODB object
|
||||
*
|
||||
* This is the OID from which the object was read from
|
||||
*
|
||||
* @param object the object
|
||||
* @return a pointer to the OID
|
||||
*/
|
||||
GIT_EXTERN(const git_oid *) git_odb_object_id(git_odb_object *object);
|
||||
|
||||
/**
|
||||
* Return the data of an ODB object
|
||||
*
|
||||
* This is the uncompressed, raw data as read from the ODB,
|
||||
* without the leading header.
|
||||
*
|
||||
* This pointer is owned by the object and shall not be free'd.
|
||||
*
|
||||
* @param object the object
|
||||
* @return a pointer to the data
|
||||
*/
|
||||
GIT_EXTERN(const void *) git_odb_object_data(git_odb_object *object);
|
||||
|
||||
/**
|
||||
* Return the size of an ODB object
|
||||
*
|
||||
* This is the real size of the `data` buffer, not the
|
||||
* actual size of the object.
|
||||
*
|
||||
* @param object the object
|
||||
* @return the size
|
||||
*/
|
||||
GIT_EXTERN(size_t) git_odb_object_size(git_odb_object *object);
|
||||
|
||||
/**
|
||||
* Return the type of an ODB object
|
||||
*
|
||||
* @param object the object
|
||||
* @return the type
|
||||
*/
|
||||
GIT_EXTERN(git_otype) git_odb_object_type(git_odb_object *object);
|
||||
|
||||
/** @} */
|
||||
GIT_END_DECL
|
||||
#endif
|
||||
@@ -1,147 +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_odb_backend_h__
|
||||
#define INCLUDE_git_odb_backend_h__
|
||||
|
||||
#include "common.h"
|
||||
#include "types.h"
|
||||
#include "oid.h"
|
||||
#include "indexer.h"
|
||||
|
||||
/**
|
||||
* @file git2/backend.h
|
||||
* @brief Git custom backend functions
|
||||
* @defgroup git_backend Git custom backend API
|
||||
* @ingroup Git
|
||||
* @{
|
||||
*/
|
||||
GIT_BEGIN_DECL
|
||||
|
||||
struct git_odb_stream;
|
||||
struct git_odb_writepack;
|
||||
|
||||
/**
|
||||
* Function type for callbacks from git_odb_foreach.
|
||||
*/
|
||||
typedef int (*git_odb_foreach_cb)(const git_oid *id, void *payload);
|
||||
|
||||
/**
|
||||
* An instance for a custom backend
|
||||
*/
|
||||
struct git_odb_backend {
|
||||
unsigned int version;
|
||||
git_odb *odb;
|
||||
|
||||
/* read and read_prefix each return to libgit2 a buffer which
|
||||
* will be freed later. The buffer should be allocated using
|
||||
* the function git_odb_backend_malloc to ensure that it can
|
||||
* be safely freed later. */
|
||||
int (* read)(
|
||||
void **, size_t *, git_otype *,
|
||||
struct git_odb_backend *,
|
||||
const git_oid *);
|
||||
|
||||
/* To find a unique object given a prefix
|
||||
* of its oid.
|
||||
* The oid given must be so that the
|
||||
* remaining (GIT_OID_HEXSZ - len)*4 bits
|
||||
* are 0s.
|
||||
*/
|
||||
int (* read_prefix)(
|
||||
git_oid *,
|
||||
void **, size_t *, git_otype *,
|
||||
struct git_odb_backend *,
|
||||
const git_oid *,
|
||||
size_t);
|
||||
|
||||
int (* read_header)(
|
||||
size_t *, git_otype *,
|
||||
struct git_odb_backend *,
|
||||
const git_oid *);
|
||||
|
||||
/* The writer may assume that the object
|
||||
* has already been hashed and is passed
|
||||
* in the first parameter.
|
||||
*/
|
||||
int (* write)(
|
||||
git_oid *,
|
||||
struct git_odb_backend *,
|
||||
const void *,
|
||||
size_t,
|
||||
git_otype);
|
||||
|
||||
int (* writestream)(
|
||||
struct git_odb_stream **,
|
||||
struct git_odb_backend *,
|
||||
size_t,
|
||||
git_otype);
|
||||
|
||||
int (* readstream)(
|
||||
struct git_odb_stream **,
|
||||
struct git_odb_backend *,
|
||||
const git_oid *);
|
||||
|
||||
int (* exists)(
|
||||
struct git_odb_backend *,
|
||||
const git_oid *);
|
||||
|
||||
int (* foreach)(
|
||||
struct git_odb_backend *,
|
||||
git_odb_foreach_cb cb,
|
||||
void *payload);
|
||||
|
||||
int (* writepack)(
|
||||
struct git_odb_writepack **,
|
||||
struct git_odb_backend *,
|
||||
git_transfer_progress_callback progress_cb,
|
||||
void *progress_payload);
|
||||
|
||||
void (* free)(struct git_odb_backend *);
|
||||
};
|
||||
|
||||
#define GIT_ODB_BACKEND_VERSION 1
|
||||
#define GIT_ODB_BACKEND_INIT {GIT_ODB_BACKEND_VERSION}
|
||||
|
||||
/** Streaming mode */
|
||||
enum {
|
||||
GIT_STREAM_RDONLY = (1 << 1),
|
||||
GIT_STREAM_WRONLY = (1 << 2),
|
||||
GIT_STREAM_RW = (GIT_STREAM_RDONLY | GIT_STREAM_WRONLY),
|
||||
};
|
||||
|
||||
/** A stream to read/write from a backend */
|
||||
struct git_odb_stream {
|
||||
struct git_odb_backend *backend;
|
||||
unsigned int mode;
|
||||
|
||||
int (*read)(struct git_odb_stream *stream, char *buffer, size_t len);
|
||||
int (*write)(struct git_odb_stream *stream, const char *buffer, size_t len);
|
||||
int (*finalize_write)(git_oid *oid_p, struct git_odb_stream *stream);
|
||||
void (*free)(struct git_odb_stream *stream);
|
||||
};
|
||||
|
||||
/** A stream to write a pack file to the ODB */
|
||||
struct git_odb_writepack {
|
||||
struct git_odb_backend *backend;
|
||||
|
||||
int (*add)(struct git_odb_writepack *writepack, const void *data, size_t size, git_transfer_progress *stats);
|
||||
int (*commit)(struct git_odb_writepack *writepack, git_transfer_progress *stats);
|
||||
void (*free)(struct git_odb_writepack *writepack);
|
||||
};
|
||||
|
||||
GIT_EXTERN(void *) git_odb_backend_malloc(git_odb_backend *backend, size_t len);
|
||||
|
||||
/**
|
||||
* Constructors for in-box ODB backends.
|
||||
*/
|
||||
GIT_EXTERN(int) git_odb_backend_pack(git_odb_backend **out, const char *objects_dir);
|
||||
GIT_EXTERN(int) git_odb_backend_loose(git_odb_backend **out, const char *objects_dir, int compression_level, int do_fsync);
|
||||
GIT_EXTERN(int) git_odb_backend_one_pack(git_odb_backend **out, const char *index_file);
|
||||
|
||||
GIT_END_DECL
|
||||
|
||||
#endif
|
||||
@@ -1,248 +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_oid_h__
|
||||
#define INCLUDE_git_oid_h__
|
||||
|
||||
#include "common.h"
|
||||
#include "types.h"
|
||||
|
||||
/**
|
||||
* @file git2/oid.h
|
||||
* @brief Git object id routines
|
||||
* @defgroup git_oid Git object id routines
|
||||
* @ingroup Git
|
||||
* @{
|
||||
*/
|
||||
GIT_BEGIN_DECL
|
||||
|
||||
/** Size (in bytes) of a raw/binary oid */
|
||||
#define GIT_OID_RAWSZ 20
|
||||
|
||||
/** Size (in bytes) of a hex formatted oid */
|
||||
#define GIT_OID_HEXSZ (GIT_OID_RAWSZ * 2)
|
||||
|
||||
/** Minimum length (in number of hex characters,
|
||||
* i.e. packets of 4 bits) of an oid prefix */
|
||||
#define GIT_OID_MINPREFIXLEN 4
|
||||
|
||||
/** Unique identity of any object (commit, tree, blob, tag). */
|
||||
typedef struct git_oid {
|
||||
/** raw binary formatted id */
|
||||
unsigned char id[GIT_OID_RAWSZ];
|
||||
} git_oid;
|
||||
|
||||
/**
|
||||
* Parse a hex formatted object id into a git_oid.
|
||||
*
|
||||
* @param out oid structure the result is written into.
|
||||
* @param str input hex string; must be pointing at the start of
|
||||
* the hex sequence and have at least the number of bytes
|
||||
* needed for an oid encoded in hex (40 bytes).
|
||||
* @return 0 or an error code
|
||||
*/
|
||||
GIT_EXTERN(int) git_oid_fromstr(git_oid *out, const char *str);
|
||||
|
||||
/**
|
||||
* Parse N characters of a hex formatted object id into a git_oid
|
||||
*
|
||||
* If N is odd, N-1 characters will be parsed instead.
|
||||
* The remaining space in the git_oid will be set to zero.
|
||||
*
|
||||
* @param out oid structure the result is written into.
|
||||
* @param str input hex string of at least size `length`
|
||||
* @param length length of the input string
|
||||
* @return 0 or an error code
|
||||
*/
|
||||
GIT_EXTERN(int) git_oid_fromstrn(git_oid *out, const char *str, size_t length);
|
||||
|
||||
/**
|
||||
* Copy an already raw oid into a git_oid structure.
|
||||
*
|
||||
* @param out oid structure the result is written into.
|
||||
* @param raw the raw input bytes to be copied.
|
||||
*/
|
||||
GIT_EXTERN(void) git_oid_fromraw(git_oid *out, const unsigned char *raw);
|
||||
|
||||
/**
|
||||
* Format a git_oid into a hex string.
|
||||
*
|
||||
* @param out output hex string; must be pointing at the start of
|
||||
* the hex sequence and have at least the number of bytes
|
||||
* needed for an oid encoded in hex (40 bytes). Only the
|
||||
* oid digits are written; a '\\0' terminator must be added
|
||||
* by the caller if it is required.
|
||||
* @param oid oid structure to format.
|
||||
*/
|
||||
GIT_EXTERN(void) git_oid_fmt(char *out, const git_oid *id);
|
||||
|
||||
/**
|
||||
* Format a git_oid into a loose-object path string.
|
||||
*
|
||||
* The resulting string is "aa/...", where "aa" is the first two
|
||||
* hex digits of the oid and "..." is the remaining 38 digits.
|
||||
*
|
||||
* @param out output hex string; must be pointing at the start of
|
||||
* the hex sequence and have at least the number of bytes
|
||||
* needed for an oid encoded in hex (41 bytes). Only the
|
||||
* oid digits are written; a '\\0' terminator must be added
|
||||
* by the caller if it is required.
|
||||
* @param id oid structure to format.
|
||||
*/
|
||||
GIT_EXTERN(void) git_oid_pathfmt(char *out, const git_oid *id);
|
||||
|
||||
/**
|
||||
* Format a git_oid into a newly allocated c-string.
|
||||
*
|
||||
* @param oid the oid structure to format
|
||||
* @return the c-string; NULL if memory is exhausted. Caller must
|
||||
* deallocate the string with git__free().
|
||||
*/
|
||||
GIT_EXTERN(char *) git_oid_allocfmt(const git_oid *id);
|
||||
|
||||
/**
|
||||
* Format a git_oid into a buffer as a hex format c-string.
|
||||
*
|
||||
* If the buffer is smaller than GIT_OID_HEXSZ+1, then the resulting
|
||||
* oid c-string will be truncated to n-1 characters. If there are
|
||||
* any input parameter errors (out == NULL, n == 0, oid == NULL),
|
||||
* then a pointer to an empty string is returned, so that the return
|
||||
* value can always be printed.
|
||||
*
|
||||
* @param out the buffer into which the oid string is output.
|
||||
* @param n the size of the out buffer.
|
||||
* @param id the oid structure to format.
|
||||
* @return the out buffer pointer, assuming no input parameter
|
||||
* errors, otherwise a pointer to an empty string.
|
||||
*/
|
||||
GIT_EXTERN(char *) git_oid_tostr(char *out, size_t n, const git_oid *id);
|
||||
|
||||
/**
|
||||
* Copy an oid from one structure to another.
|
||||
*
|
||||
* @param out oid structure the result is written into.
|
||||
* @param src oid structure to copy from.
|
||||
*/
|
||||
GIT_EXTERN(void) git_oid_cpy(git_oid *out, const git_oid *src);
|
||||
|
||||
/**
|
||||
* Compare two oid structures.
|
||||
*
|
||||
* @param a first oid structure.
|
||||
* @param b second oid structure.
|
||||
* @return <0, 0, >0 if a < b, a == b, a > b.
|
||||
*/
|
||||
GIT_INLINE(int) git_oid_cmp(const git_oid *a, const git_oid *b)
|
||||
{
|
||||
const unsigned char *sha1 = a->id;
|
||||
const unsigned char *sha2 = b->id;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < GIT_OID_RAWSZ; i++, sha1++, sha2++) {
|
||||
if (*sha1 != *sha2)
|
||||
return *sha1 - *sha2;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare two oid structures for equality
|
||||
*
|
||||
* @param a first oid structure.
|
||||
* @param b second oid structure.
|
||||
* @return true if equal, false otherwise
|
||||
*/
|
||||
GIT_INLINE(int) git_oid_equal(const git_oid *a, const git_oid *b)
|
||||
{
|
||||
return !git_oid_cmp(a, b);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare the first 'len' hexadecimal characters (packets of 4 bits)
|
||||
* of two oid structures.
|
||||
*
|
||||
* @param a first oid structure.
|
||||
* @param b second oid structure.
|
||||
* @param len the number of hex chars to compare
|
||||
* @return 0 in case of a match
|
||||
*/
|
||||
GIT_EXTERN(int) git_oid_ncmp(const git_oid *a, const git_oid *b, size_t len);
|
||||
|
||||
/**
|
||||
* Check if an oid equals an hex formatted object id.
|
||||
*
|
||||
* @param id oid structure.
|
||||
* @param str input hex string of an object id.
|
||||
* @return GIT_ENOTOID if str is not a valid hex string,
|
||||
* 0 in case of a match, GIT_ERROR otherwise.
|
||||
*/
|
||||
GIT_EXTERN(int) git_oid_streq(const git_oid *id, const char *str);
|
||||
|
||||
/**
|
||||
* Check is an oid is all zeros.
|
||||
*
|
||||
* @return 1 if all zeros, 0 otherwise.
|
||||
*/
|
||||
GIT_EXTERN(int) git_oid_iszero(const git_oid *id);
|
||||
|
||||
/**
|
||||
* OID Shortener object
|
||||
*/
|
||||
typedef struct git_oid_shorten git_oid_shorten;
|
||||
|
||||
/**
|
||||
* Create a new OID shortener.
|
||||
*
|
||||
* The OID shortener is used to process a list of OIDs
|
||||
* in text form and return the shortest length that would
|
||||
* uniquely identify all of them.
|
||||
*
|
||||
* E.g. look at the result of `git log --abbrev`.
|
||||
*
|
||||
* @param min_length The minimal length for all identifiers,
|
||||
* which will be used even if shorter OIDs would still
|
||||
* be unique.
|
||||
* @return a `git_oid_shorten` instance, NULL if OOM
|
||||
*/
|
||||
GIT_EXTERN(git_oid_shorten *) git_oid_shorten_new(size_t min_length);
|
||||
|
||||
/**
|
||||
* Add a new OID to set of shortened OIDs and calculate
|
||||
* the minimal length to uniquely identify all the OIDs in
|
||||
* the set.
|
||||
*
|
||||
* The OID is expected to be a 40-char hexadecimal string.
|
||||
* The OID is owned by the user and will not be modified
|
||||
* or freed.
|
||||
*
|
||||
* For performance reasons, there is a hard-limit of how many
|
||||
* OIDs can be added to a single set (around ~22000, assuming
|
||||
* a mostly randomized distribution), which should be enough
|
||||
* for any kind of program, and keeps the algorithm fast and
|
||||
* memory-efficient.
|
||||
*
|
||||
* Attempting to add more than those OIDs will result in a
|
||||
* GIT_ENOMEM error
|
||||
*
|
||||
* @param os a `git_oid_shorten` instance
|
||||
* @param text_id an OID in text form
|
||||
* @return the minimal length to uniquely identify all OIDs
|
||||
* added so far to the set; or an error code (<0) if an
|
||||
* error occurs.
|
||||
*/
|
||||
GIT_EXTERN(int) git_oid_shorten_add(git_oid_shorten *os, const char *text_id);
|
||||
|
||||
/**
|
||||
* Free an OID shortener instance
|
||||
*
|
||||
* @param os a `git_oid_shorten` instance
|
||||
*/
|
||||
GIT_EXTERN(void) git_oid_shorten_free(git_oid_shorten *os);
|
||||
|
||||
/** @} */
|
||||
GIT_END_DECL
|
||||
#endif
|
||||
@@ -1,117 +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_pack_h__
|
||||
#define INCLUDE_git_pack_h__
|
||||
|
||||
#include "common.h"
|
||||
#include "oid.h"
|
||||
|
||||
/**
|
||||
* @file git2/pack.h
|
||||
* @brief Git pack management routines
|
||||
* @defgroup git_pack Git pack management routines
|
||||
* @ingroup Git
|
||||
* @{
|
||||
*/
|
||||
GIT_BEGIN_DECL
|
||||
|
||||
/**
|
||||
* Initialize a new packbuilder
|
||||
*
|
||||
* @param out The new packbuilder object
|
||||
* @param repo The repository
|
||||
*
|
||||
* @return 0 or an error code
|
||||
*/
|
||||
GIT_EXTERN(int) git_packbuilder_new(git_packbuilder **out, git_repository *repo);
|
||||
|
||||
/**
|
||||
* Set number of threads to spawn
|
||||
*
|
||||
* By default, libgit2 won't spawn any threads at all;
|
||||
* when set to 0, libgit2 will autodetect the number of
|
||||
* CPUs.
|
||||
*
|
||||
* @param pb The packbuilder
|
||||
* @param n Number of threads to spawn
|
||||
* @return number of actual threads to be used
|
||||
*/
|
||||
GIT_EXTERN(unsigned int) git_packbuilder_set_threads(git_packbuilder *pb, unsigned int n);
|
||||
|
||||
/**
|
||||
* Insert a single object
|
||||
*
|
||||
* For an optimal pack it's mandatory to insert objects in recency order,
|
||||
* commits followed by trees and blobs.
|
||||
*
|
||||
* @param pb The packbuilder
|
||||
* @param id The oid of the commit
|
||||
* @param name The name; might be NULL
|
||||
*
|
||||
* @return 0 or an error code
|
||||
*/
|
||||
GIT_EXTERN(int) git_packbuilder_insert(git_packbuilder *pb, const git_oid *id, const char *name);
|
||||
|
||||
/**
|
||||
* Insert a root tree object
|
||||
*
|
||||
* This will add the tree as well as all referenced trees and blobs.
|
||||
*
|
||||
* @param pb The packbuilder
|
||||
* @param id The oid of the root tree
|
||||
*
|
||||
* @return 0 or an error code
|
||||
*/
|
||||
GIT_EXTERN(int) git_packbuilder_insert_tree(git_packbuilder *pb, const git_oid *id);
|
||||
|
||||
/**
|
||||
* Write the new pack and the corresponding index to path
|
||||
*
|
||||
* @param pb The packbuilder
|
||||
* @param path Directory to store the new pack and index
|
||||
*
|
||||
* @return 0 or an error code
|
||||
*/
|
||||
GIT_EXTERN(int) git_packbuilder_write(git_packbuilder *pb, const char *file);
|
||||
|
||||
/**
|
||||
* Create the new pack and pass each object to the callback
|
||||
*
|
||||
* @param pb the packbuilder
|
||||
* @param cb the callback to call with each packed object's buffer
|
||||
* @param payload the callback's data
|
||||
* @return 0 or an error code
|
||||
*/
|
||||
typedef int (*git_packbuilder_foreach_cb)(void *buf, size_t size, void *payload);
|
||||
GIT_EXTERN(int) git_packbuilder_foreach(git_packbuilder *pb, git_packbuilder_foreach_cb cb, void *payload);
|
||||
|
||||
/**
|
||||
* Get the total number of objects the packbuilder will write out
|
||||
*
|
||||
* @param pb the packbuilder
|
||||
* @return
|
||||
*/
|
||||
GIT_EXTERN(uint32_t) git_packbuilder_object_count(git_packbuilder *pb);
|
||||
|
||||
/**
|
||||
* Get the number of objects the packbuilder has already written out
|
||||
*
|
||||
* @param pb the packbuilder
|
||||
* @return
|
||||
*/
|
||||
GIT_EXTERN(uint32_t) git_packbuilder_written(git_packbuilder *pb);
|
||||
|
||||
/**
|
||||
* Free the packbuilder and all associated data
|
||||
*
|
||||
* @param pb The packbuilder
|
||||
*/
|
||||
GIT_EXTERN(void) git_packbuilder_free(git_packbuilder *pb);
|
||||
|
||||
/** @} */
|
||||
GIT_END_DECL
|
||||
#endif
|
||||
@@ -1,80 +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"
|
||||
|
||||
/**
|
||||
* @file git2/push.h
|
||||
* @brief Git push management functions
|
||||
* @defgroup git_push push management functions
|
||||
* @ingroup Git
|
||||
* @{
|
||||
*/
|
||||
GIT_BEGIN_DECL
|
||||
|
||||
/**
|
||||
* 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);
|
||||
|
||||
/**
|
||||
* 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);
|
||||
|
||||
/**
|
||||
* Actually push all given refspecs
|
||||
*
|
||||
* @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 equal, false otherwise
|
||||
*/
|
||||
GIT_EXTERN(int) git_push_unpack_ok(git_push *push);
|
||||
|
||||
/**
|
||||
* Call callback `cb' on each status
|
||||
*
|
||||
* @param push The push object
|
||||
* @param cb The callback to call on each object
|
||||
*
|
||||
* @return 0 on success, GIT_EUSER on non-zero callback, 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
|
||||
@@ -1,167 +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_reflog_h__
|
||||
#define INCLUDE_git_reflog_h__
|
||||
|
||||
#include "common.h"
|
||||
#include "types.h"
|
||||
#include "oid.h"
|
||||
|
||||
/**
|
||||
* @file git2/reflog.h
|
||||
* @brief Git reflog management routines
|
||||
* @defgroup git_reflog Git reflog management routines
|
||||
* @ingroup Git
|
||||
* @{
|
||||
*/
|
||||
GIT_BEGIN_DECL
|
||||
|
||||
/**
|
||||
* Read the reflog for the given reference
|
||||
*
|
||||
* If there is no reflog file for the given
|
||||
* reference yet, an empty reflog object will
|
||||
* be returned.
|
||||
*
|
||||
* The reflog must be freed manually by using
|
||||
* git_reflog_free().
|
||||
*
|
||||
* @param out pointer to reflog
|
||||
* @param ref reference to read the reflog for
|
||||
* @return 0 or an error code
|
||||
*/
|
||||
GIT_EXTERN(int) git_reflog_read(git_reflog **out, const git_reference *ref);
|
||||
|
||||
/**
|
||||
* Write an existing in-memory reflog object back to disk
|
||||
* using an atomic file lock.
|
||||
*
|
||||
* @param reflog an existing reflog object
|
||||
* @return 0 or an error code
|
||||
*/
|
||||
GIT_EXTERN(int) git_reflog_write(git_reflog *reflog);
|
||||
|
||||
/**
|
||||
* Add a new entry to the reflog.
|
||||
*
|
||||
* `msg` is optional and can be NULL.
|
||||
*
|
||||
* @param reflog an existing reflog object
|
||||
* @param id the OID the reference is now pointing to
|
||||
* @param committer the signature of the committer
|
||||
* @param msg the reflog message
|
||||
* @return 0 or an error code
|
||||
*/
|
||||
GIT_EXTERN(int) git_reflog_append(git_reflog *reflog, const git_oid *id, const git_signature *committer, const char *msg);
|
||||
|
||||
/**
|
||||
* Rename the reflog for the given reference
|
||||
*
|
||||
* The reflog to be renamed is expected to already exist
|
||||
*
|
||||
* The new name will be checked for validity.
|
||||
* See `git_reference_create_symbolic()` for rules about valid names.
|
||||
*
|
||||
* @param ref the reference
|
||||
* @param name the new name of the reference
|
||||
* @return 0 on success, GIT_EINVALIDSPEC or an error code
|
||||
*/
|
||||
GIT_EXTERN(int) git_reflog_rename(git_reference *ref, const char *name);
|
||||
|
||||
/**
|
||||
* Delete the reflog for the given reference
|
||||
*
|
||||
* @param ref the reference
|
||||
* @return 0 or an error code
|
||||
*/
|
||||
GIT_EXTERN(int) git_reflog_delete(git_reference *ref);
|
||||
|
||||
/**
|
||||
* Get the number of log entries in a reflog
|
||||
*
|
||||
* @param reflog the previously loaded reflog
|
||||
* @return the number of log entries
|
||||
*/
|
||||
GIT_EXTERN(size_t) git_reflog_entrycount(git_reflog *reflog);
|
||||
|
||||
/**
|
||||
* Lookup an entry by its index
|
||||
*
|
||||
* Requesting the reflog entry with an index of 0 (zero) will
|
||||
* return the most recently created entry.
|
||||
*
|
||||
* @param reflog a previously loaded reflog
|
||||
* @param idx the position of the entry to lookup. Should be greater than or
|
||||
* 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);
|
||||
|
||||
/**
|
||||
* Remove an entry from the reflog by its index
|
||||
*
|
||||
* To ensure there's no gap in the log history, set `rewrite_previous_entry`
|
||||
* param value to 1. When deleting entry `n`, member old_oid of entry `n-1`
|
||||
* (if any) will be updated with the value of member new_oid of entry `n+1`.
|
||||
*
|
||||
* @param reflog a previously loaded reflog.
|
||||
*
|
||||
* @param idx the position of the entry to remove. Should be greater than or
|
||||
* equal to 0 (zero) and less than `git_reflog_entrycount()`.
|
||||
*
|
||||
* @param rewrite_previous_entry 1 to rewrite the history; 0 otherwise.
|
||||
*
|
||||
* @return 0 on success, GIT_ENOTFOUND if the entry doesn't exist
|
||||
* or an error code.
|
||||
*/
|
||||
GIT_EXTERN(int) git_reflog_drop(
|
||||
git_reflog *reflog,
|
||||
size_t idx,
|
||||
int rewrite_previous_entry);
|
||||
|
||||
/**
|
||||
* Get the old oid
|
||||
*
|
||||
* @param entry a reflog entry
|
||||
* @return the old oid
|
||||
*/
|
||||
GIT_EXTERN(const git_oid *) git_reflog_entry_id_old(const git_reflog_entry *entry);
|
||||
|
||||
/**
|
||||
* Get the new oid
|
||||
*
|
||||
* @param entry a reflog entry
|
||||
* @return the new oid at this time
|
||||
*/
|
||||
GIT_EXTERN(const git_oid *) git_reflog_entry_id_new(const git_reflog_entry *entry);
|
||||
|
||||
/**
|
||||
* Get the committer of this entry
|
||||
*
|
||||
* @param entry a reflog entry
|
||||
* @return the committer
|
||||
*/
|
||||
GIT_EXTERN(const git_signature *) git_reflog_entry_committer(const git_reflog_entry *entry);
|
||||
|
||||
/**
|
||||
* Get the log message
|
||||
*
|
||||
* @param entry a reflog entry
|
||||
* @return the log msg
|
||||
*/
|
||||
GIT_EXTERN(const char *) git_reflog_entry_message(const git_reflog_entry *entry);
|
||||
|
||||
/**
|
||||
* Free the reflog
|
||||
*
|
||||
* @param reflog reflog to free
|
||||
*/
|
||||
GIT_EXTERN(void) git_reflog_free(git_reflog *reflog);
|
||||
|
||||
/** @} */
|
||||
GIT_END_DECL
|
||||
#endif
|
||||
@@ -1,509 +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_refs_h__
|
||||
#define INCLUDE_git_refs_h__
|
||||
|
||||
#include "common.h"
|
||||
#include "types.h"
|
||||
#include "oid.h"
|
||||
#include "strarray.h"
|
||||
|
||||
/**
|
||||
* @file git2/refs.h
|
||||
* @brief Git reference management routines
|
||||
* @defgroup git_reference Git reference management routines
|
||||
* @ingroup Git
|
||||
* @{
|
||||
*/
|
||||
GIT_BEGIN_DECL
|
||||
|
||||
/**
|
||||
* Lookup a reference by name in a repository.
|
||||
*
|
||||
* The returned reference must be freed by the user.
|
||||
*
|
||||
* The name will be checked for validity.
|
||||
* See `git_reference_create_symbolic()` for rules about valid names.
|
||||
*
|
||||
* @param out pointer to the looked-up reference
|
||||
* @param repo the repository to look up the reference
|
||||
* @param name the long name for the reference (e.g. HEAD, refs/heads/master, refs/tags/v0.1.0, ...)
|
||||
* @return 0 on success, ENOTFOUND, EINVALIDSPEC or an error code.
|
||||
*/
|
||||
GIT_EXTERN(int) git_reference_lookup(git_reference **out, git_repository *repo, const char *name);
|
||||
|
||||
/**
|
||||
* Lookup a reference by name and resolve immediately to OID.
|
||||
*
|
||||
* This function provides a quick way to resolve a reference name straight
|
||||
* through to the object id that it refers to. This avoids having to
|
||||
* allocate or free any `git_reference` objects for simple situations.
|
||||
*
|
||||
* The name will be checked for validity.
|
||||
* See `git_reference_create_symbolic()` for rules about valid names.
|
||||
*
|
||||
* @param out Pointer to oid to be filled in
|
||||
* @param repo The repository in which to look up the reference
|
||||
* @param name The long name for the reference
|
||||
* @return 0 on success, ENOTFOUND, EINVALIDSPEC or an error code.
|
||||
*/
|
||||
GIT_EXTERN(int) git_reference_name_to_id(
|
||||
git_oid *out, git_repository *repo, const char *name);
|
||||
|
||||
/**
|
||||
* Create a new symbolic reference.
|
||||
*
|
||||
* A symbolic reference is a reference name that refers to another
|
||||
* reference name. If the other name moves, the symbolic name will move,
|
||||
* too. As a simple example, the "HEAD" reference might refer to
|
||||
* "refs/heads/master" while on the "master" branch of a repository.
|
||||
*
|
||||
* The symbolic reference will be created in the repository and written to
|
||||
* the disk. The generated reference object must be freed by the user.
|
||||
*
|
||||
* Valid reference names must follow one of two patterns:
|
||||
*
|
||||
* 1. Top-level names must contain only capital letters and underscores,
|
||||
* and must begin and end with a letter. (e.g. "HEAD", "ORIG_HEAD").
|
||||
* 2. Names prefixed with "refs/" can be almost anything. You must avoid
|
||||
* the characters '~', '^', ':', '\\', '?', '[', and '*', and the
|
||||
* sequences ".." and "@{" which have special meaning to revparse.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* @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
|
||||
* @return 0 on success, EEXISTS, 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);
|
||||
|
||||
/**
|
||||
* Create a new direct reference.
|
||||
*
|
||||
* A direct reference (also called an object id reference) refers directly
|
||||
* to a specific object id (a.k.a. OID or SHA) in the repository. The id
|
||||
* permanently refers to the object (although the reference itself can be
|
||||
* moved). For example, in libgit2 the direct ref "refs/tags/v0.17.0"
|
||||
* refers to OID 5b9fac39d8a76b9139667c26a63e6b3f204b3977.
|
||||
*
|
||||
* The direct reference will be created in the repository and written to
|
||||
* the disk. The generated reference object must be freed by the user.
|
||||
*
|
||||
* Valid reference names must follow one of two patterns:
|
||||
*
|
||||
* 1. Top-level names must contain only capital letters and underscores,
|
||||
* and must begin and end with a letter. (e.g. "HEAD", "ORIG_HEAD").
|
||||
* 2. Names prefixed with "refs/" can be almost anything. You must avoid
|
||||
* the characters '~', '^', ':', '\\', '?', '[', and '*', and the
|
||||
* sequences ".." and "@{" which have special meaning to revparse.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* @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
|
||||
* @return 0 on success, EEXISTS, 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);
|
||||
|
||||
/**
|
||||
* Get the OID pointed to by a direct reference.
|
||||
*
|
||||
* Only available if the reference is direct (i.e. an object id reference,
|
||||
* not a symbolic one).
|
||||
*
|
||||
* To find the OID of a symbolic ref, call `git_reference_resolve()` and
|
||||
* then this function (or maybe use `git_reference_name_to_oid()` to
|
||||
* directly resolve a reference name all the way through to an OID).
|
||||
*
|
||||
* @param ref The reference
|
||||
* @return a pointer to the oid if available, NULL otherwise
|
||||
*/
|
||||
GIT_EXTERN(const git_oid *) git_reference_target(const git_reference *ref);
|
||||
|
||||
/**
|
||||
* Get full name to the reference pointed to by a symbolic reference.
|
||||
*
|
||||
* Only available if the reference is symbolic.
|
||||
*
|
||||
* @param ref The reference
|
||||
* @return a pointer to the name if available, NULL otherwise
|
||||
*/
|
||||
GIT_EXTERN(const char *) git_reference_symbolic_target(const git_reference *ref);
|
||||
|
||||
/**
|
||||
* Get the type of a reference.
|
||||
*
|
||||
* Either direct (GIT_REF_OID) or symbolic (GIT_REF_SYMBOLIC)
|
||||
*
|
||||
* @param ref The reference
|
||||
* @return the type
|
||||
*/
|
||||
GIT_EXTERN(git_ref_t) git_reference_type(const git_reference *ref);
|
||||
|
||||
/**
|
||||
* Get the full name of a reference.
|
||||
*
|
||||
* See `git_reference_create_symbolic()` for rules about valid names.
|
||||
*
|
||||
* @param ref The reference
|
||||
* @return the full name for the ref
|
||||
*/
|
||||
GIT_EXTERN(const char *) git_reference_name(const git_reference *ref);
|
||||
|
||||
/**
|
||||
* Resolve a symbolic reference to a direct reference.
|
||||
*
|
||||
* This method iteratively peels a symbolic reference until it resolves to
|
||||
* a direct reference to an OID.
|
||||
*
|
||||
* The peeled reference is returned in the `resolved_ref` argument, and
|
||||
* must be freed manually once it's no longer needed.
|
||||
*
|
||||
* If a direct reference is passed as an argument, a copy of that
|
||||
* reference is returned. This copy must be manually freed too.
|
||||
*
|
||||
* @param resolved_ref Pointer to the peeled reference
|
||||
* @param ref The reference
|
||||
* @return 0 or an error code
|
||||
*/
|
||||
GIT_EXTERN(int) git_reference_resolve(git_reference **out, const git_reference *ref);
|
||||
|
||||
/**
|
||||
* Get the repository where a reference resides.
|
||||
*
|
||||
* @param ref The reference
|
||||
* @return a pointer to the repo
|
||||
*/
|
||||
GIT_EXTERN(git_repository *) git_reference_owner(const git_reference *ref);
|
||||
|
||||
/**
|
||||
* Set the symbolic target of a reference.
|
||||
*
|
||||
* The reference must be a symbolic reference, otherwise this will fail.
|
||||
*
|
||||
* The reference will be automatically updated in memory and on disk.
|
||||
*
|
||||
* The target name will be checked for validity.
|
||||
* See `git_reference_create_symbolic()` for rules about valid names.
|
||||
*
|
||||
* @param ref The reference
|
||||
* @param target The new target for the reference
|
||||
* @return 0 on success, EINVALIDSPEC or an error code
|
||||
*/
|
||||
GIT_EXTERN(int) git_reference_symbolic_set_target(git_reference *ref, const char *target);
|
||||
|
||||
/**
|
||||
* Set the OID target of a reference.
|
||||
*
|
||||
* The reference must be a direct reference, otherwise this will fail.
|
||||
*
|
||||
* The reference will be automatically updated in memory and on disk.
|
||||
*
|
||||
* @param ref The reference
|
||||
* @param id The new target OID for the reference
|
||||
* @return 0 or an error code
|
||||
*/
|
||||
GIT_EXTERN(int) git_reference_set_target(git_reference *ref, const git_oid *id);
|
||||
|
||||
/**
|
||||
* Rename an existing reference.
|
||||
*
|
||||
* This method works for both direct and symbolic references.
|
||||
*
|
||||
* The new name will be checked for validity.
|
||||
* See `git_reference_create_symbolic()` for rules about valid names.
|
||||
*
|
||||
* The given git_reference will be updated in place.
|
||||
*
|
||||
* The reference will be immediately renamed in-memory and on disk.
|
||||
*
|
||||
* If the `force` flag is not enabled, and there's already
|
||||
* a reference with the given name, the renaming will fail.
|
||||
*
|
||||
* IMPORTANT:
|
||||
* The user needs to write a proper reflog entry if the
|
||||
* reflog is enabled for the repository. We only rename
|
||||
* the reflog if it exists.
|
||||
*
|
||||
* @param ref The reference to rename
|
||||
* @param name The new name for the reference
|
||||
* @param force Overwrite an existing reference
|
||||
* @return 0 on success, EINVALIDSPEC, EEXISTS or an error code
|
||||
*
|
||||
*/
|
||||
GIT_EXTERN(int) git_reference_rename(git_reference *ref, const char *name, int force);
|
||||
|
||||
/**
|
||||
* Delete an existing reference.
|
||||
*
|
||||
* This method works for both direct and symbolic references.
|
||||
*
|
||||
* The reference will be immediately removed on disk and from memory
|
||||
* (i.e. freed). The given reference pointer will no longer be valid.
|
||||
*
|
||||
* @param ref The reference to remove
|
||||
* @return 0 or an error code
|
||||
*/
|
||||
GIT_EXTERN(int) git_reference_delete(git_reference *ref);
|
||||
|
||||
/**
|
||||
* Pack all the loose references in the repository.
|
||||
*
|
||||
* This method will load into the cache all the loose
|
||||
* references on the repository and update the
|
||||
* `packed-refs` file with them.
|
||||
*
|
||||
* Once the `packed-refs` file has been written properly,
|
||||
* the loose references will be removed from disk.
|
||||
*
|
||||
* @param repo Repository where the loose refs will be packed
|
||||
* @return 0 or an error code
|
||||
*/
|
||||
GIT_EXTERN(int) git_reference_packall(git_repository *repo);
|
||||
|
||||
/**
|
||||
* Fill a list with all the references that can be found in a repository.
|
||||
*
|
||||
* Using the `list_flags` parameter, the listed references may be filtered
|
||||
* by type (`GIT_REF_OID` or `GIT_REF_SYMBOLIC`) or using a bitwise OR of
|
||||
* `git_ref_t` values. To include packed refs, include `GIT_REF_PACKED`.
|
||||
* For convenience, use the value `GIT_REF_LISTALL` to obtain all
|
||||
* references, including packed ones.
|
||||
*
|
||||
* The string array will be filled with the names of all references; these
|
||||
* values are owned by the user and should be free'd manually when no
|
||||
* longer needed, using `git_strarray_free()`.
|
||||
*
|
||||
* @param array Pointer to a git_strarray structure where
|
||||
* the reference names will be stored
|
||||
* @param repo Repository where to find the refs
|
||||
* @param list_flags Filtering flags for the reference listing
|
||||
* @return 0 or an error code
|
||||
*/
|
||||
GIT_EXTERN(int) git_reference_list(git_strarray *array, git_repository *repo, unsigned int list_flags);
|
||||
|
||||
typedef int (*git_reference_foreach_cb)(const char *refname, void *payload);
|
||||
|
||||
/**
|
||||
* Perform a callback on each reference in the repository.
|
||||
*
|
||||
* Using the `list_flags` parameter, the references may be filtered by
|
||||
* type (`GIT_REF_OID` or `GIT_REF_SYMBOLIC`) or using a bitwise OR of
|
||||
* `git_ref_t` values. To include packed refs, include `GIT_REF_PACKED`.
|
||||
* For convenience, use the value `GIT_REF_LISTALL` to obtain all
|
||||
* references, including packed ones.
|
||||
*
|
||||
* The `callback` function will be called for each reference in the
|
||||
* repository, receiving the name of the reference and the `payload` value
|
||||
* passed to this method. Returning a non-zero value from the callback
|
||||
* will terminate the iteration.
|
||||
*
|
||||
* @param repo Repository where to find the refs
|
||||
* @param list_flags Filtering flags for the reference listing.
|
||||
* @param callback Function which will be called for every listed ref
|
||||
* @param payload Additional data to pass to the callback
|
||||
* @return 0 on success, GIT_EUSER on non-zero callback, or error code
|
||||
*/
|
||||
GIT_EXTERN(int) git_reference_foreach(
|
||||
git_repository *repo,
|
||||
unsigned int list_flags,
|
||||
git_reference_foreach_cb callback,
|
||||
void *payload);
|
||||
|
||||
/**
|
||||
* Check if a reference has been loaded from a packfile.
|
||||
*
|
||||
* @param ref A git reference
|
||||
* @return 0 in case it's not packed; 1 otherwise
|
||||
*/
|
||||
GIT_EXTERN(int) git_reference_is_packed(git_reference *ref);
|
||||
|
||||
/**
|
||||
* Reload a reference from disk.
|
||||
*
|
||||
* Reference pointers can become outdated if the Git repository is
|
||||
* accessed simultaneously by other clients while the library is open.
|
||||
*
|
||||
* This method forces a reload of the reference from disk, to ensure that
|
||||
* the provided information is still reliable.
|
||||
*
|
||||
* If the reload fails (e.g. the reference no longer exists on disk, or
|
||||
* has become corrupted), an error code will be returned and the reference
|
||||
* pointer will be invalidated and freed.
|
||||
*
|
||||
* @param ref The reference to reload
|
||||
* @return 0 on success, or an error code
|
||||
*/
|
||||
GIT_EXTERN(int) git_reference_reload(git_reference *ref);
|
||||
|
||||
/**
|
||||
* Free the given reference.
|
||||
*
|
||||
* @param ref git_reference
|
||||
*/
|
||||
GIT_EXTERN(void) git_reference_free(git_reference *ref);
|
||||
|
||||
/**
|
||||
* Compare two references.
|
||||
*
|
||||
* @param ref1 The first git_reference
|
||||
* @param ref2 The second git_reference
|
||||
* @return 0 if the same, else a stable but meaningless ordering.
|
||||
*/
|
||||
GIT_EXTERN(int) git_reference_cmp(git_reference *ref1, git_reference *ref2);
|
||||
|
||||
/**
|
||||
* Perform a callback on each reference in the repository whose name
|
||||
* matches the given pattern.
|
||||
*
|
||||
* This function acts like `git_reference_foreach()` with an additional
|
||||
* pattern match being applied to the reference name before issuing the
|
||||
* callback function. See that function for more information.
|
||||
*
|
||||
* The pattern is matched using fnmatch or "glob" style where a '*' matches
|
||||
* any sequence of letters, a '?' matches any letter, and square brackets
|
||||
* can be used to define character ranges (such as "[0-9]" for digits).
|
||||
*
|
||||
* @param repo Repository where to find the refs
|
||||
* @param glob Pattern to match (fnmatch-style) against reference name.
|
||||
* @param list_flags Filtering flags for the reference listing.
|
||||
* @param callback Function which will be called for every listed ref
|
||||
* @param payload Additional data to pass to the callback
|
||||
* @return 0 on success, GIT_EUSER on non-zero callback, or error code
|
||||
*/
|
||||
GIT_EXTERN(int) git_reference_foreach_glob(
|
||||
git_repository *repo,
|
||||
const char *glob,
|
||||
unsigned int list_flags,
|
||||
git_reference_foreach_cb callback,
|
||||
void *payload);
|
||||
|
||||
/**
|
||||
* Check if a reflog exists for the specified reference.
|
||||
*
|
||||
* @param ref A git reference
|
||||
*
|
||||
* @return 0 when no reflog can be found, 1 when it exists;
|
||||
* otherwise an error code.
|
||||
*/
|
||||
GIT_EXTERN(int) git_reference_has_log(git_reference *ref);
|
||||
|
||||
/**
|
||||
* Check if a reference is a local branch.
|
||||
*
|
||||
* @param ref A git reference
|
||||
*
|
||||
* @return 1 when the reference lives in the refs/heads
|
||||
* namespace; 0 otherwise.
|
||||
*/
|
||||
GIT_EXTERN(int) git_reference_is_branch(git_reference *ref);
|
||||
|
||||
/**
|
||||
* Check if a reference is a remote tracking branch
|
||||
*
|
||||
* @param ref A git reference
|
||||
*
|
||||
* @return 1 when the reference lives in the refs/remotes
|
||||
* namespace; 0 otherwise.
|
||||
*/
|
||||
GIT_EXTERN(int) git_reference_is_remote(git_reference *ref);
|
||||
|
||||
|
||||
typedef enum {
|
||||
GIT_REF_FORMAT_NORMAL = 0,
|
||||
|
||||
/**
|
||||
* Control whether one-level refnames are accepted
|
||||
* (i.e., refnames that do not contain multiple /-separated
|
||||
* components). Those are expected to be written only using
|
||||
* uppercase letters and underscore (FETCH_HEAD, ...)
|
||||
*/
|
||||
GIT_REF_FORMAT_ALLOW_ONELEVEL = (1 << 0),
|
||||
|
||||
/**
|
||||
* Interpret the provided name as a reference pattern for a
|
||||
* refspec (as used with remote repositories). If this option
|
||||
* is enabled, the name is allowed to contain a single * (<star>)
|
||||
* in place of a one full pathname component
|
||||
* (e.g., foo/<star>/bar but not foo/bar<star>).
|
||||
*/
|
||||
GIT_REF_FORMAT_REFSPEC_PATTERN = (1 << 1),
|
||||
} git_reference_normalize_t;
|
||||
|
||||
/**
|
||||
* Normalize reference name and check validity.
|
||||
*
|
||||
* This will normalize the reference name by removing any leading slash
|
||||
* '/' characters and collapsing runs of adjacent slashes between name
|
||||
* components into a single slash.
|
||||
*
|
||||
* Once normalized, if the reference name is valid, it will be returned in
|
||||
* the user allocated buffer.
|
||||
*
|
||||
* See `git_reference_create_symbolic()` for rules about valid names.
|
||||
*
|
||||
* @param buffer_out User allocated buffer to store normalized name
|
||||
* @param buffer_size Size of buffer_out
|
||||
* @param name Reference name to be checked.
|
||||
* @param flags Flags to constrain name validation rules - see the
|
||||
* GIT_REF_FORMAT constants above.
|
||||
* @return 0 on success, GIT_EBUFS if buffer is too small, EINVALIDSPEC
|
||||
* or an error code.
|
||||
*/
|
||||
GIT_EXTERN(int) git_reference_normalize_name(
|
||||
char *buffer_out,
|
||||
size_t buffer_size,
|
||||
const char *name,
|
||||
unsigned int flags);
|
||||
|
||||
/**
|
||||
* Recursively peel reference until object of the specified type is found.
|
||||
*
|
||||
* The retrieved `peeled` object is owned by the repository
|
||||
* and should be closed with the `git_object_free` method.
|
||||
*
|
||||
* If you pass `GIT_OBJ_ANY` as the target type, then the object
|
||||
* will be peeled until a non-tag object is met.
|
||||
*
|
||||
* @param peeled Pointer to the peeled git_object
|
||||
* @param ref The reference 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
|
||||
*/
|
||||
GIT_EXTERN(int) git_reference_peel(
|
||||
git_object **out,
|
||||
git_reference *ref,
|
||||
git_otype type);
|
||||
|
||||
/**
|
||||
* Ensure the reference name is well-formed.
|
||||
*
|
||||
* Valid reference names must follow one of two patterns:
|
||||
*
|
||||
* 1. Top-level names must contain only capital letters and underscores,
|
||||
* and must begin and end with a letter. (e.g. "HEAD", "ORIG_HEAD").
|
||||
* 2. Names prefixed with "refs/" can be almost anything. You must avoid
|
||||
* the characters '~', '^', ':', '\\', '?', '[', and '*', and the
|
||||
* sequences ".." and "@{" which have special meaning to revparse.
|
||||
*
|
||||
* @param refname name to be checked.
|
||||
* @return 1 if the reference name is acceptable; 0 if it isn't
|
||||
*/
|
||||
GIT_EXTERN(int) git_reference_is_valid_name(const char *refname);
|
||||
|
||||
/** @} */
|
||||
GIT_END_DECL
|
||||
#endif
|
||||
@@ -1,68 +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_refspec_h__
|
||||
#define INCLUDE_git_refspec_h__
|
||||
|
||||
#include "common.h"
|
||||
#include "types.h"
|
||||
|
||||
/**
|
||||
* @file git2/refspec.h
|
||||
* @brief Git refspec attributes
|
||||
* @defgroup git_refspec Git refspec attributes
|
||||
* @ingroup Git
|
||||
* @{
|
||||
*/
|
||||
GIT_BEGIN_DECL
|
||||
|
||||
/**
|
||||
* Get the source specifier
|
||||
*
|
||||
* @param refspec the refspec
|
||||
* @return the refspec's source specifier
|
||||
*/
|
||||
GIT_EXTERN(const char *) git_refspec_src(const git_refspec *refspec);
|
||||
|
||||
/**
|
||||
* Get the destination specifier
|
||||
*
|
||||
* @param refspec the refspec
|
||||
* @return the refspec's destination specifier
|
||||
*/
|
||||
GIT_EXTERN(const char *) git_refspec_dst(const git_refspec *refspec);
|
||||
|
||||
/**
|
||||
* Get the force update setting
|
||||
*
|
||||
* @param refspec the refspec
|
||||
* @return 1 if force update has been set, 0 otherwise
|
||||
*/
|
||||
GIT_EXTERN(int) git_refspec_force(const git_refspec *refspec);
|
||||
|
||||
/**
|
||||
* Check if a refspec's source descriptor matches a reference
|
||||
*
|
||||
* @param refspec the refspec
|
||||
* @param refname the name of the reference to check
|
||||
* @return 1 if the refspec matches, 0 otherwise
|
||||
*/
|
||||
GIT_EXTERN(int) git_refspec_src_matches(const git_refspec *refspec, const char *refname);
|
||||
|
||||
/**
|
||||
* Transform a reference to its target following the refspec's rules
|
||||
*
|
||||
* @param out where to store the target name
|
||||
* @param outlen the size of the `out` buffer
|
||||
* @param spec the refspec
|
||||
* @param name the name of the reference to transform
|
||||
* @return 0, GIT_EBUFS or another error
|
||||
*/
|
||||
GIT_EXTERN(int) git_refspec_transform(char *out, size_t outlen, const git_refspec *spec, const char *name);
|
||||
|
||||
GIT_END_DECL
|
||||
|
||||
#endif
|
||||
@@ -1,465 +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_remote_h__
|
||||
#define INCLUDE_git_remote_h__
|
||||
|
||||
#include "common.h"
|
||||
#include "repository.h"
|
||||
#include "refspec.h"
|
||||
#include "net.h"
|
||||
#include "indexer.h"
|
||||
#include "strarray.h"
|
||||
#include "transport.h"
|
||||
|
||||
/**
|
||||
* @file git2/remote.h
|
||||
* @brief Git remote management functions
|
||||
* @defgroup git_remote remote management functions
|
||||
* @ingroup Git
|
||||
* @{
|
||||
*/
|
||||
GIT_BEGIN_DECL
|
||||
|
||||
typedef int (*git_remote_rename_problem_cb)(const char *problematic_refspec, void *payload);
|
||||
/*
|
||||
* TODO: This functions still need to be implemented:
|
||||
* - _listcb/_foreach
|
||||
* - _add
|
||||
* - _rename
|
||||
* - _del (needs support from config)
|
||||
*/
|
||||
|
||||
/**
|
||||
* Add a remote with the default fetch refspec to the repository's configuration. This
|
||||
* calls git_remote_save before returning.
|
||||
*
|
||||
* @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
|
||||
* @return 0, GIT_EINVALIDSPEC, GIT_EEXISTS or an error code
|
||||
*/
|
||||
GIT_EXTERN(int) git_remote_create(
|
||||
git_remote **out,
|
||||
git_repository *repo,
|
||||
const char *name,
|
||||
const char *url);
|
||||
|
||||
/**
|
||||
* Create a remote in memory
|
||||
*
|
||||
* Create a remote with the given refspec in memory. You can use
|
||||
* this when you have a URL instead of a remote's name. Note that in-memory
|
||||
* remotes cannot be converted to persisted remotes.
|
||||
*
|
||||
* 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 repo the associated repository. May be NULL for a "dangling" remote.
|
||||
* @param fetch the fetch refspec to use for this remote. May be NULL for defaults.
|
||||
* @param url the remote repository's URL
|
||||
* @return 0 or an error code
|
||||
*/
|
||||
GIT_EXTERN(int) git_remote_create_inmemory(
|
||||
git_remote **out,
|
||||
git_repository *repo,
|
||||
const char *fetch,
|
||||
const char *url);
|
||||
|
||||
/**
|
||||
* Sets the owning repository for the remote. This is only allowed on
|
||||
* dangling remotes.
|
||||
*
|
||||
* @param remote the remote to configure
|
||||
* @param repo the repository that will own the remote
|
||||
* @return 0 or an error code
|
||||
*/
|
||||
GIT_EXTERN(int) git_remote_set_repository(git_remote *remote, git_repository *repo);
|
||||
|
||||
/**
|
||||
* Get the information for a particular remote
|
||||
*
|
||||
* The name will be checked for validity.
|
||||
* See `git_tag_create()` for rules about valid names.
|
||||
*
|
||||
* @param out pointer to the new remote object
|
||||
* @param repo the associated repository
|
||||
* @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);
|
||||
|
||||
/**
|
||||
* Get the remote's name
|
||||
*
|
||||
* @param remote the remote
|
||||
* @return a pointer to the name or NULL for in-memory remotes
|
||||
*/
|
||||
GIT_EXTERN(const char *) git_remote_name(const git_remote *remote);
|
||||
|
||||
/**
|
||||
* Get the remote's url
|
||||
*
|
||||
* @param remote the remote
|
||||
* @return a pointer to the url
|
||||
*/
|
||||
GIT_EXTERN(const char *) git_remote_url(const git_remote *remote);
|
||||
|
||||
/**
|
||||
* Get the remote's url for pushing
|
||||
*
|
||||
* @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
|
||||
*
|
||||
* Existing connections will not be updated.
|
||||
*
|
||||
* @param remote the remote
|
||||
* @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);
|
||||
|
||||
/**
|
||||
* Set the remote's url for pushing
|
||||
*
|
||||
* Existing connections will not be updated.
|
||||
*
|
||||
* @param remote the remote
|
||||
* @param url the url to set or NULL to clear the pushurl
|
||||
* @return 0 or an error value
|
||||
*/
|
||||
GIT_EXTERN(int) git_remote_set_pushurl(git_remote *remote, const char* url);
|
||||
|
||||
/**
|
||||
* Set the remote's fetch refspec
|
||||
*
|
||||
* @param remote the remote
|
||||
* @apram spec the new fetch refspec
|
||||
* @return 0 or an error value
|
||||
*/
|
||||
GIT_EXTERN(int) git_remote_set_fetchspec(git_remote *remote, const char *spec);
|
||||
|
||||
/**
|
||||
* Get the fetch refspec
|
||||
*
|
||||
* @param remote the remote
|
||||
* @return a pointer to the fetch refspec or NULL if it doesn't exist
|
||||
*/
|
||||
GIT_EXTERN(const git_refspec *) git_remote_fetchspec(const git_remote *remote);
|
||||
|
||||
/**
|
||||
* Set the remote's push refspec
|
||||
*
|
||||
* @param remote the remote
|
||||
* @param spec the new push refspec
|
||||
* @return 0 or an error value
|
||||
*/
|
||||
GIT_EXTERN(int) git_remote_set_pushspec(git_remote *remote, const char *spec);
|
||||
|
||||
/**
|
||||
* Get the push refspec
|
||||
*
|
||||
* @param remote the remote
|
||||
* @return a pointer to the push refspec or NULL if it doesn't exist
|
||||
*/
|
||||
|
||||
GIT_EXTERN(const git_refspec *) git_remote_pushspec(const git_remote *remote);
|
||||
|
||||
/**
|
||||
* Open a connection to a remote
|
||||
*
|
||||
* The transport is selected based on the URL. The direction argument
|
||||
* is due to a limitation of the git protocol (over TCP or SSH) which
|
||||
* starts up a specific binary which can only do the one or the other.
|
||||
*
|
||||
* @param remote the remote to connect to
|
||||
* @param direction whether you want to receive or send data
|
||||
* @return 0 or an error code
|
||||
*/
|
||||
GIT_EXTERN(int) git_remote_connect(git_remote *remote, git_direction direction);
|
||||
|
||||
/**
|
||||
* Get a list of refs at the remote
|
||||
*
|
||||
* The remote (or more exactly its transport) must be connected. The
|
||||
* memory belongs to the remote.
|
||||
*
|
||||
* If you a return a non-zero value from the callback, this will stop
|
||||
* looping over the refs.
|
||||
*
|
||||
* @param remote the remote
|
||||
* @param list_cb function to call with each ref discovered at the remote
|
||||
* @param payload additional data to pass to the callback
|
||||
* @return 0 on success, GIT_EUSER on non-zero callback, or error code
|
||||
*/
|
||||
GIT_EXTERN(int) git_remote_ls(git_remote *remote, git_headlist_cb list_cb, void *payload);
|
||||
|
||||
/**
|
||||
* Download the packfile
|
||||
*
|
||||
* Negotiate what objects should be downloaded and download the
|
||||
* packfile with those objects. The packfile is downloaded with a
|
||||
* temporary filename, as it's final name is not known yet. If there
|
||||
* was no packfile needed (all the objects were available locally),
|
||||
* filename will be NULL and the function will return success.
|
||||
*
|
||||
* @param remote the remote to download from
|
||||
* @param progress_cb function to call with progress information. Be aware that
|
||||
* this is called inline with network and indexing operations, so performance
|
||||
* may be affected.
|
||||
* @param progress_payload payload for the progress callback
|
||||
* @return 0 or an error code
|
||||
*/
|
||||
GIT_EXTERN(int) git_remote_download(
|
||||
git_remote *remote,
|
||||
git_transfer_progress_callback progress_cb,
|
||||
void *payload);
|
||||
|
||||
/**
|
||||
* Check whether the remote is connected
|
||||
*
|
||||
* Check whether the remote's underlying transport is connected to the
|
||||
* remote host.
|
||||
*
|
||||
* @param remote the remote
|
||||
* @return 1 if it's connected, 0 otherwise.
|
||||
*/
|
||||
GIT_EXTERN(int) git_remote_connected(git_remote *remote);
|
||||
|
||||
/**
|
||||
* Cancel the operation
|
||||
*
|
||||
* At certain points in its operation, the network code checks whether
|
||||
* the operation has been cancelled and if so stops the operation.
|
||||
*
|
||||
* @param remote the remote
|
||||
*/
|
||||
GIT_EXTERN(void) git_remote_stop(git_remote *remote);
|
||||
|
||||
/**
|
||||
* Disconnect from the remote
|
||||
*
|
||||
* Close the connection to the remote and free the underlying
|
||||
* transport.
|
||||
*
|
||||
* @param remote the remote to disconnect from
|
||||
*/
|
||||
GIT_EXTERN(void) git_remote_disconnect(git_remote *remote);
|
||||
|
||||
/**
|
||||
* Free the memory associated with a remote
|
||||
*
|
||||
* This also disconnects from the remote, if the connection
|
||||
* has not been closed yet (using git_remote_disconnect).
|
||||
*
|
||||
* @param remote the remote to free
|
||||
*/
|
||||
GIT_EXTERN(void) git_remote_free(git_remote *remote);
|
||||
|
||||
/**
|
||||
* Update the tips to the new state
|
||||
*
|
||||
* @param remote the remote to update
|
||||
* @return 0 or an error code
|
||||
*/
|
||||
GIT_EXTERN(int) git_remote_update_tips(git_remote *remote);
|
||||
|
||||
/**
|
||||
* Return whether a string is a valid remote URL
|
||||
*
|
||||
* @param url the url to check
|
||||
* @param 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
|
||||
*
|
||||
* The string array must be freed by the user.
|
||||
*
|
||||
* @param out a string array which receives the names of the remotes
|
||||
* @param repo the repository to query
|
||||
* @return 0 or an error code
|
||||
*/
|
||||
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);
|
||||
|
||||
/**
|
||||
* Set a credentials acquisition callback for this remote. If the remote is
|
||||
* not available for anonymous access, then you must set this callback in order
|
||||
* to provide credentials to the transport at the time of authentication
|
||||
* failure so that retry can be performed.
|
||||
*
|
||||
* @param remote the remote to configure
|
||||
* @param cred_acquire_cb The credentials acquisition callback to use (defaults
|
||||
* to NULL)
|
||||
*/
|
||||
GIT_EXTERN(void) git_remote_set_cred_acquire_cb(
|
||||
git_remote *remote,
|
||||
git_cred_acquire_cb cred_acquire_cb,
|
||||
void *payload);
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
typedef enum git_remote_completion_type {
|
||||
GIT_REMOTE_COMPLETION_DOWNLOAD,
|
||||
GIT_REMOTE_COMPLETION_INDEXING,
|
||||
GIT_REMOTE_COMPLETION_ERROR,
|
||||
} git_remote_completion_type;
|
||||
|
||||
/**
|
||||
* The callback settings structure
|
||||
*
|
||||
* Set the calbacks to be called by the remote.
|
||||
*/
|
||||
struct git_remote_callbacks {
|
||||
unsigned int version;
|
||||
void (*progress)(const char *str, int len, void *data);
|
||||
int (*completion)(git_remote_completion_type type, void *data);
|
||||
int (*update_tips)(const char *refname, const git_oid *a, const git_oid *b, void *data);
|
||||
void *payload;
|
||||
};
|
||||
|
||||
#define GIT_REMOTE_CALLBACKS_VERSION 1
|
||||
#define GIT_REMOTE_CALLBACKS_INIT {GIT_REMOTE_CALLBACKS_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, git_remote_callbacks *callbacks);
|
||||
|
||||
/**
|
||||
* 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_UNSET,
|
||||
GIT_REMOTE_DOWNLOAD_TAGS_NONE,
|
||||
GIT_REMOTE_DOWNLOAD_TAGS_AUTO,
|
||||
GIT_REMOTE_DOWNLOAD_TAGS_ALL
|
||||
} git_remote_autotag_option_t;
|
||||
|
||||
/**
|
||||
* Retrieve the tag auto-follow setting
|
||||
*
|
||||
* @param remote the remote to query
|
||||
* @return the auto-follow setting
|
||||
*/
|
||||
GIT_EXTERN(git_remote_autotag_option_t) git_remote_autotag(git_remote *remote);
|
||||
|
||||
/**
|
||||
* Set the tag auto-follow setting
|
||||
*
|
||||
* @param remote the remote to configure
|
||||
* @param value a GIT_REMOTE_DOWNLOAD_TAGS value
|
||||
*/
|
||||
GIT_EXTERN(void) git_remote_set_autotag(
|
||||
git_remote *remote,
|
||||
git_remote_autotag_option_t value);
|
||||
|
||||
/**
|
||||
* Give the remote a new name
|
||||
*
|
||||
* All remote-tracking branches and configuration settings
|
||||
* for the remote are updated.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* @param remote the remote to rename
|
||||
* @param new_name the new name the remote should bear
|
||||
* @param callback Optional callback to notify the consumer of fetch refspecs
|
||||
* that haven't been automatically updated and need potential manual tweaking.
|
||||
* @param payload Additional data to pass to the callback
|
||||
* @return 0, GIT_EINVALIDSPEC, GIT_EEXISTS or an error code
|
||||
*/
|
||||
GIT_EXTERN(int) git_remote_rename(
|
||||
git_remote *remote,
|
||||
const char *new_name,
|
||||
git_remote_rename_problem_cb callback,
|
||||
void *payload);
|
||||
|
||||
/**
|
||||
* 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);
|
||||
|
||||
/** @} */
|
||||
GIT_END_DECL
|
||||
#endif
|
||||
@@ -1,647 +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_repository_h__
|
||||
#define INCLUDE_git_repository_h__
|
||||
|
||||
#include "common.h"
|
||||
#include "types.h"
|
||||
#include "oid.h"
|
||||
|
||||
/**
|
||||
* @file git2/repository.h
|
||||
* @brief Git repository management routines
|
||||
* @defgroup git_repository Git repository management routines
|
||||
* @ingroup Git
|
||||
* @{
|
||||
*/
|
||||
GIT_BEGIN_DECL
|
||||
|
||||
/**
|
||||
* Open a git repository.
|
||||
*
|
||||
* The 'path' argument must point to either a git repository
|
||||
* folder, or an existing work dir.
|
||||
*
|
||||
* The method will automatically detect if 'path' is a normal
|
||||
* or bare repository or fail is 'path' is neither.
|
||||
*
|
||||
* @param out pointer to the repo which will be opened
|
||||
* @param path the path to the repository
|
||||
* @return 0 or an error code
|
||||
*/
|
||||
GIT_EXTERN(int) git_repository_open(git_repository **out, const char *path);
|
||||
|
||||
/**
|
||||
* Create a "fake" repository to wrap an object database
|
||||
*
|
||||
* Create a repository object to wrap an object database to be used
|
||||
* with the API when all you have is an object database. This doesn't
|
||||
* have any paths associated with it, so use with care.
|
||||
*
|
||||
* @param out pointer to the repo
|
||||
* @param odb the object database to wrap
|
||||
* @return 0 or an error code
|
||||
*/
|
||||
GIT_EXTERN(int) git_repository_wrap_odb(git_repository **out, git_odb *odb);
|
||||
|
||||
/**
|
||||
* Look for a git repository and copy its path in the given buffer.
|
||||
* The lookup start from base_path and walk across parent directories
|
||||
* if nothing has been found. The lookup ends when the first repository
|
||||
* is found, or when reaching a directory referenced in ceiling_dirs
|
||||
* or when the filesystem changes (in case across_fs is true).
|
||||
*
|
||||
* The method will automatically detect if the repository is bare
|
||||
* (if there is a repository).
|
||||
*
|
||||
* @param path_out The user allocated buffer which will
|
||||
* contain the found path.
|
||||
*
|
||||
* @param path_size repository_path size
|
||||
*
|
||||
* @param start_path The base path where the lookup starts.
|
||||
*
|
||||
* @param across_fs If true, then the lookup will not stop when a
|
||||
* filesystem device change is detected while exploring parent directories.
|
||||
*
|
||||
* @param ceiling_dirs A GIT_PATH_LIST_SEPARATOR separated list of
|
||||
* absolute symbolic link free paths. The lookup will stop when any
|
||||
* of this paths is reached. Note that the lookup always performs on
|
||||
* start_path no matter start_path appears in ceiling_dirs ceiling_dirs
|
||||
* might be NULL (which is equivalent to an empty string)
|
||||
*
|
||||
* @return 0 or an error code
|
||||
*/
|
||||
GIT_EXTERN(int) git_repository_discover(
|
||||
char *path_out,
|
||||
size_t path_size,
|
||||
const char *start_path,
|
||||
int across_fs,
|
||||
const char *ceiling_dirs);
|
||||
|
||||
/**
|
||||
* Option flags for `git_repository_open_ext`.
|
||||
*
|
||||
* * GIT_REPOSITORY_OPEN_NO_SEARCH - Only open the repository if it can be
|
||||
* immediately found in the start_path. Do not walk up from the
|
||||
* start_path looking at parent directories.
|
||||
* * GIT_REPOSITORY_OPEN_CROSS_FS - Unless this flag is set, open will not
|
||||
* continue searching across filesystem boundaries (i.e. when `st_dev`
|
||||
* changes from the `stat` system call). (E.g. Searching in a user's home
|
||||
* directory "/home/user/source/" will not return "/.git/" as the found
|
||||
* repo if "/" is a different filesystem than "/home".)
|
||||
*/
|
||||
typedef enum {
|
||||
GIT_REPOSITORY_OPEN_NO_SEARCH = (1 << 0),
|
||||
GIT_REPOSITORY_OPEN_CROSS_FS = (1 << 1),
|
||||
} git_repository_open_flag_t;
|
||||
|
||||
/**
|
||||
* Find and open a repository with extended controls.
|
||||
*
|
||||
* @param out Pointer to the repo which will be opened. This can
|
||||
* actually be NULL if you only want to use the error code to
|
||||
* see if a repo at this path could be opened.
|
||||
* @param path Path to open as git repository. If the flags
|
||||
* permit "searching", then this can be a path to a subdirectory
|
||||
* inside the working directory of the repository.
|
||||
* @param flags A combination of the GIT_REPOSITORY_OPEN flags above.
|
||||
* @param ceiling_dirs A GIT_PATH_LIST_SEPARATOR delimited list of path
|
||||
* prefixes at which the search for a containing repository should
|
||||
* terminate.
|
||||
* @return 0 on success, GIT_ENOTFOUND if no repository could be found,
|
||||
* or -1 if there was a repository but open failed for some reason
|
||||
* (such as repo corruption or system errors).
|
||||
*/
|
||||
GIT_EXTERN(int) git_repository_open_ext(
|
||||
git_repository **out,
|
||||
const char *path,
|
||||
unsigned int flags,
|
||||
const char *ceiling_dirs);
|
||||
|
||||
/**
|
||||
* Free a previously allocated repository
|
||||
*
|
||||
* Note that after a repository is free'd, all the objects it has spawned
|
||||
* will still exist until they are manually closed by the user
|
||||
* with `git_object_free`, but accessing any of the attributes of
|
||||
* an object without a backing repository will result in undefined
|
||||
* behavior
|
||||
*
|
||||
* @param repo repository handle to close. If NULL nothing occurs.
|
||||
*/
|
||||
GIT_EXTERN(void) git_repository_free(git_repository *repo);
|
||||
|
||||
/**
|
||||
* Creates a new Git repository in the given folder.
|
||||
*
|
||||
* TODO:
|
||||
* - Reinit the repository
|
||||
*
|
||||
* @param out pointer to the repo which will be created or reinitialized
|
||||
* @param path the path to the repository
|
||||
* @param is_bare if true, a Git repository without a working directory is
|
||||
* created at the pointed path. If false, provided path will be
|
||||
* considered as the working directory into which the .git directory
|
||||
* will be created.
|
||||
*
|
||||
* @return 0 or an error code
|
||||
*/
|
||||
GIT_EXTERN(int) git_repository_init(
|
||||
git_repository **out,
|
||||
const char *path,
|
||||
unsigned is_bare);
|
||||
|
||||
/**
|
||||
* Option flags for `git_repository_init_ext`.
|
||||
*
|
||||
* These flags configure extra behaviors to `git_repository_init_ext`.
|
||||
* In every case, the default behavior is the zero value (i.e. flag is
|
||||
* not set). Just OR the flag values together for the `flags` parameter
|
||||
* when initializing a new repo. Details of individual values are:
|
||||
*
|
||||
* * BARE - Create a bare repository with no working directory.
|
||||
* * NO_REINIT - Return an EEXISTS error if the repo_path appears to
|
||||
* already be an git repository.
|
||||
* * NO_DOTGIT_DIR - Normally a "/.git/" will be appended to the repo
|
||||
* path for non-bare repos (if it is not already there), but
|
||||
* passing this flag prevents that behavior.
|
||||
* * MKDIR - Make the repo_path (and workdir_path) as needed. Init is
|
||||
* always willing to create the ".git" directory even without this
|
||||
* flag. This flag tells init to create the trailing component of
|
||||
* the repo and workdir paths as needed.
|
||||
* * MKPATH - Recursively make all components of the repo and workdir
|
||||
* paths as necessary.
|
||||
* * EXTERNAL_TEMPLATE - libgit2 normally uses internal templates to
|
||||
* initialize a new repo. This flags enables external templates,
|
||||
* 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.
|
||||
*/
|
||||
typedef enum {
|
||||
GIT_REPOSITORY_INIT_BARE = (1u << 0),
|
||||
GIT_REPOSITORY_INIT_NO_REINIT = (1u << 1),
|
||||
GIT_REPOSITORY_INIT_NO_DOTGIT_DIR = (1u << 2),
|
||||
GIT_REPOSITORY_INIT_MKDIR = (1u << 3),
|
||||
GIT_REPOSITORY_INIT_MKPATH = (1u << 4),
|
||||
GIT_REPOSITORY_INIT_EXTERNAL_TEMPLATE = (1u << 5),
|
||||
} git_repository_init_flag_t;
|
||||
|
||||
/**
|
||||
* Mode options for `git_repository_init_ext`.
|
||||
*
|
||||
* Set the mode field of the `git_repository_init_options` structure
|
||||
* either to the custom mode that you would like, or to one of the
|
||||
* following modes:
|
||||
*
|
||||
* * SHARED_UMASK - Use permissions configured by umask - the default.
|
||||
* * SHARED_GROUP - Use "--shared=group" behavior, chmod'ing the new repo
|
||||
* to be group writable and "g+sx" for sticky group assignment.
|
||||
* * SHARED_ALL - Use "--shared=all" behavior, adding world readability.
|
||||
* * Anything else - Set to custom value.
|
||||
*/
|
||||
typedef enum {
|
||||
GIT_REPOSITORY_INIT_SHARED_UMASK = 0,
|
||||
GIT_REPOSITORY_INIT_SHARED_GROUP = 0002775,
|
||||
GIT_REPOSITORY_INIT_SHARED_ALL = 0002777,
|
||||
} git_repository_init_mode_t;
|
||||
|
||||
/**
|
||||
* Extended options structure for `git_repository_init_ext`.
|
||||
*
|
||||
* This contains extra options for `git_repository_init_ext` that enable
|
||||
* additional initialization features. The fields are:
|
||||
*
|
||||
* * flags - Combination of GIT_REPOSITORY_INIT flags above.
|
||||
* * mode - Set to one of the standard GIT_REPOSITORY_INIT_SHARED_...
|
||||
* constants above, or to a custom value that you would like.
|
||||
* * workdir_path - The path to the working dir or NULL for default (i.e.
|
||||
* repo_path parent on non-bare repos). IF THIS IS RELATIVE PATH,
|
||||
* IT WILL BE EVALUATED RELATIVE TO THE REPO_PATH. If this is not
|
||||
* the "natural" working directory, a .git gitlink file will be
|
||||
* created here linking to the repo_path.
|
||||
* * description - If set, this will be used to initialize the "description"
|
||||
* file in the repository, instead of using the template content.
|
||||
* * template_path - When GIT_REPOSITORY_INIT_EXTERNAL_TEMPLATE is set,
|
||||
* this contains the path to use for the template directory. If
|
||||
* this is NULL, the config or default directory options will be
|
||||
* used instead.
|
||||
* * initial_head - The name of the head to point HEAD at. If NULL, then
|
||||
* this will be treated as "master" and the HEAD ref will be set
|
||||
* to "refs/heads/master". If this begins with "refs/" it will be
|
||||
* used verbatim; otherwise "refs/heads/" will be prefixed.
|
||||
* * origin_url - If this is non-NULL, then after the rest of the
|
||||
* repository initialization is completed, an "origin" remote
|
||||
* will be added pointing to this URL.
|
||||
*/
|
||||
typedef struct {
|
||||
unsigned int version;
|
||||
uint32_t flags;
|
||||
uint32_t mode;
|
||||
const char *workdir_path;
|
||||
const char *description;
|
||||
const char *template_path;
|
||||
const char *initial_head;
|
||||
const char *origin_url;
|
||||
} git_repository_init_options;
|
||||
|
||||
#define GIT_REPOSITORY_INIT_OPTIONS_VERSION 1
|
||||
#define GIT_REPOSITORY_INIT_OPTIONS_INIT {GIT_REPOSITORY_INIT_OPTIONS_VERSION}
|
||||
|
||||
/**
|
||||
* Create a new Git repository in the given folder with extended controls.
|
||||
*
|
||||
* This will initialize a new git repository (creating the repo_path
|
||||
* if requested by flags) and working directory as needed. It will
|
||||
* auto-detect the case sensitivity of the file system and if the
|
||||
* file system supports file mode bits correctly.
|
||||
*
|
||||
* @param out Pointer to the repo which will be created or reinitialized.
|
||||
* @param repo_path The path to the repository.
|
||||
* @param opts Pointer to git_repository_init_options struct.
|
||||
* @return 0 or an error code on failure.
|
||||
*/
|
||||
GIT_EXTERN(int) git_repository_init_ext(
|
||||
git_repository **out,
|
||||
const char *repo_path,
|
||||
git_repository_init_options *opts);
|
||||
|
||||
/**
|
||||
* Retrieve and resolve the reference pointed at by HEAD.
|
||||
*
|
||||
* The returned `git_reference` will be owned by caller and
|
||||
* `git_reference_free()` must be called when done with it to release the
|
||||
* allocated memory and prevent a leak.
|
||||
*
|
||||
* @param out pointer to the reference which will be retrieved
|
||||
* @param repo a repository object
|
||||
*
|
||||
* @return 0 on success, GIT_EORPHANEDHEAD when HEAD points to a non existing
|
||||
* branch, GIT_ENOTFOUND when HEAD is missing; an error code otherwise
|
||||
*/
|
||||
GIT_EXTERN(int) git_repository_head(git_reference **out, git_repository *repo);
|
||||
|
||||
/**
|
||||
* Check if a repository's HEAD is detached
|
||||
*
|
||||
* A repository's HEAD is detached when it points directly to a commit
|
||||
* instead of a branch.
|
||||
*
|
||||
* @param repo Repo to test
|
||||
* @return 1 if HEAD is detached, 0 if it's not; error code if there
|
||||
* was an error.
|
||||
*/
|
||||
GIT_EXTERN(int) git_repository_head_detached(git_repository *repo);
|
||||
|
||||
/**
|
||||
* Check if the current branch is an orphan
|
||||
*
|
||||
* An orphan branch is one named from HEAD but which doesn't exist in
|
||||
* the refs namespace, because it doesn't have any commit to point to.
|
||||
*
|
||||
* @param repo Repo to test
|
||||
* @return 1 if the current branch is an orphan, 0 if it's not; error
|
||||
* code if there was an error
|
||||
*/
|
||||
GIT_EXTERN(int) git_repository_head_orphan(git_repository *repo);
|
||||
|
||||
/**
|
||||
* Check if a repository is empty
|
||||
*
|
||||
* An empty repository has just been initialized and contains
|
||||
* no references.
|
||||
*
|
||||
* @param repo Repo to test
|
||||
* @return 1 if the repository is empty, 0 if it isn't, error code
|
||||
* if the repository is corrupted
|
||||
*/
|
||||
GIT_EXTERN(int) git_repository_is_empty(git_repository *repo);
|
||||
|
||||
/**
|
||||
* Get the path of this repository
|
||||
*
|
||||
* This is the path of the `.git` folder for normal repositories,
|
||||
* or of the repository itself for bare repositories.
|
||||
*
|
||||
* @param repo A repository object
|
||||
* @return the path to the repository
|
||||
*/
|
||||
GIT_EXTERN(const char *) git_repository_path(git_repository *repo);
|
||||
|
||||
/**
|
||||
* Get the path of the working directory for this repository
|
||||
*
|
||||
* If the repository is bare, this function will always return
|
||||
* NULL.
|
||||
*
|
||||
* @param repo A repository object
|
||||
* @return the path to the working dir, if it exists
|
||||
*/
|
||||
GIT_EXTERN(const char *) git_repository_workdir(git_repository *repo);
|
||||
|
||||
/**
|
||||
* Set the path to the working directory for this repository
|
||||
*
|
||||
* The working directory doesn't need to be the same one
|
||||
* that contains the `.git` folder for this repository.
|
||||
*
|
||||
* If this repository is bare, setting its working directory
|
||||
* will turn it into a normal repository, capable of performing
|
||||
* all the common workdir operations (checkout, status, index
|
||||
* manipulation, etc).
|
||||
*
|
||||
* @param repo A repository object
|
||||
* @param workdir The path to a working directory
|
||||
* @param update_gitlink Create/update gitlink in workdir and set config
|
||||
* "core.worktree" (if workdir is not the parent of the .git directory)
|
||||
* @return 0, or an error code
|
||||
*/
|
||||
GIT_EXTERN(int) git_repository_set_workdir(
|
||||
git_repository *repo, const char *workdir, int update_gitlink);
|
||||
|
||||
/**
|
||||
* Check if a repository is bare
|
||||
*
|
||||
* @param repo Repo to test
|
||||
* @return 1 if the repository is bare, 0 otherwise.
|
||||
*/
|
||||
GIT_EXTERN(int) git_repository_is_bare(git_repository *repo);
|
||||
|
||||
/**
|
||||
* Get the configuration file for this repository.
|
||||
*
|
||||
* If a configuration file has not been set, the default
|
||||
* config set for the repository will be returned, including
|
||||
* global and system configurations (if they are available).
|
||||
*
|
||||
* The configuration file must be freed once it's no longer
|
||||
* being used by the user.
|
||||
*
|
||||
* @param out Pointer to store the loaded config file
|
||||
* @param repo A repository object
|
||||
* @return 0, or an error code
|
||||
*/
|
||||
GIT_EXTERN(int) git_repository_config(git_config **out, git_repository *repo);
|
||||
|
||||
/**
|
||||
* Set the configuration file for this repository
|
||||
*
|
||||
* This configuration file will be used for all configuration
|
||||
* queries involving this repository.
|
||||
*
|
||||
* The repository will keep a reference to the config file;
|
||||
* the user must still free the config after setting it
|
||||
* to the repository, or it will leak.
|
||||
*
|
||||
* @param repo A repository object
|
||||
* @param config A Config object
|
||||
*/
|
||||
GIT_EXTERN(void) git_repository_set_config(git_repository *repo, git_config *config);
|
||||
|
||||
/**
|
||||
* Get the Object Database for this repository.
|
||||
*
|
||||
* If a custom ODB has not been set, the default
|
||||
* database for the repository will be returned (the one
|
||||
* located in `.git/objects`).
|
||||
*
|
||||
* The ODB must be freed once it's no longer being used by
|
||||
* the user.
|
||||
*
|
||||
* @param out Pointer to store the loaded ODB
|
||||
* @param repo A repository object
|
||||
* @return 0, or an error code
|
||||
*/
|
||||
GIT_EXTERN(int) git_repository_odb(git_odb **out, git_repository *repo);
|
||||
|
||||
/**
|
||||
* Set the Object Database for this repository
|
||||
*
|
||||
* The ODB will be used for all object-related operations
|
||||
* involving this repository.
|
||||
*
|
||||
* The repository will keep a reference to the ODB; the user
|
||||
* must still free the ODB object after setting it to the
|
||||
* repository, or it will leak.
|
||||
*
|
||||
* @param repo A repository object
|
||||
* @param odb An ODB object
|
||||
*/
|
||||
GIT_EXTERN(void) git_repository_set_odb(git_repository *repo, git_odb *odb);
|
||||
|
||||
/**
|
||||
* Get the Index file for this repository.
|
||||
*
|
||||
* If a custom index has not been set, the default
|
||||
* index for the repository will be returned (the one
|
||||
* located in `.git/index`).
|
||||
*
|
||||
* The index must be freed once it's no longer being used by
|
||||
* the user.
|
||||
*
|
||||
* @param out Pointer to store the loaded index
|
||||
* @param repo A repository object
|
||||
* @return 0, or an error code
|
||||
*/
|
||||
GIT_EXTERN(int) git_repository_index(git_index **out, git_repository *repo);
|
||||
|
||||
/**
|
||||
* Set the index file for this repository
|
||||
*
|
||||
* This index will be used for all index-related operations
|
||||
* involving this repository.
|
||||
*
|
||||
* The repository will keep a reference to the index file;
|
||||
* the user must still free the index after setting it
|
||||
* to the repository, or it will leak.
|
||||
*
|
||||
* @param repo A repository object
|
||||
* @param index An index object
|
||||
*/
|
||||
GIT_EXTERN(void) git_repository_set_index(git_repository *repo, git_index *index);
|
||||
|
||||
/**
|
||||
* Retrieve git's prepared message
|
||||
*
|
||||
* Operations such as git revert/cherry-pick/merge with the -n option
|
||||
* stop just short of creating a commit with the changes and save
|
||||
* their prepared message in .git/MERGE_MSG so the next git-commit
|
||||
* execution can present it to the user for them to amend if they
|
||||
* wish.
|
||||
*
|
||||
* Use this function to get the contents of this file. Don't forget to
|
||||
* remove the file after you create the commit.
|
||||
*
|
||||
* @param out Buffer to write data into or NULL to just read required size
|
||||
* @param len Length of buffer in bytes
|
||||
* @param repo Repository to read prepared message from
|
||||
* @return Bytes written to buffer, GIT_ENOTFOUND if no message, or -1 on error
|
||||
*/
|
||||
GIT_EXTERN(int) git_repository_message(char *out, size_t len, git_repository *repo);
|
||||
|
||||
/**
|
||||
* Remove git's prepared message.
|
||||
*
|
||||
* Remove the message that `git_repository_message` retrieves.
|
||||
*/
|
||||
GIT_EXTERN(int) git_repository_message_remove(git_repository *repo);
|
||||
|
||||
/**
|
||||
* Remove all the metadata associated with an ongoing git merge, including
|
||||
* MERGE_HEAD, MERGE_MSG, etc.
|
||||
*
|
||||
* @param repo A repository object
|
||||
* @return 0 on success, or error
|
||||
*/
|
||||
GIT_EXTERN(int) git_repository_merge_cleanup(git_repository *repo);
|
||||
|
||||
typedef int (*git_repository_fetchhead_foreach_cb)(const char *ref_name,
|
||||
const char *remote_url,
|
||||
const git_oid *oid,
|
||||
unsigned int is_merge,
|
||||
void *payload);
|
||||
|
||||
/**
|
||||
* Call callback 'callback' for each entry in the given FETCH_HEAD file.
|
||||
*
|
||||
* @param repo A repository object
|
||||
* @param callback Callback function
|
||||
* @param payload Pointer to callback data (optional)
|
||||
* @return 0 on success, GIT_ENOTFOUND, GIT_EUSER or error
|
||||
*/
|
||||
GIT_EXTERN(int) git_repository_fetchhead_foreach(git_repository *repo,
|
||||
git_repository_fetchhead_foreach_cb callback,
|
||||
void *payload);
|
||||
|
||||
typedef int (*git_repository_mergehead_foreach_cb)(const git_oid *oid,
|
||||
void *payload);
|
||||
|
||||
/**
|
||||
* If a merge is in progress, call callback 'cb' for each commit ID in the
|
||||
* MERGE_HEAD file.
|
||||
*
|
||||
* @param repo A repository object
|
||||
* @param callback Callback function
|
||||
* @param apyload Pointer to callback data (optional)
|
||||
* @return 0 on success, GIT_ENOTFOUND, GIT_EUSER or error
|
||||
*/
|
||||
GIT_EXTERN(int) git_repository_mergehead_foreach(git_repository *repo,
|
||||
git_repository_mergehead_foreach_cb callback,
|
||||
void *payload);
|
||||
|
||||
/**
|
||||
* Calculate hash of file using repository filtering rules.
|
||||
*
|
||||
* If you simply want to calculate the hash of a file on disk with no filters,
|
||||
* you can just use the `git_odb_hashfile()` API. However, if you want to
|
||||
* hash a file in the repository and you want to apply filtering rules (e.g.
|
||||
* crlf filters) before generating the SHA, then use this function.
|
||||
*
|
||||
* @param out Output value of calculated SHA
|
||||
* @param repo Repository pointer
|
||||
* @param path Path to file on disk whose contents should be hashed. If the
|
||||
* repository is not NULL, this can be a relative path.
|
||||
* @param type The object type to hash as (e.g. GIT_OBJ_BLOB)
|
||||
* @param as_path The path to use to look up filtering rules. If this is
|
||||
* NULL, then the `path` parameter will be used instead. If
|
||||
* this is passed as the empty string, then no filters will be
|
||||
* applied when calculating the hash.
|
||||
*/
|
||||
GIT_EXTERN(int) git_repository_hashfile(
|
||||
git_oid *out,
|
||||
git_repository *repo,
|
||||
const char *path,
|
||||
git_otype type,
|
||||
const char *as_path);
|
||||
|
||||
/**
|
||||
* Make the repository HEAD point to the specified reference.
|
||||
*
|
||||
* If the provided reference points to a Tree or a Blob, the HEAD is
|
||||
* unaltered and -1 is returned.
|
||||
*
|
||||
* If the provided reference points to a branch, the HEAD will point
|
||||
* to that branch, staying attached, or become attached if it isn't yet.
|
||||
* If the branch doesn't exist yet, no error will be return. The HEAD
|
||||
* will then be attached to an unborn branch.
|
||||
*
|
||||
* Otherwise, the HEAD will be detached and will directly point to
|
||||
* the Commit.
|
||||
*
|
||||
* @param repo Repository pointer
|
||||
* @param refname Canonical name of the reference the HEAD should point at
|
||||
* @return 0 on success, or an error code
|
||||
*/
|
||||
GIT_EXTERN(int) git_repository_set_head(
|
||||
git_repository* repo,
|
||||
const char* refname);
|
||||
|
||||
/**
|
||||
* Make the repository HEAD directly point to the Commit.
|
||||
*
|
||||
* If the provided committish cannot be found in the repository, the HEAD
|
||||
* is unaltered and GIT_ENOTFOUND is returned.
|
||||
*
|
||||
* If the provided commitish cannot be peeled into a commit, the HEAD
|
||||
* is unaltered and -1 is returned.
|
||||
*
|
||||
* Otherwise, the HEAD will eventually be detached and will directly point to
|
||||
* the peeled Commit.
|
||||
*
|
||||
* @param repo Repository pointer
|
||||
* @param commitish Object id of the Commit the HEAD should point to
|
||||
* @return 0 on success, or an error code
|
||||
*/
|
||||
GIT_EXTERN(int) git_repository_set_head_detached(
|
||||
git_repository* repo,
|
||||
const git_oid* commitish);
|
||||
|
||||
/**
|
||||
* Detach the HEAD.
|
||||
*
|
||||
* If the HEAD is already detached and points to a Commit, 0 is returned.
|
||||
*
|
||||
* If the HEAD is already detached and points to a Tag, the HEAD is
|
||||
* updated into making it point to the peeled Commit, and 0 is returned.
|
||||
*
|
||||
* If the HEAD is already detached and points to a non commitish, the HEAD is
|
||||
* unaltered, and -1 is returned.
|
||||
*
|
||||
* Otherwise, the HEAD will be detached and point to the peeled Commit.
|
||||
*
|
||||
* @param repo Repository pointer
|
||||
* @return 0 on success, GIT_EORPHANEDHEAD when HEAD points to a non existing
|
||||
* branch or an error code
|
||||
*/
|
||||
GIT_EXTERN(int) git_repository_detach_head(
|
||||
git_repository* repo);
|
||||
|
||||
typedef enum {
|
||||
GIT_REPOSITORY_STATE_NONE,
|
||||
GIT_REPOSITORY_STATE_MERGE,
|
||||
GIT_REPOSITORY_STATE_REVERT,
|
||||
GIT_REPOSITORY_STATE_CHERRY_PICK,
|
||||
GIT_REPOSITORY_STATE_BISECT,
|
||||
GIT_REPOSITORY_STATE_REBASE,
|
||||
GIT_REPOSITORY_STATE_REBASE_INTERACTIVE,
|
||||
GIT_REPOSITORY_STATE_REBASE_MERGE,
|
||||
GIT_REPOSITORY_STATE_APPLY_MAILBOX,
|
||||
GIT_REPOSITORY_STATE_APPLY_MAILBOX_OR_REBASE,
|
||||
} git_repository_state_t;
|
||||
|
||||
/**
|
||||
* Determines the status of a git repository - ie, whether an operation
|
||||
* (merge, cherry-pick, etc) is in progress.
|
||||
*
|
||||
* @param repo Repository pointer
|
||||
* @return The state of the repository
|
||||
*/
|
||||
GIT_EXTERN(int) git_repository_state(git_repository *repo);
|
||||
|
||||
/** @} */
|
||||
GIT_END_DECL
|
||||
#endif
|
||||
@@ -1,58 +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_reset_h__
|
||||
#define INCLUDE_git_reset_h__
|
||||
|
||||
/**
|
||||
* @file git2/reset.h
|
||||
* @brief Git reset management routines
|
||||
* @ingroup Git
|
||||
* @{
|
||||
*/
|
||||
GIT_BEGIN_DECL
|
||||
|
||||
/**
|
||||
* Kinds of reset operation
|
||||
*/
|
||||
typedef enum {
|
||||
GIT_RESET_SOFT = 1, /** Move the head to the given commit */
|
||||
GIT_RESET_MIXED = 2, /** SOFT plus reset index to the commit */
|
||||
GIT_RESET_HARD = 3, /** MIXED plus changes in working tree discarded */
|
||||
} git_reset_t;
|
||||
|
||||
/**
|
||||
* Sets the current head to the specified commit oid and optionally
|
||||
* resets the index and working tree to match.
|
||||
*
|
||||
* SOFT reset means the head will be moved to the commit.
|
||||
*
|
||||
* MIXED reset will trigger a SOFT reset, plus the index will be replaced
|
||||
* with the content of the commit tree.
|
||||
*
|
||||
* HARD reset will trigger a MIXED reset and the working directory will be
|
||||
* replaced with the content of the index. (Untracked and ignored files
|
||||
* will be left alone, however.)
|
||||
*
|
||||
* TODO: Implement remaining kinds of resets.
|
||||
*
|
||||
* @param repo Repository where to perform the reset operation.
|
||||
*
|
||||
* @param target Object to which the Head should be moved to. This object
|
||||
* must belong to the given `repo` and can either be a git_commit or a
|
||||
* git_tag. When a git_tag is being passed, it should be dereferencable
|
||||
* to a git_commit which oid will be used as the target of the branch.
|
||||
*
|
||||
* @param reset_type Kind of reset operation to perform.
|
||||
*
|
||||
* @return 0 on success or an error code < 0
|
||||
*/
|
||||
GIT_EXTERN(int) git_reset(
|
||||
git_repository *repo, git_object *target, git_reset_t reset_type);
|
||||
|
||||
/** @} */
|
||||
GIT_END_DECL
|
||||
#endif
|
||||
@@ -1,37 +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_revparse_h__
|
||||
#define INCLUDE_git_revparse_h__
|
||||
|
||||
#include "common.h"
|
||||
#include "types.h"
|
||||
|
||||
|
||||
/**
|
||||
* @file git2/revparse.h
|
||||
* @brief Git revision parsing routines
|
||||
* @defgroup git_revparse Git revision parsing routines
|
||||
* @ingroup Git
|
||||
* @{
|
||||
*/
|
||||
GIT_BEGIN_DECL
|
||||
|
||||
/**
|
||||
* Find an object, as specified by a revision string. See `man gitrevisions`, or the documentation
|
||||
* for `git rev-parse` for information on the syntax accepted.
|
||||
*
|
||||
* @param out pointer to output object
|
||||
* @param repo the repository to search in
|
||||
* @param spec the textual specification for an object
|
||||
* @return 0 on success, GIT_ENOTFOUND, GIT_EAMBIGUOUS,
|
||||
* GIT_EINVALIDSPEC or an error code
|
||||
*/
|
||||
GIT_EXTERN(int) git_revparse_single(git_object **out, git_repository *repo, const char *spec);
|
||||
|
||||
/** @} */
|
||||
GIT_END_DECL
|
||||
#endif
|
||||
@@ -1,237 +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_revwalk_h__
|
||||
#define INCLUDE_git_revwalk_h__
|
||||
|
||||
#include "common.h"
|
||||
#include "types.h"
|
||||
#include "oid.h"
|
||||
|
||||
/**
|
||||
* @file git2/revwalk.h
|
||||
* @brief Git revision traversal routines
|
||||
* @defgroup git_revwalk Git revision traversal routines
|
||||
* @ingroup Git
|
||||
* @{
|
||||
*/
|
||||
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.
|
||||
*/
|
||||
#define 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 by commit time;
|
||||
* this sorting mode can be combined with
|
||||
* topological sorting.
|
||||
*/
|
||||
#define 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)
|
||||
|
||||
/**
|
||||
* Allocate a new revision walker to iterate through a repo.
|
||||
*
|
||||
* This revision walker uses a custom memory pool and an internal
|
||||
* commit cache, so it is relatively expensive to allocate.
|
||||
*
|
||||
* For maximum performance, this revision walker should be
|
||||
* reused for different walks.
|
||||
*
|
||||
* This revision walker is *not* thread safe: it may only be
|
||||
* used to walk a repository on a single thread; however,
|
||||
* it is possible to have several revision walkers in
|
||||
* several different threads walking the same repository.
|
||||
*
|
||||
* @param out pointer to the new revision walker
|
||||
* @param repo the repo to walk through
|
||||
* @return 0 or an error code
|
||||
*/
|
||||
GIT_EXTERN(int) git_revwalk_new(git_revwalk **out, git_repository *repo);
|
||||
|
||||
/**
|
||||
* Reset the revision walker for reuse.
|
||||
*
|
||||
* This will clear all the pushed and hidden commits, and
|
||||
* leave the walker in a blank state (just like at
|
||||
* creation) ready to receive new commit pushes and
|
||||
* start a new walk.
|
||||
*
|
||||
* The revision walk is automatically reset when a walk
|
||||
* is over.
|
||||
*
|
||||
* @param walker handle to reset.
|
||||
*/
|
||||
GIT_EXTERN(void) git_revwalk_reset(git_revwalk *walker);
|
||||
|
||||
/**
|
||||
* Mark a commit to start traversal from.
|
||||
*
|
||||
* The given OID must belong to a commit 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 the repository 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
|
||||
*/
|
||||
GIT_EXTERN(int) git_revwalk_push(git_revwalk *walk, const git_oid *id);
|
||||
|
||||
/**
|
||||
* Push matching references
|
||||
*
|
||||
* The OIDs pointed to by the references that match the given glob
|
||||
* pattern will be pushed to the revision walker.
|
||||
*
|
||||
* A leading 'refs/' is implied if not present as well as a trailing
|
||||
* '/ *' if the glob lacks '?', '*' or '['.
|
||||
*
|
||||
* @param walk the walker being used for the traversal
|
||||
* @param glob the glob pattern references should match
|
||||
* @return 0 or an error code
|
||||
*/
|
||||
GIT_EXTERN(int) git_revwalk_push_glob(git_revwalk *walk, const char *glob);
|
||||
|
||||
/**
|
||||
* Push the repository's HEAD
|
||||
*
|
||||
* @param walk the walker being used for the traversal
|
||||
* @return 0 or an error code
|
||||
*/
|
||||
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 commit on the walked
|
||||
* repository.
|
||||
*
|
||||
* The resolved commit and all its parents will be hidden from the
|
||||
* output on the revision walk.
|
||||
*
|
||||
* @param walk the walker being used for the traversal.
|
||||
* @param commit_id the oid of commit that will be ignored during the traversal
|
||||
* @return 0 or an error code
|
||||
*/
|
||||
GIT_EXTERN(int) git_revwalk_hide(git_revwalk *walk, const git_oid *commit_id);
|
||||
|
||||
/**
|
||||
* Hide matching references.
|
||||
*
|
||||
* The OIDs pointed to by the references that match the given glob
|
||||
* pattern and their ancestors will be hidden from the output on the
|
||||
* revision walk.
|
||||
*
|
||||
* A leading 'refs/' is implied if not present as well as a trailing
|
||||
* '/ *' if the glob lacks '?', '*' or '['.
|
||||
*
|
||||
* @param walk the walker being used for the traversal
|
||||
* @param glob the glob pattern references should match
|
||||
* @return 0 or an error code
|
||||
*/
|
||||
GIT_EXTERN(int) git_revwalk_hide_glob(git_revwalk *walk, const char *glob);
|
||||
|
||||
/**
|
||||
* Hide the repository's HEAD
|
||||
*
|
||||
* @param walk the walker being used for the traversal
|
||||
* @return 0 or an error code
|
||||
*/
|
||||
GIT_EXTERN(int) git_revwalk_hide_head(git_revwalk *walk);
|
||||
|
||||
/**
|
||||
* Push the OID pointed to by a reference
|
||||
*
|
||||
* The reference must point to a commit.
|
||||
*
|
||||
* @param walk the walker being used for the traversal
|
||||
* @param refname the reference to push
|
||||
* @return 0 or an error code
|
||||
*/
|
||||
GIT_EXTERN(int) git_revwalk_push_ref(git_revwalk *walk, const char *refname);
|
||||
|
||||
/**
|
||||
* Hide the OID pointed to by a reference
|
||||
*
|
||||
* The reference must point to a commit.
|
||||
*
|
||||
* @param walk the walker being used for the traversal
|
||||
* @param refname the reference to hide
|
||||
* @return 0 or an error code
|
||||
*/
|
||||
GIT_EXTERN(int) git_revwalk_hide_ref(git_revwalk *walk, const char *refname);
|
||||
|
||||
/**
|
||||
* Get the next commit from the revision walk.
|
||||
*
|
||||
* The initial call to this method is *not* blocking when
|
||||
* iterating through a repo with a time-sorting mode.
|
||||
*
|
||||
* Iterating with Topological or inverted modes makes the initial
|
||||
* call blocking to preprocess the commit list, but this block should be
|
||||
* mostly unnoticeable on most repositories (topological preprocessing
|
||||
* times at 0.3s on the git.git repo).
|
||||
*
|
||||
* The revision walker is reset when the walk is over.
|
||||
*
|
||||
* @param out Pointer where to store the oid of the next commit
|
||||
* @param walk the walker to pop the commit from.
|
||||
* @return 0 if the next commit was found;
|
||||
* GIT_ITEROVER if there are no commits left to iterate
|
||||
*/
|
||||
GIT_EXTERN(int) git_revwalk_next(git_oid *out, git_revwalk *walk);
|
||||
|
||||
/**
|
||||
* Change the sorting mode when iterating through the
|
||||
* repository's contents.
|
||||
*
|
||||
* Changing the sorting mode resets the walker.
|
||||
*
|
||||
* @param walk the walker being used for the traversal.
|
||||
* @param sort_mode combination of GIT_SORT_XXX flags
|
||||
*/
|
||||
GIT_EXTERN(void) git_revwalk_sorting(git_revwalk *walk, unsigned int sort_mode);
|
||||
|
||||
/**
|
||||
* Free a revision walker previously allocated.
|
||||
*
|
||||
* @param walk traversal handle to close. If NULL nothing occurs.
|
||||
*/
|
||||
GIT_EXTERN(void) git_revwalk_free(git_revwalk *walk);
|
||||
|
||||
/**
|
||||
* Return the repository on which this walker
|
||||
* is operating.
|
||||
*
|
||||
* @param walk the revision walker
|
||||
* @return the repository being walked
|
||||
*/
|
||||
GIT_EXTERN(git_repository *) git_revwalk_repository(git_revwalk *walk);
|
||||
|
||||
/** @} */
|
||||
GIT_END_DECL
|
||||
#endif
|
||||
@@ -1,76 +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_signature_h__
|
||||
#define INCLUDE_git_signature_h__
|
||||
|
||||
#include "common.h"
|
||||
#include "types.h"
|
||||
|
||||
/**
|
||||
* @file git2/signature.h
|
||||
* @brief Git signature creation
|
||||
* @defgroup git_signature Git signature creation
|
||||
* @ingroup Git
|
||||
* @{
|
||||
*/
|
||||
GIT_BEGIN_DECL
|
||||
|
||||
/**
|
||||
* Create a new action signature.
|
||||
*
|
||||
* Call `git_signature_free()` to free the data.
|
||||
*
|
||||
* Note: angle brackets ('<' and '>') characters are not allowed
|
||||
* to be used in either the `name` or the `email` parameter.
|
||||
*
|
||||
* @param out new signature, in case of error NULL
|
||||
* @param name name of the person
|
||||
* @param email email of the person
|
||||
* @param time time when the action happened
|
||||
* @param offset timezone offset in minutes for the time
|
||||
* @return 0 or an error code
|
||||
*/
|
||||
GIT_EXTERN(int) git_signature_new(git_signature **out, const char *name, const char *email, git_time_t time, int offset);
|
||||
|
||||
/**
|
||||
* Create a new action signature with a timestamp of 'now'.
|
||||
*
|
||||
* Call `git_signature_free()` to free the data.
|
||||
*
|
||||
* @param out new signature, in case of error NULL
|
||||
* @param name name of the person
|
||||
* @param email email of the person
|
||||
* @return 0 or an error code
|
||||
*/
|
||||
GIT_EXTERN(int) git_signature_now(git_signature **out, const char *name, const char *email);
|
||||
|
||||
|
||||
/**
|
||||
* Create a copy of an existing signature. All internal strings are also
|
||||
* duplicated.
|
||||
*
|
||||
* Call `git_signature_free()` to free the data.
|
||||
*
|
||||
* @param sig signature to duplicated
|
||||
* @return a copy of sig, NULL on out of memory
|
||||
*/
|
||||
GIT_EXTERN(git_signature *) git_signature_dup(const git_signature *sig);
|
||||
|
||||
/**
|
||||
* Free an existing signature.
|
||||
*
|
||||
* Because the signature is not an opaque structure, it is legal to free it
|
||||
* manually, but be sure to free the "name" and "email" strings in addition
|
||||
* to the structure itself.
|
||||
*
|
||||
* @param sig signature to free
|
||||
*/
|
||||
GIT_EXTERN(void) git_signature_free(git_signature *sig);
|
||||
|
||||
/** @} */
|
||||
GIT_END_DECL
|
||||
#endif
|
||||
@@ -1,121 +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_stash_h__
|
||||
#define INCLUDE_git_stash_h__
|
||||
|
||||
#include "common.h"
|
||||
#include "types.h"
|
||||
|
||||
/**
|
||||
* @file git2/stash.h
|
||||
* @brief Git stash management routines
|
||||
* @ingroup Git
|
||||
* @{
|
||||
*/
|
||||
GIT_BEGIN_DECL
|
||||
|
||||
typedef enum {
|
||||
GIT_STASH_DEFAULT = 0,
|
||||
|
||||
/* All changes already added to the index
|
||||
* are left intact in the working directory
|
||||
*/
|
||||
GIT_STASH_KEEP_INDEX = (1 << 0),
|
||||
|
||||
/* All untracked files are also stashed and then
|
||||
* cleaned up from the working directory
|
||||
*/
|
||||
GIT_STASH_INCLUDE_UNTRACKED = (1 << 1),
|
||||
|
||||
/* All ignored files are also stashed and then
|
||||
* cleaned up from the working directory
|
||||
*/
|
||||
GIT_STASH_INCLUDE_IGNORED = (1 << 2),
|
||||
} git_stash_flags;
|
||||
|
||||
/**
|
||||
* Save the local modifications to a new stash.
|
||||
*
|
||||
* @param out Object id of the commit containing the stashed state.
|
||||
* This commit is also the target of the direct reference refs/stash.
|
||||
*
|
||||
* @param repo The owning repository.
|
||||
*
|
||||
* @param stasher The identity of the person performing the stashing.
|
||||
*
|
||||
* @param message Optional description along with the stashed state.
|
||||
*
|
||||
* @param flags Flags to control the stashing process. (see GIT_STASH_* above)
|
||||
*
|
||||
* @return 0 on success, GIT_ENOTFOUND where there's nothing to stash,
|
||||
* or error code.
|
||||
*/
|
||||
GIT_EXTERN(int) git_stash_save(
|
||||
git_oid *out,
|
||||
git_repository *repo,
|
||||
git_signature *stasher,
|
||||
const char *message,
|
||||
unsigned int flags);
|
||||
|
||||
/**
|
||||
* When iterating over all the stashed states, callback that will be
|
||||
* issued per entry.
|
||||
*
|
||||
* @param index The position within the stash list. 0 points to the
|
||||
* most recent stashed state.
|
||||
*
|
||||
* @param message The stash message.
|
||||
*
|
||||
* @param stash_id The commit oid of the stashed state.
|
||||
*
|
||||
* @param payload Extra parameter to callback function.
|
||||
*
|
||||
* @return 0 on success, GIT_EUSER on non-zero callback, or error code
|
||||
*/
|
||||
typedef int (*git_stash_cb)(
|
||||
size_t index,
|
||||
const char* message,
|
||||
const git_oid *stash_id,
|
||||
void *payload);
|
||||
|
||||
/**
|
||||
* Loop over all the stashed states and issue a callback for each one.
|
||||
*
|
||||
* If the callback returns a non-zero value, this will stop looping.
|
||||
*
|
||||
* @param repo Repository where to find the stash.
|
||||
*
|
||||
* @param callabck Callback to invoke per found stashed state. The most recent
|
||||
* stash state will be enumerated first.
|
||||
*
|
||||
* @param payload Extra parameter to callback function.
|
||||
*
|
||||
* @return 0 on success, GIT_EUSER on non-zero callback, or error code
|
||||
*/
|
||||
GIT_EXTERN(int) git_stash_foreach(
|
||||
git_repository *repo,
|
||||
git_stash_cb callback,
|
||||
void *payload);
|
||||
|
||||
/**
|
||||
* Remove a single stashed state from the stash list.
|
||||
*
|
||||
* @param repo The owning repository.
|
||||
*
|
||||
* @param index The position within the stash list. 0 points to the
|
||||
* most recent stashed state.
|
||||
*
|
||||
* @return 0 on success, or error code
|
||||
*/
|
||||
|
||||
GIT_EXTERN(int) git_stash_drop(
|
||||
git_repository *repo,
|
||||
size_t index);
|
||||
|
||||
/** @} */
|
||||
GIT_END_DECL
|
||||
#endif
|
||||
@@ -1,231 +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_status_h__
|
||||
#define INCLUDE_git_status_h__
|
||||
|
||||
#include "common.h"
|
||||
#include "types.h"
|
||||
|
||||
/**
|
||||
* @file git2/status.h
|
||||
* @brief Git file status routines
|
||||
* @defgroup git_status Git file status routines
|
||||
* @ingroup Git
|
||||
* @{
|
||||
*/
|
||||
GIT_BEGIN_DECL
|
||||
|
||||
/**
|
||||
* Status flags for a single file.
|
||||
*
|
||||
* A combination of these values will be returned to indicate the status of
|
||||
* a file. Status compares the working directory, the index, and the
|
||||
* current HEAD of the repository. The `GIT_STATUS_INDEX` set of flags
|
||||
* represents the status of file in the index relative to the HEAD, and the
|
||||
* `GIT_STATUS_WT` set of flags represent the status of the file in the
|
||||
* working directory relative to the index.
|
||||
*/
|
||||
typedef enum {
|
||||
GIT_STATUS_CURRENT = 0,
|
||||
|
||||
GIT_STATUS_INDEX_NEW = (1u << 0),
|
||||
GIT_STATUS_INDEX_MODIFIED = (1u << 1),
|
||||
GIT_STATUS_INDEX_DELETED = (1u << 2),
|
||||
GIT_STATUS_INDEX_RENAMED = (1u << 3),
|
||||
GIT_STATUS_INDEX_TYPECHANGE = (1u << 4),
|
||||
|
||||
GIT_STATUS_WT_NEW = (1u << 7),
|
||||
GIT_STATUS_WT_MODIFIED = (1u << 8),
|
||||
GIT_STATUS_WT_DELETED = (1u << 9),
|
||||
GIT_STATUS_WT_TYPECHANGE = (1u << 10),
|
||||
|
||||
GIT_STATUS_IGNORED = (1u << 14),
|
||||
} git_status_t;
|
||||
|
||||
/**
|
||||
* Function pointer to receive status on individual files
|
||||
*
|
||||
* `path` is the relative path to the file from the root of the repository.
|
||||
*
|
||||
* `status_flags` is a combination of `git_status_t` values that apply.
|
||||
*
|
||||
* `payload` is the value you passed to the foreach function as payload.
|
||||
*/
|
||||
typedef int (*git_status_cb)(
|
||||
const char *path, unsigned int status_flags, void *payload);
|
||||
|
||||
/**
|
||||
* Gather file statuses and run a callback for each one.
|
||||
*
|
||||
* The callback is passed the path of the file, the status (a combination of
|
||||
* the `git_status_t` values above) and the `payload` data pointer passed
|
||||
* into this function.
|
||||
*
|
||||
* If the callback returns a non-zero value, this function will stop looping
|
||||
* and return GIT_EUSER.
|
||||
*
|
||||
* @param repo A repository object
|
||||
* @param callback The function to call on each file
|
||||
* @param payload Pointer to pass through to callback function
|
||||
* @return 0 on success, GIT_EUSER on non-zero callback, or error code
|
||||
*/
|
||||
GIT_EXTERN(int) git_status_foreach(
|
||||
git_repository *repo,
|
||||
git_status_cb callback,
|
||||
void *payload);
|
||||
|
||||
/**
|
||||
* For extended status, select the files on which to report status.
|
||||
*
|
||||
* - GIT_STATUS_SHOW_INDEX_AND_WORKDIR is the default. This is the
|
||||
* rough equivalent of `git status --porcelain` where each file
|
||||
* will receive a callback indicating its status in the index and
|
||||
* in the workdir.
|
||||
* - GIT_STATUS_SHOW_INDEX_ONLY will only make callbacks for index
|
||||
* side of status. The status of the index contents relative to
|
||||
* the HEAD will be given.
|
||||
* - GIT_STATUS_SHOW_WORKDIR_ONLY will only make callbacks for the
|
||||
* workdir side of status, reporting the status of workdir content
|
||||
* relative to the index.
|
||||
* - GIT_STATUS_SHOW_INDEX_THEN_WORKDIR behaves like index-only
|
||||
* followed by workdir-only, causing two callbacks to be issued
|
||||
* per file (first index then workdir). This is slightly more
|
||||
* efficient than making separate calls. This makes it easier to
|
||||
* emulate the output of a plain `git status`.
|
||||
*/
|
||||
typedef enum {
|
||||
GIT_STATUS_SHOW_INDEX_AND_WORKDIR = 0,
|
||||
GIT_STATUS_SHOW_INDEX_ONLY = 1,
|
||||
GIT_STATUS_SHOW_WORKDIR_ONLY = 2,
|
||||
GIT_STATUS_SHOW_INDEX_THEN_WORKDIR = 3,
|
||||
} git_status_show_t;
|
||||
|
||||
/**
|
||||
* Flags to control status callbacks
|
||||
*
|
||||
* - GIT_STATUS_OPT_INCLUDE_UNTRACKED says that callbacks should be made
|
||||
* on untracked files. These will only be made if the workdir files are
|
||||
* included in the status "show" option.
|
||||
* - GIT_STATUS_OPT_INCLUDE_IGNORED says that ignored files should get
|
||||
* callbacks. Again, these callbacks will only be made if the workdir
|
||||
* files are included in the status "show" option. Right now, there is
|
||||
* no option to include all files in directories that are ignored
|
||||
* completely.
|
||||
* - GIT_STATUS_OPT_INCLUDE_UNMODIFIED indicates that callback should be
|
||||
* made even on unmodified files.
|
||||
* - GIT_STATUS_OPT_EXCLUDE_SUBMODULES indicates that directories which
|
||||
* appear to be submodules should just be skipped over.
|
||||
* - GIT_STATUS_OPT_RECURSE_UNTRACKED_DIRS indicates that the contents of
|
||||
* untracked directories should be included in the status. Normally if
|
||||
* an entire directory is new, then just the top-level directory will be
|
||||
* included (with a trailing slash on the entry name). Given this flag,
|
||||
* the directory itself will not be included, but all the files in it
|
||||
* will.
|
||||
* - GIT_STATUS_OPT_DISABLE_PATHSPEC_MATCH indicates that the given path
|
||||
* will be treated as a literal path, and not as a pathspec.
|
||||
*
|
||||
* Calling `git_status_foreach()` is like calling the extended version
|
||||
* with: GIT_STATUS_OPT_INCLUDE_IGNORED, GIT_STATUS_OPT_INCLUDE_UNTRACKED,
|
||||
* and GIT_STATUS_OPT_RECURSE_UNTRACKED_DIRS.
|
||||
*/
|
||||
typedef enum {
|
||||
GIT_STATUS_OPT_INCLUDE_UNTRACKED = (1 << 0),
|
||||
GIT_STATUS_OPT_INCLUDE_IGNORED = (1 << 1),
|
||||
GIT_STATUS_OPT_INCLUDE_UNMODIFIED = (1 << 2),
|
||||
GIT_STATUS_OPT_EXCLUDE_SUBMODULES = (1 << 3),
|
||||
GIT_STATUS_OPT_RECURSE_UNTRACKED_DIRS = (1 << 4),
|
||||
GIT_STATUS_OPT_DISABLE_PATHSPEC_MATCH = (1 << 5),
|
||||
} git_status_opt_t;
|
||||
|
||||
/**
|
||||
* Options to control how `git_status_foreach_ext()` will issue callbacks.
|
||||
*
|
||||
* This structure is set so that zeroing it out will give you relatively
|
||||
* sane defaults.
|
||||
*
|
||||
* The `show` value is one of the `git_status_show_t` constants that
|
||||
* control which files to scan and in what order.
|
||||
*
|
||||
* The `flags` value is an OR'ed combination of the `git_status_opt_t`
|
||||
* values above.
|
||||
*
|
||||
* The `pathspec` is an array of path patterns to match (using
|
||||
* fnmatch-style matching), or just an array of paths to match exactly if
|
||||
* `GIT_STATUS_OPT_DISABLE_PATHSPEC_MATCH` is specified in the flags.
|
||||
*/
|
||||
typedef struct {
|
||||
unsigned int version;
|
||||
git_status_show_t show;
|
||||
unsigned int flags;
|
||||
git_strarray pathspec;
|
||||
} git_status_options;
|
||||
|
||||
#define GIT_STATUS_OPTIONS_VERSION 1
|
||||
#define GIT_STATUS_OPTIONS_INIT {GIT_STATUS_OPTIONS_VERSION}
|
||||
|
||||
/**
|
||||
* Gather file status information and run callbacks as requested.
|
||||
*
|
||||
* This is an extended version of the `git_status_foreach()` API that
|
||||
* allows for more granular control over which paths will be processed and
|
||||
* in what order. See the `git_status_options` structure for details
|
||||
* about the additional controls that this makes available.
|
||||
*
|
||||
* @param repo Repository object
|
||||
* @param opts Status options structure
|
||||
* @param callback The function to call on each file
|
||||
* @param payload Pointer to pass through to callback function
|
||||
* @return 0 on success, GIT_EUSER on non-zero callback, or error code
|
||||
*/
|
||||
GIT_EXTERN(int) git_status_foreach_ext(
|
||||
git_repository *repo,
|
||||
const git_status_options *opts,
|
||||
git_status_cb callback,
|
||||
void *payload);
|
||||
|
||||
/**
|
||||
* Get file status for a single file.
|
||||
*
|
||||
* This is not quite the same as calling `git_status_foreach_ext()` with
|
||||
* the pathspec set to the specified path.
|
||||
*
|
||||
* @param status_flags The status value for the file
|
||||
* @param repo A repository object
|
||||
* @param path The file to retrieve status for, rooted at the repo's workdir
|
||||
* @return 0 on success, GIT_ENOTFOUND if the file is not found in the HEAD,
|
||||
* index, and work tree, GIT_EINVALIDPATH if `path` points at a folder,
|
||||
* GIT_EAMBIGUOUS if "path" matches multiple files, -1 on other error.
|
||||
*/
|
||||
GIT_EXTERN(int) git_status_file(
|
||||
unsigned int *status_flags,
|
||||
git_repository *repo,
|
||||
const char *path);
|
||||
|
||||
/**
|
||||
* Test if the ignore rules apply to a given file.
|
||||
*
|
||||
* This function checks the ignore rules to see if they would apply to the
|
||||
* given file. This indicates if the file would be ignored regardless of
|
||||
* whether the file is already in the index or committed to the repository.
|
||||
*
|
||||
* One way to think of this is if you were to do "git add ." on the
|
||||
* directory containing the file, would it be added or not?
|
||||
*
|
||||
* @param ignored Boolean returning 0 if the file is not ignored, 1 if it is
|
||||
* @param repo A repository object
|
||||
* @param path The file to check ignores for, rooted at the repo's workdir.
|
||||
* @return 0 if ignore rules could be processed for the file (regardless
|
||||
* of whether it exists or not), or an error < 0 if they could not.
|
||||
*/
|
||||
GIT_EXTERN(int) git_status_should_ignore(
|
||||
int *ignored,
|
||||
git_repository *repo,
|
||||
const char *path);
|
||||
|
||||
/** @} */
|
||||
GIT_END_DECL
|
||||
#endif
|
||||
@@ -1,60 +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_strarray_h__
|
||||
#define INCLUDE_git_strarray_h__
|
||||
|
||||
#include "common.h"
|
||||
|
||||
/**
|
||||
* @file git2/strarray.h
|
||||
* @brief Git string array routines
|
||||
* @defgroup git_strarray Git string array routines
|
||||
* @ingroup Git
|
||||
* @{
|
||||
*/
|
||||
GIT_BEGIN_DECL
|
||||
|
||||
/** Array of strings */
|
||||
typedef struct git_strarray {
|
||||
char **strings;
|
||||
size_t count;
|
||||
} git_strarray;
|
||||
|
||||
/**
|
||||
* Close a string array object
|
||||
*
|
||||
* This method should be called on `git_strarray` objects where the strings
|
||||
* array is allocated and contains allocated strings, such as what you
|
||||
* would get from `git_strarray_copy()`. Not doing so, will result in a
|
||||
* memory leak.
|
||||
*
|
||||
* This does not free the `git_strarray` 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_strarray from which to free string data
|
||||
*/
|
||||
GIT_EXTERN(void) git_strarray_free(git_strarray *array);
|
||||
|
||||
/**
|
||||
* Copy a string array object from source to target.
|
||||
*
|
||||
* Note: target is overwritten and hence should be empty,
|
||||
* otherwise its contents are leaked.
|
||||
*
|
||||
* @param tgt target
|
||||
* @param src source
|
||||
* @return 0 on success, < 0 on allocation failure
|
||||
*/
|
||||
GIT_EXTERN(int) git_strarray_copy(git_strarray *tgt, const git_strarray *src);
|
||||
|
||||
|
||||
/** @} */
|
||||
GIT_END_DECL
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,527 +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_submodule_h__
|
||||
#define INCLUDE_git_submodule_h__
|
||||
|
||||
#include "common.h"
|
||||
#include "types.h"
|
||||
#include "oid.h"
|
||||
|
||||
/**
|
||||
* @file git2/submodule.h
|
||||
* @brief Git submodule management utilities
|
||||
* @defgroup git_submodule Git submodule management routines
|
||||
* @ingroup Git
|
||||
* @{
|
||||
*/
|
||||
GIT_BEGIN_DECL
|
||||
|
||||
/**
|
||||
* Opaque structure representing a submodule.
|
||||
*
|
||||
* Submodule support in libgit2 builds a list of known submodules and keeps
|
||||
* it in the repository. The list is built from the .gitmodules file, the
|
||||
* .git/config file, the index, and the HEAD tree. Items in the working
|
||||
* directory that look like submodules (i.e. a git repo) but are not
|
||||
* mentioned in those places won't be tracked.
|
||||
*/
|
||||
typedef struct git_submodule git_submodule;
|
||||
|
||||
/**
|
||||
* Values that could be specified for the update rule of a submodule.
|
||||
*
|
||||
* Use the DEFAULT value if you have altered the update value via
|
||||
* `git_submodule_set_update()` and wish to reset to the original default.
|
||||
*/
|
||||
typedef enum {
|
||||
GIT_SUBMODULE_UPDATE_DEFAULT = -1,
|
||||
GIT_SUBMODULE_UPDATE_CHECKOUT = 0,
|
||||
GIT_SUBMODULE_UPDATE_REBASE = 1,
|
||||
GIT_SUBMODULE_UPDATE_MERGE = 2,
|
||||
GIT_SUBMODULE_UPDATE_NONE = 3
|
||||
} git_submodule_update_t;
|
||||
|
||||
/**
|
||||
* Values that could be specified for how closely to examine the
|
||||
* working directory when getting submodule status.
|
||||
*
|
||||
* Use the DEFUALT value if you have altered the ignore value via
|
||||
* `git_submodule_set_ignore()` and wish to reset to the original value.
|
||||
*/
|
||||
typedef enum {
|
||||
GIT_SUBMODULE_IGNORE_DEFAULT = -1, /* reset to default */
|
||||
GIT_SUBMODULE_IGNORE_NONE = 0, /* any change or untracked == dirty */
|
||||
GIT_SUBMODULE_IGNORE_UNTRACKED = 1, /* dirty if tracked files change */
|
||||
GIT_SUBMODULE_IGNORE_DIRTY = 2, /* only dirty if HEAD moved */
|
||||
GIT_SUBMODULE_IGNORE_ALL = 3 /* never dirty */
|
||||
} git_submodule_ignore_t;
|
||||
|
||||
/**
|
||||
* Return codes for submodule status.
|
||||
*
|
||||
* A combination of these flags will be returned to describe the status of a
|
||||
* submodule. Depending on the "ignore" property of the submodule, some of
|
||||
* the flags may never be returned because they indicate changes that are
|
||||
* supposed to be ignored.
|
||||
*
|
||||
* Submodule info is contained in 4 places: the HEAD tree, the index, config
|
||||
* files (both .git/config and .gitmodules), and the working directory. Any
|
||||
* or all of those places might be missing information about the submodule
|
||||
* depending on what state the repo is in. We consider all four places to
|
||||
* build the combination of status flags.
|
||||
*
|
||||
* There are four values that are not really status, but give basic info
|
||||
* about what sources of submodule data are available. These will be
|
||||
* returned even if ignore is set to "ALL".
|
||||
*
|
||||
* * IN_HEAD - superproject head contains submodule
|
||||
* * IN_INDEX - superproject index contains submodule
|
||||
* * IN_CONFIG - superproject gitmodules has submodule
|
||||
* * IN_WD - superproject workdir has submodule
|
||||
*
|
||||
* The following values will be returned so long as ignore is not "ALL".
|
||||
*
|
||||
* * INDEX_ADDED - in index, not in head
|
||||
* * INDEX_DELETED - in head, not in index
|
||||
* * INDEX_MODIFIED - index and head don't match
|
||||
* * WD_UNINITIALIZED - workdir contains empty directory
|
||||
* * WD_ADDED - in workdir, not index
|
||||
* * WD_DELETED - in index, not workdir
|
||||
* * WD_MODIFIED - index and workdir head don't match
|
||||
*
|
||||
* The following can only be returned if ignore is "NONE" or "UNTRACKED".
|
||||
*
|
||||
* * WD_INDEX_MODIFIED - submodule workdir index is dirty
|
||||
* * WD_WD_MODIFIED - submodule workdir has modified files
|
||||
*
|
||||
* Lastly, the following will only be returned for ignore "NONE".
|
||||
*
|
||||
* * WD_UNTRACKED - wd contains untracked files
|
||||
*/
|
||||
typedef enum {
|
||||
GIT_SUBMODULE_STATUS_IN_HEAD = (1u << 0),
|
||||
GIT_SUBMODULE_STATUS_IN_INDEX = (1u << 1),
|
||||
GIT_SUBMODULE_STATUS_IN_CONFIG = (1u << 2),
|
||||
GIT_SUBMODULE_STATUS_IN_WD = (1u << 3),
|
||||
GIT_SUBMODULE_STATUS_INDEX_ADDED = (1u << 4),
|
||||
GIT_SUBMODULE_STATUS_INDEX_DELETED = (1u << 5),
|
||||
GIT_SUBMODULE_STATUS_INDEX_MODIFIED = (1u << 6),
|
||||
GIT_SUBMODULE_STATUS_WD_UNINITIALIZED = (1u << 7),
|
||||
GIT_SUBMODULE_STATUS_WD_ADDED = (1u << 8),
|
||||
GIT_SUBMODULE_STATUS_WD_DELETED = (1u << 9),
|
||||
GIT_SUBMODULE_STATUS_WD_MODIFIED = (1u << 10),
|
||||
GIT_SUBMODULE_STATUS_WD_INDEX_MODIFIED = (1u << 11),
|
||||
GIT_SUBMODULE_STATUS_WD_WD_MODIFIED = (1u << 12),
|
||||
GIT_SUBMODULE_STATUS_WD_UNTRACKED = (1u << 13),
|
||||
} git_submodule_status_t;
|
||||
|
||||
#define GIT_SUBMODULE_STATUS_IS_UNMODIFIED(S) \
|
||||
(((S) & ~(GIT_SUBMODULE_STATUS_IN_HEAD | \
|
||||
GIT_SUBMODULE_STATUS_IN_INDEX | \
|
||||
GIT_SUBMODULE_STATUS_IN_CONFIG | \
|
||||
GIT_SUBMODULE_STATUS_IN_WD)) == 0)
|
||||
|
||||
#define GIT_SUBMODULE_STATUS_IS_WD_DIRTY(S) \
|
||||
(((S) & (GIT_SUBMODULE_STATUS_WD_INDEX_MODIFIED | \
|
||||
GIT_SUBMODULE_STATUS_WD_WD_MODIFIED | \
|
||||
GIT_SUBMODULE_STATUS_WD_UNTRACKED)) != 0)
|
||||
|
||||
/**
|
||||
* Lookup submodule information by name or path.
|
||||
*
|
||||
* Given either the submodule name or path (they are usually the same), this
|
||||
* returns a structure describing the submodule.
|
||||
*
|
||||
* There are two expected error scenarios:
|
||||
*
|
||||
* - The submodule is not mentioned in the HEAD, the index, and the config,
|
||||
* but does "exist" in the working directory (i.e. there is a subdirectory
|
||||
* that is a valid self-contained git repo). In this case, this function
|
||||
* returns GIT_EEXISTS to indicate the the submodule exists but not in a
|
||||
* state where a git_submodule can be instantiated.
|
||||
* - The submodule is not mentioned in the HEAD, index, or config and the
|
||||
* working directory doesn't contain a value git repo at that path.
|
||||
* There may or may not be anything else at that path, but nothing that
|
||||
* looks like a submodule. In this case, this returns GIT_ENOTFOUND.
|
||||
*
|
||||
* The submodule object is owned by the containing repo and will be freed
|
||||
* when the repo is freed. The caller need not free the submodule.
|
||||
*
|
||||
* @param submodule Pointer to submodule description object pointer..
|
||||
* @param repo The repository.
|
||||
* @param name The name of the submodule. Trailing slashes will be ignored.
|
||||
* @return 0 on success, GIT_ENOTFOUND if submodule does not exist,
|
||||
* GIT_EEXISTS if submodule exists in working directory only, -1 on
|
||||
* other errors.
|
||||
*/
|
||||
GIT_EXTERN(int) git_submodule_lookup(
|
||||
git_submodule **submodule,
|
||||
git_repository *repo,
|
||||
const char *name);
|
||||
|
||||
/**
|
||||
* Iterate over all tracked submodules of a repository.
|
||||
*
|
||||
* See the note on `git_submodule` above. This iterates over the tracked
|
||||
* submodules as decribed therein.
|
||||
*
|
||||
* If you are concerned about items in the working directory that look like
|
||||
* submodules but are not tracked, the diff API will generate a diff record
|
||||
* for workdir items that look like submodules but are not tracked, showing
|
||||
* them as added in the workdir. Also, the status API will treat the entire
|
||||
* subdirectory of a contained git repo as a single GIT_STATUS_WT_NEW item.
|
||||
*
|
||||
* @param repo The repository
|
||||
* @param callback Function to be called with the name of each submodule.
|
||||
* Return a non-zero value to terminate the iteration.
|
||||
* @param payload Extra data to pass to callback
|
||||
* @return 0 on success, -1 on error, or non-zero return value of callback
|
||||
*/
|
||||
GIT_EXTERN(int) git_submodule_foreach(
|
||||
git_repository *repo,
|
||||
int (*callback)(git_submodule *sm, const char *name, void *payload),
|
||||
void *payload);
|
||||
|
||||
/**
|
||||
* Set up a new git submodule for checkout.
|
||||
*
|
||||
* This does "git submodule add" up to the fetch and checkout of the
|
||||
* submodule contents. It preps a new submodule, creates an entry in
|
||||
* .gitmodules and creates an empty initialized repository either at the
|
||||
* given path in the working directory or in .git/modules with a gitlink
|
||||
* from the working directory to the new repo.
|
||||
*
|
||||
* To fully emulate "git submodule add" call this function, then open the
|
||||
* submodule repo and perform the clone step as needed. Lastly, call
|
||||
* `git_submodule_add_finalize()` to wrap up adding the new submodule and
|
||||
* .gitmodules to the index to be ready to commit.
|
||||
*
|
||||
* @param submodule The newly created submodule ready to open for clone
|
||||
* @param repo Superproject repository to contain the new submodule
|
||||
* @param url URL for the submodules remote
|
||||
* @param path Path at which the submodule should be created
|
||||
* @param use_gitlink Should workdir contain a gitlink to the repo in
|
||||
* .git/modules vs. repo directly in workdir.
|
||||
* @return 0 on success, GIT_EEXISTS if submodule already exists,
|
||||
* -1 on other errors.
|
||||
*/
|
||||
GIT_EXTERN(int) git_submodule_add_setup(
|
||||
git_submodule **submodule,
|
||||
git_repository *repo,
|
||||
const char *url,
|
||||
const char *path,
|
||||
int use_gitlink);
|
||||
|
||||
/**
|
||||
* Resolve the setup of a new git submodule.
|
||||
*
|
||||
* This should be called on a submodule once you have called add setup
|
||||
* and done the clone of the submodule. This adds the .gitmodules file
|
||||
* and the newly cloned submodule to the index to be ready to be committed
|
||||
* (but doesn't actually do the commit).
|
||||
*
|
||||
* @param submodule The submodule to finish adding.
|
||||
*/
|
||||
GIT_EXTERN(int) git_submodule_add_finalize(git_submodule *submodule);
|
||||
|
||||
/**
|
||||
* Add current submodule HEAD commit to index of superproject.
|
||||
*
|
||||
* @param submodule The submodule to add to the index
|
||||
* @param write_index Boolean if this should immediately write the index
|
||||
* file. If you pass this as false, you will have to get the
|
||||
* git_index and explicitly call `git_index_write()` on it to
|
||||
* save the change.
|
||||
* @return 0 on success, <0 on failure
|
||||
*/
|
||||
GIT_EXTERN(int) git_submodule_add_to_index(
|
||||
git_submodule *submodule,
|
||||
int write_index);
|
||||
|
||||
/**
|
||||
* Write submodule settings to .gitmodules file.
|
||||
*
|
||||
* This commits any in-memory changes to the submodule to the gitmodules
|
||||
* file on disk. You may also be interested in `git_submodule_init()` which
|
||||
* writes submodule info to ".git/config" (which is better for local changes
|
||||
* to submodule settings) and/or `git_submodule_sync()` which writes
|
||||
* settings about remotes to the actual submodule repository.
|
||||
*
|
||||
* @param submodule The submodule to write.
|
||||
* @return 0 on success, <0 on failure.
|
||||
*/
|
||||
GIT_EXTERN(int) git_submodule_save(git_submodule *submodule);
|
||||
|
||||
/**
|
||||
* Get the containing repository for a submodule.
|
||||
*
|
||||
* This returns a pointer to the repository that contains the submodule.
|
||||
* This is a just a reference to the repository that was passed to the
|
||||
* original `git_submodule_lookup()` call, so if that repository has been
|
||||
* freed, then this may be a dangling reference.
|
||||
*
|
||||
* @param submodule Pointer to submodule object
|
||||
* @return Pointer to `git_repository`
|
||||
*/
|
||||
GIT_EXTERN(git_repository *) git_submodule_owner(git_submodule *submodule);
|
||||
|
||||
/**
|
||||
* Get the name of submodule.
|
||||
*
|
||||
* @param submodule Pointer to submodule object
|
||||
* @return Pointer to the submodule name
|
||||
*/
|
||||
GIT_EXTERN(const char *) git_submodule_name(git_submodule *submodule);
|
||||
|
||||
/**
|
||||
* Get the path to the submodule.
|
||||
*
|
||||
* The path is almost always the same as the submodule name, but the
|
||||
* two are actually not required to match.
|
||||
*
|
||||
* @param submodule Pointer to submodule object
|
||||
* @return Pointer to the submodule path
|
||||
*/
|
||||
GIT_EXTERN(const char *) git_submodule_path(git_submodule *submodule);
|
||||
|
||||
/**
|
||||
* Get the URL for the submodule.
|
||||
*
|
||||
* @param submodule Pointer to submodule object
|
||||
* @return Pointer to the submodule url
|
||||
*/
|
||||
GIT_EXTERN(const char *) git_submodule_url(git_submodule *submodule);
|
||||
|
||||
/**
|
||||
* Set the URL for the submodule.
|
||||
*
|
||||
* This sets the URL in memory for the submodule. This will be used for
|
||||
* any following submodule actions while this submodule data is in memory.
|
||||
*
|
||||
* After calling this, you may wish to call `git_submodule_save()` to write
|
||||
* the changes back to the ".gitmodules" file and `git_submodule_sync()` to
|
||||
* write the changes to the checked out submodule repository.
|
||||
*
|
||||
* @param submodule Pointer to the submodule object
|
||||
* @param url URL that should be used for the submodule
|
||||
* @return 0 on success, <0 on failure
|
||||
*/
|
||||
GIT_EXTERN(int) git_submodule_set_url(git_submodule *submodule, const char *url);
|
||||
|
||||
/**
|
||||
* Get the OID for the submodule in the index.
|
||||
*
|
||||
* @param submodule Pointer to submodule object
|
||||
* @return Pointer to git_oid or NULL if submodule is not in index.
|
||||
*/
|
||||
GIT_EXTERN(const git_oid *) git_submodule_index_id(git_submodule *submodule);
|
||||
|
||||
/**
|
||||
* Get the OID for the submodule in the current HEAD tree.
|
||||
*
|
||||
* @param submodule Pointer to submodule object
|
||||
* @return Pointer to git_oid or NULL if submodule is not in the HEAD.
|
||||
*/
|
||||
GIT_EXTERN(const git_oid *) git_submodule_head_id(git_submodule *submodule);
|
||||
|
||||
/**
|
||||
* Get the OID for the submodule in the current working directory.
|
||||
*
|
||||
* This returns the OID that corresponds to looking up 'HEAD' in the checked
|
||||
* out submodule. If there are pending changes in the index or anything
|
||||
* else, this won't notice that. You should call `git_submodule_status()`
|
||||
* for a more complete picture about the state of the working directory.
|
||||
*
|
||||
* @param submodule Pointer to submodule object
|
||||
* @return Pointer to git_oid or NULL if submodule is not checked out.
|
||||
*/
|
||||
GIT_EXTERN(const git_oid *) git_submodule_wd_id(git_submodule *submodule);
|
||||
|
||||
/**
|
||||
* Get the ignore rule for the submodule.
|
||||
*
|
||||
* There are four ignore values:
|
||||
*
|
||||
* - **GIT_SUBMODULE_IGNORE_NONE** will consider any change to the contents
|
||||
* of the submodule from a clean checkout to be dirty, including the
|
||||
* addition of untracked files. This is the default if unspecified.
|
||||
* - **GIT_SUBMODULE_IGNORE_UNTRACKED** examines the contents of the
|
||||
* working tree (i.e. call `git_status_foreach()` on the submodule) but
|
||||
* UNTRACKED files will not count as making the submodule dirty.
|
||||
* - **GIT_SUBMODULE_IGNORE_DIRTY** means to only check if the HEAD of the
|
||||
* submodule has moved for status. This is fast since it does not need to
|
||||
* scan the working tree of the submodule at all.
|
||||
* - **GIT_SUBMODULE_IGNORE_ALL** means not to open the submodule repo.
|
||||
* The working directory will be consider clean so long as there is a
|
||||
* checked out version present.
|
||||
*/
|
||||
GIT_EXTERN(git_submodule_ignore_t) git_submodule_ignore(
|
||||
git_submodule *submodule);
|
||||
|
||||
/**
|
||||
* Set the ignore rule for the submodule.
|
||||
*
|
||||
* This sets the ignore rule in memory for the submodule. This will be used
|
||||
* for any following actions (such as `git_submodule_status()`) while the
|
||||
* submodule is in memory. You should call `git_submodule_save()` if you
|
||||
* want to persist the new ignore role.
|
||||
*
|
||||
* Calling this again with GIT_SUBMODULE_IGNORE_DEFAULT or calling
|
||||
* `git_submodule_reload()` will revert the rule to the value that was in the
|
||||
* original config.
|
||||
*
|
||||
* @return old value for ignore
|
||||
*/
|
||||
GIT_EXTERN(git_submodule_ignore_t) git_submodule_set_ignore(
|
||||
git_submodule *submodule,
|
||||
git_submodule_ignore_t ignore);
|
||||
|
||||
/**
|
||||
* Get the update rule for the submodule.
|
||||
*/
|
||||
GIT_EXTERN(git_submodule_update_t) git_submodule_update(
|
||||
git_submodule *submodule);
|
||||
|
||||
/**
|
||||
* Set the update rule for the submodule.
|
||||
*
|
||||
* This sets the update rule in memory for the submodule. You should call
|
||||
* `git_submodule_save()` if you want to persist the new update rule.
|
||||
*
|
||||
* Calling this again with GIT_SUBMODULE_UPDATE_DEFAULT or calling
|
||||
* `git_submodule_reload()` will revert the rule to the value that was in the
|
||||
* original config.
|
||||
*
|
||||
* @return old value for update
|
||||
*/
|
||||
GIT_EXTERN(git_submodule_update_t) git_submodule_set_update(
|
||||
git_submodule *submodule,
|
||||
git_submodule_update_t update);
|
||||
|
||||
/**
|
||||
* Read the fetchRecurseSubmodules rule for a submodule.
|
||||
*
|
||||
* This accesses the submodule.<name>.fetchRecurseSubmodules value for
|
||||
* the submodule that controls fetching behavior for the submodule.
|
||||
*
|
||||
* Note that at this time, libgit2 does not honor this setting and the
|
||||
* fetch functionality current ignores submodules.
|
||||
*
|
||||
* @return 0 if fetchRecurseSubmodules is false, 1 if true
|
||||
*/
|
||||
GIT_EXTERN(int) git_submodule_fetch_recurse_submodules(
|
||||
git_submodule *submodule);
|
||||
|
||||
/**
|
||||
* Set the fetchRecurseSubmodules rule for a submodule.
|
||||
*
|
||||
* This sets the submodule.<name>.fetchRecurseSubmodules value for
|
||||
* the submodule. You should call `git_submodule_save()` if you want
|
||||
* to persist the new value.
|
||||
*
|
||||
* @param submodule The submodule to modify
|
||||
* @param fetch_recurse_submodules Boolean value
|
||||
* @return old value for fetchRecurseSubmodules
|
||||
*/
|
||||
GIT_EXTERN(int) git_submodule_set_fetch_recurse_submodules(
|
||||
git_submodule *submodule,
|
||||
int fetch_recurse_submodules);
|
||||
|
||||
/**
|
||||
* Copy submodule info into ".git/config" file.
|
||||
*
|
||||
* Just like "git submodule init", this copies information about the
|
||||
* submodule into ".git/config". You can use the accessor functions
|
||||
* above to alter the in-memory git_submodule object and control what
|
||||
* is written to the config, overriding what is in .gitmodules.
|
||||
*
|
||||
* @param submodule The submodule to write into the superproject config
|
||||
* @param overwrite By default, existing entries will not be overwritten,
|
||||
* but setting this to true forces them to be updated.
|
||||
* @return 0 on success, <0 on failure.
|
||||
*/
|
||||
GIT_EXTERN(int) git_submodule_init(git_submodule *submodule, int overwrite);
|
||||
|
||||
/**
|
||||
* Copy submodule remote info into submodule repo.
|
||||
*
|
||||
* This copies the information about the submodules URL into the checked out
|
||||
* submodule config, acting like "git submodule sync". This is useful if
|
||||
* you have altered the URL for the submodule (or it has been altered by a
|
||||
* fetch of upstream changes) and you need to update your local repo.
|
||||
*/
|
||||
GIT_EXTERN(int) git_submodule_sync(git_submodule *submodule);
|
||||
|
||||
/**
|
||||
* Open the repository for a submodule.
|
||||
*
|
||||
* This is a newly opened repository object. The caller is responsible for
|
||||
* calling `git_repository_free()` on it when done. Multiple calls to this
|
||||
* function will return distinct `git_repository` objects. This will only
|
||||
* work if the submodule is checked out into the working directory.
|
||||
*
|
||||
* @param subrepo Pointer to the submodule repo which was opened
|
||||
* @param submodule Submodule to be opened
|
||||
* @return 0 on success, <0 if submodule repo could not be opened.
|
||||
*/
|
||||
GIT_EXTERN(int) git_submodule_open(
|
||||
git_repository **repo,
|
||||
git_submodule *submodule);
|
||||
|
||||
/**
|
||||
* Reread submodule info from config, index, and HEAD.
|
||||
*
|
||||
* Call this to reread cached submodule information for this submodule if
|
||||
* you have reason to believe that it has changed.
|
||||
*/
|
||||
GIT_EXTERN(int) git_submodule_reload(git_submodule *submodule);
|
||||
|
||||
/**
|
||||
* Reread all submodule info.
|
||||
*
|
||||
* Call this to reload all cached submodule information for the repo.
|
||||
*/
|
||||
GIT_EXTERN(int) git_submodule_reload_all(git_repository *repo);
|
||||
|
||||
/**
|
||||
* Get the status for a submodule.
|
||||
*
|
||||
* This looks at a submodule and tries to determine the status. It
|
||||
* will return a combination of the `GIT_SUBMODULE_STATUS` values above.
|
||||
* How deeply it examines the working directory to do this will depend
|
||||
* on the `git_submodule_ignore_t` value for the submodule - which can be
|
||||
* set either temporarily or permanently with `git_submodule_set_ignore()`.
|
||||
*
|
||||
* @param status Combination of `GIT_SUBMODULE_STATUS` flags
|
||||
* @param submodule Submodule for which to get status
|
||||
* @return 0 on success, <0 on error
|
||||
*/
|
||||
GIT_EXTERN(int) git_submodule_status(
|
||||
unsigned int *status,
|
||||
git_submodule *submodule);
|
||||
|
||||
/**
|
||||
* Get the locations of submodule information.
|
||||
*
|
||||
* This is a bit like a very lightweight version of `git_submodule_status`.
|
||||
* It just returns a made of the first four submodule status values (i.e.
|
||||
* the ones like GIT_SUBMODULE_STATUS_IN_HEAD, etc) that tell you where the
|
||||
* submodule data comes from (i.e. the HEAD commit, gitmodules file, etc.).
|
||||
* This can be useful if you want to know if the submodule is present in the
|
||||
* working directory at this point in time, etc.
|
||||
*
|
||||
* @param status Combination of first four `GIT_SUBMODULE_STATUS` flags
|
||||
* @param submodule Submodule for which to get status
|
||||
* @return 0 on success, <0 on error
|
||||
*/
|
||||
GIT_EXTERN(int) git_submodule_location(
|
||||
unsigned int *location_status,
|
||||
git_submodule *submodule);
|
||||
|
||||
/** @} */
|
||||
GIT_END_DECL
|
||||
#endif
|
||||
@@ -1,326 +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_tag_h__
|
||||
#define INCLUDE_git_tag_h__
|
||||
|
||||
#include "common.h"
|
||||
#include "types.h"
|
||||
#include "oid.h"
|
||||
#include "object.h"
|
||||
#include "strarray.h"
|
||||
|
||||
/**
|
||||
* @file git2/tag.h
|
||||
* @brief Git tag parsing routines
|
||||
* @defgroup git_tag Git tag management
|
||||
* @ingroup Git
|
||||
* @{
|
||||
*/
|
||||
GIT_BEGIN_DECL
|
||||
|
||||
/**
|
||||
* Lookup a tag object from the repository.
|
||||
*
|
||||
* @param out pointer to the looked up tag
|
||||
* @param repo the repo to use when locating the tag.
|
||||
* @param id identity of the tag to locate.
|
||||
* @return 0 or an error code
|
||||
*/
|
||||
GIT_INLINE(int) git_tag_lookup(
|
||||
git_tag **out, git_repository *repo, const git_oid *id)
|
||||
{
|
||||
return git_object_lookup(
|
||||
(git_object **)out, repo, id, (git_otype)GIT_OBJ_TAG);
|
||||
}
|
||||
|
||||
/**
|
||||
* Lookup a tag object from the repository,
|
||||
* given a prefix of its identifier (short id).
|
||||
*
|
||||
* @see git_object_lookup_prefix
|
||||
*
|
||||
* @param out pointer to the looked up tag
|
||||
* @param repo the repo to use when locating the tag.
|
||||
* @param id identity of the tag to locate.
|
||||
* @param len the length of the short identifier
|
||||
* @return 0 or an error code
|
||||
*/
|
||||
GIT_INLINE(int) git_tag_lookup_prefix(
|
||||
git_tag **out, git_repository *repo, const git_oid *id, size_t len)
|
||||
{
|
||||
return git_object_lookup_prefix(
|
||||
(git_object **)out, repo, id, len, (git_otype)GIT_OBJ_TAG);
|
||||
}
|
||||
|
||||
/**
|
||||
* Close an open tag
|
||||
*
|
||||
* You can no longer use the git_tag pointer after this call.
|
||||
*
|
||||
* IMPORTANT: You MUST call this method when you are through with a tag to
|
||||
* release memory. Failure to do so will cause a memory leak.
|
||||
*
|
||||
* @param tag the tag to close
|
||||
*/
|
||||
|
||||
GIT_INLINE(void) git_tag_free(git_tag *tag)
|
||||
{
|
||||
git_object_free((git_object *)tag);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the id of a tag.
|
||||
*
|
||||
* @param tag a previously loaded tag.
|
||||
* @return object identity for the tag.
|
||||
*/
|
||||
GIT_EXTERN(const git_oid *) git_tag_id(const git_tag *tag);
|
||||
|
||||
/**
|
||||
* Get the tagged object of a tag
|
||||
*
|
||||
* This method performs a repository lookup for the
|
||||
* given object and returns it
|
||||
*
|
||||
* @param target_out pointer where to store the target
|
||||
* @param tag a previously loaded tag.
|
||||
* @return 0 or an error code
|
||||
*/
|
||||
GIT_EXTERN(int) git_tag_target(git_object **target_out, const git_tag *tag);
|
||||
|
||||
/**
|
||||
* Get the OID of the tagged object of a tag
|
||||
*
|
||||
* @param tag a previously loaded tag.
|
||||
* @return pointer to the OID
|
||||
*/
|
||||
GIT_EXTERN(const git_oid *) git_tag_target_id(const git_tag *tag);
|
||||
|
||||
/**
|
||||
* Get the type of a tag's tagged object
|
||||
*
|
||||
* @param tag a previously loaded tag.
|
||||
* @return type of the tagged object
|
||||
*/
|
||||
GIT_EXTERN(git_otype) git_tag_target_type(const git_tag *tag);
|
||||
|
||||
/**
|
||||
* Get the name of a tag
|
||||
*
|
||||
* @param tag a previously loaded tag.
|
||||
* @return name of the tag
|
||||
*/
|
||||
GIT_EXTERN(const char *) git_tag_name(const git_tag *tag);
|
||||
|
||||
/**
|
||||
* Get the tagger (author) of a tag
|
||||
*
|
||||
* @param tag a previously loaded tag.
|
||||
* @return reference to the tag's author
|
||||
*/
|
||||
GIT_EXTERN(const git_signature *) git_tag_tagger(const git_tag *tag);
|
||||
|
||||
/**
|
||||
* Get the message of a tag
|
||||
*
|
||||
* @param tag a previously loaded tag.
|
||||
* @return message of the tag
|
||||
*/
|
||||
GIT_EXTERN(const char *) git_tag_message(const git_tag *tag);
|
||||
|
||||
|
||||
/**
|
||||
* Create a new tag in the repository from an object
|
||||
*
|
||||
* A new reference will also be created pointing to
|
||||
* this tag object. If `force` is true and a reference
|
||||
* already exists with the given name, it'll be replaced.
|
||||
*
|
||||
* The message will not be cleaned up. This can be achieved
|
||||
* through `git_message_prettify()`.
|
||||
*
|
||||
* The tag name will be checked for validity. You must avoid
|
||||
* the characters '~', '^', ':', '\\', '?', '[', and '*', and the
|
||||
* sequences ".." and "@{" which have special meaning to revparse.
|
||||
*
|
||||
* @param oid Pointer where to store the OID of the
|
||||
* newly created tag. If the tag already exists, this parameter
|
||||
* will be the oid of the existing tag, and the function will
|
||||
* return a GIT_EEXISTS error code.
|
||||
*
|
||||
* @param repo Repository where to store the tag
|
||||
*
|
||||
* @param tag_name Name for the tag; this name is validated
|
||||
* for consistency. It should also not conflict with an
|
||||
* already existing tag name
|
||||
*
|
||||
* @param target Object to which this tag points. This object
|
||||
* must belong to the given `repo`.
|
||||
*
|
||||
* @param tagger Signature of the tagger for this tag, and
|
||||
* of the tagging time
|
||||
*
|
||||
* @param message Full message for this tag
|
||||
*
|
||||
* @param force Overwrite existing references
|
||||
*
|
||||
* @return 0 on success, GIT_EINVALIDSPEC or an error code
|
||||
* A tag object is written to the ODB, and a proper reference
|
||||
* is written in the /refs/tags folder, pointing to it
|
||||
*/
|
||||
GIT_EXTERN(int) git_tag_create(
|
||||
git_oid *oid,
|
||||
git_repository *repo,
|
||||
const char *tag_name,
|
||||
const git_object *target,
|
||||
const git_signature *tagger,
|
||||
const char *message,
|
||||
int force);
|
||||
|
||||
/**
|
||||
* Create a new tag in the repository from a buffer
|
||||
*
|
||||
* @param oid Pointer where to store the OID of the newly created tag
|
||||
* @param repo Repository where to store the tag
|
||||
* @param buffer Raw tag data
|
||||
* @param force Overwrite existing tags
|
||||
* @return 0 on success; error code otherwise
|
||||
*/
|
||||
GIT_EXTERN(int) git_tag_create_frombuffer(
|
||||
git_oid *oid,
|
||||
git_repository *repo,
|
||||
const char *buffer,
|
||||
int force);
|
||||
|
||||
/**
|
||||
* Create a new lightweight tag pointing at a target object
|
||||
*
|
||||
* A new direct reference will be created pointing to
|
||||
* this target object. If `force` is true and a reference
|
||||
* already exists with the given name, it'll be replaced.
|
||||
*
|
||||
* The tag name will be checked for validity.
|
||||
* See `git_tag_create()` for rules about valid names.
|
||||
*
|
||||
* @param oid Pointer where to store the OID of the provided
|
||||
* target object. If the tag already exists, this parameter
|
||||
* will be filled with the oid of the existing pointed object
|
||||
* and the function will return a GIT_EEXISTS error code.
|
||||
*
|
||||
* @param repo Repository where to store the lightweight tag
|
||||
*
|
||||
* @param tag_name Name for the tag; this name is validated
|
||||
* for consistency. It should also not conflict with an
|
||||
* already existing tag name
|
||||
*
|
||||
* @param target Object to which this tag points. This object
|
||||
* must belong to the given `repo`.
|
||||
*
|
||||
* @param force Overwrite existing references
|
||||
*
|
||||
* @return 0 on success, GIT_EINVALIDSPEC or an error code
|
||||
* A proper reference is written in the /refs/tags folder,
|
||||
* pointing to the provided target object
|
||||
*/
|
||||
GIT_EXTERN(int) git_tag_create_lightweight(
|
||||
git_oid *oid,
|
||||
git_repository *repo,
|
||||
const char *tag_name,
|
||||
const git_object *target,
|
||||
int force);
|
||||
|
||||
/**
|
||||
* Delete an existing tag reference.
|
||||
*
|
||||
* The tag name will be checked for validity.
|
||||
* See `git_tag_create()` for rules about valid names.
|
||||
*
|
||||
* @param repo Repository where lives the tag
|
||||
*
|
||||
* @param tag_name Name of the tag to be deleted;
|
||||
* this name is validated for consistency.
|
||||
*
|
||||
* @return 0 on success, GIT_EINVALIDSPEC or an error code
|
||||
*/
|
||||
GIT_EXTERN(int) git_tag_delete(
|
||||
git_repository *repo,
|
||||
const char *tag_name);
|
||||
|
||||
/**
|
||||
* Fill a list with all the tags in the Repository
|
||||
*
|
||||
* The string array will be filled with the names of the
|
||||
* matching tags; these values are owned by the user and
|
||||
* should be free'd manually when no longer needed, using
|
||||
* `git_strarray_free`.
|
||||
*
|
||||
* @param tag_names Pointer to a git_strarray structure where
|
||||
* the tag names will be stored
|
||||
* @param repo Repository where to find the tags
|
||||
* @return 0 or an error code
|
||||
*/
|
||||
GIT_EXTERN(int) git_tag_list(
|
||||
git_strarray *tag_names,
|
||||
git_repository *repo);
|
||||
|
||||
/**
|
||||
* Fill a list with all the tags in the Repository
|
||||
* which name match a defined pattern
|
||||
*
|
||||
* If an empty pattern is provided, all the tags
|
||||
* will be returned.
|
||||
*
|
||||
* The string array will be filled with the names of the
|
||||
* matching tags; these values are owned by the user and
|
||||
* should be free'd manually when no longer needed, using
|
||||
* `git_strarray_free`.
|
||||
*
|
||||
* @param tag_names Pointer to a git_strarray structure where
|
||||
* the tag names will be stored
|
||||
* @param pattern Standard fnmatch pattern
|
||||
* @param repo Repository where to find the tags
|
||||
* @return 0 or an error code
|
||||
*/
|
||||
GIT_EXTERN(int) git_tag_list_match(
|
||||
git_strarray *tag_names,
|
||||
const char *pattern,
|
||||
git_repository *repo);
|
||||
|
||||
|
||||
typedef int (*git_tag_foreach_cb)(const char *name, git_oid *oid, void *payload);
|
||||
|
||||
/**
|
||||
* Call callback `cb' for each tag in the repository
|
||||
*
|
||||
* @param repo Repository
|
||||
* @param callback Callback function
|
||||
* @param payload Pointer to callback data (optional)
|
||||
*/
|
||||
GIT_EXTERN(int) git_tag_foreach(
|
||||
git_repository *repo,
|
||||
git_tag_foreach_cb callback,
|
||||
void *payload);
|
||||
|
||||
|
||||
/**
|
||||
* Recursively peel a tag until a non tag git_object is found
|
||||
*
|
||||
* The retrieved `tag_target` object is owned by the repository
|
||||
* and should be closed with the `git_object_free` method.
|
||||
*
|
||||
* @param tag_target_out Pointer to the peeled git_object
|
||||
* @param tag The tag to be processed
|
||||
* @return 0 or an error code
|
||||
*/
|
||||
GIT_EXTERN(int) git_tag_peel(
|
||||
git_object **tag_target_out,
|
||||
const git_tag *tag);
|
||||
|
||||
/** @} */
|
||||
GIT_END_DECL
|
||||
#endif
|
||||
@@ -1,50 +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_threads_h__
|
||||
#define INCLUDE_git_threads_h__
|
||||
|
||||
#include "common.h"
|
||||
|
||||
/**
|
||||
* @file git2/threads.h
|
||||
* @brief Library level thread functions
|
||||
* @defgroup git_thread Threading functions
|
||||
* @ingroup Git
|
||||
* @{
|
||||
*/
|
||||
GIT_BEGIN_DECL
|
||||
|
||||
/**
|
||||
* Init the threading system.
|
||||
*
|
||||
* If libgit2 has been built with GIT_THREADS
|
||||
* on, this function must be called once before
|
||||
* any other library functions.
|
||||
*
|
||||
* If libgit2 has been built without GIT_THREADS
|
||||
* support, this function is a no-op.
|
||||
*
|
||||
* @return 0 or an error code
|
||||
*/
|
||||
GIT_EXTERN(int) git_threads_init(void);
|
||||
|
||||
/**
|
||||
* Shutdown the threading system.
|
||||
*
|
||||
* If libgit2 has been built with GIT_THREADS
|
||||
* on, this function must be called before shutting
|
||||
* down the library.
|
||||
*
|
||||
* If libgit2 has been built without GIT_THREADS
|
||||
* support, this function is a no-op.
|
||||
*/
|
||||
GIT_EXTERN(void) git_threads_shutdown(void);
|
||||
|
||||
/** @} */
|
||||
GIT_END_DECL
|
||||
#endif
|
||||
|
||||
@@ -1,331 +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_transport_h__
|
||||
#define INCLUDE_git_transport_h__
|
||||
|
||||
#include "indexer.h"
|
||||
#include "net.h"
|
||||
#include "types.h"
|
||||
|
||||
/**
|
||||
* @file git2/transport.h
|
||||
* @brief Git transport interfaces and functions
|
||||
* @defgroup git_transport interfaces and functions
|
||||
* @ingroup Git
|
||||
* @{
|
||||
*/
|
||||
GIT_BEGIN_DECL
|
||||
|
||||
/*
|
||||
*** Begin interface for credentials acquisition ***
|
||||
*/
|
||||
|
||||
typedef enum {
|
||||
/* git_cred_userpass_plaintext */
|
||||
GIT_CREDTYPE_USERPASS_PLAINTEXT = 1,
|
||||
} git_credtype_t;
|
||||
|
||||
/* The base structure for all credential types */
|
||||
typedef struct git_cred {
|
||||
git_credtype_t credtype;
|
||||
void (*free)(
|
||||
struct git_cred *cred);
|
||||
} git_cred;
|
||||
|
||||
/* A plaintext username and password */
|
||||
typedef struct git_cred_userpass_plaintext {
|
||||
git_cred parent;
|
||||
char *username;
|
||||
char *password;
|
||||
} git_cred_userpass_plaintext;
|
||||
|
||||
/**
|
||||
* Creates a new plain-text username and password credential object.
|
||||
*
|
||||
* @param out The newly created credential object.
|
||||
* @param username The username of the credential.
|
||||
* @param password The password of the credential.
|
||||
*/
|
||||
GIT_EXTERN(int) git_cred_userpass_plaintext_new(
|
||||
git_cred **out,
|
||||
const char *username,
|
||||
const char *password);
|
||||
|
||||
/**
|
||||
* Signature of a function which acquires a credential object.
|
||||
*
|
||||
* @param cred The newly created credential object.
|
||||
* @param url The resource for which we are demanding a credential.
|
||||
* @param allowed_types A bitmask stating which cred types are OK to return.
|
||||
*/
|
||||
typedef int (*git_cred_acquire_cb)(
|
||||
git_cred **cred,
|
||||
const char *url,
|
||||
unsigned int allowed_types,
|
||||
void *payload);
|
||||
|
||||
/*
|
||||
*** End interface for credentials acquisition ***
|
||||
*** Begin base transport interface ***
|
||||
*/
|
||||
|
||||
typedef enum {
|
||||
GIT_TRANSPORTFLAGS_NONE = 0,
|
||||
/* If the connection is secured with SSL/TLS, the authenticity
|
||||
* of the server certificate should not be verified. */
|
||||
GIT_TRANSPORTFLAGS_NO_CHECK_CERT = 1
|
||||
} git_transport_flags_t;
|
||||
|
||||
typedef void (*git_transport_message_cb)(const char *str, int len, void *data);
|
||||
|
||||
typedef struct git_transport {
|
||||
unsigned int version;
|
||||
/* Set progress and error callbacks */
|
||||
int (*set_callbacks)(struct git_transport *transport,
|
||||
git_transport_message_cb progress_cb,
|
||||
git_transport_message_cb error_cb,
|
||||
void *payload);
|
||||
|
||||
/* Connect the transport to the remote repository, using the given
|
||||
* direction. */
|
||||
int (*connect)(struct git_transport *transport,
|
||||
const char *url,
|
||||
git_cred_acquire_cb cred_acquire_cb,
|
||||
void *cred_acquire_payload,
|
||||
int direction,
|
||||
int flags);
|
||||
|
||||
/* This function may be called after a successful call to connect(). The
|
||||
* provided callback is invoked for each ref discovered on the remote
|
||||
* end. */
|
||||
int (*ls)(struct git_transport *transport,
|
||||
git_headlist_cb list_cb,
|
||||
void *payload);
|
||||
|
||||
/* Executes the push whose context is in the git_push object. */
|
||||
int (*push)(struct git_transport *transport, git_push *push);
|
||||
|
||||
/* This function may be called after a successful call to connect(), when
|
||||
* the direction is FETCH. The function performs a negotiation to calculate
|
||||
* the wants list for the fetch. */
|
||||
int (*negotiate_fetch)(struct git_transport *transport,
|
||||
git_repository *repo,
|
||||
const git_remote_head * const *refs,
|
||||
size_t count);
|
||||
|
||||
/* This function may be called after a successful call to negotiate_fetch(),
|
||||
* when the direction is FETCH. This function retrieves the pack file for
|
||||
* the fetch from the remote end. */
|
||||
int (*download_pack)(struct git_transport *transport,
|
||||
git_repository *repo,
|
||||
git_transfer_progress *stats,
|
||||
git_transfer_progress_callback progress_cb,
|
||||
void *progress_payload);
|
||||
|
||||
/* Checks to see if the transport is connected */
|
||||
int (*is_connected)(struct git_transport *transport);
|
||||
|
||||
/* Reads the flags value previously passed into connect() */
|
||||
int (*read_flags)(struct git_transport *transport, int *flags);
|
||||
|
||||
/* Cancels any outstanding transport operation */
|
||||
void (*cancel)(struct git_transport *transport);
|
||||
|
||||
/* This function is the reverse of connect() -- it terminates the
|
||||
* connection to the remote end. */
|
||||
int (*close)(struct git_transport *transport);
|
||||
|
||||
/* Frees/destructs the git_transport object. */
|
||||
void (*free)(struct git_transport *transport);
|
||||
} git_transport;
|
||||
|
||||
#define GIT_TRANSPORT_VERSION 1
|
||||
#define GIT_TRANSPORT_INIT {GIT_TRANSPORT_VERSION}
|
||||
|
||||
/**
|
||||
* Function to use to create a transport from a URL. The transport database
|
||||
* is scanned to find a transport that implements the scheme of the URI (i.e.
|
||||
* git:// or http://) and a transport object is returned to the caller.
|
||||
*
|
||||
* @param out The newly created transport (out)
|
||||
* @param owner The git_remote which will own this transport
|
||||
* @param url The URL to connect to
|
||||
* @return 0 or an error code
|
||||
*/
|
||||
GIT_EXTERN(int) git_transport_new(git_transport **out, git_remote *owner, const char *url);
|
||||
|
||||
/**
|
||||
* Function which checks to see if a transport could be created for the
|
||||
* given URL (i.e. checks to see if libgit2 has a transport that supports
|
||||
* the given URL's scheme)
|
||||
*
|
||||
* @param url The URL to check
|
||||
* @return Zero if the URL is not valid; nonzero otherwise
|
||||
*/
|
||||
GIT_EXTERN(int) git_transport_valid_url(const char *url);
|
||||
|
||||
/* Signature of a function which creates a transport */
|
||||
typedef int (*git_transport_cb)(git_transport **out, git_remote *owner, void *param);
|
||||
|
||||
/* Transports which come with libgit2 (match git_transport_cb). The expected
|
||||
* value for "param" is listed in-line below. */
|
||||
|
||||
/**
|
||||
* Create an instance of the dummy transport.
|
||||
*
|
||||
* @param out The newly created transport (out)
|
||||
* @param owner The git_remote which will own this transport
|
||||
* @param payload You must pass NULL for this parameter.
|
||||
* @return 0 or an error code
|
||||
*/
|
||||
GIT_EXTERN(int) git_transport_dummy(
|
||||
git_transport **out,
|
||||
git_remote *owner,
|
||||
/* NULL */ void *payload);
|
||||
|
||||
/**
|
||||
* Create an instance of the local transport.
|
||||
*
|
||||
* @param out The newly created transport (out)
|
||||
* @param owner The git_remote which will own this transport
|
||||
* @param payload You must pass NULL for this parameter.
|
||||
* @return 0 or an error code
|
||||
*/
|
||||
GIT_EXTERN(int) git_transport_local(
|
||||
git_transport **out,
|
||||
git_remote *owner,
|
||||
/* NULL */ void *payload);
|
||||
|
||||
/**
|
||||
* Create an instance of the smart transport.
|
||||
*
|
||||
* @param out The newly created transport (out)
|
||||
* @param owner The git_remote which will own this transport
|
||||
* @param payload A pointer to a git_smart_subtransport_definition
|
||||
* @return 0 or an error code
|
||||
*/
|
||||
GIT_EXTERN(int) git_transport_smart(
|
||||
git_transport **out,
|
||||
git_remote *owner,
|
||||
/* (git_smart_subtransport_definition *) */ void *payload);
|
||||
|
||||
/*
|
||||
*** End of base transport interface ***
|
||||
*** Begin interface for subtransports for the smart transport ***
|
||||
*/
|
||||
|
||||
/* The smart transport knows how to speak the git protocol, but it has no
|
||||
* knowledge of how to establish a connection between it and another endpoint,
|
||||
* or how to move data back and forth. For this, a subtransport interface is
|
||||
* declared, and the smart transport delegates this work to the subtransports.
|
||||
* Three subtransports are implemented: git, http, and winhttp. (The http and
|
||||
* winhttp transports each implement both http and https.) */
|
||||
|
||||
/* Subtransports can either be RPC = 0 (persistent connection) or RPC = 1
|
||||
* (request/response). The smart transport handles the differences in its own
|
||||
* logic. The git subtransport is RPC = 0, while http and winhttp are both
|
||||
* RPC = 1. */
|
||||
|
||||
/* Actions that the smart transport can ask
|
||||
* a subtransport to perform */
|
||||
typedef enum {
|
||||
GIT_SERVICE_UPLOADPACK_LS = 1,
|
||||
GIT_SERVICE_UPLOADPACK = 2,
|
||||
GIT_SERVICE_RECEIVEPACK_LS = 3,
|
||||
GIT_SERVICE_RECEIVEPACK = 4,
|
||||
} git_smart_service_t;
|
||||
|
||||
struct git_smart_subtransport;
|
||||
|
||||
/* A stream used by the smart transport to read and write data
|
||||
* from a subtransport */
|
||||
typedef struct git_smart_subtransport_stream {
|
||||
/* The owning subtransport */
|
||||
struct git_smart_subtransport *subtransport;
|
||||
|
||||
int (*read)(
|
||||
struct git_smart_subtransport_stream *stream,
|
||||
char *buffer,
|
||||
size_t buf_size,
|
||||
size_t *bytes_read);
|
||||
|
||||
int (*write)(
|
||||
struct git_smart_subtransport_stream *stream,
|
||||
const char *buffer,
|
||||
size_t len);
|
||||
|
||||
void (*free)(
|
||||
struct git_smart_subtransport_stream *stream);
|
||||
} git_smart_subtransport_stream;
|
||||
|
||||
/* An implementation of a subtransport which carries data for the
|
||||
* smart transport */
|
||||
typedef struct git_smart_subtransport {
|
||||
int (* action)(
|
||||
git_smart_subtransport_stream **out,
|
||||
struct git_smart_subtransport *transport,
|
||||
const char *url,
|
||||
git_smart_service_t action);
|
||||
|
||||
/* Subtransports are guaranteed a call to close() between
|
||||
* calls to action(), except for the following two "natural" progressions
|
||||
* of actions against a constant URL.
|
||||
*
|
||||
* 1. UPLOADPACK_LS -> UPLOADPACK
|
||||
* 2. RECEIVEPACK_LS -> RECEIVEPACK */
|
||||
int (* close)(struct git_smart_subtransport *transport);
|
||||
|
||||
void (* free)(struct git_smart_subtransport *transport);
|
||||
} git_smart_subtransport;
|
||||
|
||||
/* A function which creates a new subtransport for the smart transport */
|
||||
typedef int (*git_smart_subtransport_cb)(
|
||||
git_smart_subtransport **out,
|
||||
git_transport* owner);
|
||||
|
||||
typedef struct git_smart_subtransport_definition {
|
||||
/* The function to use to create the git_smart_subtransport */
|
||||
git_smart_subtransport_cb callback;
|
||||
|
||||
/* True if the protocol is stateless; false otherwise. For example,
|
||||
* http:// is stateless, but git:// is not. */
|
||||
unsigned rpc : 1;
|
||||
} git_smart_subtransport_definition;
|
||||
|
||||
/* Smart transport subtransports that come with libgit2 */
|
||||
|
||||
/**
|
||||
* Create an instance of the http subtransport. This subtransport
|
||||
* also supports https. On Win32, this subtransport may be implemented
|
||||
* using the WinHTTP library.
|
||||
*
|
||||
* @param out The newly created subtransport
|
||||
* @param owner The smart transport to own this subtransport
|
||||
* @return 0 or an error code
|
||||
*/
|
||||
GIT_EXTERN(int) git_smart_subtransport_http(
|
||||
git_smart_subtransport **out,
|
||||
git_transport* owner);
|
||||
|
||||
/**
|
||||
* Create an instance of the git subtransport.
|
||||
*
|
||||
* @param out The newly created subtransport
|
||||
* @param owner The smart transport to own this subtransport
|
||||
* @return 0 or an error code
|
||||
*/
|
||||
GIT_EXTERN(int) git_smart_subtransport_git(
|
||||
git_smart_subtransport **out,
|
||||
git_transport* owner);
|
||||
|
||||
/*
|
||||
*** End interface for subtransports for the smart transport ***
|
||||
*/
|
||||
|
||||
/** @} */
|
||||
GIT_END_DECL
|
||||
#endif
|
||||
@@ -1,387 +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_tree_h__
|
||||
#define INCLUDE_git_tree_h__
|
||||
|
||||
#include "common.h"
|
||||
#include "types.h"
|
||||
#include "oid.h"
|
||||
#include "object.h"
|
||||
|
||||
/**
|
||||
* @file git2/tree.h
|
||||
* @brief Git tree parsing, loading routines
|
||||
* @defgroup git_tree Git tree parsing, loading routines
|
||||
* @ingroup Git
|
||||
* @{
|
||||
*/
|
||||
GIT_BEGIN_DECL
|
||||
|
||||
/**
|
||||
* Lookup a tree object from the repository.
|
||||
*
|
||||
* @param out Pointer to the looked up tree
|
||||
* @param repo The repo to use when locating the tree.
|
||||
* @param id Identity of the tree to locate.
|
||||
* @return 0 or an error code
|
||||
*/
|
||||
GIT_INLINE(int) git_tree_lookup(
|
||||
git_tree **out, git_repository *repo, const git_oid *id)
|
||||
{
|
||||
return git_object_lookup((git_object **)out, repo, id, GIT_OBJ_TREE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Lookup a tree object from the repository,
|
||||
* given a prefix of its identifier (short id).
|
||||
*
|
||||
* @see git_object_lookup_prefix
|
||||
*
|
||||
* @param tree pointer to the looked up tree
|
||||
* @param repo the repo to use when locating the tree.
|
||||
* @param id identity of the tree to locate.
|
||||
* @param len the length of the short identifier
|
||||
* @return 0 or an error code
|
||||
*/
|
||||
GIT_INLINE(int) git_tree_lookup_prefix(
|
||||
git_tree **out,
|
||||
git_repository *repo,
|
||||
const git_oid *id,
|
||||
size_t len)
|
||||
{
|
||||
return git_object_lookup_prefix(
|
||||
(git_object **)out, repo, id, len, GIT_OBJ_TREE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Close an open tree
|
||||
*
|
||||
* You can no longer use the git_tree pointer after this call.
|
||||
*
|
||||
* IMPORTANT: You MUST call this method when you stop using a tree to
|
||||
* release memory. Failure to do so will cause a memory leak.
|
||||
*
|
||||
* @param tree The tree to close
|
||||
*/
|
||||
GIT_INLINE(void) git_tree_free(git_tree *tree)
|
||||
{
|
||||
git_object_free((git_object *)tree);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the id of a tree.
|
||||
*
|
||||
* @param tree a previously loaded tree.
|
||||
* @return object identity for the tree.
|
||||
*/
|
||||
GIT_EXTERN(const git_oid *) git_tree_id(const git_tree *tree);
|
||||
|
||||
/**
|
||||
* Get the repository that contains the tree.
|
||||
*
|
||||
* @param tree A previously loaded tree.
|
||||
* @return Repository that contains this tree.
|
||||
*/
|
||||
GIT_EXTERN(git_repository *) git_tree_owner(const git_tree *tree);
|
||||
|
||||
/**
|
||||
* Get the number of entries listed in a tree
|
||||
*
|
||||
* @param tree a previously loaded tree.
|
||||
* @return the number of entries in the tree
|
||||
*/
|
||||
GIT_EXTERN(size_t) git_tree_entrycount(const git_tree *tree);
|
||||
|
||||
/**
|
||||
* Lookup a tree entry by its filename
|
||||
*
|
||||
* This returns a git_tree_entry that is owned by the git_tree. You don't
|
||||
* have to free it, but you must not use it after the git_tree is released.
|
||||
*
|
||||
* @param tree a previously loaded tree.
|
||||
* @param filename the filename of the desired entry
|
||||
* @return the tree entry; NULL if not found
|
||||
*/
|
||||
GIT_EXTERN(const git_tree_entry *) git_tree_entry_byname(
|
||||
git_tree *tree, const char *filename);
|
||||
|
||||
/**
|
||||
* Lookup a tree entry by its position in the tree
|
||||
*
|
||||
* This returns a git_tree_entry that is owned by the git_tree. You don't
|
||||
* have to free it, but you must not use it after the git_tree is released.
|
||||
*
|
||||
* @param tree a previously loaded tree.
|
||||
* @param idx the position in the entry list
|
||||
* @return the tree entry; NULL if not found
|
||||
*/
|
||||
GIT_EXTERN(const git_tree_entry *) git_tree_entry_byindex(
|
||||
git_tree *tree, size_t idx);
|
||||
|
||||
/**
|
||||
* Lookup a tree entry by SHA value.
|
||||
*
|
||||
* This returns a git_tree_entry that is owned by the git_tree. You don't
|
||||
* have to free it, but you must not use it after the git_tree is released.
|
||||
*
|
||||
* Warning: this must examine every entry in the tree, so it is not fast.
|
||||
*
|
||||
* @param tree a previously loaded tree.
|
||||
* @param oid the sha being looked for
|
||||
* @return the tree entry; NULL if not found
|
||||
*/
|
||||
GIT_EXTERN(const git_tree_entry *) git_tree_entry_byoid(
|
||||
const git_tree *tree, const git_oid *oid);
|
||||
|
||||
/**
|
||||
* Retrieve a tree entry contained in a tree or in any of its subtrees,
|
||||
* given its relative path.
|
||||
*
|
||||
* Unlike the other lookup functions, the returned tree entry is owned by
|
||||
* the user and must be freed explicitly with `git_tree_entry_free()`.
|
||||
*
|
||||
* @param out Pointer where to store the tree entry
|
||||
* @param root Previously loaded tree which is the root of the relative path
|
||||
* @param subtree_path Path to the contained entry
|
||||
* @return 0 on success; GIT_ENOTFOUND if the path does not exist
|
||||
*/
|
||||
GIT_EXTERN(int) git_tree_entry_bypath(
|
||||
git_tree_entry **out,
|
||||
git_tree *root,
|
||||
const char *path);
|
||||
|
||||
/**
|
||||
* Duplicate a tree entry
|
||||
*
|
||||
* Create a copy of a tree entry. The returned copy is owned by the user,
|
||||
* and must be freed explicitly with `git_tree_entry_free()`.
|
||||
*
|
||||
* @param entry A tree entry to duplicate
|
||||
* @return a copy of the original entry or NULL on error (alloc failure)
|
||||
*/
|
||||
GIT_EXTERN(git_tree_entry *) git_tree_entry_dup(const git_tree_entry *entry);
|
||||
|
||||
/**
|
||||
* Free a user-owned tree entry
|
||||
*
|
||||
* IMPORTANT: This function is only needed for tree entries owned by the
|
||||
* user, such as the ones returned by `git_tree_entry_dup()` or
|
||||
* `git_tree_entry_bypath()`.
|
||||
*
|
||||
* @param entry The entry to free
|
||||
*/
|
||||
GIT_EXTERN(void) git_tree_entry_free(git_tree_entry *entry);
|
||||
|
||||
/**
|
||||
* Get the filename of a tree entry
|
||||
*
|
||||
* @param entry a tree entry
|
||||
* @return the name of the file
|
||||
*/
|
||||
GIT_EXTERN(const char *) git_tree_entry_name(const git_tree_entry *entry);
|
||||
|
||||
/**
|
||||
* Get the id of the object pointed by the entry
|
||||
*
|
||||
* @param entry a tree entry
|
||||
* @return the oid of the object
|
||||
*/
|
||||
GIT_EXTERN(const git_oid *) git_tree_entry_id(const git_tree_entry *entry);
|
||||
|
||||
/**
|
||||
* Get the type of the object pointed by the entry
|
||||
*
|
||||
* @param entry a tree entry
|
||||
* @return the type of the pointed object
|
||||
*/
|
||||
GIT_EXTERN(git_otype) git_tree_entry_type(const git_tree_entry *entry);
|
||||
|
||||
/**
|
||||
* Get the UNIX file attributes of a tree entry
|
||||
*
|
||||
* @param entry a tree entry
|
||||
* @return filemode as an integer
|
||||
*/
|
||||
GIT_EXTERN(git_filemode_t) git_tree_entry_filemode(const git_tree_entry *entry);
|
||||
|
||||
/**
|
||||
* Convert a tree entry to the git_object it points too.
|
||||
*
|
||||
* You must call `git_object_free()` on the object when you are done with it.
|
||||
*
|
||||
* @param object pointer to the converted object
|
||||
* @param repo repository where to lookup the pointed object
|
||||
* @param entry a tree entry
|
||||
* @return 0 or an error code
|
||||
*/
|
||||
GIT_EXTERN(int) git_tree_entry_to_object(
|
||||
git_object **object_out,
|
||||
git_repository *repo,
|
||||
const git_tree_entry *entry);
|
||||
|
||||
/**
|
||||
* Create a new tree builder.
|
||||
*
|
||||
* The tree builder can be used to create or modify trees in memory and
|
||||
* write them as tree objects to the database.
|
||||
*
|
||||
* If the `source` parameter is not NULL, the tree builder will be
|
||||
* initialized with the entries of the given tree.
|
||||
*
|
||||
* If the `source` parameter is NULL, the tree builder will start with no
|
||||
* entries and will have to be filled manually.
|
||||
*
|
||||
* @param out Pointer where to store the tree builder
|
||||
* @param source Source tree to initialize the builder (optional)
|
||||
* @return 0 on success; error code otherwise
|
||||
*/
|
||||
GIT_EXTERN(int) git_treebuilder_create(
|
||||
git_treebuilder **out, const git_tree *source);
|
||||
|
||||
/**
|
||||
* Clear all the entires in the builder
|
||||
*
|
||||
* @param bld Builder to clear
|
||||
*/
|
||||
GIT_EXTERN(void) git_treebuilder_clear(git_treebuilder *bld);
|
||||
|
||||
/**
|
||||
* Free a tree builder
|
||||
*
|
||||
* This will clear all the entries and free to builder.
|
||||
* Failing to free the builder after you're done using it
|
||||
* will result in a memory leak
|
||||
*
|
||||
* @param bld Builder to free
|
||||
*/
|
||||
GIT_EXTERN(void) git_treebuilder_free(git_treebuilder *bld);
|
||||
|
||||
/**
|
||||
* Get an entry from the builder from its filename
|
||||
*
|
||||
* The returned entry is owned by the builder and should
|
||||
* not be freed manually.
|
||||
*
|
||||
* @param bld Tree builder
|
||||
* @param filename Name of the entry
|
||||
* @return pointer to the entry; NULL if not found
|
||||
*/
|
||||
GIT_EXTERN(const git_tree_entry *) git_treebuilder_get(
|
||||
git_treebuilder *bld, const char *filename);
|
||||
|
||||
/**
|
||||
* Add or update an entry to the builder
|
||||
*
|
||||
* Insert a new entry for `filename` in the builder with the
|
||||
* given attributes.
|
||||
*
|
||||
* If an entry named `filename` already exists, its attributes
|
||||
* will be updated with the given ones.
|
||||
*
|
||||
* The optional pointer `out` can be used to retrieve a pointer to
|
||||
* the newly created/updated entry. Pass NULL if you do not need it.
|
||||
*
|
||||
* No attempt is being made to ensure that the provided oid points
|
||||
* to an existing git object in the object database, nor that the
|
||||
* attributes make sense regarding the type of the pointed at object.
|
||||
*
|
||||
* @param out Pointer to store the entry (optional)
|
||||
* @param bld Tree builder
|
||||
* @param filename Filename of the entry
|
||||
* @param id SHA1 oid of the entry
|
||||
* @param filemode Folder attributes of the entry. This parameter must
|
||||
* be valued with one of the following entries: 0040000, 0100644,
|
||||
* 0100755, 0120000 or 0160000.
|
||||
* @return 0 or an error code
|
||||
*/
|
||||
GIT_EXTERN(int) git_treebuilder_insert(
|
||||
const git_tree_entry **out,
|
||||
git_treebuilder *bld,
|
||||
const char *filename,
|
||||
const git_oid *id,
|
||||
git_filemode_t filemode);
|
||||
|
||||
/**
|
||||
* Remove an entry from the builder by its filename
|
||||
*
|
||||
* @param bld Tree builder
|
||||
* @param filename Filename of the entry to remove
|
||||
*/
|
||||
GIT_EXTERN(int) git_treebuilder_remove(
|
||||
git_treebuilder *bld, const char *filename);
|
||||
|
||||
typedef int (*git_treebuilder_filter_cb)(
|
||||
const git_tree_entry *entry, void *payload);
|
||||
|
||||
/**
|
||||
* Filter the entries in the tree
|
||||
*
|
||||
* The `filter` callback will be called for each entry in the tree with a
|
||||
* pointer to the entry and the provided `payload`; if the callback returns
|
||||
* non-zero, the entry will be filtered (removed from the builder).
|
||||
*
|
||||
* @param bld Tree builder
|
||||
* @param filter Callback to filter entries
|
||||
* @param payload Extra data to pass to filter
|
||||
*/
|
||||
GIT_EXTERN(void) git_treebuilder_filter(
|
||||
git_treebuilder *bld,
|
||||
git_treebuilder_filter_cb filter,
|
||||
void *payload);
|
||||
|
||||
/**
|
||||
* Write the contents of the tree builder as a tree object
|
||||
*
|
||||
* The tree builder will be written to the given `repo`, and its
|
||||
* identifying SHA1 hash will be stored in the `id` pointer.
|
||||
*
|
||||
* @param id Pointer to store the OID of the newly written tree
|
||||
* @param repo Repository in which to store the object
|
||||
* @param bld Tree builder to write
|
||||
* @return 0 or an error code
|
||||
*/
|
||||
GIT_EXTERN(int) git_treebuilder_write(
|
||||
git_oid *id, git_repository *repo, git_treebuilder *bld);
|
||||
|
||||
|
||||
/** Callback for the tree traversal method */
|
||||
typedef int (*git_treewalk_cb)(
|
||||
const char *root, const git_tree_entry *entry, void *payload);
|
||||
|
||||
/** Tree traversal modes */
|
||||
typedef enum {
|
||||
GIT_TREEWALK_PRE = 0, /* Pre-order */
|
||||
GIT_TREEWALK_POST = 1, /* Post-order */
|
||||
} git_treewalk_mode;
|
||||
|
||||
/**
|
||||
* Traverse the entries in a tree and its subtrees in post or pre order.
|
||||
*
|
||||
* The entries will be traversed in the specified order, children subtrees
|
||||
* will be automatically loaded as required, and the `callback` will be
|
||||
* called once per entry with the current (relative) root for the entry and
|
||||
* the entry data itself.
|
||||
*
|
||||
* If the callback returns a positive value, the passed entry will be
|
||||
* skipped on the traversal (in pre mode). A negative value stops the walk.
|
||||
*
|
||||
* @param tree The tree to walk
|
||||
* @param mode Traversal mode (pre or post-order)
|
||||
* @param callback Function to call on each tree entry
|
||||
* @param payload Opaque pointer to be passed on each callback
|
||||
* @return 0 or an error code
|
||||
*/
|
||||
GIT_EXTERN(int) git_tree_walk(
|
||||
const git_tree *tree,
|
||||
git_treewalk_mode mode,
|
||||
git_treewalk_cb callback,
|
||||
void *payload);
|
||||
|
||||
/** @} */
|
||||
|
||||
GIT_END_DECL
|
||||
#endif
|
||||
@@ -1,198 +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_types_h__
|
||||
#define INCLUDE_git_types_h__
|
||||
|
||||
#include "common.h"
|
||||
|
||||
/**
|
||||
* @file git2/types.h
|
||||
* @brief libgit2 base & compatibility types
|
||||
* @ingroup Git
|
||||
* @{
|
||||
*/
|
||||
GIT_BEGIN_DECL
|
||||
|
||||
/**
|
||||
* Cross-platform compatibility types for off_t / time_t
|
||||
*
|
||||
* NOTE: This needs to be in a public header so that both the library
|
||||
* implementation and client applications both agree on the same types.
|
||||
* Otherwise we get undefined behavior.
|
||||
*
|
||||
* Use the "best" types that each platform provides. Currently we truncate
|
||||
* these intermediate representations for compatibility with the git ABI, but
|
||||
* if and when it changes to support 64 bit types, our code will naturally
|
||||
* adapt.
|
||||
* NOTE: These types should match those that are returned by our internal
|
||||
* stat() functions, for all platforms.
|
||||
*/
|
||||
#include <sys/types.h>
|
||||
#ifdef __amigaos4__
|
||||
#include <stdint.h>
|
||||
#endif
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
|
||||
typedef __int64 git_off_t;
|
||||
typedef __time64_t git_time_t;
|
||||
|
||||
#elif defined(__MINGW32__)
|
||||
|
||||
typedef off64_t git_off_t;
|
||||
typedef __time64_t git_time_t;
|
||||
|
||||
#elif defined(__HAIKU__)
|
||||
|
||||
typedef __haiku_std_int64 git_off_t;
|
||||
typedef __haiku_std_int64 git_time_t;
|
||||
|
||||
#else /* POSIX */
|
||||
|
||||
/*
|
||||
* Note: Can't use off_t since if a client program includes <sys/types.h>
|
||||
* before us (directly or indirectly), they'll get 32 bit off_t in their client
|
||||
* app, even though /we/ define _FILE_OFFSET_BITS=64.
|
||||
*/
|
||||
typedef int64_t git_off_t;
|
||||
typedef int64_t git_time_t;
|
||||
|
||||
#endif
|
||||
|
||||
/** Basic type (loose or packed) of any Git object. */
|
||||
typedef enum {
|
||||
GIT_OBJ_ANY = -2, /**< Object can be any of the following */
|
||||
GIT_OBJ_BAD = -1, /**< Object is invalid. */
|
||||
GIT_OBJ__EXT1 = 0, /**< Reserved for future use. */
|
||||
GIT_OBJ_COMMIT = 1, /**< A commit object. */
|
||||
GIT_OBJ_TREE = 2, /**< A tree (directory listing) object. */
|
||||
GIT_OBJ_BLOB = 3, /**< A file revision object. */
|
||||
GIT_OBJ_TAG = 4, /**< An annotated tag object. */
|
||||
GIT_OBJ__EXT2 = 5, /**< Reserved for future use. */
|
||||
GIT_OBJ_OFS_DELTA = 6, /**< A delta, base is given by an offset. */
|
||||
GIT_OBJ_REF_DELTA = 7, /**< A delta, base is given by object id. */
|
||||
} git_otype;
|
||||
|
||||
/** An open object database handle. */
|
||||
typedef struct git_odb git_odb;
|
||||
|
||||
/** A custom backend in an ODB */
|
||||
typedef struct git_odb_backend git_odb_backend;
|
||||
|
||||
/** An object read from the ODB */
|
||||
typedef struct git_odb_object git_odb_object;
|
||||
|
||||
/** A stream to read/write from the ODB */
|
||||
typedef struct git_odb_stream git_odb_stream;
|
||||
|
||||
/** A stream to write a packfile to the ODB */
|
||||
typedef struct git_odb_writepack git_odb_writepack;
|
||||
|
||||
/**
|
||||
* Representation of an existing git repository,
|
||||
* including all its object contents
|
||||
*/
|
||||
typedef struct git_repository git_repository;
|
||||
|
||||
/** Representation of a generic object in a repository */
|
||||
typedef struct git_object git_object;
|
||||
|
||||
/** Representation of an in-progress walk through the commits in a repo */
|
||||
typedef struct git_revwalk git_revwalk;
|
||||
|
||||
/** Parsed representation of a tag object. */
|
||||
typedef struct git_tag git_tag;
|
||||
|
||||
/** In-memory representation of a blob object. */
|
||||
typedef struct git_blob git_blob;
|
||||
|
||||
/** Parsed representation of a commit object. */
|
||||
typedef struct git_commit git_commit;
|
||||
|
||||
/** Representation of each one of the entries in a tree object. */
|
||||
typedef struct git_tree_entry git_tree_entry;
|
||||
|
||||
/** Representation of a tree object. */
|
||||
typedef struct git_tree git_tree;
|
||||
|
||||
/** Constructor for in-memory trees */
|
||||
typedef struct git_treebuilder git_treebuilder;
|
||||
|
||||
/** Memory representation of an index file. */
|
||||
typedef struct git_index git_index;
|
||||
|
||||
/** Memory representation of a set of config files */
|
||||
typedef struct git_config git_config;
|
||||
|
||||
/** Interface to access a configuration file */
|
||||
typedef struct git_config_backend git_config_backend;
|
||||
|
||||
/** Representation of a reference log entry */
|
||||
typedef struct git_reflog_entry git_reflog_entry;
|
||||
|
||||
/** Representation of a reference log */
|
||||
typedef struct git_reflog git_reflog;
|
||||
|
||||
/** Representation of a git note */
|
||||
typedef struct git_note git_note;
|
||||
|
||||
/** Representation of a git packbuilder */
|
||||
typedef struct git_packbuilder git_packbuilder;
|
||||
|
||||
/** Time in a signature */
|
||||
typedef struct git_time {
|
||||
git_time_t time; /** time in seconds from epoch */
|
||||
int offset; /** timezone offset, in minutes */
|
||||
} git_time;
|
||||
|
||||
/** An action signature (e.g. for committers, taggers, etc) */
|
||||
typedef struct git_signature {
|
||||
char *name; /** full name of the author */
|
||||
char *email; /** email of the author */
|
||||
git_time when; /** time when the action happened */
|
||||
} git_signature;
|
||||
|
||||
/** In-memory representation of a reference. */
|
||||
typedef struct git_reference git_reference;
|
||||
|
||||
/** Basic type of any Git reference. */
|
||||
typedef enum {
|
||||
GIT_REF_INVALID = 0, /** Invalid reference */
|
||||
GIT_REF_OID = 1, /** A reference which points at an object id */
|
||||
GIT_REF_SYMBOLIC = 2, /** A reference which points at another reference */
|
||||
GIT_REF_PACKED = 4,
|
||||
GIT_REF_HAS_PEEL = 8,
|
||||
GIT_REF_LISTALL = GIT_REF_OID|GIT_REF_SYMBOLIC|GIT_REF_PACKED,
|
||||
} git_ref_t;
|
||||
|
||||
/** Basic type of any Git branch. */
|
||||
typedef enum {
|
||||
GIT_BRANCH_LOCAL = 1,
|
||||
GIT_BRANCH_REMOTE = 2,
|
||||
} git_branch_t;
|
||||
|
||||
/** Valid modes for index and tree entries. */
|
||||
typedef enum {
|
||||
GIT_FILEMODE_NEW = 0000000,
|
||||
GIT_FILEMODE_TREE = 0040000,
|
||||
GIT_FILEMODE_BLOB = 0100644,
|
||||
GIT_FILEMODE_BLOB_EXECUTABLE = 0100755,
|
||||
GIT_FILEMODE_LINK = 0120000,
|
||||
GIT_FILEMODE_COMMIT = 0160000,
|
||||
} git_filemode_t;
|
||||
|
||||
typedef struct git_refspec git_refspec;
|
||||
typedef struct git_remote git_remote;
|
||||
typedef struct git_push git_push;
|
||||
|
||||
typedef struct git_remote_head git_remote_head;
|
||||
typedef struct git_remote_callbacks git_remote_callbacks;
|
||||
|
||||
/** @} */
|
||||
GIT_END_DECL
|
||||
|
||||
#endif
|
||||
@@ -1,15 +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_version_h__
|
||||
#define INCLUDE_git_version_h__
|
||||
|
||||
#define LIBGIT2_VERSION "0.17.0"
|
||||
#define LIBGIT2_VER_MAJOR 0
|
||||
#define LIBGIT2_VER_MINOR 17
|
||||
#define LIBGIT2_VER_REVISION 0
|
||||
|
||||
#endif
|
||||
@@ -1,50 +0,0 @@
|
||||
{
|
||||
'variables': {
|
||||
'includes_common': [
|
||||
'git2/include/git2.h',
|
||||
'git2/include/git2/attr.h',
|
||||
'git2/include/git2/blob.h',
|
||||
'git2/include/git2/branch.h',
|
||||
'git2/include/git2/commit.h',
|
||||
'git2/include/git2/common.h',
|
||||
'git2/include/git2/config.h',
|
||||
'git2/include/git2/diff.h',
|
||||
'git2/include/git2/errors.h',
|
||||
'git2/include/git2/index.h',
|
||||
'git2/include/git2/indexer.h',
|
||||
'git2/include/git2/merge.h',
|
||||
'git2/include/git2/net.h',
|
||||
'git2/include/git2/notes.h',
|
||||
'git2/include/git2/object.h',
|
||||
'git2/include/git2/odb.h',
|
||||
'git2/include/git2/odb_backend.h',
|
||||
'git2/include/git2/oid.h',
|
||||
'git2/include/git2/reflog.h',
|
||||
'git2/include/git2/refs.h',
|
||||
'git2/include/git2/refspec.h',
|
||||
'git2/include/git2/remote.h',
|
||||
'git2/include/git2/repository.h',
|
||||
'git2/include/git2/revwalk.h',
|
||||
'git2/include/git2/signature.h',
|
||||
'git2/include/git2/status.h',
|
||||
'git2/include/git2/submodule.h',
|
||||
'git2/include/git2/tag.h',
|
||||
'git2/include/git2/threads.h',
|
||||
'git2/include/git2/tree.h',
|
||||
'git2/include/git2/types.h',
|
||||
'git2/include/git2/version.h',
|
||||
'git2/include/git2/checkout.h',
|
||||
'git2/include/git2/clone.h',
|
||||
'git2/include/git2/ignore.h',
|
||||
'git2/include/git2/message.h',
|
||||
'git2/include/git2/pack.h',
|
||||
'git2/include/git2/reset.h',
|
||||
'git2/include/git2/revparse.h',
|
||||
'git2/include/git2/strarray.h',
|
||||
'git2/include/git2/graph.h',
|
||||
'git2/include/git2/push.h',
|
||||
'git2/include/git2/stash.h',
|
||||
'git2/include/git2/transport.h',
|
||||
],
|
||||
}
|
||||
}
|
||||
@@ -16,17 +16,6 @@ class AtomCefRenderProcessHandler : public CefRenderProcessHandler {
|
||||
virtual bool OnProcessMessageReceived(CefRefPtr<CefBrowser> browser,
|
||||
CefProcessId source_process,
|
||||
CefRefPtr<CefProcessMessage> message) OVERRIDE;
|
||||
virtual void OnWorkerContextCreated(int worker_id,
|
||||
const CefString& url,
|
||||
CefRefPtr<CefV8Context> context) OVERRIDE;
|
||||
virtual void OnWorkerContextReleased(int worker_id,
|
||||
const CefString& url,
|
||||
CefRefPtr<CefV8Context> context) OVERRIDE;
|
||||
virtual void OnWorkerUncaughtException(int worker_id,
|
||||
const CefString& url,
|
||||
CefRefPtr<CefV8Context> context,
|
||||
CefRefPtr<CefV8Exception> exception,
|
||||
CefRefPtr<CefV8StackTrace> stackTrace) OVERRIDE;
|
||||
|
||||
void Reload(CefRefPtr<CefBrowser> browser);
|
||||
void Shutdown(CefRefPtr<CefBrowser> browser);
|
||||
@@ -37,4 +26,3 @@ class AtomCefRenderProcessHandler : public CefRenderProcessHandler {
|
||||
};
|
||||
|
||||
#endif // ATOM_CEF_RENDER_PROCESS_HANDLER_H_
|
||||
|
||||
|
||||
@@ -1,10 +1,6 @@
|
||||
#import <iostream>
|
||||
#import "native/v8_extensions/atom.h"
|
||||
#import "native/v8_extensions/native.h"
|
||||
#import "native/v8_extensions/onig_reg_exp.h"
|
||||
#import "native/v8_extensions/onig_scanner.h"
|
||||
#import "native/v8_extensions/git.h"
|
||||
#import "native/v8_extensions/tags.h"
|
||||
#import "native/message_translation.h"
|
||||
#import "path_watcher.h"
|
||||
#import "atom_cef_render_process_handler.h"
|
||||
@@ -25,27 +21,6 @@ void AtomCefRenderProcessHandler::OnContextReleased(CefRefPtr<CefBrowser> browse
|
||||
[PathWatcher removePathWatcherForContext:context];
|
||||
}
|
||||
|
||||
void AtomCefRenderProcessHandler::OnWorkerContextCreated(int worker_id,
|
||||
const CefString& url,
|
||||
CefRefPtr<CefV8Context> context) {
|
||||
InjectExtensionsIntoV8Context(context);
|
||||
}
|
||||
|
||||
void AtomCefRenderProcessHandler::OnWorkerContextReleased(int worker_id,
|
||||
const CefString& url,
|
||||
CefRefPtr<CefV8Context> context) {
|
||||
}
|
||||
|
||||
void AtomCefRenderProcessHandler::OnWorkerUncaughtException(int worker_id,
|
||||
const CefString& url,
|
||||
CefRefPtr<CefV8Context> context,
|
||||
CefRefPtr<CefV8Exception> exception,
|
||||
CefRefPtr<CefV8StackTrace> stackTrace) {
|
||||
|
||||
std::string message = exception->GetMessage().ToString();
|
||||
NSLog(@"Exception throw in worker thread %s", message.c_str());
|
||||
}
|
||||
|
||||
bool AtomCefRenderProcessHandler::OnProcessMessageReceived(CefRefPtr<CefBrowser> browser,
|
||||
CefProcessId source_process,
|
||||
CefRefPtr<CefProcessMessage> message) {
|
||||
@@ -122,8 +97,4 @@ void AtomCefRenderProcessHandler::InjectExtensionsIntoV8Context(CefRefPtr<CefV8C
|
||||
// these objects are deleted when the context removes all references to them
|
||||
(new v8_extensions::Atom())->CreateContextBinding(context);
|
||||
(new v8_extensions::Native())->CreateContextBinding(context);
|
||||
(new v8_extensions::Git())->CreateContextBinding(context);
|
||||
(new v8_extensions::OnigRegExp())->CreateContextBinding(context);
|
||||
(new v8_extensions::OnigScanner())->CreateContextBinding(context);
|
||||
(new v8_extensions::Tags())->CreateContextBinding(context);
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ class AtomCefClient;
|
||||
NSSplitView *_splitView;
|
||||
NSView *_devToolsView;
|
||||
NSView *_webView;
|
||||
NSButton *_devButton;
|
||||
NSString *_bootstrapScript;
|
||||
NSString *_resourcePath;
|
||||
NSString *_pathToOpen;
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
[_splitView release];
|
||||
[_devToolsView release];
|
||||
[_webView release];
|
||||
[_devButton release];
|
||||
[_bootstrapScript release];
|
||||
[_resourcePath release];
|
||||
[_pathToOpen release];
|
||||
@@ -26,26 +27,31 @@
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (id)initWithBootstrapScript:(NSString *)bootstrapScript background:(BOOL)background alwaysUseBundleResourcePath:(BOOL)alwaysUseBundleResourcePath {
|
||||
- (id)initWithBootstrapScript:(NSString *)bootstrapScript background:(BOOL)background useBundleResourcePath:(BOOL)useBundleResourcePath {
|
||||
self = [super initWithWindowNibName:@"AtomWindow"];
|
||||
_bootstrapScript = [bootstrapScript retain];
|
||||
|
||||
AtomApplication *atomApplication = (AtomApplication *)[AtomApplication sharedApplication];
|
||||
|
||||
_resourcePath = [atomApplication.arguments objectForKey:@"resource-path"];
|
||||
if (!alwaysUseBundleResourcePath && !_resourcePath) {
|
||||
NSString *defaultRepositoryPath = [@"~/github/atom" stringByStandardizingPath];
|
||||
if ([defaultRepositoryPath characterAtIndex:0] == '/') {
|
||||
BOOL isDir = false;
|
||||
BOOL exists = [[NSFileManager defaultManager] fileExistsAtPath:defaultRepositoryPath isDirectory:&isDir];
|
||||
if (isDir && exists)
|
||||
_resourcePath = defaultRepositoryPath;
|
||||
}
|
||||
}
|
||||
|
||||
if (alwaysUseBundleResourcePath || !_resourcePath) {
|
||||
if (useBundleResourcePath) {
|
||||
_resourcePath = [[NSBundle bundleForClass:self.class] resourcePath];
|
||||
}
|
||||
else {
|
||||
_resourcePath = [[atomApplication.arguments objectForKey:@"resource-path"] stringByStandardizingPath];
|
||||
if (!_resourcePath) {
|
||||
NSString *defaultRepositoryPath = [@"~/github/atom" stringByStandardizingPath];
|
||||
if ([defaultRepositoryPath characterAtIndex:0] == '/') {
|
||||
BOOL isDir = false;
|
||||
BOOL exists = [[NSFileManager defaultManager] fileExistsAtPath:defaultRepositoryPath isDirectory:&isDir];
|
||||
if (isDir && exists) {
|
||||
_resourcePath = defaultRepositoryPath;
|
||||
}
|
||||
else {
|
||||
NSLog(@"Warning: No resource path specified and no directory exists at ~/github/atom");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ([self isDevMode]) {
|
||||
[self displayDevIcon];
|
||||
@@ -54,6 +60,36 @@
|
||||
_resourcePath = [_resourcePath stringByStandardizingPath];
|
||||
[_resourcePath retain];
|
||||
|
||||
NSMutableArray *paths = [NSMutableArray arrayWithObjects:
|
||||
@"src/stdlib",
|
||||
@"src/app",
|
||||
@"src/packages",
|
||||
@"src",
|
||||
@"vendor",
|
||||
@"static",
|
||||
@"node_modules",
|
||||
nil];
|
||||
NSMutableArray *resourcePaths = [[NSMutableArray alloc] init];
|
||||
|
||||
if (_runningSpecs) {
|
||||
[paths insertObject:@"benchmark" atIndex:0];
|
||||
[paths insertObject:@"spec" atIndex:0];
|
||||
NSString *fixturePackagesDirectory = [NSString stringWithFormat:@"%@/spec/fixtures/packages", _resourcePath];
|
||||
[resourcePaths addObject:fixturePackagesDirectory];
|
||||
}
|
||||
|
||||
NSString *userPackagesDirectory = [@"~/.atom/packages" stringByStandardizingPath];
|
||||
[resourcePaths addObject:userPackagesDirectory];
|
||||
|
||||
for (int i = 0; i < paths.count; i++) {
|
||||
NSString *fullPath = [NSString stringWithFormat:@"%@/%@", _resourcePath, [paths objectAtIndex:i]];
|
||||
[resourcePaths addObject:fullPath];
|
||||
}
|
||||
[resourcePaths addObject:_resourcePath];
|
||||
|
||||
NSString *nodePath = [resourcePaths componentsJoinedByString:@":"];
|
||||
setenv("NODE_PATH", [nodePath UTF8String], TRUE);
|
||||
|
||||
if (!background) {
|
||||
[self setShouldCascadeWindows:NO];
|
||||
[self setWindowFrameAutosaveName:@"AtomWindow"];
|
||||
@@ -69,19 +105,19 @@
|
||||
_pathToOpen = [path retain];
|
||||
AtomApplication *atomApplication = (AtomApplication *)[AtomApplication sharedApplication];
|
||||
BOOL useBundleResourcePath = [atomApplication.arguments objectForKey:@"dev"] == nil;
|
||||
return [self initWithBootstrapScript:@"window-bootstrap" background:NO alwaysUseBundleResourcePath:useBundleResourcePath];
|
||||
return [self initWithBootstrapScript:@"window-bootstrap" background:NO useBundleResourcePath:useBundleResourcePath];
|
||||
}
|
||||
|
||||
- (id)initDevWithPath:(NSString *)path {
|
||||
_pathToOpen = [path retain];
|
||||
return [self initWithBootstrapScript:@"window-bootstrap" background:NO alwaysUseBundleResourcePath:false];
|
||||
return [self initWithBootstrapScript:@"window-bootstrap" background:NO useBundleResourcePath:false];
|
||||
}
|
||||
|
||||
- (id)initInBackground {
|
||||
AtomApplication *atomApplication = (AtomApplication *)[AtomApplication sharedApplication];
|
||||
BOOL useBundleResourcePath = [atomApplication.arguments objectForKey:@"dev"] == nil;
|
||||
|
||||
[self initWithBootstrapScript:@"window-bootstrap" background:YES alwaysUseBundleResourcePath:useBundleResourcePath];
|
||||
[self initWithBootstrapScript:@"window-bootstrap" background:YES useBundleResourcePath:useBundleResourcePath];
|
||||
[self.window setFrame:NSMakeRect(0, 0, 0, 0) display:NO];
|
||||
[self.window setExcludedFromWindowsMenu:YES];
|
||||
[self.window setCollectionBehavior:NSWindowCollectionBehaviorStationary];
|
||||
@@ -91,13 +127,13 @@
|
||||
- (id)initSpecsThenExit:(BOOL)exitWhenDone {
|
||||
_runningSpecs = true;
|
||||
_exitWhenDone = exitWhenDone;
|
||||
return [self initWithBootstrapScript:@"spec-bootstrap" background:NO alwaysUseBundleResourcePath:NO];
|
||||
return [self initWithBootstrapScript:@"spec-bootstrap" background:NO useBundleResourcePath:NO];
|
||||
}
|
||||
|
||||
- (id)initBenchmarksThenExit:(BOOL)exitWhenDone {
|
||||
_runningSpecs = true;
|
||||
_exitWhenDone = exitWhenDone;
|
||||
return [self initWithBootstrapScript:@"benchmark-bootstrap" background:NO alwaysUseBundleResourcePath:NO];
|
||||
return [self initWithBootstrapScript:@"benchmark-bootstrap" background:NO useBundleResourcePath:NO];
|
||||
}
|
||||
|
||||
- (void)addBrowserToView:(NSView *)view url:(const char *)url cefHandler:(CefRefPtr<AtomCefClient>)cefClient {
|
||||
@@ -123,9 +159,10 @@
|
||||
// have the correct initial size based on the frame's last stored size.
|
||||
// HACK: I hate this and want to place this code directly in windowDidLoad
|
||||
- (void)attachWebView {
|
||||
NSURL *url = [[NSBundle bundleForClass:self.class] resourceURL];
|
||||
NSMutableString *urlString = [NSMutableString string];
|
||||
[urlString appendString:[[url URLByAppendingPathComponent:@"static/index.html"] absoluteString]];
|
||||
|
||||
NSURL *indexUrl = [[NSURL alloc] initFileURLWithPath:[_resourcePath stringByAppendingPathComponent:@"static/index.html"]];
|
||||
[urlString appendString:[indexUrl absoluteString]];
|
||||
[urlString appendFormat:@"?bootstrapScript=%@", [self encodeUrlParam:_bootstrapScript]];
|
||||
[urlString appendFormat:@"&resourcePath=%@", [self encodeUrlParam:_resourcePath]];
|
||||
if ([self isDevMode])
|
||||
@@ -208,6 +245,16 @@
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (void)windowWillEnterFullScreen:(NSNotification *)notification {
|
||||
if (_devButton)
|
||||
[_devButton setHidden:YES];
|
||||
}
|
||||
|
||||
- (void)windowDidExitFullScreen:(NSNotification *)notification {
|
||||
if (_devButton)
|
||||
[_devButton setHidden:NO];
|
||||
}
|
||||
|
||||
- (bool)isDevMode {
|
||||
NSString *bundleResourcePath = [[NSBundle bundleForClass:self.class] resourcePath];
|
||||
return ![_resourcePath isEqualToString:bundleResourcePath];
|
||||
@@ -224,55 +271,43 @@
|
||||
break;
|
||||
}
|
||||
|
||||
NSButton *devButton = [[NSButton alloc] init];
|
||||
[devButton setTitle:@"\xF0\x9F\x92\x80"];
|
||||
devButton.autoresizingMask = NSViewMinXMargin | NSViewMinYMargin;
|
||||
devButton.buttonType = NSMomentaryChangeButton;
|
||||
devButton.bordered = NO;
|
||||
[devButton sizeToFit];
|
||||
devButton.frame = NSMakeRect(fullScreenButton.frame.origin.x - devButton.frame.size.width - 5, fullScreenButton.frame.origin.y, devButton.frame.size.width, devButton.frame.size.height);
|
||||
_devButton = [[NSButton alloc] init];
|
||||
[_devButton setTitle:@"\xF0\x9F\x92\x80"];
|
||||
_devButton.autoresizingMask = NSViewMinXMargin | NSViewMinYMargin;
|
||||
_devButton.buttonType = NSMomentaryChangeButton;
|
||||
_devButton.bordered = NO;
|
||||
[_devButton sizeToFit];
|
||||
_devButton.frame = NSMakeRect(fullScreenButton.frame.origin.x - _devButton.frame.size.width - 5, fullScreenButton.frame.origin.y, _devButton.frame.size.width, _devButton.frame.size.height);
|
||||
|
||||
[[self.window.contentView superview] addSubview:devButton];
|
||||
[[self.window.contentView superview] addSubview:_devButton];
|
||||
}
|
||||
|
||||
- (void)populateBrowserSettings:(CefBrowserSettings &)settings {
|
||||
CefString(&settings.default_encoding) = "UTF-8";
|
||||
settings.remote_fonts_disabled = false;
|
||||
settings.encoding_detector_enabled = false;
|
||||
settings.javascript_disabled = false;
|
||||
settings.javascript_open_windows_disallowed = false;
|
||||
settings.javascript_close_windows_disallowed = false;
|
||||
settings.javascript_access_clipboard_disallowed = false;
|
||||
settings.dom_paste_disabled = true;
|
||||
settings.caret_browsing_enabled = false;
|
||||
settings.java_disabled = true;
|
||||
settings.plugins_disabled = true;
|
||||
settings.universal_access_from_file_urls_allowed = false;
|
||||
settings.file_access_from_file_urls_allowed = false;
|
||||
settings.web_security_disabled = true;
|
||||
settings.xss_auditor_enabled = true;
|
||||
settings.image_load_disabled = false;
|
||||
settings.shrink_standalone_images_to_fit = false;
|
||||
settings.site_specific_quirks_disabled = false;
|
||||
settings.text_area_resize_disabled = false;
|
||||
settings.page_cache_disabled = true;
|
||||
settings.tab_to_links_disabled = true;
|
||||
settings.hyperlink_auditing_disabled = true;
|
||||
settings.user_style_sheet_enabled = false;
|
||||
settings.author_and_user_styles_disabled = false;
|
||||
settings.local_storage_disabled = false;
|
||||
settings.databases_disabled = false;
|
||||
settings.application_cache_disabled = false;
|
||||
settings.webgl_disabled = false;
|
||||
settings.accelerated_compositing_disabled = false;
|
||||
settings.accelerated_layers_disabled = false;
|
||||
settings.accelerated_video_disabled = false;
|
||||
settings.accelerated_2d_canvas_disabled = false;
|
||||
// settings.accelerated_painting_enabled = true;
|
||||
// settings.accelerated_filters_enabled = true;
|
||||
settings.accelerated_plugins_disabled = false;
|
||||
settings.developer_tools_disabled = false;
|
||||
// settings.fullscreen_enabled = true;
|
||||
settings.remote_fonts = STATE_ENABLED;
|
||||
settings.javascript = STATE_ENABLED;
|
||||
settings.javascript_open_windows = STATE_ENABLED;
|
||||
settings.javascript_close_windows = STATE_ENABLED;
|
||||
settings.javascript_access_clipboard = STATE_ENABLED;
|
||||
settings.javascript_dom_paste = STATE_DISABLED;
|
||||
settings.caret_browsing = STATE_DISABLED;
|
||||
settings.java = STATE_DISABLED;
|
||||
settings.plugins = STATE_DISABLED;
|
||||
settings.universal_access_from_file_urls = STATE_DISABLED;
|
||||
settings.file_access_from_file_urls = STATE_DISABLED;
|
||||
settings.web_security = STATE_DISABLED;
|
||||
settings.image_loading = STATE_ENABLED;
|
||||
settings.image_shrink_standalone_to_fit = STATE_DISABLED;
|
||||
settings.text_area_resize = STATE_ENABLED;
|
||||
settings.page_cache = STATE_DISABLED;
|
||||
settings.tab_to_links = STATE_DISABLED;
|
||||
settings.author_and_user_styles = STATE_ENABLED;
|
||||
settings.local_storage = STATE_ENABLED;
|
||||
settings.databases = STATE_ENABLED;
|
||||
settings.application_cache = STATE_ENABLED;
|
||||
settings.webgl = STATE_ENABLED;
|
||||
settings.accelerated_compositing = STATE_ENABLED;
|
||||
settings.developer_tools = STATE_ENABLED;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
Binary file not shown.
@@ -1,91 +0,0 @@
|
||||
// CocoaOniguruma is copyrighted free software by Satoshi Nakagawa <psychs AT limechat DOT net>.
|
||||
// You can redistribute it and/or modify it under the new BSD license.
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "oniguruma.h"
|
||||
#import "OnigRegexpUtility.h"
|
||||
|
||||
|
||||
@class OnigResult;
|
||||
|
||||
typedef enum {
|
||||
OnigOptionNone = ONIG_OPTION_NONE,
|
||||
OnigOptionIgnorecase = ONIG_OPTION_IGNORECASE,
|
||||
OnigOptionExtend = ONIG_OPTION_EXTEND,
|
||||
OnigOptionMultiline = ONIG_OPTION_MULTILINE,
|
||||
OnigOptionSingleline = ONIG_OPTION_SINGLELINE,
|
||||
OnigOptionFindLongest = ONIG_OPTION_FIND_LONGEST,
|
||||
OnigOptionFindNotEmpty = ONIG_OPTION_FIND_NOT_EMPTY,
|
||||
OnigOptionNegateSingleLine = ONIG_OPTION_NEGATE_SINGLELINE,
|
||||
OnigOptionDontCaptureGroup = ONIG_OPTION_DONT_CAPTURE_GROUP,
|
||||
OnigOptionCaptureGroup = ONIG_OPTION_CAPTURE_GROUP,
|
||||
|
||||
/* options (search time) */
|
||||
OnigOptionNotbol = ONIG_OPTION_NOTBOL,
|
||||
OnigOptionNoteol = ONIG_OPTION_NOTEOL,
|
||||
OnigOptionPosixRegion = ONIG_OPTION_POSIX_REGION,
|
||||
OnigOptionMaxbit = ONIG_OPTION_MAXBIT
|
||||
} OnigOption;
|
||||
|
||||
@interface OnigRegexp : NSObject
|
||||
{
|
||||
regex_t* _entity;
|
||||
NSString* _expression;
|
||||
}
|
||||
|
||||
+ (OnigRegexp*)compile:(NSString*)expression;
|
||||
+ (OnigRegexp*)compile:(NSString*)expression error:(NSError **)error;
|
||||
+ (OnigRegexp*)compileIgnorecase:(NSString*)expression;
|
||||
+ (OnigRegexp*)compileIgnorecase:(NSString*)expression error:(NSError **)error;
|
||||
+ (OnigRegexp*)compile:(NSString*)expression ignorecase:(BOOL)ignorecase multiline:(BOOL)multiline;
|
||||
+ (OnigRegexp*)compile:(NSString*)expression ignorecase:(BOOL)ignorecase multiline:(BOOL)multiline error:(NSError **)error;
|
||||
+ (OnigRegexp*)compile:(NSString*)expression ignorecase:(BOOL)ignorecase multiline:(BOOL)multiline extended:(BOOL)extended;
|
||||
+ (OnigRegexp*)compile:(NSString*)expression ignorecase:(BOOL)ignorecase multiline:(BOOL)multiline extended:(BOOL)extended error:(NSError **)error;
|
||||
+ (OnigRegexp*)compile:(NSString*)expression options:(OnigOption)options;
|
||||
+ (OnigRegexp*)compile:(NSString*)expression options:(OnigOption)options error:(NSError **)error;
|
||||
|
||||
- (OnigResult*)search:(NSString*)target;
|
||||
- (OnigResult*)search:(NSString*)target start:(int)start;
|
||||
- (OnigResult*)search:(NSString*)target start:(int)start end:(int)end;
|
||||
- (OnigResult*)search:(NSString*)target range:(NSRange)range;
|
||||
|
||||
- (OnigResult*)match:(NSString*)target;
|
||||
- (OnigResult*)match:(NSString*)target start:(int)start;
|
||||
|
||||
- (NSUInteger)captureCount;
|
||||
- (NSString*)expression;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@interface OnigResult : NSObject
|
||||
{
|
||||
OnigRegexp* _expression;
|
||||
OnigRegion* _region;
|
||||
NSString* _target;
|
||||
NSMutableArray* _captureNames;
|
||||
}
|
||||
|
||||
- (NSString*)target;
|
||||
|
||||
- (int)count;
|
||||
- (NSString*)stringAt:(int)index;
|
||||
- (NSArray*)strings;
|
||||
- (NSRange)rangeAt:(int)index;
|
||||
- (int)locationAt:(int)index;
|
||||
- (int)lengthAt:(int)index;
|
||||
|
||||
- (NSString*)body;
|
||||
- (NSRange)bodyRange;
|
||||
|
||||
- (NSString*)preMatch;
|
||||
- (NSString*)postMatch;
|
||||
|
||||
// named capture support
|
||||
- (NSArray*)captureNames;
|
||||
- (int)indexForName:(NSString*)name;
|
||||
- (NSIndexSet*)indexesForName:(NSString*)name;
|
||||
- (NSString*)stringForName:(NSString*)name;
|
||||
- (NSArray*)stringsForName:(NSString*)name;
|
||||
|
||||
@end
|
||||
@@ -1,57 +0,0 @@
|
||||
// CocoaOniguruma is copyrighted free software by Satoshi Nakagawa <psychs AT limechat DOT net>.
|
||||
// You can redistribute it and/or modify it under the new BSD license.
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "oniguruma.h"
|
||||
#import "OnigRegexp.h"
|
||||
|
||||
|
||||
@class OnigRegexp;
|
||||
@class OnigResult;
|
||||
|
||||
|
||||
@interface NSString (OnigRegexpUtility)
|
||||
|
||||
// pattern is OnigRegexp or NSString
|
||||
|
||||
- (NSRange)rangeOfRegexp:(id)pattern;
|
||||
|
||||
// based on ruby's split
|
||||
|
||||
- (NSArray*)split;
|
||||
- (NSArray*)splitByRegexp:(id)pattern;
|
||||
- (NSArray*)splitByRegexp:(id)pattern limit:(int)limit;
|
||||
|
||||
// based on ruby's gsub
|
||||
|
||||
- (NSString*)replaceByRegexp:(id)pattern with:(NSString*)string;
|
||||
- (NSString*)replaceAllByRegexp:(id)pattern with:(NSString*)string;
|
||||
|
||||
- (NSString*)replaceByRegexp:(id)pattern withCallback:(id)object selector:(SEL)sel;
|
||||
- (NSString*)replaceAllByRegexp:(id)pattern withCallback:(id)object selector:(SEL)sel;
|
||||
|
||||
#if defined(NS_BLOCKS_AVAILABLE)
|
||||
- (NSString*)replaceByRegexp:(id)pattern withBlock:(NSString* (^)(OnigResult*))block;
|
||||
- (NSString*)replaceAllByRegexp:(id)pattern withBlock:(NSString* (^)(OnigResult*))block;
|
||||
#endif
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@interface NSMutableString (OnigRegexpUtility)
|
||||
|
||||
// pattern is OnigRegexp or NSString
|
||||
|
||||
// based on ruby's gsub
|
||||
|
||||
- (NSMutableString*)replaceByRegexp:(id)pattern with:(NSString*)string;
|
||||
- (NSMutableString*)replaceAllByRegexp:(id)pattern with:(NSString*)string;
|
||||
|
||||
- (NSMutableString*)replaceByRegexp:(id)pattern withCallback:(id)object selector:(SEL)sel;
|
||||
- (NSMutableString*)replaceAllByRegexp:(id)pattern withCallback:(id)object selector:(SEL)sel;
|
||||
|
||||
#if defined(NS_BLOCKS_AVAILABLE)
|
||||
- (NSMutableString*)replaceByRegexp:(id)pattern withBlock:(NSString* (^)(OnigResult*))block;
|
||||
- (NSMutableString*)replaceAllByRegexp:(id)pattern withBlock:(NSString* (^)(OnigResult*))block;
|
||||
#endif
|
||||
@end
|
||||
@@ -1,770 +0,0 @@
|
||||
#ifndef ONIGURUMA_H
|
||||
#define ONIGURUMA_H
|
||||
/**********************************************************************
|
||||
oniguruma.h - Oniguruma (regular expression library)
|
||||
**********************************************************************/
|
||||
/*-
|
||||
* Copyright (c) 2002-2009 K.Kosako <sndgk393 AT ybb DOT ne DOT jp>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define ONIGURUMA
|
||||
#define ONIGURUMA_VERSION_MAJOR 5
|
||||
#define ONIGURUMA_VERSION_MINOR 9
|
||||
#define ONIGURUMA_VERSION_TEENY 2
|
||||
|
||||
#ifdef __cplusplus
|
||||
# ifndef HAVE_PROTOTYPES
|
||||
# define HAVE_PROTOTYPES 1
|
||||
# endif
|
||||
# ifndef HAVE_STDARG_PROTOTYPES
|
||||
# define HAVE_STDARG_PROTOTYPES 1
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* escape Mac OS X/Xcode 2.4/gcc 4.0.1 problem */
|
||||
#if defined(__APPLE__) && defined(__GNUC__) && __GNUC__ >= 4
|
||||
# ifndef HAVE_STDARG_PROTOTYPES
|
||||
# define HAVE_STDARG_PROTOTYPES 1
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_STDARG_H
|
||||
# ifndef HAVE_STDARG_PROTOTYPES
|
||||
# define HAVE_STDARG_PROTOTYPES 1
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef P_
|
||||
#if defined(__STDC__) || defined(_WIN32)
|
||||
# define P_(args) args
|
||||
#else
|
||||
# define P_(args) ()
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef PV_
|
||||
#ifdef HAVE_STDARG_PROTOTYPES
|
||||
# define PV_(args) args
|
||||
#else
|
||||
# define PV_(args) ()
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef ONIG_EXTERN
|
||||
#if defined(_WIN32) && !defined(__GNUC__)
|
||||
#if defined(EXPORT) || defined(RUBY_EXPORT)
|
||||
#define ONIG_EXTERN extern __declspec(dllexport)
|
||||
#else
|
||||
#define ONIG_EXTERN extern __declspec(dllimport)
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef ONIG_EXTERN
|
||||
#define ONIG_EXTERN extern
|
||||
#endif
|
||||
|
||||
/* PART: character encoding */
|
||||
|
||||
#ifndef ONIG_ESCAPE_UCHAR_COLLISION
|
||||
#define UChar OnigUChar
|
||||
#endif
|
||||
|
||||
typedef unsigned char OnigUChar;
|
||||
typedef unsigned long OnigCodePoint;
|
||||
typedef unsigned int OnigCtype;
|
||||
typedef unsigned int OnigDistance;
|
||||
|
||||
#define ONIG_INFINITE_DISTANCE ~((OnigDistance )0)
|
||||
|
||||
typedef unsigned int OnigCaseFoldType; /* case fold flag */
|
||||
|
||||
ONIG_EXTERN OnigCaseFoldType OnigDefaultCaseFoldFlag;
|
||||
|
||||
/* #define ONIGENC_CASE_FOLD_HIRAGANA_KATAKANA (1<<1) */
|
||||
/* #define ONIGENC_CASE_FOLD_KATAKANA_WIDTH (1<<2) */
|
||||
#define ONIGENC_CASE_FOLD_TURKISH_AZERI (1<<20)
|
||||
#define INTERNAL_ONIGENC_CASE_FOLD_MULTI_CHAR (1<<30)
|
||||
|
||||
#define ONIGENC_CASE_FOLD_MIN INTERNAL_ONIGENC_CASE_FOLD_MULTI_CHAR
|
||||
#define ONIGENC_CASE_FOLD_DEFAULT OnigDefaultCaseFoldFlag
|
||||
|
||||
|
||||
#define ONIGENC_MAX_COMP_CASE_FOLD_CODE_LEN 3
|
||||
#define ONIGENC_GET_CASE_FOLD_CODES_MAX_NUM 13
|
||||
/* 13 => Unicode:0x1ffc */
|
||||
|
||||
/* code range */
|
||||
#define ONIGENC_CODE_RANGE_NUM(range) ((int )range[0])
|
||||
#define ONIGENC_CODE_RANGE_FROM(range,i) range[((i)*2) + 1]
|
||||
#define ONIGENC_CODE_RANGE_TO(range,i) range[((i)*2) + 2]
|
||||
|
||||
typedef struct {
|
||||
int byte_len; /* argument(original) character(s) byte length */
|
||||
int code_len; /* number of code */
|
||||
OnigCodePoint code[ONIGENC_MAX_COMP_CASE_FOLD_CODE_LEN];
|
||||
} OnigCaseFoldCodeItem;
|
||||
|
||||
typedef struct {
|
||||
OnigCodePoint esc;
|
||||
OnigCodePoint anychar;
|
||||
OnigCodePoint anytime;
|
||||
OnigCodePoint zero_or_one_time;
|
||||
OnigCodePoint one_or_more_time;
|
||||
OnigCodePoint anychar_anytime;
|
||||
} OnigMetaCharTableType;
|
||||
|
||||
typedef int (*OnigApplyAllCaseFoldFunc)(OnigCodePoint from, OnigCodePoint* to, int to_len, void* arg);
|
||||
|
||||
typedef struct OnigEncodingTypeST {
|
||||
int (*mbc_enc_len)(const OnigUChar* p);
|
||||
const char* name;
|
||||
int max_enc_len;
|
||||
int min_enc_len;
|
||||
int (*is_mbc_newline)(const OnigUChar* p, const OnigUChar* end);
|
||||
OnigCodePoint (*mbc_to_code)(const OnigUChar* p, const OnigUChar* end);
|
||||
int (*code_to_mbclen)(OnigCodePoint code);
|
||||
int (*code_to_mbc)(OnigCodePoint code, OnigUChar *buf);
|
||||
int (*mbc_case_fold)(OnigCaseFoldType flag, const OnigUChar** pp, const OnigUChar* end, OnigUChar* to);
|
||||
int (*apply_all_case_fold)(OnigCaseFoldType flag, OnigApplyAllCaseFoldFunc f, void* arg);
|
||||
int (*get_case_fold_codes_by_str)(OnigCaseFoldType flag, const OnigUChar* p, const OnigUChar* end, OnigCaseFoldCodeItem acs[]);
|
||||
int (*property_name_to_ctype)(struct OnigEncodingTypeST* enc, OnigUChar* p, OnigUChar* end);
|
||||
int (*is_code_ctype)(OnigCodePoint code, OnigCtype ctype);
|
||||
int (*get_ctype_code_range)(OnigCtype ctype, OnigCodePoint* sb_out, const OnigCodePoint* ranges[]);
|
||||
OnigUChar* (*left_adjust_char_head)(const OnigUChar* start, const OnigUChar* p);
|
||||
int (*is_allowed_reverse_match)(const OnigUChar* p, const OnigUChar* end);
|
||||
} OnigEncodingType;
|
||||
|
||||
typedef OnigEncodingType* OnigEncoding;
|
||||
|
||||
ONIG_EXTERN OnigEncodingType OnigEncodingASCII;
|
||||
ONIG_EXTERN OnigEncodingType OnigEncodingUTF16_BE;
|
||||
ONIG_EXTERN OnigEncodingType OnigEncodingUTF16_LE;
|
||||
ONIG_EXTERN OnigEncodingType OnigEncodingUTF32_BE;
|
||||
ONIG_EXTERN OnigEncodingType OnigEncodingUTF32_LE;
|
||||
|
||||
#define ONIG_ENCODING_ASCII (&OnigEncodingASCII)
|
||||
#define ONIG_ENCODING_UTF16_BE (&OnigEncodingUTF16_BE)
|
||||
#define ONIG_ENCODING_UTF16_LE (&OnigEncodingUTF16_LE)
|
||||
#define ONIG_ENCODING_UTF32_BE (&OnigEncodingUTF32_BE)
|
||||
#define ONIG_ENCODING_UTF32_LE (&OnigEncodingUTF32_LE)
|
||||
|
||||
#define ONIG_ENCODING_UNDEF ((OnigEncoding )0)
|
||||
|
||||
|
||||
/* work size */
|
||||
#define ONIGENC_CODE_TO_MBC_MAXLEN 7
|
||||
#define ONIGENC_MBC_CASE_FOLD_MAXLEN 18
|
||||
/* 18: 6(max-byte) * 3(case-fold chars) */
|
||||
|
||||
/* character types */
|
||||
#define ONIGENC_CTYPE_NEWLINE 0
|
||||
#define ONIGENC_CTYPE_ALPHA 1
|
||||
#define ONIGENC_CTYPE_BLANK 2
|
||||
#define ONIGENC_CTYPE_CNTRL 3
|
||||
#define ONIGENC_CTYPE_DIGIT 4
|
||||
#define ONIGENC_CTYPE_GRAPH 5
|
||||
#define ONIGENC_CTYPE_LOWER 6
|
||||
#define ONIGENC_CTYPE_PRINT 7
|
||||
#define ONIGENC_CTYPE_PUNCT 8
|
||||
#define ONIGENC_CTYPE_SPACE 9
|
||||
#define ONIGENC_CTYPE_UPPER 10
|
||||
#define ONIGENC_CTYPE_XDIGIT 11
|
||||
#define ONIGENC_CTYPE_WORD 12
|
||||
#define ONIGENC_CTYPE_ALNUM 13 /* alpha || digit */
|
||||
#define ONIGENC_CTYPE_ASCII 14
|
||||
#define ONIGENC_MAX_STD_CTYPE ONIGENC_CTYPE_ASCII
|
||||
|
||||
|
||||
#define onig_enc_len(enc,p,end) ONIGENC_MBC_ENC_LEN(enc,p)
|
||||
|
||||
#define ONIGENC_IS_UNDEF(enc) ((enc) == ONIG_ENCODING_UNDEF)
|
||||
#define ONIGENC_IS_SINGLEBYTE(enc) (ONIGENC_MBC_MAXLEN(enc) == 1)
|
||||
#define ONIGENC_IS_MBC_HEAD(enc,p) (ONIGENC_MBC_ENC_LEN(enc,p) != 1)
|
||||
#define ONIGENC_IS_MBC_ASCII(p) (*(p) < 128)
|
||||
#define ONIGENC_IS_CODE_ASCII(code) ((code) < 128)
|
||||
#define ONIGENC_IS_MBC_WORD(enc,s,end) \
|
||||
ONIGENC_IS_CODE_WORD(enc,ONIGENC_MBC_TO_CODE(enc,s,end))
|
||||
|
||||
|
||||
#define ONIGENC_NAME(enc) ((enc)->name)
|
||||
|
||||
#define ONIGENC_MBC_CASE_FOLD(enc,flag,pp,end,buf) \
|
||||
(enc)->mbc_case_fold(flag,(const OnigUChar** )pp,end,buf)
|
||||
#define ONIGENC_IS_ALLOWED_REVERSE_MATCH(enc,s,end) \
|
||||
(enc)->is_allowed_reverse_match(s,end)
|
||||
#define ONIGENC_LEFT_ADJUST_CHAR_HEAD(enc,start,s) \
|
||||
(enc)->left_adjust_char_head(start, s)
|
||||
#define ONIGENC_APPLY_ALL_CASE_FOLD(enc,case_fold_flag,f,arg) \
|
||||
(enc)->apply_all_case_fold(case_fold_flag,f,arg)
|
||||
#define ONIGENC_GET_CASE_FOLD_CODES_BY_STR(enc,case_fold_flag,p,end,acs) \
|
||||
(enc)->get_case_fold_codes_by_str(case_fold_flag,p,end,acs)
|
||||
#define ONIGENC_STEP_BACK(enc,start,s,n) \
|
||||
onigenc_step_back((enc),(start),(s),(n))
|
||||
|
||||
#define ONIGENC_MBC_ENC_LEN(enc,p) (enc)->mbc_enc_len(p)
|
||||
#define ONIGENC_MBC_MAXLEN(enc) ((enc)->max_enc_len)
|
||||
#define ONIGENC_MBC_MAXLEN_DIST(enc) ONIGENC_MBC_MAXLEN(enc)
|
||||
#define ONIGENC_MBC_MINLEN(enc) ((enc)->min_enc_len)
|
||||
#define ONIGENC_IS_MBC_NEWLINE(enc,p,end) (enc)->is_mbc_newline((p),(end))
|
||||
#define ONIGENC_MBC_TO_CODE(enc,p,end) (enc)->mbc_to_code((p),(end))
|
||||
#define ONIGENC_CODE_TO_MBCLEN(enc,code) (enc)->code_to_mbclen(code)
|
||||
#define ONIGENC_CODE_TO_MBC(enc,code,buf) (enc)->code_to_mbc(code,buf)
|
||||
#define ONIGENC_PROPERTY_NAME_TO_CTYPE(enc,p,end) \
|
||||
(enc)->property_name_to_ctype(enc,p,end)
|
||||
|
||||
#define ONIGENC_IS_CODE_CTYPE(enc,code,ctype) (enc)->is_code_ctype(code,ctype)
|
||||
|
||||
#define ONIGENC_IS_CODE_NEWLINE(enc,code) \
|
||||
ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_NEWLINE)
|
||||
#define ONIGENC_IS_CODE_GRAPH(enc,code) \
|
||||
ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_GRAPH)
|
||||
#define ONIGENC_IS_CODE_PRINT(enc,code) \
|
||||
ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_PRINT)
|
||||
#define ONIGENC_IS_CODE_ALNUM(enc,code) \
|
||||
ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_ALNUM)
|
||||
#define ONIGENC_IS_CODE_ALPHA(enc,code) \
|
||||
ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_ALPHA)
|
||||
#define ONIGENC_IS_CODE_LOWER(enc,code) \
|
||||
ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_LOWER)
|
||||
#define ONIGENC_IS_CODE_UPPER(enc,code) \
|
||||
ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_UPPER)
|
||||
#define ONIGENC_IS_CODE_CNTRL(enc,code) \
|
||||
ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_CNTRL)
|
||||
#define ONIGENC_IS_CODE_PUNCT(enc,code) \
|
||||
ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_PUNCT)
|
||||
#define ONIGENC_IS_CODE_SPACE(enc,code) \
|
||||
ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_SPACE)
|
||||
#define ONIGENC_IS_CODE_BLANK(enc,code) \
|
||||
ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_BLANK)
|
||||
#define ONIGENC_IS_CODE_DIGIT(enc,code) \
|
||||
ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_DIGIT)
|
||||
#define ONIGENC_IS_CODE_XDIGIT(enc,code) \
|
||||
ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_XDIGIT)
|
||||
#define ONIGENC_IS_CODE_WORD(enc,code) \
|
||||
ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_WORD)
|
||||
|
||||
#define ONIGENC_GET_CTYPE_CODE_RANGE(enc,ctype,sbout,ranges) \
|
||||
(enc)->get_ctype_code_range(ctype,sbout,ranges)
|
||||
|
||||
ONIG_EXTERN
|
||||
OnigUChar* onigenc_step_back P_((OnigEncoding enc, const OnigUChar* start, const OnigUChar* s, int n));
|
||||
|
||||
|
||||
/* encoding API */
|
||||
ONIG_EXTERN
|
||||
int onigenc_init P_((void));
|
||||
ONIG_EXTERN
|
||||
int onigenc_set_default_encoding P_((OnigEncoding enc));
|
||||
ONIG_EXTERN
|
||||
OnigEncoding onigenc_get_default_encoding P_((void));
|
||||
ONIG_EXTERN
|
||||
void onigenc_set_default_caseconv_table P_((const OnigUChar* table));
|
||||
ONIG_EXTERN
|
||||
OnigUChar* onigenc_get_right_adjust_char_head_with_prev P_((OnigEncoding enc, const OnigUChar* start, const OnigUChar* s, const OnigUChar** prev));
|
||||
ONIG_EXTERN
|
||||
OnigUChar* onigenc_get_prev_char_head P_((OnigEncoding enc, const OnigUChar* start, const OnigUChar* s));
|
||||
ONIG_EXTERN
|
||||
OnigUChar* onigenc_get_left_adjust_char_head P_((OnigEncoding enc, const OnigUChar* start, const OnigUChar* s));
|
||||
ONIG_EXTERN
|
||||
OnigUChar* onigenc_get_right_adjust_char_head P_((OnigEncoding enc, const OnigUChar* start, const OnigUChar* s));
|
||||
ONIG_EXTERN
|
||||
int onigenc_strlen P_((OnigEncoding enc, const OnigUChar* p, const OnigUChar* end));
|
||||
ONIG_EXTERN
|
||||
int onigenc_strlen_null P_((OnigEncoding enc, const OnigUChar* p));
|
||||
ONIG_EXTERN
|
||||
int onigenc_str_bytelen_null P_((OnigEncoding enc, const OnigUChar* p));
|
||||
|
||||
|
||||
|
||||
/* PART: regular expression */
|
||||
|
||||
/* config parameters */
|
||||
#define ONIG_NREGION 10
|
||||
#define ONIG_MAX_BACKREF_NUM 1000
|
||||
#define ONIG_MAX_REPEAT_NUM 100000
|
||||
#define ONIG_MAX_MULTI_BYTE_RANGES_NUM 10000
|
||||
/* constants */
|
||||
#define ONIG_MAX_ERROR_MESSAGE_LEN 90
|
||||
|
||||
typedef unsigned int OnigOptionType;
|
||||
|
||||
#define ONIG_OPTION_DEFAULT ONIG_OPTION_NONE
|
||||
|
||||
/* options */
|
||||
#define ONIG_OPTION_NONE 0U
|
||||
#define ONIG_OPTION_IGNORECASE 1U
|
||||
#define ONIG_OPTION_EXTEND (ONIG_OPTION_IGNORECASE << 1)
|
||||
#define ONIG_OPTION_MULTILINE (ONIG_OPTION_EXTEND << 1)
|
||||
#define ONIG_OPTION_SINGLELINE (ONIG_OPTION_MULTILINE << 1)
|
||||
#define ONIG_OPTION_FIND_LONGEST (ONIG_OPTION_SINGLELINE << 1)
|
||||
#define ONIG_OPTION_FIND_NOT_EMPTY (ONIG_OPTION_FIND_LONGEST << 1)
|
||||
#define ONIG_OPTION_NEGATE_SINGLELINE (ONIG_OPTION_FIND_NOT_EMPTY << 1)
|
||||
#define ONIG_OPTION_DONT_CAPTURE_GROUP (ONIG_OPTION_NEGATE_SINGLELINE << 1)
|
||||
#define ONIG_OPTION_CAPTURE_GROUP (ONIG_OPTION_DONT_CAPTURE_GROUP << 1)
|
||||
/* options (search time) */
|
||||
#define ONIG_OPTION_NOTBOL (ONIG_OPTION_CAPTURE_GROUP << 1)
|
||||
#define ONIG_OPTION_NOTEOL (ONIG_OPTION_NOTBOL << 1)
|
||||
#define ONIG_OPTION_POSIX_REGION (ONIG_OPTION_NOTEOL << 1)
|
||||
#define ONIG_OPTION_MAXBIT ONIG_OPTION_POSIX_REGION /* limit */
|
||||
|
||||
#define ONIG_OPTION_ON(options,regopt) ((options) |= (regopt))
|
||||
#define ONIG_OPTION_OFF(options,regopt) ((options) &= ~(regopt))
|
||||
#define ONIG_IS_OPTION_ON(options,option) ((options) & (option))
|
||||
|
||||
/* syntax */
|
||||
typedef struct {
|
||||
unsigned int op;
|
||||
unsigned int op2;
|
||||
unsigned int behavior;
|
||||
OnigOptionType options; /* default option */
|
||||
OnigMetaCharTableType meta_char_table;
|
||||
} OnigSyntaxType;
|
||||
|
||||
ONIG_EXTERN OnigSyntaxType OnigSyntaxASIS;
|
||||
ONIG_EXTERN OnigSyntaxType OnigSyntaxPosixBasic;
|
||||
ONIG_EXTERN OnigSyntaxType OnigSyntaxPosixExtended;
|
||||
ONIG_EXTERN OnigSyntaxType OnigSyntaxEmacs;
|
||||
ONIG_EXTERN OnigSyntaxType OnigSyntaxGrep;
|
||||
ONIG_EXTERN OnigSyntaxType OnigSyntaxGnuRegex;
|
||||
ONIG_EXTERN OnigSyntaxType OnigSyntaxJava;
|
||||
ONIG_EXTERN OnigSyntaxType OnigSyntaxPerl;
|
||||
ONIG_EXTERN OnigSyntaxType OnigSyntaxPerl_NG;
|
||||
ONIG_EXTERN OnigSyntaxType OnigSyntaxRuby;
|
||||
|
||||
/* predefined syntaxes (see regsyntax.c) */
|
||||
#define ONIG_SYNTAX_ASIS (&OnigSyntaxASIS)
|
||||
#define ONIG_SYNTAX_POSIX_BASIC (&OnigSyntaxPosixBasic)
|
||||
#define ONIG_SYNTAX_POSIX_EXTENDED (&OnigSyntaxPosixExtended)
|
||||
#define ONIG_SYNTAX_EMACS (&OnigSyntaxEmacs)
|
||||
#define ONIG_SYNTAX_GREP (&OnigSyntaxGrep)
|
||||
#define ONIG_SYNTAX_GNU_REGEX (&OnigSyntaxGnuRegex)
|
||||
#define ONIG_SYNTAX_JAVA (&OnigSyntaxJava)
|
||||
#define ONIG_SYNTAX_PERL (&OnigSyntaxPerl)
|
||||
#define ONIG_SYNTAX_PERL_NG (&OnigSyntaxPerl_NG)
|
||||
#define ONIG_SYNTAX_RUBY (&OnigSyntaxRuby)
|
||||
|
||||
/* default syntax */
|
||||
ONIG_EXTERN OnigSyntaxType* OnigDefaultSyntax;
|
||||
#define ONIG_SYNTAX_DEFAULT OnigDefaultSyntax
|
||||
|
||||
/* syntax (operators) */
|
||||
#define ONIG_SYN_OP_VARIABLE_META_CHARACTERS (1U<<0)
|
||||
#define ONIG_SYN_OP_DOT_ANYCHAR (1U<<1) /* . */
|
||||
#define ONIG_SYN_OP_ASTERISK_ZERO_INF (1U<<2) /* * */
|
||||
#define ONIG_SYN_OP_ESC_ASTERISK_ZERO_INF (1U<<3)
|
||||
#define ONIG_SYN_OP_PLUS_ONE_INF (1U<<4) /* + */
|
||||
#define ONIG_SYN_OP_ESC_PLUS_ONE_INF (1U<<5)
|
||||
#define ONIG_SYN_OP_QMARK_ZERO_ONE (1U<<6) /* ? */
|
||||
#define ONIG_SYN_OP_ESC_QMARK_ZERO_ONE (1U<<7)
|
||||
#define ONIG_SYN_OP_BRACE_INTERVAL (1U<<8) /* {lower,upper} */
|
||||
#define ONIG_SYN_OP_ESC_BRACE_INTERVAL (1U<<9) /* \{lower,upper\} */
|
||||
#define ONIG_SYN_OP_VBAR_ALT (1U<<10) /* | */
|
||||
#define ONIG_SYN_OP_ESC_VBAR_ALT (1U<<11) /* \| */
|
||||
#define ONIG_SYN_OP_LPAREN_SUBEXP (1U<<12) /* (...) */
|
||||
#define ONIG_SYN_OP_ESC_LPAREN_SUBEXP (1U<<13) /* \(...\) */
|
||||
#define ONIG_SYN_OP_ESC_AZ_BUF_ANCHOR (1U<<14) /* \A, \Z, \z */
|
||||
#define ONIG_SYN_OP_ESC_CAPITAL_G_BEGIN_ANCHOR (1U<<15) /* \G */
|
||||
#define ONIG_SYN_OP_DECIMAL_BACKREF (1U<<16) /* \num */
|
||||
#define ONIG_SYN_OP_BRACKET_CC (1U<<17) /* [...] */
|
||||
#define ONIG_SYN_OP_ESC_W_WORD (1U<<18) /* \w, \W */
|
||||
#define ONIG_SYN_OP_ESC_LTGT_WORD_BEGIN_END (1U<<19) /* \<. \> */
|
||||
#define ONIG_SYN_OP_ESC_B_WORD_BOUND (1U<<20) /* \b, \B */
|
||||
#define ONIG_SYN_OP_ESC_S_WHITE_SPACE (1U<<21) /* \s, \S */
|
||||
#define ONIG_SYN_OP_ESC_D_DIGIT (1U<<22) /* \d, \D */
|
||||
#define ONIG_SYN_OP_LINE_ANCHOR (1U<<23) /* ^, $ */
|
||||
#define ONIG_SYN_OP_POSIX_BRACKET (1U<<24) /* [:xxxx:] */
|
||||
#define ONIG_SYN_OP_QMARK_NON_GREEDY (1U<<25) /* ??,*?,+?,{n,m}? */
|
||||
#define ONIG_SYN_OP_ESC_CONTROL_CHARS (1U<<26) /* \n,\r,\t,\a ... */
|
||||
#define ONIG_SYN_OP_ESC_C_CONTROL (1U<<27) /* \cx */
|
||||
#define ONIG_SYN_OP_ESC_OCTAL3 (1U<<28) /* \OOO */
|
||||
#define ONIG_SYN_OP_ESC_X_HEX2 (1U<<29) /* \xHH */
|
||||
#define ONIG_SYN_OP_ESC_X_BRACE_HEX8 (1U<<30) /* \x{7HHHHHHH} */
|
||||
|
||||
#define ONIG_SYN_OP2_ESC_CAPITAL_Q_QUOTE (1U<<0) /* \Q...\E */
|
||||
#define ONIG_SYN_OP2_QMARK_GROUP_EFFECT (1U<<1) /* (?...) */
|
||||
#define ONIG_SYN_OP2_OPTION_PERL (1U<<2) /* (?imsx),(?-imsx) */
|
||||
#define ONIG_SYN_OP2_OPTION_RUBY (1U<<3) /* (?imx), (?-imx) */
|
||||
#define ONIG_SYN_OP2_PLUS_POSSESSIVE_REPEAT (1U<<4) /* ?+,*+,++ */
|
||||
#define ONIG_SYN_OP2_PLUS_POSSESSIVE_INTERVAL (1U<<5) /* {n,m}+ */
|
||||
#define ONIG_SYN_OP2_CCLASS_SET_OP (1U<<6) /* [...&&..[..]..] */
|
||||
#define ONIG_SYN_OP2_QMARK_LT_NAMED_GROUP (1U<<7) /* (?<name>...) */
|
||||
#define ONIG_SYN_OP2_ESC_K_NAMED_BACKREF (1U<<8) /* \k<name> */
|
||||
#define ONIG_SYN_OP2_ESC_G_SUBEXP_CALL (1U<<9) /* \g<name>, \g<n> */
|
||||
#define ONIG_SYN_OP2_ATMARK_CAPTURE_HISTORY (1U<<10) /* (?@..),(?@<x>..) */
|
||||
#define ONIG_SYN_OP2_ESC_CAPITAL_C_BAR_CONTROL (1U<<11) /* \C-x */
|
||||
#define ONIG_SYN_OP2_ESC_CAPITAL_M_BAR_META (1U<<12) /* \M-x */
|
||||
#define ONIG_SYN_OP2_ESC_V_VTAB (1U<<13) /* \v as VTAB */
|
||||
#define ONIG_SYN_OP2_ESC_U_HEX4 (1U<<14) /* \uHHHH */
|
||||
#define ONIG_SYN_OP2_ESC_GNU_BUF_ANCHOR (1U<<15) /* \`, \' */
|
||||
#define ONIG_SYN_OP2_ESC_P_BRACE_CHAR_PROPERTY (1U<<16) /* \p{...}, \P{...} */
|
||||
#define ONIG_SYN_OP2_ESC_P_BRACE_CIRCUMFLEX_NOT (1U<<17) /* \p{^..}, \P{^..} */
|
||||
/* #define ONIG_SYN_OP2_CHAR_PROPERTY_PREFIX_IS (1U<<18) */
|
||||
#define ONIG_SYN_OP2_ESC_H_XDIGIT (1U<<19) /* \h, \H */
|
||||
#define ONIG_SYN_OP2_INEFFECTIVE_ESCAPE (1U<<20) /* \ */
|
||||
|
||||
/* syntax (behavior) */
|
||||
#define ONIG_SYN_CONTEXT_INDEP_ANCHORS (1U<<31) /* not implemented */
|
||||
#define ONIG_SYN_CONTEXT_INDEP_REPEAT_OPS (1U<<0) /* ?, *, +, {n,m} */
|
||||
#define ONIG_SYN_CONTEXT_INVALID_REPEAT_OPS (1U<<1) /* error or ignore */
|
||||
#define ONIG_SYN_ALLOW_UNMATCHED_CLOSE_SUBEXP (1U<<2) /* ...)... */
|
||||
#define ONIG_SYN_ALLOW_INVALID_INTERVAL (1U<<3) /* {??? */
|
||||
#define ONIG_SYN_ALLOW_INTERVAL_LOW_ABBREV (1U<<4) /* {,n} => {0,n} */
|
||||
#define ONIG_SYN_STRICT_CHECK_BACKREF (1U<<5) /* /(\1)/,/\1()/ ..*/
|
||||
#define ONIG_SYN_DIFFERENT_LEN_ALT_LOOK_BEHIND (1U<<6) /* (?<=a|bc) */
|
||||
#define ONIG_SYN_CAPTURE_ONLY_NAMED_GROUP (1U<<7) /* see doc/RE */
|
||||
#define ONIG_SYN_ALLOW_MULTIPLEX_DEFINITION_NAME (1U<<8) /* (?<x>)(?<x>) */
|
||||
#define ONIG_SYN_FIXED_INTERVAL_IS_GREEDY_ONLY (1U<<9) /* a{n}?=(?:a{n})? */
|
||||
|
||||
/* syntax (behavior) in char class [...] */
|
||||
#define ONIG_SYN_NOT_NEWLINE_IN_NEGATIVE_CC (1U<<20) /* [^...] */
|
||||
#define ONIG_SYN_BACKSLASH_ESCAPE_IN_CC (1U<<21) /* [..\w..] etc.. */
|
||||
#define ONIG_SYN_ALLOW_EMPTY_RANGE_IN_CC (1U<<22)
|
||||
#define ONIG_SYN_ALLOW_DOUBLE_RANGE_OP_IN_CC (1U<<23) /* [0-9-a]=[0-9\-a] */
|
||||
/* syntax (behavior) warning */
|
||||
#define ONIG_SYN_WARN_CC_OP_NOT_ESCAPED (1U<<24) /* [,-,] */
|
||||
#define ONIG_SYN_WARN_REDUNDANT_NESTED_REPEAT (1U<<25) /* (?:a*)+ */
|
||||
|
||||
/* meta character specifiers (onig_set_meta_char()) */
|
||||
#define ONIG_META_CHAR_ESCAPE 0
|
||||
#define ONIG_META_CHAR_ANYCHAR 1
|
||||
#define ONIG_META_CHAR_ANYTIME 2
|
||||
#define ONIG_META_CHAR_ZERO_OR_ONE_TIME 3
|
||||
#define ONIG_META_CHAR_ONE_OR_MORE_TIME 4
|
||||
#define ONIG_META_CHAR_ANYCHAR_ANYTIME 5
|
||||
|
||||
#define ONIG_INEFFECTIVE_META_CHAR 0
|
||||
|
||||
/* error codes */
|
||||
#define ONIG_IS_PATTERN_ERROR(ecode) ((ecode) <= -100 && (ecode) > -1000)
|
||||
/* normal return */
|
||||
#define ONIG_NORMAL 0
|
||||
#define ONIG_MISMATCH -1
|
||||
#define ONIG_NO_SUPPORT_CONFIG -2
|
||||
|
||||
/* internal error */
|
||||
#define ONIGERR_MEMORY -5
|
||||
#define ONIGERR_TYPE_BUG -6
|
||||
#define ONIGERR_PARSER_BUG -11
|
||||
#define ONIGERR_STACK_BUG -12
|
||||
#define ONIGERR_UNDEFINED_BYTECODE -13
|
||||
#define ONIGERR_UNEXPECTED_BYTECODE -14
|
||||
#define ONIGERR_MATCH_STACK_LIMIT_OVER -15
|
||||
#define ONIGERR_DEFAULT_ENCODING_IS_NOT_SETTED -21
|
||||
#define ONIGERR_SPECIFIED_ENCODING_CANT_CONVERT_TO_WIDE_CHAR -22
|
||||
/* general error */
|
||||
#define ONIGERR_INVALID_ARGUMENT -30
|
||||
/* syntax error */
|
||||
#define ONIGERR_END_PATTERN_AT_LEFT_BRACE -100
|
||||
#define ONIGERR_END_PATTERN_AT_LEFT_BRACKET -101
|
||||
#define ONIGERR_EMPTY_CHAR_CLASS -102
|
||||
#define ONIGERR_PREMATURE_END_OF_CHAR_CLASS -103
|
||||
#define ONIGERR_END_PATTERN_AT_ESCAPE -104
|
||||
#define ONIGERR_END_PATTERN_AT_META -105
|
||||
#define ONIGERR_END_PATTERN_AT_CONTROL -106
|
||||
#define ONIGERR_META_CODE_SYNTAX -108
|
||||
#define ONIGERR_CONTROL_CODE_SYNTAX -109
|
||||
#define ONIGERR_CHAR_CLASS_VALUE_AT_END_OF_RANGE -110
|
||||
#define ONIGERR_CHAR_CLASS_VALUE_AT_START_OF_RANGE -111
|
||||
#define ONIGERR_UNMATCHED_RANGE_SPECIFIER_IN_CHAR_CLASS -112
|
||||
#define ONIGERR_TARGET_OF_REPEAT_OPERATOR_NOT_SPECIFIED -113
|
||||
#define ONIGERR_TARGET_OF_REPEAT_OPERATOR_INVALID -114
|
||||
#define ONIGERR_NESTED_REPEAT_OPERATOR -115
|
||||
#define ONIGERR_UNMATCHED_CLOSE_PARENTHESIS -116
|
||||
#define ONIGERR_END_PATTERN_WITH_UNMATCHED_PARENTHESIS -117
|
||||
#define ONIGERR_END_PATTERN_IN_GROUP -118
|
||||
#define ONIGERR_UNDEFINED_GROUP_OPTION -119
|
||||
#define ONIGERR_INVALID_POSIX_BRACKET_TYPE -121
|
||||
#define ONIGERR_INVALID_LOOK_BEHIND_PATTERN -122
|
||||
#define ONIGERR_INVALID_REPEAT_RANGE_PATTERN -123
|
||||
/* values error (syntax error) */
|
||||
#define ONIGERR_TOO_BIG_NUMBER -200
|
||||
#define ONIGERR_TOO_BIG_NUMBER_FOR_REPEAT_RANGE -201
|
||||
#define ONIGERR_UPPER_SMALLER_THAN_LOWER_IN_REPEAT_RANGE -202
|
||||
#define ONIGERR_EMPTY_RANGE_IN_CHAR_CLASS -203
|
||||
#define ONIGERR_MISMATCH_CODE_LENGTH_IN_CLASS_RANGE -204
|
||||
#define ONIGERR_TOO_MANY_MULTI_BYTE_RANGES -205
|
||||
#define ONIGERR_TOO_SHORT_MULTI_BYTE_STRING -206
|
||||
#define ONIGERR_TOO_BIG_BACKREF_NUMBER -207
|
||||
#define ONIGERR_INVALID_BACKREF -208
|
||||
#define ONIGERR_NUMBERED_BACKREF_OR_CALL_NOT_ALLOWED -209
|
||||
#define ONIGERR_TOO_LONG_WIDE_CHAR_VALUE -212
|
||||
#define ONIGERR_EMPTY_GROUP_NAME -214
|
||||
#define ONIGERR_INVALID_GROUP_NAME -215
|
||||
#define ONIGERR_INVALID_CHAR_IN_GROUP_NAME -216
|
||||
#define ONIGERR_UNDEFINED_NAME_REFERENCE -217
|
||||
#define ONIGERR_UNDEFINED_GROUP_REFERENCE -218
|
||||
#define ONIGERR_MULTIPLEX_DEFINED_NAME -219
|
||||
#define ONIGERR_MULTIPLEX_DEFINITION_NAME_CALL -220
|
||||
#define ONIGERR_NEVER_ENDING_RECURSION -221
|
||||
#define ONIGERR_GROUP_NUMBER_OVER_FOR_CAPTURE_HISTORY -222
|
||||
#define ONIGERR_INVALID_CHAR_PROPERTY_NAME -223
|
||||
#define ONIGERR_INVALID_CODE_POINT_VALUE -400
|
||||
#define ONIGERR_INVALID_WIDE_CHAR_VALUE -400
|
||||
#define ONIGERR_TOO_BIG_WIDE_CHAR_VALUE -401
|
||||
#define ONIGERR_NOT_SUPPORTED_ENCODING_COMBINATION -402
|
||||
#define ONIGERR_INVALID_COMBINATION_OF_OPTIONS -403
|
||||
|
||||
/* errors related to thread */
|
||||
#define ONIGERR_OVER_THREAD_PASS_LIMIT_COUNT -1001
|
||||
|
||||
|
||||
/* must be smaller than BIT_STATUS_BITS_NUM (unsigned int * 8) */
|
||||
#define ONIG_MAX_CAPTURE_HISTORY_GROUP 31
|
||||
#define ONIG_IS_CAPTURE_HISTORY_GROUP(r, i) \
|
||||
((i) <= ONIG_MAX_CAPTURE_HISTORY_GROUP && (r)->list && (r)->list[i])
|
||||
|
||||
typedef struct OnigCaptureTreeNodeStruct {
|
||||
int group; /* group number */
|
||||
int beg;
|
||||
int end;
|
||||
int allocated;
|
||||
int num_childs;
|
||||
struct OnigCaptureTreeNodeStruct** childs;
|
||||
} OnigCaptureTreeNode;
|
||||
|
||||
/* match result region type */
|
||||
struct re_registers {
|
||||
int allocated;
|
||||
int num_regs;
|
||||
int* beg;
|
||||
int* end;
|
||||
/* extended */
|
||||
OnigCaptureTreeNode* history_root; /* capture history tree root */
|
||||
};
|
||||
|
||||
/* capture tree traverse */
|
||||
#define ONIG_TRAVERSE_CALLBACK_AT_FIRST 1
|
||||
#define ONIG_TRAVERSE_CALLBACK_AT_LAST 2
|
||||
#define ONIG_TRAVERSE_CALLBACK_AT_BOTH \
|
||||
( ONIG_TRAVERSE_CALLBACK_AT_FIRST | ONIG_TRAVERSE_CALLBACK_AT_LAST )
|
||||
|
||||
|
||||
#define ONIG_REGION_NOTPOS -1
|
||||
|
||||
typedef struct re_registers OnigRegion;
|
||||
|
||||
typedef struct {
|
||||
OnigEncoding enc;
|
||||
OnigUChar* par;
|
||||
OnigUChar* par_end;
|
||||
} OnigErrorInfo;
|
||||
|
||||
typedef struct {
|
||||
int lower;
|
||||
int upper;
|
||||
} OnigRepeatRange;
|
||||
|
||||
typedef void (*OnigWarnFunc) P_((const char* s));
|
||||
extern void onig_null_warn P_((const char* s));
|
||||
#define ONIG_NULL_WARN onig_null_warn
|
||||
|
||||
#define ONIG_CHAR_TABLE_SIZE 256
|
||||
|
||||
/* regex_t state */
|
||||
#define ONIG_STATE_NORMAL 0
|
||||
#define ONIG_STATE_SEARCHING 1
|
||||
#define ONIG_STATE_COMPILING -1
|
||||
#define ONIG_STATE_MODIFY -2
|
||||
|
||||
#define ONIG_STATE(reg) \
|
||||
((reg)->state > 0 ? ONIG_STATE_SEARCHING : (reg)->state)
|
||||
|
||||
typedef struct re_pattern_buffer {
|
||||
/* common members of BBuf(bytes-buffer) */
|
||||
unsigned char* p; /* compiled pattern */
|
||||
unsigned int used; /* used space for p */
|
||||
unsigned int alloc; /* allocated space for p */
|
||||
|
||||
int state; /* normal, searching, compiling */
|
||||
int num_mem; /* used memory(...) num counted from 1 */
|
||||
int num_repeat; /* OP_REPEAT/OP_REPEAT_NG id-counter */
|
||||
int num_null_check; /* OP_NULL_CHECK_START/END id counter */
|
||||
int num_comb_exp_check; /* combination explosion check */
|
||||
int num_call; /* number of subexp call */
|
||||
unsigned int capture_history; /* (?@...) flag (1-31) */
|
||||
unsigned int bt_mem_start; /* need backtrack flag */
|
||||
unsigned int bt_mem_end; /* need backtrack flag */
|
||||
int stack_pop_level;
|
||||
int repeat_range_alloc;
|
||||
OnigRepeatRange* repeat_range;
|
||||
|
||||
OnigEncoding enc;
|
||||
OnigOptionType options;
|
||||
OnigSyntaxType* syntax;
|
||||
OnigCaseFoldType case_fold_flag;
|
||||
void* name_table;
|
||||
|
||||
/* optimization info (string search, char-map and anchors) */
|
||||
int optimize; /* optimize flag */
|
||||
int threshold_len; /* search str-length for apply optimize */
|
||||
int anchor; /* BEGIN_BUF, BEGIN_POS, (SEMI_)END_BUF */
|
||||
OnigDistance anchor_dmin; /* (SEMI_)END_BUF anchor distance */
|
||||
OnigDistance anchor_dmax; /* (SEMI_)END_BUF anchor distance */
|
||||
int sub_anchor; /* start-anchor for exact or map */
|
||||
unsigned char *exact;
|
||||
unsigned char *exact_end;
|
||||
unsigned char map[ONIG_CHAR_TABLE_SIZE]; /* used as BM skip or char-map */
|
||||
int *int_map; /* BM skip for exact_len > 255 */
|
||||
int *int_map_backward; /* BM skip for backward search */
|
||||
OnigDistance dmin; /* min-distance of exact or map */
|
||||
OnigDistance dmax; /* max-distance of exact or map */
|
||||
|
||||
/* regex_t link chain */
|
||||
struct re_pattern_buffer* chain; /* escape compile-conflict */
|
||||
} OnigRegexType;
|
||||
|
||||
typedef OnigRegexType* OnigRegex;
|
||||
|
||||
#ifndef ONIG_ESCAPE_REGEX_T_COLLISION
|
||||
typedef OnigRegexType regex_t;
|
||||
#endif
|
||||
|
||||
|
||||
typedef struct {
|
||||
int num_of_elements;
|
||||
OnigEncoding pattern_enc;
|
||||
OnigEncoding target_enc;
|
||||
OnigSyntaxType* syntax;
|
||||
OnigOptionType option;
|
||||
OnigCaseFoldType case_fold_flag;
|
||||
} OnigCompileInfo;
|
||||
|
||||
/* Oniguruma Native API */
|
||||
ONIG_EXTERN
|
||||
int onig_init P_((void));
|
||||
ONIG_EXTERN
|
||||
int onig_error_code_to_str PV_((OnigUChar* s, int err_code, ...));
|
||||
ONIG_EXTERN
|
||||
void onig_set_warn_func P_((OnigWarnFunc f));
|
||||
ONIG_EXTERN
|
||||
void onig_set_verb_warn_func P_((OnigWarnFunc f));
|
||||
ONIG_EXTERN
|
||||
int onig_new P_((OnigRegex*, const OnigUChar* pattern, const OnigUChar* pattern_end, OnigOptionType option, OnigEncoding enc, OnigSyntaxType* syntax, OnigErrorInfo* einfo));
|
||||
ONIG_EXTERN
|
||||
int onig_reg_init P_((regex_t* reg, OnigOptionType option, OnigCaseFoldType case_fold_flag, OnigEncoding enc, OnigSyntaxType* syntax));
|
||||
int onig_new_without_alloc P_((OnigRegex, const OnigUChar* pattern, const OnigUChar* pattern_end, OnigOptionType option, OnigEncoding enc, OnigSyntaxType* syntax, OnigErrorInfo* einfo));
|
||||
ONIG_EXTERN
|
||||
int onig_new_deluxe P_((OnigRegex* reg, const OnigUChar* pattern, const OnigUChar* pattern_end, OnigCompileInfo* ci, OnigErrorInfo* einfo));
|
||||
ONIG_EXTERN
|
||||
void onig_free P_((OnigRegex));
|
||||
ONIG_EXTERN
|
||||
void onig_free_body P_((OnigRegex));
|
||||
ONIG_EXTERN
|
||||
int onig_recompile P_((OnigRegex, const OnigUChar* pattern, const OnigUChar* pattern_end, OnigOptionType option, OnigEncoding enc, OnigSyntaxType* syntax, OnigErrorInfo* einfo));
|
||||
ONIG_EXTERN
|
||||
int onig_recompile_deluxe P_((OnigRegex reg, const OnigUChar* pattern, const OnigUChar* pattern_end, OnigCompileInfo* ci, OnigErrorInfo* einfo));
|
||||
ONIG_EXTERN
|
||||
int onig_search P_((OnigRegex, const OnigUChar* str, const OnigUChar* end, const OnigUChar* start, const OnigUChar* range, OnigRegion* region, OnigOptionType option));
|
||||
ONIG_EXTERN
|
||||
int onig_match P_((OnigRegex, const OnigUChar* str, const OnigUChar* end, const OnigUChar* at, OnigRegion* region, OnigOptionType option));
|
||||
ONIG_EXTERN
|
||||
OnigRegion* onig_region_new P_((void));
|
||||
ONIG_EXTERN
|
||||
void onig_region_init P_((OnigRegion* region));
|
||||
ONIG_EXTERN
|
||||
void onig_region_free P_((OnigRegion* region, int free_self));
|
||||
ONIG_EXTERN
|
||||
void onig_region_copy P_((OnigRegion* to, OnigRegion* from));
|
||||
ONIG_EXTERN
|
||||
void onig_region_clear P_((OnigRegion* region));
|
||||
ONIG_EXTERN
|
||||
int onig_region_resize P_((OnigRegion* region, int n));
|
||||
ONIG_EXTERN
|
||||
int onig_region_set P_((OnigRegion* region, int at, int beg, int end));
|
||||
ONIG_EXTERN
|
||||
int onig_name_to_group_numbers P_((OnigRegex reg, const OnigUChar* name, const OnigUChar* name_end, int** nums));
|
||||
ONIG_EXTERN
|
||||
int onig_name_to_backref_number P_((OnigRegex reg, const OnigUChar* name, const OnigUChar* name_end, OnigRegion *region));
|
||||
ONIG_EXTERN
|
||||
int onig_foreach_name P_((OnigRegex reg, int (*func)(const OnigUChar*, const OnigUChar*,int,int*,OnigRegex,void*), void* arg));
|
||||
ONIG_EXTERN
|
||||
int onig_number_of_names P_((OnigRegex reg));
|
||||
ONIG_EXTERN
|
||||
int onig_number_of_captures P_((OnigRegex reg));
|
||||
ONIG_EXTERN
|
||||
int onig_number_of_capture_histories P_((OnigRegex reg));
|
||||
ONIG_EXTERN
|
||||
OnigCaptureTreeNode* onig_get_capture_tree P_((OnigRegion* region));
|
||||
ONIG_EXTERN
|
||||
int onig_capture_tree_traverse P_((OnigRegion* region, int at, int(*callback_func)(int,int,int,int,int,void*), void* arg));
|
||||
ONIG_EXTERN
|
||||
int onig_noname_group_capture_is_active P_((OnigRegex reg));
|
||||
ONIG_EXTERN
|
||||
OnigEncoding onig_get_encoding P_((OnigRegex reg));
|
||||
ONIG_EXTERN
|
||||
OnigOptionType onig_get_options P_((OnigRegex reg));
|
||||
ONIG_EXTERN
|
||||
OnigCaseFoldType onig_get_case_fold_flag P_((OnigRegex reg));
|
||||
ONIG_EXTERN
|
||||
OnigSyntaxType* onig_get_syntax P_((OnigRegex reg));
|
||||
ONIG_EXTERN
|
||||
int onig_set_default_syntax P_((OnigSyntaxType* syntax));
|
||||
ONIG_EXTERN
|
||||
void onig_copy_syntax P_((OnigSyntaxType* to, OnigSyntaxType* from));
|
||||
ONIG_EXTERN
|
||||
unsigned int onig_get_syntax_op P_((OnigSyntaxType* syntax));
|
||||
ONIG_EXTERN
|
||||
unsigned int onig_get_syntax_op2 P_((OnigSyntaxType* syntax));
|
||||
ONIG_EXTERN
|
||||
unsigned int onig_get_syntax_behavior P_((OnigSyntaxType* syntax));
|
||||
ONIG_EXTERN
|
||||
OnigOptionType onig_get_syntax_options P_((OnigSyntaxType* syntax));
|
||||
ONIG_EXTERN
|
||||
void onig_set_syntax_op P_((OnigSyntaxType* syntax, unsigned int op));
|
||||
ONIG_EXTERN
|
||||
void onig_set_syntax_op2 P_((OnigSyntaxType* syntax, unsigned int op2));
|
||||
ONIG_EXTERN
|
||||
void onig_set_syntax_behavior P_((OnigSyntaxType* syntax, unsigned int behavior));
|
||||
ONIG_EXTERN
|
||||
void onig_set_syntax_options P_((OnigSyntaxType* syntax, OnigOptionType options));
|
||||
ONIG_EXTERN
|
||||
int onig_set_meta_char P_((OnigSyntaxType* syntax, unsigned int what, OnigCodePoint code));
|
||||
ONIG_EXTERN
|
||||
void onig_copy_encoding P_((OnigEncoding to, OnigEncoding from));
|
||||
ONIG_EXTERN
|
||||
OnigCaseFoldType onig_get_default_case_fold_flag P_((void));
|
||||
ONIG_EXTERN
|
||||
int onig_set_default_case_fold_flag P_((OnigCaseFoldType case_fold_flag));
|
||||
ONIG_EXTERN
|
||||
unsigned int onig_get_match_stack_limit_size P_((void));
|
||||
ONIG_EXTERN
|
||||
int onig_set_match_stack_limit_size P_((unsigned int size));
|
||||
ONIG_EXTERN
|
||||
int onig_end P_((void));
|
||||
ONIG_EXTERN
|
||||
const char* onig_version P_((void));
|
||||
ONIG_EXTERN
|
||||
const char* onig_copyright P_((void));
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* ONIGURUMA_H */
|
||||
Binary file not shown.
@@ -1,38 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>BuildMachineOSBuild</key>
|
||||
<string>11E2620</string>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
<string>English</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>CocoaOniguruma</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>net.limechat.CocoaOniguruma</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>CocoaOniguruma</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>FMWK</string>
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1.0</string>
|
||||
<key>DTCompiler</key>
|
||||
<string></string>
|
||||
<key>DTPlatformBuild</key>
|
||||
<string>4E3002</string>
|
||||
<key>DTPlatformVersion</key>
|
||||
<string>GM</string>
|
||||
<key>DTSDKBuild</key>
|
||||
<string>11E2620</string>
|
||||
<key>DTSDKName</key>
|
||||
<string></string>
|
||||
<key>DTXcode</key>
|
||||
<string>0433</string>
|
||||
<key>DTXcodeBuild</key>
|
||||
<string>4E3002</string>
|
||||
</dict>
|
||||
</plist>
|
||||
Binary file not shown.
@@ -1,91 +0,0 @@
|
||||
// CocoaOniguruma is copyrighted free software by Satoshi Nakagawa <psychs AT limechat DOT net>.
|
||||
// You can redistribute it and/or modify it under the new BSD license.
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "oniguruma.h"
|
||||
#import "OnigRegexpUtility.h"
|
||||
|
||||
|
||||
@class OnigResult;
|
||||
|
||||
typedef enum {
|
||||
OnigOptionNone = ONIG_OPTION_NONE,
|
||||
OnigOptionIgnorecase = ONIG_OPTION_IGNORECASE,
|
||||
OnigOptionExtend = ONIG_OPTION_EXTEND,
|
||||
OnigOptionMultiline = ONIG_OPTION_MULTILINE,
|
||||
OnigOptionSingleline = ONIG_OPTION_SINGLELINE,
|
||||
OnigOptionFindLongest = ONIG_OPTION_FIND_LONGEST,
|
||||
OnigOptionFindNotEmpty = ONIG_OPTION_FIND_NOT_EMPTY,
|
||||
OnigOptionNegateSingleLine = ONIG_OPTION_NEGATE_SINGLELINE,
|
||||
OnigOptionDontCaptureGroup = ONIG_OPTION_DONT_CAPTURE_GROUP,
|
||||
OnigOptionCaptureGroup = ONIG_OPTION_CAPTURE_GROUP,
|
||||
|
||||
/* options (search time) */
|
||||
OnigOptionNotbol = ONIG_OPTION_NOTBOL,
|
||||
OnigOptionNoteol = ONIG_OPTION_NOTEOL,
|
||||
OnigOptionPosixRegion = ONIG_OPTION_POSIX_REGION,
|
||||
OnigOptionMaxbit = ONIG_OPTION_MAXBIT
|
||||
} OnigOption;
|
||||
|
||||
@interface OnigRegexp : NSObject
|
||||
{
|
||||
regex_t* _entity;
|
||||
NSString* _expression;
|
||||
}
|
||||
|
||||
+ (OnigRegexp*)compile:(NSString*)expression;
|
||||
+ (OnigRegexp*)compile:(NSString*)expression error:(NSError **)error;
|
||||
+ (OnigRegexp*)compileIgnorecase:(NSString*)expression;
|
||||
+ (OnigRegexp*)compileIgnorecase:(NSString*)expression error:(NSError **)error;
|
||||
+ (OnigRegexp*)compile:(NSString*)expression ignorecase:(BOOL)ignorecase multiline:(BOOL)multiline;
|
||||
+ (OnigRegexp*)compile:(NSString*)expression ignorecase:(BOOL)ignorecase multiline:(BOOL)multiline error:(NSError **)error;
|
||||
+ (OnigRegexp*)compile:(NSString*)expression ignorecase:(BOOL)ignorecase multiline:(BOOL)multiline extended:(BOOL)extended;
|
||||
+ (OnigRegexp*)compile:(NSString*)expression ignorecase:(BOOL)ignorecase multiline:(BOOL)multiline extended:(BOOL)extended error:(NSError **)error;
|
||||
+ (OnigRegexp*)compile:(NSString*)expression options:(OnigOption)options;
|
||||
+ (OnigRegexp*)compile:(NSString*)expression options:(OnigOption)options error:(NSError **)error;
|
||||
|
||||
- (OnigResult*)search:(NSString*)target;
|
||||
- (OnigResult*)search:(NSString*)target start:(int)start;
|
||||
- (OnigResult*)search:(NSString*)target start:(int)start end:(int)end;
|
||||
- (OnigResult*)search:(NSString*)target range:(NSRange)range;
|
||||
|
||||
- (OnigResult*)match:(NSString*)target;
|
||||
- (OnigResult*)match:(NSString*)target start:(int)start;
|
||||
|
||||
- (NSUInteger)captureCount;
|
||||
- (NSString*)expression;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@interface OnigResult : NSObject
|
||||
{
|
||||
OnigRegexp* _expression;
|
||||
OnigRegion* _region;
|
||||
NSString* _target;
|
||||
NSMutableArray* _captureNames;
|
||||
}
|
||||
|
||||
- (NSString*)target;
|
||||
|
||||
- (int)count;
|
||||
- (NSString*)stringAt:(int)index;
|
||||
- (NSArray*)strings;
|
||||
- (NSRange)rangeAt:(int)index;
|
||||
- (int)locationAt:(int)index;
|
||||
- (int)lengthAt:(int)index;
|
||||
|
||||
- (NSString*)body;
|
||||
- (NSRange)bodyRange;
|
||||
|
||||
- (NSString*)preMatch;
|
||||
- (NSString*)postMatch;
|
||||
|
||||
// named capture support
|
||||
- (NSArray*)captureNames;
|
||||
- (int)indexForName:(NSString*)name;
|
||||
- (NSIndexSet*)indexesForName:(NSString*)name;
|
||||
- (NSString*)stringForName:(NSString*)name;
|
||||
- (NSArray*)stringsForName:(NSString*)name;
|
||||
|
||||
@end
|
||||
@@ -1,57 +0,0 @@
|
||||
// CocoaOniguruma is copyrighted free software by Satoshi Nakagawa <psychs AT limechat DOT net>.
|
||||
// You can redistribute it and/or modify it under the new BSD license.
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "oniguruma.h"
|
||||
#import "OnigRegexp.h"
|
||||
|
||||
|
||||
@class OnigRegexp;
|
||||
@class OnigResult;
|
||||
|
||||
|
||||
@interface NSString (OnigRegexpUtility)
|
||||
|
||||
// pattern is OnigRegexp or NSString
|
||||
|
||||
- (NSRange)rangeOfRegexp:(id)pattern;
|
||||
|
||||
// based on ruby's split
|
||||
|
||||
- (NSArray*)split;
|
||||
- (NSArray*)splitByRegexp:(id)pattern;
|
||||
- (NSArray*)splitByRegexp:(id)pattern limit:(int)limit;
|
||||
|
||||
// based on ruby's gsub
|
||||
|
||||
- (NSString*)replaceByRegexp:(id)pattern with:(NSString*)string;
|
||||
- (NSString*)replaceAllByRegexp:(id)pattern with:(NSString*)string;
|
||||
|
||||
- (NSString*)replaceByRegexp:(id)pattern withCallback:(id)object selector:(SEL)sel;
|
||||
- (NSString*)replaceAllByRegexp:(id)pattern withCallback:(id)object selector:(SEL)sel;
|
||||
|
||||
#if defined(NS_BLOCKS_AVAILABLE)
|
||||
- (NSString*)replaceByRegexp:(id)pattern withBlock:(NSString* (^)(OnigResult*))block;
|
||||
- (NSString*)replaceAllByRegexp:(id)pattern withBlock:(NSString* (^)(OnigResult*))block;
|
||||
#endif
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@interface NSMutableString (OnigRegexpUtility)
|
||||
|
||||
// pattern is OnigRegexp or NSString
|
||||
|
||||
// based on ruby's gsub
|
||||
|
||||
- (NSMutableString*)replaceByRegexp:(id)pattern with:(NSString*)string;
|
||||
- (NSMutableString*)replaceAllByRegexp:(id)pattern with:(NSString*)string;
|
||||
|
||||
- (NSMutableString*)replaceByRegexp:(id)pattern withCallback:(id)object selector:(SEL)sel;
|
||||
- (NSMutableString*)replaceAllByRegexp:(id)pattern withCallback:(id)object selector:(SEL)sel;
|
||||
|
||||
#if defined(NS_BLOCKS_AVAILABLE)
|
||||
- (NSMutableString*)replaceByRegexp:(id)pattern withBlock:(NSString* (^)(OnigResult*))block;
|
||||
- (NSMutableString*)replaceAllByRegexp:(id)pattern withBlock:(NSString* (^)(OnigResult*))block;
|
||||
#endif
|
||||
@end
|
||||
@@ -1,770 +0,0 @@
|
||||
#ifndef ONIGURUMA_H
|
||||
#define ONIGURUMA_H
|
||||
/**********************************************************************
|
||||
oniguruma.h - Oniguruma (regular expression library)
|
||||
**********************************************************************/
|
||||
/*-
|
||||
* Copyright (c) 2002-2009 K.Kosako <sndgk393 AT ybb DOT ne DOT jp>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define ONIGURUMA
|
||||
#define ONIGURUMA_VERSION_MAJOR 5
|
||||
#define ONIGURUMA_VERSION_MINOR 9
|
||||
#define ONIGURUMA_VERSION_TEENY 2
|
||||
|
||||
#ifdef __cplusplus
|
||||
# ifndef HAVE_PROTOTYPES
|
||||
# define HAVE_PROTOTYPES 1
|
||||
# endif
|
||||
# ifndef HAVE_STDARG_PROTOTYPES
|
||||
# define HAVE_STDARG_PROTOTYPES 1
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* escape Mac OS X/Xcode 2.4/gcc 4.0.1 problem */
|
||||
#if defined(__APPLE__) && defined(__GNUC__) && __GNUC__ >= 4
|
||||
# ifndef HAVE_STDARG_PROTOTYPES
|
||||
# define HAVE_STDARG_PROTOTYPES 1
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_STDARG_H
|
||||
# ifndef HAVE_STDARG_PROTOTYPES
|
||||
# define HAVE_STDARG_PROTOTYPES 1
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef P_
|
||||
#if defined(__STDC__) || defined(_WIN32)
|
||||
# define P_(args) args
|
||||
#else
|
||||
# define P_(args) ()
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef PV_
|
||||
#ifdef HAVE_STDARG_PROTOTYPES
|
||||
# define PV_(args) args
|
||||
#else
|
||||
# define PV_(args) ()
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef ONIG_EXTERN
|
||||
#if defined(_WIN32) && !defined(__GNUC__)
|
||||
#if defined(EXPORT) || defined(RUBY_EXPORT)
|
||||
#define ONIG_EXTERN extern __declspec(dllexport)
|
||||
#else
|
||||
#define ONIG_EXTERN extern __declspec(dllimport)
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef ONIG_EXTERN
|
||||
#define ONIG_EXTERN extern
|
||||
#endif
|
||||
|
||||
/* PART: character encoding */
|
||||
|
||||
#ifndef ONIG_ESCAPE_UCHAR_COLLISION
|
||||
#define UChar OnigUChar
|
||||
#endif
|
||||
|
||||
typedef unsigned char OnigUChar;
|
||||
typedef unsigned long OnigCodePoint;
|
||||
typedef unsigned int OnigCtype;
|
||||
typedef unsigned int OnigDistance;
|
||||
|
||||
#define ONIG_INFINITE_DISTANCE ~((OnigDistance )0)
|
||||
|
||||
typedef unsigned int OnigCaseFoldType; /* case fold flag */
|
||||
|
||||
ONIG_EXTERN OnigCaseFoldType OnigDefaultCaseFoldFlag;
|
||||
|
||||
/* #define ONIGENC_CASE_FOLD_HIRAGANA_KATAKANA (1<<1) */
|
||||
/* #define ONIGENC_CASE_FOLD_KATAKANA_WIDTH (1<<2) */
|
||||
#define ONIGENC_CASE_FOLD_TURKISH_AZERI (1<<20)
|
||||
#define INTERNAL_ONIGENC_CASE_FOLD_MULTI_CHAR (1<<30)
|
||||
|
||||
#define ONIGENC_CASE_FOLD_MIN INTERNAL_ONIGENC_CASE_FOLD_MULTI_CHAR
|
||||
#define ONIGENC_CASE_FOLD_DEFAULT OnigDefaultCaseFoldFlag
|
||||
|
||||
|
||||
#define ONIGENC_MAX_COMP_CASE_FOLD_CODE_LEN 3
|
||||
#define ONIGENC_GET_CASE_FOLD_CODES_MAX_NUM 13
|
||||
/* 13 => Unicode:0x1ffc */
|
||||
|
||||
/* code range */
|
||||
#define ONIGENC_CODE_RANGE_NUM(range) ((int )range[0])
|
||||
#define ONIGENC_CODE_RANGE_FROM(range,i) range[((i)*2) + 1]
|
||||
#define ONIGENC_CODE_RANGE_TO(range,i) range[((i)*2) + 2]
|
||||
|
||||
typedef struct {
|
||||
int byte_len; /* argument(original) character(s) byte length */
|
||||
int code_len; /* number of code */
|
||||
OnigCodePoint code[ONIGENC_MAX_COMP_CASE_FOLD_CODE_LEN];
|
||||
} OnigCaseFoldCodeItem;
|
||||
|
||||
typedef struct {
|
||||
OnigCodePoint esc;
|
||||
OnigCodePoint anychar;
|
||||
OnigCodePoint anytime;
|
||||
OnigCodePoint zero_or_one_time;
|
||||
OnigCodePoint one_or_more_time;
|
||||
OnigCodePoint anychar_anytime;
|
||||
} OnigMetaCharTableType;
|
||||
|
||||
typedef int (*OnigApplyAllCaseFoldFunc)(OnigCodePoint from, OnigCodePoint* to, int to_len, void* arg);
|
||||
|
||||
typedef struct OnigEncodingTypeST {
|
||||
int (*mbc_enc_len)(const OnigUChar* p);
|
||||
const char* name;
|
||||
int max_enc_len;
|
||||
int min_enc_len;
|
||||
int (*is_mbc_newline)(const OnigUChar* p, const OnigUChar* end);
|
||||
OnigCodePoint (*mbc_to_code)(const OnigUChar* p, const OnigUChar* end);
|
||||
int (*code_to_mbclen)(OnigCodePoint code);
|
||||
int (*code_to_mbc)(OnigCodePoint code, OnigUChar *buf);
|
||||
int (*mbc_case_fold)(OnigCaseFoldType flag, const OnigUChar** pp, const OnigUChar* end, OnigUChar* to);
|
||||
int (*apply_all_case_fold)(OnigCaseFoldType flag, OnigApplyAllCaseFoldFunc f, void* arg);
|
||||
int (*get_case_fold_codes_by_str)(OnigCaseFoldType flag, const OnigUChar* p, const OnigUChar* end, OnigCaseFoldCodeItem acs[]);
|
||||
int (*property_name_to_ctype)(struct OnigEncodingTypeST* enc, OnigUChar* p, OnigUChar* end);
|
||||
int (*is_code_ctype)(OnigCodePoint code, OnigCtype ctype);
|
||||
int (*get_ctype_code_range)(OnigCtype ctype, OnigCodePoint* sb_out, const OnigCodePoint* ranges[]);
|
||||
OnigUChar* (*left_adjust_char_head)(const OnigUChar* start, const OnigUChar* p);
|
||||
int (*is_allowed_reverse_match)(const OnigUChar* p, const OnigUChar* end);
|
||||
} OnigEncodingType;
|
||||
|
||||
typedef OnigEncodingType* OnigEncoding;
|
||||
|
||||
ONIG_EXTERN OnigEncodingType OnigEncodingASCII;
|
||||
ONIG_EXTERN OnigEncodingType OnigEncodingUTF16_BE;
|
||||
ONIG_EXTERN OnigEncodingType OnigEncodingUTF16_LE;
|
||||
ONIG_EXTERN OnigEncodingType OnigEncodingUTF32_BE;
|
||||
ONIG_EXTERN OnigEncodingType OnigEncodingUTF32_LE;
|
||||
|
||||
#define ONIG_ENCODING_ASCII (&OnigEncodingASCII)
|
||||
#define ONIG_ENCODING_UTF16_BE (&OnigEncodingUTF16_BE)
|
||||
#define ONIG_ENCODING_UTF16_LE (&OnigEncodingUTF16_LE)
|
||||
#define ONIG_ENCODING_UTF32_BE (&OnigEncodingUTF32_BE)
|
||||
#define ONIG_ENCODING_UTF32_LE (&OnigEncodingUTF32_LE)
|
||||
|
||||
#define ONIG_ENCODING_UNDEF ((OnigEncoding )0)
|
||||
|
||||
|
||||
/* work size */
|
||||
#define ONIGENC_CODE_TO_MBC_MAXLEN 7
|
||||
#define ONIGENC_MBC_CASE_FOLD_MAXLEN 18
|
||||
/* 18: 6(max-byte) * 3(case-fold chars) */
|
||||
|
||||
/* character types */
|
||||
#define ONIGENC_CTYPE_NEWLINE 0
|
||||
#define ONIGENC_CTYPE_ALPHA 1
|
||||
#define ONIGENC_CTYPE_BLANK 2
|
||||
#define ONIGENC_CTYPE_CNTRL 3
|
||||
#define ONIGENC_CTYPE_DIGIT 4
|
||||
#define ONIGENC_CTYPE_GRAPH 5
|
||||
#define ONIGENC_CTYPE_LOWER 6
|
||||
#define ONIGENC_CTYPE_PRINT 7
|
||||
#define ONIGENC_CTYPE_PUNCT 8
|
||||
#define ONIGENC_CTYPE_SPACE 9
|
||||
#define ONIGENC_CTYPE_UPPER 10
|
||||
#define ONIGENC_CTYPE_XDIGIT 11
|
||||
#define ONIGENC_CTYPE_WORD 12
|
||||
#define ONIGENC_CTYPE_ALNUM 13 /* alpha || digit */
|
||||
#define ONIGENC_CTYPE_ASCII 14
|
||||
#define ONIGENC_MAX_STD_CTYPE ONIGENC_CTYPE_ASCII
|
||||
|
||||
|
||||
#define onig_enc_len(enc,p,end) ONIGENC_MBC_ENC_LEN(enc,p)
|
||||
|
||||
#define ONIGENC_IS_UNDEF(enc) ((enc) == ONIG_ENCODING_UNDEF)
|
||||
#define ONIGENC_IS_SINGLEBYTE(enc) (ONIGENC_MBC_MAXLEN(enc) == 1)
|
||||
#define ONIGENC_IS_MBC_HEAD(enc,p) (ONIGENC_MBC_ENC_LEN(enc,p) != 1)
|
||||
#define ONIGENC_IS_MBC_ASCII(p) (*(p) < 128)
|
||||
#define ONIGENC_IS_CODE_ASCII(code) ((code) < 128)
|
||||
#define ONIGENC_IS_MBC_WORD(enc,s,end) \
|
||||
ONIGENC_IS_CODE_WORD(enc,ONIGENC_MBC_TO_CODE(enc,s,end))
|
||||
|
||||
|
||||
#define ONIGENC_NAME(enc) ((enc)->name)
|
||||
|
||||
#define ONIGENC_MBC_CASE_FOLD(enc,flag,pp,end,buf) \
|
||||
(enc)->mbc_case_fold(flag,(const OnigUChar** )pp,end,buf)
|
||||
#define ONIGENC_IS_ALLOWED_REVERSE_MATCH(enc,s,end) \
|
||||
(enc)->is_allowed_reverse_match(s,end)
|
||||
#define ONIGENC_LEFT_ADJUST_CHAR_HEAD(enc,start,s) \
|
||||
(enc)->left_adjust_char_head(start, s)
|
||||
#define ONIGENC_APPLY_ALL_CASE_FOLD(enc,case_fold_flag,f,arg) \
|
||||
(enc)->apply_all_case_fold(case_fold_flag,f,arg)
|
||||
#define ONIGENC_GET_CASE_FOLD_CODES_BY_STR(enc,case_fold_flag,p,end,acs) \
|
||||
(enc)->get_case_fold_codes_by_str(case_fold_flag,p,end,acs)
|
||||
#define ONIGENC_STEP_BACK(enc,start,s,n) \
|
||||
onigenc_step_back((enc),(start),(s),(n))
|
||||
|
||||
#define ONIGENC_MBC_ENC_LEN(enc,p) (enc)->mbc_enc_len(p)
|
||||
#define ONIGENC_MBC_MAXLEN(enc) ((enc)->max_enc_len)
|
||||
#define ONIGENC_MBC_MAXLEN_DIST(enc) ONIGENC_MBC_MAXLEN(enc)
|
||||
#define ONIGENC_MBC_MINLEN(enc) ((enc)->min_enc_len)
|
||||
#define ONIGENC_IS_MBC_NEWLINE(enc,p,end) (enc)->is_mbc_newline((p),(end))
|
||||
#define ONIGENC_MBC_TO_CODE(enc,p,end) (enc)->mbc_to_code((p),(end))
|
||||
#define ONIGENC_CODE_TO_MBCLEN(enc,code) (enc)->code_to_mbclen(code)
|
||||
#define ONIGENC_CODE_TO_MBC(enc,code,buf) (enc)->code_to_mbc(code,buf)
|
||||
#define ONIGENC_PROPERTY_NAME_TO_CTYPE(enc,p,end) \
|
||||
(enc)->property_name_to_ctype(enc,p,end)
|
||||
|
||||
#define ONIGENC_IS_CODE_CTYPE(enc,code,ctype) (enc)->is_code_ctype(code,ctype)
|
||||
|
||||
#define ONIGENC_IS_CODE_NEWLINE(enc,code) \
|
||||
ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_NEWLINE)
|
||||
#define ONIGENC_IS_CODE_GRAPH(enc,code) \
|
||||
ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_GRAPH)
|
||||
#define ONIGENC_IS_CODE_PRINT(enc,code) \
|
||||
ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_PRINT)
|
||||
#define ONIGENC_IS_CODE_ALNUM(enc,code) \
|
||||
ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_ALNUM)
|
||||
#define ONIGENC_IS_CODE_ALPHA(enc,code) \
|
||||
ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_ALPHA)
|
||||
#define ONIGENC_IS_CODE_LOWER(enc,code) \
|
||||
ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_LOWER)
|
||||
#define ONIGENC_IS_CODE_UPPER(enc,code) \
|
||||
ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_UPPER)
|
||||
#define ONIGENC_IS_CODE_CNTRL(enc,code) \
|
||||
ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_CNTRL)
|
||||
#define ONIGENC_IS_CODE_PUNCT(enc,code) \
|
||||
ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_PUNCT)
|
||||
#define ONIGENC_IS_CODE_SPACE(enc,code) \
|
||||
ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_SPACE)
|
||||
#define ONIGENC_IS_CODE_BLANK(enc,code) \
|
||||
ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_BLANK)
|
||||
#define ONIGENC_IS_CODE_DIGIT(enc,code) \
|
||||
ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_DIGIT)
|
||||
#define ONIGENC_IS_CODE_XDIGIT(enc,code) \
|
||||
ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_XDIGIT)
|
||||
#define ONIGENC_IS_CODE_WORD(enc,code) \
|
||||
ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_WORD)
|
||||
|
||||
#define ONIGENC_GET_CTYPE_CODE_RANGE(enc,ctype,sbout,ranges) \
|
||||
(enc)->get_ctype_code_range(ctype,sbout,ranges)
|
||||
|
||||
ONIG_EXTERN
|
||||
OnigUChar* onigenc_step_back P_((OnigEncoding enc, const OnigUChar* start, const OnigUChar* s, int n));
|
||||
|
||||
|
||||
/* encoding API */
|
||||
ONIG_EXTERN
|
||||
int onigenc_init P_((void));
|
||||
ONIG_EXTERN
|
||||
int onigenc_set_default_encoding P_((OnigEncoding enc));
|
||||
ONIG_EXTERN
|
||||
OnigEncoding onigenc_get_default_encoding P_((void));
|
||||
ONIG_EXTERN
|
||||
void onigenc_set_default_caseconv_table P_((const OnigUChar* table));
|
||||
ONIG_EXTERN
|
||||
OnigUChar* onigenc_get_right_adjust_char_head_with_prev P_((OnigEncoding enc, const OnigUChar* start, const OnigUChar* s, const OnigUChar** prev));
|
||||
ONIG_EXTERN
|
||||
OnigUChar* onigenc_get_prev_char_head P_((OnigEncoding enc, const OnigUChar* start, const OnigUChar* s));
|
||||
ONIG_EXTERN
|
||||
OnigUChar* onigenc_get_left_adjust_char_head P_((OnigEncoding enc, const OnigUChar* start, const OnigUChar* s));
|
||||
ONIG_EXTERN
|
||||
OnigUChar* onigenc_get_right_adjust_char_head P_((OnigEncoding enc, const OnigUChar* start, const OnigUChar* s));
|
||||
ONIG_EXTERN
|
||||
int onigenc_strlen P_((OnigEncoding enc, const OnigUChar* p, const OnigUChar* end));
|
||||
ONIG_EXTERN
|
||||
int onigenc_strlen_null P_((OnigEncoding enc, const OnigUChar* p));
|
||||
ONIG_EXTERN
|
||||
int onigenc_str_bytelen_null P_((OnigEncoding enc, const OnigUChar* p));
|
||||
|
||||
|
||||
|
||||
/* PART: regular expression */
|
||||
|
||||
/* config parameters */
|
||||
#define ONIG_NREGION 10
|
||||
#define ONIG_MAX_BACKREF_NUM 1000
|
||||
#define ONIG_MAX_REPEAT_NUM 100000
|
||||
#define ONIG_MAX_MULTI_BYTE_RANGES_NUM 10000
|
||||
/* constants */
|
||||
#define ONIG_MAX_ERROR_MESSAGE_LEN 90
|
||||
|
||||
typedef unsigned int OnigOptionType;
|
||||
|
||||
#define ONIG_OPTION_DEFAULT ONIG_OPTION_NONE
|
||||
|
||||
/* options */
|
||||
#define ONIG_OPTION_NONE 0U
|
||||
#define ONIG_OPTION_IGNORECASE 1U
|
||||
#define ONIG_OPTION_EXTEND (ONIG_OPTION_IGNORECASE << 1)
|
||||
#define ONIG_OPTION_MULTILINE (ONIG_OPTION_EXTEND << 1)
|
||||
#define ONIG_OPTION_SINGLELINE (ONIG_OPTION_MULTILINE << 1)
|
||||
#define ONIG_OPTION_FIND_LONGEST (ONIG_OPTION_SINGLELINE << 1)
|
||||
#define ONIG_OPTION_FIND_NOT_EMPTY (ONIG_OPTION_FIND_LONGEST << 1)
|
||||
#define ONIG_OPTION_NEGATE_SINGLELINE (ONIG_OPTION_FIND_NOT_EMPTY << 1)
|
||||
#define ONIG_OPTION_DONT_CAPTURE_GROUP (ONIG_OPTION_NEGATE_SINGLELINE << 1)
|
||||
#define ONIG_OPTION_CAPTURE_GROUP (ONIG_OPTION_DONT_CAPTURE_GROUP << 1)
|
||||
/* options (search time) */
|
||||
#define ONIG_OPTION_NOTBOL (ONIG_OPTION_CAPTURE_GROUP << 1)
|
||||
#define ONIG_OPTION_NOTEOL (ONIG_OPTION_NOTBOL << 1)
|
||||
#define ONIG_OPTION_POSIX_REGION (ONIG_OPTION_NOTEOL << 1)
|
||||
#define ONIG_OPTION_MAXBIT ONIG_OPTION_POSIX_REGION /* limit */
|
||||
|
||||
#define ONIG_OPTION_ON(options,regopt) ((options) |= (regopt))
|
||||
#define ONIG_OPTION_OFF(options,regopt) ((options) &= ~(regopt))
|
||||
#define ONIG_IS_OPTION_ON(options,option) ((options) & (option))
|
||||
|
||||
/* syntax */
|
||||
typedef struct {
|
||||
unsigned int op;
|
||||
unsigned int op2;
|
||||
unsigned int behavior;
|
||||
OnigOptionType options; /* default option */
|
||||
OnigMetaCharTableType meta_char_table;
|
||||
} OnigSyntaxType;
|
||||
|
||||
ONIG_EXTERN OnigSyntaxType OnigSyntaxASIS;
|
||||
ONIG_EXTERN OnigSyntaxType OnigSyntaxPosixBasic;
|
||||
ONIG_EXTERN OnigSyntaxType OnigSyntaxPosixExtended;
|
||||
ONIG_EXTERN OnigSyntaxType OnigSyntaxEmacs;
|
||||
ONIG_EXTERN OnigSyntaxType OnigSyntaxGrep;
|
||||
ONIG_EXTERN OnigSyntaxType OnigSyntaxGnuRegex;
|
||||
ONIG_EXTERN OnigSyntaxType OnigSyntaxJava;
|
||||
ONIG_EXTERN OnigSyntaxType OnigSyntaxPerl;
|
||||
ONIG_EXTERN OnigSyntaxType OnigSyntaxPerl_NG;
|
||||
ONIG_EXTERN OnigSyntaxType OnigSyntaxRuby;
|
||||
|
||||
/* predefined syntaxes (see regsyntax.c) */
|
||||
#define ONIG_SYNTAX_ASIS (&OnigSyntaxASIS)
|
||||
#define ONIG_SYNTAX_POSIX_BASIC (&OnigSyntaxPosixBasic)
|
||||
#define ONIG_SYNTAX_POSIX_EXTENDED (&OnigSyntaxPosixExtended)
|
||||
#define ONIG_SYNTAX_EMACS (&OnigSyntaxEmacs)
|
||||
#define ONIG_SYNTAX_GREP (&OnigSyntaxGrep)
|
||||
#define ONIG_SYNTAX_GNU_REGEX (&OnigSyntaxGnuRegex)
|
||||
#define ONIG_SYNTAX_JAVA (&OnigSyntaxJava)
|
||||
#define ONIG_SYNTAX_PERL (&OnigSyntaxPerl)
|
||||
#define ONIG_SYNTAX_PERL_NG (&OnigSyntaxPerl_NG)
|
||||
#define ONIG_SYNTAX_RUBY (&OnigSyntaxRuby)
|
||||
|
||||
/* default syntax */
|
||||
ONIG_EXTERN OnigSyntaxType* OnigDefaultSyntax;
|
||||
#define ONIG_SYNTAX_DEFAULT OnigDefaultSyntax
|
||||
|
||||
/* syntax (operators) */
|
||||
#define ONIG_SYN_OP_VARIABLE_META_CHARACTERS (1U<<0)
|
||||
#define ONIG_SYN_OP_DOT_ANYCHAR (1U<<1) /* . */
|
||||
#define ONIG_SYN_OP_ASTERISK_ZERO_INF (1U<<2) /* * */
|
||||
#define ONIG_SYN_OP_ESC_ASTERISK_ZERO_INF (1U<<3)
|
||||
#define ONIG_SYN_OP_PLUS_ONE_INF (1U<<4) /* + */
|
||||
#define ONIG_SYN_OP_ESC_PLUS_ONE_INF (1U<<5)
|
||||
#define ONIG_SYN_OP_QMARK_ZERO_ONE (1U<<6) /* ? */
|
||||
#define ONIG_SYN_OP_ESC_QMARK_ZERO_ONE (1U<<7)
|
||||
#define ONIG_SYN_OP_BRACE_INTERVAL (1U<<8) /* {lower,upper} */
|
||||
#define ONIG_SYN_OP_ESC_BRACE_INTERVAL (1U<<9) /* \{lower,upper\} */
|
||||
#define ONIG_SYN_OP_VBAR_ALT (1U<<10) /* | */
|
||||
#define ONIG_SYN_OP_ESC_VBAR_ALT (1U<<11) /* \| */
|
||||
#define ONIG_SYN_OP_LPAREN_SUBEXP (1U<<12) /* (...) */
|
||||
#define ONIG_SYN_OP_ESC_LPAREN_SUBEXP (1U<<13) /* \(...\) */
|
||||
#define ONIG_SYN_OP_ESC_AZ_BUF_ANCHOR (1U<<14) /* \A, \Z, \z */
|
||||
#define ONIG_SYN_OP_ESC_CAPITAL_G_BEGIN_ANCHOR (1U<<15) /* \G */
|
||||
#define ONIG_SYN_OP_DECIMAL_BACKREF (1U<<16) /* \num */
|
||||
#define ONIG_SYN_OP_BRACKET_CC (1U<<17) /* [...] */
|
||||
#define ONIG_SYN_OP_ESC_W_WORD (1U<<18) /* \w, \W */
|
||||
#define ONIG_SYN_OP_ESC_LTGT_WORD_BEGIN_END (1U<<19) /* \<. \> */
|
||||
#define ONIG_SYN_OP_ESC_B_WORD_BOUND (1U<<20) /* \b, \B */
|
||||
#define ONIG_SYN_OP_ESC_S_WHITE_SPACE (1U<<21) /* \s, \S */
|
||||
#define ONIG_SYN_OP_ESC_D_DIGIT (1U<<22) /* \d, \D */
|
||||
#define ONIG_SYN_OP_LINE_ANCHOR (1U<<23) /* ^, $ */
|
||||
#define ONIG_SYN_OP_POSIX_BRACKET (1U<<24) /* [:xxxx:] */
|
||||
#define ONIG_SYN_OP_QMARK_NON_GREEDY (1U<<25) /* ??,*?,+?,{n,m}? */
|
||||
#define ONIG_SYN_OP_ESC_CONTROL_CHARS (1U<<26) /* \n,\r,\t,\a ... */
|
||||
#define ONIG_SYN_OP_ESC_C_CONTROL (1U<<27) /* \cx */
|
||||
#define ONIG_SYN_OP_ESC_OCTAL3 (1U<<28) /* \OOO */
|
||||
#define ONIG_SYN_OP_ESC_X_HEX2 (1U<<29) /* \xHH */
|
||||
#define ONIG_SYN_OP_ESC_X_BRACE_HEX8 (1U<<30) /* \x{7HHHHHHH} */
|
||||
|
||||
#define ONIG_SYN_OP2_ESC_CAPITAL_Q_QUOTE (1U<<0) /* \Q...\E */
|
||||
#define ONIG_SYN_OP2_QMARK_GROUP_EFFECT (1U<<1) /* (?...) */
|
||||
#define ONIG_SYN_OP2_OPTION_PERL (1U<<2) /* (?imsx),(?-imsx) */
|
||||
#define ONIG_SYN_OP2_OPTION_RUBY (1U<<3) /* (?imx), (?-imx) */
|
||||
#define ONIG_SYN_OP2_PLUS_POSSESSIVE_REPEAT (1U<<4) /* ?+,*+,++ */
|
||||
#define ONIG_SYN_OP2_PLUS_POSSESSIVE_INTERVAL (1U<<5) /* {n,m}+ */
|
||||
#define ONIG_SYN_OP2_CCLASS_SET_OP (1U<<6) /* [...&&..[..]..] */
|
||||
#define ONIG_SYN_OP2_QMARK_LT_NAMED_GROUP (1U<<7) /* (?<name>...) */
|
||||
#define ONIG_SYN_OP2_ESC_K_NAMED_BACKREF (1U<<8) /* \k<name> */
|
||||
#define ONIG_SYN_OP2_ESC_G_SUBEXP_CALL (1U<<9) /* \g<name>, \g<n> */
|
||||
#define ONIG_SYN_OP2_ATMARK_CAPTURE_HISTORY (1U<<10) /* (?@..),(?@<x>..) */
|
||||
#define ONIG_SYN_OP2_ESC_CAPITAL_C_BAR_CONTROL (1U<<11) /* \C-x */
|
||||
#define ONIG_SYN_OP2_ESC_CAPITAL_M_BAR_META (1U<<12) /* \M-x */
|
||||
#define ONIG_SYN_OP2_ESC_V_VTAB (1U<<13) /* \v as VTAB */
|
||||
#define ONIG_SYN_OP2_ESC_U_HEX4 (1U<<14) /* \uHHHH */
|
||||
#define ONIG_SYN_OP2_ESC_GNU_BUF_ANCHOR (1U<<15) /* \`, \' */
|
||||
#define ONIG_SYN_OP2_ESC_P_BRACE_CHAR_PROPERTY (1U<<16) /* \p{...}, \P{...} */
|
||||
#define ONIG_SYN_OP2_ESC_P_BRACE_CIRCUMFLEX_NOT (1U<<17) /* \p{^..}, \P{^..} */
|
||||
/* #define ONIG_SYN_OP2_CHAR_PROPERTY_PREFIX_IS (1U<<18) */
|
||||
#define ONIG_SYN_OP2_ESC_H_XDIGIT (1U<<19) /* \h, \H */
|
||||
#define ONIG_SYN_OP2_INEFFECTIVE_ESCAPE (1U<<20) /* \ */
|
||||
|
||||
/* syntax (behavior) */
|
||||
#define ONIG_SYN_CONTEXT_INDEP_ANCHORS (1U<<31) /* not implemented */
|
||||
#define ONIG_SYN_CONTEXT_INDEP_REPEAT_OPS (1U<<0) /* ?, *, +, {n,m} */
|
||||
#define ONIG_SYN_CONTEXT_INVALID_REPEAT_OPS (1U<<1) /* error or ignore */
|
||||
#define ONIG_SYN_ALLOW_UNMATCHED_CLOSE_SUBEXP (1U<<2) /* ...)... */
|
||||
#define ONIG_SYN_ALLOW_INVALID_INTERVAL (1U<<3) /* {??? */
|
||||
#define ONIG_SYN_ALLOW_INTERVAL_LOW_ABBREV (1U<<4) /* {,n} => {0,n} */
|
||||
#define ONIG_SYN_STRICT_CHECK_BACKREF (1U<<5) /* /(\1)/,/\1()/ ..*/
|
||||
#define ONIG_SYN_DIFFERENT_LEN_ALT_LOOK_BEHIND (1U<<6) /* (?<=a|bc) */
|
||||
#define ONIG_SYN_CAPTURE_ONLY_NAMED_GROUP (1U<<7) /* see doc/RE */
|
||||
#define ONIG_SYN_ALLOW_MULTIPLEX_DEFINITION_NAME (1U<<8) /* (?<x>)(?<x>) */
|
||||
#define ONIG_SYN_FIXED_INTERVAL_IS_GREEDY_ONLY (1U<<9) /* a{n}?=(?:a{n})? */
|
||||
|
||||
/* syntax (behavior) in char class [...] */
|
||||
#define ONIG_SYN_NOT_NEWLINE_IN_NEGATIVE_CC (1U<<20) /* [^...] */
|
||||
#define ONIG_SYN_BACKSLASH_ESCAPE_IN_CC (1U<<21) /* [..\w..] etc.. */
|
||||
#define ONIG_SYN_ALLOW_EMPTY_RANGE_IN_CC (1U<<22)
|
||||
#define ONIG_SYN_ALLOW_DOUBLE_RANGE_OP_IN_CC (1U<<23) /* [0-9-a]=[0-9\-a] */
|
||||
/* syntax (behavior) warning */
|
||||
#define ONIG_SYN_WARN_CC_OP_NOT_ESCAPED (1U<<24) /* [,-,] */
|
||||
#define ONIG_SYN_WARN_REDUNDANT_NESTED_REPEAT (1U<<25) /* (?:a*)+ */
|
||||
|
||||
/* meta character specifiers (onig_set_meta_char()) */
|
||||
#define ONIG_META_CHAR_ESCAPE 0
|
||||
#define ONIG_META_CHAR_ANYCHAR 1
|
||||
#define ONIG_META_CHAR_ANYTIME 2
|
||||
#define ONIG_META_CHAR_ZERO_OR_ONE_TIME 3
|
||||
#define ONIG_META_CHAR_ONE_OR_MORE_TIME 4
|
||||
#define ONIG_META_CHAR_ANYCHAR_ANYTIME 5
|
||||
|
||||
#define ONIG_INEFFECTIVE_META_CHAR 0
|
||||
|
||||
/* error codes */
|
||||
#define ONIG_IS_PATTERN_ERROR(ecode) ((ecode) <= -100 && (ecode) > -1000)
|
||||
/* normal return */
|
||||
#define ONIG_NORMAL 0
|
||||
#define ONIG_MISMATCH -1
|
||||
#define ONIG_NO_SUPPORT_CONFIG -2
|
||||
|
||||
/* internal error */
|
||||
#define ONIGERR_MEMORY -5
|
||||
#define ONIGERR_TYPE_BUG -6
|
||||
#define ONIGERR_PARSER_BUG -11
|
||||
#define ONIGERR_STACK_BUG -12
|
||||
#define ONIGERR_UNDEFINED_BYTECODE -13
|
||||
#define ONIGERR_UNEXPECTED_BYTECODE -14
|
||||
#define ONIGERR_MATCH_STACK_LIMIT_OVER -15
|
||||
#define ONIGERR_DEFAULT_ENCODING_IS_NOT_SETTED -21
|
||||
#define ONIGERR_SPECIFIED_ENCODING_CANT_CONVERT_TO_WIDE_CHAR -22
|
||||
/* general error */
|
||||
#define ONIGERR_INVALID_ARGUMENT -30
|
||||
/* syntax error */
|
||||
#define ONIGERR_END_PATTERN_AT_LEFT_BRACE -100
|
||||
#define ONIGERR_END_PATTERN_AT_LEFT_BRACKET -101
|
||||
#define ONIGERR_EMPTY_CHAR_CLASS -102
|
||||
#define ONIGERR_PREMATURE_END_OF_CHAR_CLASS -103
|
||||
#define ONIGERR_END_PATTERN_AT_ESCAPE -104
|
||||
#define ONIGERR_END_PATTERN_AT_META -105
|
||||
#define ONIGERR_END_PATTERN_AT_CONTROL -106
|
||||
#define ONIGERR_META_CODE_SYNTAX -108
|
||||
#define ONIGERR_CONTROL_CODE_SYNTAX -109
|
||||
#define ONIGERR_CHAR_CLASS_VALUE_AT_END_OF_RANGE -110
|
||||
#define ONIGERR_CHAR_CLASS_VALUE_AT_START_OF_RANGE -111
|
||||
#define ONIGERR_UNMATCHED_RANGE_SPECIFIER_IN_CHAR_CLASS -112
|
||||
#define ONIGERR_TARGET_OF_REPEAT_OPERATOR_NOT_SPECIFIED -113
|
||||
#define ONIGERR_TARGET_OF_REPEAT_OPERATOR_INVALID -114
|
||||
#define ONIGERR_NESTED_REPEAT_OPERATOR -115
|
||||
#define ONIGERR_UNMATCHED_CLOSE_PARENTHESIS -116
|
||||
#define ONIGERR_END_PATTERN_WITH_UNMATCHED_PARENTHESIS -117
|
||||
#define ONIGERR_END_PATTERN_IN_GROUP -118
|
||||
#define ONIGERR_UNDEFINED_GROUP_OPTION -119
|
||||
#define ONIGERR_INVALID_POSIX_BRACKET_TYPE -121
|
||||
#define ONIGERR_INVALID_LOOK_BEHIND_PATTERN -122
|
||||
#define ONIGERR_INVALID_REPEAT_RANGE_PATTERN -123
|
||||
/* values error (syntax error) */
|
||||
#define ONIGERR_TOO_BIG_NUMBER -200
|
||||
#define ONIGERR_TOO_BIG_NUMBER_FOR_REPEAT_RANGE -201
|
||||
#define ONIGERR_UPPER_SMALLER_THAN_LOWER_IN_REPEAT_RANGE -202
|
||||
#define ONIGERR_EMPTY_RANGE_IN_CHAR_CLASS -203
|
||||
#define ONIGERR_MISMATCH_CODE_LENGTH_IN_CLASS_RANGE -204
|
||||
#define ONIGERR_TOO_MANY_MULTI_BYTE_RANGES -205
|
||||
#define ONIGERR_TOO_SHORT_MULTI_BYTE_STRING -206
|
||||
#define ONIGERR_TOO_BIG_BACKREF_NUMBER -207
|
||||
#define ONIGERR_INVALID_BACKREF -208
|
||||
#define ONIGERR_NUMBERED_BACKREF_OR_CALL_NOT_ALLOWED -209
|
||||
#define ONIGERR_TOO_LONG_WIDE_CHAR_VALUE -212
|
||||
#define ONIGERR_EMPTY_GROUP_NAME -214
|
||||
#define ONIGERR_INVALID_GROUP_NAME -215
|
||||
#define ONIGERR_INVALID_CHAR_IN_GROUP_NAME -216
|
||||
#define ONIGERR_UNDEFINED_NAME_REFERENCE -217
|
||||
#define ONIGERR_UNDEFINED_GROUP_REFERENCE -218
|
||||
#define ONIGERR_MULTIPLEX_DEFINED_NAME -219
|
||||
#define ONIGERR_MULTIPLEX_DEFINITION_NAME_CALL -220
|
||||
#define ONIGERR_NEVER_ENDING_RECURSION -221
|
||||
#define ONIGERR_GROUP_NUMBER_OVER_FOR_CAPTURE_HISTORY -222
|
||||
#define ONIGERR_INVALID_CHAR_PROPERTY_NAME -223
|
||||
#define ONIGERR_INVALID_CODE_POINT_VALUE -400
|
||||
#define ONIGERR_INVALID_WIDE_CHAR_VALUE -400
|
||||
#define ONIGERR_TOO_BIG_WIDE_CHAR_VALUE -401
|
||||
#define ONIGERR_NOT_SUPPORTED_ENCODING_COMBINATION -402
|
||||
#define ONIGERR_INVALID_COMBINATION_OF_OPTIONS -403
|
||||
|
||||
/* errors related to thread */
|
||||
#define ONIGERR_OVER_THREAD_PASS_LIMIT_COUNT -1001
|
||||
|
||||
|
||||
/* must be smaller than BIT_STATUS_BITS_NUM (unsigned int * 8) */
|
||||
#define ONIG_MAX_CAPTURE_HISTORY_GROUP 31
|
||||
#define ONIG_IS_CAPTURE_HISTORY_GROUP(r, i) \
|
||||
((i) <= ONIG_MAX_CAPTURE_HISTORY_GROUP && (r)->list && (r)->list[i])
|
||||
|
||||
typedef struct OnigCaptureTreeNodeStruct {
|
||||
int group; /* group number */
|
||||
int beg;
|
||||
int end;
|
||||
int allocated;
|
||||
int num_childs;
|
||||
struct OnigCaptureTreeNodeStruct** childs;
|
||||
} OnigCaptureTreeNode;
|
||||
|
||||
/* match result region type */
|
||||
struct re_registers {
|
||||
int allocated;
|
||||
int num_regs;
|
||||
int* beg;
|
||||
int* end;
|
||||
/* extended */
|
||||
OnigCaptureTreeNode* history_root; /* capture history tree root */
|
||||
};
|
||||
|
||||
/* capture tree traverse */
|
||||
#define ONIG_TRAVERSE_CALLBACK_AT_FIRST 1
|
||||
#define ONIG_TRAVERSE_CALLBACK_AT_LAST 2
|
||||
#define ONIG_TRAVERSE_CALLBACK_AT_BOTH \
|
||||
( ONIG_TRAVERSE_CALLBACK_AT_FIRST | ONIG_TRAVERSE_CALLBACK_AT_LAST )
|
||||
|
||||
|
||||
#define ONIG_REGION_NOTPOS -1
|
||||
|
||||
typedef struct re_registers OnigRegion;
|
||||
|
||||
typedef struct {
|
||||
OnigEncoding enc;
|
||||
OnigUChar* par;
|
||||
OnigUChar* par_end;
|
||||
} OnigErrorInfo;
|
||||
|
||||
typedef struct {
|
||||
int lower;
|
||||
int upper;
|
||||
} OnigRepeatRange;
|
||||
|
||||
typedef void (*OnigWarnFunc) P_((const char* s));
|
||||
extern void onig_null_warn P_((const char* s));
|
||||
#define ONIG_NULL_WARN onig_null_warn
|
||||
|
||||
#define ONIG_CHAR_TABLE_SIZE 256
|
||||
|
||||
/* regex_t state */
|
||||
#define ONIG_STATE_NORMAL 0
|
||||
#define ONIG_STATE_SEARCHING 1
|
||||
#define ONIG_STATE_COMPILING -1
|
||||
#define ONIG_STATE_MODIFY -2
|
||||
|
||||
#define ONIG_STATE(reg) \
|
||||
((reg)->state > 0 ? ONIG_STATE_SEARCHING : (reg)->state)
|
||||
|
||||
typedef struct re_pattern_buffer {
|
||||
/* common members of BBuf(bytes-buffer) */
|
||||
unsigned char* p; /* compiled pattern */
|
||||
unsigned int used; /* used space for p */
|
||||
unsigned int alloc; /* allocated space for p */
|
||||
|
||||
int state; /* normal, searching, compiling */
|
||||
int num_mem; /* used memory(...) num counted from 1 */
|
||||
int num_repeat; /* OP_REPEAT/OP_REPEAT_NG id-counter */
|
||||
int num_null_check; /* OP_NULL_CHECK_START/END id counter */
|
||||
int num_comb_exp_check; /* combination explosion check */
|
||||
int num_call; /* number of subexp call */
|
||||
unsigned int capture_history; /* (?@...) flag (1-31) */
|
||||
unsigned int bt_mem_start; /* need backtrack flag */
|
||||
unsigned int bt_mem_end; /* need backtrack flag */
|
||||
int stack_pop_level;
|
||||
int repeat_range_alloc;
|
||||
OnigRepeatRange* repeat_range;
|
||||
|
||||
OnigEncoding enc;
|
||||
OnigOptionType options;
|
||||
OnigSyntaxType* syntax;
|
||||
OnigCaseFoldType case_fold_flag;
|
||||
void* name_table;
|
||||
|
||||
/* optimization info (string search, char-map and anchors) */
|
||||
int optimize; /* optimize flag */
|
||||
int threshold_len; /* search str-length for apply optimize */
|
||||
int anchor; /* BEGIN_BUF, BEGIN_POS, (SEMI_)END_BUF */
|
||||
OnigDistance anchor_dmin; /* (SEMI_)END_BUF anchor distance */
|
||||
OnigDistance anchor_dmax; /* (SEMI_)END_BUF anchor distance */
|
||||
int sub_anchor; /* start-anchor for exact or map */
|
||||
unsigned char *exact;
|
||||
unsigned char *exact_end;
|
||||
unsigned char map[ONIG_CHAR_TABLE_SIZE]; /* used as BM skip or char-map */
|
||||
int *int_map; /* BM skip for exact_len > 255 */
|
||||
int *int_map_backward; /* BM skip for backward search */
|
||||
OnigDistance dmin; /* min-distance of exact or map */
|
||||
OnigDistance dmax; /* max-distance of exact or map */
|
||||
|
||||
/* regex_t link chain */
|
||||
struct re_pattern_buffer* chain; /* escape compile-conflict */
|
||||
} OnigRegexType;
|
||||
|
||||
typedef OnigRegexType* OnigRegex;
|
||||
|
||||
#ifndef ONIG_ESCAPE_REGEX_T_COLLISION
|
||||
typedef OnigRegexType regex_t;
|
||||
#endif
|
||||
|
||||
|
||||
typedef struct {
|
||||
int num_of_elements;
|
||||
OnigEncoding pattern_enc;
|
||||
OnigEncoding target_enc;
|
||||
OnigSyntaxType* syntax;
|
||||
OnigOptionType option;
|
||||
OnigCaseFoldType case_fold_flag;
|
||||
} OnigCompileInfo;
|
||||
|
||||
/* Oniguruma Native API */
|
||||
ONIG_EXTERN
|
||||
int onig_init P_((void));
|
||||
ONIG_EXTERN
|
||||
int onig_error_code_to_str PV_((OnigUChar* s, int err_code, ...));
|
||||
ONIG_EXTERN
|
||||
void onig_set_warn_func P_((OnigWarnFunc f));
|
||||
ONIG_EXTERN
|
||||
void onig_set_verb_warn_func P_((OnigWarnFunc f));
|
||||
ONIG_EXTERN
|
||||
int onig_new P_((OnigRegex*, const OnigUChar* pattern, const OnigUChar* pattern_end, OnigOptionType option, OnigEncoding enc, OnigSyntaxType* syntax, OnigErrorInfo* einfo));
|
||||
ONIG_EXTERN
|
||||
int onig_reg_init P_((regex_t* reg, OnigOptionType option, OnigCaseFoldType case_fold_flag, OnigEncoding enc, OnigSyntaxType* syntax));
|
||||
int onig_new_without_alloc P_((OnigRegex, const OnigUChar* pattern, const OnigUChar* pattern_end, OnigOptionType option, OnigEncoding enc, OnigSyntaxType* syntax, OnigErrorInfo* einfo));
|
||||
ONIG_EXTERN
|
||||
int onig_new_deluxe P_((OnigRegex* reg, const OnigUChar* pattern, const OnigUChar* pattern_end, OnigCompileInfo* ci, OnigErrorInfo* einfo));
|
||||
ONIG_EXTERN
|
||||
void onig_free P_((OnigRegex));
|
||||
ONIG_EXTERN
|
||||
void onig_free_body P_((OnigRegex));
|
||||
ONIG_EXTERN
|
||||
int onig_recompile P_((OnigRegex, const OnigUChar* pattern, const OnigUChar* pattern_end, OnigOptionType option, OnigEncoding enc, OnigSyntaxType* syntax, OnigErrorInfo* einfo));
|
||||
ONIG_EXTERN
|
||||
int onig_recompile_deluxe P_((OnigRegex reg, const OnigUChar* pattern, const OnigUChar* pattern_end, OnigCompileInfo* ci, OnigErrorInfo* einfo));
|
||||
ONIG_EXTERN
|
||||
int onig_search P_((OnigRegex, const OnigUChar* str, const OnigUChar* end, const OnigUChar* start, const OnigUChar* range, OnigRegion* region, OnigOptionType option));
|
||||
ONIG_EXTERN
|
||||
int onig_match P_((OnigRegex, const OnigUChar* str, const OnigUChar* end, const OnigUChar* at, OnigRegion* region, OnigOptionType option));
|
||||
ONIG_EXTERN
|
||||
OnigRegion* onig_region_new P_((void));
|
||||
ONIG_EXTERN
|
||||
void onig_region_init P_((OnigRegion* region));
|
||||
ONIG_EXTERN
|
||||
void onig_region_free P_((OnigRegion* region, int free_self));
|
||||
ONIG_EXTERN
|
||||
void onig_region_copy P_((OnigRegion* to, OnigRegion* from));
|
||||
ONIG_EXTERN
|
||||
void onig_region_clear P_((OnigRegion* region));
|
||||
ONIG_EXTERN
|
||||
int onig_region_resize P_((OnigRegion* region, int n));
|
||||
ONIG_EXTERN
|
||||
int onig_region_set P_((OnigRegion* region, int at, int beg, int end));
|
||||
ONIG_EXTERN
|
||||
int onig_name_to_group_numbers P_((OnigRegex reg, const OnigUChar* name, const OnigUChar* name_end, int** nums));
|
||||
ONIG_EXTERN
|
||||
int onig_name_to_backref_number P_((OnigRegex reg, const OnigUChar* name, const OnigUChar* name_end, OnigRegion *region));
|
||||
ONIG_EXTERN
|
||||
int onig_foreach_name P_((OnigRegex reg, int (*func)(const OnigUChar*, const OnigUChar*,int,int*,OnigRegex,void*), void* arg));
|
||||
ONIG_EXTERN
|
||||
int onig_number_of_names P_((OnigRegex reg));
|
||||
ONIG_EXTERN
|
||||
int onig_number_of_captures P_((OnigRegex reg));
|
||||
ONIG_EXTERN
|
||||
int onig_number_of_capture_histories P_((OnigRegex reg));
|
||||
ONIG_EXTERN
|
||||
OnigCaptureTreeNode* onig_get_capture_tree P_((OnigRegion* region));
|
||||
ONIG_EXTERN
|
||||
int onig_capture_tree_traverse P_((OnigRegion* region, int at, int(*callback_func)(int,int,int,int,int,void*), void* arg));
|
||||
ONIG_EXTERN
|
||||
int onig_noname_group_capture_is_active P_((OnigRegex reg));
|
||||
ONIG_EXTERN
|
||||
OnigEncoding onig_get_encoding P_((OnigRegex reg));
|
||||
ONIG_EXTERN
|
||||
OnigOptionType onig_get_options P_((OnigRegex reg));
|
||||
ONIG_EXTERN
|
||||
OnigCaseFoldType onig_get_case_fold_flag P_((OnigRegex reg));
|
||||
ONIG_EXTERN
|
||||
OnigSyntaxType* onig_get_syntax P_((OnigRegex reg));
|
||||
ONIG_EXTERN
|
||||
int onig_set_default_syntax P_((OnigSyntaxType* syntax));
|
||||
ONIG_EXTERN
|
||||
void onig_copy_syntax P_((OnigSyntaxType* to, OnigSyntaxType* from));
|
||||
ONIG_EXTERN
|
||||
unsigned int onig_get_syntax_op P_((OnigSyntaxType* syntax));
|
||||
ONIG_EXTERN
|
||||
unsigned int onig_get_syntax_op2 P_((OnigSyntaxType* syntax));
|
||||
ONIG_EXTERN
|
||||
unsigned int onig_get_syntax_behavior P_((OnigSyntaxType* syntax));
|
||||
ONIG_EXTERN
|
||||
OnigOptionType onig_get_syntax_options P_((OnigSyntaxType* syntax));
|
||||
ONIG_EXTERN
|
||||
void onig_set_syntax_op P_((OnigSyntaxType* syntax, unsigned int op));
|
||||
ONIG_EXTERN
|
||||
void onig_set_syntax_op2 P_((OnigSyntaxType* syntax, unsigned int op2));
|
||||
ONIG_EXTERN
|
||||
void onig_set_syntax_behavior P_((OnigSyntaxType* syntax, unsigned int behavior));
|
||||
ONIG_EXTERN
|
||||
void onig_set_syntax_options P_((OnigSyntaxType* syntax, OnigOptionType options));
|
||||
ONIG_EXTERN
|
||||
int onig_set_meta_char P_((OnigSyntaxType* syntax, unsigned int what, OnigCodePoint code));
|
||||
ONIG_EXTERN
|
||||
void onig_copy_encoding P_((OnigEncoding to, OnigEncoding from));
|
||||
ONIG_EXTERN
|
||||
OnigCaseFoldType onig_get_default_case_fold_flag P_((void));
|
||||
ONIG_EXTERN
|
||||
int onig_set_default_case_fold_flag P_((OnigCaseFoldType case_fold_flag));
|
||||
ONIG_EXTERN
|
||||
unsigned int onig_get_match_stack_limit_size P_((void));
|
||||
ONIG_EXTERN
|
||||
int onig_set_match_stack_limit_size P_((unsigned int size));
|
||||
ONIG_EXTERN
|
||||
int onig_end P_((void));
|
||||
ONIG_EXTERN
|
||||
const char* onig_version P_((void));
|
||||
ONIG_EXTERN
|
||||
const char* onig_copyright P_((void));
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* ONIGURUMA_H */
|
||||
Binary file not shown.
@@ -1,38 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>BuildMachineOSBuild</key>
|
||||
<string>11E2620</string>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
<string>English</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>CocoaOniguruma</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>net.limechat.CocoaOniguruma</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>CocoaOniguruma</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>FMWK</string>
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1.0</string>
|
||||
<key>DTCompiler</key>
|
||||
<string></string>
|
||||
<key>DTPlatformBuild</key>
|
||||
<string>4E3002</string>
|
||||
<key>DTPlatformVersion</key>
|
||||
<string>GM</string>
|
||||
<key>DTSDKBuild</key>
|
||||
<string>11E2620</string>
|
||||
<key>DTSDKName</key>
|
||||
<string></string>
|
||||
<key>DTXcode</key>
|
||||
<string>0433</string>
|
||||
<key>DTXcodeBuild</key>
|
||||
<string>4E3002</string>
|
||||
</dict>
|
||||
</plist>
|
||||
Binary file not shown.
@@ -1,91 +0,0 @@
|
||||
// CocoaOniguruma is copyrighted free software by Satoshi Nakagawa <psychs AT limechat DOT net>.
|
||||
// You can redistribute it and/or modify it under the new BSD license.
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "oniguruma.h"
|
||||
#import "OnigRegexpUtility.h"
|
||||
|
||||
|
||||
@class OnigResult;
|
||||
|
||||
typedef enum {
|
||||
OnigOptionNone = ONIG_OPTION_NONE,
|
||||
OnigOptionIgnorecase = ONIG_OPTION_IGNORECASE,
|
||||
OnigOptionExtend = ONIG_OPTION_EXTEND,
|
||||
OnigOptionMultiline = ONIG_OPTION_MULTILINE,
|
||||
OnigOptionSingleline = ONIG_OPTION_SINGLELINE,
|
||||
OnigOptionFindLongest = ONIG_OPTION_FIND_LONGEST,
|
||||
OnigOptionFindNotEmpty = ONIG_OPTION_FIND_NOT_EMPTY,
|
||||
OnigOptionNegateSingleLine = ONIG_OPTION_NEGATE_SINGLELINE,
|
||||
OnigOptionDontCaptureGroup = ONIG_OPTION_DONT_CAPTURE_GROUP,
|
||||
OnigOptionCaptureGroup = ONIG_OPTION_CAPTURE_GROUP,
|
||||
|
||||
/* options (search time) */
|
||||
OnigOptionNotbol = ONIG_OPTION_NOTBOL,
|
||||
OnigOptionNoteol = ONIG_OPTION_NOTEOL,
|
||||
OnigOptionPosixRegion = ONIG_OPTION_POSIX_REGION,
|
||||
OnigOptionMaxbit = ONIG_OPTION_MAXBIT
|
||||
} OnigOption;
|
||||
|
||||
@interface OnigRegexp : NSObject
|
||||
{
|
||||
regex_t* _entity;
|
||||
NSString* _expression;
|
||||
}
|
||||
|
||||
+ (OnigRegexp*)compile:(NSString*)expression;
|
||||
+ (OnigRegexp*)compile:(NSString*)expression error:(NSError **)error;
|
||||
+ (OnigRegexp*)compileIgnorecase:(NSString*)expression;
|
||||
+ (OnigRegexp*)compileIgnorecase:(NSString*)expression error:(NSError **)error;
|
||||
+ (OnigRegexp*)compile:(NSString*)expression ignorecase:(BOOL)ignorecase multiline:(BOOL)multiline;
|
||||
+ (OnigRegexp*)compile:(NSString*)expression ignorecase:(BOOL)ignorecase multiline:(BOOL)multiline error:(NSError **)error;
|
||||
+ (OnigRegexp*)compile:(NSString*)expression ignorecase:(BOOL)ignorecase multiline:(BOOL)multiline extended:(BOOL)extended;
|
||||
+ (OnigRegexp*)compile:(NSString*)expression ignorecase:(BOOL)ignorecase multiline:(BOOL)multiline extended:(BOOL)extended error:(NSError **)error;
|
||||
+ (OnigRegexp*)compile:(NSString*)expression options:(OnigOption)options;
|
||||
+ (OnigRegexp*)compile:(NSString*)expression options:(OnigOption)options error:(NSError **)error;
|
||||
|
||||
- (OnigResult*)search:(NSString*)target;
|
||||
- (OnigResult*)search:(NSString*)target start:(int)start;
|
||||
- (OnigResult*)search:(NSString*)target start:(int)start end:(int)end;
|
||||
- (OnigResult*)search:(NSString*)target range:(NSRange)range;
|
||||
|
||||
- (OnigResult*)match:(NSString*)target;
|
||||
- (OnigResult*)match:(NSString*)target start:(int)start;
|
||||
|
||||
- (NSUInteger)captureCount;
|
||||
- (NSString*)expression;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@interface OnigResult : NSObject
|
||||
{
|
||||
OnigRegexp* _expression;
|
||||
OnigRegion* _region;
|
||||
NSString* _target;
|
||||
NSMutableArray* _captureNames;
|
||||
}
|
||||
|
||||
- (NSString*)target;
|
||||
|
||||
- (int)count;
|
||||
- (NSString*)stringAt:(int)index;
|
||||
- (NSArray*)strings;
|
||||
- (NSRange)rangeAt:(int)index;
|
||||
- (int)locationAt:(int)index;
|
||||
- (int)lengthAt:(int)index;
|
||||
|
||||
- (NSString*)body;
|
||||
- (NSRange)bodyRange;
|
||||
|
||||
- (NSString*)preMatch;
|
||||
- (NSString*)postMatch;
|
||||
|
||||
// named capture support
|
||||
- (NSArray*)captureNames;
|
||||
- (int)indexForName:(NSString*)name;
|
||||
- (NSIndexSet*)indexesForName:(NSString*)name;
|
||||
- (NSString*)stringForName:(NSString*)name;
|
||||
- (NSArray*)stringsForName:(NSString*)name;
|
||||
|
||||
@end
|
||||
@@ -1,57 +0,0 @@
|
||||
// CocoaOniguruma is copyrighted free software by Satoshi Nakagawa <psychs AT limechat DOT net>.
|
||||
// You can redistribute it and/or modify it under the new BSD license.
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "oniguruma.h"
|
||||
#import "OnigRegexp.h"
|
||||
|
||||
|
||||
@class OnigRegexp;
|
||||
@class OnigResult;
|
||||
|
||||
|
||||
@interface NSString (OnigRegexpUtility)
|
||||
|
||||
// pattern is OnigRegexp or NSString
|
||||
|
||||
- (NSRange)rangeOfRegexp:(id)pattern;
|
||||
|
||||
// based on ruby's split
|
||||
|
||||
- (NSArray*)split;
|
||||
- (NSArray*)splitByRegexp:(id)pattern;
|
||||
- (NSArray*)splitByRegexp:(id)pattern limit:(int)limit;
|
||||
|
||||
// based on ruby's gsub
|
||||
|
||||
- (NSString*)replaceByRegexp:(id)pattern with:(NSString*)string;
|
||||
- (NSString*)replaceAllByRegexp:(id)pattern with:(NSString*)string;
|
||||
|
||||
- (NSString*)replaceByRegexp:(id)pattern withCallback:(id)object selector:(SEL)sel;
|
||||
- (NSString*)replaceAllByRegexp:(id)pattern withCallback:(id)object selector:(SEL)sel;
|
||||
|
||||
#if defined(NS_BLOCKS_AVAILABLE)
|
||||
- (NSString*)replaceByRegexp:(id)pattern withBlock:(NSString* (^)(OnigResult*))block;
|
||||
- (NSString*)replaceAllByRegexp:(id)pattern withBlock:(NSString* (^)(OnigResult*))block;
|
||||
#endif
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@interface NSMutableString (OnigRegexpUtility)
|
||||
|
||||
// pattern is OnigRegexp or NSString
|
||||
|
||||
// based on ruby's gsub
|
||||
|
||||
- (NSMutableString*)replaceByRegexp:(id)pattern with:(NSString*)string;
|
||||
- (NSMutableString*)replaceAllByRegexp:(id)pattern with:(NSString*)string;
|
||||
|
||||
- (NSMutableString*)replaceByRegexp:(id)pattern withCallback:(id)object selector:(SEL)sel;
|
||||
- (NSMutableString*)replaceAllByRegexp:(id)pattern withCallback:(id)object selector:(SEL)sel;
|
||||
|
||||
#if defined(NS_BLOCKS_AVAILABLE)
|
||||
- (NSMutableString*)replaceByRegexp:(id)pattern withBlock:(NSString* (^)(OnigResult*))block;
|
||||
- (NSMutableString*)replaceAllByRegexp:(id)pattern withBlock:(NSString* (^)(OnigResult*))block;
|
||||
#endif
|
||||
@end
|
||||
@@ -1,770 +0,0 @@
|
||||
#ifndef ONIGURUMA_H
|
||||
#define ONIGURUMA_H
|
||||
/**********************************************************************
|
||||
oniguruma.h - Oniguruma (regular expression library)
|
||||
**********************************************************************/
|
||||
/*-
|
||||
* Copyright (c) 2002-2009 K.Kosako <sndgk393 AT ybb DOT ne DOT jp>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define ONIGURUMA
|
||||
#define ONIGURUMA_VERSION_MAJOR 5
|
||||
#define ONIGURUMA_VERSION_MINOR 9
|
||||
#define ONIGURUMA_VERSION_TEENY 2
|
||||
|
||||
#ifdef __cplusplus
|
||||
# ifndef HAVE_PROTOTYPES
|
||||
# define HAVE_PROTOTYPES 1
|
||||
# endif
|
||||
# ifndef HAVE_STDARG_PROTOTYPES
|
||||
# define HAVE_STDARG_PROTOTYPES 1
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* escape Mac OS X/Xcode 2.4/gcc 4.0.1 problem */
|
||||
#if defined(__APPLE__) && defined(__GNUC__) && __GNUC__ >= 4
|
||||
# ifndef HAVE_STDARG_PROTOTYPES
|
||||
# define HAVE_STDARG_PROTOTYPES 1
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_STDARG_H
|
||||
# ifndef HAVE_STDARG_PROTOTYPES
|
||||
# define HAVE_STDARG_PROTOTYPES 1
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef P_
|
||||
#if defined(__STDC__) || defined(_WIN32)
|
||||
# define P_(args) args
|
||||
#else
|
||||
# define P_(args) ()
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef PV_
|
||||
#ifdef HAVE_STDARG_PROTOTYPES
|
||||
# define PV_(args) args
|
||||
#else
|
||||
# define PV_(args) ()
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef ONIG_EXTERN
|
||||
#if defined(_WIN32) && !defined(__GNUC__)
|
||||
#if defined(EXPORT) || defined(RUBY_EXPORT)
|
||||
#define ONIG_EXTERN extern __declspec(dllexport)
|
||||
#else
|
||||
#define ONIG_EXTERN extern __declspec(dllimport)
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef ONIG_EXTERN
|
||||
#define ONIG_EXTERN extern
|
||||
#endif
|
||||
|
||||
/* PART: character encoding */
|
||||
|
||||
#ifndef ONIG_ESCAPE_UCHAR_COLLISION
|
||||
#define UChar OnigUChar
|
||||
#endif
|
||||
|
||||
typedef unsigned char OnigUChar;
|
||||
typedef unsigned long OnigCodePoint;
|
||||
typedef unsigned int OnigCtype;
|
||||
typedef unsigned int OnigDistance;
|
||||
|
||||
#define ONIG_INFINITE_DISTANCE ~((OnigDistance )0)
|
||||
|
||||
typedef unsigned int OnigCaseFoldType; /* case fold flag */
|
||||
|
||||
ONIG_EXTERN OnigCaseFoldType OnigDefaultCaseFoldFlag;
|
||||
|
||||
/* #define ONIGENC_CASE_FOLD_HIRAGANA_KATAKANA (1<<1) */
|
||||
/* #define ONIGENC_CASE_FOLD_KATAKANA_WIDTH (1<<2) */
|
||||
#define ONIGENC_CASE_FOLD_TURKISH_AZERI (1<<20)
|
||||
#define INTERNAL_ONIGENC_CASE_FOLD_MULTI_CHAR (1<<30)
|
||||
|
||||
#define ONIGENC_CASE_FOLD_MIN INTERNAL_ONIGENC_CASE_FOLD_MULTI_CHAR
|
||||
#define ONIGENC_CASE_FOLD_DEFAULT OnigDefaultCaseFoldFlag
|
||||
|
||||
|
||||
#define ONIGENC_MAX_COMP_CASE_FOLD_CODE_LEN 3
|
||||
#define ONIGENC_GET_CASE_FOLD_CODES_MAX_NUM 13
|
||||
/* 13 => Unicode:0x1ffc */
|
||||
|
||||
/* code range */
|
||||
#define ONIGENC_CODE_RANGE_NUM(range) ((int )range[0])
|
||||
#define ONIGENC_CODE_RANGE_FROM(range,i) range[((i)*2) + 1]
|
||||
#define ONIGENC_CODE_RANGE_TO(range,i) range[((i)*2) + 2]
|
||||
|
||||
typedef struct {
|
||||
int byte_len; /* argument(original) character(s) byte length */
|
||||
int code_len; /* number of code */
|
||||
OnigCodePoint code[ONIGENC_MAX_COMP_CASE_FOLD_CODE_LEN];
|
||||
} OnigCaseFoldCodeItem;
|
||||
|
||||
typedef struct {
|
||||
OnigCodePoint esc;
|
||||
OnigCodePoint anychar;
|
||||
OnigCodePoint anytime;
|
||||
OnigCodePoint zero_or_one_time;
|
||||
OnigCodePoint one_or_more_time;
|
||||
OnigCodePoint anychar_anytime;
|
||||
} OnigMetaCharTableType;
|
||||
|
||||
typedef int (*OnigApplyAllCaseFoldFunc)(OnigCodePoint from, OnigCodePoint* to, int to_len, void* arg);
|
||||
|
||||
typedef struct OnigEncodingTypeST {
|
||||
int (*mbc_enc_len)(const OnigUChar* p);
|
||||
const char* name;
|
||||
int max_enc_len;
|
||||
int min_enc_len;
|
||||
int (*is_mbc_newline)(const OnigUChar* p, const OnigUChar* end);
|
||||
OnigCodePoint (*mbc_to_code)(const OnigUChar* p, const OnigUChar* end);
|
||||
int (*code_to_mbclen)(OnigCodePoint code);
|
||||
int (*code_to_mbc)(OnigCodePoint code, OnigUChar *buf);
|
||||
int (*mbc_case_fold)(OnigCaseFoldType flag, const OnigUChar** pp, const OnigUChar* end, OnigUChar* to);
|
||||
int (*apply_all_case_fold)(OnigCaseFoldType flag, OnigApplyAllCaseFoldFunc f, void* arg);
|
||||
int (*get_case_fold_codes_by_str)(OnigCaseFoldType flag, const OnigUChar* p, const OnigUChar* end, OnigCaseFoldCodeItem acs[]);
|
||||
int (*property_name_to_ctype)(struct OnigEncodingTypeST* enc, OnigUChar* p, OnigUChar* end);
|
||||
int (*is_code_ctype)(OnigCodePoint code, OnigCtype ctype);
|
||||
int (*get_ctype_code_range)(OnigCtype ctype, OnigCodePoint* sb_out, const OnigCodePoint* ranges[]);
|
||||
OnigUChar* (*left_adjust_char_head)(const OnigUChar* start, const OnigUChar* p);
|
||||
int (*is_allowed_reverse_match)(const OnigUChar* p, const OnigUChar* end);
|
||||
} OnigEncodingType;
|
||||
|
||||
typedef OnigEncodingType* OnigEncoding;
|
||||
|
||||
ONIG_EXTERN OnigEncodingType OnigEncodingASCII;
|
||||
ONIG_EXTERN OnigEncodingType OnigEncodingUTF16_BE;
|
||||
ONIG_EXTERN OnigEncodingType OnigEncodingUTF16_LE;
|
||||
ONIG_EXTERN OnigEncodingType OnigEncodingUTF32_BE;
|
||||
ONIG_EXTERN OnigEncodingType OnigEncodingUTF32_LE;
|
||||
|
||||
#define ONIG_ENCODING_ASCII (&OnigEncodingASCII)
|
||||
#define ONIG_ENCODING_UTF16_BE (&OnigEncodingUTF16_BE)
|
||||
#define ONIG_ENCODING_UTF16_LE (&OnigEncodingUTF16_LE)
|
||||
#define ONIG_ENCODING_UTF32_BE (&OnigEncodingUTF32_BE)
|
||||
#define ONIG_ENCODING_UTF32_LE (&OnigEncodingUTF32_LE)
|
||||
|
||||
#define ONIG_ENCODING_UNDEF ((OnigEncoding )0)
|
||||
|
||||
|
||||
/* work size */
|
||||
#define ONIGENC_CODE_TO_MBC_MAXLEN 7
|
||||
#define ONIGENC_MBC_CASE_FOLD_MAXLEN 18
|
||||
/* 18: 6(max-byte) * 3(case-fold chars) */
|
||||
|
||||
/* character types */
|
||||
#define ONIGENC_CTYPE_NEWLINE 0
|
||||
#define ONIGENC_CTYPE_ALPHA 1
|
||||
#define ONIGENC_CTYPE_BLANK 2
|
||||
#define ONIGENC_CTYPE_CNTRL 3
|
||||
#define ONIGENC_CTYPE_DIGIT 4
|
||||
#define ONIGENC_CTYPE_GRAPH 5
|
||||
#define ONIGENC_CTYPE_LOWER 6
|
||||
#define ONIGENC_CTYPE_PRINT 7
|
||||
#define ONIGENC_CTYPE_PUNCT 8
|
||||
#define ONIGENC_CTYPE_SPACE 9
|
||||
#define ONIGENC_CTYPE_UPPER 10
|
||||
#define ONIGENC_CTYPE_XDIGIT 11
|
||||
#define ONIGENC_CTYPE_WORD 12
|
||||
#define ONIGENC_CTYPE_ALNUM 13 /* alpha || digit */
|
||||
#define ONIGENC_CTYPE_ASCII 14
|
||||
#define ONIGENC_MAX_STD_CTYPE ONIGENC_CTYPE_ASCII
|
||||
|
||||
|
||||
#define onig_enc_len(enc,p,end) ONIGENC_MBC_ENC_LEN(enc,p)
|
||||
|
||||
#define ONIGENC_IS_UNDEF(enc) ((enc) == ONIG_ENCODING_UNDEF)
|
||||
#define ONIGENC_IS_SINGLEBYTE(enc) (ONIGENC_MBC_MAXLEN(enc) == 1)
|
||||
#define ONIGENC_IS_MBC_HEAD(enc,p) (ONIGENC_MBC_ENC_LEN(enc,p) != 1)
|
||||
#define ONIGENC_IS_MBC_ASCII(p) (*(p) < 128)
|
||||
#define ONIGENC_IS_CODE_ASCII(code) ((code) < 128)
|
||||
#define ONIGENC_IS_MBC_WORD(enc,s,end) \
|
||||
ONIGENC_IS_CODE_WORD(enc,ONIGENC_MBC_TO_CODE(enc,s,end))
|
||||
|
||||
|
||||
#define ONIGENC_NAME(enc) ((enc)->name)
|
||||
|
||||
#define ONIGENC_MBC_CASE_FOLD(enc,flag,pp,end,buf) \
|
||||
(enc)->mbc_case_fold(flag,(const OnigUChar** )pp,end,buf)
|
||||
#define ONIGENC_IS_ALLOWED_REVERSE_MATCH(enc,s,end) \
|
||||
(enc)->is_allowed_reverse_match(s,end)
|
||||
#define ONIGENC_LEFT_ADJUST_CHAR_HEAD(enc,start,s) \
|
||||
(enc)->left_adjust_char_head(start, s)
|
||||
#define ONIGENC_APPLY_ALL_CASE_FOLD(enc,case_fold_flag,f,arg) \
|
||||
(enc)->apply_all_case_fold(case_fold_flag,f,arg)
|
||||
#define ONIGENC_GET_CASE_FOLD_CODES_BY_STR(enc,case_fold_flag,p,end,acs) \
|
||||
(enc)->get_case_fold_codes_by_str(case_fold_flag,p,end,acs)
|
||||
#define ONIGENC_STEP_BACK(enc,start,s,n) \
|
||||
onigenc_step_back((enc),(start),(s),(n))
|
||||
|
||||
#define ONIGENC_MBC_ENC_LEN(enc,p) (enc)->mbc_enc_len(p)
|
||||
#define ONIGENC_MBC_MAXLEN(enc) ((enc)->max_enc_len)
|
||||
#define ONIGENC_MBC_MAXLEN_DIST(enc) ONIGENC_MBC_MAXLEN(enc)
|
||||
#define ONIGENC_MBC_MINLEN(enc) ((enc)->min_enc_len)
|
||||
#define ONIGENC_IS_MBC_NEWLINE(enc,p,end) (enc)->is_mbc_newline((p),(end))
|
||||
#define ONIGENC_MBC_TO_CODE(enc,p,end) (enc)->mbc_to_code((p),(end))
|
||||
#define ONIGENC_CODE_TO_MBCLEN(enc,code) (enc)->code_to_mbclen(code)
|
||||
#define ONIGENC_CODE_TO_MBC(enc,code,buf) (enc)->code_to_mbc(code,buf)
|
||||
#define ONIGENC_PROPERTY_NAME_TO_CTYPE(enc,p,end) \
|
||||
(enc)->property_name_to_ctype(enc,p,end)
|
||||
|
||||
#define ONIGENC_IS_CODE_CTYPE(enc,code,ctype) (enc)->is_code_ctype(code,ctype)
|
||||
|
||||
#define ONIGENC_IS_CODE_NEWLINE(enc,code) \
|
||||
ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_NEWLINE)
|
||||
#define ONIGENC_IS_CODE_GRAPH(enc,code) \
|
||||
ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_GRAPH)
|
||||
#define ONIGENC_IS_CODE_PRINT(enc,code) \
|
||||
ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_PRINT)
|
||||
#define ONIGENC_IS_CODE_ALNUM(enc,code) \
|
||||
ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_ALNUM)
|
||||
#define ONIGENC_IS_CODE_ALPHA(enc,code) \
|
||||
ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_ALPHA)
|
||||
#define ONIGENC_IS_CODE_LOWER(enc,code) \
|
||||
ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_LOWER)
|
||||
#define ONIGENC_IS_CODE_UPPER(enc,code) \
|
||||
ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_UPPER)
|
||||
#define ONIGENC_IS_CODE_CNTRL(enc,code) \
|
||||
ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_CNTRL)
|
||||
#define ONIGENC_IS_CODE_PUNCT(enc,code) \
|
||||
ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_PUNCT)
|
||||
#define ONIGENC_IS_CODE_SPACE(enc,code) \
|
||||
ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_SPACE)
|
||||
#define ONIGENC_IS_CODE_BLANK(enc,code) \
|
||||
ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_BLANK)
|
||||
#define ONIGENC_IS_CODE_DIGIT(enc,code) \
|
||||
ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_DIGIT)
|
||||
#define ONIGENC_IS_CODE_XDIGIT(enc,code) \
|
||||
ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_XDIGIT)
|
||||
#define ONIGENC_IS_CODE_WORD(enc,code) \
|
||||
ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_WORD)
|
||||
|
||||
#define ONIGENC_GET_CTYPE_CODE_RANGE(enc,ctype,sbout,ranges) \
|
||||
(enc)->get_ctype_code_range(ctype,sbout,ranges)
|
||||
|
||||
ONIG_EXTERN
|
||||
OnigUChar* onigenc_step_back P_((OnigEncoding enc, const OnigUChar* start, const OnigUChar* s, int n));
|
||||
|
||||
|
||||
/* encoding API */
|
||||
ONIG_EXTERN
|
||||
int onigenc_init P_((void));
|
||||
ONIG_EXTERN
|
||||
int onigenc_set_default_encoding P_((OnigEncoding enc));
|
||||
ONIG_EXTERN
|
||||
OnigEncoding onigenc_get_default_encoding P_((void));
|
||||
ONIG_EXTERN
|
||||
void onigenc_set_default_caseconv_table P_((const OnigUChar* table));
|
||||
ONIG_EXTERN
|
||||
OnigUChar* onigenc_get_right_adjust_char_head_with_prev P_((OnigEncoding enc, const OnigUChar* start, const OnigUChar* s, const OnigUChar** prev));
|
||||
ONIG_EXTERN
|
||||
OnigUChar* onigenc_get_prev_char_head P_((OnigEncoding enc, const OnigUChar* start, const OnigUChar* s));
|
||||
ONIG_EXTERN
|
||||
OnigUChar* onigenc_get_left_adjust_char_head P_((OnigEncoding enc, const OnigUChar* start, const OnigUChar* s));
|
||||
ONIG_EXTERN
|
||||
OnigUChar* onigenc_get_right_adjust_char_head P_((OnigEncoding enc, const OnigUChar* start, const OnigUChar* s));
|
||||
ONIG_EXTERN
|
||||
int onigenc_strlen P_((OnigEncoding enc, const OnigUChar* p, const OnigUChar* end));
|
||||
ONIG_EXTERN
|
||||
int onigenc_strlen_null P_((OnigEncoding enc, const OnigUChar* p));
|
||||
ONIG_EXTERN
|
||||
int onigenc_str_bytelen_null P_((OnigEncoding enc, const OnigUChar* p));
|
||||
|
||||
|
||||
|
||||
/* PART: regular expression */
|
||||
|
||||
/* config parameters */
|
||||
#define ONIG_NREGION 10
|
||||
#define ONIG_MAX_BACKREF_NUM 1000
|
||||
#define ONIG_MAX_REPEAT_NUM 100000
|
||||
#define ONIG_MAX_MULTI_BYTE_RANGES_NUM 10000
|
||||
/* constants */
|
||||
#define ONIG_MAX_ERROR_MESSAGE_LEN 90
|
||||
|
||||
typedef unsigned int OnigOptionType;
|
||||
|
||||
#define ONIG_OPTION_DEFAULT ONIG_OPTION_NONE
|
||||
|
||||
/* options */
|
||||
#define ONIG_OPTION_NONE 0U
|
||||
#define ONIG_OPTION_IGNORECASE 1U
|
||||
#define ONIG_OPTION_EXTEND (ONIG_OPTION_IGNORECASE << 1)
|
||||
#define ONIG_OPTION_MULTILINE (ONIG_OPTION_EXTEND << 1)
|
||||
#define ONIG_OPTION_SINGLELINE (ONIG_OPTION_MULTILINE << 1)
|
||||
#define ONIG_OPTION_FIND_LONGEST (ONIG_OPTION_SINGLELINE << 1)
|
||||
#define ONIG_OPTION_FIND_NOT_EMPTY (ONIG_OPTION_FIND_LONGEST << 1)
|
||||
#define ONIG_OPTION_NEGATE_SINGLELINE (ONIG_OPTION_FIND_NOT_EMPTY << 1)
|
||||
#define ONIG_OPTION_DONT_CAPTURE_GROUP (ONIG_OPTION_NEGATE_SINGLELINE << 1)
|
||||
#define ONIG_OPTION_CAPTURE_GROUP (ONIG_OPTION_DONT_CAPTURE_GROUP << 1)
|
||||
/* options (search time) */
|
||||
#define ONIG_OPTION_NOTBOL (ONIG_OPTION_CAPTURE_GROUP << 1)
|
||||
#define ONIG_OPTION_NOTEOL (ONIG_OPTION_NOTBOL << 1)
|
||||
#define ONIG_OPTION_POSIX_REGION (ONIG_OPTION_NOTEOL << 1)
|
||||
#define ONIG_OPTION_MAXBIT ONIG_OPTION_POSIX_REGION /* limit */
|
||||
|
||||
#define ONIG_OPTION_ON(options,regopt) ((options) |= (regopt))
|
||||
#define ONIG_OPTION_OFF(options,regopt) ((options) &= ~(regopt))
|
||||
#define ONIG_IS_OPTION_ON(options,option) ((options) & (option))
|
||||
|
||||
/* syntax */
|
||||
typedef struct {
|
||||
unsigned int op;
|
||||
unsigned int op2;
|
||||
unsigned int behavior;
|
||||
OnigOptionType options; /* default option */
|
||||
OnigMetaCharTableType meta_char_table;
|
||||
} OnigSyntaxType;
|
||||
|
||||
ONIG_EXTERN OnigSyntaxType OnigSyntaxASIS;
|
||||
ONIG_EXTERN OnigSyntaxType OnigSyntaxPosixBasic;
|
||||
ONIG_EXTERN OnigSyntaxType OnigSyntaxPosixExtended;
|
||||
ONIG_EXTERN OnigSyntaxType OnigSyntaxEmacs;
|
||||
ONIG_EXTERN OnigSyntaxType OnigSyntaxGrep;
|
||||
ONIG_EXTERN OnigSyntaxType OnigSyntaxGnuRegex;
|
||||
ONIG_EXTERN OnigSyntaxType OnigSyntaxJava;
|
||||
ONIG_EXTERN OnigSyntaxType OnigSyntaxPerl;
|
||||
ONIG_EXTERN OnigSyntaxType OnigSyntaxPerl_NG;
|
||||
ONIG_EXTERN OnigSyntaxType OnigSyntaxRuby;
|
||||
|
||||
/* predefined syntaxes (see regsyntax.c) */
|
||||
#define ONIG_SYNTAX_ASIS (&OnigSyntaxASIS)
|
||||
#define ONIG_SYNTAX_POSIX_BASIC (&OnigSyntaxPosixBasic)
|
||||
#define ONIG_SYNTAX_POSIX_EXTENDED (&OnigSyntaxPosixExtended)
|
||||
#define ONIG_SYNTAX_EMACS (&OnigSyntaxEmacs)
|
||||
#define ONIG_SYNTAX_GREP (&OnigSyntaxGrep)
|
||||
#define ONIG_SYNTAX_GNU_REGEX (&OnigSyntaxGnuRegex)
|
||||
#define ONIG_SYNTAX_JAVA (&OnigSyntaxJava)
|
||||
#define ONIG_SYNTAX_PERL (&OnigSyntaxPerl)
|
||||
#define ONIG_SYNTAX_PERL_NG (&OnigSyntaxPerl_NG)
|
||||
#define ONIG_SYNTAX_RUBY (&OnigSyntaxRuby)
|
||||
|
||||
/* default syntax */
|
||||
ONIG_EXTERN OnigSyntaxType* OnigDefaultSyntax;
|
||||
#define ONIG_SYNTAX_DEFAULT OnigDefaultSyntax
|
||||
|
||||
/* syntax (operators) */
|
||||
#define ONIG_SYN_OP_VARIABLE_META_CHARACTERS (1U<<0)
|
||||
#define ONIG_SYN_OP_DOT_ANYCHAR (1U<<1) /* . */
|
||||
#define ONIG_SYN_OP_ASTERISK_ZERO_INF (1U<<2) /* * */
|
||||
#define ONIG_SYN_OP_ESC_ASTERISK_ZERO_INF (1U<<3)
|
||||
#define ONIG_SYN_OP_PLUS_ONE_INF (1U<<4) /* + */
|
||||
#define ONIG_SYN_OP_ESC_PLUS_ONE_INF (1U<<5)
|
||||
#define ONIG_SYN_OP_QMARK_ZERO_ONE (1U<<6) /* ? */
|
||||
#define ONIG_SYN_OP_ESC_QMARK_ZERO_ONE (1U<<7)
|
||||
#define ONIG_SYN_OP_BRACE_INTERVAL (1U<<8) /* {lower,upper} */
|
||||
#define ONIG_SYN_OP_ESC_BRACE_INTERVAL (1U<<9) /* \{lower,upper\} */
|
||||
#define ONIG_SYN_OP_VBAR_ALT (1U<<10) /* | */
|
||||
#define ONIG_SYN_OP_ESC_VBAR_ALT (1U<<11) /* \| */
|
||||
#define ONIG_SYN_OP_LPAREN_SUBEXP (1U<<12) /* (...) */
|
||||
#define ONIG_SYN_OP_ESC_LPAREN_SUBEXP (1U<<13) /* \(...\) */
|
||||
#define ONIG_SYN_OP_ESC_AZ_BUF_ANCHOR (1U<<14) /* \A, \Z, \z */
|
||||
#define ONIG_SYN_OP_ESC_CAPITAL_G_BEGIN_ANCHOR (1U<<15) /* \G */
|
||||
#define ONIG_SYN_OP_DECIMAL_BACKREF (1U<<16) /* \num */
|
||||
#define ONIG_SYN_OP_BRACKET_CC (1U<<17) /* [...] */
|
||||
#define ONIG_SYN_OP_ESC_W_WORD (1U<<18) /* \w, \W */
|
||||
#define ONIG_SYN_OP_ESC_LTGT_WORD_BEGIN_END (1U<<19) /* \<. \> */
|
||||
#define ONIG_SYN_OP_ESC_B_WORD_BOUND (1U<<20) /* \b, \B */
|
||||
#define ONIG_SYN_OP_ESC_S_WHITE_SPACE (1U<<21) /* \s, \S */
|
||||
#define ONIG_SYN_OP_ESC_D_DIGIT (1U<<22) /* \d, \D */
|
||||
#define ONIG_SYN_OP_LINE_ANCHOR (1U<<23) /* ^, $ */
|
||||
#define ONIG_SYN_OP_POSIX_BRACKET (1U<<24) /* [:xxxx:] */
|
||||
#define ONIG_SYN_OP_QMARK_NON_GREEDY (1U<<25) /* ??,*?,+?,{n,m}? */
|
||||
#define ONIG_SYN_OP_ESC_CONTROL_CHARS (1U<<26) /* \n,\r,\t,\a ... */
|
||||
#define ONIG_SYN_OP_ESC_C_CONTROL (1U<<27) /* \cx */
|
||||
#define ONIG_SYN_OP_ESC_OCTAL3 (1U<<28) /* \OOO */
|
||||
#define ONIG_SYN_OP_ESC_X_HEX2 (1U<<29) /* \xHH */
|
||||
#define ONIG_SYN_OP_ESC_X_BRACE_HEX8 (1U<<30) /* \x{7HHHHHHH} */
|
||||
|
||||
#define ONIG_SYN_OP2_ESC_CAPITAL_Q_QUOTE (1U<<0) /* \Q...\E */
|
||||
#define ONIG_SYN_OP2_QMARK_GROUP_EFFECT (1U<<1) /* (?...) */
|
||||
#define ONIG_SYN_OP2_OPTION_PERL (1U<<2) /* (?imsx),(?-imsx) */
|
||||
#define ONIG_SYN_OP2_OPTION_RUBY (1U<<3) /* (?imx), (?-imx) */
|
||||
#define ONIG_SYN_OP2_PLUS_POSSESSIVE_REPEAT (1U<<4) /* ?+,*+,++ */
|
||||
#define ONIG_SYN_OP2_PLUS_POSSESSIVE_INTERVAL (1U<<5) /* {n,m}+ */
|
||||
#define ONIG_SYN_OP2_CCLASS_SET_OP (1U<<6) /* [...&&..[..]..] */
|
||||
#define ONIG_SYN_OP2_QMARK_LT_NAMED_GROUP (1U<<7) /* (?<name>...) */
|
||||
#define ONIG_SYN_OP2_ESC_K_NAMED_BACKREF (1U<<8) /* \k<name> */
|
||||
#define ONIG_SYN_OP2_ESC_G_SUBEXP_CALL (1U<<9) /* \g<name>, \g<n> */
|
||||
#define ONIG_SYN_OP2_ATMARK_CAPTURE_HISTORY (1U<<10) /* (?@..),(?@<x>..) */
|
||||
#define ONIG_SYN_OP2_ESC_CAPITAL_C_BAR_CONTROL (1U<<11) /* \C-x */
|
||||
#define ONIG_SYN_OP2_ESC_CAPITAL_M_BAR_META (1U<<12) /* \M-x */
|
||||
#define ONIG_SYN_OP2_ESC_V_VTAB (1U<<13) /* \v as VTAB */
|
||||
#define ONIG_SYN_OP2_ESC_U_HEX4 (1U<<14) /* \uHHHH */
|
||||
#define ONIG_SYN_OP2_ESC_GNU_BUF_ANCHOR (1U<<15) /* \`, \' */
|
||||
#define ONIG_SYN_OP2_ESC_P_BRACE_CHAR_PROPERTY (1U<<16) /* \p{...}, \P{...} */
|
||||
#define ONIG_SYN_OP2_ESC_P_BRACE_CIRCUMFLEX_NOT (1U<<17) /* \p{^..}, \P{^..} */
|
||||
/* #define ONIG_SYN_OP2_CHAR_PROPERTY_PREFIX_IS (1U<<18) */
|
||||
#define ONIG_SYN_OP2_ESC_H_XDIGIT (1U<<19) /* \h, \H */
|
||||
#define ONIG_SYN_OP2_INEFFECTIVE_ESCAPE (1U<<20) /* \ */
|
||||
|
||||
/* syntax (behavior) */
|
||||
#define ONIG_SYN_CONTEXT_INDEP_ANCHORS (1U<<31) /* not implemented */
|
||||
#define ONIG_SYN_CONTEXT_INDEP_REPEAT_OPS (1U<<0) /* ?, *, +, {n,m} */
|
||||
#define ONIG_SYN_CONTEXT_INVALID_REPEAT_OPS (1U<<1) /* error or ignore */
|
||||
#define ONIG_SYN_ALLOW_UNMATCHED_CLOSE_SUBEXP (1U<<2) /* ...)... */
|
||||
#define ONIG_SYN_ALLOW_INVALID_INTERVAL (1U<<3) /* {??? */
|
||||
#define ONIG_SYN_ALLOW_INTERVAL_LOW_ABBREV (1U<<4) /* {,n} => {0,n} */
|
||||
#define ONIG_SYN_STRICT_CHECK_BACKREF (1U<<5) /* /(\1)/,/\1()/ ..*/
|
||||
#define ONIG_SYN_DIFFERENT_LEN_ALT_LOOK_BEHIND (1U<<6) /* (?<=a|bc) */
|
||||
#define ONIG_SYN_CAPTURE_ONLY_NAMED_GROUP (1U<<7) /* see doc/RE */
|
||||
#define ONIG_SYN_ALLOW_MULTIPLEX_DEFINITION_NAME (1U<<8) /* (?<x>)(?<x>) */
|
||||
#define ONIG_SYN_FIXED_INTERVAL_IS_GREEDY_ONLY (1U<<9) /* a{n}?=(?:a{n})? */
|
||||
|
||||
/* syntax (behavior) in char class [...] */
|
||||
#define ONIG_SYN_NOT_NEWLINE_IN_NEGATIVE_CC (1U<<20) /* [^...] */
|
||||
#define ONIG_SYN_BACKSLASH_ESCAPE_IN_CC (1U<<21) /* [..\w..] etc.. */
|
||||
#define ONIG_SYN_ALLOW_EMPTY_RANGE_IN_CC (1U<<22)
|
||||
#define ONIG_SYN_ALLOW_DOUBLE_RANGE_OP_IN_CC (1U<<23) /* [0-9-a]=[0-9\-a] */
|
||||
/* syntax (behavior) warning */
|
||||
#define ONIG_SYN_WARN_CC_OP_NOT_ESCAPED (1U<<24) /* [,-,] */
|
||||
#define ONIG_SYN_WARN_REDUNDANT_NESTED_REPEAT (1U<<25) /* (?:a*)+ */
|
||||
|
||||
/* meta character specifiers (onig_set_meta_char()) */
|
||||
#define ONIG_META_CHAR_ESCAPE 0
|
||||
#define ONIG_META_CHAR_ANYCHAR 1
|
||||
#define ONIG_META_CHAR_ANYTIME 2
|
||||
#define ONIG_META_CHAR_ZERO_OR_ONE_TIME 3
|
||||
#define ONIG_META_CHAR_ONE_OR_MORE_TIME 4
|
||||
#define ONIG_META_CHAR_ANYCHAR_ANYTIME 5
|
||||
|
||||
#define ONIG_INEFFECTIVE_META_CHAR 0
|
||||
|
||||
/* error codes */
|
||||
#define ONIG_IS_PATTERN_ERROR(ecode) ((ecode) <= -100 && (ecode) > -1000)
|
||||
/* normal return */
|
||||
#define ONIG_NORMAL 0
|
||||
#define ONIG_MISMATCH -1
|
||||
#define ONIG_NO_SUPPORT_CONFIG -2
|
||||
|
||||
/* internal error */
|
||||
#define ONIGERR_MEMORY -5
|
||||
#define ONIGERR_TYPE_BUG -6
|
||||
#define ONIGERR_PARSER_BUG -11
|
||||
#define ONIGERR_STACK_BUG -12
|
||||
#define ONIGERR_UNDEFINED_BYTECODE -13
|
||||
#define ONIGERR_UNEXPECTED_BYTECODE -14
|
||||
#define ONIGERR_MATCH_STACK_LIMIT_OVER -15
|
||||
#define ONIGERR_DEFAULT_ENCODING_IS_NOT_SETTED -21
|
||||
#define ONIGERR_SPECIFIED_ENCODING_CANT_CONVERT_TO_WIDE_CHAR -22
|
||||
/* general error */
|
||||
#define ONIGERR_INVALID_ARGUMENT -30
|
||||
/* syntax error */
|
||||
#define ONIGERR_END_PATTERN_AT_LEFT_BRACE -100
|
||||
#define ONIGERR_END_PATTERN_AT_LEFT_BRACKET -101
|
||||
#define ONIGERR_EMPTY_CHAR_CLASS -102
|
||||
#define ONIGERR_PREMATURE_END_OF_CHAR_CLASS -103
|
||||
#define ONIGERR_END_PATTERN_AT_ESCAPE -104
|
||||
#define ONIGERR_END_PATTERN_AT_META -105
|
||||
#define ONIGERR_END_PATTERN_AT_CONTROL -106
|
||||
#define ONIGERR_META_CODE_SYNTAX -108
|
||||
#define ONIGERR_CONTROL_CODE_SYNTAX -109
|
||||
#define ONIGERR_CHAR_CLASS_VALUE_AT_END_OF_RANGE -110
|
||||
#define ONIGERR_CHAR_CLASS_VALUE_AT_START_OF_RANGE -111
|
||||
#define ONIGERR_UNMATCHED_RANGE_SPECIFIER_IN_CHAR_CLASS -112
|
||||
#define ONIGERR_TARGET_OF_REPEAT_OPERATOR_NOT_SPECIFIED -113
|
||||
#define ONIGERR_TARGET_OF_REPEAT_OPERATOR_INVALID -114
|
||||
#define ONIGERR_NESTED_REPEAT_OPERATOR -115
|
||||
#define ONIGERR_UNMATCHED_CLOSE_PARENTHESIS -116
|
||||
#define ONIGERR_END_PATTERN_WITH_UNMATCHED_PARENTHESIS -117
|
||||
#define ONIGERR_END_PATTERN_IN_GROUP -118
|
||||
#define ONIGERR_UNDEFINED_GROUP_OPTION -119
|
||||
#define ONIGERR_INVALID_POSIX_BRACKET_TYPE -121
|
||||
#define ONIGERR_INVALID_LOOK_BEHIND_PATTERN -122
|
||||
#define ONIGERR_INVALID_REPEAT_RANGE_PATTERN -123
|
||||
/* values error (syntax error) */
|
||||
#define ONIGERR_TOO_BIG_NUMBER -200
|
||||
#define ONIGERR_TOO_BIG_NUMBER_FOR_REPEAT_RANGE -201
|
||||
#define ONIGERR_UPPER_SMALLER_THAN_LOWER_IN_REPEAT_RANGE -202
|
||||
#define ONIGERR_EMPTY_RANGE_IN_CHAR_CLASS -203
|
||||
#define ONIGERR_MISMATCH_CODE_LENGTH_IN_CLASS_RANGE -204
|
||||
#define ONIGERR_TOO_MANY_MULTI_BYTE_RANGES -205
|
||||
#define ONIGERR_TOO_SHORT_MULTI_BYTE_STRING -206
|
||||
#define ONIGERR_TOO_BIG_BACKREF_NUMBER -207
|
||||
#define ONIGERR_INVALID_BACKREF -208
|
||||
#define ONIGERR_NUMBERED_BACKREF_OR_CALL_NOT_ALLOWED -209
|
||||
#define ONIGERR_TOO_LONG_WIDE_CHAR_VALUE -212
|
||||
#define ONIGERR_EMPTY_GROUP_NAME -214
|
||||
#define ONIGERR_INVALID_GROUP_NAME -215
|
||||
#define ONIGERR_INVALID_CHAR_IN_GROUP_NAME -216
|
||||
#define ONIGERR_UNDEFINED_NAME_REFERENCE -217
|
||||
#define ONIGERR_UNDEFINED_GROUP_REFERENCE -218
|
||||
#define ONIGERR_MULTIPLEX_DEFINED_NAME -219
|
||||
#define ONIGERR_MULTIPLEX_DEFINITION_NAME_CALL -220
|
||||
#define ONIGERR_NEVER_ENDING_RECURSION -221
|
||||
#define ONIGERR_GROUP_NUMBER_OVER_FOR_CAPTURE_HISTORY -222
|
||||
#define ONIGERR_INVALID_CHAR_PROPERTY_NAME -223
|
||||
#define ONIGERR_INVALID_CODE_POINT_VALUE -400
|
||||
#define ONIGERR_INVALID_WIDE_CHAR_VALUE -400
|
||||
#define ONIGERR_TOO_BIG_WIDE_CHAR_VALUE -401
|
||||
#define ONIGERR_NOT_SUPPORTED_ENCODING_COMBINATION -402
|
||||
#define ONIGERR_INVALID_COMBINATION_OF_OPTIONS -403
|
||||
|
||||
/* errors related to thread */
|
||||
#define ONIGERR_OVER_THREAD_PASS_LIMIT_COUNT -1001
|
||||
|
||||
|
||||
/* must be smaller than BIT_STATUS_BITS_NUM (unsigned int * 8) */
|
||||
#define ONIG_MAX_CAPTURE_HISTORY_GROUP 31
|
||||
#define ONIG_IS_CAPTURE_HISTORY_GROUP(r, i) \
|
||||
((i) <= ONIG_MAX_CAPTURE_HISTORY_GROUP && (r)->list && (r)->list[i])
|
||||
|
||||
typedef struct OnigCaptureTreeNodeStruct {
|
||||
int group; /* group number */
|
||||
int beg;
|
||||
int end;
|
||||
int allocated;
|
||||
int num_childs;
|
||||
struct OnigCaptureTreeNodeStruct** childs;
|
||||
} OnigCaptureTreeNode;
|
||||
|
||||
/* match result region type */
|
||||
struct re_registers {
|
||||
int allocated;
|
||||
int num_regs;
|
||||
int* beg;
|
||||
int* end;
|
||||
/* extended */
|
||||
OnigCaptureTreeNode* history_root; /* capture history tree root */
|
||||
};
|
||||
|
||||
/* capture tree traverse */
|
||||
#define ONIG_TRAVERSE_CALLBACK_AT_FIRST 1
|
||||
#define ONIG_TRAVERSE_CALLBACK_AT_LAST 2
|
||||
#define ONIG_TRAVERSE_CALLBACK_AT_BOTH \
|
||||
( ONIG_TRAVERSE_CALLBACK_AT_FIRST | ONIG_TRAVERSE_CALLBACK_AT_LAST )
|
||||
|
||||
|
||||
#define ONIG_REGION_NOTPOS -1
|
||||
|
||||
typedef struct re_registers OnigRegion;
|
||||
|
||||
typedef struct {
|
||||
OnigEncoding enc;
|
||||
OnigUChar* par;
|
||||
OnigUChar* par_end;
|
||||
} OnigErrorInfo;
|
||||
|
||||
typedef struct {
|
||||
int lower;
|
||||
int upper;
|
||||
} OnigRepeatRange;
|
||||
|
||||
typedef void (*OnigWarnFunc) P_((const char* s));
|
||||
extern void onig_null_warn P_((const char* s));
|
||||
#define ONIG_NULL_WARN onig_null_warn
|
||||
|
||||
#define ONIG_CHAR_TABLE_SIZE 256
|
||||
|
||||
/* regex_t state */
|
||||
#define ONIG_STATE_NORMAL 0
|
||||
#define ONIG_STATE_SEARCHING 1
|
||||
#define ONIG_STATE_COMPILING -1
|
||||
#define ONIG_STATE_MODIFY -2
|
||||
|
||||
#define ONIG_STATE(reg) \
|
||||
((reg)->state > 0 ? ONIG_STATE_SEARCHING : (reg)->state)
|
||||
|
||||
typedef struct re_pattern_buffer {
|
||||
/* common members of BBuf(bytes-buffer) */
|
||||
unsigned char* p; /* compiled pattern */
|
||||
unsigned int used; /* used space for p */
|
||||
unsigned int alloc; /* allocated space for p */
|
||||
|
||||
int state; /* normal, searching, compiling */
|
||||
int num_mem; /* used memory(...) num counted from 1 */
|
||||
int num_repeat; /* OP_REPEAT/OP_REPEAT_NG id-counter */
|
||||
int num_null_check; /* OP_NULL_CHECK_START/END id counter */
|
||||
int num_comb_exp_check; /* combination explosion check */
|
||||
int num_call; /* number of subexp call */
|
||||
unsigned int capture_history; /* (?@...) flag (1-31) */
|
||||
unsigned int bt_mem_start; /* need backtrack flag */
|
||||
unsigned int bt_mem_end; /* need backtrack flag */
|
||||
int stack_pop_level;
|
||||
int repeat_range_alloc;
|
||||
OnigRepeatRange* repeat_range;
|
||||
|
||||
OnigEncoding enc;
|
||||
OnigOptionType options;
|
||||
OnigSyntaxType* syntax;
|
||||
OnigCaseFoldType case_fold_flag;
|
||||
void* name_table;
|
||||
|
||||
/* optimization info (string search, char-map and anchors) */
|
||||
int optimize; /* optimize flag */
|
||||
int threshold_len; /* search str-length for apply optimize */
|
||||
int anchor; /* BEGIN_BUF, BEGIN_POS, (SEMI_)END_BUF */
|
||||
OnigDistance anchor_dmin; /* (SEMI_)END_BUF anchor distance */
|
||||
OnigDistance anchor_dmax; /* (SEMI_)END_BUF anchor distance */
|
||||
int sub_anchor; /* start-anchor for exact or map */
|
||||
unsigned char *exact;
|
||||
unsigned char *exact_end;
|
||||
unsigned char map[ONIG_CHAR_TABLE_SIZE]; /* used as BM skip or char-map */
|
||||
int *int_map; /* BM skip for exact_len > 255 */
|
||||
int *int_map_backward; /* BM skip for backward search */
|
||||
OnigDistance dmin; /* min-distance of exact or map */
|
||||
OnigDistance dmax; /* max-distance of exact or map */
|
||||
|
||||
/* regex_t link chain */
|
||||
struct re_pattern_buffer* chain; /* escape compile-conflict */
|
||||
} OnigRegexType;
|
||||
|
||||
typedef OnigRegexType* OnigRegex;
|
||||
|
||||
#ifndef ONIG_ESCAPE_REGEX_T_COLLISION
|
||||
typedef OnigRegexType regex_t;
|
||||
#endif
|
||||
|
||||
|
||||
typedef struct {
|
||||
int num_of_elements;
|
||||
OnigEncoding pattern_enc;
|
||||
OnigEncoding target_enc;
|
||||
OnigSyntaxType* syntax;
|
||||
OnigOptionType option;
|
||||
OnigCaseFoldType case_fold_flag;
|
||||
} OnigCompileInfo;
|
||||
|
||||
/* Oniguruma Native API */
|
||||
ONIG_EXTERN
|
||||
int onig_init P_((void));
|
||||
ONIG_EXTERN
|
||||
int onig_error_code_to_str PV_((OnigUChar* s, int err_code, ...));
|
||||
ONIG_EXTERN
|
||||
void onig_set_warn_func P_((OnigWarnFunc f));
|
||||
ONIG_EXTERN
|
||||
void onig_set_verb_warn_func P_((OnigWarnFunc f));
|
||||
ONIG_EXTERN
|
||||
int onig_new P_((OnigRegex*, const OnigUChar* pattern, const OnigUChar* pattern_end, OnigOptionType option, OnigEncoding enc, OnigSyntaxType* syntax, OnigErrorInfo* einfo));
|
||||
ONIG_EXTERN
|
||||
int onig_reg_init P_((regex_t* reg, OnigOptionType option, OnigCaseFoldType case_fold_flag, OnigEncoding enc, OnigSyntaxType* syntax));
|
||||
int onig_new_without_alloc P_((OnigRegex, const OnigUChar* pattern, const OnigUChar* pattern_end, OnigOptionType option, OnigEncoding enc, OnigSyntaxType* syntax, OnigErrorInfo* einfo));
|
||||
ONIG_EXTERN
|
||||
int onig_new_deluxe P_((OnigRegex* reg, const OnigUChar* pattern, const OnigUChar* pattern_end, OnigCompileInfo* ci, OnigErrorInfo* einfo));
|
||||
ONIG_EXTERN
|
||||
void onig_free P_((OnigRegex));
|
||||
ONIG_EXTERN
|
||||
void onig_free_body P_((OnigRegex));
|
||||
ONIG_EXTERN
|
||||
int onig_recompile P_((OnigRegex, const OnigUChar* pattern, const OnigUChar* pattern_end, OnigOptionType option, OnigEncoding enc, OnigSyntaxType* syntax, OnigErrorInfo* einfo));
|
||||
ONIG_EXTERN
|
||||
int onig_recompile_deluxe P_((OnigRegex reg, const OnigUChar* pattern, const OnigUChar* pattern_end, OnigCompileInfo* ci, OnigErrorInfo* einfo));
|
||||
ONIG_EXTERN
|
||||
int onig_search P_((OnigRegex, const OnigUChar* str, const OnigUChar* end, const OnigUChar* start, const OnigUChar* range, OnigRegion* region, OnigOptionType option));
|
||||
ONIG_EXTERN
|
||||
int onig_match P_((OnigRegex, const OnigUChar* str, const OnigUChar* end, const OnigUChar* at, OnigRegion* region, OnigOptionType option));
|
||||
ONIG_EXTERN
|
||||
OnigRegion* onig_region_new P_((void));
|
||||
ONIG_EXTERN
|
||||
void onig_region_init P_((OnigRegion* region));
|
||||
ONIG_EXTERN
|
||||
void onig_region_free P_((OnigRegion* region, int free_self));
|
||||
ONIG_EXTERN
|
||||
void onig_region_copy P_((OnigRegion* to, OnigRegion* from));
|
||||
ONIG_EXTERN
|
||||
void onig_region_clear P_((OnigRegion* region));
|
||||
ONIG_EXTERN
|
||||
int onig_region_resize P_((OnigRegion* region, int n));
|
||||
ONIG_EXTERN
|
||||
int onig_region_set P_((OnigRegion* region, int at, int beg, int end));
|
||||
ONIG_EXTERN
|
||||
int onig_name_to_group_numbers P_((OnigRegex reg, const OnigUChar* name, const OnigUChar* name_end, int** nums));
|
||||
ONIG_EXTERN
|
||||
int onig_name_to_backref_number P_((OnigRegex reg, const OnigUChar* name, const OnigUChar* name_end, OnigRegion *region));
|
||||
ONIG_EXTERN
|
||||
int onig_foreach_name P_((OnigRegex reg, int (*func)(const OnigUChar*, const OnigUChar*,int,int*,OnigRegex,void*), void* arg));
|
||||
ONIG_EXTERN
|
||||
int onig_number_of_names P_((OnigRegex reg));
|
||||
ONIG_EXTERN
|
||||
int onig_number_of_captures P_((OnigRegex reg));
|
||||
ONIG_EXTERN
|
||||
int onig_number_of_capture_histories P_((OnigRegex reg));
|
||||
ONIG_EXTERN
|
||||
OnigCaptureTreeNode* onig_get_capture_tree P_((OnigRegion* region));
|
||||
ONIG_EXTERN
|
||||
int onig_capture_tree_traverse P_((OnigRegion* region, int at, int(*callback_func)(int,int,int,int,int,void*), void* arg));
|
||||
ONIG_EXTERN
|
||||
int onig_noname_group_capture_is_active P_((OnigRegex reg));
|
||||
ONIG_EXTERN
|
||||
OnigEncoding onig_get_encoding P_((OnigRegex reg));
|
||||
ONIG_EXTERN
|
||||
OnigOptionType onig_get_options P_((OnigRegex reg));
|
||||
ONIG_EXTERN
|
||||
OnigCaseFoldType onig_get_case_fold_flag P_((OnigRegex reg));
|
||||
ONIG_EXTERN
|
||||
OnigSyntaxType* onig_get_syntax P_((OnigRegex reg));
|
||||
ONIG_EXTERN
|
||||
int onig_set_default_syntax P_((OnigSyntaxType* syntax));
|
||||
ONIG_EXTERN
|
||||
void onig_copy_syntax P_((OnigSyntaxType* to, OnigSyntaxType* from));
|
||||
ONIG_EXTERN
|
||||
unsigned int onig_get_syntax_op P_((OnigSyntaxType* syntax));
|
||||
ONIG_EXTERN
|
||||
unsigned int onig_get_syntax_op2 P_((OnigSyntaxType* syntax));
|
||||
ONIG_EXTERN
|
||||
unsigned int onig_get_syntax_behavior P_((OnigSyntaxType* syntax));
|
||||
ONIG_EXTERN
|
||||
OnigOptionType onig_get_syntax_options P_((OnigSyntaxType* syntax));
|
||||
ONIG_EXTERN
|
||||
void onig_set_syntax_op P_((OnigSyntaxType* syntax, unsigned int op));
|
||||
ONIG_EXTERN
|
||||
void onig_set_syntax_op2 P_((OnigSyntaxType* syntax, unsigned int op2));
|
||||
ONIG_EXTERN
|
||||
void onig_set_syntax_behavior P_((OnigSyntaxType* syntax, unsigned int behavior));
|
||||
ONIG_EXTERN
|
||||
void onig_set_syntax_options P_((OnigSyntaxType* syntax, OnigOptionType options));
|
||||
ONIG_EXTERN
|
||||
int onig_set_meta_char P_((OnigSyntaxType* syntax, unsigned int what, OnigCodePoint code));
|
||||
ONIG_EXTERN
|
||||
void onig_copy_encoding P_((OnigEncoding to, OnigEncoding from));
|
||||
ONIG_EXTERN
|
||||
OnigCaseFoldType onig_get_default_case_fold_flag P_((void));
|
||||
ONIG_EXTERN
|
||||
int onig_set_default_case_fold_flag P_((OnigCaseFoldType case_fold_flag));
|
||||
ONIG_EXTERN
|
||||
unsigned int onig_get_match_stack_limit_size P_((void));
|
||||
ONIG_EXTERN
|
||||
int onig_set_match_stack_limit_size P_((unsigned int size));
|
||||
ONIG_EXTERN
|
||||
int onig_end P_((void));
|
||||
ONIG_EXTERN
|
||||
const char* onig_version P_((void));
|
||||
ONIG_EXTERN
|
||||
const char* onig_copyright P_((void));
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* ONIGURUMA_H */
|
||||
Binary file not shown.
@@ -1,38 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>BuildMachineOSBuild</key>
|
||||
<string>11E2620</string>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
<string>English</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>CocoaOniguruma</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>net.limechat.CocoaOniguruma</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>CocoaOniguruma</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>FMWK</string>
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1.0</string>
|
||||
<key>DTCompiler</key>
|
||||
<string></string>
|
||||
<key>DTPlatformBuild</key>
|
||||
<string>4E3002</string>
|
||||
<key>DTPlatformVersion</key>
|
||||
<string>GM</string>
|
||||
<key>DTSDKBuild</key>
|
||||
<string>11E2620</string>
|
||||
<key>DTSDKName</key>
|
||||
<string></string>
|
||||
<key>DTXcode</key>
|
||||
<string>0433</string>
|
||||
<key>DTXcodeBuild</key>
|
||||
<string>4E3002</string>
|
||||
</dict>
|
||||
</plist>
|
||||
@@ -9,7 +9,6 @@
|
||||
void AtomCefRenderProcessHandler::OnWebKitInitialized() {
|
||||
new v8_extensions::Atom();
|
||||
new v8_extensions::NativeHandler();
|
||||
new v8_extensions::OnigRegExp();
|
||||
}
|
||||
|
||||
void AtomCefRenderProcessHandler::OnContextCreated(
|
||||
|
||||
@@ -31,11 +31,11 @@
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>APPL</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>0.3</string>
|
||||
<string>2.0</string>
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>0.3</string>
|
||||
<string>2.0</string>
|
||||
<key>LSApplicationCategoryType</key>
|
||||
<string>public.app-category.developer-tools</string>
|
||||
<key>NSMainNibFile</key>
|
||||
|
||||
@@ -99,7 +99,6 @@ static NSMutableArray *gPathWatchers;
|
||||
}
|
||||
|
||||
- (NSString *)watchPath:(NSString *)path callback:(WatchCallback)callback callbackId:(NSString *)callbackId {
|
||||
path = [path stringByStandardizingPath];
|
||||
@synchronized(self) {
|
||||
if (![self createKeventForPath:path]) {
|
||||
NSLog(@"WARNING: Failed to create kevent for path '%@'", path);
|
||||
@@ -119,8 +118,6 @@ static NSMutableArray *gPathWatchers;
|
||||
}
|
||||
|
||||
- (void)unwatchPath:(NSString *)path callbackId:(NSString *)callbackId error:(NSError **)error {
|
||||
path = [path stringByStandardizingPath];
|
||||
|
||||
@synchronized(self) {
|
||||
NSMutableDictionary *callbacks = [_callbacksByPath objectForKey:path];
|
||||
|
||||
@@ -154,8 +151,6 @@ static NSMutableArray *gPathWatchers;
|
||||
}
|
||||
|
||||
- (bool)createKeventForPath:(NSString *)path {
|
||||
path = [path stringByStandardizingPath];
|
||||
|
||||
@synchronized(self) {
|
||||
if ([_fileDescriptorsByPath objectForKey:path]) {
|
||||
NSLog(@"we already have a kevent");
|
||||
@@ -182,8 +177,6 @@ static NSMutableArray *gPathWatchers;
|
||||
}
|
||||
|
||||
- (void)removeKeventForPath:(NSString *)path {
|
||||
path = [path stringByStandardizingPath];
|
||||
|
||||
@synchronized(self) {
|
||||
NSNumber *fdNumber = [_fileDescriptorsByPath objectForKey:path];
|
||||
if (!fdNumber) {
|
||||
@@ -245,7 +238,7 @@ static NSMutableArray *gPathWatchers;
|
||||
char pathBuffer[MAXPATHLEN];
|
||||
fcntl((int)event.ident, F_GETPATH, &pathBuffer);
|
||||
close(event.ident);
|
||||
newPath = [[NSString stringWithUTF8String:pathBuffer] stringByStandardizingPath];
|
||||
newPath = [NSString stringWithUTF8String:pathBuffer];
|
||||
if (!newPath) {
|
||||
NSLog(@"WARNING: Ignoring rename event for deleted file '%@'", path);
|
||||
continue;
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
#include "include/cef_base.h"
|
||||
#include "include/cef_v8.h"
|
||||
|
||||
namespace v8_extensions {
|
||||
class Git : public CefV8Handler {
|
||||
public:
|
||||
Git();
|
||||
void CreateContextBinding(CefRefPtr<CefV8Context> context);
|
||||
virtual bool Execute(const CefString& name,
|
||||
CefRefPtr<CefV8Value> object,
|
||||
const CefV8ValueList& arguments,
|
||||
CefRefPtr<CefV8Value>& retval,
|
||||
CefString& exception) OVERRIDE;
|
||||
|
||||
// Provide the reference counting implementation for this class.
|
||||
IMPLEMENT_REFCOUNTING(Git);
|
||||
|
||||
private:
|
||||
Git(Git const&);
|
||||
void operator=(Git const&);
|
||||
};
|
||||
}
|
||||
@@ -1,493 +0,0 @@
|
||||
#import "git.h"
|
||||
#import "include/git2.h"
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
namespace v8_extensions {
|
||||
|
||||
class GitRepository : public CefBase {
|
||||
private:
|
||||
git_repository *repo;
|
||||
|
||||
static int CollectStatus(const char *path, unsigned int status, void *payload) {
|
||||
if ((status & GIT_STATUS_IGNORED) == 0) {
|
||||
std::map<const char*, unsigned int> *statuses = (std::map<const char*, unsigned int> *) payload;
|
||||
statuses->insert(std::pair<const char*, unsigned int>(path, status));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int CollectDiffHunk(const git_diff_delta *delta, const git_diff_range *range,
|
||||
const char *header, size_t header_len, void *payload) {
|
||||
std::vector<git_diff_range> *ranges = (std::vector<git_diff_range> *) payload;
|
||||
ranges->push_back(*range);
|
||||
return 0;
|
||||
}
|
||||
|
||||
public:
|
||||
GitRepository(const char *pathInRepo) {
|
||||
if (git_repository_open_ext(&repo, pathInRepo, 0, NULL) != GIT_OK) {
|
||||
repo = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
~GitRepository() {
|
||||
Destroy();
|
||||
}
|
||||
|
||||
void Destroy() {
|
||||
if (Exists()) {
|
||||
git_repository_free(repo);
|
||||
repo = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
BOOL Exists() {
|
||||
return repo != NULL;
|
||||
}
|
||||
|
||||
CefRefPtr<CefV8Value> GetPath() {
|
||||
return CefV8Value::CreateString(git_repository_path(repo));
|
||||
}
|
||||
|
||||
CefRefPtr<CefV8Value> GetHead() {
|
||||
git_reference *head;
|
||||
if (git_repository_head(&head, repo) == GIT_OK) {
|
||||
if (git_repository_head_detached(repo) == 1) {
|
||||
const git_oid* sha = git_reference_target(head);
|
||||
if (sha) {
|
||||
char oid[GIT_OID_HEXSZ + 1];
|
||||
git_oid_tostr(oid, GIT_OID_HEXSZ + 1, sha);
|
||||
git_reference_free(head);
|
||||
return CefV8Value::CreateString(oid);
|
||||
}
|
||||
}
|
||||
|
||||
CefRefPtr<CefV8Value> result = CefV8Value::CreateString(git_reference_name(head));
|
||||
git_reference_free(head);
|
||||
return result;
|
||||
}
|
||||
|
||||
return CefV8Value::CreateNull();
|
||||
}
|
||||
|
||||
CefRefPtr<CefV8Value> GetStatuses() {
|
||||
std::map<const char*, unsigned int> statuses;
|
||||
git_status_foreach(repo, CollectStatus, &statuses);
|
||||
std::map<const char*, unsigned int>::iterator iter = statuses.begin();
|
||||
CefRefPtr<CefV8Value> v8Statuses = CefV8Value::CreateObject(NULL);
|
||||
for (; iter != statuses.end(); ++iter) {
|
||||
v8Statuses->SetValue(iter->first, CefV8Value::CreateInt(iter->second), V8_PROPERTY_ATTRIBUTE_NONE);
|
||||
}
|
||||
return v8Statuses;
|
||||
}
|
||||
|
||||
int GetCommitCount(const git_oid* fromCommit, const git_oid* toCommit) {
|
||||
int count = 0;
|
||||
git_revwalk *revWalk;
|
||||
if (git_revwalk_new(&revWalk, repo) == GIT_OK) {
|
||||
git_revwalk_push(revWalk, fromCommit);
|
||||
git_revwalk_hide(revWalk, toCommit);
|
||||
git_oid currentCommit;
|
||||
while (git_revwalk_next(¤tCommit, revWalk) == GIT_OK)
|
||||
count++;
|
||||
git_revwalk_free(revWalk);
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
void GetShortBranchName(const char** out, const char* branchName) {
|
||||
*out = NULL;
|
||||
if (branchName == NULL)
|
||||
return;
|
||||
int branchNameLength = strlen(branchName);
|
||||
if (branchNameLength < 12)
|
||||
return;
|
||||
if (strncmp("refs/heads/", branchName, 11) != 0)
|
||||
return;
|
||||
|
||||
int shortNameLength = branchNameLength - 11;
|
||||
char* shortName = (char*) malloc(sizeof(char) * (shortNameLength + 1));
|
||||
shortName[shortNameLength] = '\0';
|
||||
strncpy(shortName, &branchName[11], shortNameLength);
|
||||
*out = shortName;
|
||||
}
|
||||
|
||||
void GetUpstreamBranch(const char** out, git_reference *branch) {
|
||||
*out = NULL;
|
||||
|
||||
const char* branchName = git_reference_name(branch);
|
||||
const char* shortBranchName;
|
||||
GetShortBranchName(&shortBranchName, branchName);
|
||||
if (shortBranchName == NULL)
|
||||
return;
|
||||
|
||||
int shortBranchNameLength = strlen(shortBranchName);
|
||||
char* remoteKey = (char*) malloc(sizeof(char) * (shortBranchNameLength + 15));
|
||||
sprintf(remoteKey, "branch.%s.remote", shortBranchName);
|
||||
char* mergeKey = (char*) malloc(sizeof(char) * (shortBranchNameLength + 14));
|
||||
sprintf(mergeKey, "branch.%s.merge", shortBranchName);
|
||||
free((char*)shortBranchName);
|
||||
|
||||
git_config *config;
|
||||
if (git_repository_config(&config, repo) != GIT_OK) {
|
||||
free(remoteKey);
|
||||
free(mergeKey);
|
||||
return;
|
||||
}
|
||||
|
||||
const char *remote;
|
||||
const char *merge;
|
||||
if (git_config_get_string(&remote, config, remoteKey) == GIT_OK
|
||||
&& git_config_get_string(&merge, config, mergeKey) == GIT_OK) {
|
||||
int remoteLength = strlen(remote);
|
||||
if (remoteLength > 0) {
|
||||
const char *shortMergeBranchName;
|
||||
GetShortBranchName(&shortMergeBranchName, merge);
|
||||
if (shortMergeBranchName != NULL) {
|
||||
int updateBranchLength = remoteLength + strlen(shortMergeBranchName) + 14;
|
||||
char* upstreamBranch = (char*) malloc(sizeof(char) * (updateBranchLength + 1));
|
||||
sprintf(upstreamBranch, "refs/remotes/%s/%s", remote, shortMergeBranchName);
|
||||
*out = upstreamBranch;
|
||||
}
|
||||
free((char*)shortMergeBranchName);
|
||||
}
|
||||
}
|
||||
|
||||
free(remoteKey);
|
||||
free(mergeKey);
|
||||
git_config_free(config);
|
||||
}
|
||||
|
||||
CefRefPtr<CefV8Value> GetAheadBehindCounts() {
|
||||
CefRefPtr<CefV8Value> result = NULL;
|
||||
git_reference *head;
|
||||
if (git_repository_head(&head, repo) == GIT_OK) {
|
||||
const char* upstreamBranchName;
|
||||
GetUpstreamBranch(&upstreamBranchName, head);
|
||||
if (upstreamBranchName != NULL) {
|
||||
git_reference *upstream;
|
||||
if (git_reference_lookup(&upstream, repo, upstreamBranchName) == GIT_OK) {
|
||||
const git_oid* headSha = git_reference_target(head);
|
||||
const git_oid* upstreamSha = git_reference_target(upstream);
|
||||
git_oid mergeBase;
|
||||
if (git_merge_base(&mergeBase, repo, headSha, upstreamSha) == GIT_OK) {
|
||||
result = CefV8Value::CreateObject(NULL);
|
||||
int ahead = GetCommitCount(headSha, &mergeBase);
|
||||
result->SetValue("ahead", CefV8Value::CreateInt(ahead), V8_PROPERTY_ATTRIBUTE_NONE);
|
||||
int behind = GetCommitCount(upstreamSha, &mergeBase);
|
||||
result->SetValue("behind", CefV8Value::CreateInt(behind), V8_PROPERTY_ATTRIBUTE_NONE);
|
||||
}
|
||||
git_reference_free(upstream);
|
||||
}
|
||||
free((char*)upstreamBranchName);
|
||||
}
|
||||
git_reference_free(head);
|
||||
}
|
||||
|
||||
if (result != NULL)
|
||||
return result;
|
||||
else
|
||||
return CefV8Value::CreateNull();
|
||||
}
|
||||
|
||||
CefRefPtr<CefV8Value> IsIgnored(const char *path) {
|
||||
int ignored;
|
||||
if (git_ignore_path_is_ignored(&ignored, repo, path) == GIT_OK) {
|
||||
return CefV8Value::CreateBool(ignored == 1);
|
||||
}
|
||||
else {
|
||||
return CefV8Value::CreateBool(false);
|
||||
}
|
||||
}
|
||||
|
||||
CefRefPtr<CefV8Value> GetStatus(const char *path) {
|
||||
unsigned int status = 0;
|
||||
if (git_status_file(&status, repo, path) == GIT_OK) {
|
||||
return CefV8Value::CreateInt(status);
|
||||
}
|
||||
else {
|
||||
return CefV8Value::CreateInt(0);
|
||||
}
|
||||
}
|
||||
|
||||
CefRefPtr<CefV8Value> CheckoutHead(const char *path) {
|
||||
char *copiedPath = (char *)malloc(sizeof(char) * (strlen(path) + 1));
|
||||
strcpy(copiedPath, path);
|
||||
git_checkout_opts options = GIT_CHECKOUT_OPTS_INIT;
|
||||
options.checkout_strategy = GIT_CHECKOUT_FORCE;
|
||||
git_strarray paths;
|
||||
paths.count = 1;
|
||||
paths.strings = &copiedPath;
|
||||
options.paths = paths;
|
||||
|
||||
int result = git_checkout_head(repo, &options);
|
||||
free(copiedPath);
|
||||
return CefV8Value::CreateBool(result == GIT_OK);
|
||||
}
|
||||
|
||||
CefRefPtr<CefV8Value> GetDiffStats(const char *path) {
|
||||
git_reference *head;
|
||||
if (git_repository_head(&head, repo) != GIT_OK) {
|
||||
return CefV8Value::CreateNull();
|
||||
}
|
||||
|
||||
const git_oid* sha = git_reference_target(head);
|
||||
git_commit *commit;
|
||||
int commitStatus = git_commit_lookup(&commit, repo, sha);
|
||||
git_reference_free(head);
|
||||
if (commitStatus != GIT_OK) {
|
||||
return CefV8Value::CreateNull();
|
||||
}
|
||||
|
||||
git_tree *tree;
|
||||
int treeStatus = git_commit_tree(&tree, commit);
|
||||
git_commit_free(commit);
|
||||
if (treeStatus != GIT_OK) {
|
||||
return CefV8Value::CreateNull();
|
||||
}
|
||||
|
||||
char *copiedPath = (char *)malloc(sizeof(char) * (strlen(path) + 1));
|
||||
strcpy(copiedPath, path);
|
||||
git_diff_options options = GIT_DIFF_OPTIONS_INIT;
|
||||
git_strarray paths;
|
||||
paths.count = 1;
|
||||
paths.strings = &copiedPath;
|
||||
options.pathspec = paths;
|
||||
options.context_lines = 1;
|
||||
options.flags = GIT_DIFF_DISABLE_PATHSPEC_MATCH;
|
||||
|
||||
git_diff_list *diffs;
|
||||
int diffStatus = git_diff_tree_to_workdir(&diffs, repo, tree, &options);
|
||||
git_tree_free(tree);
|
||||
free(copiedPath);
|
||||
if (diffStatus != GIT_OK || git_diff_num_deltas(diffs) != 1) {
|
||||
return CefV8Value::CreateNull();
|
||||
}
|
||||
|
||||
git_diff_patch *patch;
|
||||
int patchStatus = git_diff_get_patch(&patch, NULL, diffs, 0);
|
||||
git_diff_list_free(diffs);
|
||||
if (patchStatus != GIT_OK) {
|
||||
return CefV8Value::CreateNull();
|
||||
}
|
||||
|
||||
int added = 0;
|
||||
int deleted = 0;
|
||||
int hunks = git_diff_patch_num_hunks(patch);
|
||||
for (int i = 0; i < hunks; i++) {
|
||||
int lines = git_diff_patch_num_lines_in_hunk(patch, i);
|
||||
for (int j = 0; j < lines; j++) {
|
||||
char lineType;
|
||||
if (git_diff_patch_get_line_in_hunk(&lineType, NULL, NULL, NULL, NULL, patch, i, j) == GIT_OK) {
|
||||
switch (lineType) {
|
||||
case GIT_DIFF_LINE_ADDITION:
|
||||
added++;
|
||||
break;
|
||||
case GIT_DIFF_LINE_DELETION:
|
||||
deleted++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
git_diff_patch_free(patch);
|
||||
|
||||
CefRefPtr<CefV8Value> result = CefV8Value::CreateObject(NULL);
|
||||
result->SetValue("added", CefV8Value::CreateInt(added), V8_PROPERTY_ATTRIBUTE_NONE);
|
||||
result->SetValue("deleted", CefV8Value::CreateInt(deleted), V8_PROPERTY_ATTRIBUTE_NONE);
|
||||
return result;
|
||||
}
|
||||
|
||||
CefRefPtr<CefV8Value> GetLineDiffs(const char *path, const char *text) {
|
||||
git_reference *head;
|
||||
if (git_repository_head(&head, repo) != GIT_OK)
|
||||
return CefV8Value::CreateNull();
|
||||
|
||||
const git_oid* sha = git_reference_target(head);
|
||||
git_commit *commit;
|
||||
int commitStatus = git_commit_lookup(&commit, repo, sha);
|
||||
git_reference_free(head);
|
||||
if (commitStatus != GIT_OK)
|
||||
return CefV8Value::CreateNull();
|
||||
|
||||
git_tree *tree;
|
||||
int treeStatus = git_commit_tree(&tree, commit);
|
||||
git_commit_free(commit);
|
||||
if (treeStatus != GIT_OK)
|
||||
return CefV8Value::CreateNull();
|
||||
|
||||
git_tree_entry* treeEntry;
|
||||
git_tree_entry_bypath(&treeEntry, tree, path);
|
||||
git_blob *blob = NULL;
|
||||
if (treeEntry != NULL) {
|
||||
const git_oid *blobSha = git_tree_entry_id(treeEntry);
|
||||
if (blobSha == NULL || git_blob_lookup(&blob, repo, blobSha) != GIT_OK)
|
||||
blob = NULL;
|
||||
}
|
||||
git_tree_free(tree);
|
||||
if (blob == NULL)
|
||||
return CefV8Value::CreateNull();
|
||||
|
||||
int size = strlen(text);
|
||||
std::vector<git_diff_range> ranges;
|
||||
git_diff_options options = GIT_DIFF_OPTIONS_INIT;
|
||||
options.context_lines = 1;
|
||||
if (git_diff_blob_to_buffer(blob, text, size, &options, NULL, CollectDiffHunk, NULL, &ranges) == GIT_OK) {
|
||||
CefRefPtr<CefV8Value> v8Ranges = CefV8Value::CreateArray(ranges.size());
|
||||
for(int i = 0; i < ranges.size(); i++) {
|
||||
CefRefPtr<CefV8Value> v8Range = CefV8Value::CreateObject(NULL);
|
||||
v8Range->SetValue("oldStart", CefV8Value::CreateInt(ranges[i].old_start), V8_PROPERTY_ATTRIBUTE_NONE);
|
||||
v8Range->SetValue("oldLines", CefV8Value::CreateInt(ranges[i].old_lines), V8_PROPERTY_ATTRIBUTE_NONE);
|
||||
v8Range->SetValue("newStart", CefV8Value::CreateInt(ranges[i].new_start), V8_PROPERTY_ATTRIBUTE_NONE);
|
||||
v8Range->SetValue("newLines", CefV8Value::CreateInt(ranges[i].new_lines), V8_PROPERTY_ATTRIBUTE_NONE);
|
||||
v8Ranges->SetValue(i, v8Range);
|
||||
}
|
||||
git_blob_free(blob);
|
||||
return v8Ranges;
|
||||
} else {
|
||||
git_blob_free(blob);
|
||||
return CefV8Value::CreateNull();
|
||||
}
|
||||
}
|
||||
|
||||
CefRefPtr<CefV8Value> IsSubmodule(const char *path) {
|
||||
BOOL isSubmodule = false;
|
||||
git_index* index;
|
||||
if (git_repository_index(&index, repo) == GIT_OK) {
|
||||
const git_index_entry *entry = git_index_get_bypath(index, path, 0);
|
||||
isSubmodule = entry != NULL && (entry->mode & S_IFMT) == GIT_FILEMODE_COMMIT;
|
||||
git_index_free(index);
|
||||
}
|
||||
return CefV8Value::CreateBool(isSubmodule);
|
||||
}
|
||||
|
||||
void RefreshIndex() {
|
||||
git_index* index;
|
||||
if (git_repository_index(&index, repo) == GIT_OK) {
|
||||
git_index_read(index);
|
||||
git_index_free(index);
|
||||
}
|
||||
}
|
||||
|
||||
IMPLEMENT_REFCOUNTING(GitRepository);
|
||||
};
|
||||
|
||||
Git::Git() : CefV8Handler() {
|
||||
git_threads_init();
|
||||
}
|
||||
|
||||
void Git::CreateContextBinding(CefRefPtr<CefV8Context> context) {
|
||||
const char* methodNames[] = {
|
||||
"getRepository", "getHead", "getPath", "isIgnored", "getStatus", "checkoutHead",
|
||||
"getDiffStats", "isSubmodule", "refreshIndex", "destroy", "getStatuses",
|
||||
"getAheadBehindCounts", "getLineDiffs"
|
||||
};
|
||||
|
||||
CefRefPtr<CefV8Value> nativeObject = CefV8Value::CreateObject(NULL);
|
||||
int arrayLength = sizeof(methodNames) / sizeof(const char *);
|
||||
for (int i = 0; i < arrayLength; i++) {
|
||||
const char *functionName = methodNames[i];
|
||||
CefRefPtr<CefV8Value> function = CefV8Value::CreateFunction(functionName, this);
|
||||
nativeObject->SetValue(functionName, function, V8_PROPERTY_ATTRIBUTE_NONE);
|
||||
}
|
||||
|
||||
CefRefPtr<CefV8Value> global = context->GetGlobal();
|
||||
global->SetValue("$git", nativeObject, V8_PROPERTY_ATTRIBUTE_NONE);
|
||||
}
|
||||
|
||||
bool Git::Execute(const CefString& name,
|
||||
CefRefPtr<CefV8Value> object,
|
||||
const CefV8ValueList& arguments,
|
||||
CefRefPtr<CefV8Value>& retval,
|
||||
CefString& exception) {
|
||||
@autoreleasepool {
|
||||
if (name == "getRepository") {
|
||||
GitRepository *repository = new GitRepository(arguments[0]->GetStringValue().ToString().c_str());
|
||||
if (repository->Exists()) {
|
||||
CefRefPtr<CefBase> userData = repository;
|
||||
retval = CefV8Value::CreateObject(NULL);
|
||||
retval->SetUserData(userData);
|
||||
} else {
|
||||
retval = CefV8Value::CreateNull();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
if (name == "getHead") {
|
||||
GitRepository *userData = (GitRepository *)object->GetUserData().get();
|
||||
retval = userData->GetHead();
|
||||
return true;
|
||||
}
|
||||
|
||||
if (name == "getPath") {
|
||||
GitRepository *userData = (GitRepository *)object->GetUserData().get();
|
||||
retval = userData->GetPath();
|
||||
return true;
|
||||
}
|
||||
|
||||
if (name == "isIgnored") {
|
||||
GitRepository *userData = (GitRepository *)object->GetUserData().get();
|
||||
retval = userData->IsIgnored(arguments[0]->GetStringValue().ToString().c_str());
|
||||
return true;
|
||||
}
|
||||
|
||||
if (name == "getStatus") {
|
||||
GitRepository *userData = (GitRepository *)object->GetUserData().get();
|
||||
retval = userData->GetStatus(arguments[0]->GetStringValue().ToString().c_str());
|
||||
return true;
|
||||
}
|
||||
|
||||
if (name == "checkoutHead") {
|
||||
GitRepository *userData = (GitRepository *)object->GetUserData().get();
|
||||
retval = userData->CheckoutHead(arguments[0]->GetStringValue().ToString().c_str());
|
||||
return true;
|
||||
}
|
||||
|
||||
if (name == "getDiffStats") {
|
||||
GitRepository *userData = (GitRepository *)object->GetUserData().get();
|
||||
retval = userData->GetDiffStats(arguments[0]->GetStringValue().ToString().c_str());
|
||||
return true;
|
||||
}
|
||||
|
||||
if (name == "isSubmodule") {
|
||||
GitRepository *userData = (GitRepository *)object->GetUserData().get();
|
||||
retval = userData->IsSubmodule(arguments[0]->GetStringValue().ToString().c_str());
|
||||
return true;
|
||||
}
|
||||
|
||||
if (name == "refreshIndex") {
|
||||
GitRepository *userData = (GitRepository *)object->GetUserData().get();
|
||||
userData->RefreshIndex();
|
||||
return true;
|
||||
}
|
||||
|
||||
if (name == "destroy") {
|
||||
GitRepository *userData = (GitRepository *)object->GetUserData().get();
|
||||
userData->Destroy();
|
||||
return true;
|
||||
}
|
||||
|
||||
if (name == "getStatuses") {
|
||||
GitRepository *userData = (GitRepository *)object->GetUserData().get();
|
||||
retval = userData->GetStatuses();
|
||||
return true;
|
||||
}
|
||||
|
||||
if (name == "getAheadBehindCounts") {
|
||||
GitRepository *userData = (GitRepository *)object->GetUserData().get();
|
||||
retval = userData->GetAheadBehindCounts();
|
||||
return true;
|
||||
}
|
||||
|
||||
if (name == "getLineDiffs") {
|
||||
GitRepository *userData = (GitRepository *)object->GetUserData().get();
|
||||
std::string path = arguments[0]->GetStringValue().ToString();
|
||||
std::string text = arguments[1]->GetStringValue().ToString();
|
||||
retval = userData->GetLineDiffs(path.c_str(), text.c_str());
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#import <dispatch/dispatch.h>
|
||||
#import <CommonCrypto/CommonDigest.h>
|
||||
|
||||
#import "atom_application.h"
|
||||
#import "native.h"
|
||||
@@ -8,9 +7,8 @@
|
||||
#import "path_watcher.h"
|
||||
|
||||
#import <iostream>
|
||||
#include <fts.h>
|
||||
|
||||
static std::string windowState = "{}";
|
||||
static std::string windowState = "";
|
||||
static NSLock *windowStateLock = [[NSLock alloc] init];
|
||||
|
||||
namespace v8_extensions {
|
||||
@@ -24,11 +22,9 @@ namespace v8_extensions {
|
||||
|
||||
void Native::CreateContextBinding(CefRefPtr<CefV8Context> context) {
|
||||
const char* methodNames[] = {
|
||||
"exists", "read", "write", "absolute", "getAllFilePathsAsync", "traverseTree", "isDirectory",
|
||||
"isFile", "remove", "writeToPasteboard", "readFromPasteboard", "quit", "watchPath", "unwatchPath",
|
||||
"getWatchedPaths", "unwatchAllPaths", "makeDirectory", "move", "moveToTrash", "reload", "lastModified",
|
||||
"md5ForPath", "exec", "getPlatform", "setWindowState", "getWindowState", "isMisspelled",
|
||||
"getCorrectionsForMisspelling"
|
||||
"writeToPasteboard", "readFromPasteboard", "quit", "watchPath",
|
||||
"unwatchPath", "getWatchedPaths", "unwatchAllPaths", "moveToTrash",
|
||||
"reload", "setWindowState", "getWindowState", "beep"
|
||||
};
|
||||
|
||||
CefRefPtr<CefV8Value> nativeObject = CefV8Value::CreateObject(NULL);
|
||||
@@ -49,193 +45,7 @@ namespace v8_extensions {
|
||||
CefRefPtr<CefV8Value>& retval,
|
||||
CefString& exception) {
|
||||
@autoreleasepool {
|
||||
if (name == "exists") {
|
||||
std::string cc_value = arguments[0]->GetStringValue().ToString();
|
||||
const char *path = cc_value.c_str();
|
||||
retval = CefV8Value::CreateBool(access(path, F_OK) == 0);
|
||||
|
||||
return true;
|
||||
}
|
||||
else if (name == "read") {
|
||||
NSString *path = stringFromCefV8Value(arguments[0]);
|
||||
|
||||
NSError *error = nil;
|
||||
NSStringEncoding *encoding = nil;
|
||||
NSString *contents = [NSString stringWithContentsOfFile:path usedEncoding:encoding error:&error];
|
||||
|
||||
NSError *binaryFileError = nil;
|
||||
if (error) {
|
||||
contents = [NSString stringWithContentsOfFile:path encoding:NSASCIIStringEncoding error:&binaryFileError];
|
||||
}
|
||||
|
||||
if (binaryFileError) {
|
||||
exception = [[binaryFileError localizedDescription] UTF8String];
|
||||
}
|
||||
else {
|
||||
retval = CefV8Value::CreateString([contents UTF8String]);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
else if (name == "write") {
|
||||
NSString *path = stringFromCefV8Value(arguments[0]);
|
||||
NSString *content = stringFromCefV8Value(arguments[1]);
|
||||
|
||||
NSFileManager *fm = [NSFileManager defaultManager];
|
||||
|
||||
// Create parent directories if they don't exist
|
||||
BOOL exists = [fm fileExistsAtPath:[path stringByDeletingLastPathComponent] isDirectory:nil];
|
||||
if (!exists) {
|
||||
[fm createDirectoryAtPath:[path stringByDeletingLastPathComponent] withIntermediateDirectories:YES attributes:nil error:nil];
|
||||
}
|
||||
|
||||
NSError *error = nil;
|
||||
BOOL success = [content writeToFile:path atomically:YES encoding:NSUTF8StringEncoding error:&error];
|
||||
|
||||
if (error) {
|
||||
exception = [[error localizedDescription] UTF8String];
|
||||
}
|
||||
else if (!success) {
|
||||
std::string exception = "Cannot write to '";
|
||||
exception += [path UTF8String];
|
||||
exception += "'";
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
else if (name == "absolute") {
|
||||
NSString *path = stringFromCefV8Value(arguments[0]);
|
||||
|
||||
path = [path stringByStandardizingPath];
|
||||
if ([path characterAtIndex:0] == '/') {
|
||||
retval = CefV8Value::CreateString([path UTF8String]);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
else if (name == "getAllFilePathsAsync") {
|
||||
std::string argument = arguments[0]->GetStringValue().ToString();
|
||||
CefRefPtr<CefV8Value> callback = arguments[1];
|
||||
CefRefPtr<CefV8Context> context = CefV8Context::GetCurrentContext();
|
||||
|
||||
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
|
||||
dispatch_async(queue, ^{
|
||||
int rootPathLength = argument.size() + 1;
|
||||
char rootPath[rootPathLength];
|
||||
strcpy(rootPath, argument.c_str());
|
||||
char * const treePaths[] = {rootPath, NULL};
|
||||
|
||||
FTS *tree = fts_open(treePaths, FTS_COMFOLLOW | FTS_PHYSICAL| FTS_NOCHDIR | FTS_NOSTAT, NULL);
|
||||
std::vector<std::string> paths;
|
||||
|
||||
if (tree != NULL) {
|
||||
FTSENT *entry;
|
||||
int arrayIndex = 0;
|
||||
while ((entry = fts_read(tree)) != NULL) {
|
||||
if (entry->fts_level == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
bool isFile = entry->fts_info == FTS_NSOK;
|
||||
if (!isFile) {
|
||||
continue;
|
||||
}
|
||||
|
||||
int pathLength = entry->fts_pathlen - rootPathLength;
|
||||
char relative[pathLength + 1];
|
||||
relative[pathLength] = '\0';
|
||||
strncpy(relative, entry->fts_path + rootPathLength, pathLength);
|
||||
paths.push_back(relative);
|
||||
}
|
||||
}
|
||||
|
||||
dispatch_queue_t mainQueue = dispatch_get_main_queue();
|
||||
dispatch_async(mainQueue, ^{
|
||||
context->Enter();
|
||||
CefRefPtr<CefV8Value> v8Paths = CefV8Value::CreateArray(paths.size());
|
||||
for (int i = 0; i < paths.size(); i++) {
|
||||
v8Paths->SetValue(i, CefV8Value::CreateString(paths[i]));
|
||||
}
|
||||
CefV8ValueList callbackArgs;
|
||||
callbackArgs.push_back(v8Paths);
|
||||
callback->ExecuteFunction(callback, callbackArgs);
|
||||
context->Exit();
|
||||
});
|
||||
});
|
||||
return true;
|
||||
}
|
||||
else if (name == "traverseTree") {
|
||||
std::string argument = arguments[0]->GetStringValue().ToString();
|
||||
char rootPath[argument.size() + 1];
|
||||
strcpy(rootPath, argument.c_str());
|
||||
char * const paths[] = {rootPath, NULL};
|
||||
|
||||
FTS *tree = fts_open(paths, FTS_COMFOLLOW | FTS_PHYSICAL| FTS_NOCHDIR | FTS_NOSTAT, NULL);
|
||||
if (tree == NULL) {
|
||||
return true;
|
||||
}
|
||||
|
||||
CefRefPtr<CefV8Value> onFile = arguments[1];
|
||||
CefRefPtr<CefV8Value> onDir = arguments[2];
|
||||
CefV8ValueList args;
|
||||
FTSENT *entry;
|
||||
while ((entry = fts_read(tree)) != NULL) {
|
||||
if (entry->fts_level == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
bool isFile = entry->fts_info == FTS_NSOK;
|
||||
bool isDir = entry->fts_info == FTS_D;
|
||||
if (!isFile && !isDir) {
|
||||
continue;
|
||||
}
|
||||
|
||||
args.clear();
|
||||
args.push_back(CefV8Value::CreateString(entry->fts_path));
|
||||
if (isFile) {
|
||||
onFile->ExecuteFunction(onFile, args);
|
||||
}
|
||||
else {
|
||||
CefRefPtr<CefV8Value> enterDir = onDir->ExecuteFunction(onDir, args);
|
||||
if(enterDir != NULL && !enterDir->GetBoolValue()) {
|
||||
fts_set(tree, entry, FTS_SKIP);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
else if (name == "isDirectory") {
|
||||
NSString *path = stringFromCefV8Value(arguments[0]);
|
||||
|
||||
BOOL isDir = false;
|
||||
BOOL exists = [[NSFileManager defaultManager] fileExistsAtPath:path isDirectory:&isDir];
|
||||
retval = CefV8Value::CreateBool(exists && isDir);
|
||||
|
||||
return true;
|
||||
}
|
||||
else if (name == "isFile") {
|
||||
NSString *path = stringFromCefV8Value(arguments[0]);
|
||||
|
||||
BOOL isDir = false;
|
||||
BOOL exists = [[NSFileManager defaultManager] fileExistsAtPath:path isDirectory:&isDir];
|
||||
retval = CefV8Value::CreateBool(exists && !isDir);
|
||||
|
||||
return true;
|
||||
}
|
||||
else if (name == "remove") {
|
||||
NSString *path = stringFromCefV8Value(arguments[0]);
|
||||
|
||||
NSError *error = nil;
|
||||
[[NSFileManager defaultManager] removeItemAtPath:path error:&error];
|
||||
|
||||
if (error) {
|
||||
exception = [[error localizedDescription] UTF8String];
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
else if (name == "writeToPasteboard") {
|
||||
if (name == "writeToPasteboard") {
|
||||
NSString *text = stringFromCefV8Value(arguments[0]);
|
||||
|
||||
NSPasteboard *pb = [NSPasteboard generalPasteboard];
|
||||
@@ -268,8 +78,8 @@ namespace v8_extensions {
|
||||
|
||||
CefV8ValueList args;
|
||||
|
||||
args.push_back(CefV8Value::CreateString(std::string([eventType UTF8String], [eventType lengthOfBytesUsingEncoding:NSUTF8StringEncoding])));
|
||||
args.push_back(CefV8Value::CreateString(std::string([path UTF8String], [path lengthOfBytesUsingEncoding:NSUTF8StringEncoding])));
|
||||
args.push_back(CefV8Value::CreateString(string([eventType UTF8String], [eventType lengthOfBytesUsingEncoding:NSUTF8StringEncoding])));
|
||||
args.push_back(CefV8Value::CreateString(string([path UTF8String], [path lengthOfBytesUsingEncoding:NSUTF8StringEncoding])));
|
||||
function->ExecuteFunction(function, args);
|
||||
|
||||
context->Exit();
|
||||
@@ -281,7 +91,7 @@ namespace v8_extensions {
|
||||
retval = CefV8Value::CreateString([watchId UTF8String]);
|
||||
}
|
||||
else {
|
||||
exception = std::string("Failed to watch path '") + std::string([path UTF8String]) + std::string("' (it may not exist)");
|
||||
exception = string("Failed to watch path '") + string([path UTF8String]) + string("' (it may not exist)");
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -318,32 +128,6 @@ namespace v8_extensions {
|
||||
[pathWatcher unwatchAllPaths];
|
||||
return true;
|
||||
}
|
||||
else if (name == "makeDirectory") {
|
||||
NSString *path = stringFromCefV8Value(arguments[0]);
|
||||
NSFileManager *fm = [NSFileManager defaultManager];
|
||||
NSError *error = nil;
|
||||
[fm createDirectoryAtPath:path withIntermediateDirectories:NO attributes:nil error:&error];
|
||||
|
||||
if (error) {
|
||||
exception = [[error localizedDescription] UTF8String];
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
else if (name == "move") {
|
||||
NSString *sourcePath = stringFromCefV8Value(arguments[0]);
|
||||
NSString *targetPath = stringFromCefV8Value(arguments[1]);
|
||||
NSFileManager *fm = [NSFileManager defaultManager];
|
||||
|
||||
NSError *error = nil;
|
||||
[fm moveItemAtPath:sourcePath toPath:targetPath error:&error];
|
||||
|
||||
if (error) {
|
||||
exception = [[error localizedDescription] UTF8String];
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
else if (name == "moveToTrash") {
|
||||
NSString *sourcePath = stringFromCefV8Value(arguments[0]);
|
||||
bool success = [[NSWorkspace sharedWorkspace] performFileOperation:NSWorkspaceRecycleOperation
|
||||
@@ -353,7 +137,7 @@ namespace v8_extensions {
|
||||
tag:nil];
|
||||
|
||||
if (!success) {
|
||||
std::string exception = "Can not move ";
|
||||
string exception = "Can not move ";
|
||||
exception += [sourcePath UTF8String];
|
||||
exception += " to trash.";
|
||||
}
|
||||
@@ -363,146 +147,6 @@ namespace v8_extensions {
|
||||
else if (name == "reload") {
|
||||
CefV8Context::GetCurrentContext()->GetBrowser()->ReloadIgnoreCache();
|
||||
}
|
||||
else if (name == "lastModified") {
|
||||
NSString *path = stringFromCefV8Value(arguments[0]);
|
||||
NSFileManager *fm = [NSFileManager defaultManager];
|
||||
|
||||
NSError *error = nil;
|
||||
NSDictionary *attributes = [fm attributesOfItemAtPath:path error:&error];
|
||||
|
||||
if (error) {
|
||||
exception = [[error localizedDescription] UTF8String];
|
||||
}
|
||||
|
||||
NSDate *lastModified = [attributes objectForKey:NSFileModificationDate];
|
||||
retval = CefV8Value::CreateDate(CefTime([lastModified timeIntervalSince1970]));
|
||||
return true;
|
||||
}
|
||||
else if (name == "md5ForPath") {
|
||||
NSString *path = stringFromCefV8Value(arguments[0]);
|
||||
unsigned char outputData[CC_MD5_DIGEST_LENGTH];
|
||||
|
||||
NSData *inputData = [[NSData alloc] initWithContentsOfFile:path];
|
||||
CC_MD5([inputData bytes], [inputData length], outputData);
|
||||
[inputData release];
|
||||
|
||||
NSMutableString *hash = [[NSMutableString alloc] init];
|
||||
|
||||
for (NSUInteger i = 0; i < CC_MD5_DIGEST_LENGTH; i++) {
|
||||
[hash appendFormat:@"%02x", outputData[i]];
|
||||
}
|
||||
|
||||
retval = CefV8Value::CreateString([hash UTF8String]);
|
||||
return true;
|
||||
}
|
||||
else if (name == "exec") {
|
||||
NSString *command = stringFromCefV8Value(arguments[0]);
|
||||
CefRefPtr<CefV8Value> options = arguments[1];
|
||||
CefRefPtr<CefV8Value> callback = arguments[2];
|
||||
|
||||
NSTask *task = [[NSTask alloc] init];
|
||||
[task setLaunchPath:@"/bin/sh"];
|
||||
[task setStandardInput:[NSFileHandle fileHandleWithNullDevice]];
|
||||
[task setArguments:[NSArray arrayWithObjects:@"-l", @"-c", command, nil]];
|
||||
|
||||
NSPipe *stdout = [NSPipe pipe];
|
||||
NSPipe *stderr = [NSPipe pipe];
|
||||
[task setStandardOutput:stdout];
|
||||
[task setStandardError:stderr];
|
||||
|
||||
CefRefPtr<CefV8Context> context = CefV8Context::GetCurrentContext();
|
||||
void (^outputHandle)(NSString *contents, CefRefPtr<CefV8Value> function) = nil;
|
||||
void (^taskTerminatedHandle)(NSString *output, NSString *errorOutput) = nil;
|
||||
|
||||
outputHandle = ^(NSString *contents, CefRefPtr<CefV8Value> function) {
|
||||
context->Enter();
|
||||
|
||||
CefV8ValueList args;
|
||||
args.push_back(CefV8Value::CreateString(std::string([contents UTF8String], [contents lengthOfBytesUsingEncoding:NSUTF8StringEncoding])));
|
||||
CefRefPtr<CefV8Value> retval = function->ExecuteFunction(function, args);
|
||||
|
||||
if (function->HasException()) {
|
||||
throwException(context->GetGlobal(), function->GetException(), @"Error thrown in OutputHandle");
|
||||
}
|
||||
|
||||
context->Exit();
|
||||
};
|
||||
|
||||
taskTerminatedHandle = ^(NSString *output, NSString *errorOutput) {
|
||||
context->Enter();
|
||||
|
||||
CefV8ValueList args;
|
||||
args.push_back(CefV8Value::CreateInt([task terminationStatus]));
|
||||
args.push_back(CefV8Value::CreateString([output UTF8String]));
|
||||
args.push_back(CefV8Value::CreateString([errorOutput UTF8String]));
|
||||
|
||||
callback->ExecuteFunction(callback, args);
|
||||
|
||||
if (callback->HasException()) {
|
||||
throwException(context->GetGlobal(), callback->GetException(), @"Error thrown in TaskTerminatedHandle");
|
||||
}
|
||||
|
||||
context->Exit();
|
||||
|
||||
stdout.fileHandleForReading.readabilityHandler = nil;
|
||||
stderr.fileHandleForReading.readabilityHandler = nil;
|
||||
};
|
||||
|
||||
task.terminationHandler = ^(NSTask *) {
|
||||
@synchronized(task) {
|
||||
NSData *outputData = [[stdout fileHandleForReading] readDataToEndOfFile];
|
||||
NSString *output = [[NSString alloc] initWithData:outputData encoding:NSUTF8StringEncoding];
|
||||
NSData *errorData = [[stderr fileHandleForReading] readDataToEndOfFile];
|
||||
NSString *errorOutput = [[NSString alloc] initWithData:errorData encoding:NSUTF8StringEncoding];
|
||||
dispatch_sync(dispatch_get_main_queue(), ^() {
|
||||
taskTerminatedHandle(output, errorOutput);
|
||||
});
|
||||
[output release];
|
||||
[errorOutput release];
|
||||
}
|
||||
};
|
||||
|
||||
CefRefPtr<CefV8Value> stdoutFunction = options->GetValue("stdout");
|
||||
if (stdoutFunction->IsFunction()) {
|
||||
stdout.fileHandleForReading.readabilityHandler = ^(NSFileHandle *fileHandle) {
|
||||
@synchronized(task) {
|
||||
NSData *data = [fileHandle availableData];
|
||||
NSString *contents = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
|
||||
dispatch_sync(dispatch_get_main_queue(), ^() {
|
||||
outputHandle(contents, stdoutFunction);
|
||||
});
|
||||
[contents release];
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
CefRefPtr<CefV8Value> stderrFunction = options->GetValue("stderr");
|
||||
if (stderrFunction->IsFunction()) {
|
||||
stderr.fileHandleForReading.readabilityHandler = ^(NSFileHandle *fileHandle) {
|
||||
@synchronized(task) {
|
||||
NSData *data = [fileHandle availableData];
|
||||
NSString *contents = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
|
||||
dispatch_sync(dispatch_get_main_queue(), ^() {
|
||||
outputHandle(contents, stderrFunction);
|
||||
});
|
||||
[contents release];
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
CefRefPtr<CefV8Value> currentWorkingDirectory = options->GetValue("cwd");
|
||||
if (!currentWorkingDirectory->IsUndefined() && !currentWorkingDirectory->IsNull()) {
|
||||
[task setCurrentDirectoryPath:stringFromCefV8Value(currentWorkingDirectory)];
|
||||
}
|
||||
|
||||
[task launch];
|
||||
|
||||
return true;
|
||||
}
|
||||
else if (name == "getPlatform") {
|
||||
retval = CefV8Value::CreateString("mac");
|
||||
return true;
|
||||
}
|
||||
|
||||
else if (name == "setWindowState") {
|
||||
[windowStateLock lock];
|
||||
@@ -518,32 +162,8 @@ namespace v8_extensions {
|
||||
return true;
|
||||
}
|
||||
|
||||
else if (name == "isMisspelled") {
|
||||
NSString *word = stringFromCefV8Value(arguments[0]);
|
||||
NSSpellChecker *spellChecker = [NSSpellChecker sharedSpellChecker];
|
||||
@synchronized(spellChecker) {
|
||||
NSRange range = [spellChecker checkSpellingOfString:word startingAt:0];
|
||||
retval = CefV8Value::CreateBool(range.length > 0);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
else if (name == "getCorrectionsForMisspelling") {
|
||||
NSString *misspelling = stringFromCefV8Value(arguments[0]);
|
||||
NSSpellChecker *spellChecker = [NSSpellChecker sharedSpellChecker];
|
||||
@synchronized(spellChecker) {
|
||||
NSString *language = [spellChecker language];
|
||||
NSRange range;
|
||||
range.location = 0;
|
||||
range.length = [misspelling length];
|
||||
NSArray *guesses = [spellChecker guessesForWordRange:range inString:misspelling language:language inSpellDocumentWithTag:0];
|
||||
CefRefPtr<CefV8Value> v8Guesses = CefV8Value::CreateArray([guesses count]);
|
||||
for (int i = 0; i < [guesses count]; i++) {
|
||||
v8Guesses->SetValue(i, CefV8Value::CreateString([[guesses objectAtIndex:i] UTF8String]));
|
||||
}
|
||||
retval = v8Guesses;
|
||||
}
|
||||
return true;
|
||||
else if (name == "beep") {
|
||||
NSBeep();
|
||||
}
|
||||
|
||||
return false;
|
||||
@@ -551,7 +171,7 @@ namespace v8_extensions {
|
||||
};
|
||||
|
||||
NSString *stringFromCefV8Value(const CefRefPtr<CefV8Value>& value) {
|
||||
std::string cc_value = value->GetStringValue().ToString();
|
||||
string cc_value = value->GetStringValue().ToString();
|
||||
return [NSString stringWithUTF8String:cc_value.c_str()];
|
||||
}
|
||||
|
||||
@@ -559,7 +179,7 @@ namespace v8_extensions {
|
||||
CefV8ValueList arguments;
|
||||
|
||||
message = [message stringByAppendingFormat:@"\n%s", exception->GetMessage().ToString().c_str()];
|
||||
arguments.push_back(CefV8Value::CreateString(std::string([message UTF8String], [message lengthOfBytesUsingEncoding:NSUTF8StringEncoding])));
|
||||
arguments.push_back(CefV8Value::CreateString(string([message UTF8String], [message lengthOfBytesUsingEncoding:NSUTF8StringEncoding])));
|
||||
|
||||
CefRefPtr<CefV8Value> console = global->GetValue("console");
|
||||
console->GetValue("error")->ExecuteFunction(console, arguments);
|
||||
|
||||
@@ -515,8 +515,6 @@ bool NativeHandler::Execute(const CefString& name, CefRefPtr<CefV8Value> object,
|
||||
UnwatchPath(name, object, arguments, retval, exception);
|
||||
else if (name == "md5ForPath")
|
||||
Digest(name, object, arguments, retval, exception);
|
||||
else if (name == "getPlatform")
|
||||
retval = CefV8Value::CreateString("linux");
|
||||
else if (name == "lastModified")
|
||||
LastModified(name, object, arguments, retval, exception);
|
||||
else
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
#include "include/cef_base.h"
|
||||
#include "include/cef_v8.h"
|
||||
|
||||
namespace v8_extensions {
|
||||
|
||||
class OnigRegExp : public CefV8Handler {
|
||||
public:
|
||||
OnigRegExp();
|
||||
void CreateContextBinding(CefRefPtr<CefV8Context> context);
|
||||
virtual bool Execute(const CefString& name,
|
||||
CefRefPtr<CefV8Value> object,
|
||||
const CefV8ValueList& arguments,
|
||||
CefRefPtr<CefV8Value>& retval,
|
||||
CefString& exception) OVERRIDE;
|
||||
|
||||
// Provide the reference counting implementation for this class.
|
||||
IMPLEMENT_REFCOUNTING(OnigRegExp);
|
||||
|
||||
private:
|
||||
OnigRegExp(OnigRegExp const&);
|
||||
void operator=(OnigRegExp const&);
|
||||
};
|
||||
|
||||
}
|
||||
@@ -1,106 +0,0 @@
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#import <iostream>
|
||||
#import "CocoaOniguruma/OnigRegexp.h"
|
||||
#import "include/cef_base.h"
|
||||
#import "include/cef_v8.h"
|
||||
#import "onig_reg_exp.h"
|
||||
|
||||
namespace v8_extensions {
|
||||
|
||||
extern NSString *stringFromCefV8Value(const CefRefPtr<CefV8Value>& value);
|
||||
|
||||
class OnigRegExpUserData : public CefBase {
|
||||
public:
|
||||
OnigRegExpUserData(CefRefPtr<CefV8Value> source) {
|
||||
NSString *sourceString = [NSString stringWithUTF8String:source->GetStringValue().ToString().c_str()];
|
||||
m_regex = [[OnigRegexp compile:sourceString] retain];
|
||||
}
|
||||
|
||||
~OnigRegExpUserData() {
|
||||
[m_regex release];
|
||||
}
|
||||
|
||||
CefRefPtr<CefV8Value> Search(CefRefPtr<CefV8Value> string, CefRefPtr<CefV8Value> index) {
|
||||
OnigResult *result = [m_regex search:stringFromCefV8Value(string) start:index->GetIntValue()];
|
||||
|
||||
if ([result count] == 0) return CefV8Value::CreateNull();
|
||||
|
||||
CefRefPtr<CefV8Value> resultArray = CefV8Value::CreateArray(result.count);
|
||||
CefRefPtr<CefV8Value> indicesArray = CefV8Value::CreateArray(result.count);
|
||||
|
||||
for (int i = 0; i < [result count]; i++) {
|
||||
resultArray->SetValue(i, CefV8Value::CreateString([[result stringAt:i] UTF8String]));
|
||||
indicesArray->SetValue(i, CefV8Value::CreateInt([result locationAt:i]));
|
||||
}
|
||||
|
||||
resultArray->SetValue("index", CefV8Value::CreateInt([result locationAt:0]), V8_PROPERTY_ATTRIBUTE_NONE);
|
||||
resultArray->SetValue("indices", indicesArray, V8_PROPERTY_ATTRIBUTE_NONE);
|
||||
|
||||
return resultArray;
|
||||
}
|
||||
|
||||
CefRefPtr<CefV8Value> Test(CefRefPtr<CefV8Value> string, CefRefPtr<CefV8Value> index) {
|
||||
OnigResult *result = [m_regex search:stringFromCefV8Value(string) start:index->GetIntValue()];
|
||||
return CefV8Value::CreateBool(result);
|
||||
}
|
||||
|
||||
OnigRegexp *m_regex;
|
||||
|
||||
IMPLEMENT_REFCOUNTING(OnigRegexpUserData);
|
||||
};
|
||||
|
||||
OnigRegExp::OnigRegExp() : CefV8Handler() {
|
||||
}
|
||||
|
||||
void OnigRegExp::CreateContextBinding(CefRefPtr<CefV8Context> context) {
|
||||
const char* methodNames[] = { "search", "test", "buildOnigRegExp" };
|
||||
|
||||
CefRefPtr<CefV8Value> nativeObject = CefV8Value::CreateObject(NULL);
|
||||
int arrayLength = sizeof(methodNames) / sizeof(const char *);
|
||||
for (int i = 0; i < arrayLength; i++) {
|
||||
const char *functionName = methodNames[i];
|
||||
CefRefPtr<CefV8Value> function = CefV8Value::CreateFunction(functionName, this);
|
||||
nativeObject->SetValue(functionName, function, V8_PROPERTY_ATTRIBUTE_NONE);
|
||||
}
|
||||
|
||||
CefRefPtr<CefV8Value> global = context->GetGlobal();
|
||||
global->SetValue("$onigRegExp", nativeObject, V8_PROPERTY_ATTRIBUTE_NONE);
|
||||
}
|
||||
|
||||
bool OnigRegExp::Execute(const CefString& name,
|
||||
CefRefPtr<CefV8Value> object,
|
||||
const CefV8ValueList& arguments,
|
||||
CefRefPtr<CefV8Value>& retval,
|
||||
CefString& exception) {
|
||||
|
||||
@autoreleasepool {
|
||||
if (name == "search") {
|
||||
CefRefPtr<CefV8Value> string = arguments[0];
|
||||
CefRefPtr<CefV8Value> index = arguments.size() > 1 ? arguments[1] : CefV8Value::CreateInt(0);
|
||||
OnigRegExpUserData *userData = (OnigRegExpUserData *)object->GetUserData().get();
|
||||
retval = userData->Search(string, index);
|
||||
return true;
|
||||
}
|
||||
else if (name == "test") {
|
||||
CefRefPtr<CefV8Value> string = arguments[0];
|
||||
CefRefPtr<CefV8Value> index = arguments.size() > 1 ? arguments[1] : CefV8Value::CreateInt(0);
|
||||
OnigRegExpUserData *userData = (OnigRegExpUserData *)object->GetUserData().get();
|
||||
retval = userData->Test(string, index);
|
||||
return true;
|
||||
}
|
||||
else if (name == "buildOnigRegExp") {
|
||||
CefRefPtr<CefV8Value> pattern = arguments[0];
|
||||
CefRefPtr<OnigRegExpUserData> userData = new OnigRegExpUserData(pattern);
|
||||
if (!userData->m_regex) {
|
||||
exception = std::string("Failed to create OnigRegExp from pattern '") + pattern->GetStringValue().ToString() + "'";
|
||||
}
|
||||
retval = CefV8Value::CreateObject(NULL);
|
||||
retval->SetUserData((CefRefPtr<CefBase>)userData);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace v8_extensions
|
||||
@@ -1,228 +0,0 @@
|
||||
#include "onig_reg_exp.h"
|
||||
#include "include/cef_runnable.h"
|
||||
#include <oniguruma.h>
|
||||
#include <iostream>
|
||||
#include <stdlib.h>
|
||||
#include "io_utils.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace v8_extensions {
|
||||
|
||||
class OnigRegexpUserData: public CefBase {
|
||||
public:
|
||||
OnigRegexpUserData(CefRefPtr<CefV8Value> source) {
|
||||
OnigErrorInfo error;
|
||||
string input = source->GetStringValue().ToString();
|
||||
int length = input.length();
|
||||
UChar* pattern = (UChar*) input.c_str();
|
||||
int code = onig_new(®ex, pattern, pattern + length,
|
||||
ONIG_OPTION_SINGLELINE, ONIG_ENCODING_UTF8, ONIG_SYNTAX_DEFAULT,
|
||||
&error);
|
||||
if (code != ONIG_NORMAL) {
|
||||
char errorText[ONIG_MAX_ERROR_MESSAGE_LEN];
|
||||
onig_error_code_to_str((OnigUChar*) errorText, code, &error);
|
||||
cout << errorText << " for pattern: " << input << endl;
|
||||
}
|
||||
}
|
||||
|
||||
~OnigRegexpUserData() {
|
||||
onig_free(regex);
|
||||
}
|
||||
|
||||
OnigRegion* SearchRegion(string input, int index) {
|
||||
if (!regex)
|
||||
return NULL;
|
||||
|
||||
OnigRegion* region = onig_region_new();
|
||||
UChar* search = (UChar*) input.c_str();
|
||||
unsigned char* start = search + index;
|
||||
unsigned char* end = search + input.length();
|
||||
int code = onig_search(regex, search, end, start, end, region,
|
||||
ONIG_OPTION_NONE);
|
||||
if (code >= 0)
|
||||
return region;
|
||||
else {
|
||||
onig_region_free(region, 1);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
CefRefPtr<CefV8Value> Search(CefRefPtr<CefV8Value> argument,
|
||||
CefRefPtr<CefV8Value> index) {
|
||||
string input = argument->GetStringValue().ToString();
|
||||
OnigRegion* region = SearchRegion(input, index->GetIntValue());
|
||||
if (!region)
|
||||
return CefV8Value::CreateNull();
|
||||
|
||||
CefRefPtr<CefV8Value> indices;
|
||||
CefRefPtr<CefV8Value> resultArray = CefV8Value::CreateArray(
|
||||
region->num_regs);
|
||||
CefRefPtr<CefV8Value> indicesArray = CefV8Value::CreateArray(
|
||||
region->num_regs);
|
||||
for (int i = 0; i < region->num_regs; i++) {
|
||||
int begin = region->beg[i];
|
||||
int end = region->end[i];
|
||||
resultArray->SetValue(i,
|
||||
CefV8Value::CreateString(input.substr(begin, end - begin)));
|
||||
indicesArray->SetValue(i, CefV8Value::CreateInt(begin));
|
||||
}
|
||||
resultArray->SetValue("index", CefV8Value::CreateInt(region->beg[0]),
|
||||
V8_PROPERTY_ATTRIBUTE_NONE);
|
||||
resultArray->SetValue("indices", indicesArray, V8_PROPERTY_ATTRIBUTE_NONE);
|
||||
onig_region_free(region, 1);
|
||||
return resultArray;
|
||||
}
|
||||
|
||||
CefRefPtr<CefV8Value> Test(CefRefPtr<CefV8Value> argument,
|
||||
CefRefPtr<CefV8Value> index) {
|
||||
OnigRegion* region = SearchRegion(argument->GetStringValue().ToString(),
|
||||
index->GetIntValue());
|
||||
CefRefPtr<CefV8Value> text = CefV8Value::CreateBool(region != NULL);
|
||||
if (region)
|
||||
onig_region_free(region, 1);
|
||||
return text;
|
||||
}
|
||||
|
||||
CefRefPtr<CefV8Value> GetCaptureIndices(CefRefPtr<CefV8Value> argument,
|
||||
CefRefPtr<CefV8Value> index) {
|
||||
OnigRegion* region = SearchRegion(argument->GetStringValue().ToString(),
|
||||
index->GetIntValue());
|
||||
CefRefPtr<CefV8Value> indices;
|
||||
if (region) {
|
||||
indices = BuildCaptureIndices(region);
|
||||
onig_region_free(region, 1);
|
||||
} else
|
||||
indices = CefV8Value::CreateNull();
|
||||
return indices;
|
||||
}
|
||||
|
||||
CefRefPtr<CefV8Value> BuildCaptureIndices(OnigRegion *region) {
|
||||
CefRefPtr<CefV8Value> array = CefV8Value::CreateArray(region->num_regs * 3);
|
||||
int i = 0;
|
||||
for (int index = 0; index < region->num_regs; index++) {
|
||||
int begin = region->beg[index];
|
||||
int end = region->end[index];
|
||||
if (end - begin <= 0)
|
||||
continue;
|
||||
array->SetValue(i++, CefV8Value::CreateInt(index));
|
||||
array->SetValue(i++, CefV8Value::CreateInt(begin));
|
||||
array->SetValue(i++, CefV8Value::CreateInt(end));
|
||||
}
|
||||
|
||||
return array;
|
||||
}
|
||||
|
||||
CefRefPtr<CefV8Value> CaptureCount() {
|
||||
if (regex)
|
||||
return CefV8Value::CreateInt(onig_number_of_captures(regex));
|
||||
else
|
||||
return CefV8Value::CreateInt(0);
|
||||
}
|
||||
|
||||
regex_t* regex;
|
||||
|
||||
IMPLEMENT_REFCOUNTING(OnigRegexpUserData)
|
||||
;
|
||||
}
|
||||
;
|
||||
|
||||
OnigRegExp::OnigRegExp() :
|
||||
CefV8Handler() {
|
||||
string realFilePath = io_utils_real_app_path(
|
||||
"/native/v8_extensions/onig_reg_exp.js");
|
||||
if (!realFilePath.empty()) {
|
||||
string extensionCode;
|
||||
if (io_utils_read(realFilePath, &extensionCode) > 0)
|
||||
CefRegisterExtension("v8/onig-reg-exp", extensionCode, this);
|
||||
}
|
||||
}
|
||||
|
||||
bool OnigRegExp::Execute(const CefString& name,
|
||||
CefRefPtr<CefV8Value> object, const CefV8ValueList& arguments,
|
||||
CefRefPtr<CefV8Value>& retval, CefString& exception) {
|
||||
if (name == "captureIndices") {
|
||||
CefRefPtr<CefV8Value> string = arguments[0];
|
||||
CefRefPtr<CefV8Value> index = arguments[1];
|
||||
CefRefPtr<CefV8Value> regexes = arguments[2];
|
||||
|
||||
int bestIndex = -1;
|
||||
CefRefPtr<CefV8Value> captureIndicesForBestIndex;
|
||||
CefRefPtr<CefV8Value> captureIndices;
|
||||
|
||||
retval = CefV8Value::CreateObject(NULL);
|
||||
for (int i = 0; i < regexes->GetArrayLength(); i++) {
|
||||
OnigRegexpUserData *userData =
|
||||
(OnigRegexpUserData *) regexes->GetValue(i)->GetUserData().get();
|
||||
captureIndices = userData->GetCaptureIndices(string, index);
|
||||
if (captureIndices->IsNull())
|
||||
continue;
|
||||
|
||||
if (bestIndex == -1
|
||||
|| captureIndices->GetValue(1)->GetIntValue()
|
||||
< captureIndicesForBestIndex->GetValue(1)->GetIntValue()) {
|
||||
bestIndex = i;
|
||||
captureIndicesForBestIndex = captureIndices;
|
||||
if (captureIndices->GetValue(1)->GetIntValue() == 0)
|
||||
break; // If the match starts at 0, just use it!
|
||||
}
|
||||
}
|
||||
|
||||
if (bestIndex != -1) {
|
||||
retval->SetValue("index", CefV8Value::CreateInt(bestIndex),
|
||||
V8_PROPERTY_ATTRIBUTE_NONE);
|
||||
retval->SetValue("captureIndices", captureIndicesForBestIndex,
|
||||
V8_PROPERTY_ATTRIBUTE_NONE);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
if (name == "getCaptureIndices") {
|
||||
CefRefPtr<CefV8Value> string = arguments[0];
|
||||
CefRefPtr<CefV8Value> index =
|
||||
arguments.size() > 1 ? arguments[1] : CefV8Value::CreateInt(0);
|
||||
OnigRegexpUserData *userData =
|
||||
(OnigRegexpUserData *) object->GetUserData().get();
|
||||
retval = userData->GetCaptureIndices(string, index);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (name == "search") {
|
||||
CefRefPtr<CefV8Value> string = arguments[0];
|
||||
CefRefPtr<CefV8Value> index =
|
||||
arguments.size() > 1 ? arguments[1] : CefV8Value::CreateInt(0);
|
||||
OnigRegexpUserData *userData =
|
||||
(OnigRegexpUserData *) object->GetUserData().get();
|
||||
retval = userData->Search(string, index);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (name == "test") {
|
||||
CefRefPtr<CefV8Value> string = arguments[0];
|
||||
CefRefPtr<CefV8Value> index =
|
||||
arguments.size() > 1 ? arguments[1] : CefV8Value::CreateInt(0);
|
||||
OnigRegexpUserData *userData =
|
||||
(OnigRegexpUserData *) object->GetUserData().get();
|
||||
retval = userData->Test(string, index);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (name == "buildOnigRegExp") {
|
||||
CefRefPtr<CefBase> userData = new OnigRegexpUserData(arguments[0]);
|
||||
retval = CefV8Value::CreateObject(NULL);
|
||||
retval->SetUserData(userData);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (name == "getCaptureCount") {
|
||||
OnigRegexpUserData *userData =
|
||||
(OnigRegexpUserData *) object->GetUserData().get();
|
||||
retval = userData->CaptureCount();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
#include "include/cef_base.h"
|
||||
#include "include/cef_v8.h"
|
||||
|
||||
namespace v8_extensions {
|
||||
|
||||
class OnigScanner : public CefV8Handler {
|
||||
public:
|
||||
OnigScanner();
|
||||
void CreateContextBinding(CefRefPtr<CefV8Context> context);
|
||||
virtual bool Execute(const CefString& name,
|
||||
CefRefPtr<CefV8Value> object,
|
||||
const CefV8ValueList& arguments,
|
||||
CefRefPtr<CefV8Value>& retval,
|
||||
CefString& exception) OVERRIDE;
|
||||
|
||||
// Provide the reference counting implementation for this class.
|
||||
IMPLEMENT_REFCOUNTING(OnigRegExp);
|
||||
|
||||
private:
|
||||
OnigScanner(OnigScanner const&);
|
||||
void operator=(OnigScanner const&);
|
||||
};
|
||||
|
||||
}
|
||||
@@ -1,171 +0,0 @@
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#import <iostream>
|
||||
#import "CocoaOniguruma/OnigRegexp.h"
|
||||
#import "include/cef_base.h"
|
||||
#import "include/cef_v8.h"
|
||||
#import "onig_scanner.h"
|
||||
|
||||
namespace v8_extensions {
|
||||
|
||||
using namespace std;
|
||||
extern NSString *stringFromCefV8Value(const CefRefPtr<CefV8Value>& value);
|
||||
|
||||
class OnigScannerUserData : public CefBase {
|
||||
public:
|
||||
OnigScannerUserData(CefRefPtr<CefV8Value> sources) {
|
||||
int length = sources->GetArrayLength();
|
||||
|
||||
regExps.resize(length);
|
||||
cachedResults.resize(length);
|
||||
|
||||
for (int i = 0; i < length; i++) {
|
||||
NSString *sourceString = stringFromCefV8Value(sources->GetValue(i));
|
||||
regExps[i] = [[OnigRegexp compile:sourceString] retain];
|
||||
}
|
||||
}
|
||||
|
||||
~OnigScannerUserData() {
|
||||
for (vector<OnigRegexp *>::iterator iter = regExps.begin(); iter < regExps.end(); iter++) {
|
||||
[*iter release];
|
||||
}
|
||||
for (vector<OnigResult *>::iterator iter = cachedResults.begin(); iter < cachedResults.end(); iter++) {
|
||||
[*iter release];
|
||||
}
|
||||
}
|
||||
|
||||
CefRefPtr<CefV8Value> FindNextMatch(CefRefPtr<CefV8Value> v8String, CefRefPtr<CefV8Value> v8StartLocation) {
|
||||
|
||||
std::string string = v8String->GetStringValue().ToString();
|
||||
int startLocation = v8StartLocation->GetIntValue();
|
||||
int bestIndex = -1;
|
||||
int bestLocation = NULL;
|
||||
OnigResult *bestResult = NULL;
|
||||
|
||||
bool useCachedResults = (string == lastMatchedString && startLocation >= lastStartLocation);
|
||||
lastStartLocation = startLocation;
|
||||
|
||||
if (!useCachedResults) {
|
||||
ClearCachedResults();
|
||||
lastMatchedString = string;
|
||||
}
|
||||
|
||||
vector<OnigRegexp *>::iterator iter = regExps.begin();
|
||||
int index = 0;
|
||||
while (iter < regExps.end()) {
|
||||
OnigRegexp *regExp = *iter;
|
||||
|
||||
bool useCachedResult = false;
|
||||
OnigResult *result = NULL;
|
||||
|
||||
if (useCachedResults && index <= maxCachedIndex) {
|
||||
result = cachedResults[index];
|
||||
useCachedResult = (result == NULL || [result locationAt:0] >= startLocation);
|
||||
}
|
||||
|
||||
if (!useCachedResult) {
|
||||
result = [regExp search:[NSString stringWithUTF8String:string.c_str()] start:startLocation];
|
||||
cachedResults[index] = [result retain];
|
||||
maxCachedIndex = index;
|
||||
}
|
||||
|
||||
if ([result count] > 0) {
|
||||
int location = [result locationAt:0];
|
||||
if (bestIndex == -1 || location < bestLocation) {
|
||||
bestLocation = location;
|
||||
bestResult = result;
|
||||
bestIndex = index;
|
||||
}
|
||||
|
||||
if (location == startLocation) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
iter++;
|
||||
index++;
|
||||
}
|
||||
|
||||
if (bestIndex >= 0) {
|
||||
CefRefPtr<CefV8Value> result = CefV8Value::CreateObject(NULL);
|
||||
result->SetValue("index", CefV8Value::CreateInt(bestIndex), V8_PROPERTY_ATTRIBUTE_NONE);
|
||||
result->SetValue("captureIndices", CaptureIndicesForMatch(bestResult), V8_PROPERTY_ATTRIBUTE_NONE);
|
||||
return result;
|
||||
} else {
|
||||
return CefV8Value::CreateNull();
|
||||
}
|
||||
}
|
||||
|
||||
void ClearCachedResults() {
|
||||
maxCachedIndex = -1;
|
||||
for (vector<OnigResult *>::iterator iter = cachedResults.begin(); iter < cachedResults.end(); iter++) {
|
||||
[*iter release];
|
||||
*iter = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
CefRefPtr<CefV8Value> CaptureIndicesForMatch(OnigResult *result) {
|
||||
CefRefPtr<CefV8Value> array = CefV8Value::CreateArray([result count] * 3);
|
||||
int i = 0;
|
||||
int resultCount = [result count];
|
||||
for (int index = 0; index < resultCount; index++) {
|
||||
int captureLength = [result lengthAt:index];
|
||||
int captureStart = [result locationAt:index];
|
||||
|
||||
array->SetValue(i++, CefV8Value::CreateInt(index));
|
||||
array->SetValue(i++, CefV8Value::CreateInt(captureStart));
|
||||
array->SetValue(i++, CefV8Value::CreateInt(captureStart + captureLength));
|
||||
}
|
||||
|
||||
return array;
|
||||
}
|
||||
|
||||
protected:
|
||||
std::vector<OnigRegexp *> regExps;
|
||||
std::string lastMatchedString;
|
||||
std::vector<OnigResult *> cachedResults;
|
||||
int maxCachedIndex;
|
||||
int lastStartLocation;
|
||||
|
||||
IMPLEMENT_REFCOUNTING(OnigRegexpUserData);
|
||||
};
|
||||
|
||||
OnigScanner::OnigScanner() : CefV8Handler() {
|
||||
}
|
||||
|
||||
void OnigScanner::CreateContextBinding(CefRefPtr<CefV8Context> context) {
|
||||
const char* methodNames[] = { "findNextMatch", "buildScanner" };
|
||||
|
||||
CefRefPtr<CefV8Value> nativeObject = CefV8Value::CreateObject(NULL);
|
||||
int arrayLength = sizeof(methodNames) / sizeof(const char *);
|
||||
for (int i = 0; i < arrayLength; i++) {
|
||||
const char *functionName = methodNames[i];
|
||||
CefRefPtr<CefV8Value> function = CefV8Value::CreateFunction(functionName, this);
|
||||
nativeObject->SetValue(functionName, function, V8_PROPERTY_ATTRIBUTE_NONE);
|
||||
}
|
||||
|
||||
CefRefPtr<CefV8Value> global = context->GetGlobal();
|
||||
global->SetValue("$onigScanner", nativeObject, V8_PROPERTY_ATTRIBUTE_NONE);
|
||||
}
|
||||
|
||||
bool OnigScanner::Execute(const CefString& name,
|
||||
CefRefPtr<CefV8Value> object,
|
||||
const CefV8ValueList& arguments,
|
||||
CefRefPtr<CefV8Value>& retval,
|
||||
CefString& exception) {
|
||||
@autoreleasepool {
|
||||
if (name == "findNextMatch") {
|
||||
OnigScannerUserData *userData = (OnigScannerUserData *)object->GetUserData().get();
|
||||
retval = userData->FindNextMatch(arguments[0], arguments[1]);
|
||||
return true;
|
||||
}
|
||||
else if (name == "buildScanner") {
|
||||
retval = CefV8Value::CreateObject(NULL);
|
||||
retval->SetUserData(new OnigScannerUserData(arguments[0]));
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace v8_extensions
|
||||
@@ -1,970 +0,0 @@
|
||||
/*
|
||||
* $Id: readtags.c 592 2007-07-31 03:30:41Z dhiebert $
|
||||
*
|
||||
* Copyright (c) 1996-2003, Darren Hiebert
|
||||
*
|
||||
* This source code is released into the public domain.
|
||||
*
|
||||
* This module contains functions for reading tag files.
|
||||
*/
|
||||
|
||||
/*
|
||||
* INCLUDE FILES
|
||||
*/
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <sys/types.h> /* to declare off_t */
|
||||
|
||||
#include "readtags.h"
|
||||
|
||||
/*
|
||||
* MACROS
|
||||
*/
|
||||
#define TAB '\t'
|
||||
|
||||
|
||||
/*
|
||||
* DATA DECLARATIONS
|
||||
*/
|
||||
typedef struct {
|
||||
size_t size;
|
||||
char *buffer;
|
||||
} vstring;
|
||||
|
||||
/* Information about current tag file */
|
||||
struct sTagFile {
|
||||
/* has the file been opened and this structure initialized? */
|
||||
short initialized;
|
||||
/* format of tag file */
|
||||
short format;
|
||||
/* how is the tag file sorted? */
|
||||
sortType sortMethod;
|
||||
/* pointer to file structure */
|
||||
FILE* fp;
|
||||
/* file position of first character of `line' */
|
||||
off_t pos;
|
||||
/* size of tag file in seekable positions */
|
||||
off_t size;
|
||||
/* last line read */
|
||||
vstring line;
|
||||
/* name of tag in last line read */
|
||||
vstring name;
|
||||
/* defines tag search state */
|
||||
struct {
|
||||
/* file position of last match for tag */
|
||||
off_t pos;
|
||||
/* name of tag last searched for */
|
||||
char *name;
|
||||
/* length of name for partial matches */
|
||||
size_t nameLength;
|
||||
/* peforming partial match */
|
||||
short partial;
|
||||
/* ignoring case */
|
||||
short ignorecase;
|
||||
} search;
|
||||
/* miscellaneous extension fields */
|
||||
struct {
|
||||
/* number of entries in `list' */
|
||||
unsigned short max;
|
||||
/* list of key value pairs */
|
||||
tagExtensionField *list;
|
||||
} fields;
|
||||
/* buffers to be freed at close */
|
||||
struct {
|
||||
/* name of program author */
|
||||
char *author;
|
||||
/* name of program */
|
||||
char *name;
|
||||
/* URL of distribution */
|
||||
char *url;
|
||||
/* program version */
|
||||
char *version;
|
||||
} program;
|
||||
};
|
||||
|
||||
/*
|
||||
* DATA DEFINITIONS
|
||||
*/
|
||||
const char *const EmptyString = "";
|
||||
const char *const PseudoTagPrefix = "!_";
|
||||
|
||||
/*
|
||||
* FUNCTION DEFINITIONS
|
||||
*/
|
||||
|
||||
/*
|
||||
* Compare two strings, ignoring case.
|
||||
* Return 0 for match, < 0 for smaller, > 0 for bigger
|
||||
* Make sure case is folded to uppercase in comparison (like for 'sort -f')
|
||||
* This makes a difference when one of the chars lies between upper and lower
|
||||
* ie. one of the chars [ \ ] ^ _ ` for ascii. (The '_' in particular !)
|
||||
*/
|
||||
static int struppercmp (const char *s1, const char *s2)
|
||||
{
|
||||
int result;
|
||||
do
|
||||
{
|
||||
result = toupper ((int) *s1) - toupper ((int) *s2);
|
||||
} while (result == 0 && *s1++ != '\0' && *s2++ != '\0');
|
||||
return result;
|
||||
}
|
||||
|
||||
static int strnuppercmp (const char *s1, const char *s2, size_t n)
|
||||
{
|
||||
int result;
|
||||
do
|
||||
{
|
||||
result = toupper ((int) *s1) - toupper ((int) *s2);
|
||||
} while (result == 0 && --n > 0 && *s1++ != '\0' && *s2++ != '\0');
|
||||
return result;
|
||||
}
|
||||
|
||||
static int growString (vstring *s)
|
||||
{
|
||||
int result = 0;
|
||||
size_t newLength;
|
||||
char *newLine;
|
||||
if (s->size == 0)
|
||||
{
|
||||
newLength = 128;
|
||||
newLine = (char*) malloc (newLength);
|
||||
*newLine = '\0';
|
||||
}
|
||||
else
|
||||
{
|
||||
newLength = 2 * s->size;
|
||||
newLine = (char*) realloc (s->buffer, newLength);
|
||||
}
|
||||
if (newLine == NULL)
|
||||
perror ("string too large");
|
||||
else
|
||||
{
|
||||
s->buffer = newLine;
|
||||
s->size = newLength;
|
||||
result = 1;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/* Copy name of tag out of tag line */
|
||||
static void copyName (tagFile *const file)
|
||||
{
|
||||
size_t length;
|
||||
const char *end = strchr (file->line.buffer, '\t');
|
||||
if (end == NULL)
|
||||
{
|
||||
end = strchr (file->line.buffer, '\n');
|
||||
if (end == NULL)
|
||||
end = strchr (file->line.buffer, '\r');
|
||||
}
|
||||
if (end != NULL)
|
||||
length = end - file->line.buffer;
|
||||
else
|
||||
length = strlen (file->line.buffer);
|
||||
while (length >= file->name.size)
|
||||
growString (&file->name);
|
||||
strncpy (file->name.buffer, file->line.buffer, length);
|
||||
file->name.buffer [length] = '\0';
|
||||
}
|
||||
|
||||
static int readTagLineRaw (tagFile *const file)
|
||||
{
|
||||
int result = 1;
|
||||
int reReadLine;
|
||||
|
||||
/* If reading the line places any character other than a null or a
|
||||
* newline at the last character position in the buffer (one less than
|
||||
* the buffer size), then we must resize the buffer and reattempt to read
|
||||
* the line.
|
||||
*/
|
||||
do
|
||||
{
|
||||
char *const pLastChar = file->line.buffer + file->line.size - 2;
|
||||
char *line;
|
||||
|
||||
file->pos = ftell (file->fp);
|
||||
reReadLine = 0;
|
||||
*pLastChar = '\0';
|
||||
line = fgets (file->line.buffer, (int) file->line.size, file->fp);
|
||||
if (line == NULL)
|
||||
{
|
||||
/* read error */
|
||||
if (! feof (file->fp))
|
||||
perror ("readTagLine");
|
||||
result = 0;
|
||||
}
|
||||
else if (*pLastChar != '\0' &&
|
||||
*pLastChar != '\n' && *pLastChar != '\r')
|
||||
{
|
||||
/* buffer overflow */
|
||||
growString (&file->line);
|
||||
fseek (file->fp, file->pos, SEEK_SET);
|
||||
reReadLine = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
size_t i = strlen (file->line.buffer);
|
||||
while (i > 0 &&
|
||||
(file->line.buffer [i - 1] == '\n' || file->line.buffer [i - 1] == '\r'))
|
||||
{
|
||||
file->line.buffer [i - 1] = '\0';
|
||||
--i;
|
||||
}
|
||||
}
|
||||
} while (reReadLine && result);
|
||||
if (result)
|
||||
copyName (file);
|
||||
return result;
|
||||
}
|
||||
|
||||
static int readTagLine (tagFile *const file)
|
||||
{
|
||||
int result;
|
||||
do
|
||||
{
|
||||
result = readTagLineRaw (file);
|
||||
} while (result && *file->name.buffer == '\0');
|
||||
return result;
|
||||
}
|
||||
|
||||
static tagResult growFields (tagFile *const file)
|
||||
{
|
||||
tagResult result = TagFailure;
|
||||
unsigned short newCount = (unsigned short) 2 * file->fields.max;
|
||||
tagExtensionField *newFields = (tagExtensionField*)
|
||||
realloc (file->fields.list, newCount * sizeof (tagExtensionField));
|
||||
if (newFields == NULL)
|
||||
perror ("too many extension fields");
|
||||
else
|
||||
{
|
||||
file->fields.list = newFields;
|
||||
file->fields.max = newCount;
|
||||
result = TagSuccess;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
static void parseExtensionFields (tagFile *const file, tagEntry *const entry,
|
||||
char *const string)
|
||||
{
|
||||
char *p = string;
|
||||
while (p != NULL && *p != '\0')
|
||||
{
|
||||
while (*p == TAB)
|
||||
*p++ = '\0';
|
||||
if (*p != '\0')
|
||||
{
|
||||
char *colon;
|
||||
char *field = p;
|
||||
p = strchr (p, TAB);
|
||||
if (p != NULL)
|
||||
*p++ = '\0';
|
||||
colon = strchr (field, ':');
|
||||
if (colon == NULL)
|
||||
entry->kind = field;
|
||||
else
|
||||
{
|
||||
const char *key = field;
|
||||
const char *value = colon + 1;
|
||||
*colon = '\0';
|
||||
if (strcmp (key, "kind") == 0)
|
||||
entry->kind = value;
|
||||
else if (strcmp (key, "file") == 0)
|
||||
entry->fileScope = 1;
|
||||
else if (strcmp (key, "line") == 0)
|
||||
entry->address.lineNumber = atol (value);
|
||||
else
|
||||
{
|
||||
if (entry->fields.count == file->fields.max)
|
||||
growFields (file);
|
||||
file->fields.list [entry->fields.count].key = key;
|
||||
file->fields.list [entry->fields.count].value = value;
|
||||
++entry->fields.count;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void parseTagLine (tagFile *file, tagEntry *const entry)
|
||||
{
|
||||
int i;
|
||||
char *p = file->line.buffer;
|
||||
char *tab = strchr (p, TAB);
|
||||
|
||||
entry->fields.list = NULL;
|
||||
entry->fields.count = 0;
|
||||
entry->kind = NULL;
|
||||
entry->fileScope = 0;
|
||||
|
||||
entry->name = p;
|
||||
if (tab != NULL)
|
||||
{
|
||||
*tab = '\0';
|
||||
p = tab + 1;
|
||||
entry->file = p;
|
||||
tab = strchr (p, TAB);
|
||||
if (tab != NULL)
|
||||
{
|
||||
int fieldsPresent;
|
||||
*tab = '\0';
|
||||
p = tab + 1;
|
||||
if (*p == '/' || *p == '?')
|
||||
{
|
||||
/* parse pattern */
|
||||
int delimiter = *(unsigned char*) p;
|
||||
entry->address.lineNumber = 0;
|
||||
entry->address.pattern = p;
|
||||
do
|
||||
{
|
||||
p = strchr (p + 1, delimiter);
|
||||
if (p == NULL)
|
||||
break;
|
||||
if (*(p - 1) != '\\')
|
||||
break;
|
||||
// Make sure preceding backslash isn't an escaped backslash by
|
||||
// advancing backwards and counting the number of backslashes
|
||||
int slashCount = 1;
|
||||
while (*(p - slashCount - 1) == '\\')
|
||||
slashCount++;
|
||||
if (slashCount % 2 == 0)
|
||||
break;
|
||||
} while (1);
|
||||
if (p == NULL)
|
||||
{
|
||||
/* invalid pattern */
|
||||
}
|
||||
else
|
||||
++p;
|
||||
}
|
||||
else if (isdigit ((int) *(unsigned char*) p))
|
||||
{
|
||||
/* parse line number */
|
||||
entry->address.pattern = p;
|
||||
entry->address.lineNumber = atol (p);
|
||||
while (isdigit ((int) *(unsigned char*) p))
|
||||
++p;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* invalid pattern */
|
||||
}
|
||||
fieldsPresent = (strncmp (p, ";\"", 2) == 0);
|
||||
*p = '\0';
|
||||
if (fieldsPresent)
|
||||
parseExtensionFields (file, entry, p + 2);
|
||||
}
|
||||
}
|
||||
if (entry->fields.count > 0)
|
||||
entry->fields.list = file->fields.list;
|
||||
for (i = entry->fields.count ; i < file->fields.max ; ++i)
|
||||
{
|
||||
file->fields.list [i].key = NULL;
|
||||
file->fields.list [i].value = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static char *duplicate (const char *str)
|
||||
{
|
||||
char *result = NULL;
|
||||
if (str != NULL)
|
||||
{
|
||||
result = strdup (str);
|
||||
if (result == NULL)
|
||||
perror (NULL);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
static void readPseudoTags (tagFile *const file, tagFileInfo *const info)
|
||||
{
|
||||
fpos_t startOfLine;
|
||||
const size_t prefixLength = strlen (PseudoTagPrefix);
|
||||
if (info != NULL)
|
||||
{
|
||||
info->file.format = 1;
|
||||
info->file.sort = TAG_UNSORTED;
|
||||
info->program.author = NULL;
|
||||
info->program.name = NULL;
|
||||
info->program.url = NULL;
|
||||
info->program.version = NULL;
|
||||
}
|
||||
while (1)
|
||||
{
|
||||
fgetpos (file->fp, &startOfLine);
|
||||
if (! readTagLine (file))
|
||||
break;
|
||||
if (strncmp (file->line.buffer, PseudoTagPrefix, prefixLength) != 0)
|
||||
break;
|
||||
else
|
||||
{
|
||||
tagEntry entry;
|
||||
const char *key, *value;
|
||||
parseTagLine (file, &entry);
|
||||
key = entry.name + prefixLength;
|
||||
value = entry.file;
|
||||
if (strcmp (key, "TAG_FILE_SORTED") == 0)
|
||||
file->sortMethod = (sortType) atoi (value);
|
||||
else if (strcmp (key, "TAG_FILE_FORMAT") == 0)
|
||||
file->format = (short) atoi (value);
|
||||
else if (strcmp (key, "TAG_PROGRAM_AUTHOR") == 0)
|
||||
file->program.author = duplicate (value);
|
||||
else if (strcmp (key, "TAG_PROGRAM_NAME") == 0)
|
||||
file->program.name = duplicate (value);
|
||||
else if (strcmp (key, "TAG_PROGRAM_URL") == 0)
|
||||
file->program.url = duplicate (value);
|
||||
else if (strcmp (key, "TAG_PROGRAM_VERSION") == 0)
|
||||
file->program.version = duplicate (value);
|
||||
if (info != NULL)
|
||||
{
|
||||
info->file.format = file->format;
|
||||
info->file.sort = file->sortMethod;
|
||||
info->program.author = file->program.author;
|
||||
info->program.name = file->program.name;
|
||||
info->program.url = file->program.url;
|
||||
info->program.version = file->program.version;
|
||||
}
|
||||
}
|
||||
}
|
||||
fsetpos (file->fp, &startOfLine);
|
||||
}
|
||||
|
||||
static void gotoFirstLogicalTag (tagFile *const file)
|
||||
{
|
||||
fpos_t startOfLine;
|
||||
const size_t prefixLength = strlen (PseudoTagPrefix);
|
||||
rewind (file->fp);
|
||||
while (1)
|
||||
{
|
||||
fgetpos (file->fp, &startOfLine);
|
||||
if (! readTagLine (file))
|
||||
break;
|
||||
if (strncmp (file->line.buffer, PseudoTagPrefix, prefixLength) != 0)
|
||||
break;
|
||||
}
|
||||
fsetpos (file->fp, &startOfLine);
|
||||
}
|
||||
|
||||
static tagFile *initialize (const char *const filePath, tagFileInfo *const info)
|
||||
{
|
||||
tagFile *result = (tagFile*) calloc ((size_t) 1, sizeof (tagFile));
|
||||
if (result != NULL)
|
||||
{
|
||||
growString (&result->line);
|
||||
growString (&result->name);
|
||||
result->fields.max = 20;
|
||||
result->fields.list = (tagExtensionField*) calloc (
|
||||
result->fields.max, sizeof (tagExtensionField));
|
||||
result->fp = fopen (filePath, "r");
|
||||
if (result->fp == NULL)
|
||||
{
|
||||
free (result);
|
||||
result = NULL;
|
||||
info->status.error_number = errno;
|
||||
}
|
||||
else
|
||||
{
|
||||
fseek (result->fp, 0, SEEK_END);
|
||||
result->size = ftell (result->fp);
|
||||
rewind (result->fp);
|
||||
readPseudoTags (result, info);
|
||||
info->status.opened = 1;
|
||||
result->initialized = 1;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
static void terminate (tagFile *const file)
|
||||
{
|
||||
fclose (file->fp);
|
||||
|
||||
free (file->line.buffer);
|
||||
free (file->name.buffer);
|
||||
free (file->fields.list);
|
||||
|
||||
if (file->program.author != NULL)
|
||||
free (file->program.author);
|
||||
if (file->program.name != NULL)
|
||||
free (file->program.name);
|
||||
if (file->program.url != NULL)
|
||||
free (file->program.url);
|
||||
if (file->program.version != NULL)
|
||||
free (file->program.version);
|
||||
if (file->search.name != NULL)
|
||||
free (file->search.name);
|
||||
|
||||
memset (file, 0, sizeof (tagFile));
|
||||
|
||||
free (file);
|
||||
}
|
||||
|
||||
static tagResult readNext (tagFile *const file, tagEntry *const entry)
|
||||
{
|
||||
tagResult result;
|
||||
if (file == NULL || ! file->initialized)
|
||||
result = TagFailure;
|
||||
else if (! readTagLine (file))
|
||||
result = TagFailure;
|
||||
else
|
||||
{
|
||||
if (entry != NULL)
|
||||
parseTagLine (file, entry);
|
||||
result = TagSuccess;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
static const char *readFieldValue (
|
||||
const tagEntry *const entry, const char *const key)
|
||||
{
|
||||
const char *result = NULL;
|
||||
int i;
|
||||
if (strcmp (key, "kind") == 0)
|
||||
result = entry->kind;
|
||||
else if (strcmp (key, "file") == 0)
|
||||
result = EmptyString;
|
||||
else for (i = 0 ; i < entry->fields.count && result == NULL ; ++i)
|
||||
if (strcmp (entry->fields.list [i].key, key) == 0)
|
||||
result = entry->fields.list [i].value;
|
||||
return result;
|
||||
}
|
||||
|
||||
static int readTagLineSeek (tagFile *const file, const off_t pos)
|
||||
{
|
||||
int result = 0;
|
||||
if (fseek (file->fp, pos, SEEK_SET) == 0)
|
||||
{
|
||||
result = readTagLine (file); /* read probable partial line */
|
||||
if (pos > 0 && result)
|
||||
result = readTagLine (file); /* read complete line */
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
static int nameComparison (tagFile *const file)
|
||||
{
|
||||
int result;
|
||||
if (file->search.ignorecase)
|
||||
{
|
||||
if (file->search.partial)
|
||||
result = strnuppercmp (file->search.name, file->name.buffer,
|
||||
file->search.nameLength);
|
||||
else
|
||||
result = struppercmp (file->search.name, file->name.buffer);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (file->search.partial)
|
||||
result = strncmp (file->search.name, file->name.buffer,
|
||||
file->search.nameLength);
|
||||
else
|
||||
result = strcmp (file->search.name, file->name.buffer);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
static void findFirstNonMatchBefore (tagFile *const file)
|
||||
{
|
||||
#define JUMP_BACK 512
|
||||
int more_lines;
|
||||
int comp;
|
||||
off_t start = file->pos;
|
||||
off_t pos = start;
|
||||
do
|
||||
{
|
||||
if (pos < (off_t) JUMP_BACK)
|
||||
pos = 0;
|
||||
else
|
||||
pos = pos - JUMP_BACK;
|
||||
more_lines = readTagLineSeek (file, pos);
|
||||
comp = nameComparison (file);
|
||||
} while (more_lines && comp == 0 && pos > 0 && pos < start);
|
||||
}
|
||||
|
||||
static tagResult findFirstMatchBefore (tagFile *const file)
|
||||
{
|
||||
tagResult result = TagFailure;
|
||||
int more_lines;
|
||||
off_t start = file->pos;
|
||||
findFirstNonMatchBefore (file);
|
||||
do
|
||||
{
|
||||
more_lines = readTagLine (file);
|
||||
if (nameComparison (file) == 0)
|
||||
result = TagSuccess;
|
||||
} while (more_lines && result != TagSuccess && file->pos < start);
|
||||
return result;
|
||||
}
|
||||
|
||||
static tagResult findBinary (tagFile *const file)
|
||||
{
|
||||
tagResult result = TagFailure;
|
||||
off_t lower_limit = 0;
|
||||
off_t upper_limit = file->size;
|
||||
off_t last_pos = 0;
|
||||
off_t pos = upper_limit / 2;
|
||||
while (result != TagSuccess)
|
||||
{
|
||||
if (! readTagLineSeek (file, pos))
|
||||
{
|
||||
/* in case we fell off end of file */
|
||||
result = findFirstMatchBefore (file);
|
||||
break;
|
||||
}
|
||||
else if (pos == last_pos)
|
||||
{
|
||||
/* prevent infinite loop if we backed up to beginning of file */
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
const int comp = nameComparison (file);
|
||||
last_pos = pos;
|
||||
if (comp < 0)
|
||||
{
|
||||
upper_limit = pos;
|
||||
pos = lower_limit + ((upper_limit - lower_limit) / 2);
|
||||
}
|
||||
else if (comp > 0)
|
||||
{
|
||||
lower_limit = pos;
|
||||
pos = lower_limit + ((upper_limit - lower_limit) / 2);
|
||||
}
|
||||
else if (pos == 0)
|
||||
result = TagSuccess;
|
||||
else
|
||||
result = findFirstMatchBefore (file);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
static tagResult findSequential (tagFile *const file)
|
||||
{
|
||||
tagResult result = TagFailure;
|
||||
if (file->initialized)
|
||||
{
|
||||
while (result == TagFailure && readTagLine (file))
|
||||
{
|
||||
if (nameComparison (file) == 0)
|
||||
result = TagSuccess;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
static tagResult find (tagFile *const file, tagEntry *const entry,
|
||||
const char *const name, const int options)
|
||||
{
|
||||
tagResult result;
|
||||
if (file->search.name != NULL)
|
||||
free (file->search.name);
|
||||
file->search.name = duplicate (name);
|
||||
file->search.nameLength = strlen (name);
|
||||
file->search.partial = (options & TAG_PARTIALMATCH) != 0;
|
||||
file->search.ignorecase = (options & TAG_IGNORECASE) != 0;
|
||||
fseek (file->fp, 0, SEEK_END);
|
||||
file->size = ftell (file->fp);
|
||||
rewind (file->fp);
|
||||
if ((file->sortMethod == TAG_SORTED && !file->search.ignorecase) ||
|
||||
(file->sortMethod == TAG_FOLDSORTED && file->search.ignorecase))
|
||||
{
|
||||
#ifdef DEBUG
|
||||
printf ("<performing binary search>\n");
|
||||
#endif
|
||||
result = findBinary (file);
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef DEBUG
|
||||
printf ("<performing sequential search>\n");
|
||||
#endif
|
||||
result = findSequential (file);
|
||||
}
|
||||
|
||||
if (result != TagSuccess)
|
||||
file->search.pos = file->size;
|
||||
else
|
||||
{
|
||||
file->search.pos = file->pos;
|
||||
if (entry != NULL)
|
||||
parseTagLine (file, entry);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
static tagResult findNext (tagFile *const file, tagEntry *const entry)
|
||||
{
|
||||
tagResult result;
|
||||
if ((file->sortMethod == TAG_SORTED && !file->search.ignorecase) ||
|
||||
(file->sortMethod == TAG_FOLDSORTED && file->search.ignorecase))
|
||||
{
|
||||
result = tagsNext (file, entry);
|
||||
if (result == TagSuccess && nameComparison (file) != 0)
|
||||
result = TagFailure;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = findSequential (file);
|
||||
if (result == TagSuccess && entry != NULL)
|
||||
parseTagLine (file, entry);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
* EXTERNAL INTERFACE
|
||||
*/
|
||||
|
||||
extern tagFile *tagsOpen (const char *const filePath, tagFileInfo *const info)
|
||||
{
|
||||
return initialize (filePath, info);
|
||||
}
|
||||
|
||||
extern tagResult tagsSetSortType (tagFile *const file, const sortType type)
|
||||
{
|
||||
tagResult result = TagFailure;
|
||||
if (file != NULL && file->initialized)
|
||||
{
|
||||
file->sortMethod = type;
|
||||
result = TagSuccess;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
extern tagResult tagsFirst (tagFile *const file, tagEntry *const entry)
|
||||
{
|
||||
tagResult result = TagFailure;
|
||||
if (file != NULL && file->initialized)
|
||||
{
|
||||
gotoFirstLogicalTag (file);
|
||||
result = readNext (file, entry);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
extern tagResult tagsNext (tagFile *const file, tagEntry *const entry)
|
||||
{
|
||||
tagResult result = TagFailure;
|
||||
if (file != NULL && file->initialized)
|
||||
result = readNext (file, entry);
|
||||
return result;
|
||||
}
|
||||
|
||||
extern const char *tagsField (const tagEntry *const entry, const char *const key)
|
||||
{
|
||||
const char *result = NULL;
|
||||
if (entry != NULL)
|
||||
result = readFieldValue (entry, key);
|
||||
return result;
|
||||
}
|
||||
|
||||
extern tagResult tagsFind (tagFile *const file, tagEntry *const entry,
|
||||
const char *const name, const int options)
|
||||
{
|
||||
tagResult result = TagFailure;
|
||||
if (file != NULL && file->initialized)
|
||||
result = find (file, entry, name, options);
|
||||
return result;
|
||||
}
|
||||
|
||||
extern tagResult tagsFindNext (tagFile *const file, tagEntry *const entry)
|
||||
{
|
||||
tagResult result = TagFailure;
|
||||
if (file != NULL && file->initialized)
|
||||
result = findNext (file, entry);
|
||||
return result;
|
||||
}
|
||||
|
||||
extern tagResult tagsClose (tagFile *const file)
|
||||
{
|
||||
tagResult result = TagFailure;
|
||||
if (file != NULL && file->initialized)
|
||||
{
|
||||
terminate (file);
|
||||
result = TagSuccess;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
* TEST FRAMEWORK
|
||||
*/
|
||||
|
||||
#ifdef READTAGS_MAIN
|
||||
|
||||
static const char *TagFileName = "tags";
|
||||
static const char *ProgramName;
|
||||
static int extensionFields;
|
||||
static int SortOverride;
|
||||
static sortType SortMethod;
|
||||
|
||||
static void printTag (const tagEntry *entry)
|
||||
{
|
||||
int i;
|
||||
int first = 1;
|
||||
const char* separator = ";\"";
|
||||
const char* const empty = "";
|
||||
/* "sep" returns a value only the first time it is evaluated */
|
||||
#define sep (first ? (first = 0, separator) : empty)
|
||||
printf ("%s\t%s\t%s",
|
||||
entry->name, entry->file, entry->address.pattern);
|
||||
if (extensionFields)
|
||||
{
|
||||
if (entry->kind != NULL && entry->kind [0] != '\0')
|
||||
printf ("%s\tkind:%s", sep, entry->kind);
|
||||
if (entry->fileScope)
|
||||
printf ("%s\tfile:", sep);
|
||||
#if 0
|
||||
if (entry->address.lineNumber > 0)
|
||||
printf ("%s\tline:%lu", sep, entry->address.lineNumber);
|
||||
#endif
|
||||
for (i = 0 ; i < entry->fields.count ; ++i)
|
||||
printf ("%s\t%s:%s", sep, entry->fields.list [i].key,
|
||||
entry->fields.list [i].value);
|
||||
}
|
||||
putchar ('\n');
|
||||
#undef sep
|
||||
}
|
||||
|
||||
static void findTag (const char *const name, const int options)
|
||||
{
|
||||
tagFileInfo info;
|
||||
tagEntry entry;
|
||||
tagFile *const file = tagsOpen (TagFileName, &info);
|
||||
if (file == NULL)
|
||||
{
|
||||
fprintf (stderr, "%s: cannot open tag file: %s: %s\n",
|
||||
ProgramName, strerror (info.status.error_number), name);
|
||||
exit (1);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (SortOverride)
|
||||
tagsSetSortType (file, SortMethod);
|
||||
if (tagsFind (file, &entry, name, options) == TagSuccess)
|
||||
{
|
||||
do
|
||||
{
|
||||
printTag (&entry);
|
||||
} while (tagsFindNext (file, &entry) == TagSuccess);
|
||||
}
|
||||
tagsClose (file);
|
||||
}
|
||||
}
|
||||
|
||||
static void listTags (void)
|
||||
{
|
||||
tagFileInfo info;
|
||||
tagEntry entry;
|
||||
tagFile *const file = tagsOpen (TagFileName, &info);
|
||||
if (file == NULL)
|
||||
{
|
||||
fprintf (stderr, "%s: cannot open tag file: %s: %s\n",
|
||||
ProgramName, strerror (info.status.error_number), TagFileName);
|
||||
exit (1);
|
||||
}
|
||||
else
|
||||
{
|
||||
while (tagsNext (file, &entry) == TagSuccess)
|
||||
printTag (&entry);
|
||||
tagsClose (file);
|
||||
}
|
||||
}
|
||||
|
||||
const char *const Usage =
|
||||
"Find tag file entries matching specified names.\n\n"
|
||||
"Usage: %s [-ilp] [-s[0|1]] [-t file] [name(s)]\n\n"
|
||||
"Options:\n"
|
||||
" -e Include extension fields in output.\n"
|
||||
" -i Perform case-insensitive matching.\n"
|
||||
" -l List all tags.\n"
|
||||
" -p Perform partial matching.\n"
|
||||
" -s[0|1|2] Override sort detection of tag file.\n"
|
||||
" -t file Use specified tag file (default: \"tags\").\n"
|
||||
"Note that options are acted upon as encountered, so order is significant.\n";
|
||||
|
||||
extern int main (int argc, char **argv)
|
||||
{
|
||||
int options = 0;
|
||||
int actionSupplied = 0;
|
||||
int i;
|
||||
ProgramName = argv [0];
|
||||
if (argc == 1)
|
||||
{
|
||||
fprintf (stderr, Usage, ProgramName);
|
||||
exit (1);
|
||||
}
|
||||
for (i = 1 ; i < argc ; ++i)
|
||||
{
|
||||
const char *const arg = argv [i];
|
||||
if (arg [0] != '-')
|
||||
{
|
||||
findTag (arg, options);
|
||||
actionSupplied = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
size_t j;
|
||||
for (j = 1 ; arg [j] != '\0' ; ++j)
|
||||
{
|
||||
switch (arg [j])
|
||||
{
|
||||
case 'e': extensionFields = 1; break;
|
||||
case 'i': options |= TAG_IGNORECASE; break;
|
||||
case 'p': options |= TAG_PARTIALMATCH; break;
|
||||
case 'l': listTags (); actionSupplied = 1; break;
|
||||
|
||||
case 't':
|
||||
if (arg [j+1] != '\0')
|
||||
{
|
||||
TagFileName = arg + j + 1;
|
||||
j += strlen (TagFileName);
|
||||
}
|
||||
else if (i + 1 < argc)
|
||||
TagFileName = argv [++i];
|
||||
else
|
||||
{
|
||||
fprintf (stderr, Usage, ProgramName);
|
||||
exit (1);
|
||||
}
|
||||
break;
|
||||
case 's':
|
||||
SortOverride = 1;
|
||||
++j;
|
||||
if (arg [j] == '\0')
|
||||
SortMethod = TAG_SORTED;
|
||||
else if (strchr ("012", arg[j]) != NULL)
|
||||
SortMethod = (sortType) (arg[j] - '0');
|
||||
else
|
||||
{
|
||||
fprintf (stderr, Usage, ProgramName);
|
||||
exit (1);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
fprintf (stderr, "%s: unknown option: %c\n",
|
||||
ProgramName, arg[j]);
|
||||
exit (1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (! actionSupplied)
|
||||
{
|
||||
fprintf (stderr,
|
||||
"%s: no action specified: specify tag name(s) or -l option\n",
|
||||
ProgramName);
|
||||
exit (1);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* vi:set tabstop=4 shiftwidth=4: */
|
||||
@@ -1,252 +0,0 @@
|
||||
/*
|
||||
* $Id: readtags.h 443 2006-05-30 04:37:13Z darren $
|
||||
*
|
||||
* Copyright (c) 1996-2003, Darren Hiebert
|
||||
*
|
||||
* This source code is released for the public domain.
|
||||
*
|
||||
* This file defines the public interface for looking up tag entries in tag
|
||||
* files.
|
||||
*
|
||||
* The functions defined in this interface are intended to provide tag file
|
||||
* support to a software tool. The tag lookups provided are sufficiently fast
|
||||
* enough to permit opening a sorted tag file, searching for a matching tag,
|
||||
* then closing the tag file each time a tag is looked up (search times are
|
||||
* on the order of hundreths of a second, even for huge tag files). This is
|
||||
* the recommended use of this library for most tool applications. Adhering
|
||||
* to this approach permits a user to regenerate a tag file at will without
|
||||
* the tool needing to detect and resynchronize with changes to the tag file.
|
||||
* Even for an unsorted 24MB tag file, tag searches take about one second.
|
||||
*/
|
||||
#ifndef READTAGS_H
|
||||
#define READTAGS_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*
|
||||
* MACROS
|
||||
*/
|
||||
|
||||
/* Options for tagsSetSortType() */
|
||||
typedef enum {
|
||||
TAG_UNSORTED, TAG_SORTED, TAG_FOLDSORTED
|
||||
} sortType ;
|
||||
|
||||
/* Options for tagsFind() */
|
||||
#define TAG_FULLMATCH 0x0
|
||||
#define TAG_PARTIALMATCH 0x1
|
||||
|
||||
#define TAG_OBSERVECASE 0x0
|
||||
#define TAG_IGNORECASE 0x2
|
||||
|
||||
/*
|
||||
* DATA DECLARATIONS
|
||||
*/
|
||||
|
||||
typedef enum { TagFailure = 0, TagSuccess = 1 } tagResult;
|
||||
|
||||
struct sTagFile;
|
||||
|
||||
typedef struct sTagFile tagFile;
|
||||
|
||||
/* This structure contains information about the tag file. */
|
||||
typedef struct {
|
||||
|
||||
struct {
|
||||
/* was the tag file successfully opened? */
|
||||
int opened;
|
||||
|
||||
/* errno value when 'opened' is false */
|
||||
int error_number;
|
||||
} status;
|
||||
|
||||
/* information about the structure of the tag file */
|
||||
struct {
|
||||
/* format of tag file (1 = original, 2 = extended) */
|
||||
short format;
|
||||
|
||||
/* how is the tag file sorted? */
|
||||
sortType sort;
|
||||
} file;
|
||||
|
||||
|
||||
/* information about the program which created this tag file */
|
||||
struct {
|
||||
/* name of author of generating program (may be null) */
|
||||
const char *author;
|
||||
|
||||
/* name of program (may be null) */
|
||||
const char *name;
|
||||
|
||||
/* URL of distribution (may be null) */
|
||||
const char *url;
|
||||
|
||||
/* program version (may be null) */
|
||||
const char *version;
|
||||
} program;
|
||||
|
||||
} tagFileInfo;
|
||||
|
||||
/* This structure contains information about an extension field for a tag.
|
||||
* These exist at the end of the tag in the form "key:value").
|
||||
*/
|
||||
typedef struct {
|
||||
|
||||
/* the key of the extension field */
|
||||
const char *key;
|
||||
|
||||
/* the value of the extension field (may be an empty string) */
|
||||
const char *value;
|
||||
|
||||
} tagExtensionField;
|
||||
|
||||
/* This structure contains information about a specific tag. */
|
||||
typedef struct {
|
||||
|
||||
/* name of tag */
|
||||
const char *name;
|
||||
|
||||
/* path of source file containing definition of tag */
|
||||
const char *file;
|
||||
|
||||
/* address for locating tag in source file */
|
||||
struct {
|
||||
/* pattern for locating source line
|
||||
* (may be NULL if not present) */
|
||||
const char *pattern;
|
||||
|
||||
/* line number in source file of tag definition
|
||||
* (may be zero if not known) */
|
||||
unsigned long lineNumber;
|
||||
} address;
|
||||
|
||||
/* kind of tag (may by name, character, or NULL if not known) */
|
||||
const char *kind;
|
||||
|
||||
/* is tag of file-limited scope? */
|
||||
short fileScope;
|
||||
|
||||
/* miscellaneous extension fields */
|
||||
struct {
|
||||
/* number of entries in `list' */
|
||||
unsigned short count;
|
||||
|
||||
/* list of key value pairs */
|
||||
tagExtensionField *list;
|
||||
} fields;
|
||||
|
||||
} tagEntry;
|
||||
|
||||
|
||||
/*
|
||||
* FUNCTION PROTOTYPES
|
||||
*/
|
||||
|
||||
/*
|
||||
* This function must be called before calling other functions in this
|
||||
* library. It is passed the path to the tag file to read and a (possibly
|
||||
* null) pointer to a structure which, if not null, will be populated with
|
||||
* information about the tag file. If successful, the function will return a
|
||||
* handle which must be supplied to other calls to read information from the
|
||||
* tag file, and info.status.opened will be set to true. If unsuccessful,
|
||||
* info.status.opened will be set to false and info.status.error_number will
|
||||
* be set to the errno value representing the system error preventing the tag
|
||||
* file from being successfully opened.
|
||||
*/
|
||||
extern tagFile *tagsOpen (const char *const filePath, tagFileInfo *const info);
|
||||
|
||||
/*
|
||||
* This function allows the client to override the normal automatic detection
|
||||
* of how a tag file is sorted. Permissible values for `type' are
|
||||
* TAG_UNSORTED, TAG_SORTED, TAG_FOLDSORTED. Tag files in the new extended
|
||||
* format contain a key indicating whether or not they are sorted. However,
|
||||
* tag files in the original format do not contain such a key even when
|
||||
* sorted, preventing this library from taking advantage of fast binary
|
||||
* lookups. If the client knows that such an unmarked tag file is indeed
|
||||
* sorted (or not), it can override the automatic detection. Note that
|
||||
* incorrect lookup results will result if a tag file is marked as sorted when
|
||||
* it actually is not. The function will return TagSuccess if called on an
|
||||
* open tag file or TagFailure if not.
|
||||
*/
|
||||
extern tagResult tagsSetSortType (tagFile *const file, const sortType type);
|
||||
|
||||
/*
|
||||
* Reads the first tag in the file, if any. It is passed the handle to an
|
||||
* opened tag file and a (possibly null) pointer to a structure which, if not
|
||||
* null, will be populated with information about the first tag file entry.
|
||||
* The function will return TagSuccess another tag entry is found, or
|
||||
* TagFailure if not (i.e. it reached end of file).
|
||||
*/
|
||||
extern tagResult tagsFirst (tagFile *const file, tagEntry *const entry);
|
||||
|
||||
/*
|
||||
* Step to the next tag in the file, if any. It is passed the handle to an
|
||||
* opened tag file and a (possibly null) pointer to a structure which, if not
|
||||
* null, will be populated with information about the next tag file entry. The
|
||||
* function will return TagSuccess another tag entry is found, or TagFailure
|
||||
* if not (i.e. it reached end of file). It will always read the first tag in
|
||||
* the file immediately after calling tagsOpen().
|
||||
*/
|
||||
extern tagResult tagsNext (tagFile *const file, tagEntry *const entry);
|
||||
|
||||
/*
|
||||
* Retrieve the value associated with the extension field for a specified key.
|
||||
* It is passed a pointer to a structure already populated with values by a
|
||||
* previous call to tagsNext(), tagsFind(), or tagsFindNext(), and a string
|
||||
* containing the key of the desired extension field. If no such field of the
|
||||
* specified key exists, the function will return null.
|
||||
*/
|
||||
extern const char *tagsField (const tagEntry *const entry, const char *const key);
|
||||
|
||||
/*
|
||||
* Find the first tag matching `name'. The structure pointed to by `entry'
|
||||
* will be populated with information about the tag file entry. If a tag file
|
||||
* is sorted using the C locale, a binary search algorithm is used to search
|
||||
* the tag file, resulting in very fast tag lookups, even in huge tag files.
|
||||
* Various options controlling the matches can be combined by bit-wise or-ing
|
||||
* certain values together. The available values are:
|
||||
*
|
||||
* TAG_PARTIALMATCH
|
||||
* Tags whose leading characters match `name' will qualify.
|
||||
*
|
||||
* TAG_FULLMATCH
|
||||
* Only tags whose full lengths match `name' will qualify.
|
||||
*
|
||||
* TAG_IGNORECASE
|
||||
* Matching will be performed in a case-insenstive manner. Note that
|
||||
* this disables binary searches of the tag file.
|
||||
*
|
||||
* TAG_OBSERVECASE
|
||||
* Matching will be performed in a case-senstive manner. Note that
|
||||
* this enables binary searches of the tag file.
|
||||
*
|
||||
* The function will return TagSuccess if a tag matching the name is found, or
|
||||
* TagFailure if not.
|
||||
*/
|
||||
extern tagResult tagsFind (tagFile *const file, tagEntry *const entry, const char *const name, const int options);
|
||||
|
||||
/*
|
||||
* Find the next tag matching the name and options supplied to the most recent
|
||||
* call to tagsFind() for the same tag file. The structure pointed to by
|
||||
* `entry' will be populated with information about the tag file entry. The
|
||||
* function will return TagSuccess if another tag matching the name is found,
|
||||
* or TagFailure if not.
|
||||
*/
|
||||
extern tagResult tagsFindNext (tagFile *const file, tagEntry *const entry);
|
||||
|
||||
/*
|
||||
* Call tagsTerminate() at completion of reading the tag file, which will
|
||||
* close the file and free any internal memory allocated. The function will
|
||||
* return TagFailure is no file is currently open, TagSuccess otherwise.
|
||||
*/
|
||||
extern tagResult tagsClose (tagFile *const file);
|
||||
|
||||
#ifdef __cplusplus
|
||||
};
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/* vi:set tabstop=4 shiftwidth=4: */
|
||||
@@ -1,26 +0,0 @@
|
||||
#include "include/cef_base.h"
|
||||
#include "include/cef_v8.h"
|
||||
#include "readtags.h"
|
||||
|
||||
namespace v8_extensions {
|
||||
|
||||
class Tags : public CefV8Handler {
|
||||
public:
|
||||
Tags();
|
||||
void CreateContextBinding(CefRefPtr<CefV8Context> context);
|
||||
virtual bool Execute(const CefString& name,
|
||||
CefRefPtr<CefV8Value> object,
|
||||
const CefV8ValueList& arguments,
|
||||
CefRefPtr<CefV8Value>& retval,
|
||||
CefString& exception) OVERRIDE;
|
||||
|
||||
// Provide the reference counting implementation for this class.
|
||||
IMPLEMENT_REFCOUNTING(Tags);
|
||||
|
||||
private:
|
||||
Tags(Tags const&);
|
||||
void operator=(Tags const&);
|
||||
CefRefPtr<CefV8Value> ParseEntry(tagEntry entry);
|
||||
};
|
||||
|
||||
}
|
||||
@@ -1,116 +0,0 @@
|
||||
#import "tags.h"
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
namespace v8_extensions {
|
||||
|
||||
Tags::Tags() : CefV8Handler() {
|
||||
}
|
||||
|
||||
void Tags::CreateContextBinding(CefRefPtr<CefV8Context> context) {
|
||||
const char* methodNames[] = { "find", "getAllTagsAsync" };
|
||||
|
||||
CefRefPtr<CefV8Value> nativeObject = CefV8Value::CreateObject(NULL);
|
||||
int arrayLength = sizeof(methodNames) / sizeof(const char *);
|
||||
for (int i = 0; i < arrayLength; i++) {
|
||||
const char *functionName = methodNames[i];
|
||||
CefRefPtr<CefV8Value> function = CefV8Value::CreateFunction(functionName, this);
|
||||
nativeObject->SetValue(functionName, function, V8_PROPERTY_ATTRIBUTE_NONE);
|
||||
}
|
||||
|
||||
CefRefPtr<CefV8Value> global = context->GetGlobal();
|
||||
global->SetValue("$tags", nativeObject, V8_PROPERTY_ATTRIBUTE_NONE);
|
||||
}
|
||||
|
||||
CefRefPtr<CefV8Value> Tags::ParseEntry(tagEntry entry) {
|
||||
CefRefPtr<CefV8Value> tagEntry = CefV8Value::CreateObject(NULL);
|
||||
tagEntry->SetValue("name", CefV8Value::CreateString(entry.name), V8_PROPERTY_ATTRIBUTE_NONE);
|
||||
tagEntry->SetValue("file", CefV8Value::CreateString(entry.file), V8_PROPERTY_ATTRIBUTE_NONE);
|
||||
if (entry.address.pattern) {
|
||||
tagEntry->SetValue("pattern", CefV8Value::CreateString(entry.address.pattern), V8_PROPERTY_ATTRIBUTE_NONE);
|
||||
}
|
||||
return tagEntry;
|
||||
}
|
||||
|
||||
bool Tags::Execute(const CefString& name,
|
||||
CefRefPtr<CefV8Value> object,
|
||||
const CefV8ValueList& arguments,
|
||||
CefRefPtr<CefV8Value>& retval,
|
||||
CefString& exception) {
|
||||
|
||||
@autoreleasepool {
|
||||
if (name == "find") {
|
||||
std::string path = arguments[0]->GetStringValue().ToString();
|
||||
std::string tag = arguments[1]->GetStringValue().ToString();
|
||||
tagFileInfo info;
|
||||
tagFile* tagFile;
|
||||
tagFile = tagsOpen(path.c_str(), &info);
|
||||
if (info.status.opened) {
|
||||
tagEntry entry;
|
||||
std::vector<CefRefPtr<CefV8Value>> entries;
|
||||
if (tagsFind(tagFile, &entry, tag.c_str(), TAG_FULLMATCH | TAG_OBSERVECASE) == TagSuccess) {
|
||||
entries.push_back(ParseEntry(entry));
|
||||
while (tagsFindNext(tagFile, &entry) == TagSuccess) {
|
||||
entries.push_back(ParseEntry(entry));
|
||||
}
|
||||
}
|
||||
|
||||
retval = CefV8Value::CreateArray(entries.size());
|
||||
for (int i = 0; i < entries.size(); i++) {
|
||||
retval->SetValue(i, entries[i]);
|
||||
}
|
||||
tagsClose(tagFile);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
if (name == "getAllTagsAsync") {
|
||||
std::string path = arguments[0]->GetStringValue().ToString();
|
||||
CefRefPtr<CefV8Value> callback = arguments[1];
|
||||
CefRefPtr<CefV8Context> context = CefV8Context::GetCurrentContext();
|
||||
|
||||
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
|
||||
dispatch_async(queue, ^{
|
||||
tagFileInfo info;
|
||||
tagFile* tagFile;
|
||||
tagFile = tagsOpen(path.c_str(), &info);
|
||||
std::vector<tagEntry> entries;
|
||||
|
||||
if (info.status.opened) {
|
||||
tagEntry entry;
|
||||
while (tagsNext(tagFile, &entry) == TagSuccess) {
|
||||
entry.name = strdup(entry.name);
|
||||
entry.file = strdup(entry.file);
|
||||
if (entry.address.pattern) {
|
||||
entry.address.pattern = strdup(entry.address.pattern);
|
||||
}
|
||||
entries.push_back(entry);
|
||||
}
|
||||
tagsClose(tagFile);
|
||||
}
|
||||
|
||||
dispatch_queue_t mainQueue = dispatch_get_main_queue();
|
||||
dispatch_async(mainQueue, ^{
|
||||
context->Enter();
|
||||
CefRefPtr<CefV8Value> v8Tags = CefV8Value::CreateArray(entries.size());
|
||||
for (int i = 0; i < entries.size(); i++) {
|
||||
v8Tags->SetValue(i, ParseEntry(entries[i]));
|
||||
free((void*)entries[i].name);
|
||||
free((void*)entries[i].file);
|
||||
if (entries[i].address.pattern) {
|
||||
free((void*)entries[i].address.pattern);
|
||||
}
|
||||
}
|
||||
CefV8ValueList callbackArgs;
|
||||
callbackArgs.push_back(v8Tags);
|
||||
callback->ExecuteFunction(callback, callbackArgs);
|
||||
context->Exit();
|
||||
});
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
16
package.json
16
package.json
@@ -3,9 +3,23 @@
|
||||
"version" : "0.0.0",
|
||||
|
||||
"dependencies": {
|
||||
"coffee-script": "1.5"
|
||||
"coffee-script": "1.5",
|
||||
"ctags": "0.3.0",
|
||||
"oniguruma": "0.8.0",
|
||||
"mkdirp": "0.3.5",
|
||||
"git-utils": "0.8.0",
|
||||
"underscore": "1.4.4",
|
||||
"d3": "3.0.8",
|
||||
"coffee-cache": "0.1.0",
|
||||
"pegjs": "0.7.0",
|
||||
"async": "0.2.6",
|
||||
"spellchecker": "0.2.0",
|
||||
"plist": "git://github.com/nathansobo/node-plist.git",
|
||||
"space-pen": "git://github.com/nathansobo/space-pen.git"
|
||||
},
|
||||
|
||||
"private": true,
|
||||
|
||||
"scripts": {
|
||||
"preinstall": "true"
|
||||
}
|
||||
|
||||
Submodule prebuilt-cef updated: 3ced0be187...59d147be26
@@ -18,6 +18,15 @@ exit_unless_npm_exists() {
|
||||
exit_unless_xcode_exists
|
||||
exit_unless_npm_exists
|
||||
|
||||
npm install
|
||||
npm install npm --silent
|
||||
|
||||
NODE_DIR="$HOME/.cefode-gyp"
|
||||
NODE_VERSION="0.10.1"
|
||||
NODE_URL="https://gh-contractor-zcbenz.s3.amazonaws.com/cefode2/dist"
|
||||
if [ ! -d "node_modules/node-gyp" ]; then
|
||||
./node_modules/.bin/npm install node-gyp --silent
|
||||
HOME="$NODE_DIR" ./node_modules/.bin/node-gyp install --target="$NODE_VERSION" --dist-url="$NODE_URL" --arch=ia32
|
||||
fi
|
||||
HOME="$NODE_DIR" ./node_modules/.bin/npm install --target="$NODE_VERSION" --arch=ia32 --silent
|
||||
git submodule --quiet sync
|
||||
git submodule --quiet update --recursive --init
|
||||
|
||||
@@ -8,7 +8,7 @@ unless inputFile?.length > 0
|
||||
|
||||
outputFile = process.argv[3]
|
||||
unless outputFile?.length > 0
|
||||
console.error("Output file must be second arguments")
|
||||
console.error("Output file must be second argument")
|
||||
process.exit(1)
|
||||
|
||||
contents = fs.readFileSync(inputFile)?.toString() ? ''
|
||||
|
||||
21
script/compile-less
Normal file
21
script/compile-less
Normal file
@@ -0,0 +1,21 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -e
|
||||
|
||||
# Because of the way xcodebuild invokes external scripts we need to load
|
||||
# The Setup's environment ourselves. If this isn't done, things like the
|
||||
# node shim won't be able to find the stuff they need.
|
||||
|
||||
node --version > /dev/null 2>&1 || {
|
||||
if [ -e /opt/github/env.sh ]; then
|
||||
source /opt/github/env.sh
|
||||
else
|
||||
# Try Constructicon's PATH.
|
||||
export PATH="/usr/local/Cellar/node/0.8.21/bin:${PATH}"
|
||||
fi
|
||||
}
|
||||
|
||||
INPUT_FILE="${1}"
|
||||
OUTPUT_FILE="${2}"
|
||||
|
||||
node_modules/.bin/coffee script/compile-less.coffee -- "${INPUT_FILE}" "${OUTPUT_FILE}"
|
||||
25
script/compile-less.coffee
Normal file
25
script/compile-less.coffee
Normal file
@@ -0,0 +1,25 @@
|
||||
# Hack since the vendored less is in browser mode
|
||||
global.window = {}
|
||||
global.document =
|
||||
getElementsByTagName: -> []
|
||||
global.location =
|
||||
port: 80
|
||||
|
||||
{less} = require '../vendor/less'
|
||||
fs = require 'fs'
|
||||
|
||||
inputFile = process.argv[2]
|
||||
unless inputFile?.length > 0
|
||||
console.error("Input file must be first argument")
|
||||
process.exit(1)
|
||||
|
||||
outputFile = process.argv[3]
|
||||
unless outputFile?.length > 0
|
||||
console.error("Output file must be second argument")
|
||||
process.exit(1)
|
||||
|
||||
contents = fs.readFileSync(inputFile)?.toString() ? ''
|
||||
(new less.Parser).parse contents, (e, tree) ->
|
||||
console.error(e.stack or e) if e
|
||||
process.exit(1) if e
|
||||
fs.writeFileSync(outputFile, tree.toCSS())
|
||||
@@ -7,4 +7,9 @@ COMPILED_SOURCES_DIR="${1}"
|
||||
RESOUCES_PATH="$BUILT_PRODUCTS_DIR/$UNLOCALIZED_RESOURCES_FOLDER_PATH"
|
||||
|
||||
# Copy non-coffee files into bundle
|
||||
rsync --archive --recursive --exclude="src/**/*.coffee" --exclude="src/**/*.cson" src static vendor spec benchmark themes dot-atom atom.sh "${COMPILED_SOURCES_DIR}/" "$RESOUCES_PATH"
|
||||
rsync --archive --recursive \
|
||||
--exclude="src/**/*.coffee" --exclude="src/**/*.cson" \
|
||||
--exclude="src/**/*.less" --exclude="static/*.less" \
|
||||
--exclude="node_modules/less" \
|
||||
node_modules src static vendor spec benchmark themes dot-atom atom.sh \
|
||||
"${COMPILED_SOURCES_DIR}/" "$RESOUCES_PATH"
|
||||
|
||||
@@ -27,6 +27,9 @@ $(find_files '*.coffee' | file_list)
|
||||
'cson_sources': [
|
||||
$(find_files '*.cson' | file_list)
|
||||
],
|
||||
'less_sources': [
|
||||
$(find src static -type file -name '*.less' | file_list)
|
||||
],
|
||||
},
|
||||
}
|
||||
EOF
|
||||
|
||||
56
script/translate-crash-log-addresses.coffee
Executable file
56
script/translate-crash-log-addresses.coffee
Executable file
@@ -0,0 +1,56 @@
|
||||
#!/usr/bin/env coffee
|
||||
# Usage:
|
||||
# Copy the crash log into pasteboard and then run
|
||||
# pbpaste | ./script/translate-crash-log-addresses.coffee
|
||||
|
||||
atos = (addresses, callback) ->
|
||||
path = require 'path'
|
||||
exec = require('child_process').exec
|
||||
|
||||
cwd = path.join __dirname, '..'
|
||||
exec 'atos -o cef/Release/libcef.dylib -arch i386 '.concat(addresses...), cwd: cwd, (error, stdout, stderr) ->
|
||||
throw error if error?
|
||||
callback stdout.split('\n')
|
||||
|
||||
parse_stack_trace = (raw) ->
|
||||
lines = {}
|
||||
addresses = []
|
||||
for line in raw
|
||||
columns = line.split /\ +/
|
||||
if columns[1] == 'libcef.dylib' and /0x[a-f0-9]+/.test columns[3]
|
||||
lines[columns[0]] = addresses.length
|
||||
addresses.push '0x' + parseInt(columns[5]).toString(16) + ' '
|
||||
|
||||
atos addresses, (parsed) ->
|
||||
for line in raw
|
||||
columns = line.split /\ +/
|
||||
frame = columns[0]
|
||||
if lines[frame]?
|
||||
console.log frame, parsed[lines[frame]]
|
||||
else
|
||||
console.log line
|
||||
|
||||
parse_log_file = (content) ->
|
||||
state = 'start'
|
||||
stack_trace = []
|
||||
lines = content.split /\r?\n/
|
||||
|
||||
for line in lines
|
||||
if state == 'start'
|
||||
if /Thread \d+ Crashed::/.test line
|
||||
console.log line
|
||||
state = 'parse'
|
||||
else if state == 'parse'
|
||||
break if line == ''
|
||||
stack_trace.push line
|
||||
|
||||
parse_stack_trace stack_trace
|
||||
|
||||
input = ''
|
||||
process.stdin.resume()
|
||||
process.stdin.setEncoding 'utf8'
|
||||
process.stdin.on 'data', (chunk) ->
|
||||
input += chunk
|
||||
process.stdin.on 'end', ->
|
||||
parse_log_file input
|
||||
|
||||
48
script/update-cefode
Executable file
48
script/update-cefode
Executable file
@@ -0,0 +1,48 @@
|
||||
#!/bin/bash
|
||||
|
||||
cd "$( dirname "${BASH_SOURCE[0]}" )/.."
|
||||
|
||||
if [[ $1 == '-s' ]]; then
|
||||
SYMBOLS=1
|
||||
shift
|
||||
fi
|
||||
|
||||
if [ -z $1 ]; then
|
||||
TARGET='cef'
|
||||
else
|
||||
TARGET=$1
|
||||
fi
|
||||
|
||||
DISTURL="https://gh-contractor-zcbenz.s3.amazonaws.com/cefode2/prebuilt-cef"
|
||||
CEF_BASENAME="cef_binary_3.1423.1133_macosx"
|
||||
CEF_SYMBOLS_BASENAME="${CEF_BASENAME}_symbols"
|
||||
|
||||
TEMP_DIR=$(mktemp -d -t prebuilt-cef-download.XXXXXX)
|
||||
trap "rm -rf \"${TEMP_DIR}\"" EXIT
|
||||
|
||||
# Latest version
|
||||
if ! LATEST_VERSION=$(curl -fsSkL $DISTURL/version); then
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
# Current version
|
||||
CURRENT_VERSION=`cat cef/version 2>&1`
|
||||
|
||||
if [[ $LATEST_VERSION != $CURRENT_VERSION ]]; then
|
||||
echo "Downloading/extracting cefode2 u${LATEST_VERSION}..."
|
||||
curl --progress-bar "${DISTURL}/cef_binary_latest.zip" > "${TEMP_DIR}/cef.zip"
|
||||
unzip -q "${TEMP_DIR}/cef.zip" -d "${TEMP_DIR}"
|
||||
[ -e "${TARGET}" ] && rm -rf "${TARGET}"
|
||||
mv "${TEMP_DIR}/${CEF_BASENAME}" "${TARGET}"
|
||||
echo ${LATEST_VERSION} > 'cef/version'
|
||||
fi
|
||||
|
||||
if [[ "${SYMBOLS}" != "1" ]]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo "Downloading/extracting symbols for cefode2 u${LATEST_VERSION}..."
|
||||
curl --progress-bar "${DISTURL}/cef_binary_latest_symbols.zip" > "${TEMP_DIR}/symbols.zip"
|
||||
unzip -q "${TEMP_DIR}/symbols.zip" -d "${TEMP_DIR}"
|
||||
mv "${TEMP_DIR}/${CEF_SYMBOLS_BASENAME}"/* "${TARGET}/Release"
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user