{"thread":{"id":"9643","subject":"[PATCH] Git.pm: Add remote_refs() git-ls-remote frontend","startedAt":"2007-08-25T22:11:44Z","lastAt":"2007-08-31T02:13:23Z","messageCount":9,"participants":["Petr Baudis","Junio C Hamano","Jakub Narebski"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"51533","messageId":"20070825221143.6514.22516.stgit@rover","threadId":"9643","inReplyTo":null,"subject":"[PATCH] Git.pm: Add remote_refs() git-ls-remote frontend","fromName":"Petr Baudis","fromEmail":"pasky@suse.cz","sentAt":"2007-08-25T22:11:44Z","receivedAt":"2007-08-25T22:11:44Z","isPatch":true,"sender":{"key":"pasky@ucw.cz","avatar":"https://avatars.githubusercontent.com/u/18439?v=4"},"body":"Should support all the important features, I guess. Too bad that\n\tgit-ls-remote --heads .\n\t\nis subtly different from\n\n\tgit-ls-remote . refs/heads/\n\nso we have to provide the interface for specifying both.\n\nThis patch also converts git-remote.perl to use it.\n\nSigned-off-by: Petr Baudis <pasky@suse.cz>\n---\n\n git-remote.perl |    5 +----\n perl/Git.pm     |   55 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-\n 2 files changed, 55 insertions(+), 5 deletions(-)\n\ndiff --git a/git-remote.perl b/git-remote.perl\nindex 01cf480..8ce8418 100755\n--- a/git-remote.perl\n+++ b/git-remote.perl\n@@ -128,10 +128,7 @@ sub update_ls_remote {\n \treturn if (($harder == 0) ||\n \t\t   (($harder == 1) && exists $info->{'LS_REMOTE'}));\n \n-\tmy @ref = map {\n-\t\ts|^[0-9a-f]{40}\\s+refs/heads/||;\n-\t\t$_;\n-\t} $git->command(qw(ls-remote --heads), $info->{'URL'});\n+\tmy @ref = keys %{$git->remote_refs($info->{'URL'}, [ 'heads' ])};\n \t$info->{'LS_REMOTE'} = \\@ref;\n }\n \ndiff --git a/perl/Git.pm b/perl/Git.pm\nindex 3f4080c..3bce733 100644\n--- a/perl/Git.pm\n+++ b/perl/Git.pm\n@@ -51,7 +51,7 @@ require Exporter;\n # Methods which can be called as standalone functions as well:\n @EXPORT_OK = qw(command command_oneline command_noisy\n                 command_output_pipe command_input_pipe command_close_pipe\n-                version exec_path hash_object git_cmd_try);\n+                version exec_path hash_object git_cmd_try remote_refs);\n \n \n =head1 DESCRIPTION\n@@ -550,6 +550,59 @@ sub config_bool {\n }\n \n \n+=item remote_refs ( REPOSITORY [, GROUPS [, REFGLOBS ] ] )\n+\n+This function returns a hashref of refs stored in a given remote repository.\n+The hash is in the format C<refname =\\> hash>. For tags, the C<refname> entry\n+contains the tag object while a C<refname^{}> entry gives the tagged objects.\n+\n+C<REPOSITORY> has the same meaning as the appropriate C<git-ls-remote>\n+argument; either an URL or a remote name (if called on a repository instance).\n+C<GROUPS> is an optional arrayref that can contain 'tags' to return all the\n+tags and/or 'heads' to return all the heads. C<REFGLOB> is an optional array\n+of strings containing a shell-like glob to further limit the refs returned in\n+the hash; the meaning is again the same as the appropriate C<git-ls-remote>\n+argument.\n+\n+This function may or may not be called on a repository instance. In the former\n+case, remote names as defined in the repository are recognized as repository\n+specifiers.\n+\n+=cut\n+\n+sub remote_refs {\n+\tmy ($self, $repo, $groups, $refglobs) = _maybe_self(@_);\n+\tmy @args;\n+\tif (ref $groups eq 'ARRAY') {\n+\t\tforeach (@$groups) {\n+\t\t\tif ($_ eq 'heads') {\n+\t\t\t\tpush (@args, '--heads');\n+\t\t\t} elsif ($_ eq 'tags') {\n+\t\t\t\tpush (@args, '--tags');\n+\t\t\t} else {\n+\t\t\t\t# Ignore unknown groups for future\n+\t\t\t\t# compatibility\n+\t\t\t}\n+\t\t}\n+\t}\n+\tpush (@args, $repo);\n+\tif (ref $refglobs eq 'ARRAY') {\n+\t\tpush (@args, @$refglobs);\n+\t}\n+\n+\tmy @self = $self ? ($self) : (); # Ultra trickery\n+\tmy ($fh, $ctx) = Git::command_output_pipe(@self, 'ls-remote', @args);\n+\tmy %refs;\n+\twhile (<$fh>) {\n+\t\tchomp;\n+\t\tmy ($hash, $ref) = split(/\\t/, $_, 2);\n+\t\t$refs{$ref} = $hash;\n+\t}\n+\tGit::command_close_pipe(@self, $fh, $ctx);\n+\treturn \\%refs;\n+}\n+\n+\n =item ident ( TYPE | IDENTSTR )\n \n =item ident_person ( TYPE | IDENTSTR | IDENTARRAY )\n"},{"id":"51542","messageId":"7v6432udje.fsf@gitster.siamese.dyndns.org","threadId":"9643","inReplyTo":"20070825221143.6514.22516.stgit@rover","subject":"Re: [PATCH] Git.pm: Add remote_refs() git-ls-remote frontend","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2007-08-26T04:26:29Z","receivedAt":"2007-08-26T04:26:29Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Petr Baudis <pasky@suse.cz> writes:\n\n> diff --git a/git-remote.perl b/git-remote.perl\n> index 01cf480..8ce8418 100755\n> --- a/git-remote.perl\n> +++ b/git-remote.perl\n> @@ -128,10 +128,7 @@ sub update_ls_remote {\n>  \treturn if (($harder == 0) ||\n>  \t\t   (($harder == 1) && exists $info->{'LS_REMOTE'}));\n>  \n> -\tmy @ref = map {\n> -\t\ts|^[0-9a-f]{40}\\s+refs/heads/||;\n> -\t\t$_;\n> -\t} $git->command(qw(ls-remote --heads), $info->{'URL'});\n> +\tmy @ref = keys %{$git->remote_refs($info->{'URL'}, [ 'heads' ])};\n>  \t$info->{'LS_REMOTE'} = \\@ref;\n>  }\n\nIIRC, ls-remote returns refs sorted and this function returns\nthem as it receives.\n\nDoesn't this change make @ref randomly ordered?  \n"},{"id":"51553","messageId":"20070826095836.GG1219@pasky.or.cz","threadId":"9643","inReplyTo":"7v6432udje.fsf@gitster.siamese.dyndns.org","subject":"Re: [PATCH] Git.pm: Add remote_refs() git-ls-remote frontend","fromName":"Petr Baudis","fromEmail":"pasky@suse.cz","sentAt":"2007-08-26T09:58:36Z","receivedAt":"2007-08-26T09:58:36Z","isPatch":true,"sender":{"key":"pasky@ucw.cz","avatar":"https://avatars.githubusercontent.com/u/18439?v=4"},"body":"On Sun, Aug 26, 2007 at 06:26:29AM CEST, Junio C Hamano wrote:\n> Petr Baudis <pasky@suse.cz> writes:\n> \n> > diff --git a/git-remote.perl b/git-remote.perl\n> > index 01cf480..8ce8418 100755\n> > --- a/git-remote.perl\n> > +++ b/git-remote.perl\n> > @@ -128,10 +128,7 @@ sub update_ls_remote {\n> >  \treturn if (($harder == 0) ||\n> >  \t\t   (($harder == 1) && exists $info->{'LS_REMOTE'}));\n> >  \n> > -\tmy @ref = map {\n> > -\t\ts|^[0-9a-f]{40}\\s+refs/heads/||;\n> > -\t\t$_;\n> > -\t} $git->command(qw(ls-remote --heads), $info->{'URL'});\n> > +\tmy @ref = keys %{$git->remote_refs($info->{'URL'}, [ 'heads' ])};\n> >  \t$info->{'LS_REMOTE'} = \\@ref;\n> >  }\n> \n> IIRC, ls-remote returns refs sorted and this function returns\n> them as it receives.\n> \n> Doesn't this change make @ref randomly ordered?  \n\nYes, but I couldn't find any place in git-remote.perl where we rely on\nthe @ref ordering - maybe I'm blind...\n\n-- \n\t\t\t\tPetr \"Pasky\" Baudis\nEver try. Ever fail. No matter. // Try again. Fail again. Fail better.\n\t\t-- Samuel Beckett\n"},{"id":"51884","messageId":"fb5vod$vvc$1@sea.gmane.org","threadId":"9643","inReplyTo":"20070825221143.6514.22516.stgit@rover","subject":"Re: [PATCH] Git.pm: Add remote_refs() git-ls-remote frontend","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2007-08-30T08:39:41Z","receivedAt":"2007-08-30T08:39:41Z","isPatch":true,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"[Cc: Petr Baudis <pasky@suse.cz>, git@vger.kernel.org]\n\nPetr Baudis wrote:\n\n> Should support all the important features, I guess. Too bad that\n>       git-ls-remote --heads .\n>       \n> is subtly different from\n> \n>       git-ls-remote . refs/heads/\n> \n> so we have to provide the interface for specifying both.\n\nWhy do not use git-for-each-ref or git-show-refs? If I remember correctly\nthey _were_ faster than git-ls-remote or git-peek-remote...\n\n-- \nJakub Narebski\nWarsaw, Poland\nShadeHawk on #git\n"},{"id":"51962","messageId":"20070830233714.GJ1219@pasky.or.cz","threadId":"9643","inReplyTo":"fb5vod$vvc$1@sea.gmane.org","subject":"Re: [PATCH] Git.pm: Add remote_refs() git-ls-remote frontend","fromName":"Petr Baudis","fromEmail":"pasky@suse.cz","sentAt":"2007-08-30T23:37:15Z","receivedAt":"2007-08-30T23:37:15Z","isPatch":true,"sender":{"key":"pasky@ucw.cz","avatar":"https://avatars.githubusercontent.com/u/18439?v=4"},"body":"On Thu, Aug 30, 2007 at 10:39:41AM CEST, Jakub Narebski wrote:\n> [Cc: Petr Baudis <pasky@suse.cz>, git@vger.kernel.org]\n> \n> Petr Baudis wrote:\n> \n> > Should support all the important features, I guess. Too bad that\n> >       git-ls-remote --heads .\n> >       \n> > is subtly different from\n> > \n> >       git-ls-remote . refs/heads/\n> > \n> > so we have to provide the interface for specifying both.\n> \n> Why do not use git-for-each-ref or git-show-refs? If I remember correctly\n> they _were_ faster than git-ls-remote or git-peek-remote...\n\nBut we want to typically list refs in a remote repository.\n\n-- \n\t\t\t\tPetr \"Pasky\" Baudis\nEarly to rise and early to bed makes a male healthy and wealthy and dead.\n                -- James Thurber\n"},{"id":"51963","messageId":"20070830233749.4480.72281.stgit@rover","threadId":"9643","inReplyTo":"20070825221143.6514.22516.stgit@rover","subject":"[PATCH] Git.pm: Add remote_refs() git-ls-remote frontend","fromName":"Petr Baudis","fromEmail":"pasky@suse.cz","sentAt":"2007-08-30T23:37:49Z","receivedAt":"2007-08-30T23:37:49Z","isPatch":true,"sender":{"key":"pasky@ucw.cz","avatar":"https://avatars.githubusercontent.com/u/18439?v=4"},"body":"Should support all the important features, I guess. Too bad that\n\tgit-ls-remote --heads .\n\t\nis subtly different from\n\n\tgit-ls-remote . refs/heads/\n\nso we have to provide the interface for specifying both.\n\nThis patch also converts git-remote.perl to use it.\n\nSigned-off-by: Petr Baudis <pasky@suse.cz>\n---\nThis version re-adds missed out stripping of refs/heads/ in git-remote.perl.\n---\n\n git-remote.perl |    5 +----\n perl/Git.pm     |   55 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-\n 2 files changed, 55 insertions(+), 5 deletions(-)\n\ndiff --git a/git-remote.perl b/git-remote.perl\nindex 01cf480..1948c5c 100755\n--- a/git-remote.perl\n+++ b/git-remote.perl\n@@ -128,10 +128,7 @@ sub update_ls_remote {\n \treturn if (($harder == 0) ||\n \t\t   (($harder == 1) && exists $info->{'LS_REMOTE'}));\n \n-\tmy @ref = map {\n-\t\ts|^[0-9a-f]{40}\\s+refs/heads/||;\n-\t\t$_;\n-\t} $git->command(qw(ls-remote --heads), $info->{'URL'});\n+\tmy @ref = map { s|refs/heads/||; $_; } keys %{$git->remote_refs($info->{'URL'}, [ 'heads' ])};\n \t$info->{'LS_REMOTE'} = \\@ref;\n }\n \ndiff --git a/perl/Git.pm b/perl/Git.pm\nindex 3f4080c..3bce733 100644\n--- a/perl/Git.pm\n+++ b/perl/Git.pm\n@@ -51,7 +51,7 @@ require Exporter;\n # Methods which can be called as standalone functions as well:\n @EXPORT_OK = qw(command command_oneline command_noisy\n                 command_output_pipe command_input_pipe command_close_pipe\n-                version exec_path hash_object git_cmd_try);\n+                version exec_path hash_object git_cmd_try remote_refs);\n \n \n =head1 DESCRIPTION\n@@ -550,6 +550,59 @@ sub config_bool {\n }\n \n \n+=item remote_refs ( REPOSITORY [, GROUPS [, REFGLOBS ] ] )\n+\n+This function returns a hashref of refs stored in a given remote repository.\n+The hash is in the format C<refname =\\> hash>. For tags, the C<refname> entry\n+contains the tag object while a C<refname^{}> entry gives the tagged objects.\n+\n+C<REPOSITORY> has the same meaning as the appropriate C<git-ls-remote>\n+argument; either an URL or a remote name (if called on a repository instance).\n+C<GROUPS> is an optional arrayref that can contain 'tags' to return all the\n+tags and/or 'heads' to return all the heads. C<REFGLOB> is an optional array\n+of strings containing a shell-like glob to further limit the refs returned in\n+the hash; the meaning is again the same as the appropriate C<git-ls-remote>\n+argument.\n+\n+This function may or may not be called on a repository instance. In the former\n+case, remote names as defined in the repository are recognized as repository\n+specifiers.\n+\n+=cut\n+\n+sub remote_refs {\n+\tmy ($self, $repo, $groups, $refglobs) = _maybe_self(@_);\n+\tmy @args;\n+\tif (ref $groups eq 'ARRAY') {\n+\t\tforeach (@$groups) {\n+\t\t\tif ($_ eq 'heads') {\n+\t\t\t\tpush (@args, '--heads');\n+\t\t\t} elsif ($_ eq 'tags') {\n+\t\t\t\tpush (@args, '--tags');\n+\t\t\t} else {\n+\t\t\t\t# Ignore unknown groups for future\n+\t\t\t\t# compatibility\n+\t\t\t}\n+\t\t}\n+\t}\n+\tpush (@args, $repo);\n+\tif (ref $refglobs eq 'ARRAY') {\n+\t\tpush (@args, @$refglobs);\n+\t}\n+\n+\tmy @self = $self ? ($self) : (); # Ultra trickery\n+\tmy ($fh, $ctx) = Git::command_output_pipe(@self, 'ls-remote', @args);\n+\tmy %refs;\n+\twhile (<$fh>) {\n+\t\tchomp;\n+\t\tmy ($hash, $ref) = split(/\\t/, $_, 2);\n+\t\t$refs{$ref} = $hash;\n+\t}\n+\tGit::command_close_pipe(@self, $fh, $ctx);\n+\treturn \\%refs;\n+}\n+\n+\n =item ident ( TYPE | IDENTSTR )\n \n =item ident_person ( TYPE | IDENTSTR | IDENTARRAY )\n"},{"id":"51968","messageId":"7vr6lk5z2p.fsf@gitster.siamese.dyndns.org","threadId":"9643","inReplyTo":"20070830233749.4480.72281.stgit@rover","subject":"Re: [PATCH] Git.pm: Add remote_refs() git-ls-remote frontend","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2007-08-31T00:26:22Z","receivedAt":"2007-08-31T00:26:22Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Petr Baudis <pasky@suse.cz> writes:\n\n> Should support all the important features, I guess. Too bad that\n>\n> \tgit-ls-remote --heads .\n> \t\n> is subtly different from\n>\n> \tgit-ls-remote . refs/heads/\n>\n> so we have to provide the interface for specifying both.\n\nAre they subtly different?  To me they look like asking for\ncompletely different things.  IIRC, the patterns are ref globs,\nso\n\n\tgit ls-remote $URL 'refs/heads/*'\n\nwould be the same as the former one.\n\n> This patch also converts git-remote.perl to use it.\n>\n> Signed-off-by: Petr Baudis <pasky@suse.cz>\n> ---\n> This version re-adds missed out stripping of refs/heads/ in git-remote.perl.\n\nAh, that was the bug you were talking about on #git channel, I\nguess...\n"},{"id":"51972","messageId":"20070831013700.GL1219@pasky.or.cz","threadId":"9643","inReplyTo":"7vr6lk5z2p.fsf@gitster.siamese.dyndns.org","subject":"Re: [PATCH] Git.pm: Add remote_refs() git-ls-remote frontend","fromName":"Petr Baudis","fromEmail":"pasky@suse.cz","sentAt":"2007-08-31T01:37:00Z","receivedAt":"2007-08-31T01:37:00Z","isPatch":true,"sender":{"key":"pasky@ucw.cz","avatar":"https://avatars.githubusercontent.com/u/18439?v=4"},"body":"On Fri, Aug 31, 2007 at 02:26:22AM CEST, Junio C Hamano wrote:\n> Petr Baudis <pasky@suse.cz> writes:\n> \n> > Should support all the important features, I guess. Too bad that\n> >\n> > \tgit-ls-remote --heads .\n> > \t\n> > is subtly different from\n> >\n> > \tgit-ls-remote . refs/heads/\n> >\n> > so we have to provide the interface for specifying both.\n> \n> Are they subtly different?  To me they look like asking for\n> completely different things.  IIRC, the patterns are ref globs,\n> so\n> \n> \tgit ls-remote $URL 'refs/heads/*'\n> \n> would be the same as the former one.\n\nYes, though subtly different, as I've already explained before - for the\ncase of say\n\n\trefs/remotes/evil/refs/heads\n\n> Ah, that was the bug you were talking about on #git channel, I\n> guess...\n\n*nod*\n\n-- \n\t\t\t\tPetr \"Pasky\" Baudis\nEarly to rise and early to bed makes a male healthy and wealthy and dead.\n                -- James Thurber\n"},{"id":"51975","messageId":"7vir6w5u4c.fsf@gitster.siamese.dyndns.org","threadId":"9643","inReplyTo":"20070831013700.GL1219@pasky.or.cz","subject":"Re: [PATCH] Git.pm: Add remote_refs() git-ls-remote frontend","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2007-08-31T02:13:23Z","receivedAt":"2007-08-31T02:13:23Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Petr Baudis <pasky@suse.cz> writes:\n\n>> \tgit ls-remote $URL 'refs/heads/*'\n>> \n>> would be the same as the former one.\n>\n> Yes, though subtly different, as I've already explained before - for the\n> case of say\n>\n> \trefs/remotes/evil/refs/heads\n\nAre you voting for removal of \"ls-remote $URL 'heads/*'\" support?\nI actually think removing it makes a perfect sense.\n\n>> Ah, that was the bug you were talking about on #git channel, I\n>> guess...\n>\n> *nod*\n"}]}