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

Parsing diff --git lines

From
SFSimon Fraser <smfr@mac.com>
Date
Mar 9, 2008, 01:48 UTC
Message-ID
<F4D3B820-CCF4-4212-BF32-700EFD448143@mac.com>

I'm working on a GUI for git, and I'd like to be able to provide some diff navigation tools. That requires that I can find the file chunks in a diff, and parse out the file names.

However, I don't see a reliable way to identify the two files from a "diff --git" line. Here's a (deliberately pathological) example:

diff --git a/a / b/file with spaces.txt b/a / b/file with spaces.txt

In this case, the repository contains directories called "a " and
" b" and the file names have spaces in.

What would make this possible would be either to always quote
file paths containing spaces, or use a character other than
a space (e.g. a \t) between the two file names.

Thanks
Simon
Next: Linus Torvalds
Message 1 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.