1616#include "object-file.h"
1717#include "object-store-ll.h"
1818#include "pack-bitmap.h"
19+ #include "parse-options.h"
1920#include "log-tree.h"
2021#include "graph.h"
2122#include "bisect.h"
@@ -64,6 +65,7 @@ static const char rev_list_usage[] =
6465" --abbrev-commit\n"
6566" --left-right\n"
6667" --count\n"
68+ " -z\n"
6769" special purpose:\n"
6870" --bisect\n"
6971" --bisect-vars\n"
@@ -96,6 +98,9 @@ static int arg_show_object_names = 1;
9698
9799#define DEFAULT_OIDSET_SIZE (16*1024)
98100
101+ static char line_term = '\n' ;
102+ static char info_term = ' ' ;
103+
99104static int show_disk_usage ;
100105static off_t total_disk_usage ;
101106static int human_readable ;
@@ -131,24 +136,37 @@ static void print_missing_object(struct missing_objects_map_entry *entry,
131136{
132137 struct strbuf sb = STRBUF_INIT ;
133138
139+ if (line_term )
140+ printf ("?%s" , oid_to_hex (& entry -> entry .oid ));
141+ else
142+ printf ("%s%cmissing=yes" , oid_to_hex (& entry -> entry .oid ),
143+ info_term );
144+
134145 if (!print_missing_info ) {
135- printf ( "?%s\n" , oid_to_hex ( & entry -> entry . oid ) );
146+ putchar ( line_term );
136147 return ;
137148 }
138149
139150 if (entry -> path && * entry -> path ) {
140- struct strbuf path = STRBUF_INIT ;
151+ strbuf_addf ( & sb , "%cpath=" , info_term ) ;
141152
142- strbuf_addstr (& sb , " path=" );
143- quote_path (entry -> path , NULL , & path , QUOTE_PATH_QUOTE_SP );
144- strbuf_addbuf (& sb , & path );
153+ if (line_term ) {
154+ struct strbuf path = STRBUF_INIT ;
145155
146- strbuf_release (& path );
156+ quote_path (entry -> path , NULL , & path , QUOTE_PATH_QUOTE_SP );
157+ strbuf_addbuf (& sb , & path );
158+
159+ strbuf_release (& path );
160+ } else {
161+ strbuf_addstr (& sb , entry -> path );
162+ }
147163 }
148164 if (entry -> type )
149- strbuf_addf (& sb , " type=%s" , type_name (entry -> type ));
165+ strbuf_addf (& sb , "%ctype=%s" , info_term , type_name (entry -> type ));
166+
167+ fwrite (sb .buf , sizeof (char ), sb .len , stdout );
168+ putchar (line_term );
150169
151- printf ("?%s%s\n" , oid_to_hex (& entry -> entry .oid ), sb .buf );
152170 strbuf_release (& sb );
153171}
154172
@@ -235,13 +253,18 @@ static void show_commit(struct commit *commit, void *data)
235253 fputs (info -> header_prefix , stdout );
236254
237255 if (revs -> include_header ) {
238- if (!revs -> graph )
256+ if (!revs -> graph && line_term )
239257 fputs (get_revision_mark (revs , commit ), stdout );
240258 if (revs -> abbrev_commit && revs -> abbrev )
241259 fputs (repo_find_unique_abbrev (the_repository , & commit -> object .oid , revs -> abbrev ),
242260 stdout );
243261 else
244262 fputs (oid_to_hex (& commit -> object .oid ), stdout );
263+
264+ if (!line_term ) {
265+ if (commit -> object .flags & BOUNDARY )
266+ printf ("%cboundary=yes" , info_term );
267+ }
245268 }
246269 if (revs -> print_parents ) {
247270 struct commit_list * parents = commit -> parents ;
@@ -263,7 +286,7 @@ static void show_commit(struct commit *commit, void *data)
263286 if (revs -> commit_format == CMIT_FMT_ONELINE )
264287 putchar (' ' );
265288 else if (revs -> include_header )
266- putchar ('\n' );
289+ putchar (line_term );
267290
268291 if (revs -> verbose_header ) {
269292 struct strbuf buf = STRBUF_INIT ;
@@ -357,10 +380,19 @@ static void show_object(struct object *obj, const char *name, void *cb_data)
357380 return ;
358381 }
359382
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 ));
383+ printf ("%s" , oid_to_hex (& obj -> oid ));
384+
385+ if (arg_show_object_names ) {
386+ if (line_term ) {
387+ putchar (info_term );
388+ for (const char * p = name ; * p && * p != '\n' ; p ++ )
389+ putchar (* p );
390+ } else if (* name ) {
391+ printf ("%cpath=%s" , info_term , name );
392+ }
393+ }
394+
395+ putchar (line_term );
364396}
365397
366398static void show_edge (struct commit * commit )
@@ -634,19 +666,18 @@ int cmd_rev_list(int argc,
634666 if (!strcmp (arg , "--exclude-promisor-objects" )) {
635667 fetch_if_missing = 0 ;
636668 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 ;
669+ } else if (skip_prefix (arg , "--missing=" , & arg )) {
670+ parse_missing_action_value (arg );
671+ } else if (!strcmp (arg , "-z" )) {
672+ line_term = '\0' ;
673+ info_term = '\0' ;
647674 }
648675 }
649676
677+ die_for_incompatible_opt2 (revs .exclude_promisor_objects ,
678+ "--exclude_promisor_objects" ,
679+ arg_missing_action , "--missing" );
680+
650681 if (arg_missing_action )
651682 revs .do_not_die_on_missing_objects = 1 ;
652683
@@ -755,6 +786,20 @@ int cmd_rev_list(int argc,
755786 usage (rev_list_usage );
756787
757788 }
789+
790+ /*
791+ * Reject options currently incompatible with -z. For some options, this
792+ * is not an inherent limitation and support may be implemented in the
793+ * future.
794+ */
795+ if (!line_term ) {
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 || revs .left_right ||
799+ revs .cherry_mark )
800+ die (_ ("-z option used with unsupported option" ));
801+ }
802+
758803 if (revs .commit_format != CMIT_FMT_USERFORMAT )
759804 revs .include_header = 1 ;
760805 if (revs .commit_format != CMIT_FMT_UNSPECIFIED ) {
0 commit comments