git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v6 3/5] difftool: avoid returning -1 to cmd_main() from run_dir_diff()

From
David Aguilar <davvid@gmail.com>
Date
Sep 30, 2021, 17:01 UTC
Message-ID
<20210930170146.61489-3-davvid@gmail.com>
In-Reply-To
<20210930170146.61489-1-davvid@gmail.com>

difftool was forwarding the -1 result from error() to cmd_main(), which is implementation-defined since it is outside of the 0-255 range specified by POSIX for program exit codes.

Stop assigning the result of error() to `ret`. Assign a value of 1 whenever internal errors are detected instead.

Signed-off-by: David Aguilar <davvid@gmail.com>
---
This patch addresses the note from Ævar about returning -1 to cmd_main().
 builtin/difftool.c | 22 +++++++++++++---------
 1 file changed, 13 insertions(+), 9 deletions(-)
diff --git a/builtin/difftool.c b/builtin/difftool.c
index fdaaa86bff..e419bd3cd1 100644
--- a/builtin/difftool.c
+++ b/builtin/difftool.c
@@ -447,7 +447,8 @@ static int run_dir_diff(const char *extcmd, int symlinks, const char *prefix,
 
 		if (lmode && status != 'C') {
 			if (checkout_path(lmode, &loid, src_path, &lstate)) {
-				ret = error("could not write '%s'", src_path);
+				ret = 1;
+				error("could not write '%s'", src_path);
 				goto finish;
 			}
 		}
@@ -468,8 +469,8 @@ static int run_dir_diff(const char *extcmd, int symlinks, const char *prefix,
 			if (!use_wt_file(workdir, dst_path, &roid)) {
 				if (checkout_path(rmode, &roid, dst_path,
 						  &rstate)) {
-					ret = error("could not write '%s'",
-						    dst_path);
+					ret = 1;
+					error("could not write '%s'", dst_path);
 					goto finish;
 				}
 			} else if (!is_null_oid(&roid)) {
@@ -487,15 +488,16 @@ static int run_dir_diff(const char *extcmd, int symlinks, const char *prefix,
 
 				add_path(&rdir, rdir_len, dst_path);
 				if (ensure_leading_directories(rdir.buf)) {
-					ret = error("could not create "
-						    "directory for '%s'",
-						    dst_path);
+					ret = 1;
+					error("could not create directory for '%s'",
+						dst_path);
 					goto finish;
 				}
 				add_path(&wtdir, wtdir_len, dst_path);
 				if (symlinks) {
 					if (symlink(wtdir.buf, rdir.buf)) {
-						ret = error_errno("could not symlink '%s' to '%s'", wtdir.buf, rdir.buf);
+						ret = 1;
+						error_errno("could not symlink '%s' to '%s'", wtdir.buf, rdir.buf);
 						goto finish;
 					}
 				} else {
@@ -504,7 +506,8 @@ static int run_dir_diff(const char *extcmd, int symlinks, const char *prefix,
 						st.st_mode = 0644;
 					if (copy_file(rdir.buf, wtdir.buf,
 						      st.st_mode)) {
-						ret = error("could not copy '%s' to '%s'", wtdir.buf, rdir.buf);
+						ret = 1;
+						error("could not copy '%s' to '%s'", wtdir.buf, rdir.buf);
 						goto finish;
 					}
 				}
@@ -515,7 +518,8 @@ static int run_dir_diff(const char *extcmd, int symlinks, const char *prefix,
 	fclose(fp);
 	fp = NULL;
 	if (finish_command(child)) {
-		ret = error("error occurred running diff --raw");
+		ret = 1;
+		error("error occurred running diff --raw");
 		goto finish;
 	}
 
-- 
2.33.0.887.g8db6ae3373
Previous: David AguilarNext: Junio C Hamano
Message 3 of 11 in “difftool: create a tmpdir path without repeated slashes”
  1. 1/5 difftool: create a tmpdir path without repeated slashesDavid Aguilar, Sep 30, 2021
  2. 2/5 difftool: add a missing space to the run_dir_diff() commentsDavid Aguilar, Sep 30, 2021
  3. 3/5 difftool: avoid returning -1 to cmd_main() from run_dir_diff()David Aguilar, Sep 30, 2021
  4. Junio C HamanoSep 30, 2021
  5. David AguilarSep 30, 2021
  6. Junio C HamanoOct 1, 2021
  7. 4/5 difftool: refactor dir-diff to write files using a helper functionDavid Aguilar, Sep 30, 2021
  8. Junio C HamanoSep 30, 2021
  9. David AguilarSep 30, 2021
  10. 5/5 difftool: remove an unnecessary call to strbuf_release()David Aguilar, Sep 30, 2021
  11. Junio C HamanoSep 30, 2021

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.