@@ -575,35 +575,37 @@ static int add(int ac, const char **av, const char *prefix)
575
575
return add_worktree (path , branch , & opts );
576
576
}
577
577
578
- static void show_worktree_porcelain (struct worktree * wt )
578
+ static void show_worktree_porcelain (struct worktree * wt , int line_terminator )
579
579
{
580
580
const char * reason ;
581
581
582
- printf ("worktree %s\n " , wt -> path );
582
+ printf ("worktree %s%c " , wt -> path , line_terminator );
583
583
if (wt -> is_bare )
584
- printf ("bare\n" );
584
+ printf ("bare%c" , line_terminator );
585
585
else {
586
- printf ("HEAD %s\n " , oid_to_hex (& wt -> head_oid ));
586
+ printf ("HEAD %s%c " , oid_to_hex (& wt -> head_oid ), line_terminator );
587
587
if (wt -> is_detached )
588
- printf ("detached\n" );
588
+ printf ("detached%c" , line_terminator );
589
589
else if (wt -> head_ref )
590
- printf ("branch %s\n " , wt -> head_ref );
590
+ printf ("branch %s%c " , wt -> head_ref , line_terminator );
591
591
}
592
592
593
593
reason = worktree_lock_reason (wt );
594
- if (reason && * reason ) {
595
- struct strbuf sb = STRBUF_INIT ;
596
- quote_c_style (reason , & sb , NULL , 0 );
597
- printf ("locked %s\n" , sb .buf );
598
- strbuf_release (& sb );
599
- } else if (reason )
600
- printf ("locked\n" );
594
+ if (reason ) {
595
+ fputs ("locked" , stdout );
596
+ if (* reason ) {
597
+ fputc (' ' , stdout );
598
+ write_name_quoted (reason , stdout , line_terminator );
599
+ } else {
600
+ fputc (line_terminator , stdout );
601
+ }
602
+ }
601
603
602
604
reason = worktree_prune_reason (wt , expire );
603
605
if (reason )
604
- printf ("prunable %s\n " , reason );
606
+ printf ("prunable %s%c " , reason , line_terminator );
605
607
606
- printf ( "\n" );
608
+ fputc ( line_terminator , stdout );
607
609
}
608
610
609
611
static void show_worktree (struct worktree * wt , int path_maxlen , int abbrev_len )
@@ -681,12 +683,15 @@ static void pathsort(struct worktree **wt)
681
683
static int list (int ac , const char * * av , const char * prefix )
682
684
{
683
685
int porcelain = 0 ;
686
+ int line_terminator = '\n' ;
684
687
685
688
struct option options [] = {
686
689
OPT_BOOL (0 , "porcelain" , & porcelain , N_ ("machine-readable output" )),
687
690
OPT__VERBOSE (& verbose , N_ ("show extended annotations and reasons, if available" )),
688
691
OPT_EXPIRY_DATE (0 , "expire" , & expire ,
689
692
N_ ("add 'prunable' annotation to worktrees older than <time>" )),
693
+ OPT_SET_INT ('z' , NULL , & line_terminator ,
694
+ N_ ("terminate records with a NUL character" ), '\0' ),
690
695
OPT_END ()
691
696
};
692
697
@@ -696,6 +701,8 @@ static int list(int ac, const char **av, const char *prefix)
696
701
usage_with_options (worktree_usage , options );
697
702
else if (verbose && porcelain )
698
703
die (_ ("options '%s' and '%s' cannot be used together" ), "--verbose" , "--porcelain" );
704
+ else if (!line_terminator && !porcelain )
705
+ die (_ ("the option '%s' requires '%s'" ), "-z" , "--porcelain" );
699
706
else {
700
707
struct worktree * * worktrees = get_worktrees ();
701
708
int path_maxlen = 0 , abbrev = DEFAULT_ABBREV , i ;
@@ -708,7 +715,8 @@ static int list(int ac, const char **av, const char *prefix)
708
715
709
716
for (i = 0 ; worktrees [i ]; i ++ ) {
710
717
if (porcelain )
711
- show_worktree_porcelain (worktrees [i ]);
718
+ show_worktree_porcelain (worktrees [i ],
719
+ line_terminator );
712
720
else
713
721
show_worktree (worktrees [i ], path_maxlen , abbrev );
714
722
}
0 commit comments