This is an archive of the discontinued Mercurial Phabricator instance.

fix: use `set_possibly_dirty` instead of `normallookup`
ClosedPublic

Authored by marmoute on Jul 19 2021, 10:10 AM.

Details

Summary

This is the newer, more semantic API.

Diff Detail

Repository
rHG Mercurial
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

marmoute created this revision.Jul 19 2021, 10:10 AM
Alphare accepted this revision.Jul 19 2021, 12:29 PM
This revision is now accepted and ready to land.Jul 19 2021, 12:29 PM
baymax updated this revision to Diff 29522.Jul 19 2021, 4:04 PM

✅ refresh by Heptapod after a successful CI run (🐙 💚)

This revision was automatically updated to reflect the committed changes.

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, so maybe it was just that hg fix used the API incorrectly to start with?