Conversation
|
Thanks, this is definitely useful. I wonder if we should standardize dry-run names across the board. We have I’m not sure that I love |
|
As far as naming is concerned, I appeal to the authority that is git upstream - they call this option |
|
I don't lIke that I expected |
|
|
Which means you could in theory build a "bad hunk" that would fail the skipped code, because the I consider this skip (unless someone finds it an useful "feature") an honest-to-god bug, and that it should have been synonymous with |
|
I don't think the docs are ambiguous, though it took a careful reading for me to conclude so. That the hunk "will not be applied" does not imply that it will be tested for applicability, even if "the apply process continues". I think the use-case here is something else, akin to |
Yes, exactly so. The It feels like there may be an opportunity to improve the docs here, though, to make that clear, but it seems like the deficiency is in the callback's docs so let's not block this change for that. (Suggestions to the contrary welcome, though.) |
I don't think the callback can really know about "patch-badness" without parsing the patch itself. If you want it, I'm fine with it going in, but I'll stand by my analysis that this addition introduces some "brittleness" — you can now ask for a |
To me this just sounds like "if you do the wrong thing, something you don't want will happen". Like "if you go to the car wash and leave all of your windows down, you'll get wet." |
|
If we're doing a For example, when using this flag we're still locking the index which we don't need to do since we're not actually applying any changes. We should also avoid the subsequent checkout steps since we shouldn't be touching the disk at all in the check case. |
|
To clarify: by "manipulating the working directory" I don't mean that we're actually changing files, but we are locking the index and calling the checkout functionality unnecessarily. |
This seems like a nice-to-have, not an essential component of this patch. In other words, suitable for a separate/future patch. |
|
Addressed the specific cases you pointed out in a second commit. I also updated the first commit to handle two edge cases that I had missed. Note that it now errors out if you attempt to check a binary patch. |
|
Bump? |
|
Yep, I lost track of this, too. Thanks for the ping @ddevault. I'm 👍 on this. |
|
Aha, looking more closely, now I understand why the binary check wasn't included. I'd actually suggest moving the tests for diff --git a/src/apply.c b/src/apply.c
index ab0b32423..0fcceafc7 100644
--- a/src/apply.c
+++ b/src/apply.c
@@ -254,9 +254,7 @@ static int apply_hunk(
goto done;
}
- if (!(ctx->opts.flags & GIT_APPLY_CHECK)) {
- error = update_hunk(image, line_num, &preimage, &postimage);
- }
+ error = update_hunk(image, line_num, &preimage, &postimage);
done:
patch_image_free(&preimage);
@@ -415,21 +413,12 @@ int git_apply__patch(
newfile->mode : GIT_FILEMODE_BLOB;
}
- if (patch->delta->flags & GIT_DIFF_FLAG_BINARY) {
- if (!(ctx.opts.flags & GIT_APPLY_CHECK)) {
- error = apply_binary(contents_out, source, source_len, patch);
- } else {
- // TODO
- error = apply_err("--check with binary patches is unsupported");
- }
- }
+ if (patch->delta->flags & GIT_DIFF_FLAG_BINARY)
+ error = apply_binary(contents_out, source, source_len, patch);
else if (patch->hunks.size)
error = apply_hunks(contents_out, source, source_len, patch, &ctx);
- else {
- if (!(ctx.opts.flags & GIT_APPLY_CHECK)) {
- error = git_buf_put(contents_out, source, source_len);
- } /* else { always applicable } */
- }
+ else
+ error = git_buf_put(contents_out, source, source_len);
if (error)
goto done;
@@ -864,6 +853,9 @@ int git_apply(
if ((error = apply_deltas(repo, pre_reader, preimage, post_reader, postimage, diff, &opts)) < 0)
goto done;
+ if (opts.flags & GIT_APPLY_CHECK)
+ goto done;
+
switch (location) {
case GIT_APPLY_LOCATION_BOTH:
error = git_apply__to_workdir(repo, diff, preimage, postimage, location, &opts);
@@ -881,8 +873,7 @@ int git_apply(
if (error < 0)
goto done;
- if (!(opts.flags & GIT_APPLY_CHECK))
- error = git_indexwriter_commit(&indexwriter);
+ error = git_indexwriter_commit(&indexwriter);
done:
git_indexwriter_cleanup(&indexwriter);Then we can check binary files: diff --git a/tests/apply/apply_helpers.h b/tests/apply/apply_helpers.h
index 364daf49d..be5bd9687 100644
--- a/tests/apply/apply_helpers.h
+++ b/tests/apply/apply_helpers.h
@@ -21,6 +21,27 @@
"-longer. take out the slices of ham, and skim off the grease if any\n" \
"+longer; take out the slices of ham, and skim off the grease if any\n"
+/* This is the binary equivalent of DIFF_MODIFY_TWO_FILES */
+#define DIFF_MODIFY_TWO_FILES_BINARY \
+ "diff --git a/asparagus.txt b/asparagus.txt\n" \
+ "index f51658077d85f2264fa179b4d0848268cb3475c3..ffb36e513f5fdf8a6ba850a20142676a2ac4807d 100644\n" \
+ "GIT binary patch\n" \
+ "delta 24\n" \
+ "fcmX@ja+-zTF*v|6$k9DCSRvRyG(c}7zYP-rT_OhP\n" \
+ "\n" \
+ "delta 24\n" \
+ "fcmX@ja+-zTF*v|6$k9DCSRvRyG(d49zYP-rT;T@W\n" \
+ "\n" \
+ "diff --git a/veal.txt b/veal.txt\n" \
+ "index 94d2c01087f48213bd157222d54edfefd77c9bba..a7b066537e6be7109abfe4ff97b675d4e077da20 100644\n" \
+ "GIT binary patch\n" \
+ "delta 26\n" \
+ "hcmX@kah!uI%+=9HA=p1OKyM?L03)OIW@$zpW&mXg25bNT\n" \
+ "\n" \
+ "delta 26\n" \
+ "hcmX@kah!uI%+=9HA=p1OKyf3N03)N`W@$zpW&mU#22ub3\n" \
+ "\n"
+
#define DIFF_DELETE_FILE \
"diff --git a/gravy.txt b/gravy.txt\n" \
"deleted file mode 100644\n" \
diff --git a/tests/apply/check.c b/tests/apply/check.c
index f83cd9d3d..2c0e53ceb 100644
--- a/tests/apply/check.c
+++ b/tests/apply/check.c
@@ -70,6 +70,23 @@ void test_apply_check__parsed_diff(void)
git_diff_free(diff);
}
+void test_apply_check__binary(void)
+{
+ git_diff *diff;
+ git_apply_options opts = GIT_APPLY_OPTIONS_INIT;
+
+ opts.flags |= GIT_APPLY_CHECK;
+ cl_git_pass(git_diff_from_buffer(&diff,
+ DIFF_MODIFY_TWO_FILES_BINARY,
+ strlen(DIFF_MODIFY_TWO_FILES_BINARY)));
+ cl_git_pass(git_apply(repo, diff, GIT_APPLY_LOCATION_INDEX, &opts));
+
+ validate_index_unchanged(repo);
+ validate_workdir_unchanged(repo);
+
+ git_diff_free(diff);
+}
+
void test_apply_check__does_not_apply(void)
{
git_diff *diff; |
This adds an option which will check if a diff is applicable without actually applying it; equivalent to git apply --check.
|
Those are great suggestions! I've updated the patch accordingly. |
|
/rebuild |
|
Sorry @pks-t, an error occurred while trying to requeue the build. |
|
sigh I'm 👍, and the CI error is unrelated. I'll manually queue another build. |
|
Thanks a lot, @ddevault! |
|
Thanks folks! |
This adds an option which will check if a diff is applicable without
actually applying it; equivalent to git apply --check.