comparison mercurial/localrepo.py @ 8416:9dfee83c93c8

commit: hoist the rest of the dirstate manipulation out of commitctx
author Matt Mackall <mpm@selenic.com>
date Thu, 14 May 2009 13:24:39 -0500
parents 221a18019b2b
children cb897f10e54a
comparison
equal deleted inserted replaced
8415:221a18019b2b 8416:9dfee83c93c8
812 "(see hg resolve)")) 812 "(see hg resolve)"))
813 wctx = context.workingctx(self, (p1, p2), text, user, date, 813 wctx = context.workingctx(self, (p1, p2), text, user, date,
814 extra, changes) 814 extra, changes)
815 ret = self.commitctx(wctx, editor, True) 815 ret = self.commitctx(wctx, editor, True)
816 ms.reset() 816 ms.reset()
817
818 # update dirstate
819 for f in changes[0] + changes[1]:
820 self.dirstate.normal(f)
821 for f in changes[2]:
822 self.dirstate.forget(f)
823 self.dirstate.setparents(ret)
824
817 return ret 825 return ret
818 826
819 finally: 827 finally:
820 if ret == None: 828 if ret == None:
821 self.dirstate.invalidate() # didn't successfully commit 829 self.dirstate.invalidate() # didn't successfully commit
822 wlock.release() 830 wlock.release()
823 831
824 def commitctx(self, ctx, editor=None, working=False): 832 def commitctx(self, ctx, editor=None, error=False):
825 """Add a new revision to current repository. 833 """Add a new revision to current repository.
826 834
827 Revision information is passed via the context argument. 835 Revision information is passed via the context argument.
828 If editor is supplied, it is called to get a commit message. 836 If editor is supplied, it is called to get a commit message.
829 If working is set, the working directory is affected. 837 If working is set, the working directory is affected.
853 try: 861 try:
854 fctx = ctx[f] 862 fctx = ctx[f]
855 new[f] = self._filecommit(fctx, m1, m2, linkrev, trp, 863 new[f] = self._filecommit(fctx, m1, m2, linkrev, trp,
856 changed) 864 changed)
857 m1.set(f, fctx.flags()) 865 m1.set(f, fctx.flags())
858 if working:
859 self.dirstate.normal(f)
860
861 except (OSError, IOError): 866 except (OSError, IOError):
862 if working: 867 if error:
863 self.ui.warn(_("trouble committing %s!\n") % f) 868 self.ui.warn(_("trouble committing %s!\n") % f)
864 raise 869 raise
865 else: 870 else:
866 remove.append(f) 871 remove.append(f)
867 872
903 self.changelog.finalize(trp) 908 self.changelog.finalize(trp)
904 tr.close() 909 tr.close()
905 910
906 if self.branchcache: 911 if self.branchcache:
907 self.branchtags() 912 self.branchtags()
908
909 if working:
910 self.dirstate.setparents(n)
911 for f in removed:
912 self.dirstate.forget(f)
913 913
914 self.hook("commit", node=hex(n), parent1=xp1, parent2=xp2) 914 self.hook("commit", node=hex(n), parent1=xp1, parent2=xp2)
915 return n 915 return n
916 finally: 916 finally:
917 del tr 917 del tr