Mercurial > public > mercurial-scm > hg
comparison mercurial/localrepo.py @ 32814:2083d1643d69
workingctx: add a way for extensions to run code at status fixup time
Some extensions like fsmonitor need to run code after dirstate.status is
called, but while the wlock is held. The extensions could grab the wlock again,
but that has its own peculiar race issues. For example, fsmonitor would not
like its state to be written out if the dirstate has changed underneath (see
issue5581 for what can go wrong in that sort of case).
To protect against these sorts of issues, allow extensions to declare that they
would like to run some code to run at fixup time.
fsmonitor will switch to using this in the next patch in the series.
author | Siddharth Agarwal <sid0@fb.com> |
---|---|
date | Mon, 12 Jun 2017 13:56:50 -0700 |
parents | b8ff7d0ff361 |
children | 6fa245f80b6f |
comparison
equal
deleted
inserted
replaced
32813:6d73b7ff8f92 | 32814:2083d1643d69 |
---|---|
397 # - phase change, | 397 # - phase change, |
398 # - new obsolescence marker, | 398 # - new obsolescence marker, |
399 # - working directory parent change, | 399 # - working directory parent change, |
400 # - bookmark changes | 400 # - bookmark changes |
401 self.filteredrevcache = {} | 401 self.filteredrevcache = {} |
402 | |
403 # post-dirstate-status hooks | |
404 self._postdsstatus = [] | |
402 | 405 |
403 # generic mapping between names and nodes | 406 # generic mapping between names and nodes |
404 self.names = namespaces.namespaces() | 407 self.names = namespaces.namespaces() |
405 | 408 |
406 def close(self): | 409 def close(self): |
1882 listsubrepos=False): | 1885 listsubrepos=False): |
1883 '''a convenience method that calls node1.status(node2)''' | 1886 '''a convenience method that calls node1.status(node2)''' |
1884 return self[node1].status(node2, match, ignored, clean, unknown, | 1887 return self[node1].status(node2, match, ignored, clean, unknown, |
1885 listsubrepos) | 1888 listsubrepos) |
1886 | 1889 |
1890 def addpostdsstatus(self, ps): | |
1891 """Add a callback to run within the wlock, at the point at which status | |
1892 fixups happen. | |
1893 | |
1894 On status completion, callback(wctx, status) will be called with the | |
1895 wlock held, unless the dirstate has changed from underneath or the wlock | |
1896 couldn't be grabbed. | |
1897 | |
1898 Callbacks should not capture and use a cached copy of the dirstate -- | |
1899 it might change in the meanwhile. Instead, they should access the | |
1900 dirstate via wctx.repo().dirstate. | |
1901 | |
1902 This list is emptied out after each status run -- extensions should | |
1903 make sure it adds to this list each time dirstate.status is called. | |
1904 Extensions should also make sure they don't call this for statuses | |
1905 that don't involve the dirstate. | |
1906 """ | |
1907 | |
1908 # The list is located here for uniqueness reasons -- it is actually | |
1909 # managed by the workingctx, but that isn't unique per-repo. | |
1910 self._postdsstatus.append(ps) | |
1911 | |
1912 def postdsstatus(self): | |
1913 """Used by workingctx to get the list of post-dirstate-status hooks.""" | |
1914 return self._postdsstatus | |
1915 | |
1916 def clearpostdsstatus(self): | |
1917 """Used by workingctx to clear post-dirstate-status hooks.""" | |
1918 del self._postdsstatus[:] | |
1919 | |
1887 def heads(self, start=None): | 1920 def heads(self, start=None): |
1888 if start is None: | 1921 if start is None: |
1889 cl = self.changelog | 1922 cl = self.changelog |
1890 headrevs = reversed(cl.headrevs()) | 1923 headrevs = reversed(cl.headrevs()) |
1891 return [cl.node(rev) for rev in headrevs] | 1924 return [cl.node(rev) for rev in headrevs] |