@@ -360,8 +360,6 @@ static void wt_longstatus_print_change_data(struct wt_status *s,
360
360
switch (change_type ) {
361
361
case WT_STATUS_UPDATED :
362
362
status = d -> index_status ;
363
- if (d -> head_path )
364
- one_name = d -> head_path ;
365
363
break ;
366
364
case WT_STATUS_CHANGED :
367
365
if (d -> new_submodule_commits || d -> dirty_submodule ) {
@@ -382,6 +380,14 @@ static void wt_longstatus_print_change_data(struct wt_status *s,
382
380
change_type );
383
381
}
384
382
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
+
385
391
one = quote_path (one_name , s -> prefix , & onebuf );
386
392
two = quote_path (two_name , s -> prefix , & twobuf );
387
393
@@ -391,7 +397,7 @@ static void wt_longstatus_print_change_data(struct wt_status *s,
391
397
die ("BUG: unhandled diff status %c" , status );
392
398
len = label_width - utf8_strwidth (what );
393
399
assert (len >= 0 );
394
- if (status == DIFF_STATUS_COPIED || status == DIFF_STATUS_RENAMED )
400
+ if (one_name != two_name )
395
401
status_printf_more (s , c , "%s%.*s%s -> %s" ,
396
402
what , len , padding , one , two );
397
403
else
@@ -406,7 +412,8 @@ static void wt_longstatus_print_change_data(struct wt_status *s,
406
412
strbuf_release (& twobuf );
407
413
}
408
414
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
+ {
410
417
if (d -> new_submodule_commits )
411
418
return 'M' ;
412
419
if (d -> dirty_submodule & DIRTY_SUBMODULE_MODIFIED )
@@ -432,7 +439,7 @@ static void wt_status_collect_changed_cb(struct diff_queue_struct *q,
432
439
struct wt_status_change_data * d ;
433
440
434
441
p = q -> queue [i ];
435
- it = string_list_insert (& s -> change , p -> one -> path );
442
+ it = string_list_insert (& s -> change , p -> two -> path );
436
443
d = it -> util ;
437
444
if (!d ) {
438
445
d = xcalloc (1 , sizeof (* d ));
@@ -459,6 +466,14 @@ static void wt_status_collect_changed_cb(struct diff_queue_struct *q,
459
466
/* mode_worktree is zero for a delete. */
460
467
break ;
461
468
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 */
462
477
case DIFF_STATUS_MODIFIED :
463
478
case DIFF_STATUS_TYPE_CHANGED :
464
479
case DIFF_STATUS_UNMERGED :
@@ -467,8 +482,8 @@ static void wt_status_collect_changed_cb(struct diff_queue_struct *q,
467
482
oidcpy (& d -> oid_index , & p -> one -> oid );
468
483
break ;
469
484
470
- case DIFF_STATUS_UNKNOWN :
471
- die ("BUG: worktree status unknown???" );
485
+ default :
486
+ die ("BUG: unhandled diff-files status '%c'" , p -> status );
472
487
break ;
473
488
}
474
489
@@ -530,8 +545,11 @@ static void wt_status_collect_updated_cb(struct diff_queue_struct *q,
530
545
531
546
case DIFF_STATUS_COPIED :
532
547
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 ;
535
553
/* fallthru */
536
554
case DIFF_STATUS_MODIFIED :
537
555
case DIFF_STATUS_TYPE_CHANGED :
@@ -548,6 +566,10 @@ static void wt_status_collect_updated_cb(struct diff_queue_struct *q,
548
566
* values in these fields.
549
567
*/
550
568
break ;
569
+
570
+ default :
571
+ die ("BUG: unhandled diff-index status '%c'" , p -> status );
572
+ break ;
551
573
}
552
574
}
553
575
}
@@ -602,7 +624,7 @@ static void wt_status_collect_changes_index(struct wt_status *s)
602
624
rev .diffopt .output_format |= DIFF_FORMAT_CALLBACK ;
603
625
rev .diffopt .format_callback = wt_status_collect_updated_cb ;
604
626
rev .diffopt .format_callback_data = s ;
605
- rev .diffopt .detect_rename = 1 ;
627
+ rev .diffopt .detect_rename = DIFF_DETECT_RENAME ;
606
628
rev .diffopt .rename_limit = 200 ;
607
629
rev .diffopt .break_opt = 0 ;
608
630
copy_pathspec (& rev .prune_data , & s -> pathspec );
@@ -962,7 +984,7 @@ static void wt_longstatus_print_verbose(struct wt_status *s)
962
984
setup_revisions (0 , NULL , & rev , & opt );
963
985
964
986
rev .diffopt .output_format |= DIFF_FORMAT_PATCH ;
965
- rev .diffopt .detect_rename = 1 ;
987
+ rev .diffopt .detect_rename = DIFF_DETECT_RENAME ;
966
988
rev .diffopt .file = s -> fp ;
967
989
rev .diffopt .close_file = 0 ;
968
990
/*
@@ -1719,13 +1741,14 @@ static void wt_shortstatus_status(struct string_list_item *it,
1719
1741
putchar (' ' );
1720
1742
if (s -> null_termination ) {
1721
1743
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 );
1724
1746
} else {
1725
1747
struct strbuf onebuf = STRBUF_INIT ;
1726
1748
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 );
1729
1752
if (* one != '"' && strchr (one , ' ' ) != NULL ) {
1730
1753
putchar ('"' );
1731
1754
strbuf_addch (& onebuf , '"' );
@@ -2030,10 +2053,10 @@ static void wt_porcelain_v2_print_changed_entry(
2030
2053
struct wt_status * s )
2031
2054
{
2032
2055
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 ;
2037
2060
char key [3 ];
2038
2061
char submodule_token [5 ];
2039
2062
char sep_char , eol_char ;
@@ -2052,8 +2075,8 @@ static void wt_porcelain_v2_print_changed_entry(
2052
2075
*/
2053
2076
sep_char = '\0' ;
2054
2077
eol_char = '\0' ;
2055
- path_index = it -> string ;
2056
- path_head = d -> head_path ;
2078
+ path = it -> string ;
2079
+ path_from = d -> rename_source ;
2057
2080
} else {
2058
2081
/*
2059
2082
* Path(s) are C-quoted if necessary. Current path is ALWAYS first.
@@ -2063,27 +2086,27 @@ static void wt_porcelain_v2_print_changed_entry(
2063
2086
*/
2064
2087
sep_char = '\t' ;
2065
2088
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 );
2069
2092
}
2070
2093
2071
- if (path_head )
2094
+ if (path_from )
2072
2095
fprintf (s -> fp , "2 %s %s %06o %06o %06o %s %s %c%d %s%c%s%c" ,
2073
2096
key , submodule_token ,
2074
2097
d -> mode_head , d -> mode_index , d -> mode_worktree ,
2075
2098
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 );
2078
2101
else
2079
2102
fprintf (s -> fp , "1 %s %s %06o %06o %06o %s %s %s%c" ,
2080
2103
key , submodule_token ,
2081
2104
d -> mode_head , d -> mode_index , d -> mode_worktree ,
2082
2105
oid_to_hex (& d -> oid_head ), oid_to_hex (& d -> oid_index ),
2083
- path_index , eol_char );
2106
+ path , eol_char );
2084
2107
2085
- strbuf_release (& buf_index );
2086
- strbuf_release (& buf_head );
2108
+ strbuf_release (& buf );
2109
+ strbuf_release (& buf_from );
2087
2110
}
2088
2111
2089
2112
/*
0 commit comments