Changeset 84114 in webkit


Ignore:
Timestamp:
Apr 17, 2011 4:27:46 PM (13 years ago)
Author:
dbates@webkit.org
Message:

2011-04-17 Daniel Bates <dbates@webkit.com>

Reviewed by Eric Seidel.

webkit-patch land hangs if svn prompts for credentials
https://bugs.webkit.org/show_bug.cgi?id=31500

Prompt for username and password when using git-svn and there aren't cached SVN credentials.

  • Scripts/webkitpy/common/checkout/scm.py:
    • Added mixin class SVNRepository and made both class SVN and Git inherit from it.
    • Moved SVN.has_authorization_for_realm() to class SVNRepository and removed default value for argument realm; modified call sites as needed.
    • Modified AuthenticationError constructor to take optional prompt_for_password argument.
    • Modified {SCM, SVN, Git}.commit_with_message() to take optional password argument.
    • Modified Git._commit_on_branch() to take optional username and password argument.
    • Modified Git.push_local_commits_to_server() to take optional username and password argument and to call has_authorization_for_realm().
  • Scripts/webkitpy/common/checkout/scm_unittest.py:
    • Modified SVNTest.test_commit_without_authorization() to take dummy realm argument.
    • Modified SVNTest.test_not_have_authorization_for_realm() to pass realm argument to SVN.has_authorization_for_realm().
  • Scripts/webkitpy/common/net/credentials.py:
    • Modified Credentials.read_credentials() to call User.prompt_password() instead of using getpass.getpass() directly.
  • Scripts/webkitpy/common/system/user.py:
    • Added User.prompt_password().
  • Scripts/webkitpy/tool/steps/commit.py:
    • Modified Commit.run() to prompt for a password if needed.
Location:
trunk/Tools
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Tools/ChangeLog

    r84112 r84114  
     12011-04-17  Daniel Bates  <dbates@webkit.com>
     2
     3        Reviewed by Eric Seidel.
     4
     5        webkit-patch land hangs if svn prompts for credentials
     6        https://bugs.webkit.org/show_bug.cgi?id=31500
     7
     8        Prompt for username and password when using git-svn and there aren't cached SVN credentials.
     9
     10        * Scripts/webkitpy/common/checkout/scm.py:
     11          - Added mixin class SVNRepository and made both class SVN and Git inherit from it.
     12          - Moved SVN.has_authorization_for_realm() to class SVNRepository and removed default value
     13            for argument realm; modified call sites as needed.
     14          - Modified AuthenticationError constructor to take optional prompt_for_password argument.
     15          - Modified {SCM, SVN, Git}.commit_with_message() to take optional password argument.
     16          - Modified Git._commit_on_branch() to take optional username and password argument.
     17          - Modified Git.push_local_commits_to_server() to take optional username and password
     18            argument and to call has_authorization_for_realm().
     19        * Scripts/webkitpy/common/checkout/scm_unittest.py:
     20          - Modified SVNTest.test_commit_without_authorization() to take dummy realm argument.
     21          - Modified SVNTest.test_not_have_authorization_for_realm() to pass realm argument to
     22            SVN.has_authorization_for_realm().
     23        * Scripts/webkitpy/common/net/credentials.py:
     24          - Modified Credentials.read_credentials() to call User.prompt_password() instead
     25            of using getpass.getpass() directly.
     26        * Scripts/webkitpy/common/system/user.py:
     27          - Added User.prompt_password().
     28        * Scripts/webkitpy/tool/steps/commit.py:
     29          - Modified Commit.run() to prompt for a password if needed.
     30
    1312011-04-17  Dirk Pranke  <dpranke@chromium.org>
    232
  • trunk/Tools/Scripts/webkitpy/common/checkout/scm.py

    r83614 r84114  
    135135
    136136class AuthenticationError(Exception):
    137     def __init__(self, server_host):
     137    def __init__(self, server_host, prompt_for_password=False):
    138138        self.server_host = server_host
     139        self.prompt_for_password = prompt_for_password
    139140
    140141
     
    292293        self._subclass_must_implement()
    293294
    294     def commit_with_message(self, message, username=None, git_commit=None, force_squash=False, changed_files=None):
     295    def commit_with_message(self, message, username=None, password=None, git_commit=None, force_squash=False, changed_files=None):
    295296        self._subclass_must_implement()
    296297
     
    320321
    321322
    322 class SVN(SCM):
     323# A mixin class that represents common functionality for SVN and Git-SVN.
     324class SVNRepository:
     325    def has_authorization_for_realm(self, realm, home_directory=os.getenv("HOME")):
     326        # Assumes find and grep are installed.
     327        if not os.path.isdir(os.path.join(home_directory, ".subversion")):
     328            return False
     329        find_args = ["find", ".subversion", "-type", "f", "-exec", "grep", "-q", realm, "{}", ";", "-print"]
     330        find_output = self.run(find_args, cwd=home_directory, error_handler=Executive.ignore_error).rstrip()
     331        return find_output and os.path.isfile(os.path.join(home_directory, find_output))
     332
     333
     334class SVN(SCM, SVNRepository):
    323335    # FIXME: These belong in common.config.urls
    324336    svn_server_host = "svn.webkit.org"
     
    374386    def commit_success_regexp():
    375387        return "^Committed revision (?P<svn_revision>\d+)\.$"
    376 
    377     def has_authorization_for_realm(self, realm=svn_server_realm, home_directory=os.getenv("HOME")):
    378         # Assumes find and grep are installed.
    379         if not os.path.isdir(os.path.join(home_directory, ".subversion")):
    380             return False
    381         find_args = ["find", ".subversion", "-type", "f", "-exec", "grep", "-q", realm, "{}", ";", "-print"];
    382         find_output = self.run(find_args, cwd=home_directory, error_handler=Executive.ignore_error).rstrip()
    383         return find_output and os.path.isfile(os.path.join(home_directory, find_output))
    384388
    385389    @memoized
     
    557561        self.run(['svn', 'revert'] + file_paths)
    558562
    559     def commit_with_message(self, message, username=None, git_commit=None, force_squash=False, changed_files=None):
     563    def commit_with_message(self, message, username=None, password=None, git_commit=None, force_squash=False, changed_files=None):
    560564        # git-commit and force are not used by SVN.
    561565        svn_commit_args = ["svn", "commit"]
    562566
    563         if not username and not self.has_authorization_for_realm():
     567        if not username and not self.has_authorization_for_realm(self.svn_server_realm):
    564568            raise AuthenticationError(self.svn_server_host)
    565569        if username:
     
    599603
    600604# All git-specific logic should go here.
    601 class Git(SCM):
     605class Git(SCM, SVNRepository):
    602606    def __init__(self, cwd, executive=None):
    603607        SCM.__init__(self, cwd, executive)
     
    834838                raise AmbiguousCommitError(num_local_commits, working_directory_is_clean)
    835839
    836     def commit_with_message(self, message, username=None, git_commit=None, force_squash=False, changed_files=None):
     840    def commit_with_message(self, message, username=None, password=None, git_commit=None, force_squash=False, changed_files=None):
    837841        # Username is ignored during Git commits.
    838842        working_directory_is_clean = self.working_directory_is_clean()
     
    844848                    raise ScriptError(message="The working copy is not modified. --git-commit=HEAD.. only commits working copy changes.")
    845849                self.commit_locally_with_message(message)
    846                 return self._commit_on_branch(message, 'HEAD')
     850                return self._commit_on_branch(message, 'HEAD', username=username, password=password)
    847851
    848852            # Need working directory changes to be committed so we can checkout the merge branch.
     
    852856                # The ChangeLog modification could be made to modify the existing local commit.
    853857                raise ScriptError(message="Working copy is modified. Cannot commit individual git_commits.")
    854             return self._commit_on_branch(message, git_commit)
     858            return self._commit_on_branch(message, git_commit, username=username, password=password)
    855859
    856860        if not force_squash:
     
    858862        self.run(['git', 'reset', '--soft', self.remote_merge_base()])
    859863        self.commit_locally_with_message(message)
    860         return self.push_local_commits_to_server()
    861 
    862     def _commit_on_branch(self, message, git_commit):
     864        return self.push_local_commits_to_server(username=username, password=password)
     865
     866    def _commit_on_branch(self, message, git_commit, username=None, password=None):
    863867        branch_ref = self.run(['git', 'symbolic-ref', 'HEAD']).strip()
    864868        branch_name = branch_ref.replace('refs/heads/', '')
     
    889893
    890894            self.run(['git', 'commit', '-m', message])
    891             output = self.push_local_commits_to_server()
     895            output = self.push_local_commits_to_server(username=username, password=password)
    892896        except Exception, e:
    893897            log("COMMIT FAILED: " + str(e))
     
    937941        self.run(['git', 'commit', '--all', '-F', '-'], input=message)
    938942
    939     def push_local_commits_to_server(self):
     943    def push_local_commits_to_server(self, username=None, password=None):
    940944        dcommit_command = ['git', 'svn', 'dcommit']
    941945        if self.dryrun:
    942946            dcommit_command.append('--dry-run')
    943         output = self.run(dcommit_command, error_handler=commit_error_handler)
     947        if not self.has_authorization_for_realm(SVN.svn_server_realm):
     948            raise AuthenticationError(SVN.svn_server_host, prompt_for_password=True)
     949        if username:
     950            dcommit_command.extend(["--username", username])
     951        output = self.run(dcommit_command, error_handler=commit_error_handler, input=password)
    944952        # Return a string which looks like a commit so that things which parse this output will succeed.
    945953        if self.dryrun:
  • trunk/Tools/Scripts/webkitpy/common/checkout/scm_unittest.py

    r83152 r84114  
    665665
    666666    def test_commit_without_authorization(self):
    667         self.scm.has_authorization_for_realm = lambda: False
     667        self.scm.has_authorization_for_realm = lambda realm: False
    668668        self.assertRaises(AuthenticationError, self._shared_test_commit_with_message)
    669669
     
    675675        fake_webkit_auth_file = os.path.join(svn_config_dir_path, "fake_webkit_auth_file")
    676676        write_into_file_at_path(fake_webkit_auth_file, SVN.svn_server_realm)
    677         self.assertTrue(scm.has_authorization_for_realm(home_directory=fake_home_dir))
     677        self.assertTrue(scm.has_authorization_for_realm(SVN.svn_server_realm, home_directory=fake_home_dir))
    678678        os.remove(fake_webkit_auth_file)
    679679        os.rmdir(svn_config_dir_path)
     
    685685        svn_config_dir_path = os.path.join(fake_home_dir, ".subversion")
    686686        os.mkdir(svn_config_dir_path)
    687         self.assertFalse(scm.has_authorization_for_realm(home_directory=fake_home_dir))
     687        self.assertFalse(scm.has_authorization_for_realm(SVN.svn_server_realm, home_directory=fake_home_dir))
    688688        os.rmdir(svn_config_dir_path)
    689689        os.rmdir(fake_home_dir)
  • trunk/Tools/Scripts/webkitpy/common/net/credentials.py

    r70640 r84114  
    3030# Python module for reading stored web credentials from the OS.
    3131
    32 import getpass
    3332import os
    3433import platform
     
    150149            username = User.prompt("%s login: " % self.host)
    151150        if not password:
    152             password = getpass.getpass("%s password for %s: " % (self.host, username))
     151            password = User.prompt_password("%s password for %s: " % (self.host, username))
    153152            self._offer_to_store_credentials_in_keyring(username, password)
    154153
  • trunk/Tools/Scripts/webkitpy/common/system/user.py

    r73838 r84114  
    2727# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2828
     29import getpass
    2930import logging
    3031import os
     
    6465            response = raw_input(message)
    6566        return response
     67
     68    @classmethod
     69    def prompt_password(cls, message, repeat=1):
     70        return cls.prompt(message, repeat=repeat, raw_input=getpass.getpass)
    6671
    6772    @classmethod
  • trunk/Tools/Scripts/webkitpy/tool/steps/commit.py

    r82407 r84114  
    5151
    5252        username = None
     53        password = None
    5354        force_squash = False
    5455
     
    5960            try:
    6061                scm = self._tool.scm()
    61                 commit_text = scm.commit_with_message(self._commit_message, git_commit=self._options.git_commit, username=username, force_squash=force_squash, changed_files=self._changed_files(state))
     62                commit_text = scm.commit_with_message(self._commit_message, git_commit=self._options.git_commit, username=username, password=password, force_squash=force_squash, changed_files=self._changed_files(state))
    6263                svn_revision = scm.svn_revision_from_commit_text(commit_text)
    6364                log("Committed r%s: <%s>" % (svn_revision, urls.view_revision_url(svn_revision)))
     
    7374                username = self._tool.user.prompt("%s login: " % e.server_host, repeat=5)
    7475                if not username:
    75                     raise ScriptError("You need to specify the username on %s to perform the commit as." % self.svn_server_host)
     76                    raise ScriptError("You need to specify the username on %s to perform the commit as." % e.server_host)
     77                if e.prompt_for_password:
     78                    password = self._tool.user.prompt_password("%s password for %s: " % (e.server_host, username), repeat=5)
     79                    if not password:
     80                        raise ScriptError("You need to specify the password for %s on %s to perform the commit." % (username, e.server_host))
Note: See TracChangeset for help on using the changeset viewer.