fix: use scmutil.movedirstate() instead of reimplementing stable
authorMartin von Zweigbergk <martinvonz@google.com>
Mon, 11 Mar 2019 10:59:35 -0700
branchstable
changeset 47767 66ad7e32011f
parent 47766 3feda1e779d4
child 47768 c2b8ad34d245
fix: use scmutil.movedirstate() instead of reimplementing I wrote this patch 2 years ago as a little cleanup. I wanted to generally used `scmutil.movedirstate()` instead of manually updating the dirstate because that is easy to get wrong. I didn't know until today that the current code had a bug. So I added the test case two patches before this one and dusted off this one patch. This is a little slower than the previous code, as it diffs two manifests. However, it fixes the bug and I don't think it's going to be noticeably slower anyway. Differential Revision: https://phab.mercurial-scm.org/D11210
hgext/fix.py
tests/test-fix.t
--- a/hgext/fix.py	Mon Mar 11 10:56:56 2019 -0700
+++ b/hgext/fix.py	Mon Mar 11 10:59:35 2019 -0700
@@ -759,13 +759,12 @@
     for path, data in pycompat.iteritems(filedata):
         fctx = ctx[path]
         fctx.write(data, fctx.flags())
-        if repo.dirstate[path] == b'n':
-            repo.dirstate.set_possibly_dirty(path)
 
     oldp1 = repo.dirstate.p1()
     newp1 = replacements.get(oldp1, oldp1)
     if newp1 != oldp1:
-        repo.setparents(newp1, nullid)
+        with repo.dirstate.parentchange():
+            scmutil.movedirstate(repo, repo[newp1])
 
 
 def replacerev(ui, repo, ctx, filedata, replacements):
--- a/tests/test-fix.t	Mon Mar 11 10:56:56 2019 -0700
+++ b/tests/test-fix.t	Mon Mar 11 10:59:35 2019 -0700
@@ -370,7 +370,6 @@
   M hello.whole
   $ hg fix -s . *
   $ hg st
-  M hello.whole (known-bad-output !)
   $ hg diff
 
   $ cd ..