mercurial/merge.py
changeset 21080 04540a8499a3
parent 21024 7731a2281cf0
child 21081 ffd7b6ce46ff
equal deleted inserted replaced
21079:b02ab6486a78 21080:04540a8499a3
   374             raise util.Abort(_("case-folding collision between %s and %s")
   374             raise util.Abort(_("case-folding collision between %s and %s")
   375                              % (f, foldmap[fold]))
   375                              % (f, foldmap[fold]))
   376         foldmap[fold] = f
   376         foldmap[fold] = f
   377 
   377 
   378 def manifestmerge(repo, wctx, p2, pa, branchmerge, force, partial,
   378 def manifestmerge(repo, wctx, p2, pa, branchmerge, force, partial,
   379                   acceptremote=False):
   379                   acceptremote, followcopies):
   380     """
   380     """
   381     Merge p1 and p2 with ancestor pa and generate merge action list
   381     Merge p1 and p2 with ancestor pa and generate merge action list
   382 
   382 
   383     branchmerge and force are as passed in to update
   383     branchmerge and force are as passed in to update
   384     partial = function to filter file lists
   384     partial = function to filter file lists
   385     acceptremote = accept the incoming changes without prompting
   385     acceptremote = accept the incoming changes without prompting
   386     """
   386     """
   387 
   387 
   388     overwrite = force and not branchmerge
       
   389     actions, copy, movewithdir = [], {}, {}
   388     actions, copy, movewithdir = [], {}, {}
   390 
       
   391     followcopies = False
       
   392     if overwrite:
       
   393         pa = wctx
       
   394     elif pa == p2: # backwards
       
   395         pa = wctx.p1()
       
   396     elif not branchmerge and not wctx.dirty(missing=True):
       
   397         pass
       
   398     elif pa and repo.ui.configbool("merge", "followcopies", True):
       
   399         followcopies = True
       
   400 
   389 
   401     # manifests fetched in order are going to be faster, so prime the caches
   390     # manifests fetched in order are going to be faster, so prime the caches
   402     [x.manifest() for x in
   391     [x.manifest() for x in
   403      sorted(wctx.parents() + [p2, pa], key=lambda x: x.rev())]
   392      sorted(wctx.parents() + [p2, pa], key=lambda x: x.rev())]
   404 
   393 
   728     ms.commit()
   717     ms.commit()
   729     progress(_updating, None, total=numupdates, unit=_files)
   718     progress(_updating, None, total=numupdates, unit=_files)
   730 
   719 
   731     return updated, merged, removed, unresolved
   720     return updated, merged, removed, unresolved
   732 
   721 
   733 def calculateupdates(repo, tctx, mctx, ancestor, branchmerge, force, partial,
   722 def calculateupdates(repo, wctx, mctx, ancestor, branchmerge, force, partial,
   734                      acceptremote=False):
   723                      acceptremote, followcopies):
   735     "Calculate the actions needed to merge mctx into tctx"
   724     "Calculate the actions needed to merge mctx into wctx using ancestor"
   736     actions = []
   725 
   737     actions += manifestmerge(repo, tctx, mctx,
   726     actions = manifestmerge(repo, wctx, mctx,
   738                              ancestor,
   727                              ancestor,
   739                              branchmerge, force,
   728                              branchmerge, force,
   740                              partial, acceptremote)
   729                              partial, acceptremote, followcopies)
   741 
   730 
   742     # Filter out prompts.
   731     # Filter out prompts.
   743     newactions, prompts = [], []
   732     newactions, prompts = [], []
   744     for a in actions:
   733     for a in actions:
   745         if a[1] in ("cd", "dc"):
   734         if a[1] in ("cd", "dc"):
   763                   "use (c)hanged version or leave (d)eleted?"
   752                   "use (c)hanged version or leave (d)eleted?"
   764                   "$$ &Changed $$ &Deleted") % f, 0) == 0:
   753                   "$$ &Changed $$ &Deleted") % f, 0) == 0:
   765                 newactions.append((f, "g", (flags,), "prompt recreating"))
   754                 newactions.append((f, "g", (flags,), "prompt recreating"))
   766         else: assert False, m
   755         else: assert False, m
   767 
   756 
   768     if tctx.rev() is None:
   757     if wctx.rev() is None:
   769         newactions += _forgetremoved(tctx, mctx, branchmerge)
   758         newactions += _forgetremoved(wctx, mctx, branchmerge)
   770 
   759 
   771     return newactions
   760     return newactions
   772 
   761 
   773 def recordupdates(repo, actions, branchmerge):
   762 def recordupdates(repo, actions, branchmerge):
   774     "record merge actions to the dirstate"
   763     "record merge actions to the dirstate"
   988                         raise util.Abort(msg, hint=hint)
   977                         raise util.Abort(msg, hint=hint)
   989                 else:
   978                 else:
   990                     # Allow jumping branches if clean and specific rev given
   979                     # Allow jumping branches if clean and specific rev given
   991                     pa = p1
   980                     pa = p1
   992 
   981 
       
   982         followcopies = False
       
   983         if overwrite:
       
   984             pa = wc
       
   985         elif pa == p2: # backwards
       
   986             pa = wc.p1()
       
   987         elif not branchmerge and not wc.dirty(missing=True):
       
   988             pass
       
   989         elif pa and repo.ui.configbool("merge", "followcopies", True):
       
   990             followcopies = True
       
   991 
   993         ### calculate phase
   992         ### calculate phase
   994         actions = calculateupdates(repo, wc, p2, pa,
   993         actions = calculateupdates(repo, wc, p2, pa, branchmerge, force,
   995                                    branchmerge, force, partial, mergeancestor)
   994                                    partial, mergeancestor, followcopies)
   996 
   995 
   997         ### apply phase
   996         ### apply phase
   998         if not branchmerge: # just jump to the new rev
   997         if not branchmerge: # just jump to the new rev
   999             fp1, fp2, xp1, xp2 = fp2, nullid, xp2, ''
   998             fp1, fp2, xp1, xp2 = fp2, nullid, xp2, ''
  1000         if not partial:
   999         if not partial: