@@ -360,8 +360,6 @@ static void wt_longstatus_print_change_data(struct wt_status *s,
360360 switch (change_type ) {
361361 case WT_STATUS_UPDATED :
362362 status = d -> index_status ;
363- if (d -> head_path )
364- one_name = d -> head_path ;
365363 break ;
366364 case WT_STATUS_CHANGED :
367365 if (d -> new_submodule_commits || d -> dirty_submodule ) {
@@ -382,6 +380,14 @@ static void wt_longstatus_print_change_data(struct wt_status *s,
382380 change_type );
383381 }
384382
383+ /*
384+ * Only pick up the rename it's relevant. If the rename is for
385+ * the changed section and we're printing the updated section,
386+ * ignore it.
387+ */
388+ if (d -> rename_status == status )
389+ one_name = d -> rename_source ;
390+
385391 one = quote_path (one_name , s -> prefix , & onebuf );
386392 two = quote_path (two_name , s -> prefix , & twobuf );
387393
@@ -391,7 +397,7 @@ static void wt_longstatus_print_change_data(struct wt_status *s,
391397 die ("BUG: unhandled diff status %c" , status );
392398 len = label_width - utf8_strwidth (what );
393399 assert (len >= 0 );
394- if (status == DIFF_STATUS_COPIED || status == DIFF_STATUS_RENAMED )
400+ if (one_name != two_name )
395401 status_printf_more (s , c , "%s%.*s%s -> %s" ,
396402 what , len , padding , one , two );
397403 else
@@ -406,7 +412,8 @@ static void wt_longstatus_print_change_data(struct wt_status *s,
406412 strbuf_release (& twobuf );
407413}
408414
409- static char short_submodule_status (struct wt_status_change_data * d ) {
415+ static char short_submodule_status (struct wt_status_change_data * d )
416+ {
410417 if (d -> new_submodule_commits )
411418 return 'M' ;
412419 if (d -> dirty_submodule & DIRTY_SUBMODULE_MODIFIED )
@@ -432,7 +439,7 @@ static void wt_status_collect_changed_cb(struct diff_queue_struct *q,
432439 struct wt_status_change_data * d ;
433440
434441 p = q -> queue [i ];
435- it = string_list_insert (& s -> change , p -> one -> path );
442+ it = string_list_insert (& s -> change , p -> two -> path );
436443 d = it -> util ;
437444 if (!d ) {
438445 d = xcalloc (1 , sizeof (* d ));
@@ -459,6 +466,14 @@ static void wt_status_collect_changed_cb(struct diff_queue_struct *q,
459466 /* mode_worktree is zero for a delete. */
460467 break ;
461468
469+ case DIFF_STATUS_COPIED :
470+ case DIFF_STATUS_RENAMED :
471+ if (d -> rename_status )
472+ die ("BUG: multiple renames on the same target? how?" );
473+ d -> rename_source = xstrdup (p -> one -> path );
474+ d -> rename_score = p -> score * 100 / MAX_SCORE ;
475+ d -> rename_status = p -> status ;
476+ /* fallthru */
462477 case DIFF_STATUS_MODIFIED :
463478 case DIFF_STATUS_TYPE_CHANGED :
464479 case DIFF_STATUS_UNMERGED :
@@ -467,8 +482,8 @@ static void wt_status_collect_changed_cb(struct diff_queue_struct *q,
467482 oidcpy (& d -> oid_index , & p -> one -> oid );
468483 break ;
469484
470- case DIFF_STATUS_UNKNOWN :
471- die ("BUG: worktree status unknown???" );
485+ default :
486+ die ("BUG: unhandled diff-files status '%c'" , p -> status );
472487 break ;
473488 }
474489
@@ -530,8 +545,11 @@ static void wt_status_collect_updated_cb(struct diff_queue_struct *q,
530545
531546 case DIFF_STATUS_COPIED :
532547 case DIFF_STATUS_RENAMED :
533- d -> head_path = xstrdup (p -> one -> path );
534- d -> score = p -> score * 100 / MAX_SCORE ;
548+ if (d -> rename_status )
549+ die ("BUG: multiple renames on the same target? how?" );
550+ d -> rename_source = xstrdup (p -> one -> path );
551+ d -> rename_score = p -> score * 100 / MAX_SCORE ;
552+ d -> rename_status = p -> status ;
535553 /* fallthru */
536554 case DIFF_STATUS_MODIFIED :
537555 case DIFF_STATUS_TYPE_CHANGED :
@@ -548,6 +566,10 @@ static void wt_status_collect_updated_cb(struct diff_queue_struct *q,
548566 * values in these fields.
549567 */
550568 break ;
569+
570+ default :
571+ die ("BUG: unhandled diff-index status '%c'" , p -> status );
572+ break ;
551573 }
552574 }
553575}
@@ -602,7 +624,7 @@ static void wt_status_collect_changes_index(struct wt_status *s)
602624 rev .diffopt .output_format |= DIFF_FORMAT_CALLBACK ;
603625 rev .diffopt .format_callback = wt_status_collect_updated_cb ;
604626 rev .diffopt .format_callback_data = s ;
605- rev .diffopt .detect_rename = 1 ;
627+ rev .diffopt .detect_rename = DIFF_DETECT_RENAME ;
606628 rev .diffopt .rename_limit = 200 ;
607629 rev .diffopt .break_opt = 0 ;
608630 copy_pathspec (& rev .prune_data , & s -> pathspec );
@@ -962,7 +984,7 @@ static void wt_longstatus_print_verbose(struct wt_status *s)
962984 setup_revisions (0 , NULL , & rev , & opt );
963985
964986 rev .diffopt .output_format |= DIFF_FORMAT_PATCH ;
965- rev .diffopt .detect_rename = 1 ;
987+ rev .diffopt .detect_rename = DIFF_DETECT_RENAME ;
966988 rev .diffopt .file = s -> fp ;
967989 rev .diffopt .close_file = 0 ;
968990 /*
@@ -1719,13 +1741,14 @@ static void wt_shortstatus_status(struct string_list_item *it,
17191741 putchar (' ' );
17201742 if (s -> null_termination ) {
17211743 fprintf (stdout , "%s%c" , it -> string , 0 );
1722- if (d -> head_path )
1723- fprintf (stdout , "%s%c" , d -> head_path , 0 );
1744+ if (d -> rename_source )
1745+ fprintf (stdout , "%s%c" , d -> rename_source , 0 );
17241746 } else {
17251747 struct strbuf onebuf = STRBUF_INIT ;
17261748 const char * one ;
1727- if (d -> head_path ) {
1728- one = quote_path (d -> head_path , s -> prefix , & onebuf );
1749+
1750+ if (d -> rename_source ) {
1751+ one = quote_path (d -> rename_source , s -> prefix , & onebuf );
17291752 if (* one != '"' && strchr (one , ' ' ) != NULL ) {
17301753 putchar ('"' );
17311754 strbuf_addch (& onebuf , '"' );
@@ -2030,10 +2053,10 @@ static void wt_porcelain_v2_print_changed_entry(
20302053 struct wt_status * s )
20312054{
20322055 struct wt_status_change_data * d = it -> util ;
2033- struct strbuf buf_index = STRBUF_INIT ;
2034- struct strbuf buf_head = STRBUF_INIT ;
2035- const char * path_index = NULL ;
2036- const char * path_head = NULL ;
2056+ struct strbuf buf = STRBUF_INIT ;
2057+ struct strbuf buf_from = STRBUF_INIT ;
2058+ const char * path = NULL ;
2059+ const char * path_from = NULL ;
20372060 char key [3 ];
20382061 char submodule_token [5 ];
20392062 char sep_char , eol_char ;
@@ -2052,8 +2075,8 @@ static void wt_porcelain_v2_print_changed_entry(
20522075 */
20532076 sep_char = '\0' ;
20542077 eol_char = '\0' ;
2055- path_index = it -> string ;
2056- path_head = d -> head_path ;
2078+ path = it -> string ;
2079+ path_from = d -> rename_source ;
20572080 } else {
20582081 /*
20592082 * Path(s) are C-quoted if necessary. Current path is ALWAYS first.
@@ -2063,27 +2086,27 @@ static void wt_porcelain_v2_print_changed_entry(
20632086 */
20642087 sep_char = '\t' ;
20652088 eol_char = '\n' ;
2066- path_index = quote_path (it -> string , s -> prefix , & buf_index );
2067- if (d -> head_path )
2068- path_head = quote_path (d -> head_path , s -> prefix , & buf_head );
2089+ path = quote_path (it -> string , s -> prefix , & buf );
2090+ if (d -> rename_source )
2091+ path_from = quote_path (d -> rename_source , s -> prefix , & buf_from );
20692092 }
20702093
2071- if (path_head )
2094+ if (path_from )
20722095 fprintf (s -> fp , "2 %s %s %06o %06o %06o %s %s %c%d %s%c%s%c" ,
20732096 key , submodule_token ,
20742097 d -> mode_head , d -> mode_index , d -> mode_worktree ,
20752098 oid_to_hex (& d -> oid_head ), oid_to_hex (& d -> oid_index ),
2076- key [ 0 ] , d -> score ,
2077- path_index , sep_char , path_head , eol_char );
2099+ d -> rename_status , d -> rename_score ,
2100+ path , sep_char , path_from , eol_char );
20782101 else
20792102 fprintf (s -> fp , "1 %s %s %06o %06o %06o %s %s %s%c" ,
20802103 key , submodule_token ,
20812104 d -> mode_head , d -> mode_index , d -> mode_worktree ,
20822105 oid_to_hex (& d -> oid_head ), oid_to_hex (& d -> oid_index ),
2083- path_index , eol_char );
2106+ path , eol_char );
20842107
2085- strbuf_release (& buf_index );
2086- strbuf_release (& buf_head );
2108+ strbuf_release (& buf );
2109+ strbuf_release (& buf_from );
20872110}
20882111
20892112/*
0 commit comments