From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-Status: No, score=-3.9 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_PASS, SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by dcvr.yhbt.net (Postfix) with ESMTP id 577001F5AF for ; Tue, 7 Jul 2020 14:22:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728263AbgGGOWC (ORCPT ); Tue, 7 Jul 2020 10:22:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51146 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728333AbgGGOVx (ORCPT ); Tue, 7 Jul 2020 10:21:53 -0400 Received: from mail-wm1-x342.google.com (mail-wm1-x342.google.com [IPv6:2a00:1450:4864:20::342]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 630D2C08C5F4 for ; Tue, 7 Jul 2020 07:21:52 -0700 (PDT) Received: by mail-wm1-x342.google.com with SMTP id f18so46740185wml.3 for ; Tue, 07 Jul 2020 07:21:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=1PDu+vfdggb2dHGLKD9G3geDCGfHn8e+tRKoxgR8BbU=; b=aMUCuKonuZ4LAaAqTwfnbstoQiSIzoBds66HL6A+VgY28FnbaYByATnifZDz6X5Rxz +JDDuM19iny2Hp6AY7OlmKCZSAa6l57lgC/sLjpDH9ry2Q0/Sm0DwYOx95xo0MixCqzr mOtYzoAyR99AVpaakPDxQtR8f/6bhkQ2p8sYk1eHL4F718LHBGf6+F+aTNP+VaEdMP5V EWowlE8WIL8KVs45LCS/uDs1OOYaILDwOC15lzXaUAToym82uzsbJTvASJLVqg5l7E3p e8PzgU0qPXDAHzQ18hzPnUBDFM8895tiTh2mFhvMuUcHcpbrZ02ovvUa//2myA+G06Kv d89w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=1PDu+vfdggb2dHGLKD9G3geDCGfHn8e+tRKoxgR8BbU=; b=E+3IWIpv9xj8jHf+YpFNv1D+DjxGSeVHFvX6J4t+QXehFY92u70fxWdkL5qcjWV7l1 d8KXR/xKfVvBcIcrBPJzl1TJtc6dolbp5G0ybst72ts0n7UH9sAaNJNd0Adxo04qXqKR ckaE4pmHW6j9UmL0DM8+M9CISVQ9w0JAQzAWyIkqoFP1JsKglGgMhTa7mupVhgB53mtM PlpCEjJKYnlpIQRcjvGP3nE38uX1t6EShxN9MJ1ND2zF8/1Smr+vCkagvwL3eon7lcRx BfEcXohrqwFJxPZIzZmrF/yTYATZphvOxezv7U1vnvCS+4fFWMtltP0d3neBgf+0ONXm 5SoA== X-Gm-Message-State: AOAM5306JZ7gRBI6EIlB1S4q3297Uhkn0hK73U/HEDLa2t/fcagXBDCK lqpf4lpEKFviDslWAf011I2s/XnW X-Google-Smtp-Source: ABdhPJxf41S38AF3UhIsJHcG1FTBceSz0nXbq5+5sSPEclSb4DBz9Jvv46K4d1fTmh0Qw9E4kDZwrw== X-Received: by 2002:a1c:49d4:: with SMTP id w203mr4737490wma.13.1594131710997; Tue, 07 Jul 2020 07:21:50 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id d10sm1224817wrx.66.2020.07.07.07.21.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jul 2020 07:21:50 -0700 (PDT) Message-Id: <37fa3f6157ab7799f29331e8cf11f55e7f123e49.1594131695.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Derrick Stolee via GitGitGadget" Date: Tue, 07 Jul 2020 14:21:32 +0000 Subject: [PATCH 18/21] maintenance: add auto condition for commit-graph task Fcc: Sent Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit MIME-Version: 1.0 To: git@vger.kernel.org Cc: Johannes.Schindelin@gmx.de, sandals@crustytoothpaste.net, steadmon@google.com, jrnieder@gmail.com, peff@peff.net, congdanhqx@gmail.com, phillip.wood123@gmail.com, Derrick Stolee , Derrick Stolee Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee Instead of writing a new commit-graph in every 'git maintenance run --auto' process (when maintenance.commit-graph.enalbed is configured to be true), only write when there are "enough" commits not in a commit-graph file. This count is controlled by the maintenance.commit-graph.auto config option. To compute the count, use a depth-first search starting at each ref, and leaving markers using the PARENT1 flag. If this count reaches the limit, then terminate early and start the task. Otherwise, this operation will peel every ref and parse the commit it points to. If these are all in the commit-graph, then this is typically a very fast operation. Users with many refs might feel a slow-down, and hence could consider updating their limit to be very small. A negative value will force the step to run every time. Signed-off-by: Derrick Stolee --- Documentation/config/maintenance.txt | 10 ++++ builtin/gc.c | 76 ++++++++++++++++++++++++++++ object.h | 1 + 3 files changed, 87 insertions(+) diff --git a/Documentation/config/maintenance.txt b/Documentation/config/maintenance.txt index 370cbfb42f..9bd69b9df3 100644 --- a/Documentation/config/maintenance.txt +++ b/Documentation/config/maintenance.txt @@ -2,3 +2,13 @@ maintenance..enabled:: This boolean config option controls whether the maintenance task with name `` is run when no `--task` option is specified. By default, only `maintenance.gc.enabled` is true. + +maintenance.commit-graph.auto:: + This integer config option controls how often the `commit-graph` task + should be run as part of `git maintenance run --auto`. If zero, then + the `commit-graph` task will not run with the `--auto` option. A + negative value will force the task to run every time. Otherwise, a + positive value implies the command should run when the number of + reachable commits that are not in the commit-graph file is at least + the value of `maintenance.commit-graph.auto`. The default value is + 100. diff --git a/builtin/gc.c b/builtin/gc.c index dd24026b41..81b076b012 100644 --- a/builtin/gc.c +++ b/builtin/gc.c @@ -30,6 +30,7 @@ #include "promisor-remote.h" #include "remote.h" #include "midx.h" +#include "refs.h" #define FAILED_RUN "failed to run %s" @@ -720,6 +721,80 @@ struct maintenance_opts { int tasks_selected; } opts; +/* Remember to update object flag allocation in object.h */ +#define PARENT1 (1u<<16) + +static int num_commits_not_in_graph = 0; +static int limit_commits_not_in_graph = 100; + +static int dfs_on_ref(const char *refname, + const struct object_id *oid, int flags, + void *cb_data) +{ + int result = 0; + struct object_id peeled; + struct commit_list *stack = NULL; + struct commit *commit; + + if (!peel_ref(refname, &peeled)) + oid = &peeled; + if (oid_object_info(the_repository, oid, NULL) != OBJ_COMMIT) + return 0; + + commit = lookup_commit(the_repository, oid); + if (!commit) + return 0; + if (parse_commit(commit)) + return 0; + + commit_list_append(commit, &stack); + + while (!result && stack) { + struct commit_list *parent; + + commit = pop_commit(&stack); + + for (parent = commit->parents; parent; parent = parent->next) { + if (parse_commit(parent->item) || + commit_graph_position(parent->item) != COMMIT_NOT_FROM_GRAPH || + parent->item->object.flags & PARENT1) + continue; + + parent->item->object.flags |= PARENT1; + num_commits_not_in_graph++; + + if (num_commits_not_in_graph >= limit_commits_not_in_graph) { + result = 1; + break; + } + + commit_list_append(parent->item, &stack); + } + } + + free_commit_list(stack); + return result; +} + +static int should_write_commit_graph(struct repository *r) +{ + int result; + + repo_config_get_int(r, "maintenance.commit-graph.auto", + &limit_commits_not_in_graph); + + if (!limit_commits_not_in_graph) + return 0; + if (limit_commits_not_in_graph < 0) + return 1; + + result = for_each_ref(dfs_on_ref, NULL); + + clear_commit_marks_all(PARENT1); + + return result; +} + static int run_write_commit_graph(struct repository *r) { int result; @@ -1250,6 +1325,7 @@ static void initialize_tasks(struct repository *r) tasks[num_tasks]->name = "commit-graph"; tasks[num_tasks]->fn = maintenance_task_commit_graph; + tasks[num_tasks]->auto_condition = should_write_commit_graph; num_tasks++; hashmap_init(&task_map, task_entry_cmp, NULL, MAX_NUM_TASKS); diff --git a/object.h b/object.h index 38dc2d5a6c..4f886495d7 100644 --- a/object.h +++ b/object.h @@ -73,6 +73,7 @@ struct object_array { * list-objects-filter.c: 21 * builtin/fsck.c: 0--3 * builtin/index-pack.c: 2021 + * builtin/maintenance.c: 16 * builtin/pack-objects.c: 20 * builtin/reflog.c: 10--12 * builtin/show-branch.c: 0-------------------------------------------26 -- gitgitgadget