default:
continue;
case '\n':
- break;
+ return NULL;
case '\t': case ' ':
second = name+len;
for (;;) {
struct fragment dummy;
if (parse_fragment_header(line, len, &dummy) < 0)
continue;
- error("patch fragment without header at line %d: %.*s", linenr, len-1, line);
+ error("patch fragment without header at line %d: %.*s", linenr, (int)len-1, line);
}
if (size < len + 6)
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;
}
* 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;
while (frag) {
if (apply_one_fragment(desc, frag) < 0)
- return error("patch failed: %s:%d", patch->old_name, frag->oldpos);
+ return error("patch failed: %s:%ld", patch->old_name, frag->oldpos);
frag = frag->next;
}
return 0;
return error("%s: already exists in working directory", new_name);
if (errno != ENOENT)
return error("%s: %s", new_name, strerror(errno));
- if (!patch->new_mode)
- patch->new_mode = S_IFREG | 0644;
+ if (!patch->new_mode) {
+ if (patch->is_new)
+ patch->new_mode = S_IFREG | 0644;
+ else
+ patch->new_mode = patch->old_mode;
+ }
}
if (new_name && old_name) {
static int use_patch(struct patch *p)
{
- const char *pathname = p->new_name ? : p->old_name;
+ const char *pathname = p->new_name ? p->new_name : p->old_name;
struct excludes *x = excludes;
while (x) {
if (fnmatch(x->path, pathname, 0) == 0)