[Updated] D11177: fix: use `set_possibly_dirty` instead of `normallookup`

martinvonz (Martin von Zweigbergk) phabricator at mercurial-scm.org
Mon Aug 23 20:44:09 UTC 2021


martinvonz added a comment.


  I noticed that this broke `hg fix` in some cases. I wrote a test case to show the difference (replace `set_possibly_dirty` by `normallookup` to see the different behavior)
  
    import os
    from mercurial import (
        hg,
        ui as uimod,
    )
    
    ui = uimod.ui.load()
    
    repo = hg.repository(ui, b'test1', create=True)
    os.chdir('test1')
    
    # Add a commit with file "foo"
    with open('foo', 'wb') as f:
        f.write(b'foo\n')
    repo[None].add([b'foo'])
    node1 = repo.commit(text=b'commit1', date=b"0 0")
    
    # Modify file "foo" in a second commit
    with open('foo', 'wb') as f:
        f.write(b'foo2\n')
    repo.commit(text=b'commit2', date=b"0 0")
    
    # Simulate `hg checkout` of commit 1 by reverting the contents on disk
    # and calling dirstate.set_possibly_dirty().
    with open('foo', 'wb') as f:
        f.write(b'foo\n')
    with repo.wlock(), repo.lock(), repo.transaction(b'test') as tr:
        with repo.dirstate.parentchange():
            repo.dirstate.setparents(node1, repo.nullid)
        repo.dirstate.set_possibly_dirty(b'foo')
        # repo.dirstate.normallookup(b'foo')
        repo.dirstate.write(tr)
    
    repo = hg.repository(ui, b'.')
    print("status: %r" % repo.status())
  
  Is that difference intended?
  
  My `hg fix` case that broke was later fixed by D11210 <https://phab.mercurial-scm.org/D11210>, so maybe it was just that `hg fix` used the API incorrectly to start with?

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D11177/new/

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

To: marmoute, #hg-reviewers, Alphare
Cc: martinvonz, mercurial-patches
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mercurial-scm.org/pipermail/mercurial-patches/attachments/20210823/02cecb2d/attachment.html>


More information about the Mercurial-patches mailing list