Code

Fix a crash in ls-remote when refspec expands into nothing
[git.git] / builtin-apply.c
index f4ecf03ed465c942a395f4de5ca3ce17bbdd3011..86d89a4a7e9240a75e1500bba524acdcec7f14d2 100644 (file)
@@ -254,7 +254,7 @@ static char *find_name(const char *line, char *def, int p_value, int terminate)
                if (name) {
                        char *cp = name;
                        while (p_value) {
-                               cp = strchr(name, '/');
+                               cp = strchr(cp, '/');
                                if (!cp)
                                        break;
                                cp++;
@@ -1642,15 +1642,22 @@ static int apply_line(char *output, const char *patch, int plen)
 
        buf = output;
        if (need_fix_leading_space) {
+               int consecutive_spaces = 0;
                /* between patch[1..last_tab_in_indent] strip the
                 * funny spaces, updating them to tab as needed.
                 */
                for (i = 1; i < last_tab_in_indent; i++, plen--) {
                        char ch = patch[i];
-                       if (ch != ' ')
+                       if (ch != ' ') {
+                               consecutive_spaces = 0;
                                *output++ = ch;
-                       else if ((i % 8) == 0)
-                               *output++ = '\t';
+                       } else {
+                               consecutive_spaces++;
+                               if (consecutive_spaces == 8) {
+                                       *output++ = '\t';
+                                       consecutive_spaces = 0;
+                               }
+                       }
                }
                fixed = 1;
                i = last_tab_in_indent;
@@ -2416,7 +2423,6 @@ static void remove_file(struct patch *patch, int rmdir_empty)
        if (update_index) {
                if (remove_file_from_cache(patch->old_name) < 0)
                        die("unable to remove %s from index", patch->old_name);
-               cache_tree_invalidate_path(active_cache_tree, patch->old_name);
        }
        if (!cached) {
                if (S_ISGITLINK(patch->old_mode)) {
@@ -2571,7 +2577,6 @@ static void create_file(struct patch *patch)
                mode = S_IFREG | 0644;
        create_one_file(path, mode, buf, size);
        add_index_file(path, mode, buf, size);
-       cache_tree_invalidate_path(active_cache_tree, path);
 }
 
 /* phase zero is to remove, phase one is to create */