git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Parsing diff --git lines

From
Jakub Narebski <jnareb@gmail.com>
Date
Mar 9, 2008, 08:25 UTC
Message-ID
<m3r6ekfgnw.fsf@localhost.localdomain>
In-Reply-To
<alpine.LFD.1.00.0803081955110.5896@woody.linux-foundation.org>
Linus Torvalds <torvalds@linux-foundation.org> writes:
Show 16 quoted lines
> On Sat, 8 Mar 2008, Simon Fraser wrote:
> > 
> > However, I don't see a reliable way to identify the two files
> > from a "diff --git" line. Here's a (deliberately pathological)
> > example:
> 
> See how "git-apply" does it.
> 
> The rule is:
> 
>  - if the filenames are different, you should ignore the filenames on the 
>    "diff --git" line, and trust the ones on the "renamed from/to" ones 
>    (which are unambiguous because they only have one filename per line)
> 
>  - if the filenames aren't different, then you can unambiguously know how 
>    to parse it by simply making sure they are the same.

By the way, the default pre-commit hook behaves a bit strangely on files which contain spaces[*1*] in filename (due to GNU-diff-uism):

*
* You have some suspicious patch lines:
*
* In  b
* trailing whitespace (line 1)
 b:1:++ b/ b	
Foootnote:
==========
[*1*] If file has '"', '\' or control character in filename,
      it is quoted. 
-- 
Jakub Narebski
Poland
ShadeHawk on #git
Previous: Linus TorvaldsNext: Johannes Schindelin
Message 3 of 4 in “Parsing diff --git lines”
  1. Simon FraserMar 9, 2008
  2. Linus TorvaldsMar 9, 2008
  3. Jakub NarebskiMar 9, 2008
  4. Johannes SchindelinMar 9, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.