Skip to contentSkip to conversation

remote-hg: fix hg sharedpath when git clone is moved

PATCH In review Antoine Pelisse 2 participants 4 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 remote-hg: fix hg sharedpath when git clone is moved

remote-hg is using a mercurial shared clone to store all remotes objects in one place. Unfortunately, the sharedpath is stored as an absolute path by mercurial, creating a dependency on the location of the git repository. Whenever the git repository is moved, the sharedpath must be updated to reflect the new absolute path.

Check mercurial sharedpath file when getting the local hg repository, and update it manually with the new path if necessary.

---
 contrib/remote-helpers/git-remote-hg |  4 ++++
 contrib/remote-helpers/test-hg.sh    | 11 +++++++++++
 2 files changed, 15 insertions(+)
contrib/remote-helpers/git-remote-hg +4 -0
index c6026b9..576f094 100755
@@ -416,6 +416,10 @@ def get_repo(url, alias):
         local_path = os.path.join(dirname, 'clone')
         if not os.path.exists(local_path):
             hg.share(myui, shared_path, local_path, update=False)
+        else:
+            sharedpath_file = os.path.join(local_path, '.hg', 'sharedpath')
+            if hg_path != open(sharedpath_file, 'r').read():
+                open(sharedpath_file, 'w').write(hg_path)
 
         repo = hg.repository(myui, local_path)
         try:
contrib/remote-helpers/test-hg.sh +11 -0
index 72f745d..2477540 100755
@@ -335,6 +335,17 @@ test_expect_success 'remote cloning' '
 	check gitrepo HEAD zero
 '
 
+test_expect_success 'moving remote clone' '
+	test_when_finished "rm -rf gitrepo*" &&
+
+	(
+	git clone "hg::hgrepo" gitrepo &&
+	mv gitrepo gitrepo2 &&
+	cd gitrepo2 &&
+	git fetch
+	)
+'
+
 test_expect_success 'remote update bookmark' '
 	test_when_finished "rm -rf gitrepo*" &&
 
Signature · 1 line
1.8.5.rc1.30.g02973b8.dirty
#1 lore raw
Quoted 11 lines · Antoine Pelisse

remote-hg is using a mercurial shared clone to store all remotes objects in one place. Unfortunately, the sharedpath is stored as an absolute path by mercurial, creating a dependency on the location of the git repository. Whenever the git repository is moved, the sharedpath must be updated to reflect the new absolute path.

Check mercurial sharedpath file when getting the local hg repository, and update it manually with the new path if necessary.

---

By the way, this is the only link [1] I found about both relative path and updating the file. So it looks like there is no other way to update the path but to write the file manually.

[1]: http://bz.selenic.com/show_bug.cgi?id=2006

#2 lore raw
In reply to Antoine Pelisse
Quoted 10 lines · Antoine Pelisse

remote-hg is using a mercurial shared clone to store all remotes objects in one place. Unfortunately, the sharedpath is stored as an absolute path by mercurial, creating a dependency on the location of the git repository. Whenever the git repository is moved, the sharedpath must be updated to reflect the new absolute path.

Check mercurial sharedpath file when getting the local hg repository, and update it manually with the new path if necessary.

https://github.com/felipec/git/commit/270e7ff91a4a34e8bc27edb6bd7d7473b886f568

Signature · 1 line
Felipe Contreras
#3 lore raw
Quoted 7 lines · Felipe Contreras
Quoted 6 lines · Antoine Pelisse

remote-hg is using a mercurial shared clone to store all remotes objects in one place. Unfortunately, the sharedpath is stored as an absolute path by mercurial, creating a dependency on the location of the git repository. Whenever the git repository is moved, the sharedpath must be updated to reflect the new absolute path.

Quoted 6 lines
Quoted 4 lines

Check mercurial sharedpath file when getting the local hg repository, and update it manually with the new path if necessary.

https://github.com/felipec/git/commit/270e7ff91a4a34e8bc27edb6bd7d7473b886f568

Or that, indeed :-)