Mercurial > hg-stable
changeset 50096:d41960df197e
dirstate: wrap repository change in appropriate context in `test-context`
We need the `wlock` (to add files), the `lock` (to commit), a `transaction` (to
commit) and a `changing_files` context (to add files).
Strictly speaking, we could let the commit take the `lock` and create a
`transaction`, but it seems more consistent that way.
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Wed, 25 Jan 2023 12:56:26 +0100 |
parents | 7b289a70c2c8 |
children | 1346db77e14d |
files | tests/test-context.py |
diffstat | 1 files changed, 14 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/tests/test-context.py Wed Jan 25 12:57:52 2023 +0100 +++ b/tests/test-context.py Wed Jan 25 12:56:26 2023 +0100 @@ -42,8 +42,10 @@ os.utime('foo', (1000, 1000)) # add+commit 'foo' -repo[None].add([b'foo']) -repo.commit(text=b'commit1', date=b"0 0") +with repo.wlock(), repo.lock(), repo.transaction(b'test-context'): + with repo.dirstate.changing_files(repo): + repo[None].add([b'foo']) + repo.commit(text=b'commit1', date=b"0 0") d = repo[None][b'foo'].date() if os.name == 'nt': @@ -108,16 +110,20 @@ repo.wwrite(b'bar-m', b'bar-m\n', b'') repo.wwrite(b'bar-r', b'bar-r\n', b'') -repo[None].add([b'bar-m', b'bar-r']) -repo.commit(text=b'add bar-m, bar-r', date=b"0 0") +with repo.wlock(), repo.lock(), repo.transaction(b'test-context'): + with repo.dirstate.changing_files(repo): + repo[None].add([b'bar-m', b'bar-r']) + repo.commit(text=b'add bar-m, bar-r', date=b"0 0") # ancestor "wcctx ~ 1" actx1 = repo[b'.'] repo.wwrite(b'bar-m', b'bar-m bar-m\n', b'') repo.wwrite(b'bar-a', b'bar-a\n', b'') -repo[None].add([b'bar-a']) -repo[None].forget([b'bar-r']) +with repo.wlock(), repo.lock(), repo.transaction(b'test-context'): + with repo.dirstate.changing_files(repo): + repo[None].add([b'bar-a']) + repo[None].forget([b'bar-r']) # status at this point: # M bar-m @@ -237,7 +243,8 @@ with repo.wlock(), repo.lock(), repo.transaction(b'test'): with open(b'4', 'wb') as f: f.write(b'4') - repo.dirstate.set_tracked(b'4') + with repo.dirstate.changing_files(repo): + repo.dirstate.set_tracked(b'4') repo.commit(b'4') revsbefore = len(repo.changelog) repo.invalidate(clearfilecache=True)