@@ -651,35 +651,37 @@ static int add(int ac, const char **av, const char *prefix)
651
651
return add_worktree (path , branch , & opts );
652
652
}
653
653
654
- static void show_worktree_porcelain (struct worktree * wt )
654
+ static void show_worktree_porcelain (struct worktree * wt , int line_terminator )
655
655
{
656
656
const char * reason ;
657
657
658
- printf ("worktree %s\n " , wt -> path );
658
+ printf ("worktree %s%c " , wt -> path , line_terminator );
659
659
if (wt -> is_bare )
660
- printf ("bare\n" );
660
+ printf ("bare%c" , line_terminator );
661
661
else {
662
- printf ("HEAD %s\n " , oid_to_hex (& wt -> head_oid ));
662
+ printf ("HEAD %s%c " , oid_to_hex (& wt -> head_oid ), line_terminator );
663
663
if (wt -> is_detached )
664
- printf ("detached\n" );
664
+ printf ("detached%c" , line_terminator );
665
665
else if (wt -> head_ref )
666
- printf ("branch %s\n " , wt -> head_ref );
666
+ printf ("branch %s%c " , wt -> head_ref , line_terminator );
667
667
}
668
668
669
669
reason = worktree_lock_reason (wt );
670
- if (reason && * reason ) {
671
- struct strbuf sb = STRBUF_INIT ;
672
- quote_c_style (reason , & sb , NULL , 0 );
673
- printf ("locked %s\n" , sb .buf );
674
- strbuf_release (& sb );
675
- } else if (reason )
676
- printf ("locked\n" );
670
+ if (reason ) {
671
+ fputs ("locked" , stdout );
672
+ if (* reason ) {
673
+ fputc (' ' , stdout );
674
+ write_name_quoted (reason , stdout , line_terminator );
675
+ } else {
676
+ fputc (line_terminator , stdout );
677
+ }
678
+ }
677
679
678
680
reason = worktree_prune_reason (wt , expire );
679
681
if (reason )
680
- printf ("prunable %s\n " , reason );
682
+ printf ("prunable %s%c " , reason , line_terminator );
681
683
682
- printf ( "\n" );
684
+ fputc ( line_terminator , stdout );
683
685
}
684
686
685
687
static void show_worktree (struct worktree * wt , int path_maxlen , int abbrev_len )
@@ -757,12 +759,15 @@ static void pathsort(struct worktree **wt)
757
759
static int list (int ac , const char * * av , const char * prefix )
758
760
{
759
761
int porcelain = 0 ;
762
+ int line_terminator = '\n' ;
760
763
761
764
struct option options [] = {
762
765
OPT_BOOL (0 , "porcelain" , & porcelain , N_ ("machine-readable output" )),
763
766
OPT__VERBOSE (& verbose , N_ ("show extended annotations and reasons, if available" )),
764
767
OPT_EXPIRY_DATE (0 , "expire" , & expire ,
765
768
N_ ("add 'prunable' annotation to worktrees older than <time>" )),
769
+ OPT_SET_INT ('z' , NULL , & line_terminator ,
770
+ N_ ("terminate records with a NUL character" ), '\0' ),
766
771
OPT_END ()
767
772
};
768
773
@@ -772,6 +777,8 @@ static int list(int ac, const char **av, const char *prefix)
772
777
usage_with_options (worktree_usage , options );
773
778
else if (verbose && porcelain )
774
779
die (_ ("options '%s' and '%s' cannot be used together" ), "--verbose" , "--porcelain" );
780
+ else if (!line_terminator && !porcelain )
781
+ die (_ ("the option '%s' requires '%s'" ), "-z" , "--porcelain" );
775
782
else {
776
783
struct worktree * * worktrees = get_worktrees ();
777
784
int path_maxlen = 0 , abbrev = DEFAULT_ABBREV , i ;
@@ -784,7 +791,8 @@ static int list(int ac, const char **av, const char *prefix)
784
791
785
792
for (i = 0 ; worktrees [i ]; i ++ ) {
786
793
if (porcelain )
787
- show_worktree_porcelain (worktrees [i ]);
794
+ show_worktree_porcelain (worktrees [i ],
795
+ line_terminator );
788
796
else
789
797
show_worktree (worktrees [i ], path_maxlen , abbrev );
790
798
}
0 commit comments