# HG changeset patch # User FUJIWARA Katsunori # Date 1445012133 -32400 # Node ID 3c1d297fe929b92945d83c55bd0ce63df24a4282 # Parent 8af610bce2399efbf9e5e8a0ed7e751f47a31ea0 dirstateguard: remove layering violation around saving/restoring backup This violation, which passes 'repo' object to dirstate, was introduced by 59b5e8844eb0 and 020b12d591f3. diff -r 8af610bce239 -r 3c1d297fe929 mercurial/cmdutil.py --- a/mercurial/cmdutil.py Thu Oct 15 15:20:44 2015 -0700 +++ b/mercurial/cmdutil.py Sat Oct 17 01:15:33 2015 +0900 @@ -3339,7 +3339,7 @@ def __init__(self, repo, name): self._repo = repo self._suffix = '.backup.%s.%d' % (name, id(self)) - repo.dirstate._savebackup(repo, self._suffix) + repo.dirstate._savebackup(repo.currenttransaction(), self._suffix) self._active = True self._closed = False @@ -3357,12 +3357,14 @@ % self._suffix) raise error.Abort(msg) - self._repo.dirstate._clearbackup(self._repo, self._suffix) + self._repo.dirstate._clearbackup(self._repo.currenttransaction(), + self._suffix) self._active = False self._closed = True def _abort(self): - self._repo.dirstate._restorebackup(self._repo, self._suffix) + self._repo.dirstate._restorebackup(self._repo.currenttransaction(), + self._suffix) self._active = False def release(self): diff -r 8af610bce239 -r 3c1d297fe929 mercurial/dirstate.py --- a/mercurial/dirstate.py Thu Oct 15 15:20:44 2015 -0700 +++ b/mercurial/dirstate.py Sat Oct 17 01:15:33 2015 +0900 @@ -1123,22 +1123,21 @@ return list(files) return [f for f in dmap if match(f)] - def _actualfilename(self, repo): - if repo.currenttransaction(): + def _actualfilename(self, tr): + if tr: return self._pendingfilename else: return self._filename - def _savebackup(self, repo, suffix): + def _savebackup(self, tr, suffix): '''Save current dirstate into backup file with suffix''' - filename = self._actualfilename(repo) + filename = self._actualfilename(tr) # 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)) - tr = repo.currenttransaction() if tr: # ensure that subsequent tr.writepending returns True for # changes written out above, even if dirstate is never @@ -1153,15 +1152,15 @@ self._opener.write(filename + suffix, self._opener.tryread(filename)) - def _restorebackup(self, repo, suffix): + def _restorebackup(self, tr, suffix): '''Restore dirstate by backup file with suffix''' # this "invalidate()" prevents "wlock.release()" from writing # changes of dirstate out after restoring from backup file self.invalidate() - filename = self._actualfilename(repo) + filename = self._actualfilename(tr) self._opener.rename(filename + suffix, filename) - def _clearbackup(self, repo, suffix): + def _clearbackup(self, tr, suffix): '''Clear backup file with suffix''' - filename = self._actualfilename(repo) + filename = self._actualfilename(tr) self._opener.unlink(filename + suffix)