Code

Use strbuf API in apply, blame, commit-tree and diff
[git.git] / diff.c
diff --git a/diff.c b/diff.c
index 97cc5bc085ba21693007328bb402860420949ec0..c054b234b877952501dcf05b2ea312ae77441042 100644 (file)
--- a/diff.c
+++ b/diff.c
@@ -9,6 +9,7 @@
 #include "xdiff-interface.h"
 #include "color.h"
 #include "attr.h"
+#include "strbuf.h"
 
 #ifdef NO_FAST_WORKING_DIRECTORY
 #define FAST_WORKING_DIRECTORY 0
@@ -19,6 +20,7 @@
 static int diff_detect_rename_default;
 static int diff_rename_limit_default = -1;
 static int diff_use_color_default;
+int diff_auto_refresh_index = 1;
 
 static char diff_colors[][COLOR_MAXLEN] = {
        "\033[m",       /* reset */
@@ -166,6 +168,10 @@ int git_diff_ui_config(const char *var, const char *value)
                        diff_detect_rename_default = DIFF_DETECT_RENAME;
                return 0;
        }
+       if (!strcmp(var, "diff.autorefreshindex")) {
+               diff_auto_refresh_index = git_config_bool(var, value);
+               return 0;
+       }
        if (!prefixcmp(var, "diff.")) {
                const char *ep = strrchr(var, '.');
 
@@ -1540,26 +1546,16 @@ static int reuse_worktree_file(const char *name, const unsigned char *sha1, int
 
 static int populate_from_stdin(struct diff_filespec *s)
 {
-#define INCREMENT 1024
-       char *buf;
-       unsigned long size;
-       ssize_t got;
-
-       size = 0;
-       buf = NULL;
-       while (1) {
-               buf = xrealloc(buf, size + INCREMENT);
-               got = xread(0, buf + size, INCREMENT);
-               if (!got)
-                       break; /* EOF */
-               if (got < 0)
-                       return error("error while reading from stdin %s",
+       struct strbuf buf;
+
+       strbuf_init(&buf);
+       if (strbuf_read(&buf, 0) < 0)
+               return error("error while reading from stdin %s",
                                     strerror(errno));
-               size += got;
-       }
+
        s->should_munmap = 0;
-       s->data = buf;
-       s->size = size;
+       s->size = buf.len;
+       s->data = strbuf_detach(&buf);
        s->should_free = 1;
        return 0;
 }
@@ -2919,10 +2915,6 @@ static int diff_get_patch_id(struct diff_options *options, unsigned char *sha1)
                                fill_mmfile(&mf2, p->two) < 0)
                        return error("unable to read files to diff");
 
-               /* Maybe hash p->two? into the patch id? */
-               if (diff_filespec_is_binary(p->two))
-                       continue;
-
                len1 = remove_space(p->one->path, strlen(p->one->path));
                len2 = remove_space(p->two->path, strlen(p->two->path));
                if (p->one->mode == 0)