From patchwork Thu Mar 14 12:34:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 10852731 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id F2C9C1850 for ; Thu, 14 Mar 2019 12:34:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5C5112A1FC for ; Thu, 14 Mar 2019 12:34:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5062A2A23F; Thu, 14 Mar 2019 12:34:58 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2AB512A1FC for ; Thu, 14 Mar 2019 12:34:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727303AbfCNMe4 (ORCPT ); Thu, 14 Mar 2019 08:34:56 -0400 Received: from mail-wm1-f68.google.com ([209.85.128.68]:50553 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726688AbfCNMez (ORCPT ); Thu, 14 Mar 2019 08:34:55 -0400 Received: by mail-wm1-f68.google.com with SMTP id x7so2803618wmj.0 for ; Thu, 14 Mar 2019 05:34:54 -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=29pkbaKIcEZV76rA9luir7yhyIu1NXmLODyRRnt9pU0=; b=LWFqaRMnChJFKBQovbBjPLHZDZdKjgsvwcIouomX7f9SuQacF7QNpHHasickK0KOuk FThkiHpS36K/mE7kBfSWlD0TwkrJBXzx5lK1WWbdX/pp6UK99dKCoYr26+PNr96XEqvq aeEPoNnYSe+NECRQSh2x31+Qjh5IGhufQLjYI4ksRQac/A2o/rKZO/HgpMo7x+Zr8+jd NyWmZFCfefSvpPc7DiQqTYWGGzkW0ZMv7UQkw0EhJrlsUTF0PHP2zrAtR9RV9a0sfmpq ug48CEF95UxeZh/98TicwGX599FlafsRIXHXY6JZy8Rbqxe23tVXFjsCVM8cdonTAPj9 +8yw== 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=29pkbaKIcEZV76rA9luir7yhyIu1NXmLODyRRnt9pU0=; b=OjlS+nrMCYlhZRwtwtWIzOeGb6Ne8QxHtELZOnWWd9pZyU5+n9SyZKAsViCpjbui8W clXhQduiaBw9xFZYV9b2/wODm/vyE2mumpQF5C9uyjnO48CNnltjIjrX3FhZ/aZbgKYC QwwgD8e+Ras4ArT0tzk1iiKNfy/+DO9rs7ofrco2EBOZGe1HQ8cqsEmMzpyE4Otdyjn1 ZJg2ilctvUKFJ04vyUk4jEpkIqRPrSDz4BHRTTGGGgMkhnVfibzs0nkDy10cjvVoaqdz 4cFpPQnEfuFf8WYPhJgSAjAa7XrqCa5J5f1p94H1bRn/Sux1ixnHIWnpwGXifi5YPPz6 JjmQ== X-Gm-Message-State: APjAAAW4K+EeZ0Srr8NabldIgITWPjeeldZ8HHYQImVR100tnlzrE3hb GBdWIWMOLxM8EOdXXE6dQXAea6yi+uA= X-Google-Smtp-Source: APXvYqzmWta0wiJnMCynBX9YrnNkoJIAqpY+SyPwGPqNEN6q0vx7SY10ICd36Ok2DvVusLIwcuH3+Q== X-Received: by 2002:a1c:7a1a:: with SMTP id v26mr2296097wmc.129.1552566892890; Thu, 14 Mar 2019 05:34:52 -0700 (PDT) Received: from vm.nix.is ([2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id p6sm42374095wre.63.2019.03.14.05.34.50 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Thu, 14 Mar 2019 05:34:51 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmc=?= =?utf-8?b?4buNYyBEdXk=?= , Jeff King , Michael Haggerty , Stefan Beller , Jonathan Nieder , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v2 1/7] gc: remove redundant check for gc_auto_threshold Date: Thu, 14 Mar 2019 13:34:33 +0100 Message-Id: <20190314123439.4347-2-avarab@gmail.com> X-Mailer: git-send-email 2.21.0.360.g471c308f928 In-Reply-To: <20190313235439.30439-1-avarab@gmail.com> References: <20190313235439.30439-1-avarab@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Checking gc_auto_threshold in too_many_loose_objects() was added in 17815501a8 ("git-gc --auto: run "repack -A -d -l" as necessary.", 2007-09-17) when need_to_gc() itself was also reliant on gc_auto_pack_limit before its early return: gc_auto_threshold <= 0 && gc_auto_pack_limit <= 0 When that check was simplified to just checking "gc_auto_threshold <= 0" in b14d255ba8 ("builtin-gc.c: allow disabling all auto-gc'ing by assigning 0 to gc.auto", 2008-03-19) this unreachable code should have been removed. We only call too_many_loose_objects() from within need_to_gc() itself, which will return if this condition holds, and in cmd_gc() which will return before ever getting to "auto_gc && too_many_loose_objects()" if "auto_gc && !need_to_gc()" is true earlier in the function. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/gc.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/builtin/gc.c b/builtin/gc.c index 020f725acc..8c2312681c 100644 --- a/builtin/gc.c +++ b/builtin/gc.c @@ -157,9 +157,6 @@ static int too_many_loose_objects(void) int num_loose = 0; int needed = 0; - if (gc_auto_threshold <= 0) - return 0; - dir = opendir(git_path("objects/17")); if (!dir) return 0; From patchwork Thu Mar 14 12:34:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 10852733 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 72F7A1390 for ; Thu, 14 Mar 2019 12:35:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DD7B928B7D for ; Thu, 14 Mar 2019 12:34:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D18CC2A23F; Thu, 14 Mar 2019 12:34:59 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 74CB728B7D for ; Thu, 14 Mar 2019 12:34:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727406AbfCNMe6 (ORCPT ); Thu, 14 Mar 2019 08:34:58 -0400 Received: from mail-wr1-f66.google.com ([209.85.221.66]:43102 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726688AbfCNMe5 (ORCPT ); Thu, 14 Mar 2019 08:34:57 -0400 Received: by mail-wr1-f66.google.com with SMTP id d17so5651461wre.10 for ; Thu, 14 Mar 2019 05:34:56 -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=fwbWbcDVUm2nj+O0KFnV919PrtAZOMQJBD9zE7ycffE=; b=mLgjZQFi//feZiJnmlplylm+aSENi5BHGNp9Zxt5B0pB6OJ5UL+REquOZqFzycBAd4 j/sbt5sBd0D7XyDbvrjSyTDDVyr7YeQ4FxjT65xq2gW2bAQ6wwKS+jnCGNEHzeU3e5/K CzRdob1+PBvuqcQt/1/qUv1EqkLBD9BvOPLcExONXlP35okSa3zRXfU+ULVACb2kkf0o rdN53a685Li3U47MMvOAG8rOUcRsmkr+8ZvLOjqn3wjmpmUmGygZ2qVNR/5M/z3GUqei xNmfbTLK0xXTwT+wb9pXRNrSds1NAgtLn+R8YfODW2ZKYQDb+w1u7WaFPx8nZgFZxe2A OPRw== 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=fwbWbcDVUm2nj+O0KFnV919PrtAZOMQJBD9zE7ycffE=; b=L8bWpWvxGKjh9+wQAh+BqS3HYGc1sJu/7MjD6PfchFmNI+1G1kvvqCJDcpuYsQAvGp yYfO6kKroy8uNJxZLI5gYObhS6v0Loo2TuewPNRmBM0ALXmvvePTbTYEHV8S16SotAbm UVhndSYz0ySrrSuqEmsoEWMS/ANvDAsUZrahfZe6YMuYP8DaM+9YNRUT51Wg+/me4BR5 4EaCYJ2QkULGe/hRjK0Qsw9EC6udRDGrVLloqMii3wlcth4uXcgUN/lVtI2sqfXBMShF t5q8Op/T7TxS+qsI15lAvD/TMAXaU6/ZQSGtOnR5cH3tUGNAQnYAu3fQM+FHdtEsQYSQ CD7w== X-Gm-Message-State: APjAAAVAWEXm/DDU3qI8vdo4Was5UaKKVdzF885NA0mXBa90Sf/l4XNC cD3JhgQsihTYIYEkMvrrbIkbVEC5uso= X-Google-Smtp-Source: APXvYqxmTbCZQzWTJYwhYX+kaJiyhCmEnY3tIKmfHCckqJgVgOtAI6NdYHoJ7szQvjTkpal1f62UrQ== X-Received: by 2002:a05:6000:128f:: with SMTP id f15mr30102471wrx.74.1552566894800; Thu, 14 Mar 2019 05:34:54 -0700 (PDT) Received: from vm.nix.is ([2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id p6sm42374095wre.63.2019.03.14.05.34.53 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Thu, 14 Mar 2019 05:34:53 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmc=?= =?utf-8?b?4buNYyBEdXk=?= , Jeff King , Michael Haggerty , Stefan Beller , Jonathan Nieder , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v2 2/7] gc: convert to using the_hash_algo Date: Thu, 14 Mar 2019 13:34:34 +0100 Message-Id: <20190314123439.4347-3-avarab@gmail.com> X-Mailer: git-send-email 2.21.0.360.g471c308f928 In-Reply-To: <20190313235439.30439-1-avarab@gmail.com> References: <20190313235439.30439-1-avarab@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP There's been a lot of changing of the hardcoded "40" values to the_hash_algo->hexsz, but we've so far missed this one where we hardcoded 38 for the loose object file length. This is because a SHA-1 like abcde[...] gets turned into objects/ab/cde[...]. There's no reason to suppose the same won't be the case for SHA-256, and reading between the lines in hash-function-transition.txt the format is planned to be the same. In the future we may want to further modify this code for the hash function transition. There's a potential pathological case here where we'll only consider the loose objects for the currently active hash, but objects for that hash will share a directory storage with the other hash. Thus we could theoretically have 1k SHA-1 loose objects, and say 1 million SHA-256 objects, and not notice because we're currently using SHA-1. So assuming that "gc" eventually learns to pack up both SHA-1 and SHA-256 objects regardless of what the current the_hash_alg is perhaps this check should be changed to consider all files in objects/17/ matching [0-9a-f] 38 or 62 characters in length (i.e. both SHA-1 and SHA-256). But none of that is something we need to worry about now, and supporting both 38 and 62 characters depending on "the_hash_algo" removes another case of SHA-1 hardcoding. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/gc.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/builtin/gc.c b/builtin/gc.c index 8c2312681c..733bd7bdf4 100644 --- a/builtin/gc.c +++ b/builtin/gc.c @@ -156,6 +156,7 @@ static int too_many_loose_objects(void) int auto_threshold; int num_loose = 0; int needed = 0; + const unsigned hexsz_loose = the_hash_algo->hexsz - 2; dir = opendir(git_path("objects/17")); if (!dir) @@ -163,8 +164,8 @@ static int too_many_loose_objects(void) auto_threshold = DIV_ROUND_UP(gc_auto_threshold, 256); while ((ent = readdir(dir)) != NULL) { - if (strspn(ent->d_name, "0123456789abcdef") != 38 || - ent->d_name[38] != '\0') + if (strspn(ent->d_name, "0123456789abcdef") != hexsz_loose || + ent->d_name[hexsz_loose] != '\0') continue; if (++num_loose > auto_threshold) { needed = 1; From patchwork Thu Mar 14 12:34:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 10852735 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 738001390 for ; Thu, 14 Mar 2019 12:35:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5F4B52A1FC for ; Thu, 14 Mar 2019 12:35:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5348C2A23F; Thu, 14 Mar 2019 12:35:01 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EDDBA2A1FC for ; Thu, 14 Mar 2019 12:35:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727407AbfCNMe7 (ORCPT ); Thu, 14 Mar 2019 08:34:59 -0400 Received: from mail-wr1-f67.google.com ([209.85.221.67]:36514 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727267AbfCNMe7 (ORCPT ); Thu, 14 Mar 2019 08:34:59 -0400 Received: by mail-wr1-f67.google.com with SMTP id y13so1104427wrd.3 for ; Thu, 14 Mar 2019 05:34:57 -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=7Ajg8uPzBwMOafmb9oiC8siydAC2vaAyiWSb6jbnWfY=; b=ndcUAxc7qmLHmxe3kbLBpaAmtiE1Hjt/k/CxP8sgA4gQ2XkvijGtlraQFhUn8FgjLm boBFTG0RwZlWSAR89T6FzzD+DSGMw1F7Tppw73svN2tS55zMndpjr2EHSOrAWnvCynSV rXSFNb6JplKyY3yyNVHjDyAgaeWOkW68M/LXlcFdewKE5e2CTvQmZiF9HQDk7E5+KEc1 QrInJJqiu0Zba+iEhVzFuaQ6+JDBraQqQCsDWxcAPN/LjEMItTLpGtXz8EpZYG/NIVVz xvx6aeqc2lLshyxue+6gE6NQLhfIyT7jzz+brtqRakJLSAqYuW3hXcjSm5yxkw/8ys3g pFhw== 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=7Ajg8uPzBwMOafmb9oiC8siydAC2vaAyiWSb6jbnWfY=; b=VM7I7znpRDMdPlcM0Ey2RQduTsvXhD7OatbCGc5Mg+IHvyiILXzIgVtoCjTwVFHElW agBZr4fOBbO9r8+BybaAgf5Ewg6IA6WnvXcLkHTKdPfiqdfz8VU4v9XyIDFiXYp9HDB7 5lpTX7gueLQCsRIYOys1rVxVyXnx1M1pufl5F+vqBOgh/QI6teohZIcP4IDkbFrokfRM O6kQ3XV6lTiHvnsUkwUNg5VCLgGtU1C74EMvljiGGVTYtTpXJKECt9FAlRq9hH/QLxq8 j33Bv4CdQ4oBGgSoGUDcUeghqD8LFD3RC6Lovi3NM7DB84wIn9HTVeu3sokF1WeBDCv5 2wvQ== X-Gm-Message-State: APjAAAXcPla8XTBI910XLm/t6bnKVfsGMgAAJWlEy9q7GGgH+dxEIb+8 X9V19hXjMpsBn2Vh8XjpSVOTSEprLpI= X-Google-Smtp-Source: APXvYqw8kVlNxUMV7xJ8LaYh6ZFOpe2sFoYFoXz7R1/59CCv8/VTkxoKjY3F4J/gNso9b4aBmIEMEQ== X-Received: by 2002:adf:cf0c:: with SMTP id o12mr2901318wrj.16.1552566896699; Thu, 14 Mar 2019 05:34:56 -0700 (PDT) Received: from vm.nix.is ([2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id p6sm42374095wre.63.2019.03.14.05.34.55 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Thu, 14 Mar 2019 05:34:55 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmc=?= =?utf-8?b?4buNYyBEdXk=?= , Jeff King , Michael Haggerty , Stefan Beller , Jonathan Nieder , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v2 3/7] gc: refactor a "call me once" pattern Date: Thu, 14 Mar 2019 13:34:35 +0100 Message-Id: <20190314123439.4347-4-avarab@gmail.com> X-Mailer: git-send-email 2.21.0.360.g471c308f928 In-Reply-To: <20190313235439.30439-1-avarab@gmail.com> References: <20190313235439.30439-1-avarab@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Change an idiom we're using to ensure that gc_before_repack() only does work once (see 62aad1849f ("gc --auto: do not lock refs in the background", 2014-05-25)) to be more obvious. Nothing except this function cares about the "pack_refs" and "prune_reflogs" variables, so let's not leave the reader wondering if they're being zero'd out for later use somewhere else. Signed-off-by: Jeff King Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/gc.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/builtin/gc.c b/builtin/gc.c index 733bd7bdf4..ae716a00d4 100644 --- a/builtin/gc.c +++ b/builtin/gc.c @@ -489,14 +489,20 @@ static int report_last_gc_error(void) static void gc_before_repack(void) { + /* + * We may be called twice, as both the pre- and + * post-daemonized phases will call us, but running these + * commands more than once is pointless and wasteful. + */ + static int done = 0; + if (done++) + return; + if (pack_refs && run_command_v_opt(pack_refs_cmd.argv, RUN_GIT_CMD)) die(FAILED_RUN, pack_refs_cmd.argv[0]); if (prune_reflogs && run_command_v_opt(reflog.argv, RUN_GIT_CMD)) die(FAILED_RUN, reflog.argv[0]); - - pack_refs = 0; - prune_reflogs = 0; } int cmd_gc(int argc, const char **argv, const char *prefix) From patchwork Thu Mar 14 12:34:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 10852737 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A549417E6 for ; Thu, 14 Mar 2019 12:35:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C170B2A1FC for ; Thu, 14 Mar 2019 12:35:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B583C2A23B; Thu, 14 Mar 2019 12:35:03 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 65C562A242 for ; Thu, 14 Mar 2019 12:35:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727418AbfCNMfC (ORCPT ); Thu, 14 Mar 2019 08:35:02 -0400 Received: from mail-wr1-f46.google.com ([209.85.221.46]:46216 "EHLO mail-wr1-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726797AbfCNMfB (ORCPT ); Thu, 14 Mar 2019 08:35:01 -0400 Received: by mail-wr1-f46.google.com with SMTP id 33so5664127wrb.13 for ; Thu, 14 Mar 2019 05:34:59 -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=BfnimDtqv5SD6Iwu+dBH75qyhMYDPZ+Aoknb+G+x564=; b=VXUTVl0KbEj4fdbGVQY5HEY6SHOQ/x8Zn2F1wuow6H86aV9PPaFpbA6+q7U8iIFjah e8YvdZZBqaQPsHgs12K8m7rIKZT4E02s67SLhz70lqcpZ+EhHvyghPko+DsbKUBczbMm LvV6/u2W9W/5NfLdmwp7yBqwking/62ZNd0VBvrZ5WmQW6l0QmTsoLh7Mnc2UBoketUF OENIoTE5vOPNhF15XlWsaXdFARH2g2Aigb3GDwV1xdjVCDj3A5ZEyqt8gT/GRTbAyeEN 48p0W5aXOiqJdgGtdf/ljPTEX9UvJX1p2gvicM64uSHLE7m+gU1l/VF89+puLPWii7cK vBDA== 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=BfnimDtqv5SD6Iwu+dBH75qyhMYDPZ+Aoknb+G+x564=; b=TGhkpFmEy6INswqlL0oJnb0PhFt9yb1yYCFlyVXBt/4CGR3t3nLFyCEAtgNkCeAKgP gj4cxFYfnUiLZkiSZSseRKfcuVFHbKc/2Z0JQu+61Jdl2XyujDRifqh2LyjGGypkGQ0K 7kdYpggYmRNXOY7kUg1fUmbfZjjelBHFoyL2Ykmiz9z2rJWqN9Q7eV+ibeGCz6t04AR1 pLOUCvuxkKntvzrcZw/QRA5jbRV7AVJmJv99ty8QsL5uxEKef/hPEbJHpEiUxEKezSN+ /oXMWNwxW1ct494HJ3ca5v2xs+oZdSfdGailuK1czIzjlvO8n1p9cifYnUuQFbWHoz3l vENQ== X-Gm-Message-State: APjAAAUEgc+HnnoG6DaFd+//XEMMaQiUIfq4rwbxo5qoMDchYiO+hHJ7 ZLalTSxxX/6AauqWfJErxh+pZC7dH70= X-Google-Smtp-Source: APXvYqzjTVpDmeaFLR0/SoyvxmXOC78r2jVAr0ooCtFkHwrLfXxYv9a3ZCd1/SO2uv9Kwq64SO6Haw== X-Received: by 2002:adf:fa8c:: with SMTP id h12mr1234312wrr.75.1552566898149; Thu, 14 Mar 2019 05:34:58 -0700 (PDT) Received: from vm.nix.is ([2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id p6sm42374095wre.63.2019.03.14.05.34.57 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Thu, 14 Mar 2019 05:34:57 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmc=?= =?utf-8?b?4buNYyBEdXk=?= , Jeff King , Michael Haggerty , Stefan Beller , Jonathan Nieder , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v2 4/7] reflog tests: make use of "test_config" idiom Date: Thu, 14 Mar 2019 13:34:36 +0100 Message-Id: <20190314123439.4347-5-avarab@gmail.com> X-Mailer: git-send-email 2.21.0.360.g471c308f928 In-Reply-To: <20190313235439.30439-1-avarab@gmail.com> References: <20190313235439.30439-1-avarab@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Change a couple of tests that weren't using the helper to use it. This makes the trailing "--unset" unnecessary. Signed-off-by: Ævar Arnfjörð Bjarmason --- t/t1410-reflog.sh | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/t/t1410-reflog.sh b/t/t1410-reflog.sh index ae8a448e34..42f5ac9ed9 100755 --- a/t/t1410-reflog.sh +++ b/t/t1410-reflog.sh @@ -232,24 +232,21 @@ test_expect_success '--expire=never' ' ' test_expect_success 'gc.reflogexpire=never' ' + test_config gc.reflogexpire never && + test_config gc.reflogexpireunreachable never && - git config gc.reflogexpire never && - git config gc.reflogexpireunreachable never && git reflog expire --verbose --all && git reflog refs/heads/master >output && test_line_count = 4 output ' test_expect_success 'gc.reflogexpire=false' ' + test_config gc.reflogexpire false && + test_config gc.reflogexpireunreachable false && - git config gc.reflogexpire false && - git config gc.reflogexpireunreachable false && git reflog expire --verbose --all && git reflog refs/heads/master >output && - test_line_count = 4 output && - - git config --unset gc.reflogexpire && - git config --unset gc.reflogexpireunreachable + test_line_count = 4 output ' From patchwork Thu Mar 14 12:34:37 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 10852739 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EA16C17E6 for ; Thu, 14 Mar 2019 12:35:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8D25C2A23B for ; Thu, 14 Mar 2019 12:35:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 80F722A242; Thu, 14 Mar 2019 12:35:04 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 27BF82A23B for ; Thu, 14 Mar 2019 12:35:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727452AbfCNMfD (ORCPT ); Thu, 14 Mar 2019 08:35:03 -0400 Received: from mail-wm1-f66.google.com ([209.85.128.66]:50567 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727267AbfCNMfC (ORCPT ); Thu, 14 Mar 2019 08:35:02 -0400 Received: by mail-wm1-f66.google.com with SMTP id x7so2804105wmj.0 for ; Thu, 14 Mar 2019 05:35:01 -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=g5NrsLsVGVoc8FeFrZjYyWQIpmPIbiuwhdb5AhRsdiI=; b=BcDTnbuG1GjoR1R8iuksSOdx1rPtiBgO0bPVoSUIgPxIhiikuz83vnkUGOKRYUzQru ohe79vXi3cHg2mspLPq6dX4mHUCIgP52cX0ltyW10JZMc7SjQnuIV/2KrAx9ahTuM19T t+6PDa5v6ZKUSmIJ8yH4zF8HuTiEYn7dNThfu4fsK53jzi0hioCyJlzI2LMG7MwynBaG 7gEm1LwpITJ6MjreWFw3PKXaxbUMSHv/aSLRYW+HQMF8H0p8QzCgR3nQA731a+otNWgu x84Ix6zvjz44I8aJwY0hLLnTPJ0t/1KaGY8CYaC0Fmd1svGMKVcmrQwG3bT83FmzAxRE Mb5g== 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=g5NrsLsVGVoc8FeFrZjYyWQIpmPIbiuwhdb5AhRsdiI=; b=aEtkn8xRze2pq34w1Z0DiAnOtv4JqIkPRF6BenBzC41Z90+to6w8gtDLmfJVLMnWdB rVWYQPGgeZddRS6W7TzczzKHSYYVfWrdwK4n4Gev+sJVihhvasV9B1Dv1SElLQ2VseH3 k6prB98u+Lk1I2oczSDRnhvO0BU3WswXguLbXQxU5t2xwbwM4lxv9IEMa6tstm5jXC0i nqt5XSsltAs1L40gVcL+8Ku/yu+kmzclWG0iB9Mb3/DD8gJh+UOHn+PBaEdc+67tVWsN WumRIgZwdmStsM1bO47zDMNxokRlZjfXQwBhSztH2TmcIfJf4fgu1oF/cdkj/sXmqDYW tmgw== X-Gm-Message-State: APjAAAWHvbyPMeyqjvSj88BWOdT/8RMJJWEKAIIRr91+km48da+TEQy7 zRLyPFztCO5mL177EaE50Vr2bsNMClM= X-Google-Smtp-Source: APXvYqws0yNN5vPZQB8f+Sq2h/rCPCOtSo6OTNaRVxmONBkFHC2HcDuVKcY+XiOgDxSi+yv6d6eLzw== X-Received: by 2002:a7b:cd03:: with SMTP id f3mr2399051wmj.130.1552566899972; Thu, 14 Mar 2019 05:34:59 -0700 (PDT) Received: from vm.nix.is ([2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id p6sm42374095wre.63.2019.03.14.05.34.58 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Thu, 14 Mar 2019 05:34:59 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmc=?= =?utf-8?b?4buNYyBEdXk=?= , Jeff King , Michael Haggerty , Stefan Beller , Jonathan Nieder , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v2 5/7] reflog: exit early if there's no work to do Date: Thu, 14 Mar 2019 13:34:37 +0100 Message-Id: <20190314123439.4347-6-avarab@gmail.com> X-Mailer: git-send-email 2.21.0.360.g471c308f928 In-Reply-To: <20190313235439.30439-1-avarab@gmail.com> References: <20190313235439.30439-1-avarab@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP When gc.reflogExpire and gc.reflogExpireUnreachable are set to "never" and --stale-fix isn't in effect (covered by the first part of the "if" statement being modified here) we can exit early without pointlessly looping over all the reflogs. Signed-off-by: Jeff King Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/reflog.c | 7 +++++++ t/t1410-reflog.sh | 4 +++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/builtin/reflog.c b/builtin/reflog.c index 4d3430900d..d95c77ca0e 100644 --- a/builtin/reflog.c +++ b/builtin/reflog.c @@ -606,6 +606,13 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix) mark_reachable_objects(&cb.cmd.revs, 0, 0, NULL); if (flags & EXPIRE_REFLOGS_VERBOSE) putchar('\n'); + } else if (!cb.cmd.expire_total && !cb.cmd.expire_unreachable) { + /* + * If we're not expiring anything and not dropping + * stale entries, there's no point in even opening the + * reflogs, since we're guaranteed to do nothing. + */ + return 0; } if (do_all) { diff --git a/t/t1410-reflog.sh b/t/t1410-reflog.sh index 42f5ac9ed9..b98827f082 100755 --- a/t/t1410-reflog.sh +++ b/t/t1410-reflog.sh @@ -235,7 +235,9 @@ test_expect_success 'gc.reflogexpire=never' ' test_config gc.reflogexpire never && test_config gc.reflogexpireunreachable never && - git reflog expire --verbose --all && + git reflog expire --verbose --all >output && + test_line_count = 0 output && + git reflog refs/heads/master >output && test_line_count = 4 output ' From patchwork Thu Mar 14 12:34:38 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 10852743 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id F2C3517E6 for ; Thu, 14 Mar 2019 12:35:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A3DD02A23B for ; Thu, 14 Mar 2019 12:35:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 980472A257; Thu, 14 Mar 2019 12:35:09 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 79A602A23B for ; Thu, 14 Mar 2019 12:35:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727476AbfCNMfG (ORCPT ); Thu, 14 Mar 2019 08:35:06 -0400 Received: from mail-wr1-f66.google.com ([209.85.221.66]:46731 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727267AbfCNMfE (ORCPT ); Thu, 14 Mar 2019 08:35:04 -0400 Received: by mail-wr1-f66.google.com with SMTP id 33so5664366wrb.13 for ; Thu, 14 Mar 2019 05:35:03 -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=R+mzPH6o7d5LK0kLUlvPvjklPx0ec57GWWN5I611234=; b=HDj5NFcjqihHcJVoY2wEGDCLU4QOw+TfET9MkxZ8v42s5K6AP8uI/rO0DpHnXpAXVB UnGsTIqDPuEQtRQqjKmzyBLRBB43GRNJtjEzKteZGzSjSIY+yNxVg+xMZaGYg81etPdd cqZmt/tTunDX5CLhpm8IOCa4e9YpVzTrS9KKyf5oerfzO51z8gOu52OM3uuzOhD6/iF/ FuZqH8d92yA/I/M5sqJI2x8JMuGd72PYJsstBlFgvW46jfbsC6yEZBXXXtSqiy/bzv8m 0V7hrvIidI5DfT+sjxrTDC/tmD7vanzJtCRLbyD5q+A1MPTfh9RLPVXNU24RplTe+SXh Byvg== 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=R+mzPH6o7d5LK0kLUlvPvjklPx0ec57GWWN5I611234=; b=TPgYhfELuzUExozmE97tHcFlFFptcduvnvT+aFBERLpweUKBSj5A3RzkTZ9aW3wswN 3cpy3rQR1fTkP8h1IVPPVu8tFb7nX8+Wxyw8gPe8k9TF9RYOaq5dkIfM3dsbdrLCzgAa gX4tSNhqwGW4rO/SZGOPTOEIqdtXBcIsSBWSdIx8Onn7SQgqcw7o4BDNKJXVMfuuycnM RSGIiyAr2tmwvOGRlaCOxCb0CbN8JhNfy60AEF7R4QNrb2R+2NUljnOsEqHg3Ew2fIkH xdXllORcnge4DV9uGVtfacaM1iqdE2LD2EE1dXaaQBeELX4/QTzPMy0kjC9cOhgxpZ1/ 2o6Q== X-Gm-Message-State: APjAAAVznPnP3h8/cRJwc2ZodFA3+uT2rBUy70JL6rOBg9KPexCRXjO2 5FSfhaL6ikWzUhUvDFMExUm4sZ88WhM= X-Google-Smtp-Source: APXvYqywxMtaij1IaMKhgCdSh44Oz8BYKJ2+xabAg6UEZjvJDx8P1mztduUEiC1PaRv6lik6FueRrg== X-Received: by 2002:adf:eb02:: with SMTP id s2mr2660726wrn.40.1552566901757; Thu, 14 Mar 2019 05:35:01 -0700 (PDT) Received: from vm.nix.is ([2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id p6sm42374095wre.63.2019.03.14.05.35.00 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Thu, 14 Mar 2019 05:35:01 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmc=?= =?utf-8?b?4buNYyBEdXk=?= , Jeff King , Michael Haggerty , Stefan Beller , Jonathan Nieder , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v2 6/7] gc: don't run "reflog expire" when keeping reflogs Date: Thu, 14 Mar 2019 13:34:38 +0100 Message-Id: <20190314123439.4347-7-avarab@gmail.com> X-Mailer: git-send-email 2.21.0.360.g471c308f928 In-Reply-To: <20190313235439.30439-1-avarab@gmail.com> References: <20190313235439.30439-1-avarab@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Don't redundantly run "git reflog expire --all" when gc.reflogExpire and gc.reflogExpireUnreachable are set to "never". An earlier change taught "git reflog expire" itself to exit early under this scenario, so in some sense this isn't strictly necessary. Reasons to also do it here: 1) Similar to 8ab5aa4bd8 ("parseopt: handle malformed --expire arguments more nicely", 2018-04-21). We'll die early if the config variables are set to invalid values. We run "pack-refs" before "reflog expire", which can take a while, only to then die on an invalid gc.reflogExpire{Unreachable,} configuration. 2) Not invoking the command at all means it won't show up in trace output, which makes what's going on more obvious. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/gc.c | 17 +++++++++++++++++ t/t6500-gc.sh | 19 +++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/builtin/gc.c b/builtin/gc.c index ae716a00d4..8943bcc300 100644 --- a/builtin/gc.c +++ b/builtin/gc.c @@ -116,6 +116,19 @@ static void process_log_file_on_signal(int signo) raise(signo); } +static int gc_config_is_timestamp_never(const char *var) +{ + const char *value; + timestamp_t expire; + + if (!git_config_get_value(var, &value) && value) { + if (parse_expiry_date(value, &expire)) + die(_("failed to parse '%s' value '%s'"), var, value); + return expire == 0; + } + return 0; +} + static void gc_config(void) { const char *value; @@ -127,6 +140,10 @@ static void gc_config(void) pack_refs = git_config_bool("gc.packrefs", value); } + if (gc_config_is_timestamp_never("gc.reflogexpire") && + gc_config_is_timestamp_never("gc.reflogexpireunreachable")) + prune_reflogs = 0; + git_config_get_int("gc.aggressivewindow", &aggressive_window); git_config_get_int("gc.aggressivedepth", &aggressive_depth); git_config_get_int("gc.auto", &gc_auto_threshold); diff --git a/t/t6500-gc.sh b/t/t6500-gc.sh index 4684d06552..7411bf7fec 100755 --- a/t/t6500-gc.sh +++ b/t/t6500-gc.sh @@ -120,6 +120,25 @@ test_expect_success 'gc --quiet' ' test_must_be_empty stderr ' +test_expect_success 'gc.reflogExpire{Unreachable,}=never skips "expire" via "gc"' ' + test_config gc.reflogExpire never && + test_config gc.reflogExpireUnreachable never && + + GIT_TRACE=$(pwd)/trace.out git gc && + + # Check that git-pack-refs is run as a sanity check (done via + # gc_before_repack()) but that git-expire is not. + grep -E "^trace: (built-in|exec|run_command): git pack-refs --" trace.out && + ! grep -E "^trace: (built-in|exec|run_command): git reflog expire --" trace.out +' + +test_expect_success 'one of gc.reflogExpire{Unreachable,}=never does not skip "expire" via "gc"' ' + >trace.out && + test_config gc.reflogExpire never && + GIT_TRACE=$(pwd)/trace.out git gc && + grep -E "^trace: (built-in|exec|run_command): git reflog expire --" trace.out +' + run_and_wait_for_auto_gc () { # We read stdout from gc for the side effect of waiting until the # background gc process exits, closing its fd 9. Furthermore, the From patchwork Thu Mar 14 12:34:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 10852741 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 52D571390 for ; Thu, 14 Mar 2019 12:35:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1E8A52A23B for ; Thu, 14 Mar 2019 12:35:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 11FCD2A244; Thu, 14 Mar 2019 12:35:08 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 961AE2A23B for ; Thu, 14 Mar 2019 12:35:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727497AbfCNMfG (ORCPT ); Thu, 14 Mar 2019 08:35:06 -0400 Received: from mail-wr1-f68.google.com ([209.85.221.68]:37459 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727462AbfCNMfG (ORCPT ); Thu, 14 Mar 2019 08:35:06 -0400 Received: by mail-wr1-f68.google.com with SMTP id y15so5680427wro.4 for ; Thu, 14 Mar 2019 05:35:05 -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=+WADQxBhoTqWIZ9NHjihkjBLU5lRPCm9pM4d6ii9r+I=; b=qTzEQCF5mjMv9gnd6D0Y93gFGG2OoofZSZBkN4idd8po4F/u8JJjF6ZCrO4LCOoa63 4yTkQ7VakkHjb4c5qXofFFeIwqR7NwzZWVHx81ugkt2ACM8Gbklc5P1He27sU56QNFZP Z5jvFQsgN1+5KKYhs54gWen6oXjvEM98xeXIYOuCBmp4RpGr4okXHiYYztnEBvLD7Aur /7Z+BM4kjlg25jzl5mvs7FyHGRz6Qi74y/vA+pukhycvaOmVycW7w8iv/LfyQm9N0+8j 0isv0iqMUVP9BkViFOhX3CBhJ3oL1BbkTmG1M6KABGu7qi5yzCP2ImfpvROehDQ1rJ1Z uwJg== 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=+WADQxBhoTqWIZ9NHjihkjBLU5lRPCm9pM4d6ii9r+I=; b=BXyJqdpAuZChZHXcFDiaOQLW1xMQEzKqP3WpCG1R0rQtfBnDIW8kmIScsIWRdR/vxR nPhFevMQL3A72uMgEdGR5bYmS9NGJorR25zhlIhHaz4tavAxuFZ7O/Jpccw0Ge444HnF kqcCCbpwRtDiinCn3tE8Yo52PF6xBgntYKOSPffG3TsBgLYYFXy9DgLkrjs9WWvFTatr gBR98vWwDa6MSEraBwGYBIS4a+iP4A1eGOQlzjAqe8GejV7V/LliSxoghCiSLXkltomv gWXj8rcHa8MrKlkmLqBqPDHl9RJ77fPK9mlxH9GJLgX4+vpyDHXjD7gURNEqyqmJerL0 DPAw== X-Gm-Message-State: APjAAAW50Ny0kClbF0pgm3yXkjVTKHXrD6b7s7bs4Z8tjX6OOeWf4INk GXTHZrR+VztsbYFgb7yHe9H14MhUa2Q= X-Google-Smtp-Source: APXvYqzkLEZJRbs2HTwoBDqXxK5uSPC/YJaS+xr+6yX+iP5zN+tJxovSEXdkP6iIbmnX2zE1Pl8RVA== X-Received: by 2002:a5d:4b05:: with SMTP id v5mr21652473wrq.323.1552566903761; Thu, 14 Mar 2019 05:35:03 -0700 (PDT) Received: from vm.nix.is ([2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id p6sm42374095wre.63.2019.03.14.05.35.02 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Thu, 14 Mar 2019 05:35:03 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmc=?= =?utf-8?b?4buNYyBEdXk=?= , Jeff King , Michael Haggerty , Stefan Beller , Jonathan Nieder , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v2 7/7] reflog expire: don't assert the OID when locking refs Date: Thu, 14 Mar 2019 13:34:39 +0100 Message-Id: <20190314123439.4347-8-avarab@gmail.com> X-Mailer: git-send-email 2.21.0.360.g471c308f928 In-Reply-To: <20190313235439.30439-1-avarab@gmail.com> References: <20190313235439.30439-1-avarab@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP During reflog expiry, the cmd_reflog_expire() function first iterates over all reflogs in logs/*, and then one-by-one acquires the lock for each one to expire its reflog by getting a *.lock file on the corresponding loose ref[1] (even if the actual ref is packed). This lock is needed, but what isn't needed is locking the loose ref as a function of the OID we found from that first iteration. By the time we get around to re-visiting the reference some of the OIDs may have changed. Thus the verify_lock() function called by the lock_ref_oid_basic() function being changed here would fail with e.g. "ref '%s' is at %s but expected %s" if the repository was being updated concurrent to the "reflog expire". By not passing the OID to it we'll try to lock the reference regardless of it last known OID. Locking as a function of the OID would make "reflog expire" exit with a non-zero exit status under such contention, which in turn meant that a "gc" command (which expires reflogs before forking to the background) would encounter a hard error. This behavior of considering the OID when locking has been here ever since "reflog expire" was initially implemented in 4264dc15e1 ("git reflog expire", 2006-12-19). As seen in that simpler initial version of the code we subsequently use the OID to inform the expiry (and still do), but never needed to use it to lock the reference associated with the reflog. By locking the reference without considering what OID we last saw it at, we won't encounter user-visible contention to the extent that core.filesRefLockTimeout mitigates it. See 4ff0f01cb7 ("refs: retry acquiring reference locks for 100ms", 2017-08-21). Unfortunately this sort of probabilistic contention is hard to turn into a test. I've tested this by running the following three subshells in concurrent terminals: ( cd /tmp && rm -rf git && git init git && cd git && while true do head -c 10 /dev/urandom | hexdump >out && git add out && git commit -m"out" done ) ( cd /tmp && rm -rf git-clone && git clone file:///tmp/git git-clone && cd git-clone && while git pull do date done ) ( cd /tmp/git-clone && while git reflog expire --all do date done ) Before this change the "reflog expire" would fail really quickly with a "but expected" error. After this change both the "pull" and "reflog expire" will run for a while, but eventually fail because I get unlucky with core.filesRefLockTimeout (the "reflog expire" is in a really tight loop). That can be resolved by being more generous with higher values of core.filesRefLockTimeout than the 100ms default. 1. https://public-inbox.org/git/54857871.5090805@alum.mit.edu/ Signed-off-by: Ævar Arnfjörð Bjarmason --- refs/files-backend.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/refs/files-backend.c b/refs/files-backend.c index ef053f716c..4d4d226601 100644 --- a/refs/files-backend.c +++ b/refs/files-backend.c @@ -3037,7 +3037,7 @@ static int files_reflog_expire(struct ref_store *ref_store, * reference itself, plus we might need to update the * reference if --updateref was specified: */ - lock = lock_ref_oid_basic(refs, refname, oid, + lock = lock_ref_oid_basic(refs, refname, NULL /* NOT oid! */, NULL, NULL, REF_NO_DEREF, &type, &err); if (!lock) {