From: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
To: git@vger.kernel.org
Cc: "Junio C Hamano" <gitster@pobox.com>,
"Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Subject: [PATCH v4 2/2] log: add --show-linear-break to help see non-linear history
Date: Tue, 25 Mar 2014 20:23:27 +0700 [thread overview]
Message-ID: <1395753807-23228-2-git-send-email-pclouds@gmail.com> (raw)
In-Reply-To: <1395753807-23228-1-git-send-email-pclouds@gmail.com>
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 <pclouds@gmail.com>
---
On Fri, Mar 21, 2014 at 2:15 AM, Junio C Hamano <gitster@pobox.com> wrote:
>> * Get rid of saved_linear, use another flag in struct object instead
>
> I cannot offhand say if I like this change or not. A flag bit is a
> scarce and limited resource; commit slabs felt more suited for
> implementation of corner case eye-candies.
I leave it in bit 26. We can move it out when we run low on flag bits.
>> * Fix not showing the break bar after a root commit if the dag graph
>> has multiple roots
>
> I definitely do not like the way a commit-list data structure is
> abused to hold a phoney element that points at a NULL with its item
> pointer. Allocate a single bit in revs that says "I haven't done
> anything yet" if you want to catch the "first-ness" without breaking
> what commit_list_insert() and friends are expecting to see---they
> never expect to see a NULL asked to be on the list, AFAIK.
Fixed.
>> * Make it work with --graph (although I don't really see the point of
>> using both at the same time)
>
> I do not see the point, either. I vaguely recall that the previous
> iteration refused the combination at the option parser level, which
> I think would be the right thing to do.
Fixed.
Documentation/rev-list-options.txt | 7 ++++++
log-tree.c | 4 ++++
object.h | 2 +-
revision.c | 48 +++++++++++++++++++++++++++++++++++---
revision.h | 10 +++++++-
5 files changed, 66 insertions(+), 5 deletions(-)
diff --git a/Documentation/rev-list-options.txt b/Documentation/rev-list-options.txt
index 9a3da36..b813961 100644
--- a/Documentation/rev-list-options.txt
+++ b/Documentation/rev-list-options.txt
@@ -758,6 +758,13 @@ This enables parent rewriting, see 'History Simplification' below.
This implies the `--topo-order` option by default, but the
`--date-order` option may also be specified.
+--show-linear-break[=<barrier>]::
+ When --graph is not used, all history branches are flattened
+ which can make it hard to see that the two consecutive commits
+ do not belong to a linear branch. This option puts a barrier
+ in between them in that case. If `<barrier>` is specified, it
+ is the string that will be shown instead of the default one.
+
ifdef::git-rev-list[]
--count::
Print a number stating how many commits would have been
diff --git a/log-tree.c b/log-tree.c
index 5ce217d..cf2f86c 100644
--- a/log-tree.c
+++ b/log-tree.c
@@ -805,12 +805,16 @@ int log_tree_commit(struct rev_info *opt, struct commit *commit)
if (opt->line_level_traverse)
return line_log_print(opt, commit);
+ if (opt->track_linear && !opt->linear && !opt->reverse_output_stage)
+ printf("\n%s\n", opt->break_bar);
shown = log_tree_diff(opt, commit, &log);
if (!shown && opt->loginfo && opt->always_show_header) {
log.parent = NULL;
show_log(opt);
shown = 1;
}
+ if (opt->track_linear && !opt->linear && opt->reverse_output_stage)
+ printf("\n%s\n", opt->break_bar);
opt->loginfo = NULL;
maybe_flush_or_die(stdout, "stdout");
return shown;
diff --git a/object.h b/object.h
index 9918777..6e12f2c 100644
--- a/object.h
+++ b/object.h
@@ -28,7 +28,7 @@ struct object_array {
#define TYPE_BITS 3
/*
* object flag allocation:
- * revision.h: 0---------10
+ * revision.h: 0---------10 26
* fetch-pack.c: 0---4
* walker.c: 0-2
* upload-pack.c: 11----------------19
diff --git a/revision.c b/revision.c
index 78b5c3a..f834aa9 100644
--- a/revision.c
+++ b/revision.c
@@ -1831,6 +1831,14 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
revs->notes_opt.use_default_notes = 1;
} else if (!strcmp(arg, "--show-signature")) {
revs->show_signature = 1;
+ } else if (!strcmp(arg, "--show-linear-break") ||
+ starts_with(arg, "--show-linear-break=")) {
+ if (starts_with(arg, "--show-linear-break="))
+ revs->break_bar = xstrdup(arg + 20);
+ else
+ revs->break_bar = " ..........";
+ revs->track_linear = 1;
+ revs->track_first_time = 1;
} else if (starts_with(arg, "--show-notes=") ||
starts_with(arg, "--notes=")) {
struct strbuf buf = STRBUF_INIT;
@@ -1954,6 +1962,8 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
unkv[(*unkc)++] = arg;
return opts;
}
+ if (revs->graph && revs->track_linear)
+ die("--show-linear-break and --graph are incompatible");
return 1;
}
@@ -2896,6 +2906,27 @@ enum commit_action simplify_commit(struct rev_info *revs, struct commit *commit)
return action;
}
+static void track_linear(struct rev_info *revs, struct commit *commit)
+{
+ if (revs->track_first_time) {
+ revs->linear = 1;
+ revs->track_first_time = 0;
+ } else {
+ struct commit_list *p;
+ for (p = revs->previous_parents; p; p = p->next)
+ if (p->item == NULL || /* first commit */
+ !hashcmp(p->item->object.sha1, commit->object.sha1))
+ break;
+ revs->linear = p != NULL;
+ }
+ if (revs->reverse) {
+ if (revs->linear)
+ commit->object.flags |= TRACK_LINEAR;
+ }
+ free_commit_list(revs->previous_parents);
+ revs->previous_parents = copy_commit_list(commit->parents);
+}
+
static struct commit *get_revision_1(struct rev_info *revs)
{
if (!revs->commits)
@@ -2935,6 +2966,8 @@ static struct commit *get_revision_1(struct rev_info *revs)
die("Failed to simplify parents of commit %s",
sha1_to_hex(commit->object.sha1));
default:
+ if (revs->track_linear)
+ track_linear(revs, commit);
return commit;
}
} while (revs->commits);
@@ -3101,14 +3134,23 @@ struct commit *get_revision(struct rev_info *revs)
revs->reverse_output_stage = 1;
}
- if (revs->reverse_output_stage)
- return pop_commit(&revs->commits);
+ if (revs->reverse_output_stage) {
+ c = pop_commit(&revs->commits);
+ if (revs->track_linear)
+ revs->linear = !!(c && c->object.flags & TRACK_LINEAR);
+ return c;
+ }
c = get_revision_internal(revs);
if (c && revs->graph)
graph_update(revs->graph, c);
- if (!c)
+ if (!c) {
free_saved_parents(revs);
+ if (revs->previous_parents) {
+ free_commit_list(revs->previous_parents);
+ revs->previous_parents = NULL;
+ }
+ }
return c;
}
diff --git a/revision.h b/revision.h
index 0262bbd..d9907dd 100644
--- a/revision.h
+++ b/revision.h
@@ -19,7 +19,8 @@
#define SYMMETRIC_LEFT (1u<<8)
#define PATCHSAME (1u<<9)
#define BOTTOM (1u<<10)
-#define ALL_REV_FLAGS ((1u<<11)-1)
+#define TRACK_LINEAR (1u<<26)
+#define ALL_REV_FLAGS (((1u<<11)-1) | TRACK_LINEAR)
#define DECORATE_SHORT_REFS 1
#define DECORATE_FULL_REFS 2
@@ -138,6 +139,10 @@ struct rev_info {
preserve_subject:1;
unsigned int disable_stdin:1;
unsigned int leak_pending:1;
+ /* --show-linear-break */
+ unsigned int track_linear:1,
+ track_first_time:1,
+ linear:1;
enum date_mode date_mode;
@@ -198,6 +203,9 @@ struct rev_info {
/* copies of the parent lists, for --full-diff display */
struct saved_parents *saved_parents_slab;
+
+ struct commit_list *previous_parents;
+ const char *break_bar;
};
extern int ref_excluded(struct string_list *, const char *path);
--
1.9.1.345.ga1a145c
next prev parent reply other threads:[~2014-03-25 13:22 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-02-06 14:02 Confusing git log --- First time bug submission please advise on best practices Francis Stephens
2014-02-06 16:08 ` Vincent van Ravesteijn
2014-02-06 16:10 ` David Kastrup
2014-02-07 9:43 ` Francis Stephens
2014-02-07 10:26 ` Duy Nguyen
2014-02-07 11:37 ` demerphq
2014-02-08 13:50 ` [PATCH] log: add --show-linear-break to help see non-linear history Nguyễn Thái Ngọc Duy
2014-03-17 12:51 ` [PATCH v2] log: add --nonlinear-barrier " Nguyễn Thái Ngọc Duy
2014-03-17 19:09 ` Eric Sunshine
2014-03-17 20:32 ` Junio C Hamano
2014-03-18 11:46 ` Duy Nguyen
2014-03-18 19:08 ` Junio C Hamano
2014-03-20 5:44 ` [PATCH v3 1/2] object.h: centralize object flag allocation Nguyễn Thái Ngọc Duy
2014-03-20 5:44 ` [PATCH v3 2/2] log: add --show-linear-break to help see non-linear history Nguyễn Thái Ngọc Duy
2014-03-20 19:15 ` Junio C Hamano
2014-03-21 1:02 ` Duy Nguyen
2014-03-25 13:23 ` [PATCH v4 1/2] object.h: centralize object flag allocation Nguyễn Thái Ngọc Duy
2014-03-25 13:23 ` Nguyễn Thái Ngọc Duy [this message]
2014-03-25 22:30 ` [PATCH v4 2/2] log: add --show-linear-break to help see non-linear history Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1395753807-23228-2-git-send-email-pclouds@gmail.com \
--to=pclouds@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).