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

4 messages from 2005-09-04 to 2005-09-05. Participants: Fredrik Kuivinen, Junio C Hamano.
Thread: https://gitlist.dev/t/1725

## Fredrik Kuivinen, 2005-09-04 17:29

Subject: [PATCH] Make git-apply understand "\ No newline at end of file" in non-english locales
Message-ID: <20050904172901.GA20574@c165.ib.student.liu.se>
URL: https://gitlist.dev/e/20050904172901.GA20574%40c165.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;

```

## Fredrik Kuivinen, 2005-09-04 18:46

Subject: Re: [PATCH] Make git-apply understand "\ No newline at end of file" in non-english locales
Message-ID: <20050904184625.GB23525@c165.ib.student.liu.se>
URL: https://gitlist.dev/e/20050904184625.GB23525%40c165.ib.student.liu.se
In-Reply-To: <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 <freku@ida.liu.se>
---

The previous patch wasn't doing the right thing. Hopefully I have
managed to get it right this time.


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

b94e5e845c241fff14334001aa5d418d22cd115e
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 < 2 || line[1] != ' ')
 				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 (2 < size && !memcmp(line, "\\ ", 2))
 		offset += linelen(line, size);
 
 	patch->lines_added += added;

```

## Junio C Hamano, 2005-09-04 19:25

Subject: Re: [PATCH] Make git-apply understand "\ No newline at end of file" in non-english locales
Message-ID: <7vd5noeiub.fsf@assigned-by-dhcp.cox.net>
URL: https://gitlist.dev/e/7vd5noeiub.fsf%40assigned-by-dhcp.cox.net
In-Reply-To: <20050904184625.GB23525@c165.ib.student.liu.se>

```
Fredrik Kuivinen <freku045@student.liu.se> writes:

> 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 <freku@ida.liu.se>
> ---
>
> The previous patch wasn't doing the right thing. Hopefully I have
> managed to get it right this time.

I noticed that you left 12 in the previous patch, and thought it
was a sane safety measure to make sure that the incomplete line
marker is of reasonably length, not just any line that starts
with '\ ' (i.e. "\ foobar\n", which is a tad short).

```

## Fredrik Kuivinen, 2005-09-05 05:25

Subject: Re: [PATCH] Make git-apply understand "\ No newline at end of file" in non-english locales
Message-ID: <20050905052549.GA1875@c165.ib.student.liu.se>
URL: https://gitlist.dev/e/20050905052549.GA1875%40c165.ib.student.liu.se
In-Reply-To: <7vd5noeiub.fsf@assigned-by-dhcp.cox.net>

```
On Sun, Sep 04, 2005 at 12:25:16PM -0700, Junio C Hamano wrote:
> Fredrik Kuivinen <freku045@student.liu.se> writes:
> 
> > 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 <freku@ida.liu.se>
> > ---
> >
> > The previous patch wasn't doing the right thing. Hopefully I have
> > managed to get it right this time.
> 
> I noticed that you left 12 in the previous patch, and thought it
> was a sane safety measure to make sure that the incomplete line
> marker is of reasonably length, not just any line that starts
> with '\ ' (i.e. "\ foobar\n", which is a tad short).
> 

Maybe the first patch wasn't that bad after all :)

In the current diffutils package the Swedish translation is one of the
shortest ones, so 12 is ok for now at least.

- Fredrik

```
