{"thread":{"id":"66358","subject":"Bugreport: git log -L","startedAt":"2026-09-21T07:45:24Z","lastAt":"2026-09-21T18:30:25Z","messageCount":4,"participants":["Nikita Makarov","Kristofer Karlsson","Johannes Sixt","Tim Tassonis"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"552923","messageId":"41c54b809eb1490fb467ba0fd4c5a8cf@yadro.com","threadId":"66358","inReplyTo":null,"subject":"Bugreport: git log -L","fromName":"Nikita Makarov","fromEmail":"n.makarov@yadro.com","sentAt":"2026-09-21T07:45:15Z","receivedAt":"2026-09-21T07:45:24Z","isPatch":false,"body":"Hello, I have the found the strange behavior of \"git log -L\" command with python function.\nIt is counting a blank line that sits after a function's last statement as part of that function.\nThis happens only when the function is at the end of a file. \n\nThe way to reproduce that\n\ngit init repro && cd repro\ngit config user.email t@t && git config user.name t\n\nprintf 'def foo():\\n    return 1\\n\\n' > bug.py\ngit add bug.py && git commit -qm c1\n\nprintf 'def foo():\\n    return 1\\n' > bug.py\ngit add bug.py && git commit -qm c2\n\nThen do\n\ngit log -L :'foo':bug.py\n\nAnd you'll see\n\nAuthor: t <t@t>\nDate:   Fri Sep 18 18:21:10 2026 +0300\n\n    c2\n\ndiff --git a/bug.py b/bug.py\n--- a/bug.py\n+++ b/bug.py\n@@ -1,2 +1,3 @@\n def foo():\n     return 1\n+\n\nThough I expect that commit \"c2\" should never appear in log, since the changes from it doesn't affect the functions body at all. \n\n[System Info]\ngit version:\ngit version 2.43.0\ncpu: x86_64\nno commit associated with this build\nsizeof-long: 8\nsizeof-size_t: 8\nshell-path: /bin/sh\nuname: Linux 7.0.0-31-generic #31~24.04.1-Ubuntu SMP PREEMPT_DYNAMIC Mon Aug 10 09:38:02 UTC 2 x86_64\ncompiler info: gnuc: 13.3\nlibc info: glibc: 2.39\n$SHELL (typically, interactive shell): /bin/bash\n\n\n[Enabled Hooks]"},{"id":"552924","messageId":"CAL71e4Nw+-bmc0sCOC+L9VyxYG6MwRf-XbXDDWO1grOH=WbEOw@mail.gmail.com","threadId":"66358","inReplyTo":"41c54b809eb1490fb467ba0fd4c5a8cf@yadro.com","subject":"Re: Bugreport: git log -L","fromName":"Kristofer Karlsson","fromEmail":"krka@spotify.com","sentAt":"2026-09-21T09:49:33Z","receivedAt":"2026-09-21T09:49:46Z","isPatch":false,"body":"On Mon, 21 Sept 2026 at 09:49, Nikita Makarov <n.makarov@yadro.com> wrote:\n>\n> Hello, I have the found the strange behavior of \"git log -L\" command with python function.\n> It is counting a blank line that sits after a function's last statement as part of that function.\n> This happens only when the function is at the end of a file.\n>\n> The way to reproduce that\n>\n> git init repro && cd repro\n> git config user.email t@t && git config user.name t\n>\n> printf 'def foo():\\n    return 1\\n\\n' > bug.py\n> git add bug.py && git commit -qm c1\n>\n> printf 'def foo():\\n    return 1\\n' > bug.py\n> git add bug.py && git commit -qm c2\n>\n> Then do\n>\n> git log -L :'foo':bug.py\n>\n> And you'll see\n>\n> Author: t <t@t>\n> Date:   Fri Sep 18 18:21:10 2026 +0300\n>\n>     c2\n>\n> diff --git a/bug.py b/bug.py\n> --- a/bug.py\n> +++ b/bug.py\n> @@ -1,2 +1,3 @@\n>  def foo():\n>      return 1\n> +\n>\n> Though I expect that commit \"c2\" should never appear in log, since the changes from it doesn't affect the functions body at all.\n\nI tried to reproduce this but failed to do so. I first started\nwondering if this meant the bug had been fixed in master already,\nbut then I also failed to reproduce it on 2.43.\n\nI think the reproduction steps were wrong here, perhaps\nyou meant to put the double newline in c2 instead of in c1?\nBecause if I change that, I can reproduce it.\n\nSo the steps should have:\n\n    printf 'def foo():\\n    return 1\\n' > bug.py\n    git add bug.py && git commit -qm c1\n\n    printf 'def foo():\\n    return 1\\n\\n' > bug.py\n    git add bug.py && git commit -qm c2\n\ninstead.\n\nI think I should be able to submit a fix for this shortly.\n\nThanks,\nKristofer\n"},{"id":"552937","messageId":"4c88bb3c-4005-41bc-8ff5-9b8597aa05eb@kdbg.org","threadId":"66358","inReplyTo":"41c54b809eb1490fb467ba0fd4c5a8cf@yadro.com","subject":"Re: Bugreport: git log -L","fromName":"Johannes Sixt","fromEmail":"j6t@kdbg.org","sentAt":"2026-09-21T16:40:11Z","receivedAt":"2026-09-21T16:41:22Z","isPatch":false,"body":"Am 21.09.26 um 09:45 schrieb Nikita Makarov:\n> Hello, I have the found the strange behavior of \"git log -L\" command\n> with python function. It is counting a blank line that sits after a\n> function's last statement as part of that function. This happens\n> only when the function is at the end of a file.\n(No, it happens all the time, not just at the end of the file.)\n\n> Though I expect that commit \"c2\" should never appear in log, since\n> the changes from it doesn't affect the functions body at all.\nMost likely, Git has successfully kept up the illusion that it knows\nwhat \"a function\" is in your programming language, because you have\nfrequently seen function names in hunk headers.\n\nBut the truth is, Git doesn't know. For the purpose of `git log -L\n:function_name:file`, Git uses the same pattern as for the hunk headers\nto determine function boundaries. In particular, a function ends right\nbefore the next function begins (if there is one). By this metric, any\nblank lines (and comments!) before the next function count to the\nprevious function.\n\nSo, what you are seeing here is to be expected for the lack of a better\nnotion of what \"a function\" is.\n\nIf we are to improve on this, then a more serious problem to fix is that\ncomments above a function do not count to the function that they\ndocument, but to the previous function.\n\n-- Hannes\n\n"},{"id":"552946","messageId":"b6600538-afdd-4402-ad2c-2a5380b6c0cd@decentral.ch","threadId":"66358","inReplyTo":"41c54b809eb1490fb467ba0fd4c5a8cf@yadro.com","subject":"Re: Bugreport: git log -L","fromName":"Tim Tassonis","fromEmail":"stuff@decentral.ch","sentAt":"2026-09-21T18:04:45Z","receivedAt":"2026-09-21T18:30:25Z","isPatch":false,"body":"\n\nOn 9/21/26 09:45, Nikita Makarov wrote:\n> Hello, I have the found the strange behavior of \"git log -L\" command with python function.\n> It is counting a blank line that sits after a function's last statement as part of that function.\n> This happens only when the function is at the end of a file.\n> \n> The way to reproduce that\n> \n> git init repro && cd repro\n> git config user.email t@t && git config user.name t\n> \n> printf 'def foo():\\n    return 1\\n\\n' > bug.py\n> git add bug.py && git commit -qm c1\n> \n> printf 'def foo():\\n    return 1\\n' > bug.py\n> git add bug.py && git commit -qm c2\n> \n> Then do\n> \n> git log -L :'foo':bug.py\n> \n> And you'll see\n> \n> Author: t <t@t>\n> Date:   Fri Sep 18 18:21:10 2026 +0300\n> \n>      c2\n> \n> diff --git a/bug.py b/bug.py\n> --- a/bug.py\n> +++ b/bug.py\n> @@ -1,2 +1,3 @@\n>   def foo():\n>       return 1\n> +\n> \n> Though I expect that commit \"c2\" should never appear in log, since the changes from it doesn't affect the functions body at all.\n\n From git log --help\n...\nIf :<funcname> is given in place of <start> and <end>, it is a\nregular expression that denotes the range from the first funcname\nline that matches <funcname>, up to the next funcname line.\n:<funcname> searches from the end of the previous -L range, if any,\notherwise from the start of file.  ^:<funcname> searches from the\nstart of file. The function names are determined in the same way as\ngit diff works out patch hunk headers (see Defining a custom\nhunk-header in gitattributes(5)).\n..\n\nSo, the bug is rather the expectation that such a thing can reliably \nknow what a function is, regardless of coding style and language used.\n\nTo quote the late and great Christopher Tolkien: This could only be \nachieved. if at all, at heavy and needless cost.\n\nBye>\n> [System Info]\n> git version:\n> git version 2.43.0\n> cpu: x86_64\n> no commit associated with this build\n> sizeof-long: 8\n> sizeof-size_t: 8\n> shell-path: /bin/sh\n> uname: Linux 7.0.0-31-generic #31~24.04.1-Ubuntu SMP PREEMPT_DYNAMIC Mon Aug 10 09:38:02 UTC 2 x86_64\n> compiler info: gnuc: 13.3\n> libc info: glibc: 2.39\n> $SHELL (typically, interactive shell): /bin/bash\n> \n> \n> [Enabled Hooks]\n\n-- \ndecentral.ch - IT Stuff\nTim Tassonis\nBadenerstrasse 219\n8003 Zürich\nstuff@decentral.ch\n+41 79 229 36 17\n\n"}]}