diff options
Diffstat (limited to 'include/git2')
-rw-r--r-- | include/git2/attr.h | 166 | ||||
-rw-r--r-- | include/git2/branch.h | 119 | ||||
-rw-r--r-- | include/git2/common.h | 1 | ||||
-rw-r--r-- | include/git2/diff.h | 41 | ||||
-rw-r--r-- | include/git2/errors.h | 122 | ||||
-rw-r--r-- | include/git2/indexer.h | 45 | ||||
-rw-r--r-- | include/git2/merge.h | 35 | ||||
-rw-r--r-- | include/git2/notes.h | 10 | ||||
-rw-r--r-- | include/git2/refs.h | 20 | ||||
-rw-r--r-- | include/git2/refspec.h | 8 | ||||
-rw-r--r-- | include/git2/remote.h | 12 | ||||
-rw-r--r-- | include/git2/repository.h | 14 | ||||
-rw-r--r-- | include/git2/revwalk.h | 22 | ||||
-rw-r--r-- | include/git2/status.h | 73 | ||||
-rw-r--r-- | include/git2/submodule.h | 103 | ||||
-rw-r--r-- | include/git2/tag.h | 15 | ||||
-rw-r--r-- | include/git2/types.h | 5 |
17 files changed, 672 insertions, 139 deletions
diff --git a/include/git2/attr.h b/include/git2/attr.h index 81d1e517b..6a05496dc 100644 --- a/include/git2/attr.h +++ b/include/git2/attr.h @@ -19,42 +19,186 @@ */ 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) -#define GIT_ATTR_UNSPECIFIED(attr) ((attr) == NULL) + +/** + * 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_SET_TO_VALUE checks if an attribute is set to a value (as + * opposied 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_SET_TO_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) /** - * Lookup attribute for path returning string caller must free + * Look up the value of one git attribute for path. + * + * @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. + * @param value 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. */ GIT_EXTERN(int) git_attr_get( - git_repository *repo, const char *path, const char *name, + git_repository *repo, + uint32_t flags, + const char *path, + const char *name, const char **value); /** - * Lookup list of attributes for path, populating array of strings + * 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(repo, 0, "my/fun/file.c", 3, attrs, values); + * + * Then you could loop through the 3 values to get the settings for + * the three attributes you asked about. + * + * @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. + * @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). */ GIT_EXTERN(int) git_attr_get_many( - git_repository *repo, const char *path, - size_t num_attr, const char **names, + git_repository *repo, + uint32_t flags, + const char *path, + size_t num_attr, + const char **names, const char **values); /** - * Perform an operation on each attribute of a path. + * 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, const char *path, + 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. + * 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); @@ -62,7 +206,7 @@ GIT_EXTERN(void) git_attr_cache_flush( /** * Add a macro definition. * - * Macros will automatically be loaded from the top level .gitattributes + * 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: diff --git a/include/git2/branch.h b/include/git2/branch.h index 75927e99a..f4681dc09 100644 --- a/include/git2/branch.h +++ b/include/git2/branch.h @@ -4,12 +4,119 @@ * 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_branch_h__ -#define INCLUDE_branch_h__ +#ifndef INCLUDE_git_branch_h__ +#define INCLUDE_git_branch_h__ -struct git_branch { - char *remote; /* TODO: Make this a git_remote */ - char *merge; -}; +#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 GIT_SUCCESS 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 GIT_SUCCESS 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_type 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 GIT_SUCCESS 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 GIT_SUCCESS 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/common.h b/include/git2/common.h index a66f9c380..a8f8d8e1e 100644 --- a/include/git2/common.h +++ b/include/git2/common.h @@ -87,6 +87,7 @@ typedef struct { } 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 diff --git a/include/git2/diff.h b/include/git2/diff.h index 0176d1c2f..6afa608bb 100644 --- a/include/git2/diff.h +++ b/include/git2/diff.h @@ -39,7 +39,9 @@ enum { 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_UNTRACKED = (1 << 8), + GIT_DIFF_INCLUDE_UNMODIFIED = (1 << 9), + GIT_DIFF_RECURSE_UNTRACKED_DIRS = (1 << 10), }; /** @@ -152,19 +154,22 @@ typedef int (*git_diff_hunk_fn)( * Line origin constants. * * These values describe where a line came from and will be passed to - * the git_diff_line_fn when iterating over a diff. There are some + * the git_diff_data_fn when iterating over a diff. There are some * special origin contants 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_line_fn` along with the line */ + /* 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_output_fn` */ + /* 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' @@ -172,25 +177,19 @@ enum { /** * When iterating over a diff, callback that will be made per text diff - * line. - */ -typedef int (*git_diff_line_fn)( - void *cb_data, - git_diff_delta *delta, - char line_origin, /**< GIT_DIFF_LINE_... value from above */ - const char *content, - size_t content_len); - -/** + * 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_output_fn)( +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 *formatted_output); - + const char *content, + size_t content_len); /** @name Diff List Generator Functions * @@ -309,7 +308,7 @@ GIT_EXTERN(int) git_diff_foreach( void *cb_data, git_diff_file_fn file_cb, git_diff_hunk_fn hunk_cb, - git_diff_line_fn line_cb); + git_diff_data_fn line_cb); /** * Iterate over a diff generating text output like "git diff --name-status". @@ -317,7 +316,7 @@ GIT_EXTERN(int) git_diff_foreach( GIT_EXTERN(int) git_diff_print_compact( git_diff_list *diff, void *cb_data, - git_diff_output_fn print_cb); + git_diff_data_fn print_cb); /** * Iterate over a diff generating text output like "git diff". @@ -327,7 +326,7 @@ GIT_EXTERN(int) git_diff_print_compact( GIT_EXTERN(int) git_diff_print_patch( git_diff_list *diff, void *cb_data, - git_diff_output_fn print_cb); + git_diff_data_fn print_cb); /**@}*/ @@ -345,7 +344,7 @@ GIT_EXTERN(int) git_diff_blobs( git_diff_options *options, void *cb_data, git_diff_hunk_fn hunk_cb, - git_diff_line_fn line_cb); + git_diff_data_fn line_cb); GIT_END_DECL diff --git a/include/git2/errors.h b/include/git2/errors.h index f617986e1..0406c165a 100644 --- a/include/git2/errors.h +++ b/include/git2/errors.h @@ -21,123 +21,61 @@ 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, - /** The given short oid is ambiguous */ - GIT_EAMBIGUOUSOIDPREFIX = -29, + GIT_EAMBIGUOUS = -29, /** Skip and passthrough the given ODB backend */ GIT_EPASSTHROUGH = -30, - /** The path pattern and string did not match */ - GIT_ENOMATCH = -31, - /** The buffer is too short to satisfy the request */ GIT_ESHORTBUFFER = -32, + + GIT_EREVWALKOVER = -33, +} git_error_t; + +typedef struct { + char *message; + int klass; } 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); +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, +} git_error_class; /** - * 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`. + * Return the last `git_error` object that was generated for the + * current thread or NULL if no error has occurred. * - * @param num The error code to explain - * @return a string explaining the error code + * @return A git_error object. */ -GIT_EXTERN(const char *) git_strerror(int num); +GIT_EXTERN(const git_error *) giterr_last(void); /** - * Clear the latest library error + * Clear the last library error that occurred for this thread. */ -GIT_EXTERN(void) git_clearerror(void); +GIT_EXTERN(void) giterr_clear(void); /** @} */ GIT_END_DECL diff --git a/include/git2/indexer.h b/include/git2/indexer.h index 7f336f8e6..14bd0e402 100644 --- a/include/git2/indexer.h +++ b/include/git2/indexer.h @@ -23,6 +23,51 @@ typedef struct 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 inexer 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 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/notes.h b/include/git2/notes.h index 1b5944f9d..ecb37f3ab 100644 --- a/include/git2/notes.h +++ b/include/git2/notes.h @@ -92,6 +92,16 @@ GIT_EXTERN(int) git_note_remove(git_repository *repo, const char *notes_ref, */ 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 GIT_SUCCESS or an error code + */ +GIT_EXTERN(int) git_note_default_ref(const char **out, git_repository *repo); + /** @} */ GIT_END_DECL #endif diff --git a/include/git2/refs.h b/include/git2/refs.h index 5395ded4b..2073aabc5 100644 --- a/include/git2/refs.h +++ b/include/git2/refs.h @@ -33,6 +33,17 @@ GIT_BEGIN_DECL GIT_EXTERN(int) git_reference_lookup(git_reference **reference_out, git_repository *repo, const char *name); /** + * Lookup a reference by name and resolve immediately to OID. + * + * @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_name_to_oid( + git_oid *out, git_repository *repo, const char *name); + +/** * Create a new symbolic reference. * * The reference will be created in the repository and written @@ -304,6 +315,15 @@ GIT_EXTERN(int) git_reference_reload(git_reference *ref); */ 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 GIT_SUCCESS if the same, else a stable but meaningless ordering. + */ +GIT_EXTERN(int) git_reference_cmp(git_reference *ref1, git_reference *ref2); + /** @} */ GIT_END_DECL #endif diff --git a/include/git2/refspec.h b/include/git2/refspec.h index 3acf1143d..28afe652d 100644 --- a/include/git2/refspec.h +++ b/include/git2/refspec.h @@ -7,6 +7,7 @@ #ifndef INCLUDE_git_refspec_h__ #define INCLUDE_git_refspec_h__ +#include "common.h" #include "types.h" /** @@ -35,14 +36,13 @@ const char *git_refspec_src(const git_refspec *refspec); const char *git_refspec_dst(const git_refspec *refspec); /** - * Match a refspec's source descriptor with a reference name + * Check if a refspec's source descriptor matches a reference * * @param refspec the refspec * @param refname the name of the reference to check - * @return GIT_SUCCESS on successful match; GIT_ENOMACH on match - * failure or an error code on other failure + * @return 1 if the refspec matches, 0 otherwise */ -int git_refspec_src_match(const git_refspec *refspec, const char *refname); +int git_refspec_src_matches(const git_refspec *refspec, const char *refname); /** * Transform a reference to its target following the refspec's rules diff --git a/include/git2/remote.h b/include/git2/remote.h index 1830c7218..e81e25f98 100644 --- a/include/git2/remote.h +++ b/include/git2/remote.h @@ -11,6 +11,7 @@ #include "repository.h" #include "refspec.h" #include "net.h" +#include "indexer.h" /** * @file git2/remote.h @@ -150,7 +151,7 @@ GIT_EXTERN(int) git_remote_ls(git_remote *remote, git_headlist_cb list_cb, void * @param filename where to store the temproray filename * @return GIT_SUCCESS or an error code */ -GIT_EXTERN(int) git_remote_download(char **filename, git_remote *remote); +GIT_EXTERN(int) git_remote_download(git_remote *remote, git_off_t *bytes, git_indexer_stats *stats); /** * Check whether the remote is connected @@ -175,6 +176,9 @@ 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); @@ -182,12 +186,10 @@ GIT_EXTERN(void) git_remote_free(git_remote *remote); /** * Update the tips to the new state * - * Make sure that you only call this once you've successfully indexed - * or expanded the packfile. - * * @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); +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 diff --git a/include/git2/repository.h b/include/git2/repository.h index 34dd90444..d760c23b7 100644 --- a/include/git2/repository.h +++ b/include/git2/repository.h @@ -70,6 +70,20 @@ GIT_EXTERN(int) git_repository_discover( int across_fs, const char *ceiling_dirs); +enum { + GIT_REPOSITORY_OPEN_NO_SEARCH = (1 << 0), + GIT_REPOSITORY_OPEN_CROSS_FS = (1 << 1), +}; + +/** + * Find and open a repository with extended controls. + */ +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 * diff --git a/include/git2/revwalk.h b/include/git2/revwalk.h index e7ec2abf3..632c67588 100644 --- a/include/git2/revwalk.h +++ b/include/git2/revwalk.h @@ -164,6 +164,28 @@ GIT_EXTERN(int) git_revwalk_hide_glob(git_revwalk *walk, const char *glob); 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 referece to push + * @return GIT_SUCCESS 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 referece to hide + * @return GIT_SUCCESS 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 diff --git a/include/git2/status.h b/include/git2/status.h index 5c45dae1e..f5fc95f0a 100644 --- a/include/git2/status.h +++ b/include/git2/status.h @@ -47,6 +47,79 @@ GIT_BEGIN_DECL 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. + */ +#define GIT_STATUS_OPT_INCLUDE_UNTRACKED (1 << 0) +#define GIT_STATUS_OPT_INCLUDE_IGNORED (1 << 1) +#define GIT_STATUS_OPT_INCLUDE_UNMODIFIED (1 << 2) +#define GIT_STATUS_OPT_EXCLUDE_SUBMODULES (1 << 3) +#define 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, + 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 diff --git a/include/git2/submodule.h b/include/git2/submodule.h new file mode 100644 index 000000000..930168275 --- /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 ususally 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 f7fce3a70..9ab4b7b9e 100644 --- a/include/git2/tag.h +++ b/include/git2/tag.h @@ -274,6 +274,21 @@ GIT_EXTERN(int) git_tag_list_match( 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 GIT_SUCCESS 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/types.h b/include/git2/types.h index ffada630a..98eea5374 100644 --- a/include/git2/types.h +++ b/include/git2/types.h @@ -160,6 +160,11 @@ typedef enum { GIT_REF_LISTALL = GIT_REF_OID|GIT_REF_SYMBOLIC|GIT_REF_PACKED, } git_rtype; +/** Basic type of any Git branch. */ +typedef enum { + GIT_BRANCH_LOCAL = 1, + GIT_BRANCH_REMOTE = 2, +} git_branch_type; typedef struct git_refspec git_refspec; typedef struct git_remote git_remote; |