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"
......
/*
* 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);
......
......@@ -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;
}
}
......@@ -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);
......@@ -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);
}
......@@ -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);
......
......@@ -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);
......
......@@ -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