git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] remote-hg: Fix cloning and sharing bug

From
Antoine Pelisse <apelisse@gmail.com>
Date
Aug 4, 2013, 10:38 UTC
Message-ID
<1375612683-9104-1-git-send-email-apelisse@gmail.com>
In-Reply-To
<1A5ABD76-D3D9-400E-AC8F-26C0DEF43723@joernhees.de>

6796d49 (remote-hg: use a shared repository store) introduced sharing repository capability, but it broke backward-compatibility with already existing repositories.

Indeed, 6796d49 assumes that .git/hg/.hg (the shared repository) will exist if .git/hg exists. This can be false for already existing clones. It can also be false for local repository that are not cloned.

Fixes the compatibility break by always cloning into .git/hg/.shared (even for local repositories). In order to avoid expensive clone retrieval from slow remotes, also look for already existing clones in .git/hg/$aliases/clone.

Reported-by: Joern Hees <dev@joernhees.de>
Suggested-by: Felipe Contreras <felipe.contreras@gmail.com>
Signed-off-by: Antoine Pelisse <apelisse@gmail.com>
---
Hey,

OK, I think this version will work in all cases. Either you clone local and then remote, or remote and then local, or old version local and then remote, or old version remote and then local: You will always either have .shared repo already cloned, or will find a way to create it: either by using an already existing clone, or by cloning the given url (and that last step can't be done if we don't use .shared).

I also decided to always clone local repositories because what Jörn Hees said makes sense: If you have a local clone of a big repository, and then want to add a slow remote, you would have to reclone everything. I think the trade-off is good, because clone from local should not be that time expensive (maybe it can be on disk-space though).

As I changed indentation, the patch may deserve a second look with -w.

Cheers, Antoine

 contrib/remote-helpers/git-remote-hg |   47 ++++++++++++++++++++--------------
 1 file changed, 28 insertions(+), 19 deletions(-)
diff --git a/contrib/remote-helpers/git-remote-hg b/contrib/remote-helpers/git-remote-hg
index 0194c67..487c13d 100755
--- a/contrib/remote-helpers/git-remote-hg
+++ b/contrib/remote-helpers/git-remote-hg
@@ -385,33 +385,42 @@ def get_repo(url, alias):

     extensions.loadall(myui)

-    if hg.islocal(url) and not os.environ.get('GIT_REMOTE_HG_TEST_REMOTE'):
-        repo = hg.repository(myui, url)
-        if not os.path.exists(dirname):
-            os.makedirs(dirname)
-    else:
-        shared_path = os.path.join(gitdir, 'hg')
-        if not os.path.exists(shared_path):
+    hgdir = os.path.join(gitdir, 'hg')
+    try:
+        os.mkdir(hgdir)
+    except OSError:
+        pass
+
+    shared_path = os.path.join(hgdir, '.shared')
+    if not os.path.exists(shared_path):
+        for remote in os.listdir(hgdir):
+            try:
+                hg.clone(myui, {}, os.path.join(hgdir, remote, 'clone'),
+                         shared_path, update=False, pull=True)
+                break
+            except error.RepoError:
+                pass
+        else:
             try:
                 hg.clone(myui, {}, url, shared_path, update=False, pull=True)
             except:
                 die('Repository error')

-        if not os.path.exists(dirname):
-            os.makedirs(dirname)
+    if not os.path.exists(dirname):
+        os.makedirs(dirname)

-        local_path = os.path.join(dirname, 'clone')
-        if not os.path.exists(local_path):
-            hg.share(myui, shared_path, local_path, update=False)
+    local_path = os.path.join(dirname, 'clone')
+    if not os.path.exists(local_path):
+        hg.share(myui, shared_path, local_path, update=False)

-        repo = hg.repository(myui, local_path)
-        try:
-            peer = hg.peer(myui, {}, url)
-        except:
-            die('Repository error')
-        repo.pull(peer, heads=None, force=True)
+    repo = hg.repository(myui, local_path)
+    try:
+        peer = hg.peer(myui, {}, url)
+    except:
+        die('Repository error')
+    repo.pull(peer, heads=None, force=True)

-        updatebookmarks(repo, peer)
+    updatebookmarks(repo, peer)

     return repo

--
1.7.9.5
Previous: Jörn HeesNext: Jörn Hees
Message 8 of 16 in “remotes-hg: bugfix for fetching non local remotes”
  1. remotes-hg: bugfix for fetching non local remotesJoern Hees, Jul 25, 2013
  2. Felipe ContrerasJul 25, 2013
  3. Antoine PelisseJul 25, 2013
  4. Felipe ContrerasJul 25, 2013
  5. Antoine PelisseJul 25, 2013
  6. Junio C HamanoJul 26, 2013
  7. Jörn HeesJul 26, 2013
  8. remote-hg: Fix cloning and sharing bugAntoine Pelisse, Aug 4, 2013
  9. Jörn HeesAug 4, 2013
  10. Felipe ContrerasAug 4, 2013
  11. Jörn HeesAug 4, 2013
  12. Felipe ContrerasAug 4, 2013
  13. Antoine PelisseAug 4, 2013
  14. Felipe ContrerasAug 4, 2013
  15. Felipe ContrerasAug 4, 2013
  16. Jörn HeesJul 26, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.