comparison mercurial/localrepo.py @ 7787:b8d750daadde

Introduce HG_PREPEND to solve pretxn races - add writepending to flush delayed writes to separate file - add support in hooks for lazy evaluation of callable parameters - add HG_PENDING to pretxn hooks - call writepending if hook is used - pass repo root to hook environment - if HG_PENDING = repo root, we're in pretxn hook - read pending data to make pending changesets visible - filter HG_PENDING in tests/printenv.py
author Matt Mackall <mpm@selenic.com>
date Mon, 16 Feb 2009 19:35:07 -0600
parents b7ac53f7b061
children 6d99ff7b79b5
comparison
equal deleted inserted replaced
7786:92455c1d6f83 7787:b8d750daadde
86 self._transref = self._lockref = self._wlockref = None 86 self._transref = self._lockref = self._wlockref = None
87 87
88 def __getattr__(self, name): 88 def __getattr__(self, name):
89 if name == 'changelog': 89 if name == 'changelog':
90 self.changelog = changelog.changelog(self.sopener) 90 self.changelog = changelog.changelog(self.sopener)
91 if 'HG_PENDING' in os.environ:
92 p = os.environ['HG_PENDING']
93 if p.startswith(self.root):
94 self.changelog.readpending('00changelog.i.a')
91 self.sopener.defversion = self.changelog.version 95 self.sopener.defversion = self.changelog.version
92 return self.changelog 96 return self.changelog
93 if name == 'manifest': 97 if name == 'manifest':
94 self.changelog 98 self.changelog
95 self.manifest = manifest.manifest(self.sopener) 99 self.manifest = manifest.manifest(self.sopener)
953 del lines[0] 957 del lines[0]
954 if not lines and use_dirstate: 958 if not lines and use_dirstate:
955 raise util.Abort(_("empty commit message")) 959 raise util.Abort(_("empty commit message"))
956 text = '\n'.join(lines) 960 text = '\n'.join(lines)
957 961
962 self.changelog.delayupdate()
958 n = self.changelog.add(mn, changed + removed, text, trp, p1, p2, 963 n = self.changelog.add(mn, changed + removed, text, trp, p1, p2,
959 user, wctx.date(), extra) 964 user, wctx.date(), extra)
965 p = lambda: self.changelog.writepending() and self.root or ""
960 self.hook('pretxncommit', throw=True, node=hex(n), parent1=xp1, 966 self.hook('pretxncommit', throw=True, node=hex(n), parent1=xp1,
961 parent2=xp2) 967 parent2=xp2, pending=p)
968 self.changelog.finalize(trp)
962 tr.close() 969 tr.close()
963 970
964 if self.branchcache: 971 if self.branchcache:
965 self.branchtags() 972 self.branchtags()
966 973
2032 if fl.addgroup(chunkiter, revmap, trp) is None: 2039 if fl.addgroup(chunkiter, revmap, trp) is None:
2033 raise util.Abort(_("received file revlog group is empty")) 2040 raise util.Abort(_("received file revlog group is empty"))
2034 revisions += len(fl) - o 2041 revisions += len(fl) - o
2035 files += 1 2042 files += 1
2036 2043
2037 # make changelog see real files again
2038 cl.finalize(trp)
2039
2040 newheads = len(self.changelog.heads()) 2044 newheads = len(self.changelog.heads())
2041 heads = "" 2045 heads = ""
2042 if oldheads and newheads != oldheads: 2046 if oldheads and newheads != oldheads:
2043 heads = _(" (%+d heads)") % (newheads - oldheads) 2047 heads = _(" (%+d heads)") % (newheads - oldheads)
2044 2048
2045 self.ui.status(_("added %d changesets" 2049 self.ui.status(_("added %d changesets"
2046 " with %d changes to %d files%s\n") 2050 " with %d changes to %d files%s\n")
2047 % (changesets, revisions, files, heads)) 2051 % (changesets, revisions, files, heads))
2048 2052
2049 if changesets > 0: 2053 if changesets > 0:
2054 p = lambda: self.changelog.writepending() and self.root or ""
2050 self.hook('pretxnchangegroup', throw=True, 2055 self.hook('pretxnchangegroup', throw=True,
2051 node=hex(self.changelog.node(cor+1)), source=srctype, 2056 node=hex(self.changelog.node(cor+1)), source=srctype,
2052 url=url) 2057 url=url, pending=p)
2058
2059 # make changelog see real files again
2060 cl.finalize(trp)
2053 2061
2054 tr.close() 2062 tr.close()
2055 finally: 2063 finally:
2056 del tr 2064 del tr
2057 2065