threads / patch / 3057

patchShow non-naked git repositories in subdirectories as well.

Subject: [PATCH] Show non-naked git repositories in subdirectories as well.

## tl;dr

One message between Jan 12, 2006 and Jan 12, 2006. Diffs are folded; open one to read it.

replies: 0people: 1as markdown or json

Junio C Hamano· Jan 12, 2006, 08:55 UTC · lore

This allows $projects_list to name a directory under which a non-naked git project trees can hang.

Signed-off-by: Junio C Hamano <junkio@cox.net>
---
 * The development of this patch was done using the experimental
   "git checkout" I posted in thread:
     http://thread.gmane.org/gmane.comp.version-control.git/14375
   With the same workflow as I described there, I added this
   feature by working in the test branch, and then did this:
     $ git checkout -b projects master
   which automerged the changes in the test branch over to a new
   branch, based on Kay's upstream (thereby removing the effect
   of my other changes I had in the test branch).  All I had to
   do after that was to make a commit, and I am reasonably happy
   to see the checkout change is working nicely.
 gitweb.cgi |   20 +++++++++++---------
 1 files changed, 11 insertions(+), 9 deletions(-)
c302bfde91563778155084d13453b1c2bdc771d8
Show changes to gitweb.cgi +11 −9
diff --git a/gitweb.cgi b/gitweb.cgi
index 986d7da..ed52ed0 100755
--- a/gitweb.cgi
+++ b/gitweb.cgi
@@ -14,6 +14,7 @@ use CGI::Util qw(unescape);
 use CGI::Carp qw(fatalsToBrowser);
 use Encode;
 use Fcntl ':mode';
+use File::Find qw(find);
 binmode STDOUT, ':utf8';
 
 my $cgi = new CGI;
@@ -794,17 +795,18 @@ sub git_read_projects {
 
 	if (-d $projects_list) {
 		# search in directory
-		my $dir = $projects_list;
-		opendir my $dh, $dir or return undef;
-		while (my $dir = readdir($dh)) {
-			if (-e "$projectroot/$dir/HEAD") {
-				my $pr = {
-					path => $dir,
+		my $pl = quotemeta($projects_list);
+		find(sub {
+			if (/\.git$/ && -d _ &&
+			    (-l "$File::Find::name/HEAD" || -f _) &&
+			    $File::Find::name =~ /^$pl\/(.*)/) {
+				push @list, {
+					path => "$1"
 				};
-				push @list, $pr
+				$File::Find::prune = 1;
 			}
-		}
-		closedir($dh);
+		}, $projects_list);
+
 	} elsif (-f $projects_list) {
 		# read from file(url-encoded):
 		# 'git%2Fgit.git Linus+Torvalds'
-- 
1.1.1-g8a769

← back to recent threads