Mercurial > hg-stable
changeset 31218:fc57a8b95f1b
dirstate: avoid unnecessary load+dump during backup
Previously, dirstate.savebackup unconditionally dumps the dirstate map to
disk. It may require loading dirstate first to be able to dump it. Those
operations could be expensive if the dirstate is big, and could be avoided
if we know the dirstate file is up-to-date.
This patch avoids the read and write if the dirstate is clean. In that case,
we just do a plain copy without any serialization.
This should make commands which use transactions but do not touch dirstate
faster. For example, "hg bookmark -r REV NAME".
author | Jun Wu <quark@fb.com> |
---|---|
date | Wed, 01 Mar 2017 18:21:06 -0800 |
parents | 1ef37b16b8e8 |
children | dd2364f5180a |
files | mercurial/dirstate.py |
diffstat | 1 files changed, 3 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/dirstate.py Wed Mar 01 17:59:21 2017 -0800 +++ b/mercurial/dirstate.py Wed Mar 01 18:21:06 2017 -0800 @@ -1220,8 +1220,9 @@ # use '_writedirstate' instead of 'write' to write changes certainly, # because the latter omits writing out if transaction is running. # output file will be used to create backup of dirstate at this point. - self._writedirstate(self._opener(filename, "w", atomictemp=True, - checkambig=True)) + if self._dirty or not self._opener.exists(filename): + self._writedirstate(self._opener(filename, "w", atomictemp=True, + checkambig=True)) if tr: # ensure that subsequent tr.writepending returns True for