optimize diffcore-delta by sorting hash entries.
[gitweb.git] / diff-lib.c
index 7531e20c784c44c0b5d3ecb2057638874a09ce6c..da5571302df6ed418874fd4d7423853a7de5b52c 100644 (file)
@@ -24,7 +24,7 @@ static int read_directory(const char *path, struct path_list *list)
 
        while ((e = readdir(dir)))
                if (strcmp(".", e->d_name) && strcmp("..", e->d_name))
-                       path_list_insert(xstrdup(e->d_name), list);
+                       path_list_insert(e->d_name, list);
 
        closedir(dir);
        return 0;
@@ -189,6 +189,7 @@ static int handle_diff_files_args(struct rev_info *revs,
                                !strcmp(argv[1], "--no-index")) {
                        revs->max_count = -2;
                        revs->diffopt.exit_with_status = 1;
+                       revs->diffopt.no_index = 1;
                }
                else if (!strcmp(argv[1], "-q"))
                        *silent = 1;
@@ -204,8 +205,10 @@ static int handle_diff_files_args(struct rev_info *revs,
                 */
                read_cache();
                if (!is_in_index(revs->diffopt.paths[0]) ||
-                                       !is_in_index(revs->diffopt.paths[1]))
+                                       !is_in_index(revs->diffopt.paths[1])) {
                        revs->max_count = -2;
+                       revs->diffopt.no_index = 1;
+               }
        }
 
        /*
@@ -293,7 +296,10 @@ int setup_diff_no_index(struct rev_info *revs,
        else
                revs->diffopt.paths = argv + argc - 2;
        revs->diffopt.nr_paths = 2;
+       revs->diffopt.no_index = 1;
        revs->max_count = -2;
+       if (diff_setup_done(&revs->diffopt) < 0)
+               die("diff_setup_done failed");
        return 0;
 }
 
@@ -304,7 +310,7 @@ int run_diff_files_cmd(struct rev_info *revs, int argc, const char **argv)
        if (handle_diff_files_args(revs, argc, argv, &silent_on_removed))
                return -1;
 
-       if (revs->max_count == -2) {
+       if (revs->diffopt.no_index) {
                if (revs->diffopt.nr_paths != 2)
                        return error("need two files/directories with --no-index");
                if (queue_diff(&revs->diffopt, revs->diffopt.paths[0],
@@ -373,7 +379,7 @@ int run_diff_files(struct rev_info *revs, int silent_on_removed)
                                        continue;
                        }
                        else
-                               dpath->mode = canon_mode(st.st_mode);
+                               dpath->mode = ntohl(ce_mode_from_stat(ce, st.st_mode));
 
                        while (i < entries) {
                                struct cache_entry *nce = active_cache[i];
@@ -390,8 +396,7 @@ int run_diff_files(struct rev_info *revs, int silent_on_removed)
                                        int mode = ntohl(nce->ce_mode);
                                        num_compare_stages++;
                                        hashcpy(dpath->parent[stage-2].sha1, nce->sha1);
-                                       dpath->parent[stage-2].mode =
-                                               canon_mode(mode);
+                                       dpath->parent[stage-2].mode = ntohl(ce_mode_from_stat(nce, mode));
                                        dpath->parent[stage-2].status =
                                                DIFF_STATUS_MODIFIED;
                                }
@@ -440,15 +445,7 @@ int run_diff_files(struct rev_info *revs, int silent_on_removed)
                if (!changed && !revs->diffopt.find_copies_harder)
                        continue;
                oldmode = ntohl(ce->ce_mode);
-
-               newmode = canon_mode(st.st_mode);
-               if (!trust_executable_bit &&
-                   S_ISREG(newmode) && S_ISREG(oldmode) &&
-                   ((newmode ^ oldmode) == 0111))
-                       newmode = oldmode;
-               else if (!has_symlinks &&
-                   S_ISREG(newmode) && S_ISLNK(oldmode))
-                       newmode = oldmode;
+               newmode = ntohl(ce_mode_from_stat(ce, st.st_mode));
                diff_change(&revs->diffopt, oldmode, newmode,
                            ce->sha1, (changed ? null_sha1 : ce->sha1),
                            ce->name, NULL);
@@ -673,7 +670,7 @@ int run_diff_index(struct rev_info *revs, int cached)
        const char *tree_name;
        int match_missing = 0;
 
-       /* 
+       /*
         * Backward compatibility wart - "diff-index -m" does
         * not mean "do not ignore merges", but totally different.
         */