comparison mercurial/localrepo.py @ 8399:1c3d5c54cf1c

commitctx: replace two dirstate vars with working
author Matt Mackall <mpm@selenic.com>
date Thu, 14 May 2009 13:20:40 -0500
parents a45eb410e0f2
children 9eecc471aca3
comparison
equal deleted inserted replaced
8398:a45eb410e0f2 8399:1c3d5c54cf1c
814 if f in ms and ms[f] == 'u': 814 if f in ms and ms[f] == 'u':
815 raise util.Abort(_("unresolved merge conflicts " 815 raise util.Abort(_("unresolved merge conflicts "
816 "(see hg resolve)")) 816 "(see hg resolve)"))
817 wctx = context.workingctx(self, (p1, p2), text, user, date, 817 wctx = context.workingctx(self, (p1, p2), text, user, date,
818 extra, changes) 818 extra, changes)
819 r = self._commitctx(wctx, force, force_editor, empty_ok, 819 r = self._commitctx(wctx, force, force_editor, empty_ok, True)
820 True, True)
821 ms.reset() 820 ms.reset()
822 return r 821 return r
823 822
824 finally: 823 finally:
825 release(lock, wlock) 824 release(lock, wlock)
831 commitctx() does not touch the working directory. 830 commitctx() does not touch the working directory.
832 """ 831 """
833 lock = self.lock() 832 lock = self.lock()
834 try: 833 try:
835 return self._commitctx(ctx, force=True, force_editor=False, 834 return self._commitctx(ctx, force=True, force_editor=False,
836 empty_ok=True, use_dirstate=False, 835 empty_ok=True, working=False)
837 update_dirstate=False)
838 finally: 836 finally:
839 lock.release() 837 lock.release()
840 838
841 def _commitctx(self, wctx, force=False, force_editor=False, empty_ok=False, 839 def _commitctx(self, wctx, force=False, force_editor=False, empty_ok=False,
842 use_dirstate=True, update_dirstate=True): 840 working=True):
843 tr = None 841 tr = None
844 valid = 0 # don't save the dirstate if this isn't set 842 valid = 0 # don't save the dirstate if this isn't set
845 try: 843 try:
846 commit = sorted(wctx.modified() + wctx.added()) 844 commit = sorted(wctx.modified() + wctx.added())
847 remove = wctx.removed() 845 remove = wctx.removed()
854 c1 = self.changelog.read(p1) 852 c1 = self.changelog.read(p1)
855 c2 = self.changelog.read(p2) 853 c2 = self.changelog.read(p2)
856 m1 = self.manifest.read(c1[0]).copy() 854 m1 = self.manifest.read(c1[0]).copy()
857 m2 = self.manifest.read(c2[0]) 855 m2 = self.manifest.read(c2[0])
858 856
859 if use_dirstate: 857 if working:
860 oldname = c1[5].get("branch") # stored in UTF-8 858 oldname = c1[5].get("branch") # stored in UTF-8
861 if (not commit and not remove and not force and p2 == nullid 859 if (not commit and not remove and not force and p2 == nullid
862 and branchname == oldname): 860 and branchname == oldname):
863 self.ui.status(_("nothing changed\n")) 861 self.ui.status(_("nothing changed\n"))
864 return None 862 return None
888 # flag changed, even if there was no content 886 # flag changed, even if there was no content
889 # change. 887 # change.
890 if m1.flags(f) != newflags: 888 if m1.flags(f) != newflags:
891 changed.append(f) 889 changed.append(f)
892 m1.set(f, newflags) 890 m1.set(f, newflags)
893 if use_dirstate: 891 if working:
894 self.dirstate.normal(f) 892 self.dirstate.normal(f)
895 893
896 except (OSError, IOError): 894 except (OSError, IOError):
897 if use_dirstate: 895 if working:
898 self.ui.warn(_("trouble committing %s!\n") % f) 896 self.ui.warn(_("trouble committing %s!\n") % f)
899 raise 897 raise
900 else: 898 else:
901 remove.append(f) 899 remove.append(f)
902 900
948 os.chdir(olddir) 946 os.chdir(olddir)
949 947
950 lines = [line.rstrip() for line in text.rstrip().splitlines()] 948 lines = [line.rstrip() for line in text.rstrip().splitlines()]
951 while lines and not lines[0]: 949 while lines and not lines[0]:
952 del lines[0] 950 del lines[0]
953 if not lines and use_dirstate: 951 if not lines and working:
954 raise util.Abort(_("empty commit message")) 952 raise util.Abort(_("empty commit message"))
955 text = '\n'.join(lines) 953 text = '\n'.join(lines)
956 954
957 self.changelog.delayupdate() 955 self.changelog.delayupdate()
958 n = self.changelog.add(mn, changed + removed, text, trp, p1, p2, 956 n = self.changelog.add(mn, changed + removed, text, trp, p1, p2,
964 tr.close() 962 tr.close()
965 963
966 if self.branchcache: 964 if self.branchcache:
967 self.branchtags() 965 self.branchtags()
968 966
969 if use_dirstate or update_dirstate: 967 if working:
970 self.dirstate.setparents(n) 968 self.dirstate.setparents(n)
971 if use_dirstate: 969 for f in removed:
972 for f in removed: 970 self.dirstate.forget(f)
973 self.dirstate.forget(f)
974 valid = 1 # our dirstate updates are complete 971 valid = 1 # our dirstate updates are complete
975 972
976 self.hook("commit", node=hex(n), parent1=xp1, parent2=xp2) 973 self.hook("commit", node=hex(n), parent1=xp1, parent2=xp2)
977 return n 974 return n
978 finally: 975 finally: