summaryrefslogtreecommitdiff
path: root/include/git2
diff options
context:
space:
mode:
Diffstat (limited to 'include/git2')
-rw-r--r--include/git2/common.h86
-rw-r--r--include/git2/config.h171
-rw-r--r--include/git2/config_backend.h57
-rw-r--r--include/git2/errors.h100
-rw-r--r--include/git2/index.h95
-rw-r--r--include/git2/thread-utils.h1
-rw-r--r--include/git2/types.h6
7 files changed, 398 insertions, 118 deletions
diff --git a/include/git2/common.h b/include/git2/common.h
index 22c7cc466..9a27ac2e5 100644
--- a/include/git2/common.h
+++ b/include/git2/common.h
@@ -84,92 +84,6 @@
* @{
*/
-/** Operation completed successfully. */
-#define GIT_SUCCESS 0
-
-/**
- * Operation failed, with unspecified reason.
- * This value also serves as the base error code; all other
- * error codes are subtracted from it such that all errors
- * are < 0, in typical POSIX C tradition.
- */
-#define GIT_ERROR -1
-
-/** Input was not a properly formatted Git object id. */
-#define GIT_ENOTOID (GIT_ERROR - 1)
-
-/** Input does not exist in the scope searched. */
-#define GIT_ENOTFOUND (GIT_ERROR - 2)
-
-/** Not enough space available. */
-#define GIT_ENOMEM (GIT_ERROR - 3)
-
-/** Consult the OS error information. */
-#define GIT_EOSERR (GIT_ERROR - 4)
-
-/** The specified object is of invalid type */
-#define GIT_EOBJTYPE (GIT_ERROR - 5)
-
-/** The specified object has its data corrupted */
-#define GIT_EOBJCORRUPTED (GIT_ERROR - 6)
-
-/** The specified repository is invalid */
-#define GIT_ENOTAREPO (GIT_ERROR - 7)
-
-/** The object type is invalid or doesn't match */
-#define GIT_EINVALIDTYPE (GIT_ERROR - 8)
-
-/** The object cannot be written because it's missing internal data */
-#define GIT_EMISSINGOBJDATA (GIT_ERROR - 9)
-
-/** The packfile for the ODB is corrupted */
-#define GIT_EPACKCORRUPTED (GIT_ERROR - 10)
-
-/** Failed to acquire or release a file lock */
-#define GIT_EFLOCKFAIL (GIT_ERROR - 11)
-
-/** The Z library failed to inflate/deflate an object's data */
-#define GIT_EZLIB (GIT_ERROR - 12)
-
-/** The queried object is currently busy */
-#define GIT_EBUSY (GIT_ERROR - 13)
-
-/** The index file is not backed up by an existing repository */
-#define GIT_EBAREINDEX (GIT_ERROR - 14)
-
-/** The name of the reference is not valid */
-#define GIT_EINVALIDREFNAME (GIT_ERROR - 15)
-
-/** The specified reference has its data corrupted */
-#define GIT_EREFCORRUPTED (GIT_ERROR - 16)
-
-/** The specified symbolic reference is too deeply nested */
-#define GIT_ETOONESTEDSYMREF (GIT_ERROR - 17)
-
-/** The pack-refs file is either corrupted or its format is not currently supported */
-#define GIT_EPACKEDREFSCORRUPTED (GIT_ERROR - 18)
-
-/** The path is invalid */
-#define GIT_EINVALIDPATH (GIT_ERROR - 19)
-
-/** The revision walker is empty; there are no more commits left to iterate */
-#define GIT_EREVWALKOVER (GIT_ERROR - 20)
-
-/** The state of the reference is not valid */
-#define GIT_EINVALIDREFSTATE (GIT_ERROR - 21)
-
-/** This feature has not been implemented yet */
-#define GIT_ENOTIMPLEMENTED (GIT_ERROR - 22)
-
-/** A reference with this name already exists */
-#define GIT_EEXISTS (GIT_ERROR - 23)
-
-/** The given integer literal is too large to be parsed */
-#define GIT_EOVERFLOW (GIT_ERROR - 24)
-
-/** The given literal is not a valid number */
-#define GIT_ENOTNUM (GIT_ERROR - 25)
-
GIT_BEGIN_DECL
typedef struct {
diff --git a/include/git2/config.h b/include/git2/config.h
new file mode 100644
index 000000000..3ebbe64de
--- /dev/null
+++ b/include/git2/config.h
@@ -0,0 +1,171 @@
+/*
+ * 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_config_h__
+#define INCLUDE_git_config_h__
+
+#include "common.h"
+#include "types.h"
+
+/**
+ * @file git2/config.h
+ * @brief Git config management routines
+ * @defgroup git_config Git config management routines
+ * @ingroup Git
+ * @{
+ */
+GIT_BEGIN_DECL
+
+/**
+ * Allocate a new configuration
+ */
+GIT_EXTERN(int) git_config_new(git_config **out);
+
+/**
+ * Open a configuration file
+ *
+ * @param cfg_out pointer to the configuration data
+ * @param path where to load the confiration from
+ */
+GIT_EXTERN(int) git_config_open_bare(git_config **cfg_out, const char *path);
+
+/**
+ *
+ */
+GIT_EXTERN(int) git_config_add_backend(git_config *cfg, git_config_backend *backend, int priority);
+
+/**
+ * Free the configuration and its associated memory
+ *
+ * @param cfg the configuration to free
+ */
+GIT_EXTERN(void) git_config_free(git_config *cfg);
+
+/**
+ * Get 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
+ */
+GIT_EXTERN(int) git_config_get_int(git_config *cfg, const char *name, int *out);
+
+/**
+ * Get 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
+ */
+GIT_EXTERN(int) git_config_get_long(git_config *cfg, const char *name, long int *out);
+
+/**
+ * Get the value of a boolean config variable.
+ *
+ * This function uses the usual C convention of 0 being false and
+ * anything else true.
+ *
+ * @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
+ */
+GIT_EXTERN(int) git_config_get_bool(git_config *cfg, const char *name, int *out);
+
+/**
+ * Get the value of a string config variable.
+ *
+ * The string is owned by the variable and should not be freed by the
+ * user.
+ *
+ * @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
+ */
+GIT_EXTERN(int) git_config_get_string(git_config *cfg, const char *name, const char **out);
+
+/**
+ * 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
+ */
+GIT_EXTERN(int) git_config_set_int(git_config *cfg, const char *name, int 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
+ */
+GIT_EXTERN(int) git_config_set_long(git_config *cfg, const char *name, long int value);
+
+/**
+ * Set the value of a boolean config variable.
+ *
+ * @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
+ */
+GIT_EXTERN(int) git_config_set_bool(git_config *cfg, const char *name, int value);
+
+/**
+ * Set the value of a string config variable.
+ *
+ * A copy of the string is made and the user is free to use it
+ * afterwards.
+ *
+ * @param cfg where to look for the variable
+ * @param name the variable's name
+ * @param value the string to store.
+ * @return GIT_SUCCESS on success; error code otherwise
+ */
+GIT_EXTERN(int) git_config_set_string(git_config *cfg, const char *name, const char *value);
+
+/**
+ * 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.
+ *
+ * @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
+ */
+GIT_EXTERN(int) git_config_foreach(git_config *cfg, int (*callback)(const char *, void *data), void *data);
+
+/** @} */
+GIT_END_DECL
+#endif
diff --git a/include/git2/config_backend.h b/include/git2/config_backend.h
new file mode 100644
index 000000000..427cd95dd
--- /dev/null
+++ b/include/git2/config_backend.h
@@ -0,0 +1,57 @@
+/*
+ * 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_config_backend_h__
+#define INCLUDE_git_config_backend_h__
+
+#include "common.h"
+#include "types.h"
+#include "config.h"
+
+GIT_BEGIN_DECL
+
+struct git_config;
+
+struct git_config_backend {
+ struct git_config *cfg;
+ /* Open means open the file/database and parse if necessary */
+ int (*open)(struct git_config_backend *);
+ int (* get)(struct git_config_backend *, const char *key, const char **value);
+ int (* set)(struct git_config_backend *, const char *key, const char *value);
+ int (*foreach)(struct git_config_backend *, int (*fn)(const char *, void *), void *data);
+ void (*free)(struct git_config_backend *);
+};
+
+/**
+ * Create a file-backed configuration backend
+ *
+ * @param out the new backend
+ * @path where the config file is located
+ */
+GIT_EXTERN(int) git_config_backend_file(struct git_config_backend **out, const char *path);
+
+GIT_END_DECL
+
+#endif
diff --git a/include/git2/errors.h b/include/git2/errors.h
index 627e67c70..7e957b803 100644
--- a/include/git2/errors.h
+++ b/include/git2/errors.h
@@ -25,6 +25,8 @@
#ifndef INCLUDE_git_errors_h__
#define INCLUDE_git_errors_h__
+#include "common.h"
+
/**
* @file git2/errors.h
* @brief Git error handling routines and variables
@@ -33,8 +35,106 @@
*/
GIT_BEGIN_DECL
+typedef 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_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_error;
+
+/**
+ * Return a detailed error string with the latest error
+ * that occurred in the library.
+ * @return a string explaining the error
+ */
+GIT_EXTERN(const char *) git_lasterror(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
*/
diff --git a/include/git2/index.h b/include/git2/index.h
index 09993a154..2e5c17bc3 100644
--- a/include/git2/index.h
+++ b/include/git2/index.h
@@ -51,39 +51,29 @@ GIT_BEGIN_DECL
*
* In-memory only flags:
*/
-#define GIT_IDXENTRY_UPDATE (1 << 16)
-#define GIT_IDXENTRY_REMOVE (1 << 17)
-#define GIT_IDXENTRY_UPTODATE (1 << 18)
-#define GIT_IDXENTRY_ADDED (1 << 19)
+#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 << 20)
-#define GIT_IDXENTRY_UNHASHED (1 << 21)
-#define GIT_IDXENTRY_WT_REMOVE (1 << 22) /* remove in work directory */
-#define GIT_IDXENTRY_CONFLICTED (1 << 23)
+#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 << 24)
-#define GIT_IDXENTRY_NEW_SKIP_WORKTREE (1 << 25)
+#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 << 29)
-#define GIT_IDXENTRY_SKIP_WORKTREE (1 << 30)
+#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 << 31)
+#define GIT_IDXENTRY_EXTENDED2 (1 << 15)
#define GIT_IDXENTRY_EXTENDED_FLAGS (GIT_IDXENTRY_INTENT_TO_ADD | GIT_IDXENTRY_SKIP_WORKTREE)
-/*
- * Safeguard to avoid saving wrong flags:
- * - GIT_IDXENTRY_EXTENDED2 won't get saved until its semantic is known
- * - Bits in 0x0000FFFF have been saved in flags already
- * - Bits in 0x003F0000 are currently in-memory flags
- */
-#if GIT_IDXENTRY_EXTENDED_FLAGS & 0x803FFFFF
-#error "GIT_IDXENTRY_EXTENDED_FLAGS out of range"
-#endif
-
/** Time used in a git index entry */
typedef struct {
git_time_t seconds;
@@ -188,7 +178,12 @@ GIT_EXTERN(int) git_index_write(git_index *index);
GIT_EXTERN(int) git_index_find(git_index *index, const char *path);
/**
- * Add or update an index entry from a file in disk.
+ * Add or update an index entry from a file in disk
+ *
+ * The file `path` must be relative to the repository's
+ * working folder and must be readable.
+ *
+ * This method will fail in bare index instances.
*
* @param index an existing index object
* @param path filename to add
@@ -198,26 +193,62 @@ GIT_EXTERN(int) git_index_find(git_index *index, const char *path);
GIT_EXTERN(int) git_index_add(git_index *index, const char *path, int stage);
/**
- * Remove an entry from the index
+ * Add or update an index entry from an in-memory struct
+ *
+ * A full copy (including the 'path' string) of the given
+ * 'source_entry' will be inserted on the index.
*
* @param index an existing index object
- * @param position position of the entry to remove
+ * @param source_entry new entry object
* @return 0 on success, otherwise an error code
*/
-GIT_EXTERN(int) git_index_remove(git_index *index, int position);
+GIT_EXTERN(int) git_index_add2(git_index *index, const git_index_entry *source_entry);
/**
- * Insert an entry into the index.
+ * Add (append) an index entry from a file in disk
+ *
+ * A new entry will always be inserted into the index;
+ * if the index already contains an entry for such
+ * path, the old entry will **not** be replaced.
+ *
+ * The file `path` must be relative to the repository's
+ * working folder and must be readable.
+ *
+ * This method will fail in bare index instances.
+ *
+ * @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
+ */
+GIT_EXTERN(int) git_index_append(git_index *index, const char *path, int stage);
+
+/**
+ * Add (append) an index entry from an in-memory struct
+ *
+ * A new entry will always be inserted into the index;
+ * if the index already contains an entry for the path
+ * in the `entry` struct, the old entry will **not** be
+ * replaced.
+ *
* A full copy (including the 'path' string) of the given
- * 'source_entry' will be inserted on the index; if the index
- * already contains an entry for the same path, the entry
- * will be updated.
+ * 'source_entry' will be inserted on the index.
*
* @param index an existing index object
* @param source_entry new entry object
* @return 0 on success, otherwise an error code
*/
-GIT_EXTERN(int) git_index_insert(git_index *index, const git_index_entry *source_entry);
+GIT_EXTERN(int) git_index_append2(git_index *index, const git_index_entry *source_entry);
+
+/**
+ * Remove an entry from the index
+ *
+ * @param index an existing index object
+ * @param position position of the entry to remove
+ * @return 0 on success, otherwise an error code
+ */
+GIT_EXTERN(int) git_index_remove(git_index *index, int position);
+
/**
* Get a pointer to one of the entries in the index
diff --git a/include/git2/thread-utils.h b/include/git2/thread-utils.h
index fb8644b93..e26876bea 100644
--- a/include/git2/thread-utils.h
+++ b/include/git2/thread-utils.h
@@ -35,6 +35,7 @@
#if defined(__APPLE__) && defined(__MACH__)
# undef GIT_TLS
+# define GIT_TLS
#elif defined(__GNUC__) || \
defined(__SUNPRO_C) || \
diff --git a/include/git2/types.h b/include/git2/types.h
index 6123abc82..ab7dc523e 100644
--- a/include/git2/types.h
+++ b/include/git2/types.h
@@ -130,6 +130,12 @@ typedef struct git_treebuilder git_treebuilder;
/** Memory representation of an index file. */
typedef struct git_index git_index;
+/** Memory representation of a config file */
+typedef struct git_config git_config;
+
+/** A specific implementation of a config backend */
+typedef struct git_config_backend git_config_backend;
+
/** Time in a signature */
typedef struct git_time {
git_time_t time; /** time in seconds from epoch */