Patchwork D152: repo: skip invalidation of changelog if it has 'delayed' changes (API)

login
register
mail settings
Submitter phabricator
Date Aug. 8, 2017, 6:24 p.m.
Message ID <8523758141eb87566659846e2b5610f9@localhost.localdomain>
Download mbox | patch
Permalink /patch/22759/
State Not Applicable
Headers show

Comments

phabricator - Aug. 8, 2017, 6:24 p.m.
This revision was automatically updated to reflect the committed changes.
Closed by commit rHG01a1c4e66816: repo: skip invalidation of changelog if it has 'delayed' changes (API) (authored by martinvonz).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D152?vs=619&id=633

REVISION DETAIL
  https://phab.mercurial-scm.org/D152

AFFECTED FILES
  mercurial/localrepo.py
  tests/test-context.py

CHANGE DETAILS




To: martinvonz, #hg-reviewers, quark, indygreg
Cc: indygreg, quark, mercurial-devel

Patch

diff --git a/tests/test-context.py b/tests/test-context.py
--- a/tests/test-context.py
+++ b/tests/test-context.py
@@ -179,3 +179,14 @@ 
             print('data mismatch')
     except Exception as ex:
         print('cannot read data: %r' % ex)
+
+with repo.wlock(), repo.lock(), repo.transaction('test'):
+    with open(b'4', 'wb') as f:
+        f.write(b'4')
+    repo.dirstate.normal('4')
+    repo.commit('4')
+    revsbefore = len(repo.changelog)
+    repo.invalidate(clearfilecache=True)
+    revsafter = len(repo.changelog)
+    if revsbefore != revsafter:
+        print('changeset lost by repo.invalidate()')
diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -1461,6 +1461,13 @@ 
             # dirstate is invalidated separately in invalidatedirstate()
             if k == 'dirstate':
                 continue
+            if (k == 'changelog' and
+                self.currenttransaction() and
+                self.changelog._delayed):
+                # The changelog object may store unwritten revisions. We don't
+                # want to lose them.
+                # TODO: Solve the problem instead of working around it.
+                continue
 
             if clearfilecache:
                 del self._filecache[k]