* This applies patches on top of some (arbitrary) version of the SCM.
*
*/
-#include <fnmatch.h>
#include "cache.h"
#include "cache-tree.h"
#include "quote.h"
struct patch {
char *new_name, *old_name, *def_name;
unsigned int old_mode, new_mode;
- int is_rename, is_copy, is_new, is_delete, is_binary;
+ int is_new, is_delete; /* -1 = unknown, 0 = false, 1 = true */
int rejected;
unsigned long deflate_origlen;
int lines_added, lines_deleted;
int score;
- int inaccurate_eof:1;
+ unsigned int inaccurate_eof:1;
+ unsigned int is_binary:1;
+ unsigned int is_copy:1;
+ unsigned int is_rename:1;
struct fragment *fragments;
char *result;
unsigned long resultsize;
struct fragment dummy;
if (parse_fragment_header(line, len, &dummy) < 0)
continue;
- error("patch fragment without header at line %d: %.*s", linenr, (int)len-1, line);
+ die("patch fragment without header at line %d: %.*s",
+ linenr, (int)len-1, line);
}
if (size < len + 6)
for ( ; patch; patch = patch->next) {
const char *name;
name = patch->new_name ? patch->new_name : patch->old_name;
- printf("%d\t%d\t", patch->lines_added, patch->lines_deleted);
+ if (patch->is_binary)
+ printf("-\t-\t");
+ else
+ printf("%d\t%d\t",
+ patch->lines_added, patch->lines_deleted);
if (line_termination && quote_c_style(name, NULL, NULL, 0))
quote_c_style(name, NULL, stdout, 0);
else
die("unable to remove %s from index", patch->old_name);
cache_tree_invalidate_path(active_cache_tree, patch->old_name);
}
- if (!cached)
- unlink(patch->old_name);
+ if (!cached) {
+ if (!unlink(patch->old_name)) {
+ char *name = xstrdup(patch->old_name);
+ char *end = strrchr(name, '/');
+ while (end) {
+ *end = 0;
+ if (rmdir(name))
+ break;
+ end = strrchr(name, '/');
+ }
+ free(name);
+ }
+ }
}
static void add_index_file(const char *path, unsigned mode, void *buf, unsigned long size)