Skip to content

Commit 51619c2

Browse files
committed
extracted some common code into one sub-routine
1 parent 202ee25 commit 51619c2

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

lib/Git/PurePerl.pm

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,6 @@ sub refs {
175175

176176
sub ref_sha1 {
177177
my ( $self, $wantref ) = @_;
178-
my @refs;
179178
my $dir = dir( $self->gitdir, 'refs' );
180179
return unless -d $dir;
181180

@@ -184,8 +183,7 @@ sub ref_sha1 {
184183
my $sha1 = file($file)->slurp
185184
|| confess("Error reading $file: $!");
186185
chomp $sha1;
187-
return $self->ref_sha1($1) if $sha1 =~ /^ref: (.*)/;
188-
return $sha1;
186+
return _ensure_sha1_is_sha1( $self, $sha1 );
189187
}
190188

191189
foreach my $file ( File::Find::Rule->new->file->in($dir) ) {
@@ -194,8 +192,7 @@ sub ref_sha1 {
194192
my $sha1 = file($file)->slurp
195193
|| confess("Error reading $file: $!");
196194
chomp $sha1;
197-
return $self->ref_sha1($1) if $sha1 =~ /^ref: (.*)/;
198-
return $sha1;
195+
return _ensure_sha1_is_sha1( $self, $sha1 );
199196
}
200197
}
201198

@@ -204,15 +201,18 @@ sub ref_sha1 {
204201
foreach my $line ( $packed_refs->slurp( chomp => 1 ) ) {
205202
next if $line =~ /^#/;
206203
my ( $sha1, my $name ) = split ' ', $line;
207-
if ( $name eq $wantref ) {
208-
return $self->ref_sha1($1) if $sha1 =~ /^ref: (.*)/;
209-
return $sha1;
210-
}
204+
return _ensure_sha1_is_sha1( $self, $sha1 ) if $name eq $wantref;
211205
}
212206
}
213207
return undef;
214208
}
215209

210+
sub _ensure_sha1_is_sha1 {
211+
my ( $self, $sha1 ) = @_;
212+
return $self->ref_sha1($1) if $sha1 =~ /^ref: (.*)/;
213+
return $sha1;
214+
}
215+
216216
sub ref {
217217
my ( $self, $wantref ) = @_;
218218
return $self->get_object( $self->ref_sha1($wantref) );
@@ -557,4 +557,3 @@ This module is free software; you can redistribute it or
557557
modify it under the same terms as Perl itself.
558558
559559
=cut
560-

0 commit comments

Comments
 (0)