Summary:
We currently detect the "\" as a change, and may generate a hunk like this, without changes.
@@ -97,4 +98,4 @@
mmm
mmm
mmm
\ No newline at end of file
While "git apply" is OK with this, "patch" is not. Instead, don't detect this as a change (it is always accompanied by - / + if it's a real change).
Test Plan: Successfully applied a previously-failing SVN patch to a file without a terminal newline that had nonlocal changes.
Reviewers: 20after4, nh, btrahan
Reviewed By: 20after4
CC: aran, epriestley
Differential Revision: https://secure.phabricator.com/D1934
$ii = 0;
$jj = 0;
while ($ii < $n) {
- for ($jj = $ii; $jj < $n && $lines[$jj][0] == ' '; ++$jj) {
- // Skip lines until we find the first line with changes.
+ // Skip lines until we find the next line with changes. Note: this skips
+ // both ' ' (no changes) and '\' (no newline at end of file) lines. If we
+ // don't skip the latter, we may incorrectly generate a terminal hunk
+ // that has no actual change information when a file doesn't have a
+ // terminal newline and not changed near the end of the file. 'patch' will
+ // fail to apply the diff if we generate a hunk that does not actually
+ // contain changes.
+ for ($jj = $ii; $jj < $n; ++$jj) {
+ $char = $lines[$jj][0];
+ if ($char == '-' || $char == '+') {
+ break;
+ }
}
if ($jj >= $n) {
break;
<?php
/*
- * Copyright 2011 Facebook, Inc.
+ * Copyright 2012 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
'disjoint-hunks.new')->toUnifiedDiff());
}
-
-
+ public function testNonlocalTrailingNewline() {
+ // Diffs without changes near the end of the file should not generate a
+ // bogus, change-free hunk if the file has no trailing newline.
+ $this->assertEqual(
+ $this->loadResource('trailing-newline.diff'),
+ $this->loadOneChangeBundle(
+ 'trailing-newline.old',
+ 'trailing-newline.new')->toUnifiedDiff());
+ }
}
--- /dev/null
+Index: file
+===================================================================
+--- file
++++ file
+@@ -3,7 +3,7 @@
+ c
+ d
+ e
+-f
++QUACK
+ g
+ h
+ i
--- /dev/null
+a
+b
+c
+d
+e
+QUACK
+g
+h
+i
+j
+k
+l
+m
+n
+o
+p
+q
+r
+s
+t
+u
+v
+w
+x
+y
+z
\ No newline at end of file
--- /dev/null
+a
+b
+c
+d
+e
+f
+g
+h
+i
+j
+k
+l
+m
+n
+o
+p
+q
+r
+s
+t
+u
+v
+w
+x
+y
+z
\ No newline at end of file