From 8bbf816fed6e973e8a913a070d1abcc48e065b52 Mon Sep 17 00:00:00 2001 From: Pavan Kumar Sunkara Date: Tue, 22 Jun 2010 03:52:34 +0530 Subject: [PATCH] gitweb: Add support for enabling 'write' feature Provide $feature{'write'} to enable the 'write' functionalities for gitweb. While outputting HTML it checks for gitweb_check_feature('write') and if it's enabled, proper links will appear along with the HTML divs. Signed-off-by: Pavan Kumar Sunkara --- gitweb/gitweb.perl | 33 +++++++++++++++++++++++++++++++++ gitweb/lib/Gitweb/Config.pm | 18 ++++++++++++++++-- gitweb/lib/Gitweb/Request.pm | 5 +++-- gitweb/lib/Gitweb/View.pm | 8 +++++++- 4 files changed, 59 insertions(+), 5 deletions(-) diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl index efa9bdbfa6..640ef74b1c 100755 --- a/gitweb/gitweb.perl +++ b/gitweb/gitweb.perl @@ -139,6 +139,13 @@ our %actions = ( "project_index" => \&git_project_index, ); +# we will also need to know the possible 'edits', for validation +our %edits = ( + #already existing subroutines + "log" => \&git_log, + "summary" => \&git_summary, + #new subroutines +); # now read PATH_INFO and update the parameter list for missing parameters sub evaluate_path_info { @@ -168,6 +175,15 @@ sub evaluate_path_info { $input_params{'action'} = $action; } + return if $input_params{'edit'}; + # next, check if we have an edit + my $edit = $path_info; + $edit =~ s,/.*$,,; + if (exists $edits{$edit} && gitweb_check_feature('write')) { + $path_info =~ s,^$edit/*,,; + $input_params{'edit'} = $edit; + } + # list of actions that want hash_base instead of hash, but can have no # pathname (f) parameter my @wants_base = ( @@ -292,6 +308,13 @@ sub evaluate_and_validate_params { } } + $edit = $input_params{'edit'}; + if(defined $edit && gitweb_check_feature('write')) { + if(!validate_edit($edit)) { + die_error(400, "Invalid edit parameter"); + } + } + # parameters which are pathnames $project = $input_params{'project'}; if (defined $project) { @@ -415,6 +438,10 @@ sub dispatch { $action = 'project_list'; } } + if (defined $edit) { + $action = $edit; + %actions = %edits; + } if (!defined($actions{$action})) { die_error(400, "Unknown action"); } @@ -524,6 +551,12 @@ sub validate_action { return $input; } +sub validate_edit { + my $input = shift || return undef; + return undef unless exists $edits{$input}; + return $input; +} + sub validate_project { my $input = shift || return undef; if (!validate_pathname($input) || diff --git a/gitweb/lib/Gitweb/Config.pm b/gitweb/lib/Gitweb/Config.pm index c5285950dd..f4fa9df453 100644 --- a/gitweb/lib/Gitweb/Config.pm +++ b/gitweb/lib/Gitweb/Config.pm @@ -17,7 +17,7 @@ our @EXPORT = qw(evaluate_gitweb_config gitweb_check_feature gitweb_get_feature $GITWEB_CONFIG $GITWEB_CONFIG_SYSTEM $logo_url $logo_label $export_auth_hook $projects_list_description_width $default_projects_order $default_blob_plain_mimetype $default_text_plain_charset $fallback_encoding @diff_opts $prevent_xss $maxload - $git_avatar %avatar_size %feature @snapshot_fmts $mimetypes_file); + $git_avatar %avatar_size %feature @snapshot_fmts $mimetypes_file $git_write); use Gitweb::Git qw($git_dir); @@ -203,6 +203,17 @@ our %feature = ( # (an array) or gitweb_check_feature() to check if # is enabled + # Enable the 'write' functionalities for gitweb. While outputting HTML + # it checks for gitweb_check_feature('write') and if it's enabled, + # proper links will appear along with the HTML divs. + + # To enable system wide have in $GITWEB_CONFIG + # $feature{'write'}{'default'} = [1]; + # Project specific override is not supported. + 'write' => { + 'override' => 0, + 'default' => [0]}, + # Enable the 'blame' blob view, showing the last commit that modified # each line in the file. This can be very CPU-intensive. @@ -475,12 +486,15 @@ sub filter_snapshot_fmts { !$known_snapshot_formats{$_}{'disabled'}} @fmts; } -our (@snapshot_fmts, $git_avatar); +our (@snapshot_fmts, $git_avatar, $git_write); sub configure_gitweb_features { # list of supported snapshot formats our @snapshot_fmts = gitweb_get_feature('snapshot'); @snapshot_fmts = filter_snapshot_fmts(@snapshot_fmts); + # A variable flag to check 'write' feature + our $git_write = gitweb_check_feature('write'); + # check that the avatar feature is set to a known provider name, # and for each provider check if the dependencies are satisfied. # if the provider name is invalid or the dependencies are not met, diff --git a/gitweb/lib/Gitweb/Request.pm b/gitweb/lib/Gitweb/Request.pm index 1581a94284..d13a5b94ee 100644 --- a/gitweb/lib/Gitweb/Request.pm +++ b/gitweb/lib/Gitweb/Request.pm @@ -11,7 +11,7 @@ use warnings; use Exporter qw(import); our @EXPORT = qw($cgi $my_url $my_uri $base_url $path_info $home_link $action $project $file_name - $file_parent $hash $hash_parent $hash_base $hash_parent_base @extra_options $page + $file_parent $hash $hash_parent $hash_base $hash_parent_base @extra_options $page $edit $searchtype $search_use_regexp $searchtext $search_regexp %input_params %allowed_options @cgi_param_mapping %cgi_param_mapping $t0 evaluate_query_params evaluate_uri); @@ -21,7 +21,7 @@ if (eval { require Time::HiRes; 1; }) { } our ($cgi, $my_url, $my_uri, $base_url, $path_info, $home_link); -our ($action, $project, $file_name, $file_parent, $hash, $hash_parent, $hash_base, +our ($action, $edit, $project, $file_name, $file_parent, $hash, $hash_parent, $hash_base, $hash_parent_base, @extra_options, $page); our ($searchtype, $search_use_regexp, $searchtext, $search_regexp); @@ -43,6 +43,7 @@ our %input_params = (); our @cgi_param_mapping = ( project => "p", action => "a", + edit => "e", file_name => "f", file_parent => "fp", hash => "h", diff --git a/gitweb/lib/Gitweb/View.pm b/gitweb/lib/Gitweb/View.pm index 3118f44de8..02e7b35810 100644 --- a/gitweb/lib/Gitweb/View.pm +++ b/gitweb/lib/Gitweb/View.pm @@ -22,7 +22,7 @@ use Gitweb::Git qw($git_version $number_of_git_cmds $git_dir git_cmd); use Gitweb::Config qw(gitweb_check_feature %known_snapshot_formats @snapshot_fmts $site_name $version $stylesheet @stylesheets $favicon $logo $site_header $logo_url $logo_label $javascript $home_link_str - $site_footer gitweb_get_feature); + $site_footer gitweb_get_feature $git_write); use Gitweb::Request qw($cgi $project %cgi_param_mapping @cgi_param_mapping $my_url $my_uri %input_params $action $file_name $base_url $hash_base $searchtext $search_use_regexp $hash $t0 $home_link); @@ -54,6 +54,7 @@ sub href { # try to put as many parameters as possible in PATH_INFO: # - project name # - action + # - edit # - hash_parent or hash_parent_base:/file_parent # - hash or hash_base:/filename # - the snapshot_format as an appropriate suffix @@ -78,6 +79,11 @@ sub href { $href .= "/".esc_url($params{'action'}) unless $params{'action'} eq 'summary'; delete $params{'action'}; } + + if (defined $params{'edit'} && $git_write) { + $href .= "/".esc_url($params{'edit'}); + delete $params{'edit'}; + } # Next, we put hash_parent_base:/file_parent..hash_base:/file_name, # stripping nonexistent or useless pieces -- 2.11.4.GIT