From: Eric Wong Date: Mon, 5 Apr 2021 20:38:13 +0000 (+0000) Subject: lei_store: use getpwuid and hostname for ident X-Git-Tag: v1.7.0~818 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=86c2ebf085cc9897bafcb95b82890f2645f515e5;p=public-inbox.git lei_store: use getpwuid and hostname for ident It's nicer in case a user transfers lei/store across machines and wants a way to track when/where they imported something. --- diff --git a/lib/PublicInbox/LeiStore.pm b/lib/PublicInbox/LeiStore.pm index 094e1555..f8371abf 100644 --- a/lib/PublicInbox/LeiStore.pm +++ b/lib/PublicInbox/LeiStore.pm @@ -63,8 +63,16 @@ sub git_ident ($) { my $rdr = {}; open $rdr->{2}, '>', '/dev/null' or die "open /dev/null: $!"; chomp(my $i = $git->qx([qw(var GIT_COMMITTER_IDENT)], undef, $rdr)); - $i =~ /\A(.+) <([^>]+)> [0-9]+ [-\+]?[0-9]+$/ ? ($1, $2) : - ('lei user', 'x@example.com') + $i =~ /\A(.+) <([^>]+)> [0-9]+ [-\+]?[0-9]+$/ and return ($1, $2); + my ($user, undef, undef, undef, undef, undef, $gecos) = getpwuid($<); + ($user) = (($user // $ENV{USER} // '') =~ /([\w\-\.\+]+)/); + $user //= 'lei-user'; + ($gecos) = (($gecos // '') =~ /([\w\-\.\+ \t]+)/); + $gecos //= 'lei user'; + require Sys::Hostname; + my ($host) = (Sys::Hostname::hostname() =~ /([\w\-\.]+)/); + $host //= 'localhost'; + ($gecos, "$user\@$host") } sub importer {