# HG changeset patch # User Martin von Zweigbergk # Date 2019-03-11 17:59:35 # 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 --git a/hgext/fix.py b/hgext/fix.py --- a/hgext/fix.py +++ b/hgext/fix.py @@ -759,13 +759,12 @@ def writeworkingdir(repo, ctx, filedata, 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 --git a/tests/test-fix.t b/tests/test-fix.t --- a/tests/test-fix.t +++ b/tests/test-fix.t @@ -370,7 +370,6 @@ it clean. M hello.whole $ hg fix -s . * $ hg st - M hello.whole (known-bad-output !) $ hg diff $ cd ..