Commit 64c51121 by Ben Straub

Merge pull request #1087 from libgit2/great-renaming

The Great Renaming of 2012
parents 46982781 ca94e031
......@@ -204,7 +204,7 @@ IF (BUILD_CLAR)
ADD_CUSTOM_COMMAND(
OUTPUT ${CLAR_PATH}/clar_main.c ${CLAR_PATH}/clar.h
COMMAND ${PYTHON_EXECUTABLE} clar -vtap .
COMMAND ${PYTHON_EXECUTABLE} clar .
DEPENDS ${CLAR_PATH}/clar ${SRC_TEST}
WORKING_DIRECTORY ${CLAR_PATH}
)
......
......@@ -30,7 +30,7 @@ static int resolve_to_tree(
git_reference_resolve(&resolved, ref);
git_reference_free(ref);
if (resolved) {
git_object_lookup(&obj, repo, git_reference_oid(resolved), GIT_OBJ_ANY);
git_object_lookup(&obj, repo, git_reference_target(resolved), GIT_OBJ_ANY);
git_reference_free(resolved);
}
}
......@@ -63,12 +63,12 @@ char *colors[] = {
};
static int printer(
void *data,
const git_diff_delta *delta,
const git_diff_range *range,
char usage,
const char *line,
size_t line_len)
size_t line_len,
void *data)
{
int *last_color = data, color = 0;
......@@ -225,9 +225,9 @@ int main(int argc, char *argv[])
fputs(colors[0], stdout);
if (compact)
check(git_diff_print_compact(diff, &color, printer), "Displaying diff");
check(git_diff_print_compact(diff, printer, &color), "Displaying diff");
else
check(git_diff_print_patch(diff, &color, printer), "Displaying diff");
check(git_diff_print_patch(diff, printer, &color), "Displaying diff");
if (color >= 0)
fputs(colors[0], stdout);
......
......@@ -261,8 +261,8 @@ int main (int argc, char** argv)
git_tree_lookup(&tree, repo, &oid);
// Getting the count of entries in the tree so you can iterate over them if you want to.
int cnt = git_tree_entrycount(tree); // 3
printf("tree entries: %d\n", cnt);
size_t cnt = git_tree_entrycount(tree); // 3
printf("tree entries: %d\n", (int)cnt);
entry = git_tree_entry_byindex(tree, 0);
printf("Entry name: %s\n", git_tree_entry_name(entry)); // "hello.c"
......@@ -298,7 +298,7 @@ int main (int argc, char** argv)
// Note that this buffer may not be contain ASCII data for certain blobs (e.g. binary files):
// do not consider the buffer a NULL-terminated string, and use the `git_blob_rawsize` attribute to
// find out its exact size in bytes
printf("Blob Size: %ld\n", git_blob_rawsize(blob)); // 8
printf("Blob Size: %ld\n", (long)git_blob_rawsize(blob)); // 8
git_blob_rawcontent(blob); // "content"
// ### Revwalking
......@@ -371,7 +371,7 @@ int main (int argc, char** argv)
// All these properties are exported publicly in the `git_index_entry` struct
ecount = git_index_entrycount(index);
for (i = 0; i < ecount; ++i) {
git_index_entry *e = git_index_get_byindex(index, i);
const git_index_entry *e = git_index_get_byindex(index, i);
printf("path: %s\n", e->path);
printf("mtime: %d\n", (int)e->mtime.seconds);
......@@ -405,12 +405,12 @@ int main (int argc, char** argv)
switch (git_reference_type(ref)) {
case GIT_REF_OID:
git_oid_fmt(out, git_reference_oid(ref));
git_oid_fmt(out, git_reference_target(ref));
printf("%s [%s]\n", refname, out);
break;
case GIT_REF_SYMBOLIC:
printf("%s => %s\n", refname, git_reference_target(ref));
printf("%s => %s\n", refname, git_reference_symbolic_target(ref));
break;
default:
fprintf(stderr, "Unexpected reference type\n");
......
......@@ -72,7 +72,7 @@ int do_clone(git_repository *repo, int argc, char **argv)
checkout_opts.progress_payload = &pd;
// Do the clone
error = git_clone(&cloned_repo, url, path, &fetch_progress, &pd, &checkout_opts);
error = git_clone(&cloned_repo, url, path, &checkout_opts, &fetch_progress, &pd);
printf("\n");
if (error != 0) {
const git_error *err = giterr_last();
......
......@@ -25,7 +25,7 @@ static void *download(void *ptr)
// Connect to the remote end specifying that we want to fetch
// information from it.
if (git_remote_connect(data->remote, GIT_DIR_FETCH) < 0) {
if (git_remote_connect(data->remote, GIT_DIRECTION_FETCH) < 0) {
data->ret = -1;
goto exit;
}
......
......@@ -27,7 +27,7 @@ static int use_unnamed(git_repository *repo, const char *url)
// When connecting, the underlying code needs to know wether we
// want to push or fetch
error = git_remote_connect(remote, GIT_DIR_FETCH);
error = git_remote_connect(remote, GIT_DIRECTION_FETCH);
if (error < 0)
goto cleanup;
......@@ -49,7 +49,7 @@ static int use_remote(git_repository *repo, char *name)
if (error < 0)
goto cleanup;
error = git_remote_connect(remote, GIT_DIR_FETCH);
error = git_remote_connect(remote, GIT_DIRECTION_FETCH);
if (error < 0)
goto cleanup;
......
......@@ -183,6 +183,8 @@ GIT_EXTERN(int) git_attr_get_many(
size_t num_attr,
const char **names);
typedef int (*git_attr_foreach_cb)(const char *name, const char *value, void *payload);
/**
* Loop over all the git attributes for a path.
*
......@@ -204,7 +206,7 @@ GIT_EXTERN(int) git_attr_foreach(
git_repository *repo,
uint32_t flags,
const char *path,
int (*callback)(const char *name, const char *value, void *payload),
git_attr_foreach_cb callback,
void *payload);
/**
......
......@@ -68,6 +68,17 @@ GIT_INLINE(void) git_blob_free(git_blob *blob)
git_object_free((git_object *) blob);
}
/**
* Get the id of a blob.
*
* @param blob a previously loaded blob.
* @return SHA1 hash for this blob.
*/
GIT_INLINE(const git_oid *) git_blob_id(const git_blob *blob)
{
return git_object_id((const git_object *)blob);
}
/**
* Get a read-only buffer with the raw content of a blob.
......@@ -88,32 +99,35 @@ GIT_EXTERN(const void *) git_blob_rawcontent(git_blob *blob);
* @param blob pointer to the blob
* @return size on bytes
*/
GIT_EXTERN(size_t) git_blob_rawsize(git_blob *blob);
GIT_EXTERN(git_off_t) git_blob_rawsize(git_blob *blob);
/**
* Read a file from the working folder of a repository
* and write it to the Object Database as a loose blob
*
* @param oid return the id of the written blob
* @param id return the id of the written blob
* @param repo repository where the blob will be written.
* this repository cannot be bare
* @param path file from which the blob will be created,
* @param relative_path file from which the blob will be created,
* relative to the repository's working dir
* @return 0 or an error code
*/
GIT_EXTERN(int) git_blob_create_fromfile(git_oid *oid, git_repository *repo, const char *path);
GIT_EXTERN(int) git_blob_create_fromworkdir(git_oid *id, git_repository *repo, const char *relative_path);
/**
* Read a file from the filesystem and write its content
* to the Object Database as a loose blob
*
* @param oid return the id of the written blob
* @param id return the id of the written blob
* @param repo repository where the blob will be written.
* this repository can be bare or not
* @param path file from which the blob will be created
* @return 0 or an error code
*/
GIT_EXTERN(int) git_blob_create_fromdisk(git_oid *oid, git_repository *repo, const char *path);
GIT_EXTERN(int) git_blob_create_fromdisk(git_oid *id, git_repository *repo, const char *path);
typedef int (*git_blob_chunk_cb)(char *content, size_t max_length, void *payload);
/**
* Write a loose blob to the Object Database from a
......@@ -141,7 +155,7 @@ GIT_EXTERN(int) git_blob_create_fromdisk(git_oid *oid, git_repository *repo, con
* - When an error occurs, the callback should return -1.
*
*
* @param oid Return the id of the written blob
* @param id Return the id of the written blob
*
* @param repo repository where the blob will be written.
* This repository can be bare or not.
......@@ -152,10 +166,10 @@ GIT_EXTERN(int) git_blob_create_fromdisk(git_oid *oid, git_repository *repo, con
* @return GIT_SUCCESS or an error code
*/
GIT_EXTERN(int) git_blob_create_fromchunks(
git_oid *oid,
git_oid *id,
git_repository *repo,
const char *hintpath,
int (*source_cb)(char *content, size_t max_length, void *payload),
git_blob_chunk_cb callback,
void *payload);
/**
......
......@@ -29,7 +29,7 @@ GIT_BEGIN_DECL
*
* The returned reference must be freed by the user.
*
* @param branch_out Pointer where to store the underlying reference.
* @param out Pointer where to store the underlying reference.
*
* @param branch_name Name for the branch; this name is
* validated for consistency. It should also not conflict with
......@@ -47,10 +47,10 @@ GIT_BEGIN_DECL
* pointing to the provided target commit.
*/
GIT_EXTERN(int) git_branch_create(
git_reference **branch_out,
git_reference **out,
git_repository *repo,
const char *branch_name,
const git_object *target,
const git_commit *target,
int force);
/**
......@@ -113,7 +113,7 @@ GIT_EXTERN(int) git_branch_move(
*
* The generated reference must be freed by the user.
*
* @param branch_out pointer to the looked-up branch reference
* @param out pointer to the looked-up branch reference
*
* @param repo the repository to look up the branch
*
......@@ -127,7 +127,7 @@ GIT_EXTERN(int) git_branch_move(
* exists, otherwise an error code.
*/
GIT_EXTERN(int) git_branch_lookup(
git_reference **branch_out,
git_reference **out,
git_repository *repo,
const char *branch_name,
git_branch_t branch_type);
......@@ -136,7 +136,7 @@ GIT_EXTERN(int) git_branch_lookup(
* Return the reference supporting the remote tracking branch,
* given a local branch reference.
*
* @param tracking_out Pointer where to store the retrieved
* @param out Pointer where to store the retrieved
* reference.
*
* @param branch Current underlying reference of the branch.
......@@ -145,7 +145,7 @@ GIT_EXTERN(int) git_branch_lookup(
* reference exists, otherwise an error code.
*/
GIT_EXTERN(int) git_branch_tracking(
git_reference **tracking_out,
git_reference **out,
git_reference *branch);
/**
......
......@@ -146,8 +146,12 @@ typedef enum {
* Checkout options structure
*
* Use zeros to indicate default settings.
* This needs to be initialized with the `GIT_CHECKOUT_OPTS_INIT` macro:
*
* git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
*/
typedef struct git_checkout_opts {
unsigned int version;
unsigned int checkout_strategy; /** default will be a dry run */
int disable_filters; /** don't apply filters like CRLF conversion */
......@@ -182,6 +186,8 @@ typedef struct git_checkout_opts {
git_strarray paths;
} git_checkout_opts;
#define GIT_CHECKOUT_OPTS_INIT {1, 0}
/**
* Updates files in the index and the working tree to match the content of the
* commit pointed at by HEAD.
......@@ -223,7 +229,7 @@ GIT_EXTERN(int) git_checkout_index(
*/
GIT_EXTERN(int) git_checkout_tree(
git_repository *repo,
git_object *treeish,
const git_object *treeish,
git_checkout_opts *opts);
/** @} */
......
......@@ -42,9 +42,9 @@ GIT_EXTERN(int) git_clone(
git_repository **out,
const char *origin_url,
const char *workdir_path,
git_checkout_opts *checkout_opts,
git_transfer_progress_callback fetch_progress_cb,
void *fetch_progress_payload,
git_checkout_opts *checkout_opts);
void *fetch_progress_payload);
/**
* Create a bare clone of a remote repository.
......
......@@ -76,7 +76,10 @@ GIT_INLINE(void) git_commit_free(git_commit *commit)
* @param commit a previously loaded commit.
* @return object identity for the commit.
*/
GIT_EXTERN(const git_oid *) git_commit_id(git_commit *commit);
GIT_INLINE(const git_oid *) git_commit_id(const git_commit *commit)
{
return git_object_id((const git_object *)commit);
}
/**
* Get the encoding for the message of a commit,
......@@ -88,7 +91,7 @@ GIT_EXTERN(const git_oid *) git_commit_id(git_commit *commit);
* @param commit a previously loaded commit.
* @return NULL, or the encoding
*/
GIT_EXTERN(const char *) git_commit_message_encoding(git_commit *commit);
GIT_EXTERN(const char *) git_commit_message_encoding(const git_commit *commit);
/**
* Get the full message of a commit.
......@@ -96,7 +99,7 @@ GIT_EXTERN(const char *) git_commit_message_encoding(git_commit *commit);
* @param commit a previously loaded commit.
* @return the message of a commit
*/
GIT_EXTERN(const char *) git_commit_message(git_commit *commit);
GIT_EXTERN(const char *) git_commit_message(const git_commit *commit);
/**
* Get the commit time (i.e. committer time) of a commit.
......@@ -104,7 +107,7 @@ GIT_EXTERN(const char *) git_commit_message(git_commit *commit);
* @param commit a previously loaded commit.
* @return the time of a commit
*/
GIT_EXTERN(git_time_t) git_commit_time(git_commit *commit);
GIT_EXTERN(git_time_t) git_commit_time(const git_commit *commit);
/**
* Get the commit timezone offset (i.e. committer's preferred timezone) of a commit.
......@@ -112,7 +115,7 @@ GIT_EXTERN(git_time_t) git_commit_time(git_commit *commit);
* @param commit a previously loaded commit.
* @return positive or negative timezone offset, in minutes from UTC
*/
GIT_EXTERN(int) git_commit_time_offset(git_commit *commit);
GIT_EXTERN(int) git_commit_time_offset(const git_commit *commit);
/**
* Get the committer of a commit.
......@@ -120,7 +123,7 @@ GIT_EXTERN(int) git_commit_time_offset(git_commit *commit);
* @param commit a previously loaded commit.
* @return the committer of a commit
*/
GIT_EXTERN(const git_signature *) git_commit_committer(git_commit *commit);
GIT_EXTERN(const git_signature *) git_commit_committer(const git_commit *commit);
/**
* Get the author of a commit.
......@@ -128,7 +131,7 @@ GIT_EXTERN(const git_signature *) git_commit_committer(git_commit *commit);
* @param commit a previously loaded commit.
* @return the author of a commit
*/
GIT_EXTERN(const git_signature *) git_commit_author(git_commit *commit);
GIT_EXTERN(const git_signature *) git_commit_author(const git_commit *commit);
/**
* Get the tree pointed to by a commit.
......@@ -137,7 +140,7 @@ GIT_EXTERN(const git_signature *) git_commit_author(git_commit *commit);
* @param commit a previously loaded commit.
* @return 0 or an error code
*/
GIT_EXTERN(int) git_commit_tree(git_tree **tree_out, git_commit *commit);
GIT_EXTERN(int) git_commit_tree(git_tree **tree_out, const git_commit *commit);
/**
* Get the id of the tree pointed to by a commit. This differs from
......@@ -147,7 +150,7 @@ GIT_EXTERN(int) git_commit_tree(git_tree **tree_out, git_commit *commit);
* @param commit a previously loaded commit.
* @return the id of tree pointed to by commit.
*/
GIT_EXTERN(const git_oid *) git_commit_tree_oid(git_commit *commit);
GIT_EXTERN(const git_oid *) git_commit_tree_id(const git_commit *commit);
/**
* Get the number of parents of this commit
......@@ -155,17 +158,17 @@ GIT_EXTERN(const git_oid *) git_commit_tree_oid(git_commit *commit);
* @param commit a previously loaded commit.
* @return integer of count of parents
*/
GIT_EXTERN(unsigned int) git_commit_parentcount(git_commit *commit);
GIT_EXTERN(unsigned int) git_commit_parentcount(const git_commit *commit);
/**
* Get the specified parent of the commit.
*
* @param parent Pointer where to store the parent commit
* @param out Pointer where to store the parent commit
* @param commit a previously loaded 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 **parent, git_commit *commit, unsigned int n);
GIT_EXTERN(int) git_commit_parent(git_commit **out, git_commit *commit, unsigned int n);
/**
* Get the oid of a specified parent for a commit. This is different from
......@@ -176,7 +179,7 @@ GIT_EXTERN(int) git_commit_parent(git_commit **parent, git_commit *commit, unsig
* @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_oid(git_commit *commit, unsigned int n);
GIT_EXTERN(const git_oid *) git_commit_parent_id(git_commit *commit, unsigned int n);
/**
* Get the commit object that is the <n>th generation ancestor
......@@ -204,7 +207,7 @@ GIT_EXTERN(int) git_commit_nth_gen_ancestor(
* The message will not be cleaned up. This can be achieved
* through `git_message_prettify()`.
*
* @param oid Pointer where to store the OID of the
* @param id Pointer where to store the OID of the
* newly created commit
*
* @param repo Repository where to store the commit
......@@ -245,7 +248,7 @@ GIT_EXTERN(int) git_commit_nth_gen_ancestor(
* the given reference will be updated to point to it
*/
GIT_EXTERN(int) git_commit_create(
git_oid *oid,
git_oid *id,
git_repository *repo,
const char *update_ref,
const git_signature *author,
......@@ -273,7 +276,7 @@ GIT_EXTERN(int) git_commit_create(
* @see git_commit_create
*/
GIT_EXTERN(int) git_commit_create_v(
git_oid *oid,
git_oid *id,
git_repository *repo,
const char *update_ref,
const git_signature *author,
......
......@@ -106,6 +106,7 @@ typedef enum {
* - max_size: maximum blob size to diff, above this treated as binary
*/
typedef struct {
unsigned int version; /**< version for the struct */
uint32_t flags; /**< defaults to GIT_DIFF_NORMAL */
uint16_t context_lines; /**< defaults to 3 */
uint16_t interhunk_lines; /**< defaults to 0 */
......@@ -186,10 +187,10 @@ typedef struct {
/**
* When iterating over a diff, callback that will be made per file.
*/
typedef int (*git_diff_file_fn)(
void *cb_data,
typedef int (*git_diff_file_cb)(
const git_diff_delta *delta,
float progress);
float progress,
void *payload);
/**
* Structure describing a hunk of a diff.
......@@ -204,31 +205,31 @@ typedef struct {
/**
* When iterating over a diff, callback that will be made per hunk.
*/
typedef int (*git_diff_hunk_fn)(
void *cb_data,
typedef int (*git_diff_hunk_cb)(
const git_diff_delta *delta,
const git_diff_range *range,
const char *header,
size_t header_len);
size_t header_len,
void *payload);
/**
* Line origin constants.
*
* These values describe where a line came from and will be passed to
* the git_diff_data_fn when iterating over a diff. There are some
* the git_diff_data_cb when iterating over a diff. There are some
* special origin constants at the end that are used for the text
* output callbacks to demarcate lines that are actually part of
* the file or hunk headers.
*/
typedef enum {
/* These values will be sent to `git_diff_data_fn` along with the line */
/* These values will be sent to `git_diff_data_cb` along with the line */
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 */
/* The following values will only be sent to a `git_diff_data_fn` when
/* The following values will only be sent to a `git_diff_data_cb` when
* the content of a diff is being formatted (eg. through
* git_diff_print_patch() or git_diff_print_compact(), for instance).
*/
......@@ -245,13 +246,13 @@ typedef enum {
* of text. This uses some extra GIT_DIFF_LINE_... constants for output
* of lines of file and hunk headers.
*/
typedef int (*git_diff_data_fn)(
void *cb_data,
typedef int (*git_diff_data_cb)(
const git_diff_delta *delta,
const git_diff_range *range,
char line_origin, /**< GIT_DIFF_LINE_... value from above */
const char *content,
size_t content_len);
size_t content_len,
void *payload);
/**
* The diff patch is used to store all the text diffs for a delta.
......@@ -283,6 +284,8 @@ typedef enum {
* Control behavior of rename and copy detection
*/
typedef struct {
unsigned int version;
/** Combination of git_diff_find_t values (default FIND_RENAMES) */
unsigned int flags;
......@@ -461,7 +464,6 @@ GIT_EXTERN(int) git_diff_find_similar(
* the iteration and cause this return `GIT_EUSER`.
*
* @param diff A git_diff_list generated by one of the above functions.
* @param cb_data Reference pointer that will be passed to your callbacks.
* @param file_cb Callback function to make per file in the diff.
* @param hunk_cb Optional callback to make per hunk of text diff. This
* callback is called to describe a range of lines in the
......@@ -469,14 +471,15 @@ GIT_EXTERN(int) git_diff_find_similar(
* @param line_cb Optional callback to make per line of diff text. This
* same callback will be made for context lines, added, and
* removed lines, and even for a deleted trailing newline.
* @param payload Reference pointer that will be passed to your callbacks.
* @return 0 on success, GIT_EUSER on non-zero callback, or error code
*/
GIT_EXTERN(int) git_diff_foreach(
git_diff_list *diff,
void *cb_data,
git_diff_file_fn file_cb,
git_diff_hunk_fn hunk_cb,
git_diff_data_fn line_cb);
git_diff_file_cb file_cb,
git_diff_hunk_cb hunk_cb,
git_diff_data_cb line_cb,
void *payload);
/**
* Iterate over a diff generating text output like "git diff --name-status".
......@@ -485,14 +488,14 @@ GIT_EXTERN(int) git_diff_foreach(
* iteration and cause this return `GIT_EUSER`.
*
* @param diff A git_diff_list generated by one of the above functions.
* @param cb_data Reference pointer that will be passed to your callback.
* @param print_cb Callback to make per line of diff text.
* @param payload Reference pointer that will be passed to your callback.
* @return 0 on success, GIT_EUSER on non-zero callback, or error code
*/
GIT_EXTERN(int) git_diff_print_compact(
git_diff_list *diff,
void *cb_data,
git_diff_data_fn print_cb);
git_diff_data_cb print_cb,
void *payload);
/**
* Look up the single character abbreviation for a delta status code.
......@@ -517,7 +520,7 @@ GIT_EXTERN(char) git_diff_status_char(git_delta_t status);
* iteration and cause this return `GIT_EUSER`.
*
* @param diff A git_diff_list generated by one of the above functions.
* @param cb_data Reference pointer that will be passed to your callbacks.
* @param payload Reference pointer that will be passed to your callbacks.
* @param print_cb Callback function to output lines of the diff. This
* same function will be called for file headers, hunk
* headers, and diff lines. Fortunately, you can probably
......@@ -527,8 +530,8 @@ GIT_EXTERN(char) git_diff_status_char(git_delta_t status);
*/
GIT_EXTERN(int) git_diff_print_patch(
git_diff_list *diff,
void *cb_data,
git_diff_data_fn print_cb);
git_diff_data_cb print_cb,
void *payload);
/**
* Query how many diff records are there in a diff list.
......@@ -572,15 +575,15 @@ GIT_EXTERN(size_t) git_diff_num_deltas_of_type(
* It is okay to pass NULL for either of the output parameters; if you pass
* NULL for the `git_diff_patch`, then the text diff will not be calculated.
*
* @param patch Output parameter for the delta patch object
* @param delta Output parameter for the delta object
* @param patch_out Output parameter for the delta patch object
* @param delta_out Output parameter for the delta object
* @param diff Diff list object
* @param idx Index into diff list
* @return 0 on success, other value < 0 on error
*/
GIT_EXTERN(int) git_diff_get_patch(
git_diff_patch **patch,
const git_diff_delta **delta,
git_diff_patch **patch_out,
const git_diff_delta **delta_out,
git_diff_list *diff,
size_t idx);
......@@ -672,15 +675,15 @@ GIT_EXTERN(int) git_diff_patch_get_line_in_hunk(
* and cause this return `GIT_EUSER`.
*
* @param patch A git_diff_patch representing changes to one file
* @param cb_data Reference pointer that will be passed to your callbacks.
* @param print_cb Callback function to output lines of the patch. Will be
* called for file headers, hunk headers, and diff lines.
* @param payload Reference pointer that will be passed to your callbacks.
* @return 0 on success, GIT_EUSER on non-zero callback, or error code
*/
GIT_EXTERN(int) git_diff_patch_print(
git_diff_patch *patch,
void *cb_data,
git_diff_data_fn print_cb);
git_diff_data_cb print_cb,
void *payload);
/**
* Get the content of a patch as a single diff text.
......@@ -718,10 +721,10 @@ GIT_EXTERN(int) git_diff_blobs(
git_blob *old_blob,
git_blob *new_blob,
const git_diff_options *options,
void *cb_data,
git_diff_file_fn file_cb,
git_diff_hunk_fn hunk_cb,
git_diff_data_fn line_cb);
git_diff_file_cb file_cb,
git_diff_hunk_cb hunk_cb,
git_diff_data_cb line_cb,
void *payload);
GIT_END_DECL
......
......@@ -21,10 +21,10 @@
*/
GIT_BEGIN_DECL
#define GIT_IDXENTRY_NAMEMASK (0x0fff)
#define GIT_IDXENTRY_NAMEMASK (0x0fff)
#define GIT_IDXENTRY_STAGEMASK (0x3000)
#define GIT_IDXENTRY_EXTENDED (0x4000)
#define GIT_IDXENTRY_VALID (0x8000)
#define GIT_IDXENTRY_EXTENDED (0x4000)
#define GIT_IDXENTRY_VALID (0x8000)
#define GIT_IDXENTRY_STAGESHIFT 12
/*
......@@ -34,26 +34,26 @@ GIT_BEGIN_DECL
*
* 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_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_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_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)
#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_EXTENDED2 (1 << 15)
#define GIT_IDXENTRY_EXTENDED_FLAGS (GIT_IDXENTRY_INTENT_TO_ADD | GIT_IDXENTRY_SKIP_WORKTREE)
......@@ -119,11 +119,11 @@ enum {
*
* The index must be freed once it's no longer in use.
*
* @param index the pointer for the new index
* @param out the pointer for the new index
* @param index_path the path to the index file in disk
* @return 0 or an error code
*/
GIT_EXTERN(int) git_index_open(git_index **index, const char *index_path);
GIT_EXTERN(int) git_index_open(git_index **out, const char *index_path);
/**
* Create an in-memory index object.
......@@ -133,10 +133,10 @@ GIT_EXTERN(int) git_index_open(git_index **index, const char *index_path);
*
* The index must be freed once it's no longer in use.
*
* @param index the pointer for the new index
* @param out the pointer for the new index
* @return 0 or an error code
*/
GIT_EXTERN(int) git_index_new(git_index **index);
GIT_EXTERN(int) git_index_new(git_index **out);
/**
* Free an existing index object.
......@@ -201,7 +201,7 @@ GIT_EXTERN(int) git_index_write(git_index *index);
* @param tree tree to read
* @return 0 or an error code
*/
GIT_EXTERN(int) git_index_read_tree(git_index *index, git_tree *tree);
GIT_EXTERN(int) git_index_read_tree(git_index *index, const git_tree *tree);
/**
* Write the index as a tree
......@@ -217,12 +217,12 @@ GIT_EXTERN(int) git_index_read_tree(git_index *index, git_tree *tree);
*
* The index must not contain any file in conflict.
*
* @param oid Pointer where to store the OID of the written tree
* @param out Pointer where to store the OID of the written tree
* @param index Index to write
* @return 0 on success, GIT_EUNMERGED when the index is not clean
* or an error code
*/
GIT_EXTERN(int) git_index_write_tree(git_oid *oid, git_index *index);
GIT_EXTERN(int) git_index_write_tree(git_oid *out, git_index *index);
/**
* Write the index as a tree to the given repository
......@@ -233,13 +233,13 @@ GIT_EXTERN(int) git_index_write_tree(git_oid *oid, git_index *index);
*
* The index must not contain any file in conflict.
*
* @param oid Pointer where to store OID of the the written tree
* @param out Pointer where to store OID of the the written tree
* @param index Index to write
* @param repo Repository where to write the tree
* @return 0 on success, GIT_EUNMERGED when the index is not clean
* or an error code
*/
GIT_EXTERN(int) git_index_write_tree_to(git_oid *oid, git_index *index, git_repository *repo);
GIT_EXTERN(int) git_index_write_tree_to(git_oid *out, git_index *index, git_repository *repo);
/**@}*/
......@@ -258,7 +258,7 @@ GIT_EXTERN(int) git_index_write_tree_to(git_oid *oid, git_index *index, git_repo
* @param index an existing index object
* @return integer of count of current entries
*/
GIT_EXTERN(unsigned int) git_index_entrycount(git_index *index);
GIT_EXTERN(size_t) git_index_entrycount(const git_index *index);
/**
* Clear the contents (all the entries) of an index object.
......@@ -282,7 +282,8 @@ GIT_EXTERN(void) git_index_clear(git_index *index);
* @param n the position of the entry
* @return a pointer to the entry; NULL if out of bounds
*/
GIT_EXTERN(git_index_entry *) git_index_get_byindex(git_index *index, size_t n);
GIT_EXTERN(const git_index_entry *) git_index_get_byindex(
git_index *index, size_t n);
/**
* Get a pointer to one of the entries in the index
......@@ -298,7 +299,8 @@ GIT_EXTERN(git_index_entry *) git_index_get_byindex(git_index *index, size_t n);
* @param stage stage to search
* @return a pointer to the entry; NULL if it was not found
*/
GIT_EXTERN(git_index_entry *) git_index_get_bypath(git_index *index, const char *path, int stage);
GIT_EXTERN(const git_index_entry *) git_index_get_bypath(
git_index *index, const char *path, int stage);
/**
* Remove an entry from the index
......@@ -402,7 +404,8 @@ GIT_EXTERN(int) git_index_find(git_index *index, const char *path);
* @param their_entry the entry data for their side of the merge conflict
* @return 0 or an error code
*/
GIT_EXTERN(int) git_index_conflict_add(git_index *index,
GIT_EXTERN(int) git_index_conflict_add(
git_index *index,
const git_index_entry *ancestor_entry,
const git_index_entry *our_entry,
const git_index_entry *their_entry);
......@@ -442,7 +445,7 @@ GIT_EXTERN(void) git_index_conflict_cleanup(git_index *index);
*
* @return 1 if at least one conflict is found, 0 otherwise.
*/
GIT_EXTERN(int) git_index_has_conflicts(git_index *index);
GIT_EXTERN(int) git_index_has_conflicts(const git_index *index);
/**@}*/
......@@ -475,7 +478,7 @@ GIT_EXTERN(int) git_index_reuc_find(git_index *index, const char *path);
* Get a resolve undo entry from the index.
*
* The returned entry is read-only and should not be modified
* of freed by the caller.
* or freed by the caller.
*
* @param index an existing index object
* @param path path to search
......@@ -487,7 +490,7 @@ GIT_EXTERN(const git_index_reuc_entry *) git_index_reuc_get_bypath(git_index *in
* Get a resolve undo entry from the index.
*
* The returned entry is read-only and should not be modified
* of freed by the caller.
* or freed by the caller.
*
* @param index an existing index object
* @param n the position of the entry
......@@ -496,7 +499,7 @@ GIT_EXTERN(const git_index_reuc_entry *) git_index_reuc_get_bypath(git_index *in
GIT_EXTERN(const git_index_reuc_entry *) git_index_reuc_get_byindex(git_index *index, size_t n);
/**
* Adds an resolve undo entry for a file based on the given parameters.
* Adds a resolve undo entry for a file based on the given parameters.
*
* The resolve undo entry contains the OIDs of files that were involved
* in a merge conflict after the conflict has been resolved. This allows
......@@ -510,26 +513,26 @@ GIT_EXTERN(const git_index_reuc_entry *) git_index_reuc_get_byindex(git_index *i
* @param index an existing index object
* @param path filename to add
* @param ancestor_mode mode of the ancestor file
* @param ancestor_oid oid of the ancestor file
* @param ancestor_id oid of the ancestor file
* @param our_mode mode of our file
* @param our_oid oid of our file
* @param our_id oid of our file
* @param their_mode mode of their file
* @param their_oid oid of their file
* @param their_id oid of their file
* @return 0 or an error code
*/
GIT_EXTERN(int) git_index_reuc_add(git_index *index, const char *path,
int ancestor_mode, git_oid *ancestor_oid,
int our_mode, git_oid *our_oid,
int their_mode, git_oid *their_oid);
int ancestor_mode, git_oid *ancestor_id,
int our_mode, git_oid *our_id,
int their_mode, git_oid *their_id);
/**
* Remove an resolve undo entry from the index
*
* @param index an existing index object
* @param position position of the resolve undo entry to remove
* @param n position of the resolve undo entry to remove
* @return 0 or an error code
*/
GIT_EXTERN(int) git_index_reuc_remove(git_index *index, int position);
GIT_EXTERN(int) git_index_reuc_remove(git_index *index, size_t n);
/**@}*/
......
......@@ -44,14 +44,14 @@ GIT_EXTERN(int) git_indexer_stream_new(
git_indexer_stream **out,
const char *path,
git_transfer_progress_callback progress_cb,
void *progress_callback_payload);
void *progress_cb_payload);
/**
* Add data to the indexer
*
* @param idx the indexer
* @param data the data to add
* @param size the size of the data
* @param size the size of the data in bytes
* @param stats stat storage
*/
GIT_EXTERN(int) git_indexer_stream_add(git_indexer_stream *idx, const void *data, size_t size, git_transfer_progress *stats);
......@@ -73,7 +73,7 @@ GIT_EXTERN(int) git_indexer_stream_finalize(git_indexer_stream *idx, git_transfe
*
* @param idx the indexer instance
*/
GIT_EXTERN(const git_oid *) git_indexer_stream_hash(git_indexer_stream *idx);
GIT_EXTERN(const git_oid *) git_indexer_stream_hash(const git_indexer_stream *idx);
/**
* Free the indexer and its resources
......@@ -120,7 +120,7 @@ GIT_EXTERN(int) git_indexer_write(git_indexer *idx);
*
* @param idx the indexer instance
*/
GIT_EXTERN(const git_oid *) git_indexer_hash(git_indexer *idx);
GIT_EXTERN(const git_oid *) git_indexer_hash(const git_indexer *idx);
/**
* Free the indexer and its resources
......
......@@ -27,8 +27,13 @@ GIT_BEGIN_DECL
* @param repo the repository where the commits exist
* @param one one of the commits
* @param two the other commit
* @return Zero on success; GIT_ENOTFOUND or -1 on failure.
*/
GIT_EXTERN(int) git_merge_base(git_oid *out, git_repository *repo, const git_oid *one, const git_oid *two);
GIT_EXTERN(int) git_merge_base(
git_oid *out,
git_repository *repo,
const git_oid *one,
const git_oid *two);
/**
* Find a merge base given a list of commits
......@@ -37,8 +42,13 @@ GIT_EXTERN(int) git_merge_base(git_oid *out, git_repository *repo, const git_oid
* @param repo the repository where the commits exist
* @param input_array oids of the commits
* @param length The number of commits in the provided `input_array`
* @return Zero on success; GIT_ENOTFOUND or -1 on failure.
*/
GIT_EXTERN(int) git_merge_base_many(git_oid *out, git_repository *repo, const git_oid input_array[], size_t length);
GIT_EXTERN(int) git_merge_base_many(
git_oid *out,
git_repository *repo,
const git_oid input_array[],
size_t length);
/** @} */
GIT_END_DECL
......
......@@ -23,21 +23,27 @@ GIT_BEGIN_DECL
*
* Optionally, can remove lines starting with a "#".
*
* @param message_out The user allocated buffer which will be filled with
* the cleaned up message. Pass NULL if you just want to get the size of the
* prettified message as the output value.
* @param out The user-allocated buffer which will be filled with the
* cleaned up message. Pass NULL if you just want to get the needed
* size of the prettified message as the output value.
*
* @param size The size of the allocated buffer message_out.
* @param out_size Size of the `out` buffer in bytes.
*
* @param message The message to be prettified.
*
* @param strip_comments 1 to remove lines starting with a "#", 0 otherwise.
* @param strip_comments Non-zero to remove lines starting with "#", 0 to
* leave them in.
*
* @return -1 on error, else number of characters in prettified message
* including the trailing NUL byte
* including the trailing NUL byte
*/
GIT_EXTERN(int) git_message_prettify(char *message_out, size_t buffer_size, const char *message, int strip_comments);
GIT_EXTERN(int) git_message_prettify(
char *out,
size_t out_size,
const char *message,
int strip_comments);
/** @} */
GIT_END_DECL
#endif /* INCLUDE_git_message_h__ */
......@@ -4,8 +4,8 @@
* 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_net_h__
#define INCLUDE_net_h__
#ifndef INCLUDE_git_net_h__
#define INCLUDE_git_net_h__
#include "common.h"
#include "oid.h"
......@@ -27,8 +27,10 @@ GIT_BEGIN_DECL
* gets called.
*/
#define GIT_DIR_FETCH 0
#define GIT_DIR_PUSH 1
typedef enum {
GIT_DIRECTION_FETCH = 0,
GIT_DIRECTION_PUSH = 1
} git_direction;
/**
......@@ -44,7 +46,7 @@ struct git_remote_head {
/**
* Callback for listing the remote heads
*/
typedef int (*git_headlist_cb)(git_remote_head *, void *);
typedef int (*git_headlist_cb)(git_remote_head *rhead, void *payload);
/** @} */
GIT_END_DECL
......
......@@ -19,20 +19,34 @@
GIT_BEGIN_DECL
/**
* Callback for git_note_foreach.
*
* Receives:
* - blob_id: Oid of the blob containing the message
* - annotated_object_id: Oid of the git object being annotated
* - payload: Payload data passed to `git_note_foreach`
*/
typedef int (*git_note_foreach_cb)(
const git_oid *blob_id, const git_oid *annotated_object_id, void *payload);
/**
* Read the note for an object
*
* The note must be freed manually by the user.
*
* @param note pointer to the read note; NULL in case of error
* @param out pointer to the read note; NULL in case of error
* @param repo repository where to look up the note
* @param notes_ref canonical name of the reference to use (optional);
* defaults to "refs/notes/commits"
* @param notes_ref canonical name of the reference to use (optional); defaults to
* "refs/notes/commits"
* @param oid OID of the git object to read the note from
*
* @return 0 or an error code
*/
GIT_EXTERN(int) git_note_read(git_note **note, git_repository *repo,
const char *notes_ref, const git_oid *oid);
GIT_EXTERN(int) git_note_read(
git_note **out,
git_repository *repo,
const char *notes_ref,
const git_oid *oid);
/**
* Get the note message
......@@ -40,7 +54,7 @@ GIT_EXTERN(int) git_note_read(git_note **note, git_repository *repo,
* @param note
* @return the note message
*/
GIT_EXTERN(const char *) git_note_message(git_note *note);
GIT_EXTERN(const char *) git_note_message(const git_note *note);
/**
......@@ -49,7 +63,7 @@ GIT_EXTERN(const char *) git_note_message(git_note *note);
* @param note
* @return the note object OID
*/
GIT_EXTERN(const git_oid *) git_note_oid(git_note *note);
GIT_EXTERN(const git_oid *) git_note_oid(const git_note *note);
/**
* Add a note for an object
......@@ -65,10 +79,14 @@ GIT_EXTERN(const git_oid *) git_note_oid(git_note *note);
*
* @return 0 or an error code
*/
GIT_EXTERN(int) git_note_create(git_oid *out, git_repository *repo,
git_signature *author, git_signature *committer,
const char *notes_ref, const git_oid *oid,
const char *note);
GIT_EXTERN(int) git_note_create(
git_oid *out,
git_repository *repo,
const git_signature *author,
const git_signature *committer,
const char *notes_ref,
const git_oid *oid,
const char *note);
/**
......@@ -83,9 +101,12 @@ GIT_EXTERN(int) git_note_create(git_oid *out, git_repository *repo,
*
* @return 0 or an error code
*/
GIT_EXTERN(int) git_note_remove(git_repository *repo, const char *notes_ref,
git_signature *author, git_signature *committer,
const git_oid *oid);
GIT_EXTERN(int) git_note_remove(
git_repository *repo,
const char *notes_ref,
const git_signature *author,
const git_signature *committer,
const git_oid *oid);
/**
* Free a git_note object
......@@ -105,17 +126,6 @@ GIT_EXTERN(void) git_note_free(git_note *note);
GIT_EXTERN(int) git_note_default_ref(const char **out, git_repository *repo);
/**
* Basic components of a note
*
* - Oid of the blob containing the message
* - Oid of the git object being annotated
*/
typedef struct {
git_oid blob_oid;
git_oid annotated_object_oid;
} git_note_data;
/**
* Loop over all the notes within a specified namespace
* and issue a callback for each one.
*
......@@ -134,9 +144,8 @@ typedef struct {
GIT_EXTERN(int) git_note_foreach(
git_repository *repo,
const char *notes_ref,
int (*note_cb)(git_note_data *note_data, void *payload),
void *payload
);
git_note_foreach_cb note_cb,
void *payload);
/** @} */
GIT_END_DECL
......
......@@ -183,9 +183,9 @@ GIT_EXTERN(size_t) git_object__size(git_otype type);
* @return 0 or an error code
*/
GIT_EXTERN(int) git_object_peel(
git_object **peeled,
git_object *object,
git_otype target_type);
git_object **peeled,
const git_object *object,
git_otype target_type);
/** @} */
GIT_END_DECL
......
......@@ -136,9 +136,10 @@ GIT_EXTERN(int) git_odb_read(git_odb_object **out, git_odb *db, const git_oid *i
* @param db database to search for the object in.
* @param short_id a prefix of the id of the object to read.
* @param len the length of the prefix
* @return 0 if the object was read;
* GIT_ENOTFOUND if the object is not in the database.
* GIT_EAMBIGUOUS if the prefix is ambiguous (several objects match the prefix)
* @return
* - 0 if the object was read;
* - GIT_ENOTFOUND if the object is not in the database.
* - GIT_EAMBIGUOUS if the prefix is ambiguous (several objects match the prefix)
*/
GIT_EXTERN(int) git_odb_read_prefix(git_odb_object **out, git_odb *db, const git_oid *short_id, size_t len);
......@@ -152,15 +153,15 @@ GIT_EXTERN(int) git_odb_read_prefix(git_odb_object **out, git_odb *db, const git
* of an object, so the whole object will be read and then the
* header will be returned.
*
* @param len_p pointer where to store the length
* @param type_p pointer where to store the type
* @param len_out pointer where to store the length
* @param type_out pointer where to store the type
* @param db database to search for the object in.
* @param id identity of the object to read.
* @return
* - 0 if the object was read;
* - GIT_ENOTFOUND if the object is not in the database.
*/
GIT_EXTERN(int) git_odb_read_header(size_t *len_p, git_otype *type_p, git_odb *db, const git_oid *id);
GIT_EXTERN(int) git_odb_read_header(size_t *len_out, git_otype *type_out, git_odb *db, const git_oid *id);
/**
* Determine if the given object can be found in the object database.
......@@ -183,10 +184,10 @@ GIT_EXTERN(int) git_odb_exists(git_odb *db, const git_oid *id);
*
* @param db database to use
* @param cb the callback to call for each object
* @param data data to pass to the callback
* @param payload data to pass to the callback
* @return 0 on success, GIT_EUSER on non-zero callback, or error code
*/
GIT_EXTERN(int) git_odb_foreach(git_odb *db, int (*cb)(git_oid *oid, void *data), void *data);
GIT_EXTERN(int) git_odb_foreach(git_odb *db, git_odb_foreach_cb cb, void *payload);
/**
* Write an object directly into the ODB
......@@ -199,14 +200,14 @@ GIT_EXTERN(int) git_odb_foreach(git_odb *db, int (*cb)(git_oid *oid, void *data)
* This method is provided for compatibility with custom backends
* which are not able to support streaming writes
*
* @param oid pointer to store the OID result of the write
* @param out pointer to store the OID result of the write
* @param odb object database where to store the object
* @param data buffer with the data to store
* @param len size of the buffer
* @param type type of the data to store
* @return 0 or an error code
*/
GIT_EXTERN(int) git_odb_write(git_oid *oid, git_odb *odb, const void *data, size_t len, git_otype type);
GIT_EXTERN(int) git_odb_write(git_oid *out, git_odb *odb, const void *data, size_t len, git_otype type);
/**
* Open a stream to write an object into the ODB
......@@ -229,13 +230,13 @@ GIT_EXTERN(int) git_odb_write(git_oid *oid, git_odb *odb, const void *data, size
*
* @see git_odb_stream
*
* @param stream pointer where to store the stream
* @param out pointer where to store the stream
* @param db object database where the stream will write
* @param size final size of the object that will be written
* @param type type of the object that will be written
* @return 0 if the stream was created; error code otherwise
*/
GIT_EXTERN(int) git_odb_open_wstream(git_odb_stream **stream, git_odb *db, size_t size, git_otype type);
GIT_EXTERN(int) git_odb_open_wstream(git_odb_stream **out, git_odb *db, size_t size, git_otype type);
/**
* Open a stream to read an object from the ODB
......@@ -256,12 +257,12 @@ GIT_EXTERN(int) git_odb_open_wstream(git_odb_stream **stream, git_odb *db, size_
*
* @see git_odb_stream
*
* @param stream pointer where to store the stream
* @param out pointer where to store the stream
* @param db object database where the stream will read from
* @param oid oid of the object the stream will read from
* @return 0 if the stream was created; error code otherwise
*/
GIT_EXTERN(int) git_odb_open_rstream(git_odb_stream **stream, git_odb *db, const git_oid *oid);
GIT_EXTERN(int) git_odb_open_rstream(git_odb_stream **out, git_odb *db, const git_oid *oid);
/**
* Open a stream for writing a pack file to the ODB.
......@@ -274,14 +275,18 @@ GIT_EXTERN(int) git_odb_open_rstream(git_odb_stream **stream, git_odb *db, const
*
* @see git_odb_writepack
*
* @param writepack pointer to the writepack functions
* @param out pointer to the writepack functions
* @param db object database where the stream will read from
* @param progress_cb function to call with progress information.
* Be aware that this is called inline with network and indexing operations,
* so performance may be affected.
* @param progress_payload payload for the progress callback
*/
GIT_EXTERN(int) git_odb_write_pack(git_odb_writepack **writepack, git_odb *db, git_transfer_progress_callback progress_cb, void *progress_payload);
GIT_EXTERN(int) git_odb_write_pack(
git_odb_writepack **out,
git_odb *db,
git_transfer_progress_callback progress_cb,
void *progress_payload);
/**
* Determine the object-ID (sha1 hash) of a data buffer
......@@ -289,13 +294,13 @@ GIT_EXTERN(int) git_odb_write_pack(git_odb_writepack **writepack, git_odb *db, g
* The resulting SHA-1 OID will be the identifier for the data
* buffer as if the data buffer it were to written to the ODB.
*
* @param id the resulting object-ID.
* @param out the resulting object-ID.
* @param data data to hash
* @param len size of the data
* @param type of the data to hash
* @return 0 or an error code
*/
GIT_EXTERN(int) git_odb_hash(git_oid *id, const void *data, size_t len, git_otype type);
GIT_EXTERN(int) git_odb_hash(git_oid *out, const void *data, size_t len, git_otype type);
/**
* Read a file from disk and fill a git_oid with the object id
......
......@@ -24,7 +24,14 @@ GIT_BEGIN_DECL
struct git_odb_stream;
struct git_odb_writepack;
/** An instance for a custom backend */
/**
* Function type for callbacks from git_odb_foreach.
*/
typedef int (*git_odb_foreach_cb)(const git_oid *id, void *payload);
/**
* An instance for a custom backend
*/
struct git_odb_backend {
git_odb *odb;
......@@ -79,8 +86,8 @@ struct git_odb_backend {
int (* foreach)(
struct git_odb_backend *,
int (*cb)(git_oid *oid, void *data),
void *data);
git_odb_foreach_cb cb,
void *payload);
int (* writepack)(
struct git_odb_writepack **,
......@@ -101,7 +108,7 @@ enum {
/** A stream to read/write from a backend */
struct git_odb_stream {
struct git_odb_backend *backend;
int mode;
unsigned int mode;
int (*read)(struct git_odb_stream *stream, char *buffer, size_t len);
int (*write)(struct git_odb_stream *stream, const char *buffer, size_t len);
......@@ -118,12 +125,15 @@ struct git_odb_writepack {
void (*free)(struct git_odb_writepack *writepack);
};
GIT_EXTERN(int) git_odb_backend_pack(git_odb_backend **backend_out, const char *objects_dir);
GIT_EXTERN(int) git_odb_backend_loose(git_odb_backend **backend_out, const char *objects_dir, int compression_level, int do_fsync);
GIT_EXTERN(int) git_odb_backend_one_pack(git_odb_backend **backend_out, const char *index_file);
GIT_EXTERN(void *) git_odb_backend_malloc(git_odb_backend *backend, size_t len);
/**
* Constructors for in-box ODB backends.
*/
GIT_EXTERN(int) git_odb_backend_pack(git_odb_backend **out, const char *objects_dir);
GIT_EXTERN(int) git_odb_backend_loose(git_odb_backend **out, const char *objects_dir, int compression_level, int do_fsync);
GIT_EXTERN(int) git_odb_backend_one_pack(git_odb_backend **out, const char *index_file);
GIT_END_DECL
#endif
......@@ -30,11 +30,10 @@ GIT_BEGIN_DECL
#define GIT_OID_MINPREFIXLEN 4
/** Unique identity of any object (commit, tree, blob, tag). */
typedef struct _git_oid git_oid;
struct _git_oid {
typedef struct git_oid {
/** raw binary formatted id */
unsigned char id[GIT_OID_RAWSZ];
};
} git_oid;
/**
* Parse a hex formatted object id into a git_oid.
......@@ -71,14 +70,14 @@ GIT_EXTERN(void) git_oid_fromraw(git_oid *out, const unsigned char *raw);
/**
* Format a git_oid into a hex string.
*
* @param str output hex string; must be pointing at the start of
* @param out output hex string; must be pointing at the start of
* the hex sequence and have at least the number of bytes
* needed for an oid encoded in hex (40 bytes). Only the
* oid digits are written; a '\\0' terminator must be added
* by the caller if it is required.
* @param oid oid structure to format.
*/
GIT_EXTERN(void) git_oid_fmt(char *str, const git_oid *oid);
GIT_EXTERN(void) git_oid_fmt(char *out, const git_oid *id);
/**
* Format a git_oid into a loose-object path string.
......@@ -86,14 +85,14 @@ GIT_EXTERN(void) git_oid_fmt(char *str, const git_oid *oid);
* The resulting string is "aa/...", where "aa" is the first two
* hex digits of the oid and "..." is the remaining 38 digits.
*
* @param str output hex string; must be pointing at the start of
* @param out output hex string; must be pointing at the start of
* the hex sequence and have at least the number of bytes
* needed for an oid encoded in hex (41 bytes). Only the
* oid digits are written; a '\\0' terminator must be added
* by the caller if it is required.
* @param oid oid structure to format.
* @param id oid structure to format.
*/
GIT_EXTERN(void) git_oid_pathfmt(char *str, const git_oid *oid);
GIT_EXTERN(void) git_oid_pathfmt(char *out, const git_oid *id);
/**
* Format a git_oid into a newly allocated c-string.
......@@ -102,7 +101,7 @@ GIT_EXTERN(void) git_oid_pathfmt(char *str, const git_oid *oid);
* @return the c-string; NULL if memory is exhausted. Caller must
* deallocate the string with git__free().
*/
GIT_EXTERN(char *) git_oid_allocfmt(const git_oid *oid);
GIT_EXTERN(char *) git_oid_allocfmt(const git_oid *id);
/**
* Format a git_oid into a buffer as a hex format c-string.
......@@ -115,11 +114,11 @@ GIT_EXTERN(char *) git_oid_allocfmt(const git_oid *oid);
*
* @param out the buffer into which the oid string is output.
* @param n the size of the out buffer.
* @param oid the oid structure to format.
* @param id the oid structure to format.
* @return the out buffer pointer, assuming no input parameter
* errors, otherwise a pointer to an empty string.
*/
GIT_EXTERN(char *) git_oid_tostr(char *out, size_t n, const git_oid *oid);
GIT_EXTERN(char *) git_oid_tostr(char *out, size_t n, const git_oid *id);
/**
* Copy an oid from one structure to another.
......@@ -176,19 +175,19 @@ GIT_EXTERN(int) git_oid_ncmp(const git_oid *a, const git_oid *b, size_t len);
/**
* Check if an oid equals an hex formatted object id.
*
* @param a oid structure.
* @param id oid structure.
* @param str input hex string of an object id.
* @return GIT_ENOTOID if str is not a valid hex string,
* 0 in case of a match, GIT_ERROR otherwise.
*/
GIT_EXTERN(int) git_oid_streq(const git_oid *a, const char *str);
GIT_EXTERN(int) git_oid_streq(const git_oid *id, const char *str);
/**
* Check is an oid is all zeros.
*
* @return 1 if all zeros, 0 otherwise.
*/
GIT_EXTERN(int) git_oid_iszero(const git_oid *a);
GIT_EXTERN(int) git_oid_iszero(const git_oid *id);
/**
* OID Shortener object
......@@ -230,12 +229,12 @@ GIT_EXTERN(git_oid_shorten *) git_oid_shorten_new(size_t min_length);
* GIT_ENOMEM error
*
* @param os a `git_oid_shorten` instance
* @param text_oid an OID in text form
* @param text_id an OID in text form
* @return the minimal length to uniquely identify all OIDs
* added so far to the set; or an error code (<0) if an
* error occurs.
*/
GIT_EXTERN(int) git_oid_shorten_add(git_oid_shorten *os, const char *text_oid);
GIT_EXTERN(int) git_oid_shorten_add(git_oid_shorten *os, const char *text_id);
/**
* Free an OID shortener instance
......
......@@ -38,8 +38,9 @@ GIT_EXTERN(int) git_packbuilder_new(git_packbuilder **out, git_repository *repo)
*
* @param pb The packbuilder
* @param n Number of threads to spawn
* @return number of actual threads to be used
*/
GIT_EXTERN(void) git_packbuilder_set_threads(git_packbuilder *pb, unsigned int n);
GIT_EXTERN(unsigned int) git_packbuilder_set_threads(git_packbuilder *pb, unsigned int n);
/**
* Insert a single object
......@@ -48,12 +49,12 @@ GIT_EXTERN(void) git_packbuilder_set_threads(git_packbuilder *pb, unsigned int n
* commits followed by trees and blobs.
*
* @param pb The packbuilder
* @param oid The oid of the commit
* @param oid The name; might be NULL
* @param id The oid of the commit
* @param name The name; might be NULL
*
* @return 0 or an error code
*/
GIT_EXTERN(int) git_packbuilder_insert(git_packbuilder *pb, const git_oid *oid, const char *name);
GIT_EXTERN(int) git_packbuilder_insert(git_packbuilder *pb, const git_oid *id, const char *name);
/**
* Insert a root tree object
......@@ -61,11 +62,11 @@ GIT_EXTERN(int) git_packbuilder_insert(git_packbuilder *pb, const git_oid *oid,
* This will add the tree as well as all referenced trees and blobs.
*
* @param pb The packbuilder
* @param oid The oid of the root tree
* @param id The oid of the root tree
*
* @return 0 or an error code
*/
GIT_EXTERN(int) git_packbuilder_insert_tree(git_packbuilder *pb, const git_oid *oid);
GIT_EXTERN(int) git_packbuilder_insert_tree(git_packbuilder *pb, const git_oid *id);
/**
* Write the new pack and the corresponding index to path
......@@ -82,15 +83,17 @@ GIT_EXTERN(int) git_packbuilder_write(git_packbuilder *pb, const char *file);
*
* @param pb the packbuilder
* @param cb the callback to call with each packed object's buffer
* @param data the callback's data
* @param payload the callback's data
* @return 0 or an error code
*/
GIT_EXTERN(int) git_packbuilder_foreach(git_packbuilder *pb, int (*cb)(void *buf, size_t size, void *data), void *data);
typedef int (*git_packbuilder_foreach_cb)(void *buf, size_t size, void *payload);
GIT_EXTERN(int) git_packbuilder_foreach(git_packbuilder *pb, git_packbuilder_foreach_cb cb, void *payload);
/**
* Get the total number of objects the packbuilder will write out
*
* @param pb the packbuilder
* @return
*/
GIT_EXTERN(uint32_t) git_packbuilder_object_count(git_packbuilder *pb);
......@@ -98,6 +101,7 @@ GIT_EXTERN(uint32_t) git_packbuilder_object_count(git_packbuilder *pb);
* Get the number of objects the packbuilder has already written out
*
* @param pb the packbuilder
* @return
*/
GIT_EXTERN(uint32_t) git_packbuilder_written(git_packbuilder *pb);
......
......@@ -30,11 +30,11 @@ GIT_BEGIN_DECL
* The reflog must be freed manually by using
* git_reflog_free().
*
* @param reflog pointer to reflog
* @param out pointer to reflog
* @param ref reference to read the reflog for
* @return 0 or an error code
*/
GIT_EXTERN(int) git_reflog_read(git_reflog **reflog, git_reference *ref);
GIT_EXTERN(int) git_reflog_read(git_reflog **out, const git_reference *ref);
/**
* Write an existing in-memory reflog object back to disk
......@@ -51,12 +51,12 @@ GIT_EXTERN(int) git_reflog_write(git_reflog *reflog);
* `msg` is optional and can be NULL.
*
* @param reflog an existing reflog object
* @param new_oid the OID the reference is now pointing to
* @param id the OID the reference is now pointing to
* @param committer the signature of the committer
* @param msg the reflog message
* @return 0 or an error code
*/
GIT_EXTERN(int) git_reflog_append(git_reflog *reflog, const git_oid *new_oid, const git_signature *committer, const char *msg);
GIT_EXTERN(int) git_reflog_append(git_reflog *reflog, const git_oid *id, const git_signature *committer, const char *msg);
/**
* Rename the reflog for the given reference
......@@ -64,10 +64,10 @@ GIT_EXTERN(int) git_reflog_append(git_reflog *reflog, const git_oid *new_oid, co
* The reflog to be renamed is expected to already exist
*
* @param ref the reference
* @param new_name the new name of the reference
* @param name the new name of the reference
* @return 0 or an error code
*/
GIT_EXTERN(int) git_reflog_rename(git_reference *ref, const char *new_name);
GIT_EXTERN(int) git_reflog_rename(git_reference *ref, const char *name);
/**
* Delete the reflog for the given reference
......@@ -83,7 +83,7 @@ GIT_EXTERN(int) git_reflog_delete(git_reference *ref);
* @param reflog the previously loaded reflog
* @return the number of log entries
*/
GIT_EXTERN(unsigned int) git_reflog_entrycount(git_reflog *reflog);
GIT_EXTERN(size_t) git_reflog_entrycount(git_reflog *reflog);
/**
* Lookup an entry by its index
......@@ -126,7 +126,7 @@ GIT_EXTERN(int) git_reflog_drop(
* @param entry a reflog entry
* @return the old oid
*/
GIT_EXTERN(const git_oid *) git_reflog_entry_oidold(const git_reflog_entry *entry);
GIT_EXTERN(const git_oid *) git_reflog_entry_id_old(const git_reflog_entry *entry);
/**
* Get the new oid
......@@ -134,7 +134,7 @@ GIT_EXTERN(const git_oid *) git_reflog_entry_oidold(const git_reflog_entry *entr
* @param entry a reflog entry
* @return the new oid at this time
*/
GIT_EXTERN(const git_oid *) git_reflog_entry_oidnew(const git_reflog_entry *entry);
GIT_EXTERN(const git_oid *) git_reflog_entry_id_new(const git_reflog_entry *entry);
/**
* Get the committer of this entry
......@@ -142,15 +142,15 @@ GIT_EXTERN(const git_oid *) git_reflog_entry_oidnew(const git_reflog_entry *entr
* @param entry a reflog entry
* @return the committer
*/
GIT_EXTERN(git_signature *) git_reflog_entry_committer(const git_reflog_entry *entry);
GIT_EXTERN(const git_signature *) git_reflog_entry_committer(const git_reflog_entry *entry);
/**
* Get the log msg
* Get the log message
*
* @param entry a reflog entry
* @return the log msg
*/
GIT_EXTERN(char *) git_reflog_entry_msg(const git_reflog_entry *entry);
GIT_EXTERN(const char *) git_reflog_entry_message(const git_reflog_entry *entry);
/**
* Free the reflog
......
......@@ -29,12 +29,12 @@ GIT_BEGIN_DECL
* See `git_reference_create_symbolic()` for documentation about valid
* reference names.
*
* @param reference_out pointer to the looked-up reference
* @param out pointer to the looked-up reference
* @param repo the repository to look up the reference
* @param name the long name for the reference (e.g. HEAD, refs/heads/master, refs/tags/v0.1.0, ...)
* @return 0 or an error code
* @return 0 or an error code (ENOTFOUND, EINVALIDSPEC)
*/
GIT_EXTERN(int) git_reference_lookup(git_reference **reference_out, git_repository *repo, const char *name);
GIT_EXTERN(int) git_reference_lookup(git_reference **out, git_repository *repo, const char *name);
/**
* Lookup a reference by name and resolve immediately to OID.
......@@ -43,12 +43,13 @@ GIT_EXTERN(int) git_reference_lookup(git_reference **reference_out, git_reposito
* through to the object id that it refers to. This avoids having to
* allocate or free any `git_reference` objects for simple situations.
*
* @param oid Pointer to oid to be filled in
* @param out 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
* @return 0 on success, -1 if name could not be resolved (EINVALIDSPEC,
* ENOTFOUND, etc)
*/
GIT_EXTERN(int) git_reference_name_to_oid(
GIT_EXTERN(int) git_reference_name_to_id(
git_oid *out, git_repository *repo, const char *name);
/**
......@@ -73,14 +74,14 @@ GIT_EXTERN(int) git_reference_name_to_oid(
* This function will return an error if a reference already exists with the
* given name unless `force` is true, in which case it will be overwritten.
*
* @param ref_out Pointer to the newly created reference
* @param out Pointer to the newly created reference
* @param repo Repository where that reference will live
* @param name The name of the reference
* @param target The target of the reference
* @param force Overwrite existing references
* @return 0 or an error code
* @return 0 or an error code (EEXISTS, EINVALIDSPEC)
*/
GIT_EXTERN(int) git_reference_create_symbolic(git_reference **ref_out, git_repository *repo, const char *name, const char *target, int force);
GIT_EXTERN(int) git_reference_symbolic_create(git_reference **out, git_repository *repo, const char *name, const char *target, int force);
/**
* Create a new direct reference.
......@@ -105,14 +106,14 @@ GIT_EXTERN(int) git_reference_create_symbolic(git_reference **ref_out, git_repos
* This function will return an error if a reference already exists with the
* given name unless `force` is true, in which case it will be overwritten.
*
* @param ref_out Pointer to the newly created reference
* @param out Pointer to the newly created reference
* @param repo Repository where that reference will live
* @param name The name of the reference
* @param id The object id pointed to by the reference.
* @param force Overwrite existing references
* @return 0 or an error code
* @return 0 or an error code (EINVALIDSPEC, EEXISTS)
*/
GIT_EXTERN(int) git_reference_create_oid(git_reference **ref_out, git_repository *repo, const char *name, const git_oid *id, int force);
GIT_EXTERN(int) git_reference_create(git_reference **out, git_repository *repo, const char *name, const git_oid *id, int force);
/**
* Get the OID pointed to by a direct reference.
......@@ -127,7 +128,7 @@ GIT_EXTERN(int) git_reference_create_oid(git_reference **ref_out, git_repository
* @param ref The reference
* @return a pointer to the oid if available, NULL otherwise
*/
GIT_EXTERN(const git_oid *) git_reference_oid(git_reference *ref);
GIT_EXTERN(const git_oid *) git_reference_target(const git_reference *ref);
/**
* Get full name to the reference pointed to by a symbolic reference.
......@@ -137,7 +138,7 @@ GIT_EXTERN(const git_oid *) git_reference_oid(git_reference *ref);
* @param ref The reference
* @return a pointer to the name if available, NULL otherwise
*/
GIT_EXTERN(const char *) git_reference_target(git_reference *ref);
GIT_EXTERN(const char *) git_reference_symbolic_target(const git_reference *ref);
/**
* Get the type of a reference.
......@@ -147,7 +148,7 @@ GIT_EXTERN(const char *) git_reference_target(git_reference *ref);
* @param ref The reference
* @return the type
*/
GIT_EXTERN(git_ref_t) git_reference_type(git_reference *ref);
GIT_EXTERN(git_ref_t) git_reference_type(const git_reference *ref);
/**
* Get the full name of a reference.
......@@ -157,7 +158,7 @@ GIT_EXTERN(git_ref_t) git_reference_type(git_reference *ref);
* @param ref The reference
* @return the full name for the ref
*/
GIT_EXTERN(const char *) git_reference_name(git_reference *ref);
GIT_EXTERN(const char *) git_reference_name(const git_reference *ref);
/**
* Resolve a symbolic reference to a direct reference.
......@@ -175,7 +176,7 @@ GIT_EXTERN(const char *) git_reference_name(git_reference *ref);
* @param ref The reference
* @return 0 or an error code
*/
GIT_EXTERN(int) git_reference_resolve(git_reference **resolved_ref, git_reference *ref);
GIT_EXTERN(int) git_reference_resolve(git_reference **out, const git_reference *ref);
/**
* Get the repository where a reference resides.
......@@ -183,7 +184,7 @@ GIT_EXTERN(int) git_reference_resolve(git_reference **resolved_ref, git_referenc
* @param ref The reference
* @return a pointer to the repo
*/
GIT_EXTERN(git_repository *) git_reference_owner(git_reference *ref);
GIT_EXTERN(git_repository *) git_reference_owner(const git_reference *ref);
/**
* Set the symbolic target of a reference.
......@@ -194,9 +195,9 @@ GIT_EXTERN(git_repository *) git_reference_owner(git_reference *ref);
*
* @param ref The reference
* @param target The new target for the reference
* @return 0 or an error code
* @return 0 or an error code (EINVALIDSPEC)
*/
GIT_EXTERN(int) git_reference_set_target(git_reference *ref, const char *target);
GIT_EXTERN(int) git_reference_symbolic_set_target(git_reference *ref, const char *target);
/**
* Set the OID target of a reference.
......@@ -209,7 +210,7 @@ GIT_EXTERN(int) git_reference_set_target(git_reference *ref, const char *target)
* @param id The new target OID for the reference
* @return 0 or an error code
*/
GIT_EXTERN(int) git_reference_set_oid(git_reference *ref, const git_oid *id);
GIT_EXTERN(int) git_reference_set_target(git_reference *ref, const git_oid *id);
/**
* Rename an existing reference.
......@@ -231,12 +232,12 @@ GIT_EXTERN(int) git_reference_set_oid(git_reference *ref, const git_oid *id);
* the reflog if it exists.
*
* @param ref The reference to rename
* @param new_name The new name for the reference
* @param name The new name for the reference
* @param force Overwrite an existing reference
* @return 0 or an error code
* @return 0 or an error code (EINVALIDSPEC, EEXISTS)
*
*/
GIT_EXTERN(int) git_reference_rename(git_reference *ref, const char *new_name, int force);
GIT_EXTERN(int) git_reference_rename(git_reference *ref, const char *name, int force);
/**
* Delete an existing reference.
......@@ -287,6 +288,8 @@ GIT_EXTERN(int) git_reference_packall(git_repository *repo);
*/
GIT_EXTERN(int) git_reference_list(git_strarray *array, git_repository *repo, unsigned int list_flags);
typedef int (*git_reference_foreach_cb)(const char *refname, void *payload);
/**
* Perform a callback on each reference in the repository.
*
......@@ -307,7 +310,11 @@ GIT_EXTERN(int) git_reference_list(git_strarray *array, git_repository *repo, un
* @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, int (*callback)(const char *, void *), void *payload);
GIT_EXTERN(int) git_reference_foreach(
git_repository *repo,
unsigned int list_flags,
git_reference_foreach_cb callback,
void *payload);
/**
* Check if a reference has been loaded from a packfile.
......
......@@ -24,6 +24,7 @@
*/
GIT_BEGIN_DECL
typedef int (*git_remote_rename_problem_cb)(const char *problematic_refspec, void *payload);
/*
* TODO: This functions still need to be implemented:
* - _listcb/_foreach
......@@ -71,7 +72,7 @@ GIT_EXTERN(int) git_remote_save(const git_remote *remote);
* @param remote the remote
* @return a pointer to the name
*/
GIT_EXTERN(const char *) git_remote_name(git_remote *remote);
GIT_EXTERN(const char *) git_remote_name(const git_remote *remote);
/**
* Get the remote's url
......@@ -79,7 +80,7 @@ GIT_EXTERN(const char *) git_remote_name(git_remote *remote);
* @param remote the remote
* @return a pointer to the url
*/
GIT_EXTERN(const char *) git_remote_url(git_remote *remote);
GIT_EXTERN(const char *) git_remote_url(const git_remote *remote);
/**
* Get the remote's url for pushing
......@@ -87,7 +88,7 @@ GIT_EXTERN(const char *) git_remote_url(git_remote *remote);
* @param remote the remote
* @return a pointer to the url or NULL if no special url for pushing is set
*/
GIT_EXTERN(const char *) git_remote_pushurl(git_remote *remote);
GIT_EXTERN(const char *) git_remote_pushurl(const git_remote *remote);
/**
* Set the remote's url
......@@ -126,7 +127,7 @@ GIT_EXTERN(int) git_remote_set_fetchspec(git_remote *remote, const char *spec);
* @param remote the remote
* @return a pointer to the fetch refspec or NULL if it doesn't exist
*/
GIT_EXTERN(const git_refspec *) git_remote_fetchspec(git_remote *remote);
GIT_EXTERN(const git_refspec *) git_remote_fetchspec(const git_remote *remote);
/**
* Set the remote's push refspec
......@@ -144,7 +145,7 @@ GIT_EXTERN(int) git_remote_set_pushspec(git_remote *remote, const char *spec);
* @return a pointer to the push refspec or NULL if it doesn't exist
*/
GIT_EXTERN(const git_refspec *) git_remote_pushspec(git_remote *remote);
GIT_EXTERN(const git_refspec *) git_remote_pushspec(const git_remote *remote);
/**
* Open a connection to a remote
......@@ -157,7 +158,7 @@ GIT_EXTERN(const git_refspec *) git_remote_pushspec(git_remote *remote);
* @param direction whether you want to receive or send data
* @return 0 or an error code
*/
GIT_EXTERN(int) git_remote_connect(git_remote *remote, int direction);
GIT_EXTERN(int) git_remote_connect(git_remote *remote, git_direction direction);
/**
* Get a list of refs at the remote
......@@ -194,7 +195,7 @@ GIT_EXTERN(int) git_remote_ls(git_remote *remote, git_headlist_cb list_cb, void
GIT_EXTERN(int) git_remote_download(
git_remote *remote,
git_transfer_progress_callback progress_cb,
void *progress_payload);
void *payload);
/**
* Check whether the remote is connected
......@@ -266,11 +267,11 @@ GIT_EXTERN(int) git_remote_supported_url(const char* url);
*
* The string array must be freed by the user.
*
* @param remotes_list a string array with the names of the remotes
* @param out a string array which receives the names of the remotes
* @param repo the repository to query
* @return 0 or an error code
*/
GIT_EXTERN(int) git_remote_list(git_strarray *remotes_list, git_repository *repo);
GIT_EXTERN(int) git_remote_list(git_strarray *out, git_repository *repo);
/**
* Add a remote with the default fetch refspec to the repository's configuration
......@@ -340,7 +341,7 @@ struct git_remote_callbacks {
void (*progress)(const char *str, int len, void *data);
int (*completion)(git_remote_completion_type type, void *data);
int (*update_tips)(const char *refname, const git_oid *a, const git_oid *b, void *data);
void *data;
void *payload;
};
/**
......@@ -359,12 +360,12 @@ GIT_EXTERN(void) git_remote_set_callbacks(git_remote *remote, git_remote_callbac
*/
GIT_EXTERN(const git_transfer_progress *) git_remote_stats(git_remote *remote);
enum {
typedef enum {
GIT_REMOTE_DOWNLOAD_TAGS_UNSET,
GIT_REMOTE_DOWNLOAD_TAGS_NONE,
GIT_REMOTE_DOWNLOAD_TAGS_AUTO,
GIT_REMOTE_DOWNLOAD_TAGS_ALL
};
} git_remote_autotag_option_t;
/**
* Retrieve the tag auto-follow setting
......@@ -372,7 +373,7 @@ enum {
* @param remote the remote to query
* @return the auto-follow setting
*/
GIT_EXTERN(int) git_remote_autotag(git_remote *remote);
GIT_EXTERN(git_remote_autotag_option_t) git_remote_autotag(git_remote *remote);
/**
* Set the tag auto-follow setting
......@@ -380,7 +381,9 @@ GIT_EXTERN(int) git_remote_autotag(git_remote *remote);
* @param remote the remote to configure
* @param value a GIT_REMOTE_DOWNLOAD_TAGS value
*/
GIT_EXTERN(void) git_remote_set_autotag(git_remote *remote, int value);
GIT_EXTERN(void) git_remote_set_autotag(
git_remote *remote,
git_remote_autotag_option_t value);
/**
* Give the remote a new name
......@@ -398,7 +401,7 @@ GIT_EXTERN(void) git_remote_set_autotag(git_remote *remote, int value);
GIT_EXTERN(int) git_remote_rename(
git_remote *remote,
const char *new_name,
int (*callback)(const char *problematic_refspec, void *payload),
git_remote_rename_problem_cb callback,
void *payload);
/**
......
......@@ -29,11 +29,11 @@ GIT_BEGIN_DECL
* The method will automatically detect if 'path' is a normal
* or bare repository or fail is 'path' is neither.
*
* @param repository pointer to the repo which will be opened
* @param out pointer to the repo which will be opened
* @param path the path to the repository
* @return 0 or an error code
*/
GIT_EXTERN(int) git_repository_open(git_repository **repository, const char *path);
GIT_EXTERN(int) git_repository_open(git_repository **out, const char *path);
/**
* Create a "fake" repository to wrap an object database
......@@ -42,11 +42,11 @@ GIT_EXTERN(int) git_repository_open(git_repository **repository, const char *pat
* with the API when all you have is an object database. This doesn't
* have any paths associated with it, so use with care.
*
* @param repository pointer to the repo
* @param out pointer to the repo
* @param odb the object database to wrap
* @return 0 or an error code
*/
GIT_EXTERN(int) git_repository_wrap_odb(git_repository **repository, git_odb *odb);
GIT_EXTERN(int) git_repository_wrap_odb(git_repository **out, git_odb *odb);
/**
* Look for a git repository and copy its path in the given buffer.
......@@ -58,10 +58,10 @@ GIT_EXTERN(int) git_repository_wrap_odb(git_repository **repository, git_odb *od
* The method will automatically detect if the repository is bare
* (if there is a repository).
*
* @param repository_path The user allocated buffer which will
* @param path_out The user allocated buffer which will
* contain the found path.
*
* @param size repository_path size
* @param path_size repository_path size
*
* @param start_path The base path where the lookup starts.
*
......@@ -77,8 +77,8 @@ GIT_EXTERN(int) git_repository_wrap_odb(git_repository **repository, git_odb *od
* @return 0 or an error code
*/
GIT_EXTERN(int) git_repository_discover(
char *repository_path,
size_t size,
char *path_out,
size_t path_size,
const char *start_path,
int across_fs,
const char *ceiling_dirs);
......@@ -95,18 +95,18 @@ GIT_EXTERN(int) git_repository_discover(
* directory "/home/user/source/" will not return "/.git/" as the found
* repo if "/" is a different filesystem than "/home".)
*/
enum {
typedef enum {
GIT_REPOSITORY_OPEN_NO_SEARCH = (1 << 0),
GIT_REPOSITORY_OPEN_CROSS_FS = (1 << 1),
};
} git_repository_open_flag_t;
/**
* Find and open a repository with extended controls.
*
* @param repo_out Pointer to the repo which will be opened. This can
* @param out Pointer to the repo which will be opened. This can
* actually be NULL if you only want to use the error code to
* see if a repo at this path could be opened.
* @param start_path Path to open as git repository. If the flags
* @param path Path to open as git repository. If the flags
* permit "searching", then this can be a path to a subdirectory
* inside the working directory of the repository.
* @param flags A combination of the GIT_REPOSITORY_OPEN flags above.
......@@ -118,9 +118,9 @@ enum {
* (such as repo corruption or system errors).
*/
GIT_EXTERN(int) git_repository_open_ext(
git_repository **repo,
const char *start_path,
uint32_t flags,
git_repository **out,
const char *path,
unsigned int flags,
const char *ceiling_dirs);
/**
......@@ -142,7 +142,7 @@ GIT_EXTERN(void) git_repository_free(git_repository *repo);
* TODO:
* - Reinit the repository
*
* @param repo_out pointer to the repo which will be created or reinitialized
* @param out pointer to the repo which will be created or reinitialized
* @param path the path to the repository
* @param is_bare if true, a Git repository without a working directory is
* created at the pointed path. If false, provided path will be
......@@ -152,7 +152,7 @@ GIT_EXTERN(void) git_repository_free(git_repository *repo);
* @return 0 or an error code
*/
GIT_EXTERN(int) git_repository_init(
git_repository **repo_out,
git_repository **out,
const char *path,
unsigned is_bare);
......@@ -182,14 +182,14 @@ GIT_EXTERN(int) git_repository_init(
* `init.templatedir` global config if not, or falling back on
* "/usr/share/git-core/templates" if it exists.
*/
enum {
typedef enum {
GIT_REPOSITORY_INIT_BARE = (1u << 0),
GIT_REPOSITORY_INIT_NO_REINIT = (1u << 1),
GIT_REPOSITORY_INIT_NO_DOTGIT_DIR = (1u << 2),
GIT_REPOSITORY_INIT_MKDIR = (1u << 3),
GIT_REPOSITORY_INIT_MKPATH = (1u << 4),
GIT_REPOSITORY_INIT_EXTERNAL_TEMPLATE = (1u << 5),
};
} git_repository_init_flag_t;
/**
* Mode options for `git_repository_init_ext`.
......@@ -204,11 +204,11 @@ enum {
* * SHARED_ALL - Use "--shared=all" behavior, adding world readability.
* * Anything else - Set to custom value.
*/
enum {
typedef enum {
GIT_REPOSITORY_INIT_SHARED_UMASK = 0,
GIT_REPOSITORY_INIT_SHARED_GROUP = 0002775,
GIT_REPOSITORY_INIT_SHARED_ALL = 0002777,
};
} git_repository_init_mode_t;
/**
* Extended options structure for `git_repository_init_ext`.
......@@ -256,26 +256,30 @@ typedef struct {
* auto-detect the case sensitivity of the file system and if the
* file system supports file mode bits correctly.
*
* @param repo_out Pointer to the repo which will be created or reinitialized.
* @param out Pointer to the repo which will be created or reinitialized.
* @param repo_path The path to the repository.
* @param opts Pointer to git_repository_init_options struct.
* @return 0 or an error code on failure.
*/
GIT_EXTERN(int) git_repository_init_ext(
git_repository **repo_out,
git_repository **out,
const char *repo_path,
git_repository_init_options *opts);
/**
* Retrieve and resolve the reference pointed at by HEAD.
*
* @param head_out pointer to the reference which will be retrieved
* The returned `git_reference` will be owned by caller and
* `git_reference_free()` must be called when done with it to release the
* allocated memory and prevent a leak.
*
* @param out pointer to the reference which will be retrieved
* @param repo a repository object
*
* @return 0 on success, GIT_EORPHANEDHEAD when HEAD points to a non existing
* branch, GIT_ENOTFOUND when HEAD is missing; an error code otherwise
*/
GIT_EXTERN(int) git_repository_head(git_reference **head_out, git_repository *repo);
GIT_EXTERN(int) git_repository_head(git_reference **out, git_repository *repo);
/**
* Check if a repository's HEAD is detached
......@@ -468,12 +472,12 @@ GIT_EXTERN(void) git_repository_set_index(git_repository *repo, git_index *index
* Use this function to get the contents of this file. Don't forget to
* remove the file after you create the commit.
*
* @param buffer Buffer to write data into or NULL to just read required size
* @param out Buffer to write data into or NULL to just read required size
* @param len Length of 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
*/
GIT_EXTERN(int) git_repository_message(char *buffer, size_t len, git_repository *repo);
GIT_EXTERN(int) git_repository_message(char *out, size_t len, git_repository *repo);
/**
* Remove git's prepared message.
......
......@@ -16,16 +16,26 @@
GIT_BEGIN_DECL
/**
* Kinds of reset operation
*/
typedef enum {
GIT_RESET_SOFT = 1, /** Move the head to the given commit */
GIT_RESET_MIXED = 2, /** SOFT plus reset index to the commit */
GIT_RESET_HARD = 3, /** MIXED plus changes in working tree discarded */
} git_reset_t;
/**
* Sets the current head to the specified commit oid and optionally
* resets the index and working tree to match.
*
* When specifying a Soft kind of reset, the head will be moved to the commit.
* SOFT reset means the head will be moved to the commit.
*
* Specifying a Mixed kind of reset will trigger a Soft reset and the index will
* be replaced with the content of the commit tree.
* MIXED reset will trigger a SOFT reset, plus the index will be replaced
* with the content of the commit tree.
*
* Specifying a Hard kind of reset will trigger a Mixed reset and the working
* directory will be replaced with the content of the index.
* HARD reset will trigger a MIXED reset and the working directory will be
* replaced with the content of the index. (Untracked and ignored files
* will be left alone, however.)
*
* TODO: Implement remaining kinds of resets.
*
......@@ -38,9 +48,10 @@ GIT_BEGIN_DECL
*
* @param reset_type Kind of reset operation to perform.
*
* @return GIT_SUCCESS or an error code
* @return 0 on success or an error code < 0
*/
GIT_EXTERN(int) git_reset(git_repository *repo, git_object *target, git_reset_type reset_type);
GIT_EXTERN(int) git_reset(
git_repository *repo, git_object *target, git_reset_t reset_type);
/** @} */
GIT_END_DECL
......
......@@ -63,11 +63,11 @@ GIT_BEGIN_DECL
* it is possible to have several revision walkers in
* several different threads walking the same repository.
*
* @param walker pointer to the new revision walker
* @param out pointer to the new revision walker
* @param repo the repo to walk through
* @return 0 or an error code
*/
GIT_EXTERN(int) git_revwalk_new(git_revwalk **walker, git_repository *repo);
GIT_EXTERN(int) git_revwalk_new(git_revwalk **out, git_repository *repo);
/**
* Reset the revision walker for reuse.
......@@ -96,10 +96,10 @@ GIT_EXTERN(void) git_revwalk_reset(git_revwalk *walker);
* be started.
*
* @param walk the walker being used for the traversal.
* @param oid the oid of the commit to start from.
* @param id the oid of the commit to start from.
* @return 0 or an error code
*/
GIT_EXTERN(int) git_revwalk_push(git_revwalk *walk, const git_oid *oid);
GIT_EXTERN(int) git_revwalk_push(git_revwalk *walk, const git_oid *id);
/**
* Push matching references
......@@ -134,10 +134,10 @@ GIT_EXTERN(int) git_revwalk_push_head(git_revwalk *walk);
* output on the revision walk.
*
* @param walk the walker being used for the traversal.
* @param oid the oid of commit that will be ignored during the traversal
* @param commit_id the oid of commit that will be ignored during the traversal
* @return 0 or an error code
*/
GIT_EXTERN(int) git_revwalk_hide(git_revwalk *walk, const git_oid *oid);
GIT_EXTERN(int) git_revwalk_hide(git_revwalk *walk, const git_oid *commit_id);
/**
* Hide matching references.
......@@ -198,12 +198,12 @@ GIT_EXTERN(int) git_revwalk_hide_ref(git_revwalk *walk, const char *refname);
*
* The revision walker is reset when the walk is over.
*
* @param oid Pointer where to store the oid of the next commit
* @param out Pointer where to store the oid of the next commit
* @param walk the walker to pop the commit from.
* @return 0 if the next commit was found;
* GIT_ITEROVER if there are no commits left to iterate
*/
GIT_EXTERN(int) git_revwalk_next(git_oid *oid, git_revwalk *walk);
GIT_EXTERN(int) git_revwalk_next(git_oid *out, git_revwalk *walk);
/**
* Change the sorting mode when iterating through the
......
......@@ -20,44 +20,52 @@
GIT_BEGIN_DECL
/**
* Create a new action signature. The signature must be freed
* manually or using git_signature_free
* Create a new action signature.
*
* Call `git_signature_free()` to free the data.
*
* Note: angle brackets ('<' and '>') characters are not allowed
* to be used in either the `name` or the `email` parameter.
*
* @param sig_out new signature, in case of error NULL
* @param out new signature, in case of error NULL
* @param name name of the person
* @param email email of the person
* @param time time when the action happened
* @param offset timezone offset in minutes for the time
* @return 0 or an error code
*/
GIT_EXTERN(int) git_signature_new(git_signature **sig_out, const char *name, const char *email, git_time_t time, int offset);
GIT_EXTERN(int) git_signature_new(git_signature **out, const char *name, const char *email, git_time_t time, int offset);
/**
* Create a new action signature with a timestamp of 'now'. The
* signature must be freed manually or using git_signature_free
* Create a new action signature with a timestamp of 'now'.
*
* Call `git_signature_free()` to free the data.
*
* @param sig_out new signature, in case of error NULL
* @param out new signature, in case of error NULL
* @param name name of the person
* @param email email of the person
* @return 0 or an error code
*/
GIT_EXTERN(int) git_signature_now(git_signature **sig_out, const char *name, const char *email);
GIT_EXTERN(int) git_signature_now(git_signature **out, const char *name, const char *email);
/**
* Create a copy of an existing signature.
* Create a copy of an existing signature. All internal strings are also
* duplicated.
*
* Call `git_signature_free()` to free the data.
*
* All internal strings are also duplicated.
* @param sig signature to duplicated
* @return a copy of sig, NULL on out of memory
*/
GIT_EXTERN(git_signature *) git_signature_dup(const git_signature *sig);
/**
* Free an existing signature
* Free an existing signature.
*
* Because the signature is not an opaque structure, it is legal to free it
* manually, but be sure to free the "name" and "email" strings in addition
* to the structure itself.
*
* @param sig signature to free
*/
......
......@@ -18,7 +18,7 @@
*/
GIT_BEGIN_DECL
enum {
typedef enum {
GIT_STASH_DEFAULT = 0,
/* All changes already added to the index
......@@ -35,7 +35,7 @@ enum {
* cleaned up from the working directory
*/
GIT_STASH_INCLUDE_IGNORED = (1 << 2),
};
} git_stash_flags;
/**
* Save the local modifications to a new stash.
......@@ -49,18 +49,17 @@ enum {
*
* @param message Optional description along with the stashed state.
*
* @param flags Flags to control the stashing process.
* @param flags Flags to control the stashing process. (see GIT_STASH_* above)
*
* @return 0 on success, GIT_ENOTFOUND where there's nothing to stash,
* or error code.
*/
GIT_EXTERN(int) git_stash_save(
git_oid *out,
git_repository *repo,
git_signature *stasher,
const char *message,
uint32_t flags);
unsigned int flags);
/**
* When iterating over all the stashed states, callback that will be
......@@ -71,16 +70,16 @@ GIT_EXTERN(int) git_stash_save(
*
* @param message The stash message.
*
* @param stash_oid The commit oid of the stashed state.
* @param stash_id The commit oid of the stashed state.
*
* @param payload Extra parameter to callback function.
*
* @return 0 on success, GIT_EUSER on non-zero callback, or error code
*/
typedef int (*stash_cb)(
typedef int (*git_stash_cb)(
size_t index,
const char* message,
const git_oid *stash_oid,
const git_oid *stash_id,
void *payload);
/**
......@@ -99,7 +98,7 @@ typedef int (*stash_cb)(
*/
GIT_EXTERN(int) git_stash_foreach(
git_repository *repo,
stash_cb callback,
git_stash_cb callback,
void *payload);
/**
......
......@@ -47,6 +47,18 @@ typedef enum {
} git_status_t;
/**
* Function pointer to receive status on individual files
*
* `path` is the relative path to the file from the root of the repository.
*
* `status_flags` is a combination of `git_status_t` values that apply.
*
* `payload` is the value you passed to the foreach function as payload.
*/
typedef int (*git_status_cb)(
const char *path, unsigned int status_flags, void *payload);
/**
* Gather file statuses and run a callback for each one.
*
* The callback is passed the path of the file, the status (a combination of
......@@ -63,7 +75,7 @@ typedef enum {
*/
GIT_EXTERN(int) git_status_foreach(
git_repository *repo,
int (*callback)(const char *, unsigned int, void *),
git_status_cb callback,
void *payload);
/**
......@@ -146,9 +158,10 @@ typedef enum {
* `GIT_STATUS_OPT_DISABLE_PATHSPEC_MATCH` is specified in the flags.
*/
typedef struct {
unsigned int version;
git_status_show_t show;
unsigned int flags;
git_strarray pathspec;
unsigned int flags;
git_strarray pathspec;
} git_status_options;
/**
......@@ -168,7 +181,7 @@ typedef struct {
GIT_EXTERN(int) git_status_foreach_ext(
git_repository *repo,
const git_status_options *opts,
int (*callback)(const char *, unsigned int, void *),
git_status_cb callback,
void *payload);
/**
......
......@@ -28,21 +28,28 @@ struct _git_strarray {
/**
* Close a string array object
*
* This method must always be called once a git_strarray is no
* longer needed, otherwise memory will leak.
* This method should be called on `git_strarray` objects where the strings
* array is allocated and contains allocated strings, such as what you
* would get from `git_strarray_copy()`. Not doing so, will result in a
* memory leak.
*
* @param array array to close
* This does not free the `git_strarray` itself, since the library will
* never allocate that object directly itself (it is more commonly embedded
* inside another struct or created on the stack).
*
* @param array git_strarray from which to free string data
*/
GIT_EXTERN(void) git_strarray_free(git_strarray *array);
/**
* Copy a string array object from source to target.
*
* Note: target is overwritten and hence should be empty,
*
* Note: target is overwritten and hence should be empty,
* otherwise its contents are leaked.
*
* @param tgt target
* @param src source
* @return 0 on success, < 0 on allocation failure
*/
GIT_EXTERN(int) git_strarray_copy(git_strarray *tgt, const git_strarray *src);
......@@ -51,4 +58,4 @@ GIT_EXTERN(int) git_strarray_copy(git_strarray *tgt, const git_strarray *src);
GIT_END_DECL
#endif
......@@ -318,7 +318,7 @@ GIT_EXTERN(int) git_submodule_set_url(git_submodule *submodule, const char *url)
* @param submodule Pointer to submodule object
* @return Pointer to git_oid or NULL if submodule is not in index.
*/
GIT_EXTERN(const git_oid *) git_submodule_index_oid(git_submodule *submodule);
GIT_EXTERN(const git_oid *) git_submodule_index_id(git_submodule *submodule);
/**
* Get the OID for the submodule in the current HEAD tree.
......@@ -326,7 +326,7 @@ GIT_EXTERN(const git_oid *) git_submodule_index_oid(git_submodule *submodule);
* @param submodule Pointer to submodule object
* @return Pointer to git_oid or NULL if submodule is not in the HEAD.
*/
GIT_EXTERN(const git_oid *) git_submodule_head_oid(git_submodule *submodule);
GIT_EXTERN(const git_oid *) git_submodule_head_id(git_submodule *submodule);
/**
* Get the OID for the submodule in the current working directory.
......@@ -339,7 +339,7 @@ GIT_EXTERN(const git_oid *) git_submodule_head_oid(git_submodule *submodule);
* @param submodule Pointer to submodule object
* @return Pointer to git_oid or NULL if submodule is not checked out.
*/
GIT_EXTERN(const git_oid *) git_submodule_wd_oid(git_submodule *submodule);
GIT_EXTERN(const git_oid *) git_submodule_wd_id(git_submodule *submodule);
/**
* Get the ignore rule for the submodule.
......
......@@ -25,14 +25,16 @@ GIT_BEGIN_DECL
/**
* Lookup a tag object from the repository.
*
* @param tag pointer to the looked up tag
* @param out pointer to the looked up tag
* @param repo the repo to use when locating the tag.
* @param id identity of the tag to locate.
* @return 0 or an error code
*/
GIT_INLINE(int) git_tag_lookup(git_tag **tag, git_repository *repo, const git_oid *id)
GIT_INLINE(int) git_tag_lookup(
git_tag **out, git_repository *repo, const git_oid *id)
{
return git_object_lookup((git_object **)tag, repo, id, (git_otype)GIT_OBJ_TAG);
return git_object_lookup(
(git_object **)out, repo, id, (git_otype)GIT_OBJ_TAG);
}
/**
......@@ -41,32 +43,33 @@ GIT_INLINE(int) git_tag_lookup(git_tag **tag, git_repository *repo, const git_oi
*
* @see git_object_lookup_prefix
*
* @param tag pointer to the looked up tag
* @param out pointer to the looked up tag
* @param repo the repo to use when locating the tag.
* @param id identity of the tag to locate.
* @param len the length of the short identifier
* @return 0 or an error code
*/
GIT_INLINE(int) git_tag_lookup_prefix(git_tag **tag, git_repository *repo, const git_oid *id, size_t len)
GIT_INLINE(int) git_tag_lookup_prefix(
git_tag **out, git_repository *repo, const git_oid *id, size_t len)
{
return git_object_lookup_prefix((git_object **)tag, repo, id, len, (git_otype)GIT_OBJ_TAG);
return git_object_lookup_prefix(
(git_object **)out, repo, id, len, (git_otype)GIT_OBJ_TAG);
}
/**
* Close an open tag
*
* This is a wrapper around git_object_free()
* You can no longer use the git_tag pointer after this call.
*
* IMPORTANT:
* It *is* necessary to call this method when you stop
* using a tag. Failure to do so will cause a memory leak.
* IMPORTANT: You MUST call this method when you are through with a tag to
* release memory. Failure to do so will cause a memory leak.
*
* @param tag the tag to close
*/
GIT_INLINE(void) git_tag_free(git_tag *tag)
{
git_object_free((git_object *) tag);
git_object_free((git_object *)tag);
}
......@@ -76,7 +79,7 @@ GIT_INLINE(void) git_tag_free(git_tag *tag)
* @param tag a previously loaded tag.
* @return object identity for the tag.
*/
GIT_EXTERN(const git_oid *) git_tag_id(git_tag *tag);
GIT_EXTERN(const git_oid *) git_tag_id(const git_tag *tag);
/**
* Get the tagged object of a tag
......@@ -84,11 +87,11 @@ GIT_EXTERN(const git_oid *) git_tag_id(git_tag *tag);
* This method performs a repository lookup for the
* given object and returns it
*
* @param target pointer where to store the target
* @param target_out pointer where to store the target
* @param tag a previously loaded tag.
* @return 0 or an error code
*/
GIT_EXTERN(int) git_tag_target(git_object **target, git_tag *tag);
GIT_EXTERN(int) git_tag_target(git_object **target_out, const git_tag *tag);
/**
* Get the OID of the tagged object of a tag
......@@ -96,7 +99,7 @@ GIT_EXTERN(int) git_tag_target(git_object **target, git_tag *tag);
* @param tag a previously loaded tag.
* @return pointer to the OID
*/
GIT_EXTERN(const git_oid *) git_tag_target_oid(git_tag *tag);
GIT_EXTERN(const git_oid *) git_tag_target_id(const git_tag *tag);
/**
* Get the type of a tag's tagged object
......@@ -104,7 +107,7 @@ GIT_EXTERN(const git_oid *) git_tag_target_oid(git_tag *tag);
* @param tag a previously loaded tag.
* @return type of the tagged object
*/
GIT_EXTERN(git_otype) git_tag_target_type(git_tag *tag);
GIT_EXTERN(git_otype) git_tag_target_type(const git_tag *tag);
/**
* Get the name of a tag
......@@ -112,7 +115,7 @@ GIT_EXTERN(git_otype) git_tag_target_type(git_tag *tag);
* @param tag a previously loaded tag.
* @return name of the tag
*/
GIT_EXTERN(const char *) git_tag_name(git_tag *tag);
GIT_EXTERN(const char *) git_tag_name(const git_tag *tag);
/**
* Get the tagger (author) of a tag
......@@ -120,7 +123,7 @@ GIT_EXTERN(const char *) git_tag_name(git_tag *tag);
* @param tag a previously loaded tag.
* @return reference to the tag's author
*/
GIT_EXTERN(const git_signature *) git_tag_tagger(git_tag *tag);
GIT_EXTERN(const git_signature *) git_tag_tagger(const git_tag *tag);
/**
* Get the message of a tag
......@@ -128,7 +131,7 @@ GIT_EXTERN(const git_signature *) git_tag_tagger(git_tag *tag);
* @param tag a previously loaded tag.
* @return message of the tag
*/
GIT_EXTERN(const char *) git_tag_message(git_tag *tag);
GIT_EXTERN(const char *) git_tag_message(const git_tag *tag);
/**
......@@ -167,13 +170,13 @@ GIT_EXTERN(const char *) git_tag_message(git_tag *tag);
* is written in the /refs/tags folder, pointing to it
*/
GIT_EXTERN(int) git_tag_create(
git_oid *oid,
git_repository *repo,
const char *tag_name,
const git_object *target,
const git_signature *tagger,
const char *message,
int force);
git_oid *oid,
git_repository *repo,
const char *tag_name,
const git_object *target,
const git_signature *tagger,
const char *message,
int force);
/**
* Create a new tag in the repository from a buffer
......@@ -185,10 +188,10 @@ GIT_EXTERN(int) git_tag_create(
* @return 0 on success; error code otherwise
*/
GIT_EXTERN(int) git_tag_create_frombuffer(
git_oid *oid,
git_repository *repo,
const char *buffer,
int force);
git_oid *oid,
git_repository *repo,
const char *buffer,
int force);
/**
* Create a new lightweight tag pointing at a target object
......@@ -218,11 +221,11 @@ GIT_EXTERN(int) git_tag_create_frombuffer(
* pointing to the provided target object
*/
GIT_EXTERN(int) git_tag_create_lightweight(
git_oid *oid,
git_repository *repo,
const char *tag_name,
const git_object *target,
int force);
git_oid *oid,
git_repository *repo,
const char *tag_name,
const git_object *target,
int force);
/**
* Delete an existing tag reference.
......@@ -235,8 +238,8 @@ GIT_EXTERN(int) git_tag_create_lightweight(
* @return 0 or an error code
*/
GIT_EXTERN(int) git_tag_delete(
git_repository *repo,
const char *tag_name);
git_repository *repo,
const char *tag_name);
/**
* Fill a list with all the tags in the Repository
......@@ -252,8 +255,8 @@ GIT_EXTERN(int) git_tag_delete(
* @return 0 or an error code
*/
GIT_EXTERN(int) git_tag_list(
git_strarray *tag_names,
git_repository *repo);
git_strarray *tag_names,
git_repository *repo);
/**
* Fill a list with all the tags in the Repository
......@@ -274,39 +277,39 @@ GIT_EXTERN(int) git_tag_list(
* @return 0 or an error code
*/
GIT_EXTERN(int) git_tag_list_match(
git_strarray *tag_names,
const char *pattern,
git_repository *repo);
git_strarray *tag_names,
const char *pattern,
git_repository *repo);
typedef int (*git_tag_foreach_cb)(const char *name, git_oid *oid, void *data);
typedef int (*git_tag_foreach_cb)(const char *name, git_oid *oid, void *payload);
/**
* Call callback `cb' for each tag in the repository
*
* @param repo Repository
* @param cb Callback function
* @param cb_data Pointer to callback data (optional)
* @param callback Callback function
* @param payload Pointer to callback data (optional)
*/
GIT_EXTERN(int) git_tag_foreach(
git_repository *repo,
git_tag_foreach_cb cb,
void *cb_data);
git_repository *repo,
git_tag_foreach_cb callback,
void *payload);
/**
* Recursively peel a tag until a non tag git_object
* is met
* Recursively peel a tag until a non tag git_object is found
*
* 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_target_out Pointer to the peeled git_object
* @param tag The tag to be processed
* @return 0 or an error code
*/
GIT_EXTERN(int) git_tag_peel(
git_object **tag_target,
git_tag *tag);
git_object **tag_target_out,
const git_tag *tag);
/** @} */
GIT_END_DECL
......
......@@ -45,12 +45,12 @@ typedef struct git_cred_userpass_plaintext {
/**
* Creates a new plain-text username and password credential object.
*
* @param cred The newly created credential object.
* @param out The newly created credential object.
* @param username The username of the credential.
* @param password The password of the credential.
*/
GIT_EXTERN(int) git_cred_userpass_plaintext_new(
git_cred **cred,
git_cred **out,
const char *username,
const char *password);
......@@ -64,7 +64,7 @@ GIT_EXTERN(int) git_cred_userpass_plaintext_new(
typedef int (*git_cred_acquire_cb)(
git_cred **cred,
const char *url,
int allowed_types);
unsigned int allowed_types);
/*
*** End interface for credentials acquisition ***
......@@ -144,11 +144,11 @@ typedef struct git_transport {
* is scanned to find a transport that implements the scheme of the URI (i.e.
* git:// or http://) and a transport object is returned to the caller.
*
* @param transport The newly created transport (out)
* @param out The newly created transport (out)
* @param url The URL to connect to
* @return 0 or an error code
*/
GIT_EXTERN(int) git_transport_new(git_transport **transport, const char *url);
GIT_EXTERN(int) git_transport_new(git_transport **out, const char *url);
/**
* Function which checks to see if a transport could be created for the
......@@ -161,7 +161,7 @@ GIT_EXTERN(int) git_transport_new(git_transport **transport, const char *url);
GIT_EXTERN(int) git_transport_valid_url(const char *url);
/* Signature of a function which creates a transport */
typedef int (*git_transport_cb)(git_transport **transport, void *param);
typedef int (*git_transport_cb)(git_transport **out, void *payload);
/* Transports which come with libgit2 (match git_transport_cb). The expected
* value for "param" is listed in-line below. */
......@@ -170,34 +170,34 @@ typedef int (*git_transport_cb)(git_transport **transport, void *param);
* Create an instance of the dummy transport.
*
* @param transport The newly created transport (out)
* @param param You must pass NULL for this parameter.
* @param payload You must pass NULL for this parameter.
* @return 0 or an error code
*/
GIT_EXTERN(int) git_transport_dummy(
git_transport **transport,
/* NULL */ void *param);
/* NULL */ void *payload);
/**
* Create an instance of the local transport.
*
* @param transport The newly created transport (out)
* @param param You must pass NULL for this parameter.
* @param payload You must pass NULL for this parameter.
* @return 0 or an error code
*/
GIT_EXTERN(int) git_transport_local(
git_transport **transport,
/* NULL */ void *param);
/* NULL */ void *payload);
/**
* Create an instance of the smart transport.
*
* @param transport The newly created transport (out)
* @param param A pointer to a git_smart_subtransport_definition
* @param payload A pointer to a git_smart_subtransport_definition
* @return 0 or an error code
*/
GIT_EXTERN(int) git_transport_smart(
git_transport **transport,
/* (git_smart_subtransport_definition *) */ void *param);
/* (git_smart_subtransport_definition *) */ void *payload);
/*
*** End of base transport interface ***
......
......@@ -129,7 +129,7 @@ typedef struct git_index git_index;
typedef struct git_config git_config;
/** Interface to access a configuration file */
typedef struct git_config_file git_config_file;
typedef struct git_config_backend git_config_backend;
/** Representation of a reference log entry */
typedef struct git_reflog_entry git_reflog_entry;
......@@ -175,13 +175,6 @@ typedef enum {
GIT_BRANCH_REMOTE = 2,
} git_branch_t;
/** Kinds of reset operation. */
typedef enum {
GIT_RESET_SOFT = 1,
GIT_RESET_MIXED = 2,
GIT_RESET_HARD = 3,
} git_reset_type;
/** Valid modes for index and tree entries. */
typedef enum {
GIT_FILEMODE_NEW = 0000000,
......
......@@ -295,7 +295,7 @@ static int load_attr_blob_from_index(
{
int error;
git_index *index;
git_index_entry *entry;
const git_index_entry *entry;
if ((error = git_repository_index__weakptr(&index, repo)) < 0 ||
(error = git_index_find(index, relfile)) < 0)
......
......@@ -19,10 +19,10 @@ const void *git_blob_rawcontent(git_blob *blob)
return blob->odb_object->raw.data;
}
size_t git_blob_rawsize(git_blob *blob)
git_off_t git_blob_rawsize(git_blob *blob)
{
assert(blob);
return blob->odb_object->raw.len;
return (git_off_t)blob->odb_object->raw.len;
}
int git_blob__getbuf(git_buf *buffer, git_blob *blob)
......@@ -205,7 +205,7 @@ static int blob_create_internal(git_oid *oid, git_repository *repo, const char *
return error;
}
int git_blob_create_fromfile(git_oid *oid, git_repository *repo, const char *path)
int git_blob_create_fromworkdir(git_oid *oid, git_repository *repo, const char *path)
{
git_buf full_path = GIT_BUF_INIT;
const char *workdir;
......
......@@ -44,12 +44,6 @@ cleanup:
return error;
}
static int create_error_invalid(const char *msg)
{
giterr_set(GITERR_INVALID, "Cannot create branch - %s", msg);
return -1;
}
static int not_a_local_branch(git_reference *ref)
{
giterr_set(GITERR_INVALID, "Reference '%s' is not a local branch.", git_reference_name(ref));
......@@ -60,31 +54,26 @@ int git_branch_create(
git_reference **ref_out,
git_repository *repository,
const char *branch_name,
const git_object *target,
const git_commit *commit,
int force)
{
git_object *commit = NULL;
git_reference *branch = NULL;
git_buf canonical_branch_name = GIT_BUF_INIT;
int error = -1;
assert(branch_name && target && ref_out);
assert(git_object_owner(target) == repository);
if (git_object_peel(&commit, (git_object *)target, GIT_OBJ_COMMIT) < 0)
return create_error_invalid("The given target does not resolve to a commit");
assert(branch_name && commit && ref_out);
assert(git_object_owner((const git_object *)commit) == repository);
if (git_buf_joinpath(&canonical_branch_name, GIT_REFS_HEADS_DIR, branch_name) < 0)
goto cleanup;
error = git_reference_create_oid(&branch, repository,
git_buf_cstr(&canonical_branch_name), git_object_id(commit), force);
error = git_reference_create(&branch, repository,
git_buf_cstr(&canonical_branch_name), git_commit_id(commit), force);
if (!error)
*ref_out = branch;
cleanup:
git_object_free(commit);
git_buf_free(&canonical_branch_name);
return error;
}
......
......@@ -693,7 +693,7 @@ cleanup:
int git_checkout_tree(
git_repository *repo,
git_object *treeish,
const git_object *treeish,
git_checkout_opts *opts)
{
int error = 0;
......
......@@ -28,18 +28,18 @@ static int create_branch(
const git_oid *target,
const char *name)
{
git_object *head_obj = NULL;
git_commit *head_obj = NULL;
git_reference *branch_ref;
int error;
/* Find the target commit */
if ((error = git_object_lookup(&head_obj, repo, target, GIT_OBJ_ANY)) < 0)
if ((error = git_commit_lookup(&head_obj, repo, target)) < 0)
return error;
/* Create the new branch */
error = git_branch_create(&branch_ref, repo, name, head_obj, 0);
git_object_free(head_obj);
git_commit_free(head_obj);
if (!error)
*branch = branch_ref;
......@@ -122,7 +122,7 @@ static int reference_matches_remote_head(
if (git_buf_len(&head_info->branchname) > 0)
return 0;
if (git_reference_name_to_oid(
if (git_reference_name_to_id(
&oid,
head_info->repo,
reference_name) < 0) {
......@@ -278,7 +278,7 @@ static int setup_remotes_and_fetch(
git_remote_set_update_fetchhead(origin, 0);
/* Connect and download everything */
if (!git_remote_connect(origin, GIT_DIR_FETCH)) {
if (!git_remote_connect(origin, GIT_DIRECTION_FETCH)) {
if (!git_remote_download(origin, progress_cb, progress_payload)) {
/* Create "origin/foo" branches for all remote branches */
if (!git_remote_update_tips(origin)) {
......@@ -381,9 +381,9 @@ int git_clone(
git_repository **out,
const char *origin_url,
const char *workdir_path,
git_checkout_opts *checkout_opts,
git_transfer_progress_callback fetch_progress_cb,
void *fetch_progress_payload,
git_checkout_opts *checkout_opts)
void *fetch_progress_payload)
{
assert(out && origin_url && workdir_path);
......
......@@ -22,18 +22,18 @@ static void clear_parents(git_commit *commit)
{
unsigned int i;
for (i = 0; i < commit->parent_oids.length; ++i) {
git_oid *parent = git_vector_get(&commit->parent_oids, i);
for (i = 0; i < commit->parent_ids.length; ++i) {
git_oid *parent = git_vector_get(&commit->parent_ids, i);
git__free(parent);
}
git_vector_clear(&commit->parent_oids);
git_vector_clear(&commit->parent_ids);
}
void git_commit__free(git_commit *commit)
{
clear_parents(commit);
git_vector_free(&commit->parent_oids);
git_vector_free(&commit->parent_ids);
git_signature_free(commit->author);
git_signature_free(commit->committer);
......@@ -43,11 +43,6 @@ void git_commit__free(git_commit *commit)
git__free(commit);
}
const git_oid *git_commit_id(git_commit *c)
{
return git_object_id((git_object *)c);
}
int git_commit_create_v(
git_oid *oid,
git_repository *repo,
......@@ -141,26 +136,26 @@ int git_commit__parse_buffer(git_commit *commit, const void *data, size_t len)
const char *buffer = data;
const char *buffer_end = (const char *)data + len;
git_oid parent_oid;
git_oid parent_id;
git_vector_init(&commit->parent_oids, 4, NULL);
git_vector_init(&commit->parent_ids, 4, NULL);
if (git_oid__parse(&commit->tree_oid, &buffer, buffer_end, "tree ") < 0)
if (git_oid__parse(&commit->tree_id, &buffer, buffer_end, "tree ") < 0)
goto bad_buffer;
/*
* TODO: commit grafts!
*/
while (git_oid__parse(&parent_oid, &buffer, buffer_end, "parent ") == 0) {
git_oid *new_oid;
while (git_oid__parse(&parent_id, &buffer, buffer_end, "parent ") == 0) {
git_oid *new_id;
new_oid = git__malloc(sizeof(git_oid));
GITERR_CHECK_ALLOC(new_oid);
new_id = git__malloc(sizeof(git_oid));
GITERR_CHECK_ALLOC(new_id);
git_oid_cpy(new_oid, &parent_oid);
git_oid_cpy(new_id, &parent_id);
if (git_vector_insert(&commit->parent_oids, new_oid) < 0)
if (git_vector_insert(&commit->parent_ids, new_id) < 0)
return -1;
}
......@@ -214,7 +209,7 @@ int git_commit__parse(git_commit *commit, git_odb_object *obj)
}
#define GIT_COMMIT_GETTER(_rvalue, _name, _return) \
_rvalue git_commit_##_name(git_commit *commit) \
_rvalue git_commit_##_name(const git_commit *commit) \
{\
assert(commit); \
return _return; \
......@@ -226,34 +221,34 @@ GIT_COMMIT_GETTER(const char *, message, commit->message)
GIT_COMMIT_GETTER(const char *, message_encoding, commit->message_encoding)
GIT_COMMIT_GETTER(git_time_t, time, commit->committer->when.time)
GIT_COMMIT_GETTER(int, time_offset, commit->committer->when.offset)
GIT_COMMIT_GETTER(unsigned int, parentcount, (unsigned int)commit->parent_oids.length)
GIT_COMMIT_GETTER(const git_oid *, tree_oid, &commit->tree_oid);
GIT_COMMIT_GETTER(unsigned int, parentcount, (unsigned int)commit->parent_ids.length)
GIT_COMMIT_GETTER(const git_oid *, tree_id, &commit->tree_id);
int git_commit_tree(git_tree **tree_out, git_commit *commit)
int git_commit_tree(git_tree **tree_out, const git_commit *commit)
{
assert(commit);
return git_tree_lookup(tree_out, commit->object.repo, &commit->tree_oid);
return git_tree_lookup(tree_out, commit->object.repo, &commit->tree_id);
}
const git_oid *git_commit_parent_oid(git_commit *commit, unsigned int n)
const git_oid *git_commit_parent_id(git_commit *commit, unsigned int n)
{
assert(commit);
return git_vector_get(&commit->parent_oids, n);
return git_vector_get(&commit->parent_ids, n);
}
int git_commit_parent(git_commit **parent, git_commit *commit, unsigned int n)
{
const git_oid *parent_oid;
const git_oid *parent_id;
assert(commit);
parent_oid = git_commit_parent_oid(commit, n);
if (parent_oid == NULL) {
parent_id = git_commit_parent_id(commit, n);
if (parent_id == NULL) {
giterr_set(GITERR_INVALID, "Parent %u does not exist", n);
return GIT_ENOTFOUND;
}
return git_commit_lookup(parent, commit->object.repo, parent_oid);
return git_commit_lookup(parent, commit->object.repo, parent_id);
}
int git_commit_nth_gen_ancestor(
......
......@@ -17,8 +17,8 @@
struct git_commit {
git_object object;
git_vector parent_oids;
git_oid tree_oid;
git_vector parent_ids;
git_oid tree_id;
git_signature *author;
git_signature *committer;
......
/*
* 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.
*/
#include "commit_list.h"
#include "common.h"
#include "revwalk.h"
#include "pool.h"
#include "odb.h"
int git_commit_list_time_cmp(void *a, void *b)
{
git_commit_list_node *commit_a = (git_commit_list_node *)a;
git_commit_list_node *commit_b = (git_commit_list_node *)b;
return (commit_a->time < commit_b->time);
}
git_commit_list *git_commit_list_insert(git_commit_list_node *item, git_commit_list **list_p)
{
git_commit_list *new_list = git__malloc(sizeof(git_commit_list));
if (new_list != NULL) {
new_list->item = item;
new_list->next = *list_p;
}
*list_p = new_list;
return new_list;
}
git_commit_list *git_commit_list_insert_by_date(git_commit_list_node *item, git_commit_list **list_p)
{
git_commit_list **pp = list_p;
git_commit_list *p;
while ((p = *pp) != NULL) {
if (git_commit_list_time_cmp(p->item, item) < 0)
break;
pp = &p->next;
}
return git_commit_list_insert(item, pp);
}
git_commit_list_node *git_commit_list_alloc_node(git_revwalk *walk)
{
return (git_commit_list_node *)git_pool_malloc(&walk->commit_pool, COMMIT_ALLOC);
}
static int commit_error(git_commit_list_node *commit, const char *msg)
{
char commit_oid[GIT_OID_HEXSZ + 1];
git_oid_fmt(commit_oid, &commit->oid);
commit_oid[GIT_OID_HEXSZ] = '\0';
giterr_set(GITERR_ODB, "Failed to parse commit %s - %s", commit_oid, msg);
return -1;
}
static git_commit_list_node **alloc_parents(
git_revwalk *walk, git_commit_list_node *commit, size_t n_parents)
{
if (n_parents <= PARENTS_PER_COMMIT)
return (git_commit_list_node **)((char *)commit + sizeof(git_commit_list_node));
return (git_commit_list_node **)git_pool_malloc(
&walk->commit_pool, (uint32_t)(n_parents * sizeof(git_commit_list_node *)));
}
void git_commit_list_free(git_commit_list **list_p)
{
git_commit_list *list = *list_p;
if (list == NULL)
return;
while (list) {
git_commit_list *temp = list;
list = temp->next;
git__free(temp);
}
*list_p = NULL;
}
git_commit_list_node *git_commit_list_pop(git_commit_list **stack)
{
git_commit_list *top = *stack;
git_commit_list_node *item = top ? top->item : NULL;
if (top) {
*stack = top->next;
git__free(top);
}
return item;
}
static int commit_quick_parse(git_revwalk *walk, git_commit_list_node *commit, git_rawobj *raw)
{
const size_t parent_len = strlen("parent ") + GIT_OID_HEXSZ + 1;
unsigned char *buffer = raw->data;
unsigned char *buffer_end = buffer + raw->len;
unsigned char *parents_start, *committer_start;
int i, parents = 0;
int commit_time;
buffer += strlen("tree ") + GIT_OID_HEXSZ + 1;
parents_start = buffer;
while (buffer + parent_len < buffer_end && memcmp(buffer, "parent ", strlen("parent ")) == 0) {
parents++;
buffer += parent_len;
}
commit->parents = alloc_parents(walk, commit, parents);
GITERR_CHECK_ALLOC(commit->parents);
buffer = parents_start;
for (i = 0; i < parents; ++i) {
git_oid oid;
if (git_oid_fromstr(&oid, (char *)buffer + strlen("parent ")) < 0)
return -1;
commit->parents[i] = commit_lookup(walk, &oid);
if (commit->parents[i] == NULL)
return -1;
buffer += parent_len;
}
commit->out_degree = (unsigned short)parents;
if ((committer_start = buffer = memchr(buffer, '\n', buffer_end - buffer)) == NULL)
return commit_error(commit, "object is corrupted");
buffer++;
if ((buffer = memchr(buffer, '\n', buffer_end - buffer)) == NULL)
return commit_error(commit, "object is corrupted");
/* Skip trailing spaces */
while (buffer > committer_start && git__isspace(*buffer))
buffer--;
/* Seek for the begining of the pack of digits */
while (buffer > committer_start && git__isdigit(*buffer))
buffer--;
/* Skip potential timezone offset */
if ((buffer > committer_start) && (*buffer == '+' || *buffer == '-')) {
buffer--;
while (buffer > committer_start && git__isspace(*buffer))
buffer--;
while (buffer > committer_start && git__isdigit(*buffer))
buffer--;
}
if ((buffer == committer_start) || (git__strtol32(&commit_time, (char *)(buffer + 1), NULL, 10) < 0))
return commit_error(commit, "cannot parse commit time");
commit->time = (time_t)commit_time;
commit->parsed = 1;
return 0;
}
int git_commit_list_parse(git_revwalk *walk, git_commit_list_node *commit)
{
git_odb_object *obj;
int error;
if (commit->parsed)
return 0;
if ((error = git_odb_read(&obj, walk->odb, &commit->oid)) < 0)
return error;
assert(obj->raw.type == GIT_OBJ_COMMIT);
error = commit_quick_parse(walk, commit, &obj->raw);
git_odb_object_free(obj);
return error;
}
/*
* 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_commit_list_h__
#define INCLUDE_commit_list_h__
#include "git2/oid.h"
#define PARENT1 (1 << 0)
#define PARENT2 (1 << 1)
#define RESULT (1 << 2)
#define STALE (1 << 3)
#define PARENTS_PER_COMMIT 2
#define COMMIT_ALLOC \
(sizeof(git_commit_list_node) + PARENTS_PER_COMMIT * sizeof(git_commit_list_node *))
typedef struct git_commit_list_node {
git_oid oid;
uint32_t time;
unsigned int seen:1,
uninteresting:1,
topo_delay:1,
parsed:1,
flags : 4;
unsigned short in_degree;
unsigned short out_degree;
struct git_commit_list_node **parents;
} git_commit_list_node;
typedef struct git_commit_list {
git_commit_list_node *item;
struct git_commit_list *next;
} git_commit_list;
git_commit_list_node *git_commit_list_alloc_node(git_revwalk *walk);
int git_commit_list_time_cmp(void *a, void *b);
void git_commit_list_free(git_commit_list **list_p);
git_commit_list *git_commit_list_insert(git_commit_list_node *item, git_commit_list **list_p);
git_commit_list *git_commit_list_insert_by_date(git_commit_list_node *item, git_commit_list **list_p);
int git_commit_list_parse(git_revwalk *walk, git_commit_list_node *commit);
git_commit_list_node *git_commit_list_pop(git_commit_list **stack);
#endif
......@@ -19,13 +19,13 @@
typedef struct {
git_refcount rc;
git_config_file *file;
git_config_backend *file;
unsigned int level;
} file_internal;
static void file_internal_free(file_internal *internal)
{
git_config_file *file;
git_config_backend *file;
file = internal->file;
file->free(file);
......@@ -87,7 +87,7 @@ int git_config_add_file_ondisk(
unsigned int level,
int force)
{
git_config_file *file = NULL;
git_config_backend *file = NULL;
int res;
assert(cfg && path);
......@@ -100,7 +100,7 @@ int git_config_add_file_ondisk(
if (git_config_file__ondisk(&file, path) < 0)
return -1;
if ((res = git_config_add_file(cfg, file, level, force)) < 0) {
if ((res = git_config_add_backend(cfg, file, level, force)) < 0) {
/*
* free manually; the file is not owned by the config
* instance yet and will not be freed on cleanup
......@@ -132,7 +132,7 @@ int git_config_open_ondisk(git_config **out, const char *path)
static int find_internal_file_by_level(
file_internal **internal_out,
git_config *cfg,
const git_config *cfg,
int level)
{
int pos = -1;
......@@ -224,7 +224,7 @@ static int git_config__add_internal(
int git_config_open_level(
git_config **cfg_out,
git_config *cfg_parent,
const git_config *cfg_parent,
unsigned int level)
{
git_config *cfg;
......@@ -247,9 +247,9 @@ int git_config_open_level(
return 0;
}
int git_config_add_file(
int git_config_add_backend(
git_config *cfg,
git_config_file *file,
git_config_backend *file,
unsigned int level,
int force)
{
......@@ -284,7 +284,7 @@ int git_config_refresh(git_config *cfg)
for (i = 0; i < cfg->files.length && !error; ++i) {
file_internal *internal = git_vector_get(&cfg->files, i);
git_config_file *file = internal->file;
git_config_backend *file = internal->file;
error = file->refresh(file);
}
......@@ -296,34 +296,34 @@ int git_config_refresh(git_config *cfg)
*/
int git_config_foreach(
git_config *cfg, int (*fn)(const git_config_entry *, void *), void *data)
const git_config *cfg, git_config_foreach_cb cb, void *payload)
{
return git_config_foreach_match(cfg, NULL, fn, data);
return git_config_foreach_match(cfg, NULL, cb, payload);
}
int git_config_foreach_match(
git_config *cfg,
const git_config *cfg,
const char *regexp,
int (*fn)(const git_config_entry *, void *),
void *data)
git_config_foreach_cb cb,
void *payload)
{
int ret = 0;
unsigned int i;
file_internal *internal;
git_config_file *file;
git_config_backend *file;
for (i = 0; i < cfg->files.length && ret == 0; ++i) {
internal = git_vector_get(&cfg->files, i);
file = internal->file;
ret = file->foreach(file, regexp, fn, data);
ret = file->foreach(file, regexp, cb, payload);
}
return ret;
}
int git_config_delete(git_config *cfg, const char *name)
int git_config_delete_entry(git_config *cfg, const char *name)
{
git_config_file *file;
git_config_backend *file;
file_internal *internal;
internal = git_vector_get(&cfg->files, 0);
......@@ -355,7 +355,7 @@ int git_config_set_bool(git_config *cfg, const char *name, int value)
int git_config_set_string(git_config *cfg, const char *name, const char *value)
{
git_config_file *file;
git_config_backend *file;
file_internal *internal;
internal = git_vector_get(&cfg->files, 0);
......@@ -369,9 +369,9 @@ int git_config_set_string(git_config *cfg, const char *name, const char *value)
***********/
int git_config_get_mapped(
int *out,
git_config *cfg,
const git_config *cfg,
const char *name,
git_cvar_map *maps,
const git_cvar_map *maps,
size_t map_n)
{
const char *value;
......@@ -383,7 +383,7 @@ int git_config_get_mapped(
return git_config_lookup_map_value(out, maps, map_n, value);
}
int git_config_get_int64(int64_t *out, git_config *cfg, const char *name)
int git_config_get_int64(int64_t *out, const git_config *cfg, const char *name)
{
const char *value;
int ret;
......@@ -394,7 +394,7 @@ int git_config_get_int64(int64_t *out, git_config *cfg, const char *name)
return git_config_parse_int64(out, value);
}
int git_config_get_int32(int32_t *out, git_config *cfg, const char *name)
int git_config_get_int32(int32_t *out, const git_config *cfg, const char *name)
{
const char *value;
int ret;
......@@ -405,7 +405,7 @@ int git_config_get_int32(int32_t *out, git_config *cfg, const char *name)
return git_config_parse_int32(out, value);
}
static int get_string_at_file(const char **out, git_config_file *file, const char *name)
static int get_string_at_file(const char **out, const git_config_backend *file, const char *name)
{
const git_config_entry *entry;
int res;
......@@ -417,7 +417,7 @@ static int get_string_at_file(const char **out, git_config_file *file, const cha
return res;
}
static int get_string(const char **out, git_config *cfg, const char *name)
static int get_string(const char **out, const git_config *cfg, const char *name)
{
file_internal *internal;
unsigned int i;
......@@ -434,7 +434,7 @@ static int get_string(const char **out, git_config *cfg, const char *name)
return GIT_ENOTFOUND;
}
int git_config_get_bool(int *out, git_config *cfg, const char *name)
int git_config_get_bool(int *out, const git_config *cfg, const char *name)
{
const char *value = NULL;
int ret;
......@@ -445,7 +445,7 @@ int git_config_get_bool(int *out, git_config *cfg, const char *name)
return git_config_parse_bool(out, value);
}
int git_config_get_string(const char **out, git_config *cfg, const char *name)
int git_config_get_string(const char **out, const git_config *cfg, const char *name)
{
int ret;
const char *str = NULL;
......@@ -457,7 +457,7 @@ int git_config_get_string(const char **out, git_config *cfg, const char *name)
return 0;
}
int git_config_get_entry(const git_config_entry **out, git_config *cfg, const char *name)
int git_config_get_entry(const git_config_entry **out, const git_config *cfg, const char *name)
{
file_internal *internal;
unsigned int i;
......@@ -467,7 +467,7 @@ int git_config_get_entry(const git_config_entry **out, git_config *cfg, const ch
*out = NULL;
git_vector_foreach(&cfg->files, i, internal) {
git_config_file *file = internal->file;
git_config_backend *file = internal->file;
int ret = file->get(file, name, out);
if (ret != GIT_ENOTFOUND)
return ret;
......@@ -476,11 +476,11 @@ int git_config_get_entry(const git_config_entry **out, git_config *cfg, const ch
return GIT_ENOTFOUND;
}
int git_config_get_multivar(git_config *cfg, const char *name, const char *regexp,
int (*fn)(const git_config_entry *entry, void *data), void *data)
int git_config_get_multivar(const git_config *cfg, const char *name, const char *regexp,
git_config_foreach_cb cb, void *payload)
{
file_internal *internal;
git_config_file *file;
git_config_backend *file;
int ret = GIT_ENOTFOUND;
size_t i;
......@@ -493,7 +493,7 @@ int git_config_get_multivar(git_config *cfg, const char *name, const char *regex
for (i = cfg->files.length; i > 0; --i) {
internal = git_vector_get(&cfg->files, i - 1);
file = internal->file;
ret = file->get_multivar(file, name, regexp, fn, data);
ret = file->get_multivar(file, name, regexp, cb, payload);
if (ret < 0 && ret != GIT_ENOTFOUND)
return ret;
}
......@@ -503,7 +503,7 @@ int git_config_get_multivar(git_config *cfg, const char *name, const char *regex
int git_config_set_multivar(git_config *cfg, const char *name, const char *regexp, const char *value)
{
git_config_file *file;
git_config_backend *file;
file_internal *internal;
internal = git_vector_get(&cfg->files, 0);
......@@ -634,7 +634,7 @@ int git_config_open_default(git_config **out)
***********/
int git_config_lookup_map_value(
int *out,
git_cvar_map *maps,
const git_cvar_map *maps,
size_t map_n,
const char *value)
{
......@@ -644,7 +644,7 @@ int git_config_lookup_map_value(
goto fail_parse;
for (i = 0; i < map_n; ++i) {
git_cvar_map *m = maps + i;
const git_cvar_map *m = maps + i;
switch (m->cvar_type) {
case GIT_CVAR_FALSE:
......@@ -790,7 +790,7 @@ static int rename_config_entries_cb(
return error;
}
return git_config_delete(data->config, entry->name);
return git_config_delete_entry(data->config, entry->name);
}
int git_config_rename_section(
......
......@@ -43,6 +43,6 @@ extern int git_config_rename_section(
* @param out the new backend
* @param path where the config file is located
*/
extern int git_config_file__ondisk(struct git_config_file **out, const char *path);
extern int git_config_file__ondisk(struct git_config_backend **out, const char *path);
#endif
......@@ -64,7 +64,7 @@ typedef struct cvar_t {
(iter) = (tmp))
typedef struct {
git_config_file parent;
git_config_backend parent;
git_strmap *values;
......@@ -149,7 +149,7 @@ static void free_vars(git_strmap *values)
git_strmap_free(values);
}
static int config_open(git_config_file *cfg, unsigned int level)
static int config_open(git_config_backend *cfg, unsigned int level)
{
int res;
diskfile_backend *b = (diskfile_backend *)cfg;
......@@ -176,7 +176,7 @@ static int config_open(git_config_file *cfg, unsigned int level)
return res;
}
static int config_refresh(git_config_file *cfg)
static int config_refresh(git_config_backend *cfg)
{
int res, updated = 0;
diskfile_backend *b = (diskfile_backend *)cfg;
......@@ -203,7 +203,7 @@ static int config_refresh(git_config_file *cfg)
return res;
}
static void backend_free(git_config_file *_backend)
static void backend_free(git_config_backend *_backend)
{
diskfile_backend *backend = (diskfile_backend *)_backend;
......@@ -216,7 +216,7 @@ static void backend_free(git_config_file *_backend)
}
static int file_foreach(
git_config_file *backend,
git_config_backend *backend,
const char *regexp,
int (*fn)(const git_config_entry *, void *),
void *data)
......@@ -262,7 +262,7 @@ cleanup:
return result;
}
static int config_set(git_config_file *cfg, const char *name, const char *value)
static int config_set(git_config_backend *cfg, const char *name, const char *value)
{
cvar_t *var = NULL, *old_var;
diskfile_backend *b = (diskfile_backend *)cfg;
......@@ -346,7 +346,7 @@ static int config_set(git_config_file *cfg, const char *name, const char *value)
/*
* Internal function that actually gets the value in string form
*/
static int config_get(git_config_file *cfg, const char *name, const git_config_entry **out)
static int config_get(const git_config_backend *cfg, const char *name, const git_config_entry **out)
{
diskfile_backend *b = (diskfile_backend *)cfg;
char *key;
......@@ -368,7 +368,7 @@ static int config_get(git_config_file *cfg, const char *name, const git_config_e
}
static int config_get_multivar(
git_config_file *cfg,
git_config_backend *cfg,
const char *name,
const char *regex_str,
int (*fn)(const git_config_entry *, void *),
......@@ -431,7 +431,7 @@ static int config_get_multivar(
}
static int config_set_multivar(
git_config_file *cfg, const char *name, const char *regexp, const char *value)
git_config_backend *cfg, const char *name, const char *regexp, const char *value)
{
int replaced = 0;
cvar_t *var, *newvar;
......@@ -506,7 +506,7 @@ static int config_set_multivar(
return result;
}
static int config_delete(git_config_file *cfg, const char *name)
static int config_delete(git_config_backend *cfg, const char *name)
{
cvar_t *var;
diskfile_backend *b = (diskfile_backend *)cfg;
......@@ -540,7 +540,7 @@ static int config_delete(git_config_file *cfg, const char *name)
return result;
}
int git_config_file__ondisk(git_config_file **out, const char *path)
int git_config_file__ondisk(git_config_backend **out, const char *path)
{
diskfile_backend *backend;
......@@ -562,7 +562,7 @@ int git_config_file__ondisk(git_config_file **out, const char *path)
backend->parent.refresh = config_refresh;
backend->parent.free = backend_free;
*out = (git_config_file *)backend;
*out = (git_config_backend *)backend;
return 0;
}
......
......@@ -9,36 +9,36 @@
#include "git2/config.h"
GIT_INLINE(int) git_config_file_open(git_config_file *cfg, unsigned int level)
GIT_INLINE(int) git_config_file_open(git_config_backend *cfg, unsigned int level)
{
return cfg->open(cfg, level);
}
GIT_INLINE(void) git_config_file_free(git_config_file *cfg)
GIT_INLINE(void) git_config_file_free(git_config_backend *cfg)
{
cfg->free(cfg);
}
GIT_INLINE(int) git_config_file_get_string(
const git_config_entry **out, git_config_file *cfg, const char *name)
const git_config_entry **out, git_config_backend *cfg, const char *name)
{
return cfg->get(cfg, name, out);
}
GIT_INLINE(int) git_config_file_set_string(
git_config_file *cfg, const char *name, const char *value)
git_config_backend *cfg, const char *name, const char *value)
{
return cfg->set(cfg, name, value);
}
GIT_INLINE(int) git_config_file_delete(
git_config_file *cfg, const char *name)
git_config_backend *cfg, const char *name)
{
return cfg->del(cfg, name);
}
GIT_INLINE(int) git_config_file_foreach(
git_config_file *cfg,
git_config_backend *cfg,
int (*fn)(const git_config_entry *entry, void *data),
void *data)
{
......@@ -46,7 +46,7 @@ GIT_INLINE(int) git_config_file_foreach(
}
GIT_INLINE(int) git_config_file_foreach_match(
git_config_file *cfg,
git_config_backend *cfg,
const char *regexp,
int (*fn)(const git_config_entry *entry, void *data),
void *data)
......
......@@ -148,7 +148,7 @@ git_delta_create_index(const void *buf, unsigned long bufsize)
/* Determine index hash size. Note that indexing skips the
first byte to allow for optimizing the Rabin's polynomial
initialization in create_delta(). */
entries = (bufsize - 1) / RABIN_WINDOW;
entries = (unsigned int)(bufsize - 1) / RABIN_WINDOW;
if (bufsize >= 0xffffffffUL) {
/*
* Current delta format can't encode offsets into
......@@ -317,9 +317,12 @@ unsigned long git_delta_sizeof_index(struct git_delta_index *index)
#define MAX_OP_SIZE (5 + 5 + 1 + RABIN_WINDOW + 7)
void *
git_delta_create(const struct git_delta_index *index,
const void *trg_buf, unsigned long trg_size,
unsigned long *delta_size, unsigned long max_size)
git_delta_create(
const struct git_delta_index *index,
const void *trg_buf,
unsigned long trg_size,
unsigned long *delta_size,
unsigned long max_size)
{
unsigned int i, outpos, outsize, moff, msize, val;
int inscnt;
......@@ -332,7 +335,7 @@ git_delta_create(const struct git_delta_index *index,
outpos = 0;
outsize = 8192;
if (max_size && outsize >= max_size)
outsize = max_size + MAX_OP_SIZE + 1;
outsize = (unsigned int)(max_size + MAX_OP_SIZE + 1);
out = git__malloc(outsize);
if (!out)
return NULL;
......@@ -377,19 +380,19 @@ git_delta_create(const struct git_delta_index *index,
for (entry = index->hash[i]; entry < index->hash[i+1]; entry++) {
const unsigned char *ref = entry->ptr;
const unsigned char *src = data;
unsigned int ref_size = ref_top - ref;
unsigned int ref_size = (unsigned int)(ref_top - ref);
if (entry->val != val)
continue;
if (ref_size > (unsigned int)(top - src))
ref_size = top - src;
ref_size = (unsigned int)(top - src);
if (ref_size <= msize)
break;
while (ref_size-- && *src++ == *ref)
ref++;
if (msize < (unsigned int)(ref - entry->ptr)) {
/* this is our best match so far */
msize = ref - entry->ptr;
moff = entry->ptr - ref_data;
msize = (unsigned int)(ref - entry->ptr);
moff = (unsigned int)(entry->ptr - ref_data);
if (msize >= 4096) /* good enough */
break;
}
......
......@@ -46,11 +46,12 @@ extern unsigned long git_delta_sizeof_index(struct git_delta_index *index);
* returned and *delta_size is updated with its size. The returned buffer
* must be freed by the caller.
*/
extern void *
git_delta_create(const struct git_delta_index *index,
const void *buf, unsigned long bufsize,
unsigned long *delta_size,
unsigned long max_delta_size);
extern void *git_delta_create(
const struct git_delta_index *index,
const void *buf,
unsigned long bufsize,
unsigned long *delta_size,
unsigned long max_delta_size);
/*
* diff_delta: create a delta from source buffer to target buffer
......@@ -60,15 +61,16 @@ git_delta_create(const struct git_delta_index *index,
* pointer to the buffer with the delta data is returned and *delta_size is
* updated with its size. The returned buffer must be freed by the caller.
*/
GIT_INLINE(void *)
git_delta(const void *src_buf, unsigned long src_bufsize,
const void *trg_buf, unsigned long trg_bufsize,
unsigned long *delta_size, unsigned long max_delta_size)
GIT_INLINE(void *) git_delta(
const void *src_buf, unsigned long src_bufsize,
const void *trg_buf, unsigned long trg_bufsize,
unsigned long *delta_size,
unsigned long max_delta_size)
{
struct git_delta_index *index = git_delta_create_index(src_buf, src_bufsize);
if (index) {
void *delta = git_delta_create(index, trg_buf, trg_bufsize,
delta_size, max_delta_size);
void *delta = git_delta_create(
index, trg_buf, trg_bufsize, delta_size, max_delta_size);
git_delta_free_index(index);
return delta;
}
......@@ -82,9 +84,10 @@ git_delta(const void *src_buf, unsigned long src_bufsize,
* *trg_bufsize is updated with its size. On failure a NULL pointer is
* returned. The returned buffer must be freed by the caller.
*/
extern void *git_delta_patch(const void *src_buf, unsigned long src_size,
const void *delta_buf, unsigned long delta_size,
unsigned long *dst_size);
extern void *git_delta_patch(
const void *src_buf, unsigned long src_size,
const void *delta_buf, unsigned long delta_size,
unsigned long *dst_size);
/* the smallest possible delta size is 4 bytes */
#define GIT_DELTA_SIZE_MIN 4
......@@ -93,9 +96,8 @@ extern void *git_delta_patch(const void *src_buf, unsigned long src_size,
* This must be called twice on the delta data buffer, first to get the
* expected source buffer size, and again to get the target buffer size.
*/
GIT_INLINE(unsigned long)
git_delta_get_hdr_size(const unsigned char **datap,
const unsigned char *top)
GIT_INLINE(unsigned long) git_delta_get_hdr_size(
const unsigned char **datap, const unsigned char *top)
{
const unsigned char *data = *datap;
unsigned long cmd, size = 0;
......
......@@ -363,7 +363,7 @@ int git_diff__oid_for_file(
const git_oid *sm_oid;
if (!git_submodule_lookup(&sm, repo, path) &&
(sm_oid = git_submodule_wd_oid(sm)) != NULL)
(sm_oid = git_submodule_wd_id(sm)) != NULL)
git_oid_cpy(oid, sm_oid);
else {
/* if submodule lookup failed probably just in an intermediate
......@@ -496,7 +496,7 @@ static int maybe_modified(
/* grab OID while we are here */
if (git_oid_iszero(&nitem->oid)) {
const git_oid *sm_oid = git_submodule_wd_oid(sub);
const git_oid *sm_oid = git_submodule_wd_id(sub);
if (sm_oid != NULL) {
git_oid_cpy(&noid, sm_oid);
use_noid = &noid;
......
......@@ -27,12 +27,12 @@ typedef struct {
git_repository *repo;
git_diff_list *diff;
const git_diff_options *opts;
git_diff_file_fn file_cb;
git_diff_hunk_fn hunk_cb;
git_diff_data_fn data_cb;
void *cb_data;
int cb_error;
git_diff_range cb_range;
git_diff_file_cb file_cb;
git_diff_hunk_cb hunk_cb;
git_diff_data_cb data_cb;
void *payload;
int error;
git_diff_range range;
xdemitconf_t xdiff_config;
xpparam_t xdiff_params;
} diff_context;
......@@ -86,7 +86,7 @@ typedef struct {
extern int git_diff__paired_foreach(
git_diff_list *idx2head,
git_diff_list *wd2idx,
int (*cb)(void *cbref, git_diff_delta *i2h, git_diff_delta *w2i),
void *cbref);
int (*cb)(git_diff_delta *i2h, git_diff_delta *w2i, void *payload),
void *payload);
#endif
......@@ -155,7 +155,7 @@ GIT_INLINE(int) hash_cryptoapi_update(git_hash_ctx *ctx, const void *data, size_
{
assert(ctx->ctx.cryptoapi.valid);
if (!CryptHashData(ctx->ctx.cryptoapi.hash_handle, (const BYTE *)data, len, 0))
if (!CryptHashData(ctx->ctx.cryptoapi.hash_handle, (const BYTE *)data, (DWORD)len, 0))
return -1;
return 0;
......@@ -219,7 +219,7 @@ GIT_INLINE(int) hash_cng_init(git_hash_ctx *ctx)
GIT_INLINE(int) hash_cng_update(git_hash_ctx *ctx, const void *data, size_t len)
{
if (ctx->prov->prov.cng.hash_data(ctx->ctx.cng.hash_handle, (PBYTE)data, len, 0) < 0)
if (ctx->prov->prov.cng.hash_data(ctx->ctx.cng.hash_handle, (PBYTE)data, (ULONG)len, 0) < 0)
return -1;
return 0;
......
......@@ -94,7 +94,7 @@ static size_t read_entry(git_index_entry *dest, const void *buffer, size_t buffe
static int read_header(struct index_header *dest, const void *buffer);
static int parse_index(git_index *index, const char *buffer, size_t buffer_size);
static int is_index_extended(git_index *index);
static bool is_index_extended(git_index *index);
static int write_index(git_index *index, git_filebuf *file);
static int index_find(git_index *index, const char *path, int stage);
......@@ -298,7 +298,7 @@ static void index_free(git_index *index)
{
git_index_entry *e;
git_index_reuc_entry *reuc;
unsigned int i;
size_t i;
git_index_clear(index);
git_vector_foreach(&index->entries, i, e) {
......@@ -488,20 +488,22 @@ int git_index_write_tree_to(git_oid *oid, git_index *index, git_repository *repo
return git_tree__write_index(oid, index, repo);
}
unsigned int git_index_entrycount(git_index *index)
size_t git_index_entrycount(const git_index *index)
{
assert(index);
return (unsigned int)index->entries.length;
return index->entries.length;
}
git_index_entry *git_index_get_byindex(git_index *index, size_t n)
const git_index_entry *git_index_get_byindex(
git_index *index, size_t n)
{
assert(index);
git_vector_sort(&index->entries);
return git_vector_get(&index->entries, n);
}
git_index_entry *git_index_get_bypath(git_index *index, const char *path, int stage)
const git_index_entry *git_index_get_bypath(
git_index *index, const char *path, int stage)
{
int pos;
......@@ -580,7 +582,7 @@ static int index_entry_init(git_index_entry **entry_out, git_index *index, const
*/
/* write the blob to disk and get the oid */
if ((error = git_blob_create_fromfile(&oid, INDEX_OWNER(index), rel_path)) < 0)
if ((error = git_blob_create_fromworkdir(&oid, INDEX_OWNER(index), rel_path)) < 0)
return error;
entry = git__calloc(1, sizeof(git_index_entry));
......@@ -810,13 +812,15 @@ int git_index_find(git_index *index, const char *path)
assert(index && path);
if ((pos = git_vector_bsearch2(&index->entries, index->entries_search_path, path)) < 0)
if ((pos = git_vector_bsearch2(
&index->entries, index->entries_search_path, path)) < 0)
return pos;
/* Since our binary search only looked at path, we may be in the
* middle of a list of stages. */
* middle of a list of stages.
*/
while (pos > 0) {
git_index_entry *prev = git_vector_get(&index->entries, pos-1);
const git_index_entry *prev = git_vector_get(&index->entries, pos-1);
if (index->entries_cmp_path(prev->path, path) != 0)
break;
......@@ -827,10 +831,10 @@ int git_index_find(git_index *index, const char *path)
return pos;
}
unsigned int git_index__prefix_position(git_index *index, const char *path)
size_t git_index__prefix_position(git_index *index, const char *path)
{
struct entry_srch_key srch_key;
unsigned int pos;
size_t pos;
srch_key.path = path;
srch_key.stage = 0;
......@@ -848,7 +852,7 @@ int git_index_conflict_add(git_index *index,
const git_index_entry *their_entry)
{
git_index_entry *entries[3] = { 0 };
size_t i;
unsigned short i;
int ret = 0;
assert (index);
......@@ -886,7 +890,7 @@ int git_index_conflict_get(git_index_entry **ancestor_out,
git_index_entry **their_out,
git_index *index, const char *path)
{
int pos, stage;
int pos, posmax, stage;
git_index_entry *conflict_entry;
int error = GIT_ENOTFOUND;
......@@ -899,7 +903,8 @@ int git_index_conflict_get(git_index_entry **ancestor_out,
if ((pos = git_index_find(index, path)) < 0)
return pos;
while ((unsigned int)pos < git_index_entrycount(index)) {
for (posmax = (int)git_index_entrycount(index); pos < posmax; ++pos) {
conflict_entry = git_vector_get(&index->entries, pos);
if (index->entries_cmp_path(conflict_entry->path, path) != 0)
......@@ -923,8 +928,6 @@ int git_index_conflict_get(git_index_entry **ancestor_out,
default:
break;
};
++pos;
}
return error;
......@@ -932,7 +935,7 @@ int git_index_conflict_get(git_index_entry **ancestor_out,
int git_index_conflict_remove(git_index *index, const char *path)
{
int pos;
int pos, posmax;
git_index_entry *conflict_entry;
int error = 0;
......@@ -941,7 +944,9 @@ int git_index_conflict_remove(git_index *index, const char *path)
if ((pos = git_index_find(index, path)) < 0)
return pos;
while ((unsigned int)pos < git_index_entrycount(index)) {
posmax = (int)git_index_entrycount(index);
while (pos < posmax) {
conflict_entry = git_vector_get(&index->entries, pos);
if (index->entries_cmp_path(conflict_entry->path, path) != 0)
......@@ -961,7 +966,7 @@ int git_index_conflict_remove(git_index *index, const char *path)
return error;
}
static int index_conflicts_match(git_vector *v, size_t idx)
static int index_conflicts_match(const git_vector *v, size_t idx)
{
git_index_entry *entry = git_vector_get(v, idx);
......@@ -979,9 +984,9 @@ void git_index_conflict_cleanup(git_index *index)
git_vector_remove_matching(&index->entries, index_conflicts_match);
}
int git_index_has_conflicts(git_index *index)
int git_index_has_conflicts(const git_index *index)
{
unsigned int i;
size_t i;
git_index_entry *entry;
assert(index);
......@@ -1072,7 +1077,7 @@ const git_index_reuc_entry *git_index_reuc_get_byindex(
return git_vector_get(&index->reuc, n);
}
int git_index_reuc_remove(git_index *index, int position)
int git_index_reuc_remove(git_index *index, size_t position)
{
int error;
git_index_reuc_entry *reuc;
......@@ -1359,9 +1364,9 @@ static int parse_index(git_index *index, const char *buffer, size_t buffer_size)
return 0;
}
static int is_index_extended(git_index *index)
static bool is_index_extended(git_index *index)
{
unsigned int i, extended;
size_t i, extended;
git_index_entry *entry;
extended = 0;
......@@ -1374,7 +1379,7 @@ static int is_index_extended(git_index *index)
}
}
return extended;
return (extended > 0);
}
static int write_disk_entry(git_filebuf *file, git_index_entry *entry)
......@@ -1440,7 +1445,7 @@ static int write_disk_entry(git_filebuf *file, git_index_entry *entry)
static int write_entries(git_index *index, git_filebuf *file)
{
int error = 0;
unsigned int i;
size_t i;
git_vector case_sorted;
git_index_entry *entry;
git_vector *out = &index->entries;
......@@ -1506,7 +1511,7 @@ static int write_reuc_extension(git_index *index, git_filebuf *file)
git_vector *out = &index->reuc;
git_index_reuc_entry *reuc;
struct index_extension extension;
unsigned int i;
size_t i;
int error = 0;
git_vector_foreach(out, i, reuc) {
......@@ -1516,7 +1521,7 @@ static int write_reuc_extension(git_index *index, git_filebuf *file)
memset(&extension, 0x0, sizeof(struct index_extension));
memcpy(&extension.signature, INDEX_EXT_UNMERGED_SIG, 4);
extension.extension_size = reuc_buf.size;
extension.extension_size = (uint32_t)reuc_buf.size;
error = write_extension(file, &extension, &reuc_buf);
......@@ -1529,10 +1534,8 @@ done:
static int write_index(git_index *index, git_filebuf *file)
{
git_oid hash_final;
struct index_header header;
int is_extended;
bool is_extended;
assert(index && file);
......@@ -1599,11 +1602,11 @@ static int read_tree_cb(const char *root, const git_tree_entry *tentry, void *da
return 0;
}
int git_index_read_tree(git_index *index, git_tree *tree)
int git_index_read_tree(git_index *index, const git_tree *tree)
{
git_index_clear(index);
return git_tree_walk(tree, read_tree_cb, GIT_TREEWALK_POST, index);
return git_tree_walk(tree, GIT_TREEWALK_POST, read_tree_cb, index);
}
git_repository *git_index_owner(const git_index *index)
......
......@@ -43,7 +43,7 @@ struct git_index {
extern void git_index_entry__init_from_stat(git_index_entry *entry, struct stat *st);
extern unsigned int git_index__prefix_position(git_index *index, const char *path);
extern size_t git_index__prefix_position(git_index *index, const char *path);
extern int git_index_entry__cmp(const void *a, const void *b);
extern int git_index_entry__cmp_icase(const void *a, const void *b);
......
......@@ -56,12 +56,12 @@ struct delta_info {
git_off_t delta_off;
};
const git_oid *git_indexer_hash(git_indexer *idx)
const git_oid *git_indexer_hash(const git_indexer *idx)
{
return &idx->hash;
}
const git_oid *git_indexer_stream_hash(git_indexer_stream *idx)
const git_oid *git_indexer_stream_hash(const git_indexer_stream *idx)
{
return &idx->hash;
}
......
......@@ -85,7 +85,7 @@ struct tree_iterator_frame {
tree_iterator_frame *next, *prev;
git_tree *tree;
char *start;
unsigned int index;
size_t index;
};
typedef struct {
......@@ -329,7 +329,7 @@ int git_iterator_for_tree_range(
typedef struct {
git_iterator base;
git_index *index;
unsigned int current;
size_t current;
bool free_index;
} index_iterator;
......@@ -337,7 +337,7 @@ static int index_iterator__current(
git_iterator *self, const git_index_entry **entry)
{
index_iterator *ii = (index_iterator *)self;
git_index_entry *ie = git_index_get_byindex(ii->index, ii->current);
const git_index_entry *ie = git_index_get_byindex(ii->index, ii->current);
if (ie != NULL &&
ii->base.end != NULL &&
......@@ -434,7 +434,7 @@ typedef struct workdir_iterator_frame workdir_iterator_frame;
struct workdir_iterator_frame {
workdir_iterator_frame *next;
git_vector entries;
unsigned int index;
size_t index;
char *start;
};
......@@ -761,7 +761,8 @@ static int spoolandsort_iterator__current(
spoolandsort_iterator *si = (spoolandsort_iterator *)self;
if (si->position < si->entries.length)
*entry = (const git_index_entry *)git_vector_get_const(&si->entries, si->position);
*entry = (const git_index_entry *)git_vector_get(
&si->entries, si->position);
else
*entry = NULL;
......@@ -781,7 +782,8 @@ static int spoolandsort_iterator__advance(
spoolandsort_iterator *si = (spoolandsort_iterator *)self;
if (si->position < si->entries.length)
*entry = (const git_index_entry *)git_vector_get_const(&si->entries, ++si->position);
*entry = (const git_index_entry *)git_vector_get(
&si->entries, ++si->position);
else
*entry = NULL;
......
......@@ -6,12 +6,14 @@
*/
#include "repository.h"
#include "revwalk.h"
#include "buffer.h"
#include "merge.h"
#include "refs.h"
#include "git2/repository.h"
#include "git2/merge.h"
#include "git2/reset.h"
#include "commit_list.h"
int git_merge__cleanup(git_repository *repo)
{
......@@ -46,3 +48,197 @@ cleanup:
return error;
}
int git_merge_base_many(git_oid *out, git_repository *repo, const git_oid input_array[], size_t length)
{
git_revwalk *walk;
git_vector list;
git_commit_list *result = NULL;
int error = -1;
unsigned int i;
git_commit_list_node *commit;
assert(out && repo && input_array);
if (length < 2) {
giterr_set(GITERR_INVALID, "At least two commits are required to find an ancestor. Provided 'length' was %u.", length);
return -1;
}
if (git_vector_init(&list, length - 1, NULL) < 0)
return -1;
if (git_revwalk_new(&walk, repo) < 0)
goto cleanup;
for (i = 1; i < length; i++) {
commit = commit_lookup(walk, &input_array[i]);
if (commit == NULL)
goto cleanup;
git_vector_insert(&list, commit);
}
commit = commit_lookup(walk, &input_array[0]);
if (commit == NULL)
goto cleanup;
if (git_merge__bases_many(&result, walk, commit, &list) < 0)
goto cleanup;
if (!result) {
error = GIT_ENOTFOUND;
goto cleanup;
}
git_oid_cpy(out, &result->item->oid);
error = 0;
cleanup:
git_commit_list_free(&result);
git_revwalk_free(walk);
git_vector_free(&list);
return error;
}
int git_merge_base(git_oid *out, git_repository *repo, const git_oid *one, const git_oid *two)
{
git_revwalk *walk;
git_vector list;
git_commit_list *result = NULL;
git_commit_list_node *commit;
void *contents[1];
if (git_revwalk_new(&walk, repo) < 0)
return -1;
commit = commit_lookup(walk, two);
if (commit == NULL)
goto on_error;
/* This is just one value, so we can do it on the stack */
memset(&list, 0x0, sizeof(git_vector));
contents[0] = commit;
list.length = 1;
list.contents = contents;
commit = commit_lookup(walk, one);
if (commit == NULL)
goto on_error;
if (git_merge__bases_many(&result, walk, commit, &list) < 0)
goto on_error;
if (!result) {
git_revwalk_free(walk);
giterr_clear();
return GIT_ENOTFOUND;
}
git_oid_cpy(out, &result->item->oid);
git_commit_list_free(&result);
git_revwalk_free(walk);
return 0;
on_error:
git_revwalk_free(walk);
return -1;
}
static int interesting(git_pqueue *list)
{
unsigned int i;
/* element 0 isn't used - we need to start at 1 */
for (i = 1; i < list->size; i++) {
git_commit_list_node *commit = list->d[i];
if ((commit->flags & STALE) == 0)
return 1;
}
return 0;
}
int git_merge__bases_many(git_commit_list **out, git_revwalk *walk, git_commit_list_node *one, git_vector *twos)
{
int error;
unsigned int i;
git_commit_list_node *two;
git_commit_list *result = NULL, *tmp = NULL;
git_pqueue list;
/* if the commit is repeated, we have a our merge base already */
git_vector_foreach(twos, i, two) {
if (one == two)
return git_commit_list_insert(one, out) ? 0 : -1;
}
if (git_pqueue_init(&list, twos->length * 2, git_commit_list_time_cmp) < 0)
return -1;
if (git_commit_list_parse(walk, one) < 0)
return -1;
one->flags |= PARENT1;
if (git_pqueue_insert(&list, one) < 0)
return -1;
git_vector_foreach(twos, i, two) {
git_commit_list_parse(walk, two);
two->flags |= PARENT2;
if (git_pqueue_insert(&list, two) < 0)
return -1;
}
/* as long as there are non-STALE commits */
while (interesting(&list)) {
git_commit_list_node *commit;
int flags;
commit = git_pqueue_pop(&list);
flags = commit->flags & (PARENT1 | PARENT2 | STALE);
if (flags == (PARENT1 | PARENT2)) {
if (!(commit->flags & RESULT)) {
commit->flags |= RESULT;
if (git_commit_list_insert(commit, &result) == NULL)
return -1;
}
/* we mark the parents of a merge stale */
flags |= STALE;
}
for (i = 0; i < commit->out_degree; i++) {
git_commit_list_node *p = commit->parents[i];
if ((p->flags & flags) == flags)
continue;
if ((error = git_commit_list_parse(walk, p)) < 0)
return error;
p->flags |= flags;
if (git_pqueue_insert(&list, p) < 0)
return -1;
}
}
git_pqueue_free(&list);
/* filter out any stale commits in the results */
tmp = result;
result = NULL;
while (tmp) {
struct git_commit_list *next = tmp->next;
if (!(tmp->item->flags & STALE))
if (git_commit_list_insert_by_date(tmp->item, &result) == NULL)
return -1;
git__free(tmp);
tmp = next;
}
*out = result;
return 0;
}
......@@ -8,6 +8,8 @@
#define INCLUDE_merge_h__
#include "git2/types.h"
#include "git2/merge.h"
#include "commit_list.h"
#define GIT_MERGE_MSG_FILE "MERGE_MSG"
#define GIT_MERGE_MODE_FILE "MERGE_MODE"
......@@ -15,5 +17,6 @@
#define MERGE_CONFIG_FILE_MODE 0666
int git_merge__cleanup(git_repository *repo);
int git_merge__bases_many(git_commit_list **out, git_revwalk *walk, git_commit_list_node *one, git_vector *twos);
#endif
......@@ -19,11 +19,11 @@ static int find_subtree_in_current_level(
const char *annotated_object_sha,
int fanout)
{
unsigned int i;
size_t i;
const git_tree_entry *entry;
*out = NULL;
if (parent == NULL)
return GIT_ENOTFOUND;
......@@ -34,12 +34,12 @@ static int find_subtree_in_current_level(
continue;
if (S_ISDIR(git_tree_entry_filemode(entry))
&& strlen(git_tree_entry_name(entry)) == 2
&& strlen(git_tree_entry_name(entry)) == 2
&& !strncmp(git_tree_entry_name(entry), annotated_object_sha + fanout, 2))
return git_tree_lookup(out, repo, git_tree_entry_id(entry));
/* Not a DIR, so do we have an already existing blob? */
if (!strcmp(git_tree_entry_name(entry), annotated_object_sha + fanout))
if (!strcmp(git_tree_entry_name(entry), annotated_object_sha + fanout))
return GIT_EEXISTS;
}
......@@ -71,7 +71,7 @@ static int find_subtree_r(git_tree **out, git_tree *root,
static int find_blob(git_oid *blob, git_tree *tree, const char *target)
{
unsigned int i;
size_t i;
const git_tree_entry *entry;
for (i=0; i<git_tree_entrycount(tree); i++) {
......@@ -263,8 +263,8 @@ static int insert_note_in_tree_enotfound_cb(git_tree **out,
static int note_write(git_oid *out,
git_repository *repo,
git_signature *author,
git_signature *committer,
const git_signature *author,
const git_signature *committer,
const char *notes_ref,
const char *note,
git_tree *commit_tree,
......@@ -343,9 +343,9 @@ cleanup:
}
static int note_remove(git_repository *repo,
git_signature *author, git_signature *committer,
const char *notes_ref, git_tree *tree,
const char *target, git_commit **parents)
const git_signature *author, const git_signature *committer,
const char *notes_ref, git_tree *tree,
const char *target, git_commit **parents)
{
int error;
git_tree *tree_after_removal = NULL;
......@@ -406,7 +406,7 @@ static int retrieve_note_tree_and_commit(
if ((error = normalize_namespace(notes_ref, repo)) < 0)
return error;
if ((error = git_reference_name_to_oid(&oid, repo, *notes_ref)) < 0)
if ((error = git_reference_name_to_id(&oid, repo, *notes_ref)) < 0)
return error;
if (git_commit_lookup(commit_out, repo, &oid) < 0)
......@@ -442,9 +442,12 @@ cleanup:
}
int git_note_create(
git_oid *out, git_repository *repo,
git_signature *author, git_signature *committer,
const char *notes_ref, const git_oid *oid,
git_oid *out,
git_repository *repo,
const git_signature *author,
const git_signature *committer,
const char *notes_ref,
const git_oid *oid,
const char *note)
{
int error;
......@@ -461,7 +464,7 @@ int git_note_create(
goto cleanup;
error = note_write(out, repo, author, committer, notes_ref,
note, tree, target, &commit);
note, tree, target, &commit);
cleanup:
git__free(target);
......@@ -471,8 +474,8 @@ cleanup:
}
int git_note_remove(git_repository *repo, const char *notes_ref,
git_signature *author, git_signature *committer,
const git_oid *oid)
const git_signature *author, const git_signature *committer,
const git_oid *oid)
{
int error;
char *target = NULL;
......@@ -501,13 +504,13 @@ int git_note_default_ref(const char **out, git_repository *repo)
return note_get_default_ref(out, repo);
}
const char * git_note_message(git_note *note)
const char * git_note_message(const git_note *note)
{
assert(note);
return note->message;
}
const git_oid * git_note_oid(git_note *note)
const git_oid * git_note_oid(const git_note *note)
{
assert(note);
return &note->oid;
......@@ -525,13 +528,13 @@ void git_note_free(git_note *note)
static int process_entry_path(
const char* entry_path,
const git_oid *note_oid,
int (*note_cb)(git_note_data *note_data, void *payload),
git_note_foreach_cb note_cb,
void *payload)
{
int error = -1;
size_t i = 0, j = 0, len;
git_buf buf = GIT_BUF_INIT;
git_note_data note_data;
git_oid annotated_object_id;
if ((error = git_buf_puts(&buf, entry_path)) < 0)
goto cleanup;
......@@ -564,13 +567,10 @@ static int process_entry_path(
goto cleanup;
}
if ((error = git_oid_fromstr(
&note_data.annotated_object_oid, buf.ptr)) < 0)
if ((error = git_oid_fromstr(&annotated_object_id, buf.ptr)) < 0)
goto cleanup;
git_oid_cpy(&note_data.blob_oid, note_oid);
if (note_cb(&note_data, payload))
if (note_cb(note_oid, &annotated_object_id, payload))
error = GIT_EUSER;
cleanup:
......@@ -581,7 +581,7 @@ cleanup:
int git_note_foreach(
git_repository *repo,
const char *notes_ref,
int (*note_cb)(git_note_data *note_data, void *payload),
git_note_foreach_cb note_cb,
void *payload)
{
int error;
......
This diff is collapsed. Click to expand it.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment