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

Re: [PATCH] Don't ignore write failure from git-diff, git-log, etc.

From
Junio C Hamano <junkio@cox.net>
Date
May 28, 2007, 21:27 UTC
Message-ID
<7v1wh0bpv2.fsf@assigned-by-dhcp.cox.net>
In-Reply-To
<87sl9hw0o0.fsf@rho.meyering.net>
Jim Meyering <jim@meyering.net> writes:
Show 8 quoted lines
> Of course error messages are annoying when your short-pipe-read is
> _deliberate_ (tho, most real uses of git tools will actually get no
> message to be annoyed about[*]), but what if there really *is* a mistake?
> Try this:
>
>     # You want to force git to ignore the error.
>     $ trap '' PIPE; git-rev-list HEAD | sync
>     $

It is perfectly valid (although it is stupid) for a Porcelain script to do this:

    latest_by_jim=$(git log --pretty=oneline --author='Jim' | head -n 1)
    case "$latest_by_jim" in
    '') echo "No commit by Jim" ;;
    *)  # do something interesting on the commit
        ;;;
    esac

In such a case, it is a bit too much for my taste to force the script to redirect what comes out of fd 2 of the upstream of the pipe, so that it can filter out only the "write error" message but still show other kinds of error messages. You could do so by elaborate shell magic, perhaps like this:

        filter_pipe_error () {
                exec 3>&1
                (eval "$1" 2>&1 1>&3 | grep >&2 -v 'Broken pipe')
        }
	latest_by_jim=$(filter_pipe_error \
        	'git log --pretty=oneline --author='\''Jim'\'' | head -n 1'
	)
but what's the point?
I think something like this instead might be more palatable.
diff --git a/write_or_die.c b/write_or_die.c
index 5c4bc85..fadfcaa 100644
--- a/write_or_die.c
+++ b/write_or_die.c
@@ -41,8 +41,8 @@ int write_in_full(int fd, const void *buf, size_t count)
 void write_or_die(int fd, const void *buf, size_t count)
 {
 	if (write_in_full(fd, buf, count) < 0) {
-		if (errno == EPIPE)
-			exit(0);
- 		die("write error (%s)", strerror(errno));
+		if (errno != EPIPE)
+			die("write error (%s)", strerror(errno));
+		exit(1);
 	}
 }
Previous: Jim MeyeringNext: Linus Torvalds
Message 25 of 29 in “Don't ignore write failure from git-diff, git-log, etc.”
  1. Don't ignore write failure from git-diff, git-log, etc.Jim Meyering, May 26, 2007
  2. Linus TorvaldsMay 26, 2007
  3. Junio C HamanoMay 26, 2007
  4. Nicolas PitreMay 27, 2007
  5. Jim MeyeringMay 27, 2007
  6. Linus TorvaldsMay 27, 2007
  7. Jim MeyeringMay 28, 2007
  8. Marco RoelandMay 28, 2007
  9. Jim MeyeringMay 28, 2007
  10. Marco RoelandMay 28, 2007
  11. Jim MeyeringMay 28, 2007
  12. Petr BaudisMay 28, 2007
  13. Junio C HamanoMay 28, 2007
  14. Jim MeyeringMay 29, 2007
  15. Junio C HamanoMay 29, 2007
  16. Jim MeyeringMay 30, 2007
  17. Linus TorvaldsMay 28, 2007
  18. Jim MeyeringMay 28, 2007
  19. Linus TorvaldsMay 29, 2007
  20. Jim MeyeringMay 29, 2007
  21. Linus TorvaldsMay 29, 2007
  22. Jim MeyeringMay 30, 2007
  23. Linus TorvaldsMay 30, 2007
  24. Jim MeyeringMay 30, 2007
  25. Junio C HamanoMay 28, 2007
  26. Linus TorvaldsMay 29, 2007
  27. Jim MeyeringMay 30, 2007
  28. Junio C HamanoMay 30, 2007
  29. Jim MeyeringMay 30, 2007

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.