Merge branch 'js/maint-diff-temp-smudge'
authorJunio C Hamano <gitster@pobox.com>
Thu, 26 Mar 2009 07:27:30 +0000 (00:27 -0700)
committerJunio C Hamano <gitster@pobox.com>
Thu, 26 Mar 2009 07:27:30 +0000 (00:27 -0700)
* js/maint-diff-temp-smudge:
Smudge the files fed to external diff and textconv

1  2 
diff.c
diff --combined diff.c
index 75d9fab8f87033ba86f687fbc92c5d4ee4c68d7b,11798af0c190f369e8ac9cb0463f794bc3bb5d10..699ae6aca38147a6137cc28bcc1022e70f71db60
--- 1/diff.c
--- 2/diff.c
+++ b/diff.c
@@@ -30,14 -30,14 +30,14 @@@ int diff_auto_refresh_index = 1
  static int diff_mnemonic_prefix;
  
  static char diff_colors[][COLOR_MAXLEN] = {
 -      "\033[m",       /* reset */
 -      "",             /* PLAIN (normal) */
 -      "\033[1m",      /* METAINFO (bold) */
 -      "\033[36m",     /* FRAGINFO (cyan) */
 -      "\033[31m",     /* OLD (red) */
 -      "\033[32m",     /* NEW (green) */
 -      "\033[33m",     /* COMMIT (yellow) */
 -      "\033[41m",     /* WHITESPACE (red background) */
 +      GIT_COLOR_RESET,
 +      GIT_COLOR_NORMAL,       /* PLAIN */
 +      GIT_COLOR_BOLD,         /* METAINFO */
 +      GIT_COLOR_CYAN,         /* FRAGINFO */
 +      GIT_COLOR_RED,          /* OLD */
 +      GIT_COLOR_GREEN,        /* NEW */
 +      GIT_COLOR_YELLOW,       /* COMMIT */
 +      GIT_COLOR_BG_RED,       /* WHITESPACE */
  };
  
  static void diff_filespec_load_driver(struct diff_filespec *one);
@@@ -875,7 -875,7 +875,7 @@@ static void fill_print_name(struct diff
  
  static void show_stats(struct diffstat_t* data, struct diff_options *options)
  {
 -      int i, len, add, del, total, adds = 0, dels = 0;
 +      int i, len, add, del, adds = 0, dels = 0;
        int max_change = 0, max_len = 0;
        int total_files = data->nr;
        int width, name_width;
                 */
                add = added;
                del = deleted;
 -              total = add + del;
                adds += add;
                dels += del;
  
                if (width <= max_change) {
                        add = scale_linear(add, width, max_change);
                        del = scale_linear(del, width, max_change);
 -                      total = add + del;
                }
                show_name(options->file, prefix, name, len, reset, set);
                fprintf(options->file, "%5d%s", added + deleted,
@@@ -1781,7 -1783,7 +1781,7 @@@ static int reuse_worktree_file(const ch
         * objects however would tend to be slower as they need
         * to be individually opened and inflated.
         */
 -      if (!FAST_WORKING_DIRECTORY && !want_file && has_sha1_pack(sha1, NULL))
 +      if (!FAST_WORKING_DIRECTORY && !want_file && has_sha1_pack(sha1))
                return 0;
  
        len = strlen(name);
@@@ -1946,17 -1948,23 +1946,23 @@@ void diff_free_filespec_data(struct dif
        s->cnt_data = NULL;
  }
  
- static void prep_temp_blob(struct diff_tempfile *temp,
+ static void prep_temp_blob(const char *path, struct diff_tempfile *temp,
                           void *blob,
                           unsigned long size,
                           const unsigned char *sha1,
                           int mode)
  {
        int fd;
+       struct strbuf buf = STRBUF_INIT;
  
        fd = git_mkstemp(temp->tmp_path, PATH_MAX, ".diff_XXXXXX");
        if (fd < 0)
                die("unable to create temp-file: %s", strerror(errno));
+       if (convert_to_working_tree(path,
+                       (const char *)blob, (size_t)size, &buf)) {
+               blob = buf.buf;
+               size = buf.len;
+       }
        if (write_in_full(fd, blob, size) != size)
                die("unable to write temp-file");
        close(fd);
        strcpy(temp->hex, sha1_to_hex(sha1));
        temp->hex[40] = 0;
        sprintf(temp->mode, "%06o", mode);
+       strbuf_release(&buf);
  }
  
  static struct diff_tempfile *prepare_temp_file(const char *name,
                                die("readlink(%s)", name);
                        if (ret == sizeof(buf))
                                die("symlink too long: %s", name);
-                       prep_temp_blob(temp, buf, ret,
+                       prep_temp_blob(name, temp, buf, ret,
                                       (one->sha1_valid ?
                                        one->sha1 : null_sha1),
                                       (one->sha1_valid ?
        else {
                if (diff_populate_filespec(one, 0))
                        die("cannot read data blob for %s", one->path);
-               prep_temp_blob(temp, one->data, one->size,
+               prep_temp_blob(name, temp, one->data, one->size,
                               one->sha1, one->mode);
        }
        return temp;
@@@ -2565,13 -2574,13 +2572,13 @@@ int diff_opt_parse(struct diff_options 
  
        /* xdiff options */
        else if (!strcmp(arg, "-w") || !strcmp(arg, "--ignore-all-space"))
 -              options->xdl_opts |= XDF_IGNORE_WHITESPACE;
 +              DIFF_XDL_SET(options, IGNORE_WHITESPACE);
        else if (!strcmp(arg, "-b") || !strcmp(arg, "--ignore-space-change"))
 -              options->xdl_opts |= XDF_IGNORE_WHITESPACE_CHANGE;
 +              DIFF_XDL_SET(options, IGNORE_WHITESPACE_CHANGE);
        else if (!strcmp(arg, "--ignore-space-at-eol"))
 -              options->xdl_opts |= XDF_IGNORE_WHITESPACE_AT_EOL;
 +              DIFF_XDL_SET(options, IGNORE_WHITESPACE_AT_EOL);
        else if (!strcmp(arg, "--patience"))
 -              options->xdl_opts |= XDF_PATIENCE_DIFF;
 +              DIFF_XDL_SET(options, PATIENCE_DIFF);
  
        /* flags options */
        else if (!strcmp(arg, "--binary")) {
                DIFF_OPT_SET(options, COLOR_DIFF);
        else if (!strcmp(arg, "--no-color"))
                DIFF_OPT_CLR(options, COLOR_DIFF);
 -      else if (!strcmp(arg, "--color-words"))
 -              options->flags |= DIFF_OPT_COLOR_DIFF | DIFF_OPT_COLOR_DIFF_WORDS;
 +      else if (!strcmp(arg, "--color-words")) {
 +              DIFF_OPT_SET(options, COLOR_DIFF);
 +              DIFF_OPT_SET(options, COLOR_DIFF_WORDS);
 +      }
        else if (!prefixcmp(arg, "--color-words=")) {
 -              options->flags |= DIFF_OPT_COLOR_DIFF | DIFF_OPT_COLOR_DIFF_WORDS;
 +              DIFF_OPT_SET(options, COLOR_DIFF);
 +              DIFF_OPT_SET(options, COLOR_DIFF_WORDS);
                options->word_regex = arg + 14;
        }
        else if (!strcmp(arg, "--exit-code"))