view tests/md5sum.py @ 20553:86cefb15e7b5

cmdutil: implemented new lazy increasingwindows Now log can work in a lazy way and get results as soon as they are processed. Performance Benchmarking: $ time hg log -l1 -qr "branch(default)" 0:9117c6561b0b real 0m2.303s user 0m2.252s sys 0m0.048s $ time ./hg log -l1 -qr "branch(default)" 0:9117c6561b0b real 0m0.238s user 0m0.199s sys 0m0.037s
author Lucas Moscovicz <lmoscovicz@fb.com>
date Thu, 13 Feb 2014 14:27:12 -0800
parents 1ffeeb91c55d
children 328739ea70c3
line wrap: on
line source

#!/usr/bin/env python
#
# Based on python's Tools/scripts/md5sum.py
#
# This software may be used and distributed according to the terms
# of the PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2, which is
# GPL-compatible.

import sys, os

try:
    from hashlib import md5
except ImportError:
    from md5 import md5

try:
    import msvcrt
    msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)
    msvcrt.setmode(sys.stderr.fileno(), os.O_BINARY)
except ImportError:
    pass

for filename in sys.argv[1:]:
    try:
        fp = open(filename, 'rb')
    except IOError, msg:
        sys.stderr.write('%s: Can\'t open: %s\n' % (filename, msg))
        sys.exit(1)

    m = md5()
    try:
        while True:
            data = fp.read(8192)
            if not data:
                break
            m.update(data)
    except IOError, msg:
        sys.stderr.write('%s: I/O error: %s\n' % (filename, msg))
        sys.exit(1)
    sys.stdout.write('%s  %s\n' % (m.hexdigest(), filename))

sys.exit(0)