Now that cache.h needs strbuf.h, remove useless includes.
[gitweb.git] / builtin-apply.c
index 90e328ef917cfa591e6621966b5b3bc2ead24075..1256716aece3d3e97f615cc6d8957da68d3e14d6 100644 (file)
@@ -12,7 +12,6 @@
 #include "blob.h"
 #include "delta.h"
 #include "builtin.h"
-#include "strbuf.h"
 
 /*
  *  --check turns on checking that the working tree matches the
@@ -184,8 +183,8 @@ static void *read_patch_file(int fd, unsigned long *sizep)
 {
        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;
 
@@ -1446,8 +1445,7 @@ static int read_old_data(struct stat *st, const char *path, char **buf_p, unsign
 {
        int fd;
        unsigned long got;
-       unsigned long nsize;
-       char *nbuf;
+       struct strbuf nbuf;
        unsigned long size = *size_p;
        char *buf = *buf_p;
 
@@ -1466,13 +1464,12 @@ static int read_old_data(struct stat *st, const char *path, char **buf_p, unsign
                        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:
@@ -2439,7 +2436,7 @@ static void add_index_file(const char *path, unsigned mode, void *buf, unsigned
 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;
@@ -2458,9 +2455,11 @@ static int try_create_file(const char *path, unsigned int mode, const char *buf,
        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);
@@ -2473,8 +2472,7 @@ static int try_create_file(const char *path, unsigned int mode, const char *buf,
        }
        if (close(fd) < 0)
                die("closing file %s: %s", path, strerror(errno));
-       if (nbuf)
-               free(nbuf);
+       strbuf_release(&nbuf);
        return 0;
 }