mercurial/cmdutil.py
changeset 42856 3cf091843b4f
parent 42643 ce52377102db
child 42892 a65c4715fb5d
equal deleted inserted replaced
42855:1fd530b1e1cf 42856:3cf091843b4f
   179     hunkclasses = (crecordmod.uihunk, patch.recordhunk)
   179     hunkclasses = (crecordmod.uihunk, patch.recordhunk)
   180     return isinstance(x, hunkclasses)
   180     return isinstance(x, hunkclasses)
   181 
   181 
   182 def newandmodified(chunks, originalchunks):
   182 def newandmodified(chunks, originalchunks):
   183     newlyaddedandmodifiedfiles = set()
   183     newlyaddedandmodifiedfiles = set()
       
   184     alsorestore = set()
   184     for chunk in chunks:
   185     for chunk in chunks:
   185         if (ishunk(chunk) and chunk.header.isnewfile() and chunk not in
   186         if (ishunk(chunk) and chunk.header.isnewfile() and chunk not in
   186             originalchunks):
   187             originalchunks):
   187             newlyaddedandmodifiedfiles.add(chunk.header.filename())
   188             newlyaddedandmodifiedfiles.add(chunk.header.filename())
   188     return newlyaddedandmodifiedfiles
   189             alsorestore.update(set(chunk.header.files()) -
       
   190                                set([chunk.header.filename()]))
       
   191     return newlyaddedandmodifiedfiles, alsorestore
   189 
   192 
   190 def parsealiases(cmd):
   193 def parsealiases(cmd):
   191     return cmd.split("|")
   194     return cmd.split("|")
   192 
   195 
   193 def setupwrapcolorwrite(ui):
   196 def setupwrapcolorwrite(ui):
   324             raise error.Abort(_('error parsing patch: %s') % err)
   327             raise error.Abort(_('error parsing patch: %s') % err)
   325         opts.update(newopts)
   328         opts.update(newopts)
   326 
   329 
   327         # We need to keep a backup of files that have been newly added and
   330         # We need to keep a backup of files that have been newly added and
   328         # modified during the recording process because there is a previous
   331         # modified during the recording process because there is a previous
   329         # version without the edit in the workdir
   332         # version without the edit in the workdir. We also will need to restore
   330         newlyaddedandmodifiedfiles = newandmodified(chunks, originalchunks)
   333         # files that were the sources of renames so that the patch application
       
   334         # works.
       
   335         newlyaddedandmodifiedfiles, alsorestore = newandmodified(chunks,
       
   336                                                                  originalchunks)
   331         contenders = set()
   337         contenders = set()
   332         for h in chunks:
   338         for h in chunks:
   333             try:
   339             try:
   334                 contenders.update(set(h.files()))
   340                 contenders.update(set(h.files()))
   335             except AttributeError:
   341             except AttributeError:
   390 
   396 
   391             [os.unlink(repo.wjoin(c)) for c in newlyaddedandmodifiedfiles]
   397             [os.unlink(repo.wjoin(c)) for c in newlyaddedandmodifiedfiles]
   392             # 3a. apply filtered patch to clean repo  (clean)
   398             # 3a. apply filtered patch to clean repo  (clean)
   393             if backups:
   399             if backups:
   394                 # Equivalent to hg.revert
   400                 # Equivalent to hg.revert
   395                 m = scmutil.matchfiles(repo, backups.keys())
   401                 m = scmutil.matchfiles(repo, set(backups.keys()) | alsorestore)
   396                 mergemod.update(repo, repo.dirstate.p1(), branchmerge=False,
   402                 mergemod.update(repo, repo.dirstate.p1(), branchmerge=False,
   397                                 force=True, matcher=m)
   403                                 force=True, matcher=m)
   398 
   404 
   399             # 3b. (apply)
   405             # 3b. (apply)
   400             if dopatch:
   406             if dopatch:
  3170                 chunks = patch.reversehunks(chunks)
  3176                 chunks = patch.reversehunks(chunks)
  3171 
  3177 
  3172         except error.PatchError as err:
  3178         except error.PatchError as err:
  3173             raise error.Abort(_('error parsing patch: %s') % err)
  3179             raise error.Abort(_('error parsing patch: %s') % err)
  3174 
  3180 
  3175         newlyaddedandmodifiedfiles = newandmodified(chunks, originalchunks)
  3181         # FIXME: when doing an interactive revert of a copy, there's no way of
       
  3182         # performing a partial revert of the added file, the only option is
       
  3183         # "remove added file <name> (Yn)?", so we don't need to worry about the
       
  3184         # alsorestore value. Ideally we'd be able to partially revert
       
  3185         # copied/renamed files.
       
  3186         newlyaddedandmodifiedfiles, unusedalsorestore = newandmodified(
       
  3187                 chunks, originalchunks)
  3176         if tobackup is None:
  3188         if tobackup is None:
  3177             tobackup = set()
  3189             tobackup = set()
  3178         # Apply changes
  3190         # Apply changes
  3179         fp = stringio()
  3191         fp = stringio()
  3180         # chunks are serialized per file, but files aren't sorted
  3192         # chunks are serialized per file, but files aren't sorted