Merge branch 'nd/multiple-work-trees'
A replacement for contrib/workdir/git-new-workdir that does not rely on symbolic links and make sharing of objects and refs safer by making the borrowee and borrowers aware of each other. * nd/multiple-work-trees: (41 commits) prune --worktrees: fix expire vs worktree existence condition t1501: fix test with split index t2026: fix broken &&-chain t2026 needs procondition SANITY git-checkout.txt: a note about multiple checkout support for submodules checkout: add --ignore-other-wortrees checkout: pass whole struct to parse_branchname_arg instead of individual flags git-common-dir: make "modules/" per-working-directory directory checkout: do not fail if target is an empty directory t2025: add a test to make sure grafts is working from a linked checkout checkout: don't require a work tree when checking out into a new one git_path(): keep "info/sparse-checkout" per work-tree count-objects: report unused files in $GIT_DIR/worktrees/... gc: support prune --worktrees gc: factor out gc.pruneexpire parsing code gc: style change -- no SP before closing parenthesis checkout: clean up half-prepared directories in --to mode checkout: reject if the branch is already checked out elsewhere prune: strategies for linked checkouts checkout: support checking out into a new working directory ...
This commit is contained in:
31
wrapper.c
31
wrapper.c
@ -564,3 +564,34 @@ char *xgetcwd(void)
|
||||
die_errno(_("unable to get current working directory"));
|
||||
return strbuf_detach(&sb, NULL);
|
||||
}
|
||||
|
||||
int write_file(const char *path, int fatal, const char *fmt, ...)
|
||||
{
|
||||
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);
|
||||
if (write_in_full(fd, sb.buf, sb.len) != sb.len) {
|
||||
int err = errno;
|
||||
close(fd);
|
||||
strbuf_release(&sb);
|
||||
errno = err;
|
||||
if (fatal)
|
||||
die_errno(_("could not write to %s"), path);
|
||||
return -1;
|
||||
}
|
||||
strbuf_release(&sb);
|
||||
if (close(fd)) {
|
||||
if (fatal)
|
||||
die_errno(_("could not close %s"), path);
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
Reference in New Issue
Block a user