Commit 2de60205 by Russell Belfer

Fix usage of "new" for fieldname in public header

This should restore the ability to include libgit2 headers
in C++ projects.
parent bb97278a
...@@ -55,8 +55,8 @@ typedef struct { ...@@ -55,8 +55,8 @@ typedef struct {
uint32_t flags; /**< defaults to GIT_DIFF_NORMAL */ uint32_t flags; /**< defaults to GIT_DIFF_NORMAL */
uint16_t context_lines; /**< defaults to 3 */ uint16_t context_lines; /**< defaults to 3 */
uint16_t interhunk_lines; /**< defaults to 3 */ uint16_t interhunk_lines; /**< defaults to 3 */
char *src_prefix; /**< defaults to "a" */ char *old_prefix; /**< defaults to "a" */
char *dst_prefix; /**< defaults to "b" */ char *new_prefix; /**< defaults to "b" */
git_strarray pathspec; /**< defaults to show all paths */ git_strarray pathspec; /**< defaults to show all paths */
} git_diff_options; } git_diff_options;
...@@ -113,11 +113,11 @@ typedef struct { ...@@ -113,11 +113,11 @@ typedef struct {
* It will just use the git attributes for those files. * It will just use the git attributes for those files.
*/ */
typedef struct { typedef struct {
git_diff_file old; git_diff_file old_file;
git_diff_file new; git_diff_file new_file;
git_delta_t status; git_delta_t status;
unsigned int similarity; /**< for RENAMED and COPIED, value from 0 to 100 */ unsigned int similarity; /**< for RENAMED and COPIED, value 0-100 */
int binary; int binary;
} git_diff_delta; } git_diff_delta;
/** /**
...@@ -209,15 +209,15 @@ GIT_EXTERN(void) git_diff_list_free(git_diff_list *diff); ...@@ -209,15 +209,15 @@ GIT_EXTERN(void) git_diff_list_free(git_diff_list *diff);
* *
* @param repo The repository containing the trees. * @param repo The repository containing the trees.
* @param opts Structure with options to influence diff or NULL for defaults. * @param opts Structure with options to influence diff or NULL for defaults.
* @param old A git_tree object to diff from. * @param old_tree A git_tree object to diff from.
* @param new A git_tree object to diff to. * @param new_tree A git_tree object to diff to.
* @param diff A pointer to a git_diff_list pointer that will be allocated. * @param diff A pointer to a git_diff_list pointer that will be allocated.
*/ */
GIT_EXTERN(int) git_diff_tree_to_tree( GIT_EXTERN(int) git_diff_tree_to_tree(
git_repository *repo, git_repository *repo,
const git_diff_options *opts, /**< can be NULL for defaults */ const git_diff_options *opts, /**< can be NULL for defaults */
git_tree *old, git_tree *old_tree,
git_tree *new, git_tree *new_tree,
git_diff_list **diff); git_diff_list **diff);
/** /**
...@@ -225,13 +225,13 @@ GIT_EXTERN(int) git_diff_tree_to_tree( ...@@ -225,13 +225,13 @@ GIT_EXTERN(int) git_diff_tree_to_tree(
* *
* @param repo The repository containing the tree and index. * @param repo The repository containing the tree and index.
* @param opts Structure with options to influence diff or NULL for defaults. * @param opts Structure with options to influence diff or NULL for defaults.
* @param old A git_tree object to diff from. * @param old_tree A git_tree object to diff from.
* @param diff A pointer to a git_diff_list pointer that will be allocated. * @param diff A pointer to a git_diff_list pointer that will be allocated.
*/ */
GIT_EXTERN(int) git_diff_index_to_tree( GIT_EXTERN(int) git_diff_index_to_tree(
git_repository *repo, git_repository *repo,
const git_diff_options *opts, /**< can be NULL for defaults */ const git_diff_options *opts, /**< can be NULL for defaults */
git_tree *old, git_tree *old_tree,
git_diff_list **diff); git_diff_list **diff);
/** /**
...@@ -260,13 +260,13 @@ GIT_EXTERN(int) git_diff_workdir_to_index( ...@@ -260,13 +260,13 @@ GIT_EXTERN(int) git_diff_workdir_to_index(
* *
* @param repo The repository containing the tree. * @param repo The repository containing the tree.
* @param opts Structure with options to influence diff or NULL for defaults. * @param opts Structure with options to influence diff or NULL for defaults.
* @param old A git_tree object to diff from. * @param old_tree A git_tree object to diff from.
* @param diff A pointer to a git_diff_list pointer that will be allocated. * @param diff A pointer to a git_diff_list pointer that will be allocated.
*/ */
GIT_EXTERN(int) git_diff_workdir_to_tree( GIT_EXTERN(int) git_diff_workdir_to_tree(
git_repository *repo, git_repository *repo,
const git_diff_options *opts, /**< can be NULL for defaults */ const git_diff_options *opts, /**< can be NULL for defaults */
git_tree *old, git_tree *old_tree,
git_diff_list **diff); git_diff_list **diff);
/** /**
...@@ -341,8 +341,8 @@ GIT_EXTERN(int) git_diff_print_patch( ...@@ -341,8 +341,8 @@ GIT_EXTERN(int) git_diff_print_patch(
*/ */
GIT_EXTERN(int) git_diff_blobs( GIT_EXTERN(int) git_diff_blobs(
git_repository *repo, git_repository *repo,
git_blob *old, git_blob *old_blob,
git_blob *new, git_blob *new_blob,
git_diff_options *options, git_diff_options *options,
void *cb_data, void *cb_data,
git_diff_hunk_fn hunk_cb, git_diff_hunk_fn hunk_cb,
......
...@@ -14,14 +14,14 @@ static void diff_delta__free(git_diff_delta *delta) ...@@ -14,14 +14,14 @@ static void diff_delta__free(git_diff_delta *delta)
if (!delta) if (!delta)
return; return;
if (delta->new.flags & GIT_DIFF_FILE_FREE_PATH) { if (delta->new_file.flags & GIT_DIFF_FILE_FREE_PATH) {
git__free((char *)delta->new.path); git__free((char *)delta->new_file.path);
delta->new.path = NULL; delta->new_file.path = NULL;
} }
if (delta->old.flags & GIT_DIFF_FILE_FREE_PATH) { if (delta->old_file.flags & GIT_DIFF_FILE_FREE_PATH) {
git__free((char *)delta->old.path); git__free((char *)delta->old_file.path);
delta->old.path = NULL; delta->old_file.path = NULL;
} }
git__free(delta); git__free(delta);
...@@ -36,13 +36,13 @@ static git_diff_delta *diff_delta__alloc( ...@@ -36,13 +36,13 @@ static git_diff_delta *diff_delta__alloc(
if (!delta) if (!delta)
return NULL; return NULL;
delta->old.path = git__strdup(path); delta->old_file.path = git__strdup(path);
if (delta->old.path == NULL) { if (delta->old_file.path == NULL) {
git__free(delta); git__free(delta);
return NULL; return NULL;
} }
delta->old.flags |= GIT_DIFF_FILE_FREE_PATH; delta->old_file.flags |= GIT_DIFF_FILE_FREE_PATH;
delta->new.path = delta->old.path; delta->new_file.path = delta->old_file.path;
if (diff->opts.flags & GIT_DIFF_REVERSE) { if (diff->opts.flags & GIT_DIFF_REVERSE) {
switch (status) { switch (status) {
...@@ -64,24 +64,24 @@ static git_diff_delta *diff_delta__dup(const git_diff_delta *d) ...@@ -64,24 +64,24 @@ static git_diff_delta *diff_delta__dup(const git_diff_delta *d)
memcpy(delta, d, sizeof(git_diff_delta)); memcpy(delta, d, sizeof(git_diff_delta));
delta->old.path = git__strdup(d->old.path); delta->old_file.path = git__strdup(d->old_file.path);
if (delta->old.path == NULL) { if (delta->old_file.path == NULL) {
git__free(delta); git__free(delta);
return NULL; return NULL;
} }
delta->old.flags |= GIT_DIFF_FILE_FREE_PATH; delta->old_file.flags |= GIT_DIFF_FILE_FREE_PATH;
if (d->new.path != d->old.path) { if (d->new_file.path != d->old_file.path) {
delta->new.path = git__strdup(d->new.path); delta->new_file.path = git__strdup(d->new_file.path);
if (delta->new.path == NULL) { if (delta->new_file.path == NULL) {
git__free(delta->old.path); git__free(delta->old_file.path);
git__free(delta); git__free(delta);
return NULL; return NULL;
} }
delta->new.flags |= GIT_DIFF_FILE_FREE_PATH; delta->new_file.flags |= GIT_DIFF_FILE_FREE_PATH;
} else { } else {
delta->new.path = delta->old.path; delta->new_file.path = delta->old_file.path;
delta->new.flags &= ~GIT_DIFF_FILE_FREE_PATH; delta->new_file.flags &= ~GIT_DIFF_FILE_FREE_PATH;
} }
return delta; return delta;
...@@ -94,16 +94,16 @@ static git_diff_delta *diff_delta__merge_like_cgit( ...@@ -94,16 +94,16 @@ static git_diff_delta *diff_delta__merge_like_cgit(
if (!dup) if (!dup)
return NULL; return NULL;
if (git_oid_cmp(&dup->new.oid, &b->new.oid) == 0) if (git_oid_cmp(&dup->new_file.oid, &b->new_file.oid) == 0)
return dup; return dup;
git_oid_cpy(&dup->new.oid, &b->new.oid); git_oid_cpy(&dup->new_file.oid, &b->new_file.oid);
dup->new.mode = b->new.mode; dup->new_file.mode = b->new_file.mode;
dup->new.size = b->new.size; dup->new_file.size = b->new_file.size;
dup->new.flags = dup->new_file.flags =
(dup->new.flags & GIT_DIFF_FILE_FREE_PATH) | (dup->new_file.flags & GIT_DIFF_FILE_FREE_PATH) |
(b->new.flags & ~GIT_DIFF_FILE_FREE_PATH); (b->new_file.flags & ~GIT_DIFF_FILE_FREE_PATH);
/* Emulate C git for merging two diffs (a la 'git diff <sha>'). /* Emulate C git for merging two diffs (a la 'git diff <sha>').
* *
...@@ -111,7 +111,7 @@ static git_diff_delta *diff_delta__merge_like_cgit( ...@@ -111,7 +111,7 @@ static git_diff_delta *diff_delta__merge_like_cgit(
* diffs with the index but uses the workdir contents. This emulates * diffs with the index but uses the workdir contents. This emulates
* those choices so we can emulate the type of diff. * those choices so we can emulate the type of diff.
*/ */
if (git_oid_cmp(&dup->old.oid, &dup->new.oid) == 0) { if (git_oid_cmp(&dup->old_file.oid, &dup->new_file.oid) == 0) {
if (dup->status == GIT_DELTA_DELETED) if (dup->status == GIT_DELTA_DELETED)
/* preserve pending delete info */; /* preserve pending delete info */;
else if (b->status == GIT_DELTA_UNTRACKED || else if (b->status == GIT_DELTA_UNTRACKED ||
...@@ -141,17 +141,17 @@ static int diff_delta__from_one( ...@@ -141,17 +141,17 @@ static int diff_delta__from_one(
assert(status != GIT_DELTA_MODIFIED); assert(status != GIT_DELTA_MODIFIED);
if (delta->status == GIT_DELTA_DELETED) { if (delta->status == GIT_DELTA_DELETED) {
delta->old.mode = entry->mode; delta->old_file.mode = entry->mode;
delta->old.size = entry->file_size; delta->old_file.size = entry->file_size;
git_oid_cpy(&delta->old.oid, &entry->oid); git_oid_cpy(&delta->old_file.oid, &entry->oid);
} else /* ADDED, IGNORED, UNTRACKED */ { } else /* ADDED, IGNORED, UNTRACKED */ {
delta->new.mode = entry->mode; delta->new_file.mode = entry->mode;
delta->new.size = entry->file_size; delta->new_file.size = entry->file_size;
git_oid_cpy(&delta->new.oid, &entry->oid); git_oid_cpy(&delta->new_file.oid, &entry->oid);
} }
delta->old.flags |= GIT_DIFF_FILE_VALID_OID; delta->old_file.flags |= GIT_DIFF_FILE_VALID_OID;
delta->new.flags |= GIT_DIFF_FILE_VALID_OID; delta->new_file.flags |= GIT_DIFF_FILE_VALID_OID;
if ((error = git_vector_insert(&diff->deltas, delta)) < GIT_SUCCESS) if ((error = git_vector_insert(&diff->deltas, delta)) < GIT_SUCCESS)
diff_delta__free(delta); diff_delta__free(delta);
...@@ -162,31 +162,31 @@ static int diff_delta__from_one( ...@@ -162,31 +162,31 @@ static int diff_delta__from_one(
static int diff_delta__from_two( static int diff_delta__from_two(
git_diff_list *diff, git_diff_list *diff,
git_delta_t status, git_delta_t status,
const git_index_entry *old, const git_index_entry *old_entry,
const git_index_entry *new, const git_index_entry *new_entry,
git_oid *new_oid) git_oid *new_oid)
{ {
int error; int error;
git_diff_delta *delta; git_diff_delta *delta;
if ((diff->opts.flags & GIT_DIFF_REVERSE) != 0) { if ((diff->opts.flags & GIT_DIFF_REVERSE) != 0) {
const git_index_entry *temp = old; const git_index_entry *temp = old_entry;
old = new; old_entry = new_entry;
new = temp; new_entry = temp;
} }
delta = diff_delta__alloc(diff, status, old->path); delta = diff_delta__alloc(diff, status, old_entry->path);
if (!delta) if (!delta)
return git__rethrow(GIT_ENOMEM, "Could not allocate diff record"); return git__rethrow(GIT_ENOMEM, "Could not allocate diff record");
delta->old.mode = old->mode; delta->old_file.mode = old_entry->mode;
git_oid_cpy(&delta->old.oid, &old->oid); git_oid_cpy(&delta->old_file.oid, &old_entry->oid);
delta->old.flags |= GIT_DIFF_FILE_VALID_OID; delta->old_file.flags |= GIT_DIFF_FILE_VALID_OID;
delta->new.mode = new->mode; delta->new_file.mode = new_entry->mode;
git_oid_cpy(&delta->new.oid, new_oid ? new_oid : &new->oid); git_oid_cpy(&delta->new_file.oid, new_oid ? new_oid : &new_entry->oid);
if (new_oid || !git_oid_iszero(&new->oid)) if (new_oid || !git_oid_iszero(&new_entry->oid))
delta->new.flags |= GIT_DIFF_FILE_VALID_OID; delta->new_file.flags |= GIT_DIFF_FILE_VALID_OID;
if ((error = git_vector_insert(&diff->deltas, delta)) < GIT_SUCCESS) if ((error = git_vector_insert(&diff->deltas, delta)) < GIT_SUCCESS)
diff_delta__free(delta); diff_delta__free(delta);
...@@ -194,8 +194,8 @@ static int diff_delta__from_two( ...@@ -194,8 +194,8 @@ static int diff_delta__from_two(
return error; return error;
} }
#define DIFF_SRC_PREFIX_DEFAULT "a/" #define DIFF_OLD_PREFIX_DEFAULT "a/"
#define DIFF_DST_PREFIX_DEFAULT "b/" #define DIFF_NEW_PREFIX_DEFAULT "b/"
static char *diff_strdup_prefix(const char *prefix) static char *diff_strdup_prefix(const char *prefix)
{ {
...@@ -215,7 +215,7 @@ static char *diff_strdup_prefix(const char *prefix) ...@@ -215,7 +215,7 @@ static char *diff_strdup_prefix(const char *prefix)
static int diff_delta__cmp(const void *a, const void *b) static int diff_delta__cmp(const void *a, const void *b)
{ {
const git_diff_delta *da = a, *db = b; const git_diff_delta *da = a, *db = b;
int val = strcmp(da->old.path, db->old.path); int val = strcmp(da->old_file.path, db->old_file.path);
return val ? val : ((int)da->status - (int)db->status); return val ? val : ((int)da->status - (int)db->status);
} }
...@@ -233,25 +233,25 @@ static git_diff_list *git_diff_list_alloc( ...@@ -233,25 +233,25 @@ static git_diff_list *git_diff_list_alloc(
memcpy(&diff->opts, opts, sizeof(git_diff_options)); memcpy(&diff->opts, opts, sizeof(git_diff_options));
diff->opts.src_prefix = diff_strdup_prefix( diff->opts.old_prefix = diff_strdup_prefix(
opts->src_prefix ? opts->src_prefix : DIFF_SRC_PREFIX_DEFAULT); opts->old_prefix ? opts->old_prefix : DIFF_OLD_PREFIX_DEFAULT);
diff->opts.dst_prefix = diff_strdup_prefix( diff->opts.new_prefix = diff_strdup_prefix(
opts->dst_prefix ? opts->dst_prefix : DIFF_DST_PREFIX_DEFAULT); opts->new_prefix ? opts->new_prefix : DIFF_NEW_PREFIX_DEFAULT);
if (!diff->opts.src_prefix || !diff->opts.dst_prefix) { if (!diff->opts.old_prefix || !diff->opts.new_prefix) {
git__free(diff); git__free(diff);
return NULL; return NULL;
} }
if (diff->opts.flags & GIT_DIFF_REVERSE) { if (diff->opts.flags & GIT_DIFF_REVERSE) {
char *swap = diff->opts.src_prefix; char *swap = diff->opts.old_prefix;
diff->opts.src_prefix = diff->opts.dst_prefix; diff->opts.old_prefix = diff->opts.new_prefix;
diff->opts.dst_prefix = swap; diff->opts.new_prefix = swap;
} }
if (git_vector_init(&diff->deltas, 0, diff_delta__cmp) < GIT_SUCCESS) { if (git_vector_init(&diff->deltas, 0, diff_delta__cmp) < GIT_SUCCESS) {
git__free(diff->opts.src_prefix); git__free(diff->opts.old_prefix);
git__free(diff->opts.dst_prefix); git__free(diff->opts.new_prefix);
git__free(diff); git__free(diff);
return NULL; return NULL;
} }
...@@ -274,8 +274,8 @@ void git_diff_list_free(git_diff_list *diff) ...@@ -274,8 +274,8 @@ void git_diff_list_free(git_diff_list *diff)
diff->deltas.contents[i] = NULL; diff->deltas.contents[i] = NULL;
} }
git_vector_free(&diff->deltas); git_vector_free(&diff->deltas);
git__free(diff->opts.src_prefix); git__free(diff->opts.old_prefix);
git__free(diff->opts.dst_prefix); git__free(diff->opts.new_prefix);
git__free(diff); git__free(diff);
} }
...@@ -316,16 +316,16 @@ static int oid_for_workdir_item( ...@@ -316,16 +316,16 @@ static int oid_for_workdir_item(
} }
static int maybe_modified( static int maybe_modified(
git_iterator *old, git_iterator *old_iter,
const git_index_entry *oitem, const git_index_entry *oitem,
git_iterator *new, git_iterator *new_iter,
const git_index_entry *nitem, const git_index_entry *nitem,
git_diff_list *diff) git_diff_list *diff)
{ {
int error = GIT_SUCCESS; int error = GIT_SUCCESS;
git_oid noid, *use_noid = NULL; git_oid noid, *use_noid = NULL;
GIT_UNUSED(old); GIT_UNUSED(old_iter);
/* support "assume unchanged" & "skip worktree" bits */ /* support "assume unchanged" & "skip worktree" bits */
if ((oitem->flags_extended & GIT_IDXENTRY_INTENT_TO_ADD) != 0 || if ((oitem->flags_extended & GIT_IDXENTRY_INTENT_TO_ADD) != 0 ||
...@@ -343,7 +343,7 @@ static int maybe_modified( ...@@ -343,7 +343,7 @@ static int maybe_modified(
oitem->mode == nitem->mode) oitem->mode == nitem->mode)
return GIT_SUCCESS; return GIT_SUCCESS;
if (git_oid_iszero(&nitem->oid) && new->type == GIT_ITERATOR_WORKDIR) { if (git_oid_iszero(&nitem->oid) && new_iter->type == GIT_ITERATOR_WORKDIR) {
/* if they files look exactly alike, then we'll assume the same */ /* if they files look exactly alike, then we'll assume the same */
if (oitem->file_size == nitem->file_size && if (oitem->file_size == nitem->file_size &&
oitem->ctime.seconds == nitem->ctime.seconds && oitem->ctime.seconds == nitem->ctime.seconds &&
...@@ -376,8 +376,8 @@ static int maybe_modified( ...@@ -376,8 +376,8 @@ static int maybe_modified(
static int diff_from_iterators( static int diff_from_iterators(
git_repository *repo, git_repository *repo,
const git_diff_options *opts, /**< can be NULL for defaults */ const git_diff_options *opts, /**< can be NULL for defaults */
git_iterator *old, git_iterator *old_iter,
git_iterator *new, git_iterator *new_iter,
git_diff_list **diff_ptr) git_diff_list **diff_ptr)
{ {
int error; int error;
...@@ -389,11 +389,11 @@ static int diff_from_iterators( ...@@ -389,11 +389,11 @@ static int diff_from_iterators(
goto cleanup; goto cleanup;
} }
diff->old_src = old->type; diff->old_src = old_iter->type;
diff->new_src = new->type; diff->new_src = new_iter->type;
if ((error = git_iterator_current(old, &oitem)) < GIT_SUCCESS || if ((error = git_iterator_current(old_iter, &oitem)) < GIT_SUCCESS ||
(error = git_iterator_current(new, &nitem)) < GIT_SUCCESS) (error = git_iterator_current(new_iter, &nitem)) < GIT_SUCCESS)
goto cleanup; goto cleanup;
/* run iterators building diffs */ /* run iterators building diffs */
...@@ -403,7 +403,7 @@ static int diff_from_iterators( ...@@ -403,7 +403,7 @@ static int diff_from_iterators(
if (oitem && (!nitem || strcmp(oitem->path, nitem->path) < 0)) { if (oitem && (!nitem || strcmp(oitem->path, nitem->path) < 0)) {
error = diff_delta__from_one(diff, GIT_DELTA_DELETED, oitem); error = diff_delta__from_one(diff, GIT_DELTA_DELETED, oitem);
if (error == GIT_SUCCESS) if (error == GIT_SUCCESS)
error = git_iterator_advance(old, &oitem); error = git_iterator_advance(old_iter, &oitem);
continue; continue;
} }
...@@ -418,29 +418,29 @@ static int diff_from_iterators( ...@@ -418,29 +418,29 @@ static int diff_from_iterators(
if (ignore_prefix != NULL && if (ignore_prefix != NULL &&
git__prefixcmp(nitem->path, ignore_prefix) == 0) git__prefixcmp(nitem->path, ignore_prefix) == 0)
{ {
error = git_iterator_advance(new, &nitem); error = git_iterator_advance(new_iter, &nitem);
continue; continue;
} }
is_ignored = git_iterator_current_is_ignored(new); is_ignored = git_iterator_current_is_ignored(new_iter);
if (S_ISDIR(nitem->mode)) { if (S_ISDIR(nitem->mode)) {
if (git__prefixcmp(oitem->path, nitem->path) == 0) { if (git__prefixcmp(oitem->path, nitem->path) == 0) {
if (is_ignored) if (is_ignored)
ignore_prefix = nitem->path; ignore_prefix = nitem->path;
error = git_iterator_advance_into_directory(new, &nitem); error = git_iterator_advance_into_directory(new_iter, &nitem);
continue; continue;
} }
delta_type = GIT_DELTA_UNTRACKED; delta_type = GIT_DELTA_UNTRACKED;
} }
else if (is_ignored) else if (is_ignored)
delta_type = GIT_DELTA_IGNORED; delta_type = GIT_DELTA_IGNORED;
else if (new->type == GIT_ITERATOR_WORKDIR) else if (new_iter->type == GIT_ITERATOR_WORKDIR)
delta_type = GIT_DELTA_UNTRACKED; delta_type = GIT_DELTA_UNTRACKED;
error = diff_delta__from_one(diff, delta_type, nitem); error = diff_delta__from_one(diff, delta_type, nitem);
if (error == GIT_SUCCESS) if (error == GIT_SUCCESS)
error = git_iterator_advance(new, &nitem); error = git_iterator_advance(new_iter, &nitem);
continue; continue;
} }
...@@ -449,16 +449,16 @@ static int diff_from_iterators( ...@@ -449,16 +449,16 @@ static int diff_from_iterators(
*/ */
assert(oitem && nitem && strcmp(oitem->path, nitem->path) == 0); assert(oitem && nitem && strcmp(oitem->path, nitem->path) == 0);
error = maybe_modified(old, oitem, new, nitem, diff); error = maybe_modified(old_iter, oitem, new_iter, nitem, diff);
if (error == GIT_SUCCESS) if (error == GIT_SUCCESS)
error = git_iterator_advance(old, &oitem); error = git_iterator_advance(old_iter, &oitem);
if (error == GIT_SUCCESS) if (error == GIT_SUCCESS)
error = git_iterator_advance(new, &nitem); error = git_iterator_advance(new_iter, &nitem);
} }
cleanup: cleanup:
git_iterator_free(old); git_iterator_free(old_iter);
git_iterator_free(new); git_iterator_free(new_iter);
if (error != GIT_SUCCESS) { if (error != GIT_SUCCESS) {
git_diff_list_free(diff); git_diff_list_free(diff);
...@@ -474,17 +474,17 @@ cleanup: ...@@ -474,17 +474,17 @@ cleanup:
int git_diff_tree_to_tree( int git_diff_tree_to_tree(
git_repository *repo, git_repository *repo,
const git_diff_options *opts, /**< can be NULL for defaults */ const git_diff_options *opts, /**< can be NULL for defaults */
git_tree *old, git_tree *old_tree,
git_tree *new, git_tree *new_tree,
git_diff_list **diff) git_diff_list **diff)
{ {
int error; int error;
git_iterator *a = NULL, *b = NULL; git_iterator *a = NULL, *b = NULL;
assert(repo && old && new && diff); assert(repo && old_tree && new_tree && diff);
if ((error = git_iterator_for_tree(repo, old, &a)) < GIT_SUCCESS || if ((error = git_iterator_for_tree(repo, old_tree, &a)) < GIT_SUCCESS ||
(error = git_iterator_for_tree(repo, new, &b)) < GIT_SUCCESS) (error = git_iterator_for_tree(repo, new_tree, &b)) < GIT_SUCCESS)
return error; return error;
return diff_from_iterators(repo, opts, a, b, diff); return diff_from_iterators(repo, opts, a, b, diff);
...@@ -493,15 +493,15 @@ int git_diff_tree_to_tree( ...@@ -493,15 +493,15 @@ int git_diff_tree_to_tree(
int git_diff_index_to_tree( int git_diff_index_to_tree(
git_repository *repo, git_repository *repo,
const git_diff_options *opts, const git_diff_options *opts,
git_tree *old, git_tree *old_tree,
git_diff_list **diff) git_diff_list **diff)
{ {
int error; int error;
git_iterator *a = NULL, *b = NULL; git_iterator *a = NULL, *b = NULL;
assert(repo && old && diff); assert(repo && old_tree && diff);
if ((error = git_iterator_for_tree(repo, old, &a)) < GIT_SUCCESS || if ((error = git_iterator_for_tree(repo, old_tree, &a)) < GIT_SUCCESS ||
(error = git_iterator_for_index(repo, &b)) < GIT_SUCCESS) (error = git_iterator_for_index(repo, &b)) < GIT_SUCCESS)
return error; return error;
...@@ -529,15 +529,15 @@ int git_diff_workdir_to_index( ...@@ -529,15 +529,15 @@ int git_diff_workdir_to_index(
int git_diff_workdir_to_tree( int git_diff_workdir_to_tree(
git_repository *repo, git_repository *repo,
const git_diff_options *opts, const git_diff_options *opts,
git_tree *old, git_tree *old_tree,
git_diff_list **diff) git_diff_list **diff)
{ {
int error; int error;
git_iterator *a = NULL, *b = NULL; git_iterator *a = NULL, *b = NULL;
assert(repo && old && diff); assert(repo && old_tree && diff);
if ((error = git_iterator_for_tree(repo, old, &a)) < GIT_SUCCESS || if ((error = git_iterator_for_tree(repo, old_tree, &a)) < GIT_SUCCESS ||
(error = git_iterator_for_workdir(repo, &b)) < GIT_SUCCESS) (error = git_iterator_for_workdir(repo, &b)) < GIT_SUCCESS)
return error; return error;
...@@ -560,8 +560,10 @@ int git_diff_merge( ...@@ -560,8 +560,10 @@ int git_diff_merge(
while (i < onto->deltas.length || j < from->deltas.length) { while (i < onto->deltas.length || j < from->deltas.length) {
git_diff_delta *o = git_vector_get(&onto->deltas, i); git_diff_delta *o = git_vector_get(&onto->deltas, i);
const git_diff_delta *f = git_vector_get_const(&from->deltas, j); const git_diff_delta *f = git_vector_get_const(&from->deltas, j);
const char *opath = !o ? NULL : o->old.path ? o->old.path : o->new.path; const char *opath =
const char *fpath = !f ? NULL : f->old.path ? f->old.path : f->new.path; !o ? NULL : o->old_file.path ? o->old_file.path : o->new_file.path;
const char *fpath =
!f ? NULL : f->old_file.path ? f->old_file.path : f->new_file.path;
if (opath && (!fpath || strcmp(opath, fpath) < 0)) { if (opath && (!fpath || strcmp(opath, fpath) < 0)) {
delta = diff_delta__dup(o); delta = diff_delta__dup(o);
......
...@@ -103,11 +103,11 @@ static int set_file_is_binary_by_attr(git_repository *repo, git_diff_file *file) ...@@ -103,11 +103,11 @@ static int set_file_is_binary_by_attr(git_repository *repo, git_diff_file *file)
static void set_delta_is_binary(git_diff_delta *delta) static void set_delta_is_binary(git_diff_delta *delta)
{ {
if ((delta->old.flags & GIT_DIFF_FILE_BINARY) != 0 || if ((delta->old_file.flags & GIT_DIFF_FILE_BINARY) != 0 ||
(delta->new.flags & GIT_DIFF_FILE_BINARY) != 0) (delta->new_file.flags & GIT_DIFF_FILE_BINARY) != 0)
delta->binary = 1; delta->binary = 1;
else if ((delta->old.flags & GIT_DIFF_FILE_NOT_BINARY) != 0 || else if ((delta->old_file.flags & GIT_DIFF_FILE_NOT_BINARY) != 0 ||
(delta->new.flags & GIT_DIFF_FILE_NOT_BINARY) != 0) (delta->new_file.flags & GIT_DIFF_FILE_NOT_BINARY) != 0)
delta->binary = 0; delta->binary = 0;
/* otherwise leave delta->binary value untouched */ /* otherwise leave delta->binary value untouched */
} }
...@@ -121,34 +121,34 @@ static int file_is_binary_by_attr( ...@@ -121,34 +121,34 @@ static int file_is_binary_by_attr(
delta->binary = -1; delta->binary = -1;
/* make sure files are conceivably mmap-able */ /* make sure files are conceivably mmap-able */
if ((git_off_t)((size_t)delta->old.size) != delta->old.size || if ((git_off_t)((size_t)delta->old_file.size) != delta->old_file.size ||
(git_off_t)((size_t)delta->new.size) != delta->new.size) (git_off_t)((size_t)delta->new_file.size) != delta->new_file.size)
{ {
delta->old.flags |= GIT_DIFF_FILE_BINARY; delta->old_file.flags |= GIT_DIFF_FILE_BINARY;
delta->new.flags |= GIT_DIFF_FILE_BINARY; delta->new_file.flags |= GIT_DIFF_FILE_BINARY;
delta->binary = 1; delta->binary = 1;
return GIT_SUCCESS; return GIT_SUCCESS;
} }
/* check if user is forcing us to text diff these files */ /* check if user is forcing us to text diff these files */
if (diff->opts.flags & GIT_DIFF_FORCE_TEXT) { if (diff->opts.flags & GIT_DIFF_FORCE_TEXT) {
delta->old.flags |= GIT_DIFF_FILE_NOT_BINARY; delta->old_file.flags |= GIT_DIFF_FILE_NOT_BINARY;
delta->new.flags |= GIT_DIFF_FILE_NOT_BINARY; delta->new_file.flags |= GIT_DIFF_FILE_NOT_BINARY;
delta->binary = 0; delta->binary = 0;
return GIT_SUCCESS; return GIT_SUCCESS;
} }
/* check diff attribute +, -, or 0 */ /* check diff attribute +, -, or 0 */
error = set_file_is_binary_by_attr(diff->repo, &delta->old); error = set_file_is_binary_by_attr(diff->repo, &delta->old_file);
if (error != GIT_SUCCESS) if (error != GIT_SUCCESS)
return error; return error;
mirror_new = (delta->new.path == delta->old.path || mirror_new = (delta->new_file.path == delta->old_file.path ||
strcmp(delta->new.path, delta->old.path) == 0); strcmp(delta->new_file.path, delta->old_file.path) == 0);
if (mirror_new) if (mirror_new)
delta->new.flags &= (delta->old.flags & BINARY_DIFF_FLAGS); delta->new_file.flags &= (delta->old_file.flags & BINARY_DIFF_FLAGS);
else else
error = set_file_is_binary_by_attr(diff->repo, &delta->new); error = set_file_is_binary_by_attr(diff->repo, &delta->new_file);
set_delta_is_binary(delta); set_delta_is_binary(delta);
...@@ -163,20 +163,20 @@ static int file_is_binary_by_content( ...@@ -163,20 +163,20 @@ static int file_is_binary_by_content(
{ {
GIT_UNUSED(diff); GIT_UNUSED(diff);
if ((delta->old.flags & BINARY_DIFF_FLAGS) == 0) { if ((delta->old_file.flags & BINARY_DIFF_FLAGS) == 0) {
size_t search_len = min(old_data->len, 4000); size_t search_len = min(old_data->len, 4000);
if (strnlen(old_data->data, search_len) != search_len) if (strnlen(old_data->data, search_len) != search_len)
delta->old.flags |= GIT_DIFF_FILE_BINARY; delta->old_file.flags |= GIT_DIFF_FILE_BINARY;
else else
delta->old.flags |= GIT_DIFF_FILE_NOT_BINARY; delta->old_file.flags |= GIT_DIFF_FILE_NOT_BINARY;
} }
if ((delta->new.flags & BINARY_DIFF_FLAGS) == 0) { if ((delta->new_file.flags & BINARY_DIFF_FLAGS) == 0) {
size_t search_len = min(new_data->len, 4000); size_t search_len = min(new_data->len, 4000);
if (strnlen(new_data->data, search_len) != search_len) if (strnlen(new_data->data, search_len) != search_len)
delta->new.flags |= GIT_DIFF_FILE_BINARY; delta->new_file.flags |= GIT_DIFF_FILE_BINARY;
else else
delta->new.flags |= GIT_DIFF_FILE_NOT_BINARY; delta->new_file.flags |= GIT_DIFF_FILE_NOT_BINARY;
} }
set_delta_is_binary(delta); set_delta_is_binary(delta);
...@@ -341,37 +341,37 @@ int git_diff_foreach( ...@@ -341,37 +341,37 @@ int git_diff_foreach(
delta->status == GIT_DELTA_MODIFIED)) delta->status == GIT_DELTA_MODIFIED))
{ {
if (diff->old_src == GIT_ITERATOR_WORKDIR) if (diff->old_src == GIT_ITERATOR_WORKDIR)
error = get_workdir_content(diff->repo, &delta->old, &old_data); error = get_workdir_content(diff->repo, &delta->old_file, &old_data);
else else
error = get_blob_content( error = get_blob_content(
diff->repo, &delta->old.oid, &old_data, &old_blob); diff->repo, &delta->old_file.oid, &old_data, &old_blob);
if (error != GIT_SUCCESS) if (error != GIT_SUCCESS)
goto cleanup; goto cleanup;
} }
if (delta->binary != 1 && if (delta->binary != 1 &&
(hunk_cb || line_cb || git_oid_iszero(&delta->new.oid)) && (hunk_cb || line_cb || git_oid_iszero(&delta->new_file.oid)) &&
(delta->status == GIT_DELTA_ADDED || (delta->status == GIT_DELTA_ADDED ||
delta->status == GIT_DELTA_MODIFIED)) delta->status == GIT_DELTA_MODIFIED))
{ {
if (diff->new_src == GIT_ITERATOR_WORKDIR) if (diff->new_src == GIT_ITERATOR_WORKDIR)
error = get_workdir_content(diff->repo, &delta->new, &new_data); error = get_workdir_content(diff->repo, &delta->new_file, &new_data);
else else
error = get_blob_content( error = get_blob_content(
diff->repo, &delta->new.oid, &new_data, &new_blob); diff->repo, &delta->new_file.oid, &new_data, &new_blob);
if (error != GIT_SUCCESS) if (error != GIT_SUCCESS)
goto cleanup; goto cleanup;
if ((delta->new.flags | GIT_DIFF_FILE_VALID_OID) == 0) { if ((delta->new_file.flags | GIT_DIFF_FILE_VALID_OID) == 0) {
error = git_odb_hash( error = git_odb_hash(
&delta->new.oid, new_data.data, new_data.len, GIT_OBJ_BLOB); &delta->new_file.oid, new_data.data, new_data.len, GIT_OBJ_BLOB);
if (error != GIT_SUCCESS) if (error != GIT_SUCCESS)
goto cleanup; goto cleanup;
/* since we did not have the definitive oid, we may have /* since we did not have the definitive oid, we may have
* incorrect status and need to skip this item. * incorrect status and need to skip this item.
*/ */
if (git_oid_cmp(&delta->old.oid, &delta->new.oid) == 0) { if (git_oid_cmp(&delta->old_file.oid, &delta->new_file.oid) == 0) {
delta->status = GIT_DELTA_UNMODIFIED; delta->status = GIT_DELTA_UNMODIFIED;
goto cleanup; goto cleanup;
} }
...@@ -414,8 +414,8 @@ int git_diff_foreach( ...@@ -414,8 +414,8 @@ int git_diff_foreach(
&xdiff_params, &xdiff_config, &xdiff_callback); &xdiff_params, &xdiff_config, &xdiff_callback);
cleanup: cleanup:
release_content(&delta->old, &old_data, old_blob); release_content(&delta->old_file, &old_data, old_blob);
release_content(&delta->new, &new_data, new_blob); release_content(&delta->new_file, &new_data, new_blob);
if (error != GIT_SUCCESS) if (error != GIT_SUCCESS)
break; break;
...@@ -464,23 +464,23 @@ static int print_compact(void *data, git_diff_delta *delta, float progress) ...@@ -464,23 +464,23 @@ static int print_compact(void *data, git_diff_delta *delta, float progress)
if (!code) if (!code)
return GIT_SUCCESS; return GIT_SUCCESS;
old_suffix = pick_suffix(delta->old.mode); old_suffix = pick_suffix(delta->old_file.mode);
new_suffix = pick_suffix(delta->new.mode); new_suffix = pick_suffix(delta->new_file.mode);
git_buf_clear(pi->buf); git_buf_clear(pi->buf);
if (delta->old.path != delta->new.path && if (delta->old_file.path != delta->new_file.path &&
strcmp(delta->old.path,delta->new.path) != 0) strcmp(delta->old_file.path,delta->new_file.path) != 0)
git_buf_printf(pi->buf, "%c\t%s%c -> %s%c\n", code, git_buf_printf(pi->buf, "%c\t%s%c -> %s%c\n", code,
delta->old.path, old_suffix, delta->new.path, new_suffix); delta->old_file.path, old_suffix, delta->new_file.path, new_suffix);
else if (delta->old.mode != delta->new.mode && else if (delta->old_file.mode != delta->new_file.mode &&
delta->old.mode != 0 && delta->new.mode != 0) delta->old_file.mode != 0 && delta->new_file.mode != 0)
git_buf_printf(pi->buf, "%c\t%s%c (%o -> %o)\n", code, git_buf_printf(pi->buf, "%c\t%s%c (%o -> %o)\n", code,
delta->old.path, new_suffix, delta->old.mode, delta->new.mode); delta->old_file.path, new_suffix, delta->old_file.mode, delta->new_file.mode);
else if (old_suffix != ' ') else if (old_suffix != ' ')
git_buf_printf(pi->buf, "%c\t%s%c\n", code, delta->old.path, old_suffix); git_buf_printf(pi->buf, "%c\t%s%c\n", code, delta->old_file.path, old_suffix);
else else
git_buf_printf(pi->buf, "%c\t%s\n", code, delta->old.path); git_buf_printf(pi->buf, "%c\t%s\n", code, delta->old_file.path);
if (git_buf_lasterror(pi->buf) != GIT_SUCCESS) if (git_buf_lasterror(pi->buf) != GIT_SUCCESS)
return git_buf_lasterror(pi->buf); return git_buf_lasterror(pi->buf);
...@@ -515,21 +515,21 @@ static int print_oid_range(diff_print_info *pi, git_diff_delta *delta) ...@@ -515,21 +515,21 @@ static int print_oid_range(diff_print_info *pi, git_diff_delta *delta)
char start_oid[8], end_oid[8]; char start_oid[8], end_oid[8];
/* TODO: Determine a good actual OID range to print */ /* TODO: Determine a good actual OID range to print */
git_oid_to_string(start_oid, sizeof(start_oid), &delta->old.oid); git_oid_to_string(start_oid, sizeof(start_oid), &delta->old_file.oid);
git_oid_to_string(end_oid, sizeof(end_oid), &delta->new.oid); git_oid_to_string(end_oid, sizeof(end_oid), &delta->new_file.oid);
/* TODO: Match git diff more closely */ /* TODO: Match git diff more closely */
if (delta->old.mode == delta->new.mode) { if (delta->old_file.mode == delta->new_file.mode) {
git_buf_printf(pi->buf, "index %s..%s %o\n", git_buf_printf(pi->buf, "index %s..%s %o\n",
start_oid, end_oid, delta->old.mode); start_oid, end_oid, delta->old_file.mode);
} else { } else {
if (delta->old.mode == 0) { if (delta->old_file.mode == 0) {
git_buf_printf(pi->buf, "new file mode %o\n", delta->new.mode); git_buf_printf(pi->buf, "new file mode %o\n", delta->new_file.mode);
} else if (delta->new.mode == 0) { } else if (delta->new_file.mode == 0) {
git_buf_printf(pi->buf, "deleted file mode %o\n", delta->old.mode); git_buf_printf(pi->buf, "deleted file mode %o\n", delta->old_file.mode);
} else { } else {
git_buf_printf(pi->buf, "old mode %o\n", delta->old.mode); git_buf_printf(pi->buf, "old mode %o\n", delta->old_file.mode);
git_buf_printf(pi->buf, "new mode %o\n", delta->new.mode); git_buf_printf(pi->buf, "new mode %o\n", delta->new_file.mode);
} }
git_buf_printf(pi->buf, "index %s..%s\n", start_oid, end_oid); git_buf_printf(pi->buf, "index %s..%s\n", start_oid, end_oid);
} }
...@@ -541,23 +541,23 @@ static int print_patch_file(void *data, git_diff_delta *delta, float progress) ...@@ -541,23 +541,23 @@ static int print_patch_file(void *data, git_diff_delta *delta, float progress)
{ {
int error; int error;
diff_print_info *pi = data; diff_print_info *pi = data;
const char *oldpfx = pi->diff->opts.src_prefix; const char *oldpfx = pi->diff->opts.old_prefix;
const char *oldpath = delta->old.path; const char *oldpath = delta->old_file.path;
const char *newpfx = pi->diff->opts.dst_prefix; const char *newpfx = pi->diff->opts.new_prefix;
const char *newpath = delta->new.path; const char *newpath = delta->new_file.path;
GIT_UNUSED(progress); GIT_UNUSED(progress);
git_buf_clear(pi->buf); git_buf_clear(pi->buf);
git_buf_printf(pi->buf, "diff --git %s%s %s%s\n", oldpfx, delta->old.path, newpfx, delta->new.path); git_buf_printf(pi->buf, "diff --git %s%s %s%s\n", oldpfx, delta->old_file.path, newpfx, delta->new_file.path);
if ((error = print_oid_range(pi, delta)) < GIT_SUCCESS) if ((error = print_oid_range(pi, delta)) < GIT_SUCCESS)
return error; return error;
if (git_oid_iszero(&delta->old.oid)) { if (git_oid_iszero(&delta->old_file.oid)) {
oldpfx = ""; oldpfx = "";
oldpath = "/dev/null"; oldpath = "/dev/null";
} }
if (git_oid_iszero(&delta->new.oid)) { if (git_oid_iszero(&delta->new_file.oid)) {
oldpfx = ""; oldpfx = "";
oldpath = "/dev/null"; oldpath = "/dev/null";
} }
...@@ -664,7 +664,7 @@ int git_diff_blobs( ...@@ -664,7 +664,7 @@ int git_diff_blobs(
{ {
diff_output_info info; diff_output_info info;
git_diff_delta delta; git_diff_delta delta;
mmfile_t old, new; mmfile_t old_data, new_data;
xpparam_t xdiff_params; xpparam_t xdiff_params;
xdemitconf_t xdiff_config; xdemitconf_t xdiff_config;
xdemitcb_t xdiff_callback; xdemitcb_t xdiff_callback;
...@@ -678,31 +678,31 @@ int git_diff_blobs( ...@@ -678,31 +678,31 @@ int git_diff_blobs(
} }
if (old_blob) { if (old_blob) {
old.ptr = (char *)git_blob_rawcontent(old_blob); old_data.ptr = (char *)git_blob_rawcontent(old_blob);
old.size = git_blob_rawsize(old_blob); old_data.size = git_blob_rawsize(old_blob);
} else { } else {
old.ptr = ""; old_data.ptr = "";
old.size = 0; old_data.size = 0;
} }
if (new_blob) { if (new_blob) {
new.ptr = (char *)git_blob_rawcontent(new_blob); new_data.ptr = (char *)git_blob_rawcontent(new_blob);
new.size = git_blob_rawsize(new_blob); new_data.size = git_blob_rawsize(new_blob);
} else { } else {
new.ptr = ""; new_data.ptr = "";
new.size = 0; new_data.size = 0;
} }
/* populate a "fake" delta record */ /* populate a "fake" delta record */
delta.status = old.ptr ? delta.status = old_data.ptr ?
(new.ptr ? GIT_DELTA_MODIFIED : GIT_DELTA_DELETED) : (new_data.ptr ? GIT_DELTA_MODIFIED : GIT_DELTA_DELETED) :
(new.ptr ? GIT_DELTA_ADDED : GIT_DELTA_UNTRACKED); (new_data.ptr ? GIT_DELTA_ADDED : GIT_DELTA_UNTRACKED);
delta.old.mode = 0100644; /* can't know the truth from a blob alone */ delta.old_file.mode = 0100644; /* can't know the truth from a blob alone */
delta.new.mode = 0100644; delta.new_file.mode = 0100644;
git_oid_cpy(&delta.old.oid, git_object_id((const git_object *)old_blob)); git_oid_cpy(&delta.old_file.oid, git_object_id((const git_object *)old_blob));
git_oid_cpy(&delta.new.oid, git_object_id((const git_object *)new_blob)); git_oid_cpy(&delta.new_file.oid, git_object_id((const git_object *)new_blob));
delta.old.path = NULL; delta.old_file.path = NULL;
delta.new.path = NULL; delta.new_file.path = NULL;
delta.similarity = 0; delta.similarity = 0;
info.diff = NULL; info.diff = NULL;
...@@ -716,7 +716,7 @@ int git_diff_blobs( ...@@ -716,7 +716,7 @@ int git_diff_blobs(
xdiff_callback.outf = diff_output_cb; xdiff_callback.outf = diff_output_cb;
xdiff_callback.priv = &info; xdiff_callback.priv = &info;
xdl_diff(&old, &new, &xdiff_params, &xdiff_config, &xdiff_callback); xdl_diff(&old_data, &new_data, &xdiff_params, &xdiff_config, &xdiff_callback);
return GIT_SUCCESS; return GIT_SUCCESS;
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment