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

Re: [PATCH 2/9] Fix detection of files with only one line in git-apply.

From
Linus Torvalds <torvalds@osdl.org>
Date
Aug 28, 2005, 16:55 UTC
Message-ID
<Pine.LNX.4.58.0508280946180.3317@g5.osdl.org>
In-Reply-To
<1125242667404-git-send-email-robfitz@273k.net>
On Sun, 28 Aug 2005, Robert Fitzsimons wrote:
>
> A patch which added one line to an empty file or removed the only line
> from a one line file would be incorrectly detected as an invalid new
> or delete patch.  Added a new test case.

This patch looks wrong or at least needs some more thought. The test was done the way it was done for a reason. For example:

	if (patch->is_new != !oldlines)
		return error("new file depends on old contents");

actually has two error cases (admittedly it re-uses the same error message for both, which is a bit confusing):

 - is_new, and oldlines != 0
	This is the obvious error, and the one the message talk about.
 - !is_new, and oldlines == 0
	In kernel usage, empty files are not legal, and empty files get 
	deleted. So this actually was intentional, even if the error 
	message ends up being less than perfect.

The "is_delete" thing is the same. At least for the kernel, I want a patch that removes all content to also always _delete_ the file, because otherwise old-style patches are ambiguous. Is it a delete, or is it a "leave an empty file"?

Now, git patches aren't ambigious, so while git patches can clearly say "this is a patch to an existing empty file" vs "this patch creates this file", I wanted to have the behaviour where we maintain the principle that empty files are wrong.

Now, that's a kernel-specific thing, so it may be that enabling this behaviour this should be a command line flag, but the point is that I don't want to entirely lose the test.

		Linus
Previous: Robert FitzsimonsNext: Junio C Hamano
Message 3 of 11 in “Fix git patch header processing in git-apply.”
  1. 1/9 Fix git patch header processing in git-apply.Robert Fitzsimons, Aug 28, 2005
  2. 2/9 Fix detection of files with only one line in git-apply.Robert Fitzsimons, Aug 28, 2005
  3. Linus TorvaldsAug 28, 2005
  4. Junio C HamanoAug 28, 2005
  5. Robert FitzsimonsAug 29, 2005
  6. Linus TorvaldsAug 30, 2005
  7. Junio C HamanoAug 30, 2005
  8. Linus TorvaldsAug 30, 2005
  9. Junio C HamanoAug 30, 2005
  10. Linus TorvaldsAug 30, 2005
  11. Martin LanghoffAug 30, 2005

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.