|
16 | 16 | #include "object-file.h" |
17 | 17 | #include "object-store-ll.h" |
18 | 18 | #include "pack-bitmap.h" |
| 19 | +#include "parse-options.h" |
19 | 20 | #include "log-tree.h" |
20 | 21 | #include "graph.h" |
21 | 22 | #include "bisect.h" |
@@ -64,6 +65,7 @@ static const char rev_list_usage[] = |
64 | 65 | " --abbrev-commit\n" |
65 | 66 | " --left-right\n" |
66 | 67 | " --count\n" |
| 68 | +" -z\n" |
67 | 69 | " special purpose:\n" |
68 | 70 | " --bisect\n" |
69 | 71 | " --bisect-vars\n" |
@@ -96,10 +98,23 @@ static int arg_show_object_names = 1; |
96 | 98 |
|
97 | 99 | #define DEFAULT_OIDSET_SIZE (16*1024) |
98 | 100 |
|
| 101 | +static int nul_delim; |
99 | 102 | static int show_disk_usage; |
100 | 103 | static off_t total_disk_usage; |
101 | 104 | static int human_readable; |
102 | 105 |
|
| 106 | +static void print_object_term(int nul_delim) |
| 107 | +{ |
| 108 | + char line_sep = '\n'; |
| 109 | + |
| 110 | + if (nul_delim) |
| 111 | + line_sep = '\0'; |
| 112 | + |
| 113 | + putchar(line_sep); |
| 114 | + if (nul_delim) |
| 115 | + putchar(line_sep); |
| 116 | +} |
| 117 | + |
103 | 118 | static off_t get_object_disk_usage(struct object *obj) |
104 | 119 | { |
105 | 120 | off_t size; |
@@ -130,25 +145,38 @@ static void print_missing_object(struct missing_objects_map_entry *entry, |
130 | 145 | int print_missing_info) |
131 | 146 | { |
132 | 147 | 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)); |
133 | 154 |
|
134 | 155 | if (!print_missing_info) { |
135 | | - printf("?%s\n", oid_to_hex(&entry->entry.oid)); |
| 156 | + print_object_term(nul_delim); |
136 | 157 | return; |
137 | 158 | } |
138 | 159 |
|
139 | 160 | if (entry->path && *entry->path) { |
140 | 161 | struct strbuf path = STRBUF_INIT; |
141 | 162 |
|
142 | | - strbuf_addstr(&sb, " path="); |
143 | | - quote_path(entry->path, NULL, &path, QUOTE_PATH_QUOTE_SP); |
144 | | - 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 | + } |
145 | 171 |
|
146 | 172 | strbuf_release(&path); |
147 | 173 | } |
148 | 174 | if (entry->type) |
149 | | - 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); |
150 | 179 |
|
151 | | - printf("?%s%s\n", oid_to_hex(&entry->entry.oid), sb.buf); |
152 | 180 | strbuf_release(&sb); |
153 | 181 | } |
154 | 182 |
|
@@ -263,7 +291,7 @@ static void show_commit(struct commit *commit, void *data) |
263 | 291 | if (revs->commit_format == CMIT_FMT_ONELINE) |
264 | 292 | putchar(' '); |
265 | 293 | else if (revs->include_header) |
266 | | - putchar('\n'); |
| 294 | + print_object_term(nul_delim); |
267 | 295 |
|
268 | 296 | if (revs->verbose_header) { |
269 | 297 | struct strbuf buf = STRBUF_INIT; |
@@ -357,10 +385,20 @@ static void show_object(struct object *obj, const char *name, void *cb_data) |
357 | 385 | return; |
358 | 386 | } |
359 | 387 |
|
360 | | - if (arg_show_object_names) |
361 | | - show_object_with_name(stdout, obj, name); |
362 | | - else |
363 | | - printf("%s\n", oid_to_hex(&obj->oid)); |
| 388 | + printf("%s", oid_to_hex(&obj->oid)); |
| 389 | + |
| 390 | + if (arg_show_object_names) { |
| 391 | + if (nul_delim && *name) { |
| 392 | + putchar('\0'); |
| 393 | + printf("%s", name); |
| 394 | + } else if (!nul_delim) { |
| 395 | + putchar(' '); |
| 396 | + for (const char *p = name; *p && *p != '\n'; p++) |
| 397 | + putchar(*p); |
| 398 | + } |
| 399 | + } |
| 400 | + |
| 401 | + print_object_term(nul_delim); |
364 | 402 | } |
365 | 403 |
|
366 | 404 | static void show_edge(struct commit *commit) |
@@ -634,19 +672,17 @@ int cmd_rev_list(int argc, |
634 | 672 | if (!strcmp(arg, "--exclude-promisor-objects")) { |
635 | 673 | fetch_if_missing = 0; |
636 | 674 | revs.exclude_promisor_objects = 1; |
637 | | - break; |
638 | | - } |
639 | | - } |
640 | | - for (i = 1; i < argc; i++) { |
641 | | - const char *arg = argv[i]; |
642 | | - if (skip_prefix(arg, "--missing=", &arg)) { |
643 | | - if (revs.exclude_promisor_objects) |
644 | | - die(_("options '%s' and '%s' cannot be used together"), "--exclude-promisor-objects", "--missing"); |
645 | | - if (parse_missing_action_value(arg)) |
646 | | - break; |
| 675 | + } else if (skip_prefix(arg, "--missing=", &arg)) { |
| 676 | + parse_missing_action_value(arg); |
| 677 | + } else if (!strcmp(arg, "-z")) { |
| 678 | + nul_delim = 1; |
647 | 679 | } |
648 | 680 | } |
649 | 681 |
|
| 682 | + die_for_incompatible_opt2(revs.exclude_promisor_objects, |
| 683 | + "--exclude_promisor_objects", |
| 684 | + arg_missing_action, "--missing"); |
| 685 | + |
650 | 686 | if (arg_missing_action) |
651 | 687 | revs.do_not_die_on_missing_objects = 1; |
652 | 688 |
|
@@ -755,6 +791,14 @@ int cmd_rev_list(int argc, |
755 | 791 | usage(rev_list_usage); |
756 | 792 |
|
757 | 793 | } |
| 794 | + |
| 795 | + if (nul_delim) { |
| 796 | + if (revs.graph || revs.verbose_header || show_disk_usage || |
| 797 | + info.show_timestamp || info.header_prefix || bisect_list || |
| 798 | + use_bitmap_index || revs.edge_hint) |
| 799 | + die(_("-z option used with unsupported option")); |
| 800 | + } |
| 801 | + |
758 | 802 | if (revs.commit_format != CMIT_FMT_USERFORMAT) |
759 | 803 | revs.include_header = 1; |
760 | 804 | if (revs.commit_format != CMIT_FMT_UNSPECIFIED) { |
|
0 commit comments