@@ -2293,18 +2293,6 @@ draw_field(struct view *view, enum line_type type, const char *text, int width,
2293
2293
|| draw_space (view , LINE_DEFAULT , max - (view -> col - col ), max );
2294
2294
}
2295
2295
2296
- static bool PRINTF_LIKE (4 , 5 )
2297
- draw_formatted_field (struct view * view , enum line_type type , int width , const char * format , ...)
2298
- {
2299
- char text [SIZEOF_STR ];
2300
- int retval ;
2301
-
2302
- FORMAT_BUFFER (text , sizeof (text ), format , retval , TRUE );
2303
- if (retval < 0 )
2304
- return VIEW_MAX_LEN (view ) <= 0 ;
2305
- return draw_field (view , type , text , width , ALIGN_LEFT , FALSE );
2306
- }
2307
-
2308
2296
static bool
2309
2297
draw_date (struct view * view , struct time * time )
2310
2298
{
@@ -7636,6 +7624,8 @@ static bool draw_graph(struct view *view, struct graph_canvas *canvas)
7636
7624
* Main view backend
7637
7625
*/
7638
7626
7627
+ DEFINE_ALLOCATOR (realloc_reflogs , char * , 32 )
7628
+
7639
7629
struct commit {
7640
7630
char id [SIZEOF_REV ]; /* SHA1 ID. */
7641
7631
const struct ident * author ; /* Author of the commit. */
@@ -7647,7 +7637,10 @@ struct commit {
7647
7637
struct main_state {
7648
7638
struct graph graph ;
7649
7639
struct commit current ;
7650
- int id_width ;
7640
+ char * * reflog ;
7641
+ size_t reflogs ;
7642
+ int reflog_width ;
7643
+ char reflogmsg [SIZEOF_STR / 2 ];
7651
7644
bool in_header ;
7652
7645
bool added_changes_commits ;
7653
7646
bool with_graph ;
@@ -7685,6 +7678,7 @@ main_add_commit(struct view *view, enum line_type type, struct commit *template,
7685
7678
strncpy (commit -> title , title , titlelen );
7686
7679
state -> graph .canvas = & commit -> graph ;
7687
7680
memset (template , 0 , sizeof (* template ));
7681
+ state -> reflogmsg [0 ] = 0 ;
7688
7682
return commit ;
7689
7683
}
7690
7684
@@ -7774,13 +7768,18 @@ main_open(struct view *view, enum open_flags flags)
7774
7768
static void
7775
7769
main_done (struct view * view )
7776
7770
{
7771
+ struct main_state * state = view -> private ;
7777
7772
int i ;
7778
7773
7779
7774
for (i = 0 ; i < view -> lines ; i ++ ) {
7780
7775
struct commit * commit = view -> line [i ].data ;
7781
7776
7782
7777
free (commit -> graph .symbols );
7783
7778
}
7779
+
7780
+ for (i = 0 ; i < state -> reflogs ; i ++ )
7781
+ free (state -> reflog [i ]);
7782
+ free (state -> reflog );
7784
7783
}
7785
7784
7786
7785
#define MAIN_NO_COMMIT_REFS 1
@@ -7812,9 +7811,10 @@ main_draw(struct view *view, struct line *line, unsigned int lineno)
7812
7811
return TRUE;
7813
7812
7814
7813
if (opt_show_id ) {
7815
- if (state -> id_width ) {
7816
- if (draw_formatted_field (view , LINE_ID , state -> id_width ,
7817
- "stash@{%d}" , line -> lineno - 1 ))
7814
+ if (state -> reflogs ) {
7815
+ const char * id = state -> reflog [line -> lineno - 1 ];
7816
+
7817
+ if (draw_id_custom (view , LINE_ID , id , state -> reflog_width ))
7818
7818
return TRUE;
7819
7819
} else if (draw_id (view , commit -> id )) {
7820
7820
return TRUE;
@@ -7838,6 +7838,31 @@ main_draw(struct view *view, struct line *line, unsigned int lineno)
7838
7838
return TRUE;
7839
7839
}
7840
7840
7841
+ static bool
7842
+ main_add_reflog (struct view * view , struct main_state * state , char * reflog )
7843
+ {
7844
+ char * end = strchr (reflog , ' ' );
7845
+ int id_width ;
7846
+
7847
+ if (!end )
7848
+ return FALSE;
7849
+ * end = 0 ;
7850
+
7851
+ if (!realloc_reflogs (& state -> reflog , state -> reflogs , 1 )
7852
+ || !(reflog = strdup (reflog )))
7853
+ return FALSE;
7854
+
7855
+ state -> reflog [state -> reflogs ++ ] = reflog ;
7856
+ id_width = strlen (reflog );
7857
+ if (state -> reflog_width < id_width ) {
7858
+ state -> reflog_width = id_width ;
7859
+ if (opt_show_id )
7860
+ view -> force_redraw = TRUE;
7861
+ }
7862
+
7863
+ return TRUE;
7864
+ }
7865
+
7841
7866
/* Reads git log --pretty=raw output and parses it into the commit struct. */
7842
7867
static bool
7843
7868
main_read (struct view * view , char * line )
@@ -7894,6 +7919,16 @@ main_read(struct view *view, char *line)
7894
7919
state -> in_header = FALSE;
7895
7920
7896
7921
switch (type ) {
7922
+ case LINE_PP_REFLOG :
7923
+ if (!main_add_reflog (view , state , line + STRING_SIZE ("Reflog: " )))
7924
+ return FALSE;
7925
+ break ;
7926
+
7927
+ case LINE_PP_REFLOGMSG :
7928
+ line += STRING_SIZE ("Reflog message: " );
7929
+ string_ncopy (state -> reflogmsg , line , strlen (line ));
7930
+ break ;
7931
+
7897
7932
case LINE_PARENT :
7898
7933
if (state -> with_graph && !graph -> has_parents )
7899
7934
graph_add_parent (graph , line + STRING_SIZE ("parent " ));
@@ -7926,6 +7961,8 @@ main_read(struct view *view, char *line)
7926
7961
line ++ ;
7927
7962
if (* line == '\0' )
7928
7963
break ;
7964
+ if (* state -> reflogmsg )
7965
+ line = state -> reflogmsg ;
7929
7966
main_add_commit (view , LINE_MAIN_COMMIT , commit , line , FALSE);
7930
7967
}
7931
7968
@@ -8068,32 +8105,11 @@ stash_open(struct view *view, enum open_flags flags)
8068
8105
{
8069
8106
static const char * stash_argv [] = { "git" , "stash" , "list" ,
8070
8107
opt_encoding_arg , "--no-color" , "--pretty=raw" , NULL };
8071
-
8072
- return begin_update (view , NULL , stash_argv , flags | OPEN_RELOAD );
8073
- }
8074
-
8075
- static bool
8076
- stash_read (struct view * view , char * line )
8077
- {
8078
8108
struct main_state * state = view -> private ;
8079
- struct commit * commit = & state -> current ;
8080
-
8081
- if (!state -> added_changes_commits ) {
8082
- state -> added_changes_commits = TRUE;
8083
- state -> with_graph = FALSE;
8084
- }
8085
-
8086
- if (commit && line && get_line_type (line ) == LINE_PP_REFLOG ) {
8087
- int id_width = STRING_SIZE ("stash@{}" ) + count_digits (view -> lines );
8088
8109
8089
- if (state -> id_width < id_width ) {
8090
- state -> id_width = id_width ;
8091
- if (opt_show_id )
8092
- view -> force_redraw = TRUE;
8093
- }
8094
- }
8095
-
8096
- return main_read (view , line );
8110
+ state -> added_changes_commits = TRUE;
8111
+ state -> with_graph = FALSE;
8112
+ return begin_update (view , NULL , stash_argv , flags | OPEN_RELOAD );
8097
8113
}
8098
8114
8099
8115
static void
@@ -8110,7 +8126,7 @@ static struct view_ops stash_ops = {
8110
8126
VIEW_SEND_CHILD_ENTER ,
8111
8127
sizeof (struct main_state ),
8112
8128
stash_open ,
8113
- stash_read ,
8129
+ main_read ,
8114
8130
main_draw ,
8115
8131
main_request ,
8116
8132
main_grep ,
0 commit comments