@@ -1837,6 +1837,14 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
18371837 revs -> notes_opt .use_default_notes = 1 ;
18381838 } else if (!strcmp (arg , "--show-signature" )) {
18391839 revs -> show_signature = 1 ;
1840+ } else if (!strcmp (arg , "--show-linear-break" ) ||
1841+ starts_with (arg , "--show-linear-break=" )) {
1842+ if (starts_with (arg , "--show-linear-break=" ))
1843+ revs -> break_bar = xstrdup (arg + 20 );
1844+ else
1845+ revs -> break_bar = " .........." ;
1846+ revs -> track_linear = 1 ;
1847+ revs -> track_first_time = 1 ;
18401848 } else if (starts_with (arg , "--show-notes=" ) ||
18411849 starts_with (arg , "--notes=" )) {
18421850 struct strbuf buf = STRBUF_INIT ;
@@ -1960,6 +1968,8 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
19601968 unkv [(* unkc )++ ] = arg ;
19611969 return opts ;
19621970 }
1971+ if (revs -> graph && revs -> track_linear )
1972+ die ("--show-linear-break and --graph are incompatible" );
19631973
19641974 return 1 ;
19651975}
@@ -2902,6 +2912,27 @@ enum commit_action simplify_commit(struct rev_info *revs, struct commit *commit)
29022912 return action ;
29032913}
29042914
2915+ static void track_linear (struct rev_info * revs , struct commit * commit )
2916+ {
2917+ if (revs -> track_first_time ) {
2918+ revs -> linear = 1 ;
2919+ revs -> track_first_time = 0 ;
2920+ } else {
2921+ struct commit_list * p ;
2922+ for (p = revs -> previous_parents ; p ; p = p -> next )
2923+ if (p -> item == NULL || /* first commit */
2924+ !hashcmp (p -> item -> object .sha1 , commit -> object .sha1 ))
2925+ break ;
2926+ revs -> linear = p != NULL ;
2927+ }
2928+ if (revs -> reverse ) {
2929+ if (revs -> linear )
2930+ commit -> object .flags |= TRACK_LINEAR ;
2931+ }
2932+ free_commit_list (revs -> previous_parents );
2933+ revs -> previous_parents = copy_commit_list (commit -> parents );
2934+ }
2935+
29052936static struct commit * get_revision_1 (struct rev_info * revs )
29062937{
29072938 if (!revs -> commits )
@@ -2941,6 +2972,8 @@ static struct commit *get_revision_1(struct rev_info *revs)
29412972 die ("Failed to simplify parents of commit %s" ,
29422973 sha1_to_hex (commit -> object .sha1 ));
29432974 default :
2975+ if (revs -> track_linear )
2976+ track_linear (revs , commit );
29442977 return commit ;
29452978 }
29462979 } while (revs -> commits );
@@ -3107,14 +3140,23 @@ struct commit *get_revision(struct rev_info *revs)
31073140 revs -> reverse_output_stage = 1 ;
31083141 }
31093142
3110- if (revs -> reverse_output_stage )
3111- return pop_commit (& revs -> commits );
3143+ if (revs -> reverse_output_stage ) {
3144+ c = pop_commit (& revs -> commits );
3145+ if (revs -> track_linear )
3146+ revs -> linear = !!(c && c -> object .flags & TRACK_LINEAR );
3147+ return c ;
3148+ }
31123149
31133150 c = get_revision_internal (revs );
31143151 if (c && revs -> graph )
31153152 graph_update (revs -> graph , c );
3116- if (!c )
3153+ if (!c ) {
31173154 free_saved_parents (revs );
3155+ if (revs -> previous_parents ) {
3156+ free_commit_list (revs -> previous_parents );
3157+ revs -> previous_parents = NULL ;
3158+ }
3159+ }
31183160 return c ;
31193161}
31203162
0 commit comments