Skip to content

Commit 4101915

Browse files
committed
patch_generate: remove duplicated logic
Under the existing logic, we try to load patch contents differently, depending on whether the patch files stem from the working directory or not. But actually, the executed code paths are completely equal to each other -- so we were always the code despite the condition. Remove the condition altogether and conflate both code paths.
1 parent 53454be commit 4101915

File tree

1 file changed

+8
-29
lines changed

1 file changed

+8
-29
lines changed

src/patch_generate.c

Lines changed: 8 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -206,35 +206,14 @@ static int patch_generated_load(git_patch_generated *patch, git_patch_generated_
206206
((patch->nfile.flags & GIT_DIFF_FLAG__NO_DATA) != 0 ||
207207
(patch->nfile.file->flags & GIT_DIFF_FLAG_VALID_ID) != 0));
208208

209-
/* always try to load workdir content first because filtering may
210-
* need 2x data size and this minimizes peak memory footprint
211-
*/
212-
if (patch->ofile.src == GIT_ITERATOR_TYPE_WORKDIR) {
213-
if ((error = git_diff_file_content__load(
214-
&patch->ofile, &patch->base.diff_opts)) < 0 ||
215-
should_skip_binary(patch, patch->ofile.file))
216-
goto cleanup;
217-
}
218-
if (patch->nfile.src == GIT_ITERATOR_TYPE_WORKDIR) {
219-
if ((error = git_diff_file_content__load(
220-
&patch->nfile, &patch->base.diff_opts)) < 0 ||
221-
should_skip_binary(patch, patch->nfile.file))
222-
goto cleanup;
223-
}
224-
225-
/* once workdir has been tried, load other data as needed */
226-
if (patch->ofile.src != GIT_ITERATOR_TYPE_WORKDIR) {
227-
if ((error = git_diff_file_content__load(
228-
&patch->ofile, &patch->base.diff_opts)) < 0 ||
229-
should_skip_binary(patch, patch->ofile.file))
230-
goto cleanup;
231-
}
232-
if (patch->nfile.src != GIT_ITERATOR_TYPE_WORKDIR) {
233-
if ((error = git_diff_file_content__load(
234-
&patch->nfile, &patch->base.diff_opts)) < 0 ||
235-
should_skip_binary(patch, patch->nfile.file))
236-
goto cleanup;
237-
}
209+
if ((error = git_diff_file_content__load(
210+
&patch->ofile, &patch->base.diff_opts)) < 0 ||
211+
should_skip_binary(patch, patch->ofile.file))
212+
goto cleanup;
213+
if ((error = git_diff_file_content__load(
214+
&patch->nfile, &patch->base.diff_opts)) < 0 ||
215+
should_skip_binary(patch, patch->nfile.file))
216+
goto cleanup;
238217

239218
/* if previously missing an oid, and now that we have it the two sides
240219
* are the same (and not submodules), update MODIFIED -> UNMODIFIED

0 commit comments

Comments
 (0)