summaryrefslogtreecommitdiff
path: root/builtin/revert.c
diff options
context:
space:
mode:
authorJonathan Nieder <jrnieder@gmail.com>2011-11-16 08:03:36 (GMT)
committerJunio C Hamano <gitster@pobox.com>2011-11-17 23:06:27 (GMT)
commit418c9b176cbabf954b6325cca0bea7f9be251afe (patch)
treeda1efd67a778b6c9b4782fa69ef53ba64dbc4c75 /builtin/revert.c
parent4d2440fe0daa9ad1556dfd220af8b3a883cf849d (diff)
downloadgit-418c9b176cbabf954b6325cca0bea7f9be251afe.zip
git-418c9b176cbabf954b6325cca0bea7f9be251afe.tar.gz
git-418c9b176cbabf954b6325cca0bea7f9be251afe.tar.bz2
do not let git_path clobber errno when reporting errors
Because git_path() calls vsnprintf(), code like fd = open(git_path("SQUASH_MSG"), O_WRONLY | O_CREAT, 0666); die_errno(_("Could not write to '%s'"), git_path("SQUASH_MSG")); can end up printing an error indicator from vsnprintf() instead of open() by mistake. Store the path we are trying to write to in a temporary variable and pass _that_ to die_errno(), so the messages written by git cherry-pick/revert and git merge can avoid this source of confusion. Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/revert.c')
-rw-r--r--builtin/revert.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/builtin/revert.c b/builtin/revert.c
index b61c8e5..544e8c3 100644
--- a/builtin/revert.c
+++ b/builtin/revert.c
@@ -288,17 +288,18 @@ static char *get_encoding(const char *message)
static void write_cherry_pick_head(struct commit *commit)
{
+ const char *filename;
int fd;
struct strbuf buf = STRBUF_INIT;
strbuf_addf(&buf, "%s\n", sha1_to_hex(commit->object.sha1));
- fd = open(git_path("CHERRY_PICK_HEAD"), O_WRONLY | O_CREAT, 0666);
+ filename = git_path("CHERRY_PICK_HEAD");
+ fd = open(filename, O_WRONLY | O_CREAT, 0666);
if (fd < 0)
- die_errno(_("Could not open '%s' for writing"),
- git_path("CHERRY_PICK_HEAD"));
+ die_errno(_("Could not open '%s' for writing"), filename);
if (write_in_full(fd, buf.buf, buf.len) != buf.len || close(fd))
- die_errno(_("Could not write to '%s'"), git_path("CHERRY_PICK_HEAD"));
+ die_errno(_("Could not write to '%s'"), filename);
strbuf_release(&buf);
}