comparison mercurial/cmdutil.py @ 27391:4eeef1b2d689

merge with stable
author Matt Mackall <mpm@selenic.com>
date Wed, 16 Dec 2015 17:40:01 -0600
parents 43c00ca887d1 d9e3ebe56970
children c84a07530040
comparison
equal deleted inserted replaced
27390:8bc6ece9a2e1 27391:4eeef1b2d689
5 # This software may be used and distributed according to the terms of the 5 # This software may be used and distributed according to the terms of the
6 # GNU General Public License version 2 or any later version. 6 # GNU General Public License version 2 or any later version.
7 7
8 from node import hex, bin, nullid, nullrev, short 8 from node import hex, bin, nullid, nullrev, short
9 from i18n import _ 9 from i18n import _
10 import os, sys, errno, re, tempfile, cStringIO, shutil 10 import os, sys, errno, re, tempfile, cStringIO
11 import util, scmutil, templater, patch, error, templatekw, revlog, copies 11 import util, scmutil, templater, patch, error, templatekw, revlog, copies
12 import match as matchmod 12 import match as matchmod
13 import repair, graphmod, revset, phases, obsolete, pathutil 13 import repair, graphmod, revset, phases, obsolete, pathutil
14 import changelog 14 import changelog
15 import bookmarks 15 import bookmarks
165 for f in tobackup: 165 for f in tobackup:
166 fd, tmpname = tempfile.mkstemp(prefix=f.replace('/', '_')+'.', 166 fd, tmpname = tempfile.mkstemp(prefix=f.replace('/', '_')+'.',
167 dir=backupdir) 167 dir=backupdir)
168 os.close(fd) 168 os.close(fd)
169 ui.debug('backup %r as %r\n' % (f, tmpname)) 169 ui.debug('backup %r as %r\n' % (f, tmpname))
170 util.copyfile(repo.wjoin(f), tmpname) 170 util.copyfile(repo.wjoin(f), tmpname, copystat=True)
171 shutil.copystat(repo.wjoin(f), tmpname)
172 backups[f] = tmpname 171 backups[f] = tmpname
173 172
174 fp = cStringIO.StringIO() 173 fp = cStringIO.StringIO()
175 for c in chunks: 174 for c in chunks:
176 fname = c.filename() 175 fname = c.filename()
215 # without normallookup, restoring timestamp 214 # without normallookup, restoring timestamp
216 # may cause partially committed files 215 # may cause partially committed files
217 # to be treated as unmodified 216 # to be treated as unmodified
218 dirstate.normallookup(realname) 217 dirstate.normallookup(realname)
219 218
220 util.copyfile(tmpname, repo.wjoin(realname)) 219 # copystat=True here and above are a hack to trick any
221 # Our calls to copystat() here and above are a 220 # editors that have f open that we haven't modified them.
222 # hack to trick any editors that have f open that
223 # we haven't modified them.
224 # 221 #
225 # Also note that this racy as an editor could 222 # Also note that this racy as an editor could notice the
226 # notice the file's mtime before we've finished 223 # file's mtime before we've finished writing it.
227 # writing it. 224 util.copyfile(tmpname, repo.wjoin(realname), copystat=True)
228 shutil.copystat(tmpname, repo.wjoin(realname))
229 os.unlink(tmpname) 225 os.unlink(tmpname)
230 if tobackup: 226 if tobackup:
231 os.rmdir(backupdir) 227 os.rmdir(backupdir)
232 except OSError: 228 except OSError:
233 pass 229 pass