{"thread":{"id":"66834","subject":"git context diff does not recognize shell function name","startedAt":"2026-11-12T13:39:58Z","lastAt":"2026-11-14T08:49:42Z","messageCount":4,"participants":["Windl, Ulrich","Junio C Hamano","Johannes Sixt"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"558292","messageId":"340dc2eef42f4f6690c58765a07621e1@ukr.de","threadId":"66834","inReplyTo":null,"subject":"git context diff does not recognize shell function name","fromName":"Windl, Ulrich","fromEmail":"u.windl@ukr.de","sentAt":"2026-11-12T13:39:58Z","receivedAt":"2026-11-12T13:39:58Z","isPatch":false,"sender":{"key":"u.windl@ukr.de","avatar":null},"body":"Hi!\n\nIn git 2.51.0 I found a minor issue:\n\"git diff\" did not show the corresponding shell function name. Admittedly I used a somewhat uncommon line-breaking:\n\nThe context in question looks like this:\n---\n...\nrun_query()\n{\n    local p_l_0=\"$1\" LOG_BASE=\"$2\" SUFFIX=\"$3\" URL_BASE=\"$4\" URL=\"$5\" \\\n_COUNT=\"${6:-$COUNT}\" RESPONSE_CHECKER=\"$7\"\n    local me=\"${FUNCNAME[0]}\" m\n...\n---\n\nThe context diff looked like this:\n---\n...\n@@ -193,6 +188,36 @@ get_params()\n... \nrun_query()\n {\n@@ -201,10 +226,9 @@ _COUNT=\"${6:-$COUNT}\" RESPONSE_CHECKER=\"$7\"\n     local me=\"${FUNCNAME[0]}\" m\n...\n---\n(\"...\" is deleted lines)\nSo this may be a combination of unfortunate context sequencing and the first line of the new context being unusual.\nThe second chunk would still be the same context, namely \"run_query()\".\n\nKind regards,\nUlrich Windl\n\n"},{"id":"558344","messageId":"xmqqmrrdhiye.fsf@gitster.g","threadId":"66834","inReplyTo":"340dc2eef42f4f6690c58765a07621e1@ukr.de","subject":"Re: git context diff does not recognize shell function name","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-11-12T20:51:21Z","receivedAt":"2026-11-12T20:51:21Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Windl, Ulrich\" <u.windl@ukr.de> writes:\n\n> Hi!\n>\n> In git 2.51.0 I found a minor issue:\n\nThat is a release from more than a year ago, but I do not think we\nhad any change to userdiff (i.e., built-in patterns that define what\nline is the function header for various languages) since then (we\nadded Swift and tweaked scheme).  So for practical purposes, I would\nexpect that whatever you saw in Git 2.51 for shell to be reproducible\nin today's code.\n\nOr are you reporting that Git 2.50 (or something older than 2.51)\nbehaved in a way you prefer, and 2.51 behaves differently?\n\n> \"git diff\" did not show the corresponding shell function\n> name. Admittedly I used a somewhat uncommon line-breaking:\n>\n> The context in question looks like this:\n> ---\n> ...\n> run_query()\n> {\n>     local p_l_0=\"$1\" LOG_BASE=\"$2\" SUFFIX=\"$3\" URL_BASE=\"$4\" URL=\"$5\" \\\n> _COUNT=\"${6:-$COUNT}\" RESPONSE_CHECKER=\"$7\"\n>     local me=\"${FUNCNAME[0]}\" m\n> ...\n> ---\n>\n> The context diff looked like this:\n> ---\n> ...\n> @@ -193,6 +188,36 @@ get_params()\n> ... \n> run_query()\n>  {\n\nI assume that your e-mail message is whitespace damaged and\nrun_query() is actually indented by one space, being a context line\ntogether with the opening brace next line?  The header stating\nget_params() is expected, as the \"function name\" do not lookahead to\nfind run_query() in the hunk it is going to show.\n\n> @@ -201,10 +226,9 @@ _COUNT=\"${6:-$COUNT}\" RESPONSE_CHECKER=\"$7\"\n\nIt is not that the line that begins run_query()'s definition does\nnot look like a beginning of a function.  It is that this _COUNT=\nline does look like a beginning of a new thing, and because it comes\nafter the start of run_query().\n\nThe name of the file would affect which set of regular expressions\nare used to sift lines into function headers and other lines.  When\nthe file has no known suffix with language specific rules defined, I\nthink we just pick any line that begins with a non-whitespace\ncharacter, which explains why the line that begins with\n_COUNT=... overrides the line that begins with run_query() which\nwould have been a candidate as another and later candidate.\n\n>      local me=\"${FUNCNAME[0]}\" m\n> ...\n> ---\n> (\"...\" is deleted lines)\n> So this may be a combination of unfortunate context sequencing and\n> the first line of the new context being unusual.  The second chunk\n> would still be the same context, namely \"run_query()\".\n\n\n"},{"id":"558370","messageId":"69690c3bd37448ff8116bf3497f151a9@ukr.de","threadId":"66834","inReplyTo":"xmqqmrrdhiye.fsf@gitster.g","subject":"RE: [EXT] Re: git context diff does not recognize shell function name","fromName":"Windl, Ulrich","fromEmail":"u.windl@ukr.de","sentAt":"2026-11-13T07:09:33Z","receivedAt":"2026-11-13T07:09:33Z","isPatch":false,"sender":{"key":"u.windl@ukr.de","avatar":null},"body":"Hi!\n\nThanks for the comments. I have to use Outlook (Classic), so I cannot do much about the bugs it has, sorry for both of us.\nThe file name ends in \".sh\", and there's also a \"she-bang\" at the start saying it's a BASH script.\n\nFor \"_COUNT=\"${6:-$COUNT}\" RESPONSE_CHECKER=\"$7\"\" looking like the start of a function: I think the essential thing is that the line before ends with a backslash, so it's rather unlikely that this line starts any new definition.\n\nKind regards,\nUlrich Windl\n\n> -----Original Message-----\n> From: Junio C Hamano <gitster@pobox.com>\n> Sent: Thursday, November 12, 2026 9:51 PM\n> To: Windl, Ulrich <u.windl@ukr.de>\n> Cc: git@vger.kernel.org\n> Subject: [EXT] Re: git context diff does not recognize shell function name\n> \n> Sicherheits-Hinweis: Diese E-Mail wurde von einer Person außerhalb des UKR\n> gesendet. Seien Sie vorsichtig vor gefälschten Absendern, wenn Sie auf Links\n> klicken, Anhänge öffnen oder weitere Aktionen ausführen, bevor Sie die\n> Echtheit überprüft haben.\n> \n> \"Windl, Ulrich\" <u.windl@ukr.de> writes:\n> \n> > Hi!\n> >\n> > In git 2.51.0 I found a minor issue:\n> \n> That is a release from more than a year ago, but I do not think we\n> had any change to userdiff (i.e., built-in patterns that define what\n> line is the function header for various languages) since then (we\n> added Swift and tweaked scheme).  So for practical purposes, I would\n> expect that whatever you saw in Git 2.51 for shell to be reproducible\n> in today's code.\n> \n> Or are you reporting that Git 2.50 (or something older than 2.51)\n> behaved in a way you prefer, and 2.51 behaves differently?\n> \n> > \"git diff\" did not show the corresponding shell function\n> > name. Admittedly I used a somewhat uncommon line-breaking:\n> >\n> > The context in question looks like this:\n> > ---\n> > ...\n> > run_query()\n> > {\n> >     local p_l_0=\"$1\" LOG_BASE=\"$2\" SUFFIX=\"$3\" URL_BASE=\"$4\" URL=\"$5\"\n> \\\n> > _COUNT=\"${6:-$COUNT}\" RESPONSE_CHECKER=\"$7\"\n> >     local me=\"${FUNCNAME[0]}\" m\n> > ...\n> > ---\n> >\n> > The context diff looked like this:\n> > ---\n> > ...\n> > @@ -193,6 +188,36 @@ get_params()\n> > ...\n> > run_query()\n> >  {\n> \n> I assume that your e-mail message is whitespace damaged and\n> run_query() is actually indented by one space, being a context line\n> together with the opening brace next line?  The header stating\n> get_params() is expected, as the \"function name\" do not lookahead to\n> find run_query() in the hunk it is going to show.\n> \n> > @@ -201,10 +226,9 @@ _COUNT=\"${6:-$COUNT}\"\n> RESPONSE_CHECKER=\"$7\"\n> \n> It is not that the line that begins run_query()'s definition does\n> not look like a beginning of a function.  It is that this _COUNT=\n> line does look like a beginning of a new thing, and because it comes\n> after the start of run_query().\n> \n> The name of the file would affect which set of regular expressions\n> are used to sift lines into function headers and other lines.  When\n> the file has no known suffix with language specific rules defined, I\n> think we just pick any line that begins with a non-whitespace\n> character, which explains why the line that begins with\n> _COUNT=... overrides the line that begins with run_query() which\n> would have been a candidate as another and later candidate.\n> \n> >      local me=\"${FUNCNAME[0]}\" m\n> > ...\n> > ---\n> > (\"...\" is deleted lines)\n> > So this may be a combination of unfortunate context sequencing and\n> > the first line of the new context being unusual.  The second chunk\n> > would still be the same context, namely \"run_query()\".\n\n"},{"id":"558447","messageId":"080eb4e7-2885-4057-b063-2f114b99b883@kdbg.org","threadId":"66834","inReplyTo":"69690c3bd37448ff8116bf3497f151a9@ukr.de","subject":"Re: [EXT] Re: git context diff does not recognize shell function name","fromName":"Johannes Sixt","fromEmail":"j6t@kdbg.org","sentAt":"2026-11-14T08:49:42Z","receivedAt":"2026-11-14T08:49:42Z","isPatch":false,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Am 13.11.26 um 08:09 schrieb Windl, Ulrich:\n> The file\n> name ends in \".sh\", and there's also a \"she-bang\" at the start\n> saying it's a BASH script.\nGit does not activate diff drivers automatically for any type of file\n(AFAIR), so all of these properties are ignored. You have to activate\nthe diff driver yourself, for example, by putting a line like\n\n*.sh diff=bash\n\nin your .git/info/attributes or a .gitattributes. Without this, the\ndefault hunk header pattern is used, which picks up lines that begin\nwith a non-punctuation character.\n\n-- Hannes\n\n\n"}]}