260
260
'sha1': s.hexdigest()}
264
"""Calculate automatic user identification.
266
Returns (realname, email).
268
Only used when none is set in the environment or the id file.
270
This previously used the FQDN as the default domain, but that can
271
be very slow on machines where DNS is broken. So now we simply
276
# XXX: Any good way to get real user name on win32?
281
w = pwd.getpwuid(uid)
282
gecos = w.pw_gecos.decode(bzrlib.user_encoding)
283
username = w.pw_name.decode(bzrlib.user_encoding)
284
comma = gecos.find(',')
288
realname = gecos[:comma]
294
realname = username = getpass.getuser().decode(bzrlib.user_encoding)
296
return realname, (username + '@' + socket.gethostname())
299
def _get_user_id(branch):
300
"""Return the full user id from a file or environment variable.
302
e.g. "John Hacker <jhacker@foo.org>"
305
A branch to use for a per-branch configuration, or None.
307
The following are searched in order:
310
2. .bzr/email for this branch.
314
v = os.environ.get('BZREMAIL')
316
return v.decode(bzrlib.user_encoding)
320
return (branch.controlfile("email", "r")
322
.decode(bzrlib.user_encoding)
325
if e.errno != errno.ENOENT:
331
return (open(os.path.join(config_dir(), "email"))
333
.decode(bzrlib.user_encoding)
336
if e.errno != errno.ENOENT:
339
v = os.environ.get('EMAIL')
341
return v.decode(bzrlib.user_encoding)
346
def username(branch):
347
"""Return email-style username.
349
Something similar to 'Martin Pool <mbp@sourcefrog.net>'
351
TODO: Check it's reasonably well-formed.
353
v = _get_user_id(branch)
357
name, email = _auto_user_id()
359
return '%s <%s>' % (name, email)
364
def user_email(branch):
365
"""Return just the email component of a username."""
366
e = _get_user_id(branch)
368
m = re.search(r'[\w+.-]+@[\w+.-]+', e)
370
raise BzrError("%r doesn't seem to contain "
371
"a reasonable email address" % e)
374
return _auto_user_id()[1]
377
263
def compare_files(a, b):
378
264
"""Returns true if equal in contents"""