Merge branch 'jc/diffcore'
authorJunio C Hamano <gitster@pobox.com>
Mon, 2 Jul 2007 08:45:12 +0000 (01:45 -0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 2 Jul 2007 08:45:12 +0000 (01:45 -0700)
* jc/diffcore:
diffcore-delta.c: Ignore CR in CRLF for text files
diffcore-delta.c: update the comment on the algorithm.
diffcore_filespec: add is_binary
diffcore_count_changes: pass diffcore_filespec

1  2 
diff.c
diffcore-rename.c
diff --combined diff.c
index e0edb98846753f39cab9e377c9ac4af2d7fdbf35,74c1198e6790de1fd57f2af12847f152db1cac95..93eca79c1762e697d57ccd8c49b2f7994f722c89
--- 1/diff.c
--- 2/diff.c
+++ b/diff.c
@@@ -1813,11 -1813,6 +1813,11 @@@ static void diff_fill_sha1_info(struct 
                hashclr(one->sha1);
  }
  
 +static int similarity_index(struct diff_filepair *p)
 +{
 +      return p->score * 100 / MAX_SCORE;
 +}
 +
  static void run_diff(struct diff_filepair *p, struct diff_options *o)
  {
        const char *pgm = external_diff();
                                "similarity index %d%%\n"
                                "copy from %s\n"
                                "copy to %s\n",
 -                              (int)(0.5 + p->score * 100.0/MAX_SCORE),
 -                              name_munged, other_munged);
 +                              similarity_index(p), name_munged, other_munged);
                break;
        case DIFF_STATUS_RENAMED:
                len += snprintf(msg + len, sizeof(msg) - len,
                                "similarity index %d%%\n"
                                "rename from %s\n"
                                "rename to %s\n",
 -                              (int)(0.5 + p->score * 100.0/MAX_SCORE),
 -                              name_munged, other_munged);
 +                              similarity_index(p), name_munged, other_munged);
                break;
        case DIFF_STATUS_MODIFIED:
                if (p->score) {
                        len += snprintf(msg + len, sizeof(msg) - len,
                                        "dissimilarity index %d%%\n",
 -                                      (int)(0.5 + p->score *
 -                                            100.0/MAX_SCORE));
 +                                      similarity_index(p));
                        complete_rewrite = 1;
                        break;
                }
@@@ -2389,7 -2387,8 +2389,7 @@@ static void diff_flush_raw(struct diff_
        }
  
        if (p->score)
 -              sprintf(status, "%c%03d", p->status,
 -                      (int)(0.5 + p->score * 100.0/MAX_SCORE));
 +              sprintf(status, "%c%03d", p->status, similarity_index(p));
        else {
                status[0] = p->status;
                status[1] = 0;
@@@ -2671,7 -2670,8 +2671,7 @@@ static void show_rename_copy(const cha
  {
        char *names = pprint_rename(p->one->path, p->two->path);
  
 -      printf(" %s %s (%d%%)\n", renamecopy, names,
 -             (int)(0.5 + p->score * 100.0/MAX_SCORE));
 +      printf(" %s %s (%d%%)\n", renamecopy, names, similarity_index(p));
        free(names);
        show_mode_change(p, 0);
  }
@@@ -2695,7 -2695,7 +2695,7 @@@ static void diff_summary(struct diff_fi
                if (p->score) {
                        char *name = quote_one(p->two->path);
                        printf(" rewrite %s (%d%%)\n", name,
 -                              (int)(0.5 + p->score * 100.0/MAX_SCORE));
 +                             similarity_index(p));
                        free(name);
                        show_mode_change(p, 0);
                } else  show_mode_change(p, 1);
@@@ -3005,6 -3005,22 +3005,22 @@@ void diffcore_std(struct diff_options *
  {
        if (options->quiet)
                return;
+       /*
+        * break/rename count similarity differently depending on
+        * the binary-ness.
+        */
+       if ((options->break_opt != -1) || (options->detect_rename)) {
+               struct diff_queue_struct *q = &diff_queued_diff;
+               int i;
+               for (i = 0; i < q->nr; i++) {
+                       struct diff_filepair *p = q->queue[i];
+                       p->one->is_binary = file_is_binary(p->one);
+                       p->two->is_binary = file_is_binary(p->two);
+               }
+       }
        if (options->break_opt != -1)
                diffcore_break(options->break_opt);
        if (options->detect_rename)
diff --combined diffcore-rename.c
index e0a89f3796890d0d23bb80b3fd6e3cac2ae1b752,cb227366b8e12cc692c968560bc550776b6c9705..6bde4396f212833cc1d411e723d5215c086e7c2d
@@@ -138,7 -138,6 +138,7 @@@ struct diff_score 
        int src; /* index in rename_src */
        int dst; /* index in rename_dst */
        int score;
 +      int name_score;
  };
  
  static int estimate_similarity(struct diff_filespec *src,
  
        delta_limit = (unsigned long)
                (base_size * (MAX_SCORE-minimum_score) / MAX_SCORE);
-       if (diffcore_count_changes(src->data, src->size,
-                                  dst->data, dst->size,
+       if (diffcore_count_changes(src, dst,
                                   &src->cnt_data, &dst->cnt_data,
                                   delta_limit,
                                   &src_copied, &literal_added))
         */
        if (!dst->size)
                score = 0; /* should not happen */
 -      else {
 +      else
                score = (int)(src_copied * MAX_SCORE / max_size);
 -              if (basename_same(src, dst))
 -                      score++;
 -      }
        return score;
  }
  
@@@ -240,10 -241,6 +239,10 @@@ static void record_rename_pair(int dst_
  static int score_compare(const void *a_, const void *b_)
  {
        const struct diff_score *a = a_, *b = b_;
 +
 +      if (a->score == b->score)
 +              return b->name_score - a->name_score;
 +
        return b->score - a->score;
  }
  
@@@ -362,7 -359,6 +361,7 @@@ void diffcore_rename(struct diff_option
                        m->dst = i;
                        m->score = estimate_similarity(one, two,
                                                       minimum_score);
 +                      m->name_score = basename_same(one, two);
                        diff_free_filespec_data(one);
                }
                /* We do not need the text anymore */