From: Jakub Narebski <jnareb@gmail.com>
To: Junio C Hamano <jch@google.com>
Cc: Kacper Kornet <draenog@pld-linux.org>, git@vger.kernel.org
Subject: Re: [PATCH] gitweb: Improve repository verification
Date: Sat, 21 Apr 2012 13:28:24 +0200 [thread overview]
Message-ID: <201204211328.25162.jnareb@gmail.com> (raw)
In-Reply-To: <201204192146.09853.jnareb@gmail.com>
On Thu, 19 April 2012, Jakub Narebski wrote:
> On Thu, 19 April 2012, Junio C Hamano wrote:
> > By the way, I wonder (1) if it is worth adding support for the textual
> > ".git" file that contains "gitdir: $path", and (2) if so how big a
> > change would we need to do so.
>
> I don't think that it would be big change to add support for "gitlink"
> files, assuming that 'git --git-dir=<gitlink file> ...' works correctly.
> I would put that addition in a separate commit, though.
Well, I actually tried to write such commit, adding support for
'gitlink' files, and it turned out to be harder than I thought.
The problem that stumped me for now is that gitweb tries to read
many files inside git repository ('export-ok', 'description',
'cloneurl', 'category', etc.), allof which must be redirected to
real git directory.
I still think it is doable, but I wonder if it is worth it...
Below there is work in progress patch, which doesn't use resolve_gitdir
yet, and without any tests.
-- >8 ---------- >8 --
Subject: [PATCH] gitweb: Add support for "gitdir: <path>" gitfile
Suggested-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Jakub Narebski <jnareb@gmail.com>
---
gitweb/gitweb.perl | 54 ++++++++++++++++++++++++++++++++++++++++++++++++---
1 files changed, 50 insertions(+), 4 deletions(-)
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index 767d7a5..8d70a0a 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -639,6 +639,52 @@ sub is_git_directory {
validate_headref("$dir/HEAD");
}
+# Try to read the location of the git directory from the .git file,
+# return path to git directory if found.
+#
+# See read_gitfile in setup.c
+sub read_gitfile {
+ my $path = shift;
+ # note: the "basename eq '.git'" check isn't in setup.c version
+ return unless ($path =~ m!(?:^|/)\.git/*$! && -f $path);
+
+ open my $fh, '<', $path or return;
+ my $contents = do { local $/ = undef; <$fh> };
+ close $fh or return;
+ return unless defined $contents;
+ chomp($contents);
+
+ return unless ($contents =~ s!^gitdir: !!);
+
+ if (!File::Spec->file_name_is_absolute($contents)) {
+ $contents = File::Spec->catfile(File::Basename::dirname($path), $contents);
+ }
+
+ return unless is_git_directory($contents);
+ return $contents;
+}
+
+# Test if it looks like we're at a git repository
+#
+# - a '.git' file containing "gitdir: <path>",
+# - a git directory.
+sub is_git_repository {
+ my $path = shift;
+ return defined(read_gitfile($path)) || is_git_directory($path);
+}
+
+# Return directory of a git repository, resolving '.git' files
+# (file containing "gitdir: <path>") if any
+#
+# See resolve_gitdir in setup.c
+sub resolve_gitdir {
+ my $suspect = shift;
+ if (is_git_directory($suspect)) {
+ return $suspect;
+ }
+ return read_gitfile($suspect);
+}
+
# Check HEAD file, that it is either
#
# - a "refs/heads/.." symlink, or
@@ -665,7 +711,7 @@ sub validate_headref {
sub check_export_ok {
my ($dir) = @_;
- return (is_git_directory($dir) &&
+ return (is_git_repository($dir) &&
(!$export_ok || -e "$dir/$export_ok") &&
(!$export_auth_hook || $export_auth_hook->($dir)));
}
@@ -874,7 +920,7 @@ sub evaluate_path_info {
# find which part of PATH_INFO is project
my $project = $path_info;
$project =~ s,/+$,,;
- while ($project && !is_git_directory("$projectroot/$project")) {
+ while ($project && !is_git_repository("$projectroot/$project")) {
$project =~ s,/*[^/]*$,,;
}
return unless $project;
@@ -3094,8 +3140,8 @@ sub git_get_projects_list {
our $projectroot;
# skip project-list toplevel, if we get it.
return if (m!^[/.]$!);
- # only directories can be git repositories
- return unless (-d $_);
+ # only directories or gitlink files can be git repositories
+ return unless (-d $_ || (-f _ && $File::Find::name =~ m!(?:^|/)\.git!));
# don't traverse too deep (Find is super slow on os x)
# $project_maxdepth excludes depth of $projectroot
if (($File::Find::name =~ tr!/!!) - $pfxdepth > $project_maxdepth) {
--
1.7.9
next prev parent reply other threads:[~2012-04-21 11:28 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-04-03 13:27 [PATCH] gitweb: Option to omit column with time of the last change Kacper Kornet
2012-04-03 23:12 ` Jakub Narebski
2012-04-04 6:39 ` Kacper Kornet
2012-04-04 14:31 ` Jakub Narebski
2012-04-04 16:22 ` Kacper Kornet
2012-04-14 13:16 ` Jakub Narebski
2012-04-16 10:12 ` Kacper Kornet
2012-04-16 20:06 ` Jakub Narebski
2012-04-16 21:39 ` Kacper Kornet
2012-04-17 23:36 ` Jakub Narebski
2012-04-19 16:07 ` [PATCH] gitweb: Improve repository verification Jakub Narebski
2012-04-19 18:30 ` Junio C Hamano
2012-04-19 19:46 ` Jakub Narebski
2012-04-21 11:28 ` Jakub Narebski [this message]
2012-04-24 17:39 ` [PATCH 1/2] gitweb: Option to omit column with time of the last change Kacper Kornet
2012-04-24 17:41 ` [PATCH 2/2] gitweb: Option to not display information about owner Kacper Kornet
2012-04-26 4:39 ` Junio C Hamano
2012-04-26 15:07 ` Kacper Kornet
2012-04-26 15:53 ` Junio C Hamano
2012-04-26 16:35 ` Kacper Kornet
2012-04-26 16:45 ` [PATCH v2 " Kacper Kornet
2012-04-24 17:36 ` [PATCH] gitweb: Option to omit column with time of the last change Kacper Kornet
2012-04-04 17:14 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=201204211328.25162.jnareb@gmail.com \
--to=jnareb@gmail.com \
--cc=draenog@pld-linux.org \
--cc=git@vger.kernel.org \
--cc=jch@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).