Skip to content

Commit b407d40

Browse files
committed
Merge branch 'nd/log-show-linear-break'
Attempts to show where a single-strand-of-pearls break in "git log" output. * nd/log-show-linear-break: log: add --show-linear-break to help see non-linear history object.h: centralize object flag allocation
2 parents 2b06c1e + 1b32dec commit b407d40

File tree

14 files changed

+89
-11
lines changed

14 files changed

+89
-11
lines changed

Documentation/rev-list-options.txt

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

761+
--show-linear-break[=<barrier>]::
762+
When --graph is not used, all history branches are flattened
763+
which can make it hard to see that the two consecutive commits
764+
do not belong to a linear branch. This option puts a barrier
765+
in between them in that case. If `<barrier>` is specified, it
766+
is the string that will be shown instead of the default one.
767+
761768
ifdef::git-rev-list[]
762769
--count::
763770
Print a number stating how many commits would have been

bisect.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ static const char *argv_checkout[] = {"checkout", "-q", NULL, "--", NULL};
2121
static const char *argv_show_branch[] = {"show-branch", NULL, NULL};
2222
static const char *argv_update_ref[] = {"update-ref", "--no-deref", "BISECT_HEAD", NULL, NULL};
2323

24-
/* bits #0-15 in revision.h */
25-
24+
/* Remember to update object flag allocation in object.h */
2625
#define COUNTED (1u<<16)
2726

2827
/*

builtin/blame.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ static unsigned blame_copy_score;
7474
#define BLAME_DEFAULT_MOVE_SCORE 20
7575
#define BLAME_DEFAULT_COPY_SCORE 40
7676

77-
/* bits #0..7 in revision.h, #8..11 used for merge_bases() in commit.c */
77+
/* Remember to update object flag allocation in object.h */
7878
#define METAINFO_SHOWN (1u<<12)
7979
#define MORE_THAN_ONE_PATH (1u<<13)
8080

bundle.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ static int list_refs(struct ref_list *r, int argc, const char **argv)
120120
return 0;
121121
}
122122

123+
/* Remember to update object flag allocation in object.h */
123124
#define PREREQ_MARK (1u<<16)
124125

125126
int verify_bundle(struct bundle_header *header, int verbose)

commit.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -721,7 +721,7 @@ void sort_in_topological_order(struct commit_list **list, enum rev_sort_order so
721721

722722
/* merge-base stuff */
723723

724-
/* bits #0..15 in revision.h */
724+
/* Remember to update object flag allocation in object.h */
725725
#define PARENT1 (1u<<16)
726726
#define PARENT2 (1u<<17)
727727
#define STALE (1u<<18)

fetch-pack.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ static int agent_supported;
2626
static struct lock_file shallow_lock;
2727
static const char *alternate_shallow_file;
2828

29+
/* Remember to update object flag allocation in object.h */
2930
#define COMPLETE (1U << 0)
3031
#define COMMON (1U << 1)
3132
#define COMMON_REF (1U << 2)

http-push.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,7 @@ enum XML_Status {
6464
#define LOCK_TIME 600
6565
#define LOCK_REFRESH 30
6666

67-
/* bits #0-15 in revision.h */
68-
67+
/* Remember to update object flag allocation in object.h */
6968
#define LOCAL (1u<<16)
7069
#define REMOTE (1u<<17)
7170
#define FETCHING (1u<<18)

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: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,19 @@ struct object_array {
2626
#define OBJECT_ARRAY_INIT { 0, 0, NULL }
2727

2828
#define TYPE_BITS 3
29+
/*
30+
* object flag allocation:
31+
* revision.h: 0---------10 26
32+
* fetch-pack.c: 0---4
33+
* walker.c: 0-2
34+
* upload-pack.c: 11----------------19
35+
* builtin/blame.c: 12-13
36+
* bisect.c: 16
37+
* bundle.c: 16
38+
* http-push.c: 16-----19
39+
* commit.c: 16-----19
40+
* sha1_name.c: 20
41+
*/
2942
#define FLAG_BITS 27
3043

3144
/*

revision.c

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

Comments
 (0)