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

[PATCH] Make git-apply understand "\ No newline at end of file" in non-english locales

From
Fredrik Kuivinen <freku045@student.liu.se>
Date
Sep 4, 2005, 17:29 UTC
Message-ID
<20050904172901.GA20574@c165.ib.student.liu.se>

The message "\ No newline at end of file" which sometimes is produced by diff(1) is locale dependent. We can't assume more than that it begins with "\ ".

Signed-off-by: Fredrik Kuivinen <freku045@student.liu.se>
---

For example, given two files, "foo" and "bar", with appropriate contents 'diff -u foo bar' will produce the following output on my system.

--- foo 2005-09-04 18:59:38.000000000 +0200 +++ bar 2005-09-04 18:59:16.000000000 +0200

@@ -1 +1 @@
-foobar
+foo
\ Ingen nyrad vid filslut


 apply.c |   10 +++++++---
 1 files changed, 7 insertions(+), 3 deletions(-)

18d17c911a200c9d45414af403a145c7ac4f9317
diff --git a/apply.c b/apply.c
--- a/apply.c
+++ b/apply.c
@@ -672,9 +672,13 @@ static int parse_fragment(char *line, un
 			added++;
 			newlines--;
 			break;
-		/* We allow "\ No newline at end of file" */
+
+                /* We allow "\ No newline at end of file". Depending
+                 * on locale settings when the patch was produced we
+                 * don't know what this line looks like. The only
+                 * thing we do know is that it begins with "\ ". */
 		case '\\':
-			if (len < 12 || memcmp(line, "\\ No newline", 12))
+			if (len < 12 || memcmp(line, "\\ ", 2))
 				return -1;
 			break;
 		}
@@ -683,7 +687,7 @@ static int parse_fragment(char *line, un
 	 * it in the above loop because we hit oldlines == newlines == 0
 	 * before seeing it.
 	 */
-	if (12 < size && !memcmp(line, "\\ No newline", 12))
+	if (12 < size && !memcmp(line, "\\ ", 2))
 		offset += linelen(line, size);
 
 	patch->lines_added += added;
Next: Fredrik Kuivinen
Message 1 of 4 in “Make git-apply understand "\ No newline at end of file" in non-english locales”
  1. Make git-apply understand "\ No newline at end of file" in non-english localesFredrik Kuivinen, Sep 4, 2005
  2. Fredrik KuivinenSep 4, 2005
  3. Junio C HamanoSep 4, 2005
  4. Fredrik KuivinenSep 5, 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.