]> git.ipfire.org Git - thirdparty/git.git/commitdiff
parse_object(): check commit-graph when skip_hash set
authorJeff King <peff@peff.net>
Tue, 6 Sep 2022 23:06:25 +0000 (19:06 -0400)
committerJunio C Hamano <gitster@pobox.com>
Wed, 7 Sep 2022 19:27:02 +0000 (12:27 -0700)
If the caller told us that they don't care about us checking the object
hash, then we're free to implement any optimizations that get us the
parsed value more quickly. An obvious one is to check the commit graph
before loading an object from disk. And in fact, both of the callers who
pass in this flag are already doing so before they call parse_object()!

So we can simplify those callers, as well as any possible future ones,
by moving the logic into parse_object().

There are two subtle things to note in the diff, but neither has any
impact in practice:

  - it seems least-surprising here to do the graph lookup on the
    git-replace'd oid, rather than the original. This is in theory a
    change of behavior from the earlier code, as neither caller did a
    replace lookup itself. But in practice it doesn't matter, as we
    disable the commit graph entirely if there are any replace refs.

  - the caller in get_reference() passes the skip_hash flag only if
    revs->verify_objects isn't set, whereas it would look in the commit
    graph unconditionally. In practice this should not matter as we
    should disable the commit graph entirely when using verify_objects
    (and that was done recently in another patch).

So this should be a pure cleanup with no behavior change.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
object.c
revision.c
upload-pack.c

index 8f6de090781b7422e9bf6c42b959f1501c9492ef..2e4589bae50105da847ad5b861d1752fb26dec77 100644 (file)
--- a/object.c
+++ b/object.c
@@ -279,6 +279,12 @@ struct object *parse_object_with_flags(struct repository *r,
        if (obj && obj->parsed)
                return obj;
 
+       if (skip_hash) {
+               struct commit *commit = lookup_commit_in_graph(r, repl);
+               if (commit)
+                       return &commit->object;
+       }
+
        if ((obj && obj->type == OBJ_BLOB && repo_has_object_file(r, oid)) ||
            (!obj && repo_has_object_file(r, oid) &&
             oid_object_info(r, oid, NULL) == OBJ_BLOB)) {
index 786e090785734fe58fb2a5e85110b9d4ea939f19..a04ebd6139f2953f1283e01a83e309aff59a5878 100644 (file)
@@ -373,20 +373,10 @@ static struct object *get_reference(struct rev_info *revs, const char *name,
                                    unsigned int flags)
 {
        struct object *object;
-       struct commit *commit;
 
-       /*
-        * If the repository has commit graphs, we try to opportunistically
-        * look up the object ID in those graphs. Like this, we can avoid
-        * parsing commit data from disk.
-        */
-       commit = lookup_commit_in_graph(revs->repo, oid);
-       if (commit)
-               object = &commit->object;
-       else
-               object = parse_object_with_flags(revs->repo, oid,
-                                                revs->verify_objects ? 0 :
-                                                PARSE_OBJECT_SKIP_HASH_CHECK);
+       object = parse_object_with_flags(revs->repo, oid,
+                                        revs->verify_objects ? 0 :
+                                        PARSE_OBJECT_SKIP_HASH_CHECK);
 
        if (!object) {
                if (revs->ignore_missing)
index 4bacdf087c6a18f134468a87fd2cab73e97a7ec1..35fe1a3dbb2100dbaf350403d3c3e7da8b6601db 100644 (file)
@@ -1409,19 +1409,14 @@ static int parse_want(struct packet_writer *writer, const char *line,
        const char *arg;
        if (skip_prefix(line, "want ", &arg)) {
                struct object_id oid;
-               struct commit *commit;
                struct object *o;
 
                if (get_oid_hex(arg, &oid))
                        die("git upload-pack: protocol error, "
                            "expected to get oid, not '%s'", line);
 
-               commit = lookup_commit_in_graph(the_repository, &oid);
-               if (commit)
-                       o = &commit->object;
-               else
-                       o = parse_object_with_flags(the_repository, &oid,
-                                                   PARSE_OBJECT_SKIP_HASH_CHECK);
+               o = parse_object_with_flags(the_repository, &oid,
+                                           PARSE_OBJECT_SKIP_HASH_CHECK);
 
                if (!o) {
                        packet_writer_error(writer,