~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/workingtree_3.py

  • Committer: Jelmer Vernooij
  • Date: 2011-08-30 17:32:29 UTC
  • mto: This revision was merged to the branch mainline in revision 6115.
  • Revision ID: jelmer@samba.org-20110830173229-k234j02cfvf7gshz
Add common base class.

Show diffs side-by-side

added added

removed removed

Lines of Context:
40
40
    WorkingTreeFormat,
41
41
    )
42
42
 
43
 
class WorkingTree3(InventoryWorkingTree):
44
 
    """This is the Format 3 working tree.
45
 
 
46
 
    This differs from the base WorkingTree by:
47
 
     - having its own file lock
48
 
     - having its own last-revision property.
49
 
 
50
 
    This is new in bzr 0.8
51
 
    """
 
43
 
 
44
class PreDirStateWorkingTree(InventoryWorkingTree):
52
45
 
53
46
    def __init__(self, basedir='.', *args, **kwargs):
54
 
        super(WorkingTree3, self).__init__(basedir, *args, **kwargs)
55
 
 
 
47
        super(PreDirStateWorkingTree, self).__init__(basedir, *args, **kwargs)
56
48
        # update the whole cache up front and write to disk if anything changed;
57
49
        # in the future we might want to do this more selectively
58
50
        # two possible ways offer themselves : in self._unlock, write the cache
73
65
            trace.mutter("write hc")
74
66
            hc.write()
75
67
 
 
68
    def _write_hashcache_if_dirty(self):
 
69
        """Write out the hashcache if it is dirty."""
 
70
        if self._hashcache.needs_write:
 
71
            try:
 
72
                self._hashcache.write()
 
73
            except OSError, e:
 
74
                if e.errno not in (errno.EPERM, errno.EACCES):
 
75
                    raise
 
76
                # TODO: jam 20061219 Should this be a warning? A single line
 
77
                #       warning might be sufficient to let the user know what
 
78
                #       is going on.
 
79
                trace.mutter('Could not write hashcache for %s\nError: %s',
 
80
                              self._hashcache.cache_file_name(), e)
 
81
 
 
82
    @needs_read_lock
 
83
    def get_file_sha1(self, file_id, path=None, stat_value=None):
 
84
        if not path:
 
85
            path = self._inventory.id2path(file_id)
 
86
        return self._hashcache.get_sha1(path, stat_value)
 
87
 
 
88
 
 
89
class WorkingTree3(PreDirStateWorkingTree):
 
90
    """This is the Format 3 working tree.
 
91
 
 
92
    This differs from the base WorkingTree by:
 
93
     - having its own file lock
 
94
     - having its own last-revision property.
 
95
 
 
96
    This is new in bzr 0.8
 
97
    """
 
98
 
76
99
    @needs_read_lock
77
100
    def _last_revision(self):
78
101
        """See Mutable.last_revision."""
112
135
        finally:
113
136
            self.branch.unlock()
114
137
 
115
 
    def _write_hashcache_if_dirty(self):
116
 
        """Write out the hashcache if it is dirty."""
117
 
        if self._hashcache.needs_write:
118
 
            try:
119
 
                self._hashcache.write()
120
 
            except OSError, e:
121
 
                if e.errno not in (errno.EPERM, errno.EACCES):
122
 
                    raise
123
 
                # TODO: jam 20061219 Should this be a warning? A single line
124
 
                #       warning might be sufficient to let the user know what
125
 
                #       is going on.
126
 
                trace.mutter('Could not write hashcache for %s\nError: %s',
127
 
                              self._hashcache.cache_file_name(), e)
128
 
 
129
 
    @needs_read_lock
130
 
    def get_file_sha1(self, file_id, path=None, stat_value=None):
131
 
        if not path:
132
 
            path = self._inventory.id2path(file_id)
133
 
        return self._hashcache.get_sha1(path, stat_value)
134
 
 
135
138
 
136
139
class WorkingTreeFormat3(WorkingTreeFormat):
137
140
    """The second working tree format updated to record a format marker.