mercurial/merge.py
changeset 3248 751840e739a1
parent 3247 7a0d70b69d74
child 3249 f05c182430a0
equal deleted inserted replaced
3247:7a0d70b69d74 3248:751840e739a1
   162                 for mf in match[of]:
   162                 for mf in match[of]:
   163                     checkpair(c, mf, m1)
   163                     checkpair(c, mf, m1)
   164 
   164 
   165     return copy
   165     return copy
   166 
   166 
   167 def filtermanifest(man, partial):
   167 def manifestmerge(ui, m1, m2, ma, overwrite, backwards, partial):
   168     if partial:
       
   169         for k in man.keys():
       
   170             if not partial(k): del man[k]
       
   171 
       
   172 def manifestmerge(ui, m1, m2, ma, overwrite, backwards):
       
   173     """
   168     """
   174     Merge manifest m1 with m2 using ancestor ma and generate merge action list
   169     Merge manifest m1 with m2 using ancestor ma and generate merge action list
   175     """
   170     """
   176 
   171 
   177     def fmerge(f):
   172     def fmerge(f):
   185         ui.debug(" %s: %s -> %s\n" % (f, msg, m))
   180         ui.debug(" %s: %s -> %s\n" % (f, msg, m))
   186         action.append((f, m) + args)
   181         action.append((f, m) + args)
   187 
   182 
   188     # Compare manifests
   183     # Compare manifests
   189     for f, n in m1.iteritems():
   184     for f, n in m1.iteritems():
       
   185         if partial and not partial(f):
       
   186             continue
   190         if f in m2:
   187         if f in m2:
   191             # are files different?
   188             # are files different?
   192             if n != m2[f]:
   189             if n != m2[f]:
   193                 a = ma.get(f, nullid)
   190                 a = ma.get(f, nullid)
   194                 # are both different from the ancestor?
   191                 # are both different from the ancestor?
   204                     act("update permissions", f, "e", m2.execf(f))
   201                     act("update permissions", f, "e", m2.execf(f))
   205             # contents same, check mode bits
   202             # contents same, check mode bits
   206             elif m1.execf(f) != m2.execf(f):
   203             elif m1.execf(f) != m2.execf(f):
   207                 if overwrite or fmerge(f) != m1.execf(f):
   204                 if overwrite or fmerge(f) != m1.execf(f):
   208                     act("update permissions", f, "e", m2.execf(f))
   205                     act("update permissions", f, "e", m2.execf(f))
   209             del m2[f]
       
   210         elif f in ma:
   206         elif f in ma:
   211             if n != ma[f] and not overwrite:
   207             if n != ma[f] and not overwrite:
   212                 if ui.prompt(
   208                 if ui.prompt(
   213                     (_(" local changed %s which remote deleted\n") % f) +
   209                     (_(" local changed %s which remote deleted\n") % f) +
   214                     _("(k)eep or (d)elete?"), _("[kd]"), _("k")) == _("d"):
   210                     _("(k)eep or (d)elete?"), _("[kd]"), _("k")) == _("d"):
   219             # file is created on branch or in working directory
   215             # file is created on branch or in working directory
   220             if (overwrite and n[20:] != "u") or (backwards and not n[20:]):
   216             if (overwrite and n[20:] != "u") or (backwards and not n[20:]):
   221                 act("remote deleted", f, "r")
   217                 act("remote deleted", f, "r")
   222 
   218 
   223     for f, n in m2.iteritems():
   219     for f, n in m2.iteritems():
       
   220         if partial and not partial(f):
       
   221             continue
       
   222         if f in m1:
       
   223             continue
   224         if f in ma:
   224         if f in ma:
   225             if overwrite or backwards:
   225             if overwrite or backwards:
   226                 act("recreating", f, "g", m2.execf(f), n)
   226                 act("recreating", f, "g", m2.execf(f), n)
   227             elif n != ma[f]:
   227             elif n != ma[f]:
   228                 if ui.prompt(
   228                 if ui.prompt(
   335 
   335 
   336     if branchmerge and not forcemerge:
   336     if branchmerge and not forcemerge:
   337         if wc.modified() or wc.added() or wc.removed():
   337         if wc.modified() or wc.added() or wc.removed():
   338             raise util.Abort(_("outstanding uncommitted changes"))
   338             raise util.Abort(_("outstanding uncommitted changes"))
   339 
   339 
   340     m1 = wc.manifest().copy()
   340     m1 = wc.manifest()
   341     m2 = p2.manifest().copy()
   341     m2 = p2.manifest()
   342     ma = pa.manifest()
   342     ma = pa.manifest()
   343 
   343 
   344     # resolve the manifest to determine which files
   344     # resolve the manifest to determine which files
   345     # we care about merging
   345     # we care about merging
   346     repo.ui.note(_("resolving manifests\n"))
   346     repo.ui.note(_("resolving manifests\n"))
   349     repo.ui.debug(_(" ancestor %s local %s remote %s\n") % (p1, p2, pa))
   349     repo.ui.debug(_(" ancestor %s local %s remote %s\n") % (p1, p2, pa))
   350 
   350 
   351     action = []
   351     action = []
   352     copy = {}
   352     copy = {}
   353 
   353 
   354     filtermanifest(m1, partial)
       
   355     filtermanifest(m2, partial)
       
   356 
       
   357     if not force:
   354     if not force:
   358         checkunknown(repo, m2, wc)
   355         checkunknown(repo, m2, wc)
   359     if not branchmerge:
   356     if not branchmerge:
   360         action += forgetremoved(m2, wc)
   357         action += forgetremoved(m2, wc)
   361     if not (backwards or overwrite):
   358     if not (backwards or overwrite):
   362         copy = findcopies(repo, m1, m2, pa.rev())
   359         copy = findcopies(repo, m1, m2, pa.rev())
   363 
   360 
   364     action += manifestmerge(repo.ui, m1, m2, ma, overwrite, backwards)
   361     action += manifestmerge(repo.ui, m1, m2, ma, overwrite, backwards, partial)
   365     del m1, m2, ma
       
   366 
   362 
   367     ### apply phase
   363     ### apply phase
   368 
   364 
   369     if not branchmerge:
   365     if not branchmerge:
   370         # we don't need to do any magic, just jump to the new rev
   366         # we don't need to do any magic, just jump to the new rev