Fossil SCM

Fix diffs from or to an empty file to use the special position marker 0,0. Makes "fossil diff -N" create patches that are accepted by patch.

joerg 2011-03-08 22:13 trunk
Commit 4e77507e70d0a467c49c88c1b22a0c46bee44bc8
1 file changed +8 -1
+8 -1
--- src/diff.c
+++ src/diff.c
@@ -235,11 +235,18 @@
235235
}
236236
for(i=1; i<nr; i++){
237237
na += R[r+i*3];
238238
nb += R[r+i*3];
239239
}
240
- blob_appendf(pOut,"@@ -%d,%d +%d,%d @@\n", a+skip+1, na, b+skip+1, nb);
240
+ /*
241
+ * If the patch changes an empty file or results in an empty file,
242
+ * the block header must use 0,0 as position indicator and not 1,0.
243
+ * Otherwise, patch would be confused and may reject the diff.
244
+ */
245
+ blob_appendf(pOut,"@@ -%d,%d +%d,%d @@\n",
246
+ na ? a+skip+1 : 0, na,
247
+ nb ? b+skip+1 : 0, nb);
241248
242249
/* Show the initial common area */
243250
a += skip;
244251
b += skip;
245252
m = R[r] - skip;
246253
--- src/diff.c
+++ src/diff.c
@@ -235,11 +235,18 @@
235 }
236 for(i=1; i<nr; i++){
237 na += R[r+i*3];
238 nb += R[r+i*3];
239 }
240 blob_appendf(pOut,"@@ -%d,%d +%d,%d @@\n", a+skip+1, na, b+skip+1, nb);
 
 
 
 
 
 
 
241
242 /* Show the initial common area */
243 a += skip;
244 b += skip;
245 m = R[r] - skip;
246
--- src/diff.c
+++ src/diff.c
@@ -235,11 +235,18 @@
235 }
236 for(i=1; i<nr; i++){
237 na += R[r+i*3];
238 nb += R[r+i*3];
239 }
240 /*
241 * If the patch changes an empty file or results in an empty file,
242 * the block header must use 0,0 as position indicator and not 1,0.
243 * Otherwise, patch would be confused and may reject the diff.
244 */
245 blob_appendf(pOut,"@@ -%d,%d +%d,%d @@\n",
246 na ? a+skip+1 : 0, na,
247 nb ? b+skip+1 : 0, nb);
248
249 /* Show the initial common area */
250 a += skip;
251 b += skip;
252 m = R[r] - skip;
253

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button