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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Jim Meyering <jim@xxxxxxxxxxxx> writes:

> 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);
 	}
 }

-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux