From: Junio C Hamano <gitster@pobox.com>
To: "Rubén Justo" <rjusto@gmail.com>
Cc: Git List <git@vger.kernel.org>,
Dragan Simic <dsimic@manjaro.org>, Jeff King <peff@peff.net>
Subject: Re: [PATCH v4 6/6] add-patch: introduce the command '|'
Date: Tue, 04 Jun 2024 22:16:06 -0700 [thread overview]
Message-ID: <xmqq4ja8ynop.fsf@gitster.g> (raw)
In-Reply-To: <xmqqy17kws2k.fsf@gitster.g> (Junio C. Hamano's message of "Tue, 04 Jun 2024 10:12:03 -0700")
Junio C Hamano <gitster@pobox.com> writes:
> By the way, it should be trivial to make the "custom" pager more sticky.
Here is what you can squash into this step. I gave many other
pieces of style and design advices in other messages, which are not
covered by this patch but the necessary fixes should be obvious.
This message is only about making the custom pager stick during a
session. It does not adjust the command help to give the last pager
command (or literally "your pager"), either.
---- >8 ----
Subject: [PATCH] add-p: make custom pager sticky during a session
The original design kept resetting the choice of the custom pager
every time the '|' command is used. This was way cumbersome to use.
Keep track of the last choice in the add_p_state.custom_pager
member. This value can stick across calls to patch_update_file()
function, so a custom pager used for choosing hunks in one file
can be carried over to the view hunks in the next file.
As we make the custom pager stick, we need a way to reset it back to
the default value (which we use NULL for, as set_custom_pager()
takes the value to mean "use the default one").
As there is no value that can say "pager is not used" suitable for
the custom_pager member to take, we need a separate "use_pager" flag
so that the fact that '|' command was used can be propagated to the
next iteration of the loop, independent from what custom pager is
used.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
add-patch.c | 33 +++++++++++++++++++++++----------
1 file changed, 23 insertions(+), 10 deletions(-)
diff --git a/add-patch.c b/add-patch.c
index da13e267db..71ee7f9a94 100644
--- a/add-patch.c
+++ b/add-patch.c
@@ -272,6 +272,7 @@ struct add_p_state {
/* patch mode */
struct patch_mode *mode;
const char *revision;
+ char *custom_pager;
};
static void add_p_state_clear(struct add_p_state *s)
@@ -285,6 +286,7 @@ static void add_p_state_clear(struct add_p_state *s)
for (i = 0; i < s->file_diff_nr; i++)
free(s->file_diff[i].hunk);
free(s->file_diff);
+ free(s->custom_pager);
clear_add_i_state(&s->s);
}
@@ -1403,7 +1405,7 @@ static int patch_update_file(struct add_p_state *s,
struct child_process cp = CHILD_PROCESS_INIT;
int colored = !!s->colored.len, quit = 0;
enum prompt_mode_type prompt_mode_type;
- const char* pager = NULL;
+ int use_pager = 0;
enum {
ALLOW_GOTO_PREVIOUS_HUNK = 1 << 0,
ALLOW_GOTO_PREVIOUS_UNDECIDED_HUNK = 1 << 1,
@@ -1452,14 +1454,14 @@ static int patch_update_file(struct add_p_state *s,
strbuf_reset(&s->buf);
if (file_diff->hunk_nr) {
if (rendered_hunk_index != hunk_index) {
- if (pager)
- setup_custom_pager(pager);
+ if (use_pager)
+ setup_custom_pager(s->custom_pager);
render_hunk(s, hunk, 0, colored, &s->buf);
fputs(s->buf.buf, stdout);
rendered_hunk_index = hunk_index;
- if (pager) {
+ if (use_pager) {
wait_for_pager();
- pager = NULL;
+ use_pager = 0;
}
}
@@ -1685,15 +1687,26 @@ static int patch_update_file(struct add_p_state *s,
} else if (s->answer.buf[0] == 'p') {
rendered_hunk_index = -1;
} else if (ch == '|') {
- strbuf_remove(&s->answer, 0, 1);
- if (s->s.use_single_key && s->answer.len == 0) {
+ if (!s->s.use_single_key) {
+ strbuf_remove(&s->answer, 0, 1);
+ } else {
printf("%s", _("program? "));
fflush(stdout);
strbuf_getline(&s->answer, stdin);
- strbuf_trim_trailing_newline(&s->answer);
}
- strbuf_trim(&s->answer);
- pager = s->answer.buf;
+ strbuf_trim_trailing_newline(&s->answer);
+
+ if (!s->answer.len)
+ ; /* empty input - reuse the previous */
+ else {
+ strbuf_trim(&s->answer);
+ FREE_AND_NULL(s->custom_pager);
+ if (!s->answer.len)
+ ; /* semi-empty - use your pager */
+ else
+ s->custom_pager = xstrdup(s->answer.buf);
+ }
+ use_pager = 1;
rendered_hunk_index = -1;
} else if (s->answer.buf[0] == '?') {
const char *p = _(help_patch_remainder), *eol = p;
--
2.45.2-409-g7b0defb391
next prev parent reply other threads:[~2024-06-05 5:16 UTC|newest]
Thread overview: 113+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-19 7:06 [PATCH 0/5] use the pager in 'add -p' Rubén Justo
2024-05-19 7:10 ` [PATCH 1/5] add-patch: test for 'p' command Rubén Justo
2024-05-19 7:12 ` [PATCH 2/5] pager: do not close fd 2 unnecessarily Rubén Justo
2024-05-20 19:14 ` Junio C Hamano
2024-05-20 22:33 ` Rubén Justo
2024-05-21 20:57 ` Junio C Hamano
2024-05-21 21:35 ` Rubén Justo
2024-05-21 22:00 ` Junio C Hamano
2024-05-22 17:19 ` Rubén Justo
2024-05-22 17:40 ` Junio C Hamano
2024-05-26 6:48 ` Rubén Justo
2024-05-26 21:26 ` Junio C Hamano
2024-05-19 7:13 ` [PATCH 3/5] pager: introduce wait_for_pager Rubén Justo
2024-05-19 7:14 ` [PATCH 4/5] test-terminal: introduce --no-stdin-pty Rubén Justo
2024-05-19 7:14 ` [PATCH 5/5] add-patch: render hunks through the pager Rubén Justo
2024-05-20 19:30 ` Junio C Hamano
2024-05-20 19:45 ` Dragan Simic
2024-05-20 22:35 ` Rubén Justo
2024-05-20 23:54 ` Dragan Simic
2024-05-21 19:56 ` Rubén Justo
2024-05-21 7:07 ` Jeff King
2024-05-21 19:59 ` Rubén Justo
2024-05-23 9:06 ` Jeff King
2024-05-23 14:00 ` Junio C Hamano
2024-05-23 14:18 ` Dragan Simic
2024-05-23 23:04 ` Junio C Hamano
2024-05-23 23:28 ` Dragan Simic
2024-05-23 23:43 ` Dragan Simic
2024-05-23 23:54 ` Junio C Hamano
2024-05-23 23:57 ` Dragan Simic
2024-05-25 4:54 ` Jeff King
2024-05-23 22:25 ` Rubén Justo
2024-05-23 23:03 ` Dragan Simic
2024-05-20 22:47 ` Rubén Justo
2024-05-20 23:18 ` Junio C Hamano
2024-05-20 23:27 ` Rubén Justo
2024-05-21 20:49 ` [PATCH v2 0/5] use the pager in 'add -p' Rubén Justo
2024-05-21 20:51 ` [PATCH v2 1/5] add-patch: test for 'p' command Rubén Justo
2024-05-21 20:52 ` [PATCH v2 2/5] pager: do not close fd 2 unnecessarily Rubén Justo
2024-05-21 20:52 ` [PATCH v2 3/5] pager: introduce wait_for_pager Rubén Justo
2024-05-21 20:52 ` [PATCH v2 4/5] test-terminal: introduce --no-stdin-pty Rubén Justo
2024-05-21 20:52 ` [PATCH v2 5/5] add-patch: render hunks through the pager Rubén Justo
2024-05-22 8:09 ` Dragan Simic
2024-05-22 18:47 ` Junio C Hamano
2024-05-22 21:23 ` Rubén Justo
2024-05-22 21:27 ` Dragan Simic
2024-06-02 15:38 ` [PATCH v3 0/6] use the pager in 'add -p' Rubén Justo
2024-06-02 15:42 ` [PATCH v3 1/6] add-patch: test for 'p' command Rubén Justo
2024-06-02 15:42 ` [PATCH v3 2/6] pager: do not close fd 2 unnecessarily Rubén Justo
2024-06-02 15:43 ` [PATCH v3 3/6] pager: introduce wait_for_pager Rubén Justo
2024-06-02 15:43 ` [PATCH v3 4/6] pager: introduce setup_custom_pager Rubén Justo
2024-06-02 15:43 ` [PATCH v3 5/6] test-terminal: introduce --no-stdin-pty Rubén Justo
2024-06-02 15:44 ` [PATCH v3 6/6] add-patch: introduce the command '|' Rubén Justo
2024-06-02 16:36 ` [PATCH v3 0/6] use the pager in 'add -p' Junio C Hamano
2024-06-02 17:11 ` Junio C Hamano
2024-06-02 17:33 ` Rubén Justo
2024-06-02 17:13 ` Rubén Justo
2024-06-02 17:46 ` Dragan Simic
2024-06-03 9:03 ` Junio C Hamano
2024-06-03 10:21 ` Dragan Simic
2024-06-03 15:28 ` Junio C Hamano
2024-06-04 17:34 ` Dragan Simic
2024-06-02 17:36 ` Dragan Simic
2024-06-03 16:01 ` Junio C Hamano
2024-06-04 17:41 ` Dragan Simic
2024-06-04 17:42 ` Dragan Simic
2024-06-03 20:19 ` Rubén Justo
2024-06-04 18:13 ` Dragan Simic
2024-06-03 20:35 ` [PATCH v4 " Rubén Justo
2024-06-03 20:38 ` [PATCH v4 1/6] add-patch: test for 'p' command Rubén Justo
2024-06-03 20:38 ` [PATCH v4 2/6] pager: do not close fd 2 unnecessarily Rubén Justo
2024-06-04 15:50 ` Junio C Hamano
2024-06-03 20:38 ` [PATCH v4 3/6] pager: introduce wait_for_pager Rubén Justo
2024-06-04 10:00 ` Phillip Wood
2024-06-04 16:29 ` Junio C Hamano
2024-06-05 22:03 ` Rubén Justo
2024-06-04 16:25 ` Junio C Hamano
2024-06-03 20:38 ` [PATCH v4 4/6] pager: introduce setup_custom_pager Rubén Justo
2024-06-04 16:43 ` Junio C Hamano
2024-06-03 20:38 ` [PATCH v4 5/6] test-terminal: introduce --no-stdin-pty Rubén Justo
2024-06-04 10:05 ` Phillip Wood
2024-06-04 10:33 ` Jeff King
2024-06-05 15:39 ` Junio C Hamano
2024-06-06 8:24 ` Jeff King
2024-06-05 22:50 ` Rubén Justo
2024-06-06 8:27 ` Jeff King
2024-06-09 7:26 ` Rubén Justo
2024-06-03 20:38 ` [PATCH v4 6/6] add-patch: introduce the command '|' Rubén Justo
2024-06-04 17:12 ` Junio C Hamano
2024-06-04 20:05 ` Dragan Simic
2024-06-05 5:16 ` Junio C Hamano [this message]
2024-06-04 10:17 ` [PATCH v3 0/6] use the pager in 'add -p' Jeff King
2024-06-04 15:32 ` Junio C Hamano
2024-06-05 9:09 ` Jeff King
2024-06-05 13:21 ` Phillip Wood
2024-06-08 5:54 ` Dragan Simic
2024-06-09 7:44 ` Rubén Justo
2024-06-09 7:57 ` Dragan Simic
2024-06-10 19:09 ` Rubén Justo
2024-06-10 21:02 ` Dragan Simic
2024-06-10 14:09 ` Phillip Wood
2024-06-10 16:13 ` Junio C Hamano
2024-06-10 19:14 ` Rubén Justo
2024-06-10 19:56 ` Junio C Hamano
2024-06-10 21:08 ` Dragan Simic
2024-06-10 19:28 ` Dragan Simic
2024-06-10 20:08 ` Junio C Hamano
2024-06-10 21:16 ` Dragan Simic
2024-06-09 14:29 ` phillip.wood123
2024-06-09 17:20 ` Dragan Simic
2024-06-10 8:27 ` Phillip Wood
2024-06-10 9:09 ` Dragan Simic
2024-06-05 17:24 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=xmqq4ja8ynop.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=dsimic@manjaro.org \
--cc=git@vger.kernel.org \
--cc=peff@peff.net \
--cc=rjusto@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).