git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Denton Liu <liu.denton@gmail.com>
To: Git Mailing List <git@vger.kernel.org>
Cc: Alban Gruin <alban.gruin@gmail.com>,
	Johannes Schindelin <johannes.schindelin@gmx.de>,
	Junio C Hamano <gitster@pobox.com>,
	Phillip Wood <phillip.wood123@gmail.com>
Subject: [PATCH v2 04/17] sequencer: configurably warn on non-existent files
Date: Tue, 24 Dec 2019 06:05:01 -0500	[thread overview]
Message-ID: <fd547aab491b24a47f683d717c6b77255ac16901.1577185374.git.liu.denton@gmail.com> (raw)
In-Reply-To: <cover.1577185374.git.liu.denton@gmail.com>

In the future, we plan on externing read_oneliner(). Future users of
read_oneliner() will want the ability to output warnings in the event
that the `path` doesn't exist. Introduce the `warn_nonexistence`
parameter which, if true, would issue a warning when a file doesn't
exist by skipping the `!file_exists()` check and letting
`strbuf_read_file()` handle that case.

Mechanically replace uses of read_oneliner() in sequencer.c with the
following spatch so that current behaviour is maintained:

	@@
	expression a, b, c;
	@@
	  read_oneliner(a, b, c
	+ , 0
	  )

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 sequencer.c | 32 ++++++++++++++++----------------
 1 file changed, 16 insertions(+), 16 deletions(-)

diff --git a/sequencer.c b/sequencer.c
index 5ba8b4383f..103cea1460 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -426,13 +426,13 @@ static int write_message(const void *buf, size_t len, const char *filename,
  *
  * Returns 1 if the file was read, 0 if it could not be read or does not exist.
  */
-static int read_oneliner(struct strbuf *buf,
-	const char *path, int skip_if_empty)
+static int read_oneliner(struct strbuf *buf, const char *path,
+			 int skip_if_empty, int warn_nonexistence)
 {
 	int ret = 0;
 	struct strbuf file_buf = STRBUF_INIT;
 
-	if (!file_exists(path))
+	if (!warn_nonexistence && !file_exists(path))
 		return 0;
 
 	if (strbuf_read_file(&file_buf, path, 0) < 0) {
@@ -2558,10 +2558,10 @@ void parse_strategy_opts(struct replay_opts *opts, char *raw_opts)
 static void read_strategy_opts(struct replay_opts *opts, struct strbuf *buf)
 {
 	strbuf_reset(buf);
-	if (!read_oneliner(buf, rebase_path_strategy(), 0))
+	if (!read_oneliner(buf, rebase_path_strategy(), 0, 0))
 		return;
 	opts->strategy = strbuf_detach(buf, NULL);
-	if (!read_oneliner(buf, rebase_path_strategy_opts(), 0))
+	if (!read_oneliner(buf, rebase_path_strategy_opts(), 0, 0))
 		return;
 
 	parse_strategy_opts(opts, buf->buf);
@@ -2572,7 +2572,7 @@ static int read_populate_opts(struct replay_opts *opts)
 	if (is_rebase_i(opts)) {
 		struct strbuf buf = STRBUF_INIT;
 
-		if (read_oneliner(&buf, rebase_path_gpg_sign_opt(), 1)) {
+		if (read_oneliner(&buf, rebase_path_gpg_sign_opt(), 1, 0)) {
 			if (!starts_with(buf.buf, "-S"))
 				strbuf_reset(&buf);
 			else {
@@ -2582,7 +2582,7 @@ static int read_populate_opts(struct replay_opts *opts)
 			strbuf_reset(&buf);
 		}
 
-		if (read_oneliner(&buf, rebase_path_allow_rerere_autoupdate(), 1)) {
+		if (read_oneliner(&buf, rebase_path_allow_rerere_autoupdate(), 1, 0)) {
 			if (!strcmp(buf.buf, "--rerere-autoupdate"))
 				opts->allow_rerere_auto = RERERE_AUTOUPDATE;
 			else if (!strcmp(buf.buf, "--no-rerere-autoupdate"))
@@ -2618,7 +2618,7 @@ static int read_populate_opts(struct replay_opts *opts)
 		strbuf_release(&buf);
 
 		if (read_oneliner(&opts->current_fixups,
-				  rebase_path_current_fixups(), 1)) {
+				  rebase_path_current_fixups(), 1, 0)) {
 			const char *p = opts->current_fixups.buf;
 			opts->current_fixup_count = 1;
 			while ((p = strchr(p, '\n'))) {
@@ -2627,7 +2627,7 @@ static int read_populate_opts(struct replay_opts *opts)
 			}
 		}
 
-		if (read_oneliner(&buf, rebase_path_squash_onto(), 0)) {
+		if (read_oneliner(&buf, rebase_path_squash_onto(), 0, 0)) {
 			if (get_oid_hex(buf.buf, &opts->squash_onto) < 0)
 				return error(_("unusable squash-onto"));
 			opts->have_squash_onto = 1;
@@ -3759,7 +3759,7 @@ static int apply_autostash(struct replay_opts *opts)
 	struct child_process child = CHILD_PROCESS_INIT;
 	int ret = 0;
 
-	if (!read_oneliner(&stash_sha1, rebase_path_autostash(), 1)) {
+	if (!read_oneliner(&stash_sha1, rebase_path_autostash(), 1, 0)) {
 		strbuf_release(&stash_sha1);
 		return 0;
 	}
@@ -4093,7 +4093,7 @@ static int pick_commits(struct repository *r,
 		if (todo_list->current < todo_list->nr)
 			return 0;
 
-		if (read_oneliner(&head_ref, rebase_path_head_name(), 0) &&
+		if (read_oneliner(&head_ref, rebase_path_head_name(), 0, 0) &&
 				starts_with(head_ref.buf, "refs/")) {
 			const char *msg;
 			struct object_id head, orig;
@@ -4106,13 +4106,13 @@ static int pick_commits(struct repository *r,
 				strbuf_release(&buf);
 				return res;
 			}
-			if (!read_oneliner(&buf, rebase_path_orig_head(), 0) ||
+			if (!read_oneliner(&buf, rebase_path_orig_head(), 0, 0) ||
 					get_oid_hex(buf.buf, &orig)) {
 				res = error(_("could not read orig-head"));
 				goto cleanup_head_ref;
 			}
 			strbuf_reset(&buf);
-			if (!read_oneliner(&buf, rebase_path_onto(), 0)) {
+			if (!read_oneliner(&buf, rebase_path_onto(), 0, 0)) {
 				res = error(_("could not read 'onto'"));
 				goto cleanup_head_ref;
 			}
@@ -4145,7 +4145,7 @@ static int pick_commits(struct repository *r,
 				DIFF_FORMAT_DIFFSTAT;
 			log_tree_opt.disable_stdin = 1;
 
-			if (read_oneliner(&buf, rebase_path_orig_head(), 0) &&
+			if (read_oneliner(&buf, rebase_path_orig_head(), 0, 0) &&
 			    !get_oid(buf.buf, &orig) &&
 			    !get_oid("HEAD", &head)) {
 				diff_tree_oid(&orig, &head, "",
@@ -4230,7 +4230,7 @@ static int commit_staged_changes(struct repository *r,
 
 		if (get_oid("HEAD", &head))
 			return error(_("cannot amend non-existing commit"));
-		if (!read_oneliner(&rev, rebase_path_amend(), 0))
+		if (!read_oneliner(&rev, rebase_path_amend(), 0, 0))
 			return error(_("invalid file: '%s'"), rebase_path_amend());
 		if (get_oid_hex(rev.buf, &to_amend))
 			return error(_("invalid contents: '%s'"),
@@ -4391,7 +4391,7 @@ int sequencer_continue(struct repository *r, struct replay_opts *opts)
 		struct strbuf buf = STRBUF_INIT;
 		struct object_id oid;
 
-		if (read_oneliner(&buf, rebase_path_stopped_sha(), 1) &&
+		if (read_oneliner(&buf, rebase_path_stopped_sha(), 1, 0) &&
 		    !get_oid_committish(buf.buf, &oid))
 			record_in_rewritten(&oid, peek_command(&todo_list, 0));
 		strbuf_release(&buf);
-- 
2.24.1.810.g65a2f617f4


  parent reply	other threads:[~2019-12-24 11:05 UTC|newest]

Thread overview: 152+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-16 17:26 [RFC PATCH 0/7] merge: learn --autostash Denton Liu
2019-10-16 17:26 ` [RFC PATCH 1/7] Makefile: alphabetically sort += lists Denton Liu
2019-10-17 18:07   ` Junio C Hamano
2019-10-21 18:44     ` Johannes Schindelin
2019-10-21 18:53       ` Denton Liu
2019-10-22 23:33         ` Johannes Schindelin
2019-10-21 19:49       ` Junio C Hamano
2019-10-21 19:54         ` Jeff King
2019-10-22 11:34           ` Junio C Hamano
2019-10-16 17:26 ` [RFC PATCH 2/7] autostash: extract read_one() from rebase Denton Liu
2019-10-18  9:04   ` Phillip Wood
2019-10-21 18:46     ` Johannes Schindelin
2019-10-16 17:26 ` [RFC PATCH 3/7] autostash: extract apply_autostash() " Denton Liu
2019-10-16 17:26 ` [RFC PATCH 4/7] autostash: extract reset_head() " Denton Liu
2019-10-18  9:37   ` Phillip Wood
2019-10-21 18:56     ` Johannes Schindelin
2019-10-16 17:26 ` [RFC PATCH 5/7] autostash: extract perform_autostash() " Denton Liu
2019-10-21 19:00   ` Johannes Schindelin
2019-10-16 17:26 ` [RFC PATCH 6/7] autostash.c: undefine USE_THE_INDEX_COMPATIBILITY_MACROS Denton Liu
2019-10-18  9:41   ` Phillip Wood
2019-10-16 17:26 ` [RFC PATCH 7/7] merge: teach --autostash option Denton Liu
2019-10-18  9:46   ` Phillip Wood
2019-12-24  9:58     ` Denton Liu
2019-10-21 19:10   ` Johannes Schindelin
2019-12-24 10:05     ` Denton Liu
2019-12-24 10:12       ` Denton Liu
2019-12-24 11:04 ` [PATCH v2 00/17] merge: learn --autostash Denton Liu
2019-12-24 11:04   ` [PATCH v2 01/17] Makefile: alphabetically sort += lists Denton Liu
2019-12-30 21:38     ` Junio C Hamano
2019-12-24 11:04   ` [PATCH v2 02/17] t7600: use test_write_lines() Denton Liu
2019-12-24 11:05   ` [PATCH v2 03/17] sequencer: use file strbuf for read_oneliner() Denton Liu
2019-12-24 11:05   ` Denton Liu [this message]
2019-12-26 20:39     ` [PATCH v2 04/17] sequencer: configurably warn on non-existent files Junio C Hamano
2019-12-24 11:05   ` [PATCH v2 05/17] sequencer: make read_oneliner() extern Denton Liu
2019-12-24 11:05   ` [PATCH v2 06/17] rebase: use read_oneliner() Denton Liu
2019-12-24 11:05   ` [PATCH v2 07/17] sequencer: make apply_rebase() accept a path Denton Liu
2019-12-24 11:05   ` [PATCH v2 08/17] rebase: use apply_autostash() from sequencer.c Denton Liu
2019-12-24 11:05   ` [PATCH v2 09/17] rebase: generify reset_head() Denton Liu
2019-12-24 11:05   ` [PATCH v2 10/17] reset: extract reset_head() from rebase Denton Liu
2019-12-24 11:05   ` [PATCH v2 11/17] rebase: extract create_autostash() Denton Liu
2019-12-24 11:05   ` [PATCH v2 12/17] rebase: generify create_autostash() Denton Liu
2019-12-24 11:05   ` [PATCH v2 13/17] sequencer: extract perform_autostash() from rebase Denton Liu
2019-12-24 11:05   ` [PATCH v2 14/17] sequencer: unlink autostash in apply_autostash() Denton Liu
2019-12-24 11:05   ` [PATCH v2 15/17] merge: teach --autostash option Denton Liu
2019-12-24 11:05   ` [PATCH v2 16/17] t5520: make test_pull_autostash() accept expect_parent_num Denton Liu
2019-12-24 11:05   ` [PATCH v2 17/17] pull: pass --autostash to merge Denton Liu
2019-12-30 21:49   ` [PATCH v2 00/17] merge: learn --autostash Junio C Hamano
2019-12-31 10:34     ` Phillip Wood
2020-01-08  6:08       ` Denton Liu
2020-01-10 14:44         ` Phillip Wood
2020-01-15 16:20           ` Denton Liu
2020-01-01  7:48     ` Denton Liu
2020-03-21  9:21   ` [PATCH v3 00/19] " Denton Liu
2020-03-21  9:21     ` [PATCH v3 01/19] Makefile: ASCII-sort += lists Denton Liu
2020-03-21  9:21     ` [PATCH v3 02/19] t7600: use test_write_lines() Denton Liu
2020-03-21  9:21     ` [PATCH v3 03/19] sequencer: use file strbuf for read_oneliner() Denton Liu
2020-04-02 13:34       ` Phillip Wood
2020-03-21  9:21     ` [PATCH v3 04/19] sequencer: make read_oneliner() accept flags Denton Liu
2020-03-21  9:21     ` [PATCH v3 05/19] sequencer: configurably warn on non-existent files Denton Liu
2020-04-02 13:39       ` Phillip Wood
2020-03-21  9:21     ` [PATCH v3 06/19] sequencer: make read_oneliner() extern Denton Liu
2020-03-21  9:21     ` [PATCH v3 07/19] rebase: use read_oneliner() Denton Liu
2020-04-02 13:41       ` Phillip Wood
2020-03-21  9:21     ` [PATCH v3 08/19] sequencer: make apply_rebase() accept a path Denton Liu
2020-03-21  9:21     ` [PATCH v3 09/19] rebase: use apply_autostash() from sequencer.c Denton Liu
2020-04-02 14:59       ` Phillip Wood
2020-03-21  9:21     ` [PATCH v3 10/19] rebase: generify reset_head() Denton Liu
2020-03-21  9:21     ` [PATCH v3 11/19] reset: extract reset_head() from rebase Denton Liu
2020-04-02 15:04       ` Phillip Wood
2020-03-21  9:21     ` [PATCH v3 12/19] rebase: extract create_autostash() Denton Liu
2020-03-21  9:21     ` [PATCH v3 13/19] rebase: generify create_autostash() Denton Liu
2020-03-21  9:21     ` [PATCH v3 14/19] sequencer: extract perform_autostash() from rebase Denton Liu
2020-03-21  9:21     ` [PATCH v3 15/19] sequencer: unlink autostash in apply_autostash() Denton Liu
2020-03-21  9:21     ` [PATCH v3 16/19] sequencer: implement save_autostash() Denton Liu
2020-04-02 15:10       ` Phillip Wood
2020-03-21  9:21     ` [PATCH v3 17/19] merge: teach --autostash option Denton Liu
2020-04-02 15:24       ` Phillip Wood
2020-04-03 10:31         ` Denton Liu
2020-04-03 10:56           ` Denton Liu
2020-04-03 13:09             ` Phillip Wood
2020-04-03 21:14               ` Denton Liu
2020-04-03 13:34           ` Phillip Wood
2020-04-03 22:25             ` Denton Liu
2020-03-21  9:21     ` [PATCH v3 18/19] t5520: make test_pull_autostash() accept expect_parent_num Denton Liu
2020-03-21  9:21     ` [PATCH v3 19/19] pull: pass --autostash to merge Denton Liu
2020-04-02 16:07       ` Phillip Wood
2020-04-04  1:11     ` [PATCH v4 00/23] merge: learn --autostash Denton Liu
2020-04-04  1:11       ` [PATCH v4 01/23] Makefile: ASCII-sort += lists Denton Liu
2020-04-04  1:11       ` [PATCH v4 02/23] t7600: use test_write_lines() Denton Liu
2020-04-04  1:11       ` [PATCH v4 03/23] sequencer: stop leaking buf Denton Liu
2020-04-05 21:33         ` Junio C Hamano
2020-04-05 21:37           ` Junio C Hamano
2020-04-05 23:42           ` Denton Liu
2020-04-04  1:11       ` [PATCH v4 04/23] sequencer: reuse strbuf_trim() in read_oneliner() Denton Liu
2020-04-05 21:46         ` Junio C Hamano
2020-04-06  1:39           ` Denton Liu
2020-04-06 14:03         ` Phillip Wood
2020-04-06 14:42           ` Phillip Wood
2020-04-07 13:56             ` Denton Liu
2020-04-04  1:11       ` [PATCH v4 05/23] sequencer: make file exists check more efficient Denton Liu
2020-04-04  1:11       ` [PATCH v4 06/23] sequencer: make read_oneliner() accept flags Denton Liu
2020-04-04  1:11       ` [PATCH v4 07/23] sequencer: configurably warn on non-existent files Denton Liu
2020-04-06 14:45         ` Phillip Wood
2020-04-04  1:11       ` [PATCH v4 08/23] sequencer: make read_oneliner() extern Denton Liu
2020-04-04  1:11       ` [PATCH v4 09/23] rebase: use read_oneliner() Denton Liu
2020-04-04  1:11       ` [PATCH v4 10/23] sequencer: make apply_rebase() accept a path Denton Liu
2020-04-06 15:07         ` Phillip Wood
2020-04-04  1:11       ` [PATCH v4 11/23] sequencer: rename stash_sha1 to stash_oid Denton Liu
2020-04-04  1:11       ` [PATCH v4 12/23] rebase: use apply_autostash() from sequencer.c Denton Liu
2020-04-04  1:11       ` [PATCH v4 13/23] rebase: generify reset_head() Denton Liu
2020-04-04  1:11       ` [PATCH v4 14/23] reset: extract reset_head() from rebase Denton Liu
2020-04-04  1:11       ` [PATCH v4 15/23] rebase: extract create_autostash() Denton Liu
2020-04-04  1:11       ` [PATCH v4 16/23] rebase: generify create_autostash() Denton Liu
2020-04-04  1:11       ` [PATCH v4 17/23] sequencer: extract perform_autostash() from rebase Denton Liu
2020-04-04  1:11       ` [PATCH v4 18/23] sequencer: unlink autostash in apply_autostash() Denton Liu
2020-04-04  1:11       ` [PATCH v4 19/23] sequencer: implement save_autostash() Denton Liu
2020-04-06 15:15         ` Phillip Wood
2020-04-04  1:11       ` [PATCH v4 20/23] sequencer: implement apply_autostash_oid() Denton Liu
2020-04-04  1:11       ` [PATCH v4 21/23] merge: teach --autostash option Denton Liu
2020-04-06 15:20         ` Phillip Wood
2020-04-07 13:09           ` Denton Liu
2020-04-07 15:06             ` Phillip Wood
2020-04-04  1:11       ` [PATCH v4 22/23] t5520: make test_pull_autostash() accept expect_parent_num Denton Liu
2020-04-04  1:11       ` [PATCH v4 23/23] pull: pass --autostash to merge Denton Liu
2020-04-07 14:27       ` [PATCH v5 00/22] merge: learn --autostash Denton Liu
2020-04-07 14:27         ` [PATCH v5 01/22] Makefile: ASCII-sort += lists Denton Liu
2020-04-07 14:27         ` [PATCH v5 02/22] t7600: use test_write_lines() Denton Liu
2020-04-07 14:27         ` [PATCH v5 03/22] sequencer: stop leaking buf Denton Liu
2020-04-07 14:27         ` [PATCH v5 04/22] sequencer: make file exists check more efficient Denton Liu
2020-04-08  0:10           ` Junio C Hamano
2020-04-07 14:27         ` [PATCH v5 05/22] sequencer: make read_oneliner() accept flags Denton Liu
2020-04-08  0:11           ` Junio C Hamano
2020-04-07 14:27         ` [PATCH v5 06/22] sequencer: configurably warn on non-existent files Denton Liu
2020-04-07 14:27         ` [PATCH v5 07/22] sequencer: make read_oneliner() extern Denton Liu
2020-04-07 14:27         ` [PATCH v5 08/22] rebase: use read_oneliner() Denton Liu
2020-04-08  0:26           ` Junio C Hamano
2020-04-07 14:27         ` [PATCH v5 09/22] sequencer: make apply_autostash() accept a path Denton Liu
2020-04-07 14:27         ` [PATCH v5 10/22] sequencer: rename stash_sha1 to stash_oid Denton Liu
2020-04-07 14:27         ` [PATCH v5 11/22] rebase: use apply_autostash() from sequencer.c Denton Liu
2020-04-07 14:27         ` [PATCH v5 12/22] rebase: generify reset_head() Denton Liu
2020-04-07 14:28         ` [PATCH v5 13/22] reset: extract reset_head() from rebase Denton Liu
2020-04-07 14:28         ` [PATCH v5 14/22] rebase: extract create_autostash() Denton Liu
2020-04-07 14:28         ` [PATCH v5 15/22] rebase: generify create_autostash() Denton Liu
2020-04-07 14:28         ` [PATCH v5 16/22] sequencer: extract perform_autostash() from rebase Denton Liu
2020-04-07 14:28         ` [PATCH v5 17/22] sequencer: unlink autostash in apply_autostash() Denton Liu
2020-04-07 14:28         ` [PATCH v5 18/22] sequencer: implement save_autostash() Denton Liu
2020-04-07 14:28         ` [PATCH v5 19/22] sequencer: implement apply_autostash_oid() Denton Liu
2020-04-07 14:28         ` [PATCH v5 20/22] merge: teach --autostash option Denton Liu
2020-04-07 14:28         ` [PATCH v5 21/22] t5520: make test_pull_autostash() accept expect_parent_num Denton Liu
2020-04-07 14:28         ` [PATCH v5 22/22] pull: pass --autostash to merge Denton Liu
2020-04-10 15:34         ` [PATCH v5 00/22] merge: learn --autostash Phillip Wood
2020-04-10 16:26           ` 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

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=fd547aab491b24a47f683d717c6b77255ac16901.1577185374.git.liu.denton@gmail.com \
    --to=liu.denton@gmail.com \
    --cc=alban.gruin@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=johannes.schindelin@gmx.de \
    --cc=phillip.wood123@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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).