From 60bc2d20c40e37e92e4e15479ac4dccbde069bec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vicent=20Mart=C3=AD?= Date: Tue, 14 Feb 2012 21:23:11 +0100 Subject: error-handling: Add new routines Obviously all the old throw routines are still in place, so we can gradually port over. --- include/git2/errors.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'include/git2') diff --git a/include/git2/errors.h b/include/git2/errors.h index f617986e1..54da869b4 100644 --- a/include/git2/errors.h +++ b/include/git2/errors.h @@ -113,8 +113,23 @@ typedef enum { /** The buffer is too short to satisfy the request */ GIT_ESHORTBUFFER = -32, +} git_error_t; + +typedef struct { + char *message; + int klass; } git_error; +typedef enum { + GITERR_NOMEMORY, + +} git_error_class; + +GIT_EXTERN(void) giterr_set(git_error **error_out, int error_class, const char *string, ...); +GIT_EXTERN(void) giterr_set_oom(git_error **error); +GIT_EXTERN(void) giterr_free(git_error *error); +GIT_EXTERN(void) giterr_clear(git_error **error); + /** * Return a detailed error string with the latest error * that occurred in the library. -- cgit v1.2.1 From 45d387ac78bcf3167d69b736d0b322717bc492d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vicent=20Mart=C3=AD?= Date: Wed, 15 Feb 2012 16:54:17 +0100 Subject: refs: Error handling rework. WIP --- include/git2/errors.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'include/git2') diff --git a/include/git2/errors.h b/include/git2/errors.h index 54da869b4..e3f5f4cb0 100644 --- a/include/git2/errors.h +++ b/include/git2/errors.h @@ -122,9 +122,12 @@ typedef struct { typedef enum { GITERR_NOMEMORY, + GITERR_REFERENCE, } git_error_class; +#define GITERR_CHECK_ALLOC(ptr, error) if (ptr == NULL) { giterr_set_oom(error); return -1 } + GIT_EXTERN(void) giterr_set(git_error **error_out, int error_class, const char *string, ...); GIT_EXTERN(void) giterr_set_oom(git_error **error); GIT_EXTERN(void) giterr_free(git_error *error); -- cgit v1.2.1 From 1a48112342932e9fcd45a1ff5935f1c9c53b83d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vicent=20Mart=C3=AD?= Date: Fri, 17 Feb 2012 00:13:34 +0100 Subject: error-handling: References Yes, this is error handling solely for `refs.c`, but some of the abstractions leak all ofer the code base. --- include/git2/errors.h | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'include/git2') diff --git a/include/git2/errors.h b/include/git2/errors.h index e3f5f4cb0..9b28093dc 100644 --- a/include/git2/errors.h +++ b/include/git2/errors.h @@ -122,16 +122,17 @@ typedef struct { typedef enum { GITERR_NOMEMORY, + GITERR_OS, GITERR_REFERENCE, + GITERR_ZLIB, } git_error_class; -#define GITERR_CHECK_ALLOC(ptr, error) if (ptr == NULL) { giterr_set_oom(error); return -1 } +#define GITERR_CHECK_ALLOC(ptr) if (ptr == NULL) { return -1; } -GIT_EXTERN(void) giterr_set(git_error **error_out, int error_class, const char *string, ...); -GIT_EXTERN(void) giterr_set_oom(git_error **error); -GIT_EXTERN(void) giterr_free(git_error *error); -GIT_EXTERN(void) giterr_clear(git_error **error); +GIT_EXTERN(void) giterr_set_oom(void); +GIT_EXTERN(void) giterr_set(int error_class, const char *string, ...); +GIT_EXTERN(void) giterr_clear(void); /** * Return a detailed error string with the latest error -- cgit v1.2.1 From cb8a79617b15e347f26d21cedde0f2b8670c1876 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vicent=20Mart=C3=AD?= Date: Wed, 7 Mar 2012 00:02:55 +0100 Subject: error-handling: Repository This also includes droping `git_buf_lasterror` because it makes no sense in the new system. Note that in most of the places were it has been dropped, the code needs cleanup. I.e. GIT_ENOMEM is going away, so instead it should return a generic `-1` and obviously not throw anything. --- include/git2/errors.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include/git2') diff --git a/include/git2/errors.h b/include/git2/errors.h index 9b28093dc..7daa0670f 100644 --- a/include/git2/errors.h +++ b/include/git2/errors.h @@ -125,7 +125,7 @@ typedef enum { GITERR_OS, GITERR_REFERENCE, GITERR_ZLIB, - + GITERR_REPOSITORY, } git_error_class; #define GITERR_CHECK_ALLOC(ptr) if (ptr == NULL) { return -1; } -- cgit v1.2.1 From e54d8d8972ddfa886bfcf1a078d253b632debc72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vicent=20Mart=C3=AD?= Date: Wed, 7 Mar 2012 01:37:09 +0100 Subject: error-handling: Config --- include/git2/errors.h | 1 + 1 file changed, 1 insertion(+) (limited to 'include/git2') diff --git a/include/git2/errors.h b/include/git2/errors.h index 7daa0670f..bc420d1d4 100644 --- a/include/git2/errors.h +++ b/include/git2/errors.h @@ -126,6 +126,7 @@ typedef enum { GITERR_REFERENCE, GITERR_ZLIB, GITERR_REPOSITORY, + GITERR_CONFIG, } git_error_class; #define GITERR_CHECK_ALLOC(ptr) if (ptr == NULL) { return -1; } -- cgit v1.2.1 From dda708e78f3c3f43d814d46c29ab9f2b9d47ed5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vicent=20Mart=C3=AD?= Date: Fri, 9 Mar 2012 19:55:50 +0100 Subject: error-handling: On-disk config file backend Includes: - Proper error reporting when encountering syntax errors in a config file (file, line number, column). - Rewritten `config_write`, now with 99% less goto-spaghetti - Error state in `git_filebuf`: filebuf write functions no longer need to be checked for error returns. If any of the writes performed on a buffer fail, the last call to `git_filebuf_commit` or `git_filebuf_hash` will fail accordingly and set the appropiate error message. Baller! --- include/git2/errors.h | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) (limited to 'include/git2') diff --git a/include/git2/errors.h b/include/git2/errors.h index bc420d1d4..085dd52f0 100644 --- a/include/git2/errors.h +++ b/include/git2/errors.h @@ -127,14 +127,9 @@ typedef enum { GITERR_ZLIB, GITERR_REPOSITORY, GITERR_CONFIG, + GITERR_REGEX, } git_error_class; -#define GITERR_CHECK_ALLOC(ptr) if (ptr == NULL) { return -1; } - -GIT_EXTERN(void) giterr_set_oom(void); -GIT_EXTERN(void) giterr_set(int error_class, const char *string, ...); -GIT_EXTERN(void) giterr_clear(void); - /** * Return a detailed error string with the latest error * that occurred in the library. -- cgit v1.2.1 From e1de726c15937a8dbf81d12ef0c872cf6576ebd0 Mon Sep 17 00:00:00 2001 From: Russell Belfer Date: Mon, 12 Mar 2012 22:55:40 -0700 Subject: Migrate ODB files to new error handling This migrates odb.c, odb_loose.c, odb_pack.c and pack.c to the new style of error handling. Also got the unix and win32 versions of map.c. There are some minor changes to other files but no others were completely converted. This also contains an update to filebuf so that a zeroed out filebuf will not think that the fd (== 0) is actually open (and inadvertently call close() on fd 0 if cleaned up). Lastly, this was built and tested on win32 and contains a bunch of fixes for the win32 build which was pretty broken. --- include/git2/errors.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'include/git2') diff --git a/include/git2/errors.h b/include/git2/errors.h index 085dd52f0..cd9dc08e7 100644 --- a/include/git2/errors.h +++ b/include/git2/errors.h @@ -103,7 +103,7 @@ typedef enum { 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, @@ -128,6 +128,7 @@ typedef enum { GITERR_REPOSITORY, GITERR_CONFIG, GITERR_REGEX, + GITERR_ODB } git_error_class; /** -- cgit v1.2.1 From e3c475107045cb89c53c114716bafebc7538433f Mon Sep 17 00:00:00 2001 From: Russell Belfer Date: Tue, 13 Mar 2012 14:23:24 -0700 Subject: Resolve comments from pull request This converts the map validation function into a macro, tweaks the GITERR_OS system error automatic appending, and adds a tentative new error access API and some quick unit tests for both the old and new error APIs. --- include/git2/errors.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'include/git2') diff --git a/include/git2/errors.h b/include/git2/errors.h index cd9dc08e7..5a4e540e1 100644 --- a/include/git2/errors.h +++ b/include/git2/errors.h @@ -134,6 +134,7 @@ typedef enum { /** * Return a detailed error string with the latest error * that occurred in the library. + * @deprecated This will be replaced in the new error handling * @return a string explaining the error */ GIT_EXTERN(const char *) git_lasterror(void); @@ -145,6 +146,7 @@ GIT_EXTERN(const char *) git_lasterror(void); * NOTE: This method will be eventually deprecated in favor * of the new `git_lasterror`. * + * @deprecated This will be replaced in the new error handling * @param num The error code to explain * @return a string explaining the error code */ @@ -152,9 +154,23 @@ GIT_EXTERN(const char *) git_strerror(int num); /** * Clear the latest library error + * @deprecated This will be replaced in the new error handling */ GIT_EXTERN(void) git_clearerror(void); +/** + * Return the last `git_error` object that was generated for the + * current thread or NULL if no error has occurred. + * + * @return A git_error object. + */ +GIT_EXTERN(const git_error *) git_error_last(void); + +/** + * Clear the last library error that occurred for this thread. + */ +GIT_EXTERN(void) git_error_clear(void); + /** @} */ GIT_END_DECL #endif -- cgit v1.2.1 From 7c7ff7d11e2d22f7b9c7f8152f5c58dde37ac207 Mon Sep 17 00:00:00 2001 From: Russell Belfer Date: Mon, 19 Mar 2012 16:10:11 -0700 Subject: Migrate index, oid, and utils to new errors This includes a few cleanups that came up while converting these files. This commit introduces a could new git error classes, including the catchall class: GITERR_INVALID which I'm using as the class for invalid and out of range values which are detected at too low a level of library to use a higher level classification. For example, an overflow error in parsing an integer or a bad letter in parsing an OID string would generate an error in this class. --- include/git2/errors.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'include/git2') diff --git a/include/git2/errors.h b/include/git2/errors.h index 5a4e540e1..d71df59a2 100644 --- a/include/git2/errors.h +++ b/include/git2/errors.h @@ -123,12 +123,14 @@ typedef struct { typedef enum { GITERR_NOMEMORY, GITERR_OS, + GITERR_INVALID, GITERR_REFERENCE, GITERR_ZLIB, GITERR_REPOSITORY, GITERR_CONFIG, GITERR_REGEX, - GITERR_ODB + GITERR_ODB, + GITERR_INDEX } git_error_class; /** -- cgit v1.2.1 From a48ea31d69a76d6b398d3a1e522a1c7363a9b92a Mon Sep 17 00:00:00 2001 From: Russell Belfer Date: Wed, 21 Mar 2012 12:33:09 -0700 Subject: Reimplment git_status_foreach using git diff This is an initial reimplementation of status using diff a la the way that core git does it. --- include/git2/status.h | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 67 insertions(+), 1 deletion(-) (limited to 'include/git2') diff --git a/include/git2/status.h b/include/git2/status.h index 5c45dae1e..4dc80b93a 100644 --- a/include/git2/status.h +++ b/include/git2/status.h @@ -31,7 +31,8 @@ GIT_BEGIN_DECL #define GIT_STATUS_WT_MODIFIED (1 << 4) #define GIT_STATUS_WT_DELETED (1 << 5) -#define GIT_STATUS_IGNORED (1 << 6) +#define GIT_STATUS_IGNORED (1 << 6) +#define GIT_STATUS_WT_UNTRACKED (1 << 7) /** * Gather file statuses and run a callback for each one. @@ -46,6 +47,71 @@ 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_EXCLUDE_UNMODIFIED indicates that callback + * do not need to be made on unmodified files. + * - GIT_STATUS_OPT_EXCLUDE_SUBMODULES indicates that directories + * which appear to be submodules should just be skipped over. + */ +#define GIT_STATUS_OPT_INCLUDE_UNTRACKED (1 << 0) +#define GIT_STATUS_OPT_INCLUDE_IGNORED (1 << 1) +#define GIT_STATUS_OPT_EXCLUDE_UNMODIFIED (1 << 2) +#define GIT_STATUS_OPT_EXCLUDE_SUBMODULES (1 << 3) + +/** + * Options to control which callbacks will be made by + * `git_status_foreach_ext()` + */ +typedef struct { + git_status_show_t show; + unsigned int flags; +} 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 * -- cgit v1.2.1 From 95340398a1821bd19da1bfe459ba1f375ed89404 Mon Sep 17 00:00:00 2001 From: Russell Belfer Date: Thu, 22 Mar 2012 09:17:34 -0700 Subject: Adding new tests for new status command This is a work in progress. This adds two new sets of tests, the issue_592 tests from @nulltoken's pull request #601 and some new tests for submodules. The submodule tests still have issues where the status is not reported correctly. That needs to be fixed before merge. --- include/git2/status.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'include/git2') diff --git a/include/git2/status.h b/include/git2/status.h index 4dc80b93a..339052933 100644 --- a/include/git2/status.h +++ b/include/git2/status.h @@ -31,8 +31,7 @@ GIT_BEGIN_DECL #define GIT_STATUS_WT_MODIFIED (1 << 4) #define GIT_STATUS_WT_DELETED (1 << 5) -#define GIT_STATUS_IGNORED (1 << 6) -#define GIT_STATUS_WT_UNTRACKED (1 << 7) +#define GIT_STATUS_IGNORED (1 << 6) /** * Gather file statuses and run a callback for each one. -- cgit v1.2.1 From 66142ae03134ef8a45e6bd304c6106a1685c3c99 Mon Sep 17 00:00:00 2001 From: Russell Belfer Date: Thu, 22 Mar 2012 10:44:36 -0700 Subject: New status fixes This adds support for roughly-right tracking of submodules (although it does not recurse into submodules to detect internal modifications a la core git), and it adds support for including unmodified files in diff iteration if requested. --- include/git2/diff.h | 3 ++- include/git2/status.h | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) (limited to 'include/git2') diff --git a/include/git2/diff.h b/include/git2/diff.h index 0e7c02fd0..cb3ef4e1b 100644 --- a/include/git2/diff.h +++ b/include/git2/diff.h @@ -39,7 +39,8 @@ 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) }; /** diff --git a/include/git2/status.h b/include/git2/status.h index 339052933..a24d39fa7 100644 --- a/include/git2/status.h +++ b/include/git2/status.h @@ -83,14 +83,14 @@ typedef enum { * 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_EXCLUDE_UNMODIFIED indicates that callback - * do not need to be made on unmodified files. + * - 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. */ #define GIT_STATUS_OPT_INCLUDE_UNTRACKED (1 << 0) #define GIT_STATUS_OPT_INCLUDE_IGNORED (1 << 1) -#define GIT_STATUS_OPT_EXCLUDE_UNMODIFIED (1 << 2) +#define GIT_STATUS_OPT_INCLUDE_UNMODIFIED (1 << 2) #define GIT_STATUS_OPT_EXCLUDE_SUBMODULES (1 << 3) /** -- cgit v1.2.1 From 4b136a94d948e62634633092c9d1052c4b074e6c Mon Sep 17 00:00:00 2001 From: Russell Belfer Date: Fri, 23 Mar 2012 09:26:09 -0700 Subject: Fix crash in new status and add recurse option This fixes the bug that @nulltoken found (thank you!) where if there were untracked directories alphabetically after the last tracked item, the diff implementation would deref a NULL pointer. The fix involved the code which decides if it is necessary to recurse into a directory in the working dir, so it was easy to add a new option `GIT_STATUS_OPT_RECURSE_UNTRACKED_DIRS` to control if the contents of untracked directories should be included in status. --- include/git2/diff.h | 3 ++- include/git2/status.h | 20 ++++++++++++++------ 2 files changed, 16 insertions(+), 7 deletions(-) (limited to 'include/git2') diff --git a/include/git2/diff.h b/include/git2/diff.h index cb3ef4e1b..0c9f620c1 100644 --- a/include/git2/diff.h +++ b/include/git2/diff.h @@ -40,7 +40,8 @@ enum { 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_INCLUDE_UNMODIFIED = (1 << 9), + GIT_DIFF_RECURSE_UNTRACKED_DIRS = (1 << 10), }; /** diff --git a/include/git2/status.h b/include/git2/status.h index a24d39fa7..f5fc95f0a 100644 --- a/include/git2/status.h +++ b/include/git2/status.h @@ -87,19 +87,27 @@ typedef enum { * 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_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 which callbacks will be made by - * `git_status_foreach_ext()` + * 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; /** -- cgit v1.2.1 From bfc9ca595aa2f189743f2a7b9812f05def78ec88 Mon Sep 17 00:00:00 2001 From: Russell Belfer Date: Wed, 28 Mar 2012 16:45:36 -0700 Subject: Added submodule API and use in status When processing status for a newly checked out repo, it is possible that there will be submodules that have not yet been initialized. The only way to distinguish these from untracked directories is to have some knowledge of submodules. This commit adds a new submodule API which, given a name or path, can determine if it appears to be a submodule and can give information about the submodule. --- include/git2/submodule.h | 105 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 include/git2/submodule.h (limited to 'include/git2') diff --git a/include/git2/submodule.h b/include/git2/submodule.h new file mode 100644 index 000000000..aee2260c1 --- /dev/null +++ b/include/git2/submodule.h @@ -0,0 +1,105 @@ +/* + * 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_SUBMOUDLE_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); + +#define GIT_SUBMODULE_HEAD "[internal]HEAD" + +/** + * 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 -- cgit v1.2.1 From 95dfb031f70601b12a9eb57229fd4aa9a51ddd54 Mon Sep 17 00:00:00 2001 From: Russell Belfer Date: Fri, 30 Mar 2012 14:40:50 -0700 Subject: Improve config handling for diff,submodules,attrs This adds support for a bunch of core.* settings that affect diff and status, plus fixes up some incorrect implementations of those settings from before. Also, this cleans up the handling of config settings in the new submodules code and in the old attrs/ignore code. --- include/git2/submodule.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'include/git2') diff --git a/include/git2/submodule.h b/include/git2/submodule.h index aee2260c1..930168275 100644 --- a/include/git2/submodule.h +++ b/include/git2/submodule.h @@ -22,7 +22,7 @@ GIT_BEGIN_DECL typedef enum { GIT_SUBMODULE_UPDATE_CHECKOUT = 0, - GIT_SUBMOUDLE_UPDATE_REBASE = 1, + GIT_SUBMODULE_UPDATE_REBASE = 1, GIT_SUBMODULE_UPDATE_MERGE = 2 } git_submodule_update_t; @@ -80,8 +80,6 @@ GIT_EXTERN(int) git_submodule_foreach( int (*callback)(const char *name, void *payload), void *payload); -#define GIT_SUBMODULE_HEAD "[internal]HEAD" - /** * Lookup submodule information by name or path. * -- cgit v1.2.1 From 73fe6a8e20ffbc18ad667ff519c0fb8adf85fc3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vicent=20Mart=C3=AD?= Date: Wed, 28 Mar 2012 18:59:12 +0200 Subject: error-handling: Commit (WIP) --- include/git2/errors.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'include/git2') diff --git a/include/git2/errors.h b/include/git2/errors.h index d71df59a2..712d611ac 100644 --- a/include/git2/errors.h +++ b/include/git2/errors.h @@ -130,7 +130,8 @@ typedef enum { GITERR_CONFIG, GITERR_REGEX, GITERR_ODB, - GITERR_INDEX + GITERR_INDEX, + GITERR_OBJECT } git_error_class; /** -- cgit v1.2.1 From 3f46f313cbfcf57e5cbf3d7dc55b747568a21bef Mon Sep 17 00:00:00 2001 From: nulltoken Date: Fri, 6 Apr 2012 14:34:26 +0200 Subject: tag: Add git_tag_peel() which recursively peel a tag until a non tag git_object is met --- include/git2/tag.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'include/git2') 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 -- cgit v1.2.1 From 731df57080704183cad128c17fd065e5e25fa886 Mon Sep 17 00:00:00 2001 From: nulltoken Date: Wed, 4 Apr 2012 15:57:19 +0200 Subject: Add basic branch management API: git_branch_create(), git_branch_delete(), git_branch_list() --- include/git2/branch.h | 97 +++++++++++++++++++++++++++++++++++++++++++++++---- include/git2/types.h | 5 +++ 2 files changed, 96 insertions(+), 6 deletions(-) (limited to 'include/git2') diff --git a/include/git2/branch.h b/include/git2/branch.h index 75927e99a..fa1c6f3ec 100644 --- a/include/git2/branch.h +++ b/include/git2/branch.h @@ -4,12 +4,97 @@ * 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, + enum 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); + +/** @} */ +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; -- cgit v1.2.1 From 4615f0f71ba849adef08f7a677842af3e0ee3d53 Mon Sep 17 00:00:00 2001 From: nulltoken Date: Mon, 9 Apr 2012 03:22:14 +0200 Subject: branch: add git_branch_move() --- include/git2/branch.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'include/git2') diff --git a/include/git2/branch.h b/include/git2/branch.h index fa1c6f3ec..7f4945d1d 100644 --- a/include/git2/branch.h +++ b/include/git2/branch.h @@ -95,6 +95,28 @@ GIT_EXTERN(int) git_branch_list( 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 -- cgit v1.2.1 From 1a2b87257dd7aa462f246ff8eb66232e59387d68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= Date: Wed, 11 Apr 2012 14:27:40 +0200 Subject: Typedefs don't have enum in front --- include/git2/branch.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include/git2') diff --git a/include/git2/branch.h b/include/git2/branch.h index 7f4945d1d..f4681dc09 100644 --- a/include/git2/branch.h +++ b/include/git2/branch.h @@ -69,7 +69,7 @@ GIT_EXTERN(int) git_branch_create( GIT_EXTERN(int) git_branch_delete( git_repository *repo, const char *branch_name, - enum git_branch_type branch_type); + git_branch_type branch_type); /** * Fill a list with all the branches in the Repository -- cgit v1.2.1 From 4376f7f6f4a46ecbcc0136948b68782956cd3c45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= Date: Tue, 6 Mar 2012 08:12:35 +0100 Subject: error-handling: remote, transport --- include/git2/errors.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'include/git2') diff --git a/include/git2/errors.h b/include/git2/errors.h index 712d611ac..325d0a615 100644 --- a/include/git2/errors.h +++ b/include/git2/errors.h @@ -131,7 +131,8 @@ typedef enum { GITERR_REGEX, GITERR_ODB, GITERR_INDEX, - GITERR_OBJECT + GITERR_OBJECT, + GITERR_NET, } git_error_class; /** -- cgit v1.2.1 From 7784bcbbee972d1f00ea88655a5592fb44ca767d Mon Sep 17 00:00:00 2001 From: Russell Belfer Date: Wed, 11 Apr 2012 11:52:59 -0700 Subject: Refactor git_repository_open with new options Add a new command `git_repository_open_ext` with extended options that control how searching for a repository will be done. The existing `git_repository_open` and `git_repository_discover` are reimplemented on top of it. We may want to change the default behavior of `git_repository_open` but this commit does not do that. Improve support for "gitdir" files where the work dir is separate from the repo and support for the "separate-git-dir" config. Also, add support for opening repos created with `git-new-workdir` script (although I have only confirmed that they can be opened, not that all functions work correctly). There are also a few minor changes that came up: - Fix `git_path_prettify` to allow in-place prettifying. - Fix `git_path_root` to support backslashes on Win32. This fix should help many repo open/discover scenarios - it is the one function called when opening before prettifying the path. - Tweak `git_config_get_string` to set the "out" pointer to NULL if the config value is not found. Allows some other cleanup. - Fix a couple places that should have been calling `git_repository_config__weakptr` and were not. - Fix `cl_git_sandbox_init` clar helper to support bare repos. --- include/git2/repository.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'include/git2') 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 * -- cgit v1.2.1 From 06b9d915901b3dd9dc85016bb000e631eb1da1d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= Date: Tue, 28 Feb 2012 02:19:57 +0100 Subject: revwalk: allow pushing/hiding a reference by name The code was already there, so factor it out and let users push an OID by giving it a reference name. Only refs to commits are supported. Annotated tags will throw an error. --- include/git2/revwalk.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'include/git2') 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 @@ -163,6 +163,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. * -- cgit v1.2.1 From de7ab85dc614ba702a89f3f0c761c68ee1e00fda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= Date: Sat, 3 Mar 2012 03:31:51 +0100 Subject: Implement git_merge_base() It's implemented in revwalk.c so it has access to the revision walker's commit cache and related functions. The algorithm is the one used by git, modified so it fits better with the library's functions. --- include/git2/revwalk.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'include/git2') diff --git a/include/git2/revwalk.h b/include/git2/revwalk.h index 632c67588..db27c62b1 100644 --- a/include/git2/revwalk.h +++ b/include/git2/revwalk.h @@ -232,6 +232,9 @@ GIT_EXTERN(void) git_revwalk_free(git_revwalk *walk); */ GIT_EXTERN(git_repository *) git_revwalk_repository(git_revwalk *walk); +GIT_EXTERN(int) git_merge_base(git_oid *out, git_repository *repo, git_oid *one, git_oid *two); + + /** @} */ GIT_END_DECL #endif -- cgit v1.2.1 From bf787bd87c04e5213fc277c583970c52dea6781f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= Date: Sun, 8 Apr 2012 18:56:50 +0200 Subject: Move git_merge_base() to is own header and document it --- include/git2/merge.h | 35 +++++++++++++++++++++++++++++++++++ include/git2/revwalk.h | 3 --- 2 files changed, 35 insertions(+), 3 deletions(-) create mode 100644 include/git2/merge.h (limited to 'include/git2') 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/revwalk.h b/include/git2/revwalk.h index db27c62b1..632c67588 100644 --- a/include/git2/revwalk.h +++ b/include/git2/revwalk.h @@ -232,9 +232,6 @@ GIT_EXTERN(void) git_revwalk_free(git_revwalk *walk); */ GIT_EXTERN(git_repository *) git_revwalk_repository(git_revwalk *walk); -GIT_EXTERN(int) git_merge_base(git_oid *out, git_repository *repo, git_oid *one, git_oid *two); - - /** @} */ GIT_END_DECL #endif -- cgit v1.2.1 From 3f93e16cff90e71dad434729b3acdc437fb06436 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= Date: Thu, 29 Mar 2012 17:49:57 +0200 Subject: indexer: start writing the stream indexer This will allow us to index a packfile as soon as we receive it from the network as well as storing it with its final name so we don't need to pass temporary file names around. --- include/git2/indexer.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'include/git2') diff --git a/include/git2/indexer.h b/include/git2/indexer.h index 7f336f8e6..76b162ed2 100644 --- a/include/git2/indexer.h +++ b/include/git2/indexer.h @@ -23,6 +23,25 @@ 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, void *data, size_t size, git_indexer_stats *stats); /** * Create a new indexer instance -- cgit v1.2.1 From 453ab98da06d57c7d41a9f3ddf945ae56d56890a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= Date: Wed, 11 Apr 2012 12:55:34 +0200 Subject: indexer: Add git_indexer_stream_finalize() Resolve any lingering deltas, write out the index file and rename the packfile. --- include/git2/indexer.h | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'include/git2') diff --git a/include/git2/indexer.h b/include/git2/indexer.h index 76b162ed2..8490ef0c8 100644 --- a/include/git2/indexer.h +++ b/include/git2/indexer.h @@ -43,6 +43,15 @@ GIT_EXTERN(int) git_indexer_stream_new(git_indexer_stream **out, const char *git */ GIT_EXTERN(int) git_indexer_stream_add(git_indexer_stream *idx, 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); + /** * Create a new indexer instance * -- cgit v1.2.1 From 1c9c081a6a0e02ea8a148717083e3f7a769c5a2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= Date: Fri, 13 Apr 2012 19:25:06 +0200 Subject: indexer: add git_indexer_stream_free() and _hash() --- include/git2/indexer.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'include/git2') diff --git a/include/git2/indexer.h b/include/git2/indexer.h index 8490ef0c8..a70fab214 100644 --- a/include/git2/indexer.h +++ b/include/git2/indexer.h @@ -52,6 +52,23 @@ GIT_EXTERN(int) git_indexer_stream_add(git_indexer_stream *idx, void *data, size */ 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 * -- cgit v1.2.1 From 14a513e05866721f5ceba18cf425568d2f6af143 Mon Sep 17 00:00:00 2001 From: Russell Belfer Date: Fri, 13 Apr 2012 15:00:29 -0700 Subject: Add support for pathspec to diff and status This adds preliminary support for pathspecs to diff and status. The implementation is not very optimized (it still looks at every single file and evaluated the the pathspec match against them), but it works. --- include/git2/common.h | 1 + 1 file changed, 1 insertion(+) (limited to 'include/git2') diff --git a/include/git2/common.h b/include/git2/common.h index 170ef340d..9186fe54e 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 -- cgit v1.2.1 From f201d613a80f7ad6f54d90eb7a7a0d8b8c72676b Mon Sep 17 00:00:00 2001 From: Russell Belfer Date: Fri, 13 Apr 2012 10:33:14 -0700 Subject: Add git_reference_lookup_oid and lookup_resolved Adds a new public reference function `git_reference_lookup_oid` that directly resolved a reference name to an OID without returning the intermediate `git_reference` object (hence, no free needed). Internally, this adds a `git_reference_lookup_resolved` function that combines looking up and resolving a reference. This allows us to be more efficient with memory reallocation. The existing `git_reference_lookup` and `git_reference_resolve` are reimplmented on top of the new utility and a few places in the code are changed to use one of the two new functions. --- include/git2/refs.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'include/git2') diff --git a/include/git2/refs.h b/include/git2/refs.h index 5395ded4b..6f2ac3ce9 100644 --- a/include/git2/refs.h +++ b/include/git2/refs.h @@ -32,6 +32,16 @@ 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_lookup_oid(git_oid *out, git_repository *repo, const char *name); + /** * Create a new symbolic reference. * @@ -304,6 +314,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 -- cgit v1.2.1 From 26515e73a11b6f6c25e316ece2a6243aba7af9f5 Mon Sep 17 00:00:00 2001 From: Russell Belfer Date: Mon, 23 Apr 2012 10:06:31 -0700 Subject: Rename to git_reference_name_to_oid --- include/git2/refs.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'include/git2') diff --git a/include/git2/refs.h b/include/git2/refs.h index 6f2ac3ce9..2073aabc5 100644 --- a/include/git2/refs.h +++ b/include/git2/refs.h @@ -40,7 +40,8 @@ GIT_EXTERN(int) git_reference_lookup(git_reference **reference_out, git_reposito * @param name The long name for the reference * @return 0 on success, -1 if name could not be resolved */ -GIT_EXTERN(int) git_reference_lookup_oid(git_oid *out, git_repository *repo, const char *name); +GIT_EXTERN(int) git_reference_name_to_oid( + git_oid *out, git_repository *repo, const char *name); /** * Create a new symbolic reference. -- cgit v1.2.1 From 7a520f5d8af2aedd5693bf7314527d76d9af2ef4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= Date: Fri, 13 Apr 2012 23:19:38 +0200 Subject: fetch: use the streaming indexer when downloading a pack This changes the git_remote_download() API, but the existing one is silly, so you don't get to complain. The new API allows to know how much data has been downloaded, how many objects we expect in total and how many we've processed. --- include/git2/remote.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include/git2') diff --git a/include/git2/remote.h b/include/git2/remote.h index e6537ec52..576f5841b 100644 --- a/include/git2/remote.h +++ b/include/git2/remote.h @@ -150,7 +150,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 -- cgit v1.2.1 From dee5515a237b2d4182e454986025199064193376 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= Date: Sat, 14 Apr 2012 18:34:50 +0200 Subject: transports: buffer the git requests before sending them Trying to send every single line immediately won't give us any speed improvement and duplicates the code we need for other transports. Make the git transport use the same buffer functions as HTTP. --- include/git2/indexer.h | 2 +- include/git2/remote.h | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) (limited to 'include/git2') diff --git a/include/git2/indexer.h b/include/git2/indexer.h index a70fab214..14bd0e402 100644 --- a/include/git2/indexer.h +++ b/include/git2/indexer.h @@ -41,7 +41,7 @@ GIT_EXTERN(int) git_indexer_stream_new(git_indexer_stream **out, const char *git * @param size the size of the data * @param stats stat storage */ -GIT_EXTERN(int) git_indexer_stream_add(git_indexer_stream *idx, void *data, size_t size, git_indexer_stats *stats); +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 diff --git a/include/git2/remote.h b/include/git2/remote.h index 576f5841b..8f49fddf1 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 -- cgit v1.2.1 From f184836bd281efe8a656e3a9c6c2f9c040b88119 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= Date: Wed, 25 Apr 2012 12:13:20 +0200 Subject: remote: run a callback when updating the branch tips This allows the caller to update an internal structure or update the user output with the tips that were updated. While in the area, only try to update the ref if the value is different from its old one. --- include/git2/remote.h | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'include/git2') diff --git a/include/git2/remote.h b/include/git2/remote.h index 8f49fddf1..09b927e28 100644 --- a/include/git2/remote.h +++ b/include/git2/remote.h @@ -183,12 +183,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 -- cgit v1.2.1 From 3aa351ea0fa0d9e8d155801cdac1e83d3b1717c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= Date: Thu, 26 Apr 2012 15:05:07 +0200 Subject: error handling: move the missing parts over to the new error handling --- include/git2/errors.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'include/git2') diff --git a/include/git2/errors.h b/include/git2/errors.h index 325d0a615..17a701079 100644 --- a/include/git2/errors.h +++ b/include/git2/errors.h @@ -133,6 +133,8 @@ typedef enum { GITERR_INDEX, GITERR_OBJECT, GITERR_NET, + GITERR_TAG, + GITERR_TREE, } git_error_class; /** -- cgit v1.2.1 From 8af503bc85a92242bd698cca1e8594af909811c6 Mon Sep 17 00:00:00 2001 From: Michael Schubert Date: Sat, 28 Apr 2012 20:49:05 +0200 Subject: remote: add more doc on git_remote_free --- include/git2/remote.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'include/git2') diff --git a/include/git2/remote.h b/include/git2/remote.h index 09b927e28..7af4148dc 100644 --- a/include/git2/remote.h +++ b/include/git2/remote.h @@ -176,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); -- cgit v1.2.1 From 1d2dd864add4835c49744a566c226a1c7da04e99 Mon Sep 17 00:00:00 2001 From: nulltoken Date: Sun, 29 Apr 2012 19:42:51 +0200 Subject: diff: provide more context to the consumer of the callbacks Update the callback to provide some information related to the file change being processed and the range of the hunk, when applicable. --- include/git2/diff.h | 37 +++++++++++++++++-------------------- 1 file changed, 17 insertions(+), 20 deletions(-) (limited to 'include/git2') diff --git a/include/git2/diff.h b/include/git2/diff.h index 0c9f620c1..d8dc91c80 100644 --- a/include/git2/diff.h +++ b/include/git2/diff.h @@ -154,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' @@ -174,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 * @@ -311,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". @@ -319,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". @@ -329,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); /**@}*/ @@ -348,7 +345,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 -- cgit v1.2.1 From 16b83019af63d837b6934bcf1b71b8697d5d94c8 Mon Sep 17 00:00:00 2001 From: Russell Belfer Date: Sun, 4 Mar 2012 23:28:36 -0800 Subject: Fix usage of "new" for fieldname in public header This should restore the ability to include libgit2 headers in C++ projects. Cherry picked 2de60205dfea2c4a422b2108a5e8605f97c2e895 from development into new-error-handling. --- include/git2/diff.h | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'include/git2') diff --git a/include/git2/diff.h b/include/git2/diff.h index d8dc91c80..741be3a00 100644 --- a/include/git2/diff.h +++ b/include/git2/diff.h @@ -57,8 +57,8 @@ 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 *src_prefix; /**< defaults to "a" */ - char *dst_prefix; /**< defaults to "b" */ + char *old_prefix; /**< defaults to "a" */ + char *new_prefix; /**< defaults to "b" */ git_strarray pathspec; /**< defaults to show all paths */ } git_diff_options; @@ -115,11 +115,11 @@ typedef struct { * It will just use the git attributes for those files. */ typedef struct { - git_diff_file old; - git_diff_file new; + git_diff_file old_file; + git_diff_file new_file; git_delta_t status; - unsigned int similarity; /**< for RENAMED and COPIED, value from 0 to 100 */ - int binary; + unsigned int similarity; /**< for RENAMED and COPIED, value 0-100 */ + int binary; } git_diff_delta; /** @@ -208,15 +208,15 @@ GIT_EXTERN(void) git_diff_list_free(git_diff_list *diff); * * @param repo The repository containing the trees. * @param opts Structure with options to influence diff or NULL for defaults. - * @param old A git_tree object to diff from. - * @param new A git_tree object to diff to. + * @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, - git_tree *new, + git_tree *old_tree, + git_tree *new_tree, git_diff_list **diff); /** @@ -224,13 +224,13 @@ GIT_EXTERN(int) git_diff_tree_to_tree( * * @param repo The repository containing the tree and index. * @param opts Structure with options to influence diff or NULL for defaults. - * @param old A git_tree object to diff from. + * @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, + git_tree *old_tree, git_diff_list **diff); /** @@ -259,13 +259,13 @@ GIT_EXTERN(int) git_diff_workdir_to_index( * * @param repo The repository containing the tree. * @param opts Structure with options to influence diff or NULL for defaults. - * @param old A git_tree object to diff from. + * @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, + git_tree *old_tree, git_diff_list **diff); /** @@ -340,8 +340,8 @@ GIT_EXTERN(int) git_diff_print_patch( */ GIT_EXTERN(int) git_diff_blobs( git_repository *repo, - git_blob *old, - git_blob *new, + git_blob *old_blob, + git_blob *new_blob, git_diff_options *options, void *cb_data, git_diff_hunk_fn hunk_cb, -- cgit v1.2.1