Commits

Marcin Kasperski committed d0541d1

Improving debug messages handling.

Comments (0)

Files changed (1)

mercurial_keyring.py

 
 ############################################################
 
+def _debug(ui, msg):
+    ui.debug("[HgKeyring] " + msg)
+
+def _debug_reply(ui, msg, url, user, pwd):
+    _debug(ui, "%s. Url: %s, user: %s, passwd: %s\n" % (
+            msg, url, user, pwd and '*' * len(pwd) or 'not set'))
+
+
+############################################################
+
 class HTTPPasswordHandler(object):
     """
     Actual implementation of password handling (user prompting,
         user, pwd = urllib2.HTTPPasswordMgrWithDefaultRealm.find_user_password(
             pwmgr, realm, authuri)
         if user and pwd:
-            self._debug_reply(ui, _("Auth data found in repository URL"),
-                              base_url, user, pwd)
+            _debug_reply(ui, _("Auth data found in repository URL"),
+                         base_url, user, pwd)
             self.last_reply = dict(realm=realm,authuri=authuri,user=user)
             return user, pwd
 
             keyring_url = prefix_url
         else:
             keyring_url = base_url
-        ui.debug("[HgKeyring] " + _("Keyring URL: %s\n") % keyring_url)
+        _debug(ui, _("Keyring URL: %s\n") % keyring_url)
 
         # Checking the memory cache (there may be many http calls per command)
         cache_key = (realm, keyring_url)
             cached_auth = self.pwd_cache.get(cache_key)
             if cached_auth:
                 user, pwd = cached_auth
-                self._debug_reply(ui, _("Cached auth data found"),
-                                  base_url, user, pwd)
+                _debug_reply(ui, _("Cached auth data found"),
+                             base_url, user, pwd)
                 self.last_reply = dict(realm=realm,authuri=authuri,user=user)
                 return user, pwd
 
             user = auth_user
             if pwd:
                 self.pwd_cache[cache_key] = user, pwd
-                self._debug_reply(ui, _("Auth data set in .hg/hgrc"),
-                                  base_url, user, pwd)
+                _debug_reply(ui, _("Auth data set in .hg/hgrc"),
+                             base_url, user, pwd)
                 self.last_reply = dict(realm=realm,authuri=authuri,user=user)
                 return user, pwd
             else:
-                ui.debug("[HgKeyring] " + _("MercurialKeyring: Username found in .hg/hgrc: %s\n") % user)
+                _debug(ui, _("Username found in .hg/hgrc: %s\n") % user)
 
         # Loading password from keyring.
         # Only if username is known (so we know the key) and we are
         # not after failure (so we don't reuse the bad password).
         if user and not after_bad_auth:
+            _debug(ui, _("Looking for password for user %s and url %s") % (user, keyring_url))
             pwd = password_store.get_http_password(keyring_url, user)
             if pwd:
                 self.pwd_cache[cache_key] = user, pwd
-                self._debug_reply(ui, _("Keyring password found"),
-                                  base_url, user, pwd)
+                _debug_reply(ui, _("Keyring password found"),
+                             base_url, user, pwd)
                 self.last_reply = dict(realm=realm,authuri=authuri,user=user)
                 return user, pwd
             else:
-                ui.debug("[HgKeyring] " + _("Password not present in the keyring\n"))
+                _debug(ui, _("Password not present in the keyring\n"))
 
         # Is the username permanently set?
         fixed_user = (user and True or False)
             # It is done only if username is permanently set.
             # Otherwise we won't be able to find the password so it
             # does not make much sense to preserve it
-            ui.debug("[HgKeyring] " + _("Saving password for %s to keyring\n") % user)
+            _debug(ui, _("Saving password for %s to keyring\n") % user)
             password_store.set_http_password(keyring_url, user, pwd)
 
         # Saving password to the memory cache
         self.pwd_cache[cache_key] = user, pwd
 
-        self._debug_reply(ui, _("Manually entered password"),
-                          base_url, user, pwd)
+        _debug_reply(ui, _("Manually entered password"),
+                     base_url, user, pwd)
         self.last_reply = dict(realm=realm,authuri=authuri,user=user)
         return user, pwd
 
         return "%s://%s%s" % (parsed_url.scheme, parsed_url.netloc,
                               parsed_url.path)
 
-    def _debug_reply(self, ui, msg, url, user, pwd):
-        ui.debug("[HgKeyring] " + "%s. Url: %s, user: %s, passwd: %s\n" % (
-            msg, url, user, pwd and '*' * len(pwd) or 'not set'))
-
 ############################################################
 
 @monkeypatch_method(passwordmgr)