13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
# TODO: Some kind of command-line display of revision properties:
17
# TODO: Some kind of command-line display of revision properties:
18
18
# perhaps show them in log -v and allow them as options to the commit command.
20
20
"""Some functions to enable caching the conversion between unicode to utf8"""
22
from __future__ import absolute_import
25
_utf8_encode = codecs.getencoder("utf-8")
26
_utf8_decode = codecs.getdecoder("utf-8")
27
# wrap _utf8_decode to support None->None for optional strings.
26
_utf8_encode = codecs.utf_8_encode
27
_utf8_decode = codecs.utf_8_decode
28
28
def _utf8_decode_with_None(bytestring, _utf8_decode=_utf8_decode):
29
"""wrap _utf8_decode to support None->None for optional strings.
31
Also, only return the Unicode portion, since we don't care about the second
29
34
if bytestring is None:
32
return _utf8_decode(bytestring)
37
return _utf8_decode(bytestring)[0]
34
39
# Map revisions from and to utf8 encoding
35
40
# Whenever we do an encode/decode operation, we save the result, so that
45
50
"""Take this unicode revision id, and get a unicode version"""
46
51
# If the key is in the cache try/KeyError is 50% faster than
47
52
# val = dict.get(key), if val is None:
48
# On jam's machine the difference is
53
# On jam's machine the difference is
51
56
# Since these are primarily used when iterating over a knit entry
52
57
# *most* of the time the key will already be in the cache, so use the