@@ -18,6 +18,11 @@ static int show_stage = 0;
1818static int show_unmerged = 0 ;
1919static int line_terminator = '\n' ;
2020
21+ static const char * tag_cached = "" ;
22+ static const char * tag_unmerged = "" ;
23+ static const char * tag_removed = "" ;
24+ static const char * tag_other = "" ;
25+
2126static int nr_excludes ;
2227static const char * * excludes ;
2328static int excludes_alloc ;
@@ -143,7 +148,8 @@ static void read_directory(const char *path, const char *base, int baselen)
143148 /* fallthrough */
144149 case DT_DIR :
145150 memcpy (fullname + baselen + len , "/" , 2 );
146- read_directory (fullname , fullname , baselen + len + 1 );
151+ read_directory (fullname , fullname ,
152+ baselen + len + 1 );
147153 continue ;
148154 case DT_REG :
149155 break ;
@@ -172,7 +178,7 @@ static void show_files(void)
172178 read_directory ("." , "" , 0 );
173179 qsort (dir , nr_dir , sizeof (char * ), cmp_name );
174180 for (i = 0 ; i < nr_dir ; i ++ )
175- printf ("%s%c" , dir [i ], line_terminator );
181+ printf ("%s%s%c" , tag_other , dir [i ], line_terminator );
176182 }
177183 if (show_cached | show_stage ) {
178184 for (i = 0 ; i < active_nr ; i ++ ) {
@@ -182,14 +188,17 @@ static void show_files(void)
182188 if (show_unmerged && !ce_stage (ce ))
183189 continue ;
184190 if (!show_stage )
185- printf ("%s%c" , ce -> name , line_terminator );
191+ printf ("%s%s%c" ,
192+ ce_stage (ce ) ? tag_unmerged :
193+ tag_cached ,
194+ ce -> name , line_terminator );
186195 else
187- printf (/* "%06o %s %d %10d %s%c", */
188- "%06o %s %d %s%c" ,
196+ printf ("%s%06o %s %d %s%c" ,
197+ ce_stage (ce ) ? tag_unmerged :
198+ tag_cached ,
189199 ntohl (ce -> ce_mode ),
190200 sha1_to_hex (ce -> sha1 ),
191201 ce_stage (ce ),
192- /* ntohl(ce->ce_size), */
193202 ce -> name , line_terminator );
194203 }
195204 }
@@ -201,13 +210,14 @@ static void show_files(void)
201210 continue ;
202211 if (!lstat (ce -> name , & st ))
203212 continue ;
204- printf ("%s%c" , ce -> name , line_terminator );
213+ printf ("%s%s%c" , tag_removed , ce -> name ,
214+ line_terminator );
205215 }
206216 }
207217}
208218
209219static const char * ls_files_usage =
210- "ls-files [-z] (--[cached|deleted|others|stage|unmerged])* "
220+ "ls-files [-z] [-t] (--[cached|deleted|others|stage|unmerged])* "
211221 "[ --ignored [--exclude=<pattern>] [--exclude-from=<file>) ]" ;
212222
213223int main (int argc , char * * argv )
@@ -219,6 +229,11 @@ int main(int argc, char **argv)
219229
220230 if (!strcmp (arg , "-z" )) {
221231 line_terminator = 0 ;
232+ } else if (!strcmp (arg , "-t" )) {
233+ tag_cached = "H " ;
234+ tag_unmerged = "M " ;
235+ tag_removed = "R " ;
236+ tag_other = "? " ;
222237 } else if (!strcmp (arg , "-c" ) || !strcmp (arg , "--cached" )) {
223238 show_cached = 1 ;
224239 } else if (!strcmp (arg , "-d" ) || !strcmp (arg , "--deleted" )) {
@@ -230,7 +245,9 @@ int main(int argc, char **argv)
230245 } else if (!strcmp (arg , "-s" ) || !strcmp (arg , "--stage" )) {
231246 show_stage = 1 ;
232247 } else if (!strcmp (arg , "-u" ) || !strcmp (arg , "--unmerged" )) {
233- // There's no point in showing unmerged unless you also show the stage information
248+ /* There's no point in showing unmerged unless
249+ * you also show the stage information.
250+ */
234251 show_stage = 1 ;
235252 show_unmerged = 1 ;
236253 } else if (!strcmp (arg , "-x" ) && i + 1 < argc ) {
@@ -246,7 +263,8 @@ int main(int argc, char **argv)
246263 }
247264
248265 if (show_ignored && !nr_excludes ) {
249- fprintf (stderr , "%s: --ignored needs some exclude pattern\n" , argv [0 ]);
266+ fprintf (stderr , "%s: --ignored needs some exclude pattern\n" ,
267+ argv [0 ]);
250268 exit (1 );
251269 }
252270
0 commit comments