]> asedeno.scripts.mit.edu Git - git.git/blobdiff - builtin-apply.c
Improve use of lockfile API
[git.git] / builtin-apply.c
index ab393f32e9740c00b5e8fb40076516de7924c16f..15432b6782400b556333ee4117c7daaff20412ab 100644 (file)
@@ -912,8 +912,8 @@ static void check_whitespace(const char *line, int len, unsigned ws_rule)
                ;
        else {
                err = whitespace_error_string(result);
-               fprintf(stderr, "%s.\n%s:%d:%.*s\n",
-                    err, patch_input_file, linenr, len - 2, line + 1);
+               fprintf(stderr, "%s:%d: %s.\n%.*s\n",
+                    patch_input_file, linenr, err, len - 2, line + 1);
                free(err);
        }
 }
@@ -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");
        }