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.7 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 28ACD1F66E for ; Tue, 25 Aug 2020 18:40:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726752AbgHYSkM (ORCPT ); Tue, 25 Aug 2020 14:40:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44404 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726158AbgHYSkJ (ORCPT ); Tue, 25 Aug 2020 14:40:09 -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 6A831C061756 for ; Tue, 25 Aug 2020 11:40:09 -0700 (PDT) Received: by mail-wm1-x342.google.com with SMTP id u18so3603537wmc.3 for ; Tue, 25 Aug 2020 11:40:09 -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=ablqq3jT9ZyD0iEPR8c7GLfn5zx1HtHOn/rEKNsk8Lo=; b=Y8xkz5E6x73AuzfQIMJPHN9VXoiay1JLIhL8UJlDhiaV8WaULafdtMx0AN6k+PaOLN /hxLjRi5q8tnMWmW6jwcx5MRKbANiN3fJmnm6GCOUYhHSwiDV+6Vn3o/9SczV/fRg8w/ oJFR9/x4OEeAIvMjY2zeEPAX+dwMSP3xCjvubEbPxLREl2FV1YPOgvBg1dAtGS4DOp0P Maq3TLf4dBD1gXMr66zC1VbhQCUk9EfVwjn5X3i5BGPzFUEKD79GFTv8V1NjwCbGNCxE BGkwKG2cSoeWfsNCt+/e60kvIBQvK8GAD4sfVEIinEFTPEW8U9Kg+18SWxp51oR0xSq+ YoXA== 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=ablqq3jT9ZyD0iEPR8c7GLfn5zx1HtHOn/rEKNsk8Lo=; b=TZ6/zV7KASb2lOC7j+aOyZviA5vqBUGrE9pUmcUhyHuom/suvGgZ6byjVSesv6ijNq BO1up2HFhmhUR1mIi3WkOz1Ae4LPzjUYM/idq0DSZDU7mz20aHDxPHr9D0Zd4X5gOQcJ uaanIFoP0NhTG51fBUQ9P3pVTSw2fnMYPNMkvxVhpppfPO88+PFlt0hmX+dntjvO9iPL G1u9OG2xCyXEs6d4KEPTMTMi1eNN7qmuHqP/jypp78rWMTNZVJybJ8vK37FUaVDDVjVd YeKCBr9iYsfyFF++2O+wfiTTbKjfxURJ+VP3vFJHnBzHbhhHG/wXVNNUZOTFbAhKHe+d lxBw== X-Gm-Message-State: AOAM5330ZyUDEEdrfJKtYixwAeuDzV2gzN/qvY/AGHDCic0ONqnej6lM FKRQKXP4PPHStpwpjUgNbsEXaPBBs1M= X-Google-Smtp-Source: ABdhPJyC9W9wFkEdRNwzQHoUi5fECqpiy93qWAPyiq5zr52/Zux3NLm+sV6RC59YQleCJ3bgPVvbkg== X-Received: by 2002:a1c:c906:: with SMTP id f6mr3440267wmb.5.1598380807846; Tue, 25 Aug 2020 11:40:07 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id a7sm7115641wmj.24.2020.08.25.11.40.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Aug 2020 11:40:07 -0700 (PDT) Message-Id: In-Reply-To: References: From: "Derrick Stolee via GitGitGadget" Date: Tue, 25 Aug 2020 18:39:59 +0000 Subject: [PATCH v2 2/7] maintenance: store the "last run" time in config Fcc: Sent Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit MIME-Version: 1.0 To: git@vger.kernel.org Cc: 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 Users may want to run certain maintenance tasks only so often. Update the local config with a new 'maintenance..lastRun' config option that stores the timestamp just before running the maintenance task. I selected the timestamp before the task, as opposed to after the task, for a couple reasons: 1. The time the task takes to execute should not contribute to the interval between running the tasks. If a daily task takes 10 minutes to run, then every day the execution will drift by at least 10 minutes. 2. If the task fails for some unforseen reason, it would be good to indicate that we _attempted_ the task at a certain timestamp. This will avoid spamming a repository that is in a bad state. Signed-off-by: Derrick Stolee --- Documentation/config/maintenance.txt | 5 +++++ builtin/gc.c | 16 ++++++++++++++++ t/t7900-maintenance.sh | 10 ++++++++++ 3 files changed, 31 insertions(+) diff --git a/Documentation/config/maintenance.txt b/Documentation/config/maintenance.txt index 06db758172..8dd34169da 100644 --- a/Documentation/config/maintenance.txt +++ b/Documentation/config/maintenance.txt @@ -10,6 +10,11 @@ maintenance..enabled:: `--task` option exists. By default, only `maintenance.gc.enabled` is true. +maintenance..lastRun:: + This config value is automatically updated by Git when the task + `` is run. It stores a timestamp representing the most-recent + run of the ``. + 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 diff --git a/builtin/gc.c b/builtin/gc.c index f8459df04c..fb6f231a5c 100644 --- a/builtin/gc.c +++ b/builtin/gc.c @@ -1212,6 +1212,20 @@ static int compare_tasks_by_selection(const void *a_, const void *b_) return b->selected_order - a->selected_order; } +static void update_last_run(struct maintenance_task *task) +{ + timestamp_t now = approxidate("now"); + struct strbuf config = STRBUF_INIT; + struct strbuf value = STRBUF_INIT; + strbuf_addf(&config, "maintenance.%s.lastrun", task->name); + strbuf_addf(&value, "%"PRItime"", now); + + git_config_set(config.buf, value.buf); + + strbuf_release(&config); + strbuf_release(&value); +} + static int maintenance_run_tasks(struct maintenance_run_opts *opts) { int i, found_selected = 0; @@ -1254,6 +1268,8 @@ static int maintenance_run_tasks(struct maintenance_run_opts *opts) !tasks[i].auto_condition())) continue; + update_last_run(&tasks[i]); + trace2_region_enter("maintenance", tasks[i].name, r); if (tasks[i].fn(opts)) { error(_("task '%s' failed"), tasks[i].name); diff --git a/t/t7900-maintenance.sh b/t/t7900-maintenance.sh index e0ba19e1ff..a985ce3674 100755 --- a/t/t7900-maintenance.sh +++ b/t/t7900-maintenance.sh @@ -264,4 +264,14 @@ test_expect_success 'maintenance.incremental-repack.auto' ' done ' +test_expect_success 'tasks update maintenance..lastRun' ' + git config --unset maintenance.commit-graph.lastrun && + GIT_TRACE2_EVENT="$(pwd)/run.txt" \ + GIT_TEST_DATE_NOW=1595000000 \ + git maintenance run --task=commit-graph 2>/dev/null && + test_subcommand git commit-graph write --split --reachable \ + --no-progress