# HG changeset patch # User Siddharth Agarwal # Date 1451733661 28800 # Node ID 57c0d4888ca82918402037cf5251958cd11994c1 # Parent af13eaf9ab8cb8668dd68b74416aa5bba51d343b batchget: add support for backing up files We're going to use this in an upcoming feature. diff -r af13eaf9ab8c -r 57c0d4888ca8 mercurial/merge.py --- a/mercurial/merge.py Sat Jan 02 03:02:57 2016 -0800 +++ b/mercurial/merge.py Sat Jan 02 03:21:01 2016 -0800 @@ -26,6 +26,7 @@ error, filemerge, obsolete, + scmutil, subrepo, util, worker, @@ -971,12 +972,27 @@ verbose = repo.ui.verbose fctx = mctx.filectx wwrite = repo.wwrite + ui = repo.ui i = 0 - for f, args, msg in actions: + for f, (flags, backup), msg in actions: repo.ui.debug(" %s: %s -> g\n" % (f, msg)) if verbose: repo.ui.note(_("getting %s\n") % f) - wwrite(f, fctx(f).data(), args[0]) + + if backup: + absf = repo.wjoin(f) + orig = scmutil.origpath(ui, repo, absf) + try: + # TODO Mercurial has always aborted if an untracked directory + # is replaced by a tracked file, or generally with + # file/directory merges. This needs to be sorted out. + if repo.wvfs.isfileorlink(f): + util.rename(absf, orig) + except OSError as e: + if e.errno != errno.ENOENT: + raise + + wwrite(f, fctx(f).data(), flags) if i == 100: yield i, f i = 0