@@ -1832,6 +1832,14 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
18321832 revs -> notes_opt .use_default_notes = 1 ;
18331833 } else if (!strcmp (arg , "--show-signature" )) {
18341834 revs -> show_signature = 1 ;
1835+ } else if (!strcmp (arg , "--show-linear-break" ) ||
1836+ starts_with (arg , "--show-linear-break=" )) {
1837+ if (starts_with (arg , "--show-linear-break=" ))
1838+ revs -> break_bar = xstrdup (arg + 20 );
1839+ else
1840+ revs -> break_bar = " .........." ;
1841+ revs -> track_linear = 1 ;
1842+ revs -> track_first_time = 1 ;
18351843 } else if (starts_with (arg , "--show-notes=" ) ||
18361844 starts_with (arg , "--notes=" )) {
18371845 struct strbuf buf = STRBUF_INIT ;
@@ -1955,6 +1963,8 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
19551963 unkv [(* unkc )++ ] = arg ;
19561964 return opts ;
19571965 }
1966+ if (revs -> graph && revs -> track_linear )
1967+ die ("--show-linear-break and --graph are incompatible" );
19581968
19591969 return 1 ;
19601970}
@@ -2897,6 +2907,27 @@ enum commit_action simplify_commit(struct rev_info *revs, struct commit *commit)
28972907 return action ;
28982908}
28992909
2910+ static void track_linear (struct rev_info * revs , struct commit * commit )
2911+ {
2912+ if (revs -> track_first_time ) {
2913+ revs -> linear = 1 ;
2914+ revs -> track_first_time = 0 ;
2915+ } else {
2916+ struct commit_list * p ;
2917+ for (p = revs -> previous_parents ; p ; p = p -> next )
2918+ if (p -> item == NULL || /* first commit */
2919+ !hashcmp (p -> item -> object .sha1 , commit -> object .sha1 ))
2920+ break ;
2921+ revs -> linear = p != NULL ;
2922+ }
2923+ if (revs -> reverse ) {
2924+ if (revs -> linear )
2925+ commit -> object .flags |= TRACK_LINEAR ;
2926+ }
2927+ free_commit_list (revs -> previous_parents );
2928+ revs -> previous_parents = copy_commit_list (commit -> parents );
2929+ }
2930+
29002931static struct commit * get_revision_1 (struct rev_info * revs )
29012932{
29022933 if (!revs -> commits )
@@ -2936,6 +2967,8 @@ static struct commit *get_revision_1(struct rev_info *revs)
29362967 die ("Failed to simplify parents of commit %s" ,
29372968 sha1_to_hex (commit -> object .sha1 ));
29382969 default :
2970+ if (revs -> track_linear )
2971+ track_linear (revs , commit );
29392972 return commit ;
29402973 }
29412974 } while (revs -> commits );
@@ -3102,14 +3135,23 @@ struct commit *get_revision(struct rev_info *revs)
31023135 revs -> reverse_output_stage = 1 ;
31033136 }
31043137
3105- if (revs -> reverse_output_stage )
3106- return pop_commit (& revs -> commits );
3138+ if (revs -> reverse_output_stage ) {
3139+ c = pop_commit (& revs -> commits );
3140+ if (revs -> track_linear )
3141+ revs -> linear = !!(c && c -> object .flags & TRACK_LINEAR );
3142+ return c ;
3143+ }
31073144
31083145 c = get_revision_internal (revs );
31093146 if (c && revs -> graph )
31103147 graph_update (revs -> graph , c );
3111- if (!c )
3148+ if (!c ) {
31123149 free_saved_parents (revs );
3150+ if (revs -> previous_parents ) {
3151+ free_commit_list (revs -> previous_parents );
3152+ revs -> previous_parents = NULL ;
3153+ }
3154+ }
31133155 return c ;
31143156}
31153157
0 commit comments