From ac250c56c7d7bb11691c9dfbcd0dbf580d85e177 Mon Sep 17 00:00:00 2001 From: Ben Straub Date: Wed, 25 Apr 2012 16:24:22 -0700 Subject: First stab at implementation of rev-parse. This version supports refspecs of these kinds: - Full & partial SHAs - Output from "git describe" - "/refs/heads/master" (full ref names) - "master" (partial ref names) - "FETCH_HEAD" (named heads) --- include/git2/revparse.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 include/git2/revparse.h (limited to 'include/git2') diff --git a/include/git2/revparse.h b/include/git2/revparse.h new file mode 100644 index 000000000..3fd69d91d --- /dev/null +++ b/include/git2/revparse.h @@ -0,0 +1,22 @@ +/* + * 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_revparse_h__ +#define INCLUDE_git_revparse_h__ + +#include "common.h" +#include "types.h" + + +GIT_BEGIN_DECL + +GIT_EXTERN(int) git_revparse_single(git_object **out, git_repository *repo, const char *spec); + +//GIT_EXTERN(int) git_revparse_multi(TODO); + +GIT_END_DECL + +#endif -- cgit v1.2.1 From bfc13e7985a9368f7932115bc3d395dd1379b03d Mon Sep 17 00:00:00 2001 From: Ben Straub Date: Mon, 30 Apr 2012 09:58:43 -0700 Subject: Adding comment documentation for rev-parse api. --- include/git2/revparse.h | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'include/git2') diff --git a/include/git2/revparse.h b/include/git2/revparse.h index 3fd69d91d..4567027e5 100644 --- a/include/git2/revparse.h +++ b/include/git2/revparse.h @@ -11,12 +11,26 @@ #include "types.h" +/** + * @file git2/revparse.h + * @brief Git revision parsing routines + * @defgroup git_revparse Git revision parsing routines + * @ingroup Git + * @{ + */ GIT_BEGIN_DECL +/** + * Find an object, as specified by a revision string. See `man gitrevisions`, or the documentation + * for `git rev-parse` for information on the syntax accepted. + * + * @param out pointer to output object + * @param repo the repository to search in + * @param spec the textual specification for an object + * @return on success, GIT_ERROR otherwise (use git_error_last for information about the error) + */ GIT_EXTERN(int) git_revparse_single(git_object **out, git_repository *repo, const char *spec); -//GIT_EXTERN(int) git_revparse_multi(TODO); - +/** @} */ GIT_END_DECL - #endif -- cgit v1.2.1 From edebceffef1d661d073b9961d13042007325832d Mon Sep 17 00:00:00 2001 From: nulltoken Date: Tue, 1 May 2012 13:57:45 +0200 Subject: Add git_reset() Currently supports Soft and Mixed modes. --- include/git2/reset.h | 44 ++++++++++++++++++++++++++++++++++++++++++++ include/git2/types.h | 6 ++++++ 2 files changed, 50 insertions(+) create mode 100644 include/git2/reset.h (limited to 'include/git2') diff --git a/include/git2/reset.h b/include/git2/reset.h new file mode 100644 index 000000000..125178748 --- /dev/null +++ b/include/git2/reset.h @@ -0,0 +1,44 @@ +/* + * 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_reset_h__ +#define INCLUDE_git_reset_h__ + +/** + * @file git2/reset.h + * @brief Git reset management routines + * @ingroup Git + * @{ + */ +GIT_BEGIN_DECL + +/** + * Sets the current head to the specified commit oid and optionally + * resets the index and working tree to match. + * + * When specifying a Soft kind of reset, the head will be moved to the commit. + * + * Specifying a Mixed kind of reset will trigger a Soft reset and the index will + * be replaced with the content of the commit tree. + * + * TODO: Implement remaining kinds of resets. + * + * @param repo Repository where to perform the reset operation. + * + * @param target Object to which the Head should be moved to. This object + * must belong to the given `repo` and can either be a git_commit or a + * git_tag. When a git_tag is being passed, it should be dereferencable + * to a git_commit which oid will be used as the target of the branch. + * + * @param reset_type Kind of reset operation to perform. + * + * @return GIT_SUCCESS or an error code + */ +GIT_EXTERN(int) git_reset(git_repository *repo, const git_object *target, git_reset_type reset_type); + +/** @} */ +GIT_END_DECL +#endif diff --git a/include/git2/types.h b/include/git2/types.h index cfb0acf33..b4b48afa3 100644 --- a/include/git2/types.h +++ b/include/git2/types.h @@ -166,6 +166,12 @@ typedef enum { GIT_BRANCH_REMOTE = 2, } git_branch_t; +/** Kinds of reset operation. */ +typedef enum { + GIT_RESET_SOFT = 1, + GIT_RESET_MIXED = 2, +} git_reset_type; + typedef struct git_refspec git_refspec; typedef struct git_remote git_remote; -- cgit v1.2.1 From 3f0358604e48432b53abf097aa3ab6a1e3639813 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vicent=20Mart=C3=AD?= Date: Thu, 7 Jun 2012 22:43:03 +0200 Subject: misc: Fix warnings from PVS Studio trial --- include/git2/diff.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include/git2') diff --git a/include/git2/diff.h b/include/git2/diff.h index a0e8ad6d2..46b80d872 100644 --- a/include/git2/diff.h +++ b/include/git2/diff.h @@ -96,9 +96,9 @@ typedef enum { typedef struct { git_oid oid; char *path; - uint16_t mode; git_off_t size; unsigned int flags; + uint16_t mode; } git_diff_file; /** -- cgit v1.2.1 From 0abd724454078f2089701b54be94df7306dcfb8e Mon Sep 17 00:00:00 2001 From: Russell Belfer Date: Mon, 4 Jun 2012 16:17:41 -0700 Subject: Fix filemode comparison in diffs File modes were both not being ignored properly on platforms where they should be ignored, nor be diffed consistently on platforms where they are supported. This change adds a number of diff and status filemode change tests. This also makes sure that filemode-only changes are included in the diff output when they occur and that filemode changes are ignored successfully when core.filemode is false. There is no code that automatically toggles core.filemode based on the capabilities of the current platform, so the user still needs to be careful in their .git/config file. --- include/git2/status.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include/git2') diff --git a/include/git2/status.h b/include/git2/status.h index 6a424dfd6..69b6e47e0 100644 --- a/include/git2/status.h +++ b/include/git2/status.h @@ -102,7 +102,7 @@ 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_EXCLUDE_SUBMODULES = (1 << 3), GIT_STATUS_OPT_RECURSE_UNTRACKED_DIRS = (1 << 4), }; -- cgit v1.2.1 From 145e696b498a046762e4df9045c9b71440308486 Mon Sep 17 00:00:00 2001 From: Russell Belfer Date: Fri, 8 Jun 2012 11:56:24 -0700 Subject: Minor fixes, cleanups, and clarifications There are three actual changes in this commit: 1. When the trailing newline of a file is removed in a diff, the change will now be reported with `GIT_DIFF_LINE_DEL_EOFNL` passed to the callback. Previously, the `ADD_EOFNL` constant was given which was just an error in my understanding of when the various circumstances arose. `GIT_DIFF_LINE_ADD_EOFNL` is deprecated and should never be generated. A new newline is simply an `ADD`. 2. Rewrote the `diff_delta__merge_like_cgit` function that contains the core logic of the `git_diff_merge` implementation. The new version doesn't actually have significantly different behavior, but the logic should be much more obvious, I think. 3. Fixed a bug in `git_diff_merge` where it freed a string pool while some of the string data was still in use. This led to `git_diff_print_patch` accessing memory that had been freed. The rest of this commit contains improved documentation in `diff.h` to make the behavior and the equivalencies with core git clearer, and a bunch of new tests to cover the various cases, oh and a minor simplification of `examples/diff.c`. --- include/git2/diff.h | 91 ++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 69 insertions(+), 22 deletions(-) (limited to 'include/git2') diff --git a/include/git2/diff.h b/include/git2/diff.h index 46b80d872..d4d0eac47 100644 --- a/include/git2/diff.h +++ b/include/git2/diff.h @@ -29,6 +29,10 @@ */ GIT_BEGIN_DECL +/** + * Flags for diff options. A combination of these flags can be passed + * in via the `flags` value in the `git_diff_options`. + */ enum { GIT_DIFF_NORMAL = 0, GIT_DIFF_REVERSE = (1 << 0), @@ -160,15 +164,16 @@ typedef int (*git_diff_hunk_fn)( * the file or hunk headers. */ enum { - /* these values will be sent to `git_diff_data_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_ADD_EOFNL = '\n', /**< DEPRECATED */ 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). + + /* The following 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', @@ -206,6 +211,8 @@ GIT_EXTERN(void) git_diff_list_free(git_diff_list *diff); /** * Compute a difference between two tree objects. * + * This is equivalent to `git diff ` + * * @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. @@ -222,6 +229,9 @@ GIT_EXTERN(int) git_diff_tree_to_tree( /** * Compute a difference between a tree and the index. * + * This is equivalent to `git diff --cached ` or if you pass + * the HEAD tree, then like `git diff --cached`. + * * @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. @@ -236,6 +246,11 @@ GIT_EXTERN(int) git_diff_index_to_tree( /** * Compute a difference between the working directory and the index. * + * This matches the `git diff` command. See the note below on + * `git_diff_workdir_to_tree` for a discussion of the difference between + * `git diff` and `git diff HEAD` and how to emulate a `git diff ` + * using libgit2. + * * @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. @@ -248,14 +263,24 @@ GIT_EXTERN(int) git_diff_workdir_to_index( /** * 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 `. Running `git diff HEAD` + * or the like actually uses information from the index, along with the tree + * and workdir dir info. * - * This is *NOT* the same as 'git diff HEAD' or 'git diff '. 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. + * This function returns strictly the differences between the tree and the + * files contained in the working directory, regardless of the state of + * files in the index. It may come as a surprise, but there is no direct + * equivalent in core git. + * + * To emulate `git diff `, you should call both + * `git_diff_index_to_tree` and `git_diff_workdir_to_index`, then call + * `git_diff_merge` on the results. That will yield a `git_diff_list` that + * matches the git output. + * + * If this seems confusing, take the case of a file with a staged deletion + * where the file has then been put back into the working dir and modified. + * The tree-to-workdir diff for that file is 'modified', but core git would + * show status 'deleted' since there is a pending deletion in the index. * * @param repo The repository containing the tree. * @param opts Structure with options to influence diff or NULL for defaults. @@ -298,10 +323,23 @@ GIT_EXTERN(int) git_diff_merge( /** * 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. + * This will iterate through all of the files described in a diff. You + * should provide a file callback to learn about each file. + * + * The "hunk" and "line" callbacks are optional, and the text diff of the + * files will only be calculated if they are not NULL. Of course, these + * callbacks will not be invoked for binary files on the diff list or for + * files whose only changed is a file mode change. + * + * @param diff A git_diff_list generated by one of the above functions. + * @param cb_data Reference pointer that will be passed to your callbacks. + * @param file_cb Callback function to make per file in the diff. + * @param hunk_cb Optional callback to make per hunk of text diff. This + * callback is called to describe a range of lines in the + * diff. It will not be issued for binary files. + * @param line_cb Optional callback to make per line of diff text. This + * same callback will be made for context lines, added, and + * removed lines, and even for a deleted trailing newline. */ GIT_EXTERN(int) git_diff_foreach( git_diff_list *diff, @@ -322,6 +360,14 @@ GIT_EXTERN(int) git_diff_print_compact( * Iterate over a diff generating text output like "git diff". * * This is a super easy way to generate a patch from a diff. + * + * @param diff A git_diff_list generated by one of the above functions. + * @param cb_data Reference pointer that will be passed to your callbacks. + * @param print_cb Callback function to output lines of the diff. This + * same function will be called for file headers, hunk + * headers, and diff lines. Fortunately, you can probably + * use various GIT_DIFF_LINE constants to determine what + * text you are given. */ GIT_EXTERN(int) git_diff_print_patch( git_diff_list *diff, @@ -338,13 +384,14 @@ GIT_EXTERN(int) git_diff_print_patch( /** * 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. + * 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. + * 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, -- cgit v1.2.1 From 14ebe518320b0306b04d256d0f5230de32c3f8b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= Date: Tue, 12 Jun 2012 15:23:00 +0200 Subject: Expose git_refspec_parse() This function has been available for some time, but never in a header. Expose it so we can use it from outside the library. --- include/git2/refspec.h | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'include/git2') diff --git a/include/git2/refspec.h b/include/git2/refspec.h index 1100e9022..9e84aad99 100644 --- a/include/git2/refspec.h +++ b/include/git2/refspec.h @@ -19,6 +19,14 @@ */ GIT_BEGIN_DECL +/** + * Parse a refspec string and create a refspec object + * + * @param refspec pointer to the refspec structure to be used + * @param str the refspec as a string + */ +GIT_EXTERN(int) git_refspec_parse(git_refspec *refspec, const char *str); + /** * Get the source specifier * -- cgit v1.2.1