Mercurial > hg-git
diff hggit/__init__.py @ 1085:1003994dd497
share: host the git repository alongside the store
Before this changeset, the internal git repository were always stored in '.hg/'
even when the repository was a 'share' of another one. With this patch, hg-git
respect the '.hg/sharedpath' file and stores the internal git repository and
associated caches in the original repository. This allows multiple 'shares' to
use the same git repository.
This does not affect the 'intree' variant where the repository is directly
stored inside the working copy.
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Thu, 26 Oct 2017 18:20:00 +0200 |
parents | b6cdf7be4059 |
children | c06d4656b77b |
line wrap: on
line diff
--- a/hggit/__init__.py Fri Nov 24 21:04:54 2017 +0100 +++ b/hggit/__init__.py Thu Oct 26 18:20:00 2017 +0200 @@ -49,6 +49,7 @@ revset, scmutil, templatekw, + vfs as vfsmod, ) try: @@ -214,13 +215,21 @@ lambda *args: open(os.path.join(helpdir, 'git.rst')).read()) insort(help.helptable, entry) +def _gitvfs(repo): + """return a vfs suitable to read git related data""" + # Mercurial >= 3.3: repo.shared() + if repo.sharedpath != repo.path: + return vfsmod.vfs(repo.sharedpath) + else: + return repo.vfs + def reposetup(ui, repo): if not isinstance(repo, gitrepo.gitrepo): if (getattr(dirstate, 'rootcache', False) and (not ignoremod or getattr(ignore, 'readpats', False)) and hgutil.safehasattr(repo, 'vfs') and - os.path.exists(repo.vfs.join('git'))): + os.path.exists(_gitvfs(repo).join('git'))): # only install our dirstate wrapper if it has a hope of working import gitdirstate if ignoremod: @@ -277,13 +286,14 @@ def git_cleanup(ui, repo): '''clean up Git commit map after history editing''' new_map = [] - for line in repo.vfs(GitHandler.map_file): + vfs = _gitvfs(repo) + for line in vfs(GitHandler.map_file): gitsha, hgsha = line.strip().split(' ', 1) if hgsha in repo: new_map.append('%s %s\n' % (gitsha, hgsha)) wlock = repo.wlock() try: - f = repo.vfs(GitHandler.map_file, 'wb') + f = vfs(GitHandler.map_file, 'wb') map(f.write, new_map) finally: wlock.release()