Skip to content

Commit

Permalink
Move obtaining of default identity into a separate function.
Browse files Browse the repository at this point in the history
  • Loading branch information
jelmer committed Feb 4, 2019
1 parent ea713f7 commit 825772e
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions dulwich/repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,15 @@ def __init__(self, identity):
self.identity = identity


def _get_default_identity():
import getpass
import socket
user = getpass.getuser().encode(sys.getdefaultencoding())
email = ("{}@{}".format(getpass.getuser(), socket.gethostname())
.encode(sys.getdefaultencoding()))
return (user, email)


def check_user_identity(identity):
"""Verify that a user identity is formatted correctly.
Expand Down Expand Up @@ -629,14 +638,11 @@ def _get_user_identity(self, config):
email = config.get(("user", ), "email")
except KeyError:
email = None
default_user, default_email = _get_default_identity()
if user is None:
import getpass
user = getpass.getuser().encode(sys.getdefaultencoding())
user = default_user
if email is None:
import getpass
import socket
email = ("{}@{}".format(getpass.getuser(), socket.gethostname())
.encode(sys.getdefaultencoding()))
email = default_email
return (user + b" <" + email + b">")

def _add_graftpoints(self, updated_graftpoints):
Expand Down

0 comments on commit 825772e

Please sign in to comment.