comparison mercurial/localrepo.py @ 10492:0e64d814d7d0 stable

run commit and update hooks after command completion (issue1827) Previously, the working dir state hadn't been written when these hooks were invoked, so external commands couldn't see all changes.
author Sune Foldager <cryo@cyanite.org>
date Wed, 17 Feb 2010 15:43:21 +0100
parents 956498af9812
children 45734b51c99b
comparison
equal deleted inserted replaced
10491:d7e582cab6b6 10492:0e64d814d7d0
844 msgfile = self.opener('last-message.txt', 'wb') 844 msgfile = self.opener('last-message.txt', 'wb')
845 msgfile.write(cctx._text) 845 msgfile.write(cctx._text)
846 msgfile.close() 846 msgfile.close()
847 847
848 try: 848 try:
849 hookp1, hookp2 = hex(p1), (p2 != nullid and hex(p2) or '')
850 self.hook("precommit", throw=True, parent1=hookp1, parent2=hookp2)
849 ret = self.commitctx(cctx, True) 851 ret = self.commitctx(cctx, True)
850 except: 852 except:
851 if edited: 853 if edited:
852 msgfn = self.pathto(msgfile.name[len(self.root)+1:]) 854 msgfn = self.pathto(msgfile.name[len(self.root)+1:])
853 self.ui.write( 855 self.ui.write(
859 self.dirstate.normal(f) 861 self.dirstate.normal(f)
860 for f in changes[2]: 862 for f in changes[2]:
861 self.dirstate.forget(f) 863 self.dirstate.forget(f)
862 self.dirstate.setparents(ret) 864 self.dirstate.setparents(ret)
863 ms.reset() 865 ms.reset()
864
865 return ret
866
867 finally: 866 finally:
868 wlock.release() 867 wlock.release()
869 868
869 self.hook("commit", node=hex(ret), parent1=hookp1, parent2=hookp2)
870 return ret
871
870 def commitctx(self, ctx, error=False): 872 def commitctx(self, ctx, error=False):
871 """Add a new revision to current repository. 873 """Add a new revision to current repository.
872
873 Revision information is passed via the context argument. 874 Revision information is passed via the context argument.
874 """ 875 """
875 876
876 tr = lock = None 877 tr = lock = None
877 removed = ctx.removed() 878 removed = ctx.removed()
878 p1, p2 = ctx.p1(), ctx.p2() 879 p1, p2 = ctx.p1(), ctx.p2()
879 m1 = p1.manifest().copy() 880 m1 = p1.manifest().copy()
880 m2 = p2.manifest() 881 m2 = p2.manifest()
881 user = ctx.user() 882 user = ctx.user()
882
883 xp1, xp2 = p1.hex(), p2 and p2.hex() or ''
884 self.hook("precommit", throw=True, parent1=xp1, parent2=xp2)
885 883
886 lock = self.lock() 884 lock = self.lock()
887 try: 885 try:
888 tr = self.transaction() 886 tr = self.transaction()
889 trp = weakref.proxy(tr) 887 trp = weakref.proxy(tr)
923 self.changelog.delayupdate() 921 self.changelog.delayupdate()
924 n = self.changelog.add(mn, changed + removed, ctx.description(), 922 n = self.changelog.add(mn, changed + removed, ctx.description(),
925 trp, p1.node(), p2.node(), 923 trp, p1.node(), p2.node(),
926 user, ctx.date(), ctx.extra().copy()) 924 user, ctx.date(), ctx.extra().copy())
927 p = lambda: self.changelog.writepending() and self.root or "" 925 p = lambda: self.changelog.writepending() and self.root or ""
926 xp1, xp2 = p1.hex(), p2 and p2.hex() or ''
928 self.hook('pretxncommit', throw=True, node=hex(n), parent1=xp1, 927 self.hook('pretxncommit', throw=True, node=hex(n), parent1=xp1,
929 parent2=xp2, pending=p) 928 parent2=xp2, pending=p)
930 self.changelog.finalize(trp) 929 self.changelog.finalize(trp)
931 tr.close() 930 tr.close()
932 931
933 if self._branchcache: 932 if self._branchcache:
934 self.branchtags() 933 self.branchtags()
935
936 self.hook("commit", node=hex(n), parent1=xp1, parent2=xp2)
937 return n 934 return n
938 finally: 935 finally:
939 del tr 936 del tr
940 lock.release() 937 lock.release()
941 938