Patchwork convert: allow customizing git remote prefix

login
register
mail settings
Submitter Durham Goode
Date July 14, 2015, 5:07 a.m.
Message ID <b2ff10e2fc12fe839781.1436850476@dev2000.prn2.facebook.com>
Download mbox | patch
Permalink /patch/9969/
State Accepted
Commit d9133e89d39decf425ddf9fcec3a62fb5f5b8bbf
Headers show

Comments

Durham Goode - July 14, 2015, 5:07 a.m.
# HG changeset patch
# User Durham Goode <durham@fb.com>
# Date 1436848666 25200
#      Mon Jul 13 21:37:46 2015 -0700
# Node ID b2ff10e2fc12fe839781cb7ccd1d8d0302dd33f5
# Parent  35fa7c77c754aa4d156c42abfdb61ca178468872
convert: allow customizing git remote prefix

Previously all git remotes were created as "remote/foo". This patch adds a
configuration option for deciding what the prefix should be. This is useful if
you want the bookmarks to be "origin/foo" like they are in git, or if you're
integrating with the remotenames extension and don't want the local remote/foo
bookmarks to overlap with the remote foo bookmarks.
Pierre-Yves David - July 14, 2015, 9:01 a.m.
On 07/14/2015 06:07 AM, Durham Goode wrote:
> # HG changeset patch
> # User Durham Goode <durham@fb.com>
> # Date 1436848666 25200
> #      Mon Jul 13 21:37:46 2015 -0700
> # Node ID b2ff10e2fc12fe839781cb7ccd1d8d0302dd33f5
> # Parent  35fa7c77c754aa4d156c42abfdb61ca178468872
> convert: allow customizing git remote prefix
>
> Previously all git remotes were created as "remote/foo". This patch adds a
> configuration option for deciding what the prefix should be. This is useful if
> you want the bookmarks to be "origin/foo" like they are in git, or if you're
> integrating with the remotenames extension and don't want the local remote/foo
> bookmarks to overlap with the remote foo bookmarks.

Random question: What would it take make convert extensible so that 
remotename could take over the convertion of these label?
Sean Farley - July 14, 2015, 5:08 p.m.
Durham Goode <durham@fb.com> writes:

> # HG changeset patch
> # User Durham Goode <durham@fb.com>
> # Date 1436848666 25200
> #      Mon Jul 13 21:37:46 2015 -0700
> # Node ID b2ff10e2fc12fe839781cb7ccd1d8d0302dd33f5
> # Parent  35fa7c77c754aa4d156c42abfdb61ca178468872
> convert: allow customizing git remote prefix
>
> Previously all git remotes were created as "remote/foo". This patch adds a
> configuration option for deciding what the prefix should be. This is useful if
> you want the bookmarks to be "origin/foo" like they are in git, or if you're
> integrating with the remotenames extension and don't want the local remote/foo
> bookmarks to overlap with the remote foo bookmarks.

This looks good to me.
Sean Farley - July 14, 2015, 5:20 p.m.
Pierre-Yves David <pierre-yves.david@ens-lyon.org> writes:

> On 07/14/2015 06:07 AM, Durham Goode wrote:
>> # HG changeset patch
>> # User Durham Goode <durham@fb.com>
>> # Date 1436848666 25200
>> #      Mon Jul 13 21:37:46 2015 -0700
>> # Node ID b2ff10e2fc12fe839781cb7ccd1d8d0302dd33f5
>> # Parent  35fa7c77c754aa4d156c42abfdb61ca178468872
>> convert: allow customizing git remote prefix
>>
>> Previously all git remotes were created as "remote/foo". This patch adds a
>> configuration option for deciding what the prefix should be. This is useful if
>> you want the bookmarks to be "origin/foo" like they are in git, or if you're
>> integrating with the remotenames extension and don't want the local remote/foo
>> bookmarks to overlap with the remote foo bookmarks.
>
> Random question: What would it take make convert extensible so that 
> remotename could take over the convertion of these label?

Perhaps we should move some logic of remote bookmarks into core first,
so that 'convert' would have a smoother transition?
Durham Goode - July 14, 2015, 5:27 p.m.
On 7/14/15, 10:20 AM, "Sean Farley" <sean@farley.io> wrote:

>
>Pierre-Yves David <pierre-yves.david@ens-lyon.org> writes:
>
>> On 07/14/2015 06:07 AM, Durham Goode wrote:
>>> # HG changeset patch
>>> # User Durham Goode <durham@fb.com>
>>> # Date 1436848666 25200
>>> #      Mon Jul 13 21:37:46 2015 -0700
>>> # Node ID b2ff10e2fc12fe839781cb7ccd1d8d0302dd33f5
>>> # Parent  35fa7c77c754aa4d156c42abfdb61ca178468872
>>> convert: allow customizing git remote prefix
>>>
>>> Previously all git remotes were created as "remote/foo". This patch
>>>adds a
>>> configuration option for deciding what the prefix should be. This is
>>>useful if
>>> you want the bookmarks to be "origin/foo" like they are in git, or if
>>>you're
>>> integrating with the remotenames extension and don't want the local
>>>remote/foo
>>> bookmarks to overlap with the remote foo bookmarks.
>>
>> Random question: What would it take make convert extensible so that
>> remotename could take over the convertion of these label?
>
>Perhaps we should move some logic of remote bookmarks into core first,
>so that 'convert' would have a smoother transition?

We could refactor the bookmark creation logic in convert to be a separate
function and remotenames could wrap it.  But I don't think it matters
enough to actually do that work any time soon.
Matt Mackall - July 14, 2015, 6:57 p.m.
On Mon, 2015-07-13 at 22:07 -0700, Durham Goode wrote:
> # HG changeset patch
> # User Durham Goode <durham@fb.com>
> # Date 1436848666 25200
> #      Mon Jul 13 21:37:46 2015 -0700
> # Node ID b2ff10e2fc12fe839781cb7ccd1d8d0302dd33f5
> # Parent  35fa7c77c754aa4d156c42abfdb61ca178468872
> convert: allow customizing git remote prefix

Queued for default, thanks.

Patch

diff --git a/hgext/convert/__init__.py b/hgext/convert/__init__.py
--- a/hgext/convert/__init__.py
+++ b/hgext/convert/__init__.py
@@ -309,6 +309,10 @@  def convert(ui, src, dest=None, revmapfi
         is very expensive for large projects, and is only effective when
         ``convert.git.similarity`` is greater than 0. The default is False.
 
+    :convert.git.remoteprefix: remote refs are converted as bookmarks with
+        ``convert.git.remoteprefix`` as a prefix followed by a /. The default
+        is 'remote'.
+
     Perforce Source
     ###############
 
diff --git a/hgext/convert/git.py b/hgext/convert/git.py
--- a/hgext/convert/git.py
+++ b/hgext/convert/git.py
@@ -376,8 +376,9 @@  class convert_git(converter_source):
         prefixlen = len(prefix)
 
         # factor two commands
-        gitcmd = { 'remote/': 'git ls-remote --heads origin',
-                          '': 'git show-ref'}
+        remoteprefix = self.ui.config('convert', 'git.remoteprefix', 'remote')
+        gitcmd = { remoteprefix + '/': 'git ls-remote --heads origin',
+                                   '': 'git show-ref'}
 
         # Origin heads
         for reftype in gitcmd:
diff --git a/tests/test-convert-git.t b/tests/test-convert-git.t
--- a/tests/test-convert-git.t
+++ b/tests/test-convert-git.t
@@ -642,6 +642,30 @@  submodules)
   $ hg -R git-repo6-hg tip -T "{file_dels}\n"
   .hgsub .hgsubstate
 
+convert using a different remote prefix
+  $ git init git-repo7
+  Initialized empty Git repository in $TESTTMP/git-repo7/.git/
+  $ cd git-repo7
+  $ touch a && git add a && git commit -am "commit a"
+  [master (root-commit) 8ae5f69] commit a
+   Author: nottest <test@example.org>
+   1 file changed, 0 insertions(+), 0 deletions(-)
+   create mode 100644 a
+  $ cd ..
+  $ git clone git-repo7 git-repo7-client
+  Cloning into 'git-repo7-client'...
+  done.
+  $ hg convert --config convert.git.remoteprefix=origin git-repo7-client hg-repo7
+  initializing destination hg-repo7 repository
+  scanning source...
+  sorting...
+  converting...
+  0 commit a
+  updating bookmarks
+  $ hg -R hg-repo7 bookmarks
+     master                    0:03bf38caa4c6
+     origin/master             0:03bf38caa4c6
+
 damaged git repository tests:
 In case the hard-coded hashes change, the following commands can be used to
 list the hashes and their corresponding types in the repository:
diff --git a/tests/test-convert.t b/tests/test-convert.t
--- a/tests/test-convert.t
+++ b/tests/test-convert.t
@@ -259,6 +259,10 @@ 
                     for large projects, and is only effective when
                     "convert.git.similarity" is greater than 0. The default is
                     False.
+      convert.git.remoteprefix
+                    remote refs are converted as bookmarks with
+                    "convert.git.remoteprefix" as a prefix followed by a /. The
+                    default is 'remote'.
   
       Perforce Source
       ###############