[PATCH 3/3] Rename git-diff-tree-helper to git-diff-helper (part 2).
[git.git] / diff.c
diff --git a/diff.c b/diff.c
index 748ab4a..26b53cc 100644 (file)
--- a/diff.c
+++ b/diff.c
@@ -8,11 +8,11 @@
 #include "cache.h"
 #include "diff.h"
 
-static char *diff_opts = "-pu";
+static const char *diff_opts = "-pu";
 
 static const char *external_diff(void)
 {
-       static char *external_diff_cmd = NULL;
+       static const char *external_diff_cmd = NULL;
        static int done_preparing = 0;
 
        if (done_preparing)
@@ -26,11 +26,11 @@ static const char *external_diff(void)
         *
         * GIT_DIFF_OPTS="-c";
         */
-       if (getenv("GIT_EXTERNAL_DIFF"))
-               external_diff_cmd = getenv("GIT_EXTERNAL_DIFF");
+       if (gitenv("GIT_EXTERNAL_DIFF"))
+               external_diff_cmd = gitenv("GIT_EXTERNAL_DIFF");
 
        /* In case external diff fails... */
-       diff_opts = getenv("GIT_DIFF_OPTS") ? : diff_opts;
+       diff_opts = gitenv("GIT_DIFF_OPTS") ? : diff_opts;
 
        done_preparing = 1;
        return external_diff_cmd;
@@ -83,6 +83,7 @@ static void builtin_diff(const char *name,
                         struct diff_tempfile *temp)
 {
        int i, next_at;
+       const char *git_prefix = "# mode: ";
        const char *diff_cmd = "diff -L'%s%s' -L'%s%s'";
        const char *diff_arg  = "'%s' '%s'||:"; /* "||:" is to return 0 */
        const char *input_name_sq[2];
@@ -123,17 +124,18 @@ static void builtin_diff(const char *name,
                            diff_arg, input_name_sq[0], input_name_sq[1]);
 
        if (!path1[0][0])
-               printf("Created: %s (mode:%s)\n", name, temp[1].mode);
+               printf("%s. %s %s\n", git_prefix, temp[1].mode, name);
        else if (!path1[1][0])
-               printf("Deleted: %s\n", name);
-       else if (strcmp(temp[0].mode, temp[1].mode)) {
-               printf("Mode changed: %s (%s->%s)\n", name,
-                      temp[0].mode, temp[1].mode);
-               /* Be careful.  We do not want to diff between
-                * symlink and a file.
-                */
-               if (strncmp(temp[0].mode, "120", 3) !=
-                   strncmp(temp[1].mode, "120", 3))
+               printf("%s%s . %s\n", git_prefix, temp[0].mode, name);
+       else {
+               if (strcmp(temp[0].mode, temp[1].mode))
+                       printf("%s%s %s %s\n", git_prefix,
+                              temp[0].mode, temp[1].mode, name);
+
+               if (strncmp(temp[0].mode, temp[1].mode, 3))
+                       /* we do not run diff between different kind
+                        * of objects.
+                        */
                        exit(0);
        }
        fflush(NULL);