From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.1 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 57C2FC433E3 for ; Thu, 30 Jul 2020 22:25:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3515020829 for ; Thu, 30 Jul 2020 22:25:09 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="KxEinOld" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730547AbgG3WZI (ORCPT ); Thu, 30 Jul 2020 18:25:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43916 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730412AbgG3WYy (ORCPT ); Thu, 30 Jul 2020 18:24:54 -0400 Received: from mail-wr1-x441.google.com (mail-wr1-x441.google.com [IPv6:2a00:1450:4864:20::441]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 74AF0C061757 for ; Thu, 30 Jul 2020 15:24:54 -0700 (PDT) Received: by mail-wr1-x441.google.com with SMTP id a14so26304695wra.5 for ; Thu, 30 Jul 2020 15:24:54 -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=k5H7vskpbKfRG/gk39MiiO8RG5LEjWacblN8SAQ+xvg=; b=KxEinOldZFr9KAvsSTO11J+vpoS0X9t4MCFcQzIGV94Xlo/vEiM12h4OTXYyk3A+Om 6kG5ZW6Lz7LIDjilREOFh6coff5m6Y2VuGLMmquUsR/gOV7GxlzIGucnsxG5Hlfu7mCQ RyoiDWfEabQvBAfSc6GtIhhqGf5oPAApVmA606G6BKH/QE600eg18hh6f8UtbdPYsmeC ieGatDiLgI4IrqXqBvHwBCzejcQgJ3VNi+1lvJO9JknFWkM7QiSguH+l+HEOJ5FZ3HXa UrJjA5h2kVFfpGtwNdlc2tXp+5Ke3nes+XiWygZsNE/dW68xpzNHeAmvvBR9gBSwrxV6 xzOg== 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=k5H7vskpbKfRG/gk39MiiO8RG5LEjWacblN8SAQ+xvg=; b=iwW5A8wj6EXLGeXkyNGpW+Vle11k/+AfceQ449uYmqrnJBTQzqKUIsnme50wRNvN+f x+40cujnzsLUH93+ETho+GEhZ2M2DvA09lFH1YnKwdGAXd4liMRnVy/5aCnzUphzO1HA 6MxxgCrSDUdL3rtpjgDYs8afFyevun0aAqjNtJZ/lFudqaeCjBvRJtetZPv/mF6LZkb3 mQmLLqDuyPpaJv1dpxs4J2sNEVFO+TcBM1iYe03g07hug4qMOmJ8P0+UI8Io7eHoKOdz nfYHdrjQaBqoQVGEAIfb9Zc3bENzgH30eZTihW1PXIuA/u3iRBrkU5MeFl/hElNnfct0 LKyA== X-Gm-Message-State: AOAM532cDN+J0mDXYwD8Csfmzbtkt20xQB90j2M2a1g7mJcWZyq3yw5K 9JIGrzELM0evI6C4sJ9qTnGXXeQx X-Google-Smtp-Source: ABdhPJwyUVzxiIZ9ceOiLhowQYYDE2dAzZlY+9hkhDAgFMstpGUrl3zQsusHZBDlNg3nKDEIqIAppg== X-Received: by 2002:a05:6000:12c1:: with SMTP id l1mr672267wrx.270.1596147893016; Thu, 30 Jul 2020 15:24:53 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id j5sm10926978wmb.12.2020.07.30.15.24.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Jul 2020 15:24:52 -0700 (PDT) Message-Id: In-Reply-To: References: From: "Derrick Stolee via GitGitGadget" Date: Thu, 30 Jul 2020 22:24:22 +0000 Subject: [PATCH v3 16/20] 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, emilyshaffer@google.com, sluongng@gmail.com, jonathantanmy@google.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 1c449b3776..c85813fffe 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" @@ -713,6 +714,80 @@ static 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(void) +{ + int result; + + git_config_get_int("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(void) { struct child_process child = CHILD_PROCESS_INIT; @@ -1123,6 +1198,7 @@ static struct maintenance_task tasks[] = { [TASK_COMMIT_GRAPH] = { "commit-graph", maintenance_task_commit_graph, + should_write_commit_graph, }, }; diff --git a/object.h b/object.h index 96a2105859..30d4e0f6a0 100644 --- a/object.h +++ b/object.h @@ -74,6 +74,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