Skip to content

Commit 1b32dec

Browse files
pcloudsgitster
authored andcommitted
log: add --show-linear-break to help see non-linear history
Option explanation is in rev-list-options.txt. The interaction with -z is left undecided. Signed-off-by: Nguyễn Thái Ngọc Duy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 208acbf commit 1b32dec

File tree

5 files changed

+66
-5
lines changed

5 files changed

+66
-5
lines changed

Documentation/rev-list-options.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,13 @@ This enables parent rewriting, see 'History Simplification' below.
750750
This implies the `--topo-order` option by default, but the
751751
`--date-order` option may also be specified.
752752

753+
--show-linear-break[=<barrier>]::
754+
When --graph is not used, all history branches are flattened
755+
which can make it hard to see that the two consecutive commits
756+
do not belong to a linear branch. This option puts a barrier
757+
in between them in that case. If `<barrier>` is specified, it
758+
is the string that will be shown instead of the default one.
759+
753760
ifdef::git-rev-list[]
754761
--count::
755762
Print a number stating how many commits would have been

log-tree.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -805,12 +805,16 @@ int log_tree_commit(struct rev_info *opt, struct commit *commit)
805805
if (opt->line_level_traverse)
806806
return line_log_print(opt, commit);
807807

808+
if (opt->track_linear && !opt->linear && !opt->reverse_output_stage)
809+
printf("\n%s\n", opt->break_bar);
808810
shown = log_tree_diff(opt, commit, &log);
809811
if (!shown && opt->loginfo && opt->always_show_header) {
810812
log.parent = NULL;
811813
show_log(opt);
812814
shown = 1;
813815
}
816+
if (opt->track_linear && !opt->linear && opt->reverse_output_stage)
817+
printf("\n%s\n", opt->break_bar);
814818
opt->loginfo = NULL;
815819
maybe_flush_or_die(stdout, "stdout");
816820
return shown;

object.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ struct object_array {
2828
#define TYPE_BITS 3
2929
/*
3030
* object flag allocation:
31-
* revision.h: 0---------10
31+
* revision.h: 0---------10 26
3232
* fetch-pack.c: 0---4
3333
* walker.c: 0-2
3434
* upload-pack.c: 11----------------19

revision.c

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
29002931
static 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

revision.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
#define SYMMETRIC_LEFT (1u<<8)
2020
#define PATCHSAME (1u<<9)
2121
#define BOTTOM (1u<<10)
22-
#define ALL_REV_FLAGS ((1u<<11)-1)
22+
#define TRACK_LINEAR (1u<<26)
23+
#define ALL_REV_FLAGS (((1u<<11)-1) | TRACK_LINEAR)
2324

2425
#define DECORATE_SHORT_REFS 1
2526
#define DECORATE_FULL_REFS 2
@@ -138,6 +139,10 @@ struct rev_info {
138139
preserve_subject:1;
139140
unsigned int disable_stdin:1;
140141
unsigned int leak_pending:1;
142+
/* --show-linear-break */
143+
unsigned int track_linear:1,
144+
track_first_time:1,
145+
linear:1;
141146

142147
enum date_mode date_mode;
143148

@@ -196,6 +201,9 @@ struct rev_info {
196201

197202
/* copies of the parent lists, for --full-diff display */
198203
struct saved_parents *saved_parents_slab;
204+
205+
struct commit_list *previous_parents;
206+
const char *break_bar;
199207
};
200208

201209
extern int ref_excluded(struct string_list *, const char *path);

0 commit comments

Comments
 (0)