~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/osutils.py

  • Committer: Robert Collins
  • Date: 2007-09-17 22:13:29 UTC
  • mto: This revision was merged to the branch mainline in revision 2829.
  • Revision ID: robertc@robertcollins.net-20070917221329-s63xpy3v0j6btu56
Micro-tweaks to sha routines.

Show diffs side-by-side

added added

removed removed

Lines of Context:
567
567
    return s.hexdigest()
568
568
 
569
569
 
570
 
 
571
 
def sha_strings(strings):
 
570
def sha_strings(strings, _factory=sha.new):
572
571
    """Return the sha-1 of concatenation of strings"""
573
 
    s = sha.new()
 
572
    s = _factory()
574
573
    map(s.update, strings)
575
574
    return s.hexdigest()
576
575
 
577
576
 
578
 
def sha_string(f):
579
 
    s = sha.new()
580
 
    s.update(f)
581
 
    return s.hexdigest()
 
577
def sha_string(f, _factory=sha.new):
 
578
    return _factory(f).hexdigest()
582
579
 
583
580
 
584
581
def fingerprint_file(f):
585
 
    s = sha.new()
586
582
    b = f.read()
587
 
    s.update(b)
588
 
    size = len(b)
589
 
    return {'size': size,
590
 
            'sha1': s.hexdigest()}
 
583
    return {'size': len(b),
 
584
            'sha1': sha.new(b).hexdigest()}
591
585
 
592
586
 
593
587
def compare_files(a, b):