1111#include "builtin.h"
1212#include "tree.h"
1313#include "parse-options.h"
14+ #include "resolve-undo.h"
15+ #include "string-list.h"
1416
1517static int abbrev ;
1618static int show_deleted ;
1719static int show_cached ;
1820static int show_others ;
1921static int show_stage ;
2022static int show_unmerged ;
23+ static int show_resolve_undo ;
2124static int show_modified ;
2225static int show_killed ;
2326static int show_valid_bit ;
@@ -37,6 +40,7 @@ static const char *tag_removed = "";
3740static const char * tag_other = "" ;
3841static const char * tag_killed = "" ;
3942static const char * tag_modified = "" ;
43+ static const char * tag_resolve_undo = "" ;
4044
4145static void show_dir_entry (const char * tag , struct dir_entry * ent )
4246{
@@ -155,6 +159,38 @@ static void show_ce_entry(const char *tag, struct cache_entry *ce)
155159 write_name_quoted (ce -> name + offset , stdout , line_terminator );
156160}
157161
162+ static int show_one_ru (struct string_list_item * item , void * cbdata )
163+ {
164+ int offset = prefix_offset ;
165+ const char * path = item -> string ;
166+ struct resolve_undo_info * ui = item -> util ;
167+ int i , len ;
168+
169+ len = strlen (path );
170+ if (len < prefix_len )
171+ return 0 ; /* outside of the prefix */
172+ if (!match_pathspec (pathspec , path , len , prefix_len , ps_matched ))
173+ return 0 ; /* uninterested */
174+ for (i = 0 ; i < 3 ; i ++ ) {
175+ if (!ui -> mode [i ])
176+ continue ;
177+ printf ("%s%06o %s %d\t" , tag_resolve_undo , ui -> mode [i ],
178+ abbrev
179+ ? find_unique_abbrev (ui -> sha1 [i ], abbrev )
180+ : sha1_to_hex (ui -> sha1 [i ]),
181+ i + 1 );
182+ write_name_quoted (path + offset , stdout , line_terminator );
183+ }
184+ return 0 ;
185+ }
186+
187+ static void show_ru_info (const char * prefix )
188+ {
189+ if (!the_index .resolve_undo )
190+ return ;
191+ for_each_string_list (show_one_ru , the_index .resolve_undo , NULL );
192+ }
193+
158194static void show_files (struct dir_struct * dir , const char * prefix )
159195{
160196 int i ;
@@ -454,6 +490,8 @@ int cmd_ls_files(int argc, const char **argv, const char *prefix)
454490 DIR_HIDE_EMPTY_DIRECTORIES ),
455491 OPT_BOOLEAN ('u' , "unmerged" , & show_unmerged ,
456492 "show unmerged files in the output" ),
493+ OPT_BOOLEAN (0 , "resolve-undo" , & show_resolve_undo ,
494+ "show resolve-undo information" ),
457495 { OPTION_CALLBACK , 'x' , "exclude" , & dir .exclude_list [EXC_CMDL ], "pattern" ,
458496 "skip files matching pattern" ,
459497 0 , option_parse_exclude },
@@ -490,6 +528,7 @@ int cmd_ls_files(int argc, const char **argv, const char *prefix)
490528 tag_modified = "C " ;
491529 tag_other = "? " ;
492530 tag_killed = "K " ;
531+ tag_resolve_undo = "U " ;
493532 }
494533 if (show_modified || show_others || show_deleted || (dir .flags & DIR_SHOW_IGNORED ) || show_killed )
495534 require_work_tree = 1 ;
@@ -529,7 +568,7 @@ int cmd_ls_files(int argc, const char **argv, const char *prefix)
529568
530569 /* With no flags, we default to showing the cached files */
531570 if (!(show_stage | show_deleted | show_others | show_unmerged |
532- show_killed | show_modified ))
571+ show_killed | show_modified | show_resolve_undo ))
533572 show_cached = 1 ;
534573
535574 if (prefix )
@@ -544,6 +583,8 @@ int cmd_ls_files(int argc, const char **argv, const char *prefix)
544583 overlay_tree_on_cache (with_tree , prefix );
545584 }
546585 show_files (& dir , prefix );
586+ if (show_resolve_undo )
587+ show_ru_info (prefix );
547588
548589 if (ps_matched ) {
549590 int bad ;
0 commit comments