{"thread":{"id":"66003","subject":"[PATCH 0/2] gitweb: shorten commitdiff index hashes with file modes","startedAt":"2026-07-15T09:11:44Z","lastAt":"2026-07-17T13:53:15Z","messageCount":6,"participants":["Travor Liu","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"548245","messageId":"SA1PR10MB997715AD62D7F2AF64EB1A9887F1F82@SA1PR10MB997715.namprd10.prod.outlook.com","threadId":"66003","inReplyTo":null,"subject":"[PATCH 0/2] gitweb: shorten commitdiff index hashes with file modes","fromName":"Travor Liu","fromEmail":"travor_lzh@outlook.com","sentAt":"2026-07-15T09:11:28Z","receivedAt":"2026-07-15T09:11:44Z","isPatch":true,"body":"From: Travor Liu <travor_lzh@outlook.com>\n\nThis series fixes gitweb rendering of commitdiff index lines that carry\na trailing file mode, such as:\n\n    index <old>..<new> 100644\n\ngitweb currently recognizes the mode before matching the object IDs,\nwhich appends the file-type annotation first.  The later object-ID\nmatcher expects the ID range to end the line, so these common index\nlines keep two full, unlinked object IDs.\n\nPatch 1 moves the mode handling so the index object IDs can still be\nshortened and linked.\n\nPatch 2 adds a gitweb regression test for the common\n\"index <old>..<new> 100644\" form.\n\nTested with:\n\n    make NO_RUST=YesPlease\n    cd t && prove -v t9502-gitweb-standalone-parse-output.sh\n\nTravor Liu (2):\n  gitweb: shorten index hashes with trailing file modes\n  t9502: test gitweb index hash formatting with modes\n\n gitweb/gitweb.perl                        | 18 +++++++++++++-----\n t/t9502-gitweb-standalone-parse-output.sh | 14 ++++++++++++++\n 2 files changed, 27 insertions(+), 5 deletions(-)\n\n-- \n2.52.0\n\n"},{"id":"548246","messageId":"SA1PR10MB997715CF1DAE615A9C166BE3ABF1F82@SA1PR10MB997715.namprd10.prod.outlook.com","threadId":"66003","inReplyTo":"SA1PR10MB997715AD62D7F2AF64EB1A9887F1F82@SA1PR10MB997715.namprd10.prod.outlook.com","subject":"[PATCH 1/2] gitweb: shorten index hashes with trailing file modes","fromName":"Travor Liu","fromEmail":"travor_lzh@outlook.com","sentAt":"2026-07-15T09:11:29Z","receivedAt":"2026-07-15T09:11:53Z","isPatch":true,"body":"From: Travor Liu <travor_lzh@outlook.com>\n\nDiff index lines have included a trailing file mode since ec1fcc16af\n(Show original and resulting blob object info in diff output,\n2005-10-07) when the old and new file modes match:\n\n    index <old>..<new> 100644\n\ngitweb recognizes that trailing mode before it tries to shorten and\nlink the object IDs.  This appends the file-type annotation first, but\nthe object-ID matcher requires the ID range to end the line.  As a\nresult, this common form keeps both full object IDs as plain text.\n\nThat is inconsistent with other hash displays and makes commitdiff\noutput wider than necessary.  Recent gitweb changes have fixed mobile\noverflow in log, commit, blob and diff views; leaving two full object\nIDs in this header preserves an avoidable long line in the diff header.\n\nRemove the trailing mode before matching the index IDs, then append it\nagain after the IDs have been shortened and linked.  This preserves the\nmode display while letting ordinary and combined index lines use the\nexisting object-ID formatting paths.\n\nSigned-off-by: Travor Liu <travor_lzh@outlook.com>\n---\n gitweb/gitweb.perl | 18 +++++++++++++-----\n 1 file changed, 13 insertions(+), 5 deletions(-)\n\ndiff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl\nindex fde8045..8c2d9b8 100755\n--- a/gitweb/gitweb.perl\n+++ b/gitweb/gitweb.perl\n@@ -2339,12 +2339,14 @@ sub format_extended_diff_header_line {\n \t\t$line .= $cgi->a({-href=>$to->{'href'}, -class=>\"path\"},\n \t\t                 esc_path($to->{'file'}));\n \t}\n-\t# match single <mode>\n-\tif ($line =~ m/\\s(\\d{6})$/) {\n-\t\t$line .= '<span class=\"info\"> (' .\n-\t\t         file_type_long($1) .\n-\t\t         ')</span>';\n+\n+\t# Temporarily remove a trailing <mode> so an index line ends with its\n+\t# object IDs and can be shortened below.\n+\tmy $mode;\n+\tif ($line =~ s/\\s(\\d{6})$//) {\n+\t\t$mode = $1;\n \t}\n+\n \t# match <hash>\n \tif ($line =~ oid_nlen_prefix_infix_regex($sha1_len, \"index \", \",\") |\n \t    $line =~ oid_nlen_prefix_infix_regex($sha256_len, \"index \", \",\")) {\n@@ -2388,6 +2390,12 @@ sub format_extended_diff_header_line {\n \t\tmy ($from_id, $to_id) = ($diffinfo->{'from_id'}, $diffinfo->{'to_id'});\n \t\t$line =~ s!$from_id\\.\\.$to_id!$from_link..$to_link!;\n \t}\n+\tif (defined $mode) {\n+\t\t$line .= \" $mode\" .\n+\t\t         '<span class=\"info\"> (' .\n+\t\t         file_type_long($mode) .\n+\t\t         ')</span>';\n+\t}\n \n \treturn $line . \"<br/>\\n\";\n }\n-- \n2.52.0\n\n"},{"id":"548247","messageId":"SA1PR10MB9977159B51766C2D9FFE98FD37F1F82@SA1PR10MB997715.namprd10.prod.outlook.com","threadId":"66003","inReplyTo":"SA1PR10MB997715AD62D7F2AF64EB1A9887F1F82@SA1PR10MB997715.namprd10.prod.outlook.com","subject":"[PATCH 2/2] t9502: test gitweb index hash formatting with modes","fromName":"Travor Liu","fromEmail":"travor_lzh@outlook.com","sentAt":"2026-07-15T09:11:30Z","receivedAt":"2026-07-15T09:11:56Z","isPatch":true,"body":"From: Travor Liu <travor_lzh@outlook.com>\n\ngitweb should shorten and link the object IDs in commitdiff index lines\neven when Git includes the trailing file mode:\n\n    index <old>..<new> 100644\n\nAdd coverage for that common form by rendering a commitdiff for a\nregular file modification.  Check that the visible index line contains\nlinked short blob IDs followed by the mode and file-type annotation,\nand that the full unlinked form is not emitted.\n\nSigned-off-by: Travor Liu <travor_lzh@outlook.com>\n---\n t/t9502-gitweb-standalone-parse-output.sh | 14 ++++++++++++++\n 1 file changed, 14 insertions(+)\n\ndiff --git a/t/t9502-gitweb-standalone-parse-output.sh b/t/t9502-gitweb-standalone-parse-output.sh\nindex 81d5625..7f37e26 100755\n--- a/t/t9502-gitweb-standalone-parse-output.sh\n+++ b/t/t9502-gitweb-standalone-parse-output.sh\n@@ -115,6 +115,20 @@ test_expect_success 'snapshot: hierarchical branch name (xx/test)' '\n '\n test_debug 'cat gitweb.headers'\n \n+test_expect_success 'commitdiff: index line shortens hashes with mode' '\n+\told_blob=$(git rev-parse HEAD:foo) &&\n+\told_short=$(git rev-parse --short=7 HEAD:foo) &&\n+\techo changed >foo &&\n+\tgit commit -am \"change foo\" &&\n+\tnew_blob=$(git rev-parse HEAD:foo) &&\n+\tnew_short=$(git rev-parse --short=7 HEAD:foo) &&\n+\tgitweb_run \"p=.git;a=commitdiff;h=HEAD\" &&\n+\tgrep \">${old_short}</a>\\\\.\\\\.<a [^>]*>${new_short}</a> 100644\" \\\n+\t\tgitweb.body >index_line &&\n+\tgrep \"<span class=\\\"info\\\"> (file)</span>\" index_line &&\n+\t! grep \"index ${old_blob}\\\\.\\\\.${new_blob} 100644\" gitweb.body\n+'\n+\n # ----------------------------------------------------------------------\n # forks of projects\n \n-- \n2.52.0\n\n"},{"id":"548469","messageId":"xmqqjyqu6u7i.fsf@gitster.g","threadId":"66003","inReplyTo":"SA1PR10MB9977159B51766C2D9FFE98FD37F1F82@SA1PR10MB997715.namprd10.prod.outlook.com","subject":"Re: [PATCH 2/2] t9502: test gitweb index hash formatting with modes","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-07-17T05:50:09Z","receivedAt":"2026-07-17T05:50:13Z","isPatch":true,"body":"Travor@web.codeaurora.org, \"Liu <travor_lzh\"@outlook.com writes:\n\n> From: Travor Liu <travor_lzh@outlook.com>\n>\n> gitweb should shorten and link the object IDs in commitdiff index lines\n> even when Git includes the trailing file mode:\n>\n>     index <old>..<new> 100644\n>\n> Add coverage for that common form by rendering a commitdiff for a\n> regular file modification.  Check that the visible index line contains\n> linked short blob IDs followed by the mode and file-type annotation,\n> and that the full unlinked form is not emitted.\n>\n> Signed-off-by: Travor Liu <travor_lzh@outlook.com>\n> ---\n>  t/t9502-gitweb-standalone-parse-output.sh | 14 ++++++++++++++\n>  1 file changed, 14 insertions(+)\n\nIf the new test added by this patch validates the \"fix\" in\n[PATCH 1/2], reviewing the change might be easier if the two\nwere squashed into a single patch.\n\n> diff --git a/t/t9502-gitweb-standalone-parse-output.sh b/t/t9502-gitweb-standalone-parse-output.sh\n> index 81d5625..7f37e26 100755\n> --- a/t/t9502-gitweb-standalone-parse-output.sh\n> +++ b/t/t9502-gitweb-standalone-parse-output.sh\n> @@ -115,6 +115,20 @@ test_expect_success 'snapshot: hierarchical branch name (xx/test)' '\n>  '\n>  test_debug 'cat gitweb.headers'\n>  \n> +test_expect_success 'commitdiff: index line shortens hashes with mode' '\n> +\told_blob=$(git rev-parse HEAD:foo) &&\n> +\told_short=$(git rev-parse --short=7 HEAD:foo) &&\n> +\techo changed >foo &&\n> +\tgit commit -am \"change foo\" &&\n> +\tnew_blob=$(git rev-parse HEAD:foo) &&\n> +\tnew_short=$(git rev-parse --short=7 HEAD:foo) &&\n> +\tgitweb_run \"p=.git;a=commitdiff;h=HEAD\" &&\n> +\tgrep \">${old_short}</a>\\\\.\\\\.<a [^>]*>${new_short}</a> 100644\" \\\n> +\t\tgitweb.body >index_line &&\n> +\tgrep \"<span class=\\\"info\\\"> (file)</span>\" index_line &&\n> +\t! grep \"index ${old_blob}\\\\.\\\\.${new_blob} 100644\" gitweb.body\n> +'\n\nCan we use \"test_grep\" (for positive \"this string must be there\") and\n\"test_grep !\" (for negative \"it is an error if this string appears\"\n(note that exclamation point comes after test_grep))?  It would make\nit easier to diagnose a failing test.\n\nAlso, there is a topic in flight that enforces the use of test_grep in\nthese test scripts, and use of raw grep like the above would break\nunder those stricter rules.\n\nThanks.\n\n"},{"id":"548507","messageId":"77524BE6-107A-40FB-ABD3-E5B391E7A0AF@outlook.com","threadId":"66003","inReplyTo":"xmqqjyqu6u7i.fsf@gitster.g","subject":"Re: [PATCH 2/2] t9502: test gitweb index hash formatting with modes","fromName":"Travor Liu","fromEmail":"travor_lzh@outlook.com","sentAt":"2026-07-17T13:41:20Z","receivedAt":"2026-07-17T13:41:22Z","isPatch":true,"body":"Thanks for the comments. I will squash the changes into one patch and use test_grep in v2.\n\nBest,\nTravor\n\n﻿On 2026/7/17, 1:50 PM, \"Junio C Hamano\" <gitster@pobox.com <mailto:gitster@pobox.com>> wrote:\n\n\nTravor@web.codeaurora.org <mailto:Travor@web.codeaurora.org>, \"Liu <travor_lzh\"@outlook.com writes:\n\n\n> From: Travor Liu <travor_lzh@outlook.com <mailto:travor_lzh@outlook.com>>\n>\n> gitweb should shorten and link the object IDs in commitdiff index lines\n> even when Git includes the trailing file mode:\n>\n> index <old>..<new> 100644\n>\n> Add coverage for that common form by rendering a commitdiff for a\n> regular file modification. Check that the visible index line contains\n> linked short blob IDs followed by the mode and file-type annotation,\n> and that the full unlinked form is not emitted.\n>\n> Signed-off-by: Travor Liu <travor_lzh@outlook.com <mailto:travor_lzh@outlook.com>>\n> ---\n> t/t9502-gitweb-standalone-parse-output.sh | 14 ++++++++++++++\n> 1 file changed, 14 insertions(+)\n\n\nIf the new test added by this patch validates the \"fix\" in\n[PATCH 1/2], reviewing the change might be easier if the two\nwere squashed into a single patch.\n\n\n> diff --git a/t/t9502-gitweb-standalone-parse-output.sh b/t/t9502-gitweb-standalone-parse-output.sh\n> index 81d5625..7f37e26 100755\n> --- a/t/t9502-gitweb-standalone-parse-output.sh\n> +++ b/t/t9502-gitweb-standalone-parse-output.sh\n> @@ -115,6 +115,20 @@ test_expect_success 'snapshot: hierarchical branch name (xx/test)' '\n> '\n> test_debug 'cat gitweb.headers'\n> \n> +test_expect_success 'commitdiff: index line shortens hashes with mode' '\n> + old_blob=$(git rev-parse HEAD:foo) &&\n> + old_short=$(git rev-parse --short=7 HEAD:foo) &&\n> + echo changed >foo &&\n> + git commit -am \"change foo\" &&\n> + new_blob=$(git rev-parse HEAD:foo) &&\n> + new_short=$(git rev-parse --short=7 HEAD:foo) &&\n> + gitweb_run \"p=.git;a=commitdiff;h=HEAD\" &&\n> + grep \">${old_short}</a>\\\\.\\\\.<a [^>]*>${new_short}</a> 100644\" \\\n> + gitweb.body >index_line &&\n> + grep \"<span class=\\\"info\\\"> (file)</span>\" index_line &&\n> + ! grep \"index ${old_blob}\\\\.\\\\.${new_blob} 100644\" gitweb.body\n> +'\n\n\nCan we use \"test_grep\" (for positive \"this string must be there\") and\n\"test_grep !\" (for negative \"it is an error if this string appears\"\n(note that exclamation point comes after test_grep))? It would make\nit easier to diagnose a failing test.\n\n\nAlso, there is a topic in flight that enforces the use of test_grep in\nthese test scripts, and use of raw grep like the above would break\nunder those stricter rules.\n\n\nThanks.\n\n\n\n\n\n"},{"id":"548508","messageId":"SA1PR10MB9977150C823C0751E53B150D5AF1C62@SA1PR10MB997715.namprd10.prod.outlook.com","threadId":"66003","inReplyTo":"SA1PR10MB997715AD62D7F2AF64EB1A9887F1F82@SA1PR10MB997715.namprd10.prod.outlook.com","subject":"[PATCH v2] gitweb: shorten index hashes with trailing file modes","fromName":"Travor Liu","fromEmail":"travor_lzh@outlook.com","sentAt":"2026-07-17T13:52:45Z","receivedAt":"2026-07-17T13:53:15Z","isPatch":true,"body":"From: Travor Liu <travor_lzh@outlook.com>\n\nDiff index lines have included a trailing file mode since ec1fcc16af\n(Show original and resulting blob object info in diff output,\n2005-10-07) when the old and new file modes match:\n\n    index <old>..<new> 100644\n\ngitweb recognizes that trailing mode before it tries to shorten and\nlink the object IDs.  This appends the file-type annotation first, but\nthe object-ID matcher requires the ID range to end the line.  As a\nresult, this common form keeps both full object IDs as plain text.\n\nThat is inconsistent with other hash displays and makes commitdiff\noutput wider than necessary.  Recent gitweb changes have fixed mobile\noverflow in log, commit, blob and diff views; leaving two full object\nIDs in this header preserves an avoidable long line in the diff header.\n\n* gitweb/gitweb.perl: Remove the trailing mode before matching the index\nIDs, then append it again after the IDs have been shortened and linked.\nThis preserves the mode display while letting ordinary and combined\nindex lines use the existing object-ID formatting paths.\n\n* t/t9502-gitweb-standalone-parse-output.sh: Add coverage for that\ncommon form by rendering a commitdiff for a regular file modification.\nCheck that the visible index line contains linked short blob IDs\nfollowed by the mode and file-type annotation, and that the full\nunlinked form is not emitted.\n\nSigned-off-by: Travor Liu <travor_lzh@outlook.com>\n---\nChanges since v1:\n- Squashed the regression test into the implementation patch.\n- Replaced raw grep invocations with test_grep.\n\n gitweb/gitweb.perl                        | 18 +++++++++++++-----\n t/t9502-gitweb-standalone-parse-output.sh | 13 +++++++++++++\n 2 files changed, 26 insertions(+), 5 deletions(-)\n\ndiff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl\nindex fde8045..8c2d9b8 100755\n--- a/gitweb/gitweb.perl\n+++ b/gitweb/gitweb.perl\n@@ -2339,12 +2339,14 @@ sub format_extended_diff_header_line {\n \t\t$line .= $cgi->a({-href=>$to->{'href'}, -class=>\"path\"},\n \t\t                 esc_path($to->{'file'}));\n \t}\n-\t# match single <mode>\n-\tif ($line =~ m/\\s(\\d{6})$/) {\n-\t\t$line .= '<span class=\"info\"> (' .\n-\t\t         file_type_long($1) .\n-\t\t         ')</span>';\n+\n+\t# Temporarily remove a trailing <mode> so an index line ends with its\n+\t# object IDs and can be shortened below.\n+\tmy $mode;\n+\tif ($line =~ s/\\s(\\d{6})$//) {\n+\t\t$mode = $1;\n \t}\n+\n \t# match <hash>\n \tif ($line =~ oid_nlen_prefix_infix_regex($sha1_len, \"index \", \",\") |\n \t    $line =~ oid_nlen_prefix_infix_regex($sha256_len, \"index \", \",\")) {\n@@ -2388,6 +2390,12 @@ sub format_extended_diff_header_line {\n \t\tmy ($from_id, $to_id) = ($diffinfo->{'from_id'}, $diffinfo->{'to_id'});\n \t\t$line =~ s!$from_id\\.\\.$to_id!$from_link..$to_link!;\n \t}\n+\tif (defined $mode) {\n+\t\t$line .= \" $mode\" .\n+\t\t         '<span class=\"info\"> (' .\n+\t\t         file_type_long($mode) .\n+\t\t         ')</span>';\n+\t}\n \n \treturn $line . \"<br/>\\n\";\n }\ndiff --git a/t/t9502-gitweb-standalone-parse-output.sh b/t/t9502-gitweb-standalone-parse-output.sh\nindex 81d5625..85f7716 100755\n--- a/t/t9502-gitweb-standalone-parse-output.sh\n+++ b/t/t9502-gitweb-standalone-parse-output.sh\n@@ -115,6 +115,19 @@ test_expect_success 'snapshot: hierarchical branch name (xx/test)' '\n '\n test_debug 'cat gitweb.headers'\n \n+test_expect_success 'commitdiff: index line shortens hashes with mode' '\n+\told_blob=$(git rev-parse HEAD:foo) &&\n+\told_short=$(git rev-parse --short=7 HEAD:foo) &&\n+\techo changed >foo &&\n+\tgit commit -am \"change foo\" &&\n+\tnew_blob=$(git rev-parse HEAD:foo) &&\n+\tnew_short=$(git rev-parse --short=7 HEAD:foo) &&\n+\tgitweb_run \"p=.git;a=commitdiff;h=HEAD\" &&\n+\ttest_grep \">${old_short}</a>\\\\.\\\\.<a [^>]*>${new_short}</a> 100644<span class=\\\"info\\\"> (file)</span>\" \\\n+\t\tgitweb.body &&\n+\ttest_grep ! \"index ${old_blob}\\\\.\\\\.${new_blob} 100644\" gitweb.body\n+'\n+\n # ----------------------------------------------------------------------\n # forks of projects\n \n-- \n2.52.0\n\n"}]}