[v2] git-svn: trim leading and trailing whitespaces in author name
diff mbox series

Message ID 20190912145638.32192-1-tklauser@distanz.ch
State New
Headers show
Series
  • [v2] git-svn: trim leading and trailing whitespaces in author name
Related show

Commit Message

Tobias Klauser Sept. 12, 2019, 2:56 p.m. UTC
In some cases, the svn author names might contain leading or trailing
whitespaces, leading to messages such as:

  Author: user1
   not defined in authors.txt

(the trailing newline leads to the line break). The user "user1" is
defined in authors.txt though, e.g.

  user1 = User <user1@example.com>

Fix this by trimming the author name retreived from svn before using it
in check_author.

Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
---
v2:
 - move whitespace trimming below defined'ness check as per Eric Sunshine's
   review comment

 perl/Git/SVN.pm | 1 +
 1 file changed, 1 insertion(+)

Comments

Eric Sunshine Sept. 12, 2019, 6:20 p.m. UTC | #1
On Thu, Sep 12, 2019 at 10:56 AM Tobias Klauser <tklauser@distanz.ch> wrote:
> v2:
>  - move whitespace trimming below defined'ness check as per Eric Sunshine's
>    review comment
> diff --git a/perl/Git/SVN.pm b/perl/Git/SVN.pm
> @@ -1494,6 +1494,7 @@ sub check_author {
>         if (!defined $author || length $author == 0) {
>                 $author = '(no author)';
>         }
> +       $author =~ s/^\s+|\s+$//g;

Hmm, this still looks questionable. I would have expected the
whitespace trimming to be below the 'defined' check but before the
length($author)==0 check (since the length might become 0 once
whitespace is trimmed).

Also, a minor style/comprehension nit: Perhaps I'm just old-school,
but for me, the idiom:

    $author =~ s/^\s+//;
    $author =~ s/\s+$//;

is easier to understand at-a-glance as trimming leading and trailing
whitespace than the more compact (noisy) expression this patch uses.
But that's just a subjective review comment, not necessarily
actionable.
Tobias Klauser Sept. 13, 2019, 7:47 a.m. UTC | #2
Thank you for the review Eric!

On 2019-09-12 at 20:20:11 +0200, Eric Sunshine <sunshine@sunshineco.com> wrote:
> On Thu, Sep 12, 2019 at 10:56 AM Tobias Klauser <tklauser@distanz.ch> wrote:
> > v2:
> >  - move whitespace trimming below defined'ness check as per Eric Sunshine's
> >    review comment
> > diff --git a/perl/Git/SVN.pm b/perl/Git/SVN.pm
> > @@ -1494,6 +1494,7 @@ sub check_author {
> >         if (!defined $author || length $author == 0) {
> >                 $author = '(no author)';
> >         }
> > +       $author =~ s/^\s+|\s+$//g;
> 
> Hmm, this still looks questionable. I would have expected the
> whitespace trimming to be below the 'defined' check but before the
> length($author)==0 check (since the length might become 0 once
> whitespace is trimmed).

Agree, I didn't consider this case. Will change in v3.

> Also, a minor style/comprehension nit: Perhaps I'm just old-school,
> but for me, the idiom:
> 
>     $author =~ s/^\s+//;
>     $author =~ s/\s+$//;
> 
> is easier to understand at-a-glance as trimming leading and trailing
> whitespace than the more compact (noisy) expression this patch uses.
> But that's just a subjective review comment, not necessarily
> actionable.

Agree, the form you propose is more readable and saving just a line
doesn't seem worth the possible impact on comprehension/readability.
Will change in v3.

Patch
diff mbox series

diff --git a/perl/Git/SVN.pm b/perl/Git/SVN.pm
index 76b29659057d..d8c07419f51c 100644
--- a/perl/Git/SVN.pm
+++ b/perl/Git/SVN.pm
@@ -1494,6 +1494,7 @@  sub check_author {
 	if (!defined $author || length $author == 0) {
 		$author = '(no author)';
 	}
+	$author =~ s/^\s+|\s+$//g;
 	if (!defined $::users{$author}) {
 		if (defined $::_authors_prog) {
 			$::users{$author} = call_authors_prog($author);