convert has_sha1_file() callers to has_object_file()
authorJeff King <peff@peff.net>
Mon, 7 Jan 2019 08:37:54 +0000 (03:37 -0500)
committerJunio C Hamano <gitster@pobox.com>
Tue, 8 Jan 2019 17:41:06 +0000 (09:41 -0800)
The only remaining callers of has_sha1_file() actually have an object_id
already. They can use the "object" variant, rather than dereferencing
the hash themselves.

The code changes here were completely generated by the included
coccinelle patch.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
12 files changed:
apply.c
builtin/fetch.c
builtin/index-pack.c
builtin/reflog.c
builtin/show-ref.c
bulk-checkin.c
cache-tree.c
contrib/coccinelle/object_id.cocci
http-walker.c
refs.c
send-pack.c
sha1-file.c
diff --git a/apply.c b/apply.c
index 01793d612620246b14fa57f6ce3ed6c33df65d0f..b8e257ead24a3fe19b0dc9585f471a70b570730f 100644 (file)
--- a/apply.c
+++ b/apply.c
@@ -3183,7 +3183,7 @@ static int apply_binary(struct apply_state *state,
                return 0; /* deletion patch */
        }
 
-       if (has_sha1_file(oid.hash)) {
+       if (has_object_file(&oid)) {
                /* We already have the postimage */
                enum object_type type;
                unsigned long size;
index e0140327aab23654c69e7388c23a07b98b8ff913..57f35c6a0af4d0f12be41ad71876911de049920b 100644 (file)
@@ -317,8 +317,7 @@ static void find_non_local_tags(const struct ref *refs,
                            !has_object_file_with_flags(&ref->old_oid,
                                                        OBJECT_INFO_QUICK) &&
                            !will_fetch(head, ref->old_oid.hash) &&
-                           !has_sha1_file_with_flags(item->oid.hash,
-                                                     OBJECT_INFO_QUICK) &&
+                           !has_object_file_with_flags(&item->oid, OBJECT_INFO_QUICK) &&
                            !will_fetch(head, item->oid.hash))
                                oidclr(&item->oid);
                        item = NULL;
@@ -332,7 +331,7 @@ static void find_non_local_tags(const struct ref *refs,
                 * fetch.
                 */
                if (item &&
-                   !has_sha1_file_with_flags(item->oid.hash, OBJECT_INFO_QUICK) &&
+                   !has_object_file_with_flags(&item->oid, OBJECT_INFO_QUICK) &&
                    !will_fetch(head, item->oid.hash))
                        oidclr(&item->oid);
 
@@ -353,7 +352,7 @@ static void find_non_local_tags(const struct ref *refs,
         * checked to see if it needs fetching.
         */
        if (item &&
-           !has_sha1_file_with_flags(item->oid.hash, OBJECT_INFO_QUICK) &&
+           !has_object_file_with_flags(&item->oid, OBJECT_INFO_QUICK) &&
            !will_fetch(head, item->oid.hash))
                oidclr(&item->oid);
 
index ac1f4ea9a782508e89f269bb1bf000a4a805c793..31046c7a0a3776fe61e81c30e83f4139e980e1c8 100644 (file)
@@ -772,7 +772,7 @@ static void sha1_object(const void *data, struct object_entry *obj_entry,
        if (startup_info->have_repository) {
                read_lock();
                collision_test_needed =
-                       has_sha1_file_with_flags(oid->hash, OBJECT_INFO_QUICK);
+                       has_object_file_with_flags(oid, OBJECT_INFO_QUICK);
                read_unlock();
        }
 
index 64a8df4f252f598ff835c39ce8a3d3d417e8a31e..45e9e15006d4e8417b51c8649823c2dd878d9f69 100644 (file)
@@ -94,7 +94,7 @@ static int tree_is_complete(const struct object_id *oid)
        init_tree_desc(&desc, tree->buffer, tree->size);
        complete = 1;
        while (tree_entry(&desc, &entry)) {
-               if (!has_sha1_file(entry.oid->hash) ||
+               if (!has_object_file(entry.oid) ||
                    (S_ISDIR(entry.mode) && !tree_is_complete(entry.oid))) {
                        tree->object.flags |= INCOMPLETE;
                        complete = 0;
index ed888ffa48ce1d5ef80859b8f5b3bf1720e49abd..6a706c02a6f9782ee4abb289cfafe468253aca1f 100644 (file)
@@ -23,7 +23,7 @@ static void show_one(const char *refname, const struct object_id *oid)
        const char *hex;
        struct object_id peeled;
 
-       if (!has_sha1_file(oid->hash))
+       if (!has_object_file(oid))
                die("git show-ref: bad ref %s (%s)", refname,
                    oid_to_hex(oid));
 
index 409ecb566b3c863e453d10650d1bb21955e2dee3..39ee7d6107c15f3e5e439992bea8a8f3413aae05 100644 (file)
@@ -67,7 +67,7 @@ static int already_written(struct bulk_checkin_state *state, struct object_id *o
        int i;
 
        /* The object may already exist in the repository */
-       if (has_sha1_file(oid->hash))
+       if (has_object_file(oid))
                return 1;
 
        /* Might want to keep the list sorted */
index 190c6e5aa6bbc79f5267fa96e3c14ed2438c0488..47f3464a1f25a3e2b73b060b1841c695f1825c9c 100644 (file)
@@ -225,7 +225,7 @@ int cache_tree_fully_valid(struct cache_tree *it)
        int i;
        if (!it)
                return 0;
-       if (it->entry_count < 0 || !has_sha1_file(it->oid.hash))
+       if (it->entry_count < 0 || !has_object_file(&it->oid))
                return 0;
        for (i = 0; i < it->subtree_nr; i++) {
                if (!cache_tree_fully_valid(it->down[i]->cache_tree))
@@ -253,7 +253,7 @@ static int update_one(struct cache_tree *it,
 
        *skip_count = 0;
 
-       if (0 <= it->entry_count && has_sha1_file(it->oid.hash))
+       if (0 <= it->entry_count && has_object_file(&it->oid))
                return it->entry_count;
 
        /*
index 6a7cf3e02da832b3a2829178b968b57f3b80d081..73886ae5832e8dee5a0869009c7d9bddde76c008 100644 (file)
@@ -147,3 +147,35 @@ expression E1, E2;
 - hashcmp(E1, E2) != 0
 + !hasheq(E1, E2)
   ...>}
+
+@@
+struct object_id OID;
+@@
+- has_sha1_file(OID.hash)
++ has_object_file(&OID)
+
+@@
+identifier f != has_object_file;
+struct object_id *OIDPTR;
+@@
+  f(...) {<...
+- has_sha1_file(OIDPTR->hash)
++ has_object_file(OIDPTR)
+  ...>}
+
+@@
+struct object_id OID;
+expression E;
+@@
+- has_sha1_file_with_flags(OID.hash, E)
++ has_object_file_with_flags(&OID, E)
+
+@@
+identifier f != has_object_file_with_flags;
+struct object_id *OIDPTR;
+expression E;
+@@
+  f(...) {<...
+- has_sha1_file_with_flags(OIDPTR->hash, E)
++ has_object_file_with_flags(OIDPTR, E)
+  ...>}
index 29b59e2fe0be45d9c1d4d439062fc54bda370f42..8ae5d76c6aa216e92c26b875f72b7bb991b6e3cd 100644 (file)
@@ -131,7 +131,7 @@ static int fill_active_slot(struct walker *walker)
        list_for_each_safe(pos, tmp, head) {
                obj_req = list_entry(pos, struct object_request, node);
                if (obj_req->state == WAITING) {
-                       if (has_sha1_file(obj_req->oid.hash))
+                       if (has_object_file(&obj_req->oid))
                                obj_req->state = COMPLETE;
                        else {
                                start_object_request(walker, obj_req);
@@ -489,7 +489,7 @@ static int fetch_object(struct walker *walker, unsigned char *sha1)
        if (obj_req == NULL)
                return error("Couldn't find request for %s in the queue", hex);
 
-       if (has_sha1_file(obj_req->oid.hash)) {
+       if (has_object_file(&obj_req->oid)) {
                if (obj_req->req != NULL)
                        abort_http_object_request(obj_req->req);
                abort_object_request(obj_req);
diff --git a/refs.c b/refs.c
index f9936355cda6a1515f3192151f7fc14d0c2d7522..142888a40a611370240864e2f27f097832db11e9 100644 (file)
--- a/refs.c
+++ b/refs.c
@@ -188,7 +188,7 @@ int ref_resolves_to_object(const char *refname,
 {
        if (flags & REF_ISBROKEN)
                return 0;
-       if (!has_sha1_file(oid->hash)) {
+       if (!has_object_file(oid)) {
                error(_("%s does not point to a valid object!"), refname);
                return 0;
        }
index f692686770f69b49d44bf6dbabdb17886d85ea1a..c673d3ed06059301adf1e9a1257f32ab849850f8 100644 (file)
@@ -40,7 +40,7 @@ int option_parse_push_signed(const struct option *opt,
 
 static void feed_object(const struct object_id *oid, FILE *fh, int negative)
 {
-       if (negative && !has_sha1_file(oid->hash))
+       if (negative && !has_object_file(oid))
                return;
 
        if (negative)
index 73e5cc6fa564a1aa45c0b23c79effcced54540b4..95186c019a1572cba6a428392c6256b3fd9bf088 100644 (file)
@@ -1372,7 +1372,7 @@ int pretend_object_file(void *buf, unsigned long len, enum object_type type,
        struct cached_object *co;
 
        hash_object_file(buf, len, type_name(type), oid);
-       if (has_sha1_file(oid->hash) || find_cached_object(oid))
+       if (has_object_file(oid) || find_cached_object(oid))
                return 0;
        ALLOC_GROW(cached_objects, cached_object_nr + 1, cached_object_alloc);
        co = &cached_objects[cached_object_nr++];