@@ -24,10 +24,12 @@ struct log_state {
2424 * up/down in the log view. */
2525 int last_lineno ;
2626 size_t graph_indent ;
27+ struct option_common optcom ;
2728 enum line_type last_type ;
2829 bool commit_title_read ;
2930 bool after_commit_header ;
3031 bool reading_diff_stat ;
32+ bool external_format ;
3133};
3234
3335static inline void
@@ -63,16 +65,39 @@ log_select(struct view *view, struct line *line)
6365 state -> last_type = line -> type ;
6466}
6567
68+ static bool
69+ log_check_external_formatter ()
70+ {
71+ /* check if any formatter arugments in "%(logargs)", "%(cmdlineargs)" */
72+ const char * * opt_list [] = {
73+ opt_log_options ,
74+ opt_cmdline_args ,
75+ };
76+ for (int i = 0 ; i < ARRAY_SIZE (opt_list ); i ++ ) {
77+ if (opt_list [i ] &&
78+ (argv_containsn (opt_list [i ], "--pretty" , STRING_SIZE ("--pretty" )) ||
79+ argv_containsn (opt_list [i ], "--format" , STRING_SIZE ("--format" ))))
80+ return true;
81+ }
82+ return false;
83+ }
84+
6685static enum status_code
6786log_open (struct view * view , enum open_flags flags )
6887{
88+ struct log_state * state = view -> private ;
89+ bool external_format = log_check_external_formatter ();
6990 const char * log_argv [] = {
7091 "git" , "log" , encoding_arg , commit_order_arg (),
7192 use_mailmap_arg (), "%(logargs)" , "%(cmdlineargs)" ,
72- "%(revargs)" , "--no-color" , "--" , "%(fileargs)" , NULL
93+ "%(revargs)" , "--no-color" ,
94+ external_format ? "" : "--pretty=fuller" ,
95+ "--" , "%(fileargs)" , NULL
7396 };
7497 enum status_code code ;
7598
99+ read_option_common (view , & state -> optcom );
100+ state -> external_format = external_format ;
76101 code = begin_update (view , NULL , log_argv , flags | OPEN_WITH_STDERR );
77102 if (code != SUCCESS )
78103 return code ;
@@ -115,6 +140,7 @@ log_read(struct view *view, struct buffer *buf, bool force_stop)
115140 size_t len ;
116141 char * commit ;
117142 char * data ;
143+ bool swap_lines = false;
118144
119145 if (!buf )
120146 return true;
@@ -148,10 +174,71 @@ log_read(struct view *view, struct buffer *buf, bool force_stop)
148174 state -> reading_diff_stat = false;
149175 }
150176
177+ if (!state -> external_format ) {
178+ switch (type )
179+ {
180+ case LINE_PP_AUTHOR :
181+ if (state -> optcom .author_as_committer )
182+ return true;
183+ break ;
184+ case LINE_PP_COMMITTER :
185+ if (!state -> optcom .author_as_committer )
186+ return true;
187+ swap_lines = state -> optcom .use_author_date ;
188+ break ;
189+ case LINE_PP_AUTHORDATE :
190+ case LINE_PP_DATE :
191+ if (!state -> optcom .use_author_date )
192+ return true;
193+ break ;
194+ case LINE_PP_COMMITDATE :
195+ if (state -> optcom .use_author_date )
196+ return true;
197+ break ;
198+ default :
199+ break ;
200+ }
201+ /* remove 4 spaces after Commit:/Author:, or
202+ * convert CommitDate:/AuthorDate: to Date: */
203+ switch (type )
204+ {
205+ case LINE_PP_AUTHOR :
206+ case LINE_PP_COMMITTER :
207+ {
208+ char * p = strchr (data , ':' );
209+ if (p && p [5 ]== ' ' )
210+ memmove (p + 1 , p + 5 , strlen (p + 5 )+ 1 );
211+ break ;
212+ }
213+ case LINE_PP_AUTHORDATE :
214+ case LINE_PP_COMMITDATE :
215+ {
216+ char * p = strchr (data , ':' );
217+ if (p && p [1 ]== ' ' && (p - data ) >= 10 ) {
218+ memcpy (p - 10 , "Date: " , STRING_SIZE ("Date: " ));
219+ memmove (p - 10 + STRING_SIZE ("Date: " ), p + 2 , strlen (p + 2 )+ 1 );
220+ }
221+ break ;
222+ }
223+ default :
224+ break ;
225+ }
226+ }
227+
151228 if (!pager_common_read (view , data , type , & line ))
152229 return false;
153230 if (line && state -> graph_indent )
154231 line -> graph_indent = 1 ;
232+ if (swap_lines && view -> lines >= 2 ) {
233+ size_t last_idx = view -> lines - 1 ;
234+ struct line * line1 = & view -> line [last_idx ];
235+ struct line * line2 = & view -> line [last_idx - 1 ];
236+ struct line buf = * line1 ;
237+ * line1 = * line2 ;
238+ * line2 = buf ;
239+ line1 -> lineno -- ;
240+ line2 -> lineno ++ ;
241+ }
155242 return true;
156243}
157244
0 commit comments