summaryrefslogtreecommitdiff
path: root/wrapper.c
diff options
context:
space:
mode:
authorLibravatar Junio C Hamano <gitster@pobox.com>2015-08-31 15:39:01 -0700
committerLibravatar Junio C Hamano <gitster@pobox.com>2015-08-31 15:39:03 -0700
commitd75bb73bcf2ecce38c147980aac0cbc27a6b838a (patch)
tree915571f195467d0a8b441455a94d6dca3c95f697 /wrapper.c
parentMerge branch 'jc/log-p-cc' (diff)
parentwrite_file(): drop caller-supplied LF from calls to create a one-liner file (diff)
downloadtgif-d75bb73bcf2ecce38c147980aac0cbc27a6b838a.tar.xz
Merge branch 'jc/am-state-fix'
Recent reimplementation of "git am" changed the format of state files kept in $GIT_DIR/rebase-apply/ without meaning to do so, primarily because write_file() API was cumbersome to use and it was easy to mistakenly make text files with incomplete lines. Update write_file() interface to make it harder to misuse. * jc/am-state-fix: write_file(): drop caller-supplied LF from calls to create a one-liner file write_file_v(): do not leave incomplete line at the end write_file(): drop "fatal" parameter builtin/am: make sure state files are text builtin/am: introduce write_state_*() helper functions
Diffstat (limited to 'wrapper.c')
-rw-r--r--wrapper.c29
1 files changed, 25 insertions, 4 deletions
diff --git a/wrapper.c b/wrapper.c
index e451463431..0e22d43814 100644
--- a/wrapper.c
+++ b/wrapper.c
@@ -621,19 +621,18 @@ char *xgetcwd(void)
return strbuf_detach(&sb, NULL);
}
-int write_file(const char *path, int fatal, const char *fmt, ...)
+static int write_file_v(const char *path, int fatal,
+ const char *fmt, va_list params)
{
struct strbuf sb = STRBUF_INIT;
- va_list params;
int fd = open(path, O_RDWR | O_CREAT | O_TRUNC, 0666);
if (fd < 0) {
if (fatal)
die_errno(_("could not open %s for writing"), path);
return -1;
}
- va_start(params, fmt);
strbuf_vaddf(&sb, fmt, params);
- va_end(params);
+ strbuf_complete_line(&sb);
if (write_in_full(fd, sb.buf, sb.len) != sb.len) {
int err = errno;
close(fd);
@@ -652,6 +651,28 @@ int write_file(const char *path, int fatal, const char *fmt, ...)
return 0;
}
+int write_file(const char *path, const char *fmt, ...)
+{
+ int status;
+ va_list params;
+
+ va_start(params, fmt);
+ status = write_file_v(path, 1, fmt, params);
+ va_end(params);
+ return status;
+}
+
+int write_file_gently(const char *path, const char *fmt, ...)
+{
+ int status;
+ va_list params;
+
+ va_start(params, fmt);
+ status = write_file_v(path, 0, fmt, params);
+ va_end(params);
+ return status;
+}
+
void sleep_millisec(int millisec)
{
poll(NULL, 0, millisec);