Code

git.el: Check for existing buffers on revert.
[git.git] / builtin-apply.c
index 2edd83bf40f51f52e58737ef5e7220ae70afb6e1..15432b6782400b556333ee4117c7daaff20412ab 100644 (file)
@@ -1550,8 +1550,8 @@ static int apply_line(char *output, const char *patch, int plen,
        int i;
        int add_nl_to_tail = 0;
        int fixed = 0;
-       int last_tab_in_indent = -1;
-       int last_space_in_indent = -1;
+       int last_tab_in_indent = 0;
+       int last_space_in_indent = 0;
        int need_fix_leading_space = 0;
        char *buf;
 
@@ -1582,13 +1582,12 @@ static int apply_line(char *output, const char *patch, int plen,
                if (ch == '\t') {
                        last_tab_in_indent = i;
                        if ((ws_rule & WS_SPACE_BEFORE_TAB) &&
-                           0 <= last_space_in_indent)
+                           0 < last_space_in_indent)
                            need_fix_leading_space = 1;
                } else if (ch == ' ') {
                        last_space_in_indent = i;
                        if ((ws_rule & WS_INDENT_WITH_NON_TAB) &&
-                           last_tab_in_indent < 0 &&
-                           8 <= i)
+                           8 <= i - last_tab_in_indent)
                                need_fix_leading_space = 1;
                }
                else
@@ -2908,7 +2907,7 @@ int cmd_apply(int argc, const char **argv, const char *unused_prefix)
                            whitespace_error,
                            whitespace_error == 1 ? "" : "s",
                            whitespace_error == 1 ? "s" : "");
-               if (applied_after_fixing_ws)
+               if (applied_after_fixing_ws && apply)
                        fprintf(stderr, "warning: %d line%s applied after"
                                " fixing whitespace errors.\n",
                                applied_after_fixing_ws,
@@ -2922,7 +2921,7 @@ int cmd_apply(int argc, const char **argv, const char *unused_prefix)
 
        if (update_index) {
                if (write_cache(newfd, active_cache, active_nr) ||
-                   close(newfd) || commit_locked_index(&lock_file))
+                   commit_locked_index(&lock_file))
                        die("Unable to write new index file");
        }