diff options
Diffstat (limited to 'strbuf.c')
-rw-r--r-- | strbuf.c | 38 |
1 files changed, 12 insertions, 26 deletions
@@ -1,8 +1,16 @@ -#include "cache.h" +#include "git-compat-util.h" +#include "abspath.h" +#include "alloc.h" +#include "environment.h" +#include "gettext.h" +#include "hex.h" +#include "object-name.h" #include "refs.h" +#include "repository.h" #include "string-list.h" #include "utf8.h" #include "date.h" +#include "wrapper.h" int starts_with(const char *str, const char *prefix) { @@ -1173,30 +1181,8 @@ int strbuf_normalize_path(struct strbuf *src) return 0; } -int strbuf_edit_interactively(struct strbuf *buffer, const char *path, - const char *const *env) +void strbuf_strip_file_from_path(struct strbuf *sb) { - char *path2 = NULL; - int fd, res = 0; - - if (!is_absolute_path(path)) - path = path2 = xstrdup(git_path("%s", path)); - - fd = open(path, O_WRONLY | O_CREAT | O_TRUNC, 0666); - if (fd < 0) - res = error_errno(_("could not open '%s' for writing"), path); - else if (write_in_full(fd, buffer->buf, buffer->len) < 0) { - res = error_errno(_("could not write to '%s'"), path); - close(fd); - } else if (close(fd) < 0) - res = error_errno(_("could not close '%s'"), path); - else { - strbuf_reset(buffer); - if (launch_editor(path, buffer, env) < 0) - res = error_errno(_("could not edit '%s'"), path); - unlink(path); - } - - free(path2); - return res; + char *path_sep = find_last_dir_sep(sb->buf); + strbuf_setlen(sb, path_sep ? path_sep - sb->buf + 1 : 0); } |