Commit 3ff1d123 by Russell Belfer

Rename diff objects and split patch.h

This makes no functional change to diff but renames a couple of
the objects and splits the new git_patch (formerly git_diff_patch)
into a new header file.
parent 74353137
......@@ -45,7 +45,7 @@ char *colors[] = {
static int printer(
const git_diff_delta *delta,
const git_diff_range *range,
const git_diff_hunk *range,
char usage,
const char *line,
size_t line_len,
......@@ -126,7 +126,7 @@ int main(int argc, char *argv[])
git_tree *t1 = NULL, *t2 = NULL;
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
git_diff_find_options findopts = GIT_DIFF_FIND_OPTIONS_INIT;
git_diff_list *diff;
git_diff *diff;
int i, color = -1, format = FORMAT_PATCH, cached = 0;
char *a, *treeish1 = NULL, *treeish2 = NULL;
const char *dir = ".";
......@@ -218,11 +218,11 @@ int main(int argc, char *argv[])
else if (t1 && cached)
check(git_diff_tree_to_index(&diff, repo, t1, NULL, &opts), "Diff");
else if (t1) {
git_diff_list *diff2;
git_diff *diff2;
check(git_diff_tree_to_index(&diff, repo, t1, NULL, &opts), "Diff");
check(git_diff_index_to_workdir(&diff2, repo, NULL, &opts), "Diff");
check(git_diff_merge(diff, diff2), "Merge diffs");
git_diff_list_free(diff2);
git_diff_free(diff2);
}
else if (cached) {
check(resolve_to_tree(repo, "HEAD", &t1), "looking up HEAD");
......@@ -253,7 +253,7 @@ int main(int argc, char *argv[])
if (color >= 0)
fputs(colors[0], stdout);
git_diff_list_free(diff);
git_diff_free(diff);
git_tree_free(t1);
git_tree_free(t2);
git_repository_free(repo);
......
......@@ -184,7 +184,7 @@ static void print_commit(git_commit *commit)
static int print_diff(
const git_diff_delta *delta,
const git_diff_range *range,
const git_diff_hunk *range,
char usage,
const char *line,
size_t line_len,
......@@ -218,7 +218,7 @@ static int match_with_parent(
{
git_commit *parent;
git_tree *a, *b;
git_diff_list *diff;
git_diff *diff;
int ndeltas;
check(git_commit_parent(&parent, commit, (size_t)i), "Get parent", NULL);
......@@ -229,7 +229,7 @@ static int match_with_parent(
ndeltas = (int)git_diff_num_deltas(diff);
git_diff_list_free(diff);
git_diff_free(diff);
git_tree_free(a);
git_tree_free(b);
git_commit_free(parent);
......@@ -373,7 +373,7 @@ int main(int argc, char *argv[])
if (opt.show_diff) {
git_tree *a = NULL, *b = NULL;
git_diff_list *diff = NULL;
git_diff *diff = NULL;
if (parents > 1)
continue;
......@@ -391,7 +391,7 @@ int main(int argc, char *argv[])
check(git_diff_print_patch(diff, print_diff, NULL),
"Displaying diff", NULL);
git_diff_list_free(diff);
git_diff_free(diff);
git_tree_free(a);
git_tree_free(b);
}
......
......@@ -32,6 +32,7 @@
#include "git2/odb.h"
#include "git2/oid.h"
#include "git2/pack.h"
#include "git2/patch.h"
#include "git2/pathspec.h"
#include "git2/push.h"
#include "git2/refdb.h"
......
......@@ -20,34 +20,38 @@
* Overview
* --------
*
* Calculating diffs is generally done in two phases: building a diff list
* then traversing the diff list. This makes is easier to share logic
* across the various types of diffs (tree vs tree, workdir vs index, etc.),
* and also allows you to insert optional diff list post-processing phases,
* such as rename detected, in between the steps. When you are done with a
* diff list object, it must be freed.
* Calculating diffs is generally done in two phases: building a list of
* diffs then traversing it. This makes is easier to share logic across
* the various types of diffs (tree vs tree, workdir vs index, etc.), and
* also allows you to insert optional diff list post-processing phases,
* such as rename detection, in between the steps. When you are done with
* a diff object, it must be freed.
*
* Terminology
* -----------
*
* To understand the diff APIs, you should know the following terms:
*
* - A `diff` or `diff list` represents the cumulative list of differences
* between two snapshots of a repository (possibly filtered by a set of
* file name patterns). This is the `git_diff_list` object.
* - A `diff` represents the cumulative list of differences between two
* snapshots of a repository (possibly filtered by a set of file name
* patterns). This is the `git_diff` object.
*
* - A `delta` is a file pair with an old and new revision. The old version
* may be absent if the file was just created and the new version may be
* absent if the file was deleted. A diff is mostly just a list of deltas.
*
* - A `binary` file / delta is a file (or pair) for which no text diffs
* should be generated. A diff list can contain delta entries that are
* should be generated. A diff can contain delta entries that are
* binary, but no diff content will be output for those files. There is
* a base heuristic for binary detection and you can further tune the
* behavior with git attributes or diff flags and option settings.
*
* - A `hunk` is a span of modified lines in a delta along with some stable
* surrounding context. You can configure the amount of context and other
* properties of how hunks are generated. Each hunk also comes with a
* header that described where it starts and ends in both the old and new
* versions in the delta.
*
* - A `line` is a range of characters inside a hunk. It could be a context
* line (i.e. in both old and new versions), an added line (i.e. only in
* the new version), or a removed line (i.e. only in the old version).
......@@ -154,14 +158,14 @@ typedef enum {
} git_diff_option_t;
/**
* The diff list object that contains all individual file deltas.
* The diff object that contains all individual file deltas.
*
* This is an opaque structure which will be allocated by one of the diff
* generator functions below (such as `git_diff_tree_to_tree`). You are
* responsible for releasing the object memory when done, using the
* `git_diff_list_free()` function.
* `git_diff_free()` function.
*/
typedef struct git_diff_list git_diff_list;
typedef struct git_diff git_diff;
/**
* Flags for the delta object and the file objects on each side.
......@@ -200,11 +204,11 @@ typedef enum {
} git_delta_t;
/**
* Description of one side of a diff entry.
* Description of one side of a delta.
*
* Although this is called a "file", it may actually represent a file, a
* symbolic link, a submodule commit id, or even a tree (although that only
* if you are tracking type changes or ignored/untracked directories).
* Although this is called a "file", it could represent a file, a symbolic
* link, a submodule commit id, or even a tree (although that only if you
* are tracking type changes or ignored/untracked directories).
*
* The `oid` is the `git_oid` of the item. If the entry represents an
* absent side of a diff (e.g. the `old_file` of a `GIT_DELTA_ADDED` delta),
......@@ -231,9 +235,8 @@ typedef struct {
/**
* Description of changes to one entry.
*
* When iterating over a diff list object, this will be passed to most
* callback functions and you can use the contents to understand exactly
* what has changed.
* When iterating over a diff, this will be passed to most callbacks and
* you can use the contents to understand exactly what has changed.
*
* The `old_file` represents the "from" side of the diff and the `new_file`
* represents to "to" side of the diff. What those means depend on the
......@@ -266,18 +269,18 @@ typedef struct {
* the score (a la `printf("M%03d", 100 - delta->similarity)`).
*/
typedef struct {
git_diff_file old_file;
git_diff_file new_file;
git_delta_t status;
uint32_t similarity; /**< for RENAMED and COPIED, value 0-100 */
uint32_t flags;
git_diff_file old_file;
git_diff_file new_file;
} git_diff_delta;
/**
* Diff notification callback function.
*
* The callback will be called for each file, just before the `git_delta_t`
* gets inserted into the diff list.
* gets inserted into the diff.
*
* When the callback:
* - returns < 0, the diff process will be aborted.
......@@ -287,7 +290,7 @@ typedef struct {
* continues.
*/
typedef int (*git_diff_notify_cb)(
const git_diff_list *diff_so_far,
const git_diff *diff_so_far,
const git_diff_delta *delta_to_add,
const char *matched_pathspec,
void *payload);
......@@ -349,19 +352,20 @@ typedef int (*git_diff_file_cb)(
/**
* Structure describing a hunk of a diff.
*/
typedef struct {
typedef struct git_diff_hunk git_diff_hunk;
struct git_diff_hunk {
int old_start; /** Starting line number in old_file */
int old_lines; /** Number of lines in old_file */
int new_start; /** Starting line number in new_file */
int new_lines; /** Number of lines in new_file */
} git_diff_range;
};
/**
* When iterating over a diff, callback that will be made per hunk.
*/
typedef int (*git_diff_hunk_cb)(
const git_diff_delta *delta,
const git_diff_range *range,
const git_diff_hunk *hunk,
const char *header,
size_t header_len,
void *payload);
......@@ -370,13 +374,13 @@ typedef int (*git_diff_hunk_cb)(
* Line origin constants.
*
* These values describe where a line came from and will be passed to
* the git_diff_data_cb when iterating over a diff. There are some
* the git_diff_line_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_cb` along with the line */
/* These values will be sent to `git_diff_line_cb` along with the line */
GIT_DIFF_LINE_CONTEXT = ' ',
GIT_DIFF_LINE_ADDITION = '+',
GIT_DIFF_LINE_DELETION = '-',
......@@ -385,7 +389,7 @@ typedef enum {
GIT_DIFF_LINE_ADD_EOFNL = '>', /**< Old has no LF at end, new does */
GIT_DIFF_LINE_DEL_EOFNL = '<', /**< Old has LF at end, new does not */
/* The following values will only be sent to a `git_diff_data_cb` when
/* The following values will only be sent to a `git_diff_line_cb` when
* the content of a diff is being formatted (eg. through
* git_diff_print_patch() or git_diff_print_compact(), for instance).
*/
......@@ -402,23 +406,15 @@ 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_cb)(
typedef int (*git_diff_line_cb)(
const git_diff_delta *delta, /** delta that contains this data */
const git_diff_range *range, /** range of lines containing this data */
char line_origin, /** git_diff_list_t value from above */
const git_diff_hunk *hunk, /** range of lines containing this data */
char line_origin, /** git_diff_t value from above */
const char *content, /** diff data - not NUL terminated */
size_t content_len, /** number of bytes of diff data */
void *payload); /** user reference data */
/**
* The diff patch is used to store all the text diffs for a delta.
*
* You can easily loop over the content of patches and get information about
* them.
*/
typedef struct git_diff_patch git_diff_patch;
/**
* Flags to control the behavior of diff rename/copy detection.
*/
typedef enum {
......@@ -524,7 +520,7 @@ typedef struct {
/** @name Diff List Generator Functions
*
* These are the functions you would use to create (or destroy) a
* git_diff_list from various objects in a repository.
* git_diff from various objects in a repository.
*/
/**@{*/
......@@ -533,7 +529,7 @@ typedef struct {
*
* @param diff The previously created diff list; cannot be used after free.
*/
GIT_EXTERN(void) git_diff_list_free(git_diff_list *diff);
GIT_EXTERN(void) git_diff_free(git_diff *diff);
/**
* Create a diff list with the difference between two tree objects.
......@@ -545,14 +541,14 @@ GIT_EXTERN(void) git_diff_list_free(git_diff_list *diff);
* pass NULL to indicate an empty tree, although it is an error to pass
* NULL for both the `old_tree` and `new_tree`.
*
* @param diff Output pointer to a git_diff_list pointer to be allocated.
* @param diff Output pointer to a git_diff pointer to be allocated.
* @param repo The repository containing the trees.
* @param old_tree A git_tree object to diff from, or NULL for empty tree.
* @param new_tree A git_tree object to diff to, or NULL for empty tree.
* @param opts Structure with options to influence diff or NULL for defaults.
*/
GIT_EXTERN(int) git_diff_tree_to_tree(
git_diff_list **diff,
git_diff **diff,
git_repository *repo,
git_tree *old_tree,
git_tree *new_tree,
......@@ -567,14 +563,14 @@ GIT_EXTERN(int) git_diff_tree_to_tree(
* The tree you pass will be used for the "old_file" side of the delta, and
* the index will be used for the "new_file" side of the delta.
*
* @param diff Output pointer to a git_diff_list pointer to be allocated.
* @param diff Output pointer to a git_diff pointer to be allocated.
* @param repo The repository containing the tree and index.
* @param old_tree A git_tree object to diff from, or NULL for empty tree.
* @param index The index to diff with; repo index used if NULL.
* @param opts Structure with options to influence diff or NULL for defaults.
*/
GIT_EXTERN(int) git_diff_tree_to_index(
git_diff_list **diff,
git_diff **diff,
git_repository *repo,
git_tree *old_tree,
git_index *index,
......@@ -591,13 +587,13 @@ GIT_EXTERN(int) git_diff_tree_to_index(
* The index will be used for the "old_file" side of the delta, and the
* working directory will be used for the "new_file" side of the delta.
*
* @param diff Output pointer to a git_diff_list pointer to be allocated.
* @param diff Output pointer to a git_diff pointer to be allocated.
* @param repo The repository.
* @param index The index to diff from; repo index used if NULL.
* @param opts Structure with options to influence diff or NULL for defaults.
*/
GIT_EXTERN(int) git_diff_index_to_workdir(
git_diff_list **diff,
git_diff **diff,
git_repository *repo,
git_index *index,
const git_diff_options *opts); /**< can be NULL for defaults */
......@@ -619,20 +615,20 @@ GIT_EXTERN(int) git_diff_index_to_workdir(
*
* To emulate `git diff <treeish>`, call both `git_diff_tree_to_index` and
* `git_diff_index_to_workdir`, then call `git_diff_merge` on the results.
* That will yield a `git_diff_list` that matches the git output.
* That will yield a `git_diff` that matches the git output.
*
* If this seems confusing, take the case of a file with a staged deletion
* where the file has then been put back into the working dir and modified.
* The tree-to-workdir diff for that file is 'modified', but core git would
* show status 'deleted' since there is a pending deletion in the index.
*
* @param diff A pointer to a git_diff_list pointer that will be allocated.
* @param diff A pointer to a git_diff pointer that will be allocated.
* @param repo The repository containing the tree.
* @param old_tree A git_tree object to diff from, or NULL for empty tree.
* @param opts Structure with options to influence diff or NULL for defaults.
*/
GIT_EXTERN(int) git_diff_tree_to_workdir(
git_diff_list **diff,
git_diff **diff,
git_repository *repo,
git_tree *old_tree,
const git_diff_options *opts); /**< can be NULL for defaults */
......@@ -651,8 +647,8 @@ GIT_EXTERN(int) git_diff_tree_to_workdir(
* @param from Diff to merge.
*/
GIT_EXTERN(int) git_diff_merge(
git_diff_list *onto,
const git_diff_list *from);
git_diff *onto,
const git_diff *from);
/**
* Transform a diff list marking file renames, copies, etc.
......@@ -667,7 +663,7 @@ GIT_EXTERN(int) git_diff_merge(
* @return 0 on success, -1 on failure
*/
GIT_EXTERN(int) git_diff_find_similar(
git_diff_list *diff,
git_diff *diff,
git_diff_find_options *options);
/**@}*/
......@@ -694,7 +690,7 @@ GIT_EXTERN(int) git_diff_find_similar(
* Returning a non-zero value from any of the callbacks will terminate
* the iteration and cause this return `GIT_EUSER`.
*
* @param diff A git_diff_list generated by one of the above functions.
* @param diff A git_diff generated by one of the above functions.
* @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
......@@ -706,10 +702,10 @@ GIT_EXTERN(int) git_diff_find_similar(
* @return 0 on success, GIT_EUSER on non-zero callback, or error code
*/
GIT_EXTERN(int) git_diff_foreach(
git_diff_list *diff,
git_diff *diff,
git_diff_file_cb file_cb,
git_diff_hunk_cb hunk_cb,
git_diff_data_cb line_cb,
git_diff_line_cb line_cb,
void *payload);
/**
......@@ -718,14 +714,14 @@ GIT_EXTERN(int) git_diff_foreach(
* Returning a non-zero value from the callbacks will terminate the
* iteration and cause this return `GIT_EUSER`.
*
* @param diff A git_diff_list generated by one of the above functions.
* @param diff A git_diff generated by one of the above functions.
* @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,
git_diff_data_cb print_cb,
git_diff *diff,
git_diff_line_cb print_cb,
void *payload);
/**
......@@ -734,14 +730,14 @@ GIT_EXTERN(int) git_diff_print_compact(
* Returning a non-zero value from the callbacks will terminate the
* iteration and cause this return `GIT_EUSER`.
*
* @param diff A git_diff_list generated by one of the above functions.
* @param diff A git_diff generated by one of the above functions.
* @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_raw(
git_diff_list *diff,
git_diff_data_cb print_cb,
git_diff *diff,
git_diff_line_cb print_cb,
void *payload);
/**
......@@ -766,7 +762,7 @@ GIT_EXTERN(char) git_diff_status_char(git_delta_t status);
* Returning a non-zero value from the callbacks will terminate the
* iteration and cause this return `GIT_EUSER`.
*
* @param diff A git_diff_list generated by one of the above functions.
* @param diff A git_diff generated by one of the above functions.
* @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
......@@ -776,17 +772,17 @@ GIT_EXTERN(char) git_diff_status_char(git_delta_t status);
* @return 0 on success, GIT_EUSER on non-zero callback, or error code
*/
GIT_EXTERN(int) git_diff_print_patch(
git_diff_list *diff,
git_diff_data_cb print_cb,
git_diff *diff,
git_diff_line_cb print_cb,
void *payload);
/**
* Query how many diff records are there in a diff list.
*
* @param diff A git_diff_list generated by one of the above functions
* @param diff A git_diff generated by one of the above functions
* @return Count of number of deltas in the list
*/
GIT_EXTERN(size_t) git_diff_num_deltas(git_diff_list *diff);
GIT_EXTERN(size_t) git_diff_num_deltas(git_diff *diff);
/**
* Query how many diff deltas are there in a diff list filtered by type.
......@@ -795,12 +791,12 @@ GIT_EXTERN(size_t) git_diff_num_deltas(git_diff_list *diff);
* that is a `git_delta_t` and returns just the count of how many deltas
* match that particular type.
*
* @param diff A git_diff_list generated by one of the above functions
* @param diff A git_diff generated by one of the above functions
* @param type A git_delta_t value to filter the count
* @return Count of number of deltas matching delta_t type
*/
GIT_EXTERN(size_t) git_diff_num_deltas_of_type(
git_diff_list *diff,
git_diff *diff,
git_delta_t type);
/**
......@@ -809,191 +805,7 @@ GIT_EXTERN(size_t) git_diff_num_deltas_of_type(
* @param diff Diff list to check
* @return 0 if case sensitive, 1 if case is ignored
*/
GIT_EXTERN(int) git_diff_is_sorted_icase(const git_diff_list *diff);
/**
* Return the diff delta and patch for an entry in the diff list.
*
* The `git_diff_patch` is a newly created object contains the text diffs
* for the delta. You have to call `git_diff_patch_free()` when you are
* done with it. You can use the patch object to loop over all the hunks
* and lines in the diff of the one delta.
*
* For an unchanged file or a binary file, no `git_diff_patch` will be
* created, the output will be set to NULL, and the `binary` flag will be
* set true in the `git_diff_delta` structure.
*
* The `git_diff_delta` pointer points to internal data and you do not have
* to release it when you are done with it. It will go away when the
* `git_diff_list` and `git_diff_patch` go away.
*
* 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_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_out,
const git_diff_delta **delta_out,
git_diff_list *diff,
size_t idx);
/**
* Free a git_diff_patch object.
*/
GIT_EXTERN(void) git_diff_patch_free(
git_diff_patch *patch);
/**
* Get the delta associated with a patch
*/
GIT_EXTERN(const git_diff_delta *) git_diff_patch_delta(
git_diff_patch *patch);
/**
* Get the number of hunks in a patch
*/
GIT_EXTERN(size_t) git_diff_patch_num_hunks(
git_diff_patch *patch);
/**
* Get line counts of each type in a patch.
*
* This helps imitate a diff --numstat type of output. For that purpose,
* you only need the `total_additions` and `total_deletions` values, but we
* include the `total_context` line count in case you want the total number
* of lines of diff output that will be generated.
*
* All outputs are optional. Pass NULL if you don't need a particular count.
*
* @param total_context Count of context lines in output, can be NULL.
* @param total_additions Count of addition lines in output, can be NULL.
* @param total_deletions Count of deletion lines in output, can be NULL.
* @param patch The git_diff_patch object
* @return 0 on success, <0 on error
*/
GIT_EXTERN(int) git_diff_patch_line_stats(
size_t *total_context,
size_t *total_additions,
size_t *total_deletions,
const git_diff_patch *patch);
/**
* Get the information about a hunk in a patch
*
* Given a patch and a hunk index into the patch, this returns detailed
* information about that hunk. Any of the output pointers can be passed
* as NULL if you don't care about that particular piece of information.
*
* @param range Output pointer to git_diff_range of hunk
* @param header Output pointer to header string for hunk. Unlike the
* content pointer for each line, this will be NUL-terminated
* @param header_len Output value of characters in header string
* @param lines_in_hunk Output count of total lines in this hunk
* @param patch Input pointer to patch object
* @param hunk_idx Input index of hunk to get information about
* @return 0 on success, GIT_ENOTFOUND if hunk_idx out of range, <0 on error
*/
GIT_EXTERN(int) git_diff_patch_get_hunk(
const git_diff_range **range,
const char **header,
size_t *header_len,
size_t *lines_in_hunk,
git_diff_patch *patch,
size_t hunk_idx);
/**
* Get the number of lines in a hunk.
*
* @param patch The git_diff_patch object
* @param hunk_idx Index of the hunk
* @return Number of lines in hunk or -1 if invalid hunk index
*/
GIT_EXTERN(int) git_diff_patch_num_lines_in_hunk(
git_diff_patch *patch,
size_t hunk_idx);
/**
* Get data about a line in a hunk of a patch.
*
* Given a patch, a hunk index, and a line index in the hunk, this
* will return a lot of details about that line. If you pass a hunk
* index larger than the number of hunks or a line index larger than
* the number of lines in the hunk, this will return -1.
*
* @param line_origin A GIT_DIFF_LINE constant from above
* @param content Pointer to content of diff line, not NUL-terminated
* @param content_len Number of characters in content
* @param old_lineno Line number in old file or -1 if line is added
* @param new_lineno Line number in new file or -1 if line is deleted
* @param patch The patch to look in
* @param hunk_idx The index of the hunk
* @param line_of_hunk The index of the line in the hunk
* @return 0 on success, <0 on failure
*/
GIT_EXTERN(int) git_diff_patch_get_line_in_hunk(
char *line_origin,
const char **content,
size_t *content_len,
int *old_lineno,
int *new_lineno,
git_diff_patch *patch,
size_t hunk_idx,
size_t line_of_hunk);
/**
* Look up size of patch diff data in bytes
*
* This returns the raw size of the patch data. This only includes the
* actual data from the lines of the diff, not the file or hunk headers.
*
* If you pass `include_context` as true (non-zero), this will be the size
* of all of the diff output; if you pass it as false (zero), this will
* only include the actual changed lines (as if `context_lines` was 0).
*
* @param patch A git_diff_patch representing changes to one file
* @param include_context Include context lines in size if non-zero
* @param include_hunk_headers Include hunk header lines if non-zero
* @param include_file_headers Include file header lines if non-zero
* @return The number of bytes of data
*/
GIT_EXTERN(size_t) git_diff_patch_size(
git_diff_patch *patch,
int include_context,
int include_hunk_headers,
int include_file_headers);
/**
* Serialize the patch to text via callback.
*
* Returning a non-zero value from the callback will terminate the iteration
* and cause this return `GIT_EUSER`.
*
* @param patch A git_diff_patch representing changes to one file
* @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,
git_diff_data_cb print_cb,
void *payload);
/**
* Get the content of a patch as a single diff text.
*
* @param string Allocated string; caller must free.
* @param patch A git_diff_patch representing changes to one file
* @return 0 on success, <0 on failure.
*/
GIT_EXTERN(int) git_diff_patch_to_str(
char **string,
git_diff_patch *patch);
GIT_EXTERN(int) git_diff_is_sorted_icase(const git_diff *diff);
/**@}*/
......@@ -1037,34 +849,10 @@ GIT_EXTERN(int) git_diff_blobs(
const git_diff_options *options,
git_diff_file_cb file_cb,
git_diff_hunk_cb hunk_cb,
git_diff_data_cb line_cb,
git_diff_line_cb line_cb,
void *payload);
/**
* Directly generate a patch from the difference between two blobs.
*
* This is just like `git_diff_blobs()` except it generates a patch object
* for the difference instead of directly making callbacks. You can use the
* standard `git_diff_patch` accessor functions to read the patch data, and
* you must call `git_diff_patch_free()` on the patch when done.
*
* @param out The generated patch; NULL on error
* @param old_blob Blob for old side of diff, or NULL for empty blob
* @param old_as_path Treat old blob as if it had this filename; can be NULL
* @param new_blob Blob for new side of diff, or NULL for empty blob
* @param new_as_path Treat new blob as if it had this filename; can be NULL
* @param opts Options for diff, or NULL for default options
* @return 0 on success or error code < 0
*/
GIT_EXTERN(int) git_diff_patch_from_blobs(
git_diff_patch **out,
const git_blob *old_blob,
const char *old_as_path,
const git_blob *new_blob,
const char *new_as_path,
const git_diff_options *opts);
/**
* Directly run a diff between a blob and a buffer.
*
* As with `git_diff_blobs`, comparing a blob and buffer lacks some context,
......@@ -1084,7 +872,7 @@ GIT_EXTERN(int) git_diff_patch_from_blobs(
* @param options Options for diff, or NULL for default options
* @param file_cb Callback for "file"; made once if there is a diff; can be NULL
* @param hunk_cb Callback for each hunk in diff; can be NULL
* @param data_cb Callback for each line in diff; can be NULL
* @param line_cb Callback for each line in diff; can be NULL
* @param payload Payload passed to each callback function
* @return 0 on success, GIT_EUSER on non-zero callback return, or error code
*/
......@@ -1097,35 +885,9 @@ GIT_EXTERN(int) git_diff_blob_to_buffer(
const git_diff_options *options,
git_diff_file_cb file_cb,
git_diff_hunk_cb hunk_cb,
git_diff_data_cb data_cb,
git_diff_line_cb line_cb,
void *payload);
/**
* Directly generate a patch from the difference between a blob and a buffer.
*
* This is just like `git_diff_blob_to_buffer()` except it generates a patch
* object for the difference instead of directly making callbacks. You can
* use the standard `git_diff_patch` accessor functions to read the patch
* data, and you must call `git_diff_patch_free()` on the patch when done.
*
* @param out The generated patch; NULL on error
* @param old_blob Blob for old side of diff, or NULL for empty blob
* @param old_as_path Treat old blob as if it had this filename; can be NULL
* @param buffer Raw data for new side of diff, or NULL for empty
* @param buffer_len Length of raw data for new side of diff
* @param buffer_as_path Treat buffer as if it had this filename; can be NULL
* @param opts Options for diff, or NULL for default options
* @return 0 on success or error code < 0
*/
GIT_EXTERN(int) git_diff_patch_from_blob_and_buffer(
git_diff_patch **out,
const git_blob *old_blob,
const char *old_as_path,
const char *buffer,
size_t buffer_len,
const char *buffer_as_path,
const git_diff_options *opts);
GIT_END_DECL
......
/*
* Copyright (C) the libgit2 contributors. All rights reserved.
*
* This file is part of libgit2, distributed under the GNU GPL v2 with
* a Linking Exception. For full terms see the included COPYING file.
*/
#ifndef INCLUDE_git_patch_h__
#define INCLUDE_git_patch_h__
#include "common.h"
#include "types.h"
#include "oid.h"
#include "diff.h"
/**
* @file git2/patch.h
* @brief Patch handling routines.
* @ingroup Git
* @{
*/
GIT_BEGIN_DECL
/**
* The diff patch is used to store all the text diffs for a delta.
*
* You can easily loop over the content of patches and get information about
* them.
*/
typedef struct git_patch git_patch;
/**
* Return the diff delta and patch for an entry in the diff list.
*
* The `git_patch` is a newly created object contains the text diffs
* for the delta. You have to call `git_patch_free()` when you are
* done with it. You can use the patch object to loop over all the hunks
* and lines in the diff of the one delta.
*
* For an unchanged file or a binary file, no `git_patch` will be
* created, the output will be set to NULL, and the `binary` flag will be
* set true in the `git_diff_delta` structure.
*
* The `git_diff_delta` pointer points to internal data and you do not have
* to release it when you are done with it. It will go away when the
* `git_diff` and `git_patch` go away.
*
* It is okay to pass NULL for either of the output parameters; if you pass
* NULL for the `git_patch`, then the text diff will not be calculated.
*
* @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_patch_from_diff(
git_patch **patch_out,
const git_diff_delta **delta_out,
git_diff *diff,
size_t idx);
/**
* Directly generate a patch from the difference between two blobs.
*
* This is just like `git_diff_blobs()` except it generates a patch object
* for the difference instead of directly making callbacks. You can use the
* standard `git_patch` accessor functions to read the patch data, and
* you must call `git_patch_free()` on the patch when done.
*
* @param out The generated patch; NULL on error
* @param old_blob Blob for old side of diff, or NULL for empty blob
* @param old_as_path Treat old blob as if it had this filename; can be NULL
* @param new_blob Blob for new side of diff, or NULL for empty blob
* @param new_as_path Treat new blob as if it had this filename; can be NULL
* @param opts Options for diff, or NULL for default options
* @return 0 on success or error code < 0
*/
GIT_EXTERN(int) git_patch_from_blobs(
git_patch **out,
const git_blob *old_blob,
const char *old_as_path,
const git_blob *new_blob,
const char *new_as_path,
const git_diff_options *opts);
/**
* Directly generate a patch from the difference between a blob and a buffer.
*
* This is just like `git_diff_blob_to_buffer()` except it generates a patch
* object for the difference instead of directly making callbacks. You can
* use the standard `git_patch` accessor functions to read the patch
* data, and you must call `git_patch_free()` on the patch when done.
*
* @param out The generated patch; NULL on error
* @param old_blob Blob for old side of diff, or NULL for empty blob
* @param old_as_path Treat old blob as if it had this filename; can be NULL
* @param buffer Raw data for new side of diff, or NULL for empty
* @param buffer_len Length of raw data for new side of diff
* @param buffer_as_path Treat buffer as if it had this filename; can be NULL
* @param opts Options for diff, or NULL for default options
* @return 0 on success or error code < 0
*/
GIT_EXTERN(int) git_patch_from_blob_and_buffer(
git_patch **out,
const git_blob *old_blob,
const char *old_as_path,
const char *buffer,
size_t buffer_len,
const char *buffer_as_path,
const git_diff_options *opts);
/**
* Free a git_patch object.
*/
GIT_EXTERN(void) git_patch_free(
git_patch *patch);
/**
* Get the delta associated with a patch
*/
GIT_EXTERN(const git_diff_delta *) git_patch_delta(
git_patch *patch);
/**
* Get the number of hunks in a patch
*/
GIT_EXTERN(size_t) git_patch_num_hunks(
git_patch *patch);
/**
* Get line counts of each type in a patch.
*
* This helps imitate a diff --numstat type of output. For that purpose,
* you only need the `total_additions` and `total_deletions` values, but we
* include the `total_context` line count in case you want the total number
* of lines of diff output that will be generated.
*
* All outputs are optional. Pass NULL if you don't need a particular count.
*
* @param total_context Count of context lines in output, can be NULL.
* @param total_additions Count of addition lines in output, can be NULL.
* @param total_deletions Count of deletion lines in output, can be NULL.
* @param patch The git_patch object
* @return 0 on success, <0 on error
*/
GIT_EXTERN(int) git_patch_line_stats(
size_t *total_context,
size_t *total_additions,
size_t *total_deletions,
const git_patch *patch);
/**
* Get the information about a hunk in a patch
*
* Given a patch and a hunk index into the patch, this returns detailed
* information about that hunk. Any of the output pointers can be passed
* as NULL if you don't care about that particular piece of information.
*
* @param out Output pointer to git_diff_hunk of hunk
* @param header Output pointer to header string for hunk. Unlike the
* content pointer for each line, this will be NUL-terminated
* @param header_len Output value of characters in header string
* @param lines_in_hunk Output count of total lines in this hunk
* @param patch Input pointer to patch object
* @param hunk_idx Input index of hunk to get information about
* @return 0 on success, GIT_ENOTFOUND if hunk_idx out of range, <0 on error
*/
GIT_EXTERN(int) git_patch_get_hunk(
const git_diff_hunk **out,
const char **header,
size_t *header_len,
size_t *lines_in_hunk,
git_patch *patch,
size_t hunk_idx);
/**
* Get the number of lines in a hunk.
*
* @param patch The git_patch object
* @param hunk_idx Index of the hunk
* @return Number of lines in hunk or -1 if invalid hunk index
*/
GIT_EXTERN(int) git_patch_num_lines_in_hunk(
git_patch *patch,
size_t hunk_idx);
/**
* Get data about a line in a hunk of a patch.
*
* Given a patch, a hunk index, and a line index in the hunk, this
* will return a lot of details about that line. If you pass a hunk
* index larger than the number of hunks or a line index larger than
* the number of lines in the hunk, this will return -1.
*
* @param line_origin A GIT_DIFF_LINE constant from above
* @param content Pointer to content of diff line, not NUL-terminated
* @param content_len Number of characters in content
* @param old_lineno Line number in old file or -1 if line is added
* @param new_lineno Line number in new file or -1 if line is deleted
* @param patch The patch to look in
* @param hunk_idx The index of the hunk
* @param line_of_hunk The index of the line in the hunk
* @return 0 on success, <0 on failure
*/
GIT_EXTERN(int) git_patch_get_line_in_hunk(
char *line_origin,
const char **content,
size_t *content_len,
int *old_lineno,
int *new_lineno,
git_patch *patch,
size_t hunk_idx,
size_t line_of_hunk);
/**
* Look up size of patch diff data in bytes
*
* This returns the raw size of the patch data. This only includes the
* actual data from the lines of the diff, not the file or hunk headers.
*
* If you pass `include_context` as true (non-zero), this will be the size
* of all of the diff output; if you pass it as false (zero), this will
* only include the actual changed lines (as if `context_lines` was 0).
*
* @param patch A git_patch representing changes to one file
* @param include_context Include context lines in size if non-zero
* @param include_hunk_headers Include hunk header lines if non-zero
* @param include_file_headers Include file header lines if non-zero
* @return The number of bytes of data
*/
GIT_EXTERN(size_t) git_patch_size(
git_patch *patch,
int include_context,
int include_hunk_headers,
int include_file_headers);
/**
* Serialize the patch to text via callback.
*
* Returning a non-zero value from the callback will terminate the iteration
* and cause this return `GIT_EUSER`.
*
* @param patch A git_patch representing changes to one file
* @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_patch_print(
git_patch *patch,
git_diff_line_cb print_cb,
void *payload);
/**
* Get the content of a patch as a single diff text.
*
* @param string Allocated string; caller must free.
* @param patch A git_patch representing changes to one file
* @return 0 on success, <0 on failure.
*/
GIT_EXTERN(int) git_patch_to_str(
char **string,
git_patch *patch);
GIT_END_DECL
/**@}*/
#endif
......@@ -187,7 +187,7 @@ GIT_EXTERN(int) git_pathspec_match_tree(
*/
GIT_EXTERN(int) git_pathspec_match_diff(
git_pathspec_match_list **out,
git_diff_list *diff,
git_diff *diff,
uint32_t flags,
git_pathspec *ps);
......
......@@ -43,7 +43,7 @@ enum {
typedef struct {
git_repository *repo;
git_diff_list *diff;
git_diff *diff;
git_checkout_opts opts;
bool opts_free_baseline;
char *pfx;
......@@ -1320,7 +1320,7 @@ cleanup:
(data.strategy & GIT_CHECKOUT_DONT_UPDATE_INDEX) == 0)
error = git_index_write(data.index);
git_diff_list_free(data.diff);
git_diff_free(data.diff);
git_iterator_free(workdir);
git_iterator_free(baseline);
git__free(actions);
......
......@@ -21,7 +21,7 @@
(VAL) ? ((DIFF)->opts.flags | (FLAG)) : ((DIFF)->opts.flags & ~(VAL))
static git_diff_delta *diff_delta__alloc(
git_diff_list *diff,
git_diff *diff,
git_delta_t status,
const char *path)
{
......@@ -50,7 +50,7 @@ static git_diff_delta *diff_delta__alloc(
}
static int diff_notify(
const git_diff_list *diff,
const git_diff *diff,
const git_diff_delta *delta,
const char *matched_pathspec)
{
......@@ -62,7 +62,7 @@ static int diff_notify(
}
static int diff_delta__from_one(
git_diff_list *diff,
git_diff *diff,
git_delta_t status,
const git_index_entry *entry)
{
......@@ -120,7 +120,7 @@ static int diff_delta__from_one(
}
static int diff_delta__from_two(
git_diff_list *diff,
git_diff *diff,
git_delta_t status,
const git_index_entry *old_entry,
uint32_t old_mode,
......@@ -181,7 +181,7 @@ static int diff_delta__from_two(
}
static git_diff_delta *diff_delta__last_for_item(
git_diff_list *diff,
git_diff *diff,
const git_index_entry *item)
{
git_diff_delta *delta = git_vector_last(&diff->deltas);
......@@ -340,13 +340,13 @@ static const char *diff_mnemonic_prefix(
return pfx;
}
static git_diff_list *diff_list_alloc(
static git_diff *diff_list_alloc(
git_repository *repo,
git_iterator *old_iter,
git_iterator *new_iter)
{
git_diff_options dflt = GIT_DIFF_OPTIONS_INIT;
git_diff_list *diff = git__calloc(1, sizeof(git_diff_list));
git_diff *diff = git__calloc(1, sizeof(git_diff));
if (!diff)
return NULL;
......@@ -360,7 +360,7 @@ static git_diff_list *diff_list_alloc(
if (git_vector_init(&diff->deltas, 0, git_diff_delta__cmp) < 0 ||
git_pool_init(&diff->pool, 1, 0) < 0) {
git_diff_list_free(diff);
git_diff_free(diff);
return NULL;
}
......@@ -389,7 +389,7 @@ static git_diff_list *diff_list_alloc(
}
static int diff_list_apply_options(
git_diff_list *diff,
git_diff *diff,
const git_diff_options *opts)
{
git_config *cfg;
......@@ -490,7 +490,7 @@ static int diff_list_apply_options(
return 0;
}
static void diff_list_free(git_diff_list *diff)
static void diff_list_free(git_diff *diff)
{
git_diff_delta *delta;
unsigned int i;
......@@ -508,7 +508,7 @@ static void diff_list_free(git_diff_list *diff)
git__free(diff);
}
void git_diff_list_free(git_diff_list *diff)
void git_diff_free(git_diff *diff)
{
if (!diff)
return;
......@@ -516,7 +516,7 @@ void git_diff_list_free(git_diff_list *diff)
GIT_REFCOUNT_DEC(diff, diff_list_free);
}
void git_diff_list_addref(git_diff_list *diff)
void git_diff_addref(git_diff *diff)
{
GIT_REFCOUNT_INC(diff);
}
......@@ -612,7 +612,7 @@ typedef struct {
static int maybe_modified_submodule(
git_delta_t *status,
git_oid *found_oid,
git_diff_list *diff,
git_diff *diff,
diff_in_progress *info)
{
int error = 0;
......@@ -659,7 +659,7 @@ static int maybe_modified_submodule(
}
static int maybe_modified(
git_diff_list *diff,
git_diff *diff,
diff_in_progress *info)
{
git_oid noid;
......@@ -778,7 +778,7 @@ static int maybe_modified(
}
static bool entry_is_prefixed(
git_diff_list *diff,
git_diff *diff,
const git_index_entry *item,
const git_index_entry *prefix_item)
{
......@@ -795,7 +795,7 @@ static bool entry_is_prefixed(
}
static int diff_scan_inside_untracked_dir(
git_diff_list *diff, diff_in_progress *info, git_delta_t *delta_type)
git_diff *diff, diff_in_progress *info, git_delta_t *delta_type)
{
int error = 0;
git_buf base = GIT_BUF_INIT;
......@@ -861,7 +861,7 @@ done:
}
static int handle_unmatched_new_item(
git_diff_list *diff, diff_in_progress *info)
git_diff *diff, diff_in_progress *info)
{
int error = 0;
const git_index_entry *nitem = info->nitem;
......@@ -1016,7 +1016,7 @@ static int handle_unmatched_new_item(
}
static int handle_unmatched_old_item(
git_diff_list *diff, diff_in_progress *info)
git_diff *diff, diff_in_progress *info)
{
int error = diff_delta__from_one(diff, GIT_DELTA_DELETED, info->oitem);
if (error < 0)
......@@ -1048,7 +1048,7 @@ static int handle_unmatched_old_item(
}
static int handle_matched_item(
git_diff_list *diff, diff_in_progress *info)
git_diff *diff, diff_in_progress *info)
{
int error = 0;
......@@ -1063,7 +1063,7 @@ static int handle_matched_item(
}
int git_diff__from_iterators(
git_diff_list **diff_ptr,
git_diff **diff_ptr,
git_repository *repo,
git_iterator *old_iter,
git_iterator *new_iter,
......@@ -1071,7 +1071,7 @@ int git_diff__from_iterators(
{
int error = 0;
diff_in_progress info;
git_diff_list *diff;
git_diff *diff;
*diff_ptr = NULL;
......@@ -1132,7 +1132,7 @@ cleanup:
if (!error)
*diff_ptr = diff;
else
git_diff_list_free(diff);
git_diff_free(diff);
git_buf_free(&info.ignore_prefix);
......@@ -1149,7 +1149,7 @@ cleanup:
} while (0)
int git_diff_tree_to_tree(
git_diff_list **diff,
git_diff **diff,
git_repository *repo,
git_tree *old_tree,
git_tree *new_tree,
......@@ -1176,7 +1176,7 @@ int git_diff_tree_to_tree(
}
int git_diff_tree_to_index(
git_diff_list **diff,
git_diff **diff,
git_repository *repo,
git_tree *old_tree,
git_index *index,
......@@ -1204,7 +1204,7 @@ int git_diff_tree_to_index(
git_index__set_ignore_case(index, true);
if (!error) {
git_diff_list *d = *diff;
git_diff *d = *diff;
d->opts.flags |= GIT_DIFF_DELTAS_ARE_ICASE;
d->strcomp = git__strcasecmp;
......@@ -1221,7 +1221,7 @@ int git_diff_tree_to_index(
}
int git_diff_index_to_workdir(
git_diff_list **diff,
git_diff **diff,
git_repository *repo,
git_index *index,
const git_diff_options *opts)
......@@ -1244,7 +1244,7 @@ int git_diff_index_to_workdir(
int git_diff_tree_to_workdir(
git_diff_list **diff,
git_diff **diff,
git_repository *repo,
git_tree *old_tree,
const git_diff_options *opts)
......@@ -1262,13 +1262,13 @@ int git_diff_tree_to_workdir(
return error;
}
size_t git_diff_num_deltas(git_diff_list *diff)
size_t git_diff_num_deltas(git_diff *diff)
{
assert(diff);
return (size_t)diff->deltas.length;
}
size_t git_diff_num_deltas_of_type(git_diff_list *diff, git_delta_t type)
size_t git_diff_num_deltas_of_type(git_diff *diff, git_delta_t type)
{
size_t i, count = 0;
git_diff_delta *delta;
......@@ -1282,14 +1282,14 @@ size_t git_diff_num_deltas_of_type(git_diff_list *diff, git_delta_t type)
return count;
}
int git_diff_is_sorted_icase(const git_diff_list *diff)
int git_diff_is_sorted_icase(const git_diff *diff)
{
return (diff->opts.flags & GIT_DIFF_DELTAS_ARE_ICASE) != 0;
}
int git_diff__paired_foreach(
git_diff_list *head2idx,
git_diff_list *idx2wd,
git_diff *head2idx,
git_diff *idx2wd,
int (*cb)(git_diff_delta *h2i, git_diff_delta *i2w, void *payload),
void *payload)
{
......
......@@ -52,7 +52,7 @@ enum {
#define GIT_DIFF__VERBOSE (1 << 30)
struct git_diff_list {
struct git_diff {
git_refcount rc;
git_repository *repo;
git_diff_options opts;
......@@ -72,7 +72,7 @@ struct git_diff_list {
extern void git_diff__cleanup_modes(
uint32_t diffcaps, uint32_t *omode, uint32_t *nmode);
extern void git_diff_list_addref(git_diff_list *diff);
extern void git_diff_addref(git_diff *diff);
extern int git_diff_delta__cmp(const void *a, const void *b);
extern int git_diff_delta__casecmp(const void *a, const void *b);
......@@ -93,15 +93,15 @@ extern int git_diff__oid_for_file(
git_repository *, const char *, uint16_t, git_off_t, git_oid *);
extern int git_diff__from_iterators(
git_diff_list **diff_ptr,
git_diff **diff_ptr,
git_repository *repo,
git_iterator *old_iter,
git_iterator *new_iter,
const git_diff_options *opts);
extern int git_diff__paired_foreach(
git_diff_list *idx2head,
git_diff_list *wd2idx,
git_diff *idx2head,
git_diff *wd2idx,
int (*cb)(git_diff_delta *i2h, git_diff_delta *w2i, void *payload),
void *payload);
......
......@@ -88,7 +88,7 @@ static int diff_file_content_init_common(
int git_diff_file_content__init_from_diff(
git_diff_file_content *fc,
git_diff_list *diff,
git_diff *diff,
size_t delta_index,
bool use_old)
{
......
......@@ -27,7 +27,7 @@ typedef struct {
extern int git_diff_file_content__init_from_diff(
git_diff_file_content *fc,
git_diff_list *diff,
git_diff *diff,
size_t delta_index,
bool use_old);
......
......@@ -24,16 +24,16 @@ struct diff_patch_line {
/* cached information about a hunk in a diff */
typedef struct diff_patch_hunk diff_patch_hunk;
struct diff_patch_hunk {
git_diff_range range;
git_diff_hunk hunk;
char header[128];
size_t header_len;
size_t line_start;
size_t line_count;
};
struct git_diff_patch {
struct git_patch {
git_refcount rc;
git_diff_list *diff; /* for refcount purposes, maybe NULL for blob diffs */
git_diff *diff; /* for refcount purposes, maybe NULL for blob diffs */
git_diff_delta *delta;
size_t delta_index;
git_diff_file_content ofile;
......@@ -56,11 +56,11 @@ enum {
};
static void diff_output_init(git_diff_output*, const git_diff_options*,
git_diff_file_cb, git_diff_hunk_cb, git_diff_data_cb, void*);
git_diff_file_cb, git_diff_hunk_cb, git_diff_line_cb, void*);
static void diff_output_to_patch(git_diff_output *, git_diff_patch *);
static void diff_output_to_patch(git_diff_output *, git_patch *);
static void diff_patch_update_binary(git_diff_patch *patch)
static void diff_patch_update_binary(git_patch *patch)
{
if ((patch->delta->flags & DIFF_FLAGS_KNOWN_BINARY) != 0)
return;
......@@ -74,7 +74,7 @@ static void diff_patch_update_binary(git_diff_patch *patch)
patch->delta->flags |= GIT_DIFF_FLAG_NOT_BINARY;
}
static void diff_patch_init_common(git_diff_patch *patch)
static void diff_patch_init_common(git_patch *patch)
{
diff_patch_update_binary(patch);
......@@ -84,11 +84,11 @@ static void diff_patch_init_common(git_diff_patch *patch)
patch->flags |= GIT_DIFF_PATCH_INITIALIZED;
if (patch->diff)
git_diff_list_addref(patch->diff);
git_diff_addref(patch->diff);
}
static int diff_patch_init_from_diff(
git_diff_patch *patch, git_diff_list *diff, size_t delta_index)
git_patch *patch, git_diff *diff, size_t delta_index)
{
int error = 0;
......@@ -109,12 +109,12 @@ static int diff_patch_init_from_diff(
}
static int diff_patch_alloc_from_diff(
git_diff_patch **out,
git_diff_list *diff,
git_patch **out,
git_diff *diff,
size_t delta_index)
{
int error;
git_diff_patch *patch = git__calloc(1, sizeof(git_diff_patch));
git_patch *patch = git__calloc(1, sizeof(git_patch));
GITERR_CHECK_ALLOC(patch);
if (!(error = diff_patch_init_from_diff(patch, diff, delta_index))) {
......@@ -129,7 +129,7 @@ static int diff_patch_alloc_from_diff(
return error;
}
static int diff_patch_load(git_diff_patch *patch, git_diff_output *output)
static int diff_patch_load(git_patch *patch, git_diff_output *output)
{
int error = 0;
bool incomplete_data;
......@@ -207,7 +207,7 @@ cleanup:
}
static int diff_patch_file_callback(
git_diff_patch *patch, git_diff_output *output)
git_patch *patch, git_diff_output *output)
{
float progress;
......@@ -223,7 +223,7 @@ static int diff_patch_file_callback(
return output->error;
}
static int diff_patch_generate(git_diff_patch *patch, git_diff_output *output)
static int diff_patch_generate(git_patch *patch, git_diff_output *output)
{
int error = 0;
......@@ -248,7 +248,7 @@ static int diff_patch_generate(git_diff_patch *patch, git_diff_output *output)
return error;
}
static void diff_patch_free(git_diff_patch *patch)
static void diff_patch_free(git_patch *patch)
{
git_diff_file_content__clear(&patch->ofile);
git_diff_file_content__clear(&patch->nfile);
......@@ -256,7 +256,7 @@ static void diff_patch_free(git_diff_patch *patch)
git_array_clear(patch->lines);
git_array_clear(patch->hunks);
git_diff_list_free(patch->diff); /* decrements refcount */
git_diff_free(patch->diff); /* decrements refcount */
patch->diff = NULL;
git_pool_clear(&patch->flattened);
......@@ -265,7 +265,7 @@ static void diff_patch_free(git_diff_patch *patch)
git__free(patch);
}
static int diff_required(git_diff_list *diff, const char *action)
static int diff_required(git_diff *diff, const char *action)
{
if (diff)
return 0;
......@@ -274,16 +274,16 @@ static int diff_required(git_diff_list *diff, const char *action)
}
int git_diff_foreach(
git_diff_list *diff,
git_diff *diff,
git_diff_file_cb file_cb,
git_diff_hunk_cb hunk_cb,
git_diff_data_cb data_cb,
git_diff_line_cb data_cb,
void *payload)
{
int error = 0;
git_xdiff_output xo;
size_t idx;
git_diff_patch patch;
git_patch patch;
if (diff_required(diff, "git_diff_foreach") < 0)
return -1;
......@@ -305,7 +305,7 @@ int git_diff_foreach(
if (!error)
error = diff_patch_generate(&patch, &xo.output);
git_diff_patch_free(&patch);
git_patch_free(&patch);
}
if (error < 0)
......@@ -318,7 +318,7 @@ int git_diff_foreach(
}
typedef struct {
git_diff_patch patch;
git_patch patch;
git_diff_delta delta;
char paths[GIT_FLEX_ARRAY];
} diff_patch_with_delta;
......@@ -326,7 +326,7 @@ typedef struct {
static int diff_single_generate(diff_patch_with_delta *pd, git_xdiff_output *xo)
{
int error = 0;
git_diff_patch *patch = &pd->patch;
git_patch *patch = &pd->patch;
bool has_old = ((patch->ofile.flags & GIT_DIFF_FLAG__NO_DATA) == 0);
bool has_new = ((patch->nfile.flags & GIT_DIFF_FLAG__NO_DATA) == 0);
......@@ -430,7 +430,7 @@ int git_diff_blobs(
const git_diff_options *opts,
git_diff_file_cb file_cb,
git_diff_hunk_cb hunk_cb,
git_diff_data_cb data_cb,
git_diff_line_cb data_cb,
void *payload)
{
int error = 0;
......@@ -452,13 +452,13 @@ int git_diff_blobs(
error = diff_patch_from_blobs(
&pd, &xo, old_blob, old_path, new_blob, new_path, opts);
git_diff_patch_free(&pd.patch);
git_patch_free(&pd.patch);
return error;
}
int git_diff_patch_from_blobs(
git_diff_patch **out,
int git_patch_from_blobs(
git_patch **out,
const git_blob *old_blob,
const char *old_path,
const git_blob *new_blob,
......@@ -484,9 +484,9 @@ int git_diff_patch_from_blobs(
pd, &xo, old_blob, old_path, new_blob, new_path, opts);
if (!error)
*out = (git_diff_patch *)pd;
*out = (git_patch *)pd;
else
git_diff_patch_free((git_diff_patch *)pd);
git_patch_free((git_patch *)pd);
return error;
}
......@@ -542,7 +542,7 @@ int git_diff_blob_to_buffer(
const git_diff_options *opts,
git_diff_file_cb file_cb,
git_diff_hunk_cb hunk_cb,
git_diff_data_cb data_cb,
git_diff_line_cb data_cb,
void *payload)
{
int error = 0;
......@@ -564,13 +564,13 @@ int git_diff_blob_to_buffer(
error = diff_patch_from_blob_and_buffer(
&pd, &xo, old_blob, old_path, buf, buflen, buf_path, opts);
git_diff_patch_free(&pd.patch);
git_patch_free(&pd.patch);
return error;
}
int git_diff_patch_from_blob_and_buffer(
git_diff_patch **out,
int git_patch_from_blob_and_buffer(
git_patch **out,
const git_blob *old_blob,
const char *old_path,
const char *buf,
......@@ -597,28 +597,28 @@ int git_diff_patch_from_blob_and_buffer(
pd, &xo, old_blob, old_path, buf, buflen, buf_path, opts);
if (!error)
*out = (git_diff_patch *)pd;
*out = (git_patch *)pd;
else
git_diff_patch_free((git_diff_patch *)pd);
git_patch_free((git_patch *)pd);
return error;
}
int git_diff_get_patch(
git_diff_patch **patch_ptr,
int git_patch_from_diff(
git_patch **patch_ptr,
const git_diff_delta **delta_ptr,
git_diff_list *diff,
git_diff *diff,
size_t idx)
{
int error = 0;
git_xdiff_output xo;
git_diff_delta *delta = NULL;
git_diff_patch *patch = NULL;
git_patch *patch = NULL;
if (patch_ptr) *patch_ptr = NULL;
if (delta_ptr) *delta_ptr = NULL;
if (diff_required(diff, "git_diff_get_patch") < 0)
if (diff_required(diff, "git_patch_from_diff") < 0)
return -1;
delta = git_vector_get(&diff->deltas, idx);
......@@ -656,7 +656,7 @@ int git_diff_get_patch(
}
if (error || !patch_ptr)
git_diff_patch_free(patch);
git_patch_free(patch);
else
*patch_ptr = patch;
......@@ -665,29 +665,29 @@ int git_diff_get_patch(
return error;
}
void git_diff_patch_free(git_diff_patch *patch)
void git_patch_free(git_patch *patch)
{
if (patch)
GIT_REFCOUNT_DEC(patch, diff_patch_free);
}
const git_diff_delta *git_diff_patch_delta(git_diff_patch *patch)
const git_diff_delta *git_patch_delta(git_patch *patch)
{
assert(patch);
return patch->delta;
}
size_t git_diff_patch_num_hunks(git_diff_patch *patch)
size_t git_patch_num_hunks(git_patch *patch)
{
assert(patch);
return git_array_size(patch->hunks);
}
int git_diff_patch_line_stats(
int git_patch_line_stats(
size_t *total_ctxt,
size_t *total_adds,
size_t *total_dels,
const git_diff_patch *patch)
const git_patch *patch)
{
size_t totals[3], idx;
......@@ -726,12 +726,12 @@ static int diff_error_outofrange(const char *thing)
return GIT_ENOTFOUND;
}
int git_diff_patch_get_hunk(
const git_diff_range **range,
int git_patch_get_hunk(
const git_diff_hunk **out,
const char **header,
size_t *header_len,
size_t *lines_in_hunk,
git_diff_patch *patch,
git_patch *patch,
size_t hunk_idx)
{
diff_patch_hunk *hunk;
......@@ -740,21 +740,21 @@ int git_diff_patch_get_hunk(
hunk = git_array_get(patch->hunks, hunk_idx);
if (!hunk) {
if (range) *range = NULL;
if (out) *out = NULL;
if (header) *header = NULL;
if (header_len) *header_len = 0;
if (lines_in_hunk) *lines_in_hunk = 0;
return diff_error_outofrange("hunk");
}
if (range) *range = &hunk->range;
if (out) *out = &hunk->hunk;
if (header) *header = hunk->header;
if (header_len) *header_len = hunk->header_len;
if (lines_in_hunk) *lines_in_hunk = hunk->line_count;
return 0;
}
int git_diff_patch_num_lines_in_hunk(git_diff_patch *patch, size_t hunk_idx)
int git_patch_num_lines_in_hunk(git_patch *patch, size_t hunk_idx)
{
diff_patch_hunk *hunk;
assert(patch);
......@@ -764,13 +764,13 @@ int git_diff_patch_num_lines_in_hunk(git_diff_patch *patch, size_t hunk_idx)
return (int)hunk->line_count;
}
int git_diff_patch_get_line_in_hunk(
int git_patch_get_line_in_hunk(
char *line_origin,
const char **content,
size_t *content_len,
int *old_lineno,
int *new_lineno,
git_diff_patch *patch,
git_patch *patch,
size_t hunk_idx,
size_t line_of_hunk)
{
......@@ -810,8 +810,8 @@ notfound:
return diff_error_outofrange(thing);
}
size_t git_diff_patch_size(
git_diff_patch *patch,
size_t git_patch_size(
git_patch *patch,
int include_context,
int include_hunk_headers,
int include_file_headers)
......@@ -843,36 +843,36 @@ size_t git_diff_patch_size(
return out;
}
git_diff_list *git_diff_patch__diff(git_diff_patch *patch)
git_diff *git_patch__diff(git_patch *patch)
{
return patch->diff;
}
git_diff_driver *git_diff_patch__driver(git_diff_patch *patch)
git_diff_driver *git_patch__driver(git_patch *patch)
{
/* ofile driver is representative for whole patch */
return patch->ofile.driver;
}
void git_diff_patch__old_data(
char **ptr, size_t *len, git_diff_patch *patch)
void git_patch__old_data(
char **ptr, size_t *len, git_patch *patch)
{
*ptr = patch->ofile.map.data;
*len = patch->ofile.map.len;
}
void git_diff_patch__new_data(
char **ptr, size_t *len, git_diff_patch *patch)
void git_patch__new_data(
char **ptr, size_t *len, git_patch *patch)
{
*ptr = patch->nfile.map.data;
*len = patch->nfile.map.len;
}
int git_diff_patch__invoke_callbacks(
git_diff_patch *patch,
int git_patch__invoke_callbacks(
git_patch *patch,
git_diff_file_cb file_cb,
git_diff_hunk_cb hunk_cb,
git_diff_data_cb line_cb,
git_diff_line_cb line_cb,
void *payload)
{
int error = 0;
......@@ -888,7 +888,7 @@ int git_diff_patch__invoke_callbacks(
diff_patch_hunk *h = git_array_get(patch->hunks, i);
error = hunk_cb(
patch->delta, &h->range, h->header, h->header_len, payload);
patch->delta, &h->hunk, h->header, h->header_len, payload);
if (!line_cb)
continue;
......@@ -898,7 +898,7 @@ int git_diff_patch__invoke_callbacks(
git_array_get(patch->lines, h->line_start + j);
error = line_cb(
patch->delta, &h->range, l->origin, l->ptr, l->len, payload);
patch->delta, &h->hunk, l->origin, l->ptr, l->len, payload);
}
}
......@@ -917,12 +917,12 @@ static int diff_patch_file_cb(
static int diff_patch_hunk_cb(
const git_diff_delta *delta,
const git_diff_range *range,
const git_diff_hunk *hunk_,
const char *header,
size_t header_len,
void *payload)
{
git_diff_patch *patch = payload;
git_patch *patch = payload;
diff_patch_hunk *hunk;
GIT_UNUSED(delta);
......@@ -930,7 +930,7 @@ static int diff_patch_hunk_cb(
hunk = git_array_alloc(patch->hunks);
GITERR_CHECK_ALLOC(hunk);
memcpy(&hunk->range, range, sizeof(hunk->range));
memcpy(&hunk->hunk, hunk_, sizeof(hunk->hunk));
assert(header_len + 1 < sizeof(hunk->header));
memcpy(&hunk->header, header, header_len);
......@@ -942,27 +942,27 @@ static int diff_patch_hunk_cb(
hunk->line_start = git_array_size(patch->lines);
hunk->line_count = 0;
patch->oldno = range->old_start;
patch->newno = range->new_start;
patch->oldno = hunk_->old_start;
patch->newno = hunk_->new_start;
return 0;
}
static int diff_patch_line_cb(
const git_diff_delta *delta,
const git_diff_range *range,
const git_diff_hunk *hunk_,
char line_origin,
const char *content,
size_t content_len,
void *payload)
{
git_diff_patch *patch = payload;
git_patch *patch = payload;
diff_patch_hunk *hunk;
diff_patch_line *line;
const char *content_end = content + content_len;
GIT_UNUSED(delta);
GIT_UNUSED(range);
GIT_UNUSED(hunk_);
hunk = git_array_last(patch->hunks);
GITERR_CHECK_ALLOC(hunk);
......@@ -1023,7 +1023,7 @@ static void diff_output_init(
const git_diff_options *opts,
git_diff_file_cb file_cb,
git_diff_hunk_cb hunk_cb,
git_diff_data_cb data_cb,
git_diff_line_cb data_cb,
void *payload)
{
GIT_UNUSED(opts);
......@@ -1036,7 +1036,7 @@ static void diff_output_init(
out->payload = payload;
}
static void diff_output_to_patch(git_diff_output *out, git_diff_patch *patch)
static void diff_output_to_patch(git_diff_output *out, git_patch *patch)
{
diff_output_init(
out, NULL,
......
......@@ -11,19 +11,20 @@
#include "diff.h"
#include "diff_file.h"
#include "array.h"
#include "git2/patch.h"
extern git_diff_list *git_diff_patch__diff(git_diff_patch *);
extern git_diff *git_patch__diff(git_patch *);
extern git_diff_driver *git_diff_patch__driver(git_diff_patch *);
extern git_diff_driver *git_patch__driver(git_patch *);
extern void git_diff_patch__old_data(char **, size_t *, git_diff_patch *);
extern void git_diff_patch__new_data(char **, size_t *, git_diff_patch *);
extern void git_patch__old_data(char **, size_t *, git_patch *);
extern void git_patch__new_data(char **, size_t *, git_patch *);
extern int git_diff_patch__invoke_callbacks(
git_diff_patch *patch,
extern int git_patch__invoke_callbacks(
git_patch *patch,
git_diff_file_cb file_cb,
git_diff_hunk_cb hunk_cb,
git_diff_data_cb line_cb,
git_diff_line_cb line_cb,
void *payload);
typedef struct git_diff_output git_diff_output;
......@@ -31,7 +32,7 @@ struct git_diff_output {
/* these callbacks are issued with the diff data */
git_diff_file_cb file_cb;
git_diff_hunk_cb hunk_cb;
git_diff_data_cb data_cb;
git_diff_line_cb data_cb;
void *payload;
/* this records the actual error in cases where it may be obscured */
......@@ -40,7 +41,7 @@ struct git_diff_output {
/* this callback is used to do the diff and drive the other callbacks.
* see diff_xdiff.h for how to use this in practice for now.
*/
int (*diff_cb)(git_diff_output *output, git_diff_patch *patch);
int (*diff_cb)(git_diff_output *output, git_patch *patch);
};
#endif
......@@ -10,8 +10,8 @@
#include "fileops.h"
typedef struct {
git_diff_list *diff;
git_diff_data_cb print_cb;
git_diff *diff;
git_diff_line_cb print_cb;
void *payload;
git_buf *buf;
int oid_strlen;
......@@ -19,7 +19,7 @@ typedef struct {
static int diff_print_info_init(
diff_print_info *pi,
git_buf *out, git_diff_list *diff, git_diff_data_cb cb, void *payload)
git_buf *out, git_diff *diff, git_diff_line_cb cb, void *payload)
{
pi->diff = diff;
pi->print_cb = cb;
......@@ -119,10 +119,10 @@ static int diff_print_one_compact(
return 0;
}
/* print a git_diff_list to a print callback in compact format */
/* print a git_diff to a print callback in compact format */
int git_diff_print_compact(
git_diff_list *diff,
git_diff_data_cb print_cb,
git_diff *diff,
git_diff_line_cb print_cb,
void *payload)
{
int error;
......@@ -180,10 +180,10 @@ static int diff_print_one_raw(
return 0;
}
/* print a git_diff_list to a print callback in raw output format */
/* print a git_diff to a print callback in raw output format */
int git_diff_print_raw(
git_diff_list *diff,
git_diff_data_cb print_cb,
git_diff *diff,
git_diff_line_cb print_cb,
void *payload)
{
int error;
......@@ -325,7 +325,7 @@ static int diff_print_patch_file(
static int diff_print_patch_hunk(
const git_diff_delta *d,
const git_diff_range *r,
const git_diff_hunk *r,
const char *header,
size_t header_len,
void *data)
......@@ -348,7 +348,7 @@ static int diff_print_patch_hunk(
static int diff_print_patch_line(
const git_diff_delta *delta,
const git_diff_range *range,
const git_diff_hunk *range,
char line_origin, /* GIT_DIFF_LINE value from above */
const char *content,
size_t content_len,
......@@ -379,10 +379,10 @@ static int diff_print_patch_line(
return 0;
}
/* print a git_diff_list to an output callback in patch format */
/* print a git_diff to an output callback in patch format */
int git_diff_print_patch(
git_diff_list *diff,
git_diff_data_cb print_cb,
git_diff *diff,
git_diff_line_cb print_cb,
void *payload)
{
int error;
......@@ -399,10 +399,10 @@ int git_diff_print_patch(
return error;
}
/* print a git_diff_patch to an output callback */
int git_diff_patch_print(
git_diff_patch *patch,
git_diff_data_cb print_cb,
/* print a git_patch to an output callback */
int git_patch_print(
git_patch *patch,
git_diff_line_cb print_cb,
void *payload)
{
int error;
......@@ -412,8 +412,8 @@ int git_diff_patch_print(
assert(patch && print_cb);
if (!(error = diff_print_info_init(
&pi, &temp, git_diff_patch__diff(patch), print_cb, payload)))
error = git_diff_patch__invoke_callbacks(
&pi, &temp, git_patch__diff(patch), print_cb, payload)))
error = git_patch__invoke_callbacks(
patch, diff_print_patch_file, diff_print_patch_hunk,
diff_print_patch_line, &pi);
......@@ -424,7 +424,7 @@ int git_diff_patch_print(
static int diff_print_to_buffer_cb(
const git_diff_delta *delta,
const git_diff_range *range,
const git_diff_hunk *range,
char line_origin,
const char *content,
size_t content_len,
......@@ -435,15 +435,15 @@ static int diff_print_to_buffer_cb(
return git_buf_put(output, content, content_len);
}
/* print a git_diff_patch to a string buffer */
int git_diff_patch_to_str(
/* print a git_patch to a string buffer */
int git_patch_to_str(
char **string,
git_diff_patch *patch)
git_patch *patch)
{
int error;
git_buf output = GIT_BUF_INIT;
error = git_diff_patch_print(patch, diff_print_to_buffer_cb, &output);
error = git_patch_print(patch, diff_print_to_buffer_cb, &output);
/* GIT_EUSER means git_buf_put in print_to_buffer_cb returned -1,
* meaning a memory allocation failure, so just map to -1...
......
......@@ -97,8 +97,8 @@ static git_diff_delta *diff_delta__merge_like_cgit(
}
int git_diff_merge(
git_diff_list *onto,
const git_diff_list *from)
git_diff *onto,
const git_diff *from)
{
int error = 0;
git_pool onto_pool;
......@@ -230,7 +230,7 @@ int git_diff_find_similar__calc_similarity(
#define DEFAULT_RENAME_LIMIT 200
static int normalize_find_opts(
git_diff_list *diff,
git_diff *diff,
git_diff_find_options *opts,
git_diff_find_options *given)
{
......@@ -328,7 +328,7 @@ static int normalize_find_opts(
}
static int apply_splits_and_deletes(
git_diff_list *diff, size_t expected_size, bool actually_split)
git_diff *diff, size_t expected_size, bool actually_split)
{
git_vector onto = GIT_VECTOR_INIT;
size_t i;
......@@ -402,7 +402,7 @@ on_error:
return -1;
}
GIT_INLINE(git_diff_file *) similarity_get_file(git_diff_list *diff, size_t idx)
GIT_INLINE(git_diff_file *) similarity_get_file(git_diff *diff, size_t idx)
{
git_diff_delta *delta = git_vector_get(&diff->deltas, idx / 2);
return (idx & 1) ? &delta->new_file : &delta->old_file;
......@@ -419,7 +419,7 @@ typedef struct {
} similarity_info;
static int similarity_init(
similarity_info *info, git_diff_list *diff, size_t file_idx)
similarity_info *info, git_diff *diff, size_t file_idx)
{
info->idx = file_idx;
info->src = (file_idx & 1) ? diff->new_src : diff->old_src;
......@@ -509,7 +509,7 @@ static void similarity_unload(similarity_info *info)
*/
static int similarity_measure(
int *score,
git_diff_list *diff,
git_diff *diff,
const git_diff_find_options *opts,
void **cache,
size_t a_idx,
......@@ -595,7 +595,7 @@ cleanup:
}
static int calc_self_similarity(
git_diff_list *diff,
git_diff *diff,
const git_diff_find_options *opts,
size_t delta_idx,
void **cache)
......@@ -620,7 +620,7 @@ static int calc_self_similarity(
}
static bool is_rename_target(
git_diff_list *diff,
git_diff *diff,
const git_diff_find_options *opts,
size_t delta_idx,
void **cache)
......@@ -675,7 +675,7 @@ static bool is_rename_target(
}
static bool is_rename_source(
git_diff_list *diff,
git_diff *diff,
const git_diff_find_options *opts,
size_t delta_idx,
void **cache)
......@@ -759,7 +759,7 @@ typedef struct {
} diff_find_match;
int git_diff_find_similar(
git_diff_list *diff,
git_diff *diff,
git_diff_find_options *given_opts)
{
size_t s, t;
......
......@@ -24,26 +24,26 @@ static int git_xdiff_scan_int(const char **str, int *value)
return (digits > 0) ? 0 : -1;
}
static int git_xdiff_parse_hunk(git_diff_range *range, const char *header)
static int git_xdiff_parse_hunk(git_diff_hunk *hunk, const char *header)
{
/* expect something of the form "@@ -%d[,%d] +%d[,%d] @@" */
if (*header != '@')
return -1;
if (git_xdiff_scan_int(&header, &range->old_start) < 0)
if (git_xdiff_scan_int(&header, &hunk->old_start) < 0)
return -1;
if (*header == ',') {
if (git_xdiff_scan_int(&header, &range->old_lines) < 0)
if (git_xdiff_scan_int(&header, &hunk->old_lines) < 0)
return -1;
} else
range->old_lines = 1;
if (git_xdiff_scan_int(&header, &range->new_start) < 0)
hunk->old_lines = 1;
if (git_xdiff_scan_int(&header, &hunk->new_start) < 0)
return -1;
if (*header == ',') {
if (git_xdiff_scan_int(&header, &range->new_lines) < 0)
if (git_xdiff_scan_int(&header, &hunk->new_lines) < 0)
return -1;
} else
range->new_lines = 1;
if (range->old_start < 0 || range->new_start < 0)
hunk->new_lines = 1;
if (hunk->old_start < 0 || hunk->new_start < 0)
return -1;
return 0;
......@@ -51,24 +51,24 @@ static int git_xdiff_parse_hunk(git_diff_range *range, const char *header)
typedef struct {
git_xdiff_output *xo;
git_diff_patch *patch;
git_diff_range range;
git_patch *patch;
git_diff_hunk hunk;
} git_xdiff_info;
static int git_xdiff_cb(void *priv, mmbuffer_t *bufs, int len)
{
git_xdiff_info *info = priv;
git_diff_patch *patch = info->patch;
const git_diff_delta *delta = git_diff_patch_delta(patch);
git_patch *patch = info->patch;
const git_diff_delta *delta = git_patch_delta(patch);
git_diff_output *output = &info->xo->output;
if (len == 1) {
output->error = git_xdiff_parse_hunk(&info->range, bufs[0].ptr);
output->error = git_xdiff_parse_hunk(&info->hunk, bufs[0].ptr);
if (output->error < 0)
return output->error;
if (output->hunk_cb != NULL &&
output->hunk_cb(delta, &info->range,
output->hunk_cb(delta, &info->hunk,
bufs[0].ptr, bufs[0].size, output->payload))
output->error = GIT_EUSER;
}
......@@ -81,7 +81,7 @@ static int git_xdiff_cb(void *priv, mmbuffer_t *bufs, int len)
GIT_DIFF_LINE_CONTEXT;
if (output->data_cb != NULL &&
output->data_cb(delta, &info->range,
output->data_cb(delta, &info->hunk,
origin, bufs[1].ptr, bufs[1].size, output->payload))
output->error = GIT_EUSER;
}
......@@ -98,7 +98,7 @@ static int git_xdiff_cb(void *priv, mmbuffer_t *bufs, int len)
GIT_DIFF_LINE_CONTEXT_EOFNL;
if (output->data_cb != NULL &&
output->data_cb(delta, &info->range,
output->data_cb(delta, &info->hunk,
origin, bufs[2].ptr, bufs[2].size, output->payload))
output->error = GIT_EUSER;
}
......@@ -106,7 +106,7 @@ static int git_xdiff_cb(void *priv, mmbuffer_t *bufs, int len)
return output->error;
}
static int git_xdiff(git_diff_output *output, git_diff_patch *patch)
static int git_xdiff(git_diff_output *output, git_patch *patch)
{
git_xdiff_output *xo = (git_xdiff_output *)output;
git_xdiff_info info;
......@@ -120,7 +120,7 @@ static int git_xdiff(git_diff_output *output, git_diff_patch *patch)
xo->callback.priv = &info;
git_diff_find_context_init(
&xo->config.find_func, &findctxt, git_diff_patch__driver(patch));
&xo->config.find_func, &findctxt, git_patch__driver(patch));
xo->config.find_func_priv = &findctxt;
if (xo->config.find_func != NULL)
......@@ -132,8 +132,8 @@ static int git_xdiff(git_diff_output *output, git_diff_patch *patch)
* updates are needed to xo->params.flags
*/
git_diff_patch__old_data(&xd_old_data.ptr, &xd_old_data.size, patch);
git_diff_patch__new_data(&xd_new_data.ptr, &xd_new_data.size, patch);
git_patch__old_data(&xd_old_data.ptr, &xd_old_data.size, patch);
git_patch__new_data(&xd_new_data.ptr, &xd_new_data.size, patch);
xdl_diff(&xd_old_data, &xd_new_data,
&xo->params, &xo->config, &xo->callback);
......
......@@ -585,7 +585,7 @@ int git_pathspec_match_tree(
int git_pathspec_match_diff(
git_pathspec_match_list **out,
git_diff_list *diff,
git_diff *diff,
uint32_t flags,
git_pathspec *ps)
{
......
......@@ -24,7 +24,7 @@ int git_reset_default(
{
git_object *commit = NULL;
git_tree *tree = NULL;
git_diff_list *diff = NULL;
git_diff *diff = NULL;
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
size_t i;
git_diff_delta *delta;
......@@ -85,7 +85,7 @@ cleanup:
git_object_free(commit);
git_tree_free(tree);
git_index_free(index);
git_diff_list_free(diff);
git_diff_free(diff);
return error;
}
......
......@@ -221,7 +221,7 @@ static int build_untracked_tree(
uint32_t flags)
{
git_tree *i_tree = NULL;
git_diff_list *diff = NULL;
git_diff *diff = NULL;
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
struct cb_data data = {0};
int error;
......@@ -259,7 +259,7 @@ static int build_untracked_tree(
error = build_tree_from_index(tree_out, index);
cleanup:
git_diff_list_free(diff);
git_diff_free(diff);
git_tree_free(i_tree);
return error;
}
......@@ -311,7 +311,7 @@ static int build_workdir_tree(
{
git_repository *repo = git_index_owner(index);
git_tree *b_tree = NULL;
git_diff_list *diff = NULL, *diff2 = NULL;
git_diff *diff = NULL, *diff2 = NULL;
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
struct cb_data data = {0};
int error;
......@@ -346,8 +346,8 @@ static int build_workdir_tree(
goto cleanup;
cleanup:
git_diff_list_free(diff);
git_diff_list_free(diff2);
git_diff_free(diff);
git_diff_free(diff2);
git_tree_free(b_tree);
return error;
......
......@@ -52,7 +52,7 @@ static unsigned int index_delta2status(const git_diff_delta *head2idx)
}
static unsigned int workdir_delta2status(
git_diff_list *diff, git_diff_delta *idx2wd)
git_diff *diff, git_diff_delta *idx2wd)
{
git_status_t st = GIT_STATUS_CURRENT;
......@@ -361,8 +361,8 @@ void git_status_list_free(git_status_list *status)
if (status == NULL)
return;
git_diff_list_free(status->head2idx);
git_diff_list_free(status->idx2wd);
git_diff_free(status->head2idx);
git_diff_free(status->idx2wd);
git_vector_foreach(&status->paired, i, status_entry)
git__free(status_entry);
......
......@@ -14,8 +14,8 @@
struct git_status_list {
git_status_options opts;
git_diff_list *head2idx;
git_diff_list *idx2wd;
git_diff *head2idx;
git_diff *idx2wd;
git_vector paired;
};
......
......@@ -1528,7 +1528,7 @@ static void submodule_get_wd_status(
(sm->flags & GIT_SUBMODULE_STATUS__WD_OID_VALID) ? &sm->wd_oid : NULL;
git_tree *sm_head = NULL;
git_diff_options opt = GIT_DIFF_OPTIONS_INIT;
git_diff_list *diff;
git_diff *diff;
*status = *status & ~GIT_SUBMODULE_STATUS__WD_FLAGS;
......@@ -1568,7 +1568,7 @@ static void submodule_get_wd_status(
else {
if (git_diff_num_deltas(diff) > 0)
*status |= GIT_SUBMODULE_STATUS_WD_INDEX_MODIFIED;
git_diff_list_free(diff);
git_diff_free(diff);
diff = NULL;
}
......@@ -1588,7 +1588,7 @@ static void submodule_get_wd_status(
if (git_diff_num_deltas(diff) != untracked)
*status |= GIT_SUBMODULE_STATUS_WD_WD_MODIFIED;
git_diff_list_free(diff);
git_diff_free(diff);
diff = NULL;
}
}
......@@ -142,7 +142,7 @@ void test_diff_blob__can_compare_text_blobs_with_patch(void)
{
git_blob *a, *b, *c;
git_oid a_oid, b_oid, c_oid;
git_diff_patch *p;
git_patch *p;
const git_diff_delta *delta;
size_t tc, ta, td;
......@@ -161,11 +161,11 @@ void test_diff_blob__can_compare_text_blobs_with_patch(void)
/* Doing the equivalent of a `git diff -U1` on these files */
/* diff on tests/resources/attr/root_test1 */
cl_git_pass(git_diff_patch_from_blobs(&p, a, NULL, b, NULL, &opts));
cl_git_pass(git_patch_from_blobs(&p, a, NULL, b, NULL, &opts));
cl_assert(p != NULL);
delta = git_diff_patch_delta(p);
delta = git_patch_delta(p);
cl_assert(delta != NULL);
cl_assert_equal_i(GIT_DELTA_MODIFIED, delta->status);
cl_assert(git_oid_equal(git_blob_id(a), &delta->old_file.oid));
......@@ -173,22 +173,22 @@ void test_diff_blob__can_compare_text_blobs_with_patch(void)
cl_assert(git_oid_equal(git_blob_id(b), &delta->new_file.oid));
cl_assert_equal_sz(git_blob_rawsize(b), delta->new_file.size);
cl_assert_equal_i(1, (int)git_diff_patch_num_hunks(p));
cl_assert_equal_i(6, git_diff_patch_num_lines_in_hunk(p, 0));
cl_assert_equal_i(1, (int)git_patch_num_hunks(p));
cl_assert_equal_i(6, git_patch_num_lines_in_hunk(p, 0));
cl_git_pass(git_diff_patch_line_stats(&tc, &ta, &td, p));
cl_git_pass(git_patch_line_stats(&tc, &ta, &td, p));
cl_assert_equal_i(1, (int)tc);
cl_assert_equal_i(5, (int)ta);
cl_assert_equal_i(0, (int)td);
git_diff_patch_free(p);
git_patch_free(p);
/* diff on tests/resources/attr/root_test2 */
cl_git_pass(git_diff_patch_from_blobs(&p, b, NULL, c, NULL, &opts));
cl_git_pass(git_patch_from_blobs(&p, b, NULL, c, NULL, &opts));
cl_assert(p != NULL);
delta = git_diff_patch_delta(p);
delta = git_patch_delta(p);
cl_assert(delta != NULL);
cl_assert_equal_i(GIT_DELTA_MODIFIED, delta->status);
cl_assert(git_oid_equal(git_blob_id(b), &delta->old_file.oid));
......@@ -196,22 +196,22 @@ void test_diff_blob__can_compare_text_blobs_with_patch(void)
cl_assert(git_oid_equal(git_blob_id(c), &delta->new_file.oid));
cl_assert_equal_sz(git_blob_rawsize(c), delta->new_file.size);
cl_assert_equal_i(1, (int)git_diff_patch_num_hunks(p));
cl_assert_equal_i(15, git_diff_patch_num_lines_in_hunk(p, 0));
cl_assert_equal_i(1, (int)git_patch_num_hunks(p));
cl_assert_equal_i(15, git_patch_num_lines_in_hunk(p, 0));
cl_git_pass(git_diff_patch_line_stats(&tc, &ta, &td, p));
cl_git_pass(git_patch_line_stats(&tc, &ta, &td, p));
cl_assert_equal_i(3, (int)tc);
cl_assert_equal_i(9, (int)ta);
cl_assert_equal_i(3, (int)td);
git_diff_patch_free(p);
git_patch_free(p);
/* diff on tests/resources/attr/root_test3 */
cl_git_pass(git_diff_patch_from_blobs(&p, a, NULL, c, NULL, &opts));
cl_git_pass(git_patch_from_blobs(&p, a, NULL, c, NULL, &opts));
cl_assert(p != NULL);
delta = git_diff_patch_delta(p);
delta = git_patch_delta(p);
cl_assert(delta != NULL);
cl_assert_equal_i(GIT_DELTA_MODIFIED, delta->status);
cl_assert(git_oid_equal(git_blob_id(a), &delta->old_file.oid));
......@@ -219,19 +219,19 @@ void test_diff_blob__can_compare_text_blobs_with_patch(void)
cl_assert(git_oid_equal(git_blob_id(c), &delta->new_file.oid));
cl_assert_equal_sz(git_blob_rawsize(c), delta->new_file.size);
cl_git_pass(git_diff_patch_line_stats(&tc, &ta, &td, p));
cl_git_pass(git_patch_line_stats(&tc, &ta, &td, p));
cl_assert_equal_i(0, (int)tc);
cl_assert_equal_i(12, (int)ta);
cl_assert_equal_i(1, (int)td);
git_diff_patch_free(p);
git_patch_free(p);
/* one more */
cl_git_pass(git_diff_patch_from_blobs(&p, c, NULL, d, NULL, &opts));
cl_git_pass(git_patch_from_blobs(&p, c, NULL, d, NULL, &opts));
cl_assert(p != NULL);
delta = git_diff_patch_delta(p);
delta = git_patch_delta(p);
cl_assert(delta != NULL);
cl_assert_equal_i(GIT_DELTA_MODIFIED, delta->status);
cl_assert(git_oid_equal(git_blob_id(c), &delta->old_file.oid));
......@@ -239,16 +239,16 @@ void test_diff_blob__can_compare_text_blobs_with_patch(void)
cl_assert(git_oid_equal(git_blob_id(d), &delta->new_file.oid));
cl_assert_equal_sz(git_blob_rawsize(d), delta->new_file.size);
cl_assert_equal_i(2, (int)git_diff_patch_num_hunks(p));
cl_assert_equal_i(5, git_diff_patch_num_lines_in_hunk(p, 0));
cl_assert_equal_i(9, git_diff_patch_num_lines_in_hunk(p, 1));
cl_assert_equal_i(2, (int)git_patch_num_hunks(p));
cl_assert_equal_i(5, git_patch_num_lines_in_hunk(p, 0));
cl_assert_equal_i(9, git_patch_num_lines_in_hunk(p, 1));
cl_git_pass(git_diff_patch_line_stats(&tc, &ta, &td, p));
cl_git_pass(git_patch_line_stats(&tc, &ta, &td, p));
cl_assert_equal_i(4, (int)tc);
cl_assert_equal_i(6, (int)ta);
cl_assert_equal_i(4, (int)td);
git_diff_patch_free(p);
git_patch_free(p);
git_blob_free(a);
git_blob_free(b);
......@@ -317,16 +317,16 @@ void test_diff_blob__can_compare_against_null_blobs(void)
void test_diff_blob__can_compare_against_null_blobs_with_patch(void)
{
git_blob *e = NULL;
git_diff_patch *p;
git_patch *p;
const git_diff_delta *delta;
int line;
char origin;
cl_git_pass(git_diff_patch_from_blobs(&p, d, NULL, e, NULL, &opts));
cl_git_pass(git_patch_from_blobs(&p, d, NULL, e, NULL, &opts));
cl_assert(p != NULL);
delta = git_diff_patch_delta(p);
delta = git_patch_delta(p);
cl_assert(delta != NULL);
cl_assert_equal_i(GIT_DELTA_DELETED, delta->status);
cl_assert(git_oid_equal(git_blob_id(d), &delta->old_file.oid));
......@@ -334,24 +334,24 @@ void test_diff_blob__can_compare_against_null_blobs_with_patch(void)
cl_assert(git_oid_iszero(&delta->new_file.oid));
cl_assert_equal_sz(0, delta->new_file.size);
cl_assert_equal_i(1, (int)git_diff_patch_num_hunks(p));
cl_assert_equal_i(14, git_diff_patch_num_lines_in_hunk(p, 0));
cl_assert_equal_i(1, (int)git_patch_num_hunks(p));
cl_assert_equal_i(14, git_patch_num_lines_in_hunk(p, 0));
for (line = 0; line < git_diff_patch_num_lines_in_hunk(p, 0); ++line) {
cl_git_pass(git_diff_patch_get_line_in_hunk(
for (line = 0; line < git_patch_num_lines_in_hunk(p, 0); ++line) {
cl_git_pass(git_patch_get_line_in_hunk(
&origin, NULL, NULL, NULL, NULL, p, 0, line));
cl_assert_equal_i(GIT_DIFF_LINE_DELETION, (int)origin);
}
git_diff_patch_free(p);
git_patch_free(p);
opts.flags |= GIT_DIFF_REVERSE;
cl_git_pass(git_diff_patch_from_blobs(&p, d, NULL, e, NULL, &opts));
cl_git_pass(git_patch_from_blobs(&p, d, NULL, e, NULL, &opts));
cl_assert(p != NULL);
delta = git_diff_patch_delta(p);
delta = git_patch_delta(p);
cl_assert(delta != NULL);
cl_assert_equal_i(GIT_DELTA_ADDED, delta->status);
cl_assert(git_oid_iszero(&delta->old_file.oid));
......@@ -359,44 +359,44 @@ void test_diff_blob__can_compare_against_null_blobs_with_patch(void)
cl_assert(git_oid_equal(git_blob_id(d), &delta->new_file.oid));
cl_assert_equal_sz(git_blob_rawsize(d), delta->new_file.size);
cl_assert_equal_i(1, (int)git_diff_patch_num_hunks(p));
cl_assert_equal_i(14, git_diff_patch_num_lines_in_hunk(p, 0));
cl_assert_equal_i(1, (int)git_patch_num_hunks(p));
cl_assert_equal_i(14, git_patch_num_lines_in_hunk(p, 0));
for (line = 0; line < git_diff_patch_num_lines_in_hunk(p, 0); ++line) {
cl_git_pass(git_diff_patch_get_line_in_hunk(
for (line = 0; line < git_patch_num_lines_in_hunk(p, 0); ++line) {
cl_git_pass(git_patch_get_line_in_hunk(
&origin, NULL, NULL, NULL, NULL, p, 0, line));
cl_assert_equal_i(GIT_DIFF_LINE_ADDITION, (int)origin);
}
git_diff_patch_free(p);
git_patch_free(p);
opts.flags ^= GIT_DIFF_REVERSE;
cl_git_pass(git_diff_patch_from_blobs(&p, alien, NULL, NULL, NULL, &opts));
cl_git_pass(git_patch_from_blobs(&p, alien, NULL, NULL, NULL, &opts));
cl_assert(p != NULL);
delta = git_diff_patch_delta(p);
delta = git_patch_delta(p);
cl_assert(delta != NULL);
cl_assert_equal_i(GIT_DELTA_DELETED, delta->status);
cl_assert((delta->flags & GIT_DIFF_FLAG_BINARY) != 0);
cl_assert_equal_i(0, (int)git_diff_patch_num_hunks(p));
cl_assert_equal_i(0, (int)git_patch_num_hunks(p));
git_diff_patch_free(p);
git_patch_free(p);
cl_git_pass(git_diff_patch_from_blobs(&p, NULL, NULL, alien, NULL, &opts));
cl_git_pass(git_patch_from_blobs(&p, NULL, NULL, alien, NULL, &opts));
cl_assert(p != NULL);
delta = git_diff_patch_delta(p);
delta = git_patch_delta(p);
cl_assert(delta != NULL);
cl_assert_equal_i(GIT_DELTA_ADDED, delta->status);
cl_assert((delta->flags & GIT_DIFF_FLAG_BINARY) != 0);
cl_assert_equal_i(0, (int)git_diff_patch_num_hunks(p));
cl_assert_equal_i(0, (int)git_patch_num_hunks(p));
git_diff_patch_free(p);
git_patch_free(p);
}
static void assert_identical_blobs_comparison(diff_expects *expected)
......@@ -437,13 +437,13 @@ void test_diff_blob__can_compare_identical_blobs(void)
void test_diff_blob__can_compare_identical_blobs_with_patch(void)
{
git_diff_patch *p;
git_patch *p;
const git_diff_delta *delta;
cl_git_pass(git_diff_patch_from_blobs(&p, d, NULL, d, NULL, &opts));
cl_git_pass(git_patch_from_blobs(&p, d, NULL, d, NULL, &opts));
cl_assert(p != NULL);
delta = git_diff_patch_delta(p);
delta = git_patch_delta(p);
cl_assert(delta != NULL);
cl_assert_equal_i(GIT_DELTA_UNMODIFIED, delta->status);
cl_assert_equal_sz(delta->old_file.size, git_blob_rawsize(d));
......@@ -451,13 +451,13 @@ void test_diff_blob__can_compare_identical_blobs_with_patch(void)
cl_assert_equal_sz(delta->new_file.size, git_blob_rawsize(d));
cl_assert(git_oid_equal(git_blob_id(d), &delta->new_file.oid));
cl_assert_equal_i(0, (int)git_diff_patch_num_hunks(p));
git_diff_patch_free(p);
cl_assert_equal_i(0, (int)git_patch_num_hunks(p));
git_patch_free(p);
cl_git_pass(git_diff_patch_from_blobs(&p, NULL, NULL, NULL, NULL, &opts));
cl_git_pass(git_patch_from_blobs(&p, NULL, NULL, NULL, NULL, &opts));
cl_assert(p != NULL);
delta = git_diff_patch_delta(p);
delta = git_patch_delta(p);
cl_assert(delta != NULL);
cl_assert_equal_i(GIT_DELTA_UNMODIFIED, delta->status);
cl_assert_equal_sz(0, delta->old_file.size);
......@@ -465,14 +465,14 @@ void test_diff_blob__can_compare_identical_blobs_with_patch(void)
cl_assert_equal_sz(0, delta->new_file.size);
cl_assert(git_oid_iszero(&delta->new_file.oid));
cl_assert_equal_i(0, (int)git_diff_patch_num_hunks(p));
git_diff_patch_free(p);
cl_assert_equal_i(0, (int)git_patch_num_hunks(p));
git_patch_free(p);
cl_git_pass(git_diff_patch_from_blobs(&p, alien, NULL, alien, NULL, &opts));
cl_git_pass(git_patch_from_blobs(&p, alien, NULL, alien, NULL, &opts));
cl_assert(p != NULL);
cl_assert_equal_i(GIT_DELTA_UNMODIFIED, git_diff_patch_delta(p)->status);
cl_assert_equal_i(0, (int)git_diff_patch_num_hunks(p));
git_diff_patch_free(p);
cl_assert_equal_i(GIT_DELTA_UNMODIFIED, git_patch_delta(p)->status);
cl_assert_equal_i(0, (int)git_patch_num_hunks(p));
git_patch_free(p);
}
static void assert_binary_blobs_comparison(diff_expects *expected)
......@@ -693,7 +693,7 @@ void test_diff_blob__can_compare_blob_to_buffer(void)
void test_diff_blob__can_compare_blob_to_buffer_with_patch(void)
{
git_diff_patch *p;
git_patch *p;
git_blob *a;
git_oid a_oid;
const char *a_content = "Hello from the root\n";
......@@ -705,58 +705,58 @@ void test_diff_blob__can_compare_blob_to_buffer_with_patch(void)
cl_git_pass(git_blob_lookup_prefix(&a, g_repo, &a_oid, 4));
/* diff from blob a to content of b */
cl_git_pass(git_diff_patch_from_blob_and_buffer(
cl_git_pass(git_patch_from_blob_and_buffer(
&p, a, NULL, b_content, strlen(b_content), NULL, &opts));
cl_assert(p != NULL);
cl_assert_equal_i(GIT_DELTA_MODIFIED, git_diff_patch_delta(p)->status);
cl_assert_equal_i(1, (int)git_diff_patch_num_hunks(p));
cl_assert_equal_i(6, git_diff_patch_num_lines_in_hunk(p, 0));
cl_assert_equal_i(GIT_DELTA_MODIFIED, git_patch_delta(p)->status);
cl_assert_equal_i(1, (int)git_patch_num_hunks(p));
cl_assert_equal_i(6, git_patch_num_lines_in_hunk(p, 0));
cl_git_pass(git_diff_patch_line_stats(&tc, &ta, &td, p));
cl_git_pass(git_patch_line_stats(&tc, &ta, &td, p));
cl_assert_equal_i(1, (int)tc);
cl_assert_equal_i(5, (int)ta);
cl_assert_equal_i(0, (int)td);
git_diff_patch_free(p);
git_patch_free(p);
/* diff from blob a to content of a */
opts.flags |= GIT_DIFF_INCLUDE_UNMODIFIED;
cl_git_pass(git_diff_patch_from_blob_and_buffer(
cl_git_pass(git_patch_from_blob_and_buffer(
&p, a, NULL, a_content, strlen(a_content), NULL, &opts));
cl_assert(p != NULL);
cl_assert_equal_i(GIT_DELTA_UNMODIFIED, git_diff_patch_delta(p)->status);
cl_assert_equal_i(0, (int)git_diff_patch_num_hunks(p));
git_diff_patch_free(p);
cl_assert_equal_i(GIT_DELTA_UNMODIFIED, git_patch_delta(p)->status);
cl_assert_equal_i(0, (int)git_patch_num_hunks(p));
git_patch_free(p);
/* diff from NULL blob to content of a */
cl_git_pass(git_diff_patch_from_blob_and_buffer(
cl_git_pass(git_patch_from_blob_and_buffer(
&p, NULL, NULL, a_content, strlen(a_content), NULL, &opts));
cl_assert(p != NULL);
cl_assert_equal_i(GIT_DELTA_ADDED, git_diff_patch_delta(p)->status);
cl_assert_equal_i(1, (int)git_diff_patch_num_hunks(p));
cl_assert_equal_i(1, git_diff_patch_num_lines_in_hunk(p, 0));
git_diff_patch_free(p);
cl_assert_equal_i(GIT_DELTA_ADDED, git_patch_delta(p)->status);
cl_assert_equal_i(1, (int)git_patch_num_hunks(p));
cl_assert_equal_i(1, git_patch_num_lines_in_hunk(p, 0));
git_patch_free(p);
/* diff from blob a to NULL buffer */
cl_git_pass(git_diff_patch_from_blob_and_buffer(
cl_git_pass(git_patch_from_blob_and_buffer(
&p, a, NULL, NULL, 0, NULL, &opts));
cl_assert(p != NULL);
cl_assert_equal_i(GIT_DELTA_DELETED, git_diff_patch_delta(p)->status);
cl_assert_equal_i(1, (int)git_diff_patch_num_hunks(p));
cl_assert_equal_i(1, git_diff_patch_num_lines_in_hunk(p, 0));
git_diff_patch_free(p);
cl_assert_equal_i(GIT_DELTA_DELETED, git_patch_delta(p)->status);
cl_assert_equal_i(1, (int)git_patch_num_hunks(p));
cl_assert_equal_i(1, git_patch_num_lines_in_hunk(p, 0));
git_patch_free(p);
/* diff with reverse */
opts.flags ^= GIT_DIFF_REVERSE;
cl_git_pass(git_diff_patch_from_blob_and_buffer(
cl_git_pass(git_patch_from_blob_and_buffer(
&p, a, NULL, NULL, 0, NULL, &opts));
cl_assert(p != NULL);
cl_assert_equal_i(GIT_DELTA_ADDED, git_diff_patch_delta(p)->status);
cl_assert_equal_i(1, (int)git_diff_patch_num_hunks(p));
cl_assert_equal_i(1, git_diff_patch_num_lines_in_hunk(p, 0));
git_diff_patch_free(p);
cl_assert_equal_i(GIT_DELTA_ADDED, git_patch_delta(p)->status);
cl_assert_equal_i(1, (int)git_patch_num_hunks(p));
cl_assert_equal_i(1, git_patch_num_lines_in_hunk(p, 0));
git_patch_free(p);
git_blob_free(a);
}
......@@ -853,7 +853,7 @@ void test_diff_blob__using_path_and_attributes(void)
"0123456789\n\x01\x02\x03\x04\x05\x06\x07\x08\x09\x00\n0123456789\n";
size_t bin_len = 33;
const char *changed;
git_diff_patch *p;
git_patch *p;
char *pout;
/* set up custom diff drivers and 'diff' attribute mappings for them */
......@@ -950,9 +950,9 @@ void test_diff_blob__using_path_and_attributes(void)
cl_assert_equal_i(3, expected.line_adds);
cl_assert_equal_i(0, expected.line_dels);
cl_git_pass(git_diff_patch_from_blob_and_buffer(
cl_git_pass(git_patch_from_blob_and_buffer(
&p, nonbin, "zzz.normal", changed, strlen(changed), NULL, &opts));
cl_git_pass(git_diff_patch_to_str(&pout, p));
cl_git_pass(git_patch_to_str(&pout, p));
cl_assert_equal_s(
"diff --git a/zzz.normal b/zzz.normal\n"
"index 45141a7..75b0dbb 100644\n"
......@@ -963,21 +963,21 @@ void test_diff_blob__using_path_and_attributes(void)
"+And more\n"
"+Go here\n", pout);
git__free(pout);
git_diff_patch_free(p);
git_patch_free(p);
cl_git_pass(git_diff_patch_from_blob_and_buffer(
cl_git_pass(git_patch_from_blob_and_buffer(
&p, nonbin, "zzz.binary", changed, strlen(changed), NULL, &opts));
cl_git_pass(git_diff_patch_to_str(&pout, p));
cl_git_pass(git_patch_to_str(&pout, p));
cl_assert_equal_s(
"diff --git a/zzz.binary b/zzz.binary\n"
"index 45141a7..75b0dbb 100644\n"
"Binary files a/zzz.binary and b/zzz.binary differ\n", pout);
git__free(pout);
git_diff_patch_free(p);
git_patch_free(p);
cl_git_pass(git_diff_patch_from_blob_and_buffer(
cl_git_pass(git_patch_from_blob_and_buffer(
&p, nonbin, "zzz.alphary", changed, strlen(changed), NULL, &opts));
cl_git_pass(git_diff_patch_to_str(&pout, p));
cl_git_pass(git_patch_to_str(&pout, p));
cl_assert_equal_s(
"diff --git a/zzz.alphary b/zzz.alphary\n"
"index 45141a7..75b0dbb 100644\n"
......@@ -988,11 +988,11 @@ void test_diff_blob__using_path_and_attributes(void)
"+And more\n"
"+Go here\n", pout);
git__free(pout);
git_diff_patch_free(p);
git_patch_free(p);
cl_git_pass(git_diff_patch_from_blob_and_buffer(
cl_git_pass(git_patch_from_blob_and_buffer(
&p, nonbin, "zzz.numary", changed, strlen(changed), NULL, &opts));
cl_git_pass(git_diff_patch_to_str(&pout, p));
cl_git_pass(git_patch_to_str(&pout, p));
cl_assert_equal_s(
"diff --git a/zzz.numary b/zzz.numary\n"
"index 45141a7..75b0dbb 100644\n"
......@@ -1003,7 +1003,7 @@ void test_diff_blob__using_path_and_attributes(void)
"+And more\n"
"+Go here\n", pout);
git__free(pout);
git_diff_patch_free(p);
git_patch_free(p);
/* "0123456789\n\x01\x02\x03\x04\x05\x06\x07\x08\x09\x00\n0123456789\n"
* 33 bytes
......@@ -1011,19 +1011,19 @@ void test_diff_blob__using_path_and_attributes(void)
changed = "0123456789\n\x01\x02\x03\x04\x05\x06\x07\x08\x09\x00\nreplace a line\n";
cl_git_pass(git_diff_patch_from_blob_and_buffer(
cl_git_pass(git_patch_from_blob_and_buffer(
&p, bin, "zzz.normal", changed, 37, NULL, &opts));
cl_git_pass(git_diff_patch_to_str(&pout, p));
cl_git_pass(git_patch_to_str(&pout, p));
cl_assert_equal_s(
"diff --git a/zzz.normal b/zzz.normal\n"
"index b435cd5..1604519 100644\n"
"Binary files a/zzz.normal and b/zzz.normal differ\n", pout);
git__free(pout);
git_diff_patch_free(p);
git_patch_free(p);
cl_git_pass(git_diff_patch_from_blob_and_buffer(
cl_git_pass(git_patch_from_blob_and_buffer(
&p, bin, "zzz.textary", changed, 37, NULL, &opts));
cl_git_pass(git_diff_patch_to_str(&pout, p));
cl_git_pass(git_patch_to_str(&pout, p));
cl_assert_equal_s(
"diff --git a/zzz.textary b/zzz.textary\n"
"index b435cd5..1604519 100644\n"
......@@ -1033,11 +1033,11 @@ void test_diff_blob__using_path_and_attributes(void)
"-0123456789\n"
"+replace a line\n", pout);
git__free(pout);
git_diff_patch_free(p);
git_patch_free(p);
cl_git_pass(git_diff_patch_from_blob_and_buffer(
cl_git_pass(git_patch_from_blob_and_buffer(
&p, bin, "zzz.textalphary", changed, 37, NULL, &opts));
cl_git_pass(git_diff_patch_to_str(&pout, p));
cl_git_pass(git_patch_to_str(&pout, p));
cl_assert_equal_s(
"diff --git a/zzz.textalphary b/zzz.textalphary\n"
"index b435cd5..1604519 100644\n"
......@@ -1047,11 +1047,11 @@ void test_diff_blob__using_path_and_attributes(void)
"-0123456789\n"
"+replace a line\n", pout);
git__free(pout);
git_diff_patch_free(p);
git_patch_free(p);
cl_git_pass(git_diff_patch_from_blob_and_buffer(
cl_git_pass(git_patch_from_blob_and_buffer(
&p, bin, "zzz.textnumary", changed, 37, NULL, &opts));
cl_git_pass(git_diff_patch_to_str(&pout, p));
cl_git_pass(git_patch_to_str(&pout, p));
cl_assert_equal_s(
"diff --git a/zzz.textnumary b/zzz.textnumary\n"
"index b435cd5..1604519 100644\n"
......@@ -1061,7 +1061,7 @@ void test_diff_blob__using_path_and_attributes(void)
"-0123456789\n"
"+replace a line\n", pout);
git__free(pout);
git_diff_patch_free(p);
git_patch_free(p);
git_blob_free(nonbin);
git_blob_free(bin);
......
......@@ -95,7 +95,7 @@ int diff_print_file_cb(
int diff_hunk_cb(
const git_diff_delta *delta,
const git_diff_range *range,
const git_diff_hunk *range,
const char *header,
size_t header_len,
void *payload)
......@@ -115,7 +115,7 @@ int diff_hunk_cb(
int diff_line_cb(
const git_diff_delta *delta,
const git_diff_range *range,
const git_diff_hunk *range,
char line_origin,
const char *content,
size_t content_len,
......@@ -149,25 +149,25 @@ int diff_line_cb(
}
int diff_foreach_via_iterator(
git_diff_list *diff,
git_diff *diff,
git_diff_file_cb file_cb,
git_diff_hunk_cb hunk_cb,
git_diff_data_cb line_cb,
git_diff_line_cb line_cb,
void *data)
{
size_t d, num_d = git_diff_num_deltas(diff);
for (d = 0; d < num_d; ++d) {
git_diff_patch *patch;
git_patch *patch;
const git_diff_delta *delta;
size_t h, num_h;
cl_git_pass(git_diff_get_patch(&patch, &delta, diff, d));
cl_git_pass(git_patch_from_diff(&patch, &delta, diff, d));
cl_assert(delta);
/* call file_cb for this file */
if (file_cb != NULL && file_cb(delta, (float)d / num_d, data) != 0) {
git_diff_patch_free(patch);
git_patch_free(patch);
goto abort;
}
......@@ -179,22 +179,22 @@ int diff_foreach_via_iterator(
}
if (!hunk_cb && !line_cb) {
git_diff_patch_free(patch);
git_patch_free(patch);
continue;
}
num_h = git_diff_patch_num_hunks(patch);
num_h = git_patch_num_hunks(patch);
for (h = 0; h < num_h; h++) {
const git_diff_range *range;
const git_diff_hunk *range;
const char *hdr;
size_t hdr_len, l, num_l;
cl_git_pass(git_diff_patch_get_hunk(
cl_git_pass(git_patch_get_hunk(
&range, &hdr, &hdr_len, &num_l, patch, h));
if (hunk_cb && hunk_cb(delta, range, hdr, hdr_len, data) != 0) {
git_diff_patch_free(patch);
git_patch_free(patch);
goto abort;
}
......@@ -204,19 +204,19 @@ int diff_foreach_via_iterator(
size_t line_len;
int old_lineno, new_lineno;
cl_git_pass(git_diff_patch_get_line_in_hunk(
cl_git_pass(git_patch_get_line_in_hunk(
&origin, &line, &line_len, &old_lineno, &new_lineno,
patch, h, l));
if (line_cb &&
line_cb(delta, range, origin, line, line_len, data) != 0) {
git_diff_patch_free(patch);
git_patch_free(patch);
goto abort;
}
}
}
git_diff_patch_free(patch);
git_patch_free(patch);
}
return 0;
......@@ -228,7 +228,7 @@ abort:
static int diff_print_cb(
const git_diff_delta *delta,
const git_diff_range *range,
const git_diff_hunk *range,
char line_origin, /**< GIT_DIFF_LINE_... value from above */
const char *content,
size_t content_len,
......@@ -243,12 +243,12 @@ static int diff_print_cb(
return 0;
}
void diff_print(FILE *fp, git_diff_list *diff)
void diff_print(FILE *fp, git_diff *diff)
{
cl_git_pass(git_diff_print_patch(diff, diff_print_cb, fp ? fp : stderr));
}
void diff_print_raw(FILE *fp, git_diff_list *diff)
void diff_print_raw(FILE *fp, git_diff *diff)
{
cl_git_pass(git_diff_print_raw(diff, diff_print_cb, fp ? fp : stderr));
}
......@@ -44,25 +44,25 @@ extern int diff_print_file_cb(
extern int diff_hunk_cb(
const git_diff_delta *delta,
const git_diff_range *range,
const git_diff_hunk *range,
const char *header,
size_t header_len,
void *cb_data);
extern int diff_line_cb(
const git_diff_delta *delta,
const git_diff_range *range,
const git_diff_hunk *range,
char line_origin,
const char *content,
size_t content_len,
void *cb_data);
extern int diff_foreach_via_iterator(
git_diff_list *diff,
git_diff *diff,
git_diff_file_cb file_cb,
git_diff_hunk_cb hunk_cb,
git_diff_data_cb line_cb,
git_diff_line_cb line_cb,
void *data);
extern void diff_print(FILE *fp, git_diff_list *diff);
extern void diff_print_raw(FILE *fp, git_diff_list *diff);
extern void diff_print(FILE *fp, git_diff *diff);
extern void diff_print_raw(FILE *fp, git_diff *diff);
......@@ -13,7 +13,7 @@ void test_diff_diffiter__cleanup(void)
void test_diff_diffiter__create(void)
{
git_repository *repo = cl_git_sandbox_init("attr");
git_diff_list *diff;
git_diff *diff;
size_t d, num_d;
cl_git_pass(git_diff_index_to_workdir(&diff, repo, NULL, NULL));
......@@ -21,16 +21,16 @@ void test_diff_diffiter__create(void)
num_d = git_diff_num_deltas(diff);
for (d = 0; d < num_d; ++d) {
const git_diff_delta *delta;
cl_git_pass(git_diff_get_patch(NULL, &delta, diff, d));
cl_git_pass(git_patch_from_diff(NULL, &delta, diff, d));
}
git_diff_list_free(diff);
git_diff_free(diff);
}
void test_diff_diffiter__iterate_files_1(void)
{
git_repository *repo = cl_git_sandbox_init("attr");
git_diff_list *diff;
git_diff *diff;
size_t d, num_d;
diff_expects exp = { 0 };
......@@ -40,20 +40,20 @@ void test_diff_diffiter__iterate_files_1(void)
for (d = 0; d < num_d; ++d) {
const git_diff_delta *delta;
cl_git_pass(git_diff_get_patch(NULL, &delta, diff, d));
cl_git_pass(git_patch_from_diff(NULL, &delta, diff, d));
cl_assert(delta != NULL);
diff_file_cb(delta, (float)d / (float)num_d, &exp);
}
cl_assert_equal_sz(6, exp.files);
git_diff_list_free(diff);
git_diff_free(diff);
}
void test_diff_diffiter__iterate_files_2(void)
{
git_repository *repo = cl_git_sandbox_init("status");
git_diff_list *diff;
git_diff *diff;
size_t d, num_d;
int count = 0;
......@@ -64,20 +64,20 @@ void test_diff_diffiter__iterate_files_2(void)
for (d = 0; d < num_d; ++d) {
const git_diff_delta *delta;
cl_git_pass(git_diff_get_patch(NULL, &delta, diff, d));
cl_git_pass(git_patch_from_diff(NULL, &delta, diff, d));
cl_assert(delta != NULL);
count++;
}
cl_assert_equal_i(8, count);
git_diff_list_free(diff);
git_diff_free(diff);
}
void test_diff_diffiter__iterate_files_and_hunks(void)
{
git_repository *repo = cl_git_sandbox_init("status");
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
git_diff_list *diff = NULL;
git_diff *diff = NULL;
size_t d, num_d;
int file_count = 0, hunk_count = 0;
......@@ -90,25 +90,25 @@ void test_diff_diffiter__iterate_files_and_hunks(void)
num_d = git_diff_num_deltas(diff);
for (d = 0; d < num_d; ++d) {
git_diff_patch *patch;
git_patch *patch;
const git_diff_delta *delta;
size_t h, num_h;
cl_git_pass(git_diff_get_patch(&patch, &delta, diff, d));
cl_git_pass(git_patch_from_diff(&patch, &delta, diff, d));
cl_assert(delta);
cl_assert(patch);
file_count++;
num_h = git_diff_patch_num_hunks(patch);
num_h = git_patch_num_hunks(patch);
for (h = 0; h < num_h; h++) {
const git_diff_range *range;
const git_diff_hunk *range;
const char *header;
size_t header_len, num_l;
cl_git_pass(git_diff_patch_get_hunk(
cl_git_pass(git_patch_get_hunk(
&range, &header, &header_len, &num_l, patch, h));
cl_assert(range);
......@@ -117,20 +117,20 @@ void test_diff_diffiter__iterate_files_and_hunks(void)
hunk_count++;
}
git_diff_patch_free(patch);
git_patch_free(patch);
}
cl_assert_equal_i(13, file_count);
cl_assert_equal_i(8, hunk_count);
git_diff_list_free(diff);
git_diff_free(diff);
}
void test_diff_diffiter__max_size_threshold(void)
{
git_repository *repo = cl_git_sandbox_init("status");
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
git_diff_list *diff = NULL;
git_diff *diff = NULL;
int file_count = 0, binary_count = 0, hunk_count = 0;
size_t d, num_d;
......@@ -142,27 +142,27 @@ void test_diff_diffiter__max_size_threshold(void)
num_d = git_diff_num_deltas(diff);
for (d = 0; d < num_d; ++d) {
git_diff_patch *patch;
git_patch *patch;
const git_diff_delta *delta;
cl_git_pass(git_diff_get_patch(&patch, &delta, diff, d));
cl_git_pass(git_patch_from_diff(&patch, &delta, diff, d));
cl_assert(delta);
cl_assert(patch);
file_count++;
hunk_count += (int)git_diff_patch_num_hunks(patch);
hunk_count += (int)git_patch_num_hunks(patch);
assert((delta->flags & (GIT_DIFF_FLAG_BINARY|GIT_DIFF_FLAG_NOT_BINARY)) != 0);
binary_count += ((delta->flags & GIT_DIFF_FLAG_BINARY) != 0);
git_diff_patch_free(patch);
git_patch_free(patch);
}
cl_assert_equal_i(13, file_count);
cl_assert_equal_i(0, binary_count);
cl_assert_equal_i(8, hunk_count);
git_diff_list_free(diff);
git_diff_free(diff);
/* try again with low file size threshold */
......@@ -177,18 +177,18 @@ void test_diff_diffiter__max_size_threshold(void)
num_d = git_diff_num_deltas(diff);
for (d = 0; d < num_d; ++d) {
git_diff_patch *patch;
git_patch *patch;
const git_diff_delta *delta;
cl_git_pass(git_diff_get_patch(&patch, &delta, diff, d));
cl_git_pass(git_patch_from_diff(&patch, &delta, diff, d));
file_count++;
hunk_count += (int)git_diff_patch_num_hunks(patch);
hunk_count += (int)git_patch_num_hunks(patch);
assert((delta->flags & (GIT_DIFF_FLAG_BINARY|GIT_DIFF_FLAG_NOT_BINARY)) != 0);
binary_count += ((delta->flags & GIT_DIFF_FLAG_BINARY) != 0);
git_diff_patch_free(patch);
git_patch_free(patch);
}
cl_assert_equal_i(13, file_count);
......@@ -200,7 +200,7 @@ void test_diff_diffiter__max_size_threshold(void)
cl_assert_equal_i(3, binary_count);
cl_assert_equal_i(5, hunk_count);
git_diff_list_free(diff);
git_diff_free(diff);
}
......@@ -208,7 +208,7 @@ void test_diff_diffiter__iterate_all(void)
{
git_repository *repo = cl_git_sandbox_init("status");
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
git_diff_list *diff = NULL;
git_diff *diff = NULL;
diff_expects exp = {0};
size_t d, num_d;
......@@ -220,21 +220,21 @@ void test_diff_diffiter__iterate_all(void)
num_d = git_diff_num_deltas(diff);
for (d = 0; d < num_d; ++d) {
git_diff_patch *patch;
git_patch *patch;
const git_diff_delta *delta;
size_t h, num_h;
cl_git_pass(git_diff_get_patch(&patch, &delta, diff, d));
cl_git_pass(git_patch_from_diff(&patch, &delta, diff, d));
cl_assert(patch && delta);
exp.files++;
num_h = git_diff_patch_num_hunks(patch);
num_h = git_patch_num_hunks(patch);
for (h = 0; h < num_h; h++) {
const git_diff_range *range;
const git_diff_hunk *range;
const char *header;
size_t header_len, l, num_l;
cl_git_pass(git_diff_patch_get_hunk(
cl_git_pass(git_patch_get_hunk(
&range, &header, &header_len, &num_l, patch, h));
cl_assert(range && header);
exp.hunks++;
......@@ -244,33 +244,33 @@ void test_diff_diffiter__iterate_all(void)
const char *content;
size_t content_len;
cl_git_pass(git_diff_patch_get_line_in_hunk(
cl_git_pass(git_patch_get_line_in_hunk(
&origin, &content, &content_len, NULL, NULL, patch, h, l));
cl_assert(content);
exp.lines++;
}
}
git_diff_patch_free(patch);
git_patch_free(patch);
}
cl_assert_equal_i(13, exp.files);
cl_assert_equal_i(8, exp.hunks);
cl_assert_equal_i(14, exp.lines);
git_diff_list_free(diff);
git_diff_free(diff);
}
static void iterate_over_patch(git_diff_patch *patch, diff_expects *exp)
static void iterate_over_patch(git_patch *patch, diff_expects *exp)
{
size_t h, num_h = git_diff_patch_num_hunks(patch), num_l;
size_t h, num_h = git_patch_num_hunks(patch), num_l;
exp->files++;
exp->hunks += (int)num_h;
/* let's iterate in reverse, just because we can! */
for (h = 1, num_l = 0; h <= num_h; ++h)
num_l += git_diff_patch_num_lines_in_hunk(patch, num_h - h);
num_l += git_patch_num_lines_in_hunk(patch, num_h - h);
exp->lines += (int)num_l;
}
......@@ -281,9 +281,9 @@ void test_diff_diffiter__iterate_randomly_while_saving_state(void)
{
git_repository *repo = cl_git_sandbox_init("status");
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
git_diff_list *diff = NULL;
git_diff *diff = NULL;
diff_expects exp = {0};
git_diff_patch *patches[PATCH_CACHE];
git_patch *patches[PATCH_CACHE];
size_t p, d, num_d;
memset(patches, 0, sizeof(patches));
......@@ -308,32 +308,32 @@ void test_diff_diffiter__iterate_randomly_while_saving_state(void)
for (d = 0; d < num_d; ++d) {
/* take old patch */
git_diff_patch *patch = patches[p];
git_patch *patch = patches[p];
patches[p] = NULL;
/* cache new patch */
cl_git_pass(git_diff_get_patch(&patches[p], NULL, diff, d));
cl_git_pass(git_patch_from_diff(&patches[p], NULL, diff, d));
cl_assert(patches[p] != NULL);
/* process old patch if non-NULL */
if (patch != NULL) {
iterate_over_patch(patch, &exp);
git_diff_patch_free(patch);
git_patch_free(patch);
}
p = rand() % PATCH_CACHE;
}
/* free diff list now - refcounts should keep things safe */
git_diff_list_free(diff);
git_diff_free(diff);
/* process remaining unprocessed patches */
for (p = 0; p < PATCH_CACHE; p++) {
git_diff_patch *patch = patches[p];
git_patch *patch = patches[p];
if (patch != NULL) {
iterate_over_patch(patch, &exp);
git_diff_patch_free(patch);
git_patch_free(patch);
}
}
......@@ -416,7 +416,7 @@ static const char *expected_patch_text[8] = {
void test_diff_diffiter__iterate_and_generate_patch_text(void)
{
git_repository *repo = cl_git_sandbox_init("status");
git_diff_list *diff;
git_diff *diff;
size_t d, num_d;
cl_git_pass(git_diff_index_to_workdir(&diff, repo, NULL, NULL));
......@@ -425,28 +425,28 @@ void test_diff_diffiter__iterate_and_generate_patch_text(void)
cl_assert_equal_i(8, (int)num_d);
for (d = 0; d < num_d; ++d) {
git_diff_patch *patch;
git_patch *patch;
char *text;
cl_git_pass(git_diff_get_patch(&patch, NULL, diff, d));
cl_git_pass(git_patch_from_diff(&patch, NULL, diff, d));
cl_assert(patch != NULL);
cl_git_pass(git_diff_patch_to_str(&text, patch));
cl_git_pass(git_patch_to_str(&text, patch));
cl_assert_equal_s(expected_patch_text[d], text);
git__free(text);
git_diff_patch_free(patch);
git_patch_free(patch);
}
git_diff_list_free(diff);
git_diff_free(diff);
}
void test_diff_diffiter__checks_options_version(void)
{
git_repository *repo = cl_git_sandbox_init("status");
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
git_diff_list *diff = NULL;
git_diff *diff = NULL;
const git_error *err;
opts.version = 0;
......
......@@ -20,8 +20,8 @@ void test_diff_drivers__patterns(void)
git_config *cfg;
const char *one_sha = "19dd32dfb1520a64e5bbaae8dce6ef423dfa2f13";
git_tree *one;
git_diff_list *diff;
git_diff_patch *patch;
git_diff *diff;
git_patch *patch;
char *text;
const char *expected0 = "diff --git a/untimely.txt b/untimely.txt\nindex 9a69d96..57fd0cf 100644\n--- a/untimely.txt\n+++ b/untimely.txt\n@@ -22,3 +22,5 @@ Comes through the blood of the vanguards who\n dreamed--too soon--it had sounded.\r\n \r\n -- Rudyard Kipling\r\n+\r\n+Some new stuff\r\n";
const char *expected1 = "diff --git a/untimely.txt b/untimely.txt\nindex 9a69d96..57fd0cf 100644\nBinary files a/untimely.txt and b/untimely.txt differ\n";
......@@ -35,7 +35,7 @@ void test_diff_drivers__patterns(void)
cl_git_pass(git_diff_tree_to_workdir(&diff, g_repo, one, NULL));
cl_assert_equal_i(0, (int)git_diff_num_deltas(diff));
git_diff_list_free(diff);
git_diff_free(diff);
/* default diff */
......@@ -44,13 +44,13 @@ void test_diff_drivers__patterns(void)
cl_git_pass(git_diff_tree_to_workdir(&diff, g_repo, one, NULL));
cl_assert_equal_i(1, (int)git_diff_num_deltas(diff));
cl_git_pass(git_diff_get_patch(&patch, NULL, diff, 0));
cl_git_pass(git_diff_patch_to_str(&text, patch));
cl_git_pass(git_patch_from_diff(&patch, NULL, diff, 0));
cl_git_pass(git_patch_to_str(&text, patch));
cl_assert_equal_s(expected0, text);
git__free(text);
git_diff_patch_free(patch);
git_diff_list_free(diff);
git_patch_free(patch);
git_diff_free(diff);
/* attribute diff set to false */
......@@ -59,13 +59,13 @@ void test_diff_drivers__patterns(void)
cl_git_pass(git_diff_tree_to_workdir(&diff, g_repo, one, NULL));
cl_assert_equal_i(1, (int)git_diff_num_deltas(diff));
cl_git_pass(git_diff_get_patch(&patch, NULL, diff, 0));
cl_git_pass(git_diff_patch_to_str(&text, patch));
cl_git_pass(git_patch_from_diff(&patch, NULL, diff, 0));
cl_git_pass(git_patch_to_str(&text, patch));
cl_assert_equal_s(expected1, text);
git__free(text);
git_diff_patch_free(patch);
git_diff_list_free(diff);
git_patch_free(patch);
git_diff_free(diff);
/* attribute diff set to unconfigured value (should use default) */
......@@ -74,13 +74,13 @@ void test_diff_drivers__patterns(void)
cl_git_pass(git_diff_tree_to_workdir(&diff, g_repo, one, NULL));
cl_assert_equal_i(1, (int)git_diff_num_deltas(diff));
cl_git_pass(git_diff_get_patch(&patch, NULL, diff, 0));
cl_git_pass(git_diff_patch_to_str(&text, patch));
cl_git_pass(git_patch_from_diff(&patch, NULL, diff, 0));
cl_git_pass(git_patch_to_str(&text, patch));
cl_assert_equal_s(expected0, text);
git__free(text);
git_diff_patch_free(patch);
git_diff_list_free(diff);
git_patch_free(patch);
git_diff_free(diff);
/* let's define that driver */
......@@ -91,13 +91,13 @@ void test_diff_drivers__patterns(void)
cl_git_pass(git_diff_tree_to_workdir(&diff, g_repo, one, NULL));
cl_assert_equal_i(1, (int)git_diff_num_deltas(diff));
cl_git_pass(git_diff_get_patch(&patch, NULL, diff, 0));
cl_git_pass(git_diff_patch_to_str(&text, patch));
cl_git_pass(git_patch_from_diff(&patch, NULL, diff, 0));
cl_git_pass(git_patch_to_str(&text, patch));
cl_assert_equal_s(expected1, text);
git__free(text);
git_diff_patch_free(patch);
git_diff_list_free(diff);
git_patch_free(patch);
git_diff_free(diff);
/* let's use a real driver with some regular expressions */
......@@ -112,13 +112,13 @@ void test_diff_drivers__patterns(void)
cl_git_pass(git_diff_tree_to_workdir(&diff, g_repo, one, NULL));
cl_assert_equal_i(1, (int)git_diff_num_deltas(diff));
cl_git_pass(git_diff_get_patch(&patch, NULL, diff, 0));
cl_git_pass(git_diff_patch_to_str(&text, patch));
cl_git_pass(git_patch_from_diff(&patch, NULL, diff, 0));
cl_git_pass(git_patch_to_str(&text, patch));
cl_assert_equal_s(expected2, text);
git__free(text);
git_diff_patch_free(patch);
git_diff_list_free(diff);
git_patch_free(patch);
git_diff_free(diff);
git_tree_free(one);
}
......@@ -127,8 +127,8 @@ void test_diff_drivers__long_lines(void)
{
const char *base = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed non nisi ligula. Ut viverra enim sed lobortis suscipit.\nPhasellus eget erat odio. Praesent at est iaculis, ultricies augue vel, dignissim risus. Suspendisse at nisi quis turpis fringilla rutrum id sit amet nulla.\nNam eget dolor fermentum, aliquet nisl at, convallis tellus. Pellentesque rhoncus erat enim, id porttitor elit euismod quis.\nMauris sollicitudin magna odio, non egestas libero vehicula ut. Etiam et quam velit. Fusce eget libero rhoncus, ultricies felis sit amet, egestas purus.\nAliquam in semper tellus. Pellentesque adipiscing rutrum velit, quis malesuada lacus consequat eget.\n";
git_index *idx;
git_diff_list *diff;
git_diff_patch *patch;
git_diff *diff;
git_patch *patch;
char *actual;
const char *expected = "diff --git a/longlines.txt b/longlines.txt\nindex c1ce6ef..0134431 100644\n--- a/longlines.txt\n+++ b/longlines.txt\n@@ -3,3 +3,5 @@ Phasellus eget erat odio. Praesent at est iaculis, ultricies augue vel, dignissi\n Nam eget dolor fermentum, aliquet nisl at, convallis tellus. Pellentesque rhoncus erat enim, id porttitor elit euismod quis.\n Mauris sollicitudin magna odio, non egestas libero vehicula ut. Etiam et quam velit. Fusce eget libero rhoncus, ultricies felis sit amet, egestas purus.\n Aliquam in semper tellus. Pellentesque adipiscing rutrum velit, quis malesuada lacus consequat eget.\n+newline\n+newline\n";
......@@ -144,8 +144,8 @@ void test_diff_drivers__long_lines(void)
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, NULL));
cl_assert_equal_sz(1, git_diff_num_deltas(diff));
cl_git_pass(git_diff_get_patch(&patch, NULL, diff, 0));
cl_git_pass(git_diff_patch_to_str(&actual, patch));
cl_git_pass(git_patch_from_diff(&patch, NULL, diff, 0));
cl_git_pass(git_patch_to_str(&actual, patch));
/* if chmod not supported, overwrite mode bits since anything is possible */
if (!cl_is_chmod_supported()) {
......@@ -157,7 +157,7 @@ void test_diff_drivers__long_lines(void)
cl_assert_equal_s(expected, actual);
free(actual);
git_diff_patch_free(patch);
git_diff_list_free(diff);
git_patch_free(patch);
git_diff_free(diff);
}
......@@ -21,7 +21,7 @@ void test_diff_index__0(void)
git_tree *a = resolve_commit_oid_to_tree(g_repo, a_commit);
git_tree *b = resolve_commit_oid_to_tree(g_repo, b_commit);
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
git_diff_list *diff = NULL;
git_diff *diff = NULL;
diff_expects exp;
cl_assert(a);
......@@ -56,7 +56,7 @@ void test_diff_index__0(void)
cl_assert_equal_i(6, exp.line_adds);
cl_assert_equal_i(2, exp.line_dels);
git_diff_list_free(diff);
git_diff_free(diff);
diff = NULL;
memset(&exp, 0, sizeof(exp));
......@@ -84,7 +84,7 @@ void test_diff_index__0(void)
cl_assert_equal_i(11, exp.line_adds);
cl_assert_equal_i(2, exp.line_dels);
git_diff_list_free(diff);
git_diff_free(diff);
diff = NULL;
git_tree_free(a);
......@@ -114,7 +114,7 @@ void test_diff_index__1(void)
git_tree *a = resolve_commit_oid_to_tree(g_repo, a_commit);
git_tree *b = resolve_commit_oid_to_tree(g_repo, b_commit);
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
git_diff_list *diff = NULL;
git_diff *diff = NULL;
diff_expects exp;
cl_assert(a);
......@@ -134,7 +134,7 @@ void test_diff_index__1(void)
cl_assert_equal_i(2, exp.files);
git_diff_list_free(diff);
git_diff_free(diff);
diff = NULL;
git_tree_free(a);
......@@ -146,7 +146,7 @@ void test_diff_index__checks_options_version(void)
const char *a_commit = "26a125ee1bf";
git_tree *a = resolve_commit_oid_to_tree(g_repo, a_commit);
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
git_diff_list *diff = NULL;
git_diff *diff = NULL;
const git_error *err;
opts.version = 0;
......
......@@ -13,7 +13,7 @@ void test_diff_notify__cleanup(void)
}
static int assert_called_notifications(
const git_diff_list *diff_so_far,
const git_diff *diff_so_far,
const git_diff_delta *delta_to_add,
const char *matched_pathspec,
void *payload)
......@@ -45,7 +45,7 @@ static void test_notify(
int expected_diffed_files_count)
{
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
git_diff_list *diff = NULL;
git_diff *diff = NULL;
diff_expects exp;
g_repo = cl_git_sandbox_init("status");
......@@ -63,7 +63,7 @@ static void test_notify(
cl_assert_equal_i(expected_diffed_files_count, exp.files);
git_diff_list_free(diff);
git_diff_free(diff);
}
void test_diff_notify__notify_single_pathspec(void)
......@@ -155,7 +155,7 @@ void test_diff_notify__notify_catchall(void)
}
static int abort_diff(
const git_diff_list *diff_so_far,
const git_diff *diff_so_far,
const git_diff_delta *delta_to_add,
const char *matched_pathspec,
void *payload)
......@@ -171,7 +171,7 @@ static int abort_diff(
void test_diff_notify__notify_cb_can_abort_diff(void)
{
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
git_diff_list *diff = NULL;
git_diff *diff = NULL;
char *pathspec = NULL;
g_repo = cl_git_sandbox_init("status");
......@@ -189,7 +189,7 @@ void test_diff_notify__notify_cb_can_abort_diff(void)
}
static int filter_all(
const git_diff_list *diff_so_far,
const git_diff *diff_so_far,
const git_diff_delta *delta_to_add,
const char *matched_pathspec,
void *payload)
......@@ -205,7 +205,7 @@ static int filter_all(
void test_diff_notify__notify_cb_can_be_used_as_filtering_function(void)
{
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
git_diff_list *diff = NULL;
git_diff *diff = NULL;
char *pathspec = NULL;
diff_expects exp;
......@@ -224,5 +224,5 @@ void test_diff_notify__notify_cb_can_be_used_as_filtering_function(void)
cl_assert_equal_i(0, exp.files);
git_diff_list_free(diff);
git_diff_free(diff);
}
......@@ -26,7 +26,7 @@ void test_diff_patch__cleanup(void)
static int check_removal_cb(
const git_diff_delta *delta,
const git_diff_range *range,
const git_diff_hunk *range,
char line_origin,
const char *formatted_output,
size_t output_len,
......@@ -86,7 +86,7 @@ void test_diff_patch__can_properly_display_the_removal_of_a_file(void)
const char *one_sha = "26a125e";
const char *another_sha = "735b6a2";
git_tree *one, *another;
git_diff_list *diff;
git_diff *diff;
g_repo = cl_git_sandbox_init("status");
......@@ -97,7 +97,7 @@ void test_diff_patch__can_properly_display_the_removal_of_a_file(void)
cl_git_pass(git_diff_print_patch(diff, check_removal_cb, NULL));
git_diff_list_free(diff);
git_diff_free(diff);
git_tree_free(another);
git_tree_free(one);
......@@ -108,8 +108,8 @@ void test_diff_patch__to_string(void)
const char *one_sha = "26a125e";
const char *another_sha = "735b6a2";
git_tree *one, *another;
git_diff_list *diff;
git_diff_patch *patch;
git_diff *diff;
git_patch *patch;
char *text;
const char *expected = "diff --git a/subdir.txt b/subdir.txt\ndeleted file mode 100644\nindex e8ee89e..0000000\n--- a/subdir.txt\n+++ /dev/null\n@@ -1,2 +0,0 @@\n-Is it a bird?\n-Is it a plane?\n";
......@@ -122,20 +122,20 @@ void test_diff_patch__to_string(void)
cl_assert_equal_i(1, (int)git_diff_num_deltas(diff));
cl_git_pass(git_diff_get_patch(&patch, NULL, diff, 0));
cl_git_pass(git_patch_from_diff(&patch, NULL, diff, 0));
cl_git_pass(git_diff_patch_to_str(&text, patch));
cl_git_pass(git_patch_to_str(&text, patch));
cl_assert_equal_s(expected, text);
cl_assert_equal_sz(31, git_diff_patch_size(patch, 0, 0, 0));
cl_assert_equal_sz(31, git_diff_patch_size(patch, 1, 0, 0));
cl_assert_equal_sz(31 + 16, git_diff_patch_size(patch, 1, 1, 0));
cl_assert_equal_sz(strlen(expected), git_diff_patch_size(patch, 1, 1, 1));
cl_assert_equal_sz(31, git_patch_size(patch, 0, 0, 0));
cl_assert_equal_sz(31, git_patch_size(patch, 1, 0, 0));
cl_assert_equal_sz(31 + 16, git_patch_size(patch, 1, 1, 0));
cl_assert_equal_sz(strlen(expected), git_patch_size(patch, 1, 1, 1));
git__free(text);
git_diff_patch_free(patch);
git_diff_list_free(diff);
git_patch_free(patch);
git_diff_free(diff);
git_tree_free(another);
git_tree_free(one);
}
......@@ -145,8 +145,8 @@ void test_diff_patch__config_options(void)
const char *one_sha = "26a125e"; /* current HEAD */
git_tree *one;
git_config *cfg;
git_diff_list *diff;
git_diff_patch *patch;
git_diff *diff;
git_patch *patch;
char *text;
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
char *onefile = "staged_changes_modified_file";
......@@ -167,24 +167,24 @@ void test_diff_patch__config_options(void)
cl_git_pass(git_diff_tree_to_index(&diff, g_repo, one, NULL, &opts));
cl_assert_equal_i(1, (int)git_diff_num_deltas(diff));
cl_git_pass(git_diff_get_patch(&patch, NULL, diff, 0));
cl_git_pass(git_diff_patch_to_str(&text, patch));
cl_git_pass(git_patch_from_diff(&patch, NULL, diff, 0));
cl_git_pass(git_patch_to_str(&text, patch));
cl_assert_equal_s(expected1, text);
git__free(text);
git_diff_patch_free(patch);
git_diff_list_free(diff);
git_patch_free(patch);
git_diff_free(diff);
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
cl_assert_equal_i(1, (int)git_diff_num_deltas(diff));
cl_git_pass(git_diff_get_patch(&patch, NULL, diff, 0));
cl_git_pass(git_diff_patch_to_str(&text, patch));
cl_git_pass(git_patch_from_diff(&patch, NULL, diff, 0));
cl_git_pass(git_patch_to_str(&text, patch));
cl_assert_equal_s(expected2, text);
git__free(text);
git_diff_patch_free(patch);
git_diff_list_free(diff);
git_patch_free(patch);
git_diff_free(diff);
cl_git_pass(git_config_set_string(cfg, "diff.noprefix", "true"));
......@@ -192,13 +192,13 @@ void test_diff_patch__config_options(void)
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
cl_assert_equal_i(1, (int)git_diff_num_deltas(diff));
cl_git_pass(git_diff_get_patch(&patch, NULL, diff, 0));
cl_git_pass(git_diff_patch_to_str(&text, patch));
cl_git_pass(git_patch_from_diff(&patch, NULL, diff, 0));
cl_git_pass(git_patch_to_str(&text, patch));
cl_assert_equal_s(expected3, text);
git__free(text);
git_diff_patch_free(patch);
git_diff_list_free(diff);
git_patch_free(patch);
git_diff_free(diff);
cl_git_pass(git_config_set_int32(cfg, "core.abbrev", 12));
......@@ -206,13 +206,13 @@ void test_diff_patch__config_options(void)
cl_git_pass(git_diff_tree_to_index(&diff, g_repo, one, NULL, &opts));
cl_assert_equal_i(1, (int)git_diff_num_deltas(diff));
cl_git_pass(git_diff_get_patch(&patch, NULL, diff, 0));
cl_git_pass(git_diff_patch_to_str(&text, patch));
cl_git_pass(git_patch_from_diff(&patch, NULL, diff, 0));
cl_git_pass(git_patch_to_str(&text, patch));
cl_assert_equal_s(expected4, text);
git__free(text);
git_diff_patch_free(patch);
git_diff_list_free(diff);
git_patch_free(patch);
git_diff_free(diff);
git_tree_free(one);
git_config_free(cfg);
......@@ -223,10 +223,10 @@ void test_diff_patch__hunks_have_correct_line_numbers(void)
git_config *cfg;
git_tree *head;
git_diff_options opt = GIT_DIFF_OPTIONS_INIT;
git_diff_list *diff;
git_diff_patch *patch;
git_diff *diff;
git_patch *patch;
const git_diff_delta *delta;
const git_diff_range *range;
const git_diff_hunk *range;
const char *hdr, *text;
size_t hdrlen, hunklen, textlen;
char origin;
......@@ -253,15 +253,15 @@ void test_diff_patch__hunks_have_correct_line_numbers(void)
cl_assert_equal_i(1, (int)git_diff_num_deltas(diff));
cl_git_pass(git_diff_get_patch(&patch, &delta, diff, 0));
cl_git_pass(git_patch_from_diff(&patch, &delta, diff, 0));
cl_assert_equal_i(GIT_DELTA_MODIFIED, (int)delta->status);
cl_assert_equal_i(2, (int)git_diff_patch_num_hunks(patch));
cl_assert_equal_i(2, (int)git_patch_num_hunks(patch));
/* check hunk 0 */
cl_git_pass(
git_diff_patch_get_hunk(&range, &hdr, &hdrlen, &hunklen, patch, 0));
git_patch_get_hunk(&range, &hdr, &hdrlen, &hunklen, patch, 0));
cl_assert_equal_i(18, (int)hunklen);
......@@ -270,9 +270,9 @@ void test_diff_patch__hunks_have_correct_line_numbers(void)
cl_assert_equal_i(6, (int)range->new_start);
cl_assert_equal_i(9, (int)range->new_lines);
cl_assert_equal_i(18, (int)git_diff_patch_num_lines_in_hunk(patch, 0));
cl_assert_equal_i(18, (int)git_patch_num_lines_in_hunk(patch, 0));
cl_git_pass(git_diff_patch_get_line_in_hunk(
cl_git_pass(git_patch_get_line_in_hunk(
&origin, &text, &textlen, &oldno, &newno, patch, 0, 0));
cl_assert_equal_i(GIT_DIFF_LINE_CONTEXT, (int)origin);
cl_git_pass(git_buf_set(&actual, text, textlen));
......@@ -280,7 +280,7 @@ void test_diff_patch__hunks_have_correct_line_numbers(void)
cl_assert_equal_i(6, oldno);
cl_assert_equal_i(6, newno);
cl_git_pass(git_diff_patch_get_line_in_hunk(
cl_git_pass(git_patch_get_line_in_hunk(
&origin, &text, &textlen, &oldno, &newno, patch, 0, 3));
cl_assert_equal_i(GIT_DIFF_LINE_DELETION, (int)origin);
cl_git_pass(git_buf_set(&actual, text, textlen));
......@@ -288,7 +288,7 @@ void test_diff_patch__hunks_have_correct_line_numbers(void)
cl_assert_equal_i(9, oldno);
cl_assert_equal_i(-1, newno);
cl_git_pass(git_diff_patch_get_line_in_hunk(
cl_git_pass(git_patch_get_line_in_hunk(
&origin, &text, &textlen, &oldno, &newno, patch, 0, 12));
cl_assert_equal_i(GIT_DIFF_LINE_ADDITION, (int)origin);
cl_git_pass(git_buf_set(&actual, text, textlen));
......@@ -299,7 +299,7 @@ void test_diff_patch__hunks_have_correct_line_numbers(void)
/* check hunk 1 */
cl_git_pass(
git_diff_patch_get_hunk(&range, &hdr, &hdrlen, &hunklen, patch, 1));
git_patch_get_hunk(&range, &hdr, &hdrlen, &hunklen, patch, 1));
cl_assert_equal_i(18, (int)hunklen);
......@@ -308,9 +308,9 @@ void test_diff_patch__hunks_have_correct_line_numbers(void)
cl_assert_equal_i(25, (int)range->new_start);
cl_assert_equal_i(9, (int)range->new_lines);
cl_assert_equal_i(18, (int)git_diff_patch_num_lines_in_hunk(patch, 1));
cl_assert_equal_i(18, (int)git_patch_num_lines_in_hunk(patch, 1));
cl_git_pass(git_diff_patch_get_line_in_hunk(
cl_git_pass(git_patch_get_line_in_hunk(
&origin, &text, &textlen, &oldno, &newno, patch, 1, 0));
cl_assert_equal_i(GIT_DIFF_LINE_CONTEXT, (int)origin);
cl_git_pass(git_buf_set(&actual, text, textlen));
......@@ -318,7 +318,7 @@ void test_diff_patch__hunks_have_correct_line_numbers(void)
cl_assert_equal_i(31, oldno);
cl_assert_equal_i(25, newno);
cl_git_pass(git_diff_patch_get_line_in_hunk(
cl_git_pass(git_patch_get_line_in_hunk(
&origin, &text, &textlen, &oldno, &newno, patch, 1, 3));
cl_assert_equal_i(GIT_DIFF_LINE_DELETION, (int)origin);
cl_git_pass(git_buf_set(&actual, text, textlen));
......@@ -326,7 +326,7 @@ void test_diff_patch__hunks_have_correct_line_numbers(void)
cl_assert_equal_i(34, oldno);
cl_assert_equal_i(-1, newno);
cl_git_pass(git_diff_patch_get_line_in_hunk(
cl_git_pass(git_patch_get_line_in_hunk(
&origin, &text, &textlen, &oldno, &newno, patch, 1, 12));
cl_assert_equal_i(GIT_DIFF_LINE_ADDITION, (int)origin);
cl_git_pass(git_buf_set(&actual, text, textlen));
......@@ -334,8 +334,8 @@ void test_diff_patch__hunks_have_correct_line_numbers(void)
cl_assert_equal_i(-1, oldno);
cl_assert_equal_i(28, newno);
git_diff_patch_free(patch);
git_diff_list_free(diff);
git_patch_free(patch);
git_diff_free(diff);
/* Let's check line numbers when there is no newline */
......@@ -346,15 +346,15 @@ void test_diff_patch__hunks_have_correct_line_numbers(void)
cl_assert_equal_i(1, (int)git_diff_num_deltas(diff));
cl_git_pass(git_diff_get_patch(&patch, &delta, diff, 0));
cl_git_pass(git_patch_from_diff(&patch, &delta, diff, 0));
cl_assert_equal_i(GIT_DELTA_MODIFIED, (int)delta->status);
cl_assert_equal_i(1, (int)git_diff_patch_num_hunks(patch));
cl_assert_equal_i(1, (int)git_patch_num_hunks(patch));
/* check hunk 0 */
cl_git_pass(
git_diff_patch_get_hunk(&range, &hdr, &hdrlen, &hunklen, patch, 0));
git_patch_get_hunk(&range, &hdr, &hdrlen, &hunklen, patch, 0));
cl_assert_equal_i(6, (int)hunklen);
......@@ -363,9 +363,9 @@ void test_diff_patch__hunks_have_correct_line_numbers(void)
cl_assert_equal_i(46, (int)range->new_start);
cl_assert_equal_i(4, (int)range->new_lines);
cl_assert_equal_i(6, (int)git_diff_patch_num_lines_in_hunk(patch, 0));
cl_assert_equal_i(6, (int)git_patch_num_lines_in_hunk(patch, 0));
cl_git_pass(git_diff_patch_get_line_in_hunk(
cl_git_pass(git_patch_get_line_in_hunk(
&origin, &text, &textlen, &oldno, &newno, patch, 0, 1));
cl_assert_equal_i(GIT_DIFF_LINE_CONTEXT, (int)origin);
cl_git_pass(git_buf_set(&actual, text, textlen));
......@@ -373,7 +373,7 @@ void test_diff_patch__hunks_have_correct_line_numbers(void)
cl_assert_equal_i(47, oldno);
cl_assert_equal_i(47, newno);
cl_git_pass(git_diff_patch_get_line_in_hunk(
cl_git_pass(git_patch_get_line_in_hunk(
&origin, &text, &textlen, &oldno, &newno, patch, 0, 2));
cl_assert_equal_i(GIT_DIFF_LINE_CONTEXT, (int)origin);
cl_git_pass(git_buf_set(&actual, text, textlen));
......@@ -381,7 +381,7 @@ void test_diff_patch__hunks_have_correct_line_numbers(void)
cl_assert_equal_i(48, oldno);
cl_assert_equal_i(48, newno);
cl_git_pass(git_diff_patch_get_line_in_hunk(
cl_git_pass(git_patch_get_line_in_hunk(
&origin, &text, &textlen, &oldno, &newno, patch, 0, 3));
cl_assert_equal_i(GIT_DIFF_LINE_DELETION, (int)origin);
cl_git_pass(git_buf_set(&actual, text, textlen));
......@@ -389,7 +389,7 @@ void test_diff_patch__hunks_have_correct_line_numbers(void)
cl_assert_equal_i(49, oldno);
cl_assert_equal_i(-1, newno);
cl_git_pass(git_diff_patch_get_line_in_hunk(
cl_git_pass(git_patch_get_line_in_hunk(
&origin, &text, &textlen, &oldno, &newno, patch, 0, 4));
cl_assert_equal_i(GIT_DIFF_LINE_ADDITION, (int)origin);
cl_git_pass(git_buf_set(&actual, text, textlen));
......@@ -397,7 +397,7 @@ void test_diff_patch__hunks_have_correct_line_numbers(void)
cl_assert_equal_i(-1, oldno);
cl_assert_equal_i(49, newno);
cl_git_pass(git_diff_patch_get_line_in_hunk(
cl_git_pass(git_patch_get_line_in_hunk(
&origin, &text, &textlen, &oldno, &newno, patch, 0, 5));
cl_assert_equal_i(GIT_DIFF_LINE_DEL_EOFNL, (int)origin);
cl_git_pass(git_buf_set(&actual, text, textlen));
......@@ -405,8 +405,8 @@ void test_diff_patch__hunks_have_correct_line_numbers(void)
cl_assert_equal_i(-1, oldno);
cl_assert_equal_i(49, newno);
git_diff_patch_free(patch);
git_diff_list_free(diff);
git_patch_free(patch);
git_diff_free(diff);
git_buf_free(&actual);
git_buf_free(&old_content);
......@@ -418,8 +418,8 @@ static void check_single_patch_stats(
size_t adds, size_t dels, size_t ctxt, size_t *sizes,
const char *expected)
{
git_diff_list *diff;
git_diff_patch *patch;
git_diff *diff;
git_patch *patch;
const git_diff_delta *delta;
size_t actual_ctxt, actual_adds, actual_dels;
......@@ -427,12 +427,12 @@ static void check_single_patch_stats(
cl_assert_equal_i(1, (int)git_diff_num_deltas(diff));
cl_git_pass(git_diff_get_patch(&patch, &delta, diff, 0));
cl_git_pass(git_patch_from_diff(&patch, &delta, diff, 0));
cl_assert_equal_i(GIT_DELTA_MODIFIED, (int)delta->status);
cl_assert_equal_i((int)hunks, (int)git_diff_patch_num_hunks(patch));
cl_assert_equal_i((int)hunks, (int)git_patch_num_hunks(patch));
cl_git_pass( git_diff_patch_line_stats(
cl_git_pass( git_patch_line_stats(
&actual_ctxt, &actual_adds, &actual_dels, patch) );
cl_assert_equal_sz(ctxt, actual_ctxt);
......@@ -441,21 +441,21 @@ static void check_single_patch_stats(
if (expected != NULL) {
char *text;
cl_git_pass(git_diff_patch_to_str(&text, patch));
cl_git_pass(git_patch_to_str(&text, patch));
cl_assert_equal_s(expected, text);
git__free(text);
cl_assert_equal_sz(
strlen(expected), git_diff_patch_size(patch, 1, 1, 1));
strlen(expected), git_patch_size(patch, 1, 1, 1));
}
if (sizes) {
if (sizes[0])
cl_assert_equal_sz(sizes[0], git_diff_patch_size(patch, 0, 0, 0));
cl_assert_equal_sz(sizes[0], git_patch_size(patch, 0, 0, 0));
if (sizes[1])
cl_assert_equal_sz(sizes[1], git_diff_patch_size(patch, 1, 0, 0));
cl_assert_equal_sz(sizes[1], git_patch_size(patch, 1, 0, 0));
if (sizes[2])
cl_assert_equal_sz(sizes[2], git_diff_patch_size(patch, 1, 1, 0));
cl_assert_equal_sz(sizes[2], git_patch_size(patch, 1, 1, 0));
}
/* walk lines in hunk with basic sanity checks */
......@@ -464,12 +464,12 @@ static void check_single_patch_stats(
int lastoldno = -1, oldno, lastnewno = -1, newno;
char origin;
max_i = git_diff_patch_num_lines_in_hunk(patch, hunks - 1);
max_i = git_patch_num_lines_in_hunk(patch, hunks - 1);
for (i = 0; i < max_i; ++i) {
int expected = 1;
cl_git_pass(git_diff_patch_get_line_in_hunk(
cl_git_pass(git_patch_get_line_in_hunk(
&origin, NULL, NULL, &oldno, &newno, patch, hunks - 1, i));
if (origin == GIT_DIFF_LINE_ADD_EOFNL ||
......@@ -490,8 +490,8 @@ static void check_single_patch_stats(
}
}
git_diff_patch_free(patch);
git_diff_list_free(diff);
git_patch_free(patch);
git_diff_free(diff);
}
void test_diff_patch__line_counts_with_eofnl(void)
......
......@@ -20,7 +20,7 @@ void test_diff_pathspec__0(void)
git_tree *a = resolve_commit_oid_to_tree(g_repo, a_commit);
git_tree *b = resolve_commit_oid_to_tree(g_repo, b_commit);
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
git_diff_list *diff = NULL;
git_diff *diff = NULL;
git_strarray paths = { NULL, 1 };
char *path;
git_pathspec *ps;
......@@ -52,7 +52,7 @@ void test_diff_pathspec__0(void)
(int)git_pathspec_match_list_diff_entry(matches,0)->status);
git_pathspec_match_list_free(matches);
git_diff_list_free(diff);
git_diff_free(diff);
diff = NULL;
cl_git_pass(git_diff_tree_to_tree(&diff, g_repo, a, b, &opts));
......@@ -68,7 +68,7 @@ void test_diff_pathspec__0(void)
(int)git_pathspec_match_list_diff_entry(matches,0)->status);
git_pathspec_match_list_free(matches);
git_diff_list_free(diff);
git_diff_free(diff);
diff = NULL;
cl_git_pass(git_diff_tree_to_workdir(&diff, g_repo, a, &opts));
......@@ -84,7 +84,7 @@ void test_diff_pathspec__0(void)
(int)git_pathspec_match_list_diff_entry(matches,0)->status);
git_pathspec_match_list_free(matches);
git_diff_list_free(diff);
git_diff_free(diff);
diff = NULL;
git_tree_free(a);
......
......@@ -43,7 +43,7 @@ void test_diff_rename__match_oid(void)
const char *old_sha = "31e47d8c1fa36d7f8d537b96158e3f024de0a9f2";
const char *new_sha = "2bc7f351d20b53f1c72c16c4b036e491c478c49a";
git_tree *old_tree, *new_tree;
git_diff_list *diff;
git_diff *diff;
git_diff_options diffopts = GIT_DIFF_OPTIONS_INIT;
git_diff_find_options opts = GIT_DIFF_FIND_OPTIONS_INIT;
diff_expects exp;
......@@ -88,7 +88,7 @@ void test_diff_rename__match_oid(void)
cl_assert_equal_i(1, exp.file_status[GIT_DELTA_ADDED]);
cl_assert_equal_i(1, exp.file_status[GIT_DELTA_RENAMED]);
git_diff_list_free(diff);
git_diff_free(diff);
cl_git_pass(git_diff_tree_to_tree(
&diff, g_repo, old_tree, new_tree, &diffopts));
......@@ -109,7 +109,7 @@ void test_diff_rename__match_oid(void)
cl_assert_equal_i(1, exp.file_status[GIT_DELTA_COPIED]);
cl_assert_equal_i(1, exp.file_status[GIT_DELTA_RENAMED]);
git_diff_list_free(diff);
git_diff_free(diff);
git_tree_free(old_tree);
git_tree_free(new_tree);
......@@ -120,7 +120,7 @@ void test_diff_rename__checks_options_version(void)
const char *old_sha = "31e47d8c1fa36d7f8d537b96158e3f024de0a9f2";
const char *new_sha = "2bc7f351d20b53f1c72c16c4b036e491c478c49a";
git_tree *old_tree, *new_tree;
git_diff_list *diff;
git_diff *diff;
git_diff_options diffopts = GIT_DIFF_OPTIONS_INIT;
git_diff_find_options opts = GIT_DIFF_FIND_OPTIONS_INIT;
const git_error *err;
......@@ -142,7 +142,7 @@ void test_diff_rename__checks_options_version(void)
err = giterr_last();
cl_assert_equal_i(GITERR_INVALID, err->klass);
git_diff_list_free(diff);
git_diff_free(diff);
git_tree_free(old_tree);
git_tree_free(new_tree);
}
......@@ -153,7 +153,7 @@ void test_diff_rename__not_exact_match(void)
const char *sha1 = "1c068dee5790ef1580cfc4cd670915b48d790084";
const char *sha2 = "19dd32dfb1520a64e5bbaae8dce6ef423dfa2f13";
git_tree *old_tree, *new_tree;
git_diff_list *diff;
git_diff *diff;
git_diff_options diffopts = GIT_DIFF_OPTIONS_INIT;
git_diff_find_options opts = GIT_DIFF_FIND_OPTIONS_INIT;
diff_expects exp;
......@@ -207,7 +207,7 @@ void test_diff_rename__not_exact_match(void)
cl_assert_equal_i(2, exp.file_status[GIT_DELTA_MODIFIED]);
cl_assert_equal_i(1, exp.file_status[GIT_DELTA_ADDED]);
git_diff_list_free(diff);
git_diff_free(diff);
/* git diff -M -C \
* 2bc7f351d20b53f1c72c16c4b036e491c478c49a \
......@@ -228,7 +228,7 @@ void test_diff_rename__not_exact_match(void)
cl_assert_equal_i(2, exp.file_status[GIT_DELTA_MODIFIED]);
cl_assert_equal_i(1, exp.file_status[GIT_DELTA_COPIED]);
git_diff_list_free(diff);
git_diff_free(diff);
/* git diff -M -C --find-copies-harder --break-rewrites \
* 2bc7f351d20b53f1c72c16c4b036e491c478c49a \
......@@ -253,7 +253,7 @@ void test_diff_rename__not_exact_match(void)
cl_assert_equal_i(1, exp.file_status[GIT_DELTA_DELETED]);
cl_assert_equal_i(1, exp.file_status[GIT_DELTA_COPIED]);
git_diff_list_free(diff);
git_diff_free(diff);
/* == Changes =====================================================
* songofseven.txt -> untimely.txt (rename, convert to crlf)
......@@ -281,7 +281,7 @@ void test_diff_rename__not_exact_match(void)
cl_assert_equal_i(2, exp.file_status[GIT_DELTA_MODIFIED]);
cl_assert_equal_i(2, exp.file_status[GIT_DELTA_ADDED]);
cl_assert_equal_i(2, exp.file_status[GIT_DELTA_DELETED]);
git_diff_list_free(diff);
git_diff_free(diff);
/* git diff -M -C \
* 1c068dee5790ef1580cfc4cd670915b48d790084 \
......@@ -301,7 +301,7 @@ void test_diff_rename__not_exact_match(void)
cl_assert_equal_i(2, exp.file_status[GIT_DELTA_MODIFIED]);
cl_assert_equal_i(2, exp.file_status[GIT_DELTA_RENAMED]);
git_diff_list_free(diff);
git_diff_free(diff);
/* git diff -M -C --find-copies-harder --break-rewrites \
* 1c068dee5790ef1580cfc4cd670915b48d790084 \
......@@ -330,7 +330,7 @@ void test_diff_rename__not_exact_match(void)
cl_assert_equal_i(1, exp.file_status[GIT_DELTA_DELETED]);
cl_assert_equal_i(2, exp.file_status[GIT_DELTA_RENAMED]);
git_diff_list_free(diff);
git_diff_free(diff);
/* git diff -M -C --find-copies-harder --break-rewrites \
* 1c068dee5790ef1580cfc4cd670915b48d790084 \
......@@ -353,7 +353,7 @@ void test_diff_rename__not_exact_match(void)
cl_assert_equal_i(2, exp.file_status[GIT_DELTA_MODIFIED]);
cl_assert_equal_i(2, exp.file_status[GIT_DELTA_RENAMED]);
git_diff_list_free(diff);
git_diff_free(diff);
git_tree_free(old_tree);
git_tree_free(new_tree);
......@@ -364,7 +364,7 @@ void test_diff_rename__handles_small_files(void)
const char *tree_sha = "2bc7f351d20b53f1c72c16c4b036e491c478c49a";
git_index *index;
git_tree *tree;
git_diff_list *diff;
git_diff *diff;
git_diff_options diffopts = GIT_DIFF_OPTIONS_INIT;
git_diff_find_options opts = GIT_DIFF_FIND_OPTIONS_INIT;
......@@ -388,7 +388,7 @@ void test_diff_rename__handles_small_files(void)
GIT_DIFF_FIND_AND_BREAK_REWRITES;
cl_git_pass(git_diff_find_similar(diff, &opts));
git_diff_list_free(diff);
git_diff_free(diff);
git_tree_free(tree);
git_index_free(index);
}
......@@ -400,7 +400,7 @@ void test_diff_rename__working_directory_changes(void)
git_oid id;
git_tree *tree;
git_blob *blob;
git_diff_list *diff;
git_diff *diff;
git_diff_options diffopts = GIT_DIFF_OPTIONS_INIT;
git_diff_find_options opts = GIT_DIFF_FIND_OPTIONS_INIT;
diff_expects exp;
......@@ -451,7 +451,7 @@ void test_diff_rename__working_directory_changes(void)
cl_assert_equal_i(1, exp.file_status[GIT_DELTA_DELETED]);
cl_assert_equal_i(2, exp.file_status[GIT_DELTA_UNTRACKED]);
git_diff_list_free(diff);
git_diff_free(diff);
/* rewrite files in the working directory with / without CRLF changes */
......@@ -477,7 +477,7 @@ void test_diff_rename__working_directory_changes(void)
cl_assert_equal_i(1, exp.file_status[GIT_DELTA_DELETED]);
cl_assert_equal_i(2, exp.file_status[GIT_DELTA_UNTRACKED]);
git_diff_list_free(diff);
git_diff_free(diff);
/* try a different whitespace option */
......@@ -496,7 +496,7 @@ void test_diff_rename__working_directory_changes(void)
cl_assert_equal_i(2, exp.file_status[GIT_DELTA_DELETED]);
cl_assert_equal_i(3, exp.file_status[GIT_DELTA_UNTRACKED]);
git_diff_list_free(diff);
git_diff_free(diff);
/* try a different matching option */
......@@ -514,7 +514,7 @@ void test_diff_rename__working_directory_changes(void)
cl_assert_equal_i(3, exp.file_status[GIT_DELTA_UNTRACKED]);
cl_assert_equal_i(2, exp.file_status[GIT_DELTA_DELETED]);
git_diff_list_free(diff);
git_diff_free(diff);
/* again with exact match blob */
......@@ -545,7 +545,7 @@ void test_diff_rename__working_directory_changes(void)
cl_assert_equal_i(1, exp.file_status[GIT_DELTA_RENAMED]);
cl_assert_equal_i(2, exp.file_status[GIT_DELTA_UNTRACKED]);
git_diff_list_free(diff);
git_diff_free(diff);
git_tree_free(tree);
git_buf_free(&content);
......@@ -557,10 +557,10 @@ void test_diff_rename__patch(void)
const char *sha0 = "2bc7f351d20b53f1c72c16c4b036e491c478c49a";
const char *sha1 = "1c068dee5790ef1580cfc4cd670915b48d790084";
git_tree *old_tree, *new_tree;
git_diff_list *diff;
git_diff *diff;
git_diff_options diffopts = GIT_DIFF_OPTIONS_INIT;
git_diff_find_options opts = GIT_DIFF_FIND_OPTIONS_INIT;
git_diff_patch *patch;
git_patch *patch;
const git_diff_delta *delta;
char *text;
const char *expected = "diff --git a/sixserving.txt b/ikeepsix.txt\nindex ad0a8e5..36020db 100644\n--- a/sixserving.txt\n+++ b/ikeepsix.txt\n@@ -1,3 +1,6 @@\n+I Keep Six Honest Serving-Men\n+=============================\n+\n I KEEP six honest serving-men\n (They taught me all I knew);\n Their names are What and Why and When\n@@ -21,4 +24,4 @@ She sends'em abroad on her own affairs,\n One million Hows, two million Wheres,\n And seven million Whys!\n \n- -- Rudyard Kipling\n+ -- Rudyard Kipling\n";
......@@ -584,25 +584,25 @@ void test_diff_rename__patch(void)
cl_assert_equal_i(4, (int)git_diff_num_deltas(diff));
cl_git_pass(git_diff_get_patch(&patch, &delta, diff, 0));
cl_git_pass(git_patch_from_diff(&patch, &delta, diff, 0));
cl_assert_equal_i(GIT_DELTA_COPIED, (int)delta->status);
cl_git_pass(git_diff_patch_to_str(&text, patch));
cl_git_pass(git_patch_to_str(&text, patch));
cl_assert_equal_s(expected, text);
git__free(text);
git_diff_patch_free(patch);
git_patch_free(patch);
cl_git_pass(git_diff_get_patch(NULL, &delta, diff, 1));
cl_git_pass(git_patch_from_diff(NULL, &delta, diff, 1));
cl_assert_equal_i(GIT_DELTA_UNMODIFIED, (int)delta->status);
cl_git_pass(git_diff_get_patch(NULL, &delta, diff, 2));
cl_git_pass(git_patch_from_diff(NULL, &delta, diff, 2));
cl_assert_equal_i(GIT_DELTA_MODIFIED, (int)delta->status);
cl_git_pass(git_diff_get_patch(NULL, &delta, diff, 3));
cl_git_pass(git_patch_from_diff(NULL, &delta, diff, 3));
cl_assert_equal_i(GIT_DELTA_MODIFIED, (int)delta->status);
git_diff_list_free(diff);
git_diff_free(diff);
git_tree_free(old_tree);
git_tree_free(new_tree);
}
......@@ -612,7 +612,7 @@ void test_diff_rename__file_exchange(void)
git_buf c1 = GIT_BUF_INIT, c2 = GIT_BUF_INIT;
git_index *index;
git_tree *tree;
git_diff_list *diff;
git_diff *diff;
git_diff_options diffopts = GIT_DIFF_OPTIONS_INIT;
git_diff_find_options opts = GIT_DIFF_FIND_OPTIONS_INIT;
diff_expects exp;
......@@ -647,7 +647,7 @@ void test_diff_rename__file_exchange(void)
cl_assert_equal_i(2, exp.files);
cl_assert_equal_i(2, exp.file_status[GIT_DELTA_RENAMED]);
git_diff_list_free(diff);
git_diff_free(diff);
git_tree_free(tree);
git_index_free(index);
......@@ -660,7 +660,7 @@ void test_diff_rename__file_exchange_three(void)
git_buf c1 = GIT_BUF_INIT, c2 = GIT_BUF_INIT, c3 = GIT_BUF_INIT;
git_index *index;
git_tree *tree;
git_diff_list *diff;
git_diff *diff;
git_diff_options diffopts = GIT_DIFF_OPTIONS_INIT;
git_diff_find_options opts = GIT_DIFF_FIND_OPTIONS_INIT;
diff_expects exp;
......@@ -699,7 +699,7 @@ void test_diff_rename__file_exchange_three(void)
cl_assert_equal_i(3, exp.files);
cl_assert_equal_i(3, exp.file_status[GIT_DELTA_RENAMED]);
git_diff_list_free(diff);
git_diff_free(diff);
git_tree_free(tree);
git_index_free(index);
......@@ -713,7 +713,7 @@ void test_diff_rename__file_partial_exchange(void)
git_buf c1 = GIT_BUF_INIT, c2 = GIT_BUF_INIT;
git_index *index;
git_tree *tree;
git_diff_list *diff;
git_diff *diff;
git_diff_options diffopts = GIT_DIFF_OPTIONS_INIT;
git_diff_find_options opts = GIT_DIFF_FIND_OPTIONS_INIT;
diff_expects exp;
......@@ -752,7 +752,7 @@ void test_diff_rename__file_partial_exchange(void)
cl_assert_equal_i(1, exp.file_status[GIT_DELTA_ADDED]);
cl_assert_equal_i(1, exp.file_status[GIT_DELTA_DELETED]);
git_diff_list_free(diff);
git_diff_free(diff);
git_tree_free(tree);
git_index_free(index);
......@@ -765,7 +765,7 @@ void test_diff_rename__rename_and_copy_from_same_source(void)
git_buf c1 = GIT_BUF_INIT, c2 = GIT_BUF_INIT;
git_index *index;
git_tree *tree;
git_diff_list *diff;
git_diff *diff;
git_diff_options diffopts = GIT_DIFF_OPTIONS_INIT;
git_diff_find_options opts = GIT_DIFF_FIND_OPTIONS_INIT;
diff_expects exp;
......@@ -809,7 +809,7 @@ void test_diff_rename__rename_and_copy_from_same_source(void)
cl_assert_equal_i(2, exp.file_status[GIT_DELTA_COPIED]);
cl_assert_equal_i(4, exp.file_status[GIT_DELTA_UNMODIFIED]);
git_diff_list_free(diff);
git_diff_free(diff);
git_tree_free(tree);
git_index_free(index);
......@@ -822,7 +822,7 @@ void test_diff_rename__from_deleted_to_split(void)
git_buf c1 = GIT_BUF_INIT;
git_index *index;
git_tree *tree;
git_diff_list *diff;
git_diff *diff;
git_diff_options diffopts = GIT_DIFF_OPTIONS_INIT;
git_diff_find_options opts = GIT_DIFF_FIND_OPTIONS_INIT;
diff_expects exp;
......@@ -863,7 +863,7 @@ void test_diff_rename__from_deleted_to_split(void)
cl_assert_equal_i(1, exp.file_status[GIT_DELTA_RENAMED]);
cl_assert_equal_i(2, exp.file_status[GIT_DELTA_UNMODIFIED]);
git_diff_list_free(diff);
git_diff_free(diff);
git_tree_free(tree);
git_index_free(index);
......@@ -907,7 +907,7 @@ void test_diff_rename__rejected_match_can_match_others(void)
git_index *index;
git_tree *tree;
git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
git_diff_list *diff;
git_diff *diff;
git_diff_options diffopts = GIT_DIFF_OPTIONS_INIT;
git_diff_find_options findopts = GIT_DIFF_FIND_OPTIONS_INIT;
git_buf one = GIT_BUF_INIT, two = GIT_BUF_INIT;
......@@ -961,7 +961,7 @@ void test_diff_rename__rejected_match_can_match_others(void)
cl_git_pass(
git_diff_foreach(diff, test_names_expected, NULL, NULL, &expect));
git_diff_list_free(diff);
git_diff_free(diff);
git_tree_free(tree);
git_index_free(index);
git_reference_free(head);
......@@ -993,7 +993,7 @@ void test_diff_rename__rejected_match_can_match_others_two(void)
git_index *index;
git_tree *tree;
git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
git_diff_list *diff;
git_diff *diff;
git_diff_options diffopts = GIT_DIFF_OPTIONS_INIT;
git_diff_find_options findopts = GIT_DIFF_FIND_OPTIONS_INIT;
unsigned int status[] = { GIT_DELTA_RENAMED, GIT_DELTA_RENAMED };
......@@ -1035,7 +1035,7 @@ void test_diff_rename__rejected_match_can_match_others_two(void)
git_diff_foreach(diff, test_names_expected, NULL, NULL, &expect));
cl_assert(expect.idx > 0);
git_diff_list_free(diff);
git_diff_free(diff);
git_tree_free(tree);
git_index_free(index);
git_reference_free(head);
......@@ -1048,7 +1048,7 @@ void test_diff_rename__rejected_match_can_match_others_three(void)
git_index *index;
git_tree *tree;
git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
git_diff_list *diff;
git_diff *diff;
git_diff_options diffopts = GIT_DIFF_OPTIONS_INIT;
git_diff_find_options findopts = GIT_DIFF_FIND_OPTIONS_INIT;
......@@ -1091,7 +1091,7 @@ void test_diff_rename__rejected_match_can_match_others_three(void)
cl_assert(expect.idx == expect.len);
git_diff_list_free(diff);
git_diff_free(diff);
git_tree_free(tree);
git_index_free(index);
git_reference_free(head);
......@@ -1102,7 +1102,7 @@ void test_diff_rename__can_rename_from_rewrite(void)
{
git_index *index;
git_tree *tree;
git_diff_list *diff;
git_diff *diff;
git_diff_options diffopts = GIT_DIFF_OPTIONS_INIT;
git_diff_find_options findopts = GIT_DIFF_FIND_OPTIONS_INIT;
......@@ -1140,7 +1140,7 @@ void test_diff_rename__can_rename_from_rewrite(void)
cl_assert(expect.idx == expect.len);
git_diff_list_free(diff);
git_diff_free(diff);
git_tree_free(tree);
git_index_free(index);
}
......@@ -1149,7 +1149,7 @@ void test_diff_rename__case_changes_are_split(void)
{
git_index *index;
git_tree *tree;
git_diff_list *diff = NULL;
git_diff *diff = NULL;
diff_expects exp;
git_diff_find_options opts = GIT_DIFF_FIND_OPTIONS_INIT;
......@@ -1182,7 +1182,7 @@ void test_diff_rename__case_changes_are_split(void)
cl_assert_equal_i(1, exp.files);
cl_assert_equal_i(1, exp.file_status[GIT_DELTA_RENAMED]);
git_diff_list_free(diff);
git_diff_free(diff);
git_index_free(index);
git_tree_free(tree);
}
......@@ -1191,7 +1191,7 @@ void test_diff_rename__unmodified_can_be_renamed(void)
{
git_index *index;
git_tree *tree;
git_diff_list *diff = NULL;
git_diff *diff = NULL;
diff_expects exp;
git_diff_options diffopts = GIT_DIFF_OPTIONS_INIT;
git_diff_find_options opts = GIT_DIFF_FIND_OPTIONS_INIT;
......@@ -1230,7 +1230,7 @@ void test_diff_rename__unmodified_can_be_renamed(void)
cl_assert_equal_i(1, exp.files);
cl_assert_equal_i(1, exp.file_status[GIT_DELTA_RENAMED]);
git_diff_list_free(diff);
git_diff_free(diff);
git_index_free(index);
git_tree_free(tree);
}
......@@ -1238,7 +1238,7 @@ void test_diff_rename__unmodified_can_be_renamed(void)
void test_diff_rename__rewrite_on_single_file(void)
{
git_index *index;
git_diff_list *diff = NULL;
git_diff *diff = NULL;
diff_expects exp;
git_diff_options diffopts = GIT_DIFF_OPTIONS_INIT;
git_diff_find_options findopts = GIT_DIFF_FIND_OPTIONS_INIT;
......@@ -1280,6 +1280,6 @@ void test_diff_rename__rewrite_on_single_file(void)
cl_assert_equal_i(1, exp.file_status[GIT_DELTA_DELETED]);
cl_assert_equal_i(1, exp.file_status[GIT_DELTA_UNTRACKED]);
git_diff_list_free(diff);
git_diff_free(diff);
git_index_free(index);
}
......@@ -14,15 +14,15 @@ void test_diff_submodules__cleanup(void)
}
static void check_diff_patches_at_line(
git_diff_list *diff, const char **expected, const char *file, int line)
git_diff *diff, const char **expected, const char *file, int line)
{
const git_diff_delta *delta;
git_diff_patch *patch = NULL;
git_patch *patch = NULL;
size_t d, num_d = git_diff_num_deltas(diff);
char *patch_text;
for (d = 0; d < num_d; ++d, git_diff_patch_free(patch)) {
cl_git_pass(git_diff_get_patch(&patch, &delta, diff, d));
for (d = 0; d < num_d; ++d, git_patch_free(patch)) {
cl_git_pass(git_patch_from_diff(&patch, &delta, diff, d));
if (delta->status == GIT_DELTA_UNMODIFIED) {
cl_assert_at_line(expected[d] == NULL, file, line);
......@@ -32,11 +32,11 @@ static void check_diff_patches_at_line(
if (expected[d] && !strcmp(expected[d], "<SKIP>"))
continue;
if (expected[d] && !strcmp(expected[d], "<END>")) {
cl_git_pass(git_diff_patch_to_str(&patch_text, patch));
cl_git_pass(git_patch_to_str(&patch_text, patch));
cl_assert_at_line(!strcmp(expected[d], "<END>"), file, line);
}
cl_git_pass(git_diff_patch_to_str(&patch_text, patch));
cl_git_pass(git_patch_to_str(&patch_text, patch));
clar__assert_equal(
file, line, "expected diff did not match actual diff", 1,
......@@ -53,7 +53,7 @@ static void check_diff_patches_at_line(
void test_diff_submodules__unmodified_submodule(void)
{
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
git_diff_list *diff = NULL;
git_diff *diff = NULL;
static const char *expected[] = {
"<SKIP>", /* .gitmodules */
NULL, /* added */
......@@ -74,13 +74,13 @@ void test_diff_submodules__unmodified_submodule(void)
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
check_diff_patches(diff, expected);
git_diff_list_free(diff);
git_diff_free(diff);
}
void test_diff_submodules__dirty_submodule(void)
{
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
git_diff_list *diff = NULL;
git_diff *diff = NULL;
static const char *expected[] = {
"<SKIP>", /* .gitmodules */
NULL, /* added */
......@@ -104,13 +104,13 @@ void test_diff_submodules__dirty_submodule(void)
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
check_diff_patches(diff, expected);
git_diff_list_free(diff);
git_diff_free(diff);
}
void test_diff_submodules__dirty_submodule_2(void)
{
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
git_diff_list *diff = NULL, *diff2 = NULL;
git_diff *diff = NULL, *diff2 = NULL;
char *smpath = "testrepo";
static const char *expected_none[] = { "<END>" };
static const char *expected_dirty[] = {
......@@ -132,7 +132,7 @@ void test_diff_submodules__dirty_submodule_2(void)
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
check_diff_patches(diff, expected_none);
git_diff_list_free(diff);
git_diff_free(diff);
cl_git_rewritefile("submodules/testrepo/README", "heyheyhey");
cl_git_mkfile("submodules/testrepo/all_new.txt", "never seen before");
......@@ -146,25 +146,25 @@ void test_diff_submodules__dirty_submodule_2(void)
cl_git_pass(git_repository_head_tree(&head, g_repo));
cl_git_pass(git_diff_tree_to_index(&diff2, g_repo, head, NULL, &opts));
cl_git_pass(git_diff_merge(diff, diff2));
git_diff_list_free(diff2);
git_diff_free(diff2);
git_tree_free(head);
check_diff_patches(diff, expected_dirty);
}
git_diff_list_free(diff);
git_diff_free(diff);
cl_git_pass(git_submodule_reload_all(g_repo));
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
check_diff_patches(diff, expected_dirty);
git_diff_list_free(diff);
git_diff_free(diff);
}
void test_diff_submodules__submod2_index_to_wd(void)
{
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
git_diff_list *diff = NULL;
git_diff *diff = NULL;
static const char *expected[] = {
"<SKIP>", /* .gitmodules */
"diff --git a/sm_changed_file b/sm_changed_file\nindex 4800958..4800958 160000\n--- a/sm_changed_file\n+++ b/sm_changed_file\n@@ -1 +1 @@\n-Subproject commit 480095882d281ed676fe5b863569520e54a7d5c0\n+Subproject commit 480095882d281ed676fe5b863569520e54a7d5c0-dirty\n", /* sm_changed_file */
......@@ -182,14 +182,14 @@ void test_diff_submodules__submod2_index_to_wd(void)
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
check_diff_patches(diff, expected);
git_diff_list_free(diff);
git_diff_free(diff);
}
void test_diff_submodules__submod2_head_to_index(void)
{
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
git_tree *head;
git_diff_list *diff = NULL;
git_diff *diff = NULL;
static const char *expected[] = {
"<SKIP>", /* .gitmodules */
"diff --git a/sm_added_and_uncommited b/sm_added_and_uncommited\nnew file mode 160000\nindex 0000000..4800958\n--- /dev/null\n+++ b/sm_added_and_uncommited\n@@ -0,0 +1 @@\n+Subproject commit 480095882d281ed676fe5b863569520e54a7d5c0\n", /* sm_added_and_uncommited */
......@@ -205,7 +205,7 @@ void test_diff_submodules__submod2_head_to_index(void)
cl_git_pass(git_diff_tree_to_index(&diff, g_repo, head, NULL, &opts));
check_diff_patches(diff, expected);
git_diff_list_free(diff);
git_diff_free(diff);
git_tree_free(head);
}
......@@ -213,7 +213,7 @@ void test_diff_submodules__submod2_head_to_index(void)
void test_diff_submodules__invalid_cache(void)
{
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
git_diff_list *diff = NULL;
git_diff *diff = NULL;
git_submodule *sm;
char *smpath = "sm_changed_head";
git_repository *smrepo;
......@@ -246,7 +246,7 @@ void test_diff_submodules__invalid_cache(void)
/* baseline */
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
check_diff_patches(diff, expected_baseline);
git_diff_list_free(diff);
git_diff_free(diff);
/* update index with new HEAD */
cl_git_pass(git_submodule_lookup(&sm, g_repo, smpath));
......@@ -254,7 +254,7 @@ void test_diff_submodules__invalid_cache(void)
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
check_diff_patches(diff, expected_unchanged);
git_diff_list_free(diff);
git_diff_free(diff);
/* create untracked file in submodule working directory */
cl_git_mkfile("submod2/sm_changed_head/new_around_here", "hello");
......@@ -262,13 +262,13 @@ void test_diff_submodules__invalid_cache(void)
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
check_diff_patches(diff, expected_dirty);
git_diff_list_free(diff);
git_diff_free(diff);
git_submodule_set_ignore(sm, GIT_SUBMODULE_IGNORE_UNTRACKED);
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
check_diff_patches(diff, expected_unchanged);
git_diff_list_free(diff);
git_diff_free(diff);
/* modify tracked file in submodule working directory */
cl_git_append2file(
......@@ -276,20 +276,20 @@ void test_diff_submodules__invalid_cache(void)
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
check_diff_patches(diff, expected_dirty);
git_diff_list_free(diff);
git_diff_free(diff);
cl_git_pass(git_submodule_reload_all(g_repo));
cl_git_pass(git_submodule_lookup(&sm, g_repo, smpath));
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
check_diff_patches(diff, expected_dirty);
git_diff_list_free(diff);
git_diff_free(diff);
git_submodule_set_ignore(sm, GIT_SUBMODULE_IGNORE_DIRTY);
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
check_diff_patches(diff, expected_unchanged);
git_diff_list_free(diff);
git_diff_free(diff);
/* add file to index in submodule */
cl_git_pass(git_submodule_open(&smrepo, sm));
......@@ -300,13 +300,13 @@ void test_diff_submodules__invalid_cache(void)
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
check_diff_patches(diff, expected_dirty);
git_diff_list_free(diff);
git_diff_free(diff);
git_submodule_set_ignore(sm, GIT_SUBMODULE_IGNORE_DIRTY);
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
check_diff_patches(diff, expected_unchanged);
git_diff_list_free(diff);
git_diff_free(diff);
/* commit changed index of submodule */
cl_repo_commit_from_index(NULL, smrepo, NULL, 1372350000, "Move it");
......@@ -315,25 +315,25 @@ void test_diff_submodules__invalid_cache(void)
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
check_diff_patches(diff, expected_moved);
git_diff_list_free(diff);
git_diff_free(diff);
git_submodule_set_ignore(sm, GIT_SUBMODULE_IGNORE_ALL);
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
check_diff_patches(diff, expected_unchanged);
git_diff_list_free(diff);
git_diff_free(diff);
git_submodule_set_ignore(sm, GIT_SUBMODULE_IGNORE_NONE);
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
check_diff_patches(diff, expected_moved_dirty);
git_diff_list_free(diff);
git_diff_free(diff);
p_unlink("submod2/sm_changed_head/new_around_here");
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
check_diff_patches(diff, expected_moved);
git_diff_list_free(diff);
git_diff_free(diff);
git_index_free(smindex);
git_repository_free(smrepo);
......@@ -342,7 +342,7 @@ void test_diff_submodules__invalid_cache(void)
void test_diff_submodules__diff_ignore_options(void)
{
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
git_diff_list *diff = NULL;
git_diff *diff = NULL;
git_config *cfg;
static const char *expected_normal[] = {
"<SKIP>", /* .gitmodules */
......@@ -371,26 +371,26 @@ void test_diff_submodules__diff_ignore_options(void)
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
check_diff_patches(diff, expected_normal);
git_diff_list_free(diff);
git_diff_free(diff);
opts.flags |= GIT_DIFF_IGNORE_SUBMODULES;
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
check_diff_patches(diff, expected_ignore_all);
git_diff_list_free(diff);
git_diff_free(diff);
opts.flags &= ~GIT_DIFF_IGNORE_SUBMODULES;
opts.ignore_submodules = GIT_SUBMODULE_IGNORE_ALL;
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
check_diff_patches(diff, expected_ignore_all);
git_diff_list_free(diff);
git_diff_free(diff);
opts.ignore_submodules = GIT_SUBMODULE_IGNORE_DIRTY;
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
check_diff_patches(diff, expected_ignore_dirty);
git_diff_list_free(diff);
git_diff_free(diff);
opts.ignore_submodules = 0;
cl_git_pass(git_repository_config(&cfg, g_repo));
......@@ -398,25 +398,25 @@ void test_diff_submodules__diff_ignore_options(void)
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
check_diff_patches(diff, expected_normal);
git_diff_list_free(diff);
git_diff_free(diff);
cl_git_pass(git_config_set_bool(cfg, "diff.ignoreSubmodules", true));
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
check_diff_patches(diff, expected_ignore_all);
git_diff_list_free(diff);
git_diff_free(diff);
cl_git_pass(git_config_set_string(cfg, "diff.ignoreSubmodules", "none"));
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
check_diff_patches(diff, expected_normal);
git_diff_list_free(diff);
git_diff_free(diff);
cl_git_pass(git_config_set_string(cfg, "diff.ignoreSubmodules", "dirty"));
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
check_diff_patches(diff, expected_ignore_dirty);
git_diff_list_free(diff);
git_diff_free(diff);
git_config_free(cfg);
}
......@@ -3,7 +3,7 @@
static git_repository *g_repo = NULL;
static git_diff_options opts;
static git_diff_list *diff;
static git_diff *diff;
static git_tree *a, *b;
static diff_expects expect;
......@@ -22,7 +22,7 @@ void test_diff_tree__initialize(void)
void test_diff_tree__cleanup(void)
{
git_diff_list_free(diff);
git_diff_free(diff);
git_tree_free(a);
git_tree_free(b);
......@@ -65,7 +65,7 @@ void test_diff_tree__0(void)
cl_assert_equal_i(24 + 1 + 5 + 5, expect.line_adds);
cl_assert_equal_i(7 + 1, expect.line_dels);
git_diff_list_free(diff);
git_diff_free(diff);
diff = NULL;
memset(&expect, 0, sizeof(expect));
......@@ -168,7 +168,7 @@ void test_diff_tree__options(void)
cl_assert_equal_i(actual.line_adds, expected->line_adds);
cl_assert_equal_i(actual.line_dels, expected->line_dels);
git_diff_list_free(diff);
git_diff_free(diff);
diff = NULL;
}
......@@ -214,7 +214,7 @@ void test_diff_tree__merge(void)
const char *b_commit = "370fe9ec22";
const char *c_commit = "f5b0af1fb4f5c";
git_tree *c;
git_diff_list *diff1 = NULL, *diff2 = NULL;
git_diff *diff1 = NULL, *diff2 = NULL;
g_repo = cl_git_sandbox_init("attr");
......@@ -230,7 +230,7 @@ void test_diff_tree__merge(void)
cl_git_pass(git_diff_merge(diff1, diff2));
git_diff_list_free(diff2);
git_diff_free(diff2);
cl_git_pass(git_diff_foreach(
diff1, diff_file_cb, diff_hunk_cb, diff_line_cb, &expect));
......@@ -247,7 +247,7 @@ void test_diff_tree__merge(void)
cl_assert_equal_i(36, expect.line_adds);
cl_assert_equal_i(22, expect.line_dels);
git_diff_list_free(diff1);
git_diff_free(diff1);
}
void test_diff_tree__larger_hunks(void)
......@@ -256,8 +256,8 @@ void test_diff_tree__larger_hunks(void)
const char *b_commit = "7a9e0b02e63179929fed24f0a3e0f19168114d10";
size_t d, num_d, h, num_h, l, num_l, header_len, line_len;
const git_diff_delta *delta;
git_diff_patch *patch;
const git_diff_range *range;
git_patch *patch;
const git_diff_hunk *range;
const char *header, *line;
char origin;
......@@ -273,31 +273,31 @@ void test_diff_tree__larger_hunks(void)
num_d = git_diff_num_deltas(diff);
for (d = 0; d < num_d; ++d) {
cl_git_pass(git_diff_get_patch(&patch, &delta, diff, d));
cl_git_pass(git_patch_from_diff(&patch, &delta, diff, d));
cl_assert(patch && delta);
num_h = git_diff_patch_num_hunks(patch);
num_h = git_patch_num_hunks(patch);
for (h = 0; h < num_h; h++) {
cl_git_pass(git_diff_patch_get_hunk(
cl_git_pass(git_patch_get_hunk(
&range, &header, &header_len, &num_l, patch, h));
for (l = 0; l < num_l; ++l) {
cl_git_pass(git_diff_patch_get_line_in_hunk(
cl_git_pass(git_patch_get_line_in_hunk(
&origin, &line, &line_len, NULL, NULL, patch, h, l));
cl_assert(line);
}
cl_git_fail(git_diff_patch_get_line_in_hunk(
cl_git_fail(git_patch_get_line_in_hunk(
&origin, &line, &line_len, NULL, NULL, patch, h, num_l));
}
cl_git_fail(git_diff_patch_get_hunk(
cl_git_fail(git_patch_get_hunk(
&range, &header, &header_len, &num_l, patch, num_h));
git_diff_patch_free(patch);
git_patch_free(patch);
}
cl_git_fail(git_diff_get_patch(&patch, &delta, diff, num_d));
cl_git_fail(git_patch_from_diff(&patch, &delta, diff, num_d));
cl_assert_equal_i(2, (int)num_d);
}
......@@ -487,7 +487,7 @@ void test_diff_tree__diff_configs(void)
cl_assert_equal_i(7, expect.line_adds);
cl_assert_equal_i(15, expect.line_dels);
git_diff_list_free(diff);
git_diff_free(diff);
diff = NULL;
set_config_int(g_repo, "diff.context", 1);
......@@ -507,7 +507,7 @@ void test_diff_tree__diff_configs(void)
cl_assert_equal_i(7, expect.line_adds);
cl_assert_equal_i(15, expect.line_dels);
git_diff_list_free(diff);
git_diff_free(diff);
diff = NULL;
set_config_int(g_repo, "diff.context", 0);
......
......@@ -16,7 +16,7 @@ void test_diff_workdir__cleanup(void)
void test_diff_workdir__to_index(void)
{
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
git_diff_list *diff = NULL;
git_diff *diff = NULL;
diff_expects exp;
int use_iterator;
......@@ -60,7 +60,7 @@ void test_diff_workdir__to_index(void)
cl_assert_equal_i(5, exp.line_dels);
}
git_diff_list_free(diff);
git_diff_free(diff);
}
void test_diff_workdir__to_tree(void)
......@@ -70,8 +70,8 @@ void test_diff_workdir__to_tree(void)
const char *b_commit = "0017bd4ab1ec3"; /* the start */
git_tree *a, *b;
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
git_diff_list *diff = NULL;
git_diff_list *diff2 = NULL;
git_diff *diff = NULL;
git_diff *diff2 = NULL;
diff_expects exp;
int use_iterator;
......@@ -119,7 +119,7 @@ void test_diff_workdir__to_tree(void)
* do more apples-to-apples test comparison below.
*/
git_diff_list_free(diff);
git_diff_free(diff);
diff = NULL;
memset(&exp, 0, sizeof(exp));
......@@ -130,7 +130,7 @@ void test_diff_workdir__to_tree(void)
cl_git_pass(git_diff_tree_to_index(&diff, g_repo, a, NULL, &opts));
cl_git_pass(git_diff_index_to_workdir(&diff2, g_repo, NULL, &opts));
cl_git_pass(git_diff_merge(diff, diff2));
git_diff_list_free(diff2);
git_diff_free(diff2);
for (use_iterator = 0; use_iterator <= 1; use_iterator++) {
memset(&exp, 0, sizeof(exp));
......@@ -157,7 +157,7 @@ void test_diff_workdir__to_tree(void)
cl_assert_equal_i(5, exp.line_dels);
}
git_diff_list_free(diff);
git_diff_free(diff);
diff = NULL;
memset(&exp, 0, sizeof(exp));
......@@ -167,7 +167,7 @@ void test_diff_workdir__to_tree(void)
cl_git_pass(git_diff_tree_to_index(&diff, g_repo, b, NULL, &opts));
cl_git_pass(git_diff_index_to_workdir(&diff2, g_repo, NULL, &opts));
cl_git_pass(git_diff_merge(diff, diff2));
git_diff_list_free(diff2);
git_diff_free(diff2);
for (use_iterator = 0; use_iterator <= 1; use_iterator++) {
memset(&exp, 0, sizeof(exp));
......@@ -194,7 +194,7 @@ void test_diff_workdir__to_tree(void)
cl_assert_equal_i(4, exp.line_dels);
}
git_diff_list_free(diff);
git_diff_free(diff);
git_tree_free(a);
git_tree_free(b);
......@@ -203,7 +203,7 @@ void test_diff_workdir__to_tree(void)
void test_diff_workdir__to_index_with_pathspec(void)
{
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
git_diff_list *diff = NULL;
git_diff *diff = NULL;
diff_expects exp;
char *pathspec = NULL;
int use_iterator;
......@@ -235,7 +235,7 @@ void test_diff_workdir__to_index_with_pathspec(void)
cl_assert_equal_i(4, exp.file_status[GIT_DELTA_UNTRACKED]);
}
git_diff_list_free(diff);
git_diff_free(diff);
pathspec = "modified_file";
......@@ -258,7 +258,7 @@ void test_diff_workdir__to_index_with_pathspec(void)
cl_assert_equal_i(0, exp.file_status[GIT_DELTA_UNTRACKED]);
}
git_diff_list_free(diff);
git_diff_free(diff);
pathspec = "subdir";
......@@ -281,7 +281,7 @@ void test_diff_workdir__to_index_with_pathspec(void)
cl_assert_equal_i(1, exp.file_status[GIT_DELTA_UNTRACKED]);
}
git_diff_list_free(diff);
git_diff_free(diff);
pathspec = "*_deleted";
......@@ -304,12 +304,12 @@ void test_diff_workdir__to_index_with_pathspec(void)
cl_assert_equal_i(0, exp.file_status[GIT_DELTA_UNTRACKED]);
}
git_diff_list_free(diff);
git_diff_free(diff);
}
void test_diff_workdir__filemode_changes(void)
{
git_diff_list *diff = NULL;
git_diff *diff = NULL;
diff_expects exp;
int use_iterator;
......@@ -339,7 +339,7 @@ void test_diff_workdir__filemode_changes(void)
cl_assert_equal_i(0, exp.hunks);
}
git_diff_list_free(diff);
git_diff_free(diff);
/* chmod file and test again */
......@@ -362,14 +362,14 @@ void test_diff_workdir__filemode_changes(void)
cl_assert_equal_i(0, exp.hunks);
}
git_diff_list_free(diff);
git_diff_free(diff);
cl_assert(cl_toggle_filemode("issue_592/a.txt"));
}
void test_diff_workdir__filemode_changes_with_filemode_false(void)
{
git_diff_list *diff = NULL;
git_diff *diff = NULL;
diff_expects exp;
if (!cl_is_chmod_supported())
......@@ -391,7 +391,7 @@ void test_diff_workdir__filemode_changes_with_filemode_false(void)
cl_assert_equal_i(0, exp.file_status[GIT_DELTA_MODIFIED]);
cl_assert_equal_i(0, exp.hunks);
git_diff_list_free(diff);
git_diff_free(diff);
/* chmod file and test again */
......@@ -407,7 +407,7 @@ void test_diff_workdir__filemode_changes_with_filemode_false(void)
cl_assert_equal_i(0, exp.file_status[GIT_DELTA_MODIFIED]);
cl_assert_equal_i(0, exp.hunks);
git_diff_list_free(diff);
git_diff_free(diff);
cl_assert(cl_toggle_filemode("issue_592/a.txt"));
}
......@@ -415,7 +415,7 @@ void test_diff_workdir__filemode_changes_with_filemode_false(void)
void test_diff_workdir__head_index_and_workdir_all_differ(void)
{
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
git_diff_list *diff_i2t = NULL, *diff_w2i = NULL;
git_diff *diff_i2t = NULL, *diff_w2i = NULL;
diff_expects exp;
char *pathspec = "staged_changes_modified_file";
git_tree *tree;
......@@ -504,8 +504,8 @@ void test_diff_workdir__head_index_and_workdir_all_differ(void)
cl_assert_equal_i(0, exp.line_dels);
}
git_diff_list_free(diff_i2t);
git_diff_list_free(diff_w2i);
git_diff_free(diff_i2t);
git_diff_free(diff_w2i);
git_tree_free(tree);
}
......@@ -513,7 +513,7 @@ void test_diff_workdir__head_index_and_workdir_all_differ(void)
void test_diff_workdir__eof_newline_changes(void)
{
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
git_diff_list *diff = NULL;
git_diff *diff = NULL;
diff_expects exp;
char *pathspec = "current_file";
int use_iterator;
......@@ -546,7 +546,7 @@ void test_diff_workdir__eof_newline_changes(void)
cl_assert_equal_i(0, exp.line_dels);
}
git_diff_list_free(diff);
git_diff_free(diff);
cl_git_append2file("status/current_file", "\n");
......@@ -573,7 +573,7 @@ void test_diff_workdir__eof_newline_changes(void)
cl_assert_equal_i(0, exp.line_dels);
}
git_diff_list_free(diff);
git_diff_free(diff);
cl_git_rewritefile("status/current_file", "current_file");
......@@ -600,7 +600,7 @@ void test_diff_workdir__eof_newline_changes(void)
cl_assert_equal_i(2, exp.line_dels);
}
git_diff_list_free(diff);
git_diff_free(diff);
}
/* PREPARATION OF TEST DATA
......@@ -684,9 +684,9 @@ void test_diff_workdir__larger_hunks(void)
opts.interhunk_lines = 0;
for (i = 0; i <= 2; ++i) {
git_diff_list *diff = NULL;
git_diff_patch *patch;
const git_diff_range *range;
git_diff *diff = NULL;
git_patch *patch;
const git_diff_hunk *range;
const char *header, *line;
char origin;
......@@ -707,33 +707,33 @@ void test_diff_workdir__larger_hunks(void)
cl_assert_equal_i(2, (int)num_d);
for (d = 0; d < num_d; ++d) {
cl_git_pass(git_diff_get_patch(&patch, NULL, diff, d));
cl_git_pass(git_patch_from_diff(&patch, NULL, diff, d));
cl_assert(patch);
num_h = git_diff_patch_num_hunks(patch);
num_h = git_patch_num_hunks(patch);
for (h = 0; h < num_h; h++) {
cl_git_pass(git_diff_patch_get_hunk(
cl_git_pass(git_patch_get_hunk(
&range, &header, &header_len, &num_l, patch, h));
for (l = 0; l < num_l; ++l) {
cl_git_pass(git_diff_patch_get_line_in_hunk(
cl_git_pass(git_patch_get_line_in_hunk(
&origin, &line, &line_len, NULL, NULL, patch, h, l));
cl_assert(line);
}
/* confirm fail after the last item */
cl_git_fail(git_diff_patch_get_line_in_hunk(
cl_git_fail(git_patch_get_line_in_hunk(
&origin, &line, &line_len, NULL, NULL, patch, h, num_l));
}
/* confirm fail after the last item */
cl_git_fail(git_diff_patch_get_hunk(
cl_git_fail(git_patch_get_hunk(
&range, &header, &header_len, &num_l, patch, num_h));
git_diff_patch_free(patch);
git_patch_free(patch);
}
git_diff_list_free(diff);
git_diff_free(diff);
}
git_tree_free(a);
......@@ -758,7 +758,7 @@ void test_diff_workdir__submodules(void)
const char *a_commit = "873585b94bdeabccea991ea5e3ec1a277895b698";
git_tree *a;
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
git_diff_list *diff = NULL;
git_diff *diff = NULL;
diff_expects exp;
g_repo = setup_fixture_submod2();
......@@ -819,14 +819,14 @@ void test_diff_workdir__submodules(void)
cl_assert_equal_i(30, exp.line_adds);
cl_assert_equal_i(1, exp.line_dels);
git_diff_list_free(diff);
git_diff_free(diff);
git_tree_free(a);
}
void test_diff_workdir__cannot_diff_against_a_bare_repository(void)
{
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
git_diff_list *diff = NULL;
git_diff *diff = NULL;
git_tree *tree;
g_repo = cl_git_sandbox_init("testrepo.git");
......@@ -844,7 +844,7 @@ void test_diff_workdir__cannot_diff_against_a_bare_repository(void)
void test_diff_workdir__to_null_tree(void)
{
git_diff_list *diff;
git_diff *diff;
diff_expects exp;
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
......@@ -862,12 +862,12 @@ void test_diff_workdir__to_null_tree(void)
cl_assert_equal_i(exp.files, exp.file_status[GIT_DELTA_UNTRACKED]);
git_diff_list_free(diff);
git_diff_free(diff);
}
void test_diff_workdir__checks_options_version(void)
{
git_diff_list *diff;
git_diff *diff;
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
const git_error *err;
......@@ -887,11 +887,11 @@ void test_diff_workdir__checks_options_version(void)
void test_diff_workdir__can_diff_empty_file(void)
{
git_diff_list *diff;
git_diff *diff;
git_tree *tree;
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
struct stat st;
git_diff_patch *patch;
git_patch *patch;
g_repo = cl_git_sandbox_init("attr_index");
......@@ -901,7 +901,7 @@ void test_diff_workdir__can_diff_empty_file(void)
cl_git_pass(git_diff_tree_to_workdir(&diff, g_repo, tree, &opts));
cl_assert_equal_i(2, (int)git_diff_num_deltas(diff));
git_diff_list_free(diff);
git_diff_free(diff);
/* empty contents of file */
......@@ -912,9 +912,9 @@ void test_diff_workdir__can_diff_empty_file(void)
cl_git_pass(git_diff_tree_to_workdir(&diff, g_repo, tree, &opts));
cl_assert_equal_i(3, (int)git_diff_num_deltas(diff));
/* diffs are: .gitattributes, README.txt, sub/sub/.gitattributes */
cl_git_pass(git_diff_get_patch(&patch, NULL, diff, 1));
git_diff_patch_free(patch);
git_diff_list_free(diff);
cl_git_pass(git_patch_from_diff(&patch, NULL, diff, 1));
git_patch_free(patch);
git_diff_free(diff);
/* remove a file altogether */
......@@ -923,9 +923,9 @@ void test_diff_workdir__can_diff_empty_file(void)
cl_git_pass(git_diff_tree_to_workdir(&diff, g_repo, tree, &opts));
cl_assert_equal_i(3, (int)git_diff_num_deltas(diff));
cl_git_pass(git_diff_get_patch(&patch, NULL, diff, 1));
git_diff_patch_free(patch);
git_diff_list_free(diff);
cl_git_pass(git_patch_from_diff(&patch, NULL, diff, 1));
git_patch_free(patch);
git_diff_free(diff);
git_tree_free(tree);
}
......@@ -933,7 +933,7 @@ void test_diff_workdir__can_diff_empty_file(void)
void test_diff_workdir__to_index_issue_1397(void)
{
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
git_diff_list *diff = NULL;
git_diff *diff = NULL;
diff_expects exp;
g_repo = cl_git_sandbox_init("issue_1397");
......@@ -953,7 +953,7 @@ void test_diff_workdir__to_index_issue_1397(void)
cl_assert_equal_i(0, exp.hunks);
cl_assert_equal_i(0, exp.lines);
git_diff_list_free(diff);
git_diff_free(diff);
diff = NULL;
cl_git_rewritefile("issue_1397/crlf_file.txt",
......@@ -975,7 +975,7 @@ void test_diff_workdir__to_index_issue_1397(void)
cl_assert_equal_i(1, exp.line_adds);
cl_assert_equal_i(1, exp.line_dels);
git_diff_list_free(diff);
git_diff_free(diff);
}
void test_diff_workdir__to_tree_issue_1397(void)
......@@ -983,8 +983,8 @@ void test_diff_workdir__to_tree_issue_1397(void)
const char *a_commit = "7f483a738"; /* the current HEAD */
git_tree *a;
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
git_diff_list *diff = NULL;
git_diff_list *diff2 = NULL;
git_diff *diff = NULL;
git_diff *diff2 = NULL;
diff_expects exp;
g_repo = cl_git_sandbox_init("issue_1397");
......@@ -1006,13 +1006,13 @@ void test_diff_workdir__to_tree_issue_1397(void)
cl_assert_equal_i(0, exp.hunks);
cl_assert_equal_i(0, exp.lines);
git_diff_list_free(diff);
git_diff_free(diff);
diff = NULL;
cl_git_pass(git_diff_tree_to_index(&diff, g_repo, a, NULL, &opts));
cl_git_pass(git_diff_index_to_workdir(&diff2, g_repo, NULL, &opts));
cl_git_pass(git_diff_merge(diff, diff2));
git_diff_list_free(diff2);
git_diff_free(diff2);
memset(&exp, 0, sizeof(exp));
cl_git_pass(git_diff_foreach(
......@@ -1022,14 +1022,14 @@ void test_diff_workdir__to_tree_issue_1397(void)
cl_assert_equal_i(0, exp.hunks);
cl_assert_equal_i(0, exp.lines);
git_diff_list_free(diff);
git_diff_free(diff);
git_tree_free(a);
}
void test_diff_workdir__untracked_directory_scenarios(void)
{
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
git_diff_list *diff = NULL;
git_diff *diff = NULL;
diff_expects exp;
char *pathspec = NULL;
static const char *files0[] = {
......@@ -1079,7 +1079,7 @@ void test_diff_workdir__untracked_directory_scenarios(void)
cl_assert_equal_i(0, exp.file_status[GIT_DELTA_IGNORED]);
cl_assert_equal_i(1, exp.file_status[GIT_DELTA_UNTRACKED]);
git_diff_list_free(diff);
git_diff_free(diff);
/* empty directory */
......@@ -1099,7 +1099,7 @@ void test_diff_workdir__untracked_directory_scenarios(void)
cl_assert_equal_i(1, exp.file_status[GIT_DELTA_IGNORED]);
cl_assert_equal_i(1, exp.file_status[GIT_DELTA_UNTRACKED]);
git_diff_list_free(diff);
git_diff_free(diff);
/* empty directory in empty directory */
......@@ -1119,7 +1119,7 @@ void test_diff_workdir__untracked_directory_scenarios(void)
cl_assert_equal_i(1, exp.file_status[GIT_DELTA_IGNORED]);
cl_assert_equal_i(1, exp.file_status[GIT_DELTA_UNTRACKED]);
git_diff_list_free(diff);
git_diff_free(diff);
/* directory with only ignored files */
......@@ -1143,7 +1143,7 @@ void test_diff_workdir__untracked_directory_scenarios(void)
cl_assert_equal_i(1, exp.file_status[GIT_DELTA_IGNORED]);
cl_assert_equal_i(1, exp.file_status[GIT_DELTA_UNTRACKED]);
git_diff_list_free(diff);
git_diff_free(diff);
/* directory with ignored directory (contents irrelevant) */
......@@ -1166,7 +1166,7 @@ void test_diff_workdir__untracked_directory_scenarios(void)
cl_assert_equal_i(1, exp.file_status[GIT_DELTA_IGNORED]);
cl_assert_equal_i(1, exp.file_status[GIT_DELTA_UNTRACKED]);
git_diff_list_free(diff);
git_diff_free(diff);
/* quick version avoids directory scan */
......@@ -1186,7 +1186,7 @@ void test_diff_workdir__untracked_directory_scenarios(void)
cl_assert_equal_i(0, exp.file_status[GIT_DELTA_IGNORED]);
cl_assert_equal_i(2, exp.file_status[GIT_DELTA_UNTRACKED]);
git_diff_list_free(diff);
git_diff_free(diff);
/* directory with nested non-ignored content */
......@@ -1209,7 +1209,7 @@ void test_diff_workdir__untracked_directory_scenarios(void)
cl_assert_equal_i(0, exp.file_status[GIT_DELTA_IGNORED]);
cl_assert_equal_i(2, exp.file_status[GIT_DELTA_UNTRACKED]);
git_diff_list_free(diff);
git_diff_free(diff);
/* use RECURSE_UNTRACKED_DIRS to get actual untracked files (no ignores) */
......@@ -1230,14 +1230,14 @@ void test_diff_workdir__untracked_directory_scenarios(void)
cl_assert_equal_i(0, exp.file_status[GIT_DELTA_IGNORED]);
cl_assert_equal_i(2, exp.file_status[GIT_DELTA_UNTRACKED]);
git_diff_list_free(diff);
git_diff_free(diff);
}
void test_diff_workdir__untracked_directory_comes_last(void)
{
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
git_diff_list *diff = NULL;
git_diff *diff = NULL;
g_repo = cl_git_sandbox_init("renames");
......@@ -1255,13 +1255,13 @@ void test_diff_workdir__untracked_directory_comes_last(void)
cl_assert(diff != NULL);
git_diff_list_free(diff);
git_diff_free(diff);
}
void test_diff_workdir__untracked_with_bom(void)
{
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
git_diff_list *diff = NULL;
git_diff *diff = NULL;
const git_diff_delta *delta;
g_repo = cl_git_sandbox_init("empty_standard_repo");
......@@ -1276,9 +1276,9 @@ void test_diff_workdir__untracked_with_bom(void)
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
cl_assert_equal_i(1, git_diff_num_deltas(diff));
cl_git_pass(git_diff_get_patch(NULL, &delta, diff, 0));
cl_git_pass(git_patch_from_diff(NULL, &delta, diff, 0));
cl_assert_equal_i(GIT_DELTA_UNTRACKED, delta->status);
cl_assert((delta->flags & GIT_DIFF_FLAG_BINARY) != 0);
git_diff_list_free(diff);
git_diff_free(diff);
}
......@@ -19,7 +19,7 @@ static void test_with_many(int expected_new)
{
git_index *index;
git_tree *tree, *new_tree;
git_diff_list *diff = NULL;
git_diff *diff = NULL;
diff_expects exp;
git_diff_options diffopts = GIT_DIFF_OPTIONS_INIT;
git_diff_find_options opts = GIT_DIFF_FIND_OPTIONS_INIT;
......@@ -52,7 +52,7 @@ static void test_with_many(int expected_new)
cl_assert_equal_i(expected_new, exp.file_status[GIT_DELTA_ADDED]);
cl_assert_equal_i(expected_new + 1, exp.files);
git_diff_list_free(diff);
git_diff_free(diff);
cl_repo_commit_from_index(NULL, g_repo, NULL, 1372350000, "yoyoyo");
cl_git_pass(git_revparse_single(
......@@ -78,7 +78,7 @@ static void test_with_many(int expected_new)
cl_assert_equal_i(expected_new, exp.file_status[GIT_DELTA_ADDED]);
cl_assert_equal_i(expected_new + 1, exp.files);
git_diff_list_free(diff);
git_diff_free(diff);
git_tree_free(new_tree);
git_tree_free(tree);
......
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