patch: use delta's old_file/new_file members No need to replicate the old_file/new_file members, or plumb them strangely up.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234
diff --git a/src/apply.c b/src/apply.c
index 875f3d0..a453d3d 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 ecab570..b818c5c 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 0e06cd6..1a3aeda 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 e5019fc..2c16e64 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;