* [RFCv4 0/3] gitweb: patch view @ 2008-12-06 15:02 Giuseppe Bilotta 2008-12-06 15:02 ` [RFCv4 1/3] gitweb: add " Giuseppe Bilotta 0 siblings, 1 reply; 12+ messages in thread From: Giuseppe Bilotta @ 2008-12-06 15:02 UTC (permalink / raw) To: git; +Cc: Jakub Narebski, Petr Baudis, Junio C Hamano, Giuseppe Bilotta Fourth iteration of the patch view feature, that exposes git format-patch output in gitweb. The most significant different from the previous revision is the introduction of the 'patches' view, that only differs from 'patch' view in the treatment of single commits: 'patch' view only displays the patch for that specific commit, whereas 'patches' follows the git format-patch M.O. Giuseppe Bilotta (3): gitweb: add patch view gitweb: add patches view gitweb: link to patch(es) view from commit and log views gitweb/gitweb.perl | 107 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 106 insertions(+), 1 deletions(-) ^ permalink raw reply [flat|nested] 12+ messages in thread
* [RFCv4 1/3] gitweb: add patch view 2008-12-06 15:02 [RFCv4 0/3] gitweb: patch view Giuseppe Bilotta @ 2008-12-06 15:02 ` Giuseppe Bilotta 2008-12-06 15:02 ` [RFCv4 2/3] gitweb: add patches view Giuseppe Bilotta 2008-12-15 13:17 ` [RFCv4 1/3] gitweb: add patch view Jakub Narebski 0 siblings, 2 replies; 12+ messages in thread From: Giuseppe Bilotta @ 2008-12-06 15:02 UTC (permalink / raw) To: git; +Cc: Jakub Narebski, Petr Baudis, Junio C Hamano, Giuseppe Bilotta The output of commitdiff_plain is not intended for git-am: * when given a range of commits, commitdiff_plain publishes a single patch with the message from the first commit, instead of a patchset * the hand-built email format replicates the commit summary both as email subject and as first line of the email itself, resulting in a duplication if the output is used with git-am. We thus create a new view that can be fed to git-am directly, allowing patch exchange via gitweb. The new view exposes the output of git format-patch directly, limiting it to a single patch in the case of a single commit. A configurable upper limit is imposed on the number of commits which will be included in a patchset, to prevent DoS attacks on the server. Setting the limit to 0 will disable the patch view, setting it to a negative number will remove the limit. Signed-off-by: Giuseppe Bilotta <giuseppe.bilotta@gmail.com> --- gitweb/gitweb.perl | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 64 insertions(+), 1 deletions(-) diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl index 95988fb..71d5af4 100755 --- a/gitweb/gitweb.perl +++ b/gitweb/gitweb.perl @@ -329,6 +329,14 @@ our %feature = ( 'ctags' => { 'override' => 0, 'default' => [0]}, + + # The maximum number of patches in a patchset generated in patch + # view. Set this to 0 or undef to disable patch view, or to a + # negative number to remove any limit. + 'patches' => { + 'sub' => \&feature_patches, + 'override' => 0, + 'default' => [16]}, ); sub gitweb_get_feature { @@ -410,6 +418,19 @@ sub feature_pickaxe { return ($_[0]); } +sub feature_patches { + my @val = (git_get_project_config('patches', '--int')); + + # if @val is empty, the config is not (properly) + # overriding the feature, so we return the default, + # otherwise we pick the override + if (@val) { + return @val; + } + + return ($_[0]); +} + # checking HEAD file with -e is fragile if the repository was # initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed # and then pruned. @@ -503,6 +524,7 @@ our %actions = ( "heads" => \&git_heads, "history" => \&git_history, "log" => \&git_log, + "patch" => \&git_patch, "rss" => \&git_rss, "atom" => \&git_atom, "search" => \&git_search, @@ -5386,6 +5408,13 @@ sub git_blobdiff_plain { sub git_commitdiff { my $format = shift || 'html'; + + my $patch_max; + if ($format eq 'patch') { + $patch_max = gitweb_check_feature('patches'); + die_error(403, "Patch view not allowed") unless $patch_max; + } + $hash ||= $hash_base || "HEAD"; my %co = parse_commit($hash) or die_error(404, "Unknown commit object"); @@ -5483,7 +5512,23 @@ sub git_commitdiff { open $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts, '-p', $hash_parent_param, $hash, "--" or die_error(500, "Open git-diff-tree failed"); - + } elsif ($format eq 'patch') { + # For commit ranges, we limit the output to the number of + # patches specified in the 'patches' feature. + # For single commits, we limit the output to a single patch, + # diverging from the git format-patch default. + my @commit_spec = (); + if ($hash_parent) { + if ($patch_max > 0) { + push @commit_spec, "-$patch_max"; + } + push @commit_spec, '-n', "$hash_parent..$hash"; + } else { + push @commit_spec, '-1', '--root', $hash; + } + open $fd, "-|", git_cmd(), "format-patch", '--encoding=utf8', + '--stdout', @commit_spec + or die_error(500, "Open git-format-patch failed"); } else { die_error(400, "Unknown commitdiff format"); } @@ -5532,6 +5577,14 @@ sub git_commitdiff { print to_utf8($line) . "\n"; } print "---\n\n"; + } elsif ($format eq 'patch') { + my $filename = basename($project) . "-$hash.patch"; + + print $cgi->header( + -type => 'text/plain', + -charset => 'utf-8', + -expires => $expires, + -content_disposition => 'inline; filename="' . "$filename" . '"'); } # write patch @@ -5553,6 +5606,11 @@ sub git_commitdiff { print <$fd>; close $fd or print "Reading git-diff-tree failed\n"; + } elsif ($format eq 'patch') { + local $/ = undef; + print <$fd>; + close $fd + or print "Reading git-format-patch failed\n"; } } @@ -5560,6 +5618,11 @@ sub git_commitdiff_plain { git_commitdiff('plain'); } +# format-patch-style patches +sub git_patch { + git_commitdiff('patch'); +} + sub git_history { if (!defined $hash_base) { $hash_base = git_get_head_hash($project); -- 1.5.6.5 ^ permalink raw reply related [flat|nested] 12+ messages in thread
* [RFCv4 2/3] gitweb: add patches view 2008-12-06 15:02 ` [RFCv4 1/3] gitweb: add " Giuseppe Bilotta @ 2008-12-06 15:02 ` Giuseppe Bilotta 2008-12-06 15:02 ` [RFCv4 3/3] gitweb: link to patch(es) view from commit and log views Giuseppe Bilotta 2008-12-16 3:14 ` [RFCv4 2/3] gitweb: add patches view Jakub Narebski 2008-12-15 13:17 ` [RFCv4 1/3] gitweb: add patch view Jakub Narebski 1 sibling, 2 replies; 12+ messages in thread From: Giuseppe Bilotta @ 2008-12-06 15:02 UTC (permalink / raw) To: git; +Cc: Jakub Narebski, Petr Baudis, Junio C Hamano, Giuseppe Bilotta The only difference between patch and patches view is in the treatement of single commits: the former only displays a single patch, whereas the latter displays a patchset leading to the specified commit. --- gitweb/gitweb.perl | 20 ++++++++++++++++++-- 1 files changed, 18 insertions(+), 2 deletions(-) diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl index 71d5af4..dfc7128 100755 --- a/gitweb/gitweb.perl +++ b/gitweb/gitweb.perl @@ -525,6 +525,7 @@ our %actions = ( "history" => \&git_history, "log" => \&git_log, "patch" => \&git_patch, + "patches" => \&git_patches, "rss" => \&git_rss, "atom" => \&git_atom, "search" => \&git_search, @@ -5408,6 +5409,9 @@ sub git_blobdiff_plain { sub git_commitdiff { my $format = shift || 'html'; + # for patch view: should we limit ourselves to a single patch + # if only a single commit is passed? + my $single_patch = shift && 1; my $patch_max; if ($format eq 'patch') { @@ -5524,7 +5528,15 @@ sub git_commitdiff { } push @commit_spec, '-n', "$hash_parent..$hash"; } else { - push @commit_spec, '-1', '--root', $hash; + if ($single_patch) { + push @commit_spec, '-1'; + } else { + if ($patch_max > 0) { + push @commit_spec, "-$patch_max"; + } + push @commit_spec, "-n"; + } + push @commit_spec, '--root', $hash; } open $fd, "-|", git_cmd(), "format-patch", '--encoding=utf8', '--stdout', @commit_spec @@ -5620,7 +5632,11 @@ sub git_commitdiff_plain { # format-patch-style patches sub git_patch { - git_commitdiff('patch'); + git_commitdiff('patch', 1); +} + +sub git_patches { + git_commitdiff('patch', 0); } sub git_history { -- 1.5.6.5 ^ permalink raw reply related [flat|nested] 12+ messages in thread
* [RFCv4 3/3] gitweb: link to patch(es) view from commit and log views 2008-12-06 15:02 ` [RFCv4 2/3] gitweb: add patches view Giuseppe Bilotta @ 2008-12-06 15:02 ` Giuseppe Bilotta 2008-12-16 1:03 ` Jakub Narebski 2008-12-16 3:14 ` [RFCv4 2/3] gitweb: add patches view Jakub Narebski 1 sibling, 1 reply; 12+ messages in thread From: Giuseppe Bilotta @ 2008-12-06 15:02 UTC (permalink / raw) To: git; +Cc: Jakub Narebski, Petr Baudis, Junio C Hamano, Giuseppe Bilotta We link to patch view in commit and commitdiff view, and to patches view in log and shortlog view. In (short)log view, the link is only offered when the number of commits shown is no more than the allowed maximum number of patches. Signed-off-by: Giuseppe Bilotta <giuseppe.bilotta@gmail.com> --- gitweb/gitweb.perl | 30 ++++++++++++++++++++++++++++-- 1 files changed, 28 insertions(+), 2 deletions(-) diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl index dfc7128..8198875 100755 --- a/gitweb/gitweb.perl +++ b/gitweb/gitweb.perl @@ -5019,6 +5019,15 @@ sub git_log { my $paging_nav = format_paging_nav('log', $hash, $head, $page, $#commitlist >= 100); + my $patch_max = gitweb_check_feature('patches'); + if ($patch_max) { + if ($patch_max < 0 || @commitlist <= $patch_max) { + $paging_nav .= " ⋅ " . + $cgi->a({-href => href(action=>"patches", -replay=>1)}, + @commitlist > 1 ? "patchset" : "patch"); + } + } + git_header_html(); git_print_page_nav('log','', $hash,undef,undef, $paging_nav); @@ -5098,6 +5107,11 @@ sub git_commit { } @$parents ) . ')'; } + if (gitweb_check_feature('patches')) { + $formats_nav .= " | " . + $cgi->a({-href => href(action=>"patch", -replay=>1)}, + "patch"); + } if (!defined $parent) { $parent = "--root"; @@ -5413,9 +5427,8 @@ sub git_commitdiff { # if only a single commit is passed? my $single_patch = shift && 1; - my $patch_max; + my $patch_max = gitweb_check_feature('patches'); if ($format eq 'patch') { - $patch_max = gitweb_check_feature('patches'); die_error(403, "Patch view not allowed") unless $patch_max; } @@ -5433,6 +5446,11 @@ sub git_commitdiff { $formats_nav = $cgi->a({-href => href(action=>"commitdiff_plain", -replay=>1)}, "raw"); + if ($patch_max) { + $formats_nav .= " | " . + $cgi->a({-href => href(action=>"patch", -replay=>1)}, + "patch"); + } if (defined $hash_parent && $hash_parent ne '-c' && $hash_parent ne '--cc') { @@ -5989,6 +6007,14 @@ sub git_shortlog { $cgi->a({-href => href(-replay=>1, page=>$page+1), -accesskey => "n", -title => "Alt-n"}, "next"); } + my $patch_max = gitweb_check_feature('patches'); + if ($patch_max) { + if ($patch_max < 0 || @commitlist <= $patch_max) { + $paging_nav .= " ⋅ " . + $cgi->a({-href => href(action=>"patches", -replay=>1)}, + @commitlist > 1 ? "patchset" : "patch"); + } + } git_header_html(); git_print_page_nav('shortlog','', $hash,$hash,$hash, $paging_nav); -- 1.5.6.5 ^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [RFCv4 3/3] gitweb: link to patch(es) view from commit and log views 2008-12-06 15:02 ` [RFCv4 3/3] gitweb: link to patch(es) view from commit and log views Giuseppe Bilotta @ 2008-12-16 1:03 ` Jakub Narebski [not found] ` <cb7bb73a0812160202n1f4f7f4fi7f71455eb42bcd31@mail.gmail.com> 0 siblings, 1 reply; 12+ messages in thread From: Jakub Narebski @ 2008-12-16 1:03 UTC (permalink / raw) To: Giuseppe Bilotta; +Cc: git, Petr Baudis, Junio C Hamano On Sat, 6 Dec 2008, Giuseppe Bilotta wrote: > We link to patch view in commit and commitdiff view, and to patches view > in log and shortlog view. > > In (short)log view, the link is only offered when the number of commits > shown is no more than the allowed maximum number of patches. > > Signed-off-by: Giuseppe Bilotta <giuseppe.bilotta@gmail.com> A few remarks, but otherwise: Acked-by: Jakub Narebski <jnareb@gmail.com> > --- > gitweb/gitweb.perl | 30 ++++++++++++++++++++++++++++-- > 1 files changed, 28 insertions(+), 2 deletions(-) > > diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl > index dfc7128..8198875 100755 > --- a/gitweb/gitweb.perl > +++ b/gitweb/gitweb.perl > @@ -5019,6 +5019,15 @@ sub git_log { > > my $paging_nav = format_paging_nav('log', $hash, $head, $page, $#commitlist >= 100); > > + my $patch_max = gitweb_check_feature('patches'); If you change other places to use git_get_feature, then you should change it too. I'm not sure if it is worth it... > + if ($patch_max) { > + if ($patch_max < 0 || @commitlist <= $patch_max) { > + $paging_nav .= " ⋅ " . > + $cgi->a({-href => href(action=>"patches", -replay=>1)}, > + @commitlist > 1 ? "patchset" : "patch"); I think it would be better to always use "patches" here, as it is series of patches by design, only by accident it is one commit long. I wonder if it would make sense to pass href(..., hash_parent => $commitlist[-1]{'id'}, ...) here. But I think having separate "patches" action, with intent being displaying series of patches, is a better solution. This way you can see in URL and in the page title (thus also in window title, or in bookmark name) if it is single patch or patch series (perhaps consisting of single patch). > + } > + } > + > git_header_html(); > git_print_page_nav('log','', $hash,undef,undef, $paging_nav); > > @@ -5098,6 +5107,11 @@ sub git_commit { > } @$parents ) . > ')'; > } > + if (gitweb_check_feature('patches')) { > + $formats_nav .= " | " . > + $cgi->a({-href => href(action=>"patch", -replay=>1)}, > + "patch"); > + } Here using gitweb_check_feature makes perfect sense. > > if (!defined $parent) { > $parent = "--root"; > @@ -5413,9 +5427,8 @@ sub git_commitdiff { > # if only a single commit is passed? > my $single_patch = shift && 1; > > - my $patch_max; > + my $patch_max = gitweb_check_feature('patches'); gitweb_check_feature or gitweb_get_feature?... > if ($format eq 'patch') { > - $patch_max = gitweb_check_feature('patches'); > die_error(403, "Patch view not allowed") unless $patch_max; > } > > @@ -5433,6 +5446,11 @@ sub git_commitdiff { > $formats_nav = > $cgi->a({-href => href(action=>"commitdiff_plain", -replay=>1)}, > "raw"); > + if ($patch_max) { > + $formats_nav .= " | " . > + $cgi->a({-href => href(action=>"patch", -replay=>1)}, > + "patch"); > + } Nice reusing $patch_max in different way, as $have_patch if $format is 'html', and as limiter ($patch_max) if $format is 'patch'/'patches' > > if (defined $hash_parent && > $hash_parent ne '-c' && $hash_parent ne '--cc') { > @@ -5989,6 +6007,14 @@ sub git_shortlog { > $cgi->a({-href => href(-replay=>1, page=>$page+1), > -accesskey => "n", -title => "Alt-n"}, "next"); > } > + my $patch_max = gitweb_check_feature('patches'); > + if ($patch_max) { > + if ($patch_max < 0 || @commitlist <= $patch_max) { > + $paging_nav .= " ⋅ " . > + $cgi->a({-href => href(action=>"patches", -replay=>1)}, > + @commitlist > 1 ? "patchset" : "patch"); > + } > + } Same comment as for git_log... > > git_header_html(); > git_print_page_nav('shortlog','', $hash,$hash,$hash, $paging_nav); > -- > 1.5.6.5 > > -- Jakub Narebski Poland ^ permalink raw reply [flat|nested] 12+ messages in thread
[parent not found: <cb7bb73a0812160202n1f4f7f4fi7f71455eb42bcd31@mail.gmail.com>]
* Re: [RFCv4 3/3] gitweb: link to patch(es) view from commit and log views [not found] ` <cb7bb73a0812160202n1f4f7f4fi7f71455eb42bcd31@mail.gmail.com> @ 2008-12-16 10:14 ` Jakub Narebski 2008-12-16 11:14 ` Giuseppe Bilotta 0 siblings, 1 reply; 12+ messages in thread From: Jakub Narebski @ 2008-12-16 10:14 UTC (permalink / raw) To: Giuseppe Bilotta; +Cc: git You lost CC, somehow... On Tue, 16 Dec 2008, Giuseppe Bilotta wrote: > On Tue, Dec 16, 2008 at 2:03 AM, Jakub Narebski <jnareb@gmail.com> wrote: > > On Sat, 6 Dec 2008, Giuseppe Bilotta wrote: >>> + if ($patch_max) { >>> + if ($patch_max < 0 || @commitlist <= $patch_max) { >>> + $paging_nav .= " ⋅ " . >>> + $cgi->a({-href => href(action=>"patches", -replay=>1)}, >>> + @commitlist > 1 ? "patchset" : "patch"); [...] >> I wonder if it would make sense to pass >> >> href(..., hash_parent => $commitlist[-1]{'id'}, ...) >> >> here. But I think having separate "patches" action, with intent being >> displaying series of patches, is a better solution. This way you can >> see in URL and in the page title (thus also in window title, or in >> bookmark name) if it is single patch or patch series (perhaps consisting >> of single patch). > > I'm not sure I'm following you here. Do you mean as in manually adding > the parent endpoint to the URL when it's not specified in the log view > itself? I think that would change the behaviour for > 100 patches. First, I meant here that having separate "patches" action is a good idea in itself, whether we pass explicitly and always $hash_parent parameter here or not. Second, I haven't thought about interaction with (short)log pagination; in $patch_max < 0, i.e. unlimited patches, and most common case of running 'shortlog' action without 'hp' (hash_parent) limiter used, one would make 'patches' limited to page size, other unlimited. On one hand side limiting to page size makes "patches" be more of equivalent of current "shortlog" view; on the other hand it makes 'unlimited' actually be limited to page size, at least in this situation... -- Jakub Narebski Poland ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [RFCv4 3/3] gitweb: link to patch(es) view from commit and log views 2008-12-16 10:14 ` Jakub Narebski @ 2008-12-16 11:14 ` Giuseppe Bilotta 0 siblings, 0 replies; 12+ messages in thread From: Giuseppe Bilotta @ 2008-12-16 11:14 UTC (permalink / raw) To: Jakub Narebski; +Cc: git On Tue, Dec 16, 2008 at 11:14 AM, Jakub Narebski <jnareb@gmail.com> wrote: > You lost CC, somehow... Duh, clicked the wrong button. >>> I wonder if it would make sense to pass >>> >>> href(..., hash_parent => $commitlist[-1]{'id'}, ...) >>> >>> here. But I think having separate "patches" action, with intent being >>> displaying series of patches, is a better solution. This way you can >>> see in URL and in the page title (thus also in window title, or in >>> bookmark name) if it is single patch or patch series (perhaps consisting >>> of single patch). >> >> I'm not sure I'm following you here. Do you mean as in manually adding >> the parent endpoint to the URL when it's not specified in the log view >> itself? I think that would change the behaviour for > 100 patches. > > First, I meant here that having separate "patches" action is a good > idea in itself, whether we pass explicitly and always $hash_parent > parameter here or not. I'm not too sure about that. Do we pass the actual hash parent, or just the last patch that would be included due to the patch limit? This, btw, is an issue that should resolved with patch view: it should warn when the patch limit is reached before all intended patches are output. I'm just not sure about how to do it. > Second, I haven't thought about interaction with (short)log > pagination; in $patch_max < 0, i.e. unlimited patches, and most > common case of running 'shortlog' action without 'hp' (hash_parent) > limiter used, one would make 'patches' limited to page size, > other unlimited. On one hand side limiting to page size makes > "patches" be more of equivalent of current "shortlog" view; on the > other hand it makes 'unlimited' actually be limited to page size, > at least in this situation... Consider that switching from log to shortlog view doesn't respect pagination (e.g. if you're on page 3 of shortlog and click on log you go to page 1 of log) I would be inclined to keep patches behaviour independent of log view pagination. -- Giuseppe "Oblomov" Bilotta ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [RFCv4 2/3] gitweb: add patches view 2008-12-06 15:02 ` [RFCv4 2/3] gitweb: add patches view Giuseppe Bilotta 2008-12-06 15:02 ` [RFCv4 3/3] gitweb: link to patch(es) view from commit and log views Giuseppe Bilotta @ 2008-12-16 3:14 ` Jakub Narebski [not found] ` <cb7bb73a0812160149j1dcaefccv1caf4a2e589ffebb@mail.gmail.com> 1 sibling, 1 reply; 12+ messages in thread From: Jakub Narebski @ 2008-12-16 3:14 UTC (permalink / raw) To: Giuseppe Bilotta; +Cc: git, Petr Baudis, Junio C Hamano On Sat, 6 Dec 2008 16:02, Giuseppe Bilotta wrote: > The only difference between patch and patches view is in the treatement > of single commits: the former only displays a single patch, whereas the > latter displays a patchset leading to the specified commit. I like that fact that we have "patches" action which intent is to show series of patches, and "patch" action which intent is to show single patch. I'm just not sure if "patch" view should not simply ignore $hash_parent... Signoff? > --- > gitweb/gitweb.perl | 20 ++++++++++++++++++-- > 1 files changed, 18 insertions(+), 2 deletions(-) > > diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl > index 71d5af4..dfc7128 100755 > --- a/gitweb/gitweb.perl > +++ b/gitweb/gitweb.perl > @@ -525,6 +525,7 @@ our %actions = ( > "history" => \&git_history, > "log" => \&git_log, > "patch" => \&git_patch, > + "patches" => \&git_patches, > "rss" => \&git_rss, > "atom" => \&git_atom, > "search" => \&git_search, > @@ -5408,6 +5409,9 @@ sub git_blobdiff_plain { > > sub git_commitdiff { > my $format = shift || 'html'; > + # for patch view: should we limit ourselves to a single patch > + # if only a single commit is passed? > + my $single_patch = shift && 1; What does this "shift && 1" does? Equivalent of "!!shift"? Is it really needed? Perhaps it would be better to use %opts trick, like for some other gitweb subroutines (-single=>1, or -single_patch=>1, or -nmax=>1)? Or perhaps not... > > my $patch_max; > if ($format eq 'patch') { > @@ -5524,7 +5528,15 @@ sub git_commitdiff { > } > push @commit_spec, '-n', "$hash_parent..$hash"; > } else { > - push @commit_spec, '-1', '--root', $hash; > + if ($single_patch) { > + push @commit_spec, '-1'; > + } else { > + if ($patch_max > 0) { > + push @commit_spec, "-$patch_max"; > + } > + push @commit_spec, "-n"; > + } > + push @commit_spec, '--root', $hash; Nice. > } > open $fd, "-|", git_cmd(), "format-patch", '--encoding=utf8', > '--stdout', @commit_spec > @@ -5620,7 +5632,11 @@ sub git_commitdiff_plain { > > # format-patch-style patches > sub git_patch { > - git_commitdiff('patch'); > + git_commitdiff('patch', 1); > +} > + > +sub git_patches { > + git_commitdiff('patch', 0); I quite like it. > } > > sub git_history { > -- > 1.5.6.5 > > -- Jakub Narebski Poland ^ permalink raw reply [flat|nested] 12+ messages in thread
[parent not found: <cb7bb73a0812160149j1dcaefccv1caf4a2e589ffebb@mail.gmail.com>]
* Re: [RFCv4 2/3] gitweb: add patches view [not found] ` <cb7bb73a0812160149j1dcaefccv1caf4a2e589ffebb@mail.gmail.com> @ 2008-12-16 10:16 ` Jakub Narebski 0 siblings, 0 replies; 12+ messages in thread From: Jakub Narebski @ 2008-12-16 10:16 UTC (permalink / raw) To: Giuseppe Bilotta; +Cc: git Giuseppe Bilotta wrote: > On Tue, Dec 16, 2008 at 4:14 AM, Jakub Narebski <jnareb@gmail.com> wrote: >> On Sat, 6 Dec 2008 16:02, Giuseppe Bilotta wrote: >> >>> The only difference between patch and patches view is in the treatement >>> of single commits: the former only displays a single patch, whereas the >>> latter displays a patchset leading to the specified commit. >> >> I like that fact that we have "patches" action which intent is to >> show series of patches, and "patch" action which intent is to show >> single patch. I'm just not sure if "patch" view should not simply >> ignore $hash_parent... > > I had doubts on this myself. In the end I decided to make patch > consider hash_parent if present because IMO it's what a user would > expect in case e.g. of hand-crafted URLs. Ah. I can understand that. [...] >>> sub git_commitdiff { >>> my $format = shift || 'html'; >>> + # for patch view: should we limit ourselves to a single patch >>> + # if only a single commit is passed? >>> + my $single_patch = shift && 1; >> >> What does this "shift && 1" does? Equivalent of "!!shift"? >> Is it really needed? >> >> Perhaps it would be better to use %opts trick, like for some other >> gitweb subroutines (-single=>1, or -single_patch=>1, or -nmax=>1)? >> Or perhaps not... > > It would be MUCH better, I'll do it this way. I'll pass the -single > param in both cases, having value true/false, even though the false > case is not needed since undef is false in perl anyway. (I like > symmetry.) -- Jakub Narebski Poland ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [RFCv4 1/3] gitweb: add patch view 2008-12-06 15:02 ` [RFCv4 1/3] gitweb: add " Giuseppe Bilotta 2008-12-06 15:02 ` [RFCv4 2/3] gitweb: add patches view Giuseppe Bilotta @ 2008-12-15 13:17 ` Jakub Narebski 2008-12-15 13:48 ` Giuseppe Bilotta 1 sibling, 1 reply; 12+ messages in thread From: Jakub Narebski @ 2008-12-15 13:17 UTC (permalink / raw) To: Giuseppe Bilotta; +Cc: git, Petr Baudis, Junio C Hamano On Sat, 6 Dec 2008, Giuseppe Bilotta wrote: > The output of commitdiff_plain is not intended for git-am: > * when given a range of commits, commitdiff_plain publishes a single > patch with the message from the first commit, instead of a patchset > * the hand-built email format replicates the commit summary both as > email subject and as first line of the email itself, resulting in > a duplication if the output is used with git-am. > > We thus create a new view that can be fed to git-am directly, allowing > patch exchange via gitweb. The new view exposes the output of git > format-patch directly, limiting it to a single patch in the case of a > single commit. > > A configurable upper limit is imposed on the number of commits which > will be included in a patchset, to prevent DoS attacks on the server. > Setting the limit to 0 will disable the patch view, setting it to a > negative number will remove the limit. It would be good to have in commit mesage what is the default upper limit (or if we decide to have this feature turned off by default, proposed limit to choose when enabling this feature). Does limit of 16 patches have any numbers behind it? We use page size of 100 commits for 'shortlog', 'log' and 'history' views, but for those views we don't need to generate patches (which is slower). From a few tests "git log -100" is faster than "git format-patch -100 --stdout" about 30 times in warm cache case, and about 1.7 times in cold cache case. > > Signed-off-by: Giuseppe Bilotta <giuseppe.bilotta@gmail.com> Other than that minor detail I like this patch > --- > gitweb/gitweb.perl | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++- > 1 files changed, 64 insertions(+), 1 deletions(-) > > diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl > index 95988fb..71d5af4 100755 > --- a/gitweb/gitweb.perl > +++ b/gitweb/gitweb.perl > @@ -329,6 +329,14 @@ our %feature = ( > 'ctags' => { > 'override' => 0, > 'default' => [0]}, > + > + # The maximum number of patches in a patchset generated in patch > + # view. Set this to 0 or undef to disable patch view, or to a > + # negative number to remove any limit. I think it would be nice to have standard boilerplate explanation how to change it, and how to override it, with the addition on how to disable it from repository config, because it is not very obvious. Something like: + # To disable system wide have in $GITWEB_CONFIG + # $feature{'patches'}{'default'} = []; + # To have project specific config enable override in $GITWEB_CONFIG + # $feature{'patches'}{'override'} = 1; + # and in project config, maximum number of patches in a patchset + # or 0 to disable. Example: gitweb.patches = 0 > + 'patches' => { > + 'sub' => \&feature_patches, > + 'override' => 0, > + 'default' => [16]}, > ); > > sub gitweb_get_feature { > @@ -410,6 +418,19 @@ sub feature_pickaxe { > return ($_[0]); > } > > +sub feature_patches { > + my @val = (git_get_project_config('patches', '--int')); > + > + # if @val is empty, the config is not (properly) > + # overriding the feature, so we return the default, > + # otherwise we pick the override Very similar feature_snapshot subroutine doesn't have such comment. I don't think it is necessary, and its wording might cause confusion. > + if (@val) { > + return @val; > + } > + > + return ($_[0]); > +} > + Nice. > # checking HEAD file with -e is fragile if the repository was > # initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed > # and then pruned. > @@ -503,6 +524,7 @@ our %actions = ( > "heads" => \&git_heads, > "history" => \&git_history, > "log" => \&git_log, > + "patch" => \&git_patch, > "rss" => \&git_rss, > "atom" => \&git_atom, > "search" => \&git_search, > @@ -5386,6 +5408,13 @@ sub git_blobdiff_plain { > > sub git_commitdiff { > my $format = shift || 'html'; > + > + my $patch_max; > + if ($format eq 'patch') { > + $patch_max = gitweb_check_feature('patches'); > + die_error(403, "Patch view not allowed") unless $patch_max; > + } > + Hmmm... gitweb_check_feature > $hash ||= $hash_base || "HEAD"; > my %co = parse_commit($hash) > or die_error(404, "Unknown commit object"); > @@ -5483,7 +5512,23 @@ sub git_commitdiff { > open $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts, > '-p', $hash_parent_param, $hash, "--" > or die_error(500, "Open git-diff-tree failed"); > - > + } elsif ($format eq 'patch') { > + # For commit ranges, we limit the output to the number of > + # patches specified in the 'patches' feature. > + # For single commits, we limit the output to a single patch, > + # diverging from the git format-patch default. I think it would be more clear to use + # diverging from the git-format-patch default. > + my @commit_spec = (); > + if ($hash_parent) { > + if ($patch_max > 0) { > + push @commit_spec, "-$patch_max"; > + } > + push @commit_spec, '-n', "$hash_parent..$hash"; > + } else { > + push @commit_spec, '-1', '--root', $hash; > + } Nice solution. I like it. > + open $fd, "-|", git_cmd(), "format-patch", '--encoding=utf8', > + '--stdout', @commit_spec > + or die_error(500, "Open git-format-patch failed"); > } else { > die_error(400, "Unknown commitdiff format"); > } > @@ -5532,6 +5577,14 @@ sub git_commitdiff { > print to_utf8($line) . "\n"; > } > print "---\n\n"; > + } elsif ($format eq 'patch') { > + my $filename = basename($project) . "-$hash.patch"; I am wondering if we could somehow mark (encode) either $hash_parent or number of patches in proposed filename... but I don't think it is worth it. > + > + print $cgi->header( > + -type => 'text/plain', > + -charset => 'utf-8', > + -expires => $expires, > + -content_disposition => 'inline; filename="' . "$filename" . '"'); > } > > # write patch > @@ -5553,6 +5606,11 @@ sub git_commitdiff { > print <$fd>; > close $fd > or print "Reading git-diff-tree failed\n"; > + } elsif ($format eq 'patch') { > + local $/ = undef; > + print <$fd>; > + close $fd > + or print "Reading git-format-patch failed\n"; Nice, although... I'd prefer for Perl expert to say if it is better to dump file as a whole in such way (it might be quite large), or to do it line by line, i.e. without "local $/ = undef;", or using "print while <$fd>;" also without "local $/ = undef;". > } > } > > @@ -5560,6 +5618,11 @@ sub git_commitdiff_plain { > git_commitdiff('plain'); > } > > +# format-patch-style patches > +sub git_patch { > + git_commitdiff('patch'); > +} > + Nice. > sub git_history { > if (!defined $hash_base) { > $hash_base = git_get_head_hash($project); > -- > 1.5.6.5 > > -- Jakub Narebski Poland ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [RFCv4 1/3] gitweb: add patch view 2008-12-15 13:17 ` [RFCv4 1/3] gitweb: add patch view Jakub Narebski @ 2008-12-15 13:48 ` Giuseppe Bilotta 2008-12-15 13:58 ` Jakub Narebski 0 siblings, 1 reply; 12+ messages in thread From: Giuseppe Bilotta @ 2008-12-15 13:48 UTC (permalink / raw) To: Jakub Narebski; +Cc: git, Petr Baudis, Junio C Hamano On Mon, Dec 15, 2008 at 2:17 PM, Jakub Narebski <jnareb@gmail.com> wrote: >> + my $patch_max; >> + if ($format eq 'patch') { >> + $patch_max = gitweb_check_feature('patches'); >> + die_error(403, "Patch view not allowed") unless $patch_max; >> + } >> + > > Hmmm... gitweb_check_feature You're right, it's an abuse. I'll make it gitweb_get_feature()[0] > I am wondering if we could somehow mark (encode) either $hash_parent > or number of patches in proposed filename... but I don't think it is > worth it. Including hash_parent if defined is quite possible. I'm not sure it's really worth it considering that the typical usage would be to publish a patchset for a particular feature (in which case the hash/branch name would be enough). >> + } elsif ($format eq 'patch') { >> + local $/ = undef; >> + print <$fd>; >> + close $fd >> + or print "Reading git-format-patch failed\n"; > > Nice, although... I'd prefer for Perl expert to say if it is better > to dump file as a whole in such way (it might be quite large), or > to do it line by line, i.e. without "local $/ = undef;", or using > "print while <$fd>;" also without "local $/ = undef;". I'm just sticking to whatever the existing code does :-) As soon as you finish the patchset review I'll have a new version taking into consideration all the other suggestions and remarks I snipped from this reply. -- Giuseppe "Oblomov" Bilotta ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [RFCv4 1/3] gitweb: add patch view 2008-12-15 13:48 ` Giuseppe Bilotta @ 2008-12-15 13:58 ` Jakub Narebski 0 siblings, 0 replies; 12+ messages in thread From: Jakub Narebski @ 2008-12-15 13:58 UTC (permalink / raw) To: Giuseppe Bilotta; +Cc: git, Petr Baudis, Junio C Hamano Giuseppe Bilotta wrote: > On Mon, Dec 15, 2008 at 2:17 PM, Jakub Narebski <jnareb@gmail.com> wrote: >>> + my $patch_max; >>> + if ($format eq 'patch') { >>> + $patch_max = gitweb_check_feature('patches'); >>> + die_error(403, "Patch view not allowed") unless $patch_max; >>> + } >>> + >> >> Hmmm... gitweb_check_feature > > You're right, it's an abuse. I'll make it gitweb_get_feature()[0] Or better + ($patch_max) = gitweb_get_feature('patches'); [...] > As soon as you finish the patchset review I'll have a new version > taking into consideration all the other suggestions and remarks I > snipped from this reply. Thank you very much for keeping this patch series alive. -- Jakub Narebski Poland ^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2008-12-16 11:15 UTC | newest] Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2008-12-06 15:02 [RFCv4 0/3] gitweb: patch view Giuseppe Bilotta 2008-12-06 15:02 ` [RFCv4 1/3] gitweb: add " Giuseppe Bilotta 2008-12-06 15:02 ` [RFCv4 2/3] gitweb: add patches view Giuseppe Bilotta 2008-12-06 15:02 ` [RFCv4 3/3] gitweb: link to patch(es) view from commit and log views Giuseppe Bilotta 2008-12-16 1:03 ` Jakub Narebski [not found] ` <cb7bb73a0812160202n1f4f7f4fi7f71455eb42bcd31@mail.gmail.com> 2008-12-16 10:14 ` Jakub Narebski 2008-12-16 11:14 ` Giuseppe Bilotta 2008-12-16 3:14 ` [RFCv4 2/3] gitweb: add patches view Jakub Narebski [not found] ` <cb7bb73a0812160149j1dcaefccv1caf4a2e589ffebb@mail.gmail.com> 2008-12-16 10:16 ` Jakub Narebski 2008-12-15 13:17 ` [RFCv4 1/3] gitweb: add patch view Jakub Narebski 2008-12-15 13:48 ` Giuseppe Bilotta 2008-12-15 13:58 ` Jakub Narebski
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.