Skip to contentSkip to conversation

git-apply: modify prints to account for --3way changes

PATCH Superseded Jerry Zhang 2 participants 7 messages Apr 27, 2021 – Apr 29, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 git-apply: modify prints to account for --3way changes

"git apply" specifically calls out when it is falling back to 3way merge application. Since the order changed to preferring 3way and falling back to direct application, continue that behavior by printing whenever 3way fails and git has to fall back.

Add a --quiet flag to "git apply" so the user can turn down the verbosity.

---
 apply.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
apply.c +7 -1
index 8532b48e4f..2abf2e8a61 100644
@@ -3572,7 +3572,7 @@ static int try_threeway(struct apply_state *state,
 		 read_blob_object(&buf, &pre_oid, patch->old_mode))
 		return error(_("repository lacks the necessary blob to perform 3-way merge."));
 
-	if (state->apply_verbosity > verbosity_silent)
+	if (state->apply_verbosity > verbosity_silent && patch->direct_to_threeway)
 		fprintf(stderr, _("Performing three-way merge...\n"));
 
 	img = strbuf_detach(&buf, &len);
@@ -3639,6 +3639,10 @@ static int apply_data(struct apply_state *state, struct patch *patch,
 		return -1;
 
 	if (!state->threeway || try_threeway(state, &image, patch, st, ce) < 0) {
+		if (state->apply_verbosity > verbosity_silent &&
+		    state->threeway && !patch->direct_to_threeway)
+			fprintf(stderr, _("Falling back to direct application...\n"));
+
 		/* Note: with --reject, apply_fragments() returns 0 */
 		if (patch->direct_to_threeway || apply_fragments(state, &image, patch) < 0)
 			return -1;
@@ -5050,6 +5054,8 @@ int apply_parse_options(int argc, const char **argv,
 		OPT_BOOL(0, "allow-overlap", &state->allow_overlap,
 			N_("allow overlapping hunks")),
 		OPT__VERBOSE(&state->apply_verbosity, N_("be verbose")),
+		OPT_SET_INT('q', "quiet", &state->apply_verbosity,
+			N_("be quiet"), -1),
 		OPT_BIT(0, "inaccurate-eof", options,
 			N_("tolerate incorrectly detected missing new-line at the end of file"),
 			APPLY_OPT_INACCURATE_EOF),
Signature · 1 line
2.29.0
#1 lore raw
Quoted 6 lines · Jerry Zhang

"git apply" specifically calls out when it is falling back to 3way merge application. Since the order changed to preferring 3way and falling back to direct application, continue that behavior by printing whenever 3way fails and git has to fall back.

That makes sense.

Quoted 2 lines

Add a --quiet flag to "git apply" so the user can turn down the verbosity.

It makes sense, too.

But aren't they a different change that should belong to a separate patch? After all, the first point is to give the same kind of fallback warning/report as we used to before we swapped the fallback order, and no users needed extra "more silent" setting to deal with the fallback warning messages. Allowing to set the verbosity even lower may be desirable, but that is an independent new feature, isn't it?

I wonder if it is the more correct approach to replace OPT__VERBOSE() with OPT_VERBOSITY() here, instead of adding a separate OPT_SET_INT() like you did.

Thanks.

Quoted 38 lines
---
 apply.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
apply.c +7 -1
index 8532b48e4f..2abf2e8a61 100644
@@ -3572,7 +3572,7 @@ static int try_threeway(struct apply_state *state,
 		 read_blob_object(&buf, &pre_oid, patch->old_mode))
 		return error(_("repository lacks the necessary blob to perform 3-way merge."));
 
-	if (state->apply_verbosity > verbosity_silent)
+	if (state->apply_verbosity > verbosity_silent && patch->direct_to_threeway)
 		fprintf(stderr, _("Performing three-way merge...\n"));
 
 	img = strbuf_detach(&buf, &len);
@@ -3639,6 +3639,10 @@ static int apply_data(struct apply_state *state, struct patch *patch,
 		return -1;
 
 	if (!state->threeway || try_threeway(state, &image, patch, st, ce) < 0) {
+		if (state->apply_verbosity > verbosity_silent &&
+		    state->threeway && !patch->direct_to_threeway)
+			fprintf(stderr, _("Falling back to direct application...\n"));
+
 		/* Note: with --reject, apply_fragments() returns 0 */
 		if (patch->direct_to_threeway || apply_fragments(state, &image, patch) < 0)
 			return -1;
@@ -5050,6 +5054,8 @@ int apply_parse_options(int argc, const char **argv,
 		OPT_BOOL(0, "allow-overlap", &state->allow_overlap,
 			N_("allow overlapping hunks")),
 		OPT__VERBOSE(&state->apply_verbosity, N_("be verbose")),
+		OPT_SET_INT('q', "quiet", &state->apply_verbosity,
+			N_("be quiet"), -1),
 		OPT_BIT(0, "inaccurate-eof", options,
 			N_("tolerate incorrectly detected missing new-line at the end of file"),
 			APPLY_OPT_INACCURATE_EOF),
#2 lore raw

PATCH v2 1/1 git-apply: modify prints to account for --3way changes

In reply to Jerry Zhang

"git apply" specifically calls out when it is falling back to 3way merge application. Since the order changed to preferring 3way and falling back to direct application, continue that behavior by printing whenever 3way fails and git has to fall back.

---
V1 -> V2:
- Moved --quiet flag to separate patch

 apply.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
apply.c +5 -1
index a36d4002ca..7aa49e2048 100644
@@ -3572,7 +3572,7 @@ static int try_threeway(struct apply_state *state,
 		 read_blob_object(&buf, &pre_oid, patch->old_mode))
 		return error(_("repository lacks the necessary blob to perform 3-way merge."));
 
-	if (state->apply_verbosity > verbosity_silent)
+	if (state->apply_verbosity > verbosity_silent && patch->direct_to_threeway)
 		fprintf(stderr, _("Performing three-way merge...\n"));
 
 	img = strbuf_detach(&buf, &len);
@@ -3639,6 +3639,10 @@ static int apply_data(struct apply_state *state, struct patch *patch,
 		return -1;
 
 	if (!state->threeway || try_threeway(state, &image, patch, st, ce) < 0) {
+		if (state->apply_verbosity > verbosity_silent &&
+		    state->threeway && !patch->direct_to_threeway)
+			fprintf(stderr, _("Falling back to direct application...\n"));
+
 		/* Note: with --reject, apply_fragments() returns 0 */
 		if (patch->direct_to_threeway || apply_fragments(state, &image, patch) < 0)
 			return -1;
Signature · 1 line
2.29.0
#3 lore raw
Quoted 1 line · Jerry Zhang

Subject: Re: [PATCH V2] git-apply: modify prints to account for --3way changes

Sorry that I missed this in the previous round, but what do you mean by "prints" here?

Quoted 4 lines

"git apply" specifically calls out when it is falling back to 3way merge application. Since the order changed to preferring 3way and falling back to direct application, continue that behavior by printing whenever 3way fails and git has to fall back.

I am guessing it is safe to s/modify prints/adjust messages/ after reading this explanation.

Quoted 32 lines

---
V1 -> V2:
- Moved --quiet flag to separate patch

 apply.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
apply.c +5 -1
index a36d4002ca..7aa49e2048 100644
@@ -3572,7 +3572,7 @@ static int try_threeway(struct apply_state *state,
 		 read_blob_object(&buf, &pre_oid, patch->old_mode))
 		return error(_("repository lacks the necessary blob to perform 3-way merge."));
 
-	if (state->apply_verbosity > verbosity_silent)
+	if (state->apply_verbosity > verbosity_silent && patch->direct_to_threeway)
 		fprintf(stderr, _("Performing three-way merge...\n"));
 
 	img = strbuf_detach(&buf, &len);
@@ -3639,6 +3639,10 @@ static int apply_data(struct apply_state *state, struct patch *patch,
 		return -1;
 
 	if (!state->threeway || try_threeway(state, &image, patch, st, ce) < 0) {
+		if (state->apply_verbosity > verbosity_silent &&
+		    state->threeway && !patch->direct_to_threeway)
+			fprintf(stderr, _("Falling back to direct application...\n"));
+
 		/* Note: with --reject, apply_fragments() returns 0 */
 		if (patch->direct_to_threeway || apply_fragments(state, &image, patch) < 0)
 			return -1;
#4 lore raw
Quoted 8 lines · Junio C Hamano
Quoted 1 line · Jerry Zhang

Subject: Re: [PATCH V2] git-apply: modify prints to account for --3way changes

Sorry that I missed this in the previous round, but what do you mean by "prints" here?

Quoted 7 lines
Quoted 4 lines

"git apply" specifically calls out when it is falling back to 3way merge application. Since the order changed to preferring 3way and falling back to direct application, continue that behavior by printing whenever 3way fails and git has to fall back.

I am guessing it is safe to s/modify prints/adjust messages/ after reading this explanation.

Sure, do you want a new patch for that?

Quoted 33 lines
Quoted 33 lines

---
V1 -> V2:
- Moved --quiet flag to separate patch

 apply.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
apply.c +5 -1
index a36d4002ca..7aa49e2048 100644
@@ -3572,7 +3572,7 @@ static int try_threeway(struct apply_state *state,
               read_blob_object(&buf, &pre_oid, patch->old_mode))
              return error(_("repository lacks the necessary blob to perform 3-way merge."));
 
-     if (state->apply_verbosity > verbosity_silent)
+     if (state->apply_verbosity > verbosity_silent && patch->direct_to_threeway)
              fprintf(stderr, _("Performing three-way merge...\n"));
 
      img = strbuf_detach(&buf, &len);
@@ -3639,6 +3639,10 @@ static int apply_data(struct apply_state *state, struct patch *patch,
              return -1;
 
      if (!state->threeway || try_threeway(state, &image, patch, st, ce) < 0) {
+             if (state->apply_verbosity > verbosity_silent &&
+                 state->threeway && !patch->direct_to_threeway)
+                     fprintf(stderr, _("Falling back to direct application...\n"));
+
              /* Note: with --reject, apply_fragments() returns 0 */
              if (patch->direct_to_threeway || apply_fragments(state, &image, patch) < 0)
                      return -1;
#5 lore raw
Quoted 9 lines · Jerry Zhang
Quoted 8 lines · Junio C Hamano
Quoted 1 line · Jerry Zhang

Subject: Re: [PATCH V2] git-apply: modify prints to account for --3way changes

Sorry that I missed this in the previous round, but what do you mean by "prints" here?

Quoted 8 lines
Quoted 7 lines
Quoted 4 lines

"git apply" specifically calls out when it is falling back to 3way merge application. Since the order changed to preferring 3way and falling back to direct application, continue that behavior by printing whenever 3way fails and git has to fall back.

I am guessing it is safe to s/modify prints/adjust messages/ after reading this explanation.

Sure, do you want a new patch for that?

It's not what *I* want ;-).

If what you sent is not sufficiently clear to help readers, you would want to update, no?

#6 lore raw

PATCH v3 1/1 git-apply: adjust messages to account for --3way changes

In reply to Jerry Zhang

"git apply" specifically calls out when it is falling back to 3way merge application. Since the order changed to preferring 3way and falling back to direct application, continue that behavior by printing whenever 3way fails and git has to fall back.

---
V2->V3
- Changed "modify prints" to "adjust messages"

 apply.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
apply.c +5 -1
index 5957430433..0ddde5e8a8 100644
@@ -3572,7 +3572,7 @@ static int try_threeway(struct apply_state *state,
 		 read_blob_object(&buf, &pre_oid, patch->old_mode))
 		return error(_("repository lacks the necessary blob to perform 3-way merge."));
 
-	if (state->apply_verbosity > verbosity_silent)
+	if (state->apply_verbosity > verbosity_silent && patch->direct_to_threeway)
 		fprintf(stderr, _("Performing three-way merge...\n"));
 
 	img = strbuf_detach(&buf, &len);
@@ -3639,6 +3639,10 @@ static int apply_data(struct apply_state *state, struct patch *patch,
 		return -1;
 
 	if (!state->threeway || try_threeway(state, &image, patch, st, ce) < 0) {
+		if (state->apply_verbosity > verbosity_silent &&
+		    state->threeway && !patch->direct_to_threeway)
+			fprintf(stderr, _("Falling back to direct application...\n"));
+
 		/* Note: with --reject, apply_fragments() returns 0 */
 		if (patch->direct_to_threeway || apply_fragments(state, &image, patch) < 0)
 			return -1;
Signature · 1 line
2.29.0