~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/dirstate.py

  • Committer: paulbrianstewart at gmail
  • Date: 2011-08-13 23:07:36 UTC
  • mto: This revision was merged to the branch mainline in revision 6069.
  • Revision ID: paulbrianstewart@gmail.com-20110813230736-lqi6eek015wh23yv
Added punctuation to the commit message

Show diffs side-by-side

added added

removed removed

Lines of Context:
232
232
 
233
233
from bzrlib import (
234
234
    cache_utf8,
235
 
    config,
236
235
    debug,
237
236
    errors,
238
237
    inventory,
240
239
    osutils,
241
240
    static_tuple,
242
241
    trace,
243
 
    urlutils,
244
242
    )
245
243
 
246
244
 
450
448
        self._known_hash_changes = set()
451
449
        # How many hash changed entries can we have without saving
452
450
        self._worth_saving_limit = worth_saving_limit
453
 
        self._config_stack = config.LocationStack(urlutils.local_path_to_url(
454
 
            path))
455
451
 
456
452
    def __repr__(self):
457
453
        return "%s(%r)" % \
2512
2508
        #       IN_MEMORY_HASH_MODIFIED, we should only fail quietly if we fail
2513
2509
        #       to save an IN_MEMORY_HASH_MODIFIED, and fail *noisily* if we
2514
2510
        #       fail to save IN_MEMORY_MODIFIED
2515
 
        if not self._worth_saving():
2516
 
            return
2517
 
 
2518
 
        grabbed_write_lock = False
2519
 
        if self._lock_state != 'w':
2520
 
            grabbed_write_lock, new_lock = self._lock_token.temporary_write_lock()
2521
 
            # Switch over to the new lock, as the old one may be closed.
2522
 
            # TODO: jam 20070315 We should validate the disk file has
2523
 
            #       not changed contents, since temporary_write_lock may
2524
 
            #       not be an atomic operation.
2525
 
            self._lock_token = new_lock
2526
 
            self._state_file = new_lock.f
2527
 
            if not grabbed_write_lock:
2528
 
                # We couldn't grab a write lock, so we switch back to a read one
2529
 
                return
2530
 
        try:
2531
 
            lines = self.get_lines()
2532
 
            self._state_file.seek(0)
2533
 
            self._state_file.writelines(lines)
2534
 
            self._state_file.truncate()
2535
 
            self._state_file.flush()
2536
 
            self._maybe_fdatasync()
2537
 
            self._mark_unmodified()
2538
 
        finally:
2539
 
            if grabbed_write_lock:
2540
 
                self._lock_token = self._lock_token.restore_read_lock()
2541
 
                self._state_file = self._lock_token.f
 
2511
        if self._worth_saving():
 
2512
            grabbed_write_lock = False
 
2513
            if self._lock_state != 'w':
 
2514
                grabbed_write_lock, new_lock = self._lock_token.temporary_write_lock()
 
2515
                # Switch over to the new lock, as the old one may be closed.
2542
2516
                # TODO: jam 20070315 We should validate the disk file has
2543
 
                #       not changed contents. Since restore_read_lock may
2544
 
                #       not be an atomic operation.                
2545
 
 
2546
 
    def _maybe_fdatasync(self):
2547
 
        """Flush to disk if possible and if not configured off."""
2548
 
        if self._config_stack.get('dirstate.fdatasync'):
2549
 
            osutils.fdatasync(self._state_file.fileno())
 
2517
                #       not changed contents. Since temporary_write_lock may
 
2518
                #       not be an atomic operation.
 
2519
                self._lock_token = new_lock
 
2520
                self._state_file = new_lock.f
 
2521
                if not grabbed_write_lock:
 
2522
                    # We couldn't grab a write lock, so we switch back to a read one
 
2523
                    return
 
2524
            try:
 
2525
                lines = self.get_lines()
 
2526
                self._state_file.seek(0)
 
2527
                self._state_file.writelines(lines)
 
2528
                self._state_file.truncate()
 
2529
                self._state_file.flush()
 
2530
                self._mark_unmodified()
 
2531
            finally:
 
2532
                if grabbed_write_lock:
 
2533
                    self._lock_token = self._lock_token.restore_read_lock()
 
2534
                    self._state_file = self._lock_token.f
 
2535
                    # TODO: jam 20070315 We should validate the disk file has
 
2536
                    #       not changed contents. Since restore_read_lock may
 
2537
                    #       not be an atomic operation.
2550
2538
 
2551
2539
    def _worth_saving(self):
2552
2540
        """Is it worth saving the dirstate or not?"""