summaryrefslogtreecommitdiff
path: root/include/git2
diff options
context:
space:
mode:
authorChris Young <chris@unsatisfactorysoftware.co.uk>2012-06-07 20:29:22 +0100
committerChris Young <chris@unsatisfactorysoftware.co.uk>2012-06-07 20:29:22 +0100
commitc3f35902f3f951de5ce5193409f336ee45c682b6 (patch)
treee7329cc1496e676a65fb108bb9e830437e5ced7f /include/git2
parentcada414a8044307b28f7a4c75986e5473bb4bc1c (diff)
parentcddb8efe564738873a4cf9ac63b7976d74035ae9 (diff)
downloadlibgit2-c3f35902f3f951de5ce5193409f336ee45c682b6.tar.gz
Merge remote-tracking branch 'source/development' into update-test
Merging main libgit2! Conflicts: CMakeLists.txt src/unix/map.c
Diffstat (limited to 'include/git2')
-rw-r--r--include/git2/attr.h224
-rw-r--r--include/git2/blob.h111
-rw-r--r--include/git2/branch.h122
-rw-r--r--include/git2/commit.h160
-rw-r--r--include/git2/common.h92
-rw-r--r--include/git2/config.h281
-rw-r--r--include/git2/diff.h362
-rw-r--r--include/git2/errors.h147
-rw-r--r--include/git2/index.h116
-rw-r--r--include/git2/indexer.h121
-rw-r--r--include/git2/inttypes.h305
-rw-r--r--include/git2/merge.h35
-rw-r--r--include/git2/net.h51
-rw-r--r--include/git2/notes.h139
-rw-r--r--include/git2/object.h42
-rw-r--r--include/git2/odb.h98
-rw-r--r--include/git2/odb_backend.h42
-rw-r--r--include/git2/oid.h120
-rw-r--r--include/git2/reflog.h128
-rw-r--r--include/git2/refs.h216
-rw-r--r--include/git2/refspec.h68
-rw-r--r--include/git2/remote.h243
-rw-r--r--include/git2/repository.h337
-rw-r--r--include/git2/revwalk.h120
-rw-r--r--include/git2/signature.h36
-rw-r--r--include/git2/status.h164
-rw-r--r--include/git2/stdint.h247
-rw-r--r--include/git2/submodule.h103
-rw-r--r--include/git2/tag.h234
-rw-r--r--include/git2/thread-utils.h71
-rw-r--r--include/git2/threads.h48
-rw-r--r--include/git2/tree.h122
-rw-r--r--include/git2/types.h77
-rw-r--r--include/git2/version.h15
-rw-r--r--include/git2/windows.h59
-rw-r--r--include/git2/zlib.h58
36 files changed, 3758 insertions, 1156 deletions
diff --git a/include/git2/attr.h b/include/git2/attr.h
new file mode 100644
index 000000000..8f5a1268d
--- /dev/null
+++ b/include/git2/attr.h
@@ -0,0 +1,224 @@
+/*
+ * Copyright (C) 2009-2012 the libgit2 contributors
+ *
+ * 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) ((attr) == git_attr__true)
+
+/**
+ * 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) ((attr) == git_attr__false)
+
+/**
+ * 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) (!(attr) || (attr) == git_attr__unset)
+
+/**
+ * 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) \
+ ((attr) && (attr) != git_attr__unset && \
+ (attr) != git_attr__true && (attr) != git_attr__false)
+
+GIT_EXTERN(const char *) git_attr__true;
+GIT_EXTERN(const char *) git_attr__false;
+GIT_EXTERN(const char *) git_attr__unset;
+
+/**
+ * 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);
+
+/**
+ * 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 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 callback The function that will be invoked on each attribute
+ * and attribute value. The name parameter will be the name
+ * of the attribute and the value will be the value it is
+ * set to, including possibly NULL if the attribute is
+ * explicitly set to UNSPECIFIED using the ! sign. This
+ * 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.
+ * @param payload Passed on as extra parameter to callback function.
+ */
+GIT_EXTERN(int) git_attr_foreach(
+ git_repository *repo,
+ uint32_t flags,
+ const char *path,
+ int (*callback)(const char *name, const char *value, void *payload),
+ 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
+
diff --git a/include/git2/blob.h b/include/git2/blob.h
index 0e05d6f89..544dc7c41 100644
--- a/include/git2/blob.h
+++ b/include/git2/blob.h
@@ -1,26 +1,8 @@
/*
- * This file is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, version 2,
- * as published by the Free Software Foundation.
- *
- * In addition to the permissions in the GNU General Public License,
- * the authors give you unlimited permission to link the compiled
- * version of this file into combinations with other programs,
- * and to distribute those combinations without any restriction
- * coming from the use of this file. (The General Public License
- * restrictions do apply in other respects; for example, they cover
- * modification of the file, and distribution when not linked into
- * a combined executable.)
- *
- * This file is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; see the file COPYING. If not, write to
- * the Free Software Foundation, 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
+ * Copyright (C) 2009-2012 the libgit2 contributors
+ *
+ * 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__
@@ -45,7 +27,7 @@ GIT_BEGIN_DECL
* @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 on success; error code otherwise
+ * @return 0 or an error code
*/
GIT_INLINE(int) git_blob_lookup(git_blob **blob, git_repository *repo, const git_oid *id)
{
@@ -53,9 +35,26 @@ GIT_INLINE(int) git_blob_lookup(git_blob **blob, git_repository *repo, const git
}
/**
+ * 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, unsigned int 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_close()
+ * This is a wrapper around git_object_free()
*
* IMPORTANT:
* It *is* necessary to call this method when you stop
@@ -64,9 +63,9 @@ GIT_INLINE(int) git_blob_lookup(git_blob **blob, git_repository *repo, const git
* @param blob the blob to close
*/
-GIT_INLINE(void) git_blob_close(git_blob *blob)
+GIT_INLINE(void) git_blob_free(git_blob *blob)
{
- git_object_close((git_object *) blob);
+ git_object_free((git_object *) blob);
}
@@ -89,7 +88,7 @@ GIT_EXTERN(const void *) git_blob_rawcontent(git_blob *blob);
* @param blob pointer to the blob
* @return size on bytes
*/
-GIT_EXTERN(int) git_blob_rawsize(git_blob *blob);
+GIT_EXTERN(size_t) git_blob_rawsize(git_blob *blob);
/**
* Read a file from the working folder of a repository
@@ -100,10 +99,64 @@ GIT_EXTERN(int) git_blob_rawsize(git_blob *blob);
* this repository cannot be bare
* @param path file from which the blob will be created,
* relative to the repository's working dir
- * @return 0 on success; error code otherwise
+ * @return 0 or an error code
*/
GIT_EXTERN(int) git_blob_create_fromfile(git_oid *oid, git_repository *repo, const char *path);
+/**
+ * Read a file from the filesystem and write its content
+ * to the Object Database as a loose blob
+ *
+ * @param oid 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 *oid, git_repository *repo, const char *path);
+
+/**
+ * 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 oid 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 *oid,
+ git_repository *repo,
+ const char *hintpath,
+ int (*source_cb)(char *content, size_t max_length, void *payload),
+ void *payload);
/**
* Write an in-memory buffer to the ODB as a blob
@@ -112,7 +165,7 @@ GIT_EXTERN(int) git_blob_create_fromfile(git_oid *oid, git_repository *repo, con
* @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 on success; error code otherwise
+ * @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);
diff --git a/include/git2/branch.h b/include/git2/branch.h
new file mode 100644
index 000000000..e2432bcfc
--- /dev/null
+++ b/include/git2/branch.h
@@ -0,0 +1,122 @@
+/*
+ * Copyright (C) 2009-2012 the libgit2 contributors
+ *
+ * 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 "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.
+ *
+ * @param oid_out Pointer where to store the OID of the target commit.
+ *
+ * @param repo Repository where to store the branch.
+ *
+ * @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 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_oid *oid_out,
+ git_repository *repo,
+ const char *branch_name,
+ const git_object *target,
+ int force);
+
+/**
+ * Delete an existing branch reference.
+ *
+ * @param repo Repository where lives the branch.
+ *
+ * @param branch_name Name of the branch to be deleted;
+ * 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 if the branch
+ * doesn't exist or an error code.
+ */
+GIT_EXTERN(int) git_branch_delete(
+ git_repository *repo,
+ const char *branch_name,
+ git_branch_t branch_type);
+
+/**
+ * Fill a list with all the branches in the Repository
+ *
+ * The string array will be filled with the names of the
+ * matching branches; these values are owned by the user and
+ * should be free'd manually when no longer needed, using
+ * `git_strarray_free`.
+ *
+ * @param branch_names Pointer to a git_strarray structure
+ * where the branch names will be stored.
+ *
+ * @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.
+ *
+ * @return 0 or an error code.
+ */
+GIT_EXTERN(int) git_branch_list(
+ git_strarray *branch_names,
+ git_repository *repo,
+ unsigned int list_flags);
+
+/**
+ * Move/rename an existing branch reference.
+ *
+ * @param repo Repository where lives the branch.
+ *
+ * @param old_branch_name Current name of the branch to be moved;
+ * this name is validated for consistency.
+ *
+ * @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_ENOTFOUND if the branch
+ * doesn't exist or an error code.
+ */
+GIT_EXTERN(int) git_branch_move(
+ git_repository *repo,
+ const char *old_branch_name,
+ const char *new_branch_name,
+ int force);
+
+/** @} */
+GIT_END_DECL
+#endif
diff --git a/include/git2/commit.h b/include/git2/commit.h
index 3687d9460..a6d9bb0e3 100644
--- a/include/git2/commit.h
+++ b/include/git2/commit.h
@@ -1,26 +1,8 @@
/*
- * This file is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, version 2,
- * as published by the Free Software Foundation.
- *
- * In addition to the permissions in the GNU General Public License,
- * the authors give you unlimited permission to link the compiled
- * version of this file into combinations with other programs,
- * and to distribute those combinations without any restriction
- * coming from the use of this file. (The General Public License
- * restrictions do apply in other respects; for example, they cover
- * modification of the file, and distribution when not linked into
- * a combined executable.)
- *
- * This file is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; see the file COPYING. If not, write to
- * the Free Software Foundation, 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
+ * Copyright (C) 2009-2012 the libgit2 contributors
+ *
+ * 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__
@@ -44,9 +26,9 @@ GIT_BEGIN_DECL
*
* @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 on success; error code otherwise
+ * @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)
{
@@ -54,9 +36,27 @@ GIT_INLINE(int) git_commit_lookup(git_commit **commit, git_repository *repo, con
}
/**
+ * 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, unsigned 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_close()
+ * This is a wrapper around git_object_free()
*
* IMPORTANT:
* It *is* necessary to call this method when you stop
@@ -65,9 +65,9 @@ GIT_INLINE(int) git_commit_lookup(git_commit **commit, git_repository *repo, con
* @param commit the commit to close
*/
-GIT_INLINE(void) git_commit_close(git_commit *commit)
+GIT_INLINE(void) git_commit_free(git_commit *commit)
{
- git_object_close((git_object *) commit);
+ git_object_free((git_object *) commit);
}
/**
@@ -79,12 +79,16 @@ GIT_INLINE(void) git_commit_close(git_commit *commit)
GIT_EXTERN(const git_oid *) git_commit_id(git_commit *commit);
/**
- * Get the short (one line) message of a 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 the short message of a commit
+ * @return NULL, or the encoding
*/
-GIT_EXTERN(const char *) git_commit_message_short(git_commit *commit);
+GIT_EXTERN(const char *) git_commit_message_encoding(git_commit *commit);
/**
* Get the full message of a commit.
@@ -131,7 +135,7 @@ GIT_EXTERN(const git_signature *) git_commit_author(git_commit *commit);
*
* @param tree_out pointer where to store the tree object
* @param commit a previously loaded commit.
- * @return 0 on success; error code otherwise
+ * @return 0 or an error code
*/
GIT_EXTERN(int) git_commit_tree(git_tree **tree_out, git_commit *commit);
@@ -159,7 +163,7 @@ GIT_EXTERN(unsigned int) git_commit_parentcount(git_commit *commit);
* @param parent 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 on success; error code otherwise
+ * @return 0 or an error code
*/
GIT_EXTERN(int) git_commit_parent(git_commit **parent, git_commit *commit, unsigned int n);
@@ -175,8 +179,11 @@ GIT_EXTERN(int) git_commit_parent(git_commit **parent, git_commit *commit, unsig
GIT_EXTERN(const git_oid *) git_commit_parent_oid(git_commit *commit, unsigned int n);
/**
- * Create a new commit in the repository
+ * Create a new commit in the repository using `git_object`
+ * instances as parameters.
*
+ * The message will be cleaned up from excess whitespace
+ * it will be made sure that the last line ends with a '\n'.
*
* @param oid Pointer where to store the OID of the
* newly created commit
@@ -187,28 +194,34 @@ GIT_EXTERN(const git_oid *) git_commit_parent_oid(git_commit *commit, unsigned i
* 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
+ * 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
+ * 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_oid Object ID of the tree for this commit. Note that
- * no validation is performed on this OID. Use the _o variants of
- * this method to assure a proper tree is passed to the 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 pointers to parent OIDs for this commit.
- * Note that no validation is performed on these OIDs. Use the _o
- * variants of this method to assure that are parents for the commit
- * are proper objects.
+ * @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 on success; error code otherwise
+ * @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
*/
@@ -218,39 +231,18 @@ GIT_EXTERN(int) git_commit_create(
const char *update_ref,
const git_signature *author,
const git_signature *committer,
- const char *message,
- const git_oid *tree_oid,
- int parent_count,
- const git_oid *parent_oids[]);
-
-/**
- * Create a new commit in the repository using `git_object`
- * instances as parameters.
- *
- * The `tree_oid` and `parent_oids` paremeters now take a instance
- * of `git_tree` and `git_commit`, respectively.
- *
- * All other parameters remain the same
- *
- * @see git_commit_create
- */
-GIT_EXTERN(int) git_commit_create_o(
- git_oid *oid,
- 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 `git_object`
- * instances and a variable argument list.
+ * Create a new commit in the repository using a variable
+ * argument list.
*
- * The `tree_oid` paremeter now takes a instance
- * of `const git_tree *`.
+ * 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
@@ -261,39 +253,15 @@ GIT_EXTERN(int) git_commit_create_o(
*
* @see git_commit_create
*/
-GIT_EXTERN(int) git_commit_create_ov(
- git_oid *oid,
- git_repository *repo,
- const char *update_ref,
- const git_signature *author,
- const git_signature *committer,
- const char *message,
- const git_tree *tree,
- int parent_count,
- ...);
-
-
-/**
- * Create a new commit in the repository using
- * a variable argument list.
- *
- * The parents for the commit are specified as a variable
- * list of pointers to `const git_oid *`. 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 *oid,
git_repository *repo,
const char *update_ref,
const git_signature *author,
const git_signature *committer,
+ const char *message_encoding,
const char *message,
- const git_oid *tree_oid,
+ const git_tree *tree,
int parent_count,
...);
diff --git a/include/git2/common.h b/include/git2/common.h
index 9a27ac2e5..0e9379804 100644
--- a/include/git2/common.h
+++ b/include/git2/common.h
@@ -1,67 +1,42 @@
/*
- * This file is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, version 2,
- * as published by the Free Software Foundation.
+ * Copyright (C) 2009-2012 the libgit2 contributors
*
- * In addition to the permissions in the GNU General Public License,
- * the authors give you unlimited permission to link the compiled
- * version of this file into combinations with other programs,
- * and to distribute those combinations without any restriction
- * coming from the use of this file. (The General Public License
- * restrictions do apply in other respects; for example, they cover
- * modification of the file, and distribution when not linked into
- * a combined executable.)
- *
- * This file is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; see the file COPYING. If not, write to
- * the Free Software Foundation, 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
+ * 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 "thread-utils.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 }
+# 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 */
+ /** 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. */
-#ifdef __GNUC__
+#if __GNUC__ >= 4
# define GIT_EXTERN(type) extern \
- __attribute__((visibility("default"))) \
- type
+ __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 public TLS symbol exported for application use. */
-#ifdef __GNUC__
-# define GIT_EXTERN_TLS(type) extern \
- __attribute__((visibility("default"))) \
- GIT_TLS \
- type
-#elif defined(_MSC_VER)
-# define GIT_EXTERN_TLS(type) __declspec(dllexport) GIT_TLS type
-#else
-# define GIT_EXTERN_TLS(type) extern GIT_TLS type
-#endif
-
/** Declare a function as always inlined. */
#if defined(_MSC_VER)
# define GIT_INLINE(type) static __inline type
@@ -76,6 +51,10 @@
# define GIT_FORMAT_PRINTF(a,b) /* empty */
#endif
+#if (defined(_WIN32)) && !defined(__CYGWIN__)
+#define GIT_WIN32 1
+#endif
+
/**
* @file git2/common.h
* @brief Git common platform definitions
@@ -86,12 +65,39 @@
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
+
typedef struct {
char **strings;
size_t count;
} git_strarray;
GIT_EXTERN(void) git_strarray_free(git_strarray *array);
+GIT_EXTERN(int) git_strarray_copy(git_strarray *tgt, const git_strarray *src);
+
+/**
+ * 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);
/** @} */
GIT_END_DECL
diff --git a/include/git2/config.h b/include/git2/config.h
index 78a1f622a..36946c4a5 100644
--- a/include/git2/config.h
+++ b/include/git2/config.h
@@ -1,26 +1,8 @@
/*
- * This file is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, version 2,
- * as published by the Free Software Foundation.
- *
- * In addition to the permissions in the GNU General Public License,
- * the authors give you unlimited permission to link the compiled
- * version of this file into combinations with other programs,
- * and to distribute those combinations without any restriction
- * coming from the use of this file. (The General Public License
- * restrictions do apply in other respects; for example, they cover
- * modification of the file, and distribution when not linked into
- * a combined executable.)
- *
- * This file is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; see the file COPYING. If not, write to
- * the Free Software Foundation, 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
+ * Copyright (C) 2009-2012 the libgit2 contributors
+ *
+ * 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__
@@ -47,56 +29,146 @@ struct git_config_file {
/* Open means open the file/database and parse if necessary */
int (*open)(struct git_config_file *);
int (*get)(struct git_config_file *, const char *key, const char **value);
+ int (*get_multivar)(struct git_config_file *, const char *key, const char *regexp, int (*fn)(const char *, void *), void *data);
int (*set)(struct git_config_file *, const char *key, const char *value);
- int (*foreach)(struct git_config_file *, int (*fn)(const char *, void *), void *data);
+ int (*set_multivar)(git_config_file *cfg, const char *name, const char *regexp, const char *value);
+ int (*del)(struct git_config_file *, const char *key);
+ int (*foreach)(struct git_config_file *, int (*fn)(const char *, const char *, void *), void *data);
void (*free)(struct git_config_file *);
};
+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.
+ *
+ * @param global_config_path Buffer of GIT_PATH_MAX length to store the path
+ * @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 *global_config_path, 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 system_config_path Buffer of GIT_PATH_MAX length to store the path
+ * @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 *system_config_path, size_t length);
+
+/**
+ * Open the global configuration file
+ *
+ * Utility wrapper that calls `git_config_find_global`
+ * and opens the located file, if it exists.
+ *
+ * @param out Pointer to store the config instance
+ * @return 0 or an error code
+ */
+GIT_EXTERN(int) git_config_open_global(git_config **out);
+
/**
* Create a configuration file backend for ondisk files
*
* These are the normal `.gitconfig` files that Core Git
- * processes.
+ * processes. Note that you first have to add this file to a
+ * configuration object before you can query it for configuration
+ * variables.
*
* @param out the new backend
- * @path where the config file is located
+ * @param path where the config file is located
*/
GIT_EXTERN(int) git_config_file__ondisk(struct git_config_file **out, const char *path);
/**
- * Allocate a new configuration
+ * 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);
/**
- * Open a configuration file
+ * 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 will be accessed first).
*
- * @param cfg_out pointer to the configuration data
- * @param path where to load the confiration from
+ * @param cfg the configuration to add the file to
+ * @param file the configuration file (backend) to add
+ * @param priority the priority the backend should have
+ * @return 0 or an error code
*/
-GIT_EXTERN(int) git_config_open_file(git_config **cfg_out, const char *path);
+GIT_EXTERN(int) git_config_add_file(git_config *cfg, git_config_file *file, int priority);
/**
- * Open the global configuration file at $HOME/.gitconfig
+ * 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.
*
- * @param cfg pointer to the configuration
+ * Further queries on this config object will access each
+ * of the config file instances in order (instances with
+ * a higher priority will be accessed first).
+ *
+ * @param cfg the configuration to add the file to
+ * @param path path to the configuration file (backend) to add
+ * @param priority the priority the backend should have
+ * @return 0 or an error code
*/
-GIT_EXTERN(int) git_config_open_global(git_config **cfg);
+GIT_EXTERN(int) git_config_add_file_ondisk(git_config *cfg, const char *path, int priority);
+
/**
- * Add a config backend to an existing instance
+ * Create a new config instance containing a single on-disk file
*
- * Note that the configuration will call the backend's ->free()
- * function.
+ * This method is a simple utility wrapper for the following sequence
+ * of calls:
+ * - git_config_new
+ * - git_config_add_file_ondisk
*
- * @param cfg the configuration to add the backend to
- * @param backend the backend to add
- * @param priority the priority the backend should have
+ * @param cfg The configuration instance to create
+ * @param path Path to the on-disk file to open
+ * @return 0 or an error code
*/
-GIT_EXTERN(int) git_config_add_file(git_config *cfg, git_config_file *file, int priority);
+GIT_EXTERN(int) git_config_open_ondisk(git_config **cfg, const char *path);
/**
- * Free the configuration and its associated memory
+ * Free the configuration and its associated memory and files
*
* @param cfg the configuration to free
*/
@@ -105,22 +177,22 @@ GIT_EXTERN(void) git_config_free(git_config *cfg);
/**
* Get the value of an integer config variable.
*
+ * @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
- * @param out pointer to the variable where the value should be stored
- * @return GIT_SUCCESS on success; error code otherwise
+ * @return 0 or an error code
*/
-GIT_EXTERN(int) git_config_get_int(git_config *cfg, const char *name, int *out);
+GIT_EXTERN(int) git_config_get_int32(int32_t *out, git_config *cfg, const char *name);
/**
* Get the value of a long integer config variable.
*
+ * @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
- * @param out pointer to the variable where the value should be stored
- * @return GIT_SUCCESS on success; error code otherwise
+ * @return 0 or an error code
*/
-GIT_EXTERN(int) git_config_get_long(git_config *cfg, const char *name, long int *out);
+GIT_EXTERN(int) git_config_get_int64(int64_t *out, git_config *cfg, const char *name);
/**
* Get the value of a boolean config variable.
@@ -128,12 +200,12 @@ GIT_EXTERN(int) git_config_get_long(git_config *cfg, const char *name, long int
* This function uses the usual C convention of 0 being false and
* anything else true.
*
+ * @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
- * @param out pointer to the variable where the value should be stored
- * @return GIT_SUCCESS on success; error code otherwise
+ * @return 0 or an error code
*/
-GIT_EXTERN(int) git_config_get_bool(git_config *cfg, const char *name, int *out);
+GIT_EXTERN(int) git_config_get_bool(int *out, git_config *cfg, const char *name);
/**
* Get the value of a string config variable.
@@ -141,32 +213,46 @@ GIT_EXTERN(int) git_config_get_bool(git_config *cfg, const char *name, int *out)
* The string is owned by the variable and should not be freed by the
* user.
*
+ * @param out pointer to the variable's value
* @param cfg where to look for the variable
* @param name the variable's name
- * @param out pointer to the variable's value
- * @return GIT_SUCCESS on success; error code otherwise
+ * @return 0 or an error code
+ */
+GIT_EXTERN(int) git_config_get_string(const char **out, 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_string(git_config *cfg, const char *name, const char **out);
+GIT_EXTERN(int) git_config_get_multivar(git_config *cfg, const char *name, const char *regexp, int (*fn)(const char *, void *), void *data);
/**
* Set the value of an integer config variable.
*
* @param cfg where to look for the variable
* @param name the variable's name
- * @param out pointer to the variable where the value should be stored
- * @return GIT_SUCCESS on success; error code otherwise
+ * @param value Integer value for the variable
+ * @return 0 or an error code
*/
-GIT_EXTERN(int) git_config_set_int(git_config *cfg, const char *name, int value);
+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.
*
* @param cfg where to look for the variable
* @param name the variable's name
- * @param out pointer to the variable where the value should be stored
- * @return GIT_SUCCESS on success; error code otherwise
+ * @param value Long integer value for the variable
+ * @return 0 or an error code
*/
-GIT_EXTERN(int) git_config_set_long(git_config *cfg, const char *name, long int value);
+GIT_EXTERN(int) git_config_set_int64(git_config *cfg, const char *name, int64_t value);
/**
* Set the value of a boolean config variable.
@@ -174,7 +260,7 @@ GIT_EXTERN(int) git_config_set_long(git_config *cfg, const char *name, long int
* @param cfg where to look for the variable
* @param name the variable's name
* @param value the value to store
- * @return GIT_SUCCESS on success; error code otherwise
+ * @return 0 or an error code
*/
GIT_EXTERN(int) git_config_set_bool(git_config *cfg, const char *name, int value);
@@ -187,24 +273,83 @@ GIT_EXTERN(int) git_config_set_bool(git_config *cfg, const char *name, int value
* @param cfg where to look for the variable
* @param name the variable's name
* @param value the string to store.
- * @return GIT_SUCCESS on success; error code otherwise
+ * @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
+ *
+ * @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
+ *
+ * @param cfg the configuration
+ * @param name the variable to delete
+ */
+GIT_EXTERN(int) git_config_delete(git_config *cfg, const char *name);
+
/**
* Perform an operation on each config variable.
*
- * The callback is passed a pointer to a config variable name and the
- * data pointer passed to this function. As soon as one of the
- * callback functions returns something other than 0, this function
- * returns that value.
+ * 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 returns that value.
*
* @param cfg where to get the variables from
* @param callback the function to call on each variable
- * @param data the data to pass to the callback
- * @return GIT_SUCCESS or the return value of the callback which didn't return 0
+ * @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(
+ git_config *cfg,
+ int (*callback)(const char *var_name, const char *value, void *payload),
+ 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[3] = {
+ * {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_foreach(git_config *cfg, int (*callback)(const char *, void *data), void *data);
+GIT_EXTERN(int) git_config_get_mapped(int *out, git_config *cfg, const char *name, git_cvar_map *maps, size_t map_n);
/** @} */
GIT_END_DECL
diff --git a/include/git2/diff.h b/include/git2/diff.h
new file mode 100644
index 000000000..a0e8ad6d2
--- /dev/null
+++ b/include/git2/diff.h
@@ -0,0 +1,362 @@
+/*
+ * Copyright (C) 2009-2012 the libgit2 contributors
+ *
+ * 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.
+ *
+ * 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.
+ *
+ * @ingroup Git
+ * @{
+ */
+GIT_BEGIN_DECL
+
+enum {
+ GIT_DIFF_NORMAL = 0,
+ GIT_DIFF_REVERSE = (1 << 0),
+ GIT_DIFF_FORCE_TEXT = (1 << 1),
+ GIT_DIFF_IGNORE_WHITESPACE = (1 << 2),
+ GIT_DIFF_IGNORE_WHITESPACE_CHANGE = (1 << 3),
+ GIT_DIFF_IGNORE_WHITESPACE_EOL = (1 << 4),
+ GIT_DIFF_IGNORE_SUBMODULES = (1 << 5),
+ GIT_DIFF_PATIENCE = (1 << 6),
+ GIT_DIFF_INCLUDE_IGNORED = (1 << 7),
+ GIT_DIFF_INCLUDE_UNTRACKED = (1 << 8),
+ GIT_DIFF_INCLUDE_UNMODIFIED = (1 << 9),
+ GIT_DIFF_RECURSE_UNTRACKED_DIRS = (1 << 10),
+};
+
+/**
+ * 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.
+ *
+ * @todo Most of the parameters here are not actually supported at this time.
+ */
+typedef struct {
+ uint32_t flags; /**< defaults to GIT_DIFF_NORMAL */
+ uint16_t context_lines; /**< defaults to 3 */
+ uint16_t interhunk_lines; /**< defaults to 3 */
+ char *old_prefix; /**< defaults to "a" */
+ char *new_prefix; /**< defaults to "b" */
+ git_strarray pathspec; /**< defaults to show all paths */
+} git_diff_options;
+
+/**
+ * The diff list object that contains all individual file deltas.
+ */
+typedef struct git_diff_list git_diff_list;
+
+enum {
+ GIT_DIFF_FILE_VALID_OID = (1 << 0),
+ GIT_DIFF_FILE_FREE_PATH = (1 << 1),
+ GIT_DIFF_FILE_BINARY = (1 << 2),
+ GIT_DIFF_FILE_NOT_BINARY = (1 << 3),
+ GIT_DIFF_FILE_FREE_DATA = (1 << 4),
+ GIT_DIFF_FILE_UNMAP_DATA = (1 << 5)
+};
+
+/**
+ * What type of change is described by a git_diff_delta?
+ */
+typedef enum {
+ GIT_DELTA_UNMODIFIED = 0,
+ GIT_DELTA_ADDED = 1,
+ GIT_DELTA_DELETED = 2,
+ GIT_DELTA_MODIFIED = 3,
+ GIT_DELTA_RENAMED = 4,
+ GIT_DELTA_COPIED = 5,
+ GIT_DELTA_IGNORED = 6,
+ GIT_DELTA_UNTRACKED = 7
+} git_delta_t;
+
+/**
+ * Description of one side of a diff.
+ */
+typedef struct {
+ git_oid oid;
+ char *path;
+ uint16_t mode;
+ git_off_t size;
+ unsigned int flags;
+} git_diff_file;
+
+/**
+ * Description of changes to one file.
+ *
+ * When iterating over a diff list object, this will generally be passed to
+ * most callback functions and you can use the contents to understand
+ * exactly what has changed.
+ *
+ * Under some circumstances, not all fields will be filled in, but the code
+ * generally tries to fill in as much as possible. One example is that the
+ * "binary" field will not actually look at 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.
+ */
+typedef int (*git_diff_file_fn)(
+ void *cb_data,
+ git_diff_delta *delta,
+ float progress);
+
+/**
+ * Structure describing a hunk of a diff.
+ */
+typedef struct {
+ int old_start;
+ int old_lines;
+ int new_start;
+ int new_lines;
+} git_diff_range;
+
+/**
+ * When iterating over a diff, callback that will be made per hunk.
+ */
+typedef int (*git_diff_hunk_fn)(
+ void *cb_data,
+ git_diff_delta *delta,
+ git_diff_range *range,
+ const char *header,
+ size_t header_len);
+
+/**
+ * Line origin constants.
+ *
+ * These values describe where a line came from and will be passed to
+ * the git_diff_data_fn 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.
+ */
+enum {
+ /* these values will be sent to `git_diff_data_fn` along with the line */
+ GIT_DIFF_LINE_CONTEXT = ' ',
+ GIT_DIFF_LINE_ADDITION = '+',
+ GIT_DIFF_LINE_DELETION = '-',
+ GIT_DIFF_LINE_ADD_EOFNL = '\n', /**< LF was added at end of file */
+ GIT_DIFF_LINE_DEL_EOFNL = '\0', /**< LF was removed at end of file */
+ /* these values will only be sent to a `git_diff_data_fn` 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'
+};
+
+/**
+ * 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_fn)(
+ void *cb_data,
+ git_diff_delta *delta,
+ git_diff_range *range,
+ char line_origin, /**< GIT_DIFF_LINE_... value from above */
+ const char *content,
+ size_t content_len);
+
+/** @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);
+
+/**
+ * Compute a difference between two tree objects.
+ *
+ * @param repo The repository containing the trees.
+ * @param opts Structure with options to influence diff or NULL for defaults.
+ * @param old_tree A git_tree object to diff from.
+ * @param new_tree A git_tree object to diff to.
+ * @param diff A pointer to a git_diff_list pointer that will be allocated.
+ */
+GIT_EXTERN(int) git_diff_tree_to_tree(
+ git_repository *repo,
+ const git_diff_options *opts, /**< can be NULL for defaults */
+ git_tree *old_tree,
+ git_tree *new_tree,
+ git_diff_list **diff);
+
+/**
+ * Compute a difference between a tree and the index.
+ *
+ * @param repo The repository containing the tree and index.
+ * @param opts Structure with options to influence diff or NULL for defaults.
+ * @param old_tree A git_tree object to diff from.
+ * @param diff A pointer to a git_diff_list pointer that will be allocated.
+ */
+GIT_EXTERN(int) git_diff_index_to_tree(
+ git_repository *repo,
+ const git_diff_options *opts, /**< can be NULL for defaults */
+ git_tree *old_tree,
+ git_diff_list **diff);
+
+/**
+ * Compute a difference between the working directory and the index.
+ *
+ * @param repo The repository.
+ * @param opts Structure with options to influence diff or NULL for defaults.
+ * @param diff A pointer to a git_diff_list pointer that will be allocated.
+ */
+GIT_EXTERN(int) git_diff_workdir_to_index(
+ git_repository *repo,
+ const git_diff_options *opts, /**< can be NULL for defaults */
+ git_diff_list **diff);
+
+/**
+ * Compute a difference between the working directory and a tree.
+ *
+ * This returns strictly the differences between the tree and the
+ * files contained in the working directory, regardless of the state
+ * of files in the index. There is no direct equivalent in C git.
+ *
+ * This is *NOT* the same as 'git diff HEAD' or 'git diff <SHA>'. Those
+ * commands diff the tree, the index, and the workdir. To emulate those
+ * functions, call `git_diff_index_to_tree` and `git_diff_workdir_to_index`,
+ * then call `git_diff_merge` on the results.
+ *
+ * @param repo The repository containing the tree.
+ * @param opts Structure with options to influence diff or NULL for defaults.
+ * @param old_tree A git_tree object to diff from.
+ * @param diff A pointer to a git_diff_list pointer that will be allocated.
+ */
+GIT_EXTERN(int) git_diff_workdir_to_tree(
+ git_repository *repo,
+ const git_diff_options *opts, /**< can be NULL for defaults */
+ git_tree *old_tree,
+ git_diff_list **diff);
+
+/**
+ * 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);
+
+/**@}*/
+
+
+/** @name Diff List Processor Functions
+ *
+ * These are the functions you apply to a diff list to process it
+ * or read it in some way.
+ */
+/**@{*/
+
+/**
+ * Iterate over a diff list issuing callbacks.
+ *
+ * If the hunk and/or line callbacks are not NULL, then this will calculate
+ * text diffs for all files it thinks are not binary. If those are both
+ * NULL, then this will not bother with the text diffs, so it can be
+ * efficient.
+ */
+GIT_EXTERN(int) git_diff_foreach(
+ git_diff_list *diff,
+ void *cb_data,
+ git_diff_file_fn file_cb,
+ git_diff_hunk_fn hunk_cb,
+ git_diff_data_fn line_cb);
+
+/**
+ * Iterate over a diff generating text output like "git diff --name-status".
+ */
+GIT_EXTERN(int) git_diff_print_compact(
+ git_diff_list *diff,
+ void *cb_data,
+ git_diff_data_fn print_cb);
+
+/**
+ * Iterate over a diff generating text output like "git diff".
+ *
+ * This is a super easy way to generate a patch from a diff.
+ */
+GIT_EXTERN(int) git_diff_print_patch(
+ git_diff_list *diff,
+ void *cb_data,
+ git_diff_data_fn print_cb);
+
+/**@}*/
+
+
+/*
+ * Misc
+ */
+
+/**
+ * Directly run a text diff on two blobs.
+ *
+ * Compared to a file, a blob lacks some contextual information. As such, the
+ * `git_diff_file` parameters of the callbacks will be filled accordingly to the following:
+ * `mode` will be set to 0, `path` will be set to NULL. When dealing with a NULL blob, `oid`
+ * will be set to 0.
+ *
+ * When at least one of the blobs being dealt with is binary, the `git_diff_delta` binary
+ * attribute will be set to 1 and no call to the hunk_cb nor line_cb will be made.
+ */
+GIT_EXTERN(int) git_diff_blobs(
+ git_blob *old_blob,
+ git_blob *new_blob,
+ git_diff_options *options,
+ void *cb_data,
+ git_diff_file_fn file_cb,
+ git_diff_hunk_fn hunk_cb,
+ git_diff_data_fn line_cb);
+
+GIT_END_DECL
+
+/** @} */
+
+#endif
diff --git a/include/git2/errors.h b/include/git2/errors.h
index 3ed5cd680..ccbc9fcf4 100644
--- a/include/git2/errors.h
+++ b/include/git2/errors.h
@@ -1,26 +1,8 @@
/*
- * This file is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, version 2,
- * as published by the Free Software Foundation.
+ * Copyright (C) 2009-2012 the libgit2 contributors
*
- * In addition to the permissions in the GNU General Public License,
- * the authors give you unlimited permission to link the compiled
- * version of this file into combinations with other programs,
- * and to distribute those combinations without any restriction
- * coming from the use of this file. (The General Public License
- * restrictions do apply in other respects; for example, they cover
- * modification of the file, and distribution when not linked into
- * a combined executable.)
- *
- * This file is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; see the file COPYING. If not, write to
- * the Free Software Foundation, 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
+ * 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__
@@ -35,113 +17,92 @@
*/
GIT_BEGIN_DECL
-typedef enum {
+#ifdef GIT_OLD_ERRORS
+enum {
GIT_SUCCESS = 0,
- GIT_ERROR = -1,
-
- /** Input was not a properly formatted Git object id. */
GIT_ENOTOID = -2,
-
- /** Input does not exist in the scope searched. */
GIT_ENOTFOUND = -3,
-
- /** Not enough space available. */
GIT_ENOMEM = -4,
-
- /** Consult the OS error information. */
GIT_EOSERR = -5,
-
- /** The specified object is of invalid type */
GIT_EOBJTYPE = -6,
-
- /** The specified repository is invalid */
GIT_ENOTAREPO = -7,
-
- /** The object type is invalid or doesn't match */
GIT_EINVALIDTYPE = -8,
-
- /** The object cannot be written because it's missing internal data */
GIT_EMISSINGOBJDATA = -9,
-
- /** The packfile for the ODB is corrupted */
GIT_EPACKCORRUPTED = -10,
-
- /** Failed to acquire or release a file lock */
GIT_EFLOCKFAIL = -11,
-
- /** The Z library failed to inflate/deflate an object's data */
GIT_EZLIB = -12,
-
- /** The queried object is currently busy */
GIT_EBUSY = -13,
-
- /** The index file is not backed up by an existing repository */
GIT_EBAREINDEX = -14,
-
- /** The name of the reference is not valid */
GIT_EINVALIDREFNAME = -15,
-
- /** The specified reference has its data corrupted */
- GIT_EREFCORRUPTED = -16,
-
- /** The specified symbolic reference is too deeply nested */
+ GIT_EREFCORRUPTED = -16,
GIT_ETOONESTEDSYMREF = -17,
-
- /** The pack-refs file is either corrupted or its format is not currently supported */
GIT_EPACKEDREFSCORRUPTED = -18,
-
- /** The path is invalid */
GIT_EINVALIDPATH = -19,
-
- /** The revision walker is empty; there are no more commits left to iterate */
GIT_EREVWALKOVER = -20,
-
- /** The state of the reference is not valid */
GIT_EINVALIDREFSTATE = -21,
-
- /** This feature has not been implemented yet */
GIT_ENOTIMPLEMENTED = -22,
-
- /** A reference with this name already exists */
GIT_EEXISTS = -23,
-
- /** The given integer literal is too large to be parsed */
GIT_EOVERFLOW = -24,
-
- /** The given literal is not a valid number */
GIT_ENOTNUM = -25,
-
- /** Streaming error */
GIT_ESTREAM = -26,
-
- /** invalid arguments to function */
GIT_EINVALIDARGS = -27,
-
- /** The specified object has its data corrupted */
GIT_EOBJCORRUPTED = -28,
+ GIT_EAMBIGUOUS = -29,
+ GIT_EPASSTHROUGH = -30,
+ GIT_ENOMATCH = -31,
+ GIT_ESHORTBUFFER = -32,
+};
+#endif
+
+/** Generic return codes */
+enum {
+ GIT_OK = 0,
+ GIT_ERROR = -1,
+ GIT_ENOTFOUND = -3,
+ GIT_EEXISTS = -4,
+ GIT_EAMBIGUOUS = -5,
+ GIT_EBUFS = -6,
+
+ GIT_PASSTHROUGH = -30,
+ GIT_REVWALKOVER = -31,
+};
- /** The given short oid is ambiguous */
- GIT_EAMBIGUOUSOIDPREFIX = -29,
+typedef struct {
+ char *message;
+ int klass;
} git_error;
+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,
+} git_error_t;
+
/**
- * Return a detailed error string with the latest error
- * that occurred in the library.
- * @return a string explaining the error
+ * 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 char *) git_lasterror(void);
+GIT_EXTERN(const git_error *) giterr_last(void);
/**
- * strerror() for the Git library
- *
- * Get a string description for a given error code.
- * NOTE: This method will be eventually deprecated in favor
- * of the new `git_lasterror`.
- *
- * @param num The error code to explain
- * @return a string explaining the error code
+ * Clear the last library error that occurred for this thread.
*/
-GIT_EXTERN(const char *) git_strerror(int num);
+GIT_EXTERN(void) giterr_clear(void);
/** @} */
GIT_END_DECL
diff --git a/include/git2/index.h b/include/git2/index.h
index fa1cadeab..0fb0f955a 100644
--- a/include/git2/index.h
+++ b/include/git2/index.h
@@ -1,26 +1,8 @@
/*
- * This file is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, version 2,
- * as published by the Free Software Foundation.
- *
- * In addition to the permissions in the GNU General Public License,
- * the authors give you unlimited permission to link the compiled
- * version of this file into combinations with other programs,
- * and to distribute those combinations without any restriction
- * coming from the use of this file. (The General Public License
- * restrictions do apply in other respects; for example, they cover
- * modification of the file, and distribution when not linked into
- * a combined executable.)
- *
- * This file is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; see the file COPYING. If not, write to
- * the Free Software Foundation, 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
+ * Copyright (C) 2009-2012 the libgit2 contributors
+ *
+ * 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__
@@ -38,10 +20,10 @@
*/
GIT_BEGIN_DECL
-#define GIT_IDXENTRY_NAMEMASK (0x0fff)
+#define GIT_IDXENTRY_NAMEMASK (0x0fff)
#define GIT_IDXENTRY_STAGEMASK (0x3000)
-#define GIT_IDXENTRY_EXTENDED (0x4000)
-#define GIT_IDXENTRY_VALID (0x8000)
+#define GIT_IDXENTRY_EXTENDED (0x4000)
+#define GIT_IDXENTRY_VALID (0x8000)
#define GIT_IDXENTRY_STAGESHIFT 12
/*
@@ -51,26 +33,26 @@ GIT_BEGIN_DECL
*
* 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_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_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_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)
+#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_EXTENDED2 (1 << 15)
#define GIT_IDXENTRY_EXTENDED_FLAGS (GIT_IDXENTRY_INTENT_TO_ADD | GIT_IDXENTRY_SKIP_WORKTREE)
@@ -98,14 +80,14 @@ typedef struct git_index_entry {
unsigned short flags;
unsigned short flags_extended;
- const char *path;
+ char *path;
} git_index_entry;
/** Representation of an unmerged file entry in the index. */
typedef struct git_index_entry_unmerged {
unsigned int mode[3];
git_oid oid[3];
- const char *path;
+ char *path;
} git_index_entry_unmerged;
/**
@@ -124,7 +106,7 @@ typedef struct git_index_entry_unmerged {
*
* @param index the pointer for the new index
* @param index_path the path to the index file in disk
- * @return 0 on success; error code otherwise
+ * @return 0 or an error code
*/
GIT_EXTERN(int) git_index_open(git_index **index, const char *index_path);
@@ -149,7 +131,7 @@ GIT_EXTERN(void) git_index_free(git_index *index);
* by reading from the hard disk.
*
* @param index an existing index object
- * @return 0 on success, otherwise an error code
+ * @return 0 or an error code
*/
GIT_EXTERN(int) git_index_read(git_index *index);
@@ -158,7 +140,7 @@ GIT_EXTERN(int) git_index_read(git_index *index);
* using an atomic file lock.
*
* @param index an existing index object
- * @return 0 on success, otherwise an error code
+ * @return 0 or an error code
*/
GIT_EXTERN(int) git_index_write(git_index *index);
@@ -173,6 +155,13 @@ GIT_EXTERN(int) git_index_write(git_index *index);
GIT_EXTERN(int) git_index_find(git_index *index, const char *path);
/**
+ * Remove all entries with equal path except last added
+ *
+ * @param index an existing index object
+ */
+GIT_EXTERN(void) git_index_uniq(git_index *index);
+
+/**
* Add or update an index entry from a file in disk
*
* The file `path` must be relative to the repository's
@@ -180,10 +169,14 @@ GIT_EXTERN(int) git_index_find(git_index *index, const char *path);
*
* 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.
+ *
* @param index an existing index object
* @param path filename to add
* @param stage stage for the entry
- * @return 0 on success, otherwise an error code
+ * @return 0 or an error code
*/
GIT_EXTERN(int) git_index_add(git_index *index, const char *path, int stage);
@@ -195,7 +188,7 @@ GIT_EXTERN(int) git_index_add(git_index *index, const char *path, int stage);
*
* @param index an existing index object
* @param source_entry new entry object
- * @return 0 on success, otherwise an error code
+ * @return 0 or an error code
*/
GIT_EXTERN(int) git_index_add2(git_index *index, const git_index_entry *source_entry);
@@ -214,7 +207,7 @@ GIT_EXTERN(int) git_index_add2(git_index *index, const git_index_entry *source_e
* @param index an existing index object
* @param path filename to add
* @param stage stage for the entry
- * @return 0 on success, otherwise an error code
+ * @return 0 or an error code
*/
GIT_EXTERN(int) git_index_append(git_index *index, const char *path, int stage);
@@ -231,7 +224,7 @@ GIT_EXTERN(int) git_index_append(git_index *index, const char *path, int stage);
*
* @param index an existing index object
* @param source_entry new entry object
- * @return 0 on success, otherwise an error code
+ * @return 0 or an error code
*/
GIT_EXTERN(int) git_index_append2(git_index *index, const git_index_entry *source_entry);
@@ -240,7 +233,7 @@ GIT_EXTERN(int) git_index_append2(git_index *index, const git_index_entry *sourc
*
* @param index an existing index object
* @param position position of the entry to remove
- * @return 0 on success, otherwise an error code
+ * @return 0 or an error code
*/
GIT_EXTERN(int) git_index_remove(git_index *index, int position);
@@ -257,7 +250,7 @@ GIT_EXTERN(int) git_index_remove(git_index *index, int position);
* @param n the position of the entry
* @return a pointer to the entry; NULL if out of bounds
*/
-GIT_EXTERN(git_index_entry *) git_index_get(git_index *index, int n);
+GIT_EXTERN(git_index_entry *) git_index_get(git_index *index, unsigned int n);
/**
* Get the count of entries currently in the index
@@ -285,12 +278,24 @@ GIT_EXTERN(unsigned int) git_index_entrycount_unmerged(git_index *index);
* @param path path to search
* @return the unmerged entry; NULL if not found
*/
-GIT_EXTERN(const git_index_entry_unmerged *) git_index_get_unmerged(git_index *index, const char *path);
+GIT_EXTERN(const git_index_entry_unmerged *) git_index_get_unmerged_bypath(git_index *index, const char *path);
+
+/**
+ * Get an unmerged entry from the index.
+ *
+ * The returned entry is read-only and should not be modified
+ * of freed by the caller.
+ *
+ * @param index an existing index object
+ * @param n the position of the entry
+ * @return a pointer to the unmerged entry; NULL if out of bounds
+ */
+GIT_EXTERN(const git_index_entry_unmerged *) git_index_get_unmerged_byindex(git_index *index, unsigned int n);
/**
* Return the stage number from a git index entry
*
- * This entry is calculated from the entrie's flag
+ * This entry is calculated from the entry's flag
* attribute like this:
*
* (entry->flags & GIT_IDXENTRY_STAGEMASK) >> GIT_IDXENTRY_STAGESHIFT
@@ -300,6 +305,17 @@ GIT_EXTERN(const git_index_entry_unmerged *) git_index_get_unmerged(git_index *i
*/
GIT_EXTERN(int) git_index_entry_stage(const git_index_entry *entry);
+/**
+ * Read a tree into the index file
+ *
+ * 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, git_tree *tree);
+
/** @} */
GIT_END_DECL
#endif
diff --git a/include/git2/indexer.h b/include/git2/indexer.h
new file mode 100644
index 000000000..626377701
--- /dev/null
+++ b/include/git2/indexer.h
@@ -0,0 +1,121 @@
+/*
+ * Copyright (C) 2009-2012 the libgit2 contributors
+ *
+ * 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_indexer_stats {
+ unsigned int total;
+ unsigned int processed;
+} git_indexer_stats;
+
+
+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 gitdir (metadata directory)
+ */
+GIT_EXTERN(int) git_indexer_stream_new(git_indexer_stream **out, const char *gitdir);
+
+/**
+ * Add data to the indexer
+ *
+ * @param idx the indexer
+ * @param data the data to add
+ * @param size the size of the data
+ * @param stats stat storage
+ */
+GIT_EXTERN(int) git_indexer_stream_add(git_indexer_stream *idx, const void *data, size_t size, git_indexer_stats *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_indexer_stats *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(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_indexer_stats *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(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
diff --git a/include/git2/inttypes.h b/include/git2/inttypes.h
new file mode 100644
index 000000000..ead903f78
--- /dev/null
+++ b/include/git2/inttypes.h
@@ -0,0 +1,305 @@
+// ISO C9x compliant inttypes.h for Microsoft Visual Studio
+// Based on ISO/IEC 9899:TC2 Committee draft (May 6, 2005) WG14/N1124
+//
+// Copyright (c) 2006 Alexander Chemeris
+//
+// 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.
+//
+// 3. The name of the author may be used to endorse or promote products
+// derived from this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 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.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#ifndef _MSC_VER // [
+#error "Use this header only with Microsoft Visual C++ compilers!"
+#endif // _MSC_VER ]
+
+#ifndef _MSC_INTTYPES_H_ // [
+#define _MSC_INTTYPES_H_
+
+#if _MSC_VER > 1000
+#pragma once
+#endif
+
+#include "stdint.h"
+
+// 7.8 Format conversion of integer types
+
+typedef struct {
+ intmax_t quot;
+ intmax_t rem;
+} imaxdiv_t;
+
+// 7.8.1 Macros for format specifiers
+
+#if !defined(__cplusplus) || defined(__STDC_FORMAT_MACROS) // [ See footnote 185 at page 198
+
+// The fprintf macros for signed integers are:
+#define PRId8 "d"
+#define PRIi8 "i"
+#define PRIdLEAST8 "d"
+#define PRIiLEAST8 "i"
+#define PRIdFAST8 "d"
+#define PRIiFAST8 "i"
+
+#define PRId16 "hd"
+#define PRIi16 "hi"
+#define PRIdLEAST16 "hd"
+#define PRIiLEAST16 "hi"
+#define PRIdFAST16 "hd"
+#define PRIiFAST16 "hi"
+
+#define PRId32 "I32d"
+#define PRIi32 "I32i"
+#define PRIdLEAST32 "I32d"
+#define PRIiLEAST32 "I32i"
+#define PRIdFAST32 "I32d"
+#define PRIiFAST32 "I32i"
+
+#define PRId64 "I64d"
+#define PRIi64 "I64i"
+#define PRIdLEAST64 "I64d"
+#define PRIiLEAST64 "I64i"
+#define PRIdFAST64 "I64d"
+#define PRIiFAST64 "I64i"
+
+#define PRIdMAX "I64d"
+#define PRIiMAX "I64i"
+
+#define PRIdPTR "Id"
+#define PRIiPTR "Ii"
+
+// The fprintf macros for unsigned integers are:
+#define PRIo8 "o"
+#define PRIu8 "u"
+#define PRIx8 "x"
+#define PRIX8 "X"
+#define PRIoLEAST8 "o"
+#define PRIuLEAST8 "u"
+#define PRIxLEAST8 "x"
+#define PRIXLEAST8 "X"
+#define PRIoFAST8 "o"
+#define PRIuFAST8 "u"
+#define PRIxFAST8 "x"
+#define PRIXFAST8 "X"
+
+#define PRIo16 "ho"
+#define PRIu16 "hu"
+#define PRIx16 "hx"
+#define PRIX16 "hX"
+#define PRIoLEAST16 "ho"
+#define PRIuLEAST16 "hu"
+#define PRIxLEAST16 "hx"
+#define PRIXLEAST16 "hX"
+#define PRIoFAST16 "ho"
+#define PRIuFAST16 "hu"
+#define PRIxFAST16 "hx"
+#define PRIXFAST16 "hX"
+
+#define PRIo32 "I32o"
+#define PRIu32 "I32u"
+#define PRIx32 "I32x"
+#define PRIX32 "I32X"
+#define PRIoLEAST32 "I32o"
+#define PRIuLEAST32 "I32u"
+#define PRIxLEAST32 "I32x"
+#define PRIXLEAST32 "I32X"
+#define PRIoFAST32 "I32o"
+#define PRIuFAST32 "I32u"
+#define PRIxFAST32 "I32x"
+#define PRIXFAST32 "I32X"
+
+#define PRIo64 "I64o"
+#define PRIu64 "I64u"
+#define PRIx64 "I64x"
+#define PRIX64 "I64X"
+#define PRIoLEAST64 "I64o"
+#define PRIuLEAST64 "I64u"
+#define PRIxLEAST64 "I64x"
+#define PRIXLEAST64 "I64X"
+#define PRIoFAST64 "I64o"
+#define PRIuFAST64 "I64u"
+#define PRIxFAST64 "I64x"
+#define PRIXFAST64 "I64X"
+
+#define PRIoMAX "I64o"
+#define PRIuMAX "I64u"
+#define PRIxMAX "I64x"
+#define PRIXMAX "I64X"
+
+#define PRIoPTR "Io"
+#define PRIuPTR "Iu"
+#define PRIxPTR "Ix"
+#define PRIXPTR "IX"
+
+// The fscanf macros for signed integers are:
+#define SCNd8 "d"
+#define SCNi8 "i"
+#define SCNdLEAST8 "d"
+#define SCNiLEAST8 "i"
+#define SCNdFAST8 "d"
+#define SCNiFAST8 "i"
+
+#define SCNd16 "hd"
+#define SCNi16 "hi"
+#define SCNdLEAST16 "hd"
+#define SCNiLEAST16 "hi"
+#define SCNdFAST16 "hd"
+#define SCNiFAST16 "hi"
+
+#define SCNd32 "ld"
+#define SCNi32 "li"
+#define SCNdLEAST32 "ld"
+#define SCNiLEAST32 "li"
+#define SCNdFAST32 "ld"
+#define SCNiFAST32 "li"
+
+#define SCNd64 "I64d"
+#define SCNi64 "I64i"
+#define SCNdLEAST64 "I64d"
+#define SCNiLEAST64 "I64i"
+#define SCNdFAST64 "I64d"
+#define SCNiFAST64 "I64i"
+
+#define SCNdMAX "I64d"
+#define SCNiMAX "I64i"
+
+#ifdef _WIN64 // [
+# define SCNdPTR "I64d"
+# define SCNiPTR "I64i"
+#else // _WIN64 ][
+# define SCNdPTR "ld"
+# define SCNiPTR "li"
+#endif // _WIN64 ]
+
+// The fscanf macros for unsigned integers are:
+#define SCNo8 "o"
+#define SCNu8 "u"
+#define SCNx8 "x"
+#define SCNX8 "X"
+#define SCNoLEAST8 "o"
+#define SCNuLEAST8 "u"
+#define SCNxLEAST8 "x"
+#define SCNXLEAST8 "X"
+#define SCNoFAST8 "o"
+#define SCNuFAST8 "u"
+#define SCNxFAST8 "x"
+#define SCNXFAST8 "X"
+
+#define SCNo16 "ho"
+#define SCNu16 "hu"
+#define SCNx16 "hx"
+#define SCNX16 "hX"
+#define SCNoLEAST16 "ho"
+#define SCNuLEAST16 "hu"
+#define SCNxLEAST16 "hx"
+#define SCNXLEAST16 "hX"
+#define SCNoFAST16 "ho"
+#define SCNuFAST16 "hu"
+#define SCNxFAST16 "hx"
+#define SCNXFAST16 "hX"
+
+#define SCNo32 "lo"
+#define SCNu32 "lu"
+#define SCNx32 "lx"
+#define SCNX32 "lX"
+#define SCNoLEAST32 "lo"
+#define SCNuLEAST32 "lu"
+#define SCNxLEAST32 "lx"
+#define SCNXLEAST32 "lX"
+#define SCNoFAST32 "lo"
+#define SCNuFAST32 "lu"
+#define SCNxFAST32 "lx"
+#define SCNXFAST32 "lX"
+
+#define SCNo64 "I64o"
+#define SCNu64 "I64u"
+#define SCNx64 "I64x"
+#define SCNX64 "I64X"
+#define SCNoLEAST64 "I64o"
+#define SCNuLEAST64 "I64u"
+#define SCNxLEAST64 "I64x"
+#define SCNXLEAST64 "I64X"
+#define SCNoFAST64 "I64o"
+#define SCNuFAST64 "I64u"
+#define SCNxFAST64 "I64x"
+#define SCNXFAST64 "I64X"
+
+#define SCNoMAX "I64o"
+#define SCNuMAX "I64u"
+#define SCNxMAX "I64x"
+#define SCNXMAX "I64X"
+
+#ifdef _WIN64 // [
+# define SCNoPTR "I64o"
+# define SCNuPTR "I64u"
+# define SCNxPTR "I64x"
+# define SCNXPTR "I64X"
+#else // _WIN64 ][
+# define SCNoPTR "lo"
+# define SCNuPTR "lu"
+# define SCNxPTR "lx"
+# define SCNXPTR "lX"
+#endif // _WIN64 ]
+
+#endif // __STDC_FORMAT_MACROS ]
+
+// 7.8.2 Functions for greatest-width integer types
+
+// 7.8.2.1 The imaxabs function
+#define imaxabs _abs64
+
+// 7.8.2.2 The imaxdiv function
+
+// This is modified version of div() function from Microsoft's div.c found
+// in %MSVC.NET%\crt\src\div.c
+#ifdef STATIC_IMAXDIV // [
+static
+#else // STATIC_IMAXDIV ][
+_inline
+#endif // STATIC_IMAXDIV ]
+imaxdiv_t __cdecl imaxdiv(intmax_t numer, intmax_t denom)
+{
+ imaxdiv_t result;
+
+ result.quot = numer / denom;
+ result.rem = numer % denom;
+
+ if (numer < 0 && result.rem > 0) {
+ // did division wrong; must fix up
+ ++result.quot;
+ result.rem -= denom;
+ }
+
+ return result;
+}
+
+// 7.8.2.3 The strtoimax and strtoumax functions
+#define strtoimax _strtoi64
+#define strtoumax _strtoui64
+
+// 7.8.2.4 The wcstoimax and wcstoumax functions
+#define wcstoimax _wcstoi64
+#define wcstoumax _wcstoui64
+
+
+#endif // _MSC_INTTYPES_H_ ]
diff --git a/include/git2/merge.h b/include/git2/merge.h
new file mode 100644
index 000000000..5a0b2e7f2
--- /dev/null
+++ b/include/git2/merge.h
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2009-2012 the libgit2 contributors
+ *
+ * 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
+ */
+GIT_EXTERN(int) git_merge_base(git_oid *out, git_repository *repo, git_oid *one, git_oid *two);
+
+/** @} */
+GIT_END_DECL
+#endif
diff --git a/include/git2/net.h b/include/git2/net.h
new file mode 100644
index 000000000..c2301b6f1
--- /dev/null
+++ b/include/git2/net.h
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2009-2012 the libgit2 contributors
+ *
+ * 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_net_h__
+#define INCLUDE_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.
+ */
+
+#define GIT_DIR_FETCH 0
+#define GIT_DIR_PUSH 1
+
+
+/**
+ * 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 *, void *);
+
+/** @} */
+GIT_END_DECL
+#endif
diff --git a/include/git2/notes.h b/include/git2/notes.h
new file mode 100644
index 000000000..19073abd1
--- /dev/null
+++ b/include/git2/notes.h
@@ -0,0 +1,139 @@
+/*
+ * Copyright (C) 2009-2012 the libgit2 contributors
+ *
+ * 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
+
+/**
+ * Read the note for an object
+ *
+ * The note must be freed manually by the user.
+ *
+ * @param note the note; NULL in case of error
+ * @param repo the Git repository
+ * @param notes_ref OID reference to use (optional); defaults to "refs/notes/commits"
+ * @param oid OID of the object
+ *
+ * @return 0 or an error code
+ */
+GIT_EXTERN(int) git_note_read(git_note **note, 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(git_note *note);
+
+
+/**
+ * Get the note object OID
+ *
+ * @param note
+ * @return the note object OID
+ */
+GIT_EXTERN(const git_oid *) git_note_oid(git_note *note);
+
+
+/**
+ * Add a note for an object
+ *
+ * @param oid pointer to store the OID (optional); NULL in case of error
+ * @param repo the Git repository
+ * @param author signature of the notes commit author
+ * @param committer signature of the notes commit committer
+ * @param notes_ref OID reference to update (optional); defaults to "refs/notes/commits"
+ * @param oid The OID of the object
+ * @param oid The note to add for object oid
+ *
+ * @return 0 or an error code
+ */
+GIT_EXTERN(int) git_note_create(git_oid *out, git_repository *repo,
+ git_signature *author, git_signature *committer,
+ const char *notes_ref, const git_oid *oid,
+ const char *note);
+
+
+/**
+ * Remove the note for an object
+ *
+ * @param repo the Git repository
+ * @param notes_ref OID 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 the oid which note's to be removed
+ *
+ * @return 0 or an error code
+ */
+GIT_EXTERN(int) git_note_remove(git_repository *repo, const char *notes_ref,
+ git_signature *author, 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);
+
+/**
+ * Basic components of a note
+ *
+ * - Oid of the blob containing the message
+ * - Oid of the git object being annotated
+ */
+typedef struct {
+ git_oid blob_oid;
+ git_oid annotated_object_oid;
+} git_note_data;
+
+/**
+ * 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 OID reference to read from (optional); defaults to "refs/notes/commits".
+ *
+ * @param note_cb Callback to invoke per found annotation.
+ *
+ * @param payload Extra parameter to callback function.
+ *
+ * @return 0 or an error code.
+ */
+GIT_EXTERN(int) git_note_foreach(
+ git_repository *repo,
+ const char *notes_ref,
+ int (*note_cb)(git_note_data *note_data, void *payload),
+ void *payload
+);
+
+/** @} */
+GIT_END_DECL
+#endif
diff --git a/include/git2/object.h b/include/git2/object.h
index 83d37a263..414325121 100644
--- a/include/git2/object.h
+++ b/include/git2/object.h
@@ -1,26 +1,8 @@
/*
- * This file is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, version 2,
- * as published by the Free Software Foundation.
- *
- * In addition to the permissions in the GNU General Public License,
- * the authors give you unlimited permission to link the compiled
- * version of this file into combinations with other programs,
- * and to distribute those combinations without any restriction
- * coming from the use of this file. (The General Public License
- * restrictions do apply in other respects; for example, they cover
- * modification of the file, and distribution when not linked into
- * a combined executable.)
- *
- * This file is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; see the file COPYING. If not, write to
- * the Free Software Foundation, 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
+ * Copyright (C) 2009-2012 the libgit2 contributors
+ *
+ * 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__
@@ -39,10 +21,10 @@
GIT_BEGIN_DECL
/**
- * Lookup a reference to one of the objects in a repostory.
+ * 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_close` method
+ * should be closed with the `git_object_free` method
* instead of free'd manually.
*
* The 'type' parameter must match the type of the object
@@ -63,7 +45,7 @@ GIT_EXTERN(int) git_object_lookup(
git_otype type);
/**
- * Lookup a reference to one of the objects in a repostory,
+ * 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
@@ -74,7 +56,7 @@ GIT_EXTERN(int) git_object_lookup(
* the prefix; otherwise the method will fail.
*
* The generated reference is owned by the repository and
- * should be closed with the `git_object_close` method
+ * should be closed with the `git_object_free` method
* instead of free'd manually.
*
* The 'type' parameter must match the type of the object
@@ -82,12 +64,12 @@ GIT_EXTERN(int) git_object_lookup(
* 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 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 a reference to the object
+ * @return 0 or an error code
*/
GIT_EXTERN(int) git_object_lookup_prefix(
git_object **object_out,
@@ -132,7 +114,7 @@ GIT_EXTERN(git_repository *) git_object_owner(const git_object *obj);
* 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 agressive is the caching mechanism used
+ * depending on how aggressive is the caching mechanism used
* by the repository.
*
* IMPORTANT:
@@ -141,7 +123,7 @@ GIT_EXTERN(git_repository *) git_object_owner(const git_object *obj);
*
* @param object the object to close
*/
-GIT_EXTERN(void) git_object_close(git_object *object);
+GIT_EXTERN(void) git_object_free(git_object *object);
/**
* Convert an object type to it's string representation.
diff --git a/include/git2/odb.h b/include/git2/odb.h
index 42961463c..e2443178c 100644
--- a/include/git2/odb.h
+++ b/include/git2/odb.h
@@ -1,26 +1,8 @@
/*
- * This file is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, version 2,
- * as published by the Free Software Foundation.
- *
- * In addition to the permissions in the GNU General Public License,
- * the authors give you unlimited permission to link the compiled
- * version of this file into combinations with other programs,
- * and to distribute those combinations without any restriction
- * coming from the use of this file. (The General Public License
- * restrictions do apply in other respects; for example, they cover
- * modification of the file, and distribution when not linked into
- * a combined executable.)
- *
- * This file is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; see the file COPYING. If not, write to
- * the Free Software Foundation, 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
+ * Copyright (C) 2009-2012 the libgit2 contributors
+ *
+ * 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__
@@ -46,9 +28,8 @@ GIT_BEGIN_DECL
* 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 GIT_SUCCESS if the database was created; otherwise an error
- * code describing why the open was not possible.
+ * Set to NULL if the open failed.
+ * @return 0 or an error code
*/
GIT_EXTERN(int) git_odb_new(git_odb **out);
@@ -64,21 +45,24 @@ GIT_EXTERN(int) git_odb_new(git_odb **out);
* 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.
+ * Set to NULL if the open failed.
* @param objects_dir path of the backends' "objects" directory.
- * @return GIT_SUCCESS if the database opened; otherwise an error
- * code describing why the open was not possible.
+ * @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
- * @paramm backend pointer to a git_odb_backend instance
- * @return 0 on sucess; error code otherwise
+ * @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);
@@ -89,22 +73,26 @@ GIT_EXTERN(int) git_odb_add_backend(git_odb *odb, git_odb_backend *backend, int
* 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
- * @paramm backend pointer to a git_odb_backend instance
- * @return 0 on sucess; error code otherwise
+ * @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);
/**
* Close an open object database.
*
- * @param db database pointer to close. If NULL no action is taken.
+ * @param db database pointer to close. If NULL no action is taken.
*/
-GIT_EXTERN(void) git_odb_close(git_odb *db);
+GIT_EXTERN(void) git_odb_free(git_odb *db);
/**
* Read an object from the database.
@@ -120,7 +108,7 @@ GIT_EXTERN(void) git_odb_close(git_odb *db);
* @param db database to search for the object in.
* @param id identity of the object to read.
* @return
- * - GIT_SUCCESS if the object was read;
+ * - 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);
@@ -143,16 +131,13 @@ GIT_EXTERN(int) git_odb_read(git_odb_object **out, git_odb *db, const git_oid *i
* internally cached, so it should be closed
* by the user once it's no longer in use.
*
- * @param out_oid the oid of the unique object matching
- * the short id
* @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
- * - GIT_SUCCESS 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)
+ * @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, unsigned int len);
@@ -171,7 +156,7 @@ GIT_EXTERN(int) git_odb_read_prefix(git_odb_object **out, git_odb *db, const git
* @param db database to search for the object in.
* @param id identity of the object to read.
* @return
- * - GIT_SUCCESS if the object was read;
+ * - 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_p, git_otype *type_p, git_odb *db, const git_oid *id);
@@ -200,10 +185,10 @@ GIT_EXTERN(int) git_odb_exists(git_odb *db, const git_oid *id);
*
* @param oid 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 storr
+ * @param data buffer with the data to store
* @param len size of the buffer
* @param type type of the data to store
- * @return 0 on success; error code otherwise
+ * @return 0 or an error code
*/
GIT_EXTERN(int) git_odb_write(git_oid *oid, git_odb *odb, const void *data, size_t len, git_otype type);
@@ -215,12 +200,12 @@ GIT_EXTERN(int) git_odb_write(git_oid *oid, git_odb *odb, const void *data, size
*
* 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
*
@@ -247,7 +232,7 @@ GIT_EXTERN(int) git_odb_open_wstream(git_odb_stream **stream, git_odb *db, size_
*
* 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
*
@@ -265,18 +250,31 @@ GIT_EXTERN(int) git_odb_open_rstream(git_odb_stream **stream, git_odb *db, const
/**
* Determine the object-ID (sha1 hash) of a data buffer
*
- * The resulting SHA-1 OID will the itentifier for the data
+ * 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 id the resulting object-ID.
* @param data data to hash
* @param len size of the data
* @param type of the data to hash
- * @return 0 on success; error code otherwise
+ * @return 0 or an error code
*/
GIT_EXTERN(int) git_odb_hash(git_oid *id, 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. Similar functionality
+ * to git.git's `git hash-object` without the `-w` flag.
+ *
+ * @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
@@ -284,7 +282,7 @@ GIT_EXTERN(int) git_odb_hash(git_oid *id, const void *data, size_t len, git_otyp
*
* @param object object to close
*/
-GIT_EXTERN(void) git_odb_object_close(git_odb_object *object);
+GIT_EXTERN(void) git_odb_object_free(git_odb_object *object);
/**
* Return the OID of an ODB object
diff --git a/include/git2/odb_backend.h b/include/git2/odb_backend.h
index 796d2b9da..f4620f5f4 100644
--- a/include/git2/odb_backend.h
+++ b/include/git2/odb_backend.h
@@ -1,26 +1,8 @@
/*
- * This file is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, version 2,
- * as published by the Free Software Foundation.
+ * Copyright (C) 2009-2012 the libgit2 contributors
*
- * In addition to the permissions in the GNU General Public License,
- * the authors give you unlimited permission to link the compiled
- * version of this file into combinations with other programs,
- * and to distribute those combinations without any restriction
- * coming from the use of this file. (The General Public License
- * restrictions do apply in other respects; for example, they cover
- * modification of the file, and distribution when not linked into
- * a combined executable.)
- *
- * This file is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; see the file COPYING. If not, write to
- * the Free Software Foundation, 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
+ * 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__
@@ -92,6 +74,13 @@ struct git_odb_backend {
void (* free)(struct git_odb_backend *);
};
+/** 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;
@@ -103,17 +92,8 @@ struct git_odb_stream {
void (*free)(struct git_odb_stream *stream);
};
-/** Streaming mode */
-typedef enum {
- GIT_STREAM_RDONLY = (1 << 1),
- GIT_STREAM_WRONLY = (1 << 2),
- GIT_STREAM_RW = (GIT_STREAM_RDONLY | GIT_STREAM_WRONLY),
-} git_odb_streammode;
-
-
GIT_EXTERN(int) git_odb_backend_pack(git_odb_backend **backend_out, const char *objects_dir);
-GIT_EXTERN(int) git_odb_backend_loose(git_odb_backend **backend_out, const char *objects_dir);
-GIT_EXTERN(int) git_odb_backend_sqlite(git_odb_backend **backend_out, const char *sqlite_db);
+GIT_EXTERN(int) git_odb_backend_loose(git_odb_backend **backend_out, const char *objects_dir, int compression_level, int do_fsync);
GIT_END_DECL
diff --git a/include/git2/oid.h b/include/git2/oid.h
index f1f7dcc6c..a05b40a37 100644
--- a/include/git2/oid.h
+++ b/include/git2/oid.h
@@ -1,26 +1,8 @@
/*
- * This file is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, version 2,
- * as published by the Free Software Foundation.
- *
- * In addition to the permissions in the GNU General Public License,
- * the authors give you unlimited permission to link the compiled
- * version of this file into combinations with other programs,
- * and to distribute those combinations without any restriction
- * coming from the use of this file. (The General Public License
- * restrictions do apply in other respects; for example, they cover
- * modification of the file, and distribution when not linked into
- * a combined executable.)
- *
- * This file is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; see the file COPYING. If not, write to
- * the Free Software Foundation, 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
+ * Copyright (C) 2009-2012 the libgit2 contributors
+ *
+ * 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__
@@ -48,65 +30,83 @@ GIT_BEGIN_DECL
#define GIT_OID_MINPREFIXLEN 4
/** Unique identity of any object (commit, tree, blob, tag). */
-typedef struct {
+typedef struct _git_oid git_oid;
+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 GIT_SUCCESS if valid; GIT_ENOTOID on failure.
+ * 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_mkstr(git_oid *out, const char *str);
+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_mkraw(git_oid *out, const unsigned char *raw);
+GIT_EXTERN(void) git_oid_fromraw(git_oid *out, const unsigned char *raw);
/**
* Format a git_oid into a hex string.
+ *
* @param str 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.
+ * 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 *str, const git_oid *oid);
/**
* Format a git_oid into a loose-object path string.
- * <p>
+ *
* The resulting string is "aa/...", where "aa" is the first two
- * hex digitis of the oid and "..." is the remaining 38 digits.
+ * hex digits of the oid and "..." is the remaining 38 digits.
*
* @param str 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.
+ * 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 oid oid structure to format.
*/
GIT_EXTERN(void) git_oid_pathfmt(char *str, const git_oid *oid);
/**
- * Format a gid_oid into a newly allocated c-string.
+ * 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 free().
+ * @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 *oid);
/**
* Format a git_oid into a buffer as a hex format c-string.
- * <p>
+ *
* 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),
@@ -117,12 +117,13 @@ GIT_EXTERN(char *) git_oid_allocfmt(const git_oid *oid);
* @param n the size of the out buffer.
* @param oid the oid structure to format.
* @return the out buffer pointer, assuming no input parameter
- * errors, otherwise a pointer to an empty string.
+ * errors, otherwise a pointer to an empty string.
*/
-GIT_EXTERN(char *) git_oid_to_string(char *out, size_t n, const git_oid *oid);
+GIT_EXTERN(char *) git_oid_tostr(char *out, size_t n, const git_oid *oid);
/**
* Copy an oid from one structure to another.
+ *
* @param out oid structure the result is written into.
* @param src oid structure to copy from.
*/
@@ -130,6 +131,7 @@ 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.
@@ -139,12 +141,28 @@ GIT_EXTERN(int) git_oid_cmp(const git_oid *a, const git_oid *b);
/**
* Compare the first 'len' hexadecimal characters (packets of 4 bits)
* of two oid structures.
- * @param len the number of hex chars to compare
+ *
* @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) gid_oid_match(unsigned int len, git_oid *a, git_oid *b);
+GIT_EXTERN(int) git_oid_ncmp(const git_oid *a, const git_oid *b, unsigned int len);
+
+/**
+ * Check if an oid equals an hex formatted object id.
+ *
+ * @param a 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 *a, const char *str);
+
+/**
+ * Check is an oid is all zeros.
+ */
+GIT_EXTERN(int) git_oid_iszero(const git_oid *a);
/**
* OID Shortener object
@@ -165,7 +183,7 @@ typedef struct git_oid_shorten git_oid_shorten;
* be unique.
* @return a `git_oid_shorten` instance, NULL if OOM
*/
-git_oid_shorten *git_oid_shorten_new(size_t min_length);
+GIT_EXTERN(git_oid_shorten *) git_oid_shorten_new(size_t min_length);
/**
* Add a new OID to set of shortened OIDs and calculate
@@ -191,14 +209,14 @@ git_oid_shorten *git_oid_shorten_new(size_t min_length);
* added so far to the set; or an error code (<0) if an
* error occurs.
*/
-int git_oid_shorten_add(git_oid_shorten *os, const char *text_oid);
+GIT_EXTERN(int) git_oid_shorten_add(git_oid_shorten *os, const char *text_oid);
/**
* Free an OID shortener instance
- *
+ *
* @param os a `git_oid_shorten` instance
*/
-void git_oid_shorten_free(git_oid_shorten *os);
+GIT_EXTERN(void) git_oid_shorten_free(git_oid_shorten *os);
/** @} */
GIT_END_DECL
diff --git a/include/git2/reflog.h b/include/git2/reflog.h
new file mode 100644
index 000000000..f490e29de
--- /dev/null
+++ b/include/git2/reflog.h
@@ -0,0 +1,128 @@
+/*
+ * Copyright (C) 2009-2012 the libgit2 contributors
+ *
+ * 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
+ *
+ * The reflog must be freed manually by using
+ * git_reflog_free().
+ *
+ * @param reflog 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 **reflog, git_reference *ref);
+
+/**
+ * Write a new reflog for the given reference
+ *
+ * If there is no reflog file for the given
+ * reference yet, it will be created.
+ *
+ * `oid_old` may be NULL in case it's a new reference.
+ *
+ * `msg` is optional and can be NULL.
+ *
+ * @param ref the changed reference
+ * @param oid_old the OID the reference was 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_write(git_reference *ref, const git_oid *oid_old, const git_signature *committer, const char *msg);
+
+/**
+ * Rename the reflog for the given reference
+ *
+ * @param ref the reference
+ * @param new_name the new name of the reference
+ * @return 0 or an error code
+ */
+GIT_EXTERN(int) git_reflog_rename(git_reference *ref, const char *new_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(unsigned int) git_reflog_entrycount(git_reflog *reflog);
+
+/**
+ * Lookup an entry by its index
+ *
+ * @param reflog a previously loaded reflog
+ * @param idx the position to lookup
+ * @return the entry; NULL if not found
+ */
+GIT_EXTERN(const git_reflog_entry *) git_reflog_entry_byindex(git_reflog *reflog, unsigned int idx);
+
+/**
+ * Get the old oid
+ *
+ * @param entry a reflog entry
+ * @return the old oid
+ */
+GIT_EXTERN(const git_oid *) git_reflog_entry_oidold(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_oidnew(const git_reflog_entry *entry);
+
+/**
+ * Get the committer of this entry
+ *
+ * @param entry a reflog entry
+ * @return the committer
+ */
+GIT_EXTERN(git_signature *) git_reflog_entry_committer(const git_reflog_entry *entry);
+
+/**
+ * Get the log msg
+ *
+ * @param entry a reflog entry
+ * @return the log msg
+ */
+GIT_EXTERN(char *) git_reflog_entry_msg(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
diff --git a/include/git2/refs.h b/include/git2/refs.h
index 298c66d51..2918215aa 100644
--- a/include/git2/refs.h
+++ b/include/git2/refs.h
@@ -1,26 +1,8 @@
/*
- * This file is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, version 2,
- * as published by the Free Software Foundation.
- *
- * In addition to the permissions in the GNU General Public License,
- * the authors give you unlimited permission to link the compiled
- * version of this file into combinations with other programs,
- * and to distribute those combinations without any restriction
- * coming from the use of this file. (The General Public License
- * restrictions do apply in other respects; for example, they cover
- * modification of the file, and distribution when not linked into
- * a combined executable.)
- *
- * This file is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; see the file COPYING. If not, write to
- * the Free Software Foundation, 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
+ * Copyright (C) 2009-2012 the libgit2 contributors
+ *
+ * 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__
@@ -41,53 +23,45 @@ GIT_BEGIN_DECL
/**
* Lookup a reference by its name in a repository.
*
- * The generated reference is owned by the repository and
- * should not be freed by the user.
+ * The generated reference must be freed by the user.
*
* @param reference_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, ref/heads/master, refs/tags/v0.1.0, ...)
- * @return 0 on success; error code otherwise
+ * @return 0 or an error code
*/
GIT_EXTERN(int) git_reference_lookup(git_reference **reference_out, git_repository *repo, const char *name);
/**
- * Create a new symbolic reference.
- *
- * The reference will be created in the repository and written
- * to the disk.
- *
- * This reference is owned by the repository and shall not
- * be free'd by the user.
+ * Lookup a reference by name and resolve immediately to OID.
*
- * @param ref_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
- * @return 0 on success; error code otherwise
+ * @param oid 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, -1 if name could not be resolved
*/
-GIT_EXTERN(int) git_reference_create_symbolic(git_reference **ref_out, git_repository *repo, const char *name, const char *target);
+GIT_EXTERN(int) git_reference_name_to_oid(
+ git_oid *out, git_repository *repo, const char *name);
/**
- * Create a new symbolic reference, overwriting an existing one with
- * the same name, if it exists.
- *
- * If the new reference isn't a symbolic one, any pointers to the old
- * reference become invalid.
+ * Create a new symbolic reference.
*
* The reference will be created in the repository and written
* to the disk.
*
- * This reference is owned by the repository and shall not
- * be free'd by the user.
+ * The generated reference must be freed by the user.
+ *
+ * If `force` is true and there already exists a reference
+ * with the same name, it will be overwritten.
*
* @param ref_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
- * @return 0 on success; error code otherwise
+ * @param force Overwrite existing references
+ * @return 0 or an error code
*/
-GIT_EXTERN(int) git_reference_create_symbolic_f(git_reference **ref_out, git_repository *repo, const char *name, const char *target);
+GIT_EXTERN(int) git_reference_create_symbolic(git_reference **ref_out, git_repository *repo, const char *name, const char *target, int force);
/**
* Create a new object id reference.
@@ -95,41 +69,23 @@ GIT_EXTERN(int) git_reference_create_symbolic_f(git_reference **ref_out, git_rep
* The reference will be created in the repository and written
* to the disk.
*
- * This reference is owned by the repository and shall not
- * be free'd by the user.
+ * The generated reference must be freed by the user.
*
- * @param ref_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.
- * @return 0 on success; error code otherwise
- */
-GIT_EXTERN(int) git_reference_create_oid(git_reference **ref_out, git_repository *repo, const char *name, const git_oid *id);
-
-/**
- * Create a new object id reference, overwriting an existing one with
- * the same name, if it exists.
- *
- * If the new reference isn't an object id one, any pointers to the
- * old reference become invalid.
- *
- * The reference will be created in the repository and written
- * to the disk.
- *
- * This reference is owned by the repository and shall not
- * be free'd by the user.
+ * If `force` is true and there already exists a reference
+ * with the same name, it will be overwritten.
*
* @param ref_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.
- * @return 0 on success; error code otherwise
+ * @param force Overwrite existing references
+ * @return 0 or an error code
*/
-GIT_EXTERN(int) git_reference_create_oid_f(git_reference **ref_out, git_repository *repo, const char *name, const git_oid *id);
+GIT_EXTERN(int) git_reference_create_oid(git_reference **ref_out, git_repository *repo, const char *name, const git_oid *id, int force);
/**
* Get the OID pointed to by a reference.
- *
+ *
* Only available if the reference is direct (i.e. not symbolic)
*
* @param ref The reference
@@ -139,7 +95,7 @@ GIT_EXTERN(const git_oid *) git_reference_oid(git_reference *ref);
/**
* Get full name to the reference pointed by this reference
- *
+ *
* Only available if the reference is symbolic
*
* @param ref The reference
@@ -155,7 +111,7 @@ GIT_EXTERN(const char *) git_reference_target(git_reference *ref);
* @param ref The reference
* @return the type
*/
-GIT_EXTERN(git_rtype) git_reference_type(git_reference *ref);
+GIT_EXTERN(git_ref_t) git_reference_type(git_reference *ref);
/**
* Get the full name of a reference
@@ -166,17 +122,22 @@ GIT_EXTERN(git_rtype) git_reference_type(git_reference *ref);
GIT_EXTERN(const char *) git_reference_name(git_reference *ref);
/**
- * Resolve a symbolic reference
+ * Resolve a symbolic reference
*
- * Thie method iteratively peels a symbolic 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,
- * that reference is returned immediately
+ * 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 on success; error code otherwise
+ * @return 0 or an error code
*/
GIT_EXTERN(int) git_reference_resolve(git_reference **resolved_ref, git_reference *ref);
@@ -199,7 +160,7 @@ GIT_EXTERN(git_repository *) git_reference_owner(git_reference *ref);
*
* @param ref The reference
* @param target The new target for the reference
- * @return 0 on success; error code otherwise
+ * @return 0 or an error code
*/
GIT_EXTERN(int) git_reference_set_target(git_reference *ref, const char *target);
@@ -213,8 +174,8 @@ GIT_EXTERN(int) git_reference_set_target(git_reference *ref, const char *target)
* memory and on disk.
*
* @param ref The reference
- * @param target The new target OID for the reference
- * @return 0 on success; error code otherwise
+ * @param id The new target OID for the reference
+ * @return 0 or an error code
*/
GIT_EXTERN(int) git_reference_set_oid(git_reference *ref, const git_oid *id);
@@ -225,25 +186,26 @@ GIT_EXTERN(int) git_reference_set_oid(git_reference *ref, const git_oid *id);
* The new name will be checked for validity and may be
* modified into a normalized form.
*
- * The refernece will be immediately renamed in-memory
+ * The given git_reference will be updated in place.
+ *
+ * The reference will be immediately renamed in-memory
* and on disk.
*
- */
-GIT_EXTERN(int) git_reference_rename(git_reference *ref, const char *new_name);
-
-/**
- * Rename an existing reference, overwriting an existing one with the
- * same name, if it exists.
+ * If the `force` flag is not enabled, and there's already
+ * a reference with the given name, the renaming will fail.
*
- * This method works for both direct and symbolic references.
- * The new name will be checked for validity and may be
- * modified into a normalized form.
+ * 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.
*
- * The refernece will be immediately renamed in-memory
- * and on disk.
+ * @param ref The reference to rename
+ * @param new_name The new name for the reference
+ * @param force Overwrite an existing reference
+ * @return 0 or an error code
*
*/
-GIT_EXTERN(int) git_reference_rename_f(git_reference *ref, const char *new_name);
+GIT_EXTERN(int) git_reference_rename(git_reference *ref, const char *new_name, int force);
/**
* Delete an existing reference
@@ -253,6 +215,8 @@ GIT_EXTERN(int) git_reference_rename_f(git_reference *ref, const char *new_name)
* The reference will be immediately removed on disk and from
* memory. 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);
@@ -260,17 +224,14 @@ 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
+ * 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.
*
- * WARNING: calling this method may invalidate any existing
- * references previously loaded on the cache.
- *
* @param repo Repository where the loose refs will be packed
- * @return 0 on success; error code otherwise
+ * @return 0 or an error code
*/
GIT_EXTERN(int) git_reference_packall(git_repository *repo);
@@ -293,16 +254,15 @@ GIT_EXTERN(int) git_reference_packall(git_repository *repo);
* @param repo Repository where to find the refs
* @param list_flags Filtering flags for the reference
* listing.
- * @return 0 on success; error code otherwise
+ * @return 0 or an error code
*/
-GIT_EXTERN(int) git_reference_listall(git_strarray *array, git_repository *repo, unsigned int list_flags);
+GIT_EXTERN(int) git_reference_list(git_strarray *array, git_repository *repo, unsigned int list_flags);
/**
- * List all the references in the repository, calling a custom
- * callback for each one.
+ * Perform an operation on each reference in the repository
*
- * The listed references may be filtered by type, or using
+ * The processed references may be filtered by type, or using
* a bitwise OR of several types. Use the magic value
* `GIT_REF_LISTALL` to obtain all references, including
* packed ones.
@@ -316,9 +276,53 @@ GIT_EXTERN(int) git_reference_listall(git_strarray *array, git_repository *repo,
* 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; error code otherwise
+ * @return 0 or an error code
+ */
+GIT_EXTERN(int) git_reference_foreach(git_repository *repo, unsigned int list_flags, int (*callback)(const char *, void *), 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 may 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.
+ *
+ * @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_listcb(git_repository *repo, unsigned int list_flags, int (*callback)(const char *, void *), void *payload);
+GIT_EXTERN(int) git_reference_cmp(git_reference *ref1, git_reference *ref2);
/** @} */
GIT_END_DECL
diff --git a/include/git2/refspec.h b/include/git2/refspec.h
new file mode 100644
index 000000000..1100e9022
--- /dev/null
+++ b/include/git2/refspec.h
@@ -0,0 +1,68 @@
+/*
+ * Copyright (C) 2009-2012 the libgit2 contributors
+ *
+ * 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 ouf 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
diff --git a/include/git2/remote.h b/include/git2/remote.h
new file mode 100644
index 000000000..5c01949d2
--- /dev/null
+++ b/include/git2/remote.h
@@ -0,0 +1,243 @@
+/*
+ * Copyright (C) 2009-2012 the libgit2 contributors
+ *
+ * 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"
+
+/**
+ * @file git2/remote.h
+ * @brief Git remote management functions
+ * @defgroup git_remote remote management functions
+ * @ingroup Git
+ * @{
+ */
+GIT_BEGIN_DECL
+
+/*
+ * TODO: This functions still need to be implemented:
+ * - _listcb/_foreach
+ * - _add
+ * - _rename
+ * - _del (needs support from config)
+ */
+
+/**
+ * Create a remote in memory
+ *
+ * Create a remote with the default refspecs in memory. You can use
+ * this when you have a URL instead of a remote's name.
+ *
+ * @param out pointer to the new remote object
+ * @param repo the associated repository
+ * @param name the remote's name
+ * @param url the remote repository's URL
+ * @param fetch the fetch refspec to use for this remote
+ * @return 0 or an error code
+ */
+GIT_EXTERN(int) git_remote_new(git_remote **out, git_repository *repo, const char *name, const char *url, const char *fetch);
+
+/**
+ * Get the information for a particular remote
+ *
+ * @param out pointer to the new remote object
+ * @param cfg the repository's configuration
+ * @param name the remote's name
+ * @return 0 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
+ *
+ * @param remote the remote to save to config
+ * @return 0 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
+ */
+GIT_EXTERN(const char *) git_remote_name(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(git_remote *remote);
+
+/**
+ * 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(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(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, int 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.
+ *
+ * @param refs where to store the refs
+ * @param remote the remote
+ * @return 0 or an 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 filename where to store the temporary filename
+ * @return 0 or an error code
+ */
+GIT_EXTERN(int) git_remote_download(git_remote *remote, git_off_t *bytes, git_indexer_stats *stats);
+
+/**
+ * Check whether the remote is connected
+ *
+ * Check whether the remote's underlying transport is connected to the
+ * remote host.
+ *
+ * @return 1 if it's connected, 0 otherwise.
+ */
+GIT_EXTERN(int) git_remote_connected(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
+ * @param cb callback to run on each ref update. 'a' is the old value, 'b' is then new value
+ */
+GIT_EXTERN(int) git_remote_update_tips(git_remote *remote, int (*cb)(const char *refname, const git_oid *a, const git_oid *b));
+
+/**
+ * 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 remotes_list a string array with 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 *remotes_list, git_repository *repo);
+
+/**
+ * Add a remote with the default fetch refspec to the repository's configuration
+ *
+ * @param out the resulting remote
+ * @param repo the repository in which to create the remote
+ * @param name the remote's name
+ * @param url the remote's url
+ */
+GIT_EXTERN(int) git_remote_add(git_remote **out, git_repository *repo, const char *name, const char *url);
+
+/**
+ * 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);
+
+/** @} */
+GIT_END_DECL
+#endif
diff --git a/include/git2/repository.h b/include/git2/repository.h
index 493e82ad5..0b56a0870 100644
--- a/include/git2/repository.h
+++ b/include/git2/repository.h
@@ -1,26 +1,8 @@
/*
- * This file is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, version 2,
- * as published by the Free Software Foundation.
- *
- * In addition to the permissions in the GNU General Public License,
- * the authors give you unlimited permission to link the compiled
- * version of this file into combinations with other programs,
- * and to distribute those combinations without any restriction
- * coming from the use of this file. (The General Public License
- * restrictions do apply in other respects; for example, they cover
- * modification of the file, and distribution when not linked into
- * a combined executable.)
- *
- * This file is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; see the file COPYING. If not, write to
- * the Free Software Foundation, 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
+ * Copyright (C) 2009-2012 the libgit2 contributors
+ *
+ * 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__
@@ -41,131 +23,73 @@ GIT_BEGIN_DECL
/**
* Open a git repository.
*
- * The 'path' argument must point to an existing git repository
- * folder, e.g.
- *
- * /path/to/my_repo/.git/ (normal repository)
- * objects/
- * index
- * HEAD
- *
- * /path/to/bare_repo/ (bare repository)
- * objects/
- * index
- * HEAD
+ * 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.
+ * The method will automatically detect if 'path' is a normal
+ * or bare repository or fail is 'path' is neither.
*
* @param repository pointer to the repo which will be opened
* @param path the path to the repository
- * @return 0 on success; error code otherwise
+ * @return 0 or an error code
*/
GIT_EXTERN(int) git_repository_open(git_repository **repository, const char *path);
-
/**
- * Open a git repository by manually specifying all its paths
- *
- * @param repository pointer to the repo which will be opened
- *
- * @param git_dir The full path to the repository folder
- * e.g. a '.git' folder for live repos, any folder for bare
- * Equivalent to $GIT_DIR.
- * Cannot be NULL.
- *
- * @param git_object_directory The full path to the ODB folder.
- * the folder where all the loose and packed objects are stored
- * Equivalent to $GIT_OBJECT_DIRECTORY.
- * If NULL, "$GIT_DIR/objects/" is assumed.
+ * 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).
*
- * @param git_index_file The full path to the index (dircache) file
- * Equivalent to $GIT_INDEX_FILE.
- * If NULL, "$GIT_DIR/index" is assumed.
- *
- * @param git_work_tree The full path to the working tree of the repository,
- * if the repository is not bare.
- * Equivalent to $GIT_WORK_TREE.
- * If NULL, the repository is assumed to be bare.
- *
- * @return 0 on success; error code otherwise
- */
-GIT_EXTERN(int) git_repository_open2(git_repository **repository,
- const char *git_dir,
- const char *git_object_directory,
- const char *git_index_file,
- const char *git_work_tree);
-
-
-/**
- * Open a git repository by manually specifying its paths and
- * the object database it will use.
+ * The method will automatically detect if the repository is bare
+ * (if there is a repository).
*
- * @param repository pointer to the repo which will be opened
+ * @param repository_path The user allocated buffer which will
+ * contain the found path.
*
- * @param git_dir The full path to the repository folder
- * e.g. a '.git' folder for live repos, any folder for bare
- * Equivalent to $GIT_DIR.
- * Cannot be NULL.
+ * @param size repository_path size
*
- * @param object_database A pointer to a git_odb created & initialized
- * by the user (e.g. with custom backends). This object database
- * will be owned by the repository and will be automatically free'd.
- * It should not be manually free'd by the user, or this
- * git_repository object will become invalid.
+ * @param start_path The base path where the lookup starts.
*
- * @param git_index_file The full path to the index (dircache) file
- * Equivalent to $GIT_INDEX_FILE.
- * If NULL, "$GIT_DIR/index" is assumed.
+ * @param across_fs If true, then the lookup will not stop when a
+ * filesystem device change is detected while exploring parent directories.
*
- * @param git_work_tree The full path to the working tree of the repository,
- * if the repository is not bare.
- * Equivalent to $GIT_WORK_TREE.
- * If NULL, the repository is assumed to be bare.
+ * @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 on success; error code otherwise
+ * @return 0 or an error code
*/
+GIT_EXTERN(int) git_repository_discover(
+ char *repository_path,
+ size_t size,
+ const char *start_path,
+ int across_fs,
+ const char *ceiling_dirs);
-GIT_EXTERN(int) git_repository_open3(git_repository **repository,
- const char *git_dir,
- git_odb *object_database,
- const char *git_index_file,
- const char *git_work_tree);
+enum {
+ GIT_REPOSITORY_OPEN_NO_SEARCH = (1 << 0),
+ GIT_REPOSITORY_OPEN_CROSS_FS = (1 << 1),
+};
/**
- * Get the object database behind a Git repository
- *
- * @param repo a repository object
- * @return a pointer to the object db
+ * Find and open a repository with extended controls.
*/
-GIT_EXTERN(git_odb *) git_repository_database(git_repository *repo);
-
-/**
- * Open the Index file of a Git repository
- *
- * This returns a new and unique `git_index` object representing the
- * active index for the repository.
- *
- * This method may be called more than once (e.g. on different threads).
- *
- * Each returned `git_index` object is independent and suffers no race
- * conditions: synchronization is done at the FS level.
- *
- * Each returned `git_index` object must be manually freed by the user,
- * using `git_index_free`.
- *
- * @param index Pointer where to store the index
- * @param repo a repository object
- * @return 0 on success; error code if the index could not be opened
- */
-GIT_EXTERN(int) git_repository_index(git_index **index, git_repository *repo);
+GIT_EXTERN(int) git_repository_open_ext(
+ git_repository **repo,
+ const char *start_path,
+ uint32_t 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_close`, but accessing any of the attributes of
+ * with `git_object_free`, but accessing any of the attributes of
* an object without a backing repository will result in undefined
* behavior
*
@@ -178,19 +102,52 @@ GIT_EXTERN(void) git_repository_free(git_repository *repo);
*
* TODO:
* - Reinit the repository
- * - Create config files
*
* @param repo_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
+ * @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 on success; error code otherwise
+ * @return 0 or an error code
*/
GIT_EXTERN(int) git_repository_init(git_repository **repo_out, const char *path, unsigned is_bare);
/**
+ * Retrieve and resolve the reference pointed at by HEAD.
+ *
+ * @param head_out pointer to the reference which will be retrieved
+ * @param repo a repository object
+ *
+ * @return 0 on success; error code otherwise
+ */
+GIT_EXTERN(int) git_repository_head(git_reference **head_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
@@ -203,31 +160,145 @@ GIT_EXTERN(int) git_repository_init(git_repository **repo_out, const char *path,
GIT_EXTERN(int) git_repository_is_empty(git_repository *repo);
/**
- * Get the normalized path to the git repository.
+ * Get the path of this repository
*
- * @param repo a repository object
- * @return absolute path to the git directory
+ * 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 normalized path to the working directory of the repository.
+ * Get the path of the working directory for this repository
*
- * If the repository is bare, there is no working directory and NULL we be returned.
+ * If the repository is bare, this function will always return
+ * NULL.
*
- * @param repo a repository object
- * @return NULL if the repository is bare; absolute path to the working directory otherwise.
+ * @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
+ * @return 0, or an error code
+ */
+GIT_EXTERN(int) git_repository_set_workdir(git_repository *repo, const char *workdir);
+
+/**
* Check if a repository is bare
*
* @param repo Repo to test
- * @return 1 if the repository is empty, 0 otherwise.
+ * @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);
+
/** @} */
GIT_END_DECL
#endif
diff --git a/include/git2/revwalk.h b/include/git2/revwalk.h
index f3e0152d4..2e9dc421a 100644
--- a/include/git2/revwalk.h
+++ b/include/git2/revwalk.h
@@ -1,26 +1,8 @@
/*
- * This file is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, version 2,
- * as published by the Free Software Foundation.
- *
- * In addition to the permissions in the GNU General Public License,
- * the authors give you unlimited permission to link the compiled
- * version of this file into combinations with other programs,
- * and to distribute those combinations without any restriction
- * coming from the use of this file. (The General Public License
- * restrictions do apply in other respects; for example, they cover
- * modification of the file, and distribution when not linked into
- * a combined executable.)
- *
- * This file is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; see the file COPYING. If not, write to
- * the Free Software Foundation, 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
+ * Copyright (C) 2009-2012 the libgit2 contributors
+ *
+ * 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__
@@ -44,28 +26,28 @@ GIT_BEGIN_DECL
* and subject to change at any time.
* This is the default sorting for new walkers.
*/
-#define GIT_SORT_NONE (0)
+#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)
+#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)
+#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)
+#define GIT_SORT_REVERSE (1 << 2)
/**
* Allocate a new revision walker to iterate through a repo.
@@ -83,7 +65,7 @@ GIT_BEGIN_DECL
*
* @param walker pointer to the new revision walker
* @param repo the repo to walk through
- * @return 0 on success; error code otherwise
+ * @return 0 or an error code
*/
GIT_EXTERN(int) git_revwalk_new(git_revwalk **walker, git_repository *repo);
@@ -113,12 +95,34 @@ GIT_EXTERN(void) git_revwalk_reset(git_revwalk *walker);
* must be pushed the repository before a walk can
* be started.
*
- * @param walker the walker being used for the traversal.
+ * @param walk the walker being used for the traversal.
* @param oid the oid of the commit to start from.
- * @return 0 on success; error code otherwise
+ * @return 0 or an error code
*/
GIT_EXTERN(int) git_revwalk_push(git_revwalk *walk, const git_oid *oid);
+/**
+ * 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 it 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.
@@ -129,13 +133,59 @@ GIT_EXTERN(int) git_revwalk_push(git_revwalk *walk, const git_oid *oid);
* The resolved commit and all its parents will be hidden from the
* output on the revision walk.
*
- * @param walker the walker being used for the traversal.
- * @param commit the commit that will be ignored during the traversal
- * @return 0 on success; error code otherwise
+ * @param walk the walker being used for the traversal.
+ * @param oid 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 *oid);
/**
+ * 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 it 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
@@ -150,8 +200,8 @@ GIT_EXTERN(int) git_revwalk_hide(git_revwalk *walk, const git_oid *oid);
*
* @param oid Pointer where to store the oid of the next commit
* @param walk the walker to pop the commit from.
- * @return GIT_SUCCESS if the next commit was found;
- * GIT_EREVWALKOVER if there are no commits left to iterate
+ * @return 0 if the next commit was found;
+ * GIT_REVWALKOVER if there are no commits left to iterate
*/
GIT_EXTERN(int) git_revwalk_next(git_oid *oid, git_revwalk *walk);
@@ -169,7 +219,7 @@ 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.
+ * @param walk traversal handle to close. If NULL nothing occurs.
*/
GIT_EXTERN(void) git_revwalk_free(git_revwalk *walk);
diff --git a/include/git2/signature.h b/include/git2/signature.h
index 44d1f285e..cbf94269f 100644
--- a/include/git2/signature.h
+++ b/include/git2/signature.h
@@ -1,26 +1,8 @@
/*
- * This file is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, version 2,
- * as published by the Free Software Foundation.
+ * Copyright (C) 2009-2012 the libgit2 contributors
*
- * In addition to the permissions in the GNU General Public License,
- * the authors give you unlimited permission to link the compiled
- * version of this file into combinations with other programs,
- * and to distribute those combinations without any restriction
- * coming from the use of this file. (The General Public License
- * restrictions do apply in other respects; for example, they cover
- * modification of the file, and distribution when not linked into
- * a combined executable.)
- *
- * This file is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; see the file COPYING. If not, write to
- * the Free Software Foundation, 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
+ * 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__
@@ -41,23 +23,25 @@ GIT_BEGIN_DECL
* Create a new action signature. The signature must be freed
* manually or using git_signature_free
*
+ * @param sig_out new signature, in case of error NULL
* @param name name of the person
- * @param mail email 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 the new sig, NULL on out of memory
+ * @return 0 or an error code
*/
-GIT_EXTERN(git_signature *) git_signature_new(const char *name, const char *email, git_time_t time, int offset);
+GIT_EXTERN(int) git_signature_new(git_signature **sig_out, const char *name, const char *email, git_time_t time, int offset);
/**
* Create a new action signature with a timestamp of 'now'. The
* signature must be freed manually or using git_signature_free
*
+ * @param sig_out new signature, in case of error NULL
* @param name name of the person
* @param email email of the person
- * @return the new sig, NULL on out of memory
+ * @return 0 or an error code
*/
-GIT_EXTERN(git_signature *) git_signature_now(const char *name, const char *email);
+GIT_EXTERN(int) git_signature_now(git_signature **sig_out, const char *name, const char *email);
/**
diff --git a/include/git2/status.h b/include/git2/status.h
new file mode 100644
index 000000000..6a424dfd6
--- /dev/null
+++ b/include/git2/status.h
@@ -0,0 +1,164 @@
+/*
+ * Copyright (C) 2009-2012 the libgit2 contributors
+ *
+ * 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
+
+enum {
+ GIT_STATUS_CURRENT = 0,
+
+ GIT_STATUS_INDEX_NEW = (1 << 0),
+ GIT_STATUS_INDEX_MODIFIED = (1 << 1),
+ GIT_STATUS_INDEX_DELETED = (1 << 2),
+
+ GIT_STATUS_WT_NEW = (1 << 3),
+ GIT_STATUS_WT_MODIFIED = (1 << 4),
+ GIT_STATUS_WT_DELETED = (1 << 5),
+
+ GIT_STATUS_IGNORED = (1 << 6),
+};
+
+/**
+ * Gather file statuses and run a callback for each one.
+ *
+ * The callback is passed the path of the file, the status and the data
+ * pointer passed to this function. If the callback returns something other
+ * than 0, this function will return that value.
+ *
+ * @param repo a repository object
+ * @param callback the function to call on each file
+ * @return 0 on success or the return value of the callback that was non-zero
+ */
+GIT_EXTERN(int) git_status_foreach(
+ git_repository *repo,
+ int (*callback)(const char *, unsigned int, void *),
+ void *payload);
+
+/**
+ * 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.
+ */
+
+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_SUBMODULED = (1 << 3),
+ GIT_STATUS_OPT_RECURSE_UNTRACKED_DIRS = (1 << 4),
+};
+
+/**
+ * Options to control how callbacks will be made by
+ * `git_status_foreach_ext()`.
+ */
+typedef struct {
+ git_status_show_t show;
+ unsigned int flags;
+ git_strarray pathspec;
+} git_status_options;
+
+/**
+ * Gather file status information and run callbacks as requested.
+ */
+GIT_EXTERN(int) git_status_foreach_ext(
+ git_repository *repo,
+ const git_status_options *opts,
+ int (*callback)(const char *, unsigned int, void *),
+ void *payload);
+
+/**
+ * Get file status for a single file
+ *
+ * @param status_flags the status value
+ * @param repo a repository object
+ * @param path the file to retrieve status for, rooted at the repo's workdir
+ * @return GIT_EINVALIDPATH when `path` points at a folder, GIT_ENOTFOUND when
+ * the file doesn't exist in any of HEAD, the index or the worktree,
+ * 0 otherwise
+ */
+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 simply checks the ignore rules to see if they would apply
+ * to the given file. Unlike git_status_file(), this indicates if the file
+ * would be ignored regardless of whether the file is already in the index
+ * or in the repository.
+ *
+ * @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
diff --git a/include/git2/stdint.h b/include/git2/stdint.h
new file mode 100644
index 000000000..c66fbb817
--- /dev/null
+++ b/include/git2/stdint.h
@@ -0,0 +1,247 @@
+// ISO C9x compliant stdint.h for Microsoft Visual Studio
+// Based on ISO/IEC 9899:TC2 Committee draft (May 6, 2005) WG14/N1124
+//
+// Copyright (c) 2006-2008 Alexander Chemeris
+//
+// 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.
+//
+// 3. The name of the author may be used to endorse or promote products
+// derived from this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 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.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#ifndef _MSC_VER // [
+#error "Use this header only with Microsoft Visual C++ compilers!"
+#endif // _MSC_VER ]
+
+#ifndef _MSC_STDINT_H_ // [
+#define _MSC_STDINT_H_
+
+#if _MSC_VER > 1000
+#pragma once
+#endif
+
+#include <limits.h>
+
+// For Visual Studio 6 in C++ mode and for many Visual Studio versions when
+// compiling for ARM we should wrap <wchar.h> include with 'extern "C++" {}'
+// or compiler give many errors like this:
+// error C2733: second C linkage of overloaded function 'wmemchr' not allowed
+#ifdef __cplusplus
+extern "C" {
+#endif
+# include <wchar.h>
+#ifdef __cplusplus
+}
+#endif
+
+// Define _W64 macros to mark types changing their size, like intptr_t.
+#ifndef _W64
+# if !defined(__midl) && (defined(_X86_) || defined(_M_IX86)) && _MSC_VER >= 1300
+# define _W64 __w64
+# else
+# define _W64
+# endif
+#endif
+
+
+// 7.18.1 Integer types
+
+// 7.18.1.1 Exact-width integer types
+
+// Visual Studio 6 and Embedded Visual C++ 4 doesn't
+// realize that, e.g. char has the same size as __int8
+// so we give up on __intX for them.
+#if (_MSC_VER < 1300)
+ typedef signed char int8_t;
+ typedef signed short int16_t;
+ typedef signed int int32_t;
+ typedef unsigned char uint8_t;
+ typedef unsigned short uint16_t;
+ typedef unsigned int uint32_t;
+#else
+ typedef signed __int8 int8_t;
+ typedef signed __int16 int16_t;
+ typedef signed __int32 int32_t;
+ typedef unsigned __int8 uint8_t;
+ typedef unsigned __int16 uint16_t;
+ typedef unsigned __int32 uint32_t;
+#endif
+typedef signed __int64 int64_t;
+typedef unsigned __int64 uint64_t;
+
+
+// 7.18.1.2 Minimum-width integer types
+typedef int8_t int_least8_t;
+typedef int16_t int_least16_t;
+typedef int32_t int_least32_t;
+typedef int64_t int_least64_t;
+typedef uint8_t uint_least8_t;
+typedef uint16_t uint_least16_t;
+typedef uint32_t uint_least32_t;
+typedef uint64_t uint_least64_t;
+
+// 7.18.1.3 Fastest minimum-width integer types
+typedef int8_t int_fast8_t;
+typedef int16_t int_fast16_t;
+typedef int32_t int_fast32_t;
+typedef int64_t int_fast64_t;
+typedef uint8_t uint_fast8_t;
+typedef uint16_t uint_fast16_t;
+typedef uint32_t uint_fast32_t;
+typedef uint64_t uint_fast64_t;
+
+// 7.18.1.4 Integer types capable of holding object pointers
+#ifdef _WIN64 // [
+ typedef signed __int64 intptr_t;
+ typedef unsigned __int64 uintptr_t;
+#else // _WIN64 ][
+ typedef _W64 signed int intptr_t;
+ typedef _W64 unsigned int uintptr_t;
+#endif // _WIN64 ]
+
+// 7.18.1.5 Greatest-width integer types
+typedef int64_t intmax_t;
+typedef uint64_t uintmax_t;
+
+
+// 7.18.2 Limits of specified-width integer types
+
+#if !defined(__cplusplus) || defined(__STDC_LIMIT_MACROS) // [ See footnote 220 at page 257 and footnote 221 at page 259
+
+// 7.18.2.1 Limits of exact-width integer types
+#define INT8_MIN ((int8_t)_I8_MIN)
+#define INT8_MAX _I8_MAX
+#define INT16_MIN ((int16_t)_I16_MIN)
+#define INT16_MAX _I16_MAX
+#define INT32_MIN ((int32_t)_I32_MIN)
+#define INT32_MAX _I32_MAX
+#define INT64_MIN ((int64_t)_I64_MIN)
+#define INT64_MAX _I64_MAX
+#define UINT8_MAX _UI8_MAX
+#define UINT16_MAX _UI16_MAX
+#define UINT32_MAX _UI32_MAX
+#define UINT64_MAX _UI64_MAX
+
+// 7.18.2.2 Limits of minimum-width integer types
+#define INT_LEAST8_MIN INT8_MIN
+#define INT_LEAST8_MAX INT8_MAX
+#define INT_LEAST16_MIN INT16_MIN
+#define INT_LEAST16_MAX INT16_MAX
+#define INT_LEAST32_MIN INT32_MIN
+#define INT_LEAST32_MAX INT32_MAX
+#define INT_LEAST64_MIN INT64_MIN
+#define INT_LEAST64_MAX INT64_MAX
+#define UINT_LEAST8_MAX UINT8_MAX
+#define UINT_LEAST16_MAX UINT16_MAX
+#define UINT_LEAST32_MAX UINT32_MAX
+#define UINT_LEAST64_MAX UINT64_MAX
+
+// 7.18.2.3 Limits of fastest minimum-width integer types
+#define INT_FAST8_MIN INT8_MIN
+#define INT_FAST8_MAX INT8_MAX
+#define INT_FAST16_MIN INT16_MIN
+#define INT_FAST16_MAX INT16_MAX
+#define INT_FAST32_MIN INT32_MIN
+#define INT_FAST32_MAX INT32_MAX
+#define INT_FAST64_MIN INT64_MIN
+#define INT_FAST64_MAX INT64_MAX
+#define UINT_FAST8_MAX UINT8_MAX
+#define UINT_FAST16_MAX UINT16_MAX
+#define UINT_FAST32_MAX UINT32_MAX
+#define UINT_FAST64_MAX UINT64_MAX
+
+// 7.18.2.4 Limits of integer types capable of holding object pointers
+#ifdef _WIN64 // [
+# define INTPTR_MIN INT64_MIN
+# define INTPTR_MAX INT64_MAX
+# define UINTPTR_MAX UINT64_MAX
+#else // _WIN64 ][
+# define INTPTR_MIN INT32_MIN
+# define INTPTR_MAX INT32_MAX
+# define UINTPTR_MAX UINT32_MAX
+#endif // _WIN64 ]
+
+// 7.18.2.5 Limits of greatest-width integer types
+#define INTMAX_MIN INT64_MIN
+#define INTMAX_MAX INT64_MAX
+#define UINTMAX_MAX UINT64_MAX
+
+// 7.18.3 Limits of other integer types
+
+#ifdef _WIN64 // [
+# define PTRDIFF_MIN _I64_MIN
+# define PTRDIFF_MAX _I64_MAX
+#else // _WIN64 ][
+# define PTRDIFF_MIN _I32_MIN
+# define PTRDIFF_MAX _I32_MAX
+#endif // _WIN64 ]
+
+#define SIG_ATOMIC_MIN INT_MIN
+#define SIG_ATOMIC_MAX INT_MAX
+
+#ifndef SIZE_MAX // [
+# ifdef _WIN64 // [
+# define SIZE_MAX _UI64_MAX
+# else // _WIN64 ][
+# define SIZE_MAX _UI32_MAX
+# endif // _WIN64 ]
+#endif // SIZE_MAX ]
+
+// WCHAR_MIN and WCHAR_MAX are also defined in <wchar.h>
+#ifndef WCHAR_MIN // [
+# define WCHAR_MIN 0
+#endif // WCHAR_MIN ]
+#ifndef WCHAR_MAX // [
+# define WCHAR_MAX _UI16_MAX
+#endif // WCHAR_MAX ]
+
+#define WINT_MIN 0
+#define WINT_MAX _UI16_MAX
+
+#endif // __STDC_LIMIT_MACROS ]
+
+
+// 7.18.4 Limits of other integer types
+
+#if !defined(__cplusplus) || defined(__STDC_CONSTANT_MACROS) // [ See footnote 224 at page 260
+
+// 7.18.4.1 Macros for minimum-width integer constants
+
+#define INT8_C(val) val##i8
+#define INT16_C(val) val##i16
+#define INT32_C(val) val##i32
+#define INT64_C(val) val##i64
+
+#define UINT8_C(val) val##ui8
+#define UINT16_C(val) val##ui16
+#define UINT32_C(val) val##ui32
+#define UINT64_C(val) val##ui64
+
+// 7.18.4.2 Macros for greatest-width integer constants
+#define INTMAX_C INT64_C
+#define UINTMAX_C UINT64_C
+
+#endif // __STDC_CONSTANT_MACROS ]
+
+
+#endif // _MSC_STDINT_H_ ]
diff --git a/include/git2/submodule.h b/include/git2/submodule.h
new file mode 100644
index 000000000..f65911a3b
--- /dev/null
+++ b/include/git2/submodule.h
@@ -0,0 +1,103 @@
+/*
+ * Copyright (C) 2012 the libgit2 contributors
+ *
+ * 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
+
+typedef enum {
+ GIT_SUBMODULE_UPDATE_CHECKOUT = 0,
+ GIT_SUBMODULE_UPDATE_REBASE = 1,
+ GIT_SUBMODULE_UPDATE_MERGE = 2
+} git_submodule_update_t;
+
+typedef enum {
+ GIT_SUBMODULE_IGNORE_ALL = 0, /* never dirty */
+ GIT_SUBMODULE_IGNORE_DIRTY = 1, /* only dirty if HEAD moved */
+ GIT_SUBMODULE_IGNORE_UNTRACKED = 2, /* dirty if tracked files change */
+ GIT_SUBMODULE_IGNORE_NONE = 3 /* any change or untracked == dirty */
+} git_submodule_ignore_t;
+
+/**
+ * Description of submodule
+ *
+ * This record describes a submodule found in a repository. There
+ * should be an entry for every submodule found in the HEAD and for
+ * every submodule described in .gitmodules. The fields are as follows:
+ *
+ * - `name` is the name of the submodule from .gitmodules.
+ * - `path` is the path to the submodule from the repo working directory.
+ * It is almost always the same as `name`.
+ * - `url` is the url for the submodule.
+ * - `oid` is the HEAD SHA1 for the submodule.
+ * - `update` is a value from above - see gitmodules(5) update.
+ * - `ignore` is a value from above - see gitmodules(5) ignore.
+ * - `fetch_recurse` is 0 or 1 - see gitmodules(5) fetchRecurseSubmodules.
+ * - `refcount` is for internal use.
+ *
+ * If the submodule has been added to .gitmodules but not yet git added,
+ * then the `oid` will be zero. If the submodule has been deleted, but
+ * the delete has not been committed yet, then the `oid` will be set, but
+ * the `url` will be NULL.
+ */
+typedef struct {
+ char *name;
+ char *path;
+ char *url;
+ git_oid oid; /* sha1 of submodule HEAD ref or zero if not committed */
+ git_submodule_update_t update;
+ git_submodule_ignore_t ignore;
+ int fetch_recurse;
+ int refcount;
+} git_submodule;
+
+/**
+ * Iterate over all submodules of a repository.
+ *
+ * @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)(const char *name, void *payload),
+ void *payload);
+
+/**
+ * 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. If the submodule
+ * does not exist, this will return GIT_ENOTFOUND and set the submodule
+ * pointer to NULL.
+ *
+ * @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, -1 on error
+ */
+GIT_EXTERN(int) git_submodule_lookup(
+ git_submodule **submodule,
+ git_repository *repo,
+ const char *name);
+
+/** @} */
+GIT_END_DECL
+#endif
diff --git a/include/git2/tag.h b/include/git2/tag.h
index 3fc6b4499..13dc145b6 100644
--- a/include/git2/tag.h
+++ b/include/git2/tag.h
@@ -1,26 +1,8 @@
/*
- * This file is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, version 2,
- * as published by the Free Software Foundation.
- *
- * In addition to the permissions in the GNU General Public License,
- * the authors give you unlimited permission to link the compiled
- * version of this file into combinations with other programs,
- * and to distribute those combinations without any restriction
- * coming from the use of this file. (The General Public License
- * restrictions do apply in other respects; for example, they cover
- * modification of the file, and distribution when not linked into
- * a combined executable.)
- *
- * This file is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; see the file COPYING. If not, write to
- * the Free Software Foundation, 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
+ * Copyright (C) 2009-2012 the libgit2 contributors
+ *
+ * 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__
@@ -45,7 +27,7 @@ GIT_BEGIN_DECL
* @param tag 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 on success; error code otherwise
+ * @return 0 or an error code
*/
GIT_INLINE(int) git_tag_lookup(git_tag **tag, git_repository *repo, const git_oid *id)
{
@@ -53,9 +35,26 @@ GIT_INLINE(int) git_tag_lookup(git_tag **tag, git_repository *repo, const git_oi
}
/**
+ * Lookup a tag object from the repository,
+ * given a prefix of its identifier (short id).
+ *
+ * @see git_object_lookup_prefix
+ *
+ * @param tag 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 **tag, git_repository *repo, const git_oid *id, unsigned int len)
+{
+ return git_object_lookup_prefix((git_object **)tag, repo, id, len, (git_otype)GIT_OBJ_TAG);
+}
+
+/**
* Close an open tag
*
- * This is a wrapper around git_object_close()
+ * This is a wrapper around git_object_free()
*
* IMPORTANT:
* It *is* necessary to call this method when you stop
@@ -64,9 +63,9 @@ GIT_INLINE(int) git_tag_lookup(git_tag **tag, git_repository *repo, const git_oi
* @param tag the tag to close
*/
-GIT_INLINE(void) git_tag_close(git_tag *tag)
+GIT_INLINE(void) git_tag_free(git_tag *tag)
{
- git_object_close((git_object *) tag);
+ git_object_free((git_object *) tag);
}
@@ -86,9 +85,9 @@ GIT_EXTERN(const git_oid *) git_tag_id(git_tag *tag);
*
* @param target pointer where to store the target
* @param tag a previously loaded tag.
- * @return 0 on success; error code otherwise
+ * @return 0 or an error code
*/
-GIT_EXTERN(int) git_tag_target(git_object **target, git_tag *t);
+GIT_EXTERN(int) git_tag_target(git_object **target, git_tag *tag);
/**
* Get the OID of the tagged object of a tag
@@ -96,7 +95,7 @@ GIT_EXTERN(int) git_tag_target(git_object **target, git_tag *t);
* @param tag a previously loaded tag.
* @return pointer to the OID
*/
-GIT_EXTERN(const git_oid *) git_tag_target_oid(git_tag *t);
+GIT_EXTERN(const git_oid *) git_tag_target_oid(git_tag *tag);
/**
* Get the type of a tag's tagged object
@@ -104,7 +103,7 @@ GIT_EXTERN(const git_oid *) git_tag_target_oid(git_tag *t);
* @param tag a previously loaded tag.
* @return type of the tagged object
*/
-GIT_EXTERN(git_otype) git_tag_type(git_tag *t);
+GIT_EXTERN(git_otype) git_tag_type(git_tag *tag);
/**
* Get the name of a tag
@@ -112,7 +111,7 @@ GIT_EXTERN(git_otype) git_tag_type(git_tag *t);
* @param tag a previously loaded tag.
* @return name of the tag
*/
-GIT_EXTERN(const char *) git_tag_name(git_tag *t);
+GIT_EXTERN(const char *) git_tag_name(git_tag *tag);
/**
* Get the tagger (author) of a tag
@@ -120,7 +119,7 @@ GIT_EXTERN(const char *) git_tag_name(git_tag *t);
* @param tag a previously loaded tag.
* @return reference to the tag's author
*/
-GIT_EXTERN(const git_signature *) git_tag_tagger(git_tag *t);
+GIT_EXTERN(const git_signature *) git_tag_tagger(git_tag *tag);
/**
* Get the message of a tag
@@ -128,34 +127,41 @@ GIT_EXTERN(const git_signature *) git_tag_tagger(git_tag *t);
* @param tag a previously loaded tag.
* @return message of the tag
*/
-GIT_EXTERN(const char *) git_tag_message(git_tag *t);
+GIT_EXTERN(const char *) git_tag_message(git_tag *tag);
/**
- * Create a new tag in the repository from an OID
+ * 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 be cleaned up from excess whitespace
+ * it will be made sure that the last line ends with a '\n'.
*
* @param oid Pointer where to store the OID of the
- * newly created tag
+ * 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
+ * for consistency. It should also not conflict with an
* already existing tag name
*
- * @param target OID to which this tag points; note that no
- * validation is done on this OID. Use the _o version of this
- * method to assure a proper object is being tagged
- *
- * @param target_type Type of the tagged OID; note that no
- * validation is performed here either
+ * @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
+ * of the tagging time
*
* @param message Full message for this tag
*
- * @return 0 on success; error code otherwise.
+ * @param force Overwrite existing references
+ *
+ * @return 0 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
*/
@@ -163,103 +169,59 @@ GIT_EXTERN(int) git_tag_create(
git_oid *oid,
git_repository *repo,
const char *tag_name,
- const git_oid *target,
- git_otype target_type,
- const git_signature *tagger,
- const char *message);
-
-
-/**
- * Create a new tag in the repository from an existing
- * `git_object` instance
- *
- * This method replaces the `target` and `target_type`
- * paremeters of `git_tag_create` by a single instance
- * of a `const git_object *`, which is assured to be
- * a proper object in the ODB and hence will create
- * a valid tag
- *
- * @see git_tag_create
- */
-GIT_EXTERN(int) git_tag_create_o(
- git_oid *oid,
- git_repository *repo,
- const char *tag_name,
const git_object *target,
const git_signature *tagger,
- const char *message);
+ 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);
+ const char *buffer,
+ int force);
/**
- * Create a new tag in the repository from an OID
- * and overwrite an already existing tag reference, if any.
+ * Create a new lightweight tag pointing at a target object
*
- * @param oid Pointer where to store the OID of the
- * newly created tag
+ * 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.
*
- * @param repo Repository where to store the tag
+ * @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 tag_name Name for the tag; this name is validated
- * for consistency.
- *
- * @param target OID to which this tag points; note that no
- * validation is done on this OID. Use the _fo version of this
- * method to assure a proper object is being tagged
+ * @param repo Repository where to store the lightweight tag
*
- * @param target_type Type of the tagged OID; note that no
- * validation is performed here either
- *
- * @param tagger Signature of the tagger for this tag, and
- * of the tagging time
- *
- * @param message Full message for this 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
*
- * @return 0 on success; error code otherwise.
- * 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_f(
- git_oid *oid,
- git_repository *repo,
- const char *tag_name,
- const git_oid *target,
- git_otype target_type,
- const git_signature *tagger,
- const char *message);
-
-/**
- * Create a new tag in the repository from an existing
- * `git_object` instance and overwrite an already existing
- * tag reference, if any.
+ * @param target Object to which this tag points. This object
+ * must belong to the given `repo`.
*
- * This method replaces the `target` and `target_type`
- * paremeters of `git_tag_create_f` by a single instance
- * of a `const git_object *`, which is assured to be
- * a proper object in the ODB and hence will create
- * a valid tag
+ * @param force Overwrite existing references
*
- * @see git_tag_create_f
+ * @return 0 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_fo(
+GIT_EXTERN(int) git_tag_create_lightweight(
git_oid *oid,
git_repository *repo,
const char *tag_name,
const git_object *target,
- const git_signature *tagger,
- const char *message);
+ int force);
/**
* Delete an existing tag reference.
@@ -269,7 +231,7 @@ GIT_EXTERN(int) git_tag_create_fo(
* @param tag_name Name of the tag to be deleted;
* this name is validated for consistency.
*
- * @return 0 on success; error code otherwise.
+ * @return 0 or an error code
*/
GIT_EXTERN(int) git_tag_delete(
git_repository *repo,
@@ -283,15 +245,53 @@ GIT_EXTERN(int) git_tag_delete(
* should be free'd manually when no longer needed, using
* `git_strarray_free`.
*
- * @param array Pointer to a git_strarray structure where
+ * @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 on success; error code otherwise
+ * @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);
+
+/**
+ * Recursively peel a tag until a non tag git_object
+ * is met
+ *
+ * The retrieved `tag_target` object is owned by the repository
+ * and should be closed with the `git_object_free` method.
+ *
+ * @param tag_target 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,
+ git_tag *tag);
+
/** @} */
GIT_END_DECL
#endif
diff --git a/include/git2/thread-utils.h b/include/git2/thread-utils.h
deleted file mode 100644
index e26876bea..000000000
--- a/include/git2/thread-utils.h
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * This file is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, version 2,
- * as published by the Free Software Foundation.
- *
- * In addition to the permissions in the GNU General Public License,
- * the authors give you unlimited permission to link the compiled
- * version of this file into combinations with other programs,
- * and to distribute those combinations without any restriction
- * coming from the use of this file. (The General Public License
- * restrictions do apply in other respects; for example, they cover
- * modification of the file, and distribution when not linked into
- * a combined executable.)
- *
- * This file is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; see the file COPYING. If not, write to
- * the Free Software Foundation, 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
- */
-#ifndef INCLUDE_git_thread_utils_h__
-#define INCLUDE_git_thread_utils_h__
-
-/*
- * How TLS works is compiler+platform dependant
- * Sources: http://en.wikipedia.org/wiki/Thread-Specific_Storage
- * http://predef.sourceforge.net/precomp.html
- */
-
-#define GIT_HAS_TLS 1
-
-#if defined(__APPLE__) && defined(__MACH__)
-# undef GIT_TLS
-# define GIT_TLS
-
-#elif defined(__GNUC__) || \
- defined(__SUNPRO_C) || \
- defined(__SUNPRO_CC) || \
- defined(__xlc__) || \
- defined(__xlC__)
-# define GIT_TLS __thread
-
-#elif defined(__INTEL_COMPILER)
-# if defined(_WIN32) || defined(_WIN32_CE)
-# define GIT_TLS __declspec(thread)
-# else
-# define GIT_TLS __thread
-# endif
-
-#elif defined(_WIN32) || \
- defined(_WIN32_CE) || \
- defined(__BORLANDC__)
-# define GIT_TLS __declspec(thread)
-
-#else
-# undef GIT_HAS_TLS
-# define GIT_TLS /* nothing: tls vars are thread-global */
-#endif
-
-/* sparse and cygwin don't grok thread-local variables */
-#if defined(__CHECKER__) || defined(__CYGWIN__)
-# undef GIT_HAS_TLS
-# undef GIT_TLS
-# define GIT_TLS
-#endif
-
-#endif /* INCLUDE_git_thread_utils_h__ */
diff --git a/include/git2/threads.h b/include/git2/threads.h
new file mode 100644
index 000000000..567a10487
--- /dev/null
+++ b/include/git2/threads.h
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2009-2012 the libgit2 contributors
+ *
+ * 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.
+ */
+GIT_EXTERN(void) 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
+
diff --git a/include/git2/tree.h b/include/git2/tree.h
index 0caf60a48..8f62e752a 100644
--- a/include/git2/tree.h
+++ b/include/git2/tree.h
@@ -1,26 +1,8 @@
/*
- * This file is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, version 2,
- * as published by the Free Software Foundation.
- *
- * In addition to the permissions in the GNU General Public License,
- * the authors give you unlimited permission to link the compiled
- * version of this file into combinations with other programs,
- * and to distribute those combinations without any restriction
- * coming from the use of this file. (The General Public License
- * restrictions do apply in other respects; for example, they cover
- * modification of the file, and distribution when not linked into
- * a combined executable.)
- *
- * This file is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; see the file COPYING. If not, write to
- * the Free Software Foundation, 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
+ * Copyright (C) 2009-2012 the libgit2 contributors
+ *
+ * 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__
@@ -45,7 +27,7 @@ GIT_BEGIN_DECL
* @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.
- * @return 0 on success; error code otherwise
+ * @return 0 or an error code
*/
GIT_INLINE(int) git_tree_lookup(git_tree **tree, git_repository *repo, const git_oid *id)
{
@@ -53,9 +35,26 @@ GIT_INLINE(int) git_tree_lookup(git_tree **tree, git_repository *repo, const git
}
/**
+ * 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 **tree, git_repository *repo, const git_oid *id, unsigned int len)
+{
+ return git_object_lookup_prefix((git_object **)tree, repo, id, len, GIT_OBJ_TREE);
+}
+
+/**
* Close an open tree
*
- * This is a wrapper around git_object_close()
+ * This is a wrapper around git_object_free()
*
* IMPORTANT:
* It *is* necessary to call this method when you stop
@@ -64,9 +63,9 @@ GIT_INLINE(int) git_tree_lookup(git_tree **tree, git_repository *repo, const git
* @param tree the tree to close
*/
-GIT_INLINE(void) git_tree_close(git_tree *tree)
+GIT_INLINE(void) git_tree_free(git_tree *tree)
{
- git_object_close((git_object *) tree);
+ git_object_free((git_object *) tree);
}
@@ -84,7 +83,7 @@ GIT_EXTERN(const git_oid *) git_tree_id(git_tree *tree);
* @param tree a previously loaded tree.
* @return the number of entries in the tree
*/
-GIT_EXTERN(size_t) git_tree_entrycount(git_tree *tree);
+GIT_EXTERN(unsigned int) git_tree_entrycount(git_tree *tree);
/**
* Lookup a tree entry by its filename
@@ -102,7 +101,7 @@ GIT_EXTERN(const git_tree_entry *) git_tree_entry_byname(git_tree *tree, const c
* @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, int idx);
+GIT_EXTERN(const git_tree_entry *) git_tree_entry_byindex(git_tree *tree, unsigned int idx);
/**
* Get the UNIX file attributes of a tree entry
@@ -129,14 +128,22 @@ GIT_EXTERN(const char *) git_tree_entry_name(const git_tree_entry *entry);
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);
+
+/**
* Convert a tree entry to the git_object it points too.
*
* @param object pointer to the converted object
* @param repo repository where to lookup the pointed object
* @param entry a tree entry
- * @return 0 on success; error code otherwise
+ * @return 0 or an error code
*/
-GIT_EXTERN(int) git_tree_entry_2object(git_object **object_out, git_repository *repo, const git_tree_entry *entry);
+GIT_EXTERN(int) git_tree_entry_to_object(git_object **object_out, git_repository *repo, const git_tree_entry *entry);
/**
* Write a tree to the ODB from the index file
@@ -152,7 +159,7 @@ GIT_EXTERN(int) git_tree_entry_2object(git_object **object_out, git_repository *
*
* @param oid Pointer where to store the written tree
* @param index Index to write
- * @return 0 on success; error code otherwise
+ * @return 0 or an error code
*/
GIT_EXTERN(int) git_tree_create_fromindex(git_oid *oid, git_index *index);
@@ -165,13 +172,13 @@ GIT_EXTERN(int) git_tree_create_fromindex(git_oid *oid, git_index *index);
*
* 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
* have no entries and will have to be filled manually.
*
* @param builder_p Pointer where to store the tree builder
* @param source Source tree to initialize the builder (optional)
- * @return 0 on sucess; error code otherwise
+ * @return 0 on success; error code otherwise
*/
GIT_EXTERN(int) git_treebuilder_create(git_treebuilder **builder_p, const git_tree *source);
@@ -222,7 +229,7 @@ GIT_EXTERN(const git_tree_entry *) git_treebuilder_get(git_treebuilder *bld, con
* @param filename Filename of the entry
* @param id SHA1 oid of the entry
* @param attributes Folder attributes of the entry
- * @return 0 on success; error code otherwise
+ * @return 0 or an error code
*/
GIT_EXTERN(int) git_treebuilder_insert(git_tree_entry **entry_out, git_treebuilder *bld, const char *filename, const git_oid *id, unsigned int attributes);
@@ -257,10 +264,55 @@ GIT_EXTERN(void) git_treebuilder_filter(git_treebuilder *bld, int (*filter)(cons
* @param oid Pointer where to store the written OID
* @param repo Repository where to store the object
* @param bld Tree builder to write
- * @return 0 on success; error code otherwise
+ * @return 0 or an error code
*/
GIT_EXTERN(int) git_treebuilder_write(git_oid *oid, git_repository *repo, git_treebuilder *bld);
+/**
+ * Retrieve a subtree contained in a tree, given its
+ * relative path.
+ *
+ * The returned tree is owned by the repository and
+ * should be closed with the `git_object_free` method.
+ *
+ * @param subtree Pointer where to store the subtree
+ * @param root A previously loaded tree which will be the root of the relative path
+ * @param subtree_path Path to the contained subtree
+ * @return 0 on success; GIT_ENOTFOUND if the path does not lead to a subtree
+ */
+GIT_EXTERN(int) git_tree_get_subtree(git_tree **subtree, git_tree *root, const char *subtree_path);
+
+/** Callback for the tree traversal method */
+typedef int (*git_treewalk_cb)(const char *root, git_tree_entry *entry, void *payload);
+
+/** Tree traversal modes */
+enum git_treewalk_mode {
+ GIT_TREEWALK_PRE = 0, /* Pre-order */
+ GIT_TREEWALK_POST = 1, /* Post-order */
+};
+
+/**
+ * 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 negative value, the passed entry
+ * will be skipped on the traversal.
+ *
+ * @param tree The tree to walk
+ * @param callback Function to call on each tree entry
+ * @param mode Traversal mode (pre or post-order)
+ * @param payload Opaque pointer to be passed on each callback
+ * @return 0 or an error code
+ */
+GIT_EXTERN(int) git_tree_walk(git_tree *tree, git_treewalk_cb callback, int mode, void *payload);
+
/** @} */
+
GIT_END_DECL
#endif
diff --git a/include/git2/types.h b/include/git2/types.h
index 8fdfd7fc8..93823abf7 100644
--- a/include/git2/types.h
+++ b/include/git2/types.h
@@ -1,30 +1,14 @@
/*
- * This file is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, version 2,
- * as published by the Free Software Foundation.
+ * Copyright (C) 2009-2012 the libgit2 contributors
*
- * In addition to the permissions in the GNU General Public License,
- * the authors give you unlimited permission to link the compiled
- * version of this file into combinations with other programs,
- * and to distribute those combinations without any restriction
- * coming from the use of this file. (The General Public License
- * restrictions do apply in other respects; for example, they cover
- * modification of the file, and distribution when not linked into
- * a combined executable.)
- *
- * This file is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; see the file COPYING. If not, write to
- * the Free Software Foundation, 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
+ * 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
@@ -55,16 +39,21 @@ GIT_BEGIN_DECL
#if defined(_MSC_VER)
typedef __int64 git_off_t;
-typedef __time64_t git_time_t;
+typedef __time64_t git_time_t;
#elif defined(__MINGW32__)
typedef off64_t git_off_t;
typedef __time64_t git_time_t;
-#else /* POSIX */
+#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.
@@ -77,15 +66,15 @@ typedef int64_t git_time_t;
/** 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_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. */
@@ -139,6 +128,15 @@ typedef struct git_config git_config;
/** Interface to access a configuration file */
typedef struct git_config_file git_config_file;
+/** 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;
+
/** Time in a signature */
typedef struct git_time {
git_time_t time; /** time in seconds from epoch */
@@ -163,7 +161,18 @@ typedef enum {
GIT_REF_PACKED = 4,
GIT_REF_HAS_PEEL = 8,
GIT_REF_LISTALL = GIT_REF_OID|GIT_REF_SYMBOLIC|GIT_REF_PACKED,
-} git_rtype;
+} git_ref_t;
+
+/** Basic type of any Git branch. */
+typedef enum {
+ GIT_BRANCH_LOCAL = 1,
+ GIT_BRANCH_REMOTE = 2,
+} git_branch_t;
+
+typedef struct git_refspec git_refspec;
+typedef struct git_remote git_remote;
+
+typedef struct git_remote_head git_remote_head;
/** @} */
GIT_END_DECL
diff --git a/include/git2/version.h b/include/git2/version.h
new file mode 100644
index 000000000..8edbe323c
--- /dev/null
+++ b/include/git2/version.h
@@ -0,0 +1,15 @@
+/*
+ * Copyright (C) 2009-2012 the libgit2 contributors
+ *
+ * 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
diff --git a/include/git2/windows.h b/include/git2/windows.h
new file mode 100644
index 000000000..8b743f0aa
--- /dev/null
+++ b/include/git2/windows.h
@@ -0,0 +1,59 @@
+/*
+ * Copyright (C) 2009-2012 the libgit2 contributors
+ *
+ * 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_windows_h__
+#define INCLUDE_git_windows_h__
+
+#include "common.h"
+
+/**
+ * @file git2/windows.h
+ * @brief Windows-specific functions
+ * @ingroup Git
+ * @{
+ */
+GIT_BEGIN_DECL
+
+/**
+ * Set the active codepage for Windows syscalls
+ *
+ * All syscalls performed by the library will assume
+ * this codepage when converting paths and strings
+ * to use by the Windows kernel.
+ *
+ * The default value of UTF-8 will work automatically
+ * with most Git repositories created on Unix systems.
+ *
+ * This settings needs only be changed when working
+ * with repositories that contain paths in specific,
+ * non-UTF codepages.
+ *
+ * A full list of all available codepage identifiers may
+ * be found at:
+ *
+ * http://msdn.microsoft.com/en-us/library/windows/desktop/dd317756(v=vs.85).aspx
+ *
+ * @param codepage numeric codepage identifier
+ */
+GIT_EXTERN(void) gitwin_set_codepage(unsigned int codepage);
+
+/**
+ * Return the active codepage for Windows syscalls
+ *
+ * @return numeric codepage identifier
+ */
+GIT_EXTERN(unsigned int) gitwin_get_codepage(void);
+
+/**
+ * Set the active Windows codepage to UTF-8 (this is
+ * the default value)
+ */
+GIT_EXTERN(void) gitwin_set_utf8(void);
+
+/** @} */
+GIT_END_DECL
+#endif
+
diff --git a/include/git2/zlib.h b/include/git2/zlib.h
deleted file mode 100644
index 493566340..000000000
--- a/include/git2/zlib.h
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * This file is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, version 2,
- * as published by the Free Software Foundation.
- *
- * In addition to the permissions in the GNU General Public License,
- * the authors give you unlimited permission to link the compiled
- * version of this file into combinations with other programs,
- * and to distribute those combinations without any restriction
- * coming from the use of this file. (The General Public License
- * restrictions do apply in other respects; for example, they cover
- * modification of the file, and distribution when not linked into
- * a combined executable.)
- *
- * This file is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; see the file COPYING. If not, write to
- * the Free Software Foundation, 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
- */
-#ifndef INCLUDE_git_zlib_h__
-#define INCLUDE_git_zlib_h__
-
-#include <zlib.h>
-
-/**
- * @file git2/zlib.h
- * @brief Git data compression routines
- * @defgroup git_zlib Git data compression routines
- * @ingroup Git
- * @{
- */
-GIT_BEGIN_DECL
-
-#if defined(NO_DEFLATE_BOUND) || ZLIB_VERNUM < 0x1200
-/**
- * deflateBound returns an upper bound on the compressed size.
- *
- * This is a stub function used when zlib does not supply the
- * deflateBound() implementation itself.
- *
- * @param stream the stream pointer.
- * @param s total length of the source data (in bytes).
- * @return maximum length of the compressed data.
- */
-GIT_INLINE(size_t) deflateBound(z_streamp stream, size_t s)
-{
- return (s + ((s + 7) >> 3) + ((s + 63) >> 6) + 11);
-}
-#endif
-
-/** @} */
-GIT_END_DECL
-#endif