Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 9 Mar 2006 14:43:11 -0700
From:      "Jerry Nairn" <jpnairn@gmail.com>
To:        freebsd-cvsweb@freebsd.org
Subject:   full names and mail links in log view
Message-ID:  <3bccd73d0603091343m77a368a3jdf0ddc9e8ba44517@mail.gmail.com>

next in thread | raw e-mail | index | archive | help
I have modified our copy of cvsweb to replace cvs user name with the full
name and a mailto link in change log pages using the CVSROOT/users file use=
d
by cvs watch and the CVSROOT notify file. This is not in patch format
because I've made several other changes to our copy of cvsweb, and the
location of the functions is irrelevant. There is really only one changed
line.

<   print ' by <i>', htmlquote($author{$_}), "</i><br />\n";
---
>   print ' by <i>', userinfo($author{$_}), "</i><br />\n";

I added the hash %knownusers to the use vars statement, and this function
call in the View Files section:

##### get list of users #####
%knownusers =3D getuserinfo("${cvsroot}/users");

Then these functions are added at the end of the file:

#
# Read a cvsusers file to get full names and email addresses of
# authors we expect to see in the file logs.
#
sub getuserinfo
{
  my $userfile =3D shift;
  my %expansions;

  open (MAPFILE, "<$userfile") or die ("Unable to open $userfile ($!)");

  while (<MAPFILE>) {
    next if /^\s*#/;  # Skip comment lines.
    next if not /:/;  # Skip lines without colons.
    my ($username, $expansion) =3D split ':';
    chomp $expansion;
    $expansion =3D~ s/^'(.*)'$/$1/;
    $expansion =3D~ s/^"(.*)"$/$1/;

    # If it looks like the expansion has a real name already, then
    # we toss the username we got from CVS log.  Otherwise, keep
    # it to use in combination with the email address.
    if ($expansion =3D~ /^\s*<{0,1}\S+@.*/) {
      # Also, add angle brackets if none present
      if (! ($expansion =3D~ /<\S+@\S+>/)) {
        $expansions{$username} =3D "$username <$expansion>";
      }
      else {
        $expansions{$username} =3D "$username $expansion";
      }
    }
    else {
      $expansions{$username} =3D $expansion;
    }
  }
  close (MAPFILE);
  return %expansions;
}

#
# Given an author's name, see if we have info about the user from
# the cvsusers file.
# If so, use it to give full name and mailto link if possible.
#
sub userinfo
{
  my $username =3D shift;
  my $lcusername =3D lc($username);
  if ( exists $knownusers{$lcusername} ) {
    $knownusers{$lcusername} =3D~ /^(.*)\s{0,1}(<.*>)$/;
    my ($fullname, $mailaddress) =3D ($1, $2);
    return &link($fullname,
"mailto:'".$knownusers{$lcusername}."'<'".$knownusers{$lcusername}."'>
");
  } else {
    return $username;
  }
}

If you use this, you may want to make the regular expression for parsing th=
e
users file more robust. I just know it works with what I have in our file.
You may also want to turn this on or off via the config file, and have it
not die when there is no users file.

Jerry Nairn
Microchip Technology



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?3bccd73d0603091343m77a368a3jdf0ddc9e8ba44517>