summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@microsoft.com>2015-09-16 11:37:03 -0400
committerEdward Thomson <ethomson@github.com>2016-05-26 13:01:04 -0500
commitb85bd8ce66f271e281434ba4328a342877e0a23b (patch)
tree1d8d4de5f0dfb49d5a77fc8b96b7b040390ce7a4
parent804d5fe9f59f4d8548da9f650bc43050951f26d7 (diff)
downloadlibgit2-b85bd8ce66f271e281434ba4328a342877e0a23b.tar.gz
patch: use delta's old_file/new_file members
No need to replicate the old_file/new_file members, or plumb them strangely up.
-rw-r--r--src/apply.c2
-rw-r--r--src/patch.h2
-rw-r--r--src/patch_diff.c14
-rw-r--r--src/patch_parse.c65
4 files changed, 27 insertions, 56 deletions
diff --git a/src/apply.c b/src/apply.c
index 875f3d042..a453d3dbb 100644
--- a/src/apply.c
+++ b/src/apply.c
@@ -340,7 +340,7 @@ int git_apply__patch(
*mode_out = 0;
if (patch->delta->status != GIT_DELTA_DELETED) {
- const git_diff_file *newfile = patch->newfile(patch);
+ const git_diff_file *newfile = &patch->delta->new_file;
filename = git__strdup(newfile->path);
mode = newfile->mode ?
diff --git a/src/patch.h b/src/patch.h
index ecab570d5..b818c5cbe 100644
--- a/src/patch.h
+++ b/src/patch.h
@@ -33,8 +33,6 @@ struct git_patch {
size_t content_size;
size_t context_size;
- const git_diff_file *(*newfile)(git_patch *patch);
- const git_diff_file *(*oldfile)(git_patch *patch);
void (*free_fn)(git_patch *patch);
};
diff --git a/src/patch_diff.c b/src/patch_diff.c
index 0e06cd6eb..1a3aeda5e 100644
--- a/src/patch_diff.c
+++ b/src/patch_diff.c
@@ -21,18 +21,6 @@ static void diff_output_init(
static void diff_output_to_patch(git_patch_diff_output *, git_patch_diff *);
-static const git_diff_file *patch_diff_newfile(git_patch *p)
-{
- git_patch_diff *patch = (git_patch_diff *)p;
- return patch->nfile.file;
-}
-
-static const git_diff_file *patch_diff_oldfile(git_patch *p)
-{
- git_patch_diff *patch = (git_patch_diff *)p;
- return patch->ofile.file;
-}
-
static void patch_diff_free(git_patch *p)
{
git_patch_diff *patch = (git_patch_diff *)p;
@@ -72,8 +60,6 @@ static void patch_diff_update_binary(git_patch_diff *patch)
static void patch_diff_init_common(git_patch_diff *patch)
{
- patch->base.newfile = patch_diff_newfile;
- patch->base.oldfile = patch_diff_oldfile;
patch->base.free_fn = patch_diff_free;
patch_diff_update_binary(patch);
diff --git a/src/patch_parse.c b/src/patch_parse.c
index e5019fce9..2c16e6497 100644
--- a/src/patch_parse.c
+++ b/src/patch_parse.c
@@ -5,11 +5,9 @@
#define parse_err(...) \
( giterr_set(GITERR_PATCH, __VA_ARGS__), -1 )
+/* TODO: remove this, just use git_patch */
typedef struct {
git_patch base;
-
- git_diff_file old_file;
- git_diff_file new_file;
} git_patch_parsed;
typedef struct {
@@ -141,13 +139,13 @@ static int parse_header_path(char **out, patch_parse_ctx *ctx)
static int parse_header_git_oldpath(
git_patch_parsed *patch, patch_parse_ctx *ctx)
{
- return parse_header_path((char **)&patch->old_file.path, ctx);
+ return parse_header_path((char **)&patch->base.delta->old_file.path, ctx);
}
static int parse_header_git_newpath(
git_patch_parsed *patch, patch_parse_ctx *ctx)
{
- return parse_header_path((char **)&patch->new_file.path, ctx);
+ return parse_header_path((char **)&patch->base.delta->new_file.path, ctx);
}
static int parse_header_mode(uint16_t *mode, patch_parse_ctx *ctx)
@@ -231,37 +229,37 @@ static int parse_header_git_index(
static int parse_header_git_oldmode(
git_patch_parsed *patch, patch_parse_ctx *ctx)
{
- return parse_header_mode(&patch->old_file.mode, ctx);
+ return parse_header_mode(&patch->base.delta->old_file.mode, ctx);
}
static int parse_header_git_newmode(
git_patch_parsed *patch, patch_parse_ctx *ctx)
{
- return parse_header_mode(&patch->new_file.mode, ctx);
+ return parse_header_mode(&patch->base.delta->new_file.mode, ctx);
}
static int parse_header_git_deletedfilemode(
git_patch_parsed *patch,
patch_parse_ctx *ctx)
{
- git__free((char *)patch->old_file.path);
+ git__free((char *)patch->base.delta->old_file.path);
- patch->old_file.path = NULL;
+ patch->base.delta->old_file.path = NULL;
patch->base.delta->status = GIT_DELTA_DELETED;
- return parse_header_mode(&patch->old_file.mode, ctx);
+ return parse_header_mode(&patch->base.delta->old_file.mode, ctx);
}
static int parse_header_git_newfilemode(
git_patch_parsed *patch,
patch_parse_ctx *ctx)
{
- git__free((char *)patch->new_file.path);
+ git__free((char *)patch->base.delta->new_file.path);
- patch->new_file.path = NULL;
+ patch->base.delta->new_file.path = NULL;
patch->base.delta->status = GIT_DELTA_ADDED;
- return parse_header_mode(&patch->new_file.mode, ctx);
+ return parse_header_mode(&patch->base.delta->new_file.mode, ctx);
}
static int parse_header_rename(
@@ -313,7 +311,7 @@ static int parse_header_renamefrom(
patch->base.delta->status |= GIT_DELTA_RENAMED;
return parse_header_rename(
- (char **)&patch->old_file.path,
+ (char **)&patch->base.delta->old_file.path,
&ctx->header_old_path,
ctx);
}
@@ -324,7 +322,7 @@ static int parse_header_renameto(
patch->base.delta->status |= GIT_DELTA_RENAMED;
return parse_header_rename(
- (char **)&patch->new_file.path,
+ (char **)&patch->base.delta->new_file.path,
&ctx->header_new_path,
ctx);
}
@@ -674,16 +672,18 @@ static int parsed_patch_header(
/* For modechange only patches, it does not include filenames;
* instead we need to use the paths in the diff --git header.
*/
- if (!patch->old_file.path && !patch->new_file.path) {
+ if (!patch->base.delta->old_file.path &&
+ !patch->base.delta->new_file.path) {
+
if (!ctx->header_old_path || !ctx->header_new_path) {
error = parse_err("git diff header lacks old / new paths");
goto done;
}
- patch->old_file.path = ctx->header_old_path;
+ patch->base.delta->old_file.path = ctx->header_old_path;
ctx->header_old_path = NULL;
- patch->new_file.path = ctx->header_new_path;
+ patch->base.delta->new_file.path = ctx->header_new_path;
ctx->header_new_path = NULL;
}
@@ -848,38 +848,28 @@ static int parsed_patch_body(
static int check_patch(git_patch_parsed *patch)
{
- if (!patch->old_file.path && patch->base.delta->status != GIT_DELTA_ADDED)
+ if (!patch->base.delta->old_file.path &&
+ patch->base.delta->status != GIT_DELTA_ADDED)
return parse_err("missing old file path");
- if (!patch->new_file.path && patch->base.delta->status != GIT_DELTA_DELETED)
+ if (!patch->base.delta->new_file.path &&
+ patch->base.delta->status != GIT_DELTA_DELETED)
return parse_err("missing new file path");
- if (patch->old_file.path && patch->new_file.path) {
- if (!patch->new_file.mode)
- patch->new_file.mode = patch->old_file.mode;
+ if (patch->base.delta->old_file.path && patch->base.delta->new_file.path) {
+ if (!patch->base.delta->new_file.mode)
+ patch->base.delta->new_file.mode = patch->base.delta->old_file.mode;
}
if (patch->base.delta->status == GIT_DELTA_MODIFIED &&
!(patch->base.delta->flags & GIT_DIFF_FLAG_BINARY) &&
- patch->new_file.mode == patch->old_file.mode &&
+ patch->base.delta->new_file.mode == patch->base.delta->old_file.mode &&
git_array_size(patch->base.hunks) == 0)
return parse_err("patch with no hunks");
return 0;
}
-static const git_diff_file *parsed_patch_newfile(git_patch *p)
-{
- git_patch_parsed *patch = (git_patch_parsed *)p;
- return &patch->new_file;
-}
-
-static const git_diff_file *parsed_patch_oldfile(git_patch *p)
-{
- git_patch_parsed *patch = (git_patch_parsed *)p;
- return &patch->old_file;
-}
-
int git_patch_from_patchfile(
git_patch **out,
const char *content,
@@ -894,9 +884,6 @@ int git_patch_from_patchfile(
patch = git__calloc(1, sizeof(git_patch_parsed));
GITERR_CHECK_ALLOC(patch);
- patch->base.newfile = parsed_patch_newfile;
- patch->base.oldfile = parsed_patch_oldfile;
-
patch->base.delta = git__calloc(1, sizeof(git_diff_delta));
patch->base.delta->status = GIT_DELTA_MODIFIED;