THIS IS A TEST INSTANCE ONLY! REPOSITORIES CAN BE DELETED AT ANY TIME!

Parcourir la source

convert "hashcmp() != 0" to "!hasheq()"

This rounds out the previous three patches, covering the
inequality logic for the "hash" variant of the functions.

As with the previous three, the accompanying code changes
are the mechanical result of applying the coccinelle patch;
see those patches for more discussion.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
tags/v2.20.0-rc0
Jeff King Junio C Hamano il y a 1 an
Parent
révision
67947c34ae
12 fichiers modifiés avec 24 ajouts et 15 suppressions
  1. +2
    -2
      builtin/index-pack.c
  2. +1
    -1
      builtin/show-branch.c
  3. +1
    -1
      builtin/unpack-objects.c
  4. +1
    -1
      commit-graph.c
  5. +9
    -0
      contrib/coccinelle/object_id.cocci
  6. +1
    -1
      http-walker.c
  7. +1
    -1
      http.c
  8. +3
    -3
      pack-check.c
  9. +1
    -1
      pack-write.c
  10. +1
    -1
      packfile.c
  11. +2
    -2
      read-cache.c
  12. +1
    -1
      sha1-file.c

+ 2
- 2
builtin/index-pack.c Voir le fichier

@@ -1166,7 +1166,7 @@ static void parse_pack_objects(unsigned char *hash)
/* Check pack integrity */
flush();
the_hash_algo->final_fn(hash, &input_ctx);
if (hashcmp(fill(the_hash_algo->rawsz), hash))
if (!hasheq(fill(the_hash_algo->rawsz), hash))
die(_("pack is corrupted (SHA1 mismatch)"));
use(the_hash_algo->rawsz);

@@ -1280,7 +1280,7 @@ static void conclude_pack(int fix_thin_pack, const char *curr_pack, unsigned cha
fixup_pack_header_footer(output_fd, pack_hash,
curr_pack, nr_objects,
read_hash, consumed_bytes-the_hash_algo->rawsz);
if (hashcmp(read_hash, tail_hash) != 0)
if (!hasheq(read_hash, tail_hash))
die(_("Unexpected tail checksum for %s "
"(disk corruption?)"), curr_pack);
}


+ 1
- 1
builtin/show-branch.c Voir le fichier

@@ -485,7 +485,7 @@ static void snarf_refs(int head, int remotes)
static int rev_is_head(const char *head, const char *name,
unsigned char *head_sha1, unsigned char *sha1)
{
if (!head || (head_sha1 && sha1 && hashcmp(head_sha1, sha1)))
if (!head || (head_sha1 && sha1 && !hasheq(head_sha1, sha1)))
return 0;
skip_prefix(head, "refs/heads/", &head);
if (!skip_prefix(name, "refs/heads/", &name))


+ 1
- 1
builtin/unpack-objects.c Voir le fichier

@@ -579,7 +579,7 @@ int cmd_unpack_objects(int argc, const char **argv, const char *prefix)
if (fsck_finish(&fsck_options))
die(_("fsck error in pack objects"));
}
if (hashcmp(fill(the_hash_algo->rawsz), oid.hash))
if (!hasheq(fill(the_hash_algo->rawsz), oid.hash))
die("final sha1 did not match");
use(the_hash_algo->rawsz);



+ 1
- 1
commit-graph.c Voir le fichier

@@ -900,7 +900,7 @@ int verify_commit_graph(struct repository *r, struct commit_graph *g)
f = hashfd(devnull, NULL);
hashwrite(f, g->data, g->data_len - g->hash_len);
finalize_hashfile(f, checksum.hash, CSUM_CLOSE);
if (hashcmp(checksum.hash, g->data + g->data_len - g->hash_len)) {
if (!hasheq(checksum.hash, g->data + g->data_len - g->hash_len)) {
graph_report(_("the commit-graph file has incorrect checksum and is likely corrupt"));
verify_commit_graph_error = VERIFY_COMMIT_GRAPH_ERROR_HASH;
}


+ 9
- 0
contrib/coccinelle/object_id.cocci Voir le fichier

@@ -129,3 +129,12 @@ expression E1, E2;
@@
- oidcmp(E1, E2) != 0
+ !oideq(E1, E2)

@@
identifier f != hasheq;
expression E1, E2;
@@
f(...) {<...
- hashcmp(E1, E2) != 0
+ !hasheq(E1, E2)
...>}

+ 1
- 1
http-walker.c Voir le fichier

@@ -543,7 +543,7 @@ static int fetch_object(struct walker *walker, unsigned char *sha1)
} else if (req->zret != Z_STREAM_END) {
walker->corrupt_object_found++;
ret = error("File %s (%s) corrupt", hex, req->url);
} else if (hashcmp(obj_req->oid.hash, req->real_sha1)) {
} else if (!hasheq(obj_req->oid.hash, req->real_sha1)) {
ret = error("File %s has bad hash", hex);
} else if (req->rename < 0) {
struct strbuf buf = STRBUF_INIT;


+ 1
- 1
http.c Voir le fichier

@@ -2394,7 +2394,7 @@ int finish_http_object_request(struct http_object_request *freq)
unlink_or_warn(freq->tmpfile.buf);
return -1;
}
if (hashcmp(freq->sha1, freq->real_sha1)) {
if (!hasheq(freq->sha1, freq->real_sha1)) {
unlink_or_warn(freq->tmpfile.buf);
return -1;
}


+ 3
- 3
pack-check.c Voir le fichier

@@ -79,10 +79,10 @@ static int verify_packfile(struct packed_git *p,
} while (offset < pack_sig_ofs);
the_hash_algo->final_fn(hash, &ctx);
pack_sig = use_pack(p, w_curs, pack_sig_ofs, NULL);
if (hashcmp(hash, pack_sig))
if (!hasheq(hash, pack_sig))
err = error("%s pack checksum mismatch",
p->pack_name);
if (hashcmp(index_base + index_size - the_hash_algo->hexsz, pack_sig))
if (!hasheq(index_base + index_size - the_hash_algo->hexsz, pack_sig))
err = error("%s pack checksum does not match its index",
p->pack_name);
unuse_pack(w_curs);
@@ -180,7 +180,7 @@ int verify_pack_index(struct packed_git *p)
the_hash_algo->init_fn(&ctx);
the_hash_algo->update_fn(&ctx, index_base, (unsigned int)(index_size - the_hash_algo->rawsz));
the_hash_algo->final_fn(hash, &ctx);
if (hashcmp(hash, index_base + index_size - the_hash_algo->rawsz))
if (!hasheq(hash, index_base + index_size - the_hash_algo->rawsz))
err = error("Packfile index for %s hash mismatch",
p->pack_name);
return err;


+ 1
- 1
pack-write.c Voir le fichier

@@ -260,7 +260,7 @@ void fixup_pack_header_footer(int pack_fd,
if (partial_pack_offset == 0) {
unsigned char hash[GIT_MAX_RAWSZ];
the_hash_algo->final_fn(hash, &old_hash_ctx);
if (hashcmp(hash, partial_pack_hash) != 0)
if (!hasheq(hash, partial_pack_hash))
die("Unexpected checksum for %s "
"(disk corruption?)", pack_name);
/*


+ 1
- 1
packfile.c Voir le fichier

@@ -517,7 +517,7 @@ static int open_packed_git_1(struct packed_git *p)
if (read_result != hashsz)
return error("packfile %s signature is unavailable", p->pack_name);
idx_hash = ((unsigned char *)p->index_data) + p->index_size - hashsz * 2;
if (hashcmp(hash, idx_hash))
if (!hasheq(hash, idx_hash))
return error("packfile %s does not match index", p->pack_name);
return 0;
}


+ 2
- 2
read-cache.c Voir le fichier

@@ -1668,7 +1668,7 @@ static int verify_hdr(struct cache_header *hdr, unsigned long size)
the_hash_algo->init_fn(&c);
the_hash_algo->update_fn(&c, hdr, size - the_hash_algo->rawsz);
the_hash_algo->final_fn(hash, &c);
if (hashcmp(hash, (unsigned char *)hdr + size - the_hash_algo->rawsz))
if (!hasheq(hash, (unsigned char *)hdr + size - the_hash_algo->rawsz))
return error("bad index file sha1 signature");
return 0;
}
@@ -2395,7 +2395,7 @@ static int verify_index_from(const struct index_state *istate, const char *path)
if (n != the_hash_algo->rawsz)
goto out;

if (hashcmp(istate->oid.hash, hash))
if (!hasheq(istate->oid.hash, hash))
goto out;

close(fd);


+ 1
- 1
sha1-file.c Voir le fichier

@@ -2213,7 +2213,7 @@ static int check_stream_sha1(git_zstream *stream,
}

the_hash_algo->final_fn(real_sha1, &c);
if (hashcmp(expected_sha1, real_sha1)) {
if (!hasheq(expected_sha1, real_sha1)) {
error(_("sha1 mismatch for %s (expected %s)"), path,
sha1_to_hex(expected_sha1));
return -1;


Chargement…
Annuler
Enregistrer