{"thread":{"id":"16779","subject":"[PATCHv6 0/4] gitweb: patch view","startedAt":"2008-12-18T07:13:15Z","lastAt":"2008-12-18T07:13:19Z","messageCount":5,"participants":["Giuseppe Bilotta"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"98229","messageId":"1229584399-23879-1-git-send-email-giuseppe.bilotta@gmail.com","threadId":"16779","inReplyTo":null,"subject":"[PATCHv6 0/4] gitweb: patch view","fromName":"Giuseppe Bilotta","fromEmail":"giuseppe.bilotta@gmail.com","sentAt":"2008-12-18T07:13:15Z","receivedAt":"2008-12-18T07:13:15Z","isPatch":false,"sender":{"key":"giuseppe.bilotta@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1464?v=4"},"body":"Sixth iteration of the patch view in gitweb, that exposes the\ngit-format-patch output directly, allowing patchset exchange via gitweb.\n\nAs suggested by Junio, the call pattern for git_commitdiff is changed to\nuse named parameters even for the first parameter (-format).\n\nGiuseppe Bilotta (4):\n  gitweb: add patch view\n  gitweb: change call pattern for git_commitdiff\n  gitweb: add patches view\n  gitweb: link to patch(es) view in commit(diff) and (short)log view\n\n gitweb/gitweb.perl |  109 +++++++++++++++++++++++++++++++++++++++++++++++++++-\n 1 files changed, 108 insertions(+), 1 deletions(-)\n"},{"id":"98230","messageId":"1229584399-23879-2-git-send-email-giuseppe.bilotta@gmail.com","threadId":"16779","inReplyTo":"1229584399-23879-1-git-send-email-giuseppe.bilotta@gmail.com","subject":"[PATCHv6 1/4] gitweb: add patch view","fromName":"Giuseppe Bilotta","fromEmail":"giuseppe.bilotta@gmail.com","sentAt":"2008-12-18T07:13:16Z","receivedAt":"2008-12-18T07:13:16Z","isPatch":false,"sender":{"key":"giuseppe.bilotta@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1464?v=4"},"body":"The output of commitdiff_plain is not intended for git-am:\n * when given a range of commits, commitdiff_plain publishes a single\n   patch with the message from the first commit, instead of a patchset\n * the hand-built email format replicates the commit summary both as\n   email subject and as first line of the email itself, resulting in\n   a duplication if the output is used with git-am.\n\nWe thus create a new view that can be fed to git-am directly, allowing\npatch exchange via gitweb. The new view exposes the output of git\nformat-patch directly, limiting it to a single patch in the case of a\nsingle commit.\n\nA configurable upper limit defaulting to 16 is imposed on the number of\ncommits which will be included in a patchset, to prevent DoS attacks on\nthe server. Setting the limit to 0 will disable the patch view, setting\nit to a negative number will remove the limit.\n\nSigned-off-by: Giuseppe Bilotta <giuseppe.bilotta@gmail.com>\n---\n gitweb/gitweb.perl |   69 +++++++++++++++++++++++++++++++++++++++++++++++++++-\n 1 files changed, 68 insertions(+), 1 deletions(-)\n\ndiff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl\nindex 6eb370d..1006dfe 100755\n--- a/gitweb/gitweb.perl\n+++ b/gitweb/gitweb.perl\n@@ -330,6 +330,21 @@ our %feature = (\n \t'ctags' => {\n \t\t'override' => 0,\n \t\t'default' => [0]},\n+\n+\t# The maximum number of patches in a patchset generated in patch\n+\t# view. Set this to 0 or undef to disable patch view, or to a\n+\t# negative number to remove any limit.\n+\n+\t# To disable system wide have in $GITWEB_CONFIG\n+\t# $feature{'patches'}{'default'} = [0];\n+\t# To have project specific config enable override in $GITWEB_CONFIG\n+\t# $feature{'patches'}{'override'} = 1;\n+\t# and in project config gitweb.patches = 0|n;\n+\t# where n is the maximum number of patches allowed in a patchset.\n+\t'patches' => {\n+\t\t'sub' => \\&feature_patches,\n+\t\t'override' => 0,\n+\t\t'default' => [16]},\n );\n \n sub gitweb_get_feature {\n@@ -411,6 +426,16 @@ sub feature_pickaxe {\n \treturn ($_[0]);\n }\n \n+sub feature_patches {\n+\tmy @val = (git_get_project_config('patches', '--int'));\n+\n+\tif (@val) {\n+\t\treturn @val;\n+\t}\n+\n+\treturn ($_[0]);\n+}\n+\n # checking HEAD file with -e is fragile if the repository was\n # initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed\n # and then pruned.\n@@ -504,6 +529,7 @@ our %actions = (\n \t\"heads\" => \\&git_heads,\n \t\"history\" => \\&git_history,\n \t\"log\" => \\&git_log,\n+\t\"patch\" => \\&git_patch,\n \t\"rss\" => \\&git_rss,\n \t\"atom\" => \\&git_atom,\n \t\"search\" => \\&git_search,\n@@ -5387,6 +5413,13 @@ sub git_blobdiff_plain {\n \n sub git_commitdiff {\n \tmy $format = shift || 'html';\n+\n+\tmy $patch_max;\n+\tif ($format eq 'patch') {\n+\t\t($patch_max) = gitweb_get_feature('patches');\n+\t\tdie_error(403, \"Patch view not allowed\") unless $patch_max;\n+\t}\n+\n \t$hash ||= $hash_base || \"HEAD\";\n \tmy %co = parse_commit($hash)\n \t    or die_error(404, \"Unknown commit object\");\n@@ -5484,7 +5517,23 @@ sub git_commitdiff {\n \t\topen $fd, \"-|\", git_cmd(), \"diff-tree\", '-r', @diff_opts,\n \t\t\t'-p', $hash_parent_param, $hash, \"--\"\n \t\t\tor die_error(500, \"Open git-diff-tree failed\");\n-\n+\t} elsif ($format eq 'patch') {\n+\t\t# For commit ranges, we limit the output to the number of\n+\t\t# patches specified in the 'patches' feature.\n+\t\t# For single commits, we limit the output to a single patch,\n+\t\t# diverging from the git-format-patch default.\n+\t\tmy @commit_spec = ();\n+\t\tif ($hash_parent) {\n+\t\t\tif ($patch_max > 0) {\n+\t\t\t\tpush @commit_spec, \"-$patch_max\";\n+\t\t\t}\n+\t\t\tpush @commit_spec, '-n', \"$hash_parent..$hash\";\n+\t\t} else {\n+\t\t\tpush @commit_spec, '-1', '--root', $hash;\n+\t\t}\n+\t\topen $fd, \"-|\", git_cmd(), \"format-patch\", '--encoding=utf8',\n+\t\t\t'--stdout', @commit_spec\n+\t\t\tor die_error(500, \"Open git-format-patch failed\");\n \t} else {\n \t\tdie_error(400, \"Unknown commitdiff format\");\n \t}\n@@ -5533,6 +5582,14 @@ sub git_commitdiff {\n \t\t\tprint to_utf8($line) . \"\\n\";\n \t\t}\n \t\tprint \"---\\n\\n\";\n+\t} elsif ($format eq 'patch') {\n+\t\tmy $filename = basename($project) . \"-$hash.patch\";\n+\n+\t\tprint $cgi->header(\n+\t\t\t-type => 'text/plain',\n+\t\t\t-charset => 'utf-8',\n+\t\t\t-expires => $expires,\n+\t\t\t-content_disposition => 'inline; filename=\"' . \"$filename\" . '\"');\n \t}\n \n \t# write patch\n@@ -5554,6 +5611,11 @@ sub git_commitdiff {\n \t\tprint <$fd>;\n \t\tclose $fd\n \t\t\tor print \"Reading git-diff-tree failed\\n\";\n+\t} elsif ($format eq 'patch') {\n+\t\tlocal $/ = undef;\n+\t\tprint <$fd>;\n+\t\tclose $fd\n+\t\t\tor print \"Reading git-format-patch failed\\n\";\n \t}\n }\n \n@@ -5561,6 +5623,11 @@ sub git_commitdiff_plain {\n \tgit_commitdiff('plain');\n }\n \n+# format-patch-style patches\n+sub git_patch {\n+\tgit_commitdiff('patch');\n+}\n+\n sub git_history {\n \tif (!defined $hash_base) {\n \t\t$hash_base = git_get_head_hash($project);\n-- \n1.5.6.5\n"},{"id":"98231","messageId":"1229584399-23879-3-git-send-email-giuseppe.bilotta@gmail.com","threadId":"16779","inReplyTo":"1229584399-23879-2-git-send-email-giuseppe.bilotta@gmail.com","subject":"[PATCHv6 2/4] gitweb: change call pattern for git_commitdiff","fromName":"Giuseppe Bilotta","fromEmail":"giuseppe.bilotta@gmail.com","sentAt":"2008-12-18T07:13:17Z","receivedAt":"2008-12-18T07:13:17Z","isPatch":false,"sender":{"key":"giuseppe.bilotta@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1464?v=4"},"body":"Since we are going to introduce an additional parameter for\ngit_commitdiff to tune patch view, we switch to named/hash-based\nparameter passing for clarity and robustness.\n---\n gitweb/gitweb.perl |    7 ++++---\n 1 files changed, 4 insertions(+), 3 deletions(-)\n\ndiff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl\nindex 1006dfe..18d43e7 100755\n--- a/gitweb/gitweb.perl\n+++ b/gitweb/gitweb.perl\n@@ -5412,7 +5412,8 @@ sub git_blobdiff_plain {\n }\n \n sub git_commitdiff {\n-\tmy $format = shift || 'html';\n+\tmy %params = @_;\n+\tmy $format = $params{-format} || 'html';\n \n \tmy $patch_max;\n \tif ($format eq 'patch') {\n@@ -5620,12 +5621,12 @@ sub git_commitdiff {\n }\n \n sub git_commitdiff_plain {\n-\tgit_commitdiff('plain');\n+\tgit_commitdiff(-format => 'plain');\n }\n \n # format-patch-style patches\n sub git_patch {\n-\tgit_commitdiff('patch');\n+\tgit_commitdiff(-format => 'patch');\n }\n \n sub git_history {\n-- \n1.5.6.5\n"},{"id":"98232","messageId":"1229584399-23879-4-git-send-email-giuseppe.bilotta@gmail.com","threadId":"16779","inReplyTo":"1229584399-23879-3-git-send-email-giuseppe.bilotta@gmail.com","subject":"[PATCHv6 3/4] gitweb: add patches view","fromName":"Giuseppe Bilotta","fromEmail":"giuseppe.bilotta@gmail.com","sentAt":"2008-12-18T07:13:18Z","receivedAt":"2008-12-18T07:13:18Z","isPatch":false,"sender":{"key":"giuseppe.bilotta@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1464?v=4"},"body":"The only difference between patch and patches view is in the treatement\nof single commits: the former only displays a single patch, whereas the\nlatter displays a patchset leading to the specified commit.\n\nSigned-off-by: Giuseppe Bilotta <giuseppe.bilotta@gmail.com>\n---\n gitweb/gitweb.perl |   15 ++++++++++++++-\n 1 files changed, 14 insertions(+), 1 deletions(-)\n\ndiff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl\nindex 18d43e7..78aaebe 100755\n--- a/gitweb/gitweb.perl\n+++ b/gitweb/gitweb.perl\n@@ -530,6 +530,7 @@ our %actions = (\n \t\"history\" => \\&git_history,\n \t\"log\" => \\&git_log,\n \t\"patch\" => \\&git_patch,\n+\t\"patches\" => \\&git_patches,\n \t\"rss\" => \\&git_rss,\n \t\"atom\" => \\&git_atom,\n \t\"search\" => \\&git_search,\n@@ -5530,7 +5531,15 @@ sub git_commitdiff {\n \t\t\t}\n \t\t\tpush @commit_spec, '-n', \"$hash_parent..$hash\";\n \t\t} else {\n-\t\t\tpush @commit_spec, '-1', '--root', $hash;\n+\t\t\tif ($params{-single}) {\n+\t\t\t\tpush @commit_spec, '-1';\n+\t\t\t} else {\n+\t\t\t\tif ($patch_max > 0) {\n+\t\t\t\t\tpush @commit_spec, \"-$patch_max\";\n+\t\t\t\t}\n+\t\t\t\tpush @commit_spec, \"-n\";\n+\t\t\t}\n+\t\t\tpush @commit_spec, '--root', $hash;\n \t\t}\n \t\topen $fd, \"-|\", git_cmd(), \"format-patch\", '--encoding=utf8',\n \t\t\t'--stdout', @commit_spec\n@@ -5626,6 +5635,10 @@ sub git_commitdiff_plain {\n \n # format-patch-style patches\n sub git_patch {\n+\tgit_commitdiff(-format => 'patch', -single=> 1);\n+}\n+\n+sub git_patches {\n \tgit_commitdiff(-format => 'patch');\n }\n \n-- \n1.5.6.5\n"},{"id":"98233","messageId":"1229584399-23879-5-git-send-email-giuseppe.bilotta@gmail.com","threadId":"16779","inReplyTo":"1229584399-23879-4-git-send-email-giuseppe.bilotta@gmail.com","subject":"[PATCHv6 4/4] gitweb: link to patch(es) view in commit(diff) and (short)log view","fromName":"Giuseppe Bilotta","fromEmail":"giuseppe.bilotta@gmail.com","sentAt":"2008-12-18T07:13:19Z","receivedAt":"2008-12-18T07:13:19Z","isPatch":false,"sender":{"key":"giuseppe.bilotta@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1464?v=4"},"body":"We link to patch view in commit and commitdiff view, and to patches view\nin log and shortlog view.\n\nIn (short)log view, the link is only offered when the number of commits\nshown is no more than the allowed maximum number of patches.\n\nSigned-off-by: Giuseppe Bilotta <giuseppe.bilotta@gmail.com>\n---\n gitweb/gitweb.perl |   30 ++++++++++++++++++++++++++++--\n 1 files changed, 28 insertions(+), 2 deletions(-)\n\ndiff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl\nindex 78aaebe..fd8bc29 100755\n--- a/gitweb/gitweb.perl\n+++ b/gitweb/gitweb.perl\n@@ -5024,6 +5024,15 @@ sub git_log {\n \n \tmy $paging_nav = format_paging_nav('log', $hash, $head, $page, $#commitlist >= 100);\n \n+\tmy ($patch_max) = gitweb_get_feature('patches');\n+\tif ($patch_max) {\n+\t\tif ($patch_max < 0 || @commitlist <= $patch_max) {\n+\t\t\t$paging_nav .= \" &sdot; \" .\n+\t\t\t\t$cgi->a({-href => href(action=>\"patches\", -replay=>1)},\n+\t\t\t\t\t\"patches\");\n+\t\t}\n+\t}\n+\n \tgit_header_html();\n \tgit_print_page_nav('log','', $hash,undef,undef, $paging_nav);\n \n@@ -5103,6 +5112,11 @@ sub git_commit {\n \t\t\t} @$parents ) .\n \t\t\t')';\n \t}\n+\tif (gitweb_check_feature('patches')) {\n+\t\t$formats_nav .= \" | \" .\n+\t\t\t$cgi->a({-href => href(action=>\"patch\", -replay=>1)},\n+\t\t\t\t\"patch\");\n+\t}\n \n \tif (!defined $parent) {\n \t\t$parent = \"--root\";\n@@ -5416,9 +5430,8 @@ sub git_commitdiff {\n \tmy %params = @_;\n \tmy $format = $params{-format} || 'html';\n \n-\tmy $patch_max;\n+\tmy ($patch_max) = gitweb_get_feature('patches');\n \tif ($format eq 'patch') {\n-\t\t($patch_max) = gitweb_get_feature('patches');\n \t\tdie_error(403, \"Patch view not allowed\") unless $patch_max;\n \t}\n \n@@ -5436,6 +5449,11 @@ sub git_commitdiff {\n \t\t$formats_nav =\n \t\t\t$cgi->a({-href => href(action=>\"commitdiff_plain\", -replay=>1)},\n \t\t\t        \"raw\");\n+\t\tif ($patch_max) {\n+\t\t\t$formats_nav .= \" | \" .\n+\t\t\t\t$cgi->a({-href => href(action=>\"patch\", -replay=>1)},\n+\t\t\t\t\t\"patch\");\n+\t\t}\n \n \t\tif (defined $hash_parent &&\n \t\t    $hash_parent ne '-c' && $hash_parent ne '--cc') {\n@@ -5992,6 +6010,14 @@ sub git_shortlog {\n \t\t\t$cgi->a({-href => href(-replay=>1, page=>$page+1),\n \t\t\t         -accesskey => \"n\", -title => \"Alt-n\"}, \"next\");\n \t}\n+\tmy $patch_max = gitweb_check_feature('patches');\n+\tif ($patch_max) {\n+\t\tif ($patch_max < 0 || @commitlist <= $patch_max) {\n+\t\t\t$paging_nav .= \" &sdot; \" .\n+\t\t\t\t$cgi->a({-href => href(action=>\"patches\", -replay=>1)},\n+\t\t\t\t\t\"patches\");\n+\t\t}\n+\t}\n \n \tgit_header_html();\n \tgit_print_page_nav('shortlog','', $hash,$hash,$hash, $paging_nav);\n-- \n1.5.6.5\n"}]}