From patchwork Wed Oct 7 12:55:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Cai via GitGitGadget X-Patchwork-Id: 11820587 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 F28281580 for ; Wed, 7 Oct 2020 12:55:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CB5E72083B for ; Wed, 7 Oct 2020 12:55:22 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ZEusl/3r" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728300AbgJGMzV (ORCPT ); Wed, 7 Oct 2020 08:55:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45258 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727253AbgJGMzV (ORCPT ); Wed, 7 Oct 2020 08:55:21 -0400 Received: from mail-wr1-x443.google.com (mail-wr1-x443.google.com [IPv6:2a00:1450:4864:20::443]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CD1FDC061755 for ; Wed, 7 Oct 2020 05:55:20 -0700 (PDT) Received: by mail-wr1-x443.google.com with SMTP id h7so2043037wre.4 for ; Wed, 07 Oct 2020 05:55:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:from:date:subject:fcc:content-transfer-encoding :mime-version:to:cc; bh=KDbWRhJKv2Cp517XP2Y0vfrECh5XjAVVL8QeRX8eG6k=; b=ZEusl/3riUGEqpN99R1oLDEuIvpG8Zftl6yrmOEiipE8pYaPjLPA31G69DLylo2y1x 41Q3YFFE+4RihM0AXB/tqPzCHfD2/Pvnv0U1A9zO+MSutRP39Hc83UAqwjzS3AWGdox0 GD/8KQMNCjey47/JBn39Ip9kolubaF4l9cRxLSCAX3Bb8+z6dGN3eGgvQLd1v1AfQZBL OyrTe6IAq94q0q+KDcIGZ4khxHNmWdHxLMWtgejJgjbdXvUCTDIXrU/t/p3CenrWIi8Q 7x6GvB4negi6gZUIvLKmDt3QGxmdo88sANHhtTvSPRRWR86kgQRI+AoXjUtQKDKl7UrT uhsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=KDbWRhJKv2Cp517XP2Y0vfrECh5XjAVVL8QeRX8eG6k=; b=Xc2EFHqekRaNiPW49PA16D91KUuHuK1yy8jTRCNMK7YveKb6jlsWv3mM0tWl06ExKR c8XCTY8K1jtmP1WLTQwx6iX+dsV1WGXVugap+nbwCjVK2AfcYHFwaaO12Ir3RitLEL4d bHbI2hSQ88HMcyCLXbcjvW2KvcAv0r1l3CDuraDV9sznWQnBAf4KWSM2VfAkMEH97hpg buxCJNfjJGucRH1ukCMgliOKuIdk/vo3rJU/fpCbUeqbPsPWoiKw0WVfrlxR2yuq80DD xgqLduspZ6oRM3Cp+XyZVhPZyHkJ1XWRVCZt+2rnUDJZeC5cfp1cqlP6BoCv7NS1ULWX OZAg== X-Gm-Message-State: AOAM530jlq0wuvs8fWtayEqYsX97qwUw0D1MNy8hCoANES65cx5PKO+a puVFdCiM/aZxtiCxB3WgPcOqyjdrlyQ= X-Google-Smtp-Source: ABdhPJwl8euJyrdsPiHcSh0PB0PludYScJnf9y9aB6SnXCAQTE4XEl1iWh1eougmN2HaQqyNinRezA== X-Received: by 2002:adf:f6cd:: with SMTP id y13mr3330875wrp.161.1602075319182; Wed, 07 Oct 2020 05:55:19 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id v17sm2868821wrc.23.2020.10.07.05.55.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Oct 2020 05:55:18 -0700 (PDT) Message-Id: From: "Derrick Stolee via GitGitGadget" Date: Wed, 07 Oct 2020 12:55:17 +0000 Subject: [PATCH] maintenance: test commit-graph auto condition Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Derrick Stolee , Derrick Stolee Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee The auto condition for the commit-graph maintenance task walks refs looking for commits that are not in the commit-graph file. This was added in 4ddc79b2 (maintenance: add auto condition for commit-graph task, 2020-09-17) but was left untested. The initial goal of this change was to demonstrate the feature works properly by adding tests. However, there was an off-by-one error that caused the basic tests around maintenance.commit-graph.auto=1 to fail when it should work. The subtlety is that if a ref tip is not in the commit-graph, then we were not adding that to the total count. In the test, we see that we have only added one commit since our last commit-graph write, so the auto condition would say there is nothing to do. The fix is simple: add the check for the commit-graph position to see that the tip is not in the commit-graph file before starting our walk. Since this happens before adding to the DFS stack, we do not need to clear our (currently empty) commit list. This does add some extra complexity for the test, because we also want to verify that the walk along the parents actually does some work. This means we need to add at least two commits in a row without writing the commit-graph. However, we also need to make sure no additional refs are pointing to the middle of this list or else the for_each_ref() in should_write_commit_graph() might visit these commits as tips instead of doing a DFS walk. Hence, the last two commits are added with "git commit" instead of "test_commit". Signed-off-by: Derrick Stolee --- maintenance: test commit-graph auto condition As promised [1], here is a test to check that maintenance.commit-graph.auto behaves correctly. In the process, I found a small off-by-one error that is not super-critical, but worth fixing. Thanks, -Stolee [1] https://lore.kernel.org/git/cfc8a8e9-f812-2cb1-f6d8-57ef585346d1@gmail.com/ Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-746%2Fderrickstolee%2Fmaintenance%2Fcg-auto-test-v1 Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-746/derrickstolee/maintenance/cg-auto-test-v1 Pull-Request: https://github.com/gitgitgadget/git/pull/746 builtin/gc.c | 8 +++++++- t/t7900-maintenance.sh | 29 +++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) base-commit: 25914c4fdeefd99b06e134496dfb9bbb58a5c417 diff --git a/builtin/gc.c b/builtin/gc.c index 090959350e..12ddb68bba 100644 --- a/builtin/gc.c +++ b/builtin/gc.c @@ -737,9 +737,15 @@ static int dfs_on_ref(const char *refname, commit = lookup_commit(the_repository, oid); if (!commit) return 0; - if (parse_commit(commit)) + if (parse_commit(commit) || + commit_graph_position(commit) != COMMIT_NOT_FROM_GRAPH) return 0; + data->num_not_in_graph++; + + if (data->num_not_in_graph >= data->limit) + return 1; + commit_list_append(commit, &stack); while (!result && stack) { diff --git a/t/t7900-maintenance.sh b/t/t7900-maintenance.sh index 53c883531e..3e16439bf6 100755 --- a/t/t7900-maintenance.sh +++ b/t/t7900-maintenance.sh @@ -52,6 +52,35 @@ test_expect_success 'run --task=' ' test_subcommand git commit-graph write --split --reachable --no-progress err && test_i18ngrep "is not a valid task" err