]> Sergey Matveev's repositories - public-inbox.git/commitdiff
lei_store: use getpwuid and hostname for ident
authorEric Wong <e@80x24.org>
Mon, 5 Apr 2021 20:38:13 +0000 (20:38 +0000)
committerEric Wong <e@80x24.org>
Wed, 7 Apr 2021 07:14:33 +0000 (07:14 +0000)
It's nicer in case a user transfers lei/store across machines
and wants a way to track when/where they imported something.

lib/PublicInbox/LeiStore.pm

index 094e1555a3fcafe8b92d03c8c1b2f15b391d105e..f8371abfcb69b347abd6fd525abcf92bfdc30d78 100644 (file)
@@ -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 {