Skip to content

Commit 57834dc

Browse files
jltoblergitster
authored andcommitted
rev-list: support NUL-delimited --missing option
The `--missing={print,print-info}` option for git-rev-list(1) prints missing objects found while performing the revision walk. Add support for printing missing objects in a NUL-delimited format when the `-z` option is enabled. $ git rev-list -z --missing=print-info <rev> <oid> NUL NUL ?<oid> [NUL <token>=<value>]... NUL NUL In this mode, values containing special characters or spaces are printed as-is without being escaped or quoted. Signed-off-by: Justin Tobler <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7c679c8 commit 57834dc

File tree

3 files changed

+59
-8
lines changed

3 files changed

+59
-8
lines changed

Documentation/rev-list-options.adoc

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,15 @@ containing newline characters:
378378
<OID> [NUL <object-name>] NUL NUL
379379
-----------------------------------------------------------------------
380380
+
381-
This option is only compatible with `--objects`.
381+
When the `--missing` option is provided, missing objects are printed in the
382+
following form where value is printed as-is without any token specific
383+
encoding:
384+
+
385+
-----------------------------------------------------------------------
386+
?<OID> [NUL <token>=<value>]... NUL NUL
387+
-----------------------------------------------------------------------
388+
+
389+
This option is only compatible with `--objects` and `--missing`.
382390
endif::git-rev-list[]
383391

384392
History Simplification

builtin/rev-list.c

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -145,25 +145,38 @@ static void print_missing_object(struct missing_objects_map_entry *entry,
145145
int print_missing_info)
146146
{
147147
struct strbuf sb = STRBUF_INIT;
148+
char info_sep = ' ';
149+
150+
if (nul_delim)
151+
info_sep = '\0';
152+
153+
printf("?%s", oid_to_hex(&entry->entry.oid));
148154

149155
if (!print_missing_info) {
150-
printf("?%s\n", oid_to_hex(&entry->entry.oid));
156+
print_object_term(nul_delim);
151157
return;
152158
}
153159

154160
if (entry->path && *entry->path) {
155161
struct strbuf path = STRBUF_INIT;
156162

157-
strbuf_addstr(&sb, " path=");
158-
quote_path(entry->path, NULL, &path, QUOTE_PATH_QUOTE_SP);
159-
strbuf_addbuf(&sb, &path);
163+
strbuf_addf(&sb, "%cpath=", info_sep);
164+
165+
if (nul_delim) {
166+
strbuf_addstr(&sb, entry->path);
167+
} else {
168+
quote_path(entry->path, NULL, &path, QUOTE_PATH_QUOTE_SP);
169+
strbuf_addbuf(&sb, &path);
170+
}
160171

161172
strbuf_release(&path);
162173
}
163174
if (entry->type)
164-
strbuf_addf(&sb, " type=%s", type_name(entry->type));
175+
strbuf_addf(&sb, "%ctype=%s", info_sep, type_name(entry->type));
176+
177+
fwrite(sb.buf, sizeof(char), sb.len, stdout);
178+
print_object_term(nul_delim);
165179

166-
printf("?%s%s\n", oid_to_hex(&entry->entry.oid), sb.buf);
167180
strbuf_release(&sb);
168181
}
169182

@@ -782,7 +795,7 @@ int cmd_rev_list(int argc,
782795
if (nul_delim) {
783796
if (revs.graph || revs.verbose_header || show_disk_usage ||
784797
info.show_timestamp || info.header_prefix || bisect_list ||
785-
use_bitmap_index || revs.edge_hint || arg_missing_action)
798+
use_bitmap_index || revs.edge_hint)
786799
die(_("-z option used with unsupported option"));
787800
}
788801

t/t6022-rev-list-missing.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,4 +198,34 @@ do
198198
'
199199
done
200200

201+
test_expect_success "-z nul-delimited --missing" '
202+
test_when_finished rm -rf repo &&
203+
204+
git init repo &&
205+
(
206+
cd repo &&
207+
git commit --allow-empty -m first &&
208+
209+
path="foo bar" &&
210+
echo foobar >"$path" &&
211+
git add -A &&
212+
git commit -m second &&
213+
214+
oid=$(git rev-parse "HEAD:$path") &&
215+
type="$(git cat-file -t $oid)" &&
216+
217+
obj_path=".git/objects/$(test_oid_to_path $oid)" &&
218+
219+
git rev-list -z --objects --no-object-names \
220+
HEAD ^"$oid" >expect &&
221+
printf "?%s\0path=%s\0type=%s\0\0" "$oid" "$path" "$type" >>expect &&
222+
223+
mv "$obj_path" "$obj_path.hidden" &&
224+
git rev-list -z --objects --no-object-names \
225+
--missing=print-info HEAD >actual &&
226+
227+
test_cmp expect actual
228+
)
229+
'
230+
201231
test_done

0 commit comments

Comments
 (0)