subversion-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From danie...@apache.org
Subject svn commit: r1606354 - /subversion/trunk/tools/dist/backport.pl
Date Sat, 28 Jun 2014 13:43:01 GMT
Author: danielsh
Date: Sat Jun 28 13:43:01 2014
New Revision: 1606354

URL: http://svn.apache.org/r1606354
Log:
backport.pl interactive mode: Fix a bug when $AVAILID ended up being undef.

* tools/dist/backport.pl
  ($AVAILID): When failing to initialize this, make the warning more prominent
    and start requesting permission to continue.
  (nominate_usage): Tolerate $AVAILID being undef.
  (warned_cannot_commit): New helper.
  (vote, nominate_main, handle_entry): Verify that $AVAILID is defined where
    needed.  When it is undefined, warn or bail.

Modified:
    subversion/trunk/tools/dist/backport.pl

Modified: subversion/trunk/tools/dist/backport.pl
URL: http://svn.apache.org/viewvc/subversion/trunk/tools/dist/backport.pl?rev=1606354&r1=1606353&r2=1606354&view=diff
==============================================================================
--- subversion/trunk/tools/dist/backport.pl (original)
+++ subversion/trunk/tools/dist/backport.pl Sat Jun 28 13:43:01 2014
@@ -73,8 +73,20 @@ my ($AVAILID) = $ENV{AVAILID} // do {
   my $filename = Digest->new("MD5")->add($SVN_A_O_REALM)->hexdigest;
   `cat $ENV{HOME}/.subversion/auth/svn.simple/$filename`
   =~ /K 8\nusername\nV \d+\n(.*)/ and $1 or undef
+};
+
+unless (defined $AVAILID) {
+  unless ($MODE == Mode::Conflicts) {
+    warn "Username for commits (of votes/merges) not found; "
+         ."it will be possible to review nominations but not to commit votes "
+         ."or merges.\n";
+    warn "Press the 'any' key to continue...\n";
+    die if $MODE == Mode::AutoCommitApproveds; # unattended mode; can't prompt.
+    ReadMode 'cbreak';
+    ReadKey 0;
+    ReadMode 'restore';
+  }
 }
-// warn "Username for commits (of votes/merges) not found";
 
 ############## End of reading values from the environment ##############
 
@@ -176,6 +188,7 @@ EOF
 }
 
 sub nominate_usage {
+  my $availid = $AVAILID // "(your username)";
   my $basename = basename $0;
   print <<EOF;
 nominate.pl: a tool for adding entries to STATUS.
@@ -188,7 +201,7 @@ Will add:
    Justification:
      \$Some_justification
    Votes:
-     +1: $AVAILID
+     +1: $availid
 to STATUS.  Backport branches are detected automatically.
 
 The STATUS file in the current directory is used (unless argv[0] is "n", in
@@ -202,6 +215,18 @@ EOF
 # TODO: Do a dry-run merge on interactively-edited entries in backport.pl
 }
 
+# If $AVAILID is undefined, warn about it and return true.
+# Else return false.
+#
+# $_[0] is a string for inclusion in generated error messages.
+sub warned_cannot_commit {
+  my $caller_error_string = shift;
+  return 0 if defined $AVAILID;
+
+  warn "$0: $caller_error_string: unable to determine your username via \$AVAILID or svnauth(1)
or ~/.subversion/auth/";
+  return 1;
+}
+
 sub digest_string {
   Digest->new("MD5")->add(@_)->hexdigest
 }
@@ -549,6 +574,11 @@ sub vote {
   my @votesarray;
   return unless %$approved or %$votes;
 
+  # If $AVAILID is undef, we can only process 'edit' pseudovotes; handle_entry() is
+  # supposed to prevent numeric (±1,±0) votes from getting to this point.
+  die "Assertion failed" if not defined $AVAILID
+                            and grep { $_ ne 'edit' } map { $_->[0] } values %$votes;
+
   my $had_empty_line;
 
   $. = 0;
@@ -913,11 +943,14 @@ sub handle_entry {
         next PROMPT;
       }
       when (/^([+-][01])\s*$/i) {
+        next QUESTION if warned_cannot_commit "Entering a vote failed";
         $votes->{$key} = [$1, \%entry];
         say "Your '$1' vote has been recorded." if $VERBOSE;
         last PROMPT;
       }
       when (/^e/i) {
+        prompt "Press the 'any' key to continue...\n"
+            if warned_cannot_commit "Committing this edit later on may fail";
         my $original = $entry{raw};
         $entry{raw} = edit_string $entry{raw}, $entry{header},
                         trailing_eol => 2;
@@ -1039,6 +1072,8 @@ sub nominate_main {
   my (@revnums) = (+shift) =~ /(\d+)/g;
   my $justification = shift;
 
+  die "Unable to proceed." if warned_cannot_commit "Nominating failed";
+
   @revnums = sort { $a <=> $b } keys %{{ map { $_ => 1 } @revnums }};
   die "No revision numbers specified" unless @revnums;
 



Mime
View raw message