~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_dirstate.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2008-09-26 05:47:03 UTC
  • mfrom: (3696.5.4 integration)
  • Revision ID: pqm@pqm.ubuntu.com-20080926054703-nxn5f1h7z7gvur96
(robertc) Improve the handling of the sha1 cache by updating it
        during commit and avoiding some of the sha generation during
        iter_changes. (Robert Collins)

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 
19
19
import bisect
20
20
import os
21
 
import time
22
21
 
23
22
from bzrlib import (
24
23
    dirstate,
564
563
        state.lock_read()
565
564
        try:
566
565
            entry = state._get_entry(0, path_utf8='a-file')
567
 
            # The current sha1 sum should be empty
568
 
            self.assertEqual('', entry[1][0][1])
 
566
            # The current size should be 0 (default)
 
567
            self.assertEqual(0, entry[1][0][2])
569
568
            # We should have a real entry.
570
569
            self.assertNotEqual((None, None), entry)
571
570
            # Make sure everything is old enough
572
571
            state._sha_cutoff_time()
573
572
            state._cutoff_time += 10
574
 
            sha1sum = dirstate.update_entry(state, entry, 'a-file', os.lstat('a-file'))
575
 
            # We should have gotten a real sha1
576
 
            self.assertEqual('ecc5374e9ed82ad3ea3b4d452ea995a5fd3e70e3',
577
 
                             sha1sum)
 
573
            # Change the file length
 
574
            self.build_tree_contents([('a-file', 'shorter')])
 
575
            sha1sum = dirstate.update_entry(state, entry, 'a-file',
 
576
                os.lstat('a-file'))
 
577
            # new file, no cached sha:
 
578
            self.assertEqual(None, sha1sum)
578
579
 
579
580
            # The dirblock has been updated
580
 
            self.assertEqual(sha1sum, entry[1][0][1])
 
581
            self.assertEqual(7, entry[1][0][2])
581
582
            self.assertEqual(dirstate.DirState.IN_MEMORY_MODIFIED,
582
583
                             state._dirblock_state)
583
584
 
593
594
        state.lock_read()
594
595
        try:
595
596
            entry = state._get_entry(0, path_utf8='a-file')
596
 
            self.assertEqual(sha1sum, entry[1][0][1])
 
597
            self.assertEqual(7, entry[1][0][2])
597
598
        finally:
598
599
            state.unlock()
599
600
 
612
613
        state.lock_read()
613
614
        try:
614
615
            entry = state._get_entry(0, path_utf8='a-file')
615
 
            sha1sum = dirstate.update_entry(state, entry, 'a-file', os.lstat('a-file'))
616
 
            # We should have gotten a real sha1
617
 
            self.assertEqual('ecc5374e9ed82ad3ea3b4d452ea995a5fd3e70e3',
618
 
                             sha1sum)
 
616
            sha1sum = dirstate.update_entry(state, entry, 'a-file',
 
617
                os.lstat('a-file'))
 
618
            # No sha - too new
 
619
            self.assertEqual(None, sha1sum)
619
620
            self.assertEqual(dirstate.DirState.IN_MEMORY_MODIFIED,
620
621
                             state._dirblock_state)
621
622