From: Taylor Blau <me@ttaylorr.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: Taylor Blau <me@ttaylorr.com>, Jeff King <peff@peff.net>,
git@vger.kernel.org, dstolee@microsoft.com, szeder.dev@gmail.com
Subject: Re: [PATCH v3 4/8] builtin/commit-graph.c: extract 'read_one_commit()'
Date: Mon, 18 May 2020 13:27:09 -0600 [thread overview]
Message-ID: <20200518192709.GA3906@syl.local> (raw)
In-Reply-To: <xmqq8shuqsnf.fsf@gitster.c.googlers.com>
Hi Junio,
Sorry for a delayed response. I have been working on something that I
hope to send to the list shortly to discuss. In the meantime...
On Thu, May 14, 2020 at 11:27:00AM -0700, Junio C Hamano wrote:
> Taylor Blau <me@ttaylorr.com> writes:
>
> > static int graph_write(int argc, const char **argv)
> > {
> > - struct string_list *pack_indexes = NULL;
> > + struct strbuf buf = STRBUF_INIT;
> > + struct string_list pack_indexes;
>
> I would strongly prefer this to be initialized here, not ...
Thanks for the suggestion. Your approach is much more favorable than
what I had written here, since it does allow me to unconditionally call
'string_list_clear(...)' instead of 'UNLEAK', which all three of us
dislike :).
Below is an amended patch; please use this as 4/8 instead of the
original when queuing. I'd send you a re-rolled series, but the rest of
the patches apply cleanly on top, so I don't think there is a need
unless it would make things more convenient for you.
-- >8 --
Subject: [PATCH] builtin/commit-graph.c: extract 'read_one_commit()'
With either '--stdin-commits' or '--stdin-packs', the commit-graph
builtin will read line-delimited input, and interpret it either as a
series of commit OIDs, or pack names.
In a subsequent commit, we will begin handling '--stdin-commits'
differently by processing each line as it comes in, instead of in one
shot at the end. To make adequate room for this additional logic, split
the '--stdin-commits' case from '--stdin-packs' by only storing the
input when '--stdin-packs' is given.
In the case of '--stdin-commits', feed each line to a new
'read_one_commit' helper, which (for now) will merely call
'parse_oid_hex'.
Signed-off-by: Taylor Blau <me@ttaylorr.com>
---
builtin/commit-graph.c | 56 +++++++++++++++++++++---------------------
1 file changed, 28 insertions(+), 28 deletions(-)
diff --git a/builtin/commit-graph.c b/builtin/commit-graph.c
index 15fe60317c..a5c2332a86 100644
--- a/builtin/commit-graph.c
+++ b/builtin/commit-graph.c
@@ -138,12 +138,24 @@ static int write_option_parse_split(const struct option *opt, const char *arg,
return 0;
}
+static int read_one_commit(struct oidset *commits, const char *hash)
+{
+ struct object_id oid;
+ const char *end;
+
+ if (parse_oid_hex(hash, &oid, &end))
+ return error(_("unexpected non-hex object ID: %s"), hash);
+
+ oidset_insert(commits, &oid);
+ return 0;
+}
+
static int graph_write(int argc, const char **argv)
{
- struct string_list *pack_indexes = NULL;
+ struct string_list pack_indexes = STRING_LIST_INIT_NODUP;
+ struct strbuf buf = STRBUF_INIT;
struct oidset commits = OIDSET_INIT;
struct object_directory *odb = NULL;
- struct string_list lines;
int result = 0;
enum commit_graph_write_flags flags = 0;
@@ -209,44 +221,32 @@ static int graph_write(int argc, const char **argv)
return 0;
}
- string_list_init(&lines, 0);
- if (opts.stdin_packs || opts.stdin_commits) {
- struct strbuf buf = STRBUF_INIT;
-
+ if (opts.stdin_packs) {
while (strbuf_getline(&buf, stdin) != EOF)
- string_list_append(&lines, strbuf_detach(&buf, NULL));
+ string_list_append(&pack_indexes,
+ strbuf_detach(&buf, NULL));
+ } else if (opts.stdin_commits) {
+ oidset_init(&commits, 0);
+ flags |= COMMIT_GRAPH_WRITE_CHECK_OIDS;
- if (opts.stdin_packs)
- pack_indexes = &lines;
- if (opts.stdin_commits) {
- struct string_list_item *item;
- oidset_init(&commits, lines.nr);
- for_each_string_list_item(item, &lines) {
- struct object_id oid;
- const char *end;
-
- if (parse_oid_hex(item->string, &oid, &end)) {
- error(_("unexpected non-hex object ID: "
- "%s"), item->string);
- return 1;
- }
-
- oidset_insert(&commits, &oid);
+ while (strbuf_getline(&buf, stdin) != EOF) {
+ if (read_one_commit(&commits, buf.buf)) {
+ result = 1;
+ goto cleanup;
}
- flags |= COMMIT_GRAPH_WRITE_CHECK_OIDS;
}
-
- UNLEAK(buf);
}
if (write_commit_graph(odb,
- pack_indexes,
+ opts.stdin_packs ? &pack_indexes : NULL,
opts.stdin_commits ? &commits : NULL,
flags,
&split_opts))
result = 1;
- UNLEAK(lines);
+cleanup:
+ string_list_clear(&pack_indexes, 0);
+ strbuf_release(&buf);
return result;
}
--
2.26.0.113.ge9739cdccc
next prev parent reply other threads:[~2020-05-18 19:27 UTC|newest]
Thread overview: 59+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-05 1:13 [PATCH 0/8] commit-graph: drop CHECK_OIDS, peel in callers Taylor Blau
2020-05-05 1:13 ` [PATCH 1/8] commit-graph.c: extract 'refs_cb_data' Taylor Blau
2020-05-05 1:13 ` [PATCH 2/8] commit-graph.c: show progress of finding reachable commits Taylor Blau
2020-05-05 11:50 ` Derrick Stolee
2020-05-05 16:13 ` Taylor Blau
2020-05-05 1:13 ` [PATCH 3/8] commit-graph.c: peel refs in 'add_ref_to_set' Taylor Blau
2020-05-07 19:54 ` Jeff King
2020-05-13 19:48 ` Taylor Blau
2020-05-13 20:17 ` Jeff King
2020-05-05 1:13 ` [PATCH 4/8] builtin/commit-graph.c: extract 'read_one_commit()' Taylor Blau
2020-05-07 20:03 ` Jeff King
2020-05-13 20:01 ` Taylor Blau
2020-05-05 1:13 ` [PATCH 5/8] builtin/commit-graph.c: dereference tags in builtin Taylor Blau
2020-05-05 12:01 ` Derrick Stolee
2020-05-05 16:14 ` Taylor Blau
2020-05-07 20:14 ` Jeff King
2020-05-05 1:13 ` [PATCH 6/8] commit-graph.c: simplify 'fill_oids_from_commits' Taylor Blau
2020-05-05 12:05 ` Derrick Stolee
2020-05-07 20:21 ` Jeff King
2020-05-05 1:14 ` [PATCH 7/8] t5318: reorder test below 'graph_read_expect' Taylor Blau
2020-05-05 1:14 ` [PATCH 8/8] commit-graph: drop COMMIT_GRAPH_WRITE_CHECK_OIDS flag Taylor Blau
2020-05-05 12:10 ` Derrick Stolee
2020-05-05 16:16 ` Taylor Blau
2020-05-07 20:40 ` Jeff King
2020-05-13 21:32 ` Taylor Blau
2020-05-05 11:35 ` [PATCH 0/8] commit-graph: drop CHECK_OIDS, peel in callers Derrick Stolee
2020-05-05 16:11 ` Taylor Blau
2020-05-06 0:07 ` [PATCH v2 " Taylor Blau
2020-05-06 0:07 ` [PATCH v2 1/8] commit-graph.c: extract 'refs_cb_data' Taylor Blau
2020-05-06 0:07 ` [PATCH v2 2/8] commit-graph.c: show progress of finding reachable commits Taylor Blau
2020-05-06 0:07 ` [PATCH v2 3/8] commit-graph.c: peel refs in 'add_ref_to_set' Taylor Blau
2020-05-06 0:07 ` [PATCH v2 4/8] builtin/commit-graph.c: extract 'read_one_commit()' Taylor Blau
2020-05-06 0:07 ` [PATCH v2 5/8] builtin/commit-graph.c: dereference tags in builtin Taylor Blau
2020-05-06 0:07 ` [PATCH v2 6/8] commit-graph.c: simplify 'fill_oids_from_commits' Taylor Blau
2020-05-06 0:07 ` [PATCH v2 7/8] t5318: reorder test below 'graph_read_expect' Taylor Blau
2020-05-06 0:07 ` [PATCH v2 8/8] commit-graph: drop COMMIT_GRAPH_WRITE_CHECK_OIDS flag Taylor Blau
2020-05-07 20:42 ` [PATCH v2 0/8] commit-graph: drop CHECK_OIDS, peel in callers Jeff King
2020-05-13 21:59 ` [PATCH v3 " Taylor Blau
2020-05-13 21:59 ` [PATCH v3 1/8] commit-graph.c: extract 'refs_cb_data' Taylor Blau
2020-05-13 21:59 ` [PATCH v3 2/8] commit-graph.c: show progress of finding reachable commits Taylor Blau
2020-05-13 21:59 ` [PATCH v3 3/8] commit-graph.c: peel refs in 'add_ref_to_set' Taylor Blau
2020-05-13 21:59 ` [PATCH v3 4/8] builtin/commit-graph.c: extract 'read_one_commit()' Taylor Blau
2020-05-14 17:56 ` Jeff King
2020-05-14 18:02 ` Taylor Blau
2020-05-14 18:27 ` Junio C Hamano
2020-05-18 19:27 ` Taylor Blau [this message]
2020-05-13 21:59 ` [PATCH v3 5/8] builtin/commit-graph.c: dereference tags in builtin Taylor Blau
2020-05-14 18:01 ` Jeff King
2020-05-14 18:04 ` Taylor Blau
2020-07-10 19:02 ` [PATCH] commit-graph: fix "Collecting commits from input" progress line SZEDER Gábor
2020-07-10 19:17 ` Taylor Blau
2020-07-15 18:33 ` SZEDER Gábor
2020-07-15 18:43 ` Derrick Stolee
2020-07-15 18:58 ` Junio C Hamano
2020-05-13 21:59 ` [PATCH v3 6/8] commit-graph.c: simplify 'fill_oids_from_commits' Taylor Blau
2020-05-13 21:59 ` [PATCH v3 7/8] t5318: reorder test below 'graph_read_expect' Taylor Blau
2020-05-13 21:59 ` [PATCH v3 8/8] commit-graph: drop COMMIT_GRAPH_WRITE_CHECK_OIDS flag Taylor Blau
2020-05-14 18:09 ` Jeff King
2020-05-14 18:12 ` [PATCH v3 0/8] commit-graph: drop CHECK_OIDS, peel in callers Jeff King
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=20200518192709.GA3906@syl.local \
--to=me@ttaylorr.com \
--cc=dstolee@microsoft.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=peff@peff.net \
--cc=szeder.dev@gmail.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).