Merge branch 'rs/rm-strbuf-optim' into maint
authorJunio C Hamano <gitster@pobox.com>
Wed, 10 Aug 2016 18:55:24 +0000 (11:55 -0700)
committerJunio C Hamano <gitster@pobox.com>
Wed, 10 Aug 2016 18:55:24 +0000 (11:55 -0700)
The use of strbuf in "git rm" to build filename to remove was a bit
suboptimal, which has been fixed.

* rs/rm-strbuf-optim:
rm: reuse strbuf for all remove_dir_recursively() calls

1  2 
builtin/rm.c
diff --combined builtin/rm.c
index 8abb0207fa8e4da05ea447ae4e58c8e54c97c35b,7d6787d8dd00963b81bf9e630452c871b70f4e49..b2fee3e90ab5439a86b06079c15ca1e4cc303e60
@@@ -152,7 -152,7 +152,7 @@@ static int check_local_mod(unsigned cha
  
                if (lstat(ce->name, &st) < 0) {
                        if (errno != ENOENT && errno != ENOTDIR)
 -                              warning("'%s': %s", ce->name, strerror(errno));
 +                              warning_errno(_("failed to stat '%s'"), ce->name);
                        /* It already vanished from the working tree */
                        continue;
                }
@@@ -314,7 -314,7 +314,7 @@@ int cmd_rm(int argc, const char **argv
                list.entry[list.nr].is_submodule = S_ISGITLINK(ce->ce_mode);
                if (list.entry[list.nr++].is_submodule &&
                    !is_staging_gitmodules_ok())
 -                      die (_("Please, stage your changes to .gitmodules or stash them to proceed"));
 +                      die (_("Please stage your changes to .gitmodules or stash them to proceed"));
        }
  
        if (pathspec.nr) {
         */
        if (!index_only) {
                int removed = 0, gitmodules_modified = 0;
+               struct strbuf buf = STRBUF_INIT;
                for (i = 0; i < list.nr; i++) {
                        const char *path = list.entry[i].name;
                        if (list.entry[i].is_submodule) {
                                                continue;
                                        }
                                } else {
-                                       struct strbuf buf = STRBUF_INIT;
+                                       strbuf_reset(&buf);
                                        strbuf_addstr(&buf, path);
                                        if (!remove_dir_recursively(&buf, 0)) {
                                                removed = 1;
                                                /* Submodule was removed by user */
                                                if (!remove_path_from_gitmodules(path))
                                                        gitmodules_modified = 1;
-                                       strbuf_release(&buf);
                                        /* Fallthrough and let remove_path() fail. */
                                }
                        }
                        if (!removed)
                                die_errno("git rm: '%s'", path);
                }
+               strbuf_release(&buf);
                if (gitmodules_modified)
                        stage_updated_gitmodules();
        }