diff options
Diffstat (limited to 'include')
| -rw-r--r-- | include/git2/attr.h | 2 | ||||
| -rw-r--r-- | include/git2/branch.h | 2 | ||||
| -rw-r--r-- | include/git2/checkout.h | 3 | ||||
| -rw-r--r-- | include/git2/commit.h | 17 | ||||
| -rw-r--r-- | include/git2/config.h | 31 | ||||
| -rw-r--r-- | include/git2/diff.h | 39 | ||||
| -rw-r--r-- | include/git2/index.h | 141 | ||||
| -rw-r--r-- | include/git2/inttypes.h | 18 | ||||
| -rw-r--r-- | include/git2/merge.h | 10 | ||||
| -rw-r--r-- | include/git2/pack.h | 6 | ||||
| -rw-r--r-- | include/git2/refs.h | 57 | ||||
| -rw-r--r-- | include/git2/repository.h | 23 | ||||
| -rw-r--r-- | include/git2/reset.h | 6 | ||||
| -rw-r--r-- | include/git2/strarray.h | 4 | ||||
| -rw-r--r-- | include/git2/sys/commit.h | 5 | ||||
| -rw-r--r-- | include/git2/sys/index.h | 1 | ||||
| -rw-r--r-- | include/git2/sys/refdb_backend.h | 66 | ||||
| -rw-r--r-- | include/git2/trace.h | 3 | ||||
| -rw-r--r-- | include/git2/tree.h | 6 | ||||
| -rw-r--r-- | include/git2/types.h | 4 |
20 files changed, 296 insertions, 148 deletions
diff --git a/include/git2/attr.h b/include/git2/attr.h index f099245b0..0d8a910f2 100644 --- a/include/git2/attr.h +++ b/include/git2/attr.h @@ -141,7 +141,7 @@ GIT_EXTERN(git_attr_t) git_attr_value(const char *attr); */ GIT_EXTERN(int) git_attr_get( const char **value_out, - git_repository *repo, + git_repository *repo, uint32_t flags, const char *path, const char *name); diff --git a/include/git2/branch.h b/include/git2/branch.h index b15171360..d1838a63a 100644 --- a/include/git2/branch.h +++ b/include/git2/branch.h @@ -237,7 +237,7 @@ GIT_EXTERN(int) git_branch_is_head( * * @return Number of characters in the reference name * including the trailing NUL byte; GIT_ENOTFOUND - * when no remote matching remote was gound, + * when no remote matching remote was found, * GIT_EAMBIGUOUS when the branch maps to several remotes, * otherwise an error code. */ diff --git a/include/git2/checkout.h b/include/git2/checkout.h index d3e971b43..6798bf31c 100644 --- a/include/git2/checkout.h +++ b/include/git2/checkout.h @@ -134,6 +134,9 @@ typedef enum { /** Treat pathspec as simple list of exact match file paths */ GIT_CHECKOUT_DISABLE_PATHSPEC_MATCH = (1u << 13), + /** Ignore directories in use, they will be left empty */ + GIT_CHECKOUT_SKIP_LOCKED_DIRECTORIES = (1u << 18), + /** * THE FOLLOWING OPTIONS ARE NOT YET IMPLEMENTED */ diff --git a/include/git2/commit.h b/include/git2/commit.h index f536ac7c8..20b345f84 100644 --- a/include/git2/commit.h +++ b/include/git2/commit.h @@ -70,6 +70,14 @@ GIT_EXTERN(void) git_commit_free(git_commit *commit); GIT_EXTERN(const git_oid *) git_commit_id(const git_commit *commit); /** + * Get the repository that contains the commit. + * + * @param commit A previously loaded commit. + * @return Repository that contains this commit. + */ +GIT_EXTERN(git_repository *) git_commit_owner(const git_commit *commit); + +/** * Get the encoding for the message of a commit, * as a string representing a standard encoding name. * @@ -156,7 +164,10 @@ GIT_EXTERN(unsigned int) git_commit_parentcount(const git_commit *commit); * @param n the position of the parent (from 0 to `parentcount`) * @return 0 or an error code */ -GIT_EXTERN(int) git_commit_parent(git_commit **out, git_commit *commit, unsigned int n); +GIT_EXTERN(int) git_commit_parent( + git_commit **out, + const git_commit *commit, + unsigned int n); /** * Get the oid of a specified parent for a commit. This is different from @@ -167,7 +178,9 @@ GIT_EXTERN(int) git_commit_parent(git_commit **out, git_commit *commit, unsigned * @param n the position of the parent (from 0 to `parentcount`) * @return the id of the parent, NULL on error. */ -GIT_EXTERN(const git_oid *) git_commit_parent_id(git_commit *commit, unsigned int n); +GIT_EXTERN(const git_oid *) git_commit_parent_id( + const git_commit *commit, + unsigned int n); /** * Get the commit object that is the <n>th generation ancestor diff --git a/include/git2/config.h b/include/git2/config.h index 5a2f956fd..8d1a1a5a6 100644 --- a/include/git2/config.h +++ b/include/git2/config.h @@ -190,9 +190,24 @@ GIT_EXTERN(int) git_config_open_ondisk(git_config **out, const char *path); * multi-level parent config, or an error code */ GIT_EXTERN(int) git_config_open_level( - git_config **out, - const git_config *parent, - unsigned int level); + git_config **out, + const git_config *parent, + unsigned int level); + +/** + * Open the global/XDG configuration file according to git's rules + * + * Git allows you to store your global configuration at + * `$HOME/.config` or `$XDG_CONFIG_HOME/git/config`. For backwards + * compatability, the XDG file shouldn't be used unless the use has + * created it explicitly. With this function you'll open the correct + * one to write to. + * + * @param out pointer in which to store the config object + * @param config the config object in which to look + */ +GIT_EXTERN(int) git_config_open_global(git_config **out, git_config *config); + /** * Reload changed config files @@ -444,11 +459,11 @@ GIT_EXTERN(int) git_config_foreach_match( * @return 0 on success, error code otherwise */ GIT_EXTERN(int) git_config_get_mapped( - int *out, - const git_config *cfg, - const char *name, - const git_cvar_map *maps, - size_t map_n); + int *out, + const git_config *cfg, + const char *name, + const git_cvar_map *maps, + size_t map_n); /** * Maps a string value to an integer constant diff --git a/include/git2/diff.h b/include/git2/diff.h index 0ef47c018..1feddd7a2 100644 --- a/include/git2/diff.h +++ b/include/git2/diff.h @@ -356,8 +356,10 @@ typedef enum { GIT_DIFF_LINE_CONTEXT = ' ', GIT_DIFF_LINE_ADDITION = '+', GIT_DIFF_LINE_DELETION = '-', - GIT_DIFF_LINE_ADD_EOFNL = '\n', /**< Removed line w/o LF & added one with */ - GIT_DIFF_LINE_DEL_EOFNL = '\0', /**< LF was removed at end of file */ + + GIT_DIFF_LINE_CONTEXT_EOFNL = '=', /**< Both files have no LF at end */ + GIT_DIFF_LINE_ADD_EOFNL = '>', /**< Old has no LF at end, new does */ + GIT_DIFF_LINE_DEL_EOFNL = '<', /**< Old has LF at end, new does not */ /* The following values will only be sent to a `git_diff_data_cb` when * the content of a diff is being formatted (eg. through @@ -488,6 +490,8 @@ typedef struct { /** * Deallocate a diff list. + * + * @param diff The previously created diff list; cannot be used after free. */ GIT_EXTERN(void) git_diff_list_free(git_diff_list *diff); @@ -497,12 +501,14 @@ GIT_EXTERN(void) git_diff_list_free(git_diff_list *diff); * This is equivalent to `git diff <old-tree> <new-tree>` * * The first tree will be used for the "old_file" side of the delta and the - * second tree will be used for the "new_file" side of the delta. + * second tree will be used for the "new_file" side of the delta. You can + * pass NULL to indicate an empty tree, although it is an error to pass + * NULL for both the `old_tree` and `new_tree`. * * @param diff Output pointer to a git_diff_list pointer to be allocated. * @param repo The repository containing the trees. - * @param old_tree A git_tree object to diff from. - * @param new_tree A git_tree object to diff to. + * @param old_tree A git_tree object to diff from, or NULL for empty tree. + * @param new_tree A git_tree object to diff to, or NULL for empty tree. * @param opts Structure with options to influence diff or NULL for defaults. */ GIT_EXTERN(int) git_diff_tree_to_tree( @@ -523,7 +529,7 @@ GIT_EXTERN(int) git_diff_tree_to_tree( * * @param diff Output pointer to a git_diff_list pointer to be allocated. * @param repo The repository containing the tree and index. - * @param old_tree A git_tree object to diff from. + * @param old_tree A git_tree object to diff from, or NULL for empty tree. * @param index The index to diff with; repo index used if NULL. * @param opts Structure with options to influence diff or NULL for defaults. */ @@ -582,7 +588,7 @@ GIT_EXTERN(int) git_diff_index_to_workdir( * * @param diff A pointer to a git_diff_list pointer that will be allocated. * @param repo The repository containing the tree. - * @param old_tree A git_tree object to diff from. + * @param old_tree A git_tree object to diff from, or NULL for empty tree. * @param opts Structure with options to influence diff or NULL for defaults. */ GIT_EXTERN(int) git_diff_tree_to_workdir( @@ -926,7 +932,14 @@ GIT_EXTERN(int) git_diff_patch_to_str( * to 1 and no call to the hunk_cb nor line_cb will be made (unless you pass * `GIT_DIFF_FORCE_TEXT` of course). * - * @return 0 on success, GIT_EUSER on non-zero callback, or error code + * @param old_blob Blob for old side of diff, or NULL for empty blob + * @param new_blob Blob for new side of diff, or NULL for empty blob + * @param options Options for diff, or NULL for default options + * @param file_cb Callback for "file"; made once if there is a diff; can be NULL + * @param hunk_cb Callback for each hunk in diff; can be NULL + * @param line_cb Callback for each line in diff; can be NULL + * @param payload Payload passed to each callback function + * @return 0 on success, GIT_EUSER on non-zero callback return, or error code */ GIT_EXTERN(int) git_diff_blobs( const git_blob *old_blob, @@ -949,7 +962,15 @@ GIT_EXTERN(int) git_diff_blobs( * entire content of the buffer added). Passing NULL to the buffer will do * the reverse, with GIT_DELTA_REMOVED and blob content removed. * - * @return 0 on success, GIT_EUSER on non-zero callback, or error code + * @param old_blob Blob for old side of diff, or NULL for empty blob + * @param buffer Raw data for new side of diff + * @param buffer_len Length of raw data for new side of diff + * @param options Options for diff, or NULL for default options + * @param file_cb Callback for "file"; made once if there is a diff; can be NULL + * @param hunk_cb Callback for each hunk in diff; can be NULL + * @param line_cb Callback for each line in diff; can be NULL + * @param payload Payload passed to each callback function + * @return 0 on success, GIT_EUSER on non-zero callback return, or error code */ GIT_EXTERN(int) git_diff_blob_to_buffer( const git_blob *old_blob, diff --git a/include/git2/index.h b/include/git2/index.h index d23c3a8ea..8a1ccce55 100644 --- a/include/git2/index.h +++ b/include/git2/index.h @@ -21,50 +21,29 @@ */ GIT_BEGIN_DECL -#define GIT_IDXENTRY_NAMEMASK (0x0fff) -#define GIT_IDXENTRY_STAGEMASK (0x3000) -#define GIT_IDXENTRY_EXTENDED (0x4000) -#define GIT_IDXENTRY_VALID (0x8000) -#define GIT_IDXENTRY_STAGESHIFT 12 - -/* - * Flags are divided into two parts: in-memory flags and - * on-disk ones. Flags in GIT_IDXENTRY_EXTENDED_FLAGS - * will get saved on-disk. - * - * In-memory only flags: - */ -#define GIT_IDXENTRY_UPDATE (1 << 0) -#define GIT_IDXENTRY_REMOVE (1 << 1) -#define GIT_IDXENTRY_UPTODATE (1 << 2) -#define GIT_IDXENTRY_ADDED (1 << 3) - -#define GIT_IDXENTRY_HASHED (1 << 4) -#define GIT_IDXENTRY_UNHASHED (1 << 5) -#define GIT_IDXENTRY_WT_REMOVE (1 << 6) /* remove in work directory */ -#define GIT_IDXENTRY_CONFLICTED (1 << 7) - -#define GIT_IDXENTRY_UNPACKED (1 << 8) -#define GIT_IDXENTRY_NEW_SKIP_WORKTREE (1 << 9) - -/* - * Extended on-disk flags: - */ -#define GIT_IDXENTRY_INTENT_TO_ADD (1 << 13) -#define GIT_IDXENTRY_SKIP_WORKTREE (1 << 14) -/* GIT_IDXENTRY_EXTENDED2 is for future extension */ -#define GIT_IDXENTRY_EXTENDED2 (1 << 15) - -#define GIT_IDXENTRY_EXTENDED_FLAGS (GIT_IDXENTRY_INTENT_TO_ADD | GIT_IDXENTRY_SKIP_WORKTREE) - -/** Time used in a git index entry */ +/** Time structure used in a git index entry */ typedef struct { git_time_t seconds; /* nsec should not be stored as time_t compatible */ unsigned int nanoseconds; } git_index_time; -/** Memory representation of a file entry in the index. */ +/** + * In-memory representation of a file entry in the index. + * + * This is a public structure that represents a file entry in the index. + * The meaning of the fields corresponds to core Git's documentation (in + * "Documentation/technical/index-format.txt"). + * + * The `flags` field consists of a number of bit fields which can be + * accessed via the first set of `GIT_IDXENTRY_...` bitmasks below. These + * flags are all read from and persisted to disk. + * + * The `flags_extended` field also has a number of bit fields which can be + * accessed via the later `GIT_IDXENTRY_...` bitmasks below. Some of + * these flags are read from and written to disk, but some are set aside + * for in-memory only reference. + */ typedef struct git_index_entry { git_index_time ctime; git_index_time mtime; @@ -84,13 +63,67 @@ typedef struct git_index_entry { char *path; } git_index_entry; +/** + * Bitmasks for on-disk fields of `git_index_entry`'s `flags` + * + * These bitmasks match the four fields in the `git_index_entry` `flags` + * value both in memory and on disk. You can use them to interpret the + * data in the `flags`. + */ +#define GIT_IDXENTRY_NAMEMASK (0x0fff) +#define GIT_IDXENTRY_STAGEMASK (0x3000) +#define GIT_IDXENTRY_EXTENDED (0x4000) +#define GIT_IDXENTRY_VALID (0x8000) +#define GIT_IDXENTRY_STAGESHIFT 12 + +#define GIT_IDXENTRY_STAGE(E) (((E)->flags & GIT_IDXENTRY_STAGEMASK) >> GIT_IDXENTRY_STAGESHIFT) + +/** + * Bitmasks for on-disk fields of `git_index_entry`'s `flags_extended` + * + * In memory, the `flags_extended` fields are divided into two parts: the + * fields that are read from and written to disk, and other fields that + * in-memory only and used by libgit2. Only the flags in + * `GIT_IDXENTRY_EXTENDED_FLAGS` will get saved on-disk. + * + * These bitmasks match the three fields in the `git_index_entry` + * `flags_extended` value that belong on disk. You can use them to + * interpret the data in the `flags_extended`. + */ +#define GIT_IDXENTRY_INTENT_TO_ADD (1 << 13) +#define GIT_IDXENTRY_SKIP_WORKTREE (1 << 14) +/* GIT_IDXENTRY_EXTENDED2 is reserved for future extension */ +#define GIT_IDXENTRY_EXTENDED2 (1 << 15) + +#define GIT_IDXENTRY_EXTENDED_FLAGS (GIT_IDXENTRY_INTENT_TO_ADD | GIT_IDXENTRY_SKIP_WORKTREE) + +/** + * Bitmasks for in-memory only fields of `git_index_entry`'s `flags_extended` + * + * These bitmasks match the other fields in the `git_index_entry` + * `flags_extended` value that are only used in-memory by libgit2. You + * can use them to interpret the data in the `flags_extended`. + */ +#define GIT_IDXENTRY_UPDATE (1 << 0) +#define GIT_IDXENTRY_REMOVE (1 << 1) +#define GIT_IDXENTRY_UPTODATE (1 << 2) +#define GIT_IDXENTRY_ADDED (1 << 3) + +#define GIT_IDXENTRY_HASHED (1 << 4) +#define GIT_IDXENTRY_UNHASHED (1 << 5) +#define GIT_IDXENTRY_WT_REMOVE (1 << 6) /* remove in work directory */ +#define GIT_IDXENTRY_CONFLICTED (1 << 7) + +#define GIT_IDXENTRY_UNPACKED (1 << 8) +#define GIT_IDXENTRY_NEW_SKIP_WORKTREE (1 << 9) + /** Capabilities of system that affect index actions. */ -enum { +typedef enum { GIT_INDEXCAP_IGNORE_CASE = 1, GIT_INDEXCAP_NO_FILEMODE = 2, GIT_INDEXCAP_NO_SYMLINKS = 4, GIT_INDEXCAP_FROM_OWNER = ~0u -}; +} git_indexcap_t; /** @name Index File Functions * @@ -265,11 +298,9 @@ GIT_EXTERN(void) git_index_clear(git_index *index); /** * Get a pointer to one of the entries in the index * - * The values of this entry can be modified (except the path) - * and the changes will be written back to disk on the next - * write() call. - * - * The entry should not be freed by the caller. + * The entry is not modifiable and should not be freed. Because the + * `git_index_entry` struct is a publicly defined struct, you should + * be able to make your own permanent copy of the data if necessary. * * @param index an existing index object * @param n the position of the entry @@ -281,11 +312,9 @@ GIT_EXTERN(const git_index_entry *) git_index_get_byindex( /** * Get a pointer to one of the entries in the index * - * The values of this entry can be modified (except the path) - * and the changes will be written back to disk on the next - * write() call. - * - * The entry should not be freed by the caller. + * The entry is not modifiable and should not be freed. Because the + * `git_index_entry` struct is a publicly defined struct, you should + * be able to make your own permanent copy of the data if necessary. * * @param index an existing index object * @param path path to search @@ -335,8 +364,7 @@ GIT_EXTERN(int) git_index_add(git_index *index, const git_index_entry *source_en /** * Return the stage number from a git index entry * - * This entry is calculated from the entry's flag - * attribute like this: + * This entry is calculated from the entry's flag attribute like this: * * (entry->flags & GIT_IDXENTRY_STAGEMASK) >> GIT_IDXENTRY_STAGESHIFT * @@ -427,7 +455,7 @@ GIT_EXTERN(int) git_index_find(size_t *at_pos, git_index *index, const char *pat * @return 0 or an error code */ GIT_EXTERN(int) git_index_conflict_add( - git_index *index, + git_index *index, const git_index_entry *ancestor_entry, const git_index_entry *our_entry, const git_index_entry *their_entry); @@ -445,7 +473,12 @@ GIT_EXTERN(int) git_index_conflict_add( * @param index an existing index object * @param path path to search */ -GIT_EXTERN(int) git_index_conflict_get(git_index_entry **ancestor_out, git_index_entry **our_out, git_index_entry **their_out, git_index *index, const char *path); +GIT_EXTERN(int) git_index_conflict_get( + git_index_entry **ancestor_out, + git_index_entry **our_out, + git_index_entry **their_out, + git_index *index, + const char *path); /** * Removes the index entries that represent a conflict of a single file. diff --git a/include/git2/inttypes.h b/include/git2/inttypes.h index 716084219..17364c7f8 100644 --- a/include/git2/inttypes.h +++ b/include/git2/inttypes.h @@ -283,18 +283,18 @@ _inline #endif // STATIC_IMAXDIV ] imaxdiv_t __cdecl imaxdiv(intmax_t numer, intmax_t denom) { - imaxdiv_t result; + imaxdiv_t result; - result.quot = numer / denom; - result.rem = numer % denom; + result.quot = numer / denom; + result.rem = numer % denom; - if (numer < 0 && result.rem > 0) { - // did division wrong; must fix up - ++result.quot; - result.rem -= denom; - } + if (numer < 0 && result.rem > 0) { + // did division wrong; must fix up + ++result.quot; + result.rem -= denom; + } - return result; + return result; } // 7.8.2.3 The strtoimax and strtoumax functions diff --git a/include/git2/merge.h b/include/git2/merge.h index 8ca90b95f..955840569 100644 --- a/include/git2/merge.h +++ b/include/git2/merge.h @@ -33,7 +33,7 @@ typedef enum { /** * Automerge options for `git_merge_trees_opts`. - */ + */ typedef enum { GIT_MERGE_AUTOMERGE_NORMAL = 0, GIT_MERGE_AUTOMERGE_NONE = 1, @@ -45,18 +45,18 @@ typedef enum { typedef struct { unsigned int version; git_merge_tree_flags flags; - + /** Similarity to consider a file renamed (default 50) */ unsigned int rename_threshold; - + /** Maximum similarity sources to examine (overrides the * `merge.renameLimit` config) (default 200) */ unsigned int target_limit; - /** Pluggable similarity metric; pass NULL to use internal metric */ + /** Pluggable similarity metric; pass NULL to use internal metric */ git_diff_similarity_metric *metric; - + /** Flags for automerging content. */ git_merge_automerge_flags automerge_flags; } git_merge_tree_opts; diff --git a/include/git2/pack.h b/include/git2/pack.h index 118b8d554..5e431e62d 100644 --- a/include/git2/pack.h +++ b/include/git2/pack.h @@ -96,12 +96,12 @@ GIT_EXTERN(int) git_packbuilder_insert_tree(git_packbuilder *pb, const git_oid * /** * Insert a commit object - * + * * This will add a commit as well as the completed referenced tree. - * + * * @param pb The packbuilder * @param id The oid of the commit - * + * * @return 0 or an error code */ GIT_EXTERN(int) git_packbuilder_insert_commit(git_packbuilder *pb, const git_oid *id); diff --git a/include/git2/refs.h b/include/git2/refs.h index e1d425352..754bda785 100644 --- a/include/git2/refs.h +++ b/include/git2/refs.h @@ -55,6 +55,19 @@ GIT_EXTERN(int) git_reference_name_to_id( git_oid *out, git_repository *repo, const char *name); /** + * Lookup a reference by DWIMing its short name + * + * Apply the git precendence rules to the given shorthand to determine + * which reference the user is refering to. + * + * @param out pointer in which to store the reference + * @param repo the repository in which to look + * @param shrothand the short name for the reference + * @return 0 or an error code + */ +GIT_EXTERN(int) git_reference_dwim(git_reference **out, git_repository *repo, const char *shorthand); + +/** * Create a new symbolic reference. * * A symbolic reference is a reference name that refers to another @@ -284,12 +297,6 @@ GIT_EXTERN(int) git_reference_delete(git_reference *ref); /** * Fill a list with all the references that can be found in a repository. * - * Using the `list_flags` parameter, the listed references may be filtered - * by type (`GIT_REF_OID` or `GIT_REF_SYMBOLIC`) or using a bitwise OR of - * `git_ref_t` values. To include packed refs, include `GIT_REF_PACKED`. - * For convenience, use the value `GIT_REF_LISTALL` to obtain all - * references, including packed ones. - * * The string array will be filled with the names of all references; these * values are owned by the user and should be free'd manually when no * longer needed, using `git_strarray_free()`. @@ -297,36 +304,27 @@ GIT_EXTERN(int) git_reference_delete(git_reference *ref); * @param array Pointer to a git_strarray structure where * the reference names will be stored * @param repo Repository where to find the refs - * @param list_flags Filtering flags for the reference listing * @return 0 or an error code */ -GIT_EXTERN(int) git_reference_list(git_strarray *array, git_repository *repo, unsigned int list_flags); +GIT_EXTERN(int) git_reference_list(git_strarray *array, git_repository *repo); typedef int (*git_reference_foreach_cb)(const char *refname, void *payload); /** * Perform a callback on each reference in the repository. * - * Using the `list_flags` parameter, the references may be filtered by - * type (`GIT_REF_OID` or `GIT_REF_SYMBOLIC`) or using a bitwise OR of - * `git_ref_t` values. To include packed refs, include `GIT_REF_PACKED`. - * For convenience, use the value `GIT_REF_LISTALL` to obtain all - * references, including packed ones. - * * The `callback` function will be called for each reference in the * repository, receiving the name of the reference and the `payload` value * passed to this method. Returning a non-zero value from the callback * will terminate the iteration. * * @param repo Repository where to find the refs - * @param list_flags Filtering flags for the reference listing. * @param callback Function which will be called for every listed ref * @param payload Additional data to pass to the callback * @return 0 on success, GIT_EUSER on non-zero callback, or error code */ GIT_EXTERN(int) git_reference_foreach( git_repository *repo, - unsigned int list_flags, git_reference_foreach_cb callback, void *payload); @@ -347,6 +345,31 @@ GIT_EXTERN(void) git_reference_free(git_reference *ref); GIT_EXTERN(int) git_reference_cmp(git_reference *ref1, git_reference *ref2); /** + * Create an iterator for the repo's references + * + * @param out pointer in which to store the iterator + * @param repo the repository + * @return 0 or an error code + */ +GIT_EXTERN(int) git_reference_iterator_new(git_reference_iterator **out, git_repository *repo); + +/** + * Get the next reference name + * + * @param out pointer in which to store the string + * @param iter the iterator + * @param 0, GIT_ITEROVER if there are no more; or an error code + */ +GIT_EXTERN(int) git_reference_next(const char **out, git_reference_iterator *iter); + +/** + * Free the iterator and its associated resources + * + * @param iter the iterator to free + */ +GIT_EXTERN(void) git_reference_iterator_free(git_reference_iterator *iter); + +/** * Perform a callback on each reference in the repository whose name * matches the given pattern. * @@ -360,7 +383,6 @@ GIT_EXTERN(int) git_reference_cmp(git_reference *ref1, git_reference *ref2); * * @param repo Repository where to find the refs * @param glob Pattern to match (fnmatch-style) against reference name. - * @param list_flags Filtering flags for the reference listing. * @param callback Function which will be called for every listed ref * @param payload Additional data to pass to the callback * @return 0 on success, GIT_EUSER on non-zero callback, or error code @@ -368,7 +390,6 @@ GIT_EXTERN(int) git_reference_cmp(git_reference *ref1, git_reference *ref2); GIT_EXTERN(int) git_reference_foreach_glob( git_repository *repo, const char *glob, - unsigned int list_flags, git_reference_foreach_cb callback, void *payload); diff --git a/include/git2/repository.h b/include/git2/repository.h index cd238e17c..bb2b3db83 100644 --- a/include/git2/repository.h +++ b/include/git2/repository.h @@ -460,10 +460,19 @@ GIT_EXTERN(int) git_repository_index(git_index **out, git_repository *repo); * Use this function to get the contents of this file. Don't forget to * remove the file after you create the commit. * + * If the repository message exists and there are no errors reading it, this + * returns the bytes needed to store the message in memory (i.e. message + * file size plus one terminating NUL byte). That value is returned even if + * `out` is NULL or `len` is shorter than the necessary size. + * + * The `out` buffer will *always* be NUL terminated, even if truncation + * occurs. + * * @param out Buffer to write data into or NULL to just read required size - * @param len Length of buffer in bytes + * @param len Length of `out` buffer in bytes * @param repo Repository to read prepared message from - * @return Bytes written to buffer, GIT_ENOTFOUND if no message, or -1 on error + * @return GIT_ENOUTFOUND if no message exists, other value < 0 for other + * errors, or total bytes in message (may be > `len`) on success */ GIT_EXTERN(int) git_repository_message(char *out, size_t len, git_repository *repo); @@ -536,11 +545,11 @@ GIT_EXTERN(int) git_repository_mergehead_foreach(git_repository *repo, * applied when calculating the hash. */ GIT_EXTERN(int) git_repository_hashfile( - git_oid *out, - git_repository *repo, - const char *path, - git_otype type, - const char *as_path); + git_oid *out, + git_repository *repo, + const char *path, + git_otype type, + const char *as_path); /** * Make the repository HEAD point to the specified reference. diff --git a/include/git2/reset.h b/include/git2/reset.h index c7c951942..c36781722 100644 --- a/include/git2/reset.h +++ b/include/git2/reset.h @@ -72,9 +72,9 @@ GIT_EXTERN(int) git_reset( * @return 0 on success or an error code < 0 */ GIT_EXTERN(int) git_reset_default( - git_repository *repo, - git_object *target, - git_strarray* pathspecs); + git_repository *repo, + git_object *target, + git_strarray* pathspecs); /** @} */ GIT_END_DECL diff --git a/include/git2/strarray.h b/include/git2/strarray.h index d338eb7ad..86fa25f3f 100644 --- a/include/git2/strarray.h +++ b/include/git2/strarray.h @@ -20,8 +20,8 @@ GIT_BEGIN_DECL /** Array of strings */ typedef struct git_strarray { - char **strings; - size_t count; + char **strings; + size_t count; } git_strarray; /** diff --git a/include/git2/sys/commit.h b/include/git2/sys/commit.h index 096e028c5..34a12fb15 100644 --- a/include/git2/sys/commit.h +++ b/include/git2/sys/commit.h @@ -25,8 +25,9 @@ GIT_BEGIN_DECL * * See documentation for `git_commit_create()` for information about the * parameters, as the meaning is identical excepting that `tree` and - * `parents` now take `git_oid`. This is a dangerous API in that the - * `parents` list of `git_oid`s in not checked for validity. + * `parents` now take `git_oid`. This is a dangerous API in that nor + * the `tree`, neither the `parents` list of `git_oid`s are checked for + * validity. */ GIT_EXTERN(int) git_commit_create_from_oids( git_oid *oid, diff --git a/include/git2/sys/index.h b/include/git2/sys/index.h index f74637f84..a32e07036 100644 --- a/include/git2/sys/index.h +++ b/include/git2/sys/index.h @@ -177,4 +177,3 @@ GIT_EXTERN(void) git_index_reuc_clear(git_index *index); /** @} */ GIT_END_DECL #endif - diff --git a/include/git2/sys/refdb_backend.h b/include/git2/sys/refdb_backend.h index d5f599fec..548597fbc 100644 --- a/include/git2/sys/refdb_backend.h +++ b/include/git2/sys/refdb_backend.h @@ -20,9 +20,26 @@ */ GIT_BEGIN_DECL + +/** + * Every backend's iterator must have a pointer to itself as the first + * element, so the API can talk to it. You'd define your iterator as + * + * struct my_iterator { + * git_reference_iterator parent; + * ... + * } + * + * and assign `iter->parent.backend` to your `git_refdb_backend`. + */ +struct git_reference_iterator { + git_refdb_backend *backend; + char *glob; +}; + /** An instance for a custom backend */ struct git_refdb_backend { - unsigned int version; + unsigned int version; /** * Queries the refdb backend to determine if the given ref_name @@ -43,29 +60,42 @@ struct git_refdb_backend { const char *ref_name); /** - * Enumerates each reference in the refdb. A refdb implementation must - * provide this function. + * Allocate an iterator object for the backend. + * + * A refdb implementation must provide this function. */ - int (*foreach)( - git_refdb_backend *backend, - unsigned int list_flags, - git_reference_foreach_cb callback, - void *payload); + int (*iterator)( + git_reference_iterator **iter, + struct git_refdb_backend *backend); /** - * Enumerates each reference in the refdb that matches the given - * glob string. A refdb implementation may provide this function; - * if it is not provided, foreach will be used and the results filtered - * against the glob. + * Allocate a glob-filtering iterator object for the backend. + * + * A refdb implementation may provide this function. If it's + * not available, the glob matching will be done by the frontend. */ - int (*foreach_glob)( - git_refdb_backend *backend, - const char *glob, - unsigned int list_flags, - git_reference_foreach_cb callback, - void *payload); + int (*iterator_glob)( + git_reference_iterator **iter, + struct git_refdb_backend *backend, + const char *glob); + + /** + * Return the current value and advance the iterator. + * + * A refdb implementation must provide this function. + */ + int (*next)( + const char **name, + git_reference_iterator *iter); /** + * Free the iterator + * + * A refdb implementation must provide this function. + */ + void (*iterator_free)( + git_reference_iterator *iter); + /* * Writes the given reference to the refdb. A refdb implementation * must provide this function. */ diff --git a/include/git2/trace.h b/include/git2/trace.h index 7409b032d..f9b4d6ff6 100644 --- a/include/git2/trace.h +++ b/include/git2/trace.h @@ -32,7 +32,7 @@ typedef enum { /** Errors that do not impact the program's execution */ GIT_TRACE_ERROR = 2, - + /** Warnings that suggest abnormal data */ GIT_TRACE_WARN = 3, @@ -65,4 +65,3 @@ GIT_EXTERN(int) git_trace_set(git_trace_level_t level, git_trace_callback cb); /** @} */ GIT_END_DECL #endif - diff --git a/include/git2/tree.h b/include/git2/tree.h index 6ad722048..d673f50c4 100644 --- a/include/git2/tree.h +++ b/include/git2/tree.h @@ -97,7 +97,7 @@ GIT_EXTERN(size_t) git_tree_entrycount(const git_tree *tree); * @return the tree entry; NULL if not found */ GIT_EXTERN(const git_tree_entry *) git_tree_entry_byname( - git_tree *tree, const char *filename); + const git_tree *tree, const char *filename); /** * Lookup a tree entry by its position in the tree @@ -110,7 +110,7 @@ GIT_EXTERN(const git_tree_entry *) git_tree_entry_byname( * @return the tree entry; NULL if not found */ GIT_EXTERN(const git_tree_entry *) git_tree_entry_byindex( - git_tree *tree, size_t idx); + const git_tree *tree, size_t idx); /** * Lookup a tree entry by SHA value. @@ -141,7 +141,7 @@ GIT_EXTERN(const git_tree_entry *) git_tree_entry_byoid( */ GIT_EXTERN(int) git_tree_entry_bypath( git_tree_entry **out, - git_tree *root, + const git_tree *root, const char *path); /** diff --git a/include/git2/types.h b/include/git2/types.h index aca9ed927..43751d3b0 100644 --- a/include/git2/types.h +++ b/include/git2/types.h @@ -165,6 +165,10 @@ typedef struct git_signature { /** In-memory representation of a reference. */ typedef struct git_reference git_reference; +/** Iterator for references */ +typedef struct git_reference_iterator git_reference_iterator; + + /** Basic type of any Git reference. */ typedef enum { GIT_REF_INVALID = 0, /** Invalid reference */ |
