Update tests not to assume that generated packfiles are writable.
[gitweb.git] / diff.c
diff --git a/diff.c b/diff.c
index e4efb657e8ad8d30d7f0d25b17350fe19840e449..f516664968a6cb448611c24489254cbb2c9947ff 100644 (file)
--- a/diff.c
+++ b/diff.c
@@ -1068,9 +1068,19 @@ static int file_is_binary(struct diff_filespec *one)
        struct git_attr_check attr_diff_check;
 
        setup_diff_attr_check(&attr_diff_check);
-       if (!git_checkattr(one->path, 1, &attr_diff_check) &&
-           (0 == attr_diff_check.isset))
-               return 1;
+       if (!git_checkattr(one->path, 1, &attr_diff_check)) {
+               const char *value = attr_diff_check.value;
+               if (ATTR_TRUE(value))
+                       return 0;
+               else if (ATTR_FALSE(value))
+                       return 1;
+               else if (ATTR_UNSET(value))
+                       ;
+               else
+                       die("unknown value %s given to 'diff' attribute",
+                           value);
+       }
+
        if (!one->data) {
                if (!DIFF_FILE_VALID(one))
                        return 0;
@@ -1419,6 +1429,22 @@ static int populate_from_stdin(struct diff_filespec *s)
        return 0;
 }
 
+static int diff_populate_gitlink(struct diff_filespec *s, int size_only)
+{
+       int len;
+       char *data = xmalloc(100);
+       len = snprintf(data, 100,
+               "Subproject commit %s\n", sha1_to_hex(s->sha1));
+       s->data = data;
+       s->size = len;
+       s->should_free = 1;
+       if (size_only) {
+               s->data = NULL;
+               free(data);
+       }
+       return 0;
+}
+
 /*
  * While doing rename detection and pickaxe operation, we may need to
  * grab the data for the blob (or file) for our own in-core comparison.
@@ -1437,6 +1463,10 @@ int diff_populate_filespec(struct diff_filespec *s, int size_only)
 
        if (s->data)
                return err;
+
+       if (S_ISDIRLNK(s->mode))
+               return diff_populate_gitlink(s, size_only);
+
        if (!s->sha1_valid ||
            reuse_worktree_file(s->path, s->sha1, 0)) {
                struct stat st;
@@ -1483,9 +1513,9 @@ int diff_populate_filespec(struct diff_filespec *s, int size_only)
                /*
                 * Convert from working tree format to canonical git format
                 */
-               buf = s->data;
                size = s->size;
-               if (convert_to_git(s->path, &buf, &size)) {
+               buf = convert_to_git(s->path, s->data, &size);
+               if (buf) {
                        munmap(s->data, s->size);
                        s->should_munmap = 0;
                        s->data = buf;