packed_ref_store: move `packed_refs_path` here
[gitweb.git] / diff-lib.c
index 3007c8524c9b8017cb3dc3f7460e020b0d1aafd7..2982bf055acb6049a8cd6007244d60d985b7e619 100644 (file)
@@ -214,6 +214,12 @@ int run_diff_files(struct rev_info *revs, unsigned int option)
                                               !is_null_oid(&ce->oid),
                                               ce->name, 0);
                                continue;
+                       } else if (revs->diffopt.ita_invisible_in_index &&
+                                  ce_intent_to_add(ce)) {
+                               diff_addremove(&revs->diffopt, '+', ce->ce_mode,
+                                              EMPTY_BLOB_SHA1_BIN, 0,
+                                              ce->name, 0);
+                               continue;
                        }
 
                        changed = match_stat_with_submodule(&revs->diffopt, ce, &st,
@@ -379,6 +385,14 @@ static void do_oneway_diff(struct unpack_trees_options *o,
        struct rev_info *revs = o->unpack_data;
        int match_missing, cached;
 
+       /* i-t-a entries do not actually exist in the index */
+       if (revs->diffopt.ita_invisible_in_index &&
+           idx && ce_intent_to_add(idx)) {
+               idx = NULL;
+               if (!tree)
+                       return; /* nothing to diff.. */
+       }
+
        /* if the entry is not checked out, don't examine work tree */
        cached = o->index_only ||
                (idx && ((idx->ce_flags & CE_VALID) || ce_skip_worktree(idx)));
@@ -464,7 +478,7 @@ static int oneway_diff(const struct cache_entry * const *src,
 }
 
 static int diff_cache(struct rev_info *revs,
-                     const unsigned char *tree_sha1,
+                     const struct object_id *tree_oid,
                      const char *tree_name,
                      int cached)
 {
@@ -472,10 +486,10 @@ static int diff_cache(struct rev_info *revs,
        struct tree_desc t;
        struct unpack_trees_options opts;
 
-       tree = parse_tree_indirect(tree_sha1);
+       tree = parse_tree_indirect(tree_oid);
        if (!tree)
                return error("bad tree object %s",
-                            tree_name ? tree_name : sha1_to_hex(tree_sha1));
+                            tree_name ? tree_name : oid_to_hex(tree_oid));
        memset(&opts, 0, sizeof(opts));
        opts.head_idx = 1;
        opts.index_only = cached;
@@ -498,7 +512,7 @@ int run_diff_index(struct rev_info *revs, int cached)
        struct object_array_entry *ent;
 
        ent = revs->pending.objects;
-       if (diff_cache(revs, ent->item->oid.hash, ent->name, cached))
+       if (diff_cache(revs, &ent->item->oid, ent->name, cached))
                exit(128);
 
        diff_set_mnemonic_prefix(&revs->diffopt, "c/", cached ? "i/" : "w/");
@@ -508,7 +522,7 @@ int run_diff_index(struct rev_info *revs, int cached)
        return 0;
 }
 
-int do_diff_cache(const unsigned char *tree_sha1, struct diff_options *opt)
+int do_diff_cache(const struct object_id *tree_oid, struct diff_options *opt)
 {
        struct rev_info revs;
 
@@ -516,12 +530,13 @@ int do_diff_cache(const unsigned char *tree_sha1, struct diff_options *opt)
        copy_pathspec(&revs.prune_data, &opt->pathspec);
        revs.diffopt = *opt;
 
-       if (diff_cache(&revs, tree_sha1, NULL, 1))
+       if (diff_cache(&revs, tree_oid, NULL, 1))
                exit(128);
        return 0;
 }
 
-int index_differs_from(const char *def, int diff_flags)
+int index_differs_from(const char *def, int diff_flags,
+                      int ita_invisible_in_index)
 {
        struct rev_info rev;
        struct setup_revision_opt opt;
@@ -533,6 +548,7 @@ int index_differs_from(const char *def, int diff_flags)
        DIFF_OPT_SET(&rev.diffopt, QUICK);
        DIFF_OPT_SET(&rev.diffopt, EXIT_WITH_STATUS);
        rev.diffopt.flags |= diff_flags;
+       rev.diffopt.ita_invisible_in_index = ita_invisible_in_index;
        run_diff_index(&rev, 1);
        if (rev.pending.alloc)
                free(rev.pending.objects);