From patchwork Sun Jun 7 19:32:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Abhishek Kumar X-Patchwork-Id: 11592125 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6DB501667 for ; Sun, 7 Jun 2020 19:34:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5562A206F6 for ; Sun, 7 Jun 2020 19:34:39 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="on3c7JGE" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726985AbgFGTeg (ORCPT ); Sun, 7 Jun 2020 15:34:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34642 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726093AbgFGTef (ORCPT ); Sun, 7 Jun 2020 15:34:35 -0400 Received: from mail-pg1-x532.google.com (mail-pg1-x532.google.com [IPv6:2607:f8b0:4864:20::532]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1FF32C08C5C3 for ; Sun, 7 Jun 2020 12:34:36 -0700 (PDT) Received: by mail-pg1-x532.google.com with SMTP id t7so7767829pgt.3 for ; Sun, 07 Jun 2020 12:34:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=XLZ3DUMILfriWfuGR3/PMfKCuVXypczWP5abF3vYtCY=; b=on3c7JGEyxgvt38j2d75xyVbI7IFE2119gEGGGWZjRdYPcrXBUz25j06QYlHq0sFjJ jpkN6oOPH26jtHnGEBL1nwx5V/HZyFg8/AyjQi/DO3vtwV/txxBfxLfHRpj5GFGUN0Ax tIR84lub82kKFYHnYkbNN7SRNEJmJbVW/yScBmdDet4W+kfnkGNw+PPIMJYgNZ+Eoqwm SxeT7BY+/8YwHMwRQIri20ExR5r/oub0lPXtz2sOjY+h3a3IU9dfTEFo1hedQvA7dFdw 4TjPXemM+wHHlkInPM/tYwHLfebodLkrcOlfkwK2c8Y6wLmTWwxFIDAeT17FkM2WYxw1 hFIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=XLZ3DUMILfriWfuGR3/PMfKCuVXypczWP5abF3vYtCY=; b=Z5iQiE+pNsH3n7l0bdHeQg5hJERbXhlLoB/Xjo+aJCT0D0TzKTiZruZdgdNWAdOGAw pYtbZU5HvSd8F6H7H412rcY28c3WzKM0/7kpk8OTf8olWlKQITTJptFnhZXkqD4Cpwd8 z8JLc0Tc4E42kY4TZC/BHDry4pdsNtXlWRHVAULckMOlgUuX8dZOktA+oVGVsxu00FnD DNOo7h+4MGDkocHh7voa0mdmBM+t0PkhRvLHRJxHsieRIY0NwD1fcNu8Rtvr88BIhHoK P401WIyZk87J9whAvoBHkrAIlHyLrMZSTL1XvZwJ8cnkZhTN0nmttWgLM+0hiUpzXBPY 2HPw== X-Gm-Message-State: AOAM530jy/IWUZv+xNW0EqAGQMPRG0oPWGoO3lXMTJc4wEwJNxl+Vw1O L6/Q0ZV6TPt9urw3OEOuOe9YCJCs X-Google-Smtp-Source: ABdhPJwIQ/FPgtunGou7/wlRWnlr4LzK/iB+NrXARzkMXMy47xu/kfGAvanLyrE+trWy3k5w619AmA== X-Received: by 2002:a63:e74b:: with SMTP id j11mr15353161pgk.237.1591558475117; Sun, 07 Jun 2020 12:34:35 -0700 (PDT) Received: from localhost.localdomain ([2409:4064:58e:925f:60d1:f386:43d2:4abb]) by smtp.gmail.com with ESMTPSA id n69sm158595pfd.171.2020.06.07.12.34.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 Jun 2020 12:34:34 -0700 (PDT) From: Abhishek Kumar To: git@vger.kernel.org Cc: jnareb@gmail.com, stolee@gmail.com Subject: [GSOC Patch v2 1/4] commit-graph: introduce commit_graph_data_slab Date: Mon, 8 Jun 2020 01:02:34 +0530 Message-Id: <20200607193237.699335-2-abhishekkumar8222@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200607193237.699335-1-abhishekkumar8222@gmail.com> References: <20200604072759.19142-1-abhishekkumar8222@gmail.com> <20200607193237.699335-1-abhishekkumar8222@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org The struct commit is used in many contexts. However, members `generation` and `graph_pos` are only used for commit-graph related operations and otherwise waste memory. As they are often accessed together, let's introduce struct commit_graph_data and move them to a commit_graph_data slab. Signed-off-by: Abhishek Kumar --- commit-graph.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ commit-graph.h | 10 ++++++++++ 2 files changed, 59 insertions(+) diff --git a/commit-graph.c b/commit-graph.c index e3420ddcbf..7d887a6a2c 100644 --- a/commit-graph.c +++ b/commit-graph.c @@ -87,6 +87,55 @@ static int commit_pos_cmp(const void *va, const void *vb) commit_pos_at(&commit_pos, b); } +define_commit_slab(commit_graph_data_slab, struct commit_graph_data); +static struct commit_graph_data_slab commit_graph_data_slab = + COMMIT_SLAB_INIT(1, commit_graph_data_slab); + +uint32_t commit_graph_position(const struct commit *c) +{ + struct commit_graph_data *data = + commit_graph_data_slab_peek(&commit_graph_data_slab, c); + + return data ? data->graph_pos : COMMIT_NOT_FROM_GRAPH; +} + +uint32_t commit_graph_generation(const struct commit *c) +{ + struct commit_graph_data *data = + commit_graph_data_slab_peek(&commit_graph_data_slab, c); + + if (!data) + return GENERATION_NUMBER_INFINITY; + if (data->graph_pos == COMMIT_NOT_FROM_GRAPH) + return GENERATION_NUMBER_INFINITY; + + return data->generation; +} + +static struct commit_graph_data *commit_graph_data_at(const struct commit *c) +{ + uint32_t i = commit_graph_data_slab.slab_count, j; + uint32_t slab_size = commit_graph_data_slab.slab_size; + struct commit_graph_data *data = + commit_graph_data_slab_at(&commit_graph_data_slab, c); + + /* + * commit-slab initializes elements with zero, overwrite this with + * COMMIT_NOT_FROM_GRAPH for graph_pos. + * + * We avoid the cost of initializing `generation` as generation + * number would be GENERATION_NUMBER_INFINITY if graph position + * is COMMIT_NOT_FROM_GRAPH. + */ + for (; i < commit_graph_data_slab.slab_count; i++) { + for (j = 0; j < slab_size; j++) { + commit_graph_data_slab.slab[i][j].graph_pos = COMMIT_NOT_FROM_GRAPH; + } + } + + return data; +} + static int commit_gen_cmp(const void *va, const void *vb) { const struct commit *a = *(const struct commit **)va; diff --git a/commit-graph.h b/commit-graph.h index 4212766a4f..9d22f98f44 100644 --- a/commit-graph.h +++ b/commit-graph.h @@ -137,4 +137,14 @@ void free_commit_graph(struct commit_graph *); */ void disable_commit_graph(struct repository *r); +struct commit_graph_data { + uint32_t graph_pos; + uint32_t generation; +}; + +/* + * Commits should be parsed before accessing generation, graph positions. + */ +uint32_t commit_graph_generation(const struct commit *); +uint32_t commit_graph_position(const struct commit *); #endif From patchwork Sun Jun 7 19:32:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Abhishek Kumar X-Patchwork-Id: 11592129 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DCA91739 for ; Sun, 7 Jun 2020 19:34:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B258A206F6 for ; Sun, 7 Jun 2020 19:34:43 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="uGLJR118" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727768AbgFGTem (ORCPT ); Sun, 7 Jun 2020 15:34:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34660 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726093AbgFGTel (ORCPT ); Sun, 7 Jun 2020 15:34:41 -0400 Received: from mail-pf1-x441.google.com (mail-pf1-x441.google.com [IPv6:2607:f8b0:4864:20::441]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F1086C08C5C3 for ; Sun, 7 Jun 2020 12:34:41 -0700 (PDT) Received: by mail-pf1-x441.google.com with SMTP id b5so7547267pfp.9 for ; Sun, 07 Jun 2020 12:34:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=grBDVGfTxOWNldmRHA/7nrIMJ1CkfmCknC0lE8SxwQY=; b=uGLJR118w0DWRqE0B4rqaV1esNHg/yWlsHZlA9HVO15tTvC5ys6bZVhmeAHNAh+1ix hcmbM4JiMaLCQ2N/FsZXnYbvpg3gAvtBBbllT9yPvrahJIISfT9d1kS/5aXuLTHs2k80 JTDyekjPrF0dWYowgf323V5vPJ5VjDsDo/cBj1Wk/bs6KsQtlsvLuWmgnLRDl7FC38H1 6B2x1ocoKAMCG3d4DHqAHDQi9OH6I9iw3YfvhRhfFNlOsgjr/OpQIQLWyN4ZoQsTHeua a3jbOVExuMQ7KNbYL+O9LXNJ/yVFroEGSs2/snXE2oCktTj+UqFi5Cnti2pyvtb0Js// hQYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=grBDVGfTxOWNldmRHA/7nrIMJ1CkfmCknC0lE8SxwQY=; b=LQlxTmEmkiqDjMxkTQJKkiADi2iTghNSAytoBCL6FiyM0Wk0h3Pd42ne+XrcAuBv+y e8QBX9Uhkahs7+V5A+xY+GcJFZOXGn7sJkeXgfZ6nvzNy0DkyxNkAqol2WgfJrSXjnwn QKP/QW0NVvKjjy7bDr4BPZLgg30DxVEZzC6xHhYURZu4JB7tnHgtxb7nb39iXe1r8V1R 3EOSu/+TC6UAsTYL9WUE3LSqI4wfE0SbWJVQsd559F6Jz690/UlN4SICSiebpHQGinf5 fxBkg6vTxtysgApBHeMkf/BNoXjYGiIS+92RNJvKCjRmtvO9hLp60m60BsMSsyaiN84O leFw== X-Gm-Message-State: AOAM530YwpSFlod2c+H5Q1mN7MGp4iqLfGQkbNplfQiKmNfKNrjGLz7A AhNyOhL/uN5gRzyyGytPFHlgcmK1 X-Google-Smtp-Source: ABdhPJzkaHz3jrRtNg1oLDMKUpKHYY6pQF3b1vQyMhZfSivtcmVvE2l6pkMefBODPrn+yJZ0V6IHXQ== X-Received: by 2002:aa7:9ad5:: with SMTP id x21mr18534093pfp.257.1591558480791; Sun, 07 Jun 2020 12:34:40 -0700 (PDT) Received: from localhost.localdomain ([2409:4064:58e:925f:60d1:f386:43d2:4abb]) by smtp.gmail.com with ESMTPSA id n69sm158595pfd.171.2020.06.07.12.34.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 Jun 2020 12:34:40 -0700 (PDT) From: Abhishek Kumar To: git@vger.kernel.org Cc: jnareb@gmail.com, stolee@gmail.com Subject: [GSOC Patch v2 2/4] commit: move members graph_pos, generation to a slab Date: Mon, 8 Jun 2020 01:02:35 +0530 Message-Id: <20200607193237.699335-3-abhishekkumar8222@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200607193237.699335-1-abhishekkumar8222@gmail.com> References: <20200604072759.19142-1-abhishekkumar8222@gmail.com> <20200607193237.699335-1-abhishekkumar8222@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org We remove members `graph_pos` and `generation` from the struct commit. The default assignments in init_commit_node() are no longer valid, which is fine as the slab helpers return appropriate default values and the assignments are removed. We will replace existing use of commit->generation and commit->graph_pos by commit_graph_data slab helpers using `contrib/coccinelle/commit.cocci'. Signed-off-by: Abhishek Kumar --- alloc.c | 2 -- blame.c | 2 +- bloom.c | 6 ++-- commit-graph.c | 60 ++++++++++++++++----------------- commit-graph.h | 2 +- commit-reach.c | 50 +++++++++++++-------------- commit.c | 6 ++-- contrib/coccinelle/commit.cocci | 18 ++++++++++ revision.c | 16 ++++----- 9 files changed, 89 insertions(+), 73 deletions(-) diff --git a/alloc.c b/alloc.c index 1c64c4dd16..f37fb3b8b6 100644 --- a/alloc.c +++ b/alloc.c @@ -108,8 +108,6 @@ void init_commit_node(struct repository *r, struct commit *c) { c->object.type = OBJ_COMMIT; c->index = alloc_commit_index(r); - c->graph_pos = COMMIT_NOT_FROM_GRAPH; - c->generation = GENERATION_NUMBER_INFINITY; } void *alloc_commit_node(struct repository *r) diff --git a/blame.c b/blame.c index da7e28800e..82fa16d658 100644 --- a/blame.c +++ b/blame.c @@ -1272,7 +1272,7 @@ static int maybe_changed_path(struct repository *r, if (!bd) return 1; - if (origin->commit->generation == GENERATION_NUMBER_INFINITY) + if (commit_graph_generation(origin->commit) == GENERATION_NUMBER_INFINITY) return 1; filter = get_bloom_filter(r, origin->commit, 0); diff --git a/bloom.c b/bloom.c index 9b86aa3f59..df62e3763d 100644 --- a/bloom.c +++ b/bloom.c @@ -34,14 +34,14 @@ static int load_bloom_filter_from_graph(struct commit_graph *g, { uint32_t lex_pos, start_index, end_index; - while (c->graph_pos < g->num_commits_in_base) + while (commit_graph_position(c) < g->num_commits_in_base) g = g->base_graph; /* The commit graph commit 'c' lives in doesn't carry bloom filters. */ if (!g->chunk_bloom_indexes) return 0; - lex_pos = c->graph_pos - g->num_commits_in_base; + lex_pos = commit_graph_position(c) - g->num_commits_in_base; end_index = get_be32(g->chunk_bloom_indexes + 4 * lex_pos); @@ -188,7 +188,7 @@ struct bloom_filter *get_bloom_filter(struct repository *r, if (!filter->data) { load_commit_graph_info(r, c); - if (c->graph_pos != COMMIT_NOT_FROM_GRAPH && + if (commit_graph_position(c) != COMMIT_NOT_FROM_GRAPH && r->objects->commit_graph->chunk_bloom_indexes) { if (load_bloom_filter_from_graph(r->objects->commit_graph, filter, c)) return filter; diff --git a/commit-graph.c b/commit-graph.c index 7d887a6a2c..f7cca4def4 100644 --- a/commit-graph.c +++ b/commit-graph.c @@ -142,9 +142,9 @@ static int commit_gen_cmp(const void *va, const void *vb) const struct commit *b = *(const struct commit **)vb; /* lower generation commits first */ - if (a->generation < b->generation) + if (commit_graph_generation(a) < commit_graph_generation(b)) return -1; - else if (a->generation > b->generation) + else if (commit_graph_generation(a) > commit_graph_generation(b)) return 1; /* use date as a heuristic when generations are equal */ @@ -719,7 +719,7 @@ static struct commit_list **insert_parent_or_die(struct repository *r, c = lookup_commit(r, &oid); if (!c) die(_("could not find commit %s"), oid_to_hex(&oid)); - c->graph_pos = pos; + commit_graph_data_at(c)->graph_pos = pos; return &commit_list_insert(c, pptr)->next; } @@ -733,8 +733,8 @@ static void fill_commit_graph_info(struct commit *item, struct commit_graph *g, lex_index = pos - g->num_commits_in_base; commit_data = g->chunk_commit_data + GRAPH_DATA_WIDTH * lex_index; - item->graph_pos = pos; - item->generation = get_be32(commit_data + g->hash_len + 8) >> 2; + commit_graph_data_at(item)->graph_pos = pos; + commit_graph_data_at(item)->generation = get_be32(commit_data + g->hash_len + 8) >> 2; } static inline void set_commit_tree(struct commit *c, struct tree *t) @@ -763,7 +763,7 @@ static int fill_commit_in_graph(struct repository *r, * Store the "full" position, but then use the * "local" position for the rest of the calculation. */ - item->graph_pos = pos; + commit_graph_data_at(item)->graph_pos = pos; lex_index = pos - g->num_commits_in_base; commit_data = g->chunk_commit_data + (g->hash_len + 16) * lex_index; @@ -776,7 +776,7 @@ static int fill_commit_in_graph(struct repository *r, date_low = get_be32(commit_data + g->hash_len + 12); item->date = (timestamp_t)((date_high << 32) | date_low); - item->generation = get_be32(commit_data + g->hash_len + 8) >> 2; + commit_graph_data_at(item)->generation = get_be32(commit_data + g->hash_len + 8) >> 2; pptr = &item->parents; @@ -808,8 +808,8 @@ static int fill_commit_in_graph(struct repository *r, static int find_commit_in_graph(struct commit *item, struct commit_graph *g, uint32_t *pos) { - if (item->graph_pos != COMMIT_NOT_FROM_GRAPH) { - *pos = item->graph_pos; + if (commit_graph_position(item) != COMMIT_NOT_FROM_GRAPH) { + *pos = commit_graph_position(item); return 1; } else { struct commit_graph *cur_g = g; @@ -865,11 +865,11 @@ static struct tree *load_tree_for_commit(struct repository *r, struct object_id oid; const unsigned char *commit_data; - while (c->graph_pos < g->num_commits_in_base) + while (commit_graph_position(c) < g->num_commits_in_base) g = g->base_graph; commit_data = g->chunk_commit_data + - GRAPH_DATA_WIDTH * (c->graph_pos - g->num_commits_in_base); + GRAPH_DATA_WIDTH * (commit_graph_position(c) - g->num_commits_in_base); hashcpy(oid.hash, commit_data); set_commit_tree(c, lookup_tree(r, &oid)); @@ -883,7 +883,7 @@ static struct tree *get_commit_tree_in_graph_one(struct repository *r, { if (c->maybe_tree) return c->maybe_tree; - if (c->graph_pos == COMMIT_NOT_FROM_GRAPH) + if (commit_graph_position(c) == COMMIT_NOT_FROM_GRAPH) BUG("get_commit_tree_in_graph_one called from non-commit-graph commit"); return load_tree_for_commit(r, g, (struct commit *)c); @@ -1070,7 +1070,7 @@ static void write_graph_chunk_data(struct hashfile *f, int hash_len, else packedDate[0] = 0; - packedDate[0] |= htonl((*list)->generation << 2); + packedDate[0] |= htonl(commit_graph_generation((*list)) << 2); packedDate[1] = htonl((*list)->date); hashwrite(f, packedDate, 8); @@ -1269,7 +1269,7 @@ static void close_reachable(struct write_commit_graph_context *ctx) continue; if (ctx->split) { if ((!parse_commit(commit) && - commit->graph_pos == COMMIT_NOT_FROM_GRAPH) || + commit_graph_position(commit) == COMMIT_NOT_FROM_GRAPH) || flags == COMMIT_GRAPH_SPLIT_REPLACE) add_missing_parents(ctx, commit); } else if (!parse_commit_no_graph(commit)) @@ -1302,8 +1302,8 @@ static void compute_generation_numbers(struct write_commit_graph_context *ctx) ctx->commits.nr); for (i = 0; i < ctx->commits.nr; i++) { display_progress(ctx->progress, i + 1); - if (ctx->commits.list[i]->generation != GENERATION_NUMBER_INFINITY && - ctx->commits.list[i]->generation != GENERATION_NUMBER_ZERO) + if (commit_graph_generation(ctx->commits.list[i]) != GENERATION_NUMBER_INFINITY && + commit_graph_generation(ctx->commits.list[i]) != GENERATION_NUMBER_ZERO) continue; commit_list_insert(ctx->commits.list[i], &list); @@ -1314,22 +1314,22 @@ static void compute_generation_numbers(struct write_commit_graph_context *ctx) uint32_t max_generation = 0; for (parent = current->parents; parent; parent = parent->next) { - if (parent->item->generation == GENERATION_NUMBER_INFINITY || - parent->item->generation == GENERATION_NUMBER_ZERO) { + if (commit_graph_generation(parent->item) == GENERATION_NUMBER_INFINITY || + commit_graph_generation(parent->item) == GENERATION_NUMBER_ZERO) { all_parents_computed = 0; commit_list_insert(parent->item, &list); break; - } else if (parent->item->generation > max_generation) { - max_generation = parent->item->generation; + } else if (commit_graph_generation(parent->item) > max_generation) { + max_generation = commit_graph_generation(parent->item); } } if (all_parents_computed) { - current->generation = max_generation + 1; + commit_graph_data_at(current)->generation = max_generation + 1; pop_commit(&list); - if (current->generation > GENERATION_NUMBER_MAX) - current->generation = GENERATION_NUMBER_MAX; + if (commit_graph_generation(current) > GENERATION_NUMBER_MAX) + commit_graph_data_at(current)->generation = GENERATION_NUMBER_MAX; } } } @@ -1514,7 +1514,7 @@ static uint32_t count_distinct_commits(struct write_commit_graph_context *ctx) if (ctx->split) { struct commit *c = lookup_commit(ctx->r, &ctx->oids.list[i]); - if (!c || c->graph_pos != COMMIT_NOT_FROM_GRAPH) + if (!c || commit_graph_position(c) != COMMIT_NOT_FROM_GRAPH) continue; } @@ -1548,7 +1548,7 @@ static void copy_oids_to_commits(struct write_commit_graph_context *ctx) ctx->commits.list[ctx->commits.nr] = lookup_commit(ctx->r, &ctx->oids.list[i]); if (ctx->split && flags != COMMIT_GRAPH_SPLIT_REPLACE && - ctx->commits.list[ctx->commits.nr]->graph_pos != COMMIT_NOT_FROM_GRAPH) + commit_graph_position(ctx->commits.list[ctx->commits.nr]) != COMMIT_NOT_FROM_GRAPH) continue; if (ctx->split && flags == COMMIT_GRAPH_SPLIT_REPLACE) @@ -2336,8 +2336,8 @@ int verify_commit_graph(struct repository *r, struct commit_graph *g, int flags) oid_to_hex(&graph_parents->item->object.oid), oid_to_hex(&odb_parents->item->object.oid)); - if (graph_parents->item->generation > max_generation) - max_generation = graph_parents->item->generation; + if (commit_graph_generation(graph_parents->item) > max_generation) + max_generation = commit_graph_generation(graph_parents->item); graph_parents = graph_parents->next; odb_parents = odb_parents->next; @@ -2347,7 +2347,7 @@ int verify_commit_graph(struct repository *r, struct commit_graph *g, int flags) graph_report(_("commit-graph parent list for commit %s terminates early"), oid_to_hex(&cur_oid)); - if (!graph_commit->generation) { + if (!commit_graph_generation(graph_commit)) { if (generation_zero == GENERATION_NUMBER_EXISTS) graph_report(_("commit-graph has generation number zero for commit %s, but non-zero elsewhere"), oid_to_hex(&cur_oid)); @@ -2367,10 +2367,10 @@ int verify_commit_graph(struct repository *r, struct commit_graph *g, int flags) if (max_generation == GENERATION_NUMBER_MAX) max_generation--; - if (graph_commit->generation != max_generation + 1) + if (commit_graph_generation(graph_commit) != max_generation + 1) graph_report(_("commit-graph generation for commit %s is %u != %u"), oid_to_hex(&cur_oid), - graph_commit->generation, + commit_graph_generation(graph_commit), max_generation + 1); if (graph_commit->date != odb_commit->date) diff --git a/commit-graph.h b/commit-graph.h index 9d22f98f44..2d1fecf481 100644 --- a/commit-graph.h +++ b/commit-graph.h @@ -142,7 +142,7 @@ struct commit_graph_data { uint32_t generation; }; -/* +/* * Commits should be parsed before accessing generation, graph positions. */ uint32_t commit_graph_generation(const struct commit *); diff --git a/commit-reach.c b/commit-reach.c index 4ca7e706a1..3b2f863f5f 100644 --- a/commit-reach.c +++ b/commit-reach.c @@ -59,13 +59,13 @@ static struct commit_list *paint_down_to_common(struct repository *r, struct commit_list *parents; int flags; - if (min_generation && commit->generation > last_gen) + if (min_generation && commit_graph_generation(commit) > last_gen) BUG("bad generation skip %8x > %8x at %s", - commit->generation, last_gen, + commit_graph_generation(commit), last_gen, oid_to_hex(&commit->object.oid)); - last_gen = commit->generation; + last_gen = commit_graph_generation(commit); - if (commit->generation < min_generation) + if (commit_graph_generation(commit) < min_generation) break; flags = commit->object.flags & (PARENT1 | PARENT2 | STALE); @@ -176,7 +176,7 @@ static int remove_redundant(struct repository *r, struct commit **array, int cnt repo_parse_commit(r, array[i]); for (i = 0; i < cnt; i++) { struct commit_list *common; - uint32_t min_generation = array[i]->generation; + uint32_t min_generation = commit_graph_generation(array[i]); if (redundant[i]) continue; @@ -186,8 +186,8 @@ static int remove_redundant(struct repository *r, struct commit **array, int cnt filled_index[filled] = j; work[filled++] = array[j]; - if (array[j]->generation < min_generation) - min_generation = array[j]->generation; + if (commit_graph_generation(array[j]) < min_generation) + min_generation = commit_graph_generation(array[j]); } common = paint_down_to_common(r, array[i], filled, work, min_generation); @@ -323,16 +323,16 @@ int repo_in_merge_bases_many(struct repository *r, struct commit *commit, for (i = 0; i < nr_reference; i++) { if (repo_parse_commit(r, reference[i])) return ret; - if (reference[i]->generation < min_generation) - min_generation = reference[i]->generation; + if (commit_graph_generation(reference[i]) < min_generation) + min_generation = commit_graph_generation(reference[i]); } - if (commit->generation > min_generation) + if (commit_graph_generation(commit) > min_generation) return ret; bases = paint_down_to_common(r, commit, nr_reference, reference, - commit->generation); + commit_graph_generation(commit)); if (commit->object.flags & PARENT2) ret = 1; clear_commit_marks(commit, all_flags); @@ -467,7 +467,7 @@ static enum contains_result contains_test(struct commit *candidate, /* Otherwise, we don't know; prepare to recurse */ parse_commit_or_die(candidate); - if (candidate->generation < cutoff) + if (commit_graph_generation(candidate) < cutoff) return CONTAINS_NO; return CONTAINS_UNKNOWN; @@ -492,8 +492,8 @@ static enum contains_result contains_tag_algo(struct commit *candidate, for (p = want; p; p = p->next) { struct commit *c = p->item; load_commit_graph_info(the_repository, c); - if (c->generation < cutoff) - cutoff = c->generation; + if (commit_graph_generation(c) < cutoff) + cutoff = commit_graph_generation(c); } result = contains_test(candidate, want, cache, cutoff); @@ -544,9 +544,9 @@ static int compare_commits_by_gen(const void *_a, const void *_b) const struct commit *a = *(const struct commit * const *)_a; const struct commit *b = *(const struct commit * const *)_b; - if (a->generation < b->generation) + if (commit_graph_generation(a) < commit_graph_generation(b)) return -1; - if (a->generation > b->generation) + if (commit_graph_generation(a) > commit_graph_generation(b)) return 1; return 0; } @@ -585,7 +585,7 @@ int can_all_from_reach_with_flag(struct object_array *from, list[nr_commits] = (struct commit *)from_one; if (parse_commit(list[nr_commits]) || - list[nr_commits]->generation < min_generation) { + commit_graph_generation(list[nr_commits]) < min_generation) { result = 0; goto cleanup; } @@ -621,7 +621,7 @@ int can_all_from_reach_with_flag(struct object_array *from, if (parse_commit(parent->item) || parent->item->date < min_commit_date || - parent->item->generation < min_generation) + commit_graph_generation(parent->item) < min_generation) continue; commit_list_insert(parent->item, &stack); @@ -665,8 +665,8 @@ int can_all_from_reach(struct commit_list *from, struct commit_list *to, if (from_iter->item->date < min_commit_date) min_commit_date = from_iter->item->date; - if (from_iter->item->generation < min_generation) - min_generation = from_iter->item->generation; + if (commit_graph_generation(from_iter->item) < min_generation) + min_generation = commit_graph_generation(from_iter->item); } from_iter = from_iter->next; @@ -677,8 +677,8 @@ int can_all_from_reach(struct commit_list *from, struct commit_list *to, if (to_iter->item->date < min_commit_date) min_commit_date = to_iter->item->date; - if (to_iter->item->generation < min_generation) - min_generation = to_iter->item->generation; + if (commit_graph_generation(to_iter->item) < min_generation) + min_generation = commit_graph_generation(to_iter->item); } to_iter->item->object.flags |= PARENT2; @@ -721,8 +721,8 @@ struct commit_list *get_reachable_subset(struct commit **from, int nr_from, struct commit *c = *item; parse_commit(c); - if (c->generation < min_generation) - min_generation = c->generation; + if (commit_graph_generation(c) < min_generation) + min_generation = commit_graph_generation(c); if (!(c->object.flags & PARENT1)) { c->object.flags |= PARENT1; @@ -755,7 +755,7 @@ struct commit_list *get_reachable_subset(struct commit **from, int nr_from, parse_commit(p); - if (p->generation < min_generation) + if (commit_graph_generation(p) < min_generation) continue; if (p->object.flags & PARENT2) diff --git a/commit.c b/commit.c index 87686a7055..ad9a76dcc6 100644 --- a/commit.c +++ b/commit.c @@ -339,7 +339,7 @@ struct tree *repo_get_commit_tree(struct repository *r, if (commit->maybe_tree || !commit->object.parsed) return commit->maybe_tree; - if (commit->graph_pos != COMMIT_NOT_FROM_GRAPH) + if (commit_graph_position(commit) != COMMIT_NOT_FROM_GRAPH) return get_commit_tree_in_graph(r, commit); return NULL; @@ -731,9 +731,9 @@ int compare_commits_by_gen_then_commit_date(const void *a_, const void *b_, void const struct commit *a = a_, *b = b_; /* newer commits first */ - if (a->generation < b->generation) + if (commit_graph_generation(a) < commit_graph_generation(b)) return 1; - else if (a->generation > b->generation) + else if (commit_graph_generation(a) > commit_graph_generation(b)) return -1; /* use date as a heuristic when generations are equal */ diff --git a/contrib/coccinelle/commit.cocci b/contrib/coccinelle/commit.cocci index 778e4704f6..af6dd4c20c 100644 --- a/contrib/coccinelle/commit.cocci +++ b/contrib/coccinelle/commit.cocci @@ -32,3 +32,21 @@ expression c; - c->maybe_tree + repo_get_commit_tree(specify_the_right_repo_here, c) ...>} + +@@ +struct commit *c; +expression E; +@@ +( +- c->generation = E; ++ commit_graph_data_at(c)->generation = E; +| +- c->graph_pos = E; ++ commit_graph_data_at(c)->graph_pos = E; +| +- c->generation ++ commit_graph_generation(c) +| +- c->graph_pos ++ commit_graph_position(c) +) diff --git a/revision.c b/revision.c index 60cca8c0b9..cb1b200e9f 100644 --- a/revision.c +++ b/revision.c @@ -720,7 +720,7 @@ static int check_maybe_different_in_bloom_filter(struct rev_info *revs, if (!revs->repo->objects->commit_graph) return -1; - if (commit->generation == GENERATION_NUMBER_INFINITY) + if (commit_graph_generation(commit) == GENERATION_NUMBER_INFINITY) return -1; filter = get_bloom_filter(revs->repo, commit, 0); @@ -3314,7 +3314,7 @@ static void explore_to_depth(struct rev_info *revs, struct topo_walk_info *info = revs->topo_walk_info; struct commit *c; while ((c = prio_queue_peek(&info->explore_queue)) && - c->generation >= gen_cutoff) + commit_graph_generation(c) >= gen_cutoff) explore_walk_step(revs); } @@ -3330,7 +3330,7 @@ static void indegree_walk_step(struct rev_info *revs) if (parse_commit_gently(c, 1) < 0) return; - explore_to_depth(revs, c->generation); + explore_to_depth(revs, commit_graph_generation(c)); for (p = c->parents; p; p = p->next) { struct commit *parent = p->item; @@ -3354,7 +3354,7 @@ static void compute_indegrees_to_depth(struct rev_info *revs, struct topo_walk_info *info = revs->topo_walk_info; struct commit *c; while ((c = prio_queue_peek(&info->indegree_queue)) && - c->generation >= gen_cutoff) + commit_graph_generation(c) >= gen_cutoff) indegree_walk_step(revs); } @@ -3414,8 +3414,8 @@ static void init_topo_walk(struct rev_info *revs) test_flag_and_insert(&info->explore_queue, c, TOPO_WALK_EXPLORED); test_flag_and_insert(&info->indegree_queue, c, TOPO_WALK_INDEGREE); - if (c->generation < info->min_generation) - info->min_generation = c->generation; + if (commit_graph_generation(c) < info->min_generation) + info->min_generation = commit_graph_generation(c); *(indegree_slab_at(&info->indegree, c)) = 1; @@ -3473,8 +3473,8 @@ static void expand_topo_walk(struct rev_info *revs, struct commit *commit) if (parse_commit_gently(parent, 1) < 0) continue; - if (parent->generation < info->min_generation) { - info->min_generation = parent->generation; + if (commit_graph_generation(parent) < info->min_generation) { + info->min_generation = commit_graph_generation(parent); compute_indegrees_to_depth(revs, info->min_generation); } From patchwork Sun Jun 7 19:32:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Abhishek Kumar X-Patchwork-Id: 11592131 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 334AD13B1 for ; Sun, 7 Jun 2020 19:34:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1B8CD2073B for ; Sun, 7 Jun 2020 19:34:48 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="NwkRxKqn" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727778AbgFGTeq (ORCPT ); Sun, 7 Jun 2020 15:34:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34672 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726093AbgFGTeq (ORCPT ); Sun, 7 Jun 2020 15:34:46 -0400 Received: from mail-pj1-x1043.google.com (mail-pj1-x1043.google.com [IPv6:2607:f8b0:4864:20::1043]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8A349C08C5C3 for ; Sun, 7 Jun 2020 12:34:46 -0700 (PDT) Received: by mail-pj1-x1043.google.com with SMTP id m2so5075687pjv.2 for ; Sun, 07 Jun 2020 12:34:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=OmjkxN8Ang7C2pefcs0jG85HuCQfghiOZif30tPuXX4=; b=NwkRxKqnc05oMiUWLEEGgbkqO3Z4+ozchNkQgWVZIexOu93fjDgbkpoaUejutLUu0e dKJlovAlHd883r9YkYvn2KjWU7N2F42hcSfI+otdIlPcpibTj3X5y/4jaXxnwmcXxPbB 3obAal1FSy+lrssFbLwizMnoCvggXiMfcn4+kOluuBhhBHeKtJJvS3oCKFVtQRvcDsU1 v7q/Do1CZaUKQm50UoPBBnRJ78AUSlzVmRSnk/1WTddQ7KAIWdA0cvykzbLbXI/yH3RH bTR26LjI8NsHd3J8zLGaZus9hD9P3WG03MX0WkO2/37VWHqst92fMdo2wzFXvckENy5y yywA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=OmjkxN8Ang7C2pefcs0jG85HuCQfghiOZif30tPuXX4=; b=OXNSFfaYaHFlbY19b7HL6rQzHN9yrIBLhMWA+jSpgPqF8UMfbYiIewzn/AoNYJCQV7 z7priLgUHSq28wrXdA2aeGRQz+m06xbzORe9JTnjAjT9DPP/+M/eEhfSFtBGDmWrSltn QEXS32wvCIRVOgo/W+ZEmQLt3oE5Nz/jAFLra+/Dc9wqOh7NagB1Azqz2nuIgZbBcO42 de/beHUCRZCSGXX6Jm1C/z/d0UYtf/ONmwMixI7NWKxr/6GZp98+EXP8BDGxxpotjlfy VXYCq6q7iweUaGkvhNtp9rGgdaYH3K5VICgL93NnQg3ai3MXg8C5b6FcgM7gP9TEyQdI zc8g== X-Gm-Message-State: AOAM531RfjhcdpaVehV+XjvEez1xx9IsEyO3Cf4sRM0OU4nwRegU5frN 3DweEhJeMZRjfsRoCkG4gUHC00jh X-Google-Smtp-Source: ABdhPJzoC5jG8Tx/urunla+CuPn5XoNISqRLwD7nRlxG2IITotw7QG/QHsITD3ojc+GyKDovZ/B5fQ== X-Received: by 2002:a17:90b:3690:: with SMTP id mj16mr13778540pjb.104.1591558485693; Sun, 07 Jun 2020 12:34:45 -0700 (PDT) Received: from localhost.localdomain ([2409:4064:58e:925f:60d1:f386:43d2:4abb]) by smtp.gmail.com with ESMTPSA id n69sm158595pfd.171.2020.06.07.12.34.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 Jun 2020 12:34:45 -0700 (PDT) From: Abhishek Kumar To: git@vger.kernel.org Cc: jnareb@gmail.com, stolee@gmail.com Subject: [GSOC Patch v2 3/4] commit-graph: use generation directly when writing commit-graph Date: Mon, 8 Jun 2020 01:02:36 +0530 Message-Id: <20200607193237.699335-4-abhishekkumar8222@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200607193237.699335-1-abhishekkumar8222@gmail.com> References: <20200604072759.19142-1-abhishekkumar8222@gmail.com> <20200607193237.699335-1-abhishekkumar8222@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org commit_graph_generation() returns GENERATION_NUMBER_INFINITY if the graph position for commit is COMMIT_NOT_FROM_GRAPH. While this is true when reading from a commit graph, no graph positions are associated with a commit when writing a commit graph. Therefore, the helper incorrectly returns GENERATION_NUMBER_INFINITY despite having a finite generation number. Let's fix this by using generation number directly when writing a commit graph. Signed-off-by: Abhishek Kumar --- commit-graph.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/commit-graph.c b/commit-graph.c index f7cca4def4..0dc79e7c90 100644 --- a/commit-graph.c +++ b/commit-graph.c @@ -1070,7 +1070,7 @@ static void write_graph_chunk_data(struct hashfile *f, int hash_len, else packedDate[0] = 0; - packedDate[0] |= htonl(commit_graph_generation((*list)) << 2); + packedDate[0] |= htonl(commit_graph_data_at(*list)->generation << 2); packedDate[1] = htonl((*list)->date); hashwrite(f, packedDate, 8); @@ -1301,9 +1301,11 @@ static void compute_generation_numbers(struct write_commit_graph_context *ctx) _("Computing commit graph generation numbers"), ctx->commits.nr); for (i = 0; i < ctx->commits.nr; i++) { + uint32_t generation = commit_graph_data_at(ctx->commits.list[i])->generation; + display_progress(ctx->progress, i + 1); - if (commit_graph_generation(ctx->commits.list[i]) != GENERATION_NUMBER_INFINITY && - commit_graph_generation(ctx->commits.list[i]) != GENERATION_NUMBER_ZERO) + if (generation != GENERATION_NUMBER_INFINITY && + generation != GENERATION_NUMBER_ZERO) continue; commit_list_insert(ctx->commits.list[i], &list); @@ -1314,8 +1316,9 @@ static void compute_generation_numbers(struct write_commit_graph_context *ctx) uint32_t max_generation = 0; for (parent = current->parents; parent; parent = parent->next) { - if (commit_graph_generation(parent->item) == GENERATION_NUMBER_INFINITY || - commit_graph_generation(parent->item) == GENERATION_NUMBER_ZERO) { + + if (generation == GENERATION_NUMBER_INFINITY || + generation == GENERATION_NUMBER_ZERO) { all_parents_computed = 0; commit_list_insert(parent->item, &list); break; From patchwork Sun Jun 7 19:32:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Abhishek Kumar X-Patchwork-Id: 11592133 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3FB03739 for ; Sun, 7 Jun 2020 19:34:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1D208206F6 for ; Sun, 7 Jun 2020 19:34:52 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="dtA3Pyw6" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727787AbgFGTev (ORCPT ); Sun, 7 Jun 2020 15:34:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34684 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726093AbgFGTeu (ORCPT ); Sun, 7 Jun 2020 15:34:50 -0400 Received: from mail-pj1-x1041.google.com (mail-pj1-x1041.google.com [IPv6:2607:f8b0:4864:20::1041]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 55A0DC08C5C3 for ; Sun, 7 Jun 2020 12:34:51 -0700 (PDT) Received: by mail-pj1-x1041.google.com with SMTP id i4so1036309pjd.0 for ; Sun, 07 Jun 2020 12:34:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=WFSh+kMCaUkTsGRgdsJeaxg1eZEomM3rPHsa9cAn2zY=; b=dtA3Pyw6CSePlU4aTNce9GT3GVpLkDjgcZNiR3Gj6Ja0rVEqyUqxU3OGv3k3ECvjFO oCQ+e+G7C9S0ziXIjy12Rg6b8hJmgPyiiCtHAkt2bkPMcM6yE/ido91s0TzWm8GzTJ6O IRG2GLFRC6iVluX69qRjHd1x6Z5dNoKfxcQERMIyXA6+qZjg7eEOsMpoAMlcrU5zLEfg ZgOkAEvKfLYMKrcTJoh2pbLDvrarw9WyPEFIu46qIDs75T43ECFq/Fg5aeeRJic+/lNo rgNx2nKFe/TXryE6wcDUy3xlRk/Rxl7XF0Q5tGnkT8t/1Tu65gIFrSl3drSJvpeNN5gm jEkQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=WFSh+kMCaUkTsGRgdsJeaxg1eZEomM3rPHsa9cAn2zY=; b=XKpfE7GX6P+5ek7XiVEbGlGOr/Sr8QdLk+Vsrg/rTitpC8fSzvNE4FP6g8AoRlAahi Tbn6b8+9RcBXZi6sgbAyL8MRMIDTT/QQcsOlPoQd+uNXf5K2N/1r40dsMIpjVTPR1Kw3 2wTzscU29MHUThb3awOYW8DU3p54O4+EJA4cLUNwmdJHziqoFYiX+apvdxwFfZEDrmO9 u8LhdqPuTmpfnZ8O9OUr9q5RzyNaANtq2gjPaXZgaw8ztnd8iHIfnfJXY1yau95tahLx a2GQw7M71nXXAzl3SB61OPKv2jqx32T8JJLWGeFf8gzkivgV3SG9RbryWfAo0PSpVuEu s+jA== X-Gm-Message-State: AOAM531wCVw6p46szjb7KGAbuJlfzIe1a9//8kGP9x+FfOnb1t1q4c51 GcxtoFV/vZPxo0A3jvJ69DXtUxFt X-Google-Smtp-Source: ABdhPJxT5WQ8iUKPaV+Mn7lsc2qoCUPV78/OfIR22Rb6xvMc+QOGv3UdiuJfUYl2vH2CH+Kk5V/PmA== X-Received: by 2002:a17:90a:aa8f:: with SMTP id l15mr14668214pjq.156.1591558490204; Sun, 07 Jun 2020 12:34:50 -0700 (PDT) Received: from localhost.localdomain ([2409:4064:58e:925f:60d1:f386:43d2:4abb]) by smtp.gmail.com with ESMTPSA id n69sm158595pfd.171.2020.06.07.12.34.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 Jun 2020 12:34:49 -0700 (PDT) From: Abhishek Kumar To: git@vger.kernel.org Cc: jnareb@gmail.com, stolee@gmail.com Subject: [GSOC Patch v2 4/4] commit-graph: minimize commit_graph_data_slab access Date: Mon, 8 Jun 2020 01:02:37 +0530 Message-Id: <20200607193237.699335-5-abhishekkumar8222@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200607193237.699335-1-abhishekkumar8222@gmail.com> References: <20200604072759.19142-1-abhishekkumar8222@gmail.com> <20200607193237.699335-1-abhishekkumar8222@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org In an earlier patch, multiple struct acccesses to `graph_pos` and `generation` were auto-converted to multiple method calls. Since the values are fixed and commit-slab access costly, we would be better off with storing the values as a local variable and reuse it. Signed-off-by: Abhishek Kumar [1]: https://lore.kernel.org/git/9a15c7ba-8b55-099a-3c59-b5e7ff6124f6@gmail.com/ --- bloom.c | 5 +++-- commit-graph.c | 55 +++++++++++++++++++++++++++++----------------- commit-reach.c | 59 ++++++++++++++++++++++++++++++++------------------ commit.c | 6 +++-- revision.c | 12 ++++++---- 5 files changed, 88 insertions(+), 49 deletions(-) diff --git a/bloom.c b/bloom.c index df62e3763d..568ebd75e7 100644 --- a/bloom.c +++ b/bloom.c @@ -33,15 +33,16 @@ static int load_bloom_filter_from_graph(struct commit_graph *g, struct commit *c) { uint32_t lex_pos, start_index, end_index; + uint32_t graph_pos = commit_graph_position(c); - while (commit_graph_position(c) < g->num_commits_in_base) + while (graph_pos < g->num_commits_in_base) g = g->base_graph; /* The commit graph commit 'c' lives in doesn't carry bloom filters. */ if (!g->chunk_bloom_indexes) return 0; - lex_pos = commit_graph_position(c) - g->num_commits_in_base; + lex_pos = graph_pos - g->num_commits_in_base; end_index = get_be32(g->chunk_bloom_indexes + 4 * lex_pos); diff --git a/commit-graph.c b/commit-graph.c index 0dc79e7c90..5b10d1da2c 100644 --- a/commit-graph.c +++ b/commit-graph.c @@ -141,10 +141,12 @@ static int commit_gen_cmp(const void *va, const void *vb) const struct commit *a = *(const struct commit **)va; const struct commit *b = *(const struct commit **)vb; + uint32_t generation_a = commit_graph_generation(a); + uint32_t generation_b = commit_graph_generation(b); /* lower generation commits first */ - if (commit_graph_generation(a) < commit_graph_generation(b)) + if (generation_a < generation_b) return -1; - else if (commit_graph_generation(a) > commit_graph_generation(b)) + else if (generation_a > generation_b) return 1; /* use date as a heuristic when generations are equal */ @@ -726,6 +728,7 @@ static struct commit_list **insert_parent_or_die(struct repository *r, static void fill_commit_graph_info(struct commit *item, struct commit_graph *g, uint32_t pos) { const unsigned char *commit_data; + struct commit_graph_data *graph_data; uint32_t lex_index; while (pos < g->num_commits_in_base) @@ -733,8 +736,10 @@ static void fill_commit_graph_info(struct commit *item, struct commit_graph *g, lex_index = pos - g->num_commits_in_base; commit_data = g->chunk_commit_data + GRAPH_DATA_WIDTH * lex_index; - commit_graph_data_at(item)->graph_pos = pos; - commit_graph_data_at(item)->generation = get_be32(commit_data + g->hash_len + 8) >> 2; + + graph_data = commit_graph_data_at(item); + graph_data->graph_pos = pos; + graph_data->generation = get_be32(commit_data + g->hash_len + 8) >> 2; } static inline void set_commit_tree(struct commit *c, struct tree *t) @@ -750,6 +755,7 @@ static int fill_commit_in_graph(struct repository *r, uint32_t *parent_data_ptr; uint64_t date_low, date_high; struct commit_list **pptr; + struct commit_graph_data *graph_data; const unsigned char *commit_data; uint32_t lex_index; @@ -763,7 +769,8 @@ static int fill_commit_in_graph(struct repository *r, * Store the "full" position, but then use the * "local" position for the rest of the calculation. */ - commit_graph_data_at(item)->graph_pos = pos; + graph_data = commit_graph_data_at(item); + graph_data->graph_pos = pos; lex_index = pos - g->num_commits_in_base; commit_data = g->chunk_commit_data + (g->hash_len + 16) * lex_index; @@ -776,7 +783,7 @@ static int fill_commit_in_graph(struct repository *r, date_low = get_be32(commit_data + g->hash_len + 12); item->date = (timestamp_t)((date_high << 32) | date_low); - commit_graph_data_at(item)->generation = get_be32(commit_data + g->hash_len + 8) >> 2; + graph_data->generation = get_be32(commit_data + g->hash_len + 8) >> 2; pptr = &item->parents; @@ -808,8 +815,9 @@ static int fill_commit_in_graph(struct repository *r, static int find_commit_in_graph(struct commit *item, struct commit_graph *g, uint32_t *pos) { - if (commit_graph_position(item) != COMMIT_NOT_FROM_GRAPH) { - *pos = commit_graph_position(item); + uint32_t graph_pos = commit_graph_position(item); + if (graph_pos != COMMIT_NOT_FROM_GRAPH) { + *pos = graph_pos; return 1; } else { struct commit_graph *cur_g = g; @@ -864,12 +872,13 @@ static struct tree *load_tree_for_commit(struct repository *r, { struct object_id oid; const unsigned char *commit_data; + uint32_t graph_pos = commit_graph_position(c); - while (commit_graph_position(c) < g->num_commits_in_base) + while (graph_pos < g->num_commits_in_base) g = g->base_graph; commit_data = g->chunk_commit_data + - GRAPH_DATA_WIDTH * (commit_graph_position(c) - g->num_commits_in_base); + GRAPH_DATA_WIDTH * (graph_pos - g->num_commits_in_base); hashcpy(oid.hash, commit_data); set_commit_tree(c, lookup_tree(r, &oid)); @@ -1301,7 +1310,7 @@ static void compute_generation_numbers(struct write_commit_graph_context *ctx) _("Computing commit graph generation numbers"), ctx->commits.nr); for (i = 0; i < ctx->commits.nr; i++) { - uint32_t generation = commit_graph_data_at(ctx->commits.list[i])->generation; + uint32_t generation = commit_graph_generation(ctx->commits.list[i]); display_progress(ctx->progress, i + 1); if (generation != GENERATION_NUMBER_INFINITY && @@ -1316,23 +1325,26 @@ static void compute_generation_numbers(struct write_commit_graph_context *ctx) uint32_t max_generation = 0; for (parent = current->parents; parent; parent = parent->next) { + generation = commit_graph_generation(parent->item); if (generation == GENERATION_NUMBER_INFINITY || generation == GENERATION_NUMBER_ZERO) { all_parents_computed = 0; commit_list_insert(parent->item, &list); break; - } else if (commit_graph_generation(parent->item) > max_generation) { - max_generation = commit_graph_generation(parent->item); + } else if (generation > max_generation) { + max_generation = generation; } } if (all_parents_computed) { - commit_graph_data_at(current)->generation = max_generation + 1; + struct commit_graph_data *graph_data = commit_graph_data_at(current); + + graph_data->generation = max_generation + 1; pop_commit(&list); - if (commit_graph_generation(current) > GENERATION_NUMBER_MAX) - commit_graph_data_at(current)->generation = GENERATION_NUMBER_MAX; + if (graph_data->generation > GENERATION_NUMBER_MAX) + graph_data->generation = GENERATION_NUMBER_MAX; } } } @@ -2301,6 +2313,7 @@ int verify_commit_graph(struct repository *r, struct commit_graph *g, int flags) struct commit *graph_commit, *odb_commit; struct commit_list *graph_parents, *odb_parents; uint32_t max_generation = 0; + uint32_t generation; display_progress(progress, i + 1); hashcpy(cur_oid.hash, g->chunk_oid_lookup + g->hash_len * i); @@ -2339,8 +2352,9 @@ int verify_commit_graph(struct repository *r, struct commit_graph *g, int flags) oid_to_hex(&graph_parents->item->object.oid), oid_to_hex(&odb_parents->item->object.oid)); - if (commit_graph_generation(graph_parents->item) > max_generation) - max_generation = commit_graph_generation(graph_parents->item); + generation = commit_graph_generation(graph_parents->item); + if (generation > max_generation) + max_generation = generation; graph_parents = graph_parents->next; odb_parents = odb_parents->next; @@ -2370,10 +2384,11 @@ int verify_commit_graph(struct repository *r, struct commit_graph *g, int flags) if (max_generation == GENERATION_NUMBER_MAX) max_generation--; - if (commit_graph_generation(graph_commit) != max_generation + 1) + generation = commit_graph_generation(graph_commit); + if (generation != max_generation + 1) graph_report(_("commit-graph generation for commit %s is %u != %u"), oid_to_hex(&cur_oid), - commit_graph_generation(graph_commit), + generation, max_generation + 1); if (graph_commit->date != odb_commit->date) diff --git a/commit-reach.c b/commit-reach.c index 3b2f863f5f..f5e5c0a32b 100644 --- a/commit-reach.c +++ b/commit-reach.c @@ -58,14 +58,15 @@ static struct commit_list *paint_down_to_common(struct repository *r, struct commit *commit = prio_queue_get(&queue); struct commit_list *parents; int flags; + uint32_t generation = commit_graph_generation(commit); - if (min_generation && commit_graph_generation(commit) > last_gen) + if (min_generation && generation > last_gen) BUG("bad generation skip %8x > %8x at %s", - commit_graph_generation(commit), last_gen, + generation, last_gen, oid_to_hex(&commit->object.oid)); - last_gen = commit_graph_generation(commit); + last_gen = generation; - if (commit_graph_generation(commit) < min_generation) + if (generation < min_generation) break; flags = commit->object.flags & (PARENT1 | PARENT2 | STALE); @@ -181,13 +182,15 @@ static int remove_redundant(struct repository *r, struct commit **array, int cnt if (redundant[i]) continue; for (j = filled = 0; j < cnt; j++) { + uint32_t curr_generation; if (i == j || redundant[j]) continue; filled_index[filled] = j; work[filled++] = array[j]; - if (commit_graph_generation(array[j]) < min_generation) - min_generation = commit_graph_generation(array[j]); + curr_generation = commit_graph_generation(array[j]); + if (curr_generation < min_generation) + min_generation = curr_generation; } common = paint_down_to_common(r, array[i], filled, work, min_generation); @@ -316,23 +319,26 @@ int repo_in_merge_bases_many(struct repository *r, struct commit *commit, { struct commit_list *bases; int ret = 0, i; - uint32_t min_generation = GENERATION_NUMBER_INFINITY; + uint32_t generation, min_generation = GENERATION_NUMBER_INFINITY; if (repo_parse_commit(r, commit)) return ret; for (i = 0; i < nr_reference; i++) { if (repo_parse_commit(r, reference[i])) return ret; - if (commit_graph_generation(reference[i]) < min_generation) - min_generation = commit_graph_generation(reference[i]); + + generation = commit_graph_generation(reference[i]); + if (generation < min_generation) + min_generation = generation; } - if (commit_graph_generation(commit) > min_generation) + generation = commit_graph_generation(commit); + if (generation > min_generation) return ret; bases = paint_down_to_common(r, commit, nr_reference, reference, - commit_graph_generation(commit)); + generation); if (commit->object.flags & PARENT2) ret = 1; clear_commit_marks(commit, all_flags); @@ -490,10 +496,12 @@ static enum contains_result contains_tag_algo(struct commit *candidate, const struct commit_list *p; for (p = want; p; p = p->next) { + uint32_t generation; struct commit *c = p->item; load_commit_graph_info(the_repository, c); - if (commit_graph_generation(c) < cutoff) - cutoff = commit_graph_generation(c); + generation = commit_graph_generation(c); + if (generation < cutoff) + cutoff = generation; } result = contains_test(candidate, want, cache, cutoff); @@ -544,9 +552,12 @@ static int compare_commits_by_gen(const void *_a, const void *_b) const struct commit *a = *(const struct commit * const *)_a; const struct commit *b = *(const struct commit * const *)_b; - if (commit_graph_generation(a) < commit_graph_generation(b)) + uint32_t generation_a = commit_graph_generation(a); + uint32_t generation_b = commit_graph_generation(b); + + if (generation_a < generation_b) return -1; - if (commit_graph_generation(a) > commit_graph_generation(b)) + if (generation_a > generation_b) return 1; return 0; } @@ -662,11 +673,13 @@ int can_all_from_reach(struct commit_list *from, struct commit_list *to, add_object_array(&from_iter->item->object, NULL, &from_objs); if (!parse_commit(from_iter->item)) { + uint32_t generation; if (from_iter->item->date < min_commit_date) min_commit_date = from_iter->item->date; - if (commit_graph_generation(from_iter->item) < min_generation) - min_generation = commit_graph_generation(from_iter->item); + generation = commit_graph_generation(from_iter->item); + if (generation < min_generation) + min_generation = generation; } from_iter = from_iter->next; @@ -674,11 +687,13 @@ int can_all_from_reach(struct commit_list *from, struct commit_list *to, while (to_iter) { if (!parse_commit(to_iter->item)) { + uint32_t generation; if (to_iter->item->date < min_commit_date) min_commit_date = to_iter->item->date; - if (commit_graph_generation(to_iter->item) < min_generation) - min_generation = commit_graph_generation(to_iter->item); + generation = commit_graph_generation(to_iter->item); + if (generation < min_generation) + min_generation = generation; } to_iter->item->object.flags |= PARENT2; @@ -718,11 +733,13 @@ struct commit_list *get_reachable_subset(struct commit **from, int nr_from, struct prio_queue queue = { compare_commits_by_gen_then_commit_date }; for (item = to; item < to_last; item++) { + uint32_t generation; struct commit *c = *item; parse_commit(c); - if (commit_graph_generation(c) < min_generation) - min_generation = commit_graph_generation(c); + generation = commit_graph_generation(c); + if (generation < min_generation) + min_generation = generation; if (!(c->object.flags & PARENT1)) { c->object.flags |= PARENT1; diff --git a/commit.c b/commit.c index ad9a76dcc6..f85ade78ed 100644 --- a/commit.c +++ b/commit.c @@ -729,11 +729,13 @@ int compare_commits_by_author_date(const void *a_, const void *b_, int compare_commits_by_gen_then_commit_date(const void *a_, const void *b_, void *unused) { const struct commit *a = a_, *b = b_; + const uint32_t generation_a = commit_graph_generation(a), + generation_b = commit_graph_generation(b); /* newer commits first */ - if (commit_graph_generation(a) < commit_graph_generation(b)) + if (generation_a < generation_b) return 1; - else if (commit_graph_generation(a) > commit_graph_generation(b)) + else if (generation_a > generation_b) return -1; /* use date as a heuristic when generations are equal */ diff --git a/revision.c b/revision.c index cb1b200e9f..c257089808 100644 --- a/revision.c +++ b/revision.c @@ -3407,6 +3407,7 @@ static void init_topo_walk(struct rev_info *revs) info->min_generation = GENERATION_NUMBER_INFINITY; for (list = revs->commits; list; list = list->next) { struct commit *c = list->item; + uint32_t generation; if (parse_commit_gently(c, 1)) continue; @@ -3414,8 +3415,9 @@ static void init_topo_walk(struct rev_info *revs) test_flag_and_insert(&info->explore_queue, c, TOPO_WALK_EXPLORED); test_flag_and_insert(&info->indegree_queue, c, TOPO_WALK_INDEGREE); - if (commit_graph_generation(c) < info->min_generation) - info->min_generation = commit_graph_generation(c); + generation = commit_graph_generation(c); + if (generation < info->min_generation) + info->min_generation = generation; *(indegree_slab_at(&info->indegree, c)) = 1; @@ -3466,6 +3468,7 @@ static void expand_topo_walk(struct rev_info *revs, struct commit *commit) for (p = commit->parents; p; p = p->next) { struct commit *parent = p->item; int *pi; + uint32_t generation; if (parent->object.flags & UNINTERESTING) continue; @@ -3473,8 +3476,9 @@ static void expand_topo_walk(struct rev_info *revs, struct commit *commit) if (parse_commit_gently(parent, 1) < 0) continue; - if (commit_graph_generation(parent) < info->min_generation) { - info->min_generation = commit_graph_generation(parent); + generation = commit_graph_generation(parent); + if (generation < info->min_generation) { + info->min_generation = generation; compute_indegrees_to_depth(revs, info->min_generation); }