Commit 1c74686e by Vicent Martí

Merge pull request #1897 from libgit2/split-patch-from-diff

RFC: Proposed reworking of diff APIs
parents 98fec8a9 7ce60099
......@@ -45,25 +45,23 @@ char *colors[] = {
static int printer(
const git_diff_delta *delta,
const git_diff_range *range,
char usage,
const char *line,
size_t line_len,
const git_diff_hunk *hunk,
const git_diff_line *line,
void *data)
{
int *last_color = data, color = 0;
(void)delta; (void)range; (void)line_len;
(void)delta; (void)hunk;
if (*last_color >= 0) {
switch (usage) {
case GIT_DIFF_LINE_ADDITION: color = 3; break;
case GIT_DIFF_LINE_DELETION: color = 2; break;
switch (line->origin) {
case GIT_DIFF_LINE_ADDITION: color = 3; break;
case GIT_DIFF_LINE_DELETION: color = 2; break;
case GIT_DIFF_LINE_ADD_EOFNL: color = 3; break;
case GIT_DIFF_LINE_DEL_EOFNL: color = 2; break;
case GIT_DIFF_LINE_FILE_HDR: color = 1; break;
case GIT_DIFF_LINE_HUNK_HDR: color = 4; break;
default: color = 0;
case GIT_DIFF_LINE_FILE_HDR: color = 1; break;
case GIT_DIFF_LINE_HUNK_HDR: color = 4; break;
default: break;
}
if (color != *last_color) {
if (*last_color == 1 || color == 1)
......@@ -73,7 +71,13 @@ static int printer(
}
}
fputs(line, stdout);
if (line->origin == GIT_DIFF_LINE_CONTEXT ||
line->origin == GIT_DIFF_LINE_ADDITION ||
line->origin == GIT_DIFF_LINE_DELETION)
fputc(line->origin, stdout);
fwrite(line->content, 1, line->content_len, stdout);
return 0;
}
......@@ -114,20 +118,15 @@ static void usage(const char *message, const char *arg)
exit(1);
}
enum {
FORMAT_PATCH = 0,
FORMAT_COMPACT = 1,
FORMAT_RAW = 2
};
int main(int argc, char *argv[])
{
git_repository *repo = NULL;
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;
int i, color = -1, format = FORMAT_PATCH, cached = 0;
git_diff *diff;
int i, color = -1, cached = 0;
git_diff_format_t format = GIT_DIFF_FORMAT_PATCH;
char *a, *treeish1 = NULL, *treeish2 = NULL;
const char *dir = ".";
......@@ -148,13 +147,15 @@ int main(int argc, char *argv[])
}
else if (!strcmp(a, "-p") || !strcmp(a, "-u") ||
!strcmp(a, "--patch"))
format = FORMAT_PATCH;
format = GIT_DIFF_FORMAT_PATCH;
else if (!strcmp(a, "--cached"))
cached = 1;
else if (!strcmp(a, "--name-only"))
format = GIT_DIFF_FORMAT_NAME_ONLY;
else if (!strcmp(a, "--name-status"))
format = FORMAT_COMPACT;
format = GIT_DIFF_FORMAT_NAME_STATUS;
else if (!strcmp(a, "--raw"))
format = FORMAT_RAW;
format = GIT_DIFF_FORMAT_RAW;
else if (!strcmp(a, "--color"))
color = 0;
else if (!strcmp(a, "--no-color"))
......@@ -218,11 +219,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");
......@@ -238,22 +239,12 @@ int main(int argc, char *argv[])
if (color >= 0)
fputs(colors[0], stdout);
switch (format) {
case FORMAT_PATCH:
check(git_diff_print_patch(diff, printer, &color), "Displaying diff");
break;
case FORMAT_COMPACT:
check(git_diff_print_compact(diff, printer, &color), "Displaying diff");
break;
case FORMAT_RAW:
check(git_diff_print_raw(diff, printer, &color), "Displaying diff");
break;
}
check(git_diff_print(diff, format, printer, &color), "Displaying diff");
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,14 +184,18 @@ static void print_commit(git_commit *commit)
static int print_diff(
const git_diff_delta *delta,
const git_diff_range *range,
char usage,
const char *line,
size_t line_len,
const git_diff_hunk *hunk,
const git_diff_line *line,
void *data)
{
(void)delta; (void)range; (void)usage; (void)line_len; (void)data;
fputs(line, stdout);
(void)delta; (void)hunk; (void)data;
if (line->origin == GIT_DIFF_LINE_CONTEXT ||
line->origin == GIT_DIFF_LINE_ADDITION ||
line->origin == GIT_DIFF_LINE_DELETION)
fputc(line->origin, stdout);
fwrite(line->content, 1, line->content_len, stdout);
return 0;
}
......@@ -218,7 +222,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 +233,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 +377,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;
......@@ -388,10 +392,10 @@ int main(int argc, char *argv[])
check(git_diff_tree_to_tree(
&diff, git_commit_owner(commit), a, b, &diffopts),
"Diff commit with parent", NULL);
check(git_diff_print_patch(diff, print_diff, NULL),
check(git_diff_print(diff, GIT_DIFF_FORMAT_PATCH, 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 out Output parameter for the delta patch 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 **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_get_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 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,
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 out The git_diff_line data for this line
* @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(
const git_diff_line **out,
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);
......
......@@ -46,7 +46,7 @@ enum {
typedef struct {
git_repository *repo;
git_diff_list *diff;
git_diff *diff;
git_checkout_opts opts;
bool opts_free_baseline;
char *pfx;
......@@ -2006,7 +2006,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);
......
......@@ -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)
{
......@@ -110,7 +110,7 @@ int git_diff_file_content__init_from_diff(
has_data = use_old; break;
case GIT_DELTA_UNTRACKED:
has_data = !use_old &&
(diff->opts.flags & GIT_DIFF_INCLUDE_UNTRACKED_CONTENT) != 0;
(diff->opts.flags & GIT_DIFF_SHOW_UNTRACKED_CONTENT) != 0;
break;
case GIT_DELTA_MODIFIED:
case GIT_DELTA_COPIED:
......
......@@ -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
......@@ -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;
......@@ -117,15 +117,15 @@ int git_diff_merge(
git_pool_init(&onto_pool, 1, 0) < 0)
return -1;
if ((onto->opts.flags & GIT_DIFF_DELTAS_ARE_ICASE) != 0 ||
(from->opts.flags & GIT_DIFF_DELTAS_ARE_ICASE) != 0)
if ((onto->opts.flags & GIT_DIFF_IGNORE_CASE) != 0 ||
(from->opts.flags & GIT_DIFF_IGNORE_CASE) != 0)
{
ignore_case = true;
/* This function currently only supports merging diff lists that
* are sorted identically. */
assert((onto->opts.flags & GIT_DIFF_DELTAS_ARE_ICASE) != 0 &&
(from->opts.flags & GIT_DIFF_DELTAS_ARE_ICASE) != 0);
assert((onto->opts.flags & GIT_DIFF_IGNORE_CASE) != 0 &&
(from->opts.flags & GIT_DIFF_IGNORE_CASE) != 0);
}
for (i = 0, j = 0; i < onto->deltas.length || j < from->deltas.length; ) {
......@@ -230,9 +230,9 @@ 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)
const git_diff_find_options *given)
{
git_config *cfg = NULL;
......@@ -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;
......@@ -350,6 +350,7 @@ static int apply_splits_and_deletes(
goto on_error;
deleted->status = GIT_DELTA_DELETED;
deleted->nfiles = 1;
memset(&deleted->new_file, 0, sizeof(deleted->new_file));
deleted->new_file.path = deleted->old_file.path;
deleted->new_file.flags |= GIT_DIFF_FLAG_VALID_OID;
......@@ -361,6 +362,7 @@ static int apply_splits_and_deletes(
delta->status = GIT_DELTA_UNTRACKED;
else
delta->status = GIT_DELTA_ADDED;
delta->nfiles = 1;
memset(&delta->old_file, 0, sizeof(delta->old_file));
delta->old_file.path = delta->new_file.path;
delta->old_file.flags |= GIT_DIFF_FLAG_VALID_OID;
......@@ -402,7 +404,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 +421,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 +511,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 +597,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)
......@@ -612,7 +614,7 @@ static int calc_self_similarity(
return error;
if (similarity >= 0) {
delta->similarity = (uint32_t)similarity;
delta->similarity = (uint16_t)similarity;
delta->flags |= GIT_DIFF_FLAG__HAS_SELF_SIMILARITY;
}
......@@ -620,7 +622,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 +677,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)
......@@ -745,25 +747,27 @@ GIT_INLINE(bool) delta_is_new_only(git_diff_delta *delta)
}
GIT_INLINE(void) delta_make_rename(
git_diff_delta *to, const git_diff_delta *from, uint32_t similarity)
git_diff_delta *to, const git_diff_delta *from, uint16_t similarity)
{
to->status = GIT_DELTA_RENAMED;
to->similarity = similarity;
to->nfiles = 2;
memcpy(&to->old_file, &from->old_file, sizeof(to->old_file));
to->flags &= ~GIT_DIFF_FLAG__TO_SPLIT;
}
typedef struct {
uint32_t idx;
uint32_t similarity;
size_t idx;
uint16_t similarity;
} diff_find_match;
int git_diff_find_similar(
git_diff_list *diff,
git_diff_find_options *given_opts)
git_diff *diff,
const git_diff_find_options *given_opts)
{
size_t s, t;
int error = 0, similarity;
int error = 0, result;
uint16_t similarity;
git_diff_delta *src, *tgt;
git_diff_find_options opts;
size_t num_deltas, num_srcs = 0, num_tgts = 0;
......@@ -839,17 +843,18 @@ find_best_matches:
/* calculate similarity for this pair and find best match */
if (s == t)
similarity = -1; /* don't measure self-similarity here */
result = -1; /* don't measure self-similarity here */
else if ((error = similarity_measure(
&similarity, diff, &opts, sigcache, 2 * s, 2 * t + 1)) < 0)
&result, diff, &opts, sigcache, 2 * s, 2 * t + 1)) < 0)
goto cleanup;
if (similarity < 0)
if (result < 0)
continue;
similarity = (uint16_t)result;
/* is this a better rename? */
if (tgt2src[t].similarity < (uint32_t)similarity &&
src2tgt[s].similarity < (uint32_t)similarity)
if (tgt2src[t].similarity < similarity &&
src2tgt[s].similarity < similarity)
{
/* eject old mapping */
if (src2tgt[s].similarity > 0) {
......@@ -862,18 +867,18 @@ find_best_matches:
}
/* write new mapping */
tgt2src[t].idx = (uint32_t)s;
tgt2src[t].similarity = (uint32_t)similarity;
src2tgt[s].idx = (uint32_t)t;
src2tgt[s].similarity = (uint32_t)similarity;
tgt2src[t].idx = s;
tgt2src[t].similarity = similarity;
src2tgt[s].idx = t;
src2tgt[s].similarity = similarity;
}
/* keep best absolute match for copies */
if (tgt2src_copy != NULL &&
tgt2src_copy[t].similarity < (uint32_t)similarity)
tgt2src_copy[t].similarity < similarity)
{
tgt2src_copy[t].idx = (uint32_t)s;
tgt2src_copy[t].similarity = (uint32_t)similarity;
tgt2src_copy[t].idx = s;
tgt2src_copy[t].similarity = similarity;
}
if (++tried_srcs >= num_srcs)
......@@ -943,7 +948,7 @@ find_best_matches:
delta_make_rename(tgt, src, best_match->similarity);
num_rewrites--;
src->status = GIT_DELTA_DELETED;
assert(src->status == GIT_DELTA_DELETED);
memcpy(&src->old_file, &swap, sizeof(src->old_file));
memset(&src->new_file, 0, sizeof(src->new_file));
src->new_file.path = src->old_file.path;
......@@ -953,7 +958,7 @@ find_best_matches:
if (src2tgt[t].similarity > 0 && src2tgt[t].idx > t) {
/* what used to be at src t is now at src s */
tgt2src[src2tgt[t].idx].idx = (uint32_t)s;
tgt2src[src2tgt[t].idx].idx = s;
}
}
}
......@@ -969,6 +974,7 @@ find_best_matches:
src->status = (diff->new_src == GIT_ITERATOR_TYPE_WORKDIR) ?
GIT_DELTA_UNTRACKED : GIT_DELTA_ADDED;
src->nfiles = 1;
memset(&src->old_file, 0, sizeof(src->old_file));
src->old_file.path = src->new_file.path;
src->old_file.flags |= GIT_DIFF_FLAG_VALID_OID;
......@@ -1006,7 +1012,7 @@ find_best_matches:
/* otherwise, if we just overwrote a source, update mapping */
else if (src2tgt[t].similarity > 0 && src2tgt[t].idx > t) {
/* what used to be at src t is now at src s */
tgt2src[src2tgt[t].idx].idx = (uint32_t)s;
tgt2src[src2tgt[t].idx].idx = s;
}
num_updates++;
......@@ -1026,6 +1032,7 @@ find_best_matches:
tgt->status = GIT_DELTA_COPIED;
tgt->similarity = best_match->similarity;
tgt->nfiles = 2;
memcpy(&tgt->old_file, &src->old_file, sizeof(tgt->old_file));
num_updates++;
......
......@@ -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,38 +51,96 @@ 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;
int old_lineno, new_lineno;
} git_xdiff_info;
static int diff_update_lines(
git_xdiff_info *info,
git_diff_line *line,
const char *content,
size_t content_len)
{
const char *scan = content, *scan_end = content + content_len;
for (line->num_lines = 0; scan < scan_end; ++scan)
if (*scan == '\n')
++line->num_lines;
line->content = content;
line->content_len = content_len;
/* expect " "/"-"/"+", then data */
switch (line->origin) {
case GIT_DIFF_LINE_ADDITION:
case GIT_DIFF_LINE_DEL_EOFNL:
line->old_lineno = -1;
line->new_lineno = info->new_lineno;
info->new_lineno += (int)line->num_lines;
break;
case GIT_DIFF_LINE_DELETION:
case GIT_DIFF_LINE_ADD_EOFNL:
line->old_lineno = info->old_lineno;
line->new_lineno = -1;
info->old_lineno += (int)line->num_lines;
break;
case GIT_DIFF_LINE_CONTEXT:
case GIT_DIFF_LINE_CONTEXT_EOFNL:
line->old_lineno = info->old_lineno;
line->new_lineno = info->new_lineno;
info->old_lineno += (int)line->num_lines;
info->new_lineno += (int)line->num_lines;
break;
default:
giterr_set(GITERR_INVALID, "Unknown diff line origin %02x",
(unsigned int)line->origin);
return -1;
}
return 0;
}
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_get_delta(patch);
git_diff_output *output = &info->xo->output;
git_diff_line line;
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;
info->hunk.header_len = bufs[0].size;
if (info->hunk.header_len >= sizeof(info->hunk.header))
info->hunk.header_len = sizeof(info->hunk.header) - 1;
memcpy(info->hunk.header, bufs[0].ptr, info->hunk.header_len);
info->hunk.header[info->hunk.header_len] = '\0';
if (output->hunk_cb != NULL &&
output->hunk_cb(delta, &info->range,
bufs[0].ptr, bufs[0].size, output->payload))
output->hunk_cb(delta, &info->hunk, output->payload))
output->error = GIT_EUSER;
info->old_lineno = info->hunk.old_start;
info->new_lineno = info->hunk.new_start;
}
if (len == 2 || len == 3) {
/* expect " "/"-"/"+", then data */
char origin =
line.origin =
(*bufs[0].ptr == '+') ? GIT_DIFF_LINE_ADDITION :
(*bufs[0].ptr == '-') ? GIT_DIFF_LINE_DELETION :
GIT_DIFF_LINE_CONTEXT;
if (output->data_cb != NULL &&
output->data_cb(delta, &info->range,
origin, bufs[1].ptr, bufs[1].size, output->payload))
output->error = diff_update_lines(
info, &line, bufs[1].ptr, bufs[1].size);
if (!output->error &&
output->data_cb != NULL &&
output->data_cb(delta, &info->hunk, &line, output->payload))
output->error = GIT_EUSER;
}
......@@ -92,21 +150,24 @@ static int git_xdiff_cb(void *priv, mmbuffer_t *bufs, int len)
* If we have a '-' and a third buf, then we have removed a line
* with out a newline but added a blank line, so ADD_EOFNL.
*/
char origin =
line.origin =
(*bufs[0].ptr == '+') ? GIT_DIFF_LINE_DEL_EOFNL :
(*bufs[0].ptr == '-') ? GIT_DIFF_LINE_ADD_EOFNL :
GIT_DIFF_LINE_CONTEXT_EOFNL;
if (output->data_cb != NULL &&
output->data_cb(delta, &info->range,
origin, bufs[2].ptr, bufs[2].size, output->payload))
output->error = diff_update_lines(
info, &line, bufs[2].ptr, bufs[2].size);
if (!output->error &&
output->data_cb != NULL &&
output->data_cb(delta, &info->hunk, &line, output->payload))
output->error = GIT_EUSER;
}
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 +181,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 +193,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);
......@@ -145,7 +206,7 @@ static int git_xdiff(git_diff_output *output, git_diff_patch *patch)
void git_xdiff_init(git_xdiff_output *xo, const git_diff_options *opts)
{
uint32_t flags = opts ? opts->flags : GIT_DIFF_NORMAL;
uint32_t flags = opts ? opts->flags : 0;
xo->output.diff_cb = git_xdiff;
......@@ -161,6 +222,11 @@ void git_xdiff_init(git_xdiff_output *xo, const git_diff_options *opts)
if (flags & GIT_DIFF_IGNORE_WHITESPACE_EOL)
xo->params.flags |= XDF_IGNORE_WHITESPACE_AT_EOL;
if (flags & GIT_DIFF_PATIENCE)
xo->params.flags |= XDF_PATIENCE_DIFF;
if (flags & GIT_DIFF_MINIMAL)
xo->params.flags |= XDF_NEED_MINIMAL;
memset(&xo->callback, 0, sizeof(xo->callback));
xo->callback.outf = git_xdiff_cb;
}
......@@ -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,10 +24,9 @@ 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;
size_t i, max_i;
git_index_entry entry;
int error;
git_index *index = NULL;
......@@ -58,7 +57,9 @@ int git_reset_default(
&diff, repo, tree, index, &opts)) < 0)
goto cleanup;
git_vector_foreach(&diff->deltas, i, delta) {
for (i = 0, max_i = git_diff_num_deltas(diff); i < max_i; ++i) {
const git_diff_delta *delta = git_diff_get_delta(diff, i);
if ((error = git_index_conflict_remove(index, delta->old_file.path)) < 0)
goto cleanup;
......@@ -85,7 +86,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;
}
......
......@@ -153,65 +153,61 @@ cleanup:
return error;
}
struct cb_data {
git_index *index;
int error;
struct stash_update_rules {
bool include_changed;
bool include_untracked;
bool include_ignored;
};
static int update_index_cb(
const git_diff_delta *delta,
float progress,
void *payload)
static int stash_update_index_from_diff(
git_index *index,
const git_diff *diff,
struct stash_update_rules *data)
{
struct cb_data *data = (struct cb_data *)payload;
const char *add_path = NULL;
GIT_UNUSED(progress);
switch (delta->status) {
case GIT_DELTA_IGNORED:
if (data->include_ignored)
add_path = delta->new_file.path;
break;
case GIT_DELTA_UNTRACKED:
if (data->include_untracked)
add_path = delta->new_file.path;
break;
case GIT_DELTA_ADDED:
case GIT_DELTA_MODIFIED:
if (data->include_changed)
add_path = delta->new_file.path;
break;
case GIT_DELTA_DELETED:
if (!data->include_changed)
int error = 0;
size_t d, max_d = git_diff_num_deltas(diff);
for (d = 0; !error && d < max_d; ++d) {
const char *add_path = NULL;
const git_diff_delta *delta = git_diff_get_delta(diff, d);
switch (delta->status) {
case GIT_DELTA_IGNORED:
if (data->include_ignored)
add_path = delta->new_file.path;
break;
case GIT_DELTA_UNTRACKED:
if (data->include_untracked)
add_path = delta->new_file.path;
break;
if (git_index_find(NULL, data->index, delta->old_file.path) == 0)
data->error = git_index_remove(
data->index, delta->old_file.path, 0);
break;
default:
/* Unimplemented */
giterr_set(
GITERR_INVALID,
"Cannot update index. Unimplemented status (%d)",
delta->status);
data->error = -1;
break;
}
if (add_path != NULL)
data->error = git_index_add_bypath(data->index, add_path);
case GIT_DELTA_ADDED:
case GIT_DELTA_MODIFIED:
if (data->include_changed)
add_path = delta->new_file.path;
break;
return data->error;
case GIT_DELTA_DELETED:
if (data->include_changed &&
!git_index_find(NULL, index, delta->old_file.path))
error = git_index_remove(index, delta->old_file.path, 0);
break;
default:
/* Unimplemented */
giterr_set(
GITERR_INVALID,
"Cannot update index. Unimplemented status (%d)",
delta->status);
return -1;
}
if (add_path != NULL)
error = git_index_add_bypath(index, add_path);
}
return error;
}
static int build_untracked_tree(
......@@ -221,15 +217,13 @@ 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};
struct stash_update_rules data = {0};
int error;
git_index_clear(index);
data.index = index;
if (flags & GIT_STASH_INCLUDE_UNTRACKED) {
opts.flags |= GIT_DIFF_INCLUDE_UNTRACKED |
GIT_DIFF_RECURSE_UNTRACKED_DIRS;
......@@ -248,18 +242,13 @@ static int build_untracked_tree(
&diff, git_index_owner(index), i_tree, &opts)) < 0)
goto cleanup;
if ((error = git_diff_foreach(
diff, update_index_cb, NULL, NULL, &data)) < 0)
{
if (error == GIT_EUSER)
error = data.error;
if ((error = stash_update_index_from_diff(index, diff, &data)) < 0)
goto cleanup;
}
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,9 +300,9 @@ 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;
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
struct cb_data data = {0};
struct stash_update_rules data = {0};
int error;
opts.flags = GIT_DIFF_IGNORE_SUBMODULES;
......@@ -321,33 +310,19 @@ static int build_workdir_tree(
if ((error = git_commit_tree(&b_tree, b_commit)) < 0)
goto cleanup;
if ((error = git_diff_tree_to_index(&diff, repo, b_tree, NULL, &opts)) < 0)
goto cleanup;
if ((error = git_diff_index_to_workdir(&diff2, repo, NULL, &opts)) < 0)
goto cleanup;
if ((error = git_diff_merge(diff, diff2)) < 0)
if ((error = git_diff_tree_to_workdir_with_index(
&diff, repo, b_tree, &opts)) < 0)
goto cleanup;
data.index = index;
data.include_changed = true;
if ((error = git_diff_foreach(
diff, update_index_cb, NULL, NULL, &data)) < 0)
{
if (error == GIT_EUSER)
error = data.error;
if ((error = stash_update_index_from_diff(index, diff, &data)) < 0)
goto cleanup;
}
if ((error = build_tree_from_index(tree_out, index)) < 0)
goto cleanup;
error = build_tree_from_index(tree_out, index);
cleanup:
git_diff_list_free(diff);
git_diff_list_free(diff2);
git_diff_free(diff);
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,41 +95,37 @@ int diff_print_file_cb(
int diff_hunk_cb(
const git_diff_delta *delta,
const git_diff_range *range,
const char *header,
size_t header_len,
const git_diff_hunk *hunk,
void *payload)
{
diff_expects *e = payload;
const char *scan = hunk->header, *scan_end = scan + hunk->header_len;
GIT_UNUSED(delta);
/* confirm no NUL bytes in header text */
while (header_len--) cl_assert('\0' != *header++);
while (scan < scan_end)
cl_assert('\0' != *scan++);
e->hunks++;
e->hunk_old_lines += range->old_lines;
e->hunk_new_lines += range->new_lines;
e->hunk_old_lines += hunk->old_lines;
e->hunk_new_lines += hunk->new_lines;
return 0;
}
int diff_line_cb(
const git_diff_delta *delta,
const git_diff_range *range,
char line_origin,
const char *content,
size_t content_len,
const git_diff_hunk *hunk,
const git_diff_line *line,
void *payload)
{
diff_expects *e = payload;
GIT_UNUSED(delta);
GIT_UNUSED(range);
GIT_UNUSED(content);
GIT_UNUSED(content_len);
GIT_UNUSED(hunk);
e->lines++;
switch (line_origin) {
switch (line->origin) {
case GIT_DIFF_LINE_CONTEXT:
case GIT_DIFF_LINE_CONTEXT_EOFNL: /* techically not a line */
e->line_ctxt++;
......@@ -149,25 +145,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_assert(delta);
cl_git_pass(git_patch_from_diff(&patch, diff, d));
cl_assert((delta = git_patch_get_delta(patch)) != NULL);
/* 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,44 +175,37 @@ 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 char *hdr;
size_t hdr_len, l, num_l;
const git_diff_hunk *hunk;
size_t l, num_l;
cl_git_pass(git_diff_patch_get_hunk(
&range, &hdr, &hdr_len, &num_l, patch, h));
cl_git_pass(git_patch_get_hunk(&hunk, &num_l, patch, h));
if (hunk_cb && hunk_cb(delta, range, hdr, hdr_len, data) != 0) {
git_diff_patch_free(patch);
if (hunk_cb && hunk_cb(delta, hunk, data) != 0) {
git_patch_free(patch);
goto abort;
}
for (l = 0; l < num_l; ++l) {
char origin;
const char *line;
size_t line_len;
int old_lineno, new_lineno;
const git_diff_line *line;
cl_git_pass(git_diff_patch_get_line_in_hunk(
&origin, &line, &line_len, &old_lineno, &new_lineno,
patch, h, l));
cl_git_pass(git_patch_get_line_in_hunk(&line, patch, h, l));
if (line_cb &&
line_cb(delta, range, origin, line, line_len, data) != 0) {
git_diff_patch_free(patch);
line_cb(delta, hunk, line, data) != 0) {
git_patch_free(patch);
goto abort;
}
}
}
git_diff_patch_free(patch);
git_patch_free(patch);
}
return 0;
......@@ -228,27 +217,26 @@ abort:
static int diff_print_cb(
const git_diff_delta *delta,
const git_diff_range *range,
char line_origin, /**< GIT_DIFF_LINE_... value from above */
const char *content,
size_t content_len,
const git_diff_hunk *hunk,
const git_diff_line *line,
void *payload)
{
GIT_UNUSED(payload);
GIT_UNUSED(delta);
GIT_UNUSED(range);
GIT_UNUSED(line_origin);
GIT_UNUSED(content_len);
fputs(content, (FILE *)payload);
GIT_UNUSED(hunk);
fprintf((FILE *)payload, "%c%.*s",
line->origin, (int)line->content_len, line->content);
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));
cl_git_pass(git_diff_print(
diff, GIT_DIFF_FORMAT_PATCH, 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));
cl_git_pass(git_diff_print(
diff, GIT_DIFF_FORMAT_RAW, diff_print_cb, fp ? fp : stderr));
}
......@@ -44,25 +44,21 @@ extern int diff_print_file_cb(
extern int diff_hunk_cb(
const git_diff_delta *delta,
const git_diff_range *range,
const char *header,
size_t header_len,
const git_diff_hunk *hunk,
void *cb_data);
extern int diff_line_cb(
const git_diff_delta *delta,
const git_diff_range *range,
char line_origin,
const char *content,
size_t content_len,
const git_diff_hunk *hunk,
const git_diff_line *line,
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, 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, 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, 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, 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, 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, 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));
......@@ -90,6 +90,9 @@ void test_diff_tree__0(void)
git_tree_free(c);
}
#define DIFF_OPTS(FLAGS, CTXT) \
{GIT_DIFF_OPTIONS_VERSION, (FLAGS), 0, {NULL,0}, NULL, NULL, (CTXT), 1}
void test_diff_tree__options(void)
{
/* grabbed a couple of commit oids from the history of the attr repo */
......@@ -102,16 +105,16 @@ void test_diff_tree__options(void)
int test_ab_or_cd[] = { 0, 0, 0, 0, 1, 1, 1, 1, 1 };
git_diff_options test_options[] = {
/* a vs b tests */
{ 1, GIT_DIFF_NORMAL, 1, 1, NULL, NULL, {0} },
{ 1, GIT_DIFF_NORMAL, 3, 1, NULL, NULL, {0} },
{ 1, GIT_DIFF_REVERSE, 2, 1, NULL, NULL, {0} },
{ 1, GIT_DIFF_FORCE_TEXT, 2, 1, NULL, NULL, {0} },
DIFF_OPTS(GIT_DIFF_NORMAL, 1),
DIFF_OPTS(GIT_DIFF_NORMAL, 3),
DIFF_OPTS(GIT_DIFF_REVERSE, 2),
DIFF_OPTS(GIT_DIFF_FORCE_TEXT, 2),
/* c vs d tests */
{ 1, GIT_DIFF_NORMAL, 3, 1, NULL, NULL, {0} },
{ 1, GIT_DIFF_IGNORE_WHITESPACE, 3, 1, NULL, NULL, {0} },
{ 1, GIT_DIFF_IGNORE_WHITESPACE_CHANGE, 3, 1, NULL, NULL, {0} },
{ 1, GIT_DIFF_IGNORE_WHITESPACE_EOL, 3, 1, NULL, NULL, {0} },
{ 1, GIT_DIFF_IGNORE_WHITESPACE | GIT_DIFF_REVERSE, 1, 1, NULL, NULL, {0} },
DIFF_OPTS(GIT_DIFF_NORMAL, 3),
DIFF_OPTS(GIT_DIFF_IGNORE_WHITESPACE, 3),
DIFF_OPTS(GIT_DIFF_IGNORE_WHITESPACE_CHANGE, 3),
DIFF_OPTS(GIT_DIFF_IGNORE_WHITESPACE_EOL, 3),
DIFF_OPTS(GIT_DIFF_IGNORE_WHITESPACE | GIT_DIFF_REVERSE, 1),
};
/* to generate these values:
......@@ -168,7 +171,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 +217,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 +233,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,19 +250,17 @@ 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)
{
const char *a_commit = "d70d245ed97ed2aa596dd1af6536e4bfdb047b69";
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;
const char *header, *line;
char origin;
size_t d, num_d, h, num_h, l, num_l;
git_patch *patch;
const git_diff_hunk *hunk;
const git_diff_line *line;
g_repo = cl_git_sandbox_init("diff");
......@@ -273,31 +274,27 @@ 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_assert(patch && delta);
cl_git_pass(git_patch_from_diff(&patch, 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(
&range, &header, &header_len, &num_l, patch, h));
cl_git_pass(git_patch_get_hunk(&hunk, &num_l, patch, h));
for (l = 0; l < num_l; ++l) {
cl_git_pass(git_diff_patch_get_line_in_hunk(
&origin, &line, &line_len, NULL, NULL, patch, h, l));
cl_git_pass(git_patch_get_line_in_hunk(&line, patch, h, l));
cl_assert(line);
}
cl_git_fail(git_diff_patch_get_line_in_hunk(
&origin, &line, &line_len, NULL, NULL, patch, h, num_l));
cl_git_fail(git_patch_get_line_in_hunk(&line, patch, h, num_l));
}
cl_git_fail(git_diff_patch_get_hunk(
&range, &header, &header_len, &num_l, patch, num_h));
cl_git_fail(git_patch_get_hunk(&hunk, &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, diff, num_d));
cl_assert_equal_i(2, (int)num_d);
}
......@@ -487,7 +484,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 +504,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