mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-03 17:57:25 +00:00
Merge pull request #1897 from libgit2/split-patch-from-diff
RFC: Proposed reworking of diff APIs
This commit is contained in:
commit
1c74686e05
@ -45,25 +45,23 @@ char *colors[] = {
|
|||||||
|
|
||||||
static int printer(
|
static int printer(
|
||||||
const git_diff_delta *delta,
|
const git_diff_delta *delta,
|
||||||
const git_diff_range *range,
|
const git_diff_hunk *hunk,
|
||||||
char usage,
|
const git_diff_line *line,
|
||||||
const char *line,
|
|
||||||
size_t line_len,
|
|
||||||
void *data)
|
void *data)
|
||||||
{
|
{
|
||||||
int *last_color = data, color = 0;
|
int *last_color = data, color = 0;
|
||||||
|
|
||||||
(void)delta; (void)range; (void)line_len;
|
(void)delta; (void)hunk;
|
||||||
|
|
||||||
if (*last_color >= 0) {
|
if (*last_color >= 0) {
|
||||||
switch (usage) {
|
switch (line->origin) {
|
||||||
case GIT_DIFF_LINE_ADDITION: color = 3; break;
|
case GIT_DIFF_LINE_ADDITION: color = 3; break;
|
||||||
case GIT_DIFF_LINE_DELETION: color = 2; break;
|
case GIT_DIFF_LINE_DELETION: color = 2; break;
|
||||||
case GIT_DIFF_LINE_ADD_EOFNL: color = 3; break;
|
case GIT_DIFF_LINE_ADD_EOFNL: color = 3; break;
|
||||||
case GIT_DIFF_LINE_DEL_EOFNL: color = 2; break;
|
case GIT_DIFF_LINE_DEL_EOFNL: color = 2; break;
|
||||||
case GIT_DIFF_LINE_FILE_HDR: color = 1; break;
|
case GIT_DIFF_LINE_FILE_HDR: color = 1; break;
|
||||||
case GIT_DIFF_LINE_HUNK_HDR: color = 4; break;
|
case GIT_DIFF_LINE_HUNK_HDR: color = 4; break;
|
||||||
default: color = 0;
|
default: break;
|
||||||
}
|
}
|
||||||
if (color != *last_color) {
|
if (color != *last_color) {
|
||||||
if (*last_color == 1 || color == 1)
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -114,20 +118,15 @@ static void usage(const char *message, const char *arg)
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
enum {
|
|
||||||
FORMAT_PATCH = 0,
|
|
||||||
FORMAT_COMPACT = 1,
|
|
||||||
FORMAT_RAW = 2
|
|
||||||
};
|
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
git_repository *repo = NULL;
|
git_repository *repo = NULL;
|
||||||
git_tree *t1 = NULL, *t2 = NULL;
|
git_tree *t1 = NULL, *t2 = NULL;
|
||||||
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
|
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
|
||||||
git_diff_find_options findopts = GIT_DIFF_FIND_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;
|
int i, color = -1, cached = 0;
|
||||||
|
git_diff_format_t format = GIT_DIFF_FORMAT_PATCH;
|
||||||
char *a, *treeish1 = NULL, *treeish2 = NULL;
|
char *a, *treeish1 = NULL, *treeish2 = NULL;
|
||||||
const char *dir = ".";
|
const char *dir = ".";
|
||||||
|
|
||||||
@ -148,13 +147,15 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
else if (!strcmp(a, "-p") || !strcmp(a, "-u") ||
|
else if (!strcmp(a, "-p") || !strcmp(a, "-u") ||
|
||||||
!strcmp(a, "--patch"))
|
!strcmp(a, "--patch"))
|
||||||
format = FORMAT_PATCH;
|
format = GIT_DIFF_FORMAT_PATCH;
|
||||||
else if (!strcmp(a, "--cached"))
|
else if (!strcmp(a, "--cached"))
|
||||||
cached = 1;
|
cached = 1;
|
||||||
|
else if (!strcmp(a, "--name-only"))
|
||||||
|
format = GIT_DIFF_FORMAT_NAME_ONLY;
|
||||||
else if (!strcmp(a, "--name-status"))
|
else if (!strcmp(a, "--name-status"))
|
||||||
format = FORMAT_COMPACT;
|
format = GIT_DIFF_FORMAT_NAME_STATUS;
|
||||||
else if (!strcmp(a, "--raw"))
|
else if (!strcmp(a, "--raw"))
|
||||||
format = FORMAT_RAW;
|
format = GIT_DIFF_FORMAT_RAW;
|
||||||
else if (!strcmp(a, "--color"))
|
else if (!strcmp(a, "--color"))
|
||||||
color = 0;
|
color = 0;
|
||||||
else if (!strcmp(a, "--no-color"))
|
else if (!strcmp(a, "--no-color"))
|
||||||
@ -218,11 +219,11 @@ int main(int argc, char *argv[])
|
|||||||
else if (t1 && cached)
|
else if (t1 && cached)
|
||||||
check(git_diff_tree_to_index(&diff, repo, t1, NULL, &opts), "Diff");
|
check(git_diff_tree_to_index(&diff, repo, t1, NULL, &opts), "Diff");
|
||||||
else if (t1) {
|
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_tree_to_index(&diff, repo, t1, NULL, &opts), "Diff");
|
||||||
check(git_diff_index_to_workdir(&diff2, repo, NULL, &opts), "Diff");
|
check(git_diff_index_to_workdir(&diff2, repo, NULL, &opts), "Diff");
|
||||||
check(git_diff_merge(diff, diff2), "Merge diffs");
|
check(git_diff_merge(diff, diff2), "Merge diffs");
|
||||||
git_diff_list_free(diff2);
|
git_diff_free(diff2);
|
||||||
}
|
}
|
||||||
else if (cached) {
|
else if (cached) {
|
||||||
check(resolve_to_tree(repo, "HEAD", &t1), "looking up HEAD");
|
check(resolve_to_tree(repo, "HEAD", &t1), "looking up HEAD");
|
||||||
@ -238,22 +239,12 @@ int main(int argc, char *argv[])
|
|||||||
if (color >= 0)
|
if (color >= 0)
|
||||||
fputs(colors[0], stdout);
|
fputs(colors[0], stdout);
|
||||||
|
|
||||||
switch (format) {
|
check(git_diff_print(diff, format, printer, &color), "Displaying diff");
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (color >= 0)
|
if (color >= 0)
|
||||||
fputs(colors[0], stdout);
|
fputs(colors[0], stdout);
|
||||||
|
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
git_tree_free(t1);
|
git_tree_free(t1);
|
||||||
git_tree_free(t2);
|
git_tree_free(t2);
|
||||||
git_repository_free(repo);
|
git_repository_free(repo);
|
||||||
|
@ -184,14 +184,18 @@ static void print_commit(git_commit *commit)
|
|||||||
|
|
||||||
static int print_diff(
|
static int print_diff(
|
||||||
const git_diff_delta *delta,
|
const git_diff_delta *delta,
|
||||||
const git_diff_range *range,
|
const git_diff_hunk *hunk,
|
||||||
char usage,
|
const git_diff_line *line,
|
||||||
const char *line,
|
|
||||||
size_t line_len,
|
|
||||||
void *data)
|
void *data)
|
||||||
{
|
{
|
||||||
(void)delta; (void)range; (void)usage; (void)line_len; (void)data;
|
(void)delta; (void)hunk; (void)data;
|
||||||
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -218,7 +222,7 @@ static int match_with_parent(
|
|||||||
{
|
{
|
||||||
git_commit *parent;
|
git_commit *parent;
|
||||||
git_tree *a, *b;
|
git_tree *a, *b;
|
||||||
git_diff_list *diff;
|
git_diff *diff;
|
||||||
int ndeltas;
|
int ndeltas;
|
||||||
|
|
||||||
check(git_commit_parent(&parent, commit, (size_t)i), "Get parent", NULL);
|
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);
|
ndeltas = (int)git_diff_num_deltas(diff);
|
||||||
|
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
git_tree_free(a);
|
git_tree_free(a);
|
||||||
git_tree_free(b);
|
git_tree_free(b);
|
||||||
git_commit_free(parent);
|
git_commit_free(parent);
|
||||||
@ -373,7 +377,7 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
if (opt.show_diff) {
|
if (opt.show_diff) {
|
||||||
git_tree *a = NULL, *b = NULL;
|
git_tree *a = NULL, *b = NULL;
|
||||||
git_diff_list *diff = NULL;
|
git_diff *diff = NULL;
|
||||||
|
|
||||||
if (parents > 1)
|
if (parents > 1)
|
||||||
continue;
|
continue;
|
||||||
@ -388,10 +392,10 @@ int main(int argc, char *argv[])
|
|||||||
check(git_diff_tree_to_tree(
|
check(git_diff_tree_to_tree(
|
||||||
&diff, git_commit_owner(commit), a, b, &diffopts),
|
&diff, git_commit_owner(commit), a, b, &diffopts),
|
||||||
"Diff commit with parent", NULL);
|
"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);
|
"Displaying diff", NULL);
|
||||||
|
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
git_tree_free(a);
|
git_tree_free(a);
|
||||||
git_tree_free(b);
|
git_tree_free(b);
|
||||||
}
|
}
|
||||||
|
@ -32,6 +32,7 @@
|
|||||||
#include "git2/odb.h"
|
#include "git2/odb.h"
|
||||||
#include "git2/oid.h"
|
#include "git2/oid.h"
|
||||||
#include "git2/pack.h"
|
#include "git2/pack.h"
|
||||||
|
#include "git2/patch.h"
|
||||||
#include "git2/pathspec.h"
|
#include "git2/pathspec.h"
|
||||||
#include "git2/push.h"
|
#include "git2/push.h"
|
||||||
#include "git2/refdb.h"
|
#include "git2/refdb.h"
|
||||||
|
File diff suppressed because it is too large
Load Diff
250
include/git2/patch.h
Normal file
250
include/git2/patch.h
Normal file
@ -0,0 +1,250 @@
|
|||||||
|
/*
|
||||||
|
* 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_EXTERN(int) git_pathspec_match_diff(
|
||||||
git_pathspec_match_list **out,
|
git_pathspec_match_list **out,
|
||||||
git_diff_list *diff,
|
git_diff *diff,
|
||||||
uint32_t flags,
|
uint32_t flags,
|
||||||
git_pathspec *ps);
|
git_pathspec *ps);
|
||||||
|
|
||||||
|
@ -46,7 +46,7 @@ enum {
|
|||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
git_repository *repo;
|
git_repository *repo;
|
||||||
git_diff_list *diff;
|
git_diff *diff;
|
||||||
git_checkout_opts opts;
|
git_checkout_opts opts;
|
||||||
bool opts_free_baseline;
|
bool opts_free_baseline;
|
||||||
char *pfx;
|
char *pfx;
|
||||||
@ -2006,7 +2006,7 @@ cleanup:
|
|||||||
(data.strategy & GIT_CHECKOUT_DONT_UPDATE_INDEX) == 0)
|
(data.strategy & GIT_CHECKOUT_DONT_UPDATE_INDEX) == 0)
|
||||||
error = git_index_write(data.index);
|
error = git_index_write(data.index);
|
||||||
|
|
||||||
git_diff_list_free(data.diff);
|
git_diff_free(data.diff);
|
||||||
git_iterator_free(workdir);
|
git_iterator_free(workdir);
|
||||||
git_iterator_free(baseline);
|
git_iterator_free(baseline);
|
||||||
git__free(actions);
|
git__free(actions);
|
||||||
|
134
src/diff.c
134
src/diff.c
@ -21,7 +21,7 @@
|
|||||||
(VAL) ? ((DIFF)->opts.flags | (FLAG)) : ((DIFF)->opts.flags & ~(VAL))
|
(VAL) ? ((DIFF)->opts.flags | (FLAG)) : ((DIFF)->opts.flags & ~(VAL))
|
||||||
|
|
||||||
static git_diff_delta *diff_delta__alloc(
|
static git_diff_delta *diff_delta__alloc(
|
||||||
git_diff_list *diff,
|
git_diff *diff,
|
||||||
git_delta_t status,
|
git_delta_t status,
|
||||||
const char *path)
|
const char *path)
|
||||||
{
|
{
|
||||||
@ -50,7 +50,7 @@ static git_diff_delta *diff_delta__alloc(
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int diff_notify(
|
static int diff_notify(
|
||||||
const git_diff_list *diff,
|
const git_diff *diff,
|
||||||
const git_diff_delta *delta,
|
const git_diff_delta *delta,
|
||||||
const char *matched_pathspec)
|
const char *matched_pathspec)
|
||||||
{
|
{
|
||||||
@ -62,7 +62,7 @@ static int diff_notify(
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int diff_delta__from_one(
|
static int diff_delta__from_one(
|
||||||
git_diff_list *diff,
|
git_diff *diff,
|
||||||
git_delta_t status,
|
git_delta_t status,
|
||||||
const git_index_entry *entry)
|
const git_index_entry *entry)
|
||||||
{
|
{
|
||||||
@ -81,7 +81,7 @@ static int diff_delta__from_one(
|
|||||||
if (!git_pathspec__match(
|
if (!git_pathspec__match(
|
||||||
&diff->pathspec, entry->path,
|
&diff->pathspec, entry->path,
|
||||||
DIFF_FLAG_IS_SET(diff, GIT_DIFF_DISABLE_PATHSPEC_MATCH),
|
DIFF_FLAG_IS_SET(diff, GIT_DIFF_DISABLE_PATHSPEC_MATCH),
|
||||||
DIFF_FLAG_IS_SET(diff, GIT_DIFF_DELTAS_ARE_ICASE),
|
DIFF_FLAG_IS_SET(diff, GIT_DIFF_IGNORE_CASE),
|
||||||
&matched_pathspec, NULL))
|
&matched_pathspec, NULL))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
@ -90,6 +90,7 @@ static int diff_delta__from_one(
|
|||||||
|
|
||||||
/* This fn is just for single-sided diffs */
|
/* This fn is just for single-sided diffs */
|
||||||
assert(status != GIT_DELTA_MODIFIED);
|
assert(status != GIT_DELTA_MODIFIED);
|
||||||
|
delta->nfiles = 1;
|
||||||
|
|
||||||
if (delta->status == GIT_DELTA_DELETED) {
|
if (delta->status == GIT_DELTA_DELETED) {
|
||||||
delta->old_file.mode = entry->mode;
|
delta->old_file.mode = entry->mode;
|
||||||
@ -120,7 +121,7 @@ static int diff_delta__from_one(
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int diff_delta__from_two(
|
static int diff_delta__from_two(
|
||||||
git_diff_list *diff,
|
git_diff *diff,
|
||||||
git_delta_t status,
|
git_delta_t status,
|
||||||
const git_index_entry *old_entry,
|
const git_index_entry *old_entry,
|
||||||
uint32_t old_mode,
|
uint32_t old_mode,
|
||||||
@ -148,6 +149,7 @@ static int diff_delta__from_two(
|
|||||||
|
|
||||||
delta = diff_delta__alloc(diff, status, canonical_path);
|
delta = diff_delta__alloc(diff, status, canonical_path);
|
||||||
GITERR_CHECK_ALLOC(delta);
|
GITERR_CHECK_ALLOC(delta);
|
||||||
|
delta->nfiles = 2;
|
||||||
|
|
||||||
git_oid_cpy(&delta->old_file.oid, &old_entry->oid);
|
git_oid_cpy(&delta->old_file.oid, &old_entry->oid);
|
||||||
delta->old_file.size = old_entry->file_size;
|
delta->old_file.size = old_entry->file_size;
|
||||||
@ -181,7 +183,7 @@ static int diff_delta__from_two(
|
|||||||
}
|
}
|
||||||
|
|
||||||
static git_diff_delta *diff_delta__last_for_item(
|
static git_diff_delta *diff_delta__last_for_item(
|
||||||
git_diff_list *diff,
|
git_diff *diff,
|
||||||
const git_index_entry *item)
|
const git_index_entry *item)
|
||||||
{
|
{
|
||||||
git_diff_delta *delta = git_vector_last(&diff->deltas);
|
git_diff_delta *delta = git_vector_last(&diff->deltas);
|
||||||
@ -340,13 +342,13 @@ static const char *diff_mnemonic_prefix(
|
|||||||
return pfx;
|
return pfx;
|
||||||
}
|
}
|
||||||
|
|
||||||
static git_diff_list *diff_list_alloc(
|
static git_diff *diff_list_alloc(
|
||||||
git_repository *repo,
|
git_repository *repo,
|
||||||
git_iterator *old_iter,
|
git_iterator *old_iter,
|
||||||
git_iterator *new_iter)
|
git_iterator *new_iter)
|
||||||
{
|
{
|
||||||
git_diff_options dflt = GIT_DIFF_OPTIONS_INIT;
|
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)
|
if (!diff)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
@ -360,7 +362,7 @@ static git_diff_list *diff_list_alloc(
|
|||||||
|
|
||||||
if (git_vector_init(&diff->deltas, 0, git_diff_delta__cmp) < 0 ||
|
if (git_vector_init(&diff->deltas, 0, git_diff_delta__cmp) < 0 ||
|
||||||
git_pool_init(&diff->pool, 1, 0) < 0) {
|
git_pool_init(&diff->pool, 1, 0) < 0) {
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -368,14 +370,14 @@ static git_diff_list *diff_list_alloc(
|
|||||||
* the ignore_case bit set */
|
* the ignore_case bit set */
|
||||||
if (!git_iterator_ignore_case(old_iter) &&
|
if (!git_iterator_ignore_case(old_iter) &&
|
||||||
!git_iterator_ignore_case(new_iter)) {
|
!git_iterator_ignore_case(new_iter)) {
|
||||||
diff->opts.flags &= ~GIT_DIFF_DELTAS_ARE_ICASE;
|
diff->opts.flags &= ~GIT_DIFF_IGNORE_CASE;
|
||||||
|
|
||||||
diff->strcomp = git__strcmp;
|
diff->strcomp = git__strcmp;
|
||||||
diff->strncomp = git__strncmp;
|
diff->strncomp = git__strncmp;
|
||||||
diff->pfxcomp = git__prefixcmp;
|
diff->pfxcomp = git__prefixcmp;
|
||||||
diff->entrycomp = git_index_entry__cmp;
|
diff->entrycomp = git_index_entry__cmp;
|
||||||
} else {
|
} else {
|
||||||
diff->opts.flags |= GIT_DIFF_DELTAS_ARE_ICASE;
|
diff->opts.flags |= GIT_DIFF_IGNORE_CASE;
|
||||||
|
|
||||||
diff->strcomp = git__strcasecmp;
|
diff->strcomp = git__strcasecmp;
|
||||||
diff->strncomp = git__strncasecmp;
|
diff->strncomp = git__strncasecmp;
|
||||||
@ -389,7 +391,7 @@ static git_diff_list *diff_list_alloc(
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int diff_list_apply_options(
|
static int diff_list_apply_options(
|
||||||
git_diff_list *diff,
|
git_diff *diff,
|
||||||
const git_diff_options *opts)
|
const git_diff_options *opts)
|
||||||
{
|
{
|
||||||
git_config *cfg;
|
git_config *cfg;
|
||||||
@ -399,9 +401,9 @@ static int diff_list_apply_options(
|
|||||||
|
|
||||||
if (opts) {
|
if (opts) {
|
||||||
/* copy user options (except case sensitivity info from iterators) */
|
/* copy user options (except case sensitivity info from iterators) */
|
||||||
bool icase = DIFF_FLAG_IS_SET(diff, GIT_DIFF_DELTAS_ARE_ICASE);
|
bool icase = DIFF_FLAG_IS_SET(diff, GIT_DIFF_IGNORE_CASE);
|
||||||
memcpy(&diff->opts, opts, sizeof(diff->opts));
|
memcpy(&diff->opts, opts, sizeof(diff->opts));
|
||||||
DIFF_FLAG_SET(diff, GIT_DIFF_DELTAS_ARE_ICASE, icase);
|
DIFF_FLAG_SET(diff, GIT_DIFF_IGNORE_CASE, icase);
|
||||||
|
|
||||||
/* initialize pathspec from options */
|
/* initialize pathspec from options */
|
||||||
if (git_pathspec__vinit(&diff->pathspec, &opts->pathspec, pool) < 0)
|
if (git_pathspec__vinit(&diff->pathspec, &opts->pathspec, pool) < 0)
|
||||||
@ -413,7 +415,7 @@ static int diff_list_apply_options(
|
|||||||
diff->opts.flags |= GIT_DIFF_INCLUDE_TYPECHANGE;
|
diff->opts.flags |= GIT_DIFF_INCLUDE_TYPECHANGE;
|
||||||
|
|
||||||
/* flag INCLUDE_UNTRACKED_CONTENT implies INCLUDE_UNTRACKED */
|
/* flag INCLUDE_UNTRACKED_CONTENT implies INCLUDE_UNTRACKED */
|
||||||
if (DIFF_FLAG_IS_SET(diff, GIT_DIFF_INCLUDE_UNTRACKED_CONTENT))
|
if (DIFF_FLAG_IS_SET(diff, GIT_DIFF_SHOW_UNTRACKED_CONTENT))
|
||||||
diff->opts.flags |= GIT_DIFF_INCLUDE_UNTRACKED;
|
diff->opts.flags |= GIT_DIFF_INCLUDE_UNTRACKED;
|
||||||
|
|
||||||
/* load config values that affect diff behavior */
|
/* load config values that affect diff behavior */
|
||||||
@ -490,7 +492,7 @@ static int diff_list_apply_options(
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void diff_list_free(git_diff_list *diff)
|
static void diff_list_free(git_diff *diff)
|
||||||
{
|
{
|
||||||
git_diff_delta *delta;
|
git_diff_delta *delta;
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
@ -508,7 +510,7 @@ static void diff_list_free(git_diff_list *diff)
|
|||||||
git__free(diff);
|
git__free(diff);
|
||||||
}
|
}
|
||||||
|
|
||||||
void git_diff_list_free(git_diff_list *diff)
|
void git_diff_free(git_diff *diff)
|
||||||
{
|
{
|
||||||
if (!diff)
|
if (!diff)
|
||||||
return;
|
return;
|
||||||
@ -516,7 +518,7 @@ void git_diff_list_free(git_diff_list *diff)
|
|||||||
GIT_REFCOUNT_DEC(diff, diff_list_free);
|
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);
|
GIT_REFCOUNT_INC(diff);
|
||||||
}
|
}
|
||||||
@ -612,7 +614,7 @@ typedef struct {
|
|||||||
static int maybe_modified_submodule(
|
static int maybe_modified_submodule(
|
||||||
git_delta_t *status,
|
git_delta_t *status,
|
||||||
git_oid *found_oid,
|
git_oid *found_oid,
|
||||||
git_diff_list *diff,
|
git_diff *diff,
|
||||||
diff_in_progress *info)
|
diff_in_progress *info)
|
||||||
{
|
{
|
||||||
int error = 0;
|
int error = 0;
|
||||||
@ -659,7 +661,7 @@ static int maybe_modified_submodule(
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int maybe_modified(
|
static int maybe_modified(
|
||||||
git_diff_list *diff,
|
git_diff *diff,
|
||||||
diff_in_progress *info)
|
diff_in_progress *info)
|
||||||
{
|
{
|
||||||
git_oid noid;
|
git_oid noid;
|
||||||
@ -674,7 +676,7 @@ static int maybe_modified(
|
|||||||
if (!git_pathspec__match(
|
if (!git_pathspec__match(
|
||||||
&diff->pathspec, oitem->path,
|
&diff->pathspec, oitem->path,
|
||||||
DIFF_FLAG_IS_SET(diff, GIT_DIFF_DISABLE_PATHSPEC_MATCH),
|
DIFF_FLAG_IS_SET(diff, GIT_DIFF_DISABLE_PATHSPEC_MATCH),
|
||||||
DIFF_FLAG_IS_SET(diff, GIT_DIFF_DELTAS_ARE_ICASE),
|
DIFF_FLAG_IS_SET(diff, GIT_DIFF_IGNORE_CASE),
|
||||||
&matched_pathspec, NULL))
|
&matched_pathspec, NULL))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
@ -778,7 +780,7 @@ static int maybe_modified(
|
|||||||
}
|
}
|
||||||
|
|
||||||
static bool entry_is_prefixed(
|
static bool entry_is_prefixed(
|
||||||
git_diff_list *diff,
|
git_diff *diff,
|
||||||
const git_index_entry *item,
|
const git_index_entry *item,
|
||||||
const git_index_entry *prefix_item)
|
const git_index_entry *prefix_item)
|
||||||
{
|
{
|
||||||
@ -795,7 +797,7 @@ static bool entry_is_prefixed(
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int diff_scan_inside_untracked_dir(
|
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;
|
int error = 0;
|
||||||
git_buf base = GIT_BUF_INIT;
|
git_buf base = GIT_BUF_INIT;
|
||||||
@ -861,7 +863,7 @@ done:
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int handle_unmatched_new_item(
|
static int handle_unmatched_new_item(
|
||||||
git_diff_list *diff, diff_in_progress *info)
|
git_diff *diff, diff_in_progress *info)
|
||||||
{
|
{
|
||||||
int error = 0;
|
int error = 0;
|
||||||
const git_index_entry *nitem = info->nitem;
|
const git_index_entry *nitem = info->nitem;
|
||||||
@ -910,7 +912,7 @@ static int handle_unmatched_new_item(
|
|||||||
*/
|
*/
|
||||||
if (!recurse_into_dir &&
|
if (!recurse_into_dir &&
|
||||||
delta_type == GIT_DELTA_UNTRACKED &&
|
delta_type == GIT_DELTA_UNTRACKED &&
|
||||||
DIFF_FLAG_ISNT_SET(diff, GIT_DIFF_FAST_UNTRACKED_DIRS))
|
DIFF_FLAG_ISNT_SET(diff, GIT_DIFF_ENABLE_FAST_UNTRACKED_DIRS))
|
||||||
{
|
{
|
||||||
git_diff_delta *last;
|
git_diff_delta *last;
|
||||||
|
|
||||||
@ -1016,7 +1018,7 @@ static int handle_unmatched_new_item(
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int handle_unmatched_old_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);
|
int error = diff_delta__from_one(diff, GIT_DELTA_DELETED, info->oitem);
|
||||||
if (error < 0)
|
if (error < 0)
|
||||||
@ -1048,7 +1050,7 @@ static int handle_unmatched_old_item(
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int handle_matched_item(
|
static int handle_matched_item(
|
||||||
git_diff_list *diff, diff_in_progress *info)
|
git_diff *diff, diff_in_progress *info)
|
||||||
{
|
{
|
||||||
int error = 0;
|
int error = 0;
|
||||||
|
|
||||||
@ -1063,7 +1065,7 @@ static int handle_matched_item(
|
|||||||
}
|
}
|
||||||
|
|
||||||
int git_diff__from_iterators(
|
int git_diff__from_iterators(
|
||||||
git_diff_list **diff_ptr,
|
git_diff **diff_ptr,
|
||||||
git_repository *repo,
|
git_repository *repo,
|
||||||
git_iterator *old_iter,
|
git_iterator *old_iter,
|
||||||
git_iterator *new_iter,
|
git_iterator *new_iter,
|
||||||
@ -1071,7 +1073,7 @@ int git_diff__from_iterators(
|
|||||||
{
|
{
|
||||||
int error = 0;
|
int error = 0;
|
||||||
diff_in_progress info;
|
diff_in_progress info;
|
||||||
git_diff_list *diff;
|
git_diff *diff;
|
||||||
|
|
||||||
*diff_ptr = NULL;
|
*diff_ptr = NULL;
|
||||||
|
|
||||||
@ -1084,7 +1086,7 @@ int git_diff__from_iterators(
|
|||||||
git_buf_init(&info.ignore_prefix, 0);
|
git_buf_init(&info.ignore_prefix, 0);
|
||||||
|
|
||||||
/* make iterators have matching icase behavior */
|
/* make iterators have matching icase behavior */
|
||||||
if (DIFF_FLAG_IS_SET(diff, GIT_DIFF_DELTAS_ARE_ICASE)) {
|
if (DIFF_FLAG_IS_SET(diff, GIT_DIFF_IGNORE_CASE)) {
|
||||||
if ((error = git_iterator_set_ignore_case(old_iter, true)) < 0 ||
|
if ((error = git_iterator_set_ignore_case(old_iter, true)) < 0 ||
|
||||||
(error = git_iterator_set_ignore_case(new_iter, true)) < 0)
|
(error = git_iterator_set_ignore_case(new_iter, true)) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
@ -1132,7 +1134,7 @@ cleanup:
|
|||||||
if (!error)
|
if (!error)
|
||||||
*diff_ptr = diff;
|
*diff_ptr = diff;
|
||||||
else
|
else
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
|
|
||||||
git_buf_free(&info.ignore_prefix);
|
git_buf_free(&info.ignore_prefix);
|
||||||
|
|
||||||
@ -1149,7 +1151,7 @@ cleanup:
|
|||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
int git_diff_tree_to_tree(
|
int git_diff_tree_to_tree(
|
||||||
git_diff_list **diff,
|
git_diff **diff,
|
||||||
git_repository *repo,
|
git_repository *repo,
|
||||||
git_tree *old_tree,
|
git_tree *old_tree,
|
||||||
git_tree *new_tree,
|
git_tree *new_tree,
|
||||||
@ -1164,7 +1166,7 @@ int git_diff_tree_to_tree(
|
|||||||
* currently case insensitive, unless the user explicitly asked
|
* currently case insensitive, unless the user explicitly asked
|
||||||
* for case insensitivity
|
* for case insensitivity
|
||||||
*/
|
*/
|
||||||
if (opts && (opts->flags & GIT_DIFF_DELTAS_ARE_ICASE) != 0)
|
if (opts && (opts->flags & GIT_DIFF_IGNORE_CASE) != 0)
|
||||||
iflag = GIT_ITERATOR_IGNORE_CASE;
|
iflag = GIT_ITERATOR_IGNORE_CASE;
|
||||||
|
|
||||||
DIFF_FROM_ITERATORS(
|
DIFF_FROM_ITERATORS(
|
||||||
@ -1176,7 +1178,7 @@ int git_diff_tree_to_tree(
|
|||||||
}
|
}
|
||||||
|
|
||||||
int git_diff_tree_to_index(
|
int git_diff_tree_to_index(
|
||||||
git_diff_list **diff,
|
git_diff **diff,
|
||||||
git_repository *repo,
|
git_repository *repo,
|
||||||
git_tree *old_tree,
|
git_tree *old_tree,
|
||||||
git_index *index,
|
git_index *index,
|
||||||
@ -1204,9 +1206,9 @@ int git_diff_tree_to_index(
|
|||||||
git_index__set_ignore_case(index, true);
|
git_index__set_ignore_case(index, true);
|
||||||
|
|
||||||
if (!error) {
|
if (!error) {
|
||||||
git_diff_list *d = *diff;
|
git_diff *d = *diff;
|
||||||
|
|
||||||
d->opts.flags |= GIT_DIFF_DELTAS_ARE_ICASE;
|
d->opts.flags |= GIT_DIFF_IGNORE_CASE;
|
||||||
d->strcomp = git__strcasecmp;
|
d->strcomp = git__strcasecmp;
|
||||||
d->strncomp = git__strncasecmp;
|
d->strncomp = git__strncasecmp;
|
||||||
d->pfxcomp = git__prefixcmp_icase;
|
d->pfxcomp = git__prefixcmp_icase;
|
||||||
@ -1221,7 +1223,7 @@ int git_diff_tree_to_index(
|
|||||||
}
|
}
|
||||||
|
|
||||||
int git_diff_index_to_workdir(
|
int git_diff_index_to_workdir(
|
||||||
git_diff_list **diff,
|
git_diff **diff,
|
||||||
git_repository *repo,
|
git_repository *repo,
|
||||||
git_index *index,
|
git_index *index,
|
||||||
const git_diff_options *opts)
|
const git_diff_options *opts)
|
||||||
@ -1242,9 +1244,8 @@ int git_diff_index_to_workdir(
|
|||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int git_diff_tree_to_workdir(
|
int git_diff_tree_to_workdir(
|
||||||
git_diff_list **diff,
|
git_diff **diff,
|
||||||
git_repository *repo,
|
git_repository *repo,
|
||||||
git_tree *old_tree,
|
git_tree *old_tree,
|
||||||
const git_diff_options *opts)
|
const git_diff_options *opts)
|
||||||
@ -1262,16 +1263,43 @@ int git_diff_tree_to_workdir(
|
|||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t git_diff_num_deltas(git_diff_list *diff)
|
int git_diff_tree_to_workdir_with_index(
|
||||||
|
git_diff **diff,
|
||||||
|
git_repository *repo,
|
||||||
|
git_tree *old_tree,
|
||||||
|
const git_diff_options *opts)
|
||||||
{
|
{
|
||||||
assert(diff);
|
int error = 0;
|
||||||
return (size_t)diff->deltas.length;
|
git_diff *d1 = NULL, *d2 = NULL;
|
||||||
|
|
||||||
|
assert(diff && repo);
|
||||||
|
|
||||||
|
if (!(error = git_diff_tree_to_index(&d1, repo, old_tree, NULL, opts)) &&
|
||||||
|
!(error = git_diff_index_to_workdir(&d2, repo, NULL, opts)))
|
||||||
|
error = git_diff_merge(d1, d2);
|
||||||
|
|
||||||
|
git_diff_free(d2);
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
git_diff_free(d1);
|
||||||
|
d1 = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
*diff = d1;
|
||||||
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t git_diff_num_deltas_of_type(git_diff_list *diff, git_delta_t type)
|
|
||||||
|
size_t git_diff_num_deltas(const git_diff *diff)
|
||||||
|
{
|
||||||
|
assert(diff);
|
||||||
|
return diff->deltas.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t git_diff_num_deltas_of_type(const git_diff *diff, git_delta_t type)
|
||||||
{
|
{
|
||||||
size_t i, count = 0;
|
size_t i, count = 0;
|
||||||
git_diff_delta *delta;
|
const git_diff_delta *delta;
|
||||||
|
|
||||||
assert(diff);
|
assert(diff);
|
||||||
|
|
||||||
@ -1282,14 +1310,20 @@ size_t git_diff_num_deltas_of_type(git_diff_list *diff, git_delta_t type)
|
|||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
int git_diff_is_sorted_icase(const git_diff_list *diff)
|
const git_diff_delta *git_diff_get_delta(const git_diff *diff, size_t idx)
|
||||||
{
|
{
|
||||||
return (diff->opts.flags & GIT_DIFF_DELTAS_ARE_ICASE) != 0;
|
assert(diff);
|
||||||
|
return git_vector_get(&diff->deltas, idx);
|
||||||
|
}
|
||||||
|
|
||||||
|
int git_diff_is_sorted_icase(const git_diff *diff)
|
||||||
|
{
|
||||||
|
return (diff->opts.flags & GIT_DIFF_IGNORE_CASE) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int git_diff__paired_foreach(
|
int git_diff__paired_foreach(
|
||||||
git_diff_list *head2idx,
|
git_diff *head2idx,
|
||||||
git_diff_list *idx2wd,
|
git_diff *idx2wd,
|
||||||
int (*cb)(git_diff_delta *h2i, git_diff_delta *i2w, void *payload),
|
int (*cb)(git_diff_delta *h2i, git_diff_delta *i2w, void *payload),
|
||||||
void *payload)
|
void *payload)
|
||||||
{
|
{
|
||||||
@ -1318,10 +1352,10 @@ int git_diff__paired_foreach(
|
|||||||
* always sort by the old name in the i2w list.
|
* always sort by the old name in the i2w list.
|
||||||
*/
|
*/
|
||||||
h2i_icase = head2idx != NULL &&
|
h2i_icase = head2idx != NULL &&
|
||||||
(head2idx->opts.flags & GIT_DIFF_DELTAS_ARE_ICASE) != 0;
|
(head2idx->opts.flags & GIT_DIFF_IGNORE_CASE) != 0;
|
||||||
|
|
||||||
i2w_icase = idx2wd != NULL &&
|
i2w_icase = idx2wd != NULL &&
|
||||||
(idx2wd->opts.flags & GIT_DIFF_DELTAS_ARE_ICASE) != 0;
|
(idx2wd->opts.flags & GIT_DIFF_IGNORE_CASE) != 0;
|
||||||
|
|
||||||
icase_mismatch =
|
icase_mismatch =
|
||||||
(head2idx != NULL && idx2wd != NULL && h2i_icase != i2w_icase);
|
(head2idx != NULL && idx2wd != NULL && h2i_icase != i2w_icase);
|
||||||
|
10
src/diff.h
10
src/diff.h
@ -52,7 +52,7 @@ enum {
|
|||||||
|
|
||||||
#define GIT_DIFF__VERBOSE (1 << 30)
|
#define GIT_DIFF__VERBOSE (1 << 30)
|
||||||
|
|
||||||
struct git_diff_list {
|
struct git_diff {
|
||||||
git_refcount rc;
|
git_refcount rc;
|
||||||
git_repository *repo;
|
git_repository *repo;
|
||||||
git_diff_options opts;
|
git_diff_options opts;
|
||||||
@ -72,7 +72,7 @@ struct git_diff_list {
|
|||||||
extern void git_diff__cleanup_modes(
|
extern void git_diff__cleanup_modes(
|
||||||
uint32_t diffcaps, uint32_t *omode, uint32_t *nmode);
|
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__cmp(const void *a, const void *b);
|
||||||
extern int git_diff_delta__casecmp(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 *);
|
git_repository *, const char *, uint16_t, git_off_t, git_oid *);
|
||||||
|
|
||||||
extern int git_diff__from_iterators(
|
extern int git_diff__from_iterators(
|
||||||
git_diff_list **diff_ptr,
|
git_diff **diff_ptr,
|
||||||
git_repository *repo,
|
git_repository *repo,
|
||||||
git_iterator *old_iter,
|
git_iterator *old_iter,
|
||||||
git_iterator *new_iter,
|
git_iterator *new_iter,
|
||||||
const git_diff_options *opts);
|
const git_diff_options *opts);
|
||||||
|
|
||||||
extern int git_diff__paired_foreach(
|
extern int git_diff__paired_foreach(
|
||||||
git_diff_list *idx2head,
|
git_diff *idx2head,
|
||||||
git_diff_list *wd2idx,
|
git_diff *wd2idx,
|
||||||
int (*cb)(git_diff_delta *i2h, git_diff_delta *w2i, void *payload),
|
int (*cb)(git_diff_delta *i2h, git_diff_delta *w2i, void *payload),
|
||||||
void *payload);
|
void *payload);
|
||||||
|
|
||||||
|
@ -88,7 +88,7 @@ static int diff_file_content_init_common(
|
|||||||
|
|
||||||
int git_diff_file_content__init_from_diff(
|
int git_diff_file_content__init_from_diff(
|
||||||
git_diff_file_content *fc,
|
git_diff_file_content *fc,
|
||||||
git_diff_list *diff,
|
git_diff *diff,
|
||||||
size_t delta_index,
|
size_t delta_index,
|
||||||
bool use_old)
|
bool use_old)
|
||||||
{
|
{
|
||||||
@ -110,7 +110,7 @@ int git_diff_file_content__init_from_diff(
|
|||||||
has_data = use_old; break;
|
has_data = use_old; break;
|
||||||
case GIT_DELTA_UNTRACKED:
|
case GIT_DELTA_UNTRACKED:
|
||||||
has_data = !use_old &&
|
has_data = !use_old &&
|
||||||
(diff->opts.flags & GIT_DIFF_INCLUDE_UNTRACKED_CONTENT) != 0;
|
(diff->opts.flags & GIT_DIFF_SHOW_UNTRACKED_CONTENT) != 0;
|
||||||
break;
|
break;
|
||||||
case GIT_DELTA_MODIFIED:
|
case GIT_DELTA_MODIFIED:
|
||||||
case GIT_DELTA_COPIED:
|
case GIT_DELTA_COPIED:
|
||||||
|
@ -27,7 +27,7 @@ typedef struct {
|
|||||||
|
|
||||||
extern int git_diff_file_content__init_from_diff(
|
extern int git_diff_file_content__init_from_diff(
|
||||||
git_diff_file_content *fc,
|
git_diff_file_content *fc,
|
||||||
git_diff_list *diff,
|
git_diff *diff,
|
||||||
size_t delta_index,
|
size_t delta_index,
|
||||||
bool use_old);
|
bool use_old);
|
||||||
|
|
||||||
|
284
src/diff_patch.c
284
src/diff_patch.c
@ -12,36 +12,24 @@
|
|||||||
#include "diff_xdiff.h"
|
#include "diff_xdiff.h"
|
||||||
#include "fileops.h"
|
#include "fileops.h"
|
||||||
|
|
||||||
/* cached information about a single span in a diff */
|
|
||||||
typedef struct diff_patch_line diff_patch_line;
|
|
||||||
struct diff_patch_line {
|
|
||||||
const char *ptr;
|
|
||||||
size_t len;
|
|
||||||
size_t lines, oldno, newno;
|
|
||||||
char origin;
|
|
||||||
};
|
|
||||||
|
|
||||||
/* cached information about a hunk in a diff */
|
/* cached information about a hunk in a diff */
|
||||||
typedef struct diff_patch_hunk diff_patch_hunk;
|
typedef struct diff_patch_hunk diff_patch_hunk;
|
||||||
struct diff_patch_hunk {
|
struct diff_patch_hunk {
|
||||||
git_diff_range range;
|
git_diff_hunk hunk;
|
||||||
char header[128];
|
|
||||||
size_t header_len;
|
|
||||||
size_t line_start;
|
size_t line_start;
|
||||||
size_t line_count;
|
size_t line_count;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct git_diff_patch {
|
struct git_patch {
|
||||||
git_refcount rc;
|
git_refcount rc;
|
||||||
git_diff_list *diff; /* for refcount purposes, maybe NULL for blob diffs */
|
git_diff *diff; /* for refcount purposes, maybe NULL for blob diffs */
|
||||||
git_diff_delta *delta;
|
git_diff_delta *delta;
|
||||||
size_t delta_index;
|
size_t delta_index;
|
||||||
git_diff_file_content ofile;
|
git_diff_file_content ofile;
|
||||||
git_diff_file_content nfile;
|
git_diff_file_content nfile;
|
||||||
uint32_t flags;
|
uint32_t flags;
|
||||||
git_array_t(diff_patch_hunk) hunks;
|
git_array_t(diff_patch_hunk) hunks;
|
||||||
git_array_t(diff_patch_line) lines;
|
git_array_t(git_diff_line) lines;
|
||||||
size_t oldno, newno;
|
|
||||||
size_t content_size, context_size, header_size;
|
size_t content_size, context_size, header_size;
|
||||||
git_pool flattened;
|
git_pool flattened;
|
||||||
};
|
};
|
||||||
@ -55,12 +43,13 @@ enum {
|
|||||||
GIT_DIFF_PATCH_FLATTENED = (1 << 5),
|
GIT_DIFF_PATCH_FLATTENED = (1 << 5),
|
||||||
};
|
};
|
||||||
|
|
||||||
static void diff_output_init(git_diff_output*, const git_diff_options*,
|
static void diff_output_init(
|
||||||
git_diff_file_cb, git_diff_hunk_cb, git_diff_data_cb, void*);
|
git_diff_output*, const git_diff_options*,
|
||||||
|
git_diff_file_cb, git_diff_hunk_cb, git_diff_line_cb, void*);
|
||||||
|
|
||||||
static void diff_output_to_patch(git_diff_output *, git_diff_patch *);
|
static void diff_output_to_patch(git_diff_output *, git_patch *);
|
||||||
|
|
||||||
static void diff_patch_update_binary(git_diff_patch *patch)
|
static void diff_patch_update_binary(git_patch *patch)
|
||||||
{
|
{
|
||||||
if ((patch->delta->flags & DIFF_FLAGS_KNOWN_BINARY) != 0)
|
if ((patch->delta->flags & DIFF_FLAGS_KNOWN_BINARY) != 0)
|
||||||
return;
|
return;
|
||||||
@ -74,21 +63,21 @@ static void diff_patch_update_binary(git_diff_patch *patch)
|
|||||||
patch->delta->flags |= GIT_DIFF_FLAG_NOT_BINARY;
|
patch->delta->flags |= GIT_DIFF_FLAG_NOT_BINARY;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void diff_patch_init_common(git_diff_patch *patch)
|
static void diff_patch_init_common(git_patch *patch)
|
||||||
{
|
{
|
||||||
diff_patch_update_binary(patch);
|
diff_patch_update_binary(patch);
|
||||||
|
|
||||||
if ((patch->delta->flags & GIT_DIFF_FLAG_BINARY) != 0)
|
if ((patch->delta->flags & GIT_DIFF_FLAG_BINARY) != 0)
|
||||||
patch->flags |= GIT_DIFF_PATCH_LOADED; /* set LOADED but not DIFFABLE */
|
patch->flags |= GIT_DIFF_PATCH_LOADED; /* LOADED but not DIFFABLE */
|
||||||
|
|
||||||
patch->flags |= GIT_DIFF_PATCH_INITIALIZED;
|
patch->flags |= GIT_DIFF_PATCH_INITIALIZED;
|
||||||
|
|
||||||
if (patch->diff)
|
if (patch->diff)
|
||||||
git_diff_list_addref(patch->diff);
|
git_diff_addref(patch->diff);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int diff_patch_init_from_diff(
|
static int diff_patch_init_from_diff(
|
||||||
git_diff_patch *patch, git_diff_list *diff, size_t delta_index)
|
git_patch *patch, git_diff *diff, size_t delta_index)
|
||||||
{
|
{
|
||||||
int error = 0;
|
int error = 0;
|
||||||
|
|
||||||
@ -109,12 +98,10 @@ static int diff_patch_init_from_diff(
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int diff_patch_alloc_from_diff(
|
static int diff_patch_alloc_from_diff(
|
||||||
git_diff_patch **out,
|
git_patch **out, git_diff *diff, size_t delta_index)
|
||||||
git_diff_list *diff,
|
|
||||||
size_t delta_index)
|
|
||||||
{
|
{
|
||||||
int error;
|
int error;
|
||||||
git_diff_patch *patch = git__calloc(1, sizeof(git_diff_patch));
|
git_patch *patch = git__calloc(1, sizeof(git_patch));
|
||||||
GITERR_CHECK_ALLOC(patch);
|
GITERR_CHECK_ALLOC(patch);
|
||||||
|
|
||||||
if (!(error = diff_patch_init_from_diff(patch, diff, delta_index))) {
|
if (!(error = diff_patch_init_from_diff(patch, diff, delta_index))) {
|
||||||
@ -129,7 +116,7 @@ static int diff_patch_alloc_from_diff(
|
|||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int diff_patch_load(git_diff_patch *patch, git_diff_output *output)
|
static int diff_patch_load(git_patch *patch, git_diff_output *output)
|
||||||
{
|
{
|
||||||
int error = 0;
|
int error = 0;
|
||||||
bool incomplete_data;
|
bool incomplete_data;
|
||||||
@ -207,7 +194,7 @@ cleanup:
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int diff_patch_file_callback(
|
static int diff_patch_file_callback(
|
||||||
git_diff_patch *patch, git_diff_output *output)
|
git_patch *patch, git_diff_output *output)
|
||||||
{
|
{
|
||||||
float progress;
|
float progress;
|
||||||
|
|
||||||
@ -223,7 +210,7 @@ static int diff_patch_file_callback(
|
|||||||
return output->error;
|
return output->error;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int diff_patch_generate(git_diff_patch *patch, git_diff_output *output)
|
static int diff_patch_generate(git_patch *patch, git_diff_output *output)
|
||||||
{
|
{
|
||||||
int error = 0;
|
int error = 0;
|
||||||
|
|
||||||
@ -248,7 +235,7 @@ static int diff_patch_generate(git_diff_patch *patch, git_diff_output *output)
|
|||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void diff_patch_free(git_diff_patch *patch)
|
static void diff_patch_free(git_patch *patch)
|
||||||
{
|
{
|
||||||
git_diff_file_content__clear(&patch->ofile);
|
git_diff_file_content__clear(&patch->ofile);
|
||||||
git_diff_file_content__clear(&patch->nfile);
|
git_diff_file_content__clear(&patch->nfile);
|
||||||
@ -256,7 +243,7 @@ static void diff_patch_free(git_diff_patch *patch)
|
|||||||
git_array_clear(patch->lines);
|
git_array_clear(patch->lines);
|
||||||
git_array_clear(patch->hunks);
|
git_array_clear(patch->hunks);
|
||||||
|
|
||||||
git_diff_list_free(patch->diff); /* decrements refcount */
|
git_diff_free(patch->diff); /* decrements refcount */
|
||||||
patch->diff = NULL;
|
patch->diff = NULL;
|
||||||
|
|
||||||
git_pool_clear(&patch->flattened);
|
git_pool_clear(&patch->flattened);
|
||||||
@ -265,7 +252,7 @@ static void diff_patch_free(git_diff_patch *patch)
|
|||||||
git__free(patch);
|
git__free(patch);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int diff_required(git_diff_list *diff, const char *action)
|
static int diff_required(git_diff *diff, const char *action)
|
||||||
{
|
{
|
||||||
if (diff)
|
if (diff)
|
||||||
return 0;
|
return 0;
|
||||||
@ -274,16 +261,16 @@ static int diff_required(git_diff_list *diff, const char *action)
|
|||||||
}
|
}
|
||||||
|
|
||||||
int git_diff_foreach(
|
int git_diff_foreach(
|
||||||
git_diff_list *diff,
|
git_diff *diff,
|
||||||
git_diff_file_cb file_cb,
|
git_diff_file_cb file_cb,
|
||||||
git_diff_hunk_cb hunk_cb,
|
git_diff_hunk_cb hunk_cb,
|
||||||
git_diff_data_cb data_cb,
|
git_diff_line_cb data_cb,
|
||||||
void *payload)
|
void *payload)
|
||||||
{
|
{
|
||||||
int error = 0;
|
int error = 0;
|
||||||
git_xdiff_output xo;
|
git_xdiff_output xo;
|
||||||
size_t idx;
|
size_t idx;
|
||||||
git_diff_patch patch;
|
git_patch patch;
|
||||||
|
|
||||||
if (diff_required(diff, "git_diff_foreach") < 0)
|
if (diff_required(diff, "git_diff_foreach") < 0)
|
||||||
return -1;
|
return -1;
|
||||||
@ -305,7 +292,7 @@ int git_diff_foreach(
|
|||||||
if (!error)
|
if (!error)
|
||||||
error = diff_patch_generate(&patch, &xo.output);
|
error = diff_patch_generate(&patch, &xo.output);
|
||||||
|
|
||||||
git_diff_patch_free(&patch);
|
git_patch_free(&patch);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (error < 0)
|
if (error < 0)
|
||||||
@ -318,7 +305,7 @@ int git_diff_foreach(
|
|||||||
}
|
}
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
git_diff_patch patch;
|
git_patch patch;
|
||||||
git_diff_delta delta;
|
git_diff_delta delta;
|
||||||
char paths[GIT_FLEX_ARRAY];
|
char paths[GIT_FLEX_ARRAY];
|
||||||
} diff_patch_with_delta;
|
} diff_patch_with_delta;
|
||||||
@ -326,7 +313,7 @@ typedef struct {
|
|||||||
static int diff_single_generate(diff_patch_with_delta *pd, git_xdiff_output *xo)
|
static int diff_single_generate(diff_patch_with_delta *pd, git_xdiff_output *xo)
|
||||||
{
|
{
|
||||||
int error = 0;
|
int error = 0;
|
||||||
git_diff_patch *patch = &pd->patch;
|
git_patch *patch = &pd->patch;
|
||||||
bool has_old = ((patch->ofile.flags & GIT_DIFF_FLAG__NO_DATA) == 0);
|
bool has_old = ((patch->ofile.flags & GIT_DIFF_FLAG__NO_DATA) == 0);
|
||||||
bool has_new = ((patch->nfile.flags & GIT_DIFF_FLAG__NO_DATA) == 0);
|
bool has_new = ((patch->nfile.flags & GIT_DIFF_FLAG__NO_DATA) == 0);
|
||||||
|
|
||||||
@ -430,7 +417,7 @@ int git_diff_blobs(
|
|||||||
const git_diff_options *opts,
|
const git_diff_options *opts,
|
||||||
git_diff_file_cb file_cb,
|
git_diff_file_cb file_cb,
|
||||||
git_diff_hunk_cb hunk_cb,
|
git_diff_hunk_cb hunk_cb,
|
||||||
git_diff_data_cb data_cb,
|
git_diff_line_cb data_cb,
|
||||||
void *payload)
|
void *payload)
|
||||||
{
|
{
|
||||||
int error = 0;
|
int error = 0;
|
||||||
@ -452,13 +439,13 @@ int git_diff_blobs(
|
|||||||
error = diff_patch_from_blobs(
|
error = diff_patch_from_blobs(
|
||||||
&pd, &xo, old_blob, old_path, new_blob, new_path, opts);
|
&pd, &xo, old_blob, old_path, new_blob, new_path, opts);
|
||||||
|
|
||||||
git_diff_patch_free(&pd.patch);
|
git_patch_free(&pd.patch);
|
||||||
|
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
int git_diff_patch_from_blobs(
|
int git_patch_from_blobs(
|
||||||
git_diff_patch **out,
|
git_patch **out,
|
||||||
const git_blob *old_blob,
|
const git_blob *old_blob,
|
||||||
const char *old_path,
|
const char *old_path,
|
||||||
const git_blob *new_blob,
|
const git_blob *new_blob,
|
||||||
@ -484,9 +471,9 @@ int git_diff_patch_from_blobs(
|
|||||||
pd, &xo, old_blob, old_path, new_blob, new_path, opts);
|
pd, &xo, old_blob, old_path, new_blob, new_path, opts);
|
||||||
|
|
||||||
if (!error)
|
if (!error)
|
||||||
*out = (git_diff_patch *)pd;
|
*out = (git_patch *)pd;
|
||||||
else
|
else
|
||||||
git_diff_patch_free((git_diff_patch *)pd);
|
git_patch_free((git_patch *)pd);
|
||||||
|
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
@ -542,7 +529,7 @@ int git_diff_blob_to_buffer(
|
|||||||
const git_diff_options *opts,
|
const git_diff_options *opts,
|
||||||
git_diff_file_cb file_cb,
|
git_diff_file_cb file_cb,
|
||||||
git_diff_hunk_cb hunk_cb,
|
git_diff_hunk_cb hunk_cb,
|
||||||
git_diff_data_cb data_cb,
|
git_diff_line_cb data_cb,
|
||||||
void *payload)
|
void *payload)
|
||||||
{
|
{
|
||||||
int error = 0;
|
int error = 0;
|
||||||
@ -564,13 +551,13 @@ int git_diff_blob_to_buffer(
|
|||||||
error = diff_patch_from_blob_and_buffer(
|
error = diff_patch_from_blob_and_buffer(
|
||||||
&pd, &xo, old_blob, old_path, buf, buflen, buf_path, opts);
|
&pd, &xo, old_blob, old_path, buf, buflen, buf_path, opts);
|
||||||
|
|
||||||
git_diff_patch_free(&pd.patch);
|
git_patch_free(&pd.patch);
|
||||||
|
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
int git_diff_patch_from_blob_and_buffer(
|
int git_patch_from_blob_and_buffer(
|
||||||
git_diff_patch **out,
|
git_patch **out,
|
||||||
const git_blob *old_blob,
|
const git_blob *old_blob,
|
||||||
const char *old_path,
|
const char *old_path,
|
||||||
const char *buf,
|
const char *buf,
|
||||||
@ -597,28 +584,24 @@ int git_diff_patch_from_blob_and_buffer(
|
|||||||
pd, &xo, old_blob, old_path, buf, buflen, buf_path, opts);
|
pd, &xo, old_blob, old_path, buf, buflen, buf_path, opts);
|
||||||
|
|
||||||
if (!error)
|
if (!error)
|
||||||
*out = (git_diff_patch *)pd;
|
*out = (git_patch *)pd;
|
||||||
else
|
else
|
||||||
git_diff_patch_free((git_diff_patch *)pd);
|
git_patch_free((git_patch *)pd);
|
||||||
|
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
int git_diff_get_patch(
|
int git_patch_from_diff(
|
||||||
git_diff_patch **patch_ptr,
|
git_patch **patch_ptr, git_diff *diff, size_t idx)
|
||||||
const git_diff_delta **delta_ptr,
|
|
||||||
git_diff_list *diff,
|
|
||||||
size_t idx)
|
|
||||||
{
|
{
|
||||||
int error = 0;
|
int error = 0;
|
||||||
git_xdiff_output xo;
|
git_xdiff_output xo;
|
||||||
git_diff_delta *delta = NULL;
|
git_diff_delta *delta = NULL;
|
||||||
git_diff_patch *patch = NULL;
|
git_patch *patch = NULL;
|
||||||
|
|
||||||
if (patch_ptr) *patch_ptr = NULL;
|
if (patch_ptr) *patch_ptr = NULL;
|
||||||
if (delta_ptr) *delta_ptr = NULL;
|
|
||||||
|
|
||||||
if (diff_required(diff, "git_diff_get_patch") < 0)
|
if (diff_required(diff, "git_patch_from_diff") < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
delta = git_vector_get(&diff->deltas, idx);
|
delta = git_vector_get(&diff->deltas, idx);
|
||||||
@ -627,9 +610,6 @@ int git_diff_get_patch(
|
|||||||
return GIT_ENOTFOUND;
|
return GIT_ENOTFOUND;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (delta_ptr)
|
|
||||||
*delta_ptr = delta;
|
|
||||||
|
|
||||||
if (git_diff_delta__should_skip(&diff->opts, delta))
|
if (git_diff_delta__should_skip(&diff->opts, delta))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
@ -656,7 +636,7 @@ int git_diff_get_patch(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (error || !patch_ptr)
|
if (error || !patch_ptr)
|
||||||
git_diff_patch_free(patch);
|
git_patch_free(patch);
|
||||||
else
|
else
|
||||||
*patch_ptr = patch;
|
*patch_ptr = patch;
|
||||||
|
|
||||||
@ -665,36 +645,36 @@ int git_diff_get_patch(
|
|||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
void git_diff_patch_free(git_diff_patch *patch)
|
void git_patch_free(git_patch *patch)
|
||||||
{
|
{
|
||||||
if (patch)
|
if (patch)
|
||||||
GIT_REFCOUNT_DEC(patch, diff_patch_free);
|
GIT_REFCOUNT_DEC(patch, diff_patch_free);
|
||||||
}
|
}
|
||||||
|
|
||||||
const git_diff_delta *git_diff_patch_delta(git_diff_patch *patch)
|
const git_diff_delta *git_patch_get_delta(git_patch *patch)
|
||||||
{
|
{
|
||||||
assert(patch);
|
assert(patch);
|
||||||
return patch->delta;
|
return patch->delta;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t git_diff_patch_num_hunks(git_diff_patch *patch)
|
size_t git_patch_num_hunks(git_patch *patch)
|
||||||
{
|
{
|
||||||
assert(patch);
|
assert(patch);
|
||||||
return git_array_size(patch->hunks);
|
return git_array_size(patch->hunks);
|
||||||
}
|
}
|
||||||
|
|
||||||
int git_diff_patch_line_stats(
|
int git_patch_line_stats(
|
||||||
size_t *total_ctxt,
|
size_t *total_ctxt,
|
||||||
size_t *total_adds,
|
size_t *total_adds,
|
||||||
size_t *total_dels,
|
size_t *total_dels,
|
||||||
const git_diff_patch *patch)
|
const git_patch *patch)
|
||||||
{
|
{
|
||||||
size_t totals[3], idx;
|
size_t totals[3], idx;
|
||||||
|
|
||||||
memset(totals, 0, sizeof(totals));
|
memset(totals, 0, sizeof(totals));
|
||||||
|
|
||||||
for (idx = 0; idx < git_array_size(patch->lines); ++idx) {
|
for (idx = 0; idx < git_array_size(patch->lines); ++idx) {
|
||||||
diff_patch_line *line = git_array_get(patch->lines, idx);
|
git_diff_line *line = git_array_get(patch->lines, idx);
|
||||||
if (!line)
|
if (!line)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@ -726,12 +706,10 @@ static int diff_error_outofrange(const char *thing)
|
|||||||
return GIT_ENOTFOUND;
|
return GIT_ENOTFOUND;
|
||||||
}
|
}
|
||||||
|
|
||||||
int git_diff_patch_get_hunk(
|
int git_patch_get_hunk(
|
||||||
const git_diff_range **range,
|
const git_diff_hunk **out,
|
||||||
const char **header,
|
|
||||||
size_t *header_len,
|
|
||||||
size_t *lines_in_hunk,
|
size_t *lines_in_hunk,
|
||||||
git_diff_patch *patch,
|
git_patch *patch,
|
||||||
size_t hunk_idx)
|
size_t hunk_idx)
|
||||||
{
|
{
|
||||||
diff_patch_hunk *hunk;
|
diff_patch_hunk *hunk;
|
||||||
@ -740,21 +718,17 @@ int git_diff_patch_get_hunk(
|
|||||||
hunk = git_array_get(patch->hunks, hunk_idx);
|
hunk = git_array_get(patch->hunks, hunk_idx);
|
||||||
|
|
||||||
if (!hunk) {
|
if (!hunk) {
|
||||||
if (range) *range = NULL;
|
if (out) *out = NULL;
|
||||||
if (header) *header = NULL;
|
|
||||||
if (header_len) *header_len = 0;
|
|
||||||
if (lines_in_hunk) *lines_in_hunk = 0;
|
if (lines_in_hunk) *lines_in_hunk = 0;
|
||||||
return diff_error_outofrange("hunk");
|
return diff_error_outofrange("hunk");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (range) *range = &hunk->range;
|
if (out) *out = &hunk->hunk;
|
||||||
if (header) *header = hunk->header;
|
|
||||||
if (header_len) *header_len = hunk->header_len;
|
|
||||||
if (lines_in_hunk) *lines_in_hunk = hunk->line_count;
|
if (lines_in_hunk) *lines_in_hunk = hunk->line_count;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int git_diff_patch_num_lines_in_hunk(git_diff_patch *patch, size_t hunk_idx)
|
int git_patch_num_lines_in_hunk(git_patch *patch, size_t hunk_idx)
|
||||||
{
|
{
|
||||||
diff_patch_hunk *hunk;
|
diff_patch_hunk *hunk;
|
||||||
assert(patch);
|
assert(patch);
|
||||||
@ -764,54 +738,35 @@ int git_diff_patch_num_lines_in_hunk(git_diff_patch *patch, size_t hunk_idx)
|
|||||||
return (int)hunk->line_count;
|
return (int)hunk->line_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
int git_diff_patch_get_line_in_hunk(
|
int git_patch_get_line_in_hunk(
|
||||||
char *line_origin,
|
const git_diff_line **out,
|
||||||
const char **content,
|
git_patch *patch,
|
||||||
size_t *content_len,
|
|
||||||
int *old_lineno,
|
|
||||||
int *new_lineno,
|
|
||||||
git_diff_patch *patch,
|
|
||||||
size_t hunk_idx,
|
size_t hunk_idx,
|
||||||
size_t line_of_hunk)
|
size_t line_of_hunk)
|
||||||
{
|
{
|
||||||
diff_patch_hunk *hunk;
|
diff_patch_hunk *hunk;
|
||||||
diff_patch_line *line;
|
git_diff_line *line;
|
||||||
const char *thing;
|
|
||||||
|
|
||||||
assert(patch);
|
assert(patch);
|
||||||
|
|
||||||
if (!(hunk = git_array_get(patch->hunks, hunk_idx))) {
|
if (!(hunk = git_array_get(patch->hunks, hunk_idx))) {
|
||||||
thing = "hunk";
|
if (out) *out = NULL;
|
||||||
goto notfound;
|
return diff_error_outofrange("hunk");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (line_of_hunk >= hunk->line_count ||
|
if (line_of_hunk >= hunk->line_count ||
|
||||||
!(line = git_array_get(
|
!(line = git_array_get(
|
||||||
patch->lines, hunk->line_start + line_of_hunk))) {
|
patch->lines, hunk->line_start + line_of_hunk))) {
|
||||||
thing = "line";
|
if (out) *out = NULL;
|
||||||
goto notfound;
|
return diff_error_outofrange("line");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (line_origin) *line_origin = line->origin;
|
if (out) *out = line;
|
||||||
if (content) *content = line->ptr;
|
|
||||||
if (content_len) *content_len = line->len;
|
|
||||||
if (old_lineno) *old_lineno = (int)line->oldno;
|
|
||||||
if (new_lineno) *new_lineno = (int)line->newno;
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
notfound:
|
|
||||||
if (line_origin) *line_origin = GIT_DIFF_LINE_CONTEXT;
|
|
||||||
if (content) *content = NULL;
|
|
||||||
if (content_len) *content_len = 0;
|
|
||||||
if (old_lineno) *old_lineno = -1;
|
|
||||||
if (new_lineno) *new_lineno = -1;
|
|
||||||
|
|
||||||
return diff_error_outofrange(thing);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t git_diff_patch_size(
|
size_t git_patch_size(
|
||||||
git_diff_patch *patch,
|
git_patch *patch,
|
||||||
int include_context,
|
int include_context,
|
||||||
int include_hunk_headers,
|
int include_hunk_headers,
|
||||||
int include_file_headers)
|
int include_file_headers)
|
||||||
@ -843,36 +798,36 @@ size_t git_diff_patch_size(
|
|||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
git_diff_list *git_diff_patch__diff(git_diff_patch *patch)
|
git_diff *git_patch__diff(git_patch *patch)
|
||||||
{
|
{
|
||||||
return patch->diff;
|
return patch->diff;
|
||||||
}
|
}
|
||||||
|
|
||||||
git_diff_driver *git_diff_patch__driver(git_diff_patch *patch)
|
git_diff_driver *git_patch__driver(git_patch *patch)
|
||||||
{
|
{
|
||||||
/* ofile driver is representative for whole patch */
|
/* ofile driver is representative for whole patch */
|
||||||
return patch->ofile.driver;
|
return patch->ofile.driver;
|
||||||
}
|
}
|
||||||
|
|
||||||
void git_diff_patch__old_data(
|
void git_patch__old_data(
|
||||||
char **ptr, size_t *len, git_diff_patch *patch)
|
char **ptr, size_t *len, git_patch *patch)
|
||||||
{
|
{
|
||||||
*ptr = patch->ofile.map.data;
|
*ptr = patch->ofile.map.data;
|
||||||
*len = patch->ofile.map.len;
|
*len = patch->ofile.map.len;
|
||||||
}
|
}
|
||||||
|
|
||||||
void git_diff_patch__new_data(
|
void git_patch__new_data(
|
||||||
char **ptr, size_t *len, git_diff_patch *patch)
|
char **ptr, size_t *len, git_patch *patch)
|
||||||
{
|
{
|
||||||
*ptr = patch->nfile.map.data;
|
*ptr = patch->nfile.map.data;
|
||||||
*len = patch->nfile.map.len;
|
*len = patch->nfile.map.len;
|
||||||
}
|
}
|
||||||
|
|
||||||
int git_diff_patch__invoke_callbacks(
|
int git_patch__invoke_callbacks(
|
||||||
git_diff_patch *patch,
|
git_patch *patch,
|
||||||
git_diff_file_cb file_cb,
|
git_diff_file_cb file_cb,
|
||||||
git_diff_hunk_cb hunk_cb,
|
git_diff_hunk_cb hunk_cb,
|
||||||
git_diff_data_cb line_cb,
|
git_diff_line_cb line_cb,
|
||||||
void *payload)
|
void *payload)
|
||||||
{
|
{
|
||||||
int error = 0;
|
int error = 0;
|
||||||
@ -887,18 +842,16 @@ int git_diff_patch__invoke_callbacks(
|
|||||||
for (i = 0; !error && i < git_array_size(patch->hunks); ++i) {
|
for (i = 0; !error && i < git_array_size(patch->hunks); ++i) {
|
||||||
diff_patch_hunk *h = git_array_get(patch->hunks, i);
|
diff_patch_hunk *h = git_array_get(patch->hunks, i);
|
||||||
|
|
||||||
error = hunk_cb(
|
error = hunk_cb(patch->delta, &h->hunk, payload);
|
||||||
patch->delta, &h->range, h->header, h->header_len, payload);
|
|
||||||
|
|
||||||
if (!line_cb)
|
if (!line_cb)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
for (j = 0; !error && j < h->line_count; ++j) {
|
for (j = 0; !error && j < h->line_count; ++j) {
|
||||||
diff_patch_line *l =
|
git_diff_line *l =
|
||||||
git_array_get(patch->lines, h->line_start + j);
|
git_array_get(patch->lines, h->line_start + j);
|
||||||
|
|
||||||
error = line_cb(
|
error = line_cb(patch->delta, &h->hunk, l, payload);
|
||||||
patch->delta, &h->range, l->origin, l->ptr, l->len, payload);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -917,12 +870,10 @@ static int diff_patch_file_cb(
|
|||||||
|
|
||||||
static int diff_patch_hunk_cb(
|
static int diff_patch_hunk_cb(
|
||||||
const git_diff_delta *delta,
|
const git_diff_delta *delta,
|
||||||
const git_diff_range *range,
|
const git_diff_hunk *hunk_,
|
||||||
const char *header,
|
|
||||||
size_t header_len,
|
|
||||||
void *payload)
|
void *payload)
|
||||||
{
|
{
|
||||||
git_diff_patch *patch = payload;
|
git_patch *patch = payload;
|
||||||
diff_patch_hunk *hunk;
|
diff_patch_hunk *hunk;
|
||||||
|
|
||||||
GIT_UNUSED(delta);
|
GIT_UNUSED(delta);
|
||||||
@ -930,39 +881,28 @@ static int diff_patch_hunk_cb(
|
|||||||
hunk = git_array_alloc(patch->hunks);
|
hunk = git_array_alloc(patch->hunks);
|
||||||
GITERR_CHECK_ALLOC(hunk);
|
GITERR_CHECK_ALLOC(hunk);
|
||||||
|
|
||||||
memcpy(&hunk->range, range, sizeof(hunk->range));
|
memcpy(&hunk->hunk, hunk_, sizeof(hunk->hunk));
|
||||||
|
|
||||||
assert(header_len + 1 < sizeof(hunk->header));
|
patch->header_size += hunk_->header_len;
|
||||||
memcpy(&hunk->header, header, header_len);
|
|
||||||
hunk->header[header_len] = '\0';
|
|
||||||
hunk->header_len = header_len;
|
|
||||||
|
|
||||||
patch->header_size += header_len;
|
|
||||||
|
|
||||||
hunk->line_start = git_array_size(patch->lines);
|
hunk->line_start = git_array_size(patch->lines);
|
||||||
hunk->line_count = 0;
|
hunk->line_count = 0;
|
||||||
|
|
||||||
patch->oldno = range->old_start;
|
|
||||||
patch->newno = range->new_start;
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int diff_patch_line_cb(
|
static int diff_patch_line_cb(
|
||||||
const git_diff_delta *delta,
|
const git_diff_delta *delta,
|
||||||
const git_diff_range *range,
|
const git_diff_hunk *hunk_,
|
||||||
char line_origin,
|
const git_diff_line *line_,
|
||||||
const char *content,
|
|
||||||
size_t content_len,
|
|
||||||
void *payload)
|
void *payload)
|
||||||
{
|
{
|
||||||
git_diff_patch *patch = payload;
|
git_patch *patch = payload;
|
||||||
diff_patch_hunk *hunk;
|
diff_patch_hunk *hunk;
|
||||||
diff_patch_line *line;
|
git_diff_line *line;
|
||||||
const char *content_end = content + content_len;
|
|
||||||
|
|
||||||
GIT_UNUSED(delta);
|
GIT_UNUSED(delta);
|
||||||
GIT_UNUSED(range);
|
GIT_UNUSED(hunk_);
|
||||||
|
|
||||||
hunk = git_array_last(patch->hunks);
|
hunk = git_array_last(patch->hunks);
|
||||||
GITERR_CHECK_ALLOC(hunk);
|
GITERR_CHECK_ALLOC(hunk);
|
||||||
@ -970,48 +910,20 @@ static int diff_patch_line_cb(
|
|||||||
line = git_array_alloc(patch->lines);
|
line = git_array_alloc(patch->lines);
|
||||||
GITERR_CHECK_ALLOC(line);
|
GITERR_CHECK_ALLOC(line);
|
||||||
|
|
||||||
line->ptr = content;
|
memcpy(line, line_, sizeof(*line));
|
||||||
line->len = content_len;
|
|
||||||
line->origin = line_origin;
|
|
||||||
|
|
||||||
/* do some bookkeeping so we can provide old/new line numbers */
|
/* do some bookkeeping so we can provide old/new line numbers */
|
||||||
|
|
||||||
line->lines = 0;
|
patch->content_size += line->content_len;
|
||||||
while (content < content_end)
|
|
||||||
if (*content++ == '\n')
|
|
||||||
++line->lines;
|
|
||||||
|
|
||||||
patch->content_size += content_len;
|
if (line->origin == GIT_DIFF_LINE_ADDITION ||
|
||||||
|
line->origin == GIT_DIFF_LINE_DELETION)
|
||||||
switch (line_origin) {
|
|
||||||
case GIT_DIFF_LINE_ADDITION:
|
|
||||||
patch->content_size += 1;
|
patch->content_size += 1;
|
||||||
case GIT_DIFF_LINE_DEL_EOFNL:
|
else if (line->origin == GIT_DIFF_LINE_CONTEXT) {
|
||||||
line->oldno = -1;
|
|
||||||
line->newno = patch->newno;
|
|
||||||
patch->newno += line->lines;
|
|
||||||
break;
|
|
||||||
case GIT_DIFF_LINE_DELETION:
|
|
||||||
patch->content_size += 1;
|
patch->content_size += 1;
|
||||||
case GIT_DIFF_LINE_ADD_EOFNL:
|
patch->context_size += line->content_len + 1;
|
||||||
line->oldno = patch->oldno;
|
} else if (line->origin == GIT_DIFF_LINE_CONTEXT_EOFNL)
|
||||||
line->newno = -1;
|
patch->context_size += line->content_len;
|
||||||
patch->oldno += line->lines;
|
|
||||||
break;
|
|
||||||
case GIT_DIFF_LINE_CONTEXT:
|
|
||||||
patch->content_size += 1;
|
|
||||||
patch->context_size += 1;
|
|
||||||
case GIT_DIFF_LINE_CONTEXT_EOFNL:
|
|
||||||
patch->context_size += content_len;
|
|
||||||
line->oldno = patch->oldno;
|
|
||||||
line->newno = patch->newno;
|
|
||||||
patch->oldno += line->lines;
|
|
||||||
patch->newno += line->lines;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
assert(false);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
hunk->line_count++;
|
hunk->line_count++;
|
||||||
|
|
||||||
@ -1023,7 +935,7 @@ static void diff_output_init(
|
|||||||
const git_diff_options *opts,
|
const git_diff_options *opts,
|
||||||
git_diff_file_cb file_cb,
|
git_diff_file_cb file_cb,
|
||||||
git_diff_hunk_cb hunk_cb,
|
git_diff_hunk_cb hunk_cb,
|
||||||
git_diff_data_cb data_cb,
|
git_diff_line_cb data_cb,
|
||||||
void *payload)
|
void *payload)
|
||||||
{
|
{
|
||||||
GIT_UNUSED(opts);
|
GIT_UNUSED(opts);
|
||||||
@ -1036,7 +948,7 @@ static void diff_output_init(
|
|||||||
out->payload = payload;
|
out->payload = payload;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void diff_output_to_patch(git_diff_output *out, git_diff_patch *patch)
|
static void diff_output_to_patch(git_diff_output *out, git_patch *patch)
|
||||||
{
|
{
|
||||||
diff_output_init(
|
diff_output_init(
|
||||||
out, NULL,
|
out, NULL,
|
||||||
|
@ -11,19 +11,20 @@
|
|||||||
#include "diff.h"
|
#include "diff.h"
|
||||||
#include "diff_file.h"
|
#include "diff_file.h"
|
||||||
#include "array.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_patch__old_data(char **, size_t *, git_patch *);
|
||||||
extern void git_diff_patch__new_data(char **, size_t *, git_diff_patch *);
|
extern void git_patch__new_data(char **, size_t *, git_patch *);
|
||||||
|
|
||||||
extern int git_diff_patch__invoke_callbacks(
|
extern int git_patch__invoke_callbacks(
|
||||||
git_diff_patch *patch,
|
git_patch *patch,
|
||||||
git_diff_file_cb file_cb,
|
git_diff_file_cb file_cb,
|
||||||
git_diff_hunk_cb hunk_cb,
|
git_diff_hunk_cb hunk_cb,
|
||||||
git_diff_data_cb line_cb,
|
git_diff_line_cb line_cb,
|
||||||
void *payload);
|
void *payload);
|
||||||
|
|
||||||
typedef struct git_diff_output git_diff_output;
|
typedef struct git_diff_output git_diff_output;
|
||||||
@ -31,7 +32,7 @@ struct git_diff_output {
|
|||||||
/* these callbacks are issued with the diff data */
|
/* these callbacks are issued with the diff data */
|
||||||
git_diff_file_cb file_cb;
|
git_diff_file_cb file_cb;
|
||||||
git_diff_hunk_cb hunk_cb;
|
git_diff_hunk_cb hunk_cb;
|
||||||
git_diff_data_cb data_cb;
|
git_diff_line_cb data_cb;
|
||||||
void *payload;
|
void *payload;
|
||||||
|
|
||||||
/* this records the actual error in cases where it may be obscured */
|
/* 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.
|
/* 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.
|
* 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
|
#endif
|
||||||
|
241
src/diff_print.c
241
src/diff_print.c
@ -10,23 +10,36 @@
|
|||||||
#include "fileops.h"
|
#include "fileops.h"
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
git_diff_list *diff;
|
git_diff *diff;
|
||||||
git_diff_data_cb print_cb;
|
git_diff_format_t format;
|
||||||
|
git_diff_line_cb print_cb;
|
||||||
void *payload;
|
void *payload;
|
||||||
git_buf *buf;
|
git_buf *buf;
|
||||||
|
uint32_t flags;
|
||||||
int oid_strlen;
|
int oid_strlen;
|
||||||
|
git_diff_line line;
|
||||||
} diff_print_info;
|
} diff_print_info;
|
||||||
|
|
||||||
static int diff_print_info_init(
|
static int diff_print_info_init(
|
||||||
diff_print_info *pi,
|
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_format_t format,
|
||||||
|
git_diff_line_cb cb,
|
||||||
|
void *payload)
|
||||||
{
|
{
|
||||||
pi->diff = diff;
|
pi->diff = diff;
|
||||||
|
pi->format = format;
|
||||||
pi->print_cb = cb;
|
pi->print_cb = cb;
|
||||||
pi->payload = payload;
|
pi->payload = payload;
|
||||||
pi->buf = out;
|
pi->buf = out;
|
||||||
|
|
||||||
if (!diff || !diff->repo)
|
if (diff)
|
||||||
|
pi->flags = diff->opts.flags;
|
||||||
|
|
||||||
|
if (diff && diff->opts.oid_abbrev != 0)
|
||||||
|
pi->oid_strlen = diff->opts.oid_abbrev;
|
||||||
|
else if (!diff || !diff->repo)
|
||||||
pi->oid_strlen = GIT_ABBREV_DEFAULT;
|
pi->oid_strlen = GIT_ABBREV_DEFAULT;
|
||||||
else if (git_repository__cvar(
|
else if (git_repository__cvar(
|
||||||
&pi->oid_strlen, diff->repo, GIT_CVAR_ABBREV) < 0)
|
&pi->oid_strlen, diff->repo, GIT_CVAR_ABBREV) < 0)
|
||||||
@ -39,6 +52,11 @@ static int diff_print_info_init(
|
|||||||
else if (pi->oid_strlen > GIT_OID_HEXSZ + 1)
|
else if (pi->oid_strlen > GIT_OID_HEXSZ + 1)
|
||||||
pi->oid_strlen = GIT_OID_HEXSZ + 1;
|
pi->oid_strlen = GIT_OID_HEXSZ + 1;
|
||||||
|
|
||||||
|
memset(&pi->line, 0, sizeof(pi->line));
|
||||||
|
pi->line.old_lineno = -1;
|
||||||
|
pi->line.new_lineno = -1;
|
||||||
|
pi->line.num_lines = 1;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -77,7 +95,35 @@ static int callback_error(void)
|
|||||||
return GIT_EUSER;
|
return GIT_EUSER;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int diff_print_one_compact(
|
static int diff_print_one_name_only(
|
||||||
|
const git_diff_delta *delta, float progress, void *data)
|
||||||
|
{
|
||||||
|
diff_print_info *pi = data;
|
||||||
|
git_buf *out = pi->buf;
|
||||||
|
|
||||||
|
GIT_UNUSED(progress);
|
||||||
|
|
||||||
|
if ((pi->flags & GIT_DIFF_SHOW_UNMODIFIED) == 0 &&
|
||||||
|
delta->status == GIT_DELTA_UNMODIFIED)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
git_buf_clear(out);
|
||||||
|
|
||||||
|
if (git_buf_puts(out, delta->new_file.path) < 0 ||
|
||||||
|
git_buf_putc(out, '\n'))
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
pi->line.origin = GIT_DIFF_LINE_FILE_HDR;
|
||||||
|
pi->line.content = git_buf_cstr(out);
|
||||||
|
pi->line.content_len = git_buf_len(out);
|
||||||
|
|
||||||
|
if (pi->print_cb(delta, NULL, &pi->line, pi->payload))
|
||||||
|
return callback_error();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int diff_print_one_name_status(
|
||||||
const git_diff_delta *delta, float progress, void *data)
|
const git_diff_delta *delta, float progress, void *data)
|
||||||
{
|
{
|
||||||
diff_print_info *pi = data;
|
diff_print_info *pi = data;
|
||||||
@ -88,7 +134,7 @@ static int diff_print_one_compact(
|
|||||||
|
|
||||||
GIT_UNUSED(progress);
|
GIT_UNUSED(progress);
|
||||||
|
|
||||||
if (code == ' ')
|
if ((pi->flags & GIT_DIFF_SHOW_UNMODIFIED) == 0 && code == ' ')
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
old_suffix = diff_pick_suffix(delta->old_file.mode);
|
old_suffix = diff_pick_suffix(delta->old_file.mode);
|
||||||
@ -112,31 +158,16 @@ static int diff_print_one_compact(
|
|||||||
if (git_buf_oom(out))
|
if (git_buf_oom(out))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (pi->print_cb(delta, NULL, GIT_DIFF_LINE_FILE_HDR,
|
pi->line.origin = GIT_DIFF_LINE_FILE_HDR;
|
||||||
git_buf_cstr(out), git_buf_len(out), pi->payload))
|
pi->line.content = git_buf_cstr(out);
|
||||||
|
pi->line.content_len = git_buf_len(out);
|
||||||
|
|
||||||
|
if (pi->print_cb(delta, NULL, &pi->line, pi->payload))
|
||||||
return callback_error();
|
return callback_error();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* print a git_diff_list to a print callback in compact format */
|
|
||||||
int git_diff_print_compact(
|
|
||||||
git_diff_list *diff,
|
|
||||||
git_diff_data_cb print_cb,
|
|
||||||
void *payload)
|
|
||||||
{
|
|
||||||
int error;
|
|
||||||
git_buf buf = GIT_BUF_INIT;
|
|
||||||
diff_print_info pi;
|
|
||||||
|
|
||||||
if (!(error = diff_print_info_init(&pi, &buf, diff, print_cb, payload)))
|
|
||||||
error = git_diff_foreach(diff, diff_print_one_compact, NULL, NULL, &pi);
|
|
||||||
|
|
||||||
git_buf_free(&buf);
|
|
||||||
|
|
||||||
return error;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int diff_print_one_raw(
|
static int diff_print_one_raw(
|
||||||
const git_diff_delta *delta, float progress, void *data)
|
const git_diff_delta *delta, float progress, void *data)
|
||||||
{
|
{
|
||||||
@ -147,7 +178,7 @@ static int diff_print_one_raw(
|
|||||||
|
|
||||||
GIT_UNUSED(progress);
|
GIT_UNUSED(progress);
|
||||||
|
|
||||||
if (code == ' ')
|
if ((pi->flags & GIT_DIFF_SHOW_UNMODIFIED) == 0 && code == ' ')
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
git_buf_clear(out);
|
git_buf_clear(out);
|
||||||
@ -173,31 +204,16 @@ static int diff_print_one_raw(
|
|||||||
if (git_buf_oom(out))
|
if (git_buf_oom(out))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (pi->print_cb(delta, NULL, GIT_DIFF_LINE_FILE_HDR,
|
pi->line.origin = GIT_DIFF_LINE_FILE_HDR;
|
||||||
git_buf_cstr(out), git_buf_len(out), pi->payload))
|
pi->line.content = git_buf_cstr(out);
|
||||||
|
pi->line.content_len = git_buf_len(out);
|
||||||
|
|
||||||
|
if (pi->print_cb(delta, NULL, &pi->line, pi->payload))
|
||||||
return callback_error();
|
return callback_error();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* print a git_diff_list to a print callback in raw output format */
|
|
||||||
int git_diff_print_raw(
|
|
||||||
git_diff_list *diff,
|
|
||||||
git_diff_data_cb print_cb,
|
|
||||||
void *payload)
|
|
||||||
{
|
|
||||||
int error;
|
|
||||||
git_buf buf = GIT_BUF_INIT;
|
|
||||||
diff_print_info pi;
|
|
||||||
|
|
||||||
if (!(error = diff_print_info_init(&pi, &buf, diff, print_cb, payload)))
|
|
||||||
error = git_diff_foreach(diff, diff_print_one_raw, NULL, NULL, &pi);
|
|
||||||
|
|
||||||
git_buf_free(&buf);
|
|
||||||
|
|
||||||
return error;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int diff_print_oid_range(
|
static int diff_print_oid_range(
|
||||||
git_buf *out, const git_diff_delta *delta, int oid_strlen)
|
git_buf *out, const git_diff_delta *delta, int oid_strlen)
|
||||||
{
|
{
|
||||||
@ -287,7 +303,6 @@ static int diff_print_patch_file(
|
|||||||
pi->diff ? pi->diff->opts.old_prefix : DIFF_OLD_PREFIX_DEFAULT;
|
pi->diff ? pi->diff->opts.old_prefix : DIFF_OLD_PREFIX_DEFAULT;
|
||||||
const char *newpfx =
|
const char *newpfx =
|
||||||
pi->diff ? pi->diff->opts.new_prefix : DIFF_NEW_PREFIX_DEFAULT;
|
pi->diff ? pi->diff->opts.new_prefix : DIFF_NEW_PREFIX_DEFAULT;
|
||||||
uint32_t opts_flags = pi->diff ? pi->diff->opts.flags : GIT_DIFF_NORMAL;
|
|
||||||
|
|
||||||
GIT_UNUSED(progress);
|
GIT_UNUSED(progress);
|
||||||
|
|
||||||
@ -295,15 +310,18 @@ static int diff_print_patch_file(
|
|||||||
delta->status == GIT_DELTA_UNMODIFIED ||
|
delta->status == GIT_DELTA_UNMODIFIED ||
|
||||||
delta->status == GIT_DELTA_IGNORED ||
|
delta->status == GIT_DELTA_IGNORED ||
|
||||||
(delta->status == GIT_DELTA_UNTRACKED &&
|
(delta->status == GIT_DELTA_UNTRACKED &&
|
||||||
(opts_flags & GIT_DIFF_INCLUDE_UNTRACKED_CONTENT) == 0))
|
(pi->flags & GIT_DIFF_SHOW_UNTRACKED_CONTENT) == 0))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (git_diff_delta__format_file_header(
|
if (git_diff_delta__format_file_header(
|
||||||
pi->buf, delta, oldpfx, newpfx, pi->oid_strlen) < 0)
|
pi->buf, delta, oldpfx, newpfx, pi->oid_strlen) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (pi->print_cb(delta, NULL, GIT_DIFF_LINE_FILE_HDR,
|
pi->line.origin = GIT_DIFF_LINE_FILE_HDR;
|
||||||
git_buf_cstr(pi->buf), git_buf_len(pi->buf), pi->payload))
|
pi->line.content = git_buf_cstr(pi->buf);
|
||||||
|
pi->line.content_len = git_buf_len(pi->buf);
|
||||||
|
|
||||||
|
if (pi->print_cb(delta, NULL, &pi->line, pi->payload))
|
||||||
return callback_error();
|
return callback_error();
|
||||||
|
|
||||||
if ((delta->flags & GIT_DIFF_FLAG_BINARY) == 0)
|
if ((delta->flags & GIT_DIFF_FLAG_BINARY) == 0)
|
||||||
@ -316,8 +334,12 @@ static int diff_print_patch_file(
|
|||||||
"Binary files %s%s and %s%s differ\n") < 0)
|
"Binary files %s%s and %s%s differ\n") < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (pi->print_cb(delta, NULL, GIT_DIFF_LINE_BINARY,
|
pi->line.origin = GIT_DIFF_LINE_BINARY;
|
||||||
git_buf_cstr(pi->buf), git_buf_len(pi->buf), pi->payload))
|
pi->line.content = git_buf_cstr(pi->buf);
|
||||||
|
pi->line.content_len = git_buf_len(pi->buf);
|
||||||
|
pi->line.num_lines = 1;
|
||||||
|
|
||||||
|
if (pi->print_cb(delta, NULL, &pi->line, pi->payload))
|
||||||
return callback_error();
|
return callback_error();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@ -325,9 +347,7 @@ static int diff_print_patch_file(
|
|||||||
|
|
||||||
static int diff_print_patch_hunk(
|
static int diff_print_patch_hunk(
|
||||||
const git_diff_delta *d,
|
const git_diff_delta *d,
|
||||||
const git_diff_range *r,
|
const git_diff_hunk *h,
|
||||||
const char *header,
|
|
||||||
size_t header_len,
|
|
||||||
void *data)
|
void *data)
|
||||||
{
|
{
|
||||||
diff_print_info *pi = data;
|
diff_print_info *pi = data;
|
||||||
@ -335,12 +355,11 @@ static int diff_print_patch_hunk(
|
|||||||
if (S_ISDIR(d->new_file.mode))
|
if (S_ISDIR(d->new_file.mode))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
git_buf_clear(pi->buf);
|
pi->line.origin = GIT_DIFF_LINE_HUNK_HDR;
|
||||||
if (git_buf_put(pi->buf, header, header_len) < 0)
|
pi->line.content = h->header;
|
||||||
return -1;
|
pi->line.content_len = h->header_len;
|
||||||
|
|
||||||
if (pi->print_cb(d, r, GIT_DIFF_LINE_HUNK_HDR,
|
if (pi->print_cb(d, h, &pi->line, pi->payload))
|
||||||
git_buf_cstr(pi->buf), git_buf_len(pi->buf), pi->payload))
|
|
||||||
return callback_error();
|
return callback_error();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@ -348,10 +367,8 @@ static int diff_print_patch_hunk(
|
|||||||
|
|
||||||
static int diff_print_patch_line(
|
static int diff_print_patch_line(
|
||||||
const git_diff_delta *delta,
|
const git_diff_delta *delta,
|
||||||
const git_diff_range *range,
|
const git_diff_hunk *hunk,
|
||||||
char line_origin, /* GIT_DIFF_LINE value from above */
|
const git_diff_line *line,
|
||||||
const char *content,
|
|
||||||
size_t content_len,
|
|
||||||
void *data)
|
void *data)
|
||||||
{
|
{
|
||||||
diff_print_info *pi = data;
|
diff_print_info *pi = data;
|
||||||
@ -359,50 +376,63 @@ static int diff_print_patch_line(
|
|||||||
if (S_ISDIR(delta->new_file.mode))
|
if (S_ISDIR(delta->new_file.mode))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
git_buf_clear(pi->buf);
|
if (pi->print_cb(delta, hunk, line, pi->payload))
|
||||||
git_buf_grow(pi->buf, content_len + 2);
|
|
||||||
|
|
||||||
if (line_origin == GIT_DIFF_LINE_ADDITION ||
|
|
||||||
line_origin == GIT_DIFF_LINE_DELETION ||
|
|
||||||
line_origin == GIT_DIFF_LINE_CONTEXT)
|
|
||||||
git_buf_putc(pi->buf, line_origin);
|
|
||||||
|
|
||||||
git_buf_put(pi->buf, content, content_len);
|
|
||||||
|
|
||||||
if (git_buf_oom(pi->buf))
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
if (pi->print_cb(delta, range, line_origin,
|
|
||||||
git_buf_cstr(pi->buf), git_buf_len(pi->buf), pi->payload))
|
|
||||||
return callback_error();
|
return callback_error();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* print a git_diff_list to an output callback in patch format */
|
/* print a git_diff to an output callback */
|
||||||
int git_diff_print_patch(
|
int git_diff_print(
|
||||||
git_diff_list *diff,
|
git_diff *diff,
|
||||||
git_diff_data_cb print_cb,
|
git_diff_format_t format,
|
||||||
|
git_diff_line_cb print_cb,
|
||||||
void *payload)
|
void *payload)
|
||||||
{
|
{
|
||||||
int error;
|
int error;
|
||||||
git_buf buf = GIT_BUF_INIT;
|
git_buf buf = GIT_BUF_INIT;
|
||||||
diff_print_info pi;
|
diff_print_info pi;
|
||||||
|
git_diff_file_cb print_file = NULL;
|
||||||
|
git_diff_hunk_cb print_hunk = NULL;
|
||||||
|
git_diff_line_cb print_line = NULL;
|
||||||
|
|
||||||
if (!(error = diff_print_info_init(&pi, &buf, diff, print_cb, payload)))
|
switch (format) {
|
||||||
|
case GIT_DIFF_FORMAT_PATCH:
|
||||||
|
print_file = diff_print_patch_file;
|
||||||
|
print_hunk = diff_print_patch_hunk;
|
||||||
|
print_line = diff_print_patch_line;
|
||||||
|
break;
|
||||||
|
case GIT_DIFF_FORMAT_PATCH_HEADER:
|
||||||
|
print_file = diff_print_patch_file;
|
||||||
|
break;
|
||||||
|
case GIT_DIFF_FORMAT_RAW:
|
||||||
|
print_file = diff_print_one_raw;
|
||||||
|
break;
|
||||||
|
case GIT_DIFF_FORMAT_NAME_ONLY:
|
||||||
|
print_file = diff_print_one_name_only;
|
||||||
|
break;
|
||||||
|
case GIT_DIFF_FORMAT_NAME_STATUS:
|
||||||
|
print_file = diff_print_one_name_status;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
giterr_set(GITERR_INVALID, "Unknown diff output format (%d)", format);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!(error = diff_print_info_init(
|
||||||
|
&pi, &buf, diff, format, print_cb, payload)))
|
||||||
error = git_diff_foreach(
|
error = git_diff_foreach(
|
||||||
diff, diff_print_patch_file, diff_print_patch_hunk,
|
diff, print_file, print_hunk, print_line, &pi);
|
||||||
diff_print_patch_line, &pi);
|
|
||||||
|
|
||||||
git_buf_free(&buf);
|
git_buf_free(&buf);
|
||||||
|
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* print a git_diff_patch to an output callback */
|
/* print a git_patch to an output callback */
|
||||||
int git_diff_patch_print(
|
int git_patch_print(
|
||||||
git_diff_patch *patch,
|
git_patch *patch,
|
||||||
git_diff_data_cb print_cb,
|
git_diff_line_cb print_cb,
|
||||||
void *payload)
|
void *payload)
|
||||||
{
|
{
|
||||||
int error;
|
int error;
|
||||||
@ -412,8 +442,9 @@ int git_diff_patch_print(
|
|||||||
assert(patch && print_cb);
|
assert(patch && print_cb);
|
||||||
|
|
||||||
if (!(error = diff_print_info_init(
|
if (!(error = diff_print_info_init(
|
||||||
&pi, &temp, git_diff_patch__diff(patch), print_cb, payload)))
|
&pi, &temp, git_patch__diff(patch),
|
||||||
error = git_diff_patch__invoke_callbacks(
|
GIT_DIFF_FORMAT_PATCH, print_cb, payload)))
|
||||||
|
error = git_patch__invoke_callbacks(
|
||||||
patch, diff_print_patch_file, diff_print_patch_hunk,
|
patch, diff_print_patch_file, diff_print_patch_hunk,
|
||||||
diff_print_patch_line, &pi);
|
diff_print_patch_line, &pi);
|
||||||
|
|
||||||
@ -424,26 +455,30 @@ int git_diff_patch_print(
|
|||||||
|
|
||||||
static int diff_print_to_buffer_cb(
|
static int diff_print_to_buffer_cb(
|
||||||
const git_diff_delta *delta,
|
const git_diff_delta *delta,
|
||||||
const git_diff_range *range,
|
const git_diff_hunk *hunk,
|
||||||
char line_origin,
|
const git_diff_line *line,
|
||||||
const char *content,
|
|
||||||
size_t content_len,
|
|
||||||
void *payload)
|
void *payload)
|
||||||
{
|
{
|
||||||
git_buf *output = payload;
|
git_buf *output = payload;
|
||||||
GIT_UNUSED(delta); GIT_UNUSED(range); GIT_UNUSED(line_origin);
|
GIT_UNUSED(delta); GIT_UNUSED(hunk);
|
||||||
return git_buf_put(output, content, content_len);
|
|
||||||
|
if (line->origin == GIT_DIFF_LINE_ADDITION ||
|
||||||
|
line->origin == GIT_DIFF_LINE_DELETION ||
|
||||||
|
line->origin == GIT_DIFF_LINE_CONTEXT)
|
||||||
|
git_buf_putc(output, line->origin);
|
||||||
|
|
||||||
|
return git_buf_put(output, line->content, line->content_len);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* print a git_diff_patch to a string buffer */
|
/* print a git_patch to a string buffer */
|
||||||
int git_diff_patch_to_str(
|
int git_patch_to_str(
|
||||||
char **string,
|
char **string,
|
||||||
git_diff_patch *patch)
|
git_patch *patch)
|
||||||
{
|
{
|
||||||
int error;
|
int error;
|
||||||
git_buf output = GIT_BUF_INIT;
|
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,
|
/* GIT_EUSER means git_buf_put in print_to_buffer_cb returned -1,
|
||||||
* meaning a memory allocation failure, so just map to -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(
|
int git_diff_merge(
|
||||||
git_diff_list *onto,
|
git_diff *onto,
|
||||||
const git_diff_list *from)
|
const git_diff *from)
|
||||||
{
|
{
|
||||||
int error = 0;
|
int error = 0;
|
||||||
git_pool onto_pool;
|
git_pool onto_pool;
|
||||||
@ -117,15 +117,15 @@ int git_diff_merge(
|
|||||||
git_pool_init(&onto_pool, 1, 0) < 0)
|
git_pool_init(&onto_pool, 1, 0) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if ((onto->opts.flags & GIT_DIFF_DELTAS_ARE_ICASE) != 0 ||
|
if ((onto->opts.flags & GIT_DIFF_IGNORE_CASE) != 0 ||
|
||||||
(from->opts.flags & GIT_DIFF_DELTAS_ARE_ICASE) != 0)
|
(from->opts.flags & GIT_DIFF_IGNORE_CASE) != 0)
|
||||||
{
|
{
|
||||||
ignore_case = true;
|
ignore_case = true;
|
||||||
|
|
||||||
/* This function currently only supports merging diff lists that
|
/* This function currently only supports merging diff lists that
|
||||||
* are sorted identically. */
|
* are sorted identically. */
|
||||||
assert((onto->opts.flags & GIT_DIFF_DELTAS_ARE_ICASE) != 0 &&
|
assert((onto->opts.flags & GIT_DIFF_IGNORE_CASE) != 0 &&
|
||||||
(from->opts.flags & GIT_DIFF_DELTAS_ARE_ICASE) != 0);
|
(from->opts.flags & GIT_DIFF_IGNORE_CASE) != 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0, j = 0; i < onto->deltas.length || j < from->deltas.length; ) {
|
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
|
#define DEFAULT_RENAME_LIMIT 200
|
||||||
|
|
||||||
static int normalize_find_opts(
|
static int normalize_find_opts(
|
||||||
git_diff_list *diff,
|
git_diff *diff,
|
||||||
git_diff_find_options *opts,
|
git_diff_find_options *opts,
|
||||||
git_diff_find_options *given)
|
const git_diff_find_options *given)
|
||||||
{
|
{
|
||||||
git_config *cfg = NULL;
|
git_config *cfg = NULL;
|
||||||
|
|
||||||
@ -328,7 +328,7 @@ static int normalize_find_opts(
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int apply_splits_and_deletes(
|
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;
|
git_vector onto = GIT_VECTOR_INIT;
|
||||||
size_t i;
|
size_t i;
|
||||||
@ -350,6 +350,7 @@ static int apply_splits_and_deletes(
|
|||||||
goto on_error;
|
goto on_error;
|
||||||
|
|
||||||
deleted->status = GIT_DELTA_DELETED;
|
deleted->status = GIT_DELTA_DELETED;
|
||||||
|
deleted->nfiles = 1;
|
||||||
memset(&deleted->new_file, 0, sizeof(deleted->new_file));
|
memset(&deleted->new_file, 0, sizeof(deleted->new_file));
|
||||||
deleted->new_file.path = deleted->old_file.path;
|
deleted->new_file.path = deleted->old_file.path;
|
||||||
deleted->new_file.flags |= GIT_DIFF_FLAG_VALID_OID;
|
deleted->new_file.flags |= GIT_DIFF_FLAG_VALID_OID;
|
||||||
@ -361,6 +362,7 @@ static int apply_splits_and_deletes(
|
|||||||
delta->status = GIT_DELTA_UNTRACKED;
|
delta->status = GIT_DELTA_UNTRACKED;
|
||||||
else
|
else
|
||||||
delta->status = GIT_DELTA_ADDED;
|
delta->status = GIT_DELTA_ADDED;
|
||||||
|
delta->nfiles = 1;
|
||||||
memset(&delta->old_file, 0, sizeof(delta->old_file));
|
memset(&delta->old_file, 0, sizeof(delta->old_file));
|
||||||
delta->old_file.path = delta->new_file.path;
|
delta->old_file.path = delta->new_file.path;
|
||||||
delta->old_file.flags |= GIT_DIFF_FLAG_VALID_OID;
|
delta->old_file.flags |= GIT_DIFF_FLAG_VALID_OID;
|
||||||
@ -402,7 +404,7 @@ on_error:
|
|||||||
return -1;
|
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);
|
git_diff_delta *delta = git_vector_get(&diff->deltas, idx / 2);
|
||||||
return (idx & 1) ? &delta->new_file : &delta->old_file;
|
return (idx & 1) ? &delta->new_file : &delta->old_file;
|
||||||
@ -419,7 +421,7 @@ typedef struct {
|
|||||||
} similarity_info;
|
} similarity_info;
|
||||||
|
|
||||||
static int similarity_init(
|
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->idx = file_idx;
|
||||||
info->src = (file_idx & 1) ? diff->new_src : diff->old_src;
|
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(
|
static int similarity_measure(
|
||||||
int *score,
|
int *score,
|
||||||
git_diff_list *diff,
|
git_diff *diff,
|
||||||
const git_diff_find_options *opts,
|
const git_diff_find_options *opts,
|
||||||
void **cache,
|
void **cache,
|
||||||
size_t a_idx,
|
size_t a_idx,
|
||||||
@ -595,7 +597,7 @@ cleanup:
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int calc_self_similarity(
|
static int calc_self_similarity(
|
||||||
git_diff_list *diff,
|
git_diff *diff,
|
||||||
const git_diff_find_options *opts,
|
const git_diff_find_options *opts,
|
||||||
size_t delta_idx,
|
size_t delta_idx,
|
||||||
void **cache)
|
void **cache)
|
||||||
@ -612,7 +614,7 @@ static int calc_self_similarity(
|
|||||||
return error;
|
return error;
|
||||||
|
|
||||||
if (similarity >= 0) {
|
if (similarity >= 0) {
|
||||||
delta->similarity = (uint32_t)similarity;
|
delta->similarity = (uint16_t)similarity;
|
||||||
delta->flags |= GIT_DIFF_FLAG__HAS_SELF_SIMILARITY;
|
delta->flags |= GIT_DIFF_FLAG__HAS_SELF_SIMILARITY;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -620,7 +622,7 @@ static int calc_self_similarity(
|
|||||||
}
|
}
|
||||||
|
|
||||||
static bool is_rename_target(
|
static bool is_rename_target(
|
||||||
git_diff_list *diff,
|
git_diff *diff,
|
||||||
const git_diff_find_options *opts,
|
const git_diff_find_options *opts,
|
||||||
size_t delta_idx,
|
size_t delta_idx,
|
||||||
void **cache)
|
void **cache)
|
||||||
@ -675,7 +677,7 @@ static bool is_rename_target(
|
|||||||
}
|
}
|
||||||
|
|
||||||
static bool is_rename_source(
|
static bool is_rename_source(
|
||||||
git_diff_list *diff,
|
git_diff *diff,
|
||||||
const git_diff_find_options *opts,
|
const git_diff_find_options *opts,
|
||||||
size_t delta_idx,
|
size_t delta_idx,
|
||||||
void **cache)
|
void **cache)
|
||||||
@ -745,25 +747,27 @@ GIT_INLINE(bool) delta_is_new_only(git_diff_delta *delta)
|
|||||||
}
|
}
|
||||||
|
|
||||||
GIT_INLINE(void) delta_make_rename(
|
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->status = GIT_DELTA_RENAMED;
|
||||||
to->similarity = similarity;
|
to->similarity = similarity;
|
||||||
|
to->nfiles = 2;
|
||||||
memcpy(&to->old_file, &from->old_file, sizeof(to->old_file));
|
memcpy(&to->old_file, &from->old_file, sizeof(to->old_file));
|
||||||
to->flags &= ~GIT_DIFF_FLAG__TO_SPLIT;
|
to->flags &= ~GIT_DIFF_FLAG__TO_SPLIT;
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint32_t idx;
|
size_t idx;
|
||||||
uint32_t similarity;
|
uint16_t similarity;
|
||||||
} diff_find_match;
|
} diff_find_match;
|
||||||
|
|
||||||
int git_diff_find_similar(
|
int git_diff_find_similar(
|
||||||
git_diff_list *diff,
|
git_diff *diff,
|
||||||
git_diff_find_options *given_opts)
|
const git_diff_find_options *given_opts)
|
||||||
{
|
{
|
||||||
size_t s, t;
|
size_t s, t;
|
||||||
int error = 0, similarity;
|
int error = 0, result;
|
||||||
|
uint16_t similarity;
|
||||||
git_diff_delta *src, *tgt;
|
git_diff_delta *src, *tgt;
|
||||||
git_diff_find_options opts;
|
git_diff_find_options opts;
|
||||||
size_t num_deltas, num_srcs = 0, num_tgts = 0;
|
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 */
|
/* calculate similarity for this pair and find best match */
|
||||||
if (s == t)
|
if (s == t)
|
||||||
similarity = -1; /* don't measure self-similarity here */
|
result = -1; /* don't measure self-similarity here */
|
||||||
else if ((error = similarity_measure(
|
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;
|
goto cleanup;
|
||||||
|
|
||||||
if (similarity < 0)
|
if (result < 0)
|
||||||
continue;
|
continue;
|
||||||
|
similarity = (uint16_t)result;
|
||||||
|
|
||||||
/* is this a better rename? */
|
/* is this a better rename? */
|
||||||
if (tgt2src[t].similarity < (uint32_t)similarity &&
|
if (tgt2src[t].similarity < similarity &&
|
||||||
src2tgt[s].similarity < (uint32_t)similarity)
|
src2tgt[s].similarity < similarity)
|
||||||
{
|
{
|
||||||
/* eject old mapping */
|
/* eject old mapping */
|
||||||
if (src2tgt[s].similarity > 0) {
|
if (src2tgt[s].similarity > 0) {
|
||||||
@ -862,18 +867,18 @@ find_best_matches:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* write new mapping */
|
/* write new mapping */
|
||||||
tgt2src[t].idx = (uint32_t)s;
|
tgt2src[t].idx = s;
|
||||||
tgt2src[t].similarity = (uint32_t)similarity;
|
tgt2src[t].similarity = similarity;
|
||||||
src2tgt[s].idx = (uint32_t)t;
|
src2tgt[s].idx = t;
|
||||||
src2tgt[s].similarity = (uint32_t)similarity;
|
src2tgt[s].similarity = similarity;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* keep best absolute match for copies */
|
/* keep best absolute match for copies */
|
||||||
if (tgt2src_copy != NULL &&
|
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].idx = s;
|
||||||
tgt2src_copy[t].similarity = (uint32_t)similarity;
|
tgt2src_copy[t].similarity = similarity;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (++tried_srcs >= num_srcs)
|
if (++tried_srcs >= num_srcs)
|
||||||
@ -943,7 +948,7 @@ find_best_matches:
|
|||||||
delta_make_rename(tgt, src, best_match->similarity);
|
delta_make_rename(tgt, src, best_match->similarity);
|
||||||
num_rewrites--;
|
num_rewrites--;
|
||||||
|
|
||||||
src->status = GIT_DELTA_DELETED;
|
assert(src->status == GIT_DELTA_DELETED);
|
||||||
memcpy(&src->old_file, &swap, sizeof(src->old_file));
|
memcpy(&src->old_file, &swap, sizeof(src->old_file));
|
||||||
memset(&src->new_file, 0, sizeof(src->new_file));
|
memset(&src->new_file, 0, sizeof(src->new_file));
|
||||||
src->new_file.path = src->old_file.path;
|
src->new_file.path = src->old_file.path;
|
||||||
@ -953,7 +958,7 @@ find_best_matches:
|
|||||||
|
|
||||||
if (src2tgt[t].similarity > 0 && src2tgt[t].idx > t) {
|
if (src2tgt[t].similarity > 0 && src2tgt[t].idx > t) {
|
||||||
/* what used to be at src t is now at src s */
|
/* 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) ?
|
src->status = (diff->new_src == GIT_ITERATOR_TYPE_WORKDIR) ?
|
||||||
GIT_DELTA_UNTRACKED : GIT_DELTA_ADDED;
|
GIT_DELTA_UNTRACKED : GIT_DELTA_ADDED;
|
||||||
|
src->nfiles = 1;
|
||||||
memset(&src->old_file, 0, sizeof(src->old_file));
|
memset(&src->old_file, 0, sizeof(src->old_file));
|
||||||
src->old_file.path = src->new_file.path;
|
src->old_file.path = src->new_file.path;
|
||||||
src->old_file.flags |= GIT_DIFF_FLAG_VALID_OID;
|
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 */
|
/* otherwise, if we just overwrote a source, update mapping */
|
||||||
else if (src2tgt[t].similarity > 0 && src2tgt[t].idx > t) {
|
else if (src2tgt[t].similarity > 0 && src2tgt[t].idx > t) {
|
||||||
/* what used to be at src t is now at src s */
|
/* 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++;
|
num_updates++;
|
||||||
@ -1026,6 +1032,7 @@ find_best_matches:
|
|||||||
|
|
||||||
tgt->status = GIT_DELTA_COPIED;
|
tgt->status = GIT_DELTA_COPIED;
|
||||||
tgt->similarity = best_match->similarity;
|
tgt->similarity = best_match->similarity;
|
||||||
|
tgt->nfiles = 2;
|
||||||
memcpy(&tgt->old_file, &src->old_file, sizeof(tgt->old_file));
|
memcpy(&tgt->old_file, &src->old_file, sizeof(tgt->old_file));
|
||||||
|
|
||||||
num_updates++;
|
num_updates++;
|
||||||
|
122
src/diff_xdiff.c
122
src/diff_xdiff.c
@ -24,26 +24,26 @@ static int git_xdiff_scan_int(const char **str, int *value)
|
|||||||
return (digits > 0) ? 0 : -1;
|
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] @@" */
|
/* expect something of the form "@@ -%d[,%d] +%d[,%d] @@" */
|
||||||
if (*header != '@')
|
if (*header != '@')
|
||||||
return -1;
|
return -1;
|
||||||
if (git_xdiff_scan_int(&header, &range->old_start) < 0)
|
if (git_xdiff_scan_int(&header, &hunk->old_start) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
if (*header == ',') {
|
if (*header == ',') {
|
||||||
if (git_xdiff_scan_int(&header, &range->old_lines) < 0)
|
if (git_xdiff_scan_int(&header, &hunk->old_lines) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
} else
|
} else
|
||||||
range->old_lines = 1;
|
hunk->old_lines = 1;
|
||||||
if (git_xdiff_scan_int(&header, &range->new_start) < 0)
|
if (git_xdiff_scan_int(&header, &hunk->new_start) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
if (*header == ',') {
|
if (*header == ',') {
|
||||||
if (git_xdiff_scan_int(&header, &range->new_lines) < 0)
|
if (git_xdiff_scan_int(&header, &hunk->new_lines) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
} else
|
} else
|
||||||
range->new_lines = 1;
|
hunk->new_lines = 1;
|
||||||
if (range->old_start < 0 || range->new_start < 0)
|
if (hunk->old_start < 0 || hunk->new_start < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@ -51,38 +51,96 @@ static int git_xdiff_parse_hunk(git_diff_range *range, const char *header)
|
|||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
git_xdiff_output *xo;
|
git_xdiff_output *xo;
|
||||||
git_diff_patch *patch;
|
git_patch *patch;
|
||||||
git_diff_range range;
|
git_diff_hunk hunk;
|
||||||
|
int old_lineno, new_lineno;
|
||||||
} git_xdiff_info;
|
} 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)
|
static int git_xdiff_cb(void *priv, mmbuffer_t *bufs, int len)
|
||||||
{
|
{
|
||||||
git_xdiff_info *info = priv;
|
git_xdiff_info *info = priv;
|
||||||
git_diff_patch *patch = info->patch;
|
git_patch *patch = info->patch;
|
||||||
const git_diff_delta *delta = git_diff_patch_delta(patch);
|
const git_diff_delta *delta = git_patch_get_delta(patch);
|
||||||
git_diff_output *output = &info->xo->output;
|
git_diff_output *output = &info->xo->output;
|
||||||
|
git_diff_line line;
|
||||||
|
|
||||||
if (len == 1) {
|
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)
|
if (output->error < 0)
|
||||||
return output->error;
|
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 &&
|
if (output->hunk_cb != NULL &&
|
||||||
output->hunk_cb(delta, &info->range,
|
output->hunk_cb(delta, &info->hunk, output->payload))
|
||||||
bufs[0].ptr, bufs[0].size, output->payload))
|
|
||||||
output->error = GIT_EUSER;
|
output->error = GIT_EUSER;
|
||||||
|
|
||||||
|
info->old_lineno = info->hunk.old_start;
|
||||||
|
info->new_lineno = info->hunk.new_start;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (len == 2 || len == 3) {
|
if (len == 2 || len == 3) {
|
||||||
/* expect " "/"-"/"+", then data */
|
/* expect " "/"-"/"+", then data */
|
||||||
char origin =
|
line.origin =
|
||||||
(*bufs[0].ptr == '+') ? GIT_DIFF_LINE_ADDITION :
|
(*bufs[0].ptr == '+') ? GIT_DIFF_LINE_ADDITION :
|
||||||
(*bufs[0].ptr == '-') ? GIT_DIFF_LINE_DELETION :
|
(*bufs[0].ptr == '-') ? GIT_DIFF_LINE_DELETION :
|
||||||
GIT_DIFF_LINE_CONTEXT;
|
GIT_DIFF_LINE_CONTEXT;
|
||||||
|
|
||||||
if (output->data_cb != NULL &&
|
output->error = diff_update_lines(
|
||||||
output->data_cb(delta, &info->range,
|
info, &line, bufs[1].ptr, bufs[1].size);
|
||||||
origin, bufs[1].ptr, bufs[1].size, output->payload))
|
|
||||||
|
if (!output->error &&
|
||||||
|
output->data_cb != NULL &&
|
||||||
|
output->data_cb(delta, &info->hunk, &line, output->payload))
|
||||||
output->error = GIT_EUSER;
|
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
|
* 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.
|
* 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_DEL_EOFNL :
|
||||||
(*bufs[0].ptr == '-') ? GIT_DIFF_LINE_ADD_EOFNL :
|
(*bufs[0].ptr == '-') ? GIT_DIFF_LINE_ADD_EOFNL :
|
||||||
GIT_DIFF_LINE_CONTEXT_EOFNL;
|
GIT_DIFF_LINE_CONTEXT_EOFNL;
|
||||||
|
|
||||||
if (output->data_cb != NULL &&
|
output->error = diff_update_lines(
|
||||||
output->data_cb(delta, &info->range,
|
info, &line, bufs[2].ptr, bufs[2].size);
|
||||||
origin, bufs[2].ptr, bufs[2].size, output->payload))
|
|
||||||
|
if (!output->error &&
|
||||||
|
output->data_cb != NULL &&
|
||||||
|
output->data_cb(delta, &info->hunk, &line, output->payload))
|
||||||
output->error = GIT_EUSER;
|
output->error = GIT_EUSER;
|
||||||
}
|
}
|
||||||
|
|
||||||
return output->error;
|
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_output *xo = (git_xdiff_output *)output;
|
||||||
git_xdiff_info info;
|
git_xdiff_info info;
|
||||||
@ -120,7 +181,7 @@ static int git_xdiff(git_diff_output *output, git_diff_patch *patch)
|
|||||||
xo->callback.priv = &info;
|
xo->callback.priv = &info;
|
||||||
|
|
||||||
git_diff_find_context_init(
|
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;
|
xo->config.find_func_priv = &findctxt;
|
||||||
|
|
||||||
if (xo->config.find_func != NULL)
|
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
|
* updates are needed to xo->params.flags
|
||||||
*/
|
*/
|
||||||
|
|
||||||
git_diff_patch__old_data(&xd_old_data.ptr, &xd_old_data.size, patch);
|
git_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__new_data(&xd_new_data.ptr, &xd_new_data.size, patch);
|
||||||
|
|
||||||
xdl_diff(&xd_old_data, &xd_new_data,
|
xdl_diff(&xd_old_data, &xd_new_data,
|
||||||
&xo->params, &xo->config, &xo->callback);
|
&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)
|
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;
|
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)
|
if (flags & GIT_DIFF_IGNORE_WHITESPACE_EOL)
|
||||||
xo->params.flags |= XDF_IGNORE_WHITESPACE_AT_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));
|
memset(&xo->callback, 0, sizeof(xo->callback));
|
||||||
xo->callback.outf = git_xdiff_cb;
|
xo->callback.outf = git_xdiff_cb;
|
||||||
}
|
}
|
||||||
|
@ -585,7 +585,7 @@ int git_pathspec_match_tree(
|
|||||||
|
|
||||||
int git_pathspec_match_diff(
|
int git_pathspec_match_diff(
|
||||||
git_pathspec_match_list **out,
|
git_pathspec_match_list **out,
|
||||||
git_diff_list *diff,
|
git_diff *diff,
|
||||||
uint32_t flags,
|
uint32_t flags,
|
||||||
git_pathspec *ps)
|
git_pathspec *ps)
|
||||||
{
|
{
|
||||||
|
11
src/reset.c
11
src/reset.c
@ -24,10 +24,9 @@ int git_reset_default(
|
|||||||
{
|
{
|
||||||
git_object *commit = NULL;
|
git_object *commit = NULL;
|
||||||
git_tree *tree = NULL;
|
git_tree *tree = NULL;
|
||||||
git_diff_list *diff = NULL;
|
git_diff *diff = NULL;
|
||||||
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
|
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
|
||||||
size_t i;
|
size_t i, max_i;
|
||||||
git_diff_delta *delta;
|
|
||||||
git_index_entry entry;
|
git_index_entry entry;
|
||||||
int error;
|
int error;
|
||||||
git_index *index = NULL;
|
git_index *index = NULL;
|
||||||
@ -58,7 +57,9 @@ int git_reset_default(
|
|||||||
&diff, repo, tree, index, &opts)) < 0)
|
&diff, repo, tree, index, &opts)) < 0)
|
||||||
goto cleanup;
|
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)
|
if ((error = git_index_conflict_remove(index, delta->old_file.path)) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
@ -85,7 +86,7 @@ cleanup:
|
|||||||
git_object_free(commit);
|
git_object_free(commit);
|
||||||
git_tree_free(tree);
|
git_tree_free(tree);
|
||||||
git_index_free(index);
|
git_index_free(index);
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
|
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
133
src/stash.c
133
src/stash.c
@ -153,65 +153,61 @@ cleanup:
|
|||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct cb_data {
|
struct stash_update_rules {
|
||||||
git_index *index;
|
|
||||||
|
|
||||||
int error;
|
|
||||||
|
|
||||||
bool include_changed;
|
bool include_changed;
|
||||||
bool include_untracked;
|
bool include_untracked;
|
||||||
bool include_ignored;
|
bool include_ignored;
|
||||||
};
|
};
|
||||||
|
|
||||||
static int update_index_cb(
|
static int stash_update_index_from_diff(
|
||||||
const git_diff_delta *delta,
|
git_index *index,
|
||||||
float progress,
|
const git_diff *diff,
|
||||||
void *payload)
|
struct stash_update_rules *data)
|
||||||
{
|
{
|
||||||
struct cb_data *data = (struct cb_data *)payload;
|
int error = 0;
|
||||||
const char *add_path = NULL;
|
size_t d, max_d = git_diff_num_deltas(diff);
|
||||||
|
|
||||||
GIT_UNUSED(progress);
|
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) {
|
switch (delta->status) {
|
||||||
case GIT_DELTA_IGNORED:
|
case GIT_DELTA_IGNORED:
|
||||||
if (data->include_ignored)
|
if (data->include_ignored)
|
||||||
add_path = delta->new_file.path;
|
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)
|
|
||||||
break;
|
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:
|
case GIT_DELTA_UNTRACKED:
|
||||||
/* Unimplemented */
|
if (data->include_untracked)
|
||||||
giterr_set(
|
add_path = delta->new_file.path;
|
||||||
GITERR_INVALID,
|
break;
|
||||||
"Cannot update index. Unimplemented status (%d)",
|
|
||||||
delta->status);
|
case GIT_DELTA_ADDED:
|
||||||
data->error = -1;
|
case GIT_DELTA_MODIFIED:
|
||||||
break;
|
if (data->include_changed)
|
||||||
|
add_path = delta->new_file.path;
|
||||||
|
break;
|
||||||
|
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (add_path != NULL)
|
return error;
|
||||||
data->error = git_index_add_bypath(data->index, add_path);
|
|
||||||
|
|
||||||
return data->error;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int build_untracked_tree(
|
static int build_untracked_tree(
|
||||||
@ -221,15 +217,13 @@ static int build_untracked_tree(
|
|||||||
uint32_t flags)
|
uint32_t flags)
|
||||||
{
|
{
|
||||||
git_tree *i_tree = NULL;
|
git_tree *i_tree = NULL;
|
||||||
git_diff_list *diff = NULL;
|
git_diff *diff = NULL;
|
||||||
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
|
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
|
||||||
struct cb_data data = {0};
|
struct stash_update_rules data = {0};
|
||||||
int error;
|
int error;
|
||||||
|
|
||||||
git_index_clear(index);
|
git_index_clear(index);
|
||||||
|
|
||||||
data.index = index;
|
|
||||||
|
|
||||||
if (flags & GIT_STASH_INCLUDE_UNTRACKED) {
|
if (flags & GIT_STASH_INCLUDE_UNTRACKED) {
|
||||||
opts.flags |= GIT_DIFF_INCLUDE_UNTRACKED |
|
opts.flags |= GIT_DIFF_INCLUDE_UNTRACKED |
|
||||||
GIT_DIFF_RECURSE_UNTRACKED_DIRS;
|
GIT_DIFF_RECURSE_UNTRACKED_DIRS;
|
||||||
@ -248,18 +242,13 @@ static int build_untracked_tree(
|
|||||||
&diff, git_index_owner(index), i_tree, &opts)) < 0)
|
&diff, git_index_owner(index), i_tree, &opts)) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if ((error = git_diff_foreach(
|
if ((error = stash_update_index_from_diff(index, diff, &data)) < 0)
|
||||||
diff, update_index_cb, NULL, NULL, &data)) < 0)
|
|
||||||
{
|
|
||||||
if (error == GIT_EUSER)
|
|
||||||
error = data.error;
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
|
||||||
|
|
||||||
error = build_tree_from_index(tree_out, index);
|
error = build_tree_from_index(tree_out, index);
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
git_tree_free(i_tree);
|
git_tree_free(i_tree);
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
@ -311,9 +300,9 @@ static int build_workdir_tree(
|
|||||||
{
|
{
|
||||||
git_repository *repo = git_index_owner(index);
|
git_repository *repo = git_index_owner(index);
|
||||||
git_tree *b_tree = NULL;
|
git_tree *b_tree = NULL;
|
||||||
git_diff_list *diff = NULL, *diff2 = NULL;
|
git_diff *diff = NULL;
|
||||||
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
|
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
|
||||||
struct cb_data data = {0};
|
struct stash_update_rules data = {0};
|
||||||
int error;
|
int error;
|
||||||
|
|
||||||
opts.flags = GIT_DIFF_IGNORE_SUBMODULES;
|
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)
|
if ((error = git_commit_tree(&b_tree, b_commit)) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if ((error = git_diff_tree_to_index(&diff, repo, b_tree, NULL, &opts)) < 0)
|
if ((error = git_diff_tree_to_workdir_with_index(
|
||||||
|
&diff, repo, b_tree, &opts)) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if ((error = git_diff_index_to_workdir(&diff2, repo, NULL, &opts)) < 0)
|
|
||||||
goto cleanup;
|
|
||||||
|
|
||||||
if ((error = git_diff_merge(diff, diff2)) < 0)
|
|
||||||
goto cleanup;
|
|
||||||
|
|
||||||
data.index = index;
|
|
||||||
data.include_changed = true;
|
data.include_changed = true;
|
||||||
|
|
||||||
if ((error = git_diff_foreach(
|
if ((error = stash_update_index_from_diff(index, diff, &data)) < 0)
|
||||||
diff, update_index_cb, NULL, NULL, &data)) < 0)
|
|
||||||
{
|
|
||||||
if (error == GIT_EUSER)
|
|
||||||
error = data.error;
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
|
||||||
|
|
||||||
|
error = build_tree_from_index(tree_out, index);
|
||||||
if ((error = build_tree_from_index(tree_out, index)) < 0)
|
|
||||||
goto cleanup;
|
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
git_diff_list_free(diff2);
|
|
||||||
git_tree_free(b_tree);
|
git_tree_free(b_tree);
|
||||||
|
|
||||||
return error;
|
return error;
|
||||||
|
@ -52,7 +52,7 @@ static unsigned int index_delta2status(const git_diff_delta *head2idx)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static unsigned int workdir_delta2status(
|
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;
|
git_status_t st = GIT_STATUS_CURRENT;
|
||||||
|
|
||||||
@ -361,8 +361,8 @@ void git_status_list_free(git_status_list *status)
|
|||||||
if (status == NULL)
|
if (status == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
git_diff_list_free(status->head2idx);
|
git_diff_free(status->head2idx);
|
||||||
git_diff_list_free(status->idx2wd);
|
git_diff_free(status->idx2wd);
|
||||||
|
|
||||||
git_vector_foreach(&status->paired, i, status_entry)
|
git_vector_foreach(&status->paired, i, status_entry)
|
||||||
git__free(status_entry);
|
git__free(status_entry);
|
||||||
|
@ -14,8 +14,8 @@
|
|||||||
struct git_status_list {
|
struct git_status_list {
|
||||||
git_status_options opts;
|
git_status_options opts;
|
||||||
|
|
||||||
git_diff_list *head2idx;
|
git_diff *head2idx;
|
||||||
git_diff_list *idx2wd;
|
git_diff *idx2wd;
|
||||||
|
|
||||||
git_vector paired;
|
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;
|
(sm->flags & GIT_SUBMODULE_STATUS__WD_OID_VALID) ? &sm->wd_oid : NULL;
|
||||||
git_tree *sm_head = NULL;
|
git_tree *sm_head = NULL;
|
||||||
git_diff_options opt = GIT_DIFF_OPTIONS_INIT;
|
git_diff_options opt = GIT_DIFF_OPTIONS_INIT;
|
||||||
git_diff_list *diff;
|
git_diff *diff;
|
||||||
|
|
||||||
*status = *status & ~GIT_SUBMODULE_STATUS__WD_FLAGS;
|
*status = *status & ~GIT_SUBMODULE_STATUS__WD_FLAGS;
|
||||||
|
|
||||||
@ -1568,7 +1568,7 @@ static void submodule_get_wd_status(
|
|||||||
else {
|
else {
|
||||||
if (git_diff_num_deltas(diff) > 0)
|
if (git_diff_num_deltas(diff) > 0)
|
||||||
*status |= GIT_SUBMODULE_STATUS_WD_INDEX_MODIFIED;
|
*status |= GIT_SUBMODULE_STATUS_WD_INDEX_MODIFIED;
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
diff = NULL;
|
diff = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1588,7 +1588,7 @@ static void submodule_get_wd_status(
|
|||||||
if (git_diff_num_deltas(diff) != untracked)
|
if (git_diff_num_deltas(diff) != untracked)
|
||||||
*status |= GIT_SUBMODULE_STATUS_WD_WD_MODIFIED;
|
*status |= GIT_SUBMODULE_STATUS_WD_WD_MODIFIED;
|
||||||
|
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
diff = NULL;
|
diff = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -142,7 +142,7 @@ void test_diff_blob__can_compare_text_blobs_with_patch(void)
|
|||||||
{
|
{
|
||||||
git_blob *a, *b, *c;
|
git_blob *a, *b, *c;
|
||||||
git_oid a_oid, b_oid, c_oid;
|
git_oid a_oid, b_oid, c_oid;
|
||||||
git_diff_patch *p;
|
git_patch *p;
|
||||||
const git_diff_delta *delta;
|
const git_diff_delta *delta;
|
||||||
size_t tc, ta, td;
|
size_t tc, ta, td;
|
||||||
|
|
||||||
@ -161,11 +161,11 @@ void test_diff_blob__can_compare_text_blobs_with_patch(void)
|
|||||||
/* Doing the equivalent of a `git diff -U1` on these files */
|
/* Doing the equivalent of a `git diff -U1` on these files */
|
||||||
|
|
||||||
/* diff on tests/resources/attr/root_test1 */
|
/* diff on tests/resources/attr/root_test1 */
|
||||||
cl_git_pass(git_diff_patch_from_blobs(&p, a, NULL, b, NULL, &opts));
|
cl_git_pass(git_patch_from_blobs(&p, a, NULL, b, NULL, &opts));
|
||||||
|
|
||||||
cl_assert(p != NULL);
|
cl_assert(p != NULL);
|
||||||
|
|
||||||
delta = git_diff_patch_delta(p);
|
delta = git_patch_get_delta(p);
|
||||||
cl_assert(delta != NULL);
|
cl_assert(delta != NULL);
|
||||||
cl_assert_equal_i(GIT_DELTA_MODIFIED, delta->status);
|
cl_assert_equal_i(GIT_DELTA_MODIFIED, delta->status);
|
||||||
cl_assert(git_oid_equal(git_blob_id(a), &delta->old_file.oid));
|
cl_assert(git_oid_equal(git_blob_id(a), &delta->old_file.oid));
|
||||||
@ -173,22 +173,22 @@ void test_diff_blob__can_compare_text_blobs_with_patch(void)
|
|||||||
cl_assert(git_oid_equal(git_blob_id(b), &delta->new_file.oid));
|
cl_assert(git_oid_equal(git_blob_id(b), &delta->new_file.oid));
|
||||||
cl_assert_equal_sz(git_blob_rawsize(b), delta->new_file.size);
|
cl_assert_equal_sz(git_blob_rawsize(b), delta->new_file.size);
|
||||||
|
|
||||||
cl_assert_equal_i(1, (int)git_diff_patch_num_hunks(p));
|
cl_assert_equal_i(1, (int)git_patch_num_hunks(p));
|
||||||
cl_assert_equal_i(6, git_diff_patch_num_lines_in_hunk(p, 0));
|
cl_assert_equal_i(6, git_patch_num_lines_in_hunk(p, 0));
|
||||||
|
|
||||||
cl_git_pass(git_diff_patch_line_stats(&tc, &ta, &td, p));
|
cl_git_pass(git_patch_line_stats(&tc, &ta, &td, p));
|
||||||
cl_assert_equal_i(1, (int)tc);
|
cl_assert_equal_i(1, (int)tc);
|
||||||
cl_assert_equal_i(5, (int)ta);
|
cl_assert_equal_i(5, (int)ta);
|
||||||
cl_assert_equal_i(0, (int)td);
|
cl_assert_equal_i(0, (int)td);
|
||||||
|
|
||||||
git_diff_patch_free(p);
|
git_patch_free(p);
|
||||||
|
|
||||||
/* diff on tests/resources/attr/root_test2 */
|
/* diff on tests/resources/attr/root_test2 */
|
||||||
cl_git_pass(git_diff_patch_from_blobs(&p, b, NULL, c, NULL, &opts));
|
cl_git_pass(git_patch_from_blobs(&p, b, NULL, c, NULL, &opts));
|
||||||
|
|
||||||
cl_assert(p != NULL);
|
cl_assert(p != NULL);
|
||||||
|
|
||||||
delta = git_diff_patch_delta(p);
|
delta = git_patch_get_delta(p);
|
||||||
cl_assert(delta != NULL);
|
cl_assert(delta != NULL);
|
||||||
cl_assert_equal_i(GIT_DELTA_MODIFIED, delta->status);
|
cl_assert_equal_i(GIT_DELTA_MODIFIED, delta->status);
|
||||||
cl_assert(git_oid_equal(git_blob_id(b), &delta->old_file.oid));
|
cl_assert(git_oid_equal(git_blob_id(b), &delta->old_file.oid));
|
||||||
@ -196,22 +196,22 @@ void test_diff_blob__can_compare_text_blobs_with_patch(void)
|
|||||||
cl_assert(git_oid_equal(git_blob_id(c), &delta->new_file.oid));
|
cl_assert(git_oid_equal(git_blob_id(c), &delta->new_file.oid));
|
||||||
cl_assert_equal_sz(git_blob_rawsize(c), delta->new_file.size);
|
cl_assert_equal_sz(git_blob_rawsize(c), delta->new_file.size);
|
||||||
|
|
||||||
cl_assert_equal_i(1, (int)git_diff_patch_num_hunks(p));
|
cl_assert_equal_i(1, (int)git_patch_num_hunks(p));
|
||||||
cl_assert_equal_i(15, git_diff_patch_num_lines_in_hunk(p, 0));
|
cl_assert_equal_i(15, git_patch_num_lines_in_hunk(p, 0));
|
||||||
|
|
||||||
cl_git_pass(git_diff_patch_line_stats(&tc, &ta, &td, p));
|
cl_git_pass(git_patch_line_stats(&tc, &ta, &td, p));
|
||||||
cl_assert_equal_i(3, (int)tc);
|
cl_assert_equal_i(3, (int)tc);
|
||||||
cl_assert_equal_i(9, (int)ta);
|
cl_assert_equal_i(9, (int)ta);
|
||||||
cl_assert_equal_i(3, (int)td);
|
cl_assert_equal_i(3, (int)td);
|
||||||
|
|
||||||
git_diff_patch_free(p);
|
git_patch_free(p);
|
||||||
|
|
||||||
/* diff on tests/resources/attr/root_test3 */
|
/* diff on tests/resources/attr/root_test3 */
|
||||||
cl_git_pass(git_diff_patch_from_blobs(&p, a, NULL, c, NULL, &opts));
|
cl_git_pass(git_patch_from_blobs(&p, a, NULL, c, NULL, &opts));
|
||||||
|
|
||||||
cl_assert(p != NULL);
|
cl_assert(p != NULL);
|
||||||
|
|
||||||
delta = git_diff_patch_delta(p);
|
delta = git_patch_get_delta(p);
|
||||||
cl_assert(delta != NULL);
|
cl_assert(delta != NULL);
|
||||||
cl_assert_equal_i(GIT_DELTA_MODIFIED, delta->status);
|
cl_assert_equal_i(GIT_DELTA_MODIFIED, delta->status);
|
||||||
cl_assert(git_oid_equal(git_blob_id(a), &delta->old_file.oid));
|
cl_assert(git_oid_equal(git_blob_id(a), &delta->old_file.oid));
|
||||||
@ -219,19 +219,19 @@ void test_diff_blob__can_compare_text_blobs_with_patch(void)
|
|||||||
cl_assert(git_oid_equal(git_blob_id(c), &delta->new_file.oid));
|
cl_assert(git_oid_equal(git_blob_id(c), &delta->new_file.oid));
|
||||||
cl_assert_equal_sz(git_blob_rawsize(c), delta->new_file.size);
|
cl_assert_equal_sz(git_blob_rawsize(c), delta->new_file.size);
|
||||||
|
|
||||||
cl_git_pass(git_diff_patch_line_stats(&tc, &ta, &td, p));
|
cl_git_pass(git_patch_line_stats(&tc, &ta, &td, p));
|
||||||
cl_assert_equal_i(0, (int)tc);
|
cl_assert_equal_i(0, (int)tc);
|
||||||
cl_assert_equal_i(12, (int)ta);
|
cl_assert_equal_i(12, (int)ta);
|
||||||
cl_assert_equal_i(1, (int)td);
|
cl_assert_equal_i(1, (int)td);
|
||||||
|
|
||||||
git_diff_patch_free(p);
|
git_patch_free(p);
|
||||||
|
|
||||||
/* one more */
|
/* one more */
|
||||||
cl_git_pass(git_diff_patch_from_blobs(&p, c, NULL, d, NULL, &opts));
|
cl_git_pass(git_patch_from_blobs(&p, c, NULL, d, NULL, &opts));
|
||||||
|
|
||||||
cl_assert(p != NULL);
|
cl_assert(p != NULL);
|
||||||
|
|
||||||
delta = git_diff_patch_delta(p);
|
delta = git_patch_get_delta(p);
|
||||||
cl_assert(delta != NULL);
|
cl_assert(delta != NULL);
|
||||||
cl_assert_equal_i(GIT_DELTA_MODIFIED, delta->status);
|
cl_assert_equal_i(GIT_DELTA_MODIFIED, delta->status);
|
||||||
cl_assert(git_oid_equal(git_blob_id(c), &delta->old_file.oid));
|
cl_assert(git_oid_equal(git_blob_id(c), &delta->old_file.oid));
|
||||||
@ -239,16 +239,16 @@ void test_diff_blob__can_compare_text_blobs_with_patch(void)
|
|||||||
cl_assert(git_oid_equal(git_blob_id(d), &delta->new_file.oid));
|
cl_assert(git_oid_equal(git_blob_id(d), &delta->new_file.oid));
|
||||||
cl_assert_equal_sz(git_blob_rawsize(d), delta->new_file.size);
|
cl_assert_equal_sz(git_blob_rawsize(d), delta->new_file.size);
|
||||||
|
|
||||||
cl_assert_equal_i(2, (int)git_diff_patch_num_hunks(p));
|
cl_assert_equal_i(2, (int)git_patch_num_hunks(p));
|
||||||
cl_assert_equal_i(5, git_diff_patch_num_lines_in_hunk(p, 0));
|
cl_assert_equal_i(5, git_patch_num_lines_in_hunk(p, 0));
|
||||||
cl_assert_equal_i(9, git_diff_patch_num_lines_in_hunk(p, 1));
|
cl_assert_equal_i(9, git_patch_num_lines_in_hunk(p, 1));
|
||||||
|
|
||||||
cl_git_pass(git_diff_patch_line_stats(&tc, &ta, &td, p));
|
cl_git_pass(git_patch_line_stats(&tc, &ta, &td, p));
|
||||||
cl_assert_equal_i(4, (int)tc);
|
cl_assert_equal_i(4, (int)tc);
|
||||||
cl_assert_equal_i(6, (int)ta);
|
cl_assert_equal_i(6, (int)ta);
|
||||||
cl_assert_equal_i(4, (int)td);
|
cl_assert_equal_i(4, (int)td);
|
||||||
|
|
||||||
git_diff_patch_free(p);
|
git_patch_free(p);
|
||||||
|
|
||||||
git_blob_free(a);
|
git_blob_free(a);
|
||||||
git_blob_free(b);
|
git_blob_free(b);
|
||||||
@ -317,16 +317,16 @@ void test_diff_blob__can_compare_against_null_blobs(void)
|
|||||||
void test_diff_blob__can_compare_against_null_blobs_with_patch(void)
|
void test_diff_blob__can_compare_against_null_blobs_with_patch(void)
|
||||||
{
|
{
|
||||||
git_blob *e = NULL;
|
git_blob *e = NULL;
|
||||||
git_diff_patch *p;
|
git_patch *p;
|
||||||
const git_diff_delta *delta;
|
const git_diff_delta *delta;
|
||||||
int line;
|
const git_diff_line *line;
|
||||||
char origin;
|
int l, max_l;
|
||||||
|
|
||||||
cl_git_pass(git_diff_patch_from_blobs(&p, d, NULL, e, NULL, &opts));
|
cl_git_pass(git_patch_from_blobs(&p, d, NULL, e, NULL, &opts));
|
||||||
|
|
||||||
cl_assert(p != NULL);
|
cl_assert(p != NULL);
|
||||||
|
|
||||||
delta = git_diff_patch_delta(p);
|
delta = git_patch_get_delta(p);
|
||||||
cl_assert(delta != NULL);
|
cl_assert(delta != NULL);
|
||||||
cl_assert_equal_i(GIT_DELTA_DELETED, delta->status);
|
cl_assert_equal_i(GIT_DELTA_DELETED, delta->status);
|
||||||
cl_assert(git_oid_equal(git_blob_id(d), &delta->old_file.oid));
|
cl_assert(git_oid_equal(git_blob_id(d), &delta->old_file.oid));
|
||||||
@ -334,24 +334,24 @@ void test_diff_blob__can_compare_against_null_blobs_with_patch(void)
|
|||||||
cl_assert(git_oid_iszero(&delta->new_file.oid));
|
cl_assert(git_oid_iszero(&delta->new_file.oid));
|
||||||
cl_assert_equal_sz(0, delta->new_file.size);
|
cl_assert_equal_sz(0, delta->new_file.size);
|
||||||
|
|
||||||
cl_assert_equal_i(1, (int)git_diff_patch_num_hunks(p));
|
cl_assert_equal_i(1, (int)git_patch_num_hunks(p));
|
||||||
cl_assert_equal_i(14, git_diff_patch_num_lines_in_hunk(p, 0));
|
cl_assert_equal_i(14, git_patch_num_lines_in_hunk(p, 0));
|
||||||
|
|
||||||
for (line = 0; line < git_diff_patch_num_lines_in_hunk(p, 0); ++line) {
|
max_l = git_patch_num_lines_in_hunk(p, 0);
|
||||||
cl_git_pass(git_diff_patch_get_line_in_hunk(
|
for (l = 0; l < max_l; ++l) {
|
||||||
&origin, NULL, NULL, NULL, NULL, p, 0, line));
|
cl_git_pass(git_patch_get_line_in_hunk(&line, p, 0, l));
|
||||||
cl_assert_equal_i(GIT_DIFF_LINE_DELETION, (int)origin);
|
cl_assert_equal_i(GIT_DIFF_LINE_DELETION, (int)line->origin);
|
||||||
}
|
}
|
||||||
|
|
||||||
git_diff_patch_free(p);
|
git_patch_free(p);
|
||||||
|
|
||||||
opts.flags |= GIT_DIFF_REVERSE;
|
opts.flags |= GIT_DIFF_REVERSE;
|
||||||
|
|
||||||
cl_git_pass(git_diff_patch_from_blobs(&p, d, NULL, e, NULL, &opts));
|
cl_git_pass(git_patch_from_blobs(&p, d, NULL, e, NULL, &opts));
|
||||||
|
|
||||||
cl_assert(p != NULL);
|
cl_assert(p != NULL);
|
||||||
|
|
||||||
delta = git_diff_patch_delta(p);
|
delta = git_patch_get_delta(p);
|
||||||
cl_assert(delta != NULL);
|
cl_assert(delta != NULL);
|
||||||
cl_assert_equal_i(GIT_DELTA_ADDED, delta->status);
|
cl_assert_equal_i(GIT_DELTA_ADDED, delta->status);
|
||||||
cl_assert(git_oid_iszero(&delta->old_file.oid));
|
cl_assert(git_oid_iszero(&delta->old_file.oid));
|
||||||
@ -359,44 +359,44 @@ void test_diff_blob__can_compare_against_null_blobs_with_patch(void)
|
|||||||
cl_assert(git_oid_equal(git_blob_id(d), &delta->new_file.oid));
|
cl_assert(git_oid_equal(git_blob_id(d), &delta->new_file.oid));
|
||||||
cl_assert_equal_sz(git_blob_rawsize(d), delta->new_file.size);
|
cl_assert_equal_sz(git_blob_rawsize(d), delta->new_file.size);
|
||||||
|
|
||||||
cl_assert_equal_i(1, (int)git_diff_patch_num_hunks(p));
|
cl_assert_equal_i(1, (int)git_patch_num_hunks(p));
|
||||||
cl_assert_equal_i(14, git_diff_patch_num_lines_in_hunk(p, 0));
|
cl_assert_equal_i(14, git_patch_num_lines_in_hunk(p, 0));
|
||||||
|
|
||||||
for (line = 0; line < git_diff_patch_num_lines_in_hunk(p, 0); ++line) {
|
max_l = git_patch_num_lines_in_hunk(p, 0);
|
||||||
cl_git_pass(git_diff_patch_get_line_in_hunk(
|
for (l = 0; l < max_l; ++l) {
|
||||||
&origin, NULL, NULL, NULL, NULL, p, 0, line));
|
cl_git_pass(git_patch_get_line_in_hunk(&line, p, 0, l));
|
||||||
cl_assert_equal_i(GIT_DIFF_LINE_ADDITION, (int)origin);
|
cl_assert_equal_i(GIT_DIFF_LINE_ADDITION, (int)line->origin);
|
||||||
}
|
}
|
||||||
|
|
||||||
git_diff_patch_free(p);
|
git_patch_free(p);
|
||||||
|
|
||||||
opts.flags ^= GIT_DIFF_REVERSE;
|
opts.flags ^= GIT_DIFF_REVERSE;
|
||||||
|
|
||||||
cl_git_pass(git_diff_patch_from_blobs(&p, alien, NULL, NULL, NULL, &opts));
|
cl_git_pass(git_patch_from_blobs(&p, alien, NULL, NULL, NULL, &opts));
|
||||||
|
|
||||||
cl_assert(p != NULL);
|
cl_assert(p != NULL);
|
||||||
|
|
||||||
delta = git_diff_patch_delta(p);
|
delta = git_patch_get_delta(p);
|
||||||
cl_assert(delta != NULL);
|
cl_assert(delta != NULL);
|
||||||
cl_assert_equal_i(GIT_DELTA_DELETED, delta->status);
|
cl_assert_equal_i(GIT_DELTA_DELETED, delta->status);
|
||||||
cl_assert((delta->flags & GIT_DIFF_FLAG_BINARY) != 0);
|
cl_assert((delta->flags & GIT_DIFF_FLAG_BINARY) != 0);
|
||||||
|
|
||||||
cl_assert_equal_i(0, (int)git_diff_patch_num_hunks(p));
|
cl_assert_equal_i(0, (int)git_patch_num_hunks(p));
|
||||||
|
|
||||||
git_diff_patch_free(p);
|
git_patch_free(p);
|
||||||
|
|
||||||
cl_git_pass(git_diff_patch_from_blobs(&p, NULL, NULL, alien, NULL, &opts));
|
cl_git_pass(git_patch_from_blobs(&p, NULL, NULL, alien, NULL, &opts));
|
||||||
|
|
||||||
cl_assert(p != NULL);
|
cl_assert(p != NULL);
|
||||||
|
|
||||||
delta = git_diff_patch_delta(p);
|
delta = git_patch_get_delta(p);
|
||||||
cl_assert(delta != NULL);
|
cl_assert(delta != NULL);
|
||||||
cl_assert_equal_i(GIT_DELTA_ADDED, delta->status);
|
cl_assert_equal_i(GIT_DELTA_ADDED, delta->status);
|
||||||
cl_assert((delta->flags & GIT_DIFF_FLAG_BINARY) != 0);
|
cl_assert((delta->flags & GIT_DIFF_FLAG_BINARY) != 0);
|
||||||
|
|
||||||
cl_assert_equal_i(0, (int)git_diff_patch_num_hunks(p));
|
cl_assert_equal_i(0, (int)git_patch_num_hunks(p));
|
||||||
|
|
||||||
git_diff_patch_free(p);
|
git_patch_free(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void assert_identical_blobs_comparison(diff_expects *expected)
|
static void assert_identical_blobs_comparison(diff_expects *expected)
|
||||||
@ -437,13 +437,13 @@ void test_diff_blob__can_compare_identical_blobs(void)
|
|||||||
|
|
||||||
void test_diff_blob__can_compare_identical_blobs_with_patch(void)
|
void test_diff_blob__can_compare_identical_blobs_with_patch(void)
|
||||||
{
|
{
|
||||||
git_diff_patch *p;
|
git_patch *p;
|
||||||
const git_diff_delta *delta;
|
const git_diff_delta *delta;
|
||||||
|
|
||||||
cl_git_pass(git_diff_patch_from_blobs(&p, d, NULL, d, NULL, &opts));
|
cl_git_pass(git_patch_from_blobs(&p, d, NULL, d, NULL, &opts));
|
||||||
cl_assert(p != NULL);
|
cl_assert(p != NULL);
|
||||||
|
|
||||||
delta = git_diff_patch_delta(p);
|
delta = git_patch_get_delta(p);
|
||||||
cl_assert(delta != NULL);
|
cl_assert(delta != NULL);
|
||||||
cl_assert_equal_i(GIT_DELTA_UNMODIFIED, delta->status);
|
cl_assert_equal_i(GIT_DELTA_UNMODIFIED, delta->status);
|
||||||
cl_assert_equal_sz(delta->old_file.size, git_blob_rawsize(d));
|
cl_assert_equal_sz(delta->old_file.size, git_blob_rawsize(d));
|
||||||
@ -451,13 +451,13 @@ void test_diff_blob__can_compare_identical_blobs_with_patch(void)
|
|||||||
cl_assert_equal_sz(delta->new_file.size, git_blob_rawsize(d));
|
cl_assert_equal_sz(delta->new_file.size, git_blob_rawsize(d));
|
||||||
cl_assert(git_oid_equal(git_blob_id(d), &delta->new_file.oid));
|
cl_assert(git_oid_equal(git_blob_id(d), &delta->new_file.oid));
|
||||||
|
|
||||||
cl_assert_equal_i(0, (int)git_diff_patch_num_hunks(p));
|
cl_assert_equal_i(0, (int)git_patch_num_hunks(p));
|
||||||
git_diff_patch_free(p);
|
git_patch_free(p);
|
||||||
|
|
||||||
cl_git_pass(git_diff_patch_from_blobs(&p, NULL, NULL, NULL, NULL, &opts));
|
cl_git_pass(git_patch_from_blobs(&p, NULL, NULL, NULL, NULL, &opts));
|
||||||
cl_assert(p != NULL);
|
cl_assert(p != NULL);
|
||||||
|
|
||||||
delta = git_diff_patch_delta(p);
|
delta = git_patch_get_delta(p);
|
||||||
cl_assert(delta != NULL);
|
cl_assert(delta != NULL);
|
||||||
cl_assert_equal_i(GIT_DELTA_UNMODIFIED, delta->status);
|
cl_assert_equal_i(GIT_DELTA_UNMODIFIED, delta->status);
|
||||||
cl_assert_equal_sz(0, delta->old_file.size);
|
cl_assert_equal_sz(0, delta->old_file.size);
|
||||||
@ -465,14 +465,14 @@ void test_diff_blob__can_compare_identical_blobs_with_patch(void)
|
|||||||
cl_assert_equal_sz(0, delta->new_file.size);
|
cl_assert_equal_sz(0, delta->new_file.size);
|
||||||
cl_assert(git_oid_iszero(&delta->new_file.oid));
|
cl_assert(git_oid_iszero(&delta->new_file.oid));
|
||||||
|
|
||||||
cl_assert_equal_i(0, (int)git_diff_patch_num_hunks(p));
|
cl_assert_equal_i(0, (int)git_patch_num_hunks(p));
|
||||||
git_diff_patch_free(p);
|
git_patch_free(p);
|
||||||
|
|
||||||
cl_git_pass(git_diff_patch_from_blobs(&p, alien, NULL, alien, NULL, &opts));
|
cl_git_pass(git_patch_from_blobs(&p, alien, NULL, alien, NULL, &opts));
|
||||||
cl_assert(p != NULL);
|
cl_assert(p != NULL);
|
||||||
cl_assert_equal_i(GIT_DELTA_UNMODIFIED, git_diff_patch_delta(p)->status);
|
cl_assert_equal_i(GIT_DELTA_UNMODIFIED, git_patch_get_delta(p)->status);
|
||||||
cl_assert_equal_i(0, (int)git_diff_patch_num_hunks(p));
|
cl_assert_equal_i(0, (int)git_patch_num_hunks(p));
|
||||||
git_diff_patch_free(p);
|
git_patch_free(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void assert_binary_blobs_comparison(diff_expects *expected)
|
static void assert_binary_blobs_comparison(diff_expects *expected)
|
||||||
@ -693,7 +693,7 @@ void test_diff_blob__can_compare_blob_to_buffer(void)
|
|||||||
|
|
||||||
void test_diff_blob__can_compare_blob_to_buffer_with_patch(void)
|
void test_diff_blob__can_compare_blob_to_buffer_with_patch(void)
|
||||||
{
|
{
|
||||||
git_diff_patch *p;
|
git_patch *p;
|
||||||
git_blob *a;
|
git_blob *a;
|
||||||
git_oid a_oid;
|
git_oid a_oid;
|
||||||
const char *a_content = "Hello from the root\n";
|
const char *a_content = "Hello from the root\n";
|
||||||
@ -705,58 +705,58 @@ void test_diff_blob__can_compare_blob_to_buffer_with_patch(void)
|
|||||||
cl_git_pass(git_blob_lookup_prefix(&a, g_repo, &a_oid, 4));
|
cl_git_pass(git_blob_lookup_prefix(&a, g_repo, &a_oid, 4));
|
||||||
|
|
||||||
/* diff from blob a to content of b */
|
/* diff from blob a to content of b */
|
||||||
cl_git_pass(git_diff_patch_from_blob_and_buffer(
|
cl_git_pass(git_patch_from_blob_and_buffer(
|
||||||
&p, a, NULL, b_content, strlen(b_content), NULL, &opts));
|
&p, a, NULL, b_content, strlen(b_content), NULL, &opts));
|
||||||
|
|
||||||
cl_assert(p != NULL);
|
cl_assert(p != NULL);
|
||||||
cl_assert_equal_i(GIT_DELTA_MODIFIED, git_diff_patch_delta(p)->status);
|
cl_assert_equal_i(GIT_DELTA_MODIFIED, git_patch_get_delta(p)->status);
|
||||||
cl_assert_equal_i(1, (int)git_diff_patch_num_hunks(p));
|
cl_assert_equal_i(1, (int)git_patch_num_hunks(p));
|
||||||
cl_assert_equal_i(6, git_diff_patch_num_lines_in_hunk(p, 0));
|
cl_assert_equal_i(6, git_patch_num_lines_in_hunk(p, 0));
|
||||||
|
|
||||||
cl_git_pass(git_diff_patch_line_stats(&tc, &ta, &td, p));
|
cl_git_pass(git_patch_line_stats(&tc, &ta, &td, p));
|
||||||
cl_assert_equal_i(1, (int)tc);
|
cl_assert_equal_i(1, (int)tc);
|
||||||
cl_assert_equal_i(5, (int)ta);
|
cl_assert_equal_i(5, (int)ta);
|
||||||
cl_assert_equal_i(0, (int)td);
|
cl_assert_equal_i(0, (int)td);
|
||||||
|
|
||||||
git_diff_patch_free(p);
|
git_patch_free(p);
|
||||||
|
|
||||||
/* diff from blob a to content of a */
|
/* diff from blob a to content of a */
|
||||||
opts.flags |= GIT_DIFF_INCLUDE_UNMODIFIED;
|
opts.flags |= GIT_DIFF_INCLUDE_UNMODIFIED;
|
||||||
cl_git_pass(git_diff_patch_from_blob_and_buffer(
|
cl_git_pass(git_patch_from_blob_and_buffer(
|
||||||
&p, a, NULL, a_content, strlen(a_content), NULL, &opts));
|
&p, a, NULL, a_content, strlen(a_content), NULL, &opts));
|
||||||
cl_assert(p != NULL);
|
cl_assert(p != NULL);
|
||||||
cl_assert_equal_i(GIT_DELTA_UNMODIFIED, git_diff_patch_delta(p)->status);
|
cl_assert_equal_i(GIT_DELTA_UNMODIFIED, git_patch_get_delta(p)->status);
|
||||||
cl_assert_equal_i(0, (int)git_diff_patch_num_hunks(p));
|
cl_assert_equal_i(0, (int)git_patch_num_hunks(p));
|
||||||
git_diff_patch_free(p);
|
git_patch_free(p);
|
||||||
|
|
||||||
/* diff from NULL blob to content of a */
|
/* diff from NULL blob to content of a */
|
||||||
cl_git_pass(git_diff_patch_from_blob_and_buffer(
|
cl_git_pass(git_patch_from_blob_and_buffer(
|
||||||
&p, NULL, NULL, a_content, strlen(a_content), NULL, &opts));
|
&p, NULL, NULL, a_content, strlen(a_content), NULL, &opts));
|
||||||
cl_assert(p != NULL);
|
cl_assert(p != NULL);
|
||||||
cl_assert_equal_i(GIT_DELTA_ADDED, git_diff_patch_delta(p)->status);
|
cl_assert_equal_i(GIT_DELTA_ADDED, git_patch_get_delta(p)->status);
|
||||||
cl_assert_equal_i(1, (int)git_diff_patch_num_hunks(p));
|
cl_assert_equal_i(1, (int)git_patch_num_hunks(p));
|
||||||
cl_assert_equal_i(1, git_diff_patch_num_lines_in_hunk(p, 0));
|
cl_assert_equal_i(1, git_patch_num_lines_in_hunk(p, 0));
|
||||||
git_diff_patch_free(p);
|
git_patch_free(p);
|
||||||
|
|
||||||
/* diff from blob a to NULL buffer */
|
/* diff from blob a to NULL buffer */
|
||||||
cl_git_pass(git_diff_patch_from_blob_and_buffer(
|
cl_git_pass(git_patch_from_blob_and_buffer(
|
||||||
&p, a, NULL, NULL, 0, NULL, &opts));
|
&p, a, NULL, NULL, 0, NULL, &opts));
|
||||||
cl_assert(p != NULL);
|
cl_assert(p != NULL);
|
||||||
cl_assert_equal_i(GIT_DELTA_DELETED, git_diff_patch_delta(p)->status);
|
cl_assert_equal_i(GIT_DELTA_DELETED, git_patch_get_delta(p)->status);
|
||||||
cl_assert_equal_i(1, (int)git_diff_patch_num_hunks(p));
|
cl_assert_equal_i(1, (int)git_patch_num_hunks(p));
|
||||||
cl_assert_equal_i(1, git_diff_patch_num_lines_in_hunk(p, 0));
|
cl_assert_equal_i(1, git_patch_num_lines_in_hunk(p, 0));
|
||||||
git_diff_patch_free(p);
|
git_patch_free(p);
|
||||||
|
|
||||||
/* diff with reverse */
|
/* diff with reverse */
|
||||||
opts.flags ^= GIT_DIFF_REVERSE;
|
opts.flags ^= GIT_DIFF_REVERSE;
|
||||||
|
|
||||||
cl_git_pass(git_diff_patch_from_blob_and_buffer(
|
cl_git_pass(git_patch_from_blob_and_buffer(
|
||||||
&p, a, NULL, NULL, 0, NULL, &opts));
|
&p, a, NULL, NULL, 0, NULL, &opts));
|
||||||
cl_assert(p != NULL);
|
cl_assert(p != NULL);
|
||||||
cl_assert_equal_i(GIT_DELTA_ADDED, git_diff_patch_delta(p)->status);
|
cl_assert_equal_i(GIT_DELTA_ADDED, git_patch_get_delta(p)->status);
|
||||||
cl_assert_equal_i(1, (int)git_diff_patch_num_hunks(p));
|
cl_assert_equal_i(1, (int)git_patch_num_hunks(p));
|
||||||
cl_assert_equal_i(1, git_diff_patch_num_lines_in_hunk(p, 0));
|
cl_assert_equal_i(1, git_patch_num_lines_in_hunk(p, 0));
|
||||||
git_diff_patch_free(p);
|
git_patch_free(p);
|
||||||
|
|
||||||
git_blob_free(a);
|
git_blob_free(a);
|
||||||
}
|
}
|
||||||
@ -853,7 +853,7 @@ void test_diff_blob__using_path_and_attributes(void)
|
|||||||
"0123456789\n\x01\x02\x03\x04\x05\x06\x07\x08\x09\x00\n0123456789\n";
|
"0123456789\n\x01\x02\x03\x04\x05\x06\x07\x08\x09\x00\n0123456789\n";
|
||||||
size_t bin_len = 33;
|
size_t bin_len = 33;
|
||||||
const char *changed;
|
const char *changed;
|
||||||
git_diff_patch *p;
|
git_patch *p;
|
||||||
char *pout;
|
char *pout;
|
||||||
|
|
||||||
/* set up custom diff drivers and 'diff' attribute mappings for them */
|
/* set up custom diff drivers and 'diff' attribute mappings for them */
|
||||||
@ -950,9 +950,9 @@ void test_diff_blob__using_path_and_attributes(void)
|
|||||||
cl_assert_equal_i(3, expected.line_adds);
|
cl_assert_equal_i(3, expected.line_adds);
|
||||||
cl_assert_equal_i(0, expected.line_dels);
|
cl_assert_equal_i(0, expected.line_dels);
|
||||||
|
|
||||||
cl_git_pass(git_diff_patch_from_blob_and_buffer(
|
cl_git_pass(git_patch_from_blob_and_buffer(
|
||||||
&p, nonbin, "zzz.normal", changed, strlen(changed), NULL, &opts));
|
&p, nonbin, "zzz.normal", changed, strlen(changed), NULL, &opts));
|
||||||
cl_git_pass(git_diff_patch_to_str(&pout, p));
|
cl_git_pass(git_patch_to_str(&pout, p));
|
||||||
cl_assert_equal_s(
|
cl_assert_equal_s(
|
||||||
"diff --git a/zzz.normal b/zzz.normal\n"
|
"diff --git a/zzz.normal b/zzz.normal\n"
|
||||||
"index 45141a7..75b0dbb 100644\n"
|
"index 45141a7..75b0dbb 100644\n"
|
||||||
@ -963,21 +963,21 @@ void test_diff_blob__using_path_and_attributes(void)
|
|||||||
"+And more\n"
|
"+And more\n"
|
||||||
"+Go here\n", pout);
|
"+Go here\n", pout);
|
||||||
git__free(pout);
|
git__free(pout);
|
||||||
git_diff_patch_free(p);
|
git_patch_free(p);
|
||||||
|
|
||||||
cl_git_pass(git_diff_patch_from_blob_and_buffer(
|
cl_git_pass(git_patch_from_blob_and_buffer(
|
||||||
&p, nonbin, "zzz.binary", changed, strlen(changed), NULL, &opts));
|
&p, nonbin, "zzz.binary", changed, strlen(changed), NULL, &opts));
|
||||||
cl_git_pass(git_diff_patch_to_str(&pout, p));
|
cl_git_pass(git_patch_to_str(&pout, p));
|
||||||
cl_assert_equal_s(
|
cl_assert_equal_s(
|
||||||
"diff --git a/zzz.binary b/zzz.binary\n"
|
"diff --git a/zzz.binary b/zzz.binary\n"
|
||||||
"index 45141a7..75b0dbb 100644\n"
|
"index 45141a7..75b0dbb 100644\n"
|
||||||
"Binary files a/zzz.binary and b/zzz.binary differ\n", pout);
|
"Binary files a/zzz.binary and b/zzz.binary differ\n", pout);
|
||||||
git__free(pout);
|
git__free(pout);
|
||||||
git_diff_patch_free(p);
|
git_patch_free(p);
|
||||||
|
|
||||||
cl_git_pass(git_diff_patch_from_blob_and_buffer(
|
cl_git_pass(git_patch_from_blob_and_buffer(
|
||||||
&p, nonbin, "zzz.alphary", changed, strlen(changed), NULL, &opts));
|
&p, nonbin, "zzz.alphary", changed, strlen(changed), NULL, &opts));
|
||||||
cl_git_pass(git_diff_patch_to_str(&pout, p));
|
cl_git_pass(git_patch_to_str(&pout, p));
|
||||||
cl_assert_equal_s(
|
cl_assert_equal_s(
|
||||||
"diff --git a/zzz.alphary b/zzz.alphary\n"
|
"diff --git a/zzz.alphary b/zzz.alphary\n"
|
||||||
"index 45141a7..75b0dbb 100644\n"
|
"index 45141a7..75b0dbb 100644\n"
|
||||||
@ -988,11 +988,11 @@ void test_diff_blob__using_path_and_attributes(void)
|
|||||||
"+And more\n"
|
"+And more\n"
|
||||||
"+Go here\n", pout);
|
"+Go here\n", pout);
|
||||||
git__free(pout);
|
git__free(pout);
|
||||||
git_diff_patch_free(p);
|
git_patch_free(p);
|
||||||
|
|
||||||
cl_git_pass(git_diff_patch_from_blob_and_buffer(
|
cl_git_pass(git_patch_from_blob_and_buffer(
|
||||||
&p, nonbin, "zzz.numary", changed, strlen(changed), NULL, &opts));
|
&p, nonbin, "zzz.numary", changed, strlen(changed), NULL, &opts));
|
||||||
cl_git_pass(git_diff_patch_to_str(&pout, p));
|
cl_git_pass(git_patch_to_str(&pout, p));
|
||||||
cl_assert_equal_s(
|
cl_assert_equal_s(
|
||||||
"diff --git a/zzz.numary b/zzz.numary\n"
|
"diff --git a/zzz.numary b/zzz.numary\n"
|
||||||
"index 45141a7..75b0dbb 100644\n"
|
"index 45141a7..75b0dbb 100644\n"
|
||||||
@ -1003,7 +1003,7 @@ void test_diff_blob__using_path_and_attributes(void)
|
|||||||
"+And more\n"
|
"+And more\n"
|
||||||
"+Go here\n", pout);
|
"+Go here\n", pout);
|
||||||
git__free(pout);
|
git__free(pout);
|
||||||
git_diff_patch_free(p);
|
git_patch_free(p);
|
||||||
|
|
||||||
/* "0123456789\n\x01\x02\x03\x04\x05\x06\x07\x08\x09\x00\n0123456789\n"
|
/* "0123456789\n\x01\x02\x03\x04\x05\x06\x07\x08\x09\x00\n0123456789\n"
|
||||||
* 33 bytes
|
* 33 bytes
|
||||||
@ -1011,19 +1011,19 @@ void test_diff_blob__using_path_and_attributes(void)
|
|||||||
|
|
||||||
changed = "0123456789\n\x01\x02\x03\x04\x05\x06\x07\x08\x09\x00\nreplace a line\n";
|
changed = "0123456789\n\x01\x02\x03\x04\x05\x06\x07\x08\x09\x00\nreplace a line\n";
|
||||||
|
|
||||||
cl_git_pass(git_diff_patch_from_blob_and_buffer(
|
cl_git_pass(git_patch_from_blob_and_buffer(
|
||||||
&p, bin, "zzz.normal", changed, 37, NULL, &opts));
|
&p, bin, "zzz.normal", changed, 37, NULL, &opts));
|
||||||
cl_git_pass(git_diff_patch_to_str(&pout, p));
|
cl_git_pass(git_patch_to_str(&pout, p));
|
||||||
cl_assert_equal_s(
|
cl_assert_equal_s(
|
||||||
"diff --git a/zzz.normal b/zzz.normal\n"
|
"diff --git a/zzz.normal b/zzz.normal\n"
|
||||||
"index b435cd5..1604519 100644\n"
|
"index b435cd5..1604519 100644\n"
|
||||||
"Binary files a/zzz.normal and b/zzz.normal differ\n", pout);
|
"Binary files a/zzz.normal and b/zzz.normal differ\n", pout);
|
||||||
git__free(pout);
|
git__free(pout);
|
||||||
git_diff_patch_free(p);
|
git_patch_free(p);
|
||||||
|
|
||||||
cl_git_pass(git_diff_patch_from_blob_and_buffer(
|
cl_git_pass(git_patch_from_blob_and_buffer(
|
||||||
&p, bin, "zzz.textary", changed, 37, NULL, &opts));
|
&p, bin, "zzz.textary", changed, 37, NULL, &opts));
|
||||||
cl_git_pass(git_diff_patch_to_str(&pout, p));
|
cl_git_pass(git_patch_to_str(&pout, p));
|
||||||
cl_assert_equal_s(
|
cl_assert_equal_s(
|
||||||
"diff --git a/zzz.textary b/zzz.textary\n"
|
"diff --git a/zzz.textary b/zzz.textary\n"
|
||||||
"index b435cd5..1604519 100644\n"
|
"index b435cd5..1604519 100644\n"
|
||||||
@ -1033,11 +1033,11 @@ void test_diff_blob__using_path_and_attributes(void)
|
|||||||
"-0123456789\n"
|
"-0123456789\n"
|
||||||
"+replace a line\n", pout);
|
"+replace a line\n", pout);
|
||||||
git__free(pout);
|
git__free(pout);
|
||||||
git_diff_patch_free(p);
|
git_patch_free(p);
|
||||||
|
|
||||||
cl_git_pass(git_diff_patch_from_blob_and_buffer(
|
cl_git_pass(git_patch_from_blob_and_buffer(
|
||||||
&p, bin, "zzz.textalphary", changed, 37, NULL, &opts));
|
&p, bin, "zzz.textalphary", changed, 37, NULL, &opts));
|
||||||
cl_git_pass(git_diff_patch_to_str(&pout, p));
|
cl_git_pass(git_patch_to_str(&pout, p));
|
||||||
cl_assert_equal_s(
|
cl_assert_equal_s(
|
||||||
"diff --git a/zzz.textalphary b/zzz.textalphary\n"
|
"diff --git a/zzz.textalphary b/zzz.textalphary\n"
|
||||||
"index b435cd5..1604519 100644\n"
|
"index b435cd5..1604519 100644\n"
|
||||||
@ -1047,11 +1047,11 @@ void test_diff_blob__using_path_and_attributes(void)
|
|||||||
"-0123456789\n"
|
"-0123456789\n"
|
||||||
"+replace a line\n", pout);
|
"+replace a line\n", pout);
|
||||||
git__free(pout);
|
git__free(pout);
|
||||||
git_diff_patch_free(p);
|
git_patch_free(p);
|
||||||
|
|
||||||
cl_git_pass(git_diff_patch_from_blob_and_buffer(
|
cl_git_pass(git_patch_from_blob_and_buffer(
|
||||||
&p, bin, "zzz.textnumary", changed, 37, NULL, &opts));
|
&p, bin, "zzz.textnumary", changed, 37, NULL, &opts));
|
||||||
cl_git_pass(git_diff_patch_to_str(&pout, p));
|
cl_git_pass(git_patch_to_str(&pout, p));
|
||||||
cl_assert_equal_s(
|
cl_assert_equal_s(
|
||||||
"diff --git a/zzz.textnumary b/zzz.textnumary\n"
|
"diff --git a/zzz.textnumary b/zzz.textnumary\n"
|
||||||
"index b435cd5..1604519 100644\n"
|
"index b435cd5..1604519 100644\n"
|
||||||
@ -1061,7 +1061,7 @@ void test_diff_blob__using_path_and_attributes(void)
|
|||||||
"-0123456789\n"
|
"-0123456789\n"
|
||||||
"+replace a line\n", pout);
|
"+replace a line\n", pout);
|
||||||
git__free(pout);
|
git__free(pout);
|
||||||
git_diff_patch_free(p);
|
git_patch_free(p);
|
||||||
|
|
||||||
git_blob_free(nonbin);
|
git_blob_free(nonbin);
|
||||||
git_blob_free(bin);
|
git_blob_free(bin);
|
||||||
|
@ -95,41 +95,37 @@ int diff_print_file_cb(
|
|||||||
|
|
||||||
int diff_hunk_cb(
|
int diff_hunk_cb(
|
||||||
const git_diff_delta *delta,
|
const git_diff_delta *delta,
|
||||||
const git_diff_range *range,
|
const git_diff_hunk *hunk,
|
||||||
const char *header,
|
|
||||||
size_t header_len,
|
|
||||||
void *payload)
|
void *payload)
|
||||||
{
|
{
|
||||||
diff_expects *e = payload;
|
diff_expects *e = payload;
|
||||||
|
const char *scan = hunk->header, *scan_end = scan + hunk->header_len;
|
||||||
|
|
||||||
GIT_UNUSED(delta);
|
GIT_UNUSED(delta);
|
||||||
|
|
||||||
/* confirm no NUL bytes in header text */
|
/* 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->hunks++;
|
||||||
e->hunk_old_lines += range->old_lines;
|
e->hunk_old_lines += hunk->old_lines;
|
||||||
e->hunk_new_lines += range->new_lines;
|
e->hunk_new_lines += hunk->new_lines;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int diff_line_cb(
|
int diff_line_cb(
|
||||||
const git_diff_delta *delta,
|
const git_diff_delta *delta,
|
||||||
const git_diff_range *range,
|
const git_diff_hunk *hunk,
|
||||||
char line_origin,
|
const git_diff_line *line,
|
||||||
const char *content,
|
|
||||||
size_t content_len,
|
|
||||||
void *payload)
|
void *payload)
|
||||||
{
|
{
|
||||||
diff_expects *e = payload;
|
diff_expects *e = payload;
|
||||||
|
|
||||||
GIT_UNUSED(delta);
|
GIT_UNUSED(delta);
|
||||||
GIT_UNUSED(range);
|
GIT_UNUSED(hunk);
|
||||||
GIT_UNUSED(content);
|
|
||||||
GIT_UNUSED(content_len);
|
|
||||||
|
|
||||||
e->lines++;
|
e->lines++;
|
||||||
switch (line_origin) {
|
switch (line->origin) {
|
||||||
case GIT_DIFF_LINE_CONTEXT:
|
case GIT_DIFF_LINE_CONTEXT:
|
||||||
case GIT_DIFF_LINE_CONTEXT_EOFNL: /* techically not a line */
|
case GIT_DIFF_LINE_CONTEXT_EOFNL: /* techically not a line */
|
||||||
e->line_ctxt++;
|
e->line_ctxt++;
|
||||||
@ -149,25 +145,25 @@ int diff_line_cb(
|
|||||||
}
|
}
|
||||||
|
|
||||||
int diff_foreach_via_iterator(
|
int diff_foreach_via_iterator(
|
||||||
git_diff_list *diff,
|
git_diff *diff,
|
||||||
git_diff_file_cb file_cb,
|
git_diff_file_cb file_cb,
|
||||||
git_diff_hunk_cb hunk_cb,
|
git_diff_hunk_cb hunk_cb,
|
||||||
git_diff_data_cb line_cb,
|
git_diff_line_cb line_cb,
|
||||||
void *data)
|
void *data)
|
||||||
{
|
{
|
||||||
size_t d, num_d = git_diff_num_deltas(diff);
|
size_t d, num_d = git_diff_num_deltas(diff);
|
||||||
|
|
||||||
for (d = 0; d < num_d; ++d) {
|
for (d = 0; d < num_d; ++d) {
|
||||||
git_diff_patch *patch;
|
git_patch *patch;
|
||||||
const git_diff_delta *delta;
|
const git_diff_delta *delta;
|
||||||
size_t h, num_h;
|
size_t h, num_h;
|
||||||
|
|
||||||
cl_git_pass(git_diff_get_patch(&patch, &delta, diff, d));
|
cl_git_pass(git_patch_from_diff(&patch, diff, d));
|
||||||
cl_assert(delta);
|
cl_assert((delta = git_patch_get_delta(patch)) != NULL);
|
||||||
|
|
||||||
/* call file_cb for this file */
|
/* call file_cb for this file */
|
||||||
if (file_cb != NULL && file_cb(delta, (float)d / num_d, data) != 0) {
|
if (file_cb != NULL && file_cb(delta, (float)d / num_d, data) != 0) {
|
||||||
git_diff_patch_free(patch);
|
git_patch_free(patch);
|
||||||
goto abort;
|
goto abort;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -179,44 +175,37 @@ int diff_foreach_via_iterator(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!hunk_cb && !line_cb) {
|
if (!hunk_cb && !line_cb) {
|
||||||
git_diff_patch_free(patch);
|
git_patch_free(patch);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
num_h = git_diff_patch_num_hunks(patch);
|
num_h = git_patch_num_hunks(patch);
|
||||||
|
|
||||||
for (h = 0; h < num_h; h++) {
|
for (h = 0; h < num_h; h++) {
|
||||||
const git_diff_range *range;
|
const git_diff_hunk *hunk;
|
||||||
const char *hdr;
|
size_t l, num_l;
|
||||||
size_t hdr_len, l, num_l;
|
|
||||||
|
|
||||||
cl_git_pass(git_diff_patch_get_hunk(
|
cl_git_pass(git_patch_get_hunk(&hunk, &num_l, patch, h));
|
||||||
&range, &hdr, &hdr_len, &num_l, patch, h));
|
|
||||||
|
|
||||||
if (hunk_cb && hunk_cb(delta, range, hdr, hdr_len, data) != 0) {
|
if (hunk_cb && hunk_cb(delta, hunk, data) != 0) {
|
||||||
git_diff_patch_free(patch);
|
git_patch_free(patch);
|
||||||
goto abort;
|
goto abort;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (l = 0; l < num_l; ++l) {
|
for (l = 0; l < num_l; ++l) {
|
||||||
char origin;
|
const git_diff_line *line;
|
||||||
const char *line;
|
|
||||||
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(&line, patch, h, l));
|
||||||
&origin, &line, &line_len, &old_lineno, &new_lineno,
|
|
||||||
patch, h, l));
|
|
||||||
|
|
||||||
if (line_cb &&
|
if (line_cb &&
|
||||||
line_cb(delta, range, origin, line, line_len, data) != 0) {
|
line_cb(delta, hunk, line, data) != 0) {
|
||||||
git_diff_patch_free(patch);
|
git_patch_free(patch);
|
||||||
goto abort;
|
goto abort;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
git_diff_patch_free(patch);
|
git_patch_free(patch);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@ -228,27 +217,26 @@ abort:
|
|||||||
|
|
||||||
static int diff_print_cb(
|
static int diff_print_cb(
|
||||||
const git_diff_delta *delta,
|
const git_diff_delta *delta,
|
||||||
const git_diff_range *range,
|
const git_diff_hunk *hunk,
|
||||||
char line_origin, /**< GIT_DIFF_LINE_... value from above */
|
const git_diff_line *line,
|
||||||
const char *content,
|
|
||||||
size_t content_len,
|
|
||||||
void *payload)
|
void *payload)
|
||||||
{
|
{
|
||||||
GIT_UNUSED(payload);
|
GIT_UNUSED(payload);
|
||||||
GIT_UNUSED(delta);
|
GIT_UNUSED(delta);
|
||||||
GIT_UNUSED(range);
|
GIT_UNUSED(hunk);
|
||||||
GIT_UNUSED(line_origin);
|
fprintf((FILE *)payload, "%c%.*s",
|
||||||
GIT_UNUSED(content_len);
|
line->origin, (int)line->content_len, line->content);
|
||||||
fputs(content, (FILE *)payload);
|
|
||||||
return 0;
|
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(
|
extern int diff_hunk_cb(
|
||||||
const git_diff_delta *delta,
|
const git_diff_delta *delta,
|
||||||
const git_diff_range *range,
|
const git_diff_hunk *hunk,
|
||||||
const char *header,
|
|
||||||
size_t header_len,
|
|
||||||
void *cb_data);
|
void *cb_data);
|
||||||
|
|
||||||
extern int diff_line_cb(
|
extern int diff_line_cb(
|
||||||
const git_diff_delta *delta,
|
const git_diff_delta *delta,
|
||||||
const git_diff_range *range,
|
const git_diff_hunk *hunk,
|
||||||
char line_origin,
|
const git_diff_line *line,
|
||||||
const char *content,
|
|
||||||
size_t content_len,
|
|
||||||
void *cb_data);
|
void *cb_data);
|
||||||
|
|
||||||
extern int diff_foreach_via_iterator(
|
extern int diff_foreach_via_iterator(
|
||||||
git_diff_list *diff,
|
git_diff *diff,
|
||||||
git_diff_file_cb file_cb,
|
git_diff_file_cb file_cb,
|
||||||
git_diff_hunk_cb hunk_cb,
|
git_diff_hunk_cb hunk_cb,
|
||||||
git_diff_data_cb line_cb,
|
git_diff_line_cb line_cb,
|
||||||
void *data);
|
void *data);
|
||||||
|
|
||||||
extern void diff_print(FILE *fp, git_diff_list *diff);
|
extern void diff_print(FILE *fp, git_diff *diff);
|
||||||
extern void diff_print_raw(FILE *fp, git_diff_list *diff);
|
extern void diff_print_raw(FILE *fp, git_diff *diff);
|
||||||
|
@ -13,24 +13,26 @@ void test_diff_diffiter__cleanup(void)
|
|||||||
void test_diff_diffiter__create(void)
|
void test_diff_diffiter__create(void)
|
||||||
{
|
{
|
||||||
git_repository *repo = cl_git_sandbox_init("attr");
|
git_repository *repo = cl_git_sandbox_init("attr");
|
||||||
git_diff_list *diff;
|
git_diff *diff;
|
||||||
size_t d, num_d;
|
size_t d, num_d;
|
||||||
|
|
||||||
cl_git_pass(git_diff_index_to_workdir(&diff, repo, NULL, NULL));
|
cl_git_pass(git_diff_index_to_workdir(&diff, repo, NULL, NULL));
|
||||||
|
|
||||||
num_d = git_diff_num_deltas(diff);
|
num_d = git_diff_num_deltas(diff);
|
||||||
for (d = 0; d < num_d; ++d) {
|
for (d = 0; d < num_d; ++d) {
|
||||||
const git_diff_delta *delta;
|
const git_diff_delta *delta = git_diff_get_delta(diff, d);
|
||||||
cl_git_pass(git_diff_get_patch(NULL, &delta, diff, d));
|
cl_assert(delta != NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
git_diff_list_free(diff);
|
cl_assert(!git_diff_get_delta(diff, num_d));
|
||||||
|
|
||||||
|
git_diff_free(diff);
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_diff_diffiter__iterate_files_1(void)
|
void test_diff_diffiter__iterate_files_1(void)
|
||||||
{
|
{
|
||||||
git_repository *repo = cl_git_sandbox_init("attr");
|
git_repository *repo = cl_git_sandbox_init("attr");
|
||||||
git_diff_list *diff;
|
git_diff *diff;
|
||||||
size_t d, num_d;
|
size_t d, num_d;
|
||||||
diff_expects exp = { 0 };
|
diff_expects exp = { 0 };
|
||||||
|
|
||||||
@ -39,21 +41,20 @@ void test_diff_diffiter__iterate_files_1(void)
|
|||||||
num_d = git_diff_num_deltas(diff);
|
num_d = git_diff_num_deltas(diff);
|
||||||
|
|
||||||
for (d = 0; d < num_d; ++d) {
|
for (d = 0; d < num_d; ++d) {
|
||||||
const git_diff_delta *delta;
|
const git_diff_delta *delta = git_diff_get_delta(diff, d);
|
||||||
cl_git_pass(git_diff_get_patch(NULL, &delta, diff, d));
|
|
||||||
cl_assert(delta != NULL);
|
cl_assert(delta != NULL);
|
||||||
|
|
||||||
diff_file_cb(delta, (float)d / (float)num_d, &exp);
|
diff_file_cb(delta, (float)d / (float)num_d, &exp);
|
||||||
}
|
}
|
||||||
cl_assert_equal_sz(6, exp.files);
|
cl_assert_equal_sz(6, exp.files);
|
||||||
|
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_diff_diffiter__iterate_files_2(void)
|
void test_diff_diffiter__iterate_files_2(void)
|
||||||
{
|
{
|
||||||
git_repository *repo = cl_git_sandbox_init("status");
|
git_repository *repo = cl_git_sandbox_init("status");
|
||||||
git_diff_list *diff;
|
git_diff *diff;
|
||||||
size_t d, num_d;
|
size_t d, num_d;
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
|
||||||
@ -63,21 +64,20 @@ void test_diff_diffiter__iterate_files_2(void)
|
|||||||
cl_assert_equal_i(8, (int)num_d);
|
cl_assert_equal_i(8, (int)num_d);
|
||||||
|
|
||||||
for (d = 0; d < num_d; ++d) {
|
for (d = 0; d < num_d; ++d) {
|
||||||
const git_diff_delta *delta;
|
const git_diff_delta *delta = git_diff_get_delta(diff, d);
|
||||||
cl_git_pass(git_diff_get_patch(NULL, &delta, diff, d));
|
|
||||||
cl_assert(delta != NULL);
|
cl_assert(delta != NULL);
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
cl_assert_equal_i(8, count);
|
cl_assert_equal_i(8, count);
|
||||||
|
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_diff_diffiter__iterate_files_and_hunks(void)
|
void test_diff_diffiter__iterate_files_and_hunks(void)
|
||||||
{
|
{
|
||||||
git_repository *repo = cl_git_sandbox_init("status");
|
git_repository *repo = cl_git_sandbox_init("status");
|
||||||
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
|
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
|
||||||
git_diff_list *diff = NULL;
|
git_diff *diff = NULL;
|
||||||
size_t d, num_d;
|
size_t d, num_d;
|
||||||
int file_count = 0, hunk_count = 0;
|
int file_count = 0, hunk_count = 0;
|
||||||
|
|
||||||
@ -90,47 +90,39 @@ void test_diff_diffiter__iterate_files_and_hunks(void)
|
|||||||
num_d = git_diff_num_deltas(diff);
|
num_d = git_diff_num_deltas(diff);
|
||||||
|
|
||||||
for (d = 0; d < num_d; ++d) {
|
for (d = 0; d < num_d; ++d) {
|
||||||
git_diff_patch *patch;
|
git_patch *patch;
|
||||||
const git_diff_delta *delta;
|
|
||||||
size_t h, num_h;
|
size_t h, num_h;
|
||||||
|
|
||||||
cl_git_pass(git_diff_get_patch(&patch, &delta, diff, d));
|
cl_git_pass(git_patch_from_diff(&patch, diff, d));
|
||||||
|
|
||||||
cl_assert(delta);
|
|
||||||
cl_assert(patch);
|
cl_assert(patch);
|
||||||
|
|
||||||
file_count++;
|
file_count++;
|
||||||
|
|
||||||
num_h = git_diff_patch_num_hunks(patch);
|
num_h = git_patch_num_hunks(patch);
|
||||||
|
|
||||||
for (h = 0; h < num_h; h++) {
|
for (h = 0; h < num_h; h++) {
|
||||||
const git_diff_range *range;
|
const git_diff_hunk *hunk;
|
||||||
const char *header;
|
|
||||||
size_t header_len, num_l;
|
|
||||||
|
|
||||||
cl_git_pass(git_diff_patch_get_hunk(
|
cl_git_pass(git_patch_get_hunk(&hunk, NULL, patch, h));
|
||||||
&range, &header, &header_len, &num_l, patch, h));
|
cl_assert(hunk);
|
||||||
|
|
||||||
cl_assert(range);
|
|
||||||
cl_assert(header);
|
|
||||||
|
|
||||||
hunk_count++;
|
hunk_count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
git_diff_patch_free(patch);
|
git_patch_free(patch);
|
||||||
}
|
}
|
||||||
|
|
||||||
cl_assert_equal_i(13, file_count);
|
cl_assert_equal_i(13, file_count);
|
||||||
cl_assert_equal_i(8, hunk_count);
|
cl_assert_equal_i(8, hunk_count);
|
||||||
|
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_diff_diffiter__max_size_threshold(void)
|
void test_diff_diffiter__max_size_threshold(void)
|
||||||
{
|
{
|
||||||
git_repository *repo = cl_git_sandbox_init("status");
|
git_repository *repo = cl_git_sandbox_init("status");
|
||||||
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
|
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
|
||||||
git_diff_list *diff = NULL;
|
git_diff *diff = NULL;
|
||||||
int file_count = 0, binary_count = 0, hunk_count = 0;
|
int file_count = 0, binary_count = 0, hunk_count = 0;
|
||||||
size_t d, num_d;
|
size_t d, num_d;
|
||||||
|
|
||||||
@ -142,27 +134,28 @@ void test_diff_diffiter__max_size_threshold(void)
|
|||||||
num_d = git_diff_num_deltas(diff);
|
num_d = git_diff_num_deltas(diff);
|
||||||
|
|
||||||
for (d = 0; d < num_d; ++d) {
|
for (d = 0; d < num_d; ++d) {
|
||||||
git_diff_patch *patch;
|
git_patch *patch;
|
||||||
const git_diff_delta *delta;
|
const git_diff_delta *delta;
|
||||||
|
|
||||||
cl_git_pass(git_diff_get_patch(&patch, &delta, diff, d));
|
cl_git_pass(git_patch_from_diff(&patch, diff, d));
|
||||||
cl_assert(delta);
|
|
||||||
cl_assert(patch);
|
cl_assert(patch);
|
||||||
|
delta = git_patch_get_delta(patch);
|
||||||
|
cl_assert(delta);
|
||||||
|
|
||||||
file_count++;
|
file_count++;
|
||||||
hunk_count += (int)git_diff_patch_num_hunks(patch);
|
hunk_count += (int)git_patch_num_hunks(patch);
|
||||||
|
|
||||||
assert((delta->flags & (GIT_DIFF_FLAG_BINARY|GIT_DIFF_FLAG_NOT_BINARY)) != 0);
|
assert((delta->flags & (GIT_DIFF_FLAG_BINARY|GIT_DIFF_FLAG_NOT_BINARY)) != 0);
|
||||||
binary_count += ((delta->flags & GIT_DIFF_FLAG_BINARY) != 0);
|
binary_count += ((delta->flags & GIT_DIFF_FLAG_BINARY) != 0);
|
||||||
|
|
||||||
git_diff_patch_free(patch);
|
git_patch_free(patch);
|
||||||
}
|
}
|
||||||
|
|
||||||
cl_assert_equal_i(13, file_count);
|
cl_assert_equal_i(13, file_count);
|
||||||
cl_assert_equal_i(0, binary_count);
|
cl_assert_equal_i(0, binary_count);
|
||||||
cl_assert_equal_i(8, hunk_count);
|
cl_assert_equal_i(8, hunk_count);
|
||||||
|
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
|
|
||||||
/* try again with low file size threshold */
|
/* try again with low file size threshold */
|
||||||
|
|
||||||
@ -177,18 +170,19 @@ void test_diff_diffiter__max_size_threshold(void)
|
|||||||
num_d = git_diff_num_deltas(diff);
|
num_d = git_diff_num_deltas(diff);
|
||||||
|
|
||||||
for (d = 0; d < num_d; ++d) {
|
for (d = 0; d < num_d; ++d) {
|
||||||
git_diff_patch *patch;
|
git_patch *patch;
|
||||||
const git_diff_delta *delta;
|
const git_diff_delta *delta;
|
||||||
|
|
||||||
cl_git_pass(git_diff_get_patch(&patch, &delta, diff, d));
|
cl_git_pass(git_patch_from_diff(&patch, diff, d));
|
||||||
|
delta = git_patch_get_delta(patch);
|
||||||
|
|
||||||
file_count++;
|
file_count++;
|
||||||
hunk_count += (int)git_diff_patch_num_hunks(patch);
|
hunk_count += (int)git_patch_num_hunks(patch);
|
||||||
|
|
||||||
assert((delta->flags & (GIT_DIFF_FLAG_BINARY|GIT_DIFF_FLAG_NOT_BINARY)) != 0);
|
assert((delta->flags & (GIT_DIFF_FLAG_BINARY|GIT_DIFF_FLAG_NOT_BINARY)) != 0);
|
||||||
binary_count += ((delta->flags & GIT_DIFF_FLAG_BINARY) != 0);
|
binary_count += ((delta->flags & GIT_DIFF_FLAG_BINARY) != 0);
|
||||||
|
|
||||||
git_diff_patch_free(patch);
|
git_patch_free(patch);
|
||||||
}
|
}
|
||||||
|
|
||||||
cl_assert_equal_i(13, file_count);
|
cl_assert_equal_i(13, file_count);
|
||||||
@ -200,7 +194,7 @@ void test_diff_diffiter__max_size_threshold(void)
|
|||||||
cl_assert_equal_i(3, binary_count);
|
cl_assert_equal_i(3, binary_count);
|
||||||
cl_assert_equal_i(5, hunk_count);
|
cl_assert_equal_i(5, hunk_count);
|
||||||
|
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -208,7 +202,7 @@ void test_diff_diffiter__iterate_all(void)
|
|||||||
{
|
{
|
||||||
git_repository *repo = cl_git_sandbox_init("status");
|
git_repository *repo = cl_git_sandbox_init("status");
|
||||||
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
|
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
|
||||||
git_diff_list *diff = NULL;
|
git_diff *diff = NULL;
|
||||||
diff_expects exp = {0};
|
diff_expects exp = {0};
|
||||||
size_t d, num_d;
|
size_t d, num_d;
|
||||||
|
|
||||||
@ -220,57 +214,51 @@ void test_diff_diffiter__iterate_all(void)
|
|||||||
|
|
||||||
num_d = git_diff_num_deltas(diff);
|
num_d = git_diff_num_deltas(diff);
|
||||||
for (d = 0; d < num_d; ++d) {
|
for (d = 0; d < num_d; ++d) {
|
||||||
git_diff_patch *patch;
|
git_patch *patch;
|
||||||
const git_diff_delta *delta;
|
|
||||||
size_t h, num_h;
|
size_t h, num_h;
|
||||||
|
|
||||||
cl_git_pass(git_diff_get_patch(&patch, &delta, diff, d));
|
cl_git_pass(git_patch_from_diff(&patch, diff, d));
|
||||||
cl_assert(patch && delta);
|
cl_assert(patch);
|
||||||
exp.files++;
|
exp.files++;
|
||||||
|
|
||||||
num_h = git_diff_patch_num_hunks(patch);
|
num_h = git_patch_num_hunks(patch);
|
||||||
for (h = 0; h < num_h; h++) {
|
for (h = 0; h < num_h; h++) {
|
||||||
const git_diff_range *range;
|
const git_diff_hunk *range;
|
||||||
const char *header;
|
size_t l, num_l;
|
||||||
size_t header_len, l, num_l;
|
|
||||||
|
|
||||||
cl_git_pass(git_diff_patch_get_hunk(
|
cl_git_pass(git_patch_get_hunk(&range, &num_l, patch, h));
|
||||||
&range, &header, &header_len, &num_l, patch, h));
|
cl_assert(range);
|
||||||
cl_assert(range && header);
|
|
||||||
exp.hunks++;
|
exp.hunks++;
|
||||||
|
|
||||||
for (l = 0; l < num_l; ++l) {
|
for (l = 0; l < num_l; ++l) {
|
||||||
char origin;
|
const git_diff_line *line;
|
||||||
const char *content;
|
|
||||||
size_t content_len;
|
|
||||||
|
|
||||||
cl_git_pass(git_diff_patch_get_line_in_hunk(
|
cl_git_pass(git_patch_get_line_in_hunk(&line, patch, h, l));
|
||||||
&origin, &content, &content_len, NULL, NULL, patch, h, l));
|
cl_assert(line && line->content);
|
||||||
cl_assert(content);
|
|
||||||
exp.lines++;
|
exp.lines++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
git_diff_patch_free(patch);
|
git_patch_free(patch);
|
||||||
}
|
}
|
||||||
|
|
||||||
cl_assert_equal_i(13, exp.files);
|
cl_assert_equal_i(13, exp.files);
|
||||||
cl_assert_equal_i(8, exp.hunks);
|
cl_assert_equal_i(8, exp.hunks);
|
||||||
cl_assert_equal_i(14, exp.lines);
|
cl_assert_equal_i(14, exp.lines);
|
||||||
|
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void iterate_over_patch(git_diff_patch *patch, diff_expects *exp)
|
static void iterate_over_patch(git_patch *patch, diff_expects *exp)
|
||||||
{
|
{
|
||||||
size_t h, num_h = git_diff_patch_num_hunks(patch), num_l;
|
size_t h, num_h = git_patch_num_hunks(patch), num_l;
|
||||||
|
|
||||||
exp->files++;
|
exp->files++;
|
||||||
exp->hunks += (int)num_h;
|
exp->hunks += (int)num_h;
|
||||||
|
|
||||||
/* let's iterate in reverse, just because we can! */
|
/* let's iterate in reverse, just because we can! */
|
||||||
for (h = 1, num_l = 0; h <= num_h; ++h)
|
for (h = 1, num_l = 0; h <= num_h; ++h)
|
||||||
num_l += git_diff_patch_num_lines_in_hunk(patch, num_h - h);
|
num_l += git_patch_num_lines_in_hunk(patch, num_h - h);
|
||||||
|
|
||||||
exp->lines += (int)num_l;
|
exp->lines += (int)num_l;
|
||||||
}
|
}
|
||||||
@ -281,9 +269,9 @@ void test_diff_diffiter__iterate_randomly_while_saving_state(void)
|
|||||||
{
|
{
|
||||||
git_repository *repo = cl_git_sandbox_init("status");
|
git_repository *repo = cl_git_sandbox_init("status");
|
||||||
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
|
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
|
||||||
git_diff_list *diff = NULL;
|
git_diff *diff = NULL;
|
||||||
diff_expects exp = {0};
|
diff_expects exp = {0};
|
||||||
git_diff_patch *patches[PATCH_CACHE];
|
git_patch *patches[PATCH_CACHE];
|
||||||
size_t p, d, num_d;
|
size_t p, d, num_d;
|
||||||
|
|
||||||
memset(patches, 0, sizeof(patches));
|
memset(patches, 0, sizeof(patches));
|
||||||
@ -308,32 +296,32 @@ void test_diff_diffiter__iterate_randomly_while_saving_state(void)
|
|||||||
|
|
||||||
for (d = 0; d < num_d; ++d) {
|
for (d = 0; d < num_d; ++d) {
|
||||||
/* take old patch */
|
/* take old patch */
|
||||||
git_diff_patch *patch = patches[p];
|
git_patch *patch = patches[p];
|
||||||
patches[p] = NULL;
|
patches[p] = NULL;
|
||||||
|
|
||||||
/* cache new patch */
|
/* cache new patch */
|
||||||
cl_git_pass(git_diff_get_patch(&patches[p], NULL, diff, d));
|
cl_git_pass(git_patch_from_diff(&patches[p], diff, d));
|
||||||
cl_assert(patches[p] != NULL);
|
cl_assert(patches[p] != NULL);
|
||||||
|
|
||||||
/* process old patch if non-NULL */
|
/* process old patch if non-NULL */
|
||||||
if (patch != NULL) {
|
if (patch != NULL) {
|
||||||
iterate_over_patch(patch, &exp);
|
iterate_over_patch(patch, &exp);
|
||||||
git_diff_patch_free(patch);
|
git_patch_free(patch);
|
||||||
}
|
}
|
||||||
|
|
||||||
p = rand() % PATCH_CACHE;
|
p = rand() % PATCH_CACHE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* free diff list now - refcounts should keep things safe */
|
/* free diff list now - refcounts should keep things safe */
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
|
|
||||||
/* process remaining unprocessed patches */
|
/* process remaining unprocessed patches */
|
||||||
for (p = 0; p < PATCH_CACHE; p++) {
|
for (p = 0; p < PATCH_CACHE; p++) {
|
||||||
git_diff_patch *patch = patches[p];
|
git_patch *patch = patches[p];
|
||||||
|
|
||||||
if (patch != NULL) {
|
if (patch != NULL) {
|
||||||
iterate_over_patch(patch, &exp);
|
iterate_over_patch(patch, &exp);
|
||||||
git_diff_patch_free(patch);
|
git_patch_free(patch);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -416,7 +404,7 @@ static const char *expected_patch_text[8] = {
|
|||||||
void test_diff_diffiter__iterate_and_generate_patch_text(void)
|
void test_diff_diffiter__iterate_and_generate_patch_text(void)
|
||||||
{
|
{
|
||||||
git_repository *repo = cl_git_sandbox_init("status");
|
git_repository *repo = cl_git_sandbox_init("status");
|
||||||
git_diff_list *diff;
|
git_diff *diff;
|
||||||
size_t d, num_d;
|
size_t d, num_d;
|
||||||
|
|
||||||
cl_git_pass(git_diff_index_to_workdir(&diff, repo, NULL, NULL));
|
cl_git_pass(git_diff_index_to_workdir(&diff, repo, NULL, NULL));
|
||||||
@ -425,28 +413,28 @@ void test_diff_diffiter__iterate_and_generate_patch_text(void)
|
|||||||
cl_assert_equal_i(8, (int)num_d);
|
cl_assert_equal_i(8, (int)num_d);
|
||||||
|
|
||||||
for (d = 0; d < num_d; ++d) {
|
for (d = 0; d < num_d; ++d) {
|
||||||
git_diff_patch *patch;
|
git_patch *patch;
|
||||||
char *text;
|
char *text;
|
||||||
|
|
||||||
cl_git_pass(git_diff_get_patch(&patch, NULL, diff, d));
|
cl_git_pass(git_patch_from_diff(&patch, diff, d));
|
||||||
cl_assert(patch != NULL);
|
cl_assert(patch != NULL);
|
||||||
|
|
||||||
cl_git_pass(git_diff_patch_to_str(&text, patch));
|
cl_git_pass(git_patch_to_str(&text, patch));
|
||||||
|
|
||||||
cl_assert_equal_s(expected_patch_text[d], text);
|
cl_assert_equal_s(expected_patch_text[d], text);
|
||||||
|
|
||||||
git__free(text);
|
git__free(text);
|
||||||
git_diff_patch_free(patch);
|
git_patch_free(patch);
|
||||||
}
|
}
|
||||||
|
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_diff_diffiter__checks_options_version(void)
|
void test_diff_diffiter__checks_options_version(void)
|
||||||
{
|
{
|
||||||
git_repository *repo = cl_git_sandbox_init("status");
|
git_repository *repo = cl_git_sandbox_init("status");
|
||||||
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
|
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
|
||||||
git_diff_list *diff = NULL;
|
git_diff *diff = NULL;
|
||||||
const git_error *err;
|
const git_error *err;
|
||||||
|
|
||||||
opts.version = 0;
|
opts.version = 0;
|
||||||
|
@ -20,8 +20,8 @@ void test_diff_drivers__patterns(void)
|
|||||||
git_config *cfg;
|
git_config *cfg;
|
||||||
const char *one_sha = "19dd32dfb1520a64e5bbaae8dce6ef423dfa2f13";
|
const char *one_sha = "19dd32dfb1520a64e5bbaae8dce6ef423dfa2f13";
|
||||||
git_tree *one;
|
git_tree *one;
|
||||||
git_diff_list *diff;
|
git_diff *diff;
|
||||||
git_diff_patch *patch;
|
git_patch *patch;
|
||||||
char *text;
|
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 *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";
|
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_git_pass(git_diff_tree_to_workdir(&diff, g_repo, one, NULL));
|
||||||
cl_assert_equal_i(0, (int)git_diff_num_deltas(diff));
|
cl_assert_equal_i(0, (int)git_diff_num_deltas(diff));
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
|
|
||||||
/* default 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_git_pass(git_diff_tree_to_workdir(&diff, g_repo, one, NULL));
|
||||||
cl_assert_equal_i(1, (int)git_diff_num_deltas(diff));
|
cl_assert_equal_i(1, (int)git_diff_num_deltas(diff));
|
||||||
|
|
||||||
cl_git_pass(git_diff_get_patch(&patch, NULL, diff, 0));
|
cl_git_pass(git_patch_from_diff(&patch, diff, 0));
|
||||||
cl_git_pass(git_diff_patch_to_str(&text, patch));
|
cl_git_pass(git_patch_to_str(&text, patch));
|
||||||
cl_assert_equal_s(expected0, text);
|
cl_assert_equal_s(expected0, text);
|
||||||
|
|
||||||
git__free(text);
|
git__free(text);
|
||||||
git_diff_patch_free(patch);
|
git_patch_free(patch);
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
|
|
||||||
/* attribute diff set to false */
|
/* 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_git_pass(git_diff_tree_to_workdir(&diff, g_repo, one, NULL));
|
||||||
cl_assert_equal_i(1, (int)git_diff_num_deltas(diff));
|
cl_assert_equal_i(1, (int)git_diff_num_deltas(diff));
|
||||||
|
|
||||||
cl_git_pass(git_diff_get_patch(&patch, NULL, diff, 0));
|
cl_git_pass(git_patch_from_diff(&patch, diff, 0));
|
||||||
cl_git_pass(git_diff_patch_to_str(&text, patch));
|
cl_git_pass(git_patch_to_str(&text, patch));
|
||||||
cl_assert_equal_s(expected1, text);
|
cl_assert_equal_s(expected1, text);
|
||||||
|
|
||||||
git__free(text);
|
git__free(text);
|
||||||
git_diff_patch_free(patch);
|
git_patch_free(patch);
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
|
|
||||||
/* attribute diff set to unconfigured value (should use default) */
|
/* 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_git_pass(git_diff_tree_to_workdir(&diff, g_repo, one, NULL));
|
||||||
cl_assert_equal_i(1, (int)git_diff_num_deltas(diff));
|
cl_assert_equal_i(1, (int)git_diff_num_deltas(diff));
|
||||||
|
|
||||||
cl_git_pass(git_diff_get_patch(&patch, NULL, diff, 0));
|
cl_git_pass(git_patch_from_diff(&patch, diff, 0));
|
||||||
cl_git_pass(git_diff_patch_to_str(&text, patch));
|
cl_git_pass(git_patch_to_str(&text, patch));
|
||||||
cl_assert_equal_s(expected0, text);
|
cl_assert_equal_s(expected0, text);
|
||||||
|
|
||||||
git__free(text);
|
git__free(text);
|
||||||
git_diff_patch_free(patch);
|
git_patch_free(patch);
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
|
|
||||||
/* let's define that driver */
|
/* 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_git_pass(git_diff_tree_to_workdir(&diff, g_repo, one, NULL));
|
||||||
cl_assert_equal_i(1, (int)git_diff_num_deltas(diff));
|
cl_assert_equal_i(1, (int)git_diff_num_deltas(diff));
|
||||||
|
|
||||||
cl_git_pass(git_diff_get_patch(&patch, NULL, diff, 0));
|
cl_git_pass(git_patch_from_diff(&patch, diff, 0));
|
||||||
cl_git_pass(git_diff_patch_to_str(&text, patch));
|
cl_git_pass(git_patch_to_str(&text, patch));
|
||||||
cl_assert_equal_s(expected1, text);
|
cl_assert_equal_s(expected1, text);
|
||||||
|
|
||||||
git__free(text);
|
git__free(text);
|
||||||
git_diff_patch_free(patch);
|
git_patch_free(patch);
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
|
|
||||||
/* let's use a real driver with some regular expressions */
|
/* 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_git_pass(git_diff_tree_to_workdir(&diff, g_repo, one, NULL));
|
||||||
cl_assert_equal_i(1, (int)git_diff_num_deltas(diff));
|
cl_assert_equal_i(1, (int)git_diff_num_deltas(diff));
|
||||||
|
|
||||||
cl_git_pass(git_diff_get_patch(&patch, NULL, diff, 0));
|
cl_git_pass(git_patch_from_diff(&patch, diff, 0));
|
||||||
cl_git_pass(git_diff_patch_to_str(&text, patch));
|
cl_git_pass(git_patch_to_str(&text, patch));
|
||||||
cl_assert_equal_s(expected2, text);
|
cl_assert_equal_s(expected2, text);
|
||||||
|
|
||||||
git__free(text);
|
git__free(text);
|
||||||
git_diff_patch_free(patch);
|
git_patch_free(patch);
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
|
|
||||||
git_tree_free(one);
|
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";
|
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_index *idx;
|
||||||
git_diff_list *diff;
|
git_diff *diff;
|
||||||
git_diff_patch *patch;
|
git_patch *patch;
|
||||||
char *actual;
|
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";
|
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_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, NULL));
|
||||||
cl_assert_equal_sz(1, git_diff_num_deltas(diff));
|
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_patch_from_diff(&patch, diff, 0));
|
||||||
cl_git_pass(git_diff_patch_to_str(&actual, patch));
|
cl_git_pass(git_patch_to_str(&actual, patch));
|
||||||
|
|
||||||
/* if chmod not supported, overwrite mode bits since anything is possible */
|
/* if chmod not supported, overwrite mode bits since anything is possible */
|
||||||
if (!cl_is_chmod_supported()) {
|
if (!cl_is_chmod_supported()) {
|
||||||
@ -157,7 +157,7 @@ void test_diff_drivers__long_lines(void)
|
|||||||
cl_assert_equal_s(expected, actual);
|
cl_assert_equal_s(expected, actual);
|
||||||
|
|
||||||
free(actual);
|
free(actual);
|
||||||
git_diff_patch_free(patch);
|
git_patch_free(patch);
|
||||||
git_diff_list_free(diff);
|
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 *a = resolve_commit_oid_to_tree(g_repo, a_commit);
|
||||||
git_tree *b = resolve_commit_oid_to_tree(g_repo, b_commit);
|
git_tree *b = resolve_commit_oid_to_tree(g_repo, b_commit);
|
||||||
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
|
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
|
||||||
git_diff_list *diff = NULL;
|
git_diff *diff = NULL;
|
||||||
diff_expects exp;
|
diff_expects exp;
|
||||||
|
|
||||||
cl_assert(a);
|
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(6, exp.line_adds);
|
||||||
cl_assert_equal_i(2, exp.line_dels);
|
cl_assert_equal_i(2, exp.line_dels);
|
||||||
|
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
diff = NULL;
|
diff = NULL;
|
||||||
memset(&exp, 0, sizeof(exp));
|
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(11, exp.line_adds);
|
||||||
cl_assert_equal_i(2, exp.line_dels);
|
cl_assert_equal_i(2, exp.line_dels);
|
||||||
|
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
diff = NULL;
|
diff = NULL;
|
||||||
|
|
||||||
git_tree_free(a);
|
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 *a = resolve_commit_oid_to_tree(g_repo, a_commit);
|
||||||
git_tree *b = resolve_commit_oid_to_tree(g_repo, b_commit);
|
git_tree *b = resolve_commit_oid_to_tree(g_repo, b_commit);
|
||||||
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
|
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
|
||||||
git_diff_list *diff = NULL;
|
git_diff *diff = NULL;
|
||||||
diff_expects exp;
|
diff_expects exp;
|
||||||
|
|
||||||
cl_assert(a);
|
cl_assert(a);
|
||||||
@ -134,7 +134,7 @@ void test_diff_index__1(void)
|
|||||||
|
|
||||||
cl_assert_equal_i(2, exp.files);
|
cl_assert_equal_i(2, exp.files);
|
||||||
|
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
diff = NULL;
|
diff = NULL;
|
||||||
|
|
||||||
git_tree_free(a);
|
git_tree_free(a);
|
||||||
@ -146,7 +146,7 @@ void test_diff_index__checks_options_version(void)
|
|||||||
const char *a_commit = "26a125ee1bf";
|
const char *a_commit = "26a125ee1bf";
|
||||||
git_tree *a = resolve_commit_oid_to_tree(g_repo, a_commit);
|
git_tree *a = resolve_commit_oid_to_tree(g_repo, a_commit);
|
||||||
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
|
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
|
||||||
git_diff_list *diff = NULL;
|
git_diff *diff = NULL;
|
||||||
const git_error *err;
|
const git_error *err;
|
||||||
|
|
||||||
opts.version = 0;
|
opts.version = 0;
|
||||||
|
@ -13,7 +13,7 @@ void test_diff_notify__cleanup(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int assert_called_notifications(
|
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 git_diff_delta *delta_to_add,
|
||||||
const char *matched_pathspec,
|
const char *matched_pathspec,
|
||||||
void *payload)
|
void *payload)
|
||||||
@ -45,7 +45,7 @@ static void test_notify(
|
|||||||
int expected_diffed_files_count)
|
int expected_diffed_files_count)
|
||||||
{
|
{
|
||||||
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
|
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
|
||||||
git_diff_list *diff = NULL;
|
git_diff *diff = NULL;
|
||||||
diff_expects exp;
|
diff_expects exp;
|
||||||
|
|
||||||
g_repo = cl_git_sandbox_init("status");
|
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);
|
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)
|
void test_diff_notify__notify_single_pathspec(void)
|
||||||
@ -155,7 +155,7 @@ void test_diff_notify__notify_catchall(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int abort_diff(
|
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 git_diff_delta *delta_to_add,
|
||||||
const char *matched_pathspec,
|
const char *matched_pathspec,
|
||||||
void *payload)
|
void *payload)
|
||||||
@ -171,7 +171,7 @@ static int abort_diff(
|
|||||||
void test_diff_notify__notify_cb_can_abort_diff(void)
|
void test_diff_notify__notify_cb_can_abort_diff(void)
|
||||||
{
|
{
|
||||||
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
|
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
|
||||||
git_diff_list *diff = NULL;
|
git_diff *diff = NULL;
|
||||||
char *pathspec = NULL;
|
char *pathspec = NULL;
|
||||||
|
|
||||||
g_repo = cl_git_sandbox_init("status");
|
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(
|
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 git_diff_delta *delta_to_add,
|
||||||
const char *matched_pathspec,
|
const char *matched_pathspec,
|
||||||
void *payload)
|
void *payload)
|
||||||
@ -205,7 +205,7 @@ static int filter_all(
|
|||||||
void test_diff_notify__notify_cb_can_be_used_as_filtering_function(void)
|
void test_diff_notify__notify_cb_can_be_used_as_filtering_function(void)
|
||||||
{
|
{
|
||||||
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
|
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
|
||||||
git_diff_list *diff = NULL;
|
git_diff *diff = NULL;
|
||||||
char *pathspec = NULL;
|
char *pathspec = NULL;
|
||||||
diff_expects exp;
|
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);
|
cl_assert_equal_i(0, exp.files);
|
||||||
|
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
}
|
}
|
||||||
|
@ -26,40 +26,37 @@ void test_diff_patch__cleanup(void)
|
|||||||
|
|
||||||
static int check_removal_cb(
|
static int check_removal_cb(
|
||||||
const git_diff_delta *delta,
|
const git_diff_delta *delta,
|
||||||
const git_diff_range *range,
|
const git_diff_hunk *hunk,
|
||||||
char line_origin,
|
const git_diff_line *line,
|
||||||
const char *formatted_output,
|
|
||||||
size_t output_len,
|
|
||||||
void *payload)
|
void *payload)
|
||||||
{
|
{
|
||||||
GIT_UNUSED(payload);
|
GIT_UNUSED(payload);
|
||||||
GIT_UNUSED(output_len);
|
|
||||||
|
|
||||||
switch (line_origin) {
|
switch (line->origin) {
|
||||||
case GIT_DIFF_LINE_FILE_HDR:
|
case GIT_DIFF_LINE_FILE_HDR:
|
||||||
cl_assert_equal_s(EXPECTED_HEADER, formatted_output);
|
cl_assert_equal_s(EXPECTED_HEADER, line->content);
|
||||||
cl_assert(range == NULL);
|
cl_assert(hunk == NULL);
|
||||||
goto check_delta;
|
goto check_delta;
|
||||||
|
|
||||||
case GIT_DIFF_LINE_HUNK_HDR:
|
case GIT_DIFF_LINE_HUNK_HDR:
|
||||||
cl_assert_equal_s(EXPECTED_HUNK, formatted_output);
|
cl_assert_equal_s(EXPECTED_HUNK, line->content);
|
||||||
/* Fall through */
|
/* Fall through */
|
||||||
|
|
||||||
case GIT_DIFF_LINE_CONTEXT:
|
case GIT_DIFF_LINE_CONTEXT:
|
||||||
case GIT_DIFF_LINE_DELETION:
|
case GIT_DIFF_LINE_DELETION:
|
||||||
goto check_range;
|
goto check_hunk;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
/* unexpected code path */
|
/* unexpected code path */
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
check_range:
|
check_hunk:
|
||||||
cl_assert(range != NULL);
|
cl_assert(hunk != NULL);
|
||||||
cl_assert_equal_i(1, range->old_start);
|
cl_assert_equal_i(1, hunk->old_start);
|
||||||
cl_assert_equal_i(2, range->old_lines);
|
cl_assert_equal_i(2, hunk->old_lines);
|
||||||
cl_assert_equal_i(0, range->new_start);
|
cl_assert_equal_i(0, hunk->new_start);
|
||||||
cl_assert_equal_i(0, range->new_lines);
|
cl_assert_equal_i(0, hunk->new_lines);
|
||||||
|
|
||||||
check_delta:
|
check_delta:
|
||||||
cl_assert_equal_s("subdir.txt", delta->old_file.path);
|
cl_assert_equal_s("subdir.txt", delta->old_file.path);
|
||||||
@ -86,7 +83,7 @@ void test_diff_patch__can_properly_display_the_removal_of_a_file(void)
|
|||||||
const char *one_sha = "26a125e";
|
const char *one_sha = "26a125e";
|
||||||
const char *another_sha = "735b6a2";
|
const char *another_sha = "735b6a2";
|
||||||
git_tree *one, *another;
|
git_tree *one, *another;
|
||||||
git_diff_list *diff;
|
git_diff *diff;
|
||||||
|
|
||||||
g_repo = cl_git_sandbox_init("status");
|
g_repo = cl_git_sandbox_init("status");
|
||||||
|
|
||||||
@ -95,9 +92,10 @@ void test_diff_patch__can_properly_display_the_removal_of_a_file(void)
|
|||||||
|
|
||||||
cl_git_pass(git_diff_tree_to_tree(&diff, g_repo, one, another, NULL));
|
cl_git_pass(git_diff_tree_to_tree(&diff, g_repo, one, another, NULL));
|
||||||
|
|
||||||
cl_git_pass(git_diff_print_patch(diff, check_removal_cb, NULL));
|
cl_git_pass(git_diff_print(
|
||||||
|
diff, GIT_DIFF_FORMAT_PATCH, check_removal_cb, NULL));
|
||||||
|
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
|
|
||||||
git_tree_free(another);
|
git_tree_free(another);
|
||||||
git_tree_free(one);
|
git_tree_free(one);
|
||||||
@ -108,8 +106,8 @@ void test_diff_patch__to_string(void)
|
|||||||
const char *one_sha = "26a125e";
|
const char *one_sha = "26a125e";
|
||||||
const char *another_sha = "735b6a2";
|
const char *another_sha = "735b6a2";
|
||||||
git_tree *one, *another;
|
git_tree *one, *another;
|
||||||
git_diff_list *diff;
|
git_diff *diff;
|
||||||
git_diff_patch *patch;
|
git_patch *patch;
|
||||||
char *text;
|
char *text;
|
||||||
const char *expected = "diff --git a/subdir.txt b/subdir.txt\ndeleted file mode 100644\nindex e8ee89e..0000000\n--- a/subdir.txt\n+++ /dev/null\n@@ -1,2 +0,0 @@\n-Is it a bird?\n-Is it a plane?\n";
|
const char *expected = "diff --git a/subdir.txt b/subdir.txt\ndeleted file mode 100644\nindex e8ee89e..0000000\n--- a/subdir.txt\n+++ /dev/null\n@@ -1,2 +0,0 @@\n-Is it a bird?\n-Is it a plane?\n";
|
||||||
|
|
||||||
@ -122,20 +120,20 @@ void test_diff_patch__to_string(void)
|
|||||||
|
|
||||||
cl_assert_equal_i(1, (int)git_diff_num_deltas(diff));
|
cl_assert_equal_i(1, (int)git_diff_num_deltas(diff));
|
||||||
|
|
||||||
cl_git_pass(git_diff_get_patch(&patch, NULL, diff, 0));
|
cl_git_pass(git_patch_from_diff(&patch, diff, 0));
|
||||||
|
|
||||||
cl_git_pass(git_diff_patch_to_str(&text, patch));
|
cl_git_pass(git_patch_to_str(&text, patch));
|
||||||
|
|
||||||
cl_assert_equal_s(expected, text);
|
cl_assert_equal_s(expected, text);
|
||||||
|
|
||||||
cl_assert_equal_sz(31, git_diff_patch_size(patch, 0, 0, 0));
|
cl_assert_equal_sz(31, git_patch_size(patch, 0, 0, 0));
|
||||||
cl_assert_equal_sz(31, git_diff_patch_size(patch, 1, 0, 0));
|
cl_assert_equal_sz(31, git_patch_size(patch, 1, 0, 0));
|
||||||
cl_assert_equal_sz(31 + 16, git_diff_patch_size(patch, 1, 1, 0));
|
cl_assert_equal_sz(31 + 16, git_patch_size(patch, 1, 1, 0));
|
||||||
cl_assert_equal_sz(strlen(expected), git_diff_patch_size(patch, 1, 1, 1));
|
cl_assert_equal_sz(strlen(expected), git_patch_size(patch, 1, 1, 1));
|
||||||
|
|
||||||
git__free(text);
|
git__free(text);
|
||||||
git_diff_patch_free(patch);
|
git_patch_free(patch);
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
git_tree_free(another);
|
git_tree_free(another);
|
||||||
git_tree_free(one);
|
git_tree_free(one);
|
||||||
}
|
}
|
||||||
@ -145,8 +143,8 @@ void test_diff_patch__config_options(void)
|
|||||||
const char *one_sha = "26a125e"; /* current HEAD */
|
const char *one_sha = "26a125e"; /* current HEAD */
|
||||||
git_tree *one;
|
git_tree *one;
|
||||||
git_config *cfg;
|
git_config *cfg;
|
||||||
git_diff_list *diff;
|
git_diff *diff;
|
||||||
git_diff_patch *patch;
|
git_patch *patch;
|
||||||
char *text;
|
char *text;
|
||||||
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
|
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
|
||||||
char *onefile = "staged_changes_modified_file";
|
char *onefile = "staged_changes_modified_file";
|
||||||
@ -167,24 +165,24 @@ void test_diff_patch__config_options(void)
|
|||||||
cl_git_pass(git_diff_tree_to_index(&diff, g_repo, one, NULL, &opts));
|
cl_git_pass(git_diff_tree_to_index(&diff, g_repo, one, NULL, &opts));
|
||||||
|
|
||||||
cl_assert_equal_i(1, (int)git_diff_num_deltas(diff));
|
cl_assert_equal_i(1, (int)git_diff_num_deltas(diff));
|
||||||
cl_git_pass(git_diff_get_patch(&patch, NULL, diff, 0));
|
cl_git_pass(git_patch_from_diff(&patch, diff, 0));
|
||||||
cl_git_pass(git_diff_patch_to_str(&text, patch));
|
cl_git_pass(git_patch_to_str(&text, patch));
|
||||||
cl_assert_equal_s(expected1, text);
|
cl_assert_equal_s(expected1, text);
|
||||||
|
|
||||||
git__free(text);
|
git__free(text);
|
||||||
git_diff_patch_free(patch);
|
git_patch_free(patch);
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
|
|
||||||
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
|
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
|
||||||
|
|
||||||
cl_assert_equal_i(1, (int)git_diff_num_deltas(diff));
|
cl_assert_equal_i(1, (int)git_diff_num_deltas(diff));
|
||||||
cl_git_pass(git_diff_get_patch(&patch, NULL, diff, 0));
|
cl_git_pass(git_patch_from_diff(&patch, diff, 0));
|
||||||
cl_git_pass(git_diff_patch_to_str(&text, patch));
|
cl_git_pass(git_patch_to_str(&text, patch));
|
||||||
cl_assert_equal_s(expected2, text);
|
cl_assert_equal_s(expected2, text);
|
||||||
|
|
||||||
git__free(text);
|
git__free(text);
|
||||||
git_diff_patch_free(patch);
|
git_patch_free(patch);
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
|
|
||||||
|
|
||||||
cl_git_pass(git_config_set_string(cfg, "diff.noprefix", "true"));
|
cl_git_pass(git_config_set_string(cfg, "diff.noprefix", "true"));
|
||||||
@ -192,13 +190,13 @@ void test_diff_patch__config_options(void)
|
|||||||
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
|
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
|
||||||
|
|
||||||
cl_assert_equal_i(1, (int)git_diff_num_deltas(diff));
|
cl_assert_equal_i(1, (int)git_diff_num_deltas(diff));
|
||||||
cl_git_pass(git_diff_get_patch(&patch, NULL, diff, 0));
|
cl_git_pass(git_patch_from_diff(&patch, diff, 0));
|
||||||
cl_git_pass(git_diff_patch_to_str(&text, patch));
|
cl_git_pass(git_patch_to_str(&text, patch));
|
||||||
cl_assert_equal_s(expected3, text);
|
cl_assert_equal_s(expected3, text);
|
||||||
|
|
||||||
git__free(text);
|
git__free(text);
|
||||||
git_diff_patch_free(patch);
|
git_patch_free(patch);
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
|
|
||||||
|
|
||||||
cl_git_pass(git_config_set_int32(cfg, "core.abbrev", 12));
|
cl_git_pass(git_config_set_int32(cfg, "core.abbrev", 12));
|
||||||
@ -206,13 +204,13 @@ void test_diff_patch__config_options(void)
|
|||||||
cl_git_pass(git_diff_tree_to_index(&diff, g_repo, one, NULL, &opts));
|
cl_git_pass(git_diff_tree_to_index(&diff, g_repo, one, NULL, &opts));
|
||||||
|
|
||||||
cl_assert_equal_i(1, (int)git_diff_num_deltas(diff));
|
cl_assert_equal_i(1, (int)git_diff_num_deltas(diff));
|
||||||
cl_git_pass(git_diff_get_patch(&patch, NULL, diff, 0));
|
cl_git_pass(git_patch_from_diff(&patch, diff, 0));
|
||||||
cl_git_pass(git_diff_patch_to_str(&text, patch));
|
cl_git_pass(git_patch_to_str(&text, patch));
|
||||||
cl_assert_equal_s(expected4, text);
|
cl_assert_equal_s(expected4, text);
|
||||||
|
|
||||||
git__free(text);
|
git__free(text);
|
||||||
git_diff_patch_free(patch);
|
git_patch_free(patch);
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
|
|
||||||
git_tree_free(one);
|
git_tree_free(one);
|
||||||
git_config_free(cfg);
|
git_config_free(cfg);
|
||||||
@ -223,14 +221,12 @@ void test_diff_patch__hunks_have_correct_line_numbers(void)
|
|||||||
git_config *cfg;
|
git_config *cfg;
|
||||||
git_tree *head;
|
git_tree *head;
|
||||||
git_diff_options opt = GIT_DIFF_OPTIONS_INIT;
|
git_diff_options opt = GIT_DIFF_OPTIONS_INIT;
|
||||||
git_diff_list *diff;
|
git_diff *diff;
|
||||||
git_diff_patch *patch;
|
git_patch *patch;
|
||||||
const git_diff_delta *delta;
|
const git_diff_delta *delta;
|
||||||
const git_diff_range *range;
|
const git_diff_hunk *hunk;
|
||||||
const char *hdr, *text;
|
const git_diff_line *line;
|
||||||
size_t hdrlen, hunklen, textlen;
|
size_t hunklen;
|
||||||
char origin;
|
|
||||||
int oldno, newno;
|
|
||||||
git_buf old_content = GIT_BUF_INIT, actual = GIT_BUF_INIT;
|
git_buf old_content = GIT_BUF_INIT, actual = GIT_BUF_INIT;
|
||||||
const char *new_content = "The Song of Seven Cities\n------------------------\n\nI WAS Lord of Cities very sumptuously builded.\nSeven roaring Cities paid me tribute from afar.\nIvory their outposts were--the guardrooms of them gilded,\nAnd garrisoned with Amazons invincible in war.\n\nThis is some new text;\nNot as good as the old text;\nBut here it is.\n\nSo they warred and trafficked only yesterday, my Cities.\nTo-day there is no mark or mound of where my Cities stood.\nFor the River rose at midnight and it washed away my Cities.\nThey are evened with Atlantis and the towns before the Flood.\n\nRain on rain-gorged channels raised the water-levels round them,\nFreshet backed on freshet swelled and swept their world from sight,\nTill the emboldened floods linked arms and, flashing forward, drowned them--\nDrowned my Seven Cities and their peoples in one night!\n\nLow among the alders lie their derelict foundations,\nThe beams wherein they trusted and the plinths whereon they built--\nMy rulers and their treasure and their unborn populations,\nDead, destroyed, aborted, and defiled with mud and silt!\n\nAnother replacement;\nBreaking up the poem;\nGenerating some hunks.\n\nTo the sound of trumpets shall their seed restore my Cities\nWealthy and well-weaponed, that once more may I behold\nAll the world go softly when it walks before my Cities,\nAnd the horses and the chariots fleeing from them as of old!\n\n -- Rudyard Kipling\n";
|
const char *new_content = "The Song of Seven Cities\n------------------------\n\nI WAS Lord of Cities very sumptuously builded.\nSeven roaring Cities paid me tribute from afar.\nIvory their outposts were--the guardrooms of them gilded,\nAnd garrisoned with Amazons invincible in war.\n\nThis is some new text;\nNot as good as the old text;\nBut here it is.\n\nSo they warred and trafficked only yesterday, my Cities.\nTo-day there is no mark or mound of where my Cities stood.\nFor the River rose at midnight and it washed away my Cities.\nThey are evened with Atlantis and the towns before the Flood.\n\nRain on rain-gorged channels raised the water-levels round them,\nFreshet backed on freshet swelled and swept their world from sight,\nTill the emboldened floods linked arms and, flashing forward, drowned them--\nDrowned my Seven Cities and their peoples in one night!\n\nLow among the alders lie their derelict foundations,\nThe beams wherein they trusted and the plinths whereon they built--\nMy rulers and their treasure and their unborn populations,\nDead, destroyed, aborted, and defiled with mud and silt!\n\nAnother replacement;\nBreaking up the poem;\nGenerating some hunks.\n\nTo the sound of trumpets shall their seed restore my Cities\nWealthy and well-weaponed, that once more may I behold\nAll the world go softly when it walks before my Cities,\nAnd the horses and the chariots fleeing from them as of old!\n\n -- Rudyard Kipling\n";
|
||||||
|
|
||||||
@ -253,89 +249,83 @@ void test_diff_patch__hunks_have_correct_line_numbers(void)
|
|||||||
|
|
||||||
cl_assert_equal_i(1, (int)git_diff_num_deltas(diff));
|
cl_assert_equal_i(1, (int)git_diff_num_deltas(diff));
|
||||||
|
|
||||||
cl_git_pass(git_diff_get_patch(&patch, &delta, diff, 0));
|
cl_git_pass(git_patch_from_diff(&patch, diff, 0));
|
||||||
|
cl_assert((delta = git_patch_get_delta(patch)) != NULL);
|
||||||
|
|
||||||
cl_assert_equal_i(GIT_DELTA_MODIFIED, (int)delta->status);
|
cl_assert_equal_i(GIT_DELTA_MODIFIED, (int)delta->status);
|
||||||
cl_assert_equal_i(2, (int)git_diff_patch_num_hunks(patch));
|
cl_assert_equal_i(2, (int)git_patch_num_hunks(patch));
|
||||||
|
|
||||||
/* check hunk 0 */
|
/* check hunk 0 */
|
||||||
|
|
||||||
cl_git_pass(
|
cl_git_pass(
|
||||||
git_diff_patch_get_hunk(&range, &hdr, &hdrlen, &hunklen, patch, 0));
|
git_patch_get_hunk(&hunk, &hunklen, patch, 0));
|
||||||
|
|
||||||
cl_assert_equal_i(18, (int)hunklen);
|
cl_assert_equal_i(18, (int)hunklen);
|
||||||
|
|
||||||
cl_assert_equal_i(6, (int)range->old_start);
|
cl_assert_equal_i(6, (int)hunk->old_start);
|
||||||
cl_assert_equal_i(15, (int)range->old_lines);
|
cl_assert_equal_i(15, (int)hunk->old_lines);
|
||||||
cl_assert_equal_i(6, (int)range->new_start);
|
cl_assert_equal_i(6, (int)hunk->new_start);
|
||||||
cl_assert_equal_i(9, (int)range->new_lines);
|
cl_assert_equal_i(9, (int)hunk->new_lines);
|
||||||
|
|
||||||
cl_assert_equal_i(18, (int)git_diff_patch_num_lines_in_hunk(patch, 0));
|
cl_assert_equal_i(18, (int)git_patch_num_lines_in_hunk(patch, 0));
|
||||||
|
|
||||||
cl_git_pass(git_diff_patch_get_line_in_hunk(
|
cl_git_pass(git_patch_get_line_in_hunk(&line, patch, 0, 0));
|
||||||
&origin, &text, &textlen, &oldno, &newno, patch, 0, 0));
|
cl_assert_equal_i(GIT_DIFF_LINE_CONTEXT, (int)line->origin);
|
||||||
cl_assert_equal_i(GIT_DIFF_LINE_CONTEXT, (int)origin);
|
cl_git_pass(git_buf_set(&actual, line->content, line->content_len));
|
||||||
cl_git_pass(git_buf_set(&actual, text, textlen));
|
|
||||||
cl_assert_equal_s("Ivory their outposts were--the guardrooms of them gilded,\n", actual.ptr);
|
cl_assert_equal_s("Ivory their outposts were--the guardrooms of them gilded,\n", actual.ptr);
|
||||||
cl_assert_equal_i(6, oldno);
|
cl_assert_equal_i(6, line->old_lineno);
|
||||||
cl_assert_equal_i(6, newno);
|
cl_assert_equal_i(6, line->new_lineno);
|
||||||
|
|
||||||
cl_git_pass(git_diff_patch_get_line_in_hunk(
|
cl_git_pass(git_patch_get_line_in_hunk(&line, patch, 0, 3));
|
||||||
&origin, &text, &textlen, &oldno, &newno, patch, 0, 3));
|
cl_assert_equal_i(GIT_DIFF_LINE_DELETION, (int)line->origin);
|
||||||
cl_assert_equal_i(GIT_DIFF_LINE_DELETION, (int)origin);
|
cl_git_pass(git_buf_set(&actual, line->content, line->content_len));
|
||||||
cl_git_pass(git_buf_set(&actual, text, textlen));
|
|
||||||
cl_assert_equal_s("All the world went softly when it walked before my Cities--\n", actual.ptr);
|
cl_assert_equal_s("All the world went softly when it walked before my Cities--\n", actual.ptr);
|
||||||
cl_assert_equal_i(9, oldno);
|
cl_assert_equal_i(9, line->old_lineno);
|
||||||
cl_assert_equal_i(-1, newno);
|
cl_assert_equal_i(-1, line->new_lineno);
|
||||||
|
|
||||||
cl_git_pass(git_diff_patch_get_line_in_hunk(
|
cl_git_pass(git_patch_get_line_in_hunk(&line, patch, 0, 12));
|
||||||
&origin, &text, &textlen, &oldno, &newno, patch, 0, 12));
|
cl_assert_equal_i(GIT_DIFF_LINE_ADDITION, (int)line->origin);
|
||||||
cl_assert_equal_i(GIT_DIFF_LINE_ADDITION, (int)origin);
|
cl_git_pass(git_buf_set(&actual, line->content, line->content_len));
|
||||||
cl_git_pass(git_buf_set(&actual, text, textlen));
|
|
||||||
cl_assert_equal_s("This is some new text;\n", actual.ptr);
|
cl_assert_equal_s("This is some new text;\n", actual.ptr);
|
||||||
cl_assert_equal_i(-1, oldno);
|
cl_assert_equal_i(-1, line->old_lineno);
|
||||||
cl_assert_equal_i(9, newno);
|
cl_assert_equal_i(9, line->new_lineno);
|
||||||
|
|
||||||
/* check hunk 1 */
|
/* check hunk 1 */
|
||||||
|
|
||||||
cl_git_pass(
|
cl_git_pass(git_patch_get_hunk(&hunk, &hunklen, patch, 1));
|
||||||
git_diff_patch_get_hunk(&range, &hdr, &hdrlen, &hunklen, patch, 1));
|
|
||||||
|
|
||||||
cl_assert_equal_i(18, (int)hunklen);
|
cl_assert_equal_i(18, (int)hunklen);
|
||||||
|
|
||||||
cl_assert_equal_i(31, (int)range->old_start);
|
cl_assert_equal_i(31, (int)hunk->old_start);
|
||||||
cl_assert_equal_i(15, (int)range->old_lines);
|
cl_assert_equal_i(15, (int)hunk->old_lines);
|
||||||
cl_assert_equal_i(25, (int)range->new_start);
|
cl_assert_equal_i(25, (int)hunk->new_start);
|
||||||
cl_assert_equal_i(9, (int)range->new_lines);
|
cl_assert_equal_i(9, (int)hunk->new_lines);
|
||||||
|
|
||||||
cl_assert_equal_i(18, (int)git_diff_patch_num_lines_in_hunk(patch, 1));
|
cl_assert_equal_i(18, (int)git_patch_num_lines_in_hunk(patch, 1));
|
||||||
|
|
||||||
cl_git_pass(git_diff_patch_get_line_in_hunk(
|
cl_git_pass(git_patch_get_line_in_hunk(&line, patch, 1, 0));
|
||||||
&origin, &text, &textlen, &oldno, &newno, patch, 1, 0));
|
cl_assert_equal_i(GIT_DIFF_LINE_CONTEXT, (int)line->origin);
|
||||||
cl_assert_equal_i(GIT_DIFF_LINE_CONTEXT, (int)origin);
|
cl_git_pass(git_buf_set(&actual, line->content, line->content_len));
|
||||||
cl_git_pass(git_buf_set(&actual, text, textlen));
|
|
||||||
cl_assert_equal_s("My rulers and their treasure and their unborn populations,\n", actual.ptr);
|
cl_assert_equal_s("My rulers and their treasure and their unborn populations,\n", actual.ptr);
|
||||||
cl_assert_equal_i(31, oldno);
|
cl_assert_equal_i(31, line->old_lineno);
|
||||||
cl_assert_equal_i(25, newno);
|
cl_assert_equal_i(25, line->new_lineno);
|
||||||
|
|
||||||
cl_git_pass(git_diff_patch_get_line_in_hunk(
|
cl_git_pass(git_patch_get_line_in_hunk(&line, patch, 1, 3));
|
||||||
&origin, &text, &textlen, &oldno, &newno, patch, 1, 3));
|
cl_assert_equal_i(GIT_DIFF_LINE_DELETION, (int)line->origin);
|
||||||
cl_assert_equal_i(GIT_DIFF_LINE_DELETION, (int)origin);
|
cl_git_pass(git_buf_set(&actual, line->content, line->content_len));
|
||||||
cl_git_pass(git_buf_set(&actual, text, textlen));
|
|
||||||
cl_assert_equal_s("The Daughters of the Palace whom they cherished in my Cities,\n", actual.ptr);
|
cl_assert_equal_s("The Daughters of the Palace whom they cherished in my Cities,\n", actual.ptr);
|
||||||
cl_assert_equal_i(34, oldno);
|
cl_assert_equal_i(34, line->old_lineno);
|
||||||
cl_assert_equal_i(-1, newno);
|
cl_assert_equal_i(-1, line->new_lineno);
|
||||||
|
|
||||||
cl_git_pass(git_diff_patch_get_line_in_hunk(
|
cl_git_pass(git_patch_get_line_in_hunk(&line, patch, 1, 12));
|
||||||
&origin, &text, &textlen, &oldno, &newno, patch, 1, 12));
|
cl_assert_equal_i(GIT_DIFF_LINE_ADDITION, (int)line->origin);
|
||||||
cl_assert_equal_i(GIT_DIFF_LINE_ADDITION, (int)origin);
|
cl_git_pass(git_buf_set(&actual, line->content, line->content_len));
|
||||||
cl_git_pass(git_buf_set(&actual, text, textlen));
|
|
||||||
cl_assert_equal_s("Another replacement;\n", actual.ptr);
|
cl_assert_equal_s("Another replacement;\n", actual.ptr);
|
||||||
cl_assert_equal_i(-1, oldno);
|
cl_assert_equal_i(-1, line->old_lineno);
|
||||||
cl_assert_equal_i(28, newno);
|
cl_assert_equal_i(28, line->new_lineno);
|
||||||
|
|
||||||
git_diff_patch_free(patch);
|
git_patch_free(patch);
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
|
|
||||||
/* Let's check line numbers when there is no newline */
|
/* Let's check line numbers when there is no newline */
|
||||||
|
|
||||||
@ -346,67 +336,62 @@ void test_diff_patch__hunks_have_correct_line_numbers(void)
|
|||||||
|
|
||||||
cl_assert_equal_i(1, (int)git_diff_num_deltas(diff));
|
cl_assert_equal_i(1, (int)git_diff_num_deltas(diff));
|
||||||
|
|
||||||
cl_git_pass(git_diff_get_patch(&patch, &delta, diff, 0));
|
cl_git_pass(git_patch_from_diff(&patch, diff, 0));
|
||||||
|
cl_assert((delta = git_patch_get_delta(patch)) != NULL);
|
||||||
|
|
||||||
cl_assert_equal_i(GIT_DELTA_MODIFIED, (int)delta->status);
|
cl_assert_equal_i(GIT_DELTA_MODIFIED, (int)delta->status);
|
||||||
cl_assert_equal_i(1, (int)git_diff_patch_num_hunks(patch));
|
cl_assert_equal_i(1, (int)git_patch_num_hunks(patch));
|
||||||
|
|
||||||
/* check hunk 0 */
|
/* check hunk 0 */
|
||||||
|
|
||||||
cl_git_pass(
|
cl_git_pass(git_patch_get_hunk(&hunk, &hunklen, patch, 0));
|
||||||
git_diff_patch_get_hunk(&range, &hdr, &hdrlen, &hunklen, patch, 0));
|
|
||||||
|
|
||||||
cl_assert_equal_i(6, (int)hunklen);
|
cl_assert_equal_i(6, (int)hunklen);
|
||||||
|
|
||||||
cl_assert_equal_i(46, (int)range->old_start);
|
cl_assert_equal_i(46, (int)hunk->old_start);
|
||||||
cl_assert_equal_i(4, (int)range->old_lines);
|
cl_assert_equal_i(4, (int)hunk->old_lines);
|
||||||
cl_assert_equal_i(46, (int)range->new_start);
|
cl_assert_equal_i(46, (int)hunk->new_start);
|
||||||
cl_assert_equal_i(4, (int)range->new_lines);
|
cl_assert_equal_i(4, (int)hunk->new_lines);
|
||||||
|
|
||||||
cl_assert_equal_i(6, (int)git_diff_patch_num_lines_in_hunk(patch, 0));
|
cl_assert_equal_i(6, (int)git_patch_num_lines_in_hunk(patch, 0));
|
||||||
|
|
||||||
cl_git_pass(git_diff_patch_get_line_in_hunk(
|
cl_git_pass(git_patch_get_line_in_hunk(&line, patch, 0, 1));
|
||||||
&origin, &text, &textlen, &oldno, &newno, patch, 0, 1));
|
cl_assert_equal_i(GIT_DIFF_LINE_CONTEXT, (int)line->origin);
|
||||||
cl_assert_equal_i(GIT_DIFF_LINE_CONTEXT, (int)origin);
|
cl_git_pass(git_buf_set(&actual, line->content, line->content_len));
|
||||||
cl_git_pass(git_buf_set(&actual, text, textlen));
|
|
||||||
cl_assert_equal_s("And the horses and the chariots fleeing from them as of old!\n", actual.ptr);
|
cl_assert_equal_s("And the horses and the chariots fleeing from them as of old!\n", actual.ptr);
|
||||||
cl_assert_equal_i(47, oldno);
|
cl_assert_equal_i(47, line->old_lineno);
|
||||||
cl_assert_equal_i(47, newno);
|
cl_assert_equal_i(47, line->new_lineno);
|
||||||
|
|
||||||
cl_git_pass(git_diff_patch_get_line_in_hunk(
|
cl_git_pass(git_patch_get_line_in_hunk(&line, patch, 0, 2));
|
||||||
&origin, &text, &textlen, &oldno, &newno, patch, 0, 2));
|
cl_assert_equal_i(GIT_DIFF_LINE_CONTEXT, (int)line->origin);
|
||||||
cl_assert_equal_i(GIT_DIFF_LINE_CONTEXT, (int)origin);
|
cl_git_pass(git_buf_set(&actual, line->content, line->content_len));
|
||||||
cl_git_pass(git_buf_set(&actual, text, textlen));
|
|
||||||
cl_assert_equal_s("\n", actual.ptr);
|
cl_assert_equal_s("\n", actual.ptr);
|
||||||
cl_assert_equal_i(48, oldno);
|
cl_assert_equal_i(48, line->old_lineno);
|
||||||
cl_assert_equal_i(48, newno);
|
cl_assert_equal_i(48, line->new_lineno);
|
||||||
|
|
||||||
cl_git_pass(git_diff_patch_get_line_in_hunk(
|
cl_git_pass(git_patch_get_line_in_hunk(&line, patch, 0, 3));
|
||||||
&origin, &text, &textlen, &oldno, &newno, patch, 0, 3));
|
cl_assert_equal_i(GIT_DIFF_LINE_DELETION, (int)line->origin);
|
||||||
cl_assert_equal_i(GIT_DIFF_LINE_DELETION, (int)origin);
|
cl_git_pass(git_buf_set(&actual, line->content, line->content_len));
|
||||||
cl_git_pass(git_buf_set(&actual, text, textlen));
|
|
||||||
cl_assert_equal_s(" -- Rudyard Kipling\n", actual.ptr);
|
cl_assert_equal_s(" -- Rudyard Kipling\n", actual.ptr);
|
||||||
cl_assert_equal_i(49, oldno);
|
cl_assert_equal_i(49, line->old_lineno);
|
||||||
cl_assert_equal_i(-1, newno);
|
cl_assert_equal_i(-1, line->new_lineno);
|
||||||
|
|
||||||
cl_git_pass(git_diff_patch_get_line_in_hunk(
|
cl_git_pass(git_patch_get_line_in_hunk(&line, patch, 0, 4));
|
||||||
&origin, &text, &textlen, &oldno, &newno, patch, 0, 4));
|
cl_assert_equal_i(GIT_DIFF_LINE_ADDITION, (int)line->origin);
|
||||||
cl_assert_equal_i(GIT_DIFF_LINE_ADDITION, (int)origin);
|
cl_git_pass(git_buf_set(&actual, line->content, line->content_len));
|
||||||
cl_git_pass(git_buf_set(&actual, text, textlen));
|
|
||||||
cl_assert_equal_s(" -- Rudyard Kipling", actual.ptr);
|
cl_assert_equal_s(" -- Rudyard Kipling", actual.ptr);
|
||||||
cl_assert_equal_i(-1, oldno);
|
cl_assert_equal_i(-1, line->old_lineno);
|
||||||
cl_assert_equal_i(49, newno);
|
cl_assert_equal_i(49, line->new_lineno);
|
||||||
|
|
||||||
cl_git_pass(git_diff_patch_get_line_in_hunk(
|
cl_git_pass(git_patch_get_line_in_hunk(&line, patch, 0, 5));
|
||||||
&origin, &text, &textlen, &oldno, &newno, patch, 0, 5));
|
cl_assert_equal_i(GIT_DIFF_LINE_DEL_EOFNL, (int)line->origin);
|
||||||
cl_assert_equal_i(GIT_DIFF_LINE_DEL_EOFNL, (int)origin);
|
cl_git_pass(git_buf_set(&actual, line->content, line->content_len));
|
||||||
cl_git_pass(git_buf_set(&actual, text, textlen));
|
|
||||||
cl_assert_equal_s("\n\\ No newline at end of file\n", actual.ptr);
|
cl_assert_equal_s("\n\\ No newline at end of file\n", actual.ptr);
|
||||||
cl_assert_equal_i(-1, oldno);
|
cl_assert_equal_i(-1, line->old_lineno);
|
||||||
cl_assert_equal_i(49, newno);
|
cl_assert_equal_i(49, line->new_lineno);
|
||||||
|
|
||||||
git_diff_patch_free(patch);
|
git_patch_free(patch);
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
|
|
||||||
git_buf_free(&actual);
|
git_buf_free(&actual);
|
||||||
git_buf_free(&old_content);
|
git_buf_free(&old_content);
|
||||||
@ -418,8 +403,8 @@ static void check_single_patch_stats(
|
|||||||
size_t adds, size_t dels, size_t ctxt, size_t *sizes,
|
size_t adds, size_t dels, size_t ctxt, size_t *sizes,
|
||||||
const char *expected)
|
const char *expected)
|
||||||
{
|
{
|
||||||
git_diff_list *diff;
|
git_diff *diff;
|
||||||
git_diff_patch *patch;
|
git_patch *patch;
|
||||||
const git_diff_delta *delta;
|
const git_diff_delta *delta;
|
||||||
size_t actual_ctxt, actual_adds, actual_dels;
|
size_t actual_ctxt, actual_adds, actual_dels;
|
||||||
|
|
||||||
@ -427,12 +412,13 @@ static void check_single_patch_stats(
|
|||||||
|
|
||||||
cl_assert_equal_i(1, (int)git_diff_num_deltas(diff));
|
cl_assert_equal_i(1, (int)git_diff_num_deltas(diff));
|
||||||
|
|
||||||
cl_git_pass(git_diff_get_patch(&patch, &delta, diff, 0));
|
cl_git_pass(git_patch_from_diff(&patch, diff, 0));
|
||||||
|
cl_assert((delta = git_patch_get_delta(patch)) != NULL);
|
||||||
cl_assert_equal_i(GIT_DELTA_MODIFIED, (int)delta->status);
|
cl_assert_equal_i(GIT_DELTA_MODIFIED, (int)delta->status);
|
||||||
|
|
||||||
cl_assert_equal_i((int)hunks, (int)git_diff_patch_num_hunks(patch));
|
cl_assert_equal_i((int)hunks, (int)git_patch_num_hunks(patch));
|
||||||
|
|
||||||
cl_git_pass( git_diff_patch_line_stats(
|
cl_git_pass( git_patch_line_stats(
|
||||||
&actual_ctxt, &actual_adds, &actual_dels, patch) );
|
&actual_ctxt, &actual_adds, &actual_dels, patch) );
|
||||||
|
|
||||||
cl_assert_equal_sz(ctxt, actual_ctxt);
|
cl_assert_equal_sz(ctxt, actual_ctxt);
|
||||||
@ -441,57 +427,60 @@ static void check_single_patch_stats(
|
|||||||
|
|
||||||
if (expected != NULL) {
|
if (expected != NULL) {
|
||||||
char *text;
|
char *text;
|
||||||
cl_git_pass(git_diff_patch_to_str(&text, patch));
|
cl_git_pass(git_patch_to_str(&text, patch));
|
||||||
cl_assert_equal_s(expected, text);
|
cl_assert_equal_s(expected, text);
|
||||||
git__free(text);
|
git__free(text);
|
||||||
|
|
||||||
cl_assert_equal_sz(
|
cl_assert_equal_sz(
|
||||||
strlen(expected), git_diff_patch_size(patch, 1, 1, 1));
|
strlen(expected), git_patch_size(patch, 1, 1, 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sizes) {
|
if (sizes) {
|
||||||
if (sizes[0])
|
if (sizes[0])
|
||||||
cl_assert_equal_sz(sizes[0], git_diff_patch_size(patch, 0, 0, 0));
|
cl_assert_equal_sz(sizes[0], git_patch_size(patch, 0, 0, 0));
|
||||||
if (sizes[1])
|
if (sizes[1])
|
||||||
cl_assert_equal_sz(sizes[1], git_diff_patch_size(patch, 1, 0, 0));
|
cl_assert_equal_sz(sizes[1], git_patch_size(patch, 1, 0, 0));
|
||||||
if (sizes[2])
|
if (sizes[2])
|
||||||
cl_assert_equal_sz(sizes[2], git_diff_patch_size(patch, 1, 1, 0));
|
cl_assert_equal_sz(sizes[2], git_patch_size(patch, 1, 1, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* walk lines in hunk with basic sanity checks */
|
/* walk lines in hunk with basic sanity checks */
|
||||||
for (; hunks > 0; --hunks) {
|
for (; hunks > 0; --hunks) {
|
||||||
size_t i, max_i;
|
size_t i, max_i;
|
||||||
int lastoldno = -1, oldno, lastnewno = -1, newno;
|
const git_diff_line *line;
|
||||||
char origin;
|
int last_new_lineno = -1, last_old_lineno = -1;
|
||||||
|
|
||||||
max_i = git_diff_patch_num_lines_in_hunk(patch, hunks - 1);
|
max_i = git_patch_num_lines_in_hunk(patch, hunks - 1);
|
||||||
|
|
||||||
for (i = 0; i < max_i; ++i) {
|
for (i = 0; i < max_i; ++i) {
|
||||||
int expected = 1;
|
int expected = 1;
|
||||||
|
|
||||||
cl_git_pass(git_diff_patch_get_line_in_hunk(
|
cl_git_pass(
|
||||||
&origin, NULL, NULL, &oldno, &newno, patch, hunks - 1, i));
|
git_patch_get_line_in_hunk(&line, patch, hunks - 1, i));
|
||||||
|
|
||||||
if (origin == GIT_DIFF_LINE_ADD_EOFNL ||
|
if (line->origin == GIT_DIFF_LINE_ADD_EOFNL ||
|
||||||
origin == GIT_DIFF_LINE_DEL_EOFNL ||
|
line->origin == GIT_DIFF_LINE_DEL_EOFNL ||
|
||||||
origin == GIT_DIFF_LINE_CONTEXT_EOFNL)
|
line->origin == GIT_DIFF_LINE_CONTEXT_EOFNL)
|
||||||
expected = 0;
|
expected = 0;
|
||||||
|
|
||||||
if (oldno >= 0) {
|
if (line->old_lineno >= 0) {
|
||||||
if (lastoldno >= 0)
|
if (last_old_lineno >= 0)
|
||||||
cl_assert_equal_i(expected, oldno - lastoldno);
|
cl_assert_equal_i(
|
||||||
lastoldno = oldno;
|
expected, line->old_lineno - last_old_lineno);
|
||||||
|
last_old_lineno = line->old_lineno;
|
||||||
}
|
}
|
||||||
if (newno >= 0) {
|
|
||||||
if (lastnewno >= 0)
|
if (line->new_lineno >= 0) {
|
||||||
cl_assert_equal_i(expected, newno - lastnewno);
|
if (last_new_lineno >= 0)
|
||||||
lastnewno = newno;
|
cl_assert_equal_i(
|
||||||
|
expected, line->new_lineno - last_new_lineno);
|
||||||
|
last_new_lineno = line->new_lineno;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
git_diff_patch_free(patch);
|
git_patch_free(patch);
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_diff_patch__line_counts_with_eofnl(void)
|
void test_diff_patch__line_counts_with_eofnl(void)
|
||||||
|
@ -20,7 +20,7 @@ void test_diff_pathspec__0(void)
|
|||||||
git_tree *a = resolve_commit_oid_to_tree(g_repo, a_commit);
|
git_tree *a = resolve_commit_oid_to_tree(g_repo, a_commit);
|
||||||
git_tree *b = resolve_commit_oid_to_tree(g_repo, b_commit);
|
git_tree *b = resolve_commit_oid_to_tree(g_repo, b_commit);
|
||||||
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
|
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
|
||||||
git_diff_list *diff = NULL;
|
git_diff *diff = NULL;
|
||||||
git_strarray paths = { NULL, 1 };
|
git_strarray paths = { NULL, 1 };
|
||||||
char *path;
|
char *path;
|
||||||
git_pathspec *ps;
|
git_pathspec *ps;
|
||||||
@ -52,7 +52,7 @@ void test_diff_pathspec__0(void)
|
|||||||
(int)git_pathspec_match_list_diff_entry(matches,0)->status);
|
(int)git_pathspec_match_list_diff_entry(matches,0)->status);
|
||||||
git_pathspec_match_list_free(matches);
|
git_pathspec_match_list_free(matches);
|
||||||
|
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
diff = NULL;
|
diff = NULL;
|
||||||
|
|
||||||
cl_git_pass(git_diff_tree_to_tree(&diff, g_repo, a, b, &opts));
|
cl_git_pass(git_diff_tree_to_tree(&diff, g_repo, a, b, &opts));
|
||||||
@ -68,7 +68,7 @@ void test_diff_pathspec__0(void)
|
|||||||
(int)git_pathspec_match_list_diff_entry(matches,0)->status);
|
(int)git_pathspec_match_list_diff_entry(matches,0)->status);
|
||||||
git_pathspec_match_list_free(matches);
|
git_pathspec_match_list_free(matches);
|
||||||
|
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
diff = NULL;
|
diff = NULL;
|
||||||
|
|
||||||
cl_git_pass(git_diff_tree_to_workdir(&diff, g_repo, a, &opts));
|
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);
|
(int)git_pathspec_match_list_diff_entry(matches,0)->status);
|
||||||
git_pathspec_match_list_free(matches);
|
git_pathspec_match_list_free(matches);
|
||||||
|
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
diff = NULL;
|
diff = NULL;
|
||||||
|
|
||||||
git_tree_free(a);
|
git_tree_free(a);
|
||||||
|
@ -43,7 +43,7 @@ void test_diff_rename__match_oid(void)
|
|||||||
const char *old_sha = "31e47d8c1fa36d7f8d537b96158e3f024de0a9f2";
|
const char *old_sha = "31e47d8c1fa36d7f8d537b96158e3f024de0a9f2";
|
||||||
const char *new_sha = "2bc7f351d20b53f1c72c16c4b036e491c478c49a";
|
const char *new_sha = "2bc7f351d20b53f1c72c16c4b036e491c478c49a";
|
||||||
git_tree *old_tree, *new_tree;
|
git_tree *old_tree, *new_tree;
|
||||||
git_diff_list *diff;
|
git_diff *diff;
|
||||||
git_diff_options diffopts = GIT_DIFF_OPTIONS_INIT;
|
git_diff_options diffopts = GIT_DIFF_OPTIONS_INIT;
|
||||||
git_diff_find_options opts = GIT_DIFF_FIND_OPTIONS_INIT;
|
git_diff_find_options opts = GIT_DIFF_FIND_OPTIONS_INIT;
|
||||||
diff_expects exp;
|
diff_expects exp;
|
||||||
@ -88,7 +88,7 @@ void test_diff_rename__match_oid(void)
|
|||||||
cl_assert_equal_i(1, exp.file_status[GIT_DELTA_ADDED]);
|
cl_assert_equal_i(1, exp.file_status[GIT_DELTA_ADDED]);
|
||||||
cl_assert_equal_i(1, exp.file_status[GIT_DELTA_RENAMED]);
|
cl_assert_equal_i(1, exp.file_status[GIT_DELTA_RENAMED]);
|
||||||
|
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
|
|
||||||
cl_git_pass(git_diff_tree_to_tree(
|
cl_git_pass(git_diff_tree_to_tree(
|
||||||
&diff, g_repo, old_tree, new_tree, &diffopts));
|
&diff, g_repo, old_tree, new_tree, &diffopts));
|
||||||
@ -109,7 +109,7 @@ void test_diff_rename__match_oid(void)
|
|||||||
cl_assert_equal_i(1, exp.file_status[GIT_DELTA_COPIED]);
|
cl_assert_equal_i(1, exp.file_status[GIT_DELTA_COPIED]);
|
||||||
cl_assert_equal_i(1, exp.file_status[GIT_DELTA_RENAMED]);
|
cl_assert_equal_i(1, exp.file_status[GIT_DELTA_RENAMED]);
|
||||||
|
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
|
|
||||||
git_tree_free(old_tree);
|
git_tree_free(old_tree);
|
||||||
git_tree_free(new_tree);
|
git_tree_free(new_tree);
|
||||||
@ -120,7 +120,7 @@ void test_diff_rename__checks_options_version(void)
|
|||||||
const char *old_sha = "31e47d8c1fa36d7f8d537b96158e3f024de0a9f2";
|
const char *old_sha = "31e47d8c1fa36d7f8d537b96158e3f024de0a9f2";
|
||||||
const char *new_sha = "2bc7f351d20b53f1c72c16c4b036e491c478c49a";
|
const char *new_sha = "2bc7f351d20b53f1c72c16c4b036e491c478c49a";
|
||||||
git_tree *old_tree, *new_tree;
|
git_tree *old_tree, *new_tree;
|
||||||
git_diff_list *diff;
|
git_diff *diff;
|
||||||
git_diff_options diffopts = GIT_DIFF_OPTIONS_INIT;
|
git_diff_options diffopts = GIT_DIFF_OPTIONS_INIT;
|
||||||
git_diff_find_options opts = GIT_DIFF_FIND_OPTIONS_INIT;
|
git_diff_find_options opts = GIT_DIFF_FIND_OPTIONS_INIT;
|
||||||
const git_error *err;
|
const git_error *err;
|
||||||
@ -142,7 +142,7 @@ void test_diff_rename__checks_options_version(void)
|
|||||||
err = giterr_last();
|
err = giterr_last();
|
||||||
cl_assert_equal_i(GITERR_INVALID, err->klass);
|
cl_assert_equal_i(GITERR_INVALID, err->klass);
|
||||||
|
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
git_tree_free(old_tree);
|
git_tree_free(old_tree);
|
||||||
git_tree_free(new_tree);
|
git_tree_free(new_tree);
|
||||||
}
|
}
|
||||||
@ -153,7 +153,7 @@ void test_diff_rename__not_exact_match(void)
|
|||||||
const char *sha1 = "1c068dee5790ef1580cfc4cd670915b48d790084";
|
const char *sha1 = "1c068dee5790ef1580cfc4cd670915b48d790084";
|
||||||
const char *sha2 = "19dd32dfb1520a64e5bbaae8dce6ef423dfa2f13";
|
const char *sha2 = "19dd32dfb1520a64e5bbaae8dce6ef423dfa2f13";
|
||||||
git_tree *old_tree, *new_tree;
|
git_tree *old_tree, *new_tree;
|
||||||
git_diff_list *diff;
|
git_diff *diff;
|
||||||
git_diff_options diffopts = GIT_DIFF_OPTIONS_INIT;
|
git_diff_options diffopts = GIT_DIFF_OPTIONS_INIT;
|
||||||
git_diff_find_options opts = GIT_DIFF_FIND_OPTIONS_INIT;
|
git_diff_find_options opts = GIT_DIFF_FIND_OPTIONS_INIT;
|
||||||
diff_expects exp;
|
diff_expects exp;
|
||||||
@ -207,7 +207,7 @@ void test_diff_rename__not_exact_match(void)
|
|||||||
cl_assert_equal_i(2, exp.file_status[GIT_DELTA_MODIFIED]);
|
cl_assert_equal_i(2, exp.file_status[GIT_DELTA_MODIFIED]);
|
||||||
cl_assert_equal_i(1, exp.file_status[GIT_DELTA_ADDED]);
|
cl_assert_equal_i(1, exp.file_status[GIT_DELTA_ADDED]);
|
||||||
|
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
|
|
||||||
/* git diff -M -C \
|
/* git diff -M -C \
|
||||||
* 2bc7f351d20b53f1c72c16c4b036e491c478c49a \
|
* 2bc7f351d20b53f1c72c16c4b036e491c478c49a \
|
||||||
@ -228,7 +228,7 @@ void test_diff_rename__not_exact_match(void)
|
|||||||
cl_assert_equal_i(2, exp.file_status[GIT_DELTA_MODIFIED]);
|
cl_assert_equal_i(2, exp.file_status[GIT_DELTA_MODIFIED]);
|
||||||
cl_assert_equal_i(1, exp.file_status[GIT_DELTA_COPIED]);
|
cl_assert_equal_i(1, exp.file_status[GIT_DELTA_COPIED]);
|
||||||
|
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
|
|
||||||
/* git diff -M -C --find-copies-harder --break-rewrites \
|
/* git diff -M -C --find-copies-harder --break-rewrites \
|
||||||
* 2bc7f351d20b53f1c72c16c4b036e491c478c49a \
|
* 2bc7f351d20b53f1c72c16c4b036e491c478c49a \
|
||||||
@ -253,7 +253,7 @@ void test_diff_rename__not_exact_match(void)
|
|||||||
cl_assert_equal_i(1, exp.file_status[GIT_DELTA_DELETED]);
|
cl_assert_equal_i(1, exp.file_status[GIT_DELTA_DELETED]);
|
||||||
cl_assert_equal_i(1, exp.file_status[GIT_DELTA_COPIED]);
|
cl_assert_equal_i(1, exp.file_status[GIT_DELTA_COPIED]);
|
||||||
|
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
|
|
||||||
/* == Changes =====================================================
|
/* == Changes =====================================================
|
||||||
* songofseven.txt -> untimely.txt (rename, convert to crlf)
|
* songofseven.txt -> untimely.txt (rename, convert to crlf)
|
||||||
@ -281,7 +281,7 @@ void test_diff_rename__not_exact_match(void)
|
|||||||
cl_assert_equal_i(2, exp.file_status[GIT_DELTA_MODIFIED]);
|
cl_assert_equal_i(2, exp.file_status[GIT_DELTA_MODIFIED]);
|
||||||
cl_assert_equal_i(2, exp.file_status[GIT_DELTA_ADDED]);
|
cl_assert_equal_i(2, exp.file_status[GIT_DELTA_ADDED]);
|
||||||
cl_assert_equal_i(2, exp.file_status[GIT_DELTA_DELETED]);
|
cl_assert_equal_i(2, exp.file_status[GIT_DELTA_DELETED]);
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
|
|
||||||
/* git diff -M -C \
|
/* git diff -M -C \
|
||||||
* 1c068dee5790ef1580cfc4cd670915b48d790084 \
|
* 1c068dee5790ef1580cfc4cd670915b48d790084 \
|
||||||
@ -301,7 +301,7 @@ void test_diff_rename__not_exact_match(void)
|
|||||||
cl_assert_equal_i(2, exp.file_status[GIT_DELTA_MODIFIED]);
|
cl_assert_equal_i(2, exp.file_status[GIT_DELTA_MODIFIED]);
|
||||||
cl_assert_equal_i(2, exp.file_status[GIT_DELTA_RENAMED]);
|
cl_assert_equal_i(2, exp.file_status[GIT_DELTA_RENAMED]);
|
||||||
|
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
|
|
||||||
/* git diff -M -C --find-copies-harder --break-rewrites \
|
/* git diff -M -C --find-copies-harder --break-rewrites \
|
||||||
* 1c068dee5790ef1580cfc4cd670915b48d790084 \
|
* 1c068dee5790ef1580cfc4cd670915b48d790084 \
|
||||||
@ -330,7 +330,7 @@ void test_diff_rename__not_exact_match(void)
|
|||||||
cl_assert_equal_i(1, exp.file_status[GIT_DELTA_DELETED]);
|
cl_assert_equal_i(1, exp.file_status[GIT_DELTA_DELETED]);
|
||||||
cl_assert_equal_i(2, exp.file_status[GIT_DELTA_RENAMED]);
|
cl_assert_equal_i(2, exp.file_status[GIT_DELTA_RENAMED]);
|
||||||
|
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
|
|
||||||
/* git diff -M -C --find-copies-harder --break-rewrites \
|
/* git diff -M -C --find-copies-harder --break-rewrites \
|
||||||
* 1c068dee5790ef1580cfc4cd670915b48d790084 \
|
* 1c068dee5790ef1580cfc4cd670915b48d790084 \
|
||||||
@ -353,7 +353,7 @@ void test_diff_rename__not_exact_match(void)
|
|||||||
cl_assert_equal_i(2, exp.file_status[GIT_DELTA_MODIFIED]);
|
cl_assert_equal_i(2, exp.file_status[GIT_DELTA_MODIFIED]);
|
||||||
cl_assert_equal_i(2, exp.file_status[GIT_DELTA_RENAMED]);
|
cl_assert_equal_i(2, exp.file_status[GIT_DELTA_RENAMED]);
|
||||||
|
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
|
|
||||||
git_tree_free(old_tree);
|
git_tree_free(old_tree);
|
||||||
git_tree_free(new_tree);
|
git_tree_free(new_tree);
|
||||||
@ -364,7 +364,7 @@ void test_diff_rename__handles_small_files(void)
|
|||||||
const char *tree_sha = "2bc7f351d20b53f1c72c16c4b036e491c478c49a";
|
const char *tree_sha = "2bc7f351d20b53f1c72c16c4b036e491c478c49a";
|
||||||
git_index *index;
|
git_index *index;
|
||||||
git_tree *tree;
|
git_tree *tree;
|
||||||
git_diff_list *diff;
|
git_diff *diff;
|
||||||
git_diff_options diffopts = GIT_DIFF_OPTIONS_INIT;
|
git_diff_options diffopts = GIT_DIFF_OPTIONS_INIT;
|
||||||
git_diff_find_options opts = GIT_DIFF_FIND_OPTIONS_INIT;
|
git_diff_find_options opts = GIT_DIFF_FIND_OPTIONS_INIT;
|
||||||
|
|
||||||
@ -388,7 +388,7 @@ void test_diff_rename__handles_small_files(void)
|
|||||||
GIT_DIFF_FIND_AND_BREAK_REWRITES;
|
GIT_DIFF_FIND_AND_BREAK_REWRITES;
|
||||||
cl_git_pass(git_diff_find_similar(diff, &opts));
|
cl_git_pass(git_diff_find_similar(diff, &opts));
|
||||||
|
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
git_tree_free(tree);
|
git_tree_free(tree);
|
||||||
git_index_free(index);
|
git_index_free(index);
|
||||||
}
|
}
|
||||||
@ -400,7 +400,7 @@ void test_diff_rename__working_directory_changes(void)
|
|||||||
git_oid id;
|
git_oid id;
|
||||||
git_tree *tree;
|
git_tree *tree;
|
||||||
git_blob *blob;
|
git_blob *blob;
|
||||||
git_diff_list *diff;
|
git_diff *diff;
|
||||||
git_diff_options diffopts = GIT_DIFF_OPTIONS_INIT;
|
git_diff_options diffopts = GIT_DIFF_OPTIONS_INIT;
|
||||||
git_diff_find_options opts = GIT_DIFF_FIND_OPTIONS_INIT;
|
git_diff_find_options opts = GIT_DIFF_FIND_OPTIONS_INIT;
|
||||||
diff_expects exp;
|
diff_expects exp;
|
||||||
@ -451,7 +451,7 @@ void test_diff_rename__working_directory_changes(void)
|
|||||||
cl_assert_equal_i(1, exp.file_status[GIT_DELTA_DELETED]);
|
cl_assert_equal_i(1, exp.file_status[GIT_DELTA_DELETED]);
|
||||||
cl_assert_equal_i(2, exp.file_status[GIT_DELTA_UNTRACKED]);
|
cl_assert_equal_i(2, exp.file_status[GIT_DELTA_UNTRACKED]);
|
||||||
|
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
|
|
||||||
/* rewrite files in the working directory with / without CRLF changes */
|
/* rewrite files in the working directory with / without CRLF changes */
|
||||||
|
|
||||||
@ -477,7 +477,7 @@ void test_diff_rename__working_directory_changes(void)
|
|||||||
cl_assert_equal_i(1, exp.file_status[GIT_DELTA_DELETED]);
|
cl_assert_equal_i(1, exp.file_status[GIT_DELTA_DELETED]);
|
||||||
cl_assert_equal_i(2, exp.file_status[GIT_DELTA_UNTRACKED]);
|
cl_assert_equal_i(2, exp.file_status[GIT_DELTA_UNTRACKED]);
|
||||||
|
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
|
|
||||||
/* try a different whitespace option */
|
/* try a different whitespace option */
|
||||||
|
|
||||||
@ -496,7 +496,7 @@ void test_diff_rename__working_directory_changes(void)
|
|||||||
cl_assert_equal_i(2, exp.file_status[GIT_DELTA_DELETED]);
|
cl_assert_equal_i(2, exp.file_status[GIT_DELTA_DELETED]);
|
||||||
cl_assert_equal_i(3, exp.file_status[GIT_DELTA_UNTRACKED]);
|
cl_assert_equal_i(3, exp.file_status[GIT_DELTA_UNTRACKED]);
|
||||||
|
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
|
|
||||||
/* try a different matching option */
|
/* try a different matching option */
|
||||||
|
|
||||||
@ -514,7 +514,7 @@ void test_diff_rename__working_directory_changes(void)
|
|||||||
cl_assert_equal_i(3, exp.file_status[GIT_DELTA_UNTRACKED]);
|
cl_assert_equal_i(3, exp.file_status[GIT_DELTA_UNTRACKED]);
|
||||||
cl_assert_equal_i(2, exp.file_status[GIT_DELTA_DELETED]);
|
cl_assert_equal_i(2, exp.file_status[GIT_DELTA_DELETED]);
|
||||||
|
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
|
|
||||||
/* again with exact match blob */
|
/* again with exact match blob */
|
||||||
|
|
||||||
@ -545,7 +545,7 @@ void test_diff_rename__working_directory_changes(void)
|
|||||||
cl_assert_equal_i(1, exp.file_status[GIT_DELTA_RENAMED]);
|
cl_assert_equal_i(1, exp.file_status[GIT_DELTA_RENAMED]);
|
||||||
cl_assert_equal_i(2, exp.file_status[GIT_DELTA_UNTRACKED]);
|
cl_assert_equal_i(2, exp.file_status[GIT_DELTA_UNTRACKED]);
|
||||||
|
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
|
|
||||||
git_tree_free(tree);
|
git_tree_free(tree);
|
||||||
git_buf_free(&content);
|
git_buf_free(&content);
|
||||||
@ -557,10 +557,10 @@ void test_diff_rename__patch(void)
|
|||||||
const char *sha0 = "2bc7f351d20b53f1c72c16c4b036e491c478c49a";
|
const char *sha0 = "2bc7f351d20b53f1c72c16c4b036e491c478c49a";
|
||||||
const char *sha1 = "1c068dee5790ef1580cfc4cd670915b48d790084";
|
const char *sha1 = "1c068dee5790ef1580cfc4cd670915b48d790084";
|
||||||
git_tree *old_tree, *new_tree;
|
git_tree *old_tree, *new_tree;
|
||||||
git_diff_list *diff;
|
git_diff *diff;
|
||||||
git_diff_options diffopts = GIT_DIFF_OPTIONS_INIT;
|
git_diff_options diffopts = GIT_DIFF_OPTIONS_INIT;
|
||||||
git_diff_find_options opts = GIT_DIFF_FIND_OPTIONS_INIT;
|
git_diff_find_options opts = GIT_DIFF_FIND_OPTIONS_INIT;
|
||||||
git_diff_patch *patch;
|
git_patch *patch;
|
||||||
const git_diff_delta *delta;
|
const git_diff_delta *delta;
|
||||||
char *text;
|
char *text;
|
||||||
const char *expected = "diff --git a/sixserving.txt b/ikeepsix.txt\nindex ad0a8e5..36020db 100644\n--- a/sixserving.txt\n+++ b/ikeepsix.txt\n@@ -1,3 +1,6 @@\n+I Keep Six Honest Serving-Men\n+=============================\n+\n I KEEP six honest serving-men\n (They taught me all I knew);\n Their names are What and Why and When\n@@ -21,4 +24,4 @@ She sends'em abroad on her own affairs,\n One million Hows, two million Wheres,\n And seven million Whys!\n \n- -- Rudyard Kipling\n+ -- Rudyard Kipling\n";
|
const char *expected = "diff --git a/sixserving.txt b/ikeepsix.txt\nindex ad0a8e5..36020db 100644\n--- a/sixserving.txt\n+++ b/ikeepsix.txt\n@@ -1,3 +1,6 @@\n+I Keep Six Honest Serving-Men\n+=============================\n+\n I KEEP six honest serving-men\n (They taught me all I knew);\n Their names are What and Why and When\n@@ -21,4 +24,4 @@ She sends'em abroad on her own affairs,\n One million Hows, two million Wheres,\n And seven million Whys!\n \n- -- Rudyard Kipling\n+ -- Rudyard Kipling\n";
|
||||||
@ -584,25 +584,26 @@ void test_diff_rename__patch(void)
|
|||||||
|
|
||||||
cl_assert_equal_i(4, (int)git_diff_num_deltas(diff));
|
cl_assert_equal_i(4, (int)git_diff_num_deltas(diff));
|
||||||
|
|
||||||
cl_git_pass(git_diff_get_patch(&patch, &delta, diff, 0));
|
cl_git_pass(git_patch_from_diff(&patch, diff, 0));
|
||||||
|
cl_assert((delta = git_patch_get_delta(patch)) != NULL);
|
||||||
cl_assert_equal_i(GIT_DELTA_COPIED, (int)delta->status);
|
cl_assert_equal_i(GIT_DELTA_COPIED, (int)delta->status);
|
||||||
|
|
||||||
cl_git_pass(git_diff_patch_to_str(&text, patch));
|
cl_git_pass(git_patch_to_str(&text, patch));
|
||||||
cl_assert_equal_s(expected, text);
|
cl_assert_equal_s(expected, text);
|
||||||
git__free(text);
|
git__free(text);
|
||||||
|
|
||||||
git_diff_patch_free(patch);
|
git_patch_free(patch);
|
||||||
|
|
||||||
cl_git_pass(git_diff_get_patch(NULL, &delta, diff, 1));
|
cl_assert((delta = git_diff_get_delta(diff, 1)) != NULL);
|
||||||
cl_assert_equal_i(GIT_DELTA_UNMODIFIED, (int)delta->status);
|
cl_assert_equal_i(GIT_DELTA_UNMODIFIED, (int)delta->status);
|
||||||
|
|
||||||
cl_git_pass(git_diff_get_patch(NULL, &delta, diff, 2));
|
cl_assert((delta = git_diff_get_delta(diff, 2)) != NULL);
|
||||||
cl_assert_equal_i(GIT_DELTA_MODIFIED, (int)delta->status);
|
cl_assert_equal_i(GIT_DELTA_MODIFIED, (int)delta->status);
|
||||||
|
|
||||||
cl_git_pass(git_diff_get_patch(NULL, &delta, diff, 3));
|
cl_assert((delta = git_diff_get_delta(diff, 3)) != NULL);
|
||||||
cl_assert_equal_i(GIT_DELTA_MODIFIED, (int)delta->status);
|
cl_assert_equal_i(GIT_DELTA_MODIFIED, (int)delta->status);
|
||||||
|
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
git_tree_free(old_tree);
|
git_tree_free(old_tree);
|
||||||
git_tree_free(new_tree);
|
git_tree_free(new_tree);
|
||||||
}
|
}
|
||||||
@ -612,7 +613,7 @@ void test_diff_rename__file_exchange(void)
|
|||||||
git_buf c1 = GIT_BUF_INIT, c2 = GIT_BUF_INIT;
|
git_buf c1 = GIT_BUF_INIT, c2 = GIT_BUF_INIT;
|
||||||
git_index *index;
|
git_index *index;
|
||||||
git_tree *tree;
|
git_tree *tree;
|
||||||
git_diff_list *diff;
|
git_diff *diff;
|
||||||
git_diff_options diffopts = GIT_DIFF_OPTIONS_INIT;
|
git_diff_options diffopts = GIT_DIFF_OPTIONS_INIT;
|
||||||
git_diff_find_options opts = GIT_DIFF_FIND_OPTIONS_INIT;
|
git_diff_find_options opts = GIT_DIFF_FIND_OPTIONS_INIT;
|
||||||
diff_expects exp;
|
diff_expects exp;
|
||||||
@ -647,7 +648,7 @@ void test_diff_rename__file_exchange(void)
|
|||||||
cl_assert_equal_i(2, exp.files);
|
cl_assert_equal_i(2, exp.files);
|
||||||
cl_assert_equal_i(2, exp.file_status[GIT_DELTA_RENAMED]);
|
cl_assert_equal_i(2, exp.file_status[GIT_DELTA_RENAMED]);
|
||||||
|
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
git_tree_free(tree);
|
git_tree_free(tree);
|
||||||
git_index_free(index);
|
git_index_free(index);
|
||||||
|
|
||||||
@ -660,7 +661,7 @@ void test_diff_rename__file_exchange_three(void)
|
|||||||
git_buf c1 = GIT_BUF_INIT, c2 = GIT_BUF_INIT, c3 = GIT_BUF_INIT;
|
git_buf c1 = GIT_BUF_INIT, c2 = GIT_BUF_INIT, c3 = GIT_BUF_INIT;
|
||||||
git_index *index;
|
git_index *index;
|
||||||
git_tree *tree;
|
git_tree *tree;
|
||||||
git_diff_list *diff;
|
git_diff *diff;
|
||||||
git_diff_options diffopts = GIT_DIFF_OPTIONS_INIT;
|
git_diff_options diffopts = GIT_DIFF_OPTIONS_INIT;
|
||||||
git_diff_find_options opts = GIT_DIFF_FIND_OPTIONS_INIT;
|
git_diff_find_options opts = GIT_DIFF_FIND_OPTIONS_INIT;
|
||||||
diff_expects exp;
|
diff_expects exp;
|
||||||
@ -699,7 +700,7 @@ void test_diff_rename__file_exchange_three(void)
|
|||||||
cl_assert_equal_i(3, exp.files);
|
cl_assert_equal_i(3, exp.files);
|
||||||
cl_assert_equal_i(3, exp.file_status[GIT_DELTA_RENAMED]);
|
cl_assert_equal_i(3, exp.file_status[GIT_DELTA_RENAMED]);
|
||||||
|
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
git_tree_free(tree);
|
git_tree_free(tree);
|
||||||
git_index_free(index);
|
git_index_free(index);
|
||||||
|
|
||||||
@ -713,7 +714,7 @@ void test_diff_rename__file_partial_exchange(void)
|
|||||||
git_buf c1 = GIT_BUF_INIT, c2 = GIT_BUF_INIT;
|
git_buf c1 = GIT_BUF_INIT, c2 = GIT_BUF_INIT;
|
||||||
git_index *index;
|
git_index *index;
|
||||||
git_tree *tree;
|
git_tree *tree;
|
||||||
git_diff_list *diff;
|
git_diff *diff;
|
||||||
git_diff_options diffopts = GIT_DIFF_OPTIONS_INIT;
|
git_diff_options diffopts = GIT_DIFF_OPTIONS_INIT;
|
||||||
git_diff_find_options opts = GIT_DIFF_FIND_OPTIONS_INIT;
|
git_diff_find_options opts = GIT_DIFF_FIND_OPTIONS_INIT;
|
||||||
diff_expects exp;
|
diff_expects exp;
|
||||||
@ -752,7 +753,7 @@ void test_diff_rename__file_partial_exchange(void)
|
|||||||
cl_assert_equal_i(1, exp.file_status[GIT_DELTA_ADDED]);
|
cl_assert_equal_i(1, exp.file_status[GIT_DELTA_ADDED]);
|
||||||
cl_assert_equal_i(1, exp.file_status[GIT_DELTA_DELETED]);
|
cl_assert_equal_i(1, exp.file_status[GIT_DELTA_DELETED]);
|
||||||
|
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
git_tree_free(tree);
|
git_tree_free(tree);
|
||||||
git_index_free(index);
|
git_index_free(index);
|
||||||
|
|
||||||
@ -765,7 +766,7 @@ void test_diff_rename__rename_and_copy_from_same_source(void)
|
|||||||
git_buf c1 = GIT_BUF_INIT, c2 = GIT_BUF_INIT;
|
git_buf c1 = GIT_BUF_INIT, c2 = GIT_BUF_INIT;
|
||||||
git_index *index;
|
git_index *index;
|
||||||
git_tree *tree;
|
git_tree *tree;
|
||||||
git_diff_list *diff;
|
git_diff *diff;
|
||||||
git_diff_options diffopts = GIT_DIFF_OPTIONS_INIT;
|
git_diff_options diffopts = GIT_DIFF_OPTIONS_INIT;
|
||||||
git_diff_find_options opts = GIT_DIFF_FIND_OPTIONS_INIT;
|
git_diff_find_options opts = GIT_DIFF_FIND_OPTIONS_INIT;
|
||||||
diff_expects exp;
|
diff_expects exp;
|
||||||
@ -809,7 +810,7 @@ void test_diff_rename__rename_and_copy_from_same_source(void)
|
|||||||
cl_assert_equal_i(2, exp.file_status[GIT_DELTA_COPIED]);
|
cl_assert_equal_i(2, exp.file_status[GIT_DELTA_COPIED]);
|
||||||
cl_assert_equal_i(4, exp.file_status[GIT_DELTA_UNMODIFIED]);
|
cl_assert_equal_i(4, exp.file_status[GIT_DELTA_UNMODIFIED]);
|
||||||
|
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
git_tree_free(tree);
|
git_tree_free(tree);
|
||||||
git_index_free(index);
|
git_index_free(index);
|
||||||
|
|
||||||
@ -822,7 +823,7 @@ void test_diff_rename__from_deleted_to_split(void)
|
|||||||
git_buf c1 = GIT_BUF_INIT;
|
git_buf c1 = GIT_BUF_INIT;
|
||||||
git_index *index;
|
git_index *index;
|
||||||
git_tree *tree;
|
git_tree *tree;
|
||||||
git_diff_list *diff;
|
git_diff *diff;
|
||||||
git_diff_options diffopts = GIT_DIFF_OPTIONS_INIT;
|
git_diff_options diffopts = GIT_DIFF_OPTIONS_INIT;
|
||||||
git_diff_find_options opts = GIT_DIFF_FIND_OPTIONS_INIT;
|
git_diff_find_options opts = GIT_DIFF_FIND_OPTIONS_INIT;
|
||||||
diff_expects exp;
|
diff_expects exp;
|
||||||
@ -863,7 +864,7 @@ void test_diff_rename__from_deleted_to_split(void)
|
|||||||
cl_assert_equal_i(1, exp.file_status[GIT_DELTA_RENAMED]);
|
cl_assert_equal_i(1, exp.file_status[GIT_DELTA_RENAMED]);
|
||||||
cl_assert_equal_i(2, exp.file_status[GIT_DELTA_UNMODIFIED]);
|
cl_assert_equal_i(2, exp.file_status[GIT_DELTA_UNMODIFIED]);
|
||||||
|
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
git_tree_free(tree);
|
git_tree_free(tree);
|
||||||
git_index_free(index);
|
git_index_free(index);
|
||||||
|
|
||||||
@ -907,7 +908,7 @@ void test_diff_rename__rejected_match_can_match_others(void)
|
|||||||
git_index *index;
|
git_index *index;
|
||||||
git_tree *tree;
|
git_tree *tree;
|
||||||
git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
|
git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
|
||||||
git_diff_list *diff;
|
git_diff *diff;
|
||||||
git_diff_options diffopts = GIT_DIFF_OPTIONS_INIT;
|
git_diff_options diffopts = GIT_DIFF_OPTIONS_INIT;
|
||||||
git_diff_find_options findopts = GIT_DIFF_FIND_OPTIONS_INIT;
|
git_diff_find_options findopts = GIT_DIFF_FIND_OPTIONS_INIT;
|
||||||
git_buf one = GIT_BUF_INIT, two = GIT_BUF_INIT;
|
git_buf one = GIT_BUF_INIT, two = GIT_BUF_INIT;
|
||||||
@ -961,7 +962,7 @@ void test_diff_rename__rejected_match_can_match_others(void)
|
|||||||
cl_git_pass(
|
cl_git_pass(
|
||||||
git_diff_foreach(diff, test_names_expected, NULL, NULL, &expect));
|
git_diff_foreach(diff, test_names_expected, NULL, NULL, &expect));
|
||||||
|
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
git_tree_free(tree);
|
git_tree_free(tree);
|
||||||
git_index_free(index);
|
git_index_free(index);
|
||||||
git_reference_free(head);
|
git_reference_free(head);
|
||||||
@ -993,7 +994,7 @@ void test_diff_rename__rejected_match_can_match_others_two(void)
|
|||||||
git_index *index;
|
git_index *index;
|
||||||
git_tree *tree;
|
git_tree *tree;
|
||||||
git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
|
git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
|
||||||
git_diff_list *diff;
|
git_diff *diff;
|
||||||
git_diff_options diffopts = GIT_DIFF_OPTIONS_INIT;
|
git_diff_options diffopts = GIT_DIFF_OPTIONS_INIT;
|
||||||
git_diff_find_options findopts = GIT_DIFF_FIND_OPTIONS_INIT;
|
git_diff_find_options findopts = GIT_DIFF_FIND_OPTIONS_INIT;
|
||||||
unsigned int status[] = { GIT_DELTA_RENAMED, GIT_DELTA_RENAMED };
|
unsigned int status[] = { GIT_DELTA_RENAMED, GIT_DELTA_RENAMED };
|
||||||
@ -1035,7 +1036,7 @@ void test_diff_rename__rejected_match_can_match_others_two(void)
|
|||||||
git_diff_foreach(diff, test_names_expected, NULL, NULL, &expect));
|
git_diff_foreach(diff, test_names_expected, NULL, NULL, &expect));
|
||||||
cl_assert(expect.idx > 0);
|
cl_assert(expect.idx > 0);
|
||||||
|
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
git_tree_free(tree);
|
git_tree_free(tree);
|
||||||
git_index_free(index);
|
git_index_free(index);
|
||||||
git_reference_free(head);
|
git_reference_free(head);
|
||||||
@ -1048,7 +1049,7 @@ void test_diff_rename__rejected_match_can_match_others_three(void)
|
|||||||
git_index *index;
|
git_index *index;
|
||||||
git_tree *tree;
|
git_tree *tree;
|
||||||
git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
|
git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
|
||||||
git_diff_list *diff;
|
git_diff *diff;
|
||||||
git_diff_options diffopts = GIT_DIFF_OPTIONS_INIT;
|
git_diff_options diffopts = GIT_DIFF_OPTIONS_INIT;
|
||||||
git_diff_find_options findopts = GIT_DIFF_FIND_OPTIONS_INIT;
|
git_diff_find_options findopts = GIT_DIFF_FIND_OPTIONS_INIT;
|
||||||
|
|
||||||
@ -1091,7 +1092,7 @@ void test_diff_rename__rejected_match_can_match_others_three(void)
|
|||||||
|
|
||||||
cl_assert(expect.idx == expect.len);
|
cl_assert(expect.idx == expect.len);
|
||||||
|
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
git_tree_free(tree);
|
git_tree_free(tree);
|
||||||
git_index_free(index);
|
git_index_free(index);
|
||||||
git_reference_free(head);
|
git_reference_free(head);
|
||||||
@ -1102,7 +1103,7 @@ void test_diff_rename__can_rename_from_rewrite(void)
|
|||||||
{
|
{
|
||||||
git_index *index;
|
git_index *index;
|
||||||
git_tree *tree;
|
git_tree *tree;
|
||||||
git_diff_list *diff;
|
git_diff *diff;
|
||||||
git_diff_options diffopts = GIT_DIFF_OPTIONS_INIT;
|
git_diff_options diffopts = GIT_DIFF_OPTIONS_INIT;
|
||||||
git_diff_find_options findopts = GIT_DIFF_FIND_OPTIONS_INIT;
|
git_diff_find_options findopts = GIT_DIFF_FIND_OPTIONS_INIT;
|
||||||
|
|
||||||
@ -1140,7 +1141,7 @@ void test_diff_rename__can_rename_from_rewrite(void)
|
|||||||
|
|
||||||
cl_assert(expect.idx == expect.len);
|
cl_assert(expect.idx == expect.len);
|
||||||
|
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
git_tree_free(tree);
|
git_tree_free(tree);
|
||||||
git_index_free(index);
|
git_index_free(index);
|
||||||
}
|
}
|
||||||
@ -1149,7 +1150,7 @@ void test_diff_rename__case_changes_are_split(void)
|
|||||||
{
|
{
|
||||||
git_index *index;
|
git_index *index;
|
||||||
git_tree *tree;
|
git_tree *tree;
|
||||||
git_diff_list *diff = NULL;
|
git_diff *diff = NULL;
|
||||||
diff_expects exp;
|
diff_expects exp;
|
||||||
git_diff_find_options opts = GIT_DIFF_FIND_OPTIONS_INIT;
|
git_diff_find_options opts = GIT_DIFF_FIND_OPTIONS_INIT;
|
||||||
|
|
||||||
@ -1182,7 +1183,7 @@ void test_diff_rename__case_changes_are_split(void)
|
|||||||
cl_assert_equal_i(1, exp.files);
|
cl_assert_equal_i(1, exp.files);
|
||||||
cl_assert_equal_i(1, exp.file_status[GIT_DELTA_RENAMED]);
|
cl_assert_equal_i(1, exp.file_status[GIT_DELTA_RENAMED]);
|
||||||
|
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
git_index_free(index);
|
git_index_free(index);
|
||||||
git_tree_free(tree);
|
git_tree_free(tree);
|
||||||
}
|
}
|
||||||
@ -1191,7 +1192,7 @@ void test_diff_rename__unmodified_can_be_renamed(void)
|
|||||||
{
|
{
|
||||||
git_index *index;
|
git_index *index;
|
||||||
git_tree *tree;
|
git_tree *tree;
|
||||||
git_diff_list *diff = NULL;
|
git_diff *diff = NULL;
|
||||||
diff_expects exp;
|
diff_expects exp;
|
||||||
git_diff_options diffopts = GIT_DIFF_OPTIONS_INIT;
|
git_diff_options diffopts = GIT_DIFF_OPTIONS_INIT;
|
||||||
git_diff_find_options opts = GIT_DIFF_FIND_OPTIONS_INIT;
|
git_diff_find_options opts = GIT_DIFF_FIND_OPTIONS_INIT;
|
||||||
@ -1230,7 +1231,7 @@ void test_diff_rename__unmodified_can_be_renamed(void)
|
|||||||
cl_assert_equal_i(1, exp.files);
|
cl_assert_equal_i(1, exp.files);
|
||||||
cl_assert_equal_i(1, exp.file_status[GIT_DELTA_RENAMED]);
|
cl_assert_equal_i(1, exp.file_status[GIT_DELTA_RENAMED]);
|
||||||
|
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
git_index_free(index);
|
git_index_free(index);
|
||||||
git_tree_free(tree);
|
git_tree_free(tree);
|
||||||
}
|
}
|
||||||
@ -1238,7 +1239,7 @@ void test_diff_rename__unmodified_can_be_renamed(void)
|
|||||||
void test_diff_rename__rewrite_on_single_file(void)
|
void test_diff_rename__rewrite_on_single_file(void)
|
||||||
{
|
{
|
||||||
git_index *index;
|
git_index *index;
|
||||||
git_diff_list *diff = NULL;
|
git_diff *diff = NULL;
|
||||||
diff_expects exp;
|
diff_expects exp;
|
||||||
git_diff_options diffopts = GIT_DIFF_OPTIONS_INIT;
|
git_diff_options diffopts = GIT_DIFF_OPTIONS_INIT;
|
||||||
git_diff_find_options findopts = GIT_DIFF_FIND_OPTIONS_INIT;
|
git_diff_find_options findopts = GIT_DIFF_FIND_OPTIONS_INIT;
|
||||||
@ -1280,6 +1281,6 @@ void test_diff_rename__rewrite_on_single_file(void)
|
|||||||
cl_assert_equal_i(1, exp.file_status[GIT_DELTA_DELETED]);
|
cl_assert_equal_i(1, exp.file_status[GIT_DELTA_DELETED]);
|
||||||
cl_assert_equal_i(1, exp.file_status[GIT_DELTA_UNTRACKED]);
|
cl_assert_equal_i(1, exp.file_status[GIT_DELTA_UNTRACKED]);
|
||||||
|
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
git_index_free(index);
|
git_index_free(index);
|
||||||
}
|
}
|
||||||
|
@ -14,15 +14,16 @@ void test_diff_submodules__cleanup(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void check_diff_patches_at_line(
|
static void check_diff_patches_at_line(
|
||||||
git_diff_list *diff, const char **expected, const char *file, int line)
|
git_diff *diff, const char **expected, const char *file, int line)
|
||||||
{
|
{
|
||||||
const git_diff_delta *delta;
|
const git_diff_delta *delta;
|
||||||
git_diff_patch *patch = NULL;
|
git_patch *patch = NULL;
|
||||||
size_t d, num_d = git_diff_num_deltas(diff);
|
size_t d, num_d = git_diff_num_deltas(diff);
|
||||||
char *patch_text;
|
char *patch_text;
|
||||||
|
|
||||||
for (d = 0; d < num_d; ++d, git_diff_patch_free(patch)) {
|
for (d = 0; d < num_d; ++d, git_patch_free(patch)) {
|
||||||
cl_git_pass(git_diff_get_patch(&patch, &delta, diff, d));
|
cl_git_pass(git_patch_from_diff(&patch, diff, d));
|
||||||
|
cl_assert((delta = git_patch_get_delta(patch)) != NULL);
|
||||||
|
|
||||||
if (delta->status == GIT_DELTA_UNMODIFIED) {
|
if (delta->status == GIT_DELTA_UNMODIFIED) {
|
||||||
cl_assert_at_line(expected[d] == NULL, file, line);
|
cl_assert_at_line(expected[d] == NULL, file, line);
|
||||||
@ -32,11 +33,11 @@ static void check_diff_patches_at_line(
|
|||||||
if (expected[d] && !strcmp(expected[d], "<SKIP>"))
|
if (expected[d] && !strcmp(expected[d], "<SKIP>"))
|
||||||
continue;
|
continue;
|
||||||
if (expected[d] && !strcmp(expected[d], "<END>")) {
|
if (expected[d] && !strcmp(expected[d], "<END>")) {
|
||||||
cl_git_pass(git_diff_patch_to_str(&patch_text, patch));
|
cl_git_pass(git_patch_to_str(&patch_text, patch));
|
||||||
cl_assert_at_line(!strcmp(expected[d], "<END>"), file, line);
|
cl_assert_at_line(!strcmp(expected[d], "<END>"), file, line);
|
||||||
}
|
}
|
||||||
|
|
||||||
cl_git_pass(git_diff_patch_to_str(&patch_text, patch));
|
cl_git_pass(git_patch_to_str(&patch_text, patch));
|
||||||
|
|
||||||
clar__assert_equal(
|
clar__assert_equal(
|
||||||
file, line, "expected diff did not match actual diff", 1,
|
file, line, "expected diff did not match actual diff", 1,
|
||||||
@ -53,7 +54,7 @@ static void check_diff_patches_at_line(
|
|||||||
void test_diff_submodules__unmodified_submodule(void)
|
void test_diff_submodules__unmodified_submodule(void)
|
||||||
{
|
{
|
||||||
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
|
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
|
||||||
git_diff_list *diff = NULL;
|
git_diff *diff = NULL;
|
||||||
static const char *expected[] = {
|
static const char *expected[] = {
|
||||||
"<SKIP>", /* .gitmodules */
|
"<SKIP>", /* .gitmodules */
|
||||||
NULL, /* added */
|
NULL, /* added */
|
||||||
@ -74,13 +75,13 @@ void test_diff_submodules__unmodified_submodule(void)
|
|||||||
|
|
||||||
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
|
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
|
||||||
check_diff_patches(diff, expected);
|
check_diff_patches(diff, expected);
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_diff_submodules__dirty_submodule(void)
|
void test_diff_submodules__dirty_submodule(void)
|
||||||
{
|
{
|
||||||
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
|
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
|
||||||
git_diff_list *diff = NULL;
|
git_diff *diff = NULL;
|
||||||
static const char *expected[] = {
|
static const char *expected[] = {
|
||||||
"<SKIP>", /* .gitmodules */
|
"<SKIP>", /* .gitmodules */
|
||||||
NULL, /* added */
|
NULL, /* added */
|
||||||
@ -104,13 +105,13 @@ void test_diff_submodules__dirty_submodule(void)
|
|||||||
|
|
||||||
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
|
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
|
||||||
check_diff_patches(diff, expected);
|
check_diff_patches(diff, expected);
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_diff_submodules__dirty_submodule_2(void)
|
void test_diff_submodules__dirty_submodule_2(void)
|
||||||
{
|
{
|
||||||
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
|
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
|
||||||
git_diff_list *diff = NULL, *diff2 = NULL;
|
git_diff *diff = NULL, *diff2 = NULL;
|
||||||
char *smpath = "testrepo";
|
char *smpath = "testrepo";
|
||||||
static const char *expected_none[] = { "<END>" };
|
static const char *expected_none[] = { "<END>" };
|
||||||
static const char *expected_dirty[] = {
|
static const char *expected_dirty[] = {
|
||||||
@ -123,7 +124,7 @@ void test_diff_submodules__dirty_submodule_2(void)
|
|||||||
cl_git_pass(git_submodule_reload_all(g_repo));
|
cl_git_pass(git_submodule_reload_all(g_repo));
|
||||||
|
|
||||||
opts.flags = GIT_DIFF_INCLUDE_UNTRACKED |
|
opts.flags = GIT_DIFF_INCLUDE_UNTRACKED |
|
||||||
GIT_DIFF_INCLUDE_UNTRACKED_CONTENT |
|
GIT_DIFF_SHOW_UNTRACKED_CONTENT |
|
||||||
GIT_DIFF_RECURSE_UNTRACKED_DIRS |
|
GIT_DIFF_RECURSE_UNTRACKED_DIRS |
|
||||||
GIT_DIFF_DISABLE_PATHSPEC_MATCH;
|
GIT_DIFF_DISABLE_PATHSPEC_MATCH;
|
||||||
opts.old_prefix = "a"; opts.new_prefix = "b";
|
opts.old_prefix = "a"; opts.new_prefix = "b";
|
||||||
@ -132,7 +133,7 @@ void test_diff_submodules__dirty_submodule_2(void)
|
|||||||
|
|
||||||
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
|
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
|
||||||
check_diff_patches(diff, expected_none);
|
check_diff_patches(diff, expected_none);
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
|
|
||||||
cl_git_rewritefile("submodules/testrepo/README", "heyheyhey");
|
cl_git_rewritefile("submodules/testrepo/README", "heyheyhey");
|
||||||
cl_git_mkfile("submodules/testrepo/all_new.txt", "never seen before");
|
cl_git_mkfile("submodules/testrepo/all_new.txt", "never seen before");
|
||||||
@ -146,25 +147,25 @@ void test_diff_submodules__dirty_submodule_2(void)
|
|||||||
cl_git_pass(git_repository_head_tree(&head, g_repo));
|
cl_git_pass(git_repository_head_tree(&head, g_repo));
|
||||||
cl_git_pass(git_diff_tree_to_index(&diff2, g_repo, head, NULL, &opts));
|
cl_git_pass(git_diff_tree_to_index(&diff2, g_repo, head, NULL, &opts));
|
||||||
cl_git_pass(git_diff_merge(diff, diff2));
|
cl_git_pass(git_diff_merge(diff, diff2));
|
||||||
git_diff_list_free(diff2);
|
git_diff_free(diff2);
|
||||||
git_tree_free(head);
|
git_tree_free(head);
|
||||||
|
|
||||||
check_diff_patches(diff, expected_dirty);
|
check_diff_patches(diff, expected_dirty);
|
||||||
}
|
}
|
||||||
|
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
|
|
||||||
cl_git_pass(git_submodule_reload_all(g_repo));
|
cl_git_pass(git_submodule_reload_all(g_repo));
|
||||||
|
|
||||||
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
|
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
|
||||||
check_diff_patches(diff, expected_dirty);
|
check_diff_patches(diff, expected_dirty);
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_diff_submodules__submod2_index_to_wd(void)
|
void test_diff_submodules__submod2_index_to_wd(void)
|
||||||
{
|
{
|
||||||
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
|
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
|
||||||
git_diff_list *diff = NULL;
|
git_diff *diff = NULL;
|
||||||
static const char *expected[] = {
|
static const char *expected[] = {
|
||||||
"<SKIP>", /* .gitmodules */
|
"<SKIP>", /* .gitmodules */
|
||||||
"diff --git a/sm_changed_file b/sm_changed_file\nindex 4800958..4800958 160000\n--- a/sm_changed_file\n+++ b/sm_changed_file\n@@ -1 +1 @@\n-Subproject commit 480095882d281ed676fe5b863569520e54a7d5c0\n+Subproject commit 480095882d281ed676fe5b863569520e54a7d5c0-dirty\n", /* sm_changed_file */
|
"diff --git a/sm_changed_file b/sm_changed_file\nindex 4800958..4800958 160000\n--- a/sm_changed_file\n+++ b/sm_changed_file\n@@ -1 +1 @@\n-Subproject commit 480095882d281ed676fe5b863569520e54a7d5c0\n+Subproject commit 480095882d281ed676fe5b863569520e54a7d5c0-dirty\n", /* sm_changed_file */
|
||||||
@ -182,14 +183,14 @@ void test_diff_submodules__submod2_index_to_wd(void)
|
|||||||
|
|
||||||
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
|
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
|
||||||
check_diff_patches(diff, expected);
|
check_diff_patches(diff, expected);
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_diff_submodules__submod2_head_to_index(void)
|
void test_diff_submodules__submod2_head_to_index(void)
|
||||||
{
|
{
|
||||||
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
|
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
|
||||||
git_tree *head;
|
git_tree *head;
|
||||||
git_diff_list *diff = NULL;
|
git_diff *diff = NULL;
|
||||||
static const char *expected[] = {
|
static const char *expected[] = {
|
||||||
"<SKIP>", /* .gitmodules */
|
"<SKIP>", /* .gitmodules */
|
||||||
"diff --git a/sm_added_and_uncommited b/sm_added_and_uncommited\nnew file mode 160000\nindex 0000000..4800958\n--- /dev/null\n+++ b/sm_added_and_uncommited\n@@ -0,0 +1 @@\n+Subproject commit 480095882d281ed676fe5b863569520e54a7d5c0\n", /* sm_added_and_uncommited */
|
"diff --git a/sm_added_and_uncommited b/sm_added_and_uncommited\nnew file mode 160000\nindex 0000000..4800958\n--- /dev/null\n+++ b/sm_added_and_uncommited\n@@ -0,0 +1 @@\n+Subproject commit 480095882d281ed676fe5b863569520e54a7d5c0\n", /* sm_added_and_uncommited */
|
||||||
@ -205,7 +206,7 @@ void test_diff_submodules__submod2_head_to_index(void)
|
|||||||
|
|
||||||
cl_git_pass(git_diff_tree_to_index(&diff, g_repo, head, NULL, &opts));
|
cl_git_pass(git_diff_tree_to_index(&diff, g_repo, head, NULL, &opts));
|
||||||
check_diff_patches(diff, expected);
|
check_diff_patches(diff, expected);
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
|
|
||||||
git_tree_free(head);
|
git_tree_free(head);
|
||||||
}
|
}
|
||||||
@ -213,7 +214,7 @@ void test_diff_submodules__submod2_head_to_index(void)
|
|||||||
void test_diff_submodules__invalid_cache(void)
|
void test_diff_submodules__invalid_cache(void)
|
||||||
{
|
{
|
||||||
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
|
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
|
||||||
git_diff_list *diff = NULL;
|
git_diff *diff = NULL;
|
||||||
git_submodule *sm;
|
git_submodule *sm;
|
||||||
char *smpath = "sm_changed_head";
|
char *smpath = "sm_changed_head";
|
||||||
git_repository *smrepo;
|
git_repository *smrepo;
|
||||||
@ -246,7 +247,7 @@ void test_diff_submodules__invalid_cache(void)
|
|||||||
/* baseline */
|
/* baseline */
|
||||||
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
|
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
|
||||||
check_diff_patches(diff, expected_baseline);
|
check_diff_patches(diff, expected_baseline);
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
|
|
||||||
/* update index with new HEAD */
|
/* update index with new HEAD */
|
||||||
cl_git_pass(git_submodule_lookup(&sm, g_repo, smpath));
|
cl_git_pass(git_submodule_lookup(&sm, g_repo, smpath));
|
||||||
@ -254,7 +255,7 @@ void test_diff_submodules__invalid_cache(void)
|
|||||||
|
|
||||||
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
|
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
|
||||||
check_diff_patches(diff, expected_unchanged);
|
check_diff_patches(diff, expected_unchanged);
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
|
|
||||||
/* create untracked file in submodule working directory */
|
/* create untracked file in submodule working directory */
|
||||||
cl_git_mkfile("submod2/sm_changed_head/new_around_here", "hello");
|
cl_git_mkfile("submod2/sm_changed_head/new_around_here", "hello");
|
||||||
@ -262,13 +263,13 @@ void test_diff_submodules__invalid_cache(void)
|
|||||||
|
|
||||||
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
|
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
|
||||||
check_diff_patches(diff, expected_dirty);
|
check_diff_patches(diff, expected_dirty);
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
|
|
||||||
git_submodule_set_ignore(sm, GIT_SUBMODULE_IGNORE_UNTRACKED);
|
git_submodule_set_ignore(sm, GIT_SUBMODULE_IGNORE_UNTRACKED);
|
||||||
|
|
||||||
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
|
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
|
||||||
check_diff_patches(diff, expected_unchanged);
|
check_diff_patches(diff, expected_unchanged);
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
|
|
||||||
/* modify tracked file in submodule working directory */
|
/* modify tracked file in submodule working directory */
|
||||||
cl_git_append2file(
|
cl_git_append2file(
|
||||||
@ -276,20 +277,20 @@ void test_diff_submodules__invalid_cache(void)
|
|||||||
|
|
||||||
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
|
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
|
||||||
check_diff_patches(diff, expected_dirty);
|
check_diff_patches(diff, expected_dirty);
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
|
|
||||||
cl_git_pass(git_submodule_reload_all(g_repo));
|
cl_git_pass(git_submodule_reload_all(g_repo));
|
||||||
cl_git_pass(git_submodule_lookup(&sm, g_repo, smpath));
|
cl_git_pass(git_submodule_lookup(&sm, g_repo, smpath));
|
||||||
|
|
||||||
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
|
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
|
||||||
check_diff_patches(diff, expected_dirty);
|
check_diff_patches(diff, expected_dirty);
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
|
|
||||||
git_submodule_set_ignore(sm, GIT_SUBMODULE_IGNORE_DIRTY);
|
git_submodule_set_ignore(sm, GIT_SUBMODULE_IGNORE_DIRTY);
|
||||||
|
|
||||||
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
|
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
|
||||||
check_diff_patches(diff, expected_unchanged);
|
check_diff_patches(diff, expected_unchanged);
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
|
|
||||||
/* add file to index in submodule */
|
/* add file to index in submodule */
|
||||||
cl_git_pass(git_submodule_open(&smrepo, sm));
|
cl_git_pass(git_submodule_open(&smrepo, sm));
|
||||||
@ -300,13 +301,13 @@ void test_diff_submodules__invalid_cache(void)
|
|||||||
|
|
||||||
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
|
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
|
||||||
check_diff_patches(diff, expected_dirty);
|
check_diff_patches(diff, expected_dirty);
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
|
|
||||||
git_submodule_set_ignore(sm, GIT_SUBMODULE_IGNORE_DIRTY);
|
git_submodule_set_ignore(sm, GIT_SUBMODULE_IGNORE_DIRTY);
|
||||||
|
|
||||||
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
|
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
|
||||||
check_diff_patches(diff, expected_unchanged);
|
check_diff_patches(diff, expected_unchanged);
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
|
|
||||||
/* commit changed index of submodule */
|
/* commit changed index of submodule */
|
||||||
cl_repo_commit_from_index(NULL, smrepo, NULL, 1372350000, "Move it");
|
cl_repo_commit_from_index(NULL, smrepo, NULL, 1372350000, "Move it");
|
||||||
@ -315,25 +316,25 @@ void test_diff_submodules__invalid_cache(void)
|
|||||||
|
|
||||||
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
|
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
|
||||||
check_diff_patches(diff, expected_moved);
|
check_diff_patches(diff, expected_moved);
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
|
|
||||||
git_submodule_set_ignore(sm, GIT_SUBMODULE_IGNORE_ALL);
|
git_submodule_set_ignore(sm, GIT_SUBMODULE_IGNORE_ALL);
|
||||||
|
|
||||||
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
|
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
|
||||||
check_diff_patches(diff, expected_unchanged);
|
check_diff_patches(diff, expected_unchanged);
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
|
|
||||||
git_submodule_set_ignore(sm, GIT_SUBMODULE_IGNORE_NONE);
|
git_submodule_set_ignore(sm, GIT_SUBMODULE_IGNORE_NONE);
|
||||||
|
|
||||||
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
|
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
|
||||||
check_diff_patches(diff, expected_moved_dirty);
|
check_diff_patches(diff, expected_moved_dirty);
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
|
|
||||||
p_unlink("submod2/sm_changed_head/new_around_here");
|
p_unlink("submod2/sm_changed_head/new_around_here");
|
||||||
|
|
||||||
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
|
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
|
||||||
check_diff_patches(diff, expected_moved);
|
check_diff_patches(diff, expected_moved);
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
|
|
||||||
git_index_free(smindex);
|
git_index_free(smindex);
|
||||||
git_repository_free(smrepo);
|
git_repository_free(smrepo);
|
||||||
@ -342,7 +343,7 @@ void test_diff_submodules__invalid_cache(void)
|
|||||||
void test_diff_submodules__diff_ignore_options(void)
|
void test_diff_submodules__diff_ignore_options(void)
|
||||||
{
|
{
|
||||||
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
|
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
|
||||||
git_diff_list *diff = NULL;
|
git_diff *diff = NULL;
|
||||||
git_config *cfg;
|
git_config *cfg;
|
||||||
static const char *expected_normal[] = {
|
static const char *expected_normal[] = {
|
||||||
"<SKIP>", /* .gitmodules */
|
"<SKIP>", /* .gitmodules */
|
||||||
@ -371,26 +372,26 @@ void test_diff_submodules__diff_ignore_options(void)
|
|||||||
|
|
||||||
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
|
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
|
||||||
check_diff_patches(diff, expected_normal);
|
check_diff_patches(diff, expected_normal);
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
|
|
||||||
opts.flags |= GIT_DIFF_IGNORE_SUBMODULES;
|
opts.flags |= GIT_DIFF_IGNORE_SUBMODULES;
|
||||||
|
|
||||||
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
|
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
|
||||||
check_diff_patches(diff, expected_ignore_all);
|
check_diff_patches(diff, expected_ignore_all);
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
|
|
||||||
opts.flags &= ~GIT_DIFF_IGNORE_SUBMODULES;
|
opts.flags &= ~GIT_DIFF_IGNORE_SUBMODULES;
|
||||||
opts.ignore_submodules = GIT_SUBMODULE_IGNORE_ALL;
|
opts.ignore_submodules = GIT_SUBMODULE_IGNORE_ALL;
|
||||||
|
|
||||||
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
|
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
|
||||||
check_diff_patches(diff, expected_ignore_all);
|
check_diff_patches(diff, expected_ignore_all);
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
|
|
||||||
opts.ignore_submodules = GIT_SUBMODULE_IGNORE_DIRTY;
|
opts.ignore_submodules = GIT_SUBMODULE_IGNORE_DIRTY;
|
||||||
|
|
||||||
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
|
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
|
||||||
check_diff_patches(diff, expected_ignore_dirty);
|
check_diff_patches(diff, expected_ignore_dirty);
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
|
|
||||||
opts.ignore_submodules = 0;
|
opts.ignore_submodules = 0;
|
||||||
cl_git_pass(git_repository_config(&cfg, g_repo));
|
cl_git_pass(git_repository_config(&cfg, g_repo));
|
||||||
@ -398,25 +399,25 @@ void test_diff_submodules__diff_ignore_options(void)
|
|||||||
|
|
||||||
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
|
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
|
||||||
check_diff_patches(diff, expected_normal);
|
check_diff_patches(diff, expected_normal);
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
|
|
||||||
cl_git_pass(git_config_set_bool(cfg, "diff.ignoreSubmodules", true));
|
cl_git_pass(git_config_set_bool(cfg, "diff.ignoreSubmodules", true));
|
||||||
|
|
||||||
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
|
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
|
||||||
check_diff_patches(diff, expected_ignore_all);
|
check_diff_patches(diff, expected_ignore_all);
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
|
|
||||||
cl_git_pass(git_config_set_string(cfg, "diff.ignoreSubmodules", "none"));
|
cl_git_pass(git_config_set_string(cfg, "diff.ignoreSubmodules", "none"));
|
||||||
|
|
||||||
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
|
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
|
||||||
check_diff_patches(diff, expected_normal);
|
check_diff_patches(diff, expected_normal);
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
|
|
||||||
cl_git_pass(git_config_set_string(cfg, "diff.ignoreSubmodules", "dirty"));
|
cl_git_pass(git_config_set_string(cfg, "diff.ignoreSubmodules", "dirty"));
|
||||||
|
|
||||||
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
|
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
|
||||||
check_diff_patches(diff, expected_ignore_dirty);
|
check_diff_patches(diff, expected_ignore_dirty);
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
|
|
||||||
git_config_free(cfg);
|
git_config_free(cfg);
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
static git_repository *g_repo = NULL;
|
static git_repository *g_repo = NULL;
|
||||||
static git_diff_options opts;
|
static git_diff_options opts;
|
||||||
static git_diff_list *diff;
|
static git_diff *diff;
|
||||||
static git_tree *a, *b;
|
static git_tree *a, *b;
|
||||||
static diff_expects expect;
|
static diff_expects expect;
|
||||||
|
|
||||||
@ -22,7 +22,7 @@ void test_diff_tree__initialize(void)
|
|||||||
|
|
||||||
void test_diff_tree__cleanup(void)
|
void test_diff_tree__cleanup(void)
|
||||||
{
|
{
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
git_tree_free(a);
|
git_tree_free(a);
|
||||||
git_tree_free(b);
|
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(24 + 1 + 5 + 5, expect.line_adds);
|
||||||
cl_assert_equal_i(7 + 1, expect.line_dels);
|
cl_assert_equal_i(7 + 1, expect.line_dels);
|
||||||
|
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
diff = NULL;
|
diff = NULL;
|
||||||
|
|
||||||
memset(&expect, 0, sizeof(expect));
|
memset(&expect, 0, sizeof(expect));
|
||||||
@ -90,6 +90,9 @@ void test_diff_tree__0(void)
|
|||||||
git_tree_free(c);
|
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)
|
void test_diff_tree__options(void)
|
||||||
{
|
{
|
||||||
/* grabbed a couple of commit oids from the history of the attr repo */
|
/* 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 };
|
int test_ab_or_cd[] = { 0, 0, 0, 0, 1, 1, 1, 1, 1 };
|
||||||
git_diff_options test_options[] = {
|
git_diff_options test_options[] = {
|
||||||
/* a vs b tests */
|
/* a vs b tests */
|
||||||
{ 1, GIT_DIFF_NORMAL, 1, 1, NULL, NULL, {0} },
|
DIFF_OPTS(GIT_DIFF_NORMAL, 1),
|
||||||
{ 1, GIT_DIFF_NORMAL, 3, 1, NULL, NULL, {0} },
|
DIFF_OPTS(GIT_DIFF_NORMAL, 3),
|
||||||
{ 1, GIT_DIFF_REVERSE, 2, 1, NULL, NULL, {0} },
|
DIFF_OPTS(GIT_DIFF_REVERSE, 2),
|
||||||
{ 1, GIT_DIFF_FORCE_TEXT, 2, 1, NULL, NULL, {0} },
|
DIFF_OPTS(GIT_DIFF_FORCE_TEXT, 2),
|
||||||
/* c vs d tests */
|
/* c vs d tests */
|
||||||
{ 1, GIT_DIFF_NORMAL, 3, 1, NULL, NULL, {0} },
|
DIFF_OPTS(GIT_DIFF_NORMAL, 3),
|
||||||
{ 1, GIT_DIFF_IGNORE_WHITESPACE, 3, 1, NULL, NULL, {0} },
|
DIFF_OPTS(GIT_DIFF_IGNORE_WHITESPACE, 3),
|
||||||
{ 1, GIT_DIFF_IGNORE_WHITESPACE_CHANGE, 3, 1, NULL, NULL, {0} },
|
DIFF_OPTS(GIT_DIFF_IGNORE_WHITESPACE_CHANGE, 3),
|
||||||
{ 1, GIT_DIFF_IGNORE_WHITESPACE_EOL, 3, 1, NULL, NULL, {0} },
|
DIFF_OPTS(GIT_DIFF_IGNORE_WHITESPACE_EOL, 3),
|
||||||
{ 1, GIT_DIFF_IGNORE_WHITESPACE | GIT_DIFF_REVERSE, 1, 1, NULL, NULL, {0} },
|
DIFF_OPTS(GIT_DIFF_IGNORE_WHITESPACE | GIT_DIFF_REVERSE, 1),
|
||||||
};
|
};
|
||||||
|
|
||||||
/* to generate these values:
|
/* 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_adds, expected->line_adds);
|
||||||
cl_assert_equal_i(actual.line_dels, expected->line_dels);
|
cl_assert_equal_i(actual.line_dels, expected->line_dels);
|
||||||
|
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
diff = NULL;
|
diff = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -214,7 +217,7 @@ void test_diff_tree__merge(void)
|
|||||||
const char *b_commit = "370fe9ec22";
|
const char *b_commit = "370fe9ec22";
|
||||||
const char *c_commit = "f5b0af1fb4f5c";
|
const char *c_commit = "f5b0af1fb4f5c";
|
||||||
git_tree *c;
|
git_tree *c;
|
||||||
git_diff_list *diff1 = NULL, *diff2 = NULL;
|
git_diff *diff1 = NULL, *diff2 = NULL;
|
||||||
|
|
||||||
g_repo = cl_git_sandbox_init("attr");
|
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));
|
cl_git_pass(git_diff_merge(diff1, diff2));
|
||||||
|
|
||||||
git_diff_list_free(diff2);
|
git_diff_free(diff2);
|
||||||
|
|
||||||
cl_git_pass(git_diff_foreach(
|
cl_git_pass(git_diff_foreach(
|
||||||
diff1, diff_file_cb, diff_hunk_cb, diff_line_cb, &expect));
|
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(36, expect.line_adds);
|
||||||
cl_assert_equal_i(22, expect.line_dels);
|
cl_assert_equal_i(22, expect.line_dels);
|
||||||
|
|
||||||
git_diff_list_free(diff1);
|
git_diff_free(diff1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_diff_tree__larger_hunks(void)
|
void test_diff_tree__larger_hunks(void)
|
||||||
{
|
{
|
||||||
const char *a_commit = "d70d245ed97ed2aa596dd1af6536e4bfdb047b69";
|
const char *a_commit = "d70d245ed97ed2aa596dd1af6536e4bfdb047b69";
|
||||||
const char *b_commit = "7a9e0b02e63179929fed24f0a3e0f19168114d10";
|
const char *b_commit = "7a9e0b02e63179929fed24f0a3e0f19168114d10";
|
||||||
size_t d, num_d, h, num_h, l, num_l, header_len, line_len;
|
size_t d, num_d, h, num_h, l, num_l;
|
||||||
const git_diff_delta *delta;
|
git_patch *patch;
|
||||||
git_diff_patch *patch;
|
const git_diff_hunk *hunk;
|
||||||
const git_diff_range *range;
|
const git_diff_line *line;
|
||||||
const char *header, *line;
|
|
||||||
char origin;
|
|
||||||
|
|
||||||
g_repo = cl_git_sandbox_init("diff");
|
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);
|
num_d = git_diff_num_deltas(diff);
|
||||||
for (d = 0; d < num_d; ++d) {
|
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, diff, d));
|
||||||
cl_assert(patch && delta);
|
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++) {
|
for (h = 0; h < num_h; h++) {
|
||||||
cl_git_pass(git_diff_patch_get_hunk(
|
cl_git_pass(git_patch_get_hunk(&hunk, &num_l, patch, h));
|
||||||
&range, &header, &header_len, &num_l, patch, h));
|
|
||||||
|
|
||||||
for (l = 0; l < num_l; ++l) {
|
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(&line, patch, h, l));
|
||||||
&origin, &line, &line_len, NULL, NULL, patch, h, l));
|
|
||||||
cl_assert(line);
|
cl_assert(line);
|
||||||
}
|
}
|
||||||
|
|
||||||
cl_git_fail(git_diff_patch_get_line_in_hunk(
|
cl_git_fail(git_patch_get_line_in_hunk(&line, patch, h, num_l));
|
||||||
&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(&hunk, &num_l, patch, num_h));
|
||||||
&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, diff, num_d));
|
||||||
|
|
||||||
cl_assert_equal_i(2, (int)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(7, expect.line_adds);
|
||||||
cl_assert_equal_i(15, expect.line_dels);
|
cl_assert_equal_i(15, expect.line_dels);
|
||||||
|
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
diff = NULL;
|
diff = NULL;
|
||||||
|
|
||||||
set_config_int(g_repo, "diff.context", 1);
|
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(7, expect.line_adds);
|
||||||
cl_assert_equal_i(15, expect.line_dels);
|
cl_assert_equal_i(15, expect.line_dels);
|
||||||
|
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
diff = NULL;
|
diff = NULL;
|
||||||
|
|
||||||
set_config_int(g_repo, "diff.context", 0);
|
set_config_int(g_repo, "diff.context", 0);
|
||||||
|
@ -16,7 +16,7 @@ void test_diff_workdir__cleanup(void)
|
|||||||
void test_diff_workdir__to_index(void)
|
void test_diff_workdir__to_index(void)
|
||||||
{
|
{
|
||||||
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
|
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
|
||||||
git_diff_list *diff = NULL;
|
git_diff *diff = NULL;
|
||||||
diff_expects exp;
|
diff_expects exp;
|
||||||
int use_iterator;
|
int use_iterator;
|
||||||
|
|
||||||
@ -60,7 +60,7 @@ void test_diff_workdir__to_index(void)
|
|||||||
cl_assert_equal_i(5, exp.line_dels);
|
cl_assert_equal_i(5, exp.line_dels);
|
||||||
}
|
}
|
||||||
|
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_diff_workdir__to_tree(void)
|
void test_diff_workdir__to_tree(void)
|
||||||
@ -70,8 +70,8 @@ void test_diff_workdir__to_tree(void)
|
|||||||
const char *b_commit = "0017bd4ab1ec3"; /* the start */
|
const char *b_commit = "0017bd4ab1ec3"; /* the start */
|
||||||
git_tree *a, *b;
|
git_tree *a, *b;
|
||||||
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
|
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
|
||||||
git_diff_list *diff = NULL;
|
git_diff *diff = NULL;
|
||||||
git_diff_list *diff2 = NULL;
|
git_diff *diff2 = NULL;
|
||||||
diff_expects exp;
|
diff_expects exp;
|
||||||
int use_iterator;
|
int use_iterator;
|
||||||
|
|
||||||
@ -119,7 +119,7 @@ void test_diff_workdir__to_tree(void)
|
|||||||
* do more apples-to-apples test comparison below.
|
* do more apples-to-apples test comparison below.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
diff = NULL;
|
diff = NULL;
|
||||||
memset(&exp, 0, sizeof(exp));
|
memset(&exp, 0, sizeof(exp));
|
||||||
|
|
||||||
@ -130,7 +130,7 @@ void test_diff_workdir__to_tree(void)
|
|||||||
cl_git_pass(git_diff_tree_to_index(&diff, g_repo, a, NULL, &opts));
|
cl_git_pass(git_diff_tree_to_index(&diff, g_repo, a, NULL, &opts));
|
||||||
cl_git_pass(git_diff_index_to_workdir(&diff2, g_repo, NULL, &opts));
|
cl_git_pass(git_diff_index_to_workdir(&diff2, g_repo, NULL, &opts));
|
||||||
cl_git_pass(git_diff_merge(diff, diff2));
|
cl_git_pass(git_diff_merge(diff, diff2));
|
||||||
git_diff_list_free(diff2);
|
git_diff_free(diff2);
|
||||||
|
|
||||||
for (use_iterator = 0; use_iterator <= 1; use_iterator++) {
|
for (use_iterator = 0; use_iterator <= 1; use_iterator++) {
|
||||||
memset(&exp, 0, sizeof(exp));
|
memset(&exp, 0, sizeof(exp));
|
||||||
@ -157,7 +157,7 @@ void test_diff_workdir__to_tree(void)
|
|||||||
cl_assert_equal_i(5, exp.line_dels);
|
cl_assert_equal_i(5, exp.line_dels);
|
||||||
}
|
}
|
||||||
|
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
diff = NULL;
|
diff = NULL;
|
||||||
memset(&exp, 0, sizeof(exp));
|
memset(&exp, 0, sizeof(exp));
|
||||||
|
|
||||||
@ -167,7 +167,7 @@ void test_diff_workdir__to_tree(void)
|
|||||||
cl_git_pass(git_diff_tree_to_index(&diff, g_repo, b, NULL, &opts));
|
cl_git_pass(git_diff_tree_to_index(&diff, g_repo, b, NULL, &opts));
|
||||||
cl_git_pass(git_diff_index_to_workdir(&diff2, g_repo, NULL, &opts));
|
cl_git_pass(git_diff_index_to_workdir(&diff2, g_repo, NULL, &opts));
|
||||||
cl_git_pass(git_diff_merge(diff, diff2));
|
cl_git_pass(git_diff_merge(diff, diff2));
|
||||||
git_diff_list_free(diff2);
|
git_diff_free(diff2);
|
||||||
|
|
||||||
for (use_iterator = 0; use_iterator <= 1; use_iterator++) {
|
for (use_iterator = 0; use_iterator <= 1; use_iterator++) {
|
||||||
memset(&exp, 0, sizeof(exp));
|
memset(&exp, 0, sizeof(exp));
|
||||||
@ -194,7 +194,7 @@ void test_diff_workdir__to_tree(void)
|
|||||||
cl_assert_equal_i(4, exp.line_dels);
|
cl_assert_equal_i(4, exp.line_dels);
|
||||||
}
|
}
|
||||||
|
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
|
|
||||||
git_tree_free(a);
|
git_tree_free(a);
|
||||||
git_tree_free(b);
|
git_tree_free(b);
|
||||||
@ -203,7 +203,7 @@ void test_diff_workdir__to_tree(void)
|
|||||||
void test_diff_workdir__to_index_with_pathspec(void)
|
void test_diff_workdir__to_index_with_pathspec(void)
|
||||||
{
|
{
|
||||||
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
|
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
|
||||||
git_diff_list *diff = NULL;
|
git_diff *diff = NULL;
|
||||||
diff_expects exp;
|
diff_expects exp;
|
||||||
char *pathspec = NULL;
|
char *pathspec = NULL;
|
||||||
int use_iterator;
|
int use_iterator;
|
||||||
@ -235,7 +235,7 @@ void test_diff_workdir__to_index_with_pathspec(void)
|
|||||||
cl_assert_equal_i(4, exp.file_status[GIT_DELTA_UNTRACKED]);
|
cl_assert_equal_i(4, exp.file_status[GIT_DELTA_UNTRACKED]);
|
||||||
}
|
}
|
||||||
|
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
|
|
||||||
pathspec = "modified_file";
|
pathspec = "modified_file";
|
||||||
|
|
||||||
@ -258,7 +258,7 @@ void test_diff_workdir__to_index_with_pathspec(void)
|
|||||||
cl_assert_equal_i(0, exp.file_status[GIT_DELTA_UNTRACKED]);
|
cl_assert_equal_i(0, exp.file_status[GIT_DELTA_UNTRACKED]);
|
||||||
}
|
}
|
||||||
|
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
|
|
||||||
pathspec = "subdir";
|
pathspec = "subdir";
|
||||||
|
|
||||||
@ -281,7 +281,7 @@ void test_diff_workdir__to_index_with_pathspec(void)
|
|||||||
cl_assert_equal_i(1, exp.file_status[GIT_DELTA_UNTRACKED]);
|
cl_assert_equal_i(1, exp.file_status[GIT_DELTA_UNTRACKED]);
|
||||||
}
|
}
|
||||||
|
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
|
|
||||||
pathspec = "*_deleted";
|
pathspec = "*_deleted";
|
||||||
|
|
||||||
@ -304,12 +304,12 @@ void test_diff_workdir__to_index_with_pathspec(void)
|
|||||||
cl_assert_equal_i(0, exp.file_status[GIT_DELTA_UNTRACKED]);
|
cl_assert_equal_i(0, exp.file_status[GIT_DELTA_UNTRACKED]);
|
||||||
}
|
}
|
||||||
|
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_diff_workdir__filemode_changes(void)
|
void test_diff_workdir__filemode_changes(void)
|
||||||
{
|
{
|
||||||
git_diff_list *diff = NULL;
|
git_diff *diff = NULL;
|
||||||
diff_expects exp;
|
diff_expects exp;
|
||||||
int use_iterator;
|
int use_iterator;
|
||||||
|
|
||||||
@ -339,7 +339,7 @@ void test_diff_workdir__filemode_changes(void)
|
|||||||
cl_assert_equal_i(0, exp.hunks);
|
cl_assert_equal_i(0, exp.hunks);
|
||||||
}
|
}
|
||||||
|
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
|
|
||||||
/* chmod file and test again */
|
/* chmod file and test again */
|
||||||
|
|
||||||
@ -362,14 +362,14 @@ void test_diff_workdir__filemode_changes(void)
|
|||||||
cl_assert_equal_i(0, exp.hunks);
|
cl_assert_equal_i(0, exp.hunks);
|
||||||
}
|
}
|
||||||
|
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
|
|
||||||
cl_assert(cl_toggle_filemode("issue_592/a.txt"));
|
cl_assert(cl_toggle_filemode("issue_592/a.txt"));
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_diff_workdir__filemode_changes_with_filemode_false(void)
|
void test_diff_workdir__filemode_changes_with_filemode_false(void)
|
||||||
{
|
{
|
||||||
git_diff_list *diff = NULL;
|
git_diff *diff = NULL;
|
||||||
diff_expects exp;
|
diff_expects exp;
|
||||||
|
|
||||||
if (!cl_is_chmod_supported())
|
if (!cl_is_chmod_supported())
|
||||||
@ -391,7 +391,7 @@ void test_diff_workdir__filemode_changes_with_filemode_false(void)
|
|||||||
cl_assert_equal_i(0, exp.file_status[GIT_DELTA_MODIFIED]);
|
cl_assert_equal_i(0, exp.file_status[GIT_DELTA_MODIFIED]);
|
||||||
cl_assert_equal_i(0, exp.hunks);
|
cl_assert_equal_i(0, exp.hunks);
|
||||||
|
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
|
|
||||||
/* chmod file and test again */
|
/* chmod file and test again */
|
||||||
|
|
||||||
@ -407,7 +407,7 @@ void test_diff_workdir__filemode_changes_with_filemode_false(void)
|
|||||||
cl_assert_equal_i(0, exp.file_status[GIT_DELTA_MODIFIED]);
|
cl_assert_equal_i(0, exp.file_status[GIT_DELTA_MODIFIED]);
|
||||||
cl_assert_equal_i(0, exp.hunks);
|
cl_assert_equal_i(0, exp.hunks);
|
||||||
|
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
|
|
||||||
cl_assert(cl_toggle_filemode("issue_592/a.txt"));
|
cl_assert(cl_toggle_filemode("issue_592/a.txt"));
|
||||||
}
|
}
|
||||||
@ -415,7 +415,7 @@ void test_diff_workdir__filemode_changes_with_filemode_false(void)
|
|||||||
void test_diff_workdir__head_index_and_workdir_all_differ(void)
|
void test_diff_workdir__head_index_and_workdir_all_differ(void)
|
||||||
{
|
{
|
||||||
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
|
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
|
||||||
git_diff_list *diff_i2t = NULL, *diff_w2i = NULL;
|
git_diff *diff_i2t = NULL, *diff_w2i = NULL;
|
||||||
diff_expects exp;
|
diff_expects exp;
|
||||||
char *pathspec = "staged_changes_modified_file";
|
char *pathspec = "staged_changes_modified_file";
|
||||||
git_tree *tree;
|
git_tree *tree;
|
||||||
@ -504,8 +504,8 @@ void test_diff_workdir__head_index_and_workdir_all_differ(void)
|
|||||||
cl_assert_equal_i(0, exp.line_dels);
|
cl_assert_equal_i(0, exp.line_dels);
|
||||||
}
|
}
|
||||||
|
|
||||||
git_diff_list_free(diff_i2t);
|
git_diff_free(diff_i2t);
|
||||||
git_diff_list_free(diff_w2i);
|
git_diff_free(diff_w2i);
|
||||||
|
|
||||||
git_tree_free(tree);
|
git_tree_free(tree);
|
||||||
}
|
}
|
||||||
@ -513,7 +513,7 @@ void test_diff_workdir__head_index_and_workdir_all_differ(void)
|
|||||||
void test_diff_workdir__eof_newline_changes(void)
|
void test_diff_workdir__eof_newline_changes(void)
|
||||||
{
|
{
|
||||||
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
|
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
|
||||||
git_diff_list *diff = NULL;
|
git_diff *diff = NULL;
|
||||||
diff_expects exp;
|
diff_expects exp;
|
||||||
char *pathspec = "current_file";
|
char *pathspec = "current_file";
|
||||||
int use_iterator;
|
int use_iterator;
|
||||||
@ -546,7 +546,7 @@ void test_diff_workdir__eof_newline_changes(void)
|
|||||||
cl_assert_equal_i(0, exp.line_dels);
|
cl_assert_equal_i(0, exp.line_dels);
|
||||||
}
|
}
|
||||||
|
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
|
|
||||||
cl_git_append2file("status/current_file", "\n");
|
cl_git_append2file("status/current_file", "\n");
|
||||||
|
|
||||||
@ -573,7 +573,7 @@ void test_diff_workdir__eof_newline_changes(void)
|
|||||||
cl_assert_equal_i(0, exp.line_dels);
|
cl_assert_equal_i(0, exp.line_dels);
|
||||||
}
|
}
|
||||||
|
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
|
|
||||||
cl_git_rewritefile("status/current_file", "current_file");
|
cl_git_rewritefile("status/current_file", "current_file");
|
||||||
|
|
||||||
@ -600,7 +600,7 @@ void test_diff_workdir__eof_newline_changes(void)
|
|||||||
cl_assert_equal_i(2, exp.line_dels);
|
cl_assert_equal_i(2, exp.line_dels);
|
||||||
}
|
}
|
||||||
|
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* PREPARATION OF TEST DATA
|
/* PREPARATION OF TEST DATA
|
||||||
@ -673,7 +673,7 @@ void test_diff_workdir__larger_hunks(void)
|
|||||||
const char *b_commit = "7a9e0b02e63179929fed24f0a3e0f19168114d10";
|
const char *b_commit = "7a9e0b02e63179929fed24f0a3e0f19168114d10";
|
||||||
git_tree *a, *b;
|
git_tree *a, *b;
|
||||||
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
|
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
|
||||||
size_t i, d, num_d, h, num_h, l, num_l, header_len, line_len;
|
size_t i, d, num_d, h, num_h, l, num_l;
|
||||||
|
|
||||||
g_repo = cl_git_sandbox_init("diff");
|
g_repo = cl_git_sandbox_init("diff");
|
||||||
|
|
||||||
@ -684,11 +684,10 @@ void test_diff_workdir__larger_hunks(void)
|
|||||||
opts.interhunk_lines = 0;
|
opts.interhunk_lines = 0;
|
||||||
|
|
||||||
for (i = 0; i <= 2; ++i) {
|
for (i = 0; i <= 2; ++i) {
|
||||||
git_diff_list *diff = NULL;
|
git_diff *diff = NULL;
|
||||||
git_diff_patch *patch;
|
git_patch *patch;
|
||||||
const git_diff_range *range;
|
const git_diff_hunk *hunk;
|
||||||
const char *header, *line;
|
const git_diff_line *line;
|
||||||
char origin;
|
|
||||||
|
|
||||||
/* okay, this is a bit silly, but oh well */
|
/* okay, this is a bit silly, but oh well */
|
||||||
switch (i) {
|
switch (i) {
|
||||||
@ -707,33 +706,31 @@ void test_diff_workdir__larger_hunks(void)
|
|||||||
cl_assert_equal_i(2, (int)num_d);
|
cl_assert_equal_i(2, (int)num_d);
|
||||||
|
|
||||||
for (d = 0; d < num_d; ++d) {
|
for (d = 0; d < num_d; ++d) {
|
||||||
cl_git_pass(git_diff_get_patch(&patch, NULL, diff, d));
|
cl_git_pass(git_patch_from_diff(&patch, diff, d));
|
||||||
cl_assert(patch);
|
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++) {
|
for (h = 0; h < num_h; h++) {
|
||||||
cl_git_pass(git_diff_patch_get_hunk(
|
cl_git_pass(git_patch_get_hunk(&hunk, &num_l, patch, h));
|
||||||
&range, &header, &header_len, &num_l, patch, h));
|
|
||||||
|
|
||||||
for (l = 0; l < num_l; ++l) {
|
for (l = 0; l < num_l; ++l) {
|
||||||
cl_git_pass(git_diff_patch_get_line_in_hunk(
|
cl_git_pass(
|
||||||
&origin, &line, &line_len, NULL, NULL, patch, h, l));
|
git_patch_get_line_in_hunk(&line, patch, h, l));
|
||||||
cl_assert(line);
|
cl_assert(line);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* confirm fail after the last item */
|
/* confirm fail after the last item */
|
||||||
cl_git_fail(git_diff_patch_get_line_in_hunk(
|
cl_git_fail(
|
||||||
&origin, &line, &line_len, NULL, NULL, patch, h, num_l));
|
git_patch_get_line_in_hunk(&line, patch, h, num_l));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* confirm fail after the last item */
|
/* confirm fail after the last item */
|
||||||
cl_git_fail(git_diff_patch_get_hunk(
|
cl_git_fail(git_patch_get_hunk(&hunk, &num_l, patch, num_h));
|
||||||
&range, &header, &header_len, &num_l, patch, num_h));
|
|
||||||
|
|
||||||
git_diff_patch_free(patch);
|
git_patch_free(patch);
|
||||||
}
|
}
|
||||||
|
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
}
|
}
|
||||||
|
|
||||||
git_tree_free(a);
|
git_tree_free(a);
|
||||||
@ -758,7 +755,7 @@ void test_diff_workdir__submodules(void)
|
|||||||
const char *a_commit = "873585b94bdeabccea991ea5e3ec1a277895b698";
|
const char *a_commit = "873585b94bdeabccea991ea5e3ec1a277895b698";
|
||||||
git_tree *a;
|
git_tree *a;
|
||||||
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
|
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
|
||||||
git_diff_list *diff = NULL;
|
git_diff *diff = NULL;
|
||||||
diff_expects exp;
|
diff_expects exp;
|
||||||
|
|
||||||
g_repo = setup_fixture_submod2();
|
g_repo = setup_fixture_submod2();
|
||||||
@ -769,7 +766,7 @@ void test_diff_workdir__submodules(void)
|
|||||||
GIT_DIFF_INCLUDE_UNTRACKED |
|
GIT_DIFF_INCLUDE_UNTRACKED |
|
||||||
GIT_DIFF_INCLUDE_IGNORED |
|
GIT_DIFF_INCLUDE_IGNORED |
|
||||||
GIT_DIFF_RECURSE_UNTRACKED_DIRS |
|
GIT_DIFF_RECURSE_UNTRACKED_DIRS |
|
||||||
GIT_DIFF_INCLUDE_UNTRACKED_CONTENT;
|
GIT_DIFF_SHOW_UNTRACKED_CONTENT;
|
||||||
|
|
||||||
cl_git_pass(git_diff_tree_to_workdir(&diff, g_repo, a, &opts));
|
cl_git_pass(git_diff_tree_to_workdir(&diff, g_repo, a, &opts));
|
||||||
|
|
||||||
@ -819,14 +816,14 @@ void test_diff_workdir__submodules(void)
|
|||||||
cl_assert_equal_i(30, exp.line_adds);
|
cl_assert_equal_i(30, exp.line_adds);
|
||||||
cl_assert_equal_i(1, exp.line_dels);
|
cl_assert_equal_i(1, exp.line_dels);
|
||||||
|
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
git_tree_free(a);
|
git_tree_free(a);
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_diff_workdir__cannot_diff_against_a_bare_repository(void)
|
void test_diff_workdir__cannot_diff_against_a_bare_repository(void)
|
||||||
{
|
{
|
||||||
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
|
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
|
||||||
git_diff_list *diff = NULL;
|
git_diff *diff = NULL;
|
||||||
git_tree *tree;
|
git_tree *tree;
|
||||||
|
|
||||||
g_repo = cl_git_sandbox_init("testrepo.git");
|
g_repo = cl_git_sandbox_init("testrepo.git");
|
||||||
@ -844,7 +841,7 @@ void test_diff_workdir__cannot_diff_against_a_bare_repository(void)
|
|||||||
|
|
||||||
void test_diff_workdir__to_null_tree(void)
|
void test_diff_workdir__to_null_tree(void)
|
||||||
{
|
{
|
||||||
git_diff_list *diff;
|
git_diff *diff;
|
||||||
diff_expects exp;
|
diff_expects exp;
|
||||||
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
|
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
|
||||||
|
|
||||||
@ -862,12 +859,12 @@ void test_diff_workdir__to_null_tree(void)
|
|||||||
|
|
||||||
cl_assert_equal_i(exp.files, exp.file_status[GIT_DELTA_UNTRACKED]);
|
cl_assert_equal_i(exp.files, exp.file_status[GIT_DELTA_UNTRACKED]);
|
||||||
|
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_diff_workdir__checks_options_version(void)
|
void test_diff_workdir__checks_options_version(void)
|
||||||
{
|
{
|
||||||
git_diff_list *diff;
|
git_diff *diff;
|
||||||
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
|
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
|
||||||
const git_error *err;
|
const git_error *err;
|
||||||
|
|
||||||
@ -887,11 +884,11 @@ void test_diff_workdir__checks_options_version(void)
|
|||||||
|
|
||||||
void test_diff_workdir__can_diff_empty_file(void)
|
void test_diff_workdir__can_diff_empty_file(void)
|
||||||
{
|
{
|
||||||
git_diff_list *diff;
|
git_diff *diff;
|
||||||
git_tree *tree;
|
git_tree *tree;
|
||||||
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
|
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
|
||||||
struct stat st;
|
struct stat st;
|
||||||
git_diff_patch *patch;
|
git_patch *patch;
|
||||||
|
|
||||||
g_repo = cl_git_sandbox_init("attr_index");
|
g_repo = cl_git_sandbox_init("attr_index");
|
||||||
|
|
||||||
@ -901,7 +898,7 @@ void test_diff_workdir__can_diff_empty_file(void)
|
|||||||
|
|
||||||
cl_git_pass(git_diff_tree_to_workdir(&diff, g_repo, tree, &opts));
|
cl_git_pass(git_diff_tree_to_workdir(&diff, g_repo, tree, &opts));
|
||||||
cl_assert_equal_i(2, (int)git_diff_num_deltas(diff));
|
cl_assert_equal_i(2, (int)git_diff_num_deltas(diff));
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
|
|
||||||
/* empty contents of file */
|
/* empty contents of file */
|
||||||
|
|
||||||
@ -912,9 +909,9 @@ void test_diff_workdir__can_diff_empty_file(void)
|
|||||||
cl_git_pass(git_diff_tree_to_workdir(&diff, g_repo, tree, &opts));
|
cl_git_pass(git_diff_tree_to_workdir(&diff, g_repo, tree, &opts));
|
||||||
cl_assert_equal_i(3, (int)git_diff_num_deltas(diff));
|
cl_assert_equal_i(3, (int)git_diff_num_deltas(diff));
|
||||||
/* diffs are: .gitattributes, README.txt, sub/sub/.gitattributes */
|
/* diffs are: .gitattributes, README.txt, sub/sub/.gitattributes */
|
||||||
cl_git_pass(git_diff_get_patch(&patch, NULL, diff, 1));
|
cl_git_pass(git_patch_from_diff(&patch, diff, 1));
|
||||||
git_diff_patch_free(patch);
|
git_patch_free(patch);
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
|
|
||||||
/* remove a file altogether */
|
/* remove a file altogether */
|
||||||
|
|
||||||
@ -923,9 +920,9 @@ void test_diff_workdir__can_diff_empty_file(void)
|
|||||||
|
|
||||||
cl_git_pass(git_diff_tree_to_workdir(&diff, g_repo, tree, &opts));
|
cl_git_pass(git_diff_tree_to_workdir(&diff, g_repo, tree, &opts));
|
||||||
cl_assert_equal_i(3, (int)git_diff_num_deltas(diff));
|
cl_assert_equal_i(3, (int)git_diff_num_deltas(diff));
|
||||||
cl_git_pass(git_diff_get_patch(&patch, NULL, diff, 1));
|
cl_git_pass(git_patch_from_diff(&patch, diff, 1));
|
||||||
git_diff_patch_free(patch);
|
git_patch_free(patch);
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
|
|
||||||
git_tree_free(tree);
|
git_tree_free(tree);
|
||||||
}
|
}
|
||||||
@ -933,7 +930,7 @@ void test_diff_workdir__can_diff_empty_file(void)
|
|||||||
void test_diff_workdir__to_index_issue_1397(void)
|
void test_diff_workdir__to_index_issue_1397(void)
|
||||||
{
|
{
|
||||||
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
|
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
|
||||||
git_diff_list *diff = NULL;
|
git_diff *diff = NULL;
|
||||||
diff_expects exp;
|
diff_expects exp;
|
||||||
|
|
||||||
g_repo = cl_git_sandbox_init("issue_1397");
|
g_repo = cl_git_sandbox_init("issue_1397");
|
||||||
@ -953,7 +950,7 @@ void test_diff_workdir__to_index_issue_1397(void)
|
|||||||
cl_assert_equal_i(0, exp.hunks);
|
cl_assert_equal_i(0, exp.hunks);
|
||||||
cl_assert_equal_i(0, exp.lines);
|
cl_assert_equal_i(0, exp.lines);
|
||||||
|
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
diff = NULL;
|
diff = NULL;
|
||||||
|
|
||||||
cl_git_rewritefile("issue_1397/crlf_file.txt",
|
cl_git_rewritefile("issue_1397/crlf_file.txt",
|
||||||
@ -975,7 +972,7 @@ void test_diff_workdir__to_index_issue_1397(void)
|
|||||||
cl_assert_equal_i(1, exp.line_adds);
|
cl_assert_equal_i(1, exp.line_adds);
|
||||||
cl_assert_equal_i(1, exp.line_dels);
|
cl_assert_equal_i(1, exp.line_dels);
|
||||||
|
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_diff_workdir__to_tree_issue_1397(void)
|
void test_diff_workdir__to_tree_issue_1397(void)
|
||||||
@ -983,8 +980,8 @@ void test_diff_workdir__to_tree_issue_1397(void)
|
|||||||
const char *a_commit = "7f483a738"; /* the current HEAD */
|
const char *a_commit = "7f483a738"; /* the current HEAD */
|
||||||
git_tree *a;
|
git_tree *a;
|
||||||
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
|
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
|
||||||
git_diff_list *diff = NULL;
|
git_diff *diff = NULL;
|
||||||
git_diff_list *diff2 = NULL;
|
git_diff *diff2 = NULL;
|
||||||
diff_expects exp;
|
diff_expects exp;
|
||||||
|
|
||||||
g_repo = cl_git_sandbox_init("issue_1397");
|
g_repo = cl_git_sandbox_init("issue_1397");
|
||||||
@ -1006,13 +1003,13 @@ void test_diff_workdir__to_tree_issue_1397(void)
|
|||||||
cl_assert_equal_i(0, exp.hunks);
|
cl_assert_equal_i(0, exp.hunks);
|
||||||
cl_assert_equal_i(0, exp.lines);
|
cl_assert_equal_i(0, exp.lines);
|
||||||
|
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
diff = NULL;
|
diff = NULL;
|
||||||
|
|
||||||
cl_git_pass(git_diff_tree_to_index(&diff, g_repo, a, NULL, &opts));
|
cl_git_pass(git_diff_tree_to_index(&diff, g_repo, a, NULL, &opts));
|
||||||
cl_git_pass(git_diff_index_to_workdir(&diff2, g_repo, NULL, &opts));
|
cl_git_pass(git_diff_index_to_workdir(&diff2, g_repo, NULL, &opts));
|
||||||
cl_git_pass(git_diff_merge(diff, diff2));
|
cl_git_pass(git_diff_merge(diff, diff2));
|
||||||
git_diff_list_free(diff2);
|
git_diff_free(diff2);
|
||||||
|
|
||||||
memset(&exp, 0, sizeof(exp));
|
memset(&exp, 0, sizeof(exp));
|
||||||
cl_git_pass(git_diff_foreach(
|
cl_git_pass(git_diff_foreach(
|
||||||
@ -1022,14 +1019,14 @@ void test_diff_workdir__to_tree_issue_1397(void)
|
|||||||
cl_assert_equal_i(0, exp.hunks);
|
cl_assert_equal_i(0, exp.hunks);
|
||||||
cl_assert_equal_i(0, exp.lines);
|
cl_assert_equal_i(0, exp.lines);
|
||||||
|
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
git_tree_free(a);
|
git_tree_free(a);
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_diff_workdir__untracked_directory_scenarios(void)
|
void test_diff_workdir__untracked_directory_scenarios(void)
|
||||||
{
|
{
|
||||||
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
|
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
|
||||||
git_diff_list *diff = NULL;
|
git_diff *diff = NULL;
|
||||||
diff_expects exp;
|
diff_expects exp;
|
||||||
char *pathspec = NULL;
|
char *pathspec = NULL;
|
||||||
static const char *files0[] = {
|
static const char *files0[] = {
|
||||||
@ -1079,7 +1076,7 @@ void test_diff_workdir__untracked_directory_scenarios(void)
|
|||||||
cl_assert_equal_i(0, exp.file_status[GIT_DELTA_IGNORED]);
|
cl_assert_equal_i(0, exp.file_status[GIT_DELTA_IGNORED]);
|
||||||
cl_assert_equal_i(1, exp.file_status[GIT_DELTA_UNTRACKED]);
|
cl_assert_equal_i(1, exp.file_status[GIT_DELTA_UNTRACKED]);
|
||||||
|
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
|
|
||||||
/* empty directory */
|
/* empty directory */
|
||||||
|
|
||||||
@ -1099,7 +1096,7 @@ void test_diff_workdir__untracked_directory_scenarios(void)
|
|||||||
cl_assert_equal_i(1, exp.file_status[GIT_DELTA_IGNORED]);
|
cl_assert_equal_i(1, exp.file_status[GIT_DELTA_IGNORED]);
|
||||||
cl_assert_equal_i(1, exp.file_status[GIT_DELTA_UNTRACKED]);
|
cl_assert_equal_i(1, exp.file_status[GIT_DELTA_UNTRACKED]);
|
||||||
|
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
|
|
||||||
/* empty directory in empty directory */
|
/* empty directory in empty directory */
|
||||||
|
|
||||||
@ -1119,7 +1116,7 @@ void test_diff_workdir__untracked_directory_scenarios(void)
|
|||||||
cl_assert_equal_i(1, exp.file_status[GIT_DELTA_IGNORED]);
|
cl_assert_equal_i(1, exp.file_status[GIT_DELTA_IGNORED]);
|
||||||
cl_assert_equal_i(1, exp.file_status[GIT_DELTA_UNTRACKED]);
|
cl_assert_equal_i(1, exp.file_status[GIT_DELTA_UNTRACKED]);
|
||||||
|
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
|
|
||||||
/* directory with only ignored files */
|
/* directory with only ignored files */
|
||||||
|
|
||||||
@ -1143,7 +1140,7 @@ void test_diff_workdir__untracked_directory_scenarios(void)
|
|||||||
cl_assert_equal_i(1, exp.file_status[GIT_DELTA_IGNORED]);
|
cl_assert_equal_i(1, exp.file_status[GIT_DELTA_IGNORED]);
|
||||||
cl_assert_equal_i(1, exp.file_status[GIT_DELTA_UNTRACKED]);
|
cl_assert_equal_i(1, exp.file_status[GIT_DELTA_UNTRACKED]);
|
||||||
|
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
|
|
||||||
/* directory with ignored directory (contents irrelevant) */
|
/* directory with ignored directory (contents irrelevant) */
|
||||||
|
|
||||||
@ -1166,11 +1163,11 @@ void test_diff_workdir__untracked_directory_scenarios(void)
|
|||||||
cl_assert_equal_i(1, exp.file_status[GIT_DELTA_IGNORED]);
|
cl_assert_equal_i(1, exp.file_status[GIT_DELTA_IGNORED]);
|
||||||
cl_assert_equal_i(1, exp.file_status[GIT_DELTA_UNTRACKED]);
|
cl_assert_equal_i(1, exp.file_status[GIT_DELTA_UNTRACKED]);
|
||||||
|
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
|
|
||||||
/* quick version avoids directory scan */
|
/* quick version avoids directory scan */
|
||||||
|
|
||||||
opts.flags = opts.flags | GIT_DIFF_FAST_UNTRACKED_DIRS;
|
opts.flags = opts.flags | GIT_DIFF_ENABLE_FAST_UNTRACKED_DIRS;
|
||||||
|
|
||||||
memset(&exp, 0, sizeof(exp));
|
memset(&exp, 0, sizeof(exp));
|
||||||
exp.names = files1;
|
exp.names = files1;
|
||||||
@ -1186,11 +1183,11 @@ void test_diff_workdir__untracked_directory_scenarios(void)
|
|||||||
cl_assert_equal_i(0, exp.file_status[GIT_DELTA_IGNORED]);
|
cl_assert_equal_i(0, exp.file_status[GIT_DELTA_IGNORED]);
|
||||||
cl_assert_equal_i(2, exp.file_status[GIT_DELTA_UNTRACKED]);
|
cl_assert_equal_i(2, exp.file_status[GIT_DELTA_UNTRACKED]);
|
||||||
|
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
|
|
||||||
/* directory with nested non-ignored content */
|
/* directory with nested non-ignored content */
|
||||||
|
|
||||||
opts.flags = opts.flags & ~GIT_DIFF_FAST_UNTRACKED_DIRS;
|
opts.flags = opts.flags & ~GIT_DIFF_ENABLE_FAST_UNTRACKED_DIRS;
|
||||||
|
|
||||||
cl_git_mkfile("status/subdir/directory/more/notignored",
|
cl_git_mkfile("status/subdir/directory/more/notignored",
|
||||||
"not ignored deep under untracked\n");
|
"not ignored deep under untracked\n");
|
||||||
@ -1209,7 +1206,7 @@ void test_diff_workdir__untracked_directory_scenarios(void)
|
|||||||
cl_assert_equal_i(0, exp.file_status[GIT_DELTA_IGNORED]);
|
cl_assert_equal_i(0, exp.file_status[GIT_DELTA_IGNORED]);
|
||||||
cl_assert_equal_i(2, exp.file_status[GIT_DELTA_UNTRACKED]);
|
cl_assert_equal_i(2, exp.file_status[GIT_DELTA_UNTRACKED]);
|
||||||
|
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
|
|
||||||
/* use RECURSE_UNTRACKED_DIRS to get actual untracked files (no ignores) */
|
/* use RECURSE_UNTRACKED_DIRS to get actual untracked files (no ignores) */
|
||||||
|
|
||||||
@ -1230,14 +1227,14 @@ void test_diff_workdir__untracked_directory_scenarios(void)
|
|||||||
cl_assert_equal_i(0, exp.file_status[GIT_DELTA_IGNORED]);
|
cl_assert_equal_i(0, exp.file_status[GIT_DELTA_IGNORED]);
|
||||||
cl_assert_equal_i(2, exp.file_status[GIT_DELTA_UNTRACKED]);
|
cl_assert_equal_i(2, exp.file_status[GIT_DELTA_UNTRACKED]);
|
||||||
|
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void test_diff_workdir__untracked_directory_comes_last(void)
|
void test_diff_workdir__untracked_directory_comes_last(void)
|
||||||
{
|
{
|
||||||
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
|
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
|
||||||
git_diff_list *diff = NULL;
|
git_diff *diff = NULL;
|
||||||
|
|
||||||
g_repo = cl_git_sandbox_init("renames");
|
g_repo = cl_git_sandbox_init("renames");
|
||||||
|
|
||||||
@ -1255,13 +1252,13 @@ void test_diff_workdir__untracked_directory_comes_last(void)
|
|||||||
|
|
||||||
cl_assert(diff != NULL);
|
cl_assert(diff != NULL);
|
||||||
|
|
||||||
git_diff_list_free(diff);
|
git_diff_free(diff);
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_diff_workdir__untracked_with_bom(void)
|
void test_diff_workdir__untracked_with_bom(void)
|
||||||
{
|
{
|
||||||
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
|
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
|
||||||
git_diff_list *diff = NULL;
|
git_diff *diff = NULL;
|
||||||
const git_diff_delta *delta;
|
const git_diff_delta *delta;
|
||||||
|
|
||||||
g_repo = cl_git_sandbox_init("empty_standard_repo");
|
g_repo = cl_git_sandbox_init("empty_standard_repo");
|
||||||
@ -1271,14 +1268,64 @@ void test_diff_workdir__untracked_with_bom(void)
|
|||||||
"\xFF\xFE\x31\x00\x32\x00\x33\x00\x34\x00", 10, O_WRONLY|O_CREAT, 0664);
|
"\xFF\xFE\x31\x00\x32\x00\x33\x00\x34\x00", 10, O_WRONLY|O_CREAT, 0664);
|
||||||
|
|
||||||
opts.flags =
|
opts.flags =
|
||||||
GIT_DIFF_INCLUDE_UNTRACKED | GIT_DIFF_INCLUDE_UNTRACKED_CONTENT;
|
GIT_DIFF_INCLUDE_UNTRACKED | GIT_DIFF_SHOW_UNTRACKED_CONTENT;
|
||||||
|
|
||||||
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
|
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
|
||||||
|
|
||||||
cl_assert_equal_i(1, git_diff_num_deltas(diff));
|
cl_assert_equal_i(1, git_diff_num_deltas(diff));
|
||||||
cl_git_pass(git_diff_get_patch(NULL, &delta, diff, 0));
|
cl_assert((delta = git_diff_get_delta(diff, 0)) != NULL);
|
||||||
cl_assert_equal_i(GIT_DELTA_UNTRACKED, delta->status);
|
cl_assert_equal_i(GIT_DELTA_UNTRACKED, delta->status);
|
||||||
cl_assert((delta->flags & GIT_DIFF_FLAG_BINARY) != 0);
|
|
||||||
|
|
||||||
git_diff_list_free(diff);
|
/* not known at this point
|
||||||
|
* cl_assert((delta->flags & GIT_DIFF_FLAG_BINARY) != 0);
|
||||||
|
*/
|
||||||
|
|
||||||
|
git_diff_free(diff);
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_diff_workdir__patience_diff(void)
|
||||||
|
{
|
||||||
|
git_index *index;
|
||||||
|
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
|
||||||
|
git_diff *diff = NULL;
|
||||||
|
git_patch *patch = NULL;
|
||||||
|
char *as_str = NULL;
|
||||||
|
const char *expected_normal = "diff --git a/test.txt b/test.txt\nindex 34a5acc..d52725f 100644\n--- a/test.txt\n+++ b/test.txt\n@@ -1,10 +1,7 @@\n When I wrote this\n I did not know\n-how to create\n-a patience diff\n I did not know\n how to create\n+a patience diff\n another problem\n-I did not know\n-how to create\n a minimal diff\n";
|
||||||
|
const char *expected_patience = "diff --git a/test.txt b/test.txt\nindex 34a5acc..d52725f 100644\n--- a/test.txt\n+++ b/test.txt\n@@ -1,10 +1,7 @@\n When I wrote this\n I did not know\n+I did not know\n how to create\n a patience diff\n-I did not know\n-how to create\n another problem\n-I did not know\n-how to create\n a minimal diff\n";
|
||||||
|
|
||||||
|
g_repo = cl_git_sandbox_init("empty_standard_repo");
|
||||||
|
cl_repo_set_bool(g_repo, "core.autocrlf", true);
|
||||||
|
cl_git_pass(git_repository_index(&index, g_repo));
|
||||||
|
|
||||||
|
cl_git_mkfile(
|
||||||
|
"empty_standard_repo/test.txt",
|
||||||
|
"When I wrote this\nI did not know\nhow to create\na patience diff\nI did not know\nhow to create\nanother problem\nI did not know\nhow to create\na minimal diff\n");
|
||||||
|
cl_git_pass(git_index_add_bypath(index, "test.txt"));
|
||||||
|
cl_repo_commit_from_index(NULL, g_repo, NULL, 1372350000, "Base");
|
||||||
|
|
||||||
|
cl_git_rewritefile(
|
||||||
|
"empty_standard_repo/test.txt",
|
||||||
|
"When I wrote this\nI did not know\nI did not know\nhow to create\na patience diff\nanother problem\na minimal diff\n");
|
||||||
|
|
||||||
|
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
|
||||||
|
cl_assert_equal_i(1, git_diff_num_deltas(diff));
|
||||||
|
cl_git_pass(git_patch_from_diff(&patch, diff, 0));
|
||||||
|
cl_git_pass(git_patch_to_str(&as_str, patch));
|
||||||
|
|
||||||
|
cl_assert_equal_s(expected_normal, as_str);
|
||||||
|
git__free(as_str);
|
||||||
|
git_patch_free(patch);
|
||||||
|
git_diff_free(diff);
|
||||||
|
|
||||||
|
opts.flags |= GIT_DIFF_PATIENCE;
|
||||||
|
|
||||||
|
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
|
||||||
|
cl_assert_equal_i(1, git_diff_num_deltas(diff));
|
||||||
|
cl_git_pass(git_patch_from_diff(&patch, diff, 0));
|
||||||
|
cl_git_pass(git_patch_to_str(&as_str, patch));
|
||||||
|
|
||||||
|
cl_assert_equal_s(expected_patience, as_str);
|
||||||
|
git__free(as_str);
|
||||||
|
git_patch_free(patch);
|
||||||
|
git_diff_free(diff);
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@ static void test_with_many(int expected_new)
|
|||||||
{
|
{
|
||||||
git_index *index;
|
git_index *index;
|
||||||
git_tree *tree, *new_tree;
|
git_tree *tree, *new_tree;
|
||||||
git_diff_list *diff = NULL;
|
git_diff *diff = NULL;
|
||||||
diff_expects exp;
|
diff_expects exp;
|
||||||
git_diff_options diffopts = GIT_DIFF_OPTIONS_INIT;
|
git_diff_options diffopts = GIT_DIFF_OPTIONS_INIT;
|
||||||
git_diff_find_options opts = GIT_DIFF_FIND_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, exp.file_status[GIT_DELTA_ADDED]);
|
||||||
cl_assert_equal_i(expected_new + 1, exp.files);
|
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_repo_commit_from_index(NULL, g_repo, NULL, 1372350000, "yoyoyo");
|
||||||
cl_git_pass(git_revparse_single(
|
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, exp.file_status[GIT_DELTA_ADDED]);
|
||||||
cl_assert_equal_i(expected_new + 1, exp.files);
|
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(new_tree);
|
||||||
git_tree_free(tree);
|
git_tree_free(tree);
|
||||||
|
Loading…
Reference in New Issue
Block a user