15
15
#include "submodule.h"
16
16
#include "column.h"
17
17
#include "strbuf.h"
18
+ #include "utf8.h"
18
19
19
20
static char default_wt_status_colors [][COLOR_MAXLEN ] = {
20
21
GIT_COLOR_NORMAL , /* WT_STATUS_HEADER */
@@ -264,6 +265,30 @@ static void wt_status_print_unmerged_data(struct wt_status *s,
264
265
strbuf_release (& onebuf );
265
266
}
266
267
268
+ static const char * wt_status_diff_status_string (int status )
269
+ {
270
+ switch (status ) {
271
+ case DIFF_STATUS_ADDED :
272
+ return _ ("new file" );
273
+ case DIFF_STATUS_COPIED :
274
+ return _ ("copied" );
275
+ case DIFF_STATUS_DELETED :
276
+ return _ ("deleted" );
277
+ case DIFF_STATUS_MODIFIED :
278
+ return _ ("modified" );
279
+ case DIFF_STATUS_RENAMED :
280
+ return _ ("renamed" );
281
+ case DIFF_STATUS_TYPE_CHANGED :
282
+ return _ ("typechange" );
283
+ case DIFF_STATUS_UNKNOWN :
284
+ return _ ("unknown" );
285
+ case DIFF_STATUS_UNMERGED :
286
+ return _ ("unmerged" );
287
+ default :
288
+ return NULL ;
289
+ }
290
+ }
291
+
267
292
static void wt_status_print_change_data (struct wt_status * s ,
268
293
int change_type ,
269
294
struct string_list_item * it )
@@ -276,6 +301,23 @@ static void wt_status_print_change_data(struct wt_status *s,
276
301
const char * one , * two ;
277
302
struct strbuf onebuf = STRBUF_INIT , twobuf = STRBUF_INIT ;
278
303
struct strbuf extra = STRBUF_INIT ;
304
+ static char * padding ;
305
+ const char * what ;
306
+ int len ;
307
+
308
+ if (!padding ) {
309
+ int width = 0 ;
310
+ /* If DIFF_STATUS_* uses outside this range, we're in trouble */
311
+ for (status = 'A' ; status <= 'Z' ; status ++ ) {
312
+ what = wt_status_diff_status_string (status );
313
+ len = what ? strlen (what ) : 0 ;
314
+ if (len > width )
315
+ width = len ;
316
+ }
317
+ width += 2 ; /* colon and a space */
318
+ padding = xmallocz (width );
319
+ memset (padding , ' ' , width );
320
+ }
279
321
280
322
one_name = two_name = it -> string ;
281
323
switch (change_type ) {
@@ -307,34 +349,18 @@ static void wt_status_print_change_data(struct wt_status *s,
307
349
two = quote_path (two_name , s -> prefix , & twobuf );
308
350
309
351
status_printf (s , color (WT_STATUS_HEADER , s ), "\t" );
310
- switch (status ) {
311
- case DIFF_STATUS_ADDED :
312
- status_printf_more (s , c , _ ("new file: %s" ), one );
313
- break ;
314
- case DIFF_STATUS_COPIED :
315
- status_printf_more (s , c , _ ("copied: %s -> %s" ), one , two );
316
- break ;
317
- case DIFF_STATUS_DELETED :
318
- status_printf_more (s , c , _ ("deleted: %s" ), one );
319
- break ;
320
- case DIFF_STATUS_MODIFIED :
321
- status_printf_more (s , c , _ ("modified: %s" ), one );
322
- break ;
323
- case DIFF_STATUS_RENAMED :
324
- status_printf_more (s , c , _ ("renamed: %s -> %s" ), one , two );
325
- break ;
326
- case DIFF_STATUS_TYPE_CHANGED :
327
- status_printf_more (s , c , _ ("typechange: %s" ), one );
328
- break ;
329
- case DIFF_STATUS_UNKNOWN :
330
- status_printf_more (s , c , _ ("unknown: %s" ), one );
331
- break ;
332
- case DIFF_STATUS_UNMERGED :
333
- status_printf_more (s , c , _ ("unmerged: %s" ), one );
334
- break ;
335
- default :
352
+ what = wt_status_diff_status_string (status );
353
+ if (!what )
336
354
die (_ ("bug: unhandled diff status %c" ), status );
337
- }
355
+ /* 1 for colon, which is not part of "what" */
356
+ len = strlen (padding ) - (utf8_strwidth (what ) + 1 );
357
+ assert (len >= 0 );
358
+ if (status == DIFF_STATUS_COPIED || status == DIFF_STATUS_RENAMED )
359
+ status_printf_more (s , c , "%s:%.*s%s -> %s" ,
360
+ what , len , padding , one , two );
361
+ else
362
+ status_printf_more (s , c , "%s:%.*s%s" ,
363
+ what , len , padding , one );
338
364
if (extra .len ) {
339
365
status_printf_more (s , color (WT_STATUS_HEADER , s ), "%s" , extra .buf );
340
366
strbuf_release (& extra );
0 commit comments