16
16
#include "strvec.h"
17
17
#include "commit-reach.h"
18
18
#include "progress.h"
19
+ #include "utf8.h"
19
20
20
21
static const char * const builtin_remote_usage [] = {
21
22
"git remote [-v | --verbose]" ,
@@ -1279,6 +1280,20 @@ static int get_one_entry(struct remote *remote, void *priv)
1279
1280
return 0 ;
1280
1281
}
1281
1282
1283
+ static int calc_maxwidth (struct string_list * list )
1284
+ {
1285
+ int max = 0 ;
1286
+ struct string_list_item * item ;
1287
+
1288
+ for_each_string_list_item (item , list ) {
1289
+ int w = utf8_strwidth (item -> string );
1290
+
1291
+ if (w > max )
1292
+ max = w ;
1293
+ }
1294
+ return max ;
1295
+ }
1296
+
1282
1297
static int show_all (void )
1283
1298
{
1284
1299
struct string_list list = STRING_LIST_INIT_DUP ;
@@ -1287,16 +1302,25 @@ static int show_all(void)
1287
1302
result = for_each_remote (get_one_entry , & list );
1288
1303
1289
1304
if (!result ) {
1290
- int i ;
1305
+ int maxwidth = 0 ;
1306
+ struct string_list_item * item ;
1291
1307
1308
+ if (verbose )
1309
+ maxwidth = calc_maxwidth (& list );
1292
1310
string_list_sort (& list );
1293
- for (i = 0 ; i < list .nr ; i ++ ) {
1294
- struct string_list_item * item = list .items + i ;
1295
- if (verbose )
1296
- printf ("%s\t%s\n" , item -> string ,
1297
- item -> util ? (const char * )item -> util : "" );
1298
- else {
1299
- if (i && !strcmp ((item - 1 )-> string , item -> string ))
1311
+ for_each_string_list_item (item , & list ) {
1312
+ if (verbose ) {
1313
+ struct strbuf s = STRBUF_INIT ;
1314
+
1315
+ strbuf_utf8_align (& s , ALIGN_LEFT , maxwidth + 1 ,
1316
+ item -> string );
1317
+ if (item -> util )
1318
+ strbuf_addstr (& s , item -> util );
1319
+ printf ("%s\n" , s .buf );
1320
+ strbuf_release (& s );
1321
+ } else {
1322
+ if (item != list .items &&
1323
+ !strcmp ((item - 1 )-> string , item -> string ))
1300
1324
continue ;
1301
1325
printf ("%s\n" , item -> string );
1302
1326
}
0 commit comments