]> arthur.barton.de Git - bup.git/commitdiff
Fallbacks for missing GECOS data; this solves a test issue.
authorMichael Witten <mfwitten@gmail.com>
Mon, 18 Jun 2012 06:06:36 +0000 (06:06 +0000)
committerRob Browning <rlb@defaultvalue.org>
Sat, 22 Sep 2012 21:19:39 +0000 (16:19 -0500)
See the thread starting here:

  Subject: tests fail while trying to compile & install on arch linux
  Date: Sun, 20 May 2012 23:08:20 +0300
  From: Alper Kanat <tunix@raptiye.org>
  Message-ID: <CAPMuxnSmeHLcP=9M7uYPn6LQeCGNfZOF9DgCFQBHCzwR_DQ0Cg@mail.gmail.com>

When an entry for the current user has been successfully retrieved from the
Unix password database by the function:

  bup.helpers.usersfullname

then solely the GECOS field has been used to formulate an author's and
committer's full name for constructing a git commit object. Unfortunately,
this field may well be empty for a great many users; for such a user, the
result has been a full name that is the empty string.

This had not been a problem until the following commit was made in the course
of the development of `git' itself:

  commit 4b340cfab9c7a18e39bc531d6a6ffaffdf95f62d
  Author:     Junio C Hamano <gitster@pobox.com>
  AuthorDate: Sun Mar 11 01:25:43 2012 -0800
  Commit:     Junio C Hamano <gitster@pobox.com>
  CommitDate: Sun Mar 11 03:56:50 2012 -0700

      ident.c: add split_ident_line() to parse formatted ident line

      The commit formatting logic format_person_part() in pretty.c
      implements the logic to split an author/committer ident line into
      its parts, intermixed with logic to compute its output using these
      piece it computes.

      Separate the former out to a helper function split_ident_line() so
      that other codepath can use the same logic, and rewrite the function
      using the helper function.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
The new `split_ident_line()' function added by that commit is written
under the stricter assumption that the user's name is *not* the empty
string; clearly, this assumption is broken by what `bup' has been doing
when the user's GECOS field is empty.

Consequently, the easiest solution (as far as `bup' development is
concerned) is to make sure that the full name is never the empty
string. This is achieved by using fallbacks when the GECOS field
yields the empty string:

  0. The user's login name is tried.
  1. The string "user <uid>" is composed, where `<uid>' is the
     current process's user identifier.

Essentially, this seems to solve the problem, as it allows tests to
pass on my system. However, both:

  bup.helpers.username
  bup.helpers.usersfullname

still rely on Unix-specific functionality, which is not really acceptable.

Signed-off-by: Michael Witten <mfwitten@gmail.com>
Reviewed-by: Gabriel Filion <lelutin@gmail.com>
Tested-by: Zoran Zaric <zz@zoranzaric.de>
lib/bup/helpers.py

index d9d177cabf30931a14e074e828204c2b7ed13999..3e6f6d2c149dde67e138e5c828523307188594ef 100644 (file)
@@ -231,9 +231,13 @@ def userfullname():
     if not _userfullname:
         uid = os.getuid()
         try:
-            _userfullname = pwd.getpwuid(uid)[4].split(',')[0]
+            entry = pwd.getpwuid(uid)
+            _userfullname = entry[4].split(',')[0] or entry[0]
         except KeyError:
-            _userfullname = 'user%d' % uid
+            pass
+        finally:
+            if not _userfullname:
+              _userfullname = 'user %d' % uid
     return _userfullname