git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
To: git@vger.kernel.org
Cc: "Junio C Hamano" <gitster@pobox.com>, "Jeff King" <peff@peff.net>,
	"Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Subject: [PATCH v2 08/14] revision.c: use commit-slab for show_source
Date: Sun, 13 May 2018 07:52:02 +0200	[thread overview]
Message-ID: <20180513055208.17952-9-pclouds@gmail.com> (raw)
In-Reply-To: <20180513055208.17952-1-pclouds@gmail.com>

Instead of relying on commit->util to store the source string, let the
user provide a commit-slab to store the source strings in.

It's done so that commit->util can be removed. See more explanation in
the commit that removes commit->util.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 builtin/fast-export.c | 14 +++++++++-----
 builtin/log.c         |  7 +++++--
 log-tree.c            |  8 ++++++--
 revision.c            | 19 +++++++++++++++----
 revision.h            |  5 ++++-
 5 files changed, 39 insertions(+), 14 deletions(-)

diff --git a/builtin/fast-export.c b/builtin/fast-export.c
index 530df12f05..b08e5ea0e3 100644
--- a/builtin/fast-export.c
+++ b/builtin/fast-export.c
@@ -21,6 +21,7 @@
 #include "quote.h"
 #include "remote.h"
 #include "blob.h"
+#include "commit-slab.h"
 
 static const char *fast_export_usage[] = {
 	N_("git fast-export [rev-list-opts]"),
@@ -38,6 +39,7 @@ static struct string_list extra_refs = STRING_LIST_INIT_NODUP;
 static struct refspec *refspecs;
 static int refspecs_nr;
 static int anonymize;
+static struct revision_sources revision_sources;
 
 static int parse_opt_signed_tag_mode(const struct option *opt,
 				     const char *arg, int unset)
@@ -590,7 +592,7 @@ static void handle_commit(struct commit *commit, struct rev_info *rev,
 		if (!S_ISGITLINK(diff_queued_diff.queue[i]->two->mode))
 			export_blob(&diff_queued_diff.queue[i]->two->oid);
 
-	refname = commit->util;
+	refname = *revision_sources_peek(&revision_sources, commit);
 	if (anonymize) {
 		refname = anonymize_refname(refname);
 		anonymize_ident_line(&committer, &committer_end);
@@ -862,10 +864,11 @@ static void get_tags_and_duplicates(struct rev_cmdline_info *info)
 		 * This ref will not be updated through a commit, lets make
 		 * sure it gets properly updated eventually.
 		 */
-		if (commit->util || commit->object.flags & SHOWN)
+		if (*revision_sources_at(&revision_sources, commit) ||
+		    commit->object.flags & SHOWN)
 			string_list_append(&extra_refs, full_name)->util = commit;
-		if (!commit->util)
-			commit->util = full_name;
+		if (!*revision_sources_at(&revision_sources, commit))
+			*revision_sources_at(&revision_sources, commit) = full_name;
 	}
 }
 
@@ -1029,8 +1032,9 @@ int cmd_fast_export(int argc, const char **argv, const char *prefix)
 	git_config(git_default_config, NULL);
 
 	init_revisions(&revs, prefix);
+	init_revision_sources(&revision_sources);
 	revs.topo_order = 1;
-	revs.show_source = 1;
+	revs.sources = &revision_sources;
 	revs.rewrite_parents = 1;
 	argc = parse_options(argc, argv, prefix, options, fast_export_usage,
 			PARSE_OPT_KEEP_ARGV0 | PARSE_OPT_KEEP_UNKNOWN);
diff --git a/builtin/log.c b/builtin/log.c
index 71f68a3e4f..d017e57475 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -148,6 +148,7 @@ static void cmd_log_init_finish(int argc, const char **argv, const char *prefix,
 	static struct string_list decorate_refs_include = STRING_LIST_INIT_NODUP;
 	struct decoration_filter decoration_filter = {&decorate_refs_include,
 						      &decorate_refs_exclude};
+	static struct revision_sources revision_sources;
 
 	const struct option builtin_log_options[] = {
 		OPT__QUIET(&quiet, N_("suppress diff output")),
@@ -194,8 +195,10 @@ static void cmd_log_init_finish(int argc, const char **argv, const char *prefix,
 	    rev->diffopt.filter || rev->diffopt.flags.follow_renames)
 		rev->always_show_header = 0;
 
-	if (source)
-		rev->show_source = 1;
+	if (source) {
+		init_revision_sources(&revision_sources);
+		rev->sources = &revision_sources;
+	}
 
 	if (mailmap) {
 		rev->mailmap = xcalloc(1, sizeof(struct string_list));
diff --git a/log-tree.c b/log-tree.c
index d1c0bedf24..0b41ee3235 100644
--- a/log-tree.c
+++ b/log-tree.c
@@ -295,8 +295,12 @@ void show_decorations(struct rev_info *opt, struct commit *commit)
 {
 	struct strbuf sb = STRBUF_INIT;
 
-	if (opt->show_source && commit->util)
-		fprintf(opt->diffopt.file, "\t%s", (char *) commit->util);
+	if (opt->sources) {
+		char **slot = revision_sources_peek(opt->sources, commit);
+
+		if (slot && *slot)
+			fprintf(opt->diffopt.file, "\t%s", *slot);
+	}
 	if (!opt->show_decorations)
 		return;
 	format_decorations(&sb, commit, opt->diffopt.use_color);
diff --git a/revision.c b/revision.c
index 1cff11833e..be8fe7d67b 100644
--- a/revision.c
+++ b/revision.c
@@ -29,6 +29,8 @@ volatile show_early_output_fn_t show_early_output;
 static const char *term_bad;
 static const char *term_good;
 
+implement_shared_commit_slab(revision_sources, char *);
+
 void show_object_with_name(FILE *out, struct object *obj, const char *name)
 {
 	const char *p;
@@ -255,14 +257,19 @@ static struct commit *handle_commit(struct rev_info *revs,
 	 */
 	if (object->type == OBJ_COMMIT) {
 		struct commit *commit = (struct commit *)object;
+
 		if (parse_commit(commit) < 0)
 			die("unable to parse commit %s", name);
 		if (flags & UNINTERESTING) {
 			mark_parents_uninteresting(commit);
 			revs->limited = 1;
 		}
-		if (revs->show_source && !commit->util)
-			commit->util = xstrdup(name);
+		if (revs->sources) {
+			char **slot = revision_sources_at(revs->sources, commit);
+
+			if (!*slot)
+				*slot = xstrdup(name);
+		}
 		return commit;
 	}
 
@@ -814,8 +821,12 @@ static int add_parents_to_list(struct rev_info *revs, struct commit *commit,
 			}
 			return -1;
 		}
-		if (revs->show_source && !p->util)
-			p->util = commit->util;
+		if (revs->sources) {
+			char **slot = revision_sources_at(revs->sources, p);
+
+			if (!*slot)
+				*slot = *revision_sources_at(revs->sources, commit);
+		}
 		p->object.flags |= left_flag;
 		if (!(p->object.flags & SEEN)) {
 			p->object.flags |= SEEN;
diff --git a/revision.h b/revision.h
index b8c47b98e2..f3dc5f9740 100644
--- a/revision.h
+++ b/revision.h
@@ -6,6 +6,7 @@
 #include "notes.h"
 #include "pretty.h"
 #include "diff.h"
+#include "commit-slab-hdr.h"
 
 /* Remember to update object flag allocation in object.h */
 #define SEEN		(1u<<0)
@@ -29,6 +30,7 @@ struct rev_info;
 struct log_info;
 struct string_list;
 struct saved_parents;
+define_shared_commit_slab(revision_sources, char *);
 
 struct rev_cmdline_info {
 	unsigned int nr;
@@ -111,7 +113,6 @@ struct rev_info {
 			right_only:1,
 			rewrite_parents:1,
 			print_parents:1,
-			show_source:1,
 			show_decorations:1,
 			reverse:1,
 			reverse_output_stage:1,
@@ -224,6 +225,8 @@ struct rev_info {
 
 	struct commit_list *previous_parents;
 	const char *break_bar;
+
+	struct revision_sources *sources;
 };
 
 extern int ref_excluded(struct string_list *, const char *path);
-- 
2.17.0.705.g3525833791


  parent reply	other threads:[~2018-05-13  5:52 UTC|newest]

Thread overview: 82+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-12  8:00 [PATCH 00/12] Die commit->util, die! Nguyễn Thái Ngọc Duy
2018-05-12  8:00 ` [PATCH 01/12] blame: use commit-slab for blame suspects instead of commit->util Nguyễn Thái Ngọc Duy
2018-05-12  9:22   ` Jeff King
2018-05-12 12:13     ` Duy Nguyen
2018-05-12  8:00 ` [PATCH 02/12] describe: use commit-slab for commit names " Nguyễn Thái Ngọc Duy
2018-05-12  8:00 ` [PATCH 03/12] shallow.c: use commit-slab for commit depth " Nguyễn Thái Ngọc Duy
2018-05-12  9:07   ` Jeff King
2018-05-12  9:18     ` Jeff King
2018-05-12 12:09       ` Duy Nguyen
2018-05-12 19:12         ` Jeff King
2018-05-12 11:59     ` Duy Nguyen
2018-05-12  8:00 ` [PATCH 04/12] sequencer.c: use commit-slab to mark seen commits Nguyễn Thái Ngọc Duy
2018-05-12  9:25   ` Jeff King
2018-05-12 13:43     ` Junio C Hamano
2018-05-12 14:00       ` Duy Nguyen
2018-05-12  8:00 ` [PATCH 05/12] sequencer.c: use commit-slab to associate todo items to commits Nguyễn Thái Ngọc Duy
2018-05-12  9:28   ` Jeff King
2018-05-12  8:00 ` [PATCH 06/12] revision.c: use commit-slab for show_source Nguyễn Thái Ngọc Duy
2018-05-12  9:33   ` Jeff King
2018-05-12 13:58     ` Junio C Hamano
2018-05-12 14:13       ` Duy Nguyen
2018-05-12 19:06         ` Jeff King
2018-05-12  8:00 ` [PATCH 07/12] bisect.c: use commit-slab for commit weight instead of commit->util Nguyễn Thái Ngọc Duy
2018-05-12 13:59   ` Junio C Hamano
2018-05-12  8:00 ` [PATCH 08/12] name-rev: use commit-slab for rev-name " Nguyễn Thái Ngọc Duy
2018-05-12  8:00 ` [PATCH 09/12] show-branch: use commit-slab for commit-name " Nguyễn Thái Ngọc Duy
2018-05-12  8:00 ` [PATCH 10/12] log: use commit-slab in prepare_bases() " Nguyễn Thái Ngọc Duy
2018-05-12  8:00 ` [PATCH 11/12] merge: use commit-slab in merge remote desc " Nguyễn Thái Ngọc Duy
2018-05-12  8:00 ` [PATCH 12/12] commit.h: delete 'util' field in struct commit Nguyễn Thái Ngọc Duy
2018-05-12  9:41 ` [PATCH 00/12] Die commit->util, die! Jeff King
2018-05-12 18:50 ` Jakub Narebski
2018-05-13  5:39   ` Duy Nguyen
2018-05-13  5:51 ` [PATCH v2 00/14] " Nguyễn Thái Ngọc Duy
2018-05-13  5:51   ` [PATCH v2 01/14] commit-slab.h: code split Nguyễn Thái Ngọc Duy
2018-05-13 23:33     ` Junio C Hamano
2018-05-13  5:51   ` [PATCH v2 02/14] commit-slab: support shared commit-slab Nguyễn Thái Ngọc Duy
2018-05-13 23:36     ` Junio C Hamano
2018-05-13  5:51   ` [PATCH v2 03/14] blame: use commit-slab for blame suspects instead of commit->util Nguyễn Thái Ngọc Duy
2018-05-13 23:42     ` Junio C Hamano
2018-05-13  5:51   ` [PATCH v2 04/14] describe: use commit-slab for commit names " Nguyễn Thái Ngọc Duy
2018-05-13 23:45     ` Junio C Hamano
2018-05-13  5:51   ` [PATCH v2 05/14] shallow.c: use commit-slab for commit depth " Nguyễn Thái Ngọc Duy
2018-05-13  5:52   ` [PATCH v2 06/14] sequencer.c: use commit-slab to mark seen commits Nguyễn Thái Ngọc Duy
2018-05-14  4:17     ` Junio C Hamano
2018-05-13  5:52   ` [PATCH v2 07/14] sequencer.c: use commit-slab to associate todo items to commits Nguyễn Thái Ngọc Duy
2018-05-13  5:52   ` Nguyễn Thái Ngọc Duy [this message]
2018-05-14  5:10     ` [PATCH v2 08/14] revision.c: use commit-slab for show_source Junio C Hamano
2018-05-14  5:37       ` Junio C Hamano
2018-05-13  5:52   ` [PATCH v2 09/14] bisect.c: use commit-slab for commit weight instead of commit->util Nguyễn Thái Ngọc Duy
2018-05-14  6:16     ` Junio C Hamano
2018-05-13  5:52   ` [PATCH v2 10/14] name-rev: use commit-slab for rev-name " Nguyễn Thái Ngọc Duy
2018-05-13  5:52   ` [PATCH v2 11/14] show-branch: use commit-slab for commit-name " Nguyễn Thái Ngọc Duy
2018-05-14  6:45     ` Junio C Hamano
2018-05-19  4:51       ` Duy Nguyen
2018-05-13  5:52   ` [PATCH v2 12/14] log: use commit-slab in prepare_bases() " Nguyễn Thái Ngọc Duy
2018-05-13  5:52   ` [PATCH v2 13/14] merge: use commit-slab in merge remote desc " Nguyễn Thái Ngọc Duy
2018-05-18  2:16     ` Junio C Hamano
2018-05-18 17:54       ` Ramsay Jones
2018-05-13  5:52   ` [PATCH v2 14/14] commit.h: delete 'util' field in struct commit Nguyễn Thái Ngọc Duy
2018-05-14  7:52     ` Junio C Hamano
2018-05-14 16:07       ` Duy Nguyen
2018-05-14 17:30         ` Duy Nguyen
2018-05-14 18:14           ` Derrick Stolee
2018-05-19  5:41             ` Duy Nguyen
2018-05-19  5:28   ` [PATCH v3 00/15] Die commit->util, die! Nguyễn Thái Ngọc Duy
2018-05-19  5:28     ` [PATCH v3 01/15] commit-slab.h: code split Nguyễn Thái Ngọc Duy
2018-05-21  5:11       ` Junio C Hamano
2018-05-19  5:28     ` [PATCH v3 02/15] commit-slab: support shared commit-slab Nguyễn Thái Ngọc Duy
2018-05-19  5:28     ` [PATCH v3 03/15] blame: use commit-slab for blame suspects instead of commit->util Nguyễn Thái Ngọc Duy
2018-05-19  5:28     ` [PATCH v3 04/15] describe: use commit-slab for commit names " Nguyễn Thái Ngọc Duy
2018-05-19  5:28     ` [PATCH v3 05/15] shallow.c: use commit-slab for commit depth " Nguyễn Thái Ngọc Duy
2018-05-19  5:28     ` [PATCH v3 06/15] sequencer.c: use commit-slab to mark seen commits Nguyễn Thái Ngọc Duy
2018-05-19  5:28     ` [PATCH v3 07/15] sequencer.c: use commit-slab to associate todo items to commits Nguyễn Thái Ngọc Duy
2018-05-19  5:28     ` [PATCH v3 08/15] revision.c: use commit-slab for show_source Nguyễn Thái Ngọc Duy
2018-05-19  5:28     ` [PATCH v3 09/15] bisect.c: use commit-slab for commit weight instead of commit->util Nguyễn Thái Ngọc Duy
2018-05-19  5:28     ` [PATCH v3 10/15] name-rev: use commit-slab for rev-name " Nguyễn Thái Ngọc Duy
2018-05-19  5:28     ` [PATCH v3 11/15] show-branch: use commit-slab for commit-name " Nguyễn Thái Ngọc Duy
2018-05-19  5:28     ` [PATCH v3 12/15] show-branch: note about its object flags usage Nguyễn Thái Ngọc Duy
2018-05-19  5:28     ` [PATCH v3 13/15] log: use commit-slab in prepare_bases() instead of commit->util Nguyễn Thái Ngọc Duy
2018-05-19  5:28     ` [PATCH v3 14/15] merge: use commit-slab in merge remote desc " Nguyễn Thái Ngọc Duy
2018-05-19  5:28     ` [PATCH v3 15/15] commit.h: delete 'util' field in struct commit Nguyễn Thái Ngọc Duy
2018-05-22 22:40 ` [PATCH 00/12] Die commit->util, die! Stefan Beller

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=20180513055208.17952-9-pclouds@gmail.com \
    --to=pclouds@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=peff@peff.net \
    /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).