Commit cfbe4be3 by Vicent Marti Committed by Ben Straub

More external API cleanup

Conflicts:
	src/branch.c
	tests-clar/refs/branches/create.c
parent 2508cc66
...@@ -204,7 +204,7 @@ IF (BUILD_CLAR) ...@@ -204,7 +204,7 @@ IF (BUILD_CLAR)
ADD_CUSTOM_COMMAND( ADD_CUSTOM_COMMAND(
OUTPUT ${CLAR_PATH}/clar_main.c ${CLAR_PATH}/clar.h 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} DEPENDS ${CLAR_PATH}/clar ${SRC_TEST}
WORKING_DIRECTORY ${CLAR_PATH} WORKING_DIRECTORY ${CLAR_PATH}
) )
......
...@@ -183,6 +183,8 @@ GIT_EXTERN(int) git_attr_get_many( ...@@ -183,6 +183,8 @@ GIT_EXTERN(int) git_attr_get_many(
size_t num_attr, size_t num_attr,
const char **names); 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. * Loop over all the git attributes for a path.
* *
...@@ -204,7 +206,7 @@ GIT_EXTERN(int) git_attr_foreach( ...@@ -204,7 +206,7 @@ GIT_EXTERN(int) git_attr_foreach(
git_repository *repo, git_repository *repo,
uint32_t flags, uint32_t flags,
const char *path, const char *path,
int (*callback)(const char *name, const char *value, void *payload), git_attr_foreach_cb callback,
void *payload); void *payload);
/** /**
......
...@@ -68,6 +68,17 @@ GIT_INLINE(void) git_blob_free(git_blob *blob) ...@@ -68,6 +68,17 @@ GIT_INLINE(void) git_blob_free(git_blob *blob)
git_object_free((git_object *) 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. * 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); ...@@ -88,32 +99,35 @@ GIT_EXTERN(const void *) git_blob_rawcontent(git_blob *blob);
* @param blob pointer to the blob * @param blob pointer to the blob
* @return size on bytes * @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 * Read a file from the working folder of a repository
* and write it to the Object Database as a loose blob * 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. * @param repo repository where the blob will be written.
* this repository cannot be bare * 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 * relative to the repository's working dir
* @return 0 or an error code * @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 * Read a file from the filesystem and write its content
* to the Object Database as a loose blob * 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. * @param repo repository where the blob will be written.
* this repository can be bare or not * this repository can be bare or not
* @param path file from which the blob will be created * @param path file from which the blob will be created
* @return 0 or an error code * @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 * 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 ...@@ -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. * - 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. * @param repo repository where the blob will be written.
* This repository can be bare or not. * 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 ...@@ -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 * @return GIT_SUCCESS or an error code
*/ */
GIT_EXTERN(int) git_blob_create_fromchunks( GIT_EXTERN(int) git_blob_create_fromchunks(
git_oid *oid, git_oid *id,
git_repository *repo, git_repository *repo,
const char *hintpath, const char *hintpath,
int (*source_cb)(char *content, size_t max_length, void *payload), git_blob_chunk_cb callback,
void *payload); void *payload);
/** /**
......
...@@ -29,7 +29,7 @@ GIT_BEGIN_DECL ...@@ -29,7 +29,7 @@ GIT_BEGIN_DECL
* *
* The returned reference must be freed by the user. * 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 * @param branch_name Name for the branch; this name is
* validated for consistency. It should also not conflict with * validated for consistency. It should also not conflict with
...@@ -47,10 +47,10 @@ GIT_BEGIN_DECL ...@@ -47,10 +47,10 @@ GIT_BEGIN_DECL
* pointing to the provided target commit. * pointing to the provided target commit.
*/ */
GIT_EXTERN(int) git_branch_create( GIT_EXTERN(int) git_branch_create(
git_reference **branch_out, git_reference **out,
git_repository *repo, git_repository *repo,
const char *branch_name, const char *branch_name,
const git_object *target, const git_commit *target,
int force); int force);
/** /**
...@@ -113,7 +113,7 @@ GIT_EXTERN(int) git_branch_move( ...@@ -113,7 +113,7 @@ GIT_EXTERN(int) git_branch_move(
* *
* The generated reference must be freed by the user. * 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 * @param repo the repository to look up the branch
* *
...@@ -127,7 +127,7 @@ GIT_EXTERN(int) git_branch_move( ...@@ -127,7 +127,7 @@ GIT_EXTERN(int) git_branch_move(
* exists, otherwise an error code. * exists, otherwise an error code.
*/ */
GIT_EXTERN(int) git_branch_lookup( GIT_EXTERN(int) git_branch_lookup(
git_reference **branch_out, git_reference **out,
git_repository *repo, git_repository *repo,
const char *branch_name, const char *branch_name,
git_branch_t branch_type); git_branch_t branch_type);
...@@ -136,7 +136,7 @@ GIT_EXTERN(int) git_branch_lookup( ...@@ -136,7 +136,7 @@ GIT_EXTERN(int) git_branch_lookup(
* Return the reference supporting the remote tracking branch, * Return the reference supporting the remote tracking branch,
* given a local branch reference. * given a local branch reference.
* *
* @param tracking_out Pointer where to store the retrieved * @param out Pointer where to store the retrieved
* reference. * reference.
* *
* @param branch Current underlying reference of the branch. * @param branch Current underlying reference of the branch.
...@@ -145,7 +145,7 @@ GIT_EXTERN(int) git_branch_lookup( ...@@ -145,7 +145,7 @@ GIT_EXTERN(int) git_branch_lookup(
* reference exists, otherwise an error code. * reference exists, otherwise an error code.
*/ */
GIT_EXTERN(int) git_branch_tracking( GIT_EXTERN(int) git_branch_tracking(
git_reference **tracking_out, git_reference **out,
git_reference *branch); git_reference *branch);
/** /**
......
...@@ -146,8 +146,12 @@ typedef enum { ...@@ -146,8 +146,12 @@ typedef enum {
* Checkout options structure * Checkout options structure
* *
* Use zeros to indicate default settings. * 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 { typedef struct git_checkout_opts {
unsigned int version;
unsigned int checkout_strategy; /** default will be a dry run */ unsigned int checkout_strategy; /** default will be a dry run */
int disable_filters; /** don't apply filters like CRLF conversion */ int disable_filters; /** don't apply filters like CRLF conversion */
...@@ -182,6 +186,8 @@ typedef struct git_checkout_opts { ...@@ -182,6 +186,8 @@ typedef struct git_checkout_opts {
git_strarray paths; git_strarray paths;
} git_checkout_opts; } 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 * Updates files in the index and the working tree to match the content of the
* commit pointed at by HEAD. * commit pointed at by HEAD.
...@@ -223,7 +229,7 @@ GIT_EXTERN(int) git_checkout_index( ...@@ -223,7 +229,7 @@ GIT_EXTERN(int) git_checkout_index(
*/ */
GIT_EXTERN(int) git_checkout_tree( GIT_EXTERN(int) git_checkout_tree(
git_repository *repo, git_repository *repo,
git_object *treeish, const git_object *treeish,
git_checkout_opts *opts); git_checkout_opts *opts);
/** @} */ /** @} */
......
...@@ -42,9 +42,9 @@ GIT_EXTERN(int) git_clone( ...@@ -42,9 +42,9 @@ GIT_EXTERN(int) git_clone(
git_repository **out, git_repository **out,
const char *origin_url, const char *origin_url,
const char *workdir_path, const char *workdir_path,
git_checkout_opts *checkout_opts,
git_transfer_progress_callback fetch_progress_cb, git_transfer_progress_callback fetch_progress_cb,
void *fetch_progress_payload, void *fetch_progress_payload);
git_checkout_opts *checkout_opts);
/** /**
* Create a bare clone of a remote repository. * Create a bare clone of a remote repository.
......
...@@ -76,7 +76,10 @@ GIT_INLINE(void) git_commit_free(git_commit *commit) ...@@ -76,7 +76,10 @@ GIT_INLINE(void) git_commit_free(git_commit *commit)
* @param commit a previously loaded commit. * @param commit a previously loaded commit.
* @return object identity for the 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, * Get the encoding for the message of a commit,
...@@ -88,7 +91,7 @@ GIT_EXTERN(const git_oid *) git_commit_id(git_commit *commit); ...@@ -88,7 +91,7 @@ GIT_EXTERN(const git_oid *) git_commit_id(git_commit *commit);
* @param commit a previously loaded commit. * @param commit a previously loaded commit.
* @return NULL, or the encoding * @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. * Get the full message of a commit.
...@@ -96,7 +99,7 @@ GIT_EXTERN(const char *) git_commit_message_encoding(git_commit *commit); ...@@ -96,7 +99,7 @@ GIT_EXTERN(const char *) git_commit_message_encoding(git_commit *commit);
* @param commit a previously loaded commit. * @param commit a previously loaded commit.
* @return the message of a 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. * 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); ...@@ -104,7 +107,7 @@ GIT_EXTERN(const char *) git_commit_message(git_commit *commit);
* @param commit a previously loaded commit. * @param commit a previously loaded commit.
* @return the time of a 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. * 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); ...@@ -112,7 +115,7 @@ GIT_EXTERN(git_time_t) git_commit_time(git_commit *commit);
* @param commit a previously loaded commit. * @param commit a previously loaded commit.
* @return positive or negative timezone offset, in minutes from UTC * @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. * Get the committer of a commit.
...@@ -120,7 +123,7 @@ GIT_EXTERN(int) git_commit_time_offset(git_commit *commit); ...@@ -120,7 +123,7 @@ GIT_EXTERN(int) git_commit_time_offset(git_commit *commit);
* @param commit a previously loaded commit. * @param commit a previously loaded commit.
* @return the committer of a 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. * Get the author of a commit.
...@@ -128,7 +131,7 @@ GIT_EXTERN(const git_signature *) git_commit_committer(git_commit *commit); ...@@ -128,7 +131,7 @@ GIT_EXTERN(const git_signature *) git_commit_committer(git_commit *commit);
* @param commit a previously loaded commit. * @param commit a previously loaded commit.
* @return the author of a 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. * Get the tree pointed to by a commit.
...@@ -137,7 +140,7 @@ GIT_EXTERN(const git_signature *) git_commit_author(git_commit *commit); ...@@ -137,7 +140,7 @@ GIT_EXTERN(const git_signature *) git_commit_author(git_commit *commit);
* @param commit a previously loaded commit. * @param commit a previously loaded commit.
* @return 0 or an error code * @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 * 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); ...@@ -147,7 +150,7 @@ GIT_EXTERN(int) git_commit_tree(git_tree **tree_out, git_commit *commit);
* @param commit a previously loaded commit. * @param commit a previously loaded commit.
* @return the id of tree pointed to by 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 * Get the number of parents of this commit
...@@ -155,17 +158,17 @@ GIT_EXTERN(const git_oid *) git_commit_tree_oid(git_commit *commit); ...@@ -155,17 +158,17 @@ GIT_EXTERN(const git_oid *) git_commit_tree_oid(git_commit *commit);
* @param commit a previously loaded commit. * @param commit a previously loaded commit.
* @return integer of count of parents * @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. * 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 commit a previously loaded commit.
* @param n the position of the parent (from 0 to `parentcount`) * @param n the position of the parent (from 0 to `parentcount`)
* @return 0 or an error code * @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 * 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 ...@@ -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`) * @param n the position of the parent (from 0 to `parentcount`)
* @return the id of the parent, NULL on error. * @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 * Get the commit object that is the <n>th generation ancestor
...@@ -204,7 +207,7 @@ GIT_EXTERN(int) git_commit_nth_gen_ancestor( ...@@ -204,7 +207,7 @@ GIT_EXTERN(int) git_commit_nth_gen_ancestor(
* The message will not be cleaned up. This can be achieved * The message will not be cleaned up. This can be achieved
* through `git_message_prettify()`. * 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 * newly created commit
* *
* @param repo Repository where to store the commit * @param repo Repository where to store the commit
...@@ -245,7 +248,7 @@ GIT_EXTERN(int) git_commit_nth_gen_ancestor( ...@@ -245,7 +248,7 @@ GIT_EXTERN(int) git_commit_nth_gen_ancestor(
* the given reference will be updated to point to it * the given reference will be updated to point to it
*/ */
GIT_EXTERN(int) git_commit_create( GIT_EXTERN(int) git_commit_create(
git_oid *oid, git_oid *id,
git_repository *repo, git_repository *repo,
const char *update_ref, const char *update_ref,
const git_signature *author, const git_signature *author,
...@@ -273,7 +276,7 @@ GIT_EXTERN(int) git_commit_create( ...@@ -273,7 +276,7 @@ GIT_EXTERN(int) git_commit_create(
* @see git_commit_create * @see git_commit_create
*/ */
GIT_EXTERN(int) git_commit_create_v( GIT_EXTERN(int) git_commit_create_v(
git_oid *oid, git_oid *id,
git_repository *repo, git_repository *repo,
const char *update_ref, const char *update_ref,
const git_signature *author, const git_signature *author,
......
...@@ -106,6 +106,7 @@ typedef enum { ...@@ -106,6 +106,7 @@ typedef enum {
* - max_size: maximum blob size to diff, above this treated as binary * - max_size: maximum blob size to diff, above this treated as binary
*/ */
typedef struct { typedef struct {
unsigned int version; /**< version for the struct */
uint32_t flags; /**< defaults to GIT_DIFF_NORMAL */ uint32_t flags; /**< defaults to GIT_DIFF_NORMAL */
uint16_t context_lines; /**< defaults to 3 */ uint16_t context_lines; /**< defaults to 3 */
uint16_t interhunk_lines; /**< defaults to 0 */ uint16_t interhunk_lines; /**< defaults to 0 */
...@@ -186,7 +187,7 @@ typedef struct { ...@@ -186,7 +187,7 @@ typedef struct {
/** /**
* When iterating over a diff, callback that will be made per file. * When iterating over a diff, callback that will be made per file.
*/ */
typedef int (*git_diff_file_fn)( typedef int (*git_diff_file_cb)(
void *cb_data, void *cb_data,
const git_diff_delta *delta, const git_diff_delta *delta,
float progress); float progress);
...@@ -204,7 +205,7 @@ typedef struct { ...@@ -204,7 +205,7 @@ typedef struct {
/** /**
* When iterating over a diff, callback that will be made per hunk. * When iterating over a diff, callback that will be made per hunk.
*/ */
typedef int (*git_diff_hunk_fn)( typedef int (*git_diff_hunk_cb)(
void *cb_data, void *cb_data,
const git_diff_delta *delta, const git_diff_delta *delta,
const git_diff_range *range, const git_diff_range *range,
...@@ -215,20 +216,20 @@ typedef int (*git_diff_hunk_fn)( ...@@ -215,20 +216,20 @@ typedef int (*git_diff_hunk_fn)(
* Line origin constants. * Line origin constants.
* *
* These values describe where a line came from and will be passed to * 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 * special origin constants at the end that are used for the text
* output callbacks to demarcate lines that are actually part of * output callbacks to demarcate lines that are actually part of
* the file or hunk headers. * the file or hunk headers.
*/ */
typedef enum { 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_CONTEXT = ' ',
GIT_DIFF_LINE_ADDITION = '+', GIT_DIFF_LINE_ADDITION = '+',
GIT_DIFF_LINE_DELETION = '-', GIT_DIFF_LINE_DELETION = '-',
GIT_DIFF_LINE_ADD_EOFNL = '\n', /**< Removed line w/o LF & added one with */ GIT_DIFF_LINE_ADD_EOFNL = '\n', /**< Removed line w/o LF & added one with */
GIT_DIFF_LINE_DEL_EOFNL = '\0', /**< LF was removed at end of file */ GIT_DIFF_LINE_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 * the content of a diff is being formatted (eg. through
* git_diff_print_patch() or git_diff_print_compact(), for instance). * git_diff_print_patch() or git_diff_print_compact(), for instance).
*/ */
...@@ -245,7 +246,7 @@ typedef enum { ...@@ -245,7 +246,7 @@ typedef enum {
* of text. This uses some extra GIT_DIFF_LINE_... constants for output * of text. This uses some extra GIT_DIFF_LINE_... constants for output
* of lines of file and hunk headers. * of lines of file and hunk headers.
*/ */
typedef int (*git_diff_data_fn)( typedef int (*git_diff_data_cb)(
void *cb_data, void *cb_data,
const git_diff_delta *delta, const git_diff_delta *delta,
const git_diff_range *range, const git_diff_range *range,
...@@ -474,9 +475,9 @@ GIT_EXTERN(int) git_diff_find_similar( ...@@ -474,9 +475,9 @@ GIT_EXTERN(int) git_diff_find_similar(
GIT_EXTERN(int) git_diff_foreach( GIT_EXTERN(int) git_diff_foreach(
git_diff_list *diff, git_diff_list *diff,
void *cb_data, void *cb_data,
git_diff_file_fn file_cb, git_diff_file_cb file_cb,
git_diff_hunk_fn hunk_cb, git_diff_hunk_cb hunk_cb,
git_diff_data_fn line_cb); git_diff_data_cb line_cb);
/** /**
* Iterate over a diff generating text output like "git diff --name-status". * Iterate over a diff generating text output like "git diff --name-status".
...@@ -492,7 +493,7 @@ GIT_EXTERN(int) git_diff_foreach( ...@@ -492,7 +493,7 @@ GIT_EXTERN(int) git_diff_foreach(
GIT_EXTERN(int) git_diff_print_compact( GIT_EXTERN(int) git_diff_print_compact(
git_diff_list *diff, git_diff_list *diff,
void *cb_data, void *cb_data,
git_diff_data_fn print_cb); git_diff_data_cb print_cb);
/** /**
* Look up the single character abbreviation for a delta status code. * Look up the single character abbreviation for a delta status code.
...@@ -528,7 +529,7 @@ GIT_EXTERN(char) git_diff_status_char(git_delta_t status); ...@@ -528,7 +529,7 @@ GIT_EXTERN(char) git_diff_status_char(git_delta_t status);
GIT_EXTERN(int) git_diff_print_patch( GIT_EXTERN(int) git_diff_print_patch(
git_diff_list *diff, git_diff_list *diff,
void *cb_data, void *cb_data,
git_diff_data_fn print_cb); git_diff_data_cb print_cb);
/** /**
* Query how many diff records are there in a diff list. * Query how many diff records are there in a diff list.
...@@ -680,7 +681,7 @@ GIT_EXTERN(int) git_diff_patch_get_line_in_hunk( ...@@ -680,7 +681,7 @@ GIT_EXTERN(int) git_diff_patch_get_line_in_hunk(
GIT_EXTERN(int) git_diff_patch_print( GIT_EXTERN(int) git_diff_patch_print(
git_diff_patch *patch, git_diff_patch *patch,
void *cb_data, void *cb_data,
git_diff_data_fn print_cb); git_diff_data_cb print_cb);
/** /**
* Get the content of a patch as a single diff text. * Get the content of a patch as a single diff text.
...@@ -719,9 +720,9 @@ GIT_EXTERN(int) git_diff_blobs( ...@@ -719,9 +720,9 @@ GIT_EXTERN(int) git_diff_blobs(
git_blob *new_blob, git_blob *new_blob,
const git_diff_options *options, const git_diff_options *options,
void *cb_data, void *cb_data,
git_diff_file_fn file_cb, git_diff_file_cb file_cb,
git_diff_hunk_fn hunk_cb, git_diff_hunk_cb hunk_cb,
git_diff_data_fn line_cb); git_diff_data_cb line_cb);
GIT_END_DECL GIT_END_DECL
......
...@@ -184,7 +184,7 @@ GIT_EXTERN(size_t) git_object__size(git_otype type); ...@@ -184,7 +184,7 @@ GIT_EXTERN(size_t) git_object__size(git_otype type);
*/ */
GIT_EXTERN(int) git_object_peel( GIT_EXTERN(int) git_object_peel(
git_object **peeled, git_object **peeled,
git_object *object, const git_object *object,
git_otype target_type); git_otype target_type);
/** @} */ /** @} */
......
...@@ -19,10 +19,10 @@ const void *git_blob_rawcontent(git_blob *blob) ...@@ -19,10 +19,10 @@ const void *git_blob_rawcontent(git_blob *blob)
return blob->odb_object->raw.data; 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); 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) 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 * ...@@ -205,7 +205,7 @@ static int blob_create_internal(git_oid *oid, git_repository *repo, const char *
return error; 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; git_buf full_path = GIT_BUF_INIT;
const char *workdir; const char *workdir;
......
...@@ -44,12 +44,6 @@ cleanup: ...@@ -44,12 +44,6 @@ cleanup:
return error; 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) static int not_a_local_branch(git_reference *ref)
{ {
giterr_set(GITERR_INVALID, "Reference '%s' is not a local branch.", git_reference_name(ref)); giterr_set(GITERR_INVALID, "Reference '%s' is not a local branch.", git_reference_name(ref));
...@@ -60,31 +54,26 @@ int git_branch_create( ...@@ -60,31 +54,26 @@ int git_branch_create(
git_reference **ref_out, git_reference **ref_out,
git_repository *repository, git_repository *repository,
const char *branch_name, const char *branch_name,
const git_object *target, const git_commit *commit,
int force) int force)
{ {
git_object *commit = NULL;
git_reference *branch = NULL; git_reference *branch = NULL;
git_buf canonical_branch_name = GIT_BUF_INIT; git_buf canonical_branch_name = GIT_BUF_INIT;
int error = -1; int error = -1;
assert(branch_name && target && ref_out); assert(branch_name && commit && ref_out);
assert(git_object_owner(target) == repository); assert(git_object_owner((const git_object *)commit) == 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");
if (git_buf_joinpath(&canonical_branch_name, GIT_REFS_HEADS_DIR, branch_name) < 0) if (git_buf_joinpath(&canonical_branch_name, GIT_REFS_HEADS_DIR, branch_name) < 0)
goto cleanup; goto cleanup;
error = git_reference_create(&branch, repository, error = git_reference_create(&branch, repository,
git_buf_cstr(&canonical_branch_name), git_object_id(commit), force); git_buf_cstr(&canonical_branch_name), git_commit_id(commit), force);
if (!error) if (!error)
*ref_out = branch; *ref_out = branch;
cleanup: cleanup:
git_object_free(commit);
git_buf_free(&canonical_branch_name); git_buf_free(&canonical_branch_name);
return error; return error;
} }
......
...@@ -693,7 +693,7 @@ cleanup: ...@@ -693,7 +693,7 @@ cleanup:
int git_checkout_tree( int git_checkout_tree(
git_repository *repo, git_repository *repo,
git_object *treeish, const git_object *treeish,
git_checkout_opts *opts) git_checkout_opts *opts)
{ {
int error = 0; int error = 0;
......
...@@ -28,18 +28,18 @@ static int create_branch( ...@@ -28,18 +28,18 @@ static int create_branch(
const git_oid *target, const git_oid *target,
const char *name) const char *name)
{ {
git_object *head_obj = NULL; git_commit *head_obj = NULL;
git_reference *branch_ref; git_reference *branch_ref;
int error; int error;
/* Find the target commit */ /* 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; return error;
/* Create the new branch */ /* Create the new branch */
error = git_branch_create(&branch_ref, repo, name, head_obj, 0); error = git_branch_create(&branch_ref, repo, name, head_obj, 0);
git_object_free(head_obj); git_commit_free(head_obj);
if (!error) if (!error)
*branch = branch_ref; *branch = branch_ref;
...@@ -381,9 +381,9 @@ int git_clone( ...@@ -381,9 +381,9 @@ int git_clone(
git_repository **out, git_repository **out,
const char *origin_url, const char *origin_url,
const char *workdir_path, const char *workdir_path,
git_checkout_opts *checkout_opts,
git_transfer_progress_callback fetch_progress_cb, git_transfer_progress_callback fetch_progress_cb,
void *fetch_progress_payload, void *fetch_progress_payload)
git_checkout_opts *checkout_opts)
{ {
assert(out && origin_url && workdir_path); assert(out && origin_url && workdir_path);
......
...@@ -22,18 +22,18 @@ static void clear_parents(git_commit *commit) ...@@ -22,18 +22,18 @@ static void clear_parents(git_commit *commit)
{ {
unsigned int i; unsigned int i;
for (i = 0; i < commit->parent_oids.length; ++i) { for (i = 0; i < commit->parent_ids.length; ++i) {
git_oid *parent = git_vector_get(&commit->parent_oids, i); git_oid *parent = git_vector_get(&commit->parent_ids, i);
git__free(parent); git__free(parent);
} }
git_vector_clear(&commit->parent_oids); git_vector_clear(&commit->parent_ids);
} }
void git_commit__free(git_commit *commit) void git_commit__free(git_commit *commit)
{ {
clear_parents(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->author);
git_signature_free(commit->committer); git_signature_free(commit->committer);
...@@ -43,11 +43,6 @@ void git_commit__free(git_commit *commit) ...@@ -43,11 +43,6 @@ void git_commit__free(git_commit *commit)
git__free(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( int git_commit_create_v(
git_oid *oid, git_oid *oid,
git_repository *repo, git_repository *repo,
...@@ -141,26 +136,26 @@ int git_commit__parse_buffer(git_commit *commit, const void *data, size_t len) ...@@ -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 = data;
const char *buffer_end = (const char *)data + len; 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; goto bad_buffer;
/* /*
* TODO: commit grafts! * TODO: commit grafts!
*/ */
while (git_oid__parse(&parent_oid, &buffer, buffer_end, "parent ") == 0) { while (git_oid__parse(&parent_id, &buffer, buffer_end, "parent ") == 0) {
git_oid *new_oid; git_oid *new_id;
new_oid = git__malloc(sizeof(git_oid)); new_id = git__malloc(sizeof(git_oid));
GITERR_CHECK_ALLOC(new_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; return -1;
} }
...@@ -214,7 +209,7 @@ int git_commit__parse(git_commit *commit, git_odb_object *obj) ...@@ -214,7 +209,7 @@ int git_commit__parse(git_commit *commit, git_odb_object *obj)
} }
#define GIT_COMMIT_GETTER(_rvalue, _name, _return) \ #define GIT_COMMIT_GETTER(_rvalue, _name, _return) \
_rvalue git_commit_##_name(git_commit *commit) \ _rvalue git_commit_##_name(const git_commit *commit) \
{\ {\
assert(commit); \ assert(commit); \
return _return; \ return _return; \
...@@ -226,34 +221,34 @@ GIT_COMMIT_GETTER(const char *, message, commit->message) ...@@ -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(const char *, message_encoding, commit->message_encoding)
GIT_COMMIT_GETTER(git_time_t, time, commit->committer->when.time) GIT_COMMIT_GETTER(git_time_t, time, commit->committer->when.time)
GIT_COMMIT_GETTER(int, time_offset, commit->committer->when.offset) 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(unsigned int, parentcount, (unsigned int)commit->parent_ids.length)
GIT_COMMIT_GETTER(const git_oid *, tree_oid, &commit->tree_oid); 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); 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); 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) 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); assert(commit);
parent_oid = git_commit_parent_oid(commit, n); parent_id = git_commit_parent_id(commit, n);
if (parent_oid == NULL) { if (parent_id == NULL) {
giterr_set(GITERR_INVALID, "Parent %u does not exist", n); giterr_set(GITERR_INVALID, "Parent %u does not exist", n);
return GIT_ENOTFOUND; 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( int git_commit_nth_gen_ancestor(
......
...@@ -17,8 +17,8 @@ ...@@ -17,8 +17,8 @@
struct git_commit { struct git_commit {
git_object object; git_object object;
git_vector parent_oids; git_vector parent_ids;
git_oid tree_oid; git_oid tree_id;
git_signature *author; git_signature *author;
git_signature *committer; git_signature *committer;
......
...@@ -441,9 +441,9 @@ static void diff_context_init( ...@@ -441,9 +441,9 @@ static void diff_context_init(
git_repository *repo, git_repository *repo,
const git_diff_options *opts, const git_diff_options *opts,
void *data, void *data,
git_diff_file_fn file_cb, git_diff_file_cb file_cb,
git_diff_hunk_fn hunk_cb, git_diff_hunk_cb hunk_cb,
git_diff_data_fn data_cb) git_diff_data_cb data_cb)
{ {
memset(ctxt, 0, sizeof(diff_context)); memset(ctxt, 0, sizeof(diff_context));
...@@ -905,9 +905,9 @@ static int diff_patch_line_cb( ...@@ -905,9 +905,9 @@ static int diff_patch_line_cb(
int git_diff_foreach( int git_diff_foreach(
git_diff_list *diff, git_diff_list *diff,
void *cb_data, void *cb_data,
git_diff_file_fn file_cb, git_diff_file_cb file_cb,
git_diff_hunk_fn hunk_cb, git_diff_hunk_cb hunk_cb,
git_diff_data_fn data_cb) git_diff_data_cb data_cb)
{ {
int error = 0; int error = 0;
diff_context ctxt; diff_context ctxt;
...@@ -951,7 +951,7 @@ int git_diff_foreach( ...@@ -951,7 +951,7 @@ int git_diff_foreach(
typedef struct { typedef struct {
git_diff_list *diff; git_diff_list *diff;
git_diff_data_fn print_cb; git_diff_data_cb print_cb;
void *cb_data; void *cb_data;
git_buf *buf; git_buf *buf;
} diff_print_info; } diff_print_info;
...@@ -1030,7 +1030,7 @@ static int print_compact( ...@@ -1030,7 +1030,7 @@ static int print_compact(
int git_diff_print_compact( int git_diff_print_compact(
git_diff_list *diff, git_diff_list *diff,
void *cb_data, void *cb_data,
git_diff_data_fn print_cb) git_diff_data_cb print_cb)
{ {
int error; int error;
git_buf buf = GIT_BUF_INIT; git_buf buf = GIT_BUF_INIT;
...@@ -1211,7 +1211,7 @@ static int print_patch_line( ...@@ -1211,7 +1211,7 @@ static int print_patch_line(
int git_diff_print_patch( int git_diff_print_patch(
git_diff_list *diff, git_diff_list *diff,
void *cb_data, void *cb_data,
git_diff_data_fn print_cb) git_diff_data_cb print_cb)
{ {
int error; int error;
git_buf buf = GIT_BUF_INIT; git_buf buf = GIT_BUF_INIT;
...@@ -1251,9 +1251,9 @@ int git_diff_blobs( ...@@ -1251,9 +1251,9 @@ int git_diff_blobs(
git_blob *new_blob, git_blob *new_blob,
const git_diff_options *options, const git_diff_options *options,
void *cb_data, void *cb_data,
git_diff_file_fn file_cb, git_diff_file_cb file_cb,
git_diff_hunk_fn hunk_cb, git_diff_hunk_cb hunk_cb,
git_diff_data_fn data_cb) git_diff_data_cb data_cb)
{ {
int error; int error;
git_repository *repo; git_repository *repo;
...@@ -1518,7 +1518,7 @@ static int print_to_buffer_cb( ...@@ -1518,7 +1518,7 @@ static int print_to_buffer_cb(
int git_diff_patch_print( int git_diff_patch_print(
git_diff_patch *patch, git_diff_patch *patch,
void *cb_data, void *cb_data,
git_diff_data_fn print_cb) git_diff_data_cb print_cb)
{ {
int error; int error;
git_buf temp = GIT_BUF_INIT; git_buf temp = GIT_BUF_INIT;
......
...@@ -27,9 +27,9 @@ typedef struct { ...@@ -27,9 +27,9 @@ typedef struct {
git_repository *repo; git_repository *repo;
git_diff_list *diff; git_diff_list *diff;
const git_diff_options *opts; const git_diff_options *opts;
git_diff_file_fn file_cb; git_diff_file_cb file_cb;
git_diff_hunk_fn hunk_cb; git_diff_hunk_cb hunk_cb;
git_diff_data_fn data_cb; git_diff_data_cb data_cb;
void *cb_data; void *cb_data;
int cb_error; int cb_error;
git_diff_range cb_range; git_diff_range cb_range;
......
...@@ -580,7 +580,7 @@ static int index_entry_init(git_index_entry **entry_out, git_index *index, const ...@@ -580,7 +580,7 @@ static int index_entry_init(git_index_entry **entry_out, git_index *index, const
*/ */
/* write the blob to disk and get the oid */ /* 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; return error;
entry = git__calloc(1, sizeof(git_index_entry)); entry = git__calloc(1, sizeof(git_index_entry));
......
...@@ -334,7 +334,7 @@ static int dereference_object(git_object **dereferenced, git_object *obj) ...@@ -334,7 +334,7 @@ static int dereference_object(git_object **dereferenced, git_object *obj)
int git_object_peel( int git_object_peel(
git_object **peeled, git_object **peeled,
git_object *object, const git_object *object,
git_otype target_type) git_otype target_type)
{ {
git_object *source, *deref = NULL; git_object *source, *deref = NULL;
...@@ -342,9 +342,9 @@ int git_object_peel( ...@@ -342,9 +342,9 @@ int git_object_peel(
assert(object && peeled); assert(object && peeled);
if (git_object_type(object) == target_type) if (git_object_type(object) == target_type)
return git_object__dup(peeled, object); return git_object__dup(peeled, (git_object *)object);
source = object; source = (git_object *)object;
while (!dereference_object(&deref, source)) { while (!dereference_object(&deref, source)) {
......
...@@ -306,7 +306,7 @@ static int local_download_pack( ...@@ -306,7 +306,7 @@ static int local_download_pack(
if (git_odb_exists(odb, &oid)) continue; if (git_odb_exists(odb, &oid)) continue;
if (!git_object_lookup((git_object**)&commit, t->repo, &oid, GIT_OBJ_COMMIT)) { if (!git_object_lookup((git_object**)&commit, t->repo, &oid, GIT_OBJ_COMMIT)) {
const git_oid *tree_oid = git_commit_tree_oid(commit); const git_oid *tree_oid = git_commit_tree_id(commit);
git_commit_free(commit); git_commit_free(commit);
/* Add the commit and its tree */ /* Add the commit and its tree */
......
...@@ -109,7 +109,7 @@ static void fetch_progress(const git_transfer_progress *stats, void *payload) ...@@ -109,7 +109,7 @@ static void fetch_progress(const git_transfer_progress *stats, void *payload)
void test_clone_network__can_checkout_a_cloned_repo(void) void test_clone_network__can_checkout_a_cloned_repo(void)
{ {
git_checkout_opts opts = {0}; git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
git_buf path = GIT_BUF_INIT; git_buf path = GIT_BUF_INIT;
git_reference *head; git_reference *head;
bool checkout_progress_cb_was_called = false, bool checkout_progress_cb_was_called = false,
...@@ -121,8 +121,8 @@ void test_clone_network__can_checkout_a_cloned_repo(void) ...@@ -121,8 +121,8 @@ void test_clone_network__can_checkout_a_cloned_repo(void)
cl_set_cleanup(&cleanup_repository, "./default-checkout"); cl_set_cleanup(&cleanup_repository, "./default-checkout");
cl_git_pass(git_clone(&g_repo, LIVE_REPO_URL, "./default-checkout", cl_git_pass(git_clone(&g_repo, LIVE_REPO_URL, "./default-checkout", &opts,
&fetch_progress, &fetch_progress_cb_was_called, &opts)); &fetch_progress, &fetch_progress_cb_was_called));
cl_git_pass(git_buf_joinpath(&path, git_repository_workdir(g_repo), "master.txt")); cl_git_pass(git_buf_joinpath(&path, git_repository_workdir(g_repo), "master.txt"));
cl_assert_equal_i(true, git_path_isfile(git_buf_cstr(&path))); cl_assert_equal_i(true, git_path_isfile(git_buf_cstr(&path)));
......
...@@ -59,7 +59,7 @@ void test_diff_blob__can_compare_text_blobs(void) ...@@ -59,7 +59,7 @@ void test_diff_blob__can_compare_text_blobs(void)
/* diff on tests/resources/attr/root_test1 */ /* diff on tests/resources/attr/root_test1 */
cl_git_pass(git_diff_blobs( cl_git_pass(git_diff_blobs(
a, b, &opts, &expected, diff_file_fn, diff_hunk_fn, diff_line_fn)); a, b, &opts, &expected, diff_file_cb, diff_hunk_cb, diff_line_cb));
cl_assert_equal_i(1, expected.files); cl_assert_equal_i(1, expected.files);
cl_assert_equal_i(1, expected.file_status[GIT_DELTA_MODIFIED]); cl_assert_equal_i(1, expected.file_status[GIT_DELTA_MODIFIED]);
...@@ -74,7 +74,7 @@ void test_diff_blob__can_compare_text_blobs(void) ...@@ -74,7 +74,7 @@ void test_diff_blob__can_compare_text_blobs(void)
/* diff on tests/resources/attr/root_test2 */ /* diff on tests/resources/attr/root_test2 */
memset(&expected, 0, sizeof(expected)); memset(&expected, 0, sizeof(expected));
cl_git_pass(git_diff_blobs( cl_git_pass(git_diff_blobs(
b, c, &opts, &expected, diff_file_fn, diff_hunk_fn, diff_line_fn)); b, c, &opts, &expected, diff_file_cb, diff_hunk_cb, diff_line_cb));
cl_assert_equal_i(1, expected.files); cl_assert_equal_i(1, expected.files);
cl_assert_equal_i(1, expected.file_status[GIT_DELTA_MODIFIED]); cl_assert_equal_i(1, expected.file_status[GIT_DELTA_MODIFIED]);
...@@ -89,7 +89,7 @@ void test_diff_blob__can_compare_text_blobs(void) ...@@ -89,7 +89,7 @@ void test_diff_blob__can_compare_text_blobs(void)
/* diff on tests/resources/attr/root_test3 */ /* diff on tests/resources/attr/root_test3 */
memset(&expected, 0, sizeof(expected)); memset(&expected, 0, sizeof(expected));
cl_git_pass(git_diff_blobs( cl_git_pass(git_diff_blobs(
a, c, &opts, &expected, diff_file_fn, diff_hunk_fn, diff_line_fn)); a, c, &opts, &expected, diff_file_cb, diff_hunk_cb, diff_line_cb));
cl_assert_equal_i(1, expected.files); cl_assert_equal_i(1, expected.files);
cl_assert_equal_i(1, expected.file_status[GIT_DELTA_MODIFIED]); cl_assert_equal_i(1, expected.file_status[GIT_DELTA_MODIFIED]);
...@@ -103,7 +103,7 @@ void test_diff_blob__can_compare_text_blobs(void) ...@@ -103,7 +103,7 @@ void test_diff_blob__can_compare_text_blobs(void)
memset(&expected, 0, sizeof(expected)); memset(&expected, 0, sizeof(expected));
cl_git_pass(git_diff_blobs( cl_git_pass(git_diff_blobs(
c, d, &opts, &expected, diff_file_fn, diff_hunk_fn, diff_line_fn)); c, d, &opts, &expected, diff_file_cb, diff_hunk_cb, diff_line_cb));
cl_assert_equal_i(1, expected.files); cl_assert_equal_i(1, expected.files);
cl_assert_equal_i(1, expected.file_status[GIT_DELTA_MODIFIED]); cl_assert_equal_i(1, expected.file_status[GIT_DELTA_MODIFIED]);
...@@ -125,7 +125,7 @@ void test_diff_blob__can_compare_against_null_blobs(void) ...@@ -125,7 +125,7 @@ void test_diff_blob__can_compare_against_null_blobs(void)
git_blob *e = NULL; git_blob *e = NULL;
cl_git_pass(git_diff_blobs( cl_git_pass(git_diff_blobs(
d, e, &opts, &expected, diff_file_fn, diff_hunk_fn, diff_line_fn)); d, e, &opts, &expected, diff_file_cb, diff_hunk_cb, diff_line_cb));
cl_assert_equal_i(1, expected.files); cl_assert_equal_i(1, expected.files);
cl_assert_equal_i(1, expected.file_status[GIT_DELTA_DELETED]); cl_assert_equal_i(1, expected.file_status[GIT_DELTA_DELETED]);
...@@ -140,7 +140,7 @@ void test_diff_blob__can_compare_against_null_blobs(void) ...@@ -140,7 +140,7 @@ void test_diff_blob__can_compare_against_null_blobs(void)
memset(&expected, 0, sizeof(expected)); memset(&expected, 0, sizeof(expected));
cl_git_pass(git_diff_blobs( cl_git_pass(git_diff_blobs(
d, e, &opts, &expected, diff_file_fn, diff_hunk_fn, diff_line_fn)); d, e, &opts, &expected, diff_file_cb, diff_hunk_cb, diff_line_cb));
cl_assert_equal_i(1, expected.files); cl_assert_equal_i(1, expected.files);
cl_assert_equal_i(1, expected.file_status[GIT_DELTA_ADDED]); cl_assert_equal_i(1, expected.file_status[GIT_DELTA_ADDED]);
...@@ -155,7 +155,7 @@ void test_diff_blob__can_compare_against_null_blobs(void) ...@@ -155,7 +155,7 @@ void test_diff_blob__can_compare_against_null_blobs(void)
memset(&expected, 0, sizeof(expected)); memset(&expected, 0, sizeof(expected));
cl_git_pass(git_diff_blobs( cl_git_pass(git_diff_blobs(
alien, NULL, &opts, &expected, diff_file_fn, diff_hunk_fn, diff_line_fn)); alien, NULL, &opts, &expected, diff_file_cb, diff_hunk_cb, diff_line_cb));
cl_assert_equal_i(1, expected.files); cl_assert_equal_i(1, expected.files);
cl_assert_equal_i(1, expected.files_binary); cl_assert_equal_i(1, expected.files_binary);
...@@ -166,7 +166,7 @@ void test_diff_blob__can_compare_against_null_blobs(void) ...@@ -166,7 +166,7 @@ void test_diff_blob__can_compare_against_null_blobs(void)
memset(&expected, 0, sizeof(expected)); memset(&expected, 0, sizeof(expected));
cl_git_pass(git_diff_blobs( cl_git_pass(git_diff_blobs(
NULL, alien, &opts, &expected, diff_file_fn, diff_hunk_fn, diff_line_fn)); NULL, alien, &opts, &expected, diff_file_cb, diff_hunk_cb, diff_line_cb));
cl_assert_equal_i(1, expected.files); cl_assert_equal_i(1, expected.files);
cl_assert_equal_i(1, expected.files_binary); cl_assert_equal_i(1, expected.files_binary);
...@@ -186,21 +186,21 @@ static void assert_identical_blobs_comparison(diff_expects *expected) ...@@ -186,21 +186,21 @@ static void assert_identical_blobs_comparison(diff_expects *expected)
void test_diff_blob__can_compare_identical_blobs(void) void test_diff_blob__can_compare_identical_blobs(void)
{ {
cl_git_pass(git_diff_blobs( cl_git_pass(git_diff_blobs(
d, d, &opts, &expected, diff_file_fn, diff_hunk_fn, diff_line_fn)); d, d, &opts, &expected, diff_file_cb, diff_hunk_cb, diff_line_cb));
cl_assert_equal_i(0, expected.files_binary); cl_assert_equal_i(0, expected.files_binary);
assert_identical_blobs_comparison(&expected); assert_identical_blobs_comparison(&expected);
memset(&expected, 0, sizeof(expected)); memset(&expected, 0, sizeof(expected));
cl_git_pass(git_diff_blobs( cl_git_pass(git_diff_blobs(
NULL, NULL, &opts, &expected, diff_file_fn, diff_hunk_fn, diff_line_fn)); NULL, NULL, &opts, &expected, diff_file_cb, diff_hunk_cb, diff_line_cb));
cl_assert_equal_i(0, expected.files_binary); cl_assert_equal_i(0, expected.files_binary);
assert_identical_blobs_comparison(&expected); assert_identical_blobs_comparison(&expected);
memset(&expected, 0, sizeof(expected)); memset(&expected, 0, sizeof(expected));
cl_git_pass(git_diff_blobs( cl_git_pass(git_diff_blobs(
alien, alien, &opts, &expected, diff_file_fn, diff_hunk_fn, diff_line_fn)); alien, alien, &opts, &expected, diff_file_cb, diff_hunk_cb, diff_line_cb));
cl_assert(expected.files_binary > 0); cl_assert(expected.files_binary > 0);
assert_identical_blobs_comparison(&expected); assert_identical_blobs_comparison(&expected);
...@@ -226,14 +226,14 @@ void test_diff_blob__can_compare_two_binary_blobs(void) ...@@ -226,14 +226,14 @@ void test_diff_blob__can_compare_two_binary_blobs(void)
cl_git_pass(git_blob_lookup_prefix(&heart, g_repo, &h_oid, 4)); cl_git_pass(git_blob_lookup_prefix(&heart, g_repo, &h_oid, 4));
cl_git_pass(git_diff_blobs( cl_git_pass(git_diff_blobs(
alien, heart, &opts, &expected, diff_file_fn, diff_hunk_fn, diff_line_fn)); alien, heart, &opts, &expected, diff_file_cb, diff_hunk_cb, diff_line_cb));
assert_binary_blobs_comparison(&expected); assert_binary_blobs_comparison(&expected);
memset(&expected, 0, sizeof(expected)); memset(&expected, 0, sizeof(expected));
cl_git_pass(git_diff_blobs( cl_git_pass(git_diff_blobs(
heart, alien, &opts, &expected, diff_file_fn, diff_hunk_fn, diff_line_fn)); heart, alien, &opts, &expected, diff_file_cb, diff_hunk_cb, diff_line_cb));
assert_binary_blobs_comparison(&expected); assert_binary_blobs_comparison(&expected);
...@@ -243,14 +243,14 @@ void test_diff_blob__can_compare_two_binary_blobs(void) ...@@ -243,14 +243,14 @@ void test_diff_blob__can_compare_two_binary_blobs(void)
void test_diff_blob__can_compare_a_binary_blob_and_a_text_blob(void) void test_diff_blob__can_compare_a_binary_blob_and_a_text_blob(void)
{ {
cl_git_pass(git_diff_blobs( cl_git_pass(git_diff_blobs(
alien, d, &opts, &expected, diff_file_fn, diff_hunk_fn, diff_line_fn)); alien, d, &opts, &expected, diff_file_cb, diff_hunk_cb, diff_line_cb));
assert_binary_blobs_comparison(&expected); assert_binary_blobs_comparison(&expected);
memset(&expected, 0, sizeof(expected)); memset(&expected, 0, sizeof(expected));
cl_git_pass(git_diff_blobs( cl_git_pass(git_diff_blobs(
d, alien, &opts, &expected, diff_file_fn, diff_hunk_fn, diff_line_fn)); d, alien, &opts, &expected, diff_file_cb, diff_hunk_cb, diff_line_cb));
assert_binary_blobs_comparison(&expected); assert_binary_blobs_comparison(&expected);
} }
...@@ -291,7 +291,7 @@ void test_diff_blob__comparing_two_text_blobs_honors_interhunkcontext(void) ...@@ -291,7 +291,7 @@ void test_diff_blob__comparing_two_text_blobs_honors_interhunkcontext(void)
/* Test with default inter-hunk-context (not set) => default is 0 */ /* Test with default inter-hunk-context (not set) => default is 0 */
cl_git_pass(git_diff_blobs( cl_git_pass(git_diff_blobs(
old_d, d, &opts, &expected, diff_file_fn, diff_hunk_fn, diff_line_fn)); old_d, d, &opts, &expected, diff_file_cb, diff_hunk_cb, diff_line_cb));
cl_assert_equal_i(2, expected.hunks); cl_assert_equal_i(2, expected.hunks);
...@@ -299,7 +299,7 @@ void test_diff_blob__comparing_two_text_blobs_honors_interhunkcontext(void) ...@@ -299,7 +299,7 @@ void test_diff_blob__comparing_two_text_blobs_honors_interhunkcontext(void)
opts.interhunk_lines = 0; opts.interhunk_lines = 0;
memset(&expected, 0, sizeof(expected)); memset(&expected, 0, sizeof(expected));
cl_git_pass(git_diff_blobs( cl_git_pass(git_diff_blobs(
old_d, d, &opts, &expected, diff_file_fn, diff_hunk_fn, diff_line_fn)); old_d, d, &opts, &expected, diff_file_cb, diff_hunk_cb, diff_line_cb));
cl_assert_equal_i(2, expected.hunks); cl_assert_equal_i(2, expected.hunks);
...@@ -307,7 +307,7 @@ void test_diff_blob__comparing_two_text_blobs_honors_interhunkcontext(void) ...@@ -307,7 +307,7 @@ void test_diff_blob__comparing_two_text_blobs_honors_interhunkcontext(void)
opts.interhunk_lines = 1; opts.interhunk_lines = 1;
memset(&expected, 0, sizeof(expected)); memset(&expected, 0, sizeof(expected));
cl_git_pass(git_diff_blobs( cl_git_pass(git_diff_blobs(
old_d, d, &opts, &expected, diff_file_fn, diff_hunk_fn, diff_line_fn)); old_d, d, &opts, &expected, diff_file_cb, diff_hunk_cb, diff_line_cb));
cl_assert_equal_i(1, expected.hunks); cl_assert_equal_i(1, expected.hunks);
......
...@@ -21,7 +21,7 @@ git_tree *resolve_commit_oid_to_tree( ...@@ -21,7 +21,7 @@ git_tree *resolve_commit_oid_to_tree(
return tree; return tree;
} }
int diff_file_fn( int diff_file_cb(
void *cb_data, void *cb_data,
const git_diff_delta *delta, const git_diff_delta *delta,
float progress) float progress)
...@@ -42,7 +42,7 @@ int diff_file_fn( ...@@ -42,7 +42,7 @@ int diff_file_fn(
return 0; return 0;
} }
int diff_hunk_fn( int diff_hunk_cb(
void *cb_data, void *cb_data,
const git_diff_delta *delta, const git_diff_delta *delta,
const git_diff_range *range, const git_diff_range *range,
...@@ -61,7 +61,7 @@ int diff_hunk_fn( ...@@ -61,7 +61,7 @@ int diff_hunk_fn(
return 0; return 0;
} }
int diff_line_fn( int diff_line_cb(
void *cb_data, void *cb_data,
const git_diff_delta *delta, const git_diff_delta *delta,
const git_diff_range *range, const git_diff_range *range,
...@@ -104,9 +104,9 @@ int diff_line_fn( ...@@ -104,9 +104,9 @@ int diff_line_fn(
int diff_foreach_via_iterator( int diff_foreach_via_iterator(
git_diff_list *diff, git_diff_list *diff,
void *data, void *data,
git_diff_file_fn file_cb, git_diff_file_cb file_cb,
git_diff_hunk_fn hunk_cb, git_diff_hunk_cb hunk_cb,
git_diff_data_fn line_cb) git_diff_data_cb line_cb)
{ {
size_t d, num_d = git_diff_num_deltas(diff); size_t d, num_d = git_diff_num_deltas(diff);
......
...@@ -20,19 +20,19 @@ typedef struct { ...@@ -20,19 +20,19 @@ typedef struct {
int line_dels; int line_dels;
} diff_expects; } diff_expects;
extern int diff_file_fn( extern int diff_file_cb(
void *cb_data, void *cb_data,
const git_diff_delta *delta, const git_diff_delta *delta,
float progress); float progress);
extern int diff_hunk_fn( extern int diff_hunk_cb(
void *cb_data, void *cb_data,
const git_diff_delta *delta, const git_diff_delta *delta,
const git_diff_range *range, const git_diff_range *range,
const char *header, const char *header,
size_t header_len); size_t header_len);
extern int diff_line_fn( extern int diff_line_cb(
void *cb_data, void *cb_data,
const git_diff_delta *delta, const git_diff_delta *delta,
const git_diff_range *range, const git_diff_range *range,
...@@ -43,8 +43,8 @@ extern int diff_line_fn( ...@@ -43,8 +43,8 @@ extern int diff_line_fn(
extern int diff_foreach_via_iterator( extern int diff_foreach_via_iterator(
git_diff_list *diff, git_diff_list *diff,
void *data, void *data,
git_diff_file_fn file_cb, git_diff_file_cb file_cb,
git_diff_hunk_fn hunk_cb, git_diff_hunk_cb hunk_cb,
git_diff_data_fn line_cb); git_diff_data_cb line_cb);
extern void diff_print(FILE *fp, git_diff_list *diff); extern void diff_print(FILE *fp, git_diff_list *diff);
...@@ -35,7 +35,7 @@ void test_diff_index__0(void) ...@@ -35,7 +35,7 @@ void test_diff_index__0(void)
cl_git_pass(git_diff_index_to_tree(&diff, g_repo, a, NULL, &opts)); cl_git_pass(git_diff_index_to_tree(&diff, g_repo, a, NULL, &opts));
cl_git_pass(git_diff_foreach( cl_git_pass(git_diff_foreach(
diff, &exp, diff_file_fn, diff_hunk_fn, diff_line_fn)); diff, &exp, diff_file_cb, diff_hunk_cb, diff_line_cb));
/* to generate these values: /* to generate these values:
* - cd to tests/resources/status, * - cd to tests/resources/status,
...@@ -63,7 +63,7 @@ void test_diff_index__0(void) ...@@ -63,7 +63,7 @@ void test_diff_index__0(void)
cl_git_pass(git_diff_index_to_tree(&diff, g_repo, b, NULL, &opts)); cl_git_pass(git_diff_index_to_tree(&diff, g_repo, b, NULL, &opts));
cl_git_pass(git_diff_foreach( cl_git_pass(git_diff_foreach(
diff, &exp, diff_file_fn, diff_hunk_fn, diff_line_fn)); diff, &exp, diff_file_cb, diff_hunk_cb, diff_line_cb));
/* to generate these values: /* to generate these values:
* - cd to tests/resources/status, * - cd to tests/resources/status,
......
...@@ -55,7 +55,7 @@ void test_diff_rename__match_oid(void) ...@@ -55,7 +55,7 @@ void test_diff_rename__match_oid(void)
*/ */
memset(&exp, 0, sizeof(exp)); memset(&exp, 0, sizeof(exp));
cl_git_pass(git_diff_foreach( cl_git_pass(git_diff_foreach(
diff, &exp, diff_file_fn, diff_hunk_fn, diff_line_fn)); diff, &exp, diff_file_cb, diff_hunk_cb, diff_line_cb));
cl_assert_equal_i(4, exp.files); cl_assert_equal_i(4, exp.files);
cl_assert_equal_i(1, exp.file_status[GIT_DELTA_UNMODIFIED]); cl_assert_equal_i(1, exp.file_status[GIT_DELTA_UNMODIFIED]);
...@@ -69,7 +69,7 @@ void test_diff_rename__match_oid(void) ...@@ -69,7 +69,7 @@ void test_diff_rename__match_oid(void)
memset(&exp, 0, sizeof(exp)); memset(&exp, 0, sizeof(exp));
cl_git_pass(git_diff_foreach( cl_git_pass(git_diff_foreach(
diff, &exp, diff_file_fn, diff_hunk_fn, diff_line_fn)); diff, &exp, diff_file_cb, diff_hunk_cb, diff_line_cb));
cl_assert_equal_i(3, exp.files); cl_assert_equal_i(3, exp.files);
cl_assert_equal_i(1, exp.file_status[GIT_DELTA_UNMODIFIED]); cl_assert_equal_i(1, exp.file_status[GIT_DELTA_UNMODIFIED]);
...@@ -91,7 +91,7 @@ void test_diff_rename__match_oid(void) ...@@ -91,7 +91,7 @@ void test_diff_rename__match_oid(void)
memset(&exp, 0, sizeof(exp)); memset(&exp, 0, sizeof(exp));
cl_git_pass(git_diff_foreach( cl_git_pass(git_diff_foreach(
diff, &exp, diff_file_fn, diff_hunk_fn, diff_line_fn)); diff, &exp, diff_file_cb, diff_hunk_cb, diff_line_cb));
cl_assert_equal_i(3, exp.files); cl_assert_equal_i(3, exp.files);
cl_assert_equal_i(1, exp.file_status[GIT_DELTA_UNMODIFIED]); cl_assert_equal_i(1, exp.file_status[GIT_DELTA_UNMODIFIED]);
......
...@@ -37,7 +37,7 @@ void test_diff_tree__0(void) ...@@ -37,7 +37,7 @@ void test_diff_tree__0(void)
cl_git_pass(git_diff_tree_to_tree(&diff, g_repo, a, b, &opts)); cl_git_pass(git_diff_tree_to_tree(&diff, g_repo, a, b, &opts));
cl_git_pass(git_diff_foreach( cl_git_pass(git_diff_foreach(
diff, &exp, diff_file_fn, diff_hunk_fn, diff_line_fn)); diff, &exp, diff_file_cb, diff_hunk_cb, diff_line_cb));
cl_assert_equal_i(5, exp.files); cl_assert_equal_i(5, exp.files);
cl_assert_equal_i(2, exp.file_status[GIT_DELTA_ADDED]); cl_assert_equal_i(2, exp.file_status[GIT_DELTA_ADDED]);
...@@ -59,7 +59,7 @@ void test_diff_tree__0(void) ...@@ -59,7 +59,7 @@ void test_diff_tree__0(void)
cl_git_pass(git_diff_tree_to_tree(&diff, g_repo, c, b, &opts)); cl_git_pass(git_diff_tree_to_tree(&diff, g_repo, c, b, &opts));
cl_git_pass(git_diff_foreach( cl_git_pass(git_diff_foreach(
diff, &exp, diff_file_fn, diff_hunk_fn, diff_line_fn)); diff, &exp, diff_file_cb, diff_hunk_cb, diff_line_cb));
cl_assert_equal_i(2, exp.files); cl_assert_equal_i(2, exp.files);
cl_assert_equal_i(0, exp.file_status[GIT_DELTA_ADDED]); cl_assert_equal_i(0, exp.file_status[GIT_DELTA_ADDED]);
...@@ -94,17 +94,18 @@ void test_diff_tree__options(void) ...@@ -94,17 +94,18 @@ void test_diff_tree__options(void)
int test_ab_or_cd[] = { 0, 0, 0, 0, 1, 1, 1, 1, 1 }; int test_ab_or_cd[] = { 0, 0, 0, 0, 1, 1, 1, 1, 1 };
git_diff_options test_options[] = { git_diff_options test_options[] = {
/* a vs b tests */ /* a vs b tests */
{ GIT_DIFF_NORMAL, 1, 1, NULL, NULL, {0} }, { 1, GIT_DIFF_NORMAL, 1, 1, NULL, NULL, {0} },
{ GIT_DIFF_NORMAL, 3, 1, NULL, NULL, {0} }, { 1, GIT_DIFF_NORMAL, 3, 1, NULL, NULL, {0} },
{ GIT_DIFF_REVERSE, 2, 1, NULL, NULL, {0} }, { 1, GIT_DIFF_REVERSE, 2, 1, NULL, NULL, {0} },
{ GIT_DIFF_FORCE_TEXT, 2, 1, NULL, NULL, {0} }, { 1, GIT_DIFF_FORCE_TEXT, 2, 1, NULL, NULL, {0} },
/* c vs d tests */ /* c vs d tests */
{ GIT_DIFF_NORMAL, 3, 1, NULL, NULL, {0} }, { 1, GIT_DIFF_NORMAL, 3, 1, NULL, NULL, {0} },
{ GIT_DIFF_IGNORE_WHITESPACE, 3, 1, NULL, NULL, {0} }, { 1, GIT_DIFF_IGNORE_WHITESPACE, 3, 1, NULL, NULL, {0} },
{ GIT_DIFF_IGNORE_WHITESPACE_CHANGE, 3, 1, NULL, NULL, {0} }, { 1, GIT_DIFF_IGNORE_WHITESPACE_CHANGE, 3, 1, NULL, NULL, {0} },
{ GIT_DIFF_IGNORE_WHITESPACE_EOL, 3, 1, NULL, NULL, {0} }, { 1, GIT_DIFF_IGNORE_WHITESPACE_EOL, 3, 1, NULL, NULL, {0} },
{ GIT_DIFF_IGNORE_WHITESPACE | GIT_DIFF_REVERSE, 1, 1, NULL, NULL, {0} }, { 1, GIT_DIFF_IGNORE_WHITESPACE | GIT_DIFF_REVERSE, 1, 1, NULL, NULL, {0} },
}; };
/* to generate these values: /* to generate these values:
* - cd to tests/resources/attr, * - cd to tests/resources/attr,
* - mv .gitted .git * - mv .gitted .git
...@@ -112,6 +113,7 @@ void test_diff_tree__options(void) ...@@ -112,6 +113,7 @@ void test_diff_tree__options(void)
* - mv .git .gitted * - mv .git .gitted
*/ */
#define EXPECT_STATUS_ADM(ADDS,DELS,MODS) { 0, ADDS, DELS, MODS, 0, 0, 0, 0, 0 } #define EXPECT_STATUS_ADM(ADDS,DELS,MODS) { 0, ADDS, DELS, MODS, 0, 0, 0, 0, 0 }
diff_expects test_expects[] = { diff_expects test_expects[] = {
/* a vs b tests */ /* a vs b tests */
{ 5, 0, EXPECT_STATUS_ADM(3, 0, 2), 4, 0, 0, 51, 2, 46, 3 }, { 5, 0, EXPECT_STATUS_ADM(3, 0, 2), 4, 0, 0, 51, 2, 46, 3 },
...@@ -146,7 +148,7 @@ void test_diff_tree__options(void) ...@@ -146,7 +148,7 @@ void test_diff_tree__options(void)
cl_git_pass(git_diff_tree_to_tree(&diff, g_repo, c, d, &opts)); cl_git_pass(git_diff_tree_to_tree(&diff, g_repo, c, d, &opts));
cl_git_pass(git_diff_foreach( cl_git_pass(git_diff_foreach(
diff, &actual, diff_file_fn, diff_hunk_fn, diff_line_fn)); diff, &actual, diff_file_cb, diff_hunk_cb, diff_line_cb));
expected = &test_expects[i]; expected = &test_expects[i];
cl_assert_equal_i(actual.files, expected->files); cl_assert_equal_i(actual.files, expected->files);
...@@ -190,7 +192,7 @@ void test_diff_tree__bare(void) ...@@ -190,7 +192,7 @@ void test_diff_tree__bare(void)
cl_git_pass(git_diff_tree_to_tree(&diff, g_repo, a, b, &opts)); cl_git_pass(git_diff_tree_to_tree(&diff, g_repo, a, b, &opts));
cl_git_pass(git_diff_foreach( cl_git_pass(git_diff_foreach(
diff, &exp, diff_file_fn, diff_hunk_fn, diff_line_fn)); diff, &exp, diff_file_cb, diff_hunk_cb, diff_line_cb));
cl_assert_equal_i(3, exp.files); cl_assert_equal_i(3, exp.files);
cl_assert_equal_i(2, exp.file_status[GIT_DELTA_ADDED]); cl_assert_equal_i(2, exp.file_status[GIT_DELTA_ADDED]);
...@@ -240,7 +242,7 @@ void test_diff_tree__merge(void) ...@@ -240,7 +242,7 @@ void test_diff_tree__merge(void)
memset(&exp, 0, sizeof(exp)); memset(&exp, 0, sizeof(exp));
cl_git_pass(git_diff_foreach( cl_git_pass(git_diff_foreach(
diff1, &exp, diff_file_fn, diff_hunk_fn, diff_line_fn)); diff1, &exp, diff_file_cb, diff_hunk_cb, diff_line_cb));
cl_assert_equal_i(6, exp.files); cl_assert_equal_i(6, exp.files);
cl_assert_equal_i(2, exp.file_status[GIT_DELTA_ADDED]); cl_assert_equal_i(2, exp.file_status[GIT_DELTA_ADDED]);
......
...@@ -33,10 +33,10 @@ void test_diff_workdir__to_index(void) ...@@ -33,10 +33,10 @@ void test_diff_workdir__to_index(void)
if (use_iterator) if (use_iterator)
cl_git_pass(diff_foreach_via_iterator( cl_git_pass(diff_foreach_via_iterator(
diff, &exp, diff_file_fn, diff_hunk_fn, diff_line_fn)); diff, &exp, diff_file_cb, diff_hunk_cb, diff_line_cb));
else else
cl_git_pass(git_diff_foreach( cl_git_pass(git_diff_foreach(
diff, &exp, diff_file_fn, diff_hunk_fn, diff_line_fn)); diff, &exp, diff_file_cb, diff_hunk_cb, diff_line_cb));
/* to generate these values: /* to generate these values:
* - cd to tests/resources/status, * - cd to tests/resources/status,
...@@ -101,10 +101,10 @@ void test_diff_workdir__to_tree(void) ...@@ -101,10 +101,10 @@ void test_diff_workdir__to_tree(void)
if (use_iterator) if (use_iterator)
cl_git_pass(diff_foreach_via_iterator( cl_git_pass(diff_foreach_via_iterator(
diff, &exp, diff_file_fn, diff_hunk_fn, diff_line_fn)); diff, &exp, diff_file_cb, diff_hunk_cb, diff_line_cb));
else else
cl_git_pass(git_diff_foreach( cl_git_pass(git_diff_foreach(
diff, &exp, diff_file_fn, diff_hunk_fn, diff_line_fn)); diff, &exp, diff_file_cb, diff_hunk_cb, diff_line_cb));
cl_assert_equal_i(14, exp.files); cl_assert_equal_i(14, exp.files);
cl_assert_equal_i(0, exp.file_status[GIT_DELTA_ADDED]); cl_assert_equal_i(0, exp.file_status[GIT_DELTA_ADDED]);
...@@ -137,10 +137,10 @@ void test_diff_workdir__to_tree(void) ...@@ -137,10 +137,10 @@ void test_diff_workdir__to_tree(void)
if (use_iterator) if (use_iterator)
cl_git_pass(diff_foreach_via_iterator( cl_git_pass(diff_foreach_via_iterator(
diff, &exp, diff_file_fn, diff_hunk_fn, diff_line_fn)); diff, &exp, diff_file_cb, diff_hunk_cb, diff_line_cb));
else else
cl_git_pass(git_diff_foreach( cl_git_pass(git_diff_foreach(
diff, &exp, diff_file_fn, diff_hunk_fn, diff_line_fn)); diff, &exp, diff_file_cb, diff_hunk_cb, diff_line_cb));
cl_assert_equal_i(15, exp.files); cl_assert_equal_i(15, exp.files);
cl_assert_equal_i(2, exp.file_status[GIT_DELTA_ADDED]); cl_assert_equal_i(2, exp.file_status[GIT_DELTA_ADDED]);
...@@ -174,10 +174,10 @@ void test_diff_workdir__to_tree(void) ...@@ -174,10 +174,10 @@ void test_diff_workdir__to_tree(void)
if (use_iterator) if (use_iterator)
cl_git_pass(diff_foreach_via_iterator( cl_git_pass(diff_foreach_via_iterator(
diff, &exp, diff_file_fn, diff_hunk_fn, diff_line_fn)); diff, &exp, diff_file_cb, diff_hunk_cb, diff_line_cb));
else else
cl_git_pass(git_diff_foreach( cl_git_pass(git_diff_foreach(
diff, &exp, diff_file_fn, diff_hunk_fn, diff_line_fn)); diff, &exp, diff_file_cb, diff_hunk_cb, diff_line_cb));
cl_assert_equal_i(16, exp.files); cl_assert_equal_i(16, exp.files);
cl_assert_equal_i(5, exp.file_status[GIT_DELTA_ADDED]); cl_assert_equal_i(5, exp.file_status[GIT_DELTA_ADDED]);
...@@ -223,9 +223,9 @@ void test_diff_workdir__to_index_with_pathspec(void) ...@@ -223,9 +223,9 @@ void test_diff_workdir__to_index_with_pathspec(void)
if (use_iterator) if (use_iterator)
cl_git_pass(diff_foreach_via_iterator( cl_git_pass(diff_foreach_via_iterator(
diff, &exp, diff_file_fn, NULL, NULL)); diff, &exp, diff_file_cb, NULL, NULL));
else else
cl_git_pass(git_diff_foreach(diff, &exp, diff_file_fn, NULL, NULL)); cl_git_pass(git_diff_foreach(diff, &exp, diff_file_cb, NULL, NULL));
cl_assert_equal_i(13, exp.files); cl_assert_equal_i(13, exp.files);
cl_assert_equal_i(0, exp.file_status[GIT_DELTA_ADDED]); cl_assert_equal_i(0, exp.file_status[GIT_DELTA_ADDED]);
...@@ -246,9 +246,9 @@ void test_diff_workdir__to_index_with_pathspec(void) ...@@ -246,9 +246,9 @@ void test_diff_workdir__to_index_with_pathspec(void)
if (use_iterator) if (use_iterator)
cl_git_pass(diff_foreach_via_iterator( cl_git_pass(diff_foreach_via_iterator(
diff, &exp, diff_file_fn, NULL, NULL)); diff, &exp, diff_file_cb, NULL, NULL));
else else
cl_git_pass(git_diff_foreach(diff, &exp, diff_file_fn, NULL, NULL)); cl_git_pass(git_diff_foreach(diff, &exp, diff_file_cb, NULL, NULL));
cl_assert_equal_i(1, exp.files); cl_assert_equal_i(1, exp.files);
cl_assert_equal_i(0, exp.file_status[GIT_DELTA_ADDED]); cl_assert_equal_i(0, exp.file_status[GIT_DELTA_ADDED]);
...@@ -269,9 +269,9 @@ void test_diff_workdir__to_index_with_pathspec(void) ...@@ -269,9 +269,9 @@ void test_diff_workdir__to_index_with_pathspec(void)
if (use_iterator) if (use_iterator)
cl_git_pass(diff_foreach_via_iterator( cl_git_pass(diff_foreach_via_iterator(
diff, &exp, diff_file_fn, NULL, NULL)); diff, &exp, diff_file_cb, NULL, NULL));
else else
cl_git_pass(git_diff_foreach(diff, &exp, diff_file_fn, NULL, NULL)); cl_git_pass(git_diff_foreach(diff, &exp, diff_file_cb, NULL, NULL));
cl_assert_equal_i(3, exp.files); cl_assert_equal_i(3, exp.files);
cl_assert_equal_i(0, exp.file_status[GIT_DELTA_ADDED]); cl_assert_equal_i(0, exp.file_status[GIT_DELTA_ADDED]);
...@@ -292,9 +292,9 @@ void test_diff_workdir__to_index_with_pathspec(void) ...@@ -292,9 +292,9 @@ void test_diff_workdir__to_index_with_pathspec(void)
if (use_iterator) if (use_iterator)
cl_git_pass(diff_foreach_via_iterator( cl_git_pass(diff_foreach_via_iterator(
diff, &exp, diff_file_fn, NULL, NULL)); diff, &exp, diff_file_cb, NULL, NULL));
else else
cl_git_pass(git_diff_foreach(diff, &exp, diff_file_fn, NULL, NULL)); cl_git_pass(git_diff_foreach(diff, &exp, diff_file_cb, NULL, NULL));
cl_assert_equal_i(2, exp.files); cl_assert_equal_i(2, exp.files);
cl_assert_equal_i(0, exp.file_status[GIT_DELTA_ADDED]); cl_assert_equal_i(0, exp.file_status[GIT_DELTA_ADDED]);
...@@ -331,10 +331,10 @@ void test_diff_workdir__filemode_changes(void) ...@@ -331,10 +331,10 @@ void test_diff_workdir__filemode_changes(void)
if (use_iterator) if (use_iterator)
cl_git_pass(diff_foreach_via_iterator( cl_git_pass(diff_foreach_via_iterator(
diff, &exp, diff_file_fn, diff_hunk_fn, diff_line_fn)); diff, &exp, diff_file_cb, diff_hunk_cb, diff_line_cb));
else else
cl_git_pass(git_diff_foreach( cl_git_pass(git_diff_foreach(
diff, &exp, diff_file_fn, diff_hunk_fn, diff_line_fn)); diff, &exp, diff_file_cb, diff_hunk_cb, diff_line_cb));
cl_assert_equal_i(0, exp.files); cl_assert_equal_i(0, exp.files);
cl_assert_equal_i(0, exp.file_status[GIT_DELTA_MODIFIED]); cl_assert_equal_i(0, exp.file_status[GIT_DELTA_MODIFIED]);
...@@ -354,10 +354,10 @@ void test_diff_workdir__filemode_changes(void) ...@@ -354,10 +354,10 @@ void test_diff_workdir__filemode_changes(void)
if (use_iterator) if (use_iterator)
cl_git_pass(diff_foreach_via_iterator( cl_git_pass(diff_foreach_via_iterator(
diff, &exp, diff_file_fn, diff_hunk_fn, diff_line_fn)); diff, &exp, diff_file_cb, diff_hunk_cb, diff_line_cb));
else else
cl_git_pass(git_diff_foreach( cl_git_pass(git_diff_foreach(
diff, &exp, diff_file_fn, diff_hunk_fn, diff_line_fn)); diff, &exp, diff_file_cb, diff_hunk_cb, diff_line_cb));
cl_assert_equal_i(1, exp.files); cl_assert_equal_i(1, exp.files);
cl_assert_equal_i(1, exp.file_status[GIT_DELTA_MODIFIED]); cl_assert_equal_i(1, exp.file_status[GIT_DELTA_MODIFIED]);
...@@ -390,7 +390,7 @@ void test_diff_workdir__filemode_changes_with_filemode_false(void) ...@@ -390,7 +390,7 @@ void test_diff_workdir__filemode_changes_with_filemode_false(void)
memset(&exp, 0, sizeof(exp)); memset(&exp, 0, sizeof(exp));
cl_git_pass(git_diff_foreach( cl_git_pass(git_diff_foreach(
diff, &exp, diff_file_fn, diff_hunk_fn, diff_line_fn)); diff, &exp, diff_file_cb, diff_hunk_cb, diff_line_cb));
cl_assert_equal_i(0, exp.files); cl_assert_equal_i(0, exp.files);
cl_assert_equal_i(0, exp.file_status[GIT_DELTA_MODIFIED]); cl_assert_equal_i(0, exp.file_status[GIT_DELTA_MODIFIED]);
...@@ -406,7 +406,7 @@ void test_diff_workdir__filemode_changes_with_filemode_false(void) ...@@ -406,7 +406,7 @@ void test_diff_workdir__filemode_changes_with_filemode_false(void)
memset(&exp, 0, sizeof(exp)); memset(&exp, 0, sizeof(exp));
cl_git_pass(git_diff_foreach( cl_git_pass(git_diff_foreach(
diff, &exp, diff_file_fn, diff_hunk_fn, diff_line_fn)); diff, &exp, diff_file_cb, diff_hunk_cb, diff_line_cb));
cl_assert_equal_i(0, exp.files); cl_assert_equal_i(0, exp.files);
cl_assert_equal_i(0, exp.file_status[GIT_DELTA_MODIFIED]); cl_assert_equal_i(0, exp.file_status[GIT_DELTA_MODIFIED]);
...@@ -450,10 +450,10 @@ void test_diff_workdir__head_index_and_workdir_all_differ(void) ...@@ -450,10 +450,10 @@ void test_diff_workdir__head_index_and_workdir_all_differ(void)
if (use_iterator) if (use_iterator)
cl_git_pass(diff_foreach_via_iterator( cl_git_pass(diff_foreach_via_iterator(
diff_i2t, &exp, diff_file_fn, diff_hunk_fn, diff_line_fn)); diff_i2t, &exp, diff_file_cb, diff_hunk_cb, diff_line_cb));
else else
cl_git_pass(git_diff_foreach( cl_git_pass(git_diff_foreach(
diff_i2t, &exp, diff_file_fn, diff_hunk_fn, diff_line_fn)); diff_i2t, &exp, diff_file_cb, diff_hunk_cb, diff_line_cb));
cl_assert_equal_i(1, exp.files); cl_assert_equal_i(1, exp.files);
cl_assert_equal_i(0, exp.file_status[GIT_DELTA_ADDED]); cl_assert_equal_i(0, exp.file_status[GIT_DELTA_ADDED]);
...@@ -471,10 +471,10 @@ void test_diff_workdir__head_index_and_workdir_all_differ(void) ...@@ -471,10 +471,10 @@ void test_diff_workdir__head_index_and_workdir_all_differ(void)
if (use_iterator) if (use_iterator)
cl_git_pass(diff_foreach_via_iterator( cl_git_pass(diff_foreach_via_iterator(
diff_w2i, &exp, diff_file_fn, diff_hunk_fn, diff_line_fn)); diff_w2i, &exp, diff_file_cb, diff_hunk_cb, diff_line_cb));
else else
cl_git_pass(git_diff_foreach( cl_git_pass(git_diff_foreach(
diff_w2i, &exp, diff_file_fn, diff_hunk_fn, diff_line_fn)); diff_w2i, &exp, diff_file_cb, diff_hunk_cb, diff_line_cb));
cl_assert_equal_i(1, exp.files); cl_assert_equal_i(1, exp.files);
cl_assert_equal_i(0, exp.file_status[GIT_DELTA_ADDED]); cl_assert_equal_i(0, exp.file_status[GIT_DELTA_ADDED]);
...@@ -494,10 +494,10 @@ void test_diff_workdir__head_index_and_workdir_all_differ(void) ...@@ -494,10 +494,10 @@ void test_diff_workdir__head_index_and_workdir_all_differ(void)
if (use_iterator) if (use_iterator)
cl_git_pass(diff_foreach_via_iterator( cl_git_pass(diff_foreach_via_iterator(
diff_i2t, &exp, diff_file_fn, diff_hunk_fn, diff_line_fn)); diff_i2t, &exp, diff_file_cb, diff_hunk_cb, diff_line_cb));
else else
cl_git_pass(git_diff_foreach( cl_git_pass(git_diff_foreach(
diff_i2t, &exp, diff_file_fn, diff_hunk_fn, diff_line_fn)); diff_i2t, &exp, diff_file_cb, diff_hunk_cb, diff_line_cb));
cl_assert_equal_i(1, exp.files); cl_assert_equal_i(1, exp.files);
cl_assert_equal_i(0, exp.file_status[GIT_DELTA_ADDED]); cl_assert_equal_i(0, exp.file_status[GIT_DELTA_ADDED]);
...@@ -536,10 +536,10 @@ void test_diff_workdir__eof_newline_changes(void) ...@@ -536,10 +536,10 @@ void test_diff_workdir__eof_newline_changes(void)
if (use_iterator) if (use_iterator)
cl_git_pass(diff_foreach_via_iterator( cl_git_pass(diff_foreach_via_iterator(
diff, &exp, diff_file_fn, diff_hunk_fn, diff_line_fn)); diff, &exp, diff_file_cb, diff_hunk_cb, diff_line_cb));
else else
cl_git_pass(git_diff_foreach( cl_git_pass(git_diff_foreach(
diff, &exp, diff_file_fn, diff_hunk_fn, diff_line_fn)); diff, &exp, diff_file_cb, diff_hunk_cb, diff_line_cb));
cl_assert_equal_i(0, exp.files); cl_assert_equal_i(0, exp.files);
cl_assert_equal_i(0, exp.file_status[GIT_DELTA_ADDED]); cl_assert_equal_i(0, exp.file_status[GIT_DELTA_ADDED]);
...@@ -563,10 +563,10 @@ void test_diff_workdir__eof_newline_changes(void) ...@@ -563,10 +563,10 @@ void test_diff_workdir__eof_newline_changes(void)
if (use_iterator) if (use_iterator)
cl_git_pass(diff_foreach_via_iterator( cl_git_pass(diff_foreach_via_iterator(
diff, &exp, diff_file_fn, diff_hunk_fn, diff_line_fn)); diff, &exp, diff_file_cb, diff_hunk_cb, diff_line_cb));
else else
cl_git_pass(git_diff_foreach( cl_git_pass(git_diff_foreach(
diff, &exp, diff_file_fn, diff_hunk_fn, diff_line_fn)); diff, &exp, diff_file_cb, diff_hunk_cb, diff_line_cb));
cl_assert_equal_i(1, exp.files); cl_assert_equal_i(1, exp.files);
cl_assert_equal_i(0, exp.file_status[GIT_DELTA_ADDED]); cl_assert_equal_i(0, exp.file_status[GIT_DELTA_ADDED]);
...@@ -590,10 +590,10 @@ void test_diff_workdir__eof_newline_changes(void) ...@@ -590,10 +590,10 @@ void test_diff_workdir__eof_newline_changes(void)
if (use_iterator) if (use_iterator)
cl_git_pass(diff_foreach_via_iterator( cl_git_pass(diff_foreach_via_iterator(
diff, &exp, diff_file_fn, diff_hunk_fn, diff_line_fn)); diff, &exp, diff_file_cb, diff_hunk_cb, diff_line_cb));
else else
cl_git_pass(git_diff_foreach( cl_git_pass(git_diff_foreach(
diff, &exp, diff_file_fn, diff_hunk_fn, diff_line_fn)); diff, &exp, diff_file_cb, diff_hunk_cb, diff_line_cb));
cl_assert_equal_i(1, exp.files); cl_assert_equal_i(1, exp.files);
cl_assert_equal_i(0, exp.file_status[GIT_DELTA_ADDED]); cl_assert_equal_i(0, exp.file_status[GIT_DELTA_ADDED]);
...@@ -792,7 +792,7 @@ void test_diff_workdir__submodules(void) ...@@ -792,7 +792,7 @@ void test_diff_workdir__submodules(void)
memset(&exp, 0, sizeof(exp)); memset(&exp, 0, sizeof(exp));
cl_git_pass(git_diff_foreach( cl_git_pass(git_diff_foreach(
diff, &exp, diff_file_fn, diff_hunk_fn, diff_line_fn)); diff, &exp, diff_file_cb, diff_hunk_cb, diff_line_cb));
/* the following differs from "git diff 873585" by one "untracked" file /* the following differs from "git diff 873585" by one "untracked" file
* because the diff list includes the "not_submodule/" directory which * because the diff list includes the "not_submodule/" directory which
......
...@@ -14,7 +14,7 @@ static const char *g_raw[NUM_TEST_OBJECTS] = { ...@@ -14,7 +14,7 @@ static const char *g_raw[NUM_TEST_OBJECTS] = {
"foo\nbar\rboth\r\nreversed\n\ragain\nproblems\r", "foo\nbar\rboth\r\nreversed\n\ragain\nproblems\r",
"123\n\000\001\002\003\004abc\255\254\253\r\n" "123\n\000\001\002\003\004abc\255\254\253\r\n"
}; };
static int g_len[NUM_TEST_OBJECTS] = { -1, -1, -1, -1, -1, 17 }; static git_off_t g_len[NUM_TEST_OBJECTS] = { -1, -1, -1, -1, -1, 17 };
static git_text_stats g_stats[NUM_TEST_OBJECTS] = { static git_text_stats g_stats[NUM_TEST_OBJECTS] = {
{ 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0 },
{ 0, 0, 2, 0, 6, 0 }, { 0, 0, 2, 0, 6, 0 },
...@@ -65,7 +65,7 @@ void test_object_blob_filter__unfiltered(void) ...@@ -65,7 +65,7 @@ void test_object_blob_filter__unfiltered(void)
for (i = 0; i < NUM_TEST_OBJECTS; i++) { for (i = 0; i < NUM_TEST_OBJECTS; i++) {
cl_git_pass(git_blob_lookup(&blob, g_repo, &g_oids[i])); cl_git_pass(git_blob_lookup(&blob, g_repo, &g_oids[i]));
cl_assert((size_t)g_len[i] == git_blob_rawsize(blob)); cl_assert(g_len[i] == git_blob_rawsize(blob));
cl_assert(memcmp(git_blob_rawcontent(blob), g_raw[i], g_len[i]) == 0); cl_assert(memcmp(git_blob_rawcontent(blob), g_raw[i], g_len[i]) == 0);
git_blob_free(blob); git_blob_free(blob);
} }
......
...@@ -33,7 +33,7 @@ void test_object_blob_write__can_create_a_blob_in_a_standard_repo_from_a_file_lo ...@@ -33,7 +33,7 @@ void test_object_blob_write__can_create_a_blob_in_a_standard_repo_from_a_file_lo
{ {
repo = cl_git_sandbox_init(WORKDIR); repo = cl_git_sandbox_init(WORKDIR);
assert_blob_creation(WORKDIR "/test.txt", "test.txt", &git_blob_create_fromfile); assert_blob_creation(WORKDIR "/test.txt", "test.txt", &git_blob_create_fromworkdir);
} }
void test_object_blob_write__can_create_a_blob_in_a_standard_repo_from_a_absolute_filepath_pointing_outside_of_the_working_directory(void) void test_object_blob_write__can_create_a_blob_in_a_standard_repo_from_a_absolute_filepath_pointing_outside_of_the_working_directory(void)
......
...@@ -67,7 +67,7 @@ static void seed_packbuilder(void) ...@@ -67,7 +67,7 @@ static void seed_packbuilder(void)
git_object *obj; git_object *obj;
cl_git_pass(git_object_lookup(&obj, _repo, o, GIT_OBJ_COMMIT)); cl_git_pass(git_object_lookup(&obj, _repo, o, GIT_OBJ_COMMIT));
cl_git_pass(git_packbuilder_insert_tree(_packbuilder, cl_git_pass(git_packbuilder_insert_tree(_packbuilder,
git_commit_tree_oid((git_commit *)obj))); git_commit_tree_id((git_commit *)obj)));
git_object_free(obj); git_object_free(obj);
} }
} }
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
#include "refs.h" #include "refs.h"
static git_repository *repo; static git_repository *repo;
static git_object *target; static git_commit *target;
static git_reference *branch; static git_reference *branch;
void test_refs_branches_create__initialize(void) void test_refs_branches_create__initialize(void)
...@@ -27,17 +27,17 @@ void test_refs_branches_create__cleanup(void) ...@@ -27,17 +27,17 @@ void test_refs_branches_create__cleanup(void)
cl_fixture_cleanup("testrepo.git"); cl_fixture_cleanup("testrepo.git");
} }
static void retrieve_target_from_oid(git_object **object_out, git_repository *repo, const char *sha) static void retrieve_target_from_oid(git_commit **out, git_repository *repo, const char *sha)
{ {
git_oid oid; git_oid oid;
cl_git_pass(git_oid_fromstr(&oid, sha)); cl_git_pass(git_oid_fromstr(&oid, sha));
cl_git_pass(git_object_lookup(object_out, repo, &oid, GIT_OBJ_ANY)); cl_git_pass(git_commit_lookup(out, repo, &oid));
} }
static void retrieve_known_commit(git_object **object, git_repository *repo) static void retrieve_known_commit(git_commit **commit, git_repository *repo)
{ {
retrieve_target_from_oid(object, repo, "e90810b8df3e80c413d903f631643c716887138d"); retrieve_target_from_oid(commit, repo, "e90810b8df3e80c413d903f631643c716887138d");
} }
#define NEW_BRANCH_NAME "new-branch-on-the-block" #define NEW_BRANCH_NAME "new-branch-on-the-block"
...@@ -47,7 +47,7 @@ void test_refs_branches_create__can_create_a_local_branch(void) ...@@ -47,7 +47,7 @@ void test_refs_branches_create__can_create_a_local_branch(void)
retrieve_known_commit(&target, repo); retrieve_known_commit(&target, repo);
cl_git_pass(git_branch_create(&branch, repo, NEW_BRANCH_NAME, target, 0)); cl_git_pass(git_branch_create(&branch, repo, NEW_BRANCH_NAME, target, 0));
cl_git_pass(git_oid_cmp(git_reference_target(branch), git_object_id(target))); cl_git_pass(git_oid_cmp(git_reference_target(branch), git_commit_id(target)));
} }
void test_refs_branches_create__can_not_create_a_branch_if_its_name_collide_with_an_existing_one(void) void test_refs_branches_create__can_not_create_a_branch_if_its_name_collide_with_an_existing_one(void)
...@@ -62,29 +62,6 @@ void test_refs_branches_create__can_force_create_over_an_existing_branch(void) ...@@ -62,29 +62,6 @@ void test_refs_branches_create__can_force_create_over_an_existing_branch(void)
retrieve_known_commit(&target, repo); retrieve_known_commit(&target, repo);
cl_git_pass(git_branch_create(&branch, repo, "br2", target, 1)); cl_git_pass(git_branch_create(&branch, repo, "br2", target, 1));
cl_git_pass(git_oid_cmp(git_reference_target(branch), git_object_id(target))); cl_git_pass(git_oid_cmp(git_reference_target(branch), git_commit_id(target)));
cl_assert_equal_s("refs/heads/br2", git_reference_name(branch)); cl_assert_equal_s("refs/heads/br2", git_reference_name(branch));
} }
void test_refs_branches_create__creating_a_branch_targeting_a_tag_dereferences_it_to_its_commit(void)
{
/* b25fa35 is a tag, pointing to another tag which points to a commit */
retrieve_target_from_oid(&target, repo, "b25fa35b38051e4ae45d4222e795f9df2e43f1d1");
cl_git_pass(git_branch_create(&branch, repo, NEW_BRANCH_NAME, target, 0));
cl_git_pass(git_oid_streq(git_reference_target(branch), "e90810b8df3e80c413d903f631643c716887138d"));
}
void test_refs_branches_create__can_not_create_a_branch_pointing_to_a_non_commit_object(void)
{
/* 53fc32d is the tree of commit e90810b */
retrieve_target_from_oid(&target, repo, "53fc32d17276939fc79ed05badaef2db09990016");
cl_git_fail(git_branch_create(&branch, repo, NEW_BRANCH_NAME, target, 0));
git_object_free(target);
/* 521d87c is an annotated tag pointing to a blob */
retrieve_target_from_oid(&target, repo, "521d87c1ec3aef9824daf6d96cc0ae3710766d91");
cl_git_fail(git_branch_create(&branch, repo, NEW_BRANCH_NAME, target, 0));
}
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