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

Re: Access different NAMESPACE of remote repo from client side

From
Jiang Xin <worldhello.net@gmail.com>
Date
Nov 16, 2013, 08:00 UTC
Message-ID
<CANYiYbHzHEFLshU8r-m=0CUo7JTu-iyv1W4N291hX8+r1BYY-w@mail.gmail.com>
In-Reply-To
<52863410.9090508@gmail.com>
2013/11/15 Sitaram Chamarty <sitaramc@gmail.com>:
Show 17 quoted lines
> On 11/15/2013 07:55 PM, Sitaram Chamarty wrote:
>> On 11/15/2013 01:49 PM, Jiang Xin wrote:
>>> Just like solution 2, these settings won't work without a patched
>>> git-shell or gitolite.
>>
>> Gitolite has a namespaces branch that handles namespaces as described in
>> http://gitolite.com/gitolite/namespaces.html
>>
>> Briefly, it recognises that you can have a "main" repo off of which
>> several developer might want to hang their logical repos.
>>
>> It also recognises that the actual names of the logical repos will
>> follow some pattern that may include the name of the developer also, and
>> provides a way to derive the name of the physical repo from the logical
>> one.
>>
>> There is an example or two in that link.

I use gitolite everyday, and thank you for inventing it. I use gitolite v2 for a long time, and migrated to v3 recently. Thank you for pointing out there is a "namespace" feature branch, and I love the implementation very much, it is so easy to map logical repos to one physical repo.

Show 5 quoted lines
>
> I should add that the Gitolite model is: the user doesn't need to know
> about namespaces, because namespaces are just things that the server
> admin is setting up for his own reasons...
>

I want to say something that git-namespace is sometimes significant for normal user not only for admin.

Some of my repos are managed by Topgit. With the help of topgit, dependance of the topic branch (usually named as "t/feature-name") are tracked by file ".topdeps" and a special ref named as "refs/top-bases/t/feature-name". So there are many topic branches and many useful special refs.

Every time when I want to update all topic branches to the new upstream version, just before run "tg update", I want to take a snapshoot of all branches and refs. Clone is heavy, so I want to use light-weight namespace.

If the server is out of my control, it would be nice to let the user pass namespace to the server from client side.

Indeed, I patched gitolite first as the follows, than I find out git-shell needs to be patched too.

diff --git a/src/gitolite-shell b/src/gitolite-shell
index 7a27cc0..1c957da 100755
--- a/src/gitolite-shell
+++ b/src/gitolite-shell
@@ -101,7 +101,7 @@ sub main {
     my $user = $ENV{GL_USER} = shift @ARGV;

     # set up the repo and the attempted access
-    my ( $verb, $repo ) = parse_soc();    # returns only for git commands
+    my ( $verb, $option, $repo ) = parse_soc();    # returns only for
git commands
     sanity($repo);
     $ENV{GL_REPO} = $repo;
     my $aa = ( $verb =~ 'upload' ? 'R' : 'W' );
@@ -135,7 +135,11 @@ sub main {
         _system( "git", "http-backend" );
     } else {
         my $repodir = "'$rc{GL_REPO_BASE}/$repo.git'";
-        _system( "git", "shell", "-c", "$verb $repodir" );
+        my $cmd = $verb;
+        if ($option) {
+            $cmd =~ s/^(git)[- ](.*)$/$1 $option $2/;
+        }
+        _system( "git", "shell", "-c", "$cmd $repodir" );
     }
     trigger( 'POST_GIT', $repo, $user, $aa, 'any', $verb );
 }
@@ -146,13 +150,24 @@ sub parse_soc {
     my $soc = $ENV{SSH_ORIGINAL_COMMAND};
     $soc ||= 'info';

-    my $git_commands = "git-upload-pack|git-receive-pack|git-upload-archive";
-    if ( $soc =~ m(^($git_commands) '/?(.*?)(?:\.git(\d)?)?'$) ) {
-        my ( $verb, $repo, $trace_level ) = ( $1, $2, $3 );
+    my $git_commands = "upload-pack|receive-pack|upload-archive";
+    my ( $verb, $option, $repo, $trace_level );
+    if ( $soc =~
m(^git\s+(?:(--namespace)(?:=|\s+)(\S+)\s+)?(\S+)\s+'/?(.*?)(?:\.git(\d)?)?'$)
) {
+        $option = "$1=$2";
+        $verb = "git-$3";
+        $repo = $4;
+        $trace_level = $5;
+    } elsif ( $soc =~ m(^git[- ]($git_commands) '/?(.*?)(?:\.git(\d)?)?'$) ) {
+        $verb = "git-$1";
+        $repo = $2;
+        $trace_level = $3;
+    }
+
+    if ($verb) {
         $ENV{D} = $trace_level if $trace_level;
         _die "invalid repo name: '$repo'" if $repo !~ $REPONAME_PATT;
         trace( 2, "git command", $soc );
-        return ( $verb, $repo );
+        return ( $verb, $option, $repo );
     }

     # after this we should not return; caller expects us to handle it all here
-- 
Jiang Xin
Previous: Sitaram ChamartyNext: Sitaram Chamarty
Message 5 of 6 in “Access different NAMESPACE of remote repo from client side”
  1. Jiang XinNov 15, 2013
  2. shell: allow git command with --namespace optionJiang Xin, Nov 15, 2013
  3. Sitaram ChamartyNov 15, 2013
  4. Sitaram ChamartyNov 15, 2013
  5. Jiang XinNov 16, 2013
  6. Sitaram ChamartyNov 16, 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.