Code

detect close failure on just-written file handles
[git.git] / diff.c
diff --git a/diff.c b/diff.c
index 8354e71e0707960f7a1094e288bea0fac83ec6b8..9938969fa50e8af2a4eabe96ae122111ae42fe75 100644 (file)
--- a/diff.c
+++ b/diff.c
@@ -186,13 +186,11 @@ static const char *external_diff(void)
        return external_diff_cmd;
 }
 
-#define TEMPFILE_PATH_LEN              50
-
 static struct diff_tempfile {
        const char *name; /* filename external diff should read from */
        char hex[41];
        char mode[10];
-       char tmp_path[TEMPFILE_PATH_LEN];
+       char tmp_path[PATH_MAX];
 } diff_temp[2];
 
 static int count_lines(const char *data, int size)
@@ -1109,10 +1107,8 @@ static void setup_diff_attr_check(struct git_attr_check *check)
        check->attr = attr_diff;
 }
 
-#define FIRST_FEW_BYTES 8000
 static int file_is_binary(struct diff_filespec *one)
 {
-       unsigned long sz;
        struct git_attr_check attr_diff_check;
 
        setup_diff_attr_check(&attr_diff_check);
@@ -1129,10 +1125,7 @@ static int file_is_binary(struct diff_filespec *one)
                        return 0;
                diff_populate_filespec(one, 0);
        }
-       sz = one->size;
-       if (FIRST_FEW_BYTES < sz)
-               sz = FIRST_FEW_BYTES;
-       return !!memchr(one->data, 0, sz);
+       return buffer_is_binary(one->data, one->size);
 }
 
 static void builtin_diff(const char *name_a,
@@ -1351,7 +1344,7 @@ void fill_filespec(struct diff_filespec *spec, const unsigned char *sha1,
 }
 
 /*
- * Given a name and sha1 pair, if the dircache tells us the file in
+ * Given a name and sha1 pair, if the index tells us the file in
  * the work tree has that object contents, return true, so that
  * prepare_temp_file() does not have to inflate and extract.
  */
@@ -1411,7 +1404,7 @@ static int populate_from_stdin(struct diff_filespec *s)
 #define INCREMENT 1024
        char *buf;
        unsigned long size;
-       int got;
+       ssize_t got;
 
        size = 0;
        buf = NULL;
@@ -1467,7 +1460,7 @@ int diff_populate_filespec(struct diff_filespec *s, int size_only)
        if (size_only && 0 < s->size)
                return 0;
 
-       if (S_ISDIRLNK(s->mode))
+       if (S_ISGITLINK(s->mode))
                return diff_populate_gitlink(s, size_only);
 
        if (!s->sha1_valid ||
@@ -1561,7 +1554,7 @@ static void prep_temp_blob(struct diff_tempfile *temp,
 {
        int fd;
 
-       fd = git_mkstemp(temp->tmp_path, TEMPFILE_PATH_LEN, ".diff_XXXXXX");
+       fd = git_mkstemp(temp->tmp_path, PATH_MAX, ".diff_XXXXXX");
        if (fd < 0)
                die("unable to create temp-file");
        if (write_in_full(fd, blob, size) != size)
@@ -2110,6 +2103,8 @@ static int opt_arg(const char *arg, int arg_short, const char *arg_long, int *va
        return 1;
 }
 
+static int diff_scoreopt_parse(const char *opt);
+
 int diff_opt_parse(struct diff_options *options, const char **av, int ac)
 {
        const char *arg = av[0];
@@ -2206,6 +2201,8 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
                options->detect_rename = DIFF_DETECT_RENAME;
        }
        else if (!prefixcmp(arg, "-C")) {
+               if (options->detect_rename == DIFF_DETECT_COPY)
+                       options->find_copies_harder = 1;
                if ((options->rename_score =
                     diff_scoreopt_parse(arg)) == -1)
                        return -1;
@@ -2213,6 +2210,8 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
        }
        else if (!strcmp(arg, "--find-copies-harder"))
                options->find_copies_harder = 1;
+       else if (!strcmp(arg, "--follow"))
+               options->follow_renames = 1;
        else if (!strcmp(arg, "--abbrev"))
                options->abbrev = DEFAULT_ABBREV;
        else if (!prefixcmp(arg, "--abbrev=")) {
@@ -2281,7 +2280,7 @@ static int parse_num(const char **cp_p)
        return (int)((num >= scale) ? MAX_SCORE : (MAX_SCORE * num / scale));
 }
 
-int diff_scoreopt_parse(const char *opt)
+static int diff_scoreopt_parse(const char *opt)
 {
        int opt1, opt2, cmd;
 
@@ -3038,7 +3037,7 @@ void diff_addremove(struct diff_options *options,
         * entries to the diff-core.  They will be prefixed
         * with something like '=' or '*' (I haven't decided
         * which but should not make any difference).
-        * Feeding the same new and old to diff_change() 
+        * Feeding the same new and old to diff_change()
         * also has the same effect.
         * Before the final output happens, they are pruned after
         * merged into rename/copy pairs as appropriate.
@@ -3065,7 +3064,7 @@ void diff_change(struct diff_options *options,
                 unsigned old_mode, unsigned new_mode,
                 const unsigned char *old_sha1,
                 const unsigned char *new_sha1,
-                const char *base, const char *path) 
+                const char *base, const char *path)
 {
        char concatpath[PATH_MAX];
        struct diff_filespec *one, *two;