Mercurial > hg
comparison mercurial/localrepo.py @ 26751:520defbc0335
hook: centralize passing HG_PENDING to external hook process
This patch centralizes passing HG_PENDING to external hook process
into '_exthook()'. To make in-memory changes visible to external hook
process, this patch does:
- write (or schedule to write) in-memory dirstate changes, and
- set HG_PENDING environment variable, if:
- a transaction is running, and
- there are in-memory changes to be visible
This patch tests some commands with some hooks, because transaction
activity of a same hook differs from each other ("---": "not tested").
======== ========= ========= ============
command preupdate precommit pretxncommit
======== ========= ========= ============
unshelve o --- ---
backout x --- ---
import --- o o
qrefresh --- x o
======== ========= ========= ============
Each hooks are examined separately to prevent in-memory changes from
being visible to external process accidentally by side effect of hooks
previously invoked.
author | FUJIWARA Katsunori <foozy@lares.dti.ne.jp> |
---|---|
date | Sat, 17 Oct 2015 01:15:34 +0900 |
parents | 5ba0a99ff27f |
children | 69a121c378ef |
comparison
equal
deleted
inserted
replaced
26750:9f9ec4abe700 | 26751:520defbc0335 |
---|---|
992 vfsmap = {'plain': self.vfs} # root of .hg/ | 992 vfsmap = {'plain': self.vfs} # root of .hg/ |
993 # we must avoid cyclic reference between repo and transaction. | 993 # we must avoid cyclic reference between repo and transaction. |
994 reporef = weakref.ref(self) | 994 reporef = weakref.ref(self) |
995 def validate(tr): | 995 def validate(tr): |
996 """will run pre-closing hooks""" | 996 """will run pre-closing hooks""" |
997 pending = lambda: tr.writepending() and self.root or "" | 997 reporef().hook('pretxnclose', throw=True, |
998 reporef().hook('pretxnclose', throw=True, pending=pending, | |
999 txnname=desc, **tr.hookargs) | 998 txnname=desc, **tr.hookargs) |
1000 def releasefn(tr, success): | 999 def releasefn(tr, success): |
1001 repo = reporef() | 1000 repo = reporef() |
1002 if success: | 1001 if success: |
1003 # this should be explicitly invoked here, because | 1002 # this should be explicitly invoked here, because |
1680 self.ui.note(_("committing changelog\n")) | 1679 self.ui.note(_("committing changelog\n")) |
1681 self.changelog.delayupdate(tr) | 1680 self.changelog.delayupdate(tr) |
1682 n = self.changelog.add(mn, files, ctx.description(), | 1681 n = self.changelog.add(mn, files, ctx.description(), |
1683 trp, p1.node(), p2.node(), | 1682 trp, p1.node(), p2.node(), |
1684 user, ctx.date(), ctx.extra().copy()) | 1683 user, ctx.date(), ctx.extra().copy()) |
1685 p = lambda: tr.writepending() and self.root or "" | |
1686 xp1, xp2 = p1.hex(), p2 and p2.hex() or '' | 1684 xp1, xp2 = p1.hex(), p2 and p2.hex() or '' |
1687 self.hook('pretxncommit', throw=True, node=hex(n), parent1=xp1, | 1685 self.hook('pretxncommit', throw=True, node=hex(n), parent1=xp1, |
1688 parent2=xp2, pending=p) | 1686 parent2=xp2) |
1689 # set the new commit is proper phase | 1687 # set the new commit is proper phase |
1690 targetphase = subrepo.newcommitphase(self.ui, ctx) | 1688 targetphase = subrepo.newcommitphase(self.ui, ctx) |
1691 if targetphase: | 1689 if targetphase: |
1692 # retract boundary do not alter parent changeset. | 1690 # retract boundary do not alter parent changeset. |
1693 # if a parent have higher the resulting phase will | 1691 # if a parent have higher the resulting phase will |
1863 try: | 1861 try: |
1864 tr = self.currenttransaction() | 1862 tr = self.currenttransaction() |
1865 hookargs = {} | 1863 hookargs = {} |
1866 if tr is not None: | 1864 if tr is not None: |
1867 hookargs.update(tr.hookargs) | 1865 hookargs.update(tr.hookargs) |
1868 pending = lambda: tr.writepending() and self.root or "" | |
1869 hookargs['pending'] = pending | |
1870 hookargs['namespace'] = namespace | 1866 hookargs['namespace'] = namespace |
1871 hookargs['key'] = key | 1867 hookargs['key'] = key |
1872 hookargs['old'] = old | 1868 hookargs['old'] = old |
1873 hookargs['new'] = new | 1869 hookargs['new'] = new |
1874 self.hook('prepushkey', throw=True, **hookargs) | 1870 self.hook('prepushkey', throw=True, **hookargs) |