rev-list: extend print-info to print missing object type
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>
Justin Tobler committed
Feb 4, 2025 at 18:41 UTC
3295c3539896750f742a56de0c4ac965f8d96303
3 files changed
+13
-4
Documentation/rev-list-options.txt
+3
@@ -1038,6 +1038,9 @@ one of the following:
1038
* The `path=<path>` shows the path of the missing object inferred from a
1039
containing object. A path containing SP or special characters is enclosed in
1040
double-quotes in the C style as needed.
1041
++
1042
+* The `type=<type>` shows the type of the missing object inferred from a
1043
+ containing object.
1044
--
1045
+
1046
If some tips passed to the traversal are missing, they will be
builtin/rev-list.c
+8
-3
@@ -79,6 +79,7 @@ static int arg_print_omitted; /* print objects omitted by filter */
79
struct missing_objects_map_entry {
80
struct oidmap_entry entry;
81
const char *path;
82
+ unsigned type;
83
};
84
static struct oidmap missing_objects;
85
enum missing_action {
@@ -109,7 +110,8 @@ static off_t get_object_disk_usage(struct object *obj)
110
return size;
111
}
112
112
-static void add_missing_object_entry(struct object_id *oid, const char *path)
113
+static void add_missing_object_entry(struct object_id *oid, const char *path,
114
+ unsigned type)
115
{
116
struct missing_objects_map_entry *entry;
117
@@ -118,6 +120,7 @@ static void add_missing_object_entry(struct object_id *oid, const char *path)
120
121
CALLOC_ARRAY(entry, 1);
122
entry->entry.oid = *oid;
123
+ entry->type = type;
124
if (path)
125
entry->path = xstrdup(path);
126
oidmap_put(&missing_objects, entry);
@@ -142,6 +145,8 @@ static void print_missing_object(struct missing_objects_map_entry *entry,
145
146
strbuf_release(&path);
147
}
148
+ if (entry->type)
149
+ strbuf_addf(&sb, " type=%s", type_name(entry->type));
150
151
printf("?%s%s\n", oid_to_hex(&entry->entry.oid), sb.buf);
152
strbuf_release(&sb);
@@ -166,7 +171,7 @@ static inline void finish_object__ma(struct object *obj, const char *name)
171
172
case MA_PRINT:
173
case MA_PRINT_INFO:
169
- add_missing_object_entry(&obj->oid, name);
174
+ add_missing_object_entry(&obj->oid, name, obj->type);
175
return;
176
177
case MA_ALLOW_PROMISOR:
@@ -843,7 +848,7 @@ int cmd_rev_list(int argc,
848
849
/* Add missing tips */
850
while ((oid = oidset_iter_next(&iter)))
846
- add_missing_object_entry(oid, NULL);
851
+ add_missing_object_entry(oid, NULL, 0);
852
853
oidset_clear(&revs.missing_commits);
854
}
t/t6022-rev-list-missing.sh
+2
-1
@@ -164,6 +164,7 @@ do
164
165
oid="$(git rev-parse "$obj")" &&
166
path=".git/objects/$(test_oid_to_path $oid)" &&
167
+ type_info=" type=$(git cat-file -t $oid)" &&
168
169
case $obj in
170
HEAD:foo)
@@ -184,7 +185,7 @@ do
185
# get the expected oids.
186
git rev-list --objects --no-object-names \
187
HEAD ^"$obj" >expect.raw &&
187
- echo "?$oid$path_info" >>expect.raw &&
188
+ echo "?$oid$path_info$type_info" >>expect.raw &&
189
190
mv "$path" "$path.hidden" &&
191
git rev-list --objects --no-object-names \