Skip to contentSkip to conversation

Git.pm: Add remote_refs() git-ls-remote frontend

PATCH In review Petr Baudis 3 participants 9 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Git.pm: Add remote_refs() git-ls-remote frontend

Should support all the important features, I guess. Too bad that

	git-ls-remote --heads .

is subtly different from

git-ls-remote . refs/heads/

so we have to provide the interface for specifying both.

This patch also converts git-remote.perl to use it.

---

 git-remote.perl |    5 +----
 perl/Git.pm     |   55 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 55 insertions(+), 5 deletions(-)
git-remote.perl +1 -4
index 01cf480..8ce8418 100755
@@ -128,10 +128,7 @@ sub update_ls_remote {
 	return if (($harder == 0) ||
 		   (($harder == 1) && exists $info->{'LS_REMOTE'}));
 
-	my @ref = map {
-		s|^[0-9a-f]{40}\s+refs/heads/||;
-		$_;
-	} $git->command(qw(ls-remote --heads), $info->{'URL'});
+	my @ref = keys %{$git->remote_refs($info->{'URL'}, [ 'heads' ])};
 	$info->{'LS_REMOTE'} = \@ref;
 }
 
perl/Git.pm +54 -1

67 lines not on this page · raw message

#1 lore raw
Quoted 5 lines · Petr Baudis
git-remote.perl +0 -0
index 01cf480..8ce8418 100755

git-remote.perl sub update_ls_remote { · line 133

Quoted 10 lines
git-remote.perl +1 -4
@@ -128,10 +128,7 @@ sub update_ls_remote {
 	return if (($harder == 0) ||
 		   (($harder == 1) && exists $info->{'LS_REMOTE'}));
 
-	my @ref = map {
-		s|^[0-9a-f]{40}\s+refs/heads/||;
-		$_;
-	} $git->command(qw(ls-remote --heads), $info->{'URL'});
+	my @ref = keys %{$git->remote_refs($info->{'URL'}, [ 'heads' ])};
 	$info->{'LS_REMOTE'} = \@ref;
 }

IIRC, ls-remote returns refs sorted and this function returns them as it receives.

Doesn't this change make @ref randomly ordered?

#2 lore raw
Quoted 21 lines · Junio C Hamano
Quoted 5 lines · Petr Baudis
git-remote.perl +0 -0
index 01cf480..8ce8418 100755

git-remote.perl sub update_ls_remote { · line 133

Quoted 10 lines
git-remote.perl +1 -4
@@ -128,10 +128,7 @@ sub update_ls_remote {
 	return if (($harder == 0) ||
 		   (($harder == 1) && exists $info->{'LS_REMOTE'}));
 
-	my @ref = map {
-		s|^[0-9a-f]{40}\s+refs/heads/||;
-		$_;
-	} $git->command(qw(ls-remote --heads), $info->{'URL'});
+	my @ref = keys %{$git->remote_refs($info->{'URL'}, [ 'heads' ])};
 	$info->{'LS_REMOTE'} = \@ref;
 }

IIRC, ls-remote returns refs sorted and this function returns them as it receives.

Quoted 1 line

Doesn't this change make @ref randomly ordered?

Yes, but I couldn't find any place in git-remote.perl where we rely on the @ref ordering - maybe I'm blind...

Signature · 3 lines
				Petr "Pasky" Baudis
Ever try. Ever fail. No matter. // Try again. Fail again. Fail better.
		-- Samuel Beckett
#3 lore raw

PATCH 1/1 Git.pm: Add remote_refs() git-ls-remote frontend

In reply to Petr Baudis

Should support all the important features, I guess. Too bad that

	git-ls-remote --heads .

is subtly different from

git-ls-remote . refs/heads/

so we have to provide the interface for specifying both.

This patch also converts git-remote.perl to use it.

---
This version re-adds missed out stripping of refs/heads/ in git-remote.perl.
---

 git-remote.perl |    5 +----
 perl/Git.pm     |   55 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 55 insertions(+), 5 deletions(-)
git-remote.perl +1 -4
index 01cf480..1948c5c 100755
@@ -128,10 +128,7 @@ sub update_ls_remote {
 	return if (($harder == 0) ||
 		   (($harder == 1) && exists $info->{'LS_REMOTE'}));
 
-	my @ref = map {
-		s|^[0-9a-f]{40}\s+refs/heads/||;
-		$_;
-	} $git->command(qw(ls-remote --heads), $info->{'URL'});
+	my @ref = map { s|refs/heads/||; $_; } keys %{$git->remote_refs($info->{'URL'}, [ 'heads' ])};
 	$info->{'LS_REMOTE'} = \@ref;
 }
 
perl/Git.pm +54 -1

67 lines not on this page · raw message

#4 lore raw
Quoted 9 lines · Petr Baudis

Should support all the important features, I guess. Too bad that

	git-ls-remote --heads .

is subtly different from

git-ls-remote . refs/heads/

so we have to provide the interface for specifying both.

Are they subtly different? To me they look like asking for completely different things. IIRC, the patterns are ref globs, so

git ls-remote $URL 'refs/heads/*'

would be the same as the former one.

Quoted 5 lines

This patch also converts git-remote.perl to use it.

---
This version re-adds missed out stripping of refs/heads/ in git-remote.perl.

Ah, that was the bug you were talking about on #git channel, I guess...

#5 lore raw
Quoted 12 lines · Junio C Hamano
Quoted 9 lines · Petr Baudis

Should support all the important features, I guess. Too bad that

	git-ls-remote --heads .

is subtly different from

git-ls-remote . refs/heads/

so we have to provide the interface for specifying both.

Quoted 7 lines

Are they subtly different? To me they look like asking for completely different things. IIRC, the patterns are ref globs, so

git ls-remote $URL 'refs/heads/*'

would be the same as the former one.

Yes, though subtly different, as I've already explained before - for the case of say

refs/remotes/evil/refs/heads

Quoted 2 lines

Ah, that was the bug you were talking about on #git channel, I guess...

*nod*

Signature · 3 lines
				Petr "Pasky" Baudis
Early to rise and early to bed makes a male healthy and wealthy and dead.
                -- James Thurber
#6 lore raw
Quoted 8 lines · Petr Baudis
Quoted 3 lines

git ls-remote $URL 'refs/heads/*'

would be the same as the former one.

Yes, though subtly different, as I've already explained before - for the case of say

refs/remotes/evil/refs/heads

Are you voting for removal of "ls-remote $URL 'heads/*'" support? I actually think removing it makes a perfect sense.

Quoted 4 lines
Quoted 2 lines

Ah, that was the bug you were talking about on #git channel, I guess...

*nod*

#7 lore raw
In reply to Petr Baudis

[Cc: Petr Baudis <[email protected]>, [email protected]]

Quoted 8 lines · Petr Baudis

Should support all the important features, I guess. Too bad that

      git-ls-remote --heads .

is subtly different from

git-ls-remote . refs/heads/

so we have to provide the interface for specifying both.

Why do not use git-for-each-ref or git-show-refs? If I remember correctly they _were_ faster than git-ls-remote or git-peek-remote...

Signature · 3 lines
Jakub Narebski
Warsaw, Poland
ShadeHawk on #git
#8 lore raw
Quoted 7 lines · Jakub Narebski

[Cc: Petr Baudis <[email protected]>, [email protected]]

Quoted 3 lines · Petr Baudis

Should support all the important features, I guess. Too bad that

      git-ls-remote --heads .
Quoted 8 lines
Quoted 5 lines

is subtly different from

git-ls-remote . refs/heads/

so we have to provide the interface for specifying both.

Why do not use git-for-each-ref or git-show-refs? If I remember correctly they _were_ faster than git-ls-remote or git-peek-remote...

But we want to typically list refs in a remote repository.

Signature · 3 lines
				Petr "Pasky" Baudis
Early to rise and early to bed makes a male healthy and wealthy and dead.
                -- James Thurber