#include "blob.h"
#include "delta.h"
#include "builtin.h"
-#include "strbuf.h"
/*
* --check turns on checking that the working tree matches the
{
struct strbuf buf;
- strbuf_init(&buf);
- if (strbuf_read(&buf, fd) < 0)
+ strbuf_init(&buf, 0);
+ if (strbuf_read(&buf, fd, 0) < 0)
die("git-apply: read returned %s", strerror(errno));
*sizep = buf.len;
{
int fd;
unsigned long got;
- unsigned long nsize;
- char *nbuf;
+ struct strbuf nbuf;
unsigned long size = *size_p;
char *buf = *buf_p;
got += ret;
}
close(fd);
- nsize = got;
- nbuf = convert_to_git(path, buf, &nsize);
- if (nbuf) {
+ strbuf_init(&nbuf, 0);
+ if (convert_to_git(path, buf, size, &nbuf)) {
free(buf);
- *buf_p = nbuf;
- *alloc_p = nsize;
- *size_p = nsize;
+ *buf_p = nbuf.buf;
+ *alloc_p = nbuf.alloc;
+ *size_p = nbuf.len;
}
return got != size;
default:
static int try_create_file(const char *path, unsigned int mode, const char *buf, unsigned long size)
{
int fd;
- char *nbuf;
+ struct strbuf nbuf;
if (S_ISGITLINK(mode)) {
struct stat st;
if (fd < 0)
return -1;
- nbuf = convert_to_working_tree(path, buf, &size);
- if (nbuf)
- buf = nbuf;
+ strbuf_init(&nbuf, 0);
+ if (convert_to_working_tree(path, buf, size, &nbuf)) {
+ size = nbuf.len;
+ buf = nbuf.buf;
+ }
while (size) {
int written = xwrite(fd, buf, size);
}
if (close(fd) < 0)
die("closing file %s: %s", path, strerror(errno));
- if (nbuf)
- free(nbuf);
+ strbuf_release(&nbuf);
return 0;
}