tree-diff: move all action-taking code out of compare_tree_entry()
[gitweb.git] / diff-lib.c
index f35de0ffa0ec263acae7ac6211e3c2817987f760..bf624e77161d3337746bd5f5e8719c97cff1fbbd 100644 (file)
@@ -64,8 +64,9 @@ static int check_removed(const struct cache_entry *ce, struct stat *st)
  * commits, untracked content and/or modified content).
  */
 static int match_stat_with_submodule(struct diff_options *diffopt,
-                                     struct cache_entry *ce, struct stat *st,
-                                     unsigned ce_option, unsigned *dirty_submodule)
+                                    const struct cache_entry *ce,
+                                    struct stat *st, unsigned ce_option,
+                                    unsigned *dirty_submodule)
 {
        int changed = ce_match_stat(ce, st, ce_option);
        if (S_ISGITLINK(ce->ce_mode)) {
@@ -86,10 +87,12 @@ int run_diff_files(struct rev_info *revs, unsigned int option)
 {
        int entries, i;
        int diff_unmerged_stage = revs->max_count;
-       int silent_on_removed = option & DIFF_SILENT_ON_REMOVED;
        unsigned ce_option = ((option & DIFF_RACY_IS_MODIFIED)
                              ? CE_MATCH_RACY_IS_DIRTY : 0);
 
+       if (option & DIFF_SILENT_ON_REMOVED)
+               handle_deprecated_show_diff_q(&revs->diffopt);
+
        diff_set_mnemonic_prefix(&revs->diffopt, "i/", "w/");
 
        if (diff_unmerged_stage < 0)
@@ -121,7 +124,6 @@ int run_diff_files(struct rev_info *revs, unsigned int option)
                        dpath->path = (char *) &(dpath->parent[5]);
 
                        dpath->next = NULL;
-                       dpath->len = path_len;
                        memcpy(dpath->path, ce->name, path_len);
                        dpath->path[path_len] = '\0';
                        hashclr(dpath->sha1);
@@ -136,8 +138,6 @@ int run_diff_files(struct rev_info *revs, unsigned int option)
                                        perror(ce->name);
                                        continue;
                                }
-                               if (silent_on_removed)
-                                       continue;
                                wt_mode = 0;
                        }
                        dpath->mode = wt_mode;
@@ -203,8 +203,6 @@ int run_diff_files(struct rev_info *revs, unsigned int option)
                                perror(ce->name);
                                continue;
                        }
-                       if (silent_on_removed)
-                               continue;
                        diff_addremove(&revs->diffopt, '-', ce->ce_mode,
                                       ce->sha1, !is_null_sha1(ce->sha1),
                                       ce->name, 0);
@@ -237,7 +235,7 @@ int run_diff_files(struct rev_info *revs, unsigned int option)
 /* A file entry went away or appeared */
 static void diff_index_show_file(struct rev_info *revs,
                                 const char *prefix,
-                                struct cache_entry *ce,
+                                const struct cache_entry *ce,
                                 const unsigned char *sha1, int sha1_valid,
                                 unsigned int mode,
                                 unsigned dirty_submodule)
@@ -246,7 +244,7 @@ static void diff_index_show_file(struct rev_info *revs,
                       sha1, sha1_valid, ce->name, dirty_submodule);
 }
 
-static int get_stat_data(struct cache_entry *ce,
+static int get_stat_data(const struct cache_entry *ce,
                         const unsigned char **sha1p,
                         unsigned int *modep,
                         int cached, int match_missing,
@@ -283,7 +281,7 @@ static int get_stat_data(struct cache_entry *ce,
 }
 
 static void show_new_file(struct rev_info *revs,
-                         struct cache_entry *new,
+                         const struct cache_entry *new,
                          int cached, int match_missing)
 {
        const unsigned char *sha1;
@@ -302,8 +300,8 @@ static void show_new_file(struct rev_info *revs,
 }
 
 static int show_modified(struct rev_info *revs,
-                        struct cache_entry *old,
-                        struct cache_entry *new,
+                        const struct cache_entry *old,
+                        const struct cache_entry *new,
                         int report_missing,
                         int cached, int match_missing)
 {
@@ -327,7 +325,6 @@ static int show_modified(struct rev_info *revs,
                p = xmalloc(combine_diff_path_size(2, pathlen));
                p->path = (char *) &p->parent[2];
                p->next = NULL;
-               p->len = pathlen;
                memcpy(p->path, new->name, pathlen);
                p->path[pathlen] = 0;
                p->mode = mode;
@@ -362,8 +359,8 @@ static int show_modified(struct rev_info *revs,
  * give you the position and number of entries in the index).
  */
 static void do_oneway_diff(struct unpack_trees_options *o,
-       struct cache_entry *idx,
-       struct cache_entry *tree)
+                          const struct cache_entry *idx,
+                          const struct cache_entry *tree)
 {
        struct rev_info *revs = o->unpack_data;
        int match_missing, cached;
@@ -423,10 +420,11 @@ static void do_oneway_diff(struct unpack_trees_options *o,
  * the fairly complex unpack_trees() semantic requirements, including
  * the skipping, the path matching, the type conflict cases etc.
  */
-static int oneway_diff(struct cache_entry **src, struct unpack_trees_options *o)
+static int oneway_diff(const struct cache_entry * const *src,
+                      struct unpack_trees_options *o)
 {
-       struct cache_entry *idx = src[0];
-       struct cache_entry *tree = src[1];
+       const struct cache_entry *idx = src[0];
+       const struct cache_entry *tree = src[1];
        struct rev_info *revs = o->unpack_data;
 
        /*
@@ -474,7 +472,6 @@ static int diff_cache(struct rev_info *revs,
        opts.dst_index = NULL;
        opts.pathspec = &revs->diffopt.pathspec;
        opts.pathspec->recursive = 1;
-       opts.pathspec->max_depth = -1;
 
        init_tree_desc(&t, tree->buffer, tree->size);
        return unpack_trees(1, &t, &opts);
@@ -500,7 +497,7 @@ int do_diff_cache(const unsigned char *tree_sha1, struct diff_options *opt)
        struct rev_info revs;
 
        init_revisions(&revs, NULL);
-       init_pathspec(&revs.prune_data, opt->pathspec.raw);
+       copy_pathspec(&revs.prune_data, &opt->pathspec);
        revs.diffopt = *opt;
 
        if (diff_cache(&revs, tree_sha1, NULL, 1))