gitweb: patch view
v4 cover gitweb: patch view
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(-)
RFC v4 1/3 gitweb: add patch view
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.
--- gitweb/gitweb.perl | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 64 insertions(+), 1 deletions(-)
gitweb/gitweb.perl +64 -1
@@ -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);
Signature · 1 line
1.5.6.5
RFC v4 2/3 gitweb: add patches view
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(-)
gitweb/gitweb.perl +18 -2
@@ -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 {
Signature · 1 line
1.5.6.5
RFC v4 3/3 gitweb: link to patch(es) view from commit and log views
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.
--- gitweb/gitweb.perl | 30 ++++++++++++++++++++++++++++-- 1 files changed, 28 insertions(+), 2 deletions(-)
gitweb/gitweb.perl +28 -2
@@ -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);
Signature · 1 line
1.5.6.5
Re: [RFCv4 3/3] gitweb: link to patch(es) view from commit and log views
Quoted 7 lines · 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 <[email protected]>
A few remarks, but otherwise:
gitweb/gitweb.perl sub git_log { · line 5022
Quoted 13 lines
--- gitweb/gitweb.perl | 30 ++++++++++++++++++++++++++++-- 1 files changed, 28 insertions(+), 2 deletions(-)gitweb/gitweb.perl +1
-0@@ -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...
gitweb/gitweb.perl sub git_log { · line 5027
Quoted 5 lines
gitweb/gitweb.perl +5
-0+ 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).
Quoted 7 lines
gitweb/gitweb.perl +3
-0+ } + } + git_header_html(); git_print_page_nav('log','', $hash,undef,undef, $paging_nav);
gitweb/gitweb.perl sub git_commit { · line 5114
Quoted 8 lines
gitweb/gitweb.perl +5
-0@@ -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.
gitweb/gitweb.perl sub git_commitdiff { · line 5430
Quoted 9 lines
gitweb/gitweb.perl +1
-1if (!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?...
Quoted 6 lines
gitweb/gitweb.perl +0
-1if ($format eq 'patch') { - $patch_max = gitweb_check_feature('patches'); die_error(403, "Patch view not allowed") unless $patch_max; }
gitweb/gitweb.perl sub git_commitdiff { · line 5453
Quoted 8 lines
gitweb/gitweb.perl +5
-0@@ -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'
Quoted 5 lines
gitweb/gitweb.perl +0
-0if (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),
gitweb/gitweb.perl sub git_shortlog { · line 6017
Quoted 10 lines
gitweb/gitweb.perl +8
-0-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...
Quoted 7 lines
gitweb/gitweb.perl +0
-0git_header_html(); git_print_page_nav('shortlog','', $hash,$hash,$hash, $paging_nav);Signature · 1 line
1.5.6.5
Signature · 2 lines
Jakub Narebski Poland
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [RFCv4 3/3] gitweb: link to patch(es) view from commit and log views
You lost CC, somehow...
Quoted 9 lines · Giuseppe Bilotta
Quoted 8 lines · Jakub Narebski
Quoted 5 lines · Giuseppe Bilotta
gitweb/gitweb.perl +5
-0+ if ($patch_max) { + if ($patch_max < 0 || @commitlist <= $patch_max) { + $paging_nav .= " ⋅ " . + $cgi->a({-href => href(action=>"patches", -replay=>1)}, + @commitlist > 1 ? "patchset" : "patch");
[...]
Quoted 10 lines
Quoted 9 lines
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).
Quoted 3 lines
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...
Signature · 2 lines
Jakub Narebski Poland
Re: [RFCv4 3/3] gitweb: link to patch(es) view from commit and log views
Quoted 1 line · Jakub Narebski
You lost CC, somehow...
Duh, clicked the wrong button.
Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
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).
Quoted 7 lines
Quoted 3 lines
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.
Quoted 8 lines
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.
Signature · 1 line
Giuseppe "Oblomov" Bilotta
Re: [RFCv4 2/3] gitweb: add patches view
In reply to Giuseppe BilottaQuoted 3 lines · 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.
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?
Quoted 17 lines
--- gitweb/gitweb.perl | 20 ++++++++++++++++++-- 1 files changed, 18 insertions(+), 2 deletions(-)gitweb/gitweb.perl +1
-0@@ -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,
gitweb/gitweb.perl sub git_blobdiff_plain { · line 5414
Quoted 6 lines
gitweb/gitweb.perl +3
-0@@ -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...
Quoted 7 lines
gitweb/gitweb.perl +0
-0my $patch_max; if ($format eq 'patch') {@@ -5524,7 +5528,15 @@ sub git_commitdiff { } push @commit_spec, '-n', "$hash_parent..$hash"; } else {
gitweb/gitweb.perl sub git_commitdiff { · line 5539
Quoted 10 lines
gitweb/gitweb.perl +9
-1- 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.
gitweb/gitweb.perl sub git_commitdiff_plain { · line 5639
Quoted 13 lines
gitweb/gitweb.perl +5
-1} 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.
Quoted 7 lines
gitweb/gitweb.perl +0
-0} sub git_history {Signature · 1 line
1.5.6.5
Signature · 2 lines
Jakub Narebski Poland
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [RFCv4 2/3] gitweb: add patches view
Quoted 7 lines · Giuseppe Bilotta
Quoted 6 lines · Jakub Narebski
Quoted 3 lines · 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.
Quoted 8 lines
Quoted 4 lines
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_parentif present because IMO it's what a user would expect in case e.g. of hand-crafted URLs.
Ah. I can understand that.
[...]
Quoted 17 lines
Quoted 6 lines
gitweb/gitweb.perl sub git_blobdiff_plain { · line 5414
Quoted 5 lines
sub git_commitdiff { my $format = shift || 'html';gitweb/gitweb.perl +3
-0+ # for patch view: should we limit ourselves to a single patch + # if only a single commit is passed? + my $single_patch = shift && 1;Quoted 6 lines
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.)
Signature · 2 lines
Jakub Narebski Poland
Re: [RFCv4 1/3] gitweb: add patch view
In reply to Giuseppe BilottaQuoted 12 lines · Giuseppe Bilotta
The output of
commitdiff_plainis not intended for git-am:
* when given a range of commits,commitdiff_plainpublishes 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.
Quoted 4 lines
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.
Quoted 2 lines
Signed-off-by Giuseppe Bilotta <[email protected]>
Other than that minor detail I like this patch
Quoted 9 lines
--- gitweb/gitweb.perl | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 64 insertions(+), 1 deletions(-)gitweb/gitweb.perl +0
-0
gitweb/gitweb.perl our %feature = ( · line 335
Quoted 7 lines
gitweb/gitweb.perl +4
-0@@ -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
Quoted 8 lines
gitweb/gitweb.perl +4
-0+ 'patches' => { + 'sub' => \&feature_patches, + 'override' => 0, + 'default' => [16]}, ); sub gitweb_get_feature {
gitweb/gitweb.perl sub feature_pickaxe { · line 426
Quoted 9 lines
gitweb/gitweb.perl +6
-0@@ -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.
gitweb/gitweb.perl sub feature_pickaxe { · line 433
Quoted 7 lines
gitweb/gitweb.perl +7
-0+ if (@val) { + return @val; + } + + return ($_[0]); +} +
Nice.
Quoted 12 lines
gitweb/gitweb.perl +1
-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,
gitweb/gitweb.perl sub git_blobdiff_plain { · line 5417
Quoted 10 lines
gitweb/gitweb.perl +7
-0@@ -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
gitweb/gitweb.perl sub git_commitdiff { · line 5519
Quoted 13 lines
gitweb/gitweb.perl +5
-1$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.
gitweb/gitweb.perl sub git_commitdiff { · line 5528
Quoted 9 lines
gitweb/gitweb.perl +9
-0+ 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.
gitweb/gitweb.perl sub git_commitdiff { · line 5581
Quoted 12 lines
gitweb/gitweb.perl +5
-0+ 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.
Quoted 10 lines
gitweb/gitweb.perl +6
-0+ + print $cgi->header( + -type => 'text/plain', + -charset => 'utf-8', + -expires => $expires, + -content_disposition => 'inline; filename="' . "$filename" . '"'); } # write patch
gitweb/gitweb.perl sub git_commitdiff { · line 5613
Quoted 8 lines
gitweb/gitweb.perl +5
-0@@ -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;".
gitweb/gitweb.perl sub git_commitdiff_plain { · line 5625
Quoted 12 lines
gitweb/gitweb.perl +5
-0} }@@ -5560,6 +5618,11 @@ sub git_commitdiff_plain { git_commitdiff('plain'); } +# format-patch-style patches +sub git_patch { + git_commitdiff('patch'); +} +
Nice.
Quoted 7 lines
gitweb/gitweb.perl +0
-0sub git_history { if (!defined $hash_base) { $hash_base = git_get_head_hash($project);Signature · 1 line
1.5.6.5
Signature · 2 lines
Jakub Narebski Poland
Re: [RFCv4 1/3] gitweb: add patch view
Quoted 8 lines · Jakub Narebski
gitweb/gitweb.perl sub git_blobdiff_plain { · line 5417
Quoted 6 lines
gitweb/gitweb.perl +6
-0+ 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]
Quoted 3 lines
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).
Quoted 10 lines
gitweb/gitweb.perl sub git_commitdiff { · line 5613
Quoted 5 lines
gitweb/gitweb.perl +5
-0+ } 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.
Signature · 1 line
Giuseppe "Oblomov" Bilotta
Re: [RFCv4 1/3] gitweb: add patch view
Quoted 9 lines · Giuseppe Bilotta
Quoted 7 lines · Jakub Narebski
Quoted 6 lines
gitweb/gitweb.perl +6
-0+ my $patch_max; + if ($format eq 'patch') { + $patch_max = gitweb_check_feature('patches'); + die_error(403, "Patch view not allowed") unless $patch_max; + } +
Quoted 3 lines
Quoted 1 line
Hmmm...
gitweb_check_featureYou're right, it's an abuse. I'll make it gitweb_get_feature()[0]
Or better
+ ($patch_max) = gitweb_get_feature('patches');
[...]
Quoted 3 lines
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.
Signature · 2 lines
Jakub Narebski Poland