From patchwork Tue Jan 5 19:23:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Martin_=C3=85gren?= X-Patchwork-Id: 12000243 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=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT 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 CC39AC433E9 for ; Tue, 5 Jan 2021 19:26:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A1C9922CF8 for ; Tue, 5 Jan 2021 19:26:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728655AbhAET0C (ORCPT ); Tue, 5 Jan 2021 14:26:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47074 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726663AbhAET0B (ORCPT ); Tue, 5 Jan 2021 14:26:01 -0500 Received: from mail-lf1-x12b.google.com (mail-lf1-x12b.google.com [IPv6:2a00:1450:4864:20::12b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3D97BC061795 for ; Tue, 5 Jan 2021 11:24:39 -0800 (PST) Received: by mail-lf1-x12b.google.com with SMTP id o19so1140846lfo.1 for ; Tue, 05 Jan 2021 11:24:39 -0800 (PST) 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=ayM9kLV7lJvZ+kQc7BAf+3o6iyHcSb3H+W8asukRojQ=; b=sPT8hKUYnFyAqlfSrAjHfThpaAEE8DfusaBwvX5hbZvmzE6VmBKzdX/lIG7o9Z+Gjo 6oaq7uCs953YiGsR+4hYOB4U967ADcNVNu9navUIz3XmAjPllcxT+mLL2S/2T9LmZet3 s2wGCCL5dofrmhpLBW5XxtlCUBNEOXq68TbFDPXdAiUq4M4ztojHh4XvR5hAZbvPwXGv UvPjQr3IPH2LhVUlJsZ2KEozn2yG672F0qHkx+gW6xreQFNIRTJ7DljsffwbpKOYZbdT pLojGgIGGFxL0T3mzie2reaUr7qkGhzht5mXDkaQats7KdumVBxY0v8DcJ2pQRZwpz9+ IE7Q== 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=ayM9kLV7lJvZ+kQc7BAf+3o6iyHcSb3H+W8asukRojQ=; b=EvgJ5pqRLGHvs5KAHKgtft6gx4IlJCs/CsxR47/mRdBRV0XNpF0uIOjv34NbHR1K3C I5/H00U8hbcjqs1EvEwmgsEBEB74b3o6LND11QI1To5do0Vv8+KQAmlz0+QS5txGy1VV /nFGHpc0n6Tb07PTyw/VSAY5ZDL5vu9gCJN6RZ3N61jVjC6+av76qkCNk4pSLrfI+qRl 3s5cjpl+/x/4N12zpfFbEUc8+8v6iUmo+DJwSYnYkXDEEClYnn0cw/C3vjPvlvtKnSjh VQf5S6vOtSMCa/LCzf7IWqYP/TOlWgQZkh4vpBhfdlvfc9SLQdGkjuctbvAGW4M/yaJi muVw== X-Gm-Message-State: AOAM530xqmbBSl7cnXgwl+Lb2EJbFbxmC8wg/xisfgtz8M2TSJtkaRBk iZfj8fXCDuEPOQpoVKK0HwWxPBGE9Go= X-Google-Smtp-Source: ABdhPJxgKryPv6w0ljhYvCm1H6u8Qk5R8TsgjCwG7xrZG3ogXGIawofbSC4cR1GqNPVK/oKXgflfKQ== X-Received: by 2002:ac2:446d:: with SMTP id y13mr294357lfl.615.1609874677563; Tue, 05 Jan 2021 11:24:37 -0800 (PST) Received: from localhost.localdomain (31-211-229-121.customers.ownit.se. [31.211.229.121]) by smtp.gmail.com with ESMTPSA id h1sm9116lfc.121.2021.01.05.11.24.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Jan 2021 11:24:37 -0800 (PST) From: =?utf-8?q?Martin_=C3=85gren?= To: git@vger.kernel.org Cc: Alban Gruin , Derrick Stolee Subject: [PATCH 1/5] builtin/gc: don't peek into `struct lock_file` Date: Tue, 5 Jan 2021 20:23:46 +0100 Message-Id: X-Mailer: git-send-email 2.30.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org A `struct lock_file` is pretty much just a wrapper around a tempfile. But it's easy enough to avoid relying on this. Use the wrappers that the lock file API provides rather than peeking at the temp file or even into *its* internals. Signed-off-by: Martin Ågren --- builtin/gc.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/builtin/gc.c b/builtin/gc.c index 4c24f41852..64f2b52d6e 100644 --- a/builtin/gc.c +++ b/builtin/gc.c @@ -92,7 +92,7 @@ static void process_log_file(void) */ int saved_errno = errno; fprintf(stderr, _("Failed to fstat %s: %s"), - get_tempfile_path(log_lock.tempfile), + get_lock_file_path(&log_lock), strerror(saved_errno)); fflush(stderr); commit_lock_file(&log_lock); @@ -1518,7 +1518,7 @@ static int update_background_schedule(int run_maintenance) strvec_split(&crontab_list.args, crontab_name); strvec_push(&crontab_list.args, "-l"); crontab_list.in = -1; - crontab_list.out = dup(lk.tempfile->fd); + crontab_list.out = dup(get_lock_file_fd(&lk)); crontab_list.git_cmd = 0; if (start_command(&crontab_list)) { @@ -1533,7 +1533,7 @@ static int update_background_schedule(int run_maintenance) * Read from the .lock file, filtering out the old * schedule while appending the new schedule. */ - cron_list = fdopen(lk.tempfile->fd, "r"); + cron_list = fdopen(get_lock_file_fd(&lk), "r"); rewind(cron_list); strvec_split(&crontab_edit.args, crontab_name); From patchwork Tue Jan 5 19:23:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Martin_=C3=85gren?= X-Patchwork-Id: 12000241 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=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT 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 E4B7AC433E6 for ; Tue, 5 Jan 2021 19:26:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B9AC222D6F for ; Tue, 5 Jan 2021 19:26:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727451AbhAET0C (ORCPT ); Tue, 5 Jan 2021 14:26:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47076 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726545AbhAET0B (ORCPT ); Tue, 5 Jan 2021 14:26:01 -0500 Received: from mail-lf1-x135.google.com (mail-lf1-x135.google.com [IPv6:2a00:1450:4864:20::135]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 14816C061796 for ; Tue, 5 Jan 2021 11:24:43 -0800 (PST) Received: by mail-lf1-x135.google.com with SMTP id o19so1141320lfo.1 for ; Tue, 05 Jan 2021 11:24:42 -0800 (PST) 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=h160zvyTCWIHZC4E07QPWvDkUCT/B3ZZvGD+ofHAQ9c=; b=W+6tlkpt+BqhW7vA63S06btRXdZ1PvJHj4ZCpYP6V9LrYnlb/NRE5sgIDzENQ1d4/C +quJomAQN5kcIKBI6q4omv6PBU8dbtLlmkV7uy0HuR0ezy4+r8/r8odGzhwxUYreGHjl Y2AZcklneGdlpxbRrDP/qt9jhYFOcjHt+t/EpafoQNDNy0JuiOrvVi+cmLSLX2+rY+IV hAO51pZAM3ltN6cJ9h+lK9AHVMNQogy1Ifgp6JJhIy8wIlya2XcNmlJX5ooKTnSQiGqz LCzaj8q8KOteHuzIiIpGqQwHeiqvks2C58GN7UXTvt4QsCnqVWLkpeIJ2bC/rlHkg/7e iTPA== 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=h160zvyTCWIHZC4E07QPWvDkUCT/B3ZZvGD+ofHAQ9c=; b=ryUCmxT9S3sOPObrgDetHZXaX7TF1apQaLXcjSMfcOLyG04bgHWc6IommX+YcuwkJ1 LkCMleeqIWqcjnpZbJggr/HrF5XK/yVLtnh4ZNH5y0D6Btpyd5xOXz8xZeFqQ5BtdILu H1beNSvn0f1oS0UbFCGlMkpB9QxbB/4p5ptEPJn1a708sc0klY+tKTiUNkdDUfjGXAI0 mLWPMdhtbbrKSrcLrWBEbbYGyBVZRa7k9kcVzul83Ot9sUpsBXzrStb1EXND6lTLnKXd MNq2dfLTgYYT7kG16SB51aBaN8BWxaVF/hwZ6cgR7CRfPgJNXRQ/6DUlb2f5gNuC4iOo pqDQ== X-Gm-Message-State: AOAM531tq/0LvXIrrJ6XDygax1yfHDfNSKLq3Y4CwSIAmPHQRknbPFwL AZSbMRnQhUn14+2h5CYzDeCVD3+SbxI= X-Google-Smtp-Source: ABdhPJxRIiwtDqhw0flvOLpSPLw+RayFVkUEaFa4W75IoYQTQIRyfE7QcVQD+WtizG2jh2fPxJi5Iw== X-Received: by 2002:a05:6512:63:: with SMTP id i3mr347419lfo.170.1609874681402; Tue, 05 Jan 2021 11:24:41 -0800 (PST) Received: from localhost.localdomain (31-211-229-121.customers.ownit.se. [31.211.229.121]) by smtp.gmail.com with ESMTPSA id h1sm9116lfc.121.2021.01.05.11.24.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Jan 2021 11:24:40 -0800 (PST) From: =?utf-8?q?Martin_=C3=85gren?= To: git@vger.kernel.org Cc: Alban Gruin , Derrick Stolee Subject: [PATCH 2/5] commit-graph: don't peek into `struct lock_file` Date: Tue, 5 Jan 2021 20:23:47 +0100 Message-Id: <7a91469c7c791d5faeabc601775a3b535cbfc26e.1609874026.git.martin.agren@gmail.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Similar to the previous commit, avoid peeking into the `struct lock_file`. Use the lock file API instead. Signed-off-by: Martin Ågren --- commit-graph.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/commit-graph.c b/commit-graph.c index 06f8dc1d89..031641014f 100644 --- a/commit-graph.c +++ b/commit-graph.c @@ -1694,8 +1694,8 @@ static int write_commit_graph_file(struct write_commit_graph_context *ctx) } else { hold_lock_file_for_update_mode(&lk, ctx->graph_name, LOCK_DIE_ON_ERROR, 0444); - fd = lk.tempfile->fd; - f = hashfd(lk.tempfile->fd, lk.tempfile->filename.buf); + fd = get_lock_file_fd(&lk); + f = hashfd(fd, get_lock_file_path(&lk)); } chunks[0].id = GRAPH_CHUNKID_OIDFANOUT; @@ -1833,7 +1833,7 @@ static int write_commit_graph_file(struct write_commit_graph_context *ctx) result = rename(ctx->graph_name, final_graph_name); for (i = 0; i < ctx->num_commit_graphs_after; i++) - fprintf(lk.tempfile->fp, "%s\n", ctx->commit_graph_hash_after[i]); + fprintf(get_lock_file_fp(&lk), "%s\n", ctx->commit_graph_hash_after[i]); if (result) { error(_("failed to rename temporary commit-graph file")); From patchwork Tue Jan 5 19:23:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Martin_=C3=85gren?= X-Patchwork-Id: 12000239 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=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT 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 96A3FC433DB for ; Tue, 5 Jan 2021 19:26:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7195C22CF8 for ; Tue, 5 Jan 2021 19:26:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730522AbhAET0C (ORCPT ); Tue, 5 Jan 2021 14:26:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47078 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726683AbhAET0B (ORCPT ); Tue, 5 Jan 2021 14:26:01 -0500 Received: from mail-lf1-x12f.google.com (mail-lf1-x12f.google.com [IPv6:2a00:1450:4864:20::12f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E6E2EC061798 for ; Tue, 5 Jan 2021 11:24:44 -0800 (PST) Received: by mail-lf1-x12f.google.com with SMTP id x20so966353lfe.12 for ; Tue, 05 Jan 2021 11:24:44 -0800 (PST) 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=OTcZy0lfk9sqHtVCIHKXZztuPDmTjS6lr9VU7ngS/FE=; b=M7T0ZEt4Q0RgsdDUdczYvzkkRcvc/7V7ZphlpIUbNZ+9IDRjQgJHc8szXFkM4k9FOU vOkuY5MQ5RifJxj+q0OIiniGbRr3k53xWx8mypnuw8F8aiE/t2DaYFGM6LFKiUX5Y1eT ycoEQdiAyYV8xl1Tzodf6Exp+GIGsyg5ubK8gIN7s0OXQmFBXy/jQxbKKrksCAipmyUy k6qfn5fjARoHl5xezdgxHnRjptt+FzhsUHGTn27vADIqclPKpm6lD+PfnURH34lFe7Iy jxB/tBPIIEbBt2Rc37SrbATdUZltCp1OCEAGfiOoJ6PC3izr++xiH3SpB+bDWBRoraqi ZjOw== 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=OTcZy0lfk9sqHtVCIHKXZztuPDmTjS6lr9VU7ngS/FE=; b=hvRPJMr9HxZpo9Nz3ah16rsm6BOYTy6swU7RyYxMZgbvWYiIx4qC7VNPl3GVt1hgim /WgFmsv/mb2h5f2kQWh/vyHIM9uX7UrajG+YPoCZbKWV1Brd3wDDGhkdnCmTbNFMy5i8 LpEc+wX0TIoB+u8BO54F4vgMd/IjVEAWBRW3PpRF3wnDwj/1zIVcpuES03Ca2Nu7mi40 Mdpe0FuYJUIyjK38d77YzR4FwbxKmjOZh3bnbheEga7hMI7vNSndIn9V0dhQtKQ9SLHe Q+3Nd5aF9hU5FnwSUYUAMm7/9y1gR5zf0na/UwQ5Nb7jB17wjJhBHzd3T0XYO9+H7bzQ 5Mww== X-Gm-Message-State: AOAM5311q7q/z1+UIyDIYQwMaiZ0Mp7N4ve3C3uAf5d0yPdYsp6ocpSb Rv6AcZVYUOyezc79OiQ8dqMZq8THSBA= X-Google-Smtp-Source: ABdhPJxB3GmuyOx2j62etNtfV0NHYxHxAMEOSc3n3VxlOM+jkMxhmtrXni4sObSajf9FspY9g1f8OQ== X-Received: by 2002:a19:991:: with SMTP id 139mr320837lfj.637.1609874683220; Tue, 05 Jan 2021 11:24:43 -0800 (PST) Received: from localhost.localdomain (31-211-229-121.customers.ownit.se. [31.211.229.121]) by smtp.gmail.com with ESMTPSA id h1sm9116lfc.121.2021.01.05.11.24.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Jan 2021 11:24:42 -0800 (PST) From: =?utf-8?q?Martin_=C3=85gren?= To: git@vger.kernel.org Cc: Alban Gruin , Derrick Stolee Subject: [PATCH 3/5] midx: don't peek into `struct lock_file` Date: Tue, 5 Jan 2021 20:23:48 +0100 Message-Id: <6dfb457b2a3187546eb4b4d90679348f2051a57d.1609874026.git.martin.agren@gmail.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Similar to the previous commits, avoid peeking into the `struct lock_file`. Use the lock file API instead. The two functions we're calling here double-check that the tempfile is indeed "active", which is arguably overkill considering how we took the lock on the line immediately above. More importantly, this future-proofs us against, e.g., other code appearing between these two lines or the lock file and/or tempfile internals changing. Signed-off-by: Martin Ågren --- midx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/midx.c b/midx.c index 79c282b070..9d41b9c271 100644 --- a/midx.c +++ b/midx.c @@ -918,7 +918,7 @@ static int write_midx_internal(const char *object_dir, struct multi_pack_index * (pack_name_concat_len % MIDX_CHUNK_ALIGNMENT); hold_lock_file_for_update(&lk, midx_name, LOCK_DIE_ON_ERROR); - f = hashfd(lk.tempfile->fd, lk.tempfile->filename.buf); + f = hashfd(get_lock_file_fd(&lk), get_lock_file_path(&lk)); FREE_AND_NULL(midx_name); if (packs.m) From patchwork Tue Jan 5 19:23:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Martin_=C3=85gren?= X-Patchwork-Id: 12000237 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=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT 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 BA6F2C433E0 for ; Tue, 5 Jan 2021 19:26:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8A9C022D5B for ; Tue, 5 Jan 2021 19:26:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730693AbhAET0D (ORCPT ); Tue, 5 Jan 2021 14:26:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47080 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727036AbhAET0B (ORCPT ); Tue, 5 Jan 2021 14:26:01 -0500 Received: from mail-lf1-x12c.google.com (mail-lf1-x12c.google.com [IPv6:2a00:1450:4864:20::12c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ADF3EC06179A for ; Tue, 5 Jan 2021 11:24:46 -0800 (PST) Received: by mail-lf1-x12c.google.com with SMTP id h205so1073602lfd.5 for ; Tue, 05 Jan 2021 11:24:46 -0800 (PST) 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=XzxljG3u3B2G+pGLsNysBl8bhKcbOyXfAVTZFr7A7Jk=; b=rLRvnhQ5nKgBSRiX7M4uq3gaM/MaRwz2OwQqjLnr3ThZthlQO+Vv/dpjmE5NpWIkte sSQbanFpuB91jKn2gskocFa7mqsxR2nhU5pdZihYWfQ292KFQZFxNdPEEJzen7X0QUxH XBrHhWXxyAZR1FDVjInyAm7XgVXa68Kg0St2rHpA+gMp8nNUxdeUddXGo4/oGV3KQ7mr 8wvCM2F5BxrL53N2bDbW7LwATEK2NhiRSYqU9QYkS8UK0DyQG/Bb8TbDaqY3HvBgQ6tq HC0xL4l/CgYPK9aoGPXnzxcv96gYUhOdYxg9GQqnn0Yh5uKyh3Yp4hjzMOpwzYr70zFL kd5w== 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=XzxljG3u3B2G+pGLsNysBl8bhKcbOyXfAVTZFr7A7Jk=; b=uoEGnGbMcA8J6Jj/QqIzAUwNXpG5U6XPVrH02jnpGPYVV9dW2wDh5WPKkHzzQPUFj8 ldXRDoxBhDvILjFIZEsfhwfLTNu2GDz19sOWNPecud07sOavdA7lv90vVmDu76awKDbi epVmP/HZ7NEy2kN4NWexNwNX+D1dTwgehif3ZmKe/khoL2TQCzTYCEf7jiBrce6/rhsA adhG6HX1AX7qKIQji4EIGP13yHGvcjBu+cKnXB0Yz9csM9vOd5J0fWp5Mh4GGwPeFz3G N2C2Dqg+QsL2qfeTu/OfDim9n9n2cLULvjOtEf9il241VOZhAUWJ0Hf7n9E/wJ5GUZeV qGbw== X-Gm-Message-State: AOAM532aN/xctwS2HbRnScSWCSr0TXUgPtXKamvNoVd5zMZmHPyazX4v yM26aVvoq6uK5ACePPfFwy+3gDQL8/w= X-Google-Smtp-Source: ABdhPJw5bhyzAOfwQCDiUYN03VZjvkWN56sodZTnFlENHQvynP3ULgwxfjxkGD0xekXxToIadPJIIA== X-Received: by 2002:a2e:9d87:: with SMTP id c7mr466512ljj.43.1609874684962; Tue, 05 Jan 2021 11:24:44 -0800 (PST) Received: from localhost.localdomain (31-211-229-121.customers.ownit.se. [31.211.229.121]) by smtp.gmail.com with ESMTPSA id h1sm9116lfc.121.2021.01.05.11.24.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Jan 2021 11:24:44 -0800 (PST) From: =?utf-8?q?Martin_=C3=85gren?= To: git@vger.kernel.org Cc: Alban Gruin , Derrick Stolee Subject: [PATCH 4/5] refs/files-backend: don't peek into `struct lock_file` Date: Tue, 5 Jan 2021 20:23:49 +0100 Message-Id: X-Mailer: git-send-email 2.30.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Similar to the previous commits, avoid peeking into the `struct lock_file`. Use the lock file API instead. Note how we obtain the path to the lock file if `fdopen_lock_file()` failed and that this is not a problem: as documented in lockfile.h, failure to "fdopen" does not roll back the lock file and we're free to, e.g., query it for its path. Signed-off-by: Martin Ågren --- refs/files-backend.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/refs/files-backend.c b/refs/files-backend.c index 04e85e7002..4fdc68810b 100644 --- a/refs/files-backend.c +++ b/refs/files-backend.c @@ -1824,12 +1824,12 @@ static int create_symref_locked(struct files_ref_store *refs, if (!fdopen_lock_file(&lock->lk, "w")) return error("unable to fdopen %s: %s", - lock->lk.tempfile->filename.buf, strerror(errno)); + get_lock_file_path(&lock->lk), strerror(errno)); update_symref_reflog(refs, lock, refname, target, logmsg); /* no error check; commit_ref will check ferror */ - fprintf(lock->lk.tempfile->fp, "ref: %s\n", target); + fprintf(get_lock_file_fp(&lock->lk), "ref: %s\n", target); if (commit_ref(lock) < 0) return error("unable to write symref for %s: %s", refname, strerror(errno)); From patchwork Tue Jan 5 19:23:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Martin_=C3=85gren?= X-Patchwork-Id: 12000245 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=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT 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 3FB83C433DB for ; Tue, 5 Jan 2021 19:26:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 184B322D5B for ; Tue, 5 Jan 2021 19:26:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730723AbhAET0m (ORCPT ); Tue, 5 Jan 2021 14:26:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47184 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728466AbhAET0l (ORCPT ); Tue, 5 Jan 2021 14:26:41 -0500 Received: from mail-lf1-x12f.google.com (mail-lf1-x12f.google.com [IPv6:2a00:1450:4864:20::12f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 26F77C06179E for ; Tue, 5 Jan 2021 11:24:50 -0800 (PST) Received: by mail-lf1-x12f.google.com with SMTP id o19so1142119lfo.1 for ; Tue, 05 Jan 2021 11:24:50 -0800 (PST) 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=yNQ63wqyU19asx04oRrhU7bk1AWqHAd66DS/wbSJuF0=; b=ErnpkDEPWqSjL6itGnpvxINFGfaNf6U/Z8I8ASJMZvc/1gN1Ii7usrLDDo2dw7ok66 S5BO2FuFoiwQgfXVt4djXC5Q8Fg0XuI3Ipt7KU0AgzS2mXqGehreKi/Pgi4p0UPVw1jh k1l1diIqbxNanqINDTf4T4gpHTCRSI67u/emmr75Zq73p2+o9FcWqGPP5P/25+f/EUBP pyeFrMvKT7ruhVpGuT0CAPPY+nyl4z6uSpjd2iXLBXiMJsj4MEBacjke/d+ylhrk9gAH tCzQ0lBKR8FE7MsOa1fwkizVYdtSnptoL1W7xbzB3XAKjvOwVFqSNHMtCfuJJlwfQ/mL TbyA== 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=yNQ63wqyU19asx04oRrhU7bk1AWqHAd66DS/wbSJuF0=; b=spqDvFGekiJWLmPT/7K2jSzkGNoU/S7jHRE8efSx8/NGOcKCZ1FTw6XK3ymExZC+tR JbvRbiZyu5k/2JE9NjTFhgh5G2jg/w7Xm21SStNE+F+fi5CbS0EAxxqmVNYPgEAV8Wq5 jtBQEB8mljrcXgYJTDDYZltGy+DXkBlLlEEGsoI5DUZMI9Je9uu/oJszJZzzFnwGDVIV s2xAcSNMW/ymyWdAPid/AXhVQJt2cB0dG3zQfu+F89auzKMswgm3Tm3bn8U5Nw2SORc+ fTCyesS9QnzWj9Rt39g6D7Bvj1QHF6U6kNDCiEsWKfSYWVGksPGdMaxLSmkLVZwyCq8H Ofhg== X-Gm-Message-State: AOAM5338TdTQOn2TdQXRkkNpU2zYtawbn8HsA3GdFRA7+qQTsrmXXZpA pxs48C15cuxg+4fPOMQGsEV3RmQGM5U= X-Google-Smtp-Source: ABdhPJz9hCC2Qkz4fBlGI49w7oiC1mj4fK2OuqTuk/F5gPqgBxPitAWk/w/FJY0PQ7o77LRcTmcZow== X-Received: by 2002:a19:5041:: with SMTP id z1mr370478lfj.77.1609874688395; Tue, 05 Jan 2021 11:24:48 -0800 (PST) Received: from localhost.localdomain (31-211-229-121.customers.ownit.se. [31.211.229.121]) by smtp.gmail.com with ESMTPSA id h1sm9116lfc.121.2021.01.05.11.24.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Jan 2021 11:24:47 -0800 (PST) From: =?utf-8?q?Martin_=C3=85gren?= To: git@vger.kernel.org Cc: Alban Gruin , Derrick Stolee Subject: [PATCH 5/5] read-cache: try not to peek into `struct {lock_,temp}file` Date: Tue, 5 Jan 2021 20:23:50 +0100 Message-Id: X-Mailer: git-send-email 2.30.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Similar to the previous commits, try to avoid peeking into the `struct lock_file`. We also have some `struct tempfile`s -- let's avoid looking into those as well. Note that `do_write_index()` takes a tempfile and that when we call it, we either have a tempfile which we can easily hand down, or we have a lock file, from which we need to somehow obtain the internal tempfile. So we need to leave that one instance of peeking-into. Nevertheless, this commit leaves us not relying on exactly how the path of the tempfile / lock file is stored internally. Signed-off-by: Martin Ågren --- read-cache.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/read-cache.c b/read-cache.c index ecf6f68994..29144cf879 100644 --- a/read-cache.c +++ b/read-cache.c @@ -3014,10 +3014,10 @@ static int do_write_index(struct index_state *istate, struct tempfile *tempfile, if (ce_flush(&c, newfd, istate->oid.hash)) return -1; if (close_tempfile_gently(tempfile)) { - error(_("could not close '%s'"), tempfile->filename.buf); + error(_("could not close '%s'"), get_tempfile_path(tempfile)); return -1; } - if (stat(tempfile->filename.buf, &st)) + if (stat(get_tempfile_path(tempfile), &st)) return -1; istate->timestamp.sec = (unsigned int)st.st_mtime; istate->timestamp.nsec = ST_MTIME_NSEC(st); @@ -3058,10 +3058,10 @@ static int do_write_locked_index(struct index_state *istate, struct lock_file *l * that is associated with the given "istate". */ trace2_region_enter_printf("index", "do_write_index", the_repository, - "%s", lock->tempfile->filename.buf); + "%s", get_lock_file_path(lock)); ret = do_write_index(istate, lock->tempfile, 0); trace2_region_leave_printf("index", "do_write_index", the_repository, - "%s", lock->tempfile->filename.buf); + "%s", get_lock_file_path(lock)); if (ret) return ret; @@ -3158,10 +3158,10 @@ static int write_shared_index(struct index_state *istate, move_cache_to_base_index(istate); trace2_region_enter_printf("index", "shared/do_write_index", - the_repository, "%s", (*temp)->filename.buf); + the_repository, "%s", get_tempfile_path(*temp)); ret = do_write_index(si->base, *temp, 1); trace2_region_leave_printf("index", "shared/do_write_index", - the_repository, "%s", (*temp)->filename.buf); + the_repository, "%s", get_tempfile_path(*temp)); if (ret) return ret;