]> git.ipfire.org Git - thirdparty/git.git/commitdiff
rev-list: extend print-info to print missing object type
authorJustin Tobler <jltobler@gmail.com>
Wed, 5 Feb 2025 00:41:47 +0000 (18:41 -0600)
committerJunio C Hamano <gitster@pobox.com>
Wed, 5 Feb 2025 17:32:01 +0000 (09:32 -0800)
Additional information about missing objects found in git-rev-list(1)
can be printed by specifying the `print-info` missing action for the
`--missing` option. Extend this action to also print missing object type
information inferred from its containing object. This token follows the
form `type=<type>` and specifies the expected object type of the missing
object.

Signed-off-by: Justin Tobler <jltobler@gmail.com>
Acked-by: Christian Couder <christian.couder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Documentation/rev-list-options.txt
builtin/rev-list.c
t/t6022-rev-list-missing.sh

index 0bea9d4ad36bf3456c4de6dc43661237397c239b..f10f78c60046b2be841c9e2403960663439296c3 100644 (file)
@@ -1038,6 +1038,9 @@ one of the following:
 * The `path=<path>` shows the path of the missing object inferred from a
   containing object. A path containing SP or special characters is enclosed in
   double-quotes in the C style as needed.
++
+* The `type=<type>` shows the type of the missing object inferred from a
+  containing object.
 --
 +
 If some tips passed to the traversal are missing, they will be
index 1e2b0a81e8aca9225a59655ded0474c76ae3c917..bb26bee0d4565ad2c9df92fe7035bf8dd556217c 100644 (file)
@@ -79,6 +79,7 @@ static int arg_print_omitted; /* print objects omitted by filter */
 struct missing_objects_map_entry {
        struct oidmap_entry entry;
        const char *path;
+       unsigned type;
 };
 static struct oidmap missing_objects;
 enum missing_action {
@@ -109,7 +110,8 @@ static off_t get_object_disk_usage(struct object *obj)
        return size;
 }
 
-static void add_missing_object_entry(struct object_id *oid, const char *path)
+static void add_missing_object_entry(struct object_id *oid, const char *path,
+                                    unsigned type)
 {
        struct missing_objects_map_entry *entry;
 
@@ -118,6 +120,7 @@ static void add_missing_object_entry(struct object_id *oid, const char *path)
 
        CALLOC_ARRAY(entry, 1);
        entry->entry.oid = *oid;
+       entry->type = type;
        if (path)
                entry->path = xstrdup(path);
        oidmap_put(&missing_objects, entry);
@@ -142,6 +145,8 @@ static void print_missing_object(struct missing_objects_map_entry *entry,
 
                strbuf_release(&path);
        }
+       if (entry->type)
+               strbuf_addf(&sb, " type=%s", type_name(entry->type));
 
        printf("?%s%s\n", oid_to_hex(&entry->entry.oid), sb.buf);
        strbuf_release(&sb);
@@ -166,7 +171,7 @@ static inline void finish_object__ma(struct object *obj, const char *name)
 
        case MA_PRINT:
        case MA_PRINT_INFO:
-               add_missing_object_entry(&obj->oid, name);
+               add_missing_object_entry(&obj->oid, name, obj->type);
                return;
 
        case MA_ALLOW_PROMISOR:
@@ -843,7 +848,7 @@ int cmd_rev_list(int argc,
 
                /* Add missing tips */
                while ((oid = oidset_iter_next(&iter)))
-                       add_missing_object_entry(oid, NULL);
+                       add_missing_object_entry(oid, NULL, 0);
 
                oidset_clear(&revs.missing_commits);
        }
index 38afca6f098710b2f827439cc1740c3e92452056..3e2790d4c826d8e6219b55c95edb8aaf26e4c73a 100755 (executable)
@@ -164,6 +164,7 @@ do
 
                        oid="$(git rev-parse "$obj")" &&
                        path=".git/objects/$(test_oid_to_path $oid)" &&
+                       type_info=" type=$(git cat-file -t $oid)" &&
 
                        case $obj in
                        HEAD:foo)
@@ -184,7 +185,7 @@ do
                        # get the expected oids.
                        git rev-list --objects --no-object-names \
                                HEAD ^"$obj" >expect.raw &&
-                       echo "?$oid$path_info" >>expect.raw &&
+                       echo "?$oid$path_info$type_info" >>expect.raw &&
 
                        mv "$path" "$path.hidden" &&
                        git rev-list --objects --no-object-names \