ident: report passwd errors with a more friendly message
commit2f70587502b6b5a8cfda5a3eff54392f48e2db8d
authorJeff King <peff@peff.net>
Mon, 21 May 2012 23:10:20 +0000 (21 19:10 -0400)
committerJunio C Hamano <gitster@pobox.com>
Tue, 22 May 2012 16:08:20 +0000 (22 09:08 -0700)
tree444e6b44d4b083958ba642b9217dacecb32ef382
parent8587ead78ad3d2af760270b21035ffe48fde3e7b
ident: report passwd errors with a more friendly message

When getpwuid fails, we give a cute but cryptic message.
While it makes sense if you know that getpwuid or identity
functions are being called, this code is triggered behind
the scenes by quite a few git commands these days (e.g.,
receive-pack on a remote server might use it for a reflog;
the current message is hard to distinguish from an
authentication error).  Let's switch to something that gives
a little more context.

While we're at it, we can factor out all of the
cut-and-pastes of the "you don't exist" message into a
wrapper function. Rather than provide xgetpwuid, let's make
it even more specific to just getting the passwd entry for
the current uid. That's the only way we use getpwuid anyway,
and it lets us make an even more specific error message.

The current message also fails to mention errno. While the
usual cause for getpwuid failing is that the user does not
exist, mentioning errno makes it easier to diagnose these
problems.  Note that POSIX specifies that errno remain
untouched if the passwd entry does not exist (but will be
set on actual errors), whereas some systems will return
ENOENT or similar for a missing entry. We handle both cases
in our wrapper.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Documentation/git-commit-tree.txt
Documentation/git-var.txt
git-compat-util.h
ident.c
wrapper.c