comparison mercurial/util.py @ 15390:fffe49886a51 stable

util: allow sha1() with no args Normally this works because we replace util.sha1 with hashlib.sha1 after first use, but if the first user doesn't provide an arg, it breaks.
author Matt Mackall <mpm@selenic.com>
date Mon, 31 Oct 2011 14:22:11 -0500
parents a347b3614bae
children d7bfbc92a1c0
comparison
equal deleted inserted replaced
15389:3bece03bf3c6 15390:fffe49886a51
71 unlinkpath = platform.unlinkpath 71 unlinkpath = platform.unlinkpath
72 username = platform.username 72 username = platform.username
73 73
74 # Python compatibility 74 # Python compatibility
75 75
76 def sha1(s): 76 def sha1(s=''):
77 return _fastsha1(s) 77 return _fastsha1(s)
78 78
79 _notset = object() 79 _notset = object()
80 def safehasattr(thing, attr): 80 def safehasattr(thing, attr):
81 return getattr(thing, attr, _notset) is not _notset 81 return getattr(thing, attr, _notset) is not _notset
82 82
83 def _fastsha1(s): 83 def _fastsha1(s=''):
84 # This function will import sha1 from hashlib or sha (whichever is 84 # This function will import sha1 from hashlib or sha (whichever is
85 # available) and overwrite itself with it on the first call. 85 # available) and overwrite itself with it on the first call.
86 # Subsequent calls will go directly to the imported function. 86 # Subsequent calls will go directly to the imported function.
87 if sys.version_info >= (2, 5): 87 if sys.version_info >= (2, 5):
88 from hashlib import sha1 as _sha1 88 from hashlib import sha1 as _sha1