]> git.ipfire.org Git - thirdparty/git.git/blobdiff - diff.c
Merge branch 'jt/delay-fetch-if-missing'
[thirdparty/git.git] / diff.c
diff --git a/diff.c b/diff.c
index 5eaf689fccf39bc6f69de5efc1e09d244860b63f..afe4400a60e072f42e090f87aa32e84653edfd0a 100644 (file)
--- a/diff.c
+++ b/diff.c
@@ -25,7 +25,7 @@
 #include "packfile.h"
 #include "parse-options.h"
 #include "help.h"
-#include "fetch-object.h"
+#include "promisor-remote.h"
 
 #ifdef NO_FAST_WORKING_DIRECTORY
 #define FAST_WORKING_DIRECTORY 0
@@ -1038,7 +1038,7 @@ static void pmb_advance_or_null_multi_match(struct diff_options *o,
        int i;
        char *got_match = xcalloc(1, pmb_nr);
 
-       hashmap_for_each_entry_from(hm, match, struct moved_entry, ent) {
+       hashmap_for_each_entry_from(hm, match, ent) {
                for (i = 0; i < pmb_nr; i++) {
                        struct moved_entry *prev = pmb[i].match;
                        struct moved_entry *cur = (prev && prev->next_line) ?
@@ -1146,15 +1146,13 @@ static void mark_color_as_moved(struct diff_options *o,
                case DIFF_SYMBOL_PLUS:
                        hm = del_lines;
                        key = prepare_entry(o, n);
-                       match = hashmap_get_entry(hm, key, NULL,
-                                               struct moved_entry, ent);
+                       match = hashmap_get_entry(hm, key, ent, NULL);
                        free(key);
                        break;
                case DIFF_SYMBOL_MINUS:
                        hm = add_lines;
                        key = prepare_entry(o, n);
-                       match = hashmap_get_entry(hm, key, NULL,
-                                               struct moved_entry, ent);
+                       match = hashmap_get_entry(hm, key, ent, NULL);
                        free(key);
                        break;
                default:
@@ -1193,8 +1191,7 @@ static void mark_color_as_moved(struct diff_options *o,
                         * The current line is the start of a new block.
                         * Setup the set of potential blocks.
                         */
-                       hashmap_for_each_entry_from(hm, match,
-                                               struct moved_entry, ent) {
+                       hashmap_for_each_entry_from(hm, match, ent) {
                                ALLOC_GROW(pmb, pmb_nr + 1, pmb_alloc);
                                if (o->color_moved_ws_handling &
                                    COLOR_MOVED_WS_ALLOW_INDENTATION_CHANGE) {
@@ -5984,7 +5981,7 @@ static void diff_summary(struct diff_options *opt, struct diff_filepair *p)
 }
 
 struct patch_id_t {
-       git_SHA_CTX *ctx;
+       git_hash_ctx *ctx;
        int patchlen;
 };
 
@@ -6001,16 +5998,16 @@ static int remove_space(char *line, int len)
        return dst - line;
 }
 
-void flush_one_hunk(struct object_id *result, git_SHA_CTX *ctx)
+void flush_one_hunk(struct object_id *result, git_hash_ctx *ctx)
 {
        unsigned char hash[GIT_MAX_RAWSZ];
        unsigned short carry = 0;
        int i;
 
-       git_SHA1_Final(hash, ctx);
-       git_SHA1_Init(ctx);
+       the_hash_algo->final_fn(hash, ctx);
+       the_hash_algo->init_fn(ctx);
        /* 20-byte sum, with carry */
-       for (i = 0; i < GIT_SHA1_RAWSZ; ++i) {
+       for (i = 0; i < the_hash_algo->rawsz; ++i) {
                carry += result->hash[i] + hash[i];
                result->hash[i] = carry;
                carry >>= 8;
@@ -6024,21 +6021,21 @@ static void patch_id_consume(void *priv, char *line, unsigned long len)
 
        new_len = remove_space(line, len);
 
-       git_SHA1_Update(data->ctx, line, new_len);
+       the_hash_algo->update_fn(data->ctx, line, new_len);
        data->patchlen += new_len;
 }
 
-static void patch_id_add_string(git_SHA_CTX *ctx, const char *str)
+static void patch_id_add_string(git_hash_ctx *ctx, const char *str)
 {
-       git_SHA1_Update(ctx, str, strlen(str));
+       the_hash_algo->update_fn(ctx, str, strlen(str));
 }
 
-static void patch_id_add_mode(git_SHA_CTX *ctx, unsigned mode)
+static void patch_id_add_mode(git_hash_ctx *ctx, unsigned mode)
 {
        /* large enough for 2^32 in octal */
        char buf[12];
        int len = xsnprintf(buf, sizeof(buf), "%06o", mode);
-       git_SHA1_Update(ctx, buf, len);
+       the_hash_algo->update_fn(ctx, buf, len);
 }
 
 /* returns 0 upon success, and writes result into oid */
@@ -6046,10 +6043,10 @@ static int diff_get_patch_id(struct diff_options *options, struct object_id *oid
 {
        struct diff_queue_struct *q = &diff_queued_diff;
        int i;
-       git_SHA_CTX ctx;
+       git_hash_ctx ctx;
        struct patch_id_t data;
 
-       git_SHA1_Init(&ctx);
+       the_hash_algo->init_fn(&ctx);
        memset(&data, 0, sizeof(struct patch_id_t));
        data.ctx = &ctx;
        oidclr(oid);
@@ -6082,27 +6079,27 @@ static int diff_get_patch_id(struct diff_options *options, struct object_id *oid
                len2 = remove_space(p->two->path, strlen(p->two->path));
                patch_id_add_string(&ctx, "diff--git");
                patch_id_add_string(&ctx, "a/");
-               git_SHA1_Update(&ctx, p->one->path, len1);
+               the_hash_algo->update_fn(&ctx, p->one->path, len1);
                patch_id_add_string(&ctx, "b/");
-               git_SHA1_Update(&ctx, p->two->path, len2);
+               the_hash_algo->update_fn(&ctx, p->two->path, len2);
 
                if (p->one->mode == 0) {
                        patch_id_add_string(&ctx, "newfilemode");
                        patch_id_add_mode(&ctx, p->two->mode);
                        patch_id_add_string(&ctx, "---/dev/null");
                        patch_id_add_string(&ctx, "+++b/");
-                       git_SHA1_Update(&ctx, p->two->path, len2);
+                       the_hash_algo->update_fn(&ctx, p->two->path, len2);
                } else if (p->two->mode == 0) {
                        patch_id_add_string(&ctx, "deletedfilemode");
                        patch_id_add_mode(&ctx, p->one->mode);
                        patch_id_add_string(&ctx, "---a/");
-                       git_SHA1_Update(&ctx, p->one->path, len1);
+                       the_hash_algo->update_fn(&ctx, p->one->path, len1);
                        patch_id_add_string(&ctx, "+++/dev/null");
                } else {
                        patch_id_add_string(&ctx, "---a/");
-                       git_SHA1_Update(&ctx, p->one->path, len1);
+                       the_hash_algo->update_fn(&ctx, p->one->path, len1);
                        patch_id_add_string(&ctx, "+++b/");
-                       git_SHA1_Update(&ctx, p->two->path, len2);
+                       the_hash_algo->update_fn(&ctx, p->two->path, len2);
                }
 
                if (diff_header_only)
@@ -6114,10 +6111,10 @@ static int diff_get_patch_id(struct diff_options *options, struct object_id *oid
 
                if (diff_filespec_is_binary(options->repo, p->one) ||
                    diff_filespec_is_binary(options->repo, p->two)) {
-                       git_SHA1_Update(&ctx, oid_to_hex(&p->one->oid),
-                                       GIT_SHA1_HEXSZ);
-                       git_SHA1_Update(&ctx, oid_to_hex(&p->two->oid),
-                                       GIT_SHA1_HEXSZ);
+                       the_hash_algo->update_fn(&ctx, oid_to_hex(&p->one->oid),
+                                       the_hash_algo->hexsz);
+                       the_hash_algo->update_fn(&ctx, oid_to_hex(&p->two->oid),
+                                       the_hash_algo->hexsz);
                        continue;
                }
 
@@ -6134,7 +6131,7 @@ static int diff_get_patch_id(struct diff_options *options, struct object_id *oid
        }
 
        if (!stable)
-               git_SHA1_Final(oid->hash, &ctx);
+               the_hash_algo->final_fn(oid->hash, &ctx);
 
        return 0;
 }
@@ -6236,8 +6233,10 @@ static void diff_flush_patch_all_file_pairs(struct diff_options *o)
                        if (o->color_moved == COLOR_MOVED_ZEBRA_DIM)
                                dim_moved_lines(o);
 
-                       hashmap_free(&add_lines, 1);
-                       hashmap_free(&del_lines, 1);
+                       hashmap_free_entries(&add_lines, struct moved_entry,
+                                               ent);
+                       hashmap_free_entries(&del_lines, struct moved_entry,
+                                               ent);
                }
 
                for (i = 0; i < esm.nr; i++)
@@ -6518,6 +6517,7 @@ static void add_if_missing(struct repository *r,
                           const struct diff_filespec *filespec)
 {
        if (filespec && filespec->oid_valid &&
+           !S_ISGITLINK(filespec->mode) &&
            oid_object_info_extended(r, &filespec->oid, NULL,
                                     OBJECT_INFO_FOR_PREFETCH))
                oid_array_append(to_fetch, &filespec->oid);
@@ -6525,8 +6525,7 @@ static void add_if_missing(struct repository *r,
 
 void diffcore_std(struct diff_options *options)
 {
-       if (options->repo == the_repository &&
-           repository_format_partial_clone) {
+       if (options->repo == the_repository && has_promisor_remote()) {
                /*
                 * Prefetch the diff pairs that are about to be flushed.
                 */
@@ -6543,8 +6542,8 @@ void diffcore_std(struct diff_options *options)
                        /*
                         * NEEDSWORK: Consider deduplicating the OIDs sent.
                         */
-                       fetch_objects(repository_format_partial_clone,
-                                     to_fetch.oid, to_fetch.nr);
+                       promisor_remote_get_direct(options->repo,
+                                                  to_fetch.oid, to_fetch.nr);
                oid_array_clear(&to_fetch);
        }