mercurial/hg.py
changeset 993 6f274afc05c7
parent 992 f859e9cba1b9
child 994 88c15682d9b0
equal deleted inserted replaced
992:f859e9cba1b9 993:6f274afc05c7
  1747                 get[f] = merge[f][1]
  1747                 get[f] = merge[f][1]
  1748             merge = {}
  1748             merge = {}
  1749 
  1749 
  1750         if linear_path or force:
  1750         if linear_path or force:
  1751             # we don't need to do any magic, just jump to the new rev
  1751             # we don't need to do any magic, just jump to the new rev
  1752             mode = 'n'
  1752             branch_merge = False
  1753             p1, p2 = p2, nullid
  1753             p1, p2 = p2, nullid
  1754         else:
  1754         else:
  1755             if not allow:
  1755             if not allow:
  1756                 self.ui.status("this update spans a branch" +
  1756                 self.ui.status("this update spans a branch" +
  1757                                " affecting the following files:\n")
  1757                                " affecting the following files:\n")
  1763                     self.ui.status(" %s%s\n" % (f, cf))
  1763                     self.ui.status(" %s%s\n" % (f, cf))
  1764                 self.ui.warn("aborting update spanning branches!\n")
  1764                 self.ui.warn("aborting update spanning branches!\n")
  1765                 self.ui.status("(use update -m to merge across branches" +
  1765                 self.ui.status("(use update -m to merge across branches" +
  1766                                " or -C to lose changes)\n")
  1766                                " or -C to lose changes)\n")
  1767                 return 1
  1767                 return 1
  1768             mode = 'm'
  1768             branch_merge = True
  1769 
  1769 
  1770         if moddirstate:
  1770         if moddirstate:
  1771             self.dirstate.setparents(p1, p2)
  1771             self.dirstate.setparents(p1, p2)
  1772 
  1772 
  1773         # get the files we don't need to change
  1773         # get the files we don't need to change
  1782             except IOError:
  1782             except IOError:
  1783                 os.makedirs(os.path.dirname(self.wjoin(f)))
  1783                 os.makedirs(os.path.dirname(self.wjoin(f)))
  1784                 self.wfile(f, "w").write(t)
  1784                 self.wfile(f, "w").write(t)
  1785             util.set_exec(self.wjoin(f), mf2[f])
  1785             util.set_exec(self.wjoin(f), mf2[f])
  1786             if moddirstate:
  1786             if moddirstate:
  1787                 if mode == 'm':
  1787                 if branch_merge:
  1788                     self.dirstate.update([f], 'n', st_mtime=0)
  1788                     self.dirstate.update([f], 'n', st_mtime=-1)
  1789                 else:
  1789                 else:
  1790                     self.dirstate.update([f], 'n')
  1790                     self.dirstate.update([f], 'n')
  1791 
  1791 
  1792         # merge the tricky bits
  1792         # merge the tricky bits
  1793         files = merge.keys()
  1793         files = merge.keys()
  1794         files.sort()
  1794         files.sort()
  1795         for f in files:
  1795         for f in files:
  1796             self.ui.status("merging %s\n" % f)
  1796             self.ui.status("merging %s\n" % f)
  1797             m, o, flag = merge[f]
  1797             my, other, flag = merge[f]
  1798             self.merge3(f, m, o)
  1798             self.merge3(f, my, other)
  1799             util.set_exec(self.wjoin(f), flag)
  1799             util.set_exec(self.wjoin(f), flag)
  1800             if moddirstate:
  1800             if moddirstate:
  1801                 if mode == 'm':
  1801                 if branch_merge:
  1802                     # only update dirstate on branch merge, otherwise we
  1802                     # We've done a branch merge, mark this file as merged
  1803                     # could mark files with changes as unchanged
  1803                     # so that we properly record the merger later
  1804                     self.dirstate.update([f], mode)
  1804                     self.dirstate.update([f], 'm')
  1805                 elif p2 == nullid:
       
  1806                     # update dirstate from parent1's manifest
       
  1807                     m1n = self.changelog.read(p1)[0]
       
  1808                     m1 = self.manifest.read(m1n)
       
  1809                     f_len = len(self.file(f).read(m1[f]))
       
  1810                     self.dirstate.update([f], mode, st_size=f_len, st_mtime=0)
       
  1811                 else:
  1805                 else:
  1812                     self.ui.warn("Second parent without branch merge!?\n"
  1806                     # We've update-merged a locally modified file, so
  1813                                  "Dirstate for file %s may be wrong.\n" % f)
  1807                     # we set the dirstate to emulate a normal checkout
       
  1808                     # of that file some time in the past. Thus our
       
  1809                     # merge will appear as a normal local file
       
  1810                     # modification.
       
  1811                     f_len = len(self.file(f).read(other))
       
  1812                     self.dirstate.update([f], 'n', st_size=f_len, st_mtime=-1)
  1814 
  1813 
  1815         remove.sort()
  1814         remove.sort()
  1816         for f in remove:
  1815         for f in remove:
  1817             self.ui.note("removing %s\n" % f)
  1816             self.ui.note("removing %s\n" % f)
  1818             try:
  1817             try:
  1821                 self.ui.warn("update failed to remove %s: %s!\n" % (f, inst))
  1820                 self.ui.warn("update failed to remove %s: %s!\n" % (f, inst))
  1822             # try removing directories that might now be empty
  1821             # try removing directories that might now be empty
  1823             try: os.removedirs(os.path.dirname(self.wjoin(f)))
  1822             try: os.removedirs(os.path.dirname(self.wjoin(f)))
  1824             except: pass
  1823             except: pass
  1825         if moddirstate:
  1824         if moddirstate:
  1826             if mode == 'n':
  1825             if branch_merge:
       
  1826                 self.dirstate.update(remove, 'r')
       
  1827             else:
  1827                 self.dirstate.forget(remove)
  1828                 self.dirstate.forget(remove)
  1828             else:
       
  1829                 self.dirstate.update(remove, 'r')
       
  1830 
  1829 
  1831     def merge3(self, fn, my, other):
  1830     def merge3(self, fn, my, other):
  1832         """perform a 3-way merge in the working directory"""
  1831         """perform a 3-way merge in the working directory"""
  1833 
  1832 
  1834         def temp(prefix, node):
  1833         def temp(prefix, node):