@@ -155,6 +155,7 @@ sub ref_names {
155
155
if ( -f $packed_refs ) {
156
156
foreach my $line ( $packed_refs -> slurp( chomp => 1 ) ) {
157
157
next if $line =~ / ^#/ ;
158
+ next if $line =~ / ^\^ / ;
158
159
my ( $sha1 , my $name ) = split ' ' , $line ;
159
160
push @names , $name ;
160
161
}
@@ -174,7 +175,6 @@ sub refs {
174
175
175
176
sub ref_sha1 {
176
177
my ( $self , $wantref ) = @_ ;
177
- my @refs ;
178
178
my $dir = dir( $self -> gitdir, ' refs' );
179
179
return unless -d $dir ;
180
180
@@ -183,8 +183,7 @@ sub ref_sha1 {
183
183
my $sha1 = file($file )-> slurp
184
184
|| confess(" Error reading $file : $! " );
185
185
chomp $sha1 ;
186
- return $self -> ref_sha1($1 ) if $sha1 =~ / ^ref: (.*)/ ;
187
- return $sha1 ;
186
+ return _ensure_sha1_is_sha1( $self , $sha1 );
188
187
}
189
188
190
189
foreach my $file ( File::Find::Rule-> new-> file-> in($dir ) ) {
@@ -193,25 +192,36 @@ sub ref_sha1 {
193
192
my $sha1 = file($file )-> slurp
194
193
|| confess(" Error reading $file : $! " );
195
194
chomp $sha1 ;
196
- return $self -> ref_sha1($1 ) if $sha1 =~ / ^ref: (.*)/ ;
197
- return $sha1 ;
195
+ return _ensure_sha1_is_sha1( $self , $sha1 );
198
196
}
199
197
}
200
198
201
199
my $packed_refs = file( $self -> gitdir, ' packed-refs' );
202
200
if ( -f $packed_refs ) {
201
+ my $last_name ;
202
+ my $last_sha1 ;
203
203
foreach my $line ( $packed_refs -> slurp( chomp => 1 ) ) {
204
204
next if $line =~ / ^#/ ;
205
205
my ( $sha1 , my $name ) = split ' ' , $line ;
206
- if ( $name eq $wantref ) {
207
- return $self -> ref_sha1($1 ) if $sha1 =~ / ^ref: (.*)/ ;
208
- return $sha1 ;
209
- }
206
+ $sha1 =~ s / ^\^ // ;
207
+ $name ||= $last_name ;
208
+
209
+ return _ensure_sha1_is_sha1( $self , $last_sha1 ) if $last_name and $last_name eq $wantref and $name ne $wantref ;
210
+
211
+ $last_name = $name ;
212
+ $last_sha1 = $sha1 ;
210
213
}
214
+ return _ensure_sha1_is_sha1( $self , $last_sha1 ) if $last_name eq $wantref ;
211
215
}
212
216
return undef ;
213
217
}
214
218
219
+ sub _ensure_sha1_is_sha1 {
220
+ my ( $self , $sha1 ) = @_ ;
221
+ return $self -> ref_sha1($1 ) if $sha1 =~ / ^ref: (.*)/ ;
222
+ return $sha1 ;
223
+ }
224
+
215
225
sub ref {
216
226
my ( $self , $wantref ) = @_ ;
217
227
return $self -> get_object( $self -> ref_sha1($wantref ) );
@@ -556,4 +566,3 @@ This module is free software; you can redistribute it or
556
566
modify it under the same terms as Perl itself.
557
567
558
568
=cut
559
-
0 commit comments