# [PATCH 2/2] gitweb: Remove git_to_hash function

5 messages from 2006-08-27 to 2006-08-31. Participants: Jakub Narebski, Junio C Hamano, Dennis Stosberg.
Thread: https://gitlist.dev/t/5411

## Jakub Narebski, 2006-08-27 21:43

Subject: [PATCH 0/2] gitweb: Get rid of failed experiments ;-)
Message-ID: <200608272343.14653.jnareb@gmail.com>
URL: https://gitlist.dev/e/200608272343.14653.jnareb%40gmail.com

```
Remove unused subroutines or subroutines which don't work correctly from 
gitweb.

-- 
Jakub Narebski
Poland

```

## Jakub Narebski, 2006-08-27 21:44

Subject: [PATCH 1/2] gitweb: Remove unused git_get_{preceding,following}_references
Message-ID: <200608272344.38542.jnareb@gmail.com>
URL: https://gitlist.dev/e/200608272344.38542.jnareb%40gmail.com
In-Reply-To: <200608272343.14653.jnareb@gmail.com>

```
Remove unused (and with errors in implementation)
git_get_{preceding,following}_references subroutines.

Signed-off-by: Jakub Narebski <jnareb@gmail.com>
---
 gitweb/gitweb.perl |   51 ---------------------------------------------------
 1 files changed, 0 insertions(+), 51 deletions(-)

diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index ba5024a..6918947 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -784,57 +784,6 @@ sub git_get_references {
 	return \%refs;
 }
 
-sub git_get_following_references {
-	my $hash = shift || return undef;
-	my $type = shift;
-	my $base = shift || $hash_base || "HEAD";
-
-	my $refs = git_get_references($type);
-	open my $fd, "-|", $GIT, "rev-list", $base
-		or return undef;
-	my @commits = map { chomp; $_ } <$fd>;
-	close $fd
-		or return undef;
-
-	my @reflist;
-	my $lastref;
-
-	foreach my $commit (@commits) {
-		foreach my $ref (@{$refs->{$commit}}) {
-			$lastref = $ref;
-			push @reflist, $lastref;
-		}
-		if ($commit eq $hash) {
-			last;
-		}
-	}
-
-	return wantarray ? @reflist : $lastref;
-}
-
-sub git_get_preceding_references {
-	my $hash = shift || return undef;
-	my $type = shift;
-
-	my $refs = git_get_references($type);
-	open my $fd, "-|", $GIT, "rev-list", $hash
-		or return undef;
-	my @commits = map { chomp; $_ } <$fd>;
-	close $fd
-		or return undef;
-
-	my @reflist;
-
-	foreach my $commit (@commits) {
-		foreach my $ref (@{$refs->{$commit}}) {
-			return $ref unless wantarray;
-			push @reflist, $ref;
-		}
-	}
-
-	return @reflist;
-}
-
 sub git_get_rev_name_tags {
 	my $hash = shift || return undef;
 
-- 
1.4.1.1

```

## Jakub Narebski, 2006-08-27 21:45

Subject: [PATCH 2/2] gitweb: Remove git_to_hash function
Message-ID: <200608272345.26722.jnareb@gmail.com>
URL: https://gitlist.dev/e/200608272345.26722.jnareb%40gmail.com
In-Reply-To: <200608272343.14653.jnareb@gmail.com>

```
Remove git_to_hash function, which was to translate symbolic reference
to hash, and it's use in git_blobdiff.  We don't try so hard to guess
filename if it was not provided.

Signed-off-by: Jakub Narebski <jnareb@gmail.com>
---
 gitweb/gitweb.perl |   27 +++------------------------
 1 files changed, 3 insertions(+), 24 deletions(-)

diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index 99c74f1..ae18c27 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -635,26 +635,6 @@ sub git_get_hash_by_path {
 	return $3;
 }
 
-# converts symbolic name to hash
-sub git_to_hash {
-	my @params = @_;
-	return undef unless @params;
-
-	open my $fd, "-|", $GIT, "rev-parse", @params
-		or return undef;
-	my @hashes = map { chomp; $_ } <$fd>;
-	close $fd;
-
-	if (wantarray) {
-		return @hashes;
-	} elsif (scalar(@hashes) == 1) {
-		# single hash
-		return $hashes[0];
-	} else {
-		return \@hashes;
-	}
-}
-
 ## ......................................................................
 ## git utility functions, directly accessing git repository
 
@@ -2739,10 +2719,9 @@ sub git_blobdiff {
 			@difftree
 				or die_error('404 Not Found', "Blob diff not found");
 
-		} elsif (defined $hash) { # try to find filename from $hash
-			if ($hash !~ /[0-9a-fA-F]{40}/) {
-				$hash = git_to_hash($hash);
-			}
+		} elsif (defined $hash &&
+		         $hash =~ /[0-9a-fA-F]{40}/) {
+			# try to find filename from $hash
 
 			# read filtered raw output
 			open $fd, "-|", $GIT, "diff-tree", '-r', @diff_opts, $hash_parent_base, $hash_base
-- 
1.4.1.1

```

## Junio C Hamano, 2006-08-27 22:22

Subject: Re: [PATCH 0/2] gitweb: Get rid of failed experiments ;-)
Message-ID: <7vac5px1ic.fsf@assigned-by-dhcp.cox.net>
URL: https://gitlist.dev/e/7vac5px1ic.fsf%40assigned-by-dhcp.cox.net
In-Reply-To: <200608272343.14653.jnareb@gmail.com>

```
Jakub Narebski <jnareb@gmail.com> writes:

> Remove unused subroutines or subroutines which don't work correctly from 
> gitweb.

I'll apply both, thanks.  [2/2] had a fuzz at the very end of
the second hunk (your base version do not have -M to diff-tree
parameter anymore) but that was easy to deal with.

Also thanks for the reminder about "typo in git_patchset_body".

```

## Dennis Stosberg, 2006-08-31 19:32

Subject: [PATCH] gitweb: Remove forgotten call to git_to_hash
Message-ID: <20060831193245.G22a7ca6b@leonov.stosberg.net>
URL: https://gitlist.dev/e/20060831193245.G22a7ca6b%40leonov.stosberg.net
In-Reply-To: <7vac5px1ic.fsf@assigned-by-dhcp.cox.net>

```
On Aug 27th, Jakub Narebski sent a patch which removed the git_to_hash()
function and this call to it. The patch did not apply cleanly and had to
be applied manually. Removing the last chunk has obviously been forgotten.

See: commit  0aea33762b1262d11fb43eda9f3fc152b5622cca and
     message <200608272345.26722.jnareb@gmail.com>

Signed-off-by: Dennis Stosberg <dennis@stosberg.net>
---
 gitweb/gitweb.perl |    4 ----
 1 files changed, 0 insertions(+), 4 deletions(-)

diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index 9324d71..68f40bd 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -2778,10 +2778,6 @@ sub git_blobdiff {
 			@difftree
 				or die_error('404 Not Found', "Blob diff not found");
 
-		} elsif (defined $hash) { # try to find filename from $hash
-			if ($hash !~ /[0-9a-fA-F]{40}/) {
-				$hash = git_to_hash($hash);
-			}
 		} elsif (defined $hash &&
 		         $hash =~ /[0-9a-fA-F]{40}/) {
 			# try to find filename from $hash
-- 
1.4.2

```
