Details
Details
- Reviewers
- None
- Group Reviewers
hg-reviewers - Commits
- rHGbc843e251134: unshare: use context manager for locks
Diff Detail
Diff Detail
- Repository
- rHG Mercurial
- Lint
Lint Skipped - Unit
Unit Tests Skipped
| hg-reviewers |
| Lint Skipped |
| Unit Tests Skipped |
| Path | Packages | |||
|---|---|---|---|---|
| M | mercurial/hg.py (21 lines) |
| Commit | Parents | Author | Summary | Date |
|---|---|---|---|---|
| Martin von Zweigbergk | Jan 17 2019, 12:18 PM |
| Copy the store data to the repo and remove the sharedpath data. | Copy the store data to the repo and remove the sharedpath data. | ||||
| Returns a new repository object representing the unshared repository. | Returns a new repository object representing the unshared repository. | ||||
| The passed repository object is not usable after this function is | The passed repository object is not usable after this function is | ||||
| called. | called. | ||||
| """ | """ | ||||
| destlock = None | with repo.lock(): | ||||
| lock = repo.lock() | |||||
| try: | |||||
| # we use locks here because if we race with commit, we | # we use locks here because if we race with commit, we | ||||
| # can end up with extra data in the cloned revlogs that's | # can end up with extra data in the cloned revlogs that's | ||||
| # not pointed to by changesets, thus causing verify to | # not pointed to by changesets, thus causing verify to | ||||
| # fail | # fail | ||||
| destlock = copystore(ui, repo, repo.path) | destlock = copystore(ui, repo, repo.path) | ||||
| with destlock or util.nullcontextmanager(): | |||||
| sharefile = repo.vfs.join('sharedpath') | sharefile = repo.vfs.join('sharedpath') | ||||
| util.rename(sharefile, sharefile + '.old') | util.rename(sharefile, sharefile + '.old') | ||||
| repo.requirements.discard('shared') | repo.requirements.discard('shared') | ||||
| repo.requirements.discard('relshared') | repo.requirements.discard('relshared') | ||||
| repo._writerequirements() | repo._writerequirements() | ||||
| finally: | |||||
| destlock and destlock.release() | |||||
| lock and lock.release() | |||||
| # Removing share changes some fundamental properties of the repo instance. | # Removing share changes some fundamental properties of the repo instance. | ||||
| # So we instantiate a new repo object and operate on it rather than | # So we instantiate a new repo object and operate on it rather than | ||||
| # try to keep the existing repo usable. | # try to keep the existing repo usable. | ||||
| newrepo = repository(repo.baseui, repo.root, create=False) | newrepo = repository(repo.baseui, repo.root, create=False) | ||||
| # TODO: figure out how to access subrepos that exist, but were previously | # TODO: figure out how to access subrepos that exist, but were previously | ||||
| # removed from .hgsub | # removed from .hgsub | ||||