9
9
#include "quote.h"
10
10
#include "run-command.h"
11
11
#include "remote.h"
12
+ #include "refs.h"
12
13
13
14
static char default_wt_status_colors [][COLOR_MAXLEN ] = {
14
15
GIT_COLOR_NORMAL , /* WT_STATUS_HEADER */
@@ -17,6 +18,8 @@ static char default_wt_status_colors[][COLOR_MAXLEN] = {
17
18
GIT_COLOR_RED , /* WT_STATUS_UNTRACKED */
18
19
GIT_COLOR_RED , /* WT_STATUS_NOBRANCH */
19
20
GIT_COLOR_RED , /* WT_STATUS_UNMERGED */
21
+ GIT_COLOR_GREEN , /* WT_STATUS_LOCAL_BRANCH */
22
+ GIT_COLOR_RED , /* WT_STATUS_REMOTE_BRANCH */
20
23
};
21
24
22
25
static const char * color (int slot , struct wt_status * s )
@@ -756,9 +759,69 @@ static void wt_shortstatus_other(int null_termination, struct string_list_item *
756
759
}
757
760
}
758
761
759
- void wt_shortstatus_print (struct wt_status * s , int null_termination )
762
+ static void wt_shortstatus_print_tracking (struct wt_status * s )
763
+ {
764
+ struct branch * branch ;
765
+ const char * header_color = color (WT_STATUS_HEADER , s );
766
+ const char * branch_color_local = color (WT_STATUS_LOCAL_BRANCH , s );
767
+ const char * branch_color_remote = color (WT_STATUS_REMOTE_BRANCH , s );
768
+
769
+ const char * base ;
770
+ const char * branch_name ;
771
+ int num_ours , num_theirs ;
772
+
773
+ color_fprintf (s -> fp , color (WT_STATUS_HEADER , s ), "## " );
774
+
775
+ if (!s -> branch )
776
+ return ;
777
+ branch_name = s -> branch ;
778
+
779
+ if (!prefixcmp (branch_name , "refs/heads/" ))
780
+ branch_name += 11 ;
781
+ else if (!strcmp (branch_name , "HEAD" )) {
782
+ branch_name = "HEAD (no branch)" ;
783
+ branch_color_local = color (WT_STATUS_NOBRANCH , s );
784
+ }
785
+
786
+ branch = branch_get (s -> branch + 11 );
787
+ if (s -> is_initial )
788
+ color_fprintf (s -> fp , header_color , "Initial commit on " );
789
+ if (!stat_tracking_info (branch , & num_ours , & num_theirs )) {
790
+ color_fprintf_ln (s -> fp , branch_color_local ,
791
+ "%s" , branch_name );
792
+ return ;
793
+ }
794
+
795
+ base = branch -> merge [0 ]-> dst ;
796
+ base = shorten_unambiguous_ref (base , 0 );
797
+ color_fprintf (s -> fp , branch_color_local , "%s" , branch_name );
798
+ color_fprintf (s -> fp , header_color , "..." );
799
+ color_fprintf (s -> fp , branch_color_remote , "%s" , base );
800
+
801
+ color_fprintf (s -> fp , header_color , " [" );
802
+ if (!num_ours ) {
803
+ color_fprintf (s -> fp , header_color , "behind " );
804
+ color_fprintf (s -> fp , branch_color_remote , "%d" , num_theirs );
805
+ } else if (!num_theirs ) {
806
+ color_fprintf (s -> fp , header_color , "ahead " );
807
+ color_fprintf (s -> fp , branch_color_local , "%d" , num_ours );
808
+ } else {
809
+ color_fprintf (s -> fp , header_color , "ahead " );
810
+ color_fprintf (s -> fp , branch_color_local , "%d" , num_ours );
811
+ color_fprintf (s -> fp , header_color , ", behind " );
812
+ color_fprintf (s -> fp , branch_color_remote , "%d" , num_theirs );
813
+ }
814
+
815
+ color_fprintf_ln (s -> fp , header_color , "]" );
816
+ }
817
+
818
+ void wt_shortstatus_print (struct wt_status * s , int null_termination , int show_branch )
760
819
{
761
820
int i ;
821
+
822
+ if (show_branch )
823
+ wt_shortstatus_print_tracking (s );
824
+
762
825
for (i = 0 ; i < s -> change .nr ; i ++ ) {
763
826
struct wt_status_change_data * d ;
764
827
struct string_list_item * it ;
@@ -789,5 +852,5 @@ void wt_porcelain_print(struct wt_status *s, int null_termination)
789
852
s -> use_color = 0 ;
790
853
s -> relative_paths = 0 ;
791
854
s -> prefix = NULL ;
792
- wt_shortstatus_print (s , null_termination );
855
+ wt_shortstatus_print (s , null_termination , 0 );
793
856
}
0 commit comments