# HG changeset patch # User Martin von Zweigbergk # Date 1552327175 25200 # Node ID 66ad7e32011f2739fca408d4ab0e674a31135f28 # Parent 3feda1e779d48c0e66c28a4697f765b6c283fdff 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 diff -r 3feda1e779d4 -r 66ad7e32011f hgext/fix.py --- 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): diff -r 3feda1e779d4 -r 66ad7e32011f tests/test-fix.t --- 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 ..