Skip to contentSkip to conversation

remotes-hg: bugfix for fetching non local remotes

PATCH In review Joern Hees 4 participants 16 messages Jun 15, 2016

lore
Share & tools
lore

Joern Hees

author
#0 lore raw

PATCH v3 1/1 remotes-hg: bugfix for fetching non local remotes

6796d49 introduced a bug by making shared_path == ".git/hg' which will most likely exist already, causing a new remote never to be cloned and subsequently causing hg.share to fail with error msg:
"mercurial.error.RepoError: repository .git/hg not found"

Changing shared_path to ".git/hg/.shared" will solve this problem and create a shared local mercurial repository for non local remotes. The initial dot circumvents a name clash problem should a remote be called "shared".

Thanks-to: Junio C Hamano <[email protected]>

---
 contrib/remote-helpers/git-remote-hg | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
contrib/remote-helpers/git-remote-hg +1 -1
index 0194c67..f4e9d1c 100755
@@ -390,7 +390,7 @@ def get_repo(url, alias):
         if not os.path.exists(dirname):
             os.makedirs(dirname)
     else:
-        shared_path = os.path.join(gitdir, 'hg')
+        shared_path = os.path.join(gitdir, 'hg', '.shared')
         if not os.path.exists(shared_path):
             try:
                 hg.clone(myui, {}, url, shared_path, update=False, pull=True)
Signature · 1 line
1.8.3.4
#1 lore raw
Quoted 31 lines · Joern Hees

6796d49 introduced a bug by making shared_path == ".git/hg' which will most likely exist already, causing a new remote never to be cloned and subsequently causing hg.share to fail with error msg:
"mercurial.error.RepoError: repository .git/hg not found"

Changing shared_path to ".git/hg/.shared" will solve this problem and create a shared local mercurial repository for non local remotes. The initial dot circumvents a name clash problem should a remote be called "shared".

Thanks-to: Junio C Hamano <[email protected]>

---
 contrib/remote-helpers/git-remote-hg | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
contrib/remote-helpers/git-remote-hg +1 -2
index 0194c67..f4e9d1c 100755
@@ -390,7 +390,7 @@ def get_repo(url, alias):
         if not os.path.exists(dirname):
             os.makedirs(dirname)
     else:
-        shared_path = os.path.join(gitdir, 'hg')
+        shared_path = os.path.join(gitdir, 'hg', '.shared')
         if not os.path.exists(shared_path):
             try:
                 hg.clone(myui, {}, url, shared_path, update=False, pull=True)
--
Quoted 1 line

1.8.3.4

I don't like this approach because if it's a huge repository the user would have to clone again, not only if he was using v1.8.3, but also if he was using the latest and greatest (because you are changing the location again). It's relatively trivial to move from the old to the shared organization, so that's what I vote for. Besides, I don't see the point of having a '.shared/.hg' directory, and nothing else on that '.shared' folder.

So, here's my patch. If only Junio read them.

Subject: [PATCH] remote-hg: add shared repo upgrade

6796d49 (remote-hg: use a shared repository store) introduced a bug by making the shared repository '.git/hg', which is already used before that patch, so clones that happened before that patch, fail after that patch, because there's no shared Mercurial repo.

It's trivial to upgrade to the new organization by copying the Mercurial repo from one of the remotes (e.g. 'origin'), so let's do so.

---
 contrib/remote-helpers/git-remote-hg.py | 7 +++++++
 1 file changed, 7 insertions(+)
(quoted diff) +0 -0

b/contrib/remote-helpers/git-remote-hg.py
index 0194c67..57a8ec4 100755

contrib/remote-helpers/git-remote-hg.py +7 -0
@@ -396,6 +396,13 @@ def get_repo(url, alias):
                 hg.clone(myui, {}, url, shared_path, update=False, pull=True)
             except:
                 die('Repository error')
+        else:
+            # check and upgrade old organization
+            hg_path = os.path.join(shared_path, '.hg')
+            if not os.path.exists(hg_path):
+                repos = os.listdir(shared_path)
+                local_hg = os.path.join(shared_path, repos[0], 'clone', '.hg')
+                shutil.copytree(local_hg, hg_path)
 
         if not os.path.exists(dirname):
             os.makedirs(dirname)
Signature · 4 lines
1.8.3.3

-- 
Felipe Contreras
author
#2 lore raw
Quoted 21 lines · Felipe Contreras
Quoted 19 lines

[…]
---
contrib/remote-helpers/git-remote-hg | 2 +-

1 file changed, 1 insertion(+), 1 deletion(-)
contrib/remote-helpers/git-remote-hg +1 -2
index 0194c67..f4e9d1c 100755
@@ -390,7 +390,7 @@ def get_repo(url, alias):
        if not os.path.exists(dirname):
            os.makedirs(dirname)
    else:
-        shared_path = os.path.join(gitdir, 'hg')
+        shared_path = os.path.join(gitdir, 'hg', '.shared')
        if not os.path.exists(shared_path):
            try:
                hg.clone(myui, {}, url, shared_path, update=False, pull=True)
--
Quoted 1 line

1.8.3.4

Quoted 7 lines

I don't like this approach because if it's a huge repository the user would have to clone again, not only if he was using v1.8.3, but also if he was using the latest and greatest (because you are changing the location again). t's relatively trivial to move from the old to the shared organization, so that's what I vote for. Besides, I don't see the point of having a '.shared/.hg' directory, and nothing else on that '.shared' folder.

Agreed… it just was the shortest possible fix with an in my POV minor optimisation drawback of once refetching...

#3 lore raw
In reply to Felipe Contreras
Quoted 3 lines · Felipe Contreras

Besides, I don't see
the point of having a '.shared/.hg' directory, and nothing else on that '.shared' folder.

Is it not already true about the ".git/hg/$alias/clone/" directory ?

Quoted 11 lines

So, here's my patch. If only Junio read them.

Subject: [PATCH] remote-hg: add shared repo upgrade

6796d49 (remote-hg: use a shared repository store) introduced a bug by making the shared repository '.git/hg', which is already used before that patch, so clones that happened before that patch, fail after that patch, because there's no shared Mercurial repo.

It's trivial to upgrade to the new organization by copying the Mercurial repo from one of the remotes (e.g. 'origin'), so let's do so.

I agree with you that we should consider migration. But there's another use-case I think can fail.
What happens with the following:

git clone hg::/my/hg/repo
cd repo && git remote add newremote hg::http://some/hg/url

Git clone will create .git/hg/origin and with no hg clone (because it's a local repository), and then create marks-file in there.

Quoted 12 lines
---
 contrib/remote-helpers/git-remote-hg.py | 7 +++++++
 1 file changed, 7 insertions(+)
contrib/remote-helpers/git-remote-hg.py +0 -0
index 0194c67..57a8ec4 100755

contrib/remote-helpers/git-remote-hg.py def get_repo(url, alias): · line 405

Quoted 10 lines
contrib/remote-helpers/git-remote-hg.py +7 -0
@@ -396,6 +396,13 @@ def get_repo(url, alias):
                 hg.clone(myui, {}, url, shared_path, update=False, pull=True)
             except:
                 die('Repository error')
+        else:
+            # check and upgrade old organization
+            hg_path = os.path.join(shared_path, '.hg')
+            if not os.path.exists(hg_path):
+                repos = os.listdir(shared_path)
+                local_hg = os.path.join(shared_path, repos[0], 'clone', '.hg')
+                shutil.copytree(local_hg, hg_path)

With the use-case I described above, I think shutil.copytree() would raise an exception because local_hg doesn't exist.

#4 lore raw
Quoted 7 lines · Antoine Pelisse
Quoted 3 lines · Felipe Contreras

Besides, I don't see
the point of having a '.shared/.hg' directory, and nothing else on that '.shared' folder.

Is it not already true about the ".git/hg/$alias/clone/" directory ?

Yeah, but that directory is kind of useful. Somebody might want to clone that, and it's self-explanatory; "Where is the clone of that Mercurial remote? Oh, there".

Quoted 39 lines
Quoted 11 lines

So, here's my patch. If only Junio read them.

Subject: [PATCH] remote-hg: add shared repo upgrade

6796d49 (remote-hg: use a shared repository store) introduced a bug by making the shared repository '.git/hg', which is already used before that patch, so clones that happened before that patch, fail after that patch, because there's no shared Mercurial repo.

It's trivial to upgrade to the new organization by copying the Mercurial repo from one of the remotes (e.g. 'origin'), so let's do so.

I agree with you that we should consider migration. But there's another use-case I think can fail.
What happens with the following:

git clone hg::/my/hg/repo
cd repo && git remote add newremote hg::http://some/hg/url

Git clone will create .git/hg/origin and with no hg clone (because it's a local repository), and then create marks-file in there.

Quoted 17 lines
---
 contrib/remote-helpers/git-remote-hg.py | 7 +++++++
 1 file changed, 7 insertions(+)
contrib/remote-helpers/git-remote-hg.py +2 -0
index 0194c67..57a8ec4 100755
@@ -396,6 +396,13 @@ def get_repo(url, alias):
                 hg.clone(myui, {}, url, shared_path, update=False, pull=True)
             except:
                 die('Repository error')
+        else:
+            # check and upgrade old organization
Quoted 8 lines

contrib/remote-helpers/git-remote-hg.py def get_repo(url, alias): · line 405

Quoted 5 lines
contrib/remote-helpers/git-remote-hg.py +5 -0
+            hg_path = os.path.join(shared_path, '.hg')
+            if not os.path.exists(hg_path):
+                repos = os.listdir(shared_path)
+                local_hg = os.path.join(shared_path, repos[0], 'clone', '.hg')
+                shutil.copytree(local_hg, hg_path)

With the use-case I described above, I think shutil.copytree() would raise an exception because local_hg doesn't exist.

That's true. Maybe something like:

for x in repos:
local_hg = os.path.join(shared_path, x, 'clone', '.hg') if os.path.exists(local_hg):
shutil.copytree(local_hg, hg_path)
break

Signature · 1 line
Felipe Contreras
#5 lore raw
Quoted 7 lines · Felipe Contreras

That's true. Maybe something like:

for x in repos:
local_hg = os.path.join(shared_path, x, 'clone', '.hg') if os.path.exists(local_hg):
shutil.copytree(local_hg, hg_path)
break

I think that would work, but I think the patch from Joern Hees would have to be reverted first (as it's merged in next)

Cheers,
Antoine

author
#6 lore raw
Quoted 11 lines · Antoine Pelisse
Quoted 7 lines · Felipe Contreras

That's true. Maybe something like:

for x in repos:
local_hg = os.path.join(shared_path, x, 'clone', '.hg') if os.path.exists(local_hg):
shutil.copytree(local_hg, hg_path)
break

I think that would work

yupp, might work, but holding you liable to the same optimality restriction you imposed on me before:
This will still refetch the whole repo once if it was cloned from a local hg repo first (they don't have a clone subdir).
Shouldn't we then also go through the additional effort and copy the .hg dir from local remotes when a "remote remote" is added and there's no other remote remote?

j

#7 lore raw

PATCH 1/1 remote-hg: Fix cloning and sharing bug

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.

---
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(-)
contrib/remote-helpers/git-remote-hg +28 -19
index 0194c67..487c13d 100755
@@ -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

author
#8 lore raw

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

Hi,

Quoted 7 lines · Antoine Pelisse

[…]
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).

I was working on a similar patch in the meantime, this point was the only thing that kept me from submitting… Can someone of you think of an easy way to do this lazily on the first non-local remote being added?
In case we don't have a non-local clone (a mercurial dir with a clone subdir) yet, we would try to go though the local mercurial remotes and then clone them… Just would need a way to get their URLs. I thought about going through all "git remote -v" This way we wouldn't need to copy by default (bad for big repos), but could still do this in a cheap way if a slow remote is added later on.

Btw, is there any reason why we don't just use the local mercurial remotes as shared repo? Cause it's not under our git dir and might be deleted?

Quoted 16 lines

[…]
contrib/remote-helpers/git-remote-hg | 47 ++++++++++++++++++++--------------

1 file changed, 28 insertions(+), 19 deletions(-)
contrib/remote-helpers/git-remote-hg +0 -4
index 0194c67..487c13d 100755
@@ -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)

contrib/remote-helpers/git-remote-hg def get_repo(url, alias): · line 394

Quoted 10 lines
contrib/remote-helpers/git-remote-hg +7 -3
-    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')

I thought we had agreed to use .git/hg as the shared directory before? (so that a clone into that dir would end up in .git/hg/.hg instead of .git/hg/.shared/.hg)

contrib/remote-helpers/git-remote-hg def get_repo(url, alias): · line 403

Quoted 9 lines
contrib/remote-helpers/git-remote-hg +9 -0
+    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:

Elegant use of the for-else clause, but to my experience confuses many people.

This would also be the place to check for local remotes after not finding already cloned non-local remotes (the lazy approach mentioned above). As this would cause nested "for-else" loops, i'd rather repeatedly check for existence of .git/hg/.hg and list the several fallback in order, the last one being this one:

contrib/remote-helpers/git-remote-hg def get_repo(url, alias): · line 407

Quoted 4 lines
contrib/remote-helpers/git-remote-hg +0 -0
            try:
                hg.clone(myui, {}, url, shared_path, update=False, pull=True)
            except:
                die('Repository error')

If you want i'll send around my patch as RFC.
In the end i don't care which one is accepted and how, most important that one is accepted to fix the bug.

Cheers,
Jörn

#9 lore raw

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

Quoted 11 lines · Jörn Hees

Hi,

Quoted 7 lines · Antoine Pelisse

[…]
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).

Quoted 6 lines

I was working on a similar patch in the meantime, this point was the only thing that kept me from submitting… Can someone of you think of an easy way to do this lazily on the first non-local remote being added?
In case we don't have a non-local clone (a mercurial dir with a clone subdir) yet, we would try to go though the local mercurial remotes and then clone them… Just would need a way to get their URLs. I thought about going through all "git remote -v"

git config --get-regexp '^remote.*.url' is probably more appropriate.

Either way, I don't see why such a change should be in the same patch.

Quoted 5 lines

This way we wouldn't need to copy by default (bad for big repos), but could still do this in a cheap way if a slow remote is added later on.

Btw, is there any reason why we don't just use the local mercurial remotes as shared repo? Cause it's not under our git dir and might be deleted?

Yes. Or moved, or might be in an external drive, or many other reasons.

This is my solution:

contrib/remote-helpers/git-remote-hg.py +16 -5
@@ -391,11 +391,22 @@ def get_repo(url, alias):
             os.makedirs(dirname)
     else:
         shared_path = os.path.join(gitdir, 'hg')
-        if not os.path.exists(shared_path):
-            try:
-                hg.clone(myui, {}, url, shared_path, update=False, pull=True)
-            except:
-                die('Repository error')
+
+        # check and upgrade old organization
+        hg_path = os.path.join(shared_path, '.hg')
+        if os.path.exists(shared_path) and not os.path.exists(hg_path):
+            repos = os.listdir(shared_path)
+            for x in repos:
+                local_hg = os.path.join(shared_path, x, 'clone', '.hg')
+                if not os.path.exists(local_hg):
+                    continue
+                shutil.copytree(local_hg, hg_path)
+
+        # setup shared repo (if not there)
+        try:
+            hg.peer(myui, {}, shared_path, create=True)
+        except error.RepoError:
+            pass
 
         if not os.path.exists(dirname):
             os.makedirs(dirname)

It should also work in all the cases, but there would not be an extra unnecessary clone while upgrading, and it doesn't sneak in any other changes.

You can see the changes on top of my previous patch that lead to this diff in my repo:

https://github.com/felipec/git/commits/fc/master

Cheers.

Signature · 1 line
Felipe Contreras
author
#10 lore raw

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

Quoted 3 lines · Felipe Contreras

git config --get-regexp '^remote.*.url' is probably more appropriate.

Either way, I don't see why such a change should be in the same patch.

+1

Quoted 17 lines

This is my solution:

contrib/remote-helpers/git-remote-hg.py +4 -5
@@ -391,11 +391,22 @@ def get_repo(url, alias):
            os.makedirs(dirname)
    else:
        shared_path = os.path.join(gitdir, 'hg')
-        if not os.path.exists(shared_path):
-            try:
-                hg.clone(myui, {}, url, shared_path, update=False, pull=True)
-            except:
-                die('Repository error')
+
+        # check and upgrade old organization
+        hg_path = os.path.join(shared_path, '.hg')
+        if os.path.exists(shared_path) and not os.path.exists(hg_path):

contrib/remote-helpers/git-remote-hg.py def get_repo(url, alias): · line 407

Quoted 10 lines
contrib/remote-helpers/git-remote-hg.py +10 -0
+            repos = os.listdir(shared_path)
+            for x in repos:
+                local_hg = os.path.join(shared_path, x, 'clone', '.hg')
+                if not os.path.exists(local_hg):
+                    continue
+                shutil.copytree(local_hg, hg_path)
+
+        # setup shared repo (if not there)
+        try:
+            hg.peer(myui, {}, shared_path, create=True)

Didn't look this up, this will raise the error below when it exists already?

Quoted 9 lines
contrib/remote-helpers/git-remote-hg.py +2 -0
+        except error.RepoError:
+            pass
 
        if not os.path.exists(dirname):
            os.makedirs(dirname)

It should also work in all the cases, but there would not be an extra unnecessary clone while upgrading, and it doesn't sneak in any other changes.

+1
Seems to be the best fix until now.

Cheers,
Jörn

#11 lore raw

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

Quoted 23 lines · Jörn Hees
Quoted 21 lines · Felipe Contreras

This is my solution:

contrib/remote-helpers/git-remote-hg.py +8 -5
@@ -391,11 +391,22 @@ def get_repo(url, alias):
            os.makedirs(dirname)
    else:
        shared_path = os.path.join(gitdir, 'hg')
-        if not os.path.exists(shared_path):
-            try:
-                hg.clone(myui, {}, url, shared_path, update=False, pull=True)
-            except:
-                die('Repository error')
+
+        # check and upgrade old organization
+        hg_path = os.path.join(shared_path, '.hg')
+        if os.path.exists(shared_path) and not os.path.exists(hg_path):
+            repos = os.listdir(shared_path)
+            for x in repos:
+                local_hg = os.path.join(shared_path, x, 'clone', '.hg')
+                if not os.path.exists(local_hg):
Quoted 8 lines

contrib/remote-helpers/git-remote-hg.py def get_repo(url, alias): · line 407

Quoted 6 lines
contrib/remote-helpers/git-remote-hg.py +6 -0
+                    continue
+                shutil.copytree(local_hg, hg_path)
+
+        # setup shared repo (if not there)
+        try:
+            hg.peer(myui, {}, shared_path, create=True)

Didn't look this up, this will raise the error below when it exists already?

Exactly.

Signature · 1 line
Felipe Contreras
#12 lore raw

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

In reply to Felipe Contreras
Quoted 31 lines
contrib/remote-helpers/git-remote-hg.py +16 -5
@@ -391,11 +391,22 @@ def get_repo(url, alias):
             os.makedirs(dirname)
     else:
         shared_path = os.path.join(gitdir, 'hg')
-        if not os.path.exists(shared_path):
-            try:
-                hg.clone(myui, {}, url, shared_path, update=False, pull=True)
-            except:
-                die('Repository error')
+
+        # check and upgrade old organization
+        hg_path = os.path.join(shared_path, '.hg')
+        if os.path.exists(shared_path) and not os.path.exists(hg_path):
+            repos = os.listdir(shared_path)
+            for x in repos:
+                local_hg = os.path.join(shared_path, x, 'clone', '.hg')
+                if not os.path.exists(local_hg):
+                    continue
+                shutil.copytree(local_hg, hg_path)
+
+        # setup shared repo (if not there)
+        try:
+            hg.peer(myui, {}, shared_path, create=True)
+        except error.RepoError:
+            pass
 
         if not os.path.exists(dirname):
             os.makedirs(dirname)
Quoted 3 lines

It should also work in all the cases, but there would not be an extra unnecessary clone while upgrading, and it doesn't sneak in any other changes.

That's fine with me. Indeed, we can think about "cloning local repos" in a separate thread if needed. I clearly don't have a strong opinion about that.

Would you mind squashing your changes into a patch ?

Cheers,

#13 lore raw

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

Quoted 1 line · Antoine Pelisse

Would you mind squashing your changes into a patch ?

I actually would, and I'm not going to explain why because people get offended way too easily in this mailing list.

Maybe later.

Signature · 1 line
Felipe Contreras
#14 lore raw

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

In reply to Antoine Pelisse
Quoted 11 lines · Antoine Pelisse

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).

This seems to presume that there's no way to fix it otherwise, but there is.

Maybe always cloning is a good idea, maybe it's not, but that is a change that should be done in a separate commit, and it can.

Quoted 3 lines

In order to avoid expensive clone
retrieval from slow remotes, also look for already existing clones in .git/hg/$aliases/clone.

This is yet another change that should be in yet another patch.

Quoted 6 lines

---
Hey,

Quoted 6 lines

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).

Perhaps it would work in all the cases, but it would need to reclone if the user is updating from v1.8.3.

Quoted 6 lines

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 said; this should be discussed in a different patch. Personally I think the current behavior is all right, because the use case of cloning a local repository is way more common that cloning a repository, and then adding a slow remote. We should optimize for the common use-case.

Signature · 1 line
Felipe Contreras
#15 lore raw
In reply to Antoine Pelisse
Quoted 4 lines · Antoine Pelisse
Quoted 2 lines · Felipe Contreras

That's true. Maybe something like:

Quoted 8 lines
Quoted 5 lines

for x in repos:
local_hg = os.path.join(shared_path, x, 'clone', '.hg') if os.path.exists(local_hg):
shutil.copytree(local_hg, hg_path)
break

I think that would work, but I think the patch from Joern Hees would have to be reverted first (as it's merged in next)

The expectation is that not all things in 'next' today will be in 1.8.4 anyway, so it is perfectly OK to revert it as needed.

Thanks.